12 #include <boost/functional/hash.hpp>
28 declareInterface<Trk::ITrkAlignmentDeviationTool>(
this);
32 ATH_MSG_INFO(
"*****************************************");
39 return StatusCode::SUCCESS;
43 ATH_MSG_DEBUG(
"AlignmentErrorTool::makeAlignmentDeviations()");
51 const auto& deviationVec = readCdo->getDeviations();
52 std::vector<deviationSummary_t> devSumVec;
53 devSumVec.reserve(deviationVec.size());
55 for (
const auto &
i : deviationVec) {
60 devSumVec.emplace_back(std::move(aDevSumm));
64 const tsosc_t* tsosc =
track.trackStateOnSurfaces();
67 unsigned int nPrecisionHits = 0;
68 for (
const auto *tsos : *tsosc) {
78 unsigned int index = crot->indexOfMaxAssignProb();
79 rot = &(crot->rioOnTrack(
index));
101 if (!readCdo->hasNswHits()
107 if (!calibId.
isValid())
continue;
114 }
else if (calibId.
is_mmg()) {
116 }
else if (calibId.
is_stg()) {
121 ATH_MSG_DEBUG(
"Hit is in station " << alignStationName <<
" multilayer " << multilayerName);
130 Amg::Vector3D hitU = tsos->trackParameters()->momentum().unit();
138 if (hitP.cross(zATLAS).dot(hitV)<0.0) {
143 bool is_matched =
false;
146 for (
auto & iDev : devSumVec) {
148 if (!boost::regex_match(alignStationName, iDev.stationName)) {
151 if (!boost::regex_match(multilayerName, iDev.multilayer)) {
156 iDev.hits.push_back(rot);
159 iDev.sumP += w2 * hitP;
160 iDev.sumU += w2 * hitU;
161 iDev.sumV += w2 * hitV;
170 ATH_MSG_WARNING(
"The hits in the station " << alignStationName <<
", multilayer " << multilayerName
171 <<
" couldn't be matched to any deviation regexp in the list.");
179 for (
auto& dev : devSumVec) {
180 if (dev.hits.size() == nPrecisionHits) {
186 std::vector<const Trk::RIO_OnTrack*> v1,
v2;
187 for (
auto iti = devSumVec.begin(); iti != devSumVec.end(); ++iti) {
194 std::stable_sort(v1.begin(), v1.end());
196 for (
auto itj = iti+1; itj != devSumVec.end(); ++itj) {
198 if (iti->hits.size() != itj->hits.size()) {
203 std::stable_sort(
v2.begin(),
v2.end());
208 ATH_MSG_DEBUG(
"Found deviations " << iDev <<
" and " << jDev <<
" related to the same list of hits. Merging...");
209 ATH_MSG_DEBUG(
"old (translation, rotation) systematic uncertainties for "
210 << iDev <<
": " << iti->translation <<
", " << iti->rotation);
211 ATH_MSG_DEBUG(
"old (translation, rotation) systematic uncertainties for "
212 << jDev <<
": " << itj->translation <<
", " << itj->rotation);
215 double new_translation = std::hypot(iti->translation, itj->translation);
216 double new_rotation = std::hypot(iti->rotation, itj->rotation);
222 iti->translation = new_translation;
223 iti->rotation = new_rotation;
224 ATH_MSG_DEBUG(
"New combined (translation, rotation) systematic uncertainties: " << new_translation <<
", " << new_rotation);
235 for (
const auto & iDev : devSumVec) {
236 if (iDev.hits.empty()) {
241 double translation = iDev.translation;
246 double sumW2 = iDev.sumW2;
248 sumP *= (1. / sumW2);
249 sumU *= (1. / sumW2);
250 sumV *= (1. / sumW2);
253 std::size_t hitshash = 0;
254 for (
const auto *
it : iDev.hits) {
255 boost::hash_combine(hitshash, (
it->identify()).get_compact());
257 deviations.push_back(
259 deviations.back()->setHashOfHits(hitshash);
262 << sumU.x() <<
", " << sumU.y() <<
", " << sumU.z() <<
") with sigma=" << translation *
Gaudi::Units::mm
263 <<
" mm was applied to " << iDev.hits.size()
264 <<
" hits matching the station: " << iDev.stationName.str() <<
" and the multilayer "
265 << iDev.multilayer.str());
268 std::size_t hitshash = 0;
269 for (
const auto *
it : iDev.hits) {
270 boost::hash_combine(hitshash, (
it->identify()).get_compact());
273 deviations.back()->setHashOfHits(hitshash);
275 ATH_MSG_DEBUG(
"A rotation around the center = (" << sumP.x() <<
", " << sumP.y() <<
", " << sumP.z() <<
") and axis = ("
276 << sumV.x() <<
", " << sumV.y() <<
", " << sumV.z()
278 << iDev.hits.size() <<
" hits matching the station "
279 << iDev.stationName.str() <<
" and the multilayer "
280 << iDev.multilayer.str());
287 ATH_MSG_DEBUG(
"Found " << deviations.size() <<
" nuisances after duplicates merging");
299 if (
sector(calibId)==13) {
307 ret.push_back(
static_cast<char>(
'0'+std::abs(
hardwareEta(calibId))));
314 return calibId.
eta()>0 ?
"A" : calibId.
eta()<0 ?
"C" :
"B";
318 int sec =
sector(calibId);
319 if (sec<0 || sec > 99) {
320 throw std::runtime_error(
"Unhandled sector number");
322 std::string
ret =
"00";
331 return calibId.
phi();
347 case StationName::EES:
348 case StationName::EMS:
349 case StationName::EOS:
350 case StationName::EIS:
352 case StationName::BMG:
353 case StationName::MMS:
354 case StationName::STS:
366 if (
sector(calibId)==13) {
367 switch (calibId.
eta()) {
376 return calibId.
eta();
380 if (
sector(calibId)==13) {
381 if (calibId.
eta()== 7)
return 1;
382 if (calibId.
eta()==-7)
return -1;
384 return calibId.
eta();
387 return calibId.
eta()>0 ? calibId.
eta()*2-1 : calibId.
eta()*2+1;
389 return calibId.
eta()*2;
390 case StationName::EIL:
393 switch (calibId.
eta()) {
400 return calibId.
eta();
402 case StationName::EEL:
404 if ((
sector(calibId) == 5) && (calibId.
eta() == 1))
return 2;
405 if ((
sector(calibId) == 5) && (calibId.
eta() == -1))
return -2;
406 return calibId.
eta();
408 default:
return calibId.
eta();