| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64calib/detectorsOrder.hh" | ||
| 2 | |||
| 3 | namespace na64dp { | ||
| 4 | namespace calib { | ||
| 5 | |||
| 6 | struct StationEntry { | ||
| 7 | std::unordered_set<DetID> layerIDs; | ||
| 8 | float avrgVal; | ||
| 9 | ✗ | StationEntry() : avrgVal(0.) {} | |
| 10 | }; | ||
| 11 | |||
| 12 | std::map<DetID, unsigned int> | ||
| 13 | ✗ | OrderedStations::_sort_detectors( const std::unordered_map<DetID, Placement> & byIDs | |
| 14 | , size_t & nSortedGroups | ||
| 15 | ) const { | ||
| 16 | // collect station keys | ||
| 17 | ✗ | std::unordered_map<StationKey, StationEntry > detIDsByStationKeys; | |
| 18 | ✗ | for(auto & entry : byIDs) { | |
| 19 | // check if matches selection/zones criteria | ||
| 20 | ✗ | bool matches = true; | |
| 21 | ✗ | for(auto selPair : _selectorPtrs) { | |
| 22 | ✗ | if(!selPair->second) { | |
| 23 | ✗ | NA64DP_RUNTIME_ERROR("Unresolved selector \"%s\"", selPair->first.c_str()); | |
| 24 | } | ||
| 25 | ✗ | if(selPair->second->matches(entry.first)) continue; | |
| 26 | ✗ | _log << log4cpp::Priority::DEBUG | |
| 27 | ✗ | << "Placement item \"" << naming()[entry.first] << "\" declined from" | |
| 28 | ✗ | " detectors order " << (void*) this << " by selector \"" << selPair->first.c_str() | |
| 29 | ✗ | << "\""; | |
| 30 | ✗ | matches = false; | |
| 31 | ✗ | break; | |
| 32 | } | ||
| 33 | ✗ | if(!matches) continue; | |
| 34 | ✗ | if((!_permittedZones.empty()) && _permittedZones.find(entry.second.zone) == _permittedZones.end()) { | |
| 35 | ✗ | _log << log4cpp::Priority::DEBUG | |
| 36 | ✗ | << "Placement item \"" << naming()[entry.first] << "\" declined from" | |
| 37 | ✗ | " detectors order " << (void*) this << " by zone mismatch"; | |
| 38 | ✗ | continue; | |
| 39 | } | ||
| 40 | // Add station key | ||
| 41 | ✗ | auto ir = detIDsByStationKeys.emplace( StationKey(entry.first), StationEntry() ); | |
| 42 | ✗ | if(!ir.second) { | |
| 43 | ✗ | ir.first->second.avrgVal += _callback(entry.first, entry.second); | |
| 44 | } else { | ||
| 45 | ✗ | ir.first->second.avrgVal = _callback(entry.first, entry.second); | |
| 46 | } | ||
| 47 | ✗ | ir.first->second.layerIDs.insert(entry.first); | |
| 48 | } | ||
| 49 | // find averaged value per station | ||
| 50 | ✗ | for(auto & p : detIDsByStationKeys) { | |
| 51 | ✗ | assert(!p.second.layerIDs.empty()); | |
| 52 | ✗ | p.second.avrgVal /= p.second.layerIDs.size(); | |
| 53 | } | ||
| 54 | // build reverse map for stations only | ||
| 55 | ✗ | std::map<float, StationKey> skByVal; | |
| 56 | ✗ | std::transform( detIDsByStationKeys.begin(), detIDsByStationKeys.end() | |
| 57 | , std::inserter(skByVal, skByVal.end()) | ||
| 58 | ✗ | , [](const auto & p){ | |
| 59 | ✗ | return std::pair<float, StationKey>(p.second.avrgVal, p.first);} | |
| 60 | ); | ||
| 61 | // build enumerated list | ||
| 62 | ✗ | unsigned int n = 0; | |
| 63 | ✗ | std::ostringstream oss; | |
| 64 | ✗ | std::map<DetID, unsigned int> r; | |
| 65 | ✗ | for( const auto & stationEntry : skByVal ) { | |
| 66 | ✗ | oss << "#" << n << ", station \"" << naming()[stationEntry.second] << "\" (avrg=" | |
| 67 | ✗ | << stationEntry.first << "):"; | |
| 68 | ✗ | for( const auto & layerID : detIDsByStationKeys.find(stationEntry.second)->second.layerIDs ) { | |
| 69 | ✗ | r.emplace(layerID, n); | |
| 70 | ✗ | oss << "\"" << naming()[layerID] << "\" "; | |
| 71 | } | ||
| 72 | ✗ | r.emplace(stationEntry.second, n); // add station id itself too | |
| 73 | ✗ | ++n; | |
| 74 | } | ||
| 75 | ✗ | _log << log4cpp::Priority::DEBUG << "Station order recached: " << oss.str(); | |
| 76 | ✗ | nSortedGroups = skByVal.size(); | |
| 77 | ✗ | return r; | |
| 78 | } | ||
| 79 | |||
| 80 | ✗ | float OrderedStations::z_center(DetID, const Placement & pl) { | |
| 81 | ✗ | return pl.center[2]; | |
| 82 | } | ||
| 83 | |||
| 84 | } // namespace ::na64dp::calib | ||
| 85 | } // namespace na64dp | ||
| 86 | |||
| 87 |