44 ATH_MSG_DEBUG(
"AlignmentErrorTool::makeAlignmentDeviations()");
53 std::vector<deviationSummary_t> devSumVec;
54 devSumVec.reserve(deviationVec.size());
56 for (
const auto & i : deviationVec) {
61 devSumVec.emplace_back(std::move(aDevSumm));
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));
91 ATH_MSG_VERBOSE(
"Given Identifier " << channelId.get_compact() <<
" is not a muon Identifier, continuing");
111 if (!calibId.
isValid())
continue;
113 ATH_MSG_DEBUG(
"Hit is in station " << calibId <<
" (MuonFixedLongId)");
122 Amg::Vector3D hitU = tsos->trackParameters()->momentum().unit();
125 int icol = (calibId.
is_mdt()||calibId.
is_csc()) ? 2 : 1;
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()) {
149 key_id =
m_idHelperSvc->mdtIdHelper().channelID(channelId, multilayer, 1, 1);
155 key_id =
m_idHelperSvc->mmIdHelper().channelID(channelId, multilayer, 1, 1);
158 key_id =
m_idHelperSvc->stgcIdHelper().channelID(channelId, multilayer, 1, 0, 1);
168 auto range = map_struct.id_rule_map.equal_range(key_id);
169 for (
auto i = range.first; i != range.second; ++i){
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) {
213 for (
auto itj = iti+1; itj != devSumVec.end(); ++itj) {
215 if (iti->hits.size() != itj->hits.size()) {
223 auto iDev = std::distance(devSumVec.begin(), iti);
224 auto jDev = std::distance(devSumVec.begin(), itj);
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()) {
257 double rotation = iDev.rotation;
258 double translation = iDev.translation;
263 double sumW2 = iDev.sumW2;
265 sumP *= (1. / sumW2);
266 sumU *= (1. / sumW2);
267 sumV *= (1. / sumW2);
269 if (translation >= 0.001 * Gaudi::Units::mm) {
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());
284 if (rotation >= 0.000001 * Gaudi::Units::rad) {
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()
294 <<
") with sigma=" << rotation / Gaudi::Units::mrad <<
" mrad was applied to "
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");