12 #include <boost/functional/hash.hpp>
15 #include <unordered_map>
29 declareInterface<Trk::ITrkAlignmentDeviationTool>(
this);
33 ATH_MSG_INFO(
"*****************************************");
40 return StatusCode::SUCCESS;
44 ATH_MSG_DEBUG(
"AlignmentErrorTool::makeAlignmentDeviations()");
52 const auto& deviationVec = readCdo->getAlignmentErrorRules();
53 std::vector<deviationSummary_t> devSumVec;
54 devSumVec.reserve(deviationVec.size());
56 for (
const auto &
i : deviationVec) {
61 devSumVec.emplace_back(std::move(aDevSumm));
64 const auto& MuonAlignmentErrorRuleCacheVec = readCdo->getMuonAlignmentErrorRuleCache();
65 const auto& map_struct = MuonAlignmentErrorRuleCacheVec[0];
68 const tsosc_t* tsosc =
track.trackStateOnSurfaces();
71 unsigned int nPrecisionHits = 0;
72 for (
const auto *tsos : *tsosc) {
82 unsigned int index = crot->indexOfMaxAssignProb();
83 rot = &(crot->rioOnTrack(
index));
105 if (!readCdo->hasNswHits()
111 if (!calibId.
isValid())
continue;
113 ATH_MSG_DEBUG(
"Hit is in station " << calibId <<
" (MuonFixedLongId)");
122 Amg::Vector3D hitU = tsos->trackParameters()->momentum().unit();
130 if (hitP.cross(zATLAS).dot(hitV)<0.0) {
135 bool is_matched =
false;
141 }
else if (calibId.
is_mmg()) {
143 }
else if (calibId.
is_stg()) {
168 auto range = map_struct.id_rule_map.equal_range(key_id);
173 devSumVec[rule_idx].hits.push_back(rot);
175 devSumVec[rule_idx].sumW2 += w2;
176 devSumVec[rule_idx].sumP += w2 * hitP;
177 devSumVec[rule_idx].sumU += w2 * hitU;
178 devSumVec[rule_idx].sumV += w2 * hitV;
187 ATH_MSG_WARNING(
"The hits in the station " << calibId <<
" (MuonFixedLongId)"
188 <<
" couldn't be matched to any deviation regexp in the list.");
196 for (
auto& dev : devSumVec) {
197 if (dev.hits.size() == nPrecisionHits) {
203 std::vector<const Trk::RIO_OnTrack*> v1,
v2;
204 for (
auto iti = devSumVec.begin(); iti != devSumVec.end(); ++iti) {
211 std::stable_sort(v1.begin(), v1.end());
213 for (
auto itj = iti+1; itj != devSumVec.end(); ++itj) {
215 if (iti->hits.size() != itj->hits.size()) {
220 std::stable_sort(
v2.begin(),
v2.end());
225 ATH_MSG_DEBUG(
"Found deviations " << iDev <<
" and " << jDev <<
" related to the same list of hits. Merging...");
226 ATH_MSG_DEBUG(
"old (translation, rotation) systematic uncertainties for "
227 << iDev <<
": " << iti->translation <<
", " << iti->rotation);
228 ATH_MSG_DEBUG(
"old (translation, rotation) systematic uncertainties for "
229 << jDev <<
": " << itj->translation <<
", " << itj->rotation);
232 double new_translation = std::hypot(iti->translation, itj->translation);
233 double new_rotation = std::hypot(iti->rotation, itj->rotation);
239 iti->translation = new_translation;
240 iti->rotation = new_rotation;
241 ATH_MSG_DEBUG(
"New combined (translation, rotation) systematic uncertainties: " << new_translation <<
", " << new_rotation);
252 for (
const auto & iDev : devSumVec) {
253 if (iDev.hits.empty()) {
258 double translation = iDev.translation;
263 double sumW2 = iDev.sumW2;
265 sumP *= (1. / sumW2);
266 sumU *= (1. / sumW2);
267 sumV *= (1. / sumW2);
270 std::size_t hitshash = 0;
271 for (
const auto *
it : iDev.hits) {
272 boost::hash_combine(hitshash, (
it->identify()).get_compact());
274 deviations.push_back(
276 deviations.back()->setHashOfHits(hitshash);
279 << sumU.x() <<
", " << sumU.y() <<
", " << sumU.z() <<
") with sigma=" << translation *
Gaudi::Units::mm
280 <<
" mm was applied to " << iDev.hits.size()
281 <<
" hits matching the station: " << iDev.stationName.str() <<
" and the multilayer "
282 << iDev.multilayer.str());
285 std::size_t hitshash = 0;
286 for (
const auto *
it : iDev.hits) {
287 boost::hash_combine(hitshash, (
it->identify()).get_compact());
290 deviations.back()->setHashOfHits(hitshash);
292 ATH_MSG_DEBUG(
"A rotation around the center = (" << sumP.x() <<
", " << sumP.y() <<
", " << sumP.z() <<
") and axis = ("
293 << sumV.x() <<
", " << sumV.y() <<
", " << sumV.z()
295 << iDev.hits.size() <<
" hits matching the station "
296 << iDev.stationName.str() <<
" and the multilayer "
297 << iDev.multilayer.str());
304 ATH_MSG_DEBUG(
"Found " << deviations.size() <<
" nuisances after duplicates merging");