ATLAS Offline Software
Loading...
Searching...
No Matches
AlignmentErrorTestAlg.cxx
Go to the documentation of this file.
2
3#include <format>
4
11
12namespace MuonAlign {
13
15 ISvcLocator* pSvcLocator)
16 : AthAlgorithm(name, pSvcLocator) {}
17
20 ATH_CHECK(m_idTool.retrieve());
21 ATH_CHECK(m_trackCollection.initialize());
22 ATH_CHECK(m_eventInfoKey.initialize());
23 return StatusCode::SUCCESS;
24}
25
27 const EventContext& ctx = getContext();
29 if (!trackCollection.isValid()) {
30 throw std::runtime_error("Cannot retrieve track collection");
31 }
32
34 if (eventInfo.isValid()) {
35 ATH_MSG_INFO("Reading event " << eventInfo->eventNumber()
36 << " from run " << eventInfo->runNumber()
37 << " with timestamp " << eventInfo->timeStamp());
38 }
39
40 ATH_MSG_INFO("Retrieved track collection with " << trackCollection->size()
41 << " entries");
42
43 auto getListOfHits = [](const Trk::Track* track) -> std::vector<const Trk::RIO_OnTrack*> {
44 std::vector<const Trk::RIO_OnTrack*> ret;
45 for (const auto *tsos : *(track->trackStateOnSurfaces())) {
47 continue;
48 }
49 const Trk::MeasurementBase* meas = tsos->measurementOnTrack();
50 const auto* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas);
51 if (!rot) {
52 const auto* crot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(meas);
53 if (crot) {
54 unsigned int index = crot->indexOfMaxAssignProb();
55 rot = &(crot->rioOnTrack(index));
56 }
57 }
58 if (!rot) continue;
59 ret.emplace_back(rot);
60 }
61 return ret;
62 };
63
64 auto makeChamberString = [&](const std::vector<const Trk::RIO_OnTrack*>& hits) -> std::string {
65 std::set<std::string> chambers;
66 for (const auto* rot : hits) {
68 m_idTool->idToFixedLongId(rot->identify());
69 if (calibId.isValid()) {
70 chambers.emplace(calibId.stationNameString());
71 }
72 }
73 std::string chambers_str;
74 bool first = true;
75 for (const auto& str : chambers) {
76 if (!first) {
77 chambers_str.append(",");
78 }
79 chambers_str.append(str);
80 first = false;
81 }
82 return chambers_str;
83 };
84
85 int itrack = 0;
86 for (const Trk::Track* track : *trackCollection) {
87 ATH_MSG_INFO("Track " << itrack++);
88 ATH_MSG_INFO("Collected chambers: " << makeChamberString(getListOfHits(track)));
89 std::vector<Trk::AlignmentDeviation*> deviations;
90 m_alignmentErrorTool->makeAlignmentDeviations(*track, deviations);
91 for (const Trk::AlignmentDeviation* np : deviations) {
92 const auto& hits = np->getListOfHits();
93 if (const auto* tdev =
94 dynamic_cast<const MuonAlign::AlignmentTranslationDeviation*>(np)) {
95 Amg::Vector3D u = tdev->getU();
96 double sigma = tdev->getSigma();
98 std::format("TranslationNP U = {:14.6f} {:14.6f} {:14.6f}"
99 " sigma = {:8.6f} chambers = {}",
100 u.x(), u.y(), u.z(), sigma, makeChamberString(hits)));
101 } else if (const auto* rdev =
102 dynamic_cast<const MuonAlign::AlignmentRotationDeviation*>(np)) {
103 Amg::Vector3D c = rdev->getCenter();
104 Amg::Vector3D a = rdev->getAxis();
105 double sigma = rdev->getSigma();
106 ATH_MSG_INFO(std::format(
107 "RotationNP C = {:14.6f} {:14.6f} {:14.6f} "
108 "A = {:14.6f} {:14.6f} {:14.6f} sigma = {:11.9f} chambers = {}",
109 c.x(), c.y(), c.z(), a.x(), a.y(), a.z(), sigma, makeChamberString(hits)));
110 } else {
111 throw std::runtime_error("Deviation type is not implemented");
112 }
113 }
114 }
115
116 return StatusCode::SUCCESS;
117}
118
119} // namespace MuonAlign
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
static Double_t a
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
ToolHandle< Trk::ITrkAlignmentDeviationTool > m_alignmentErrorTool
SG::ReadHandleKey<::TrackCollection > m_trackCollection
ToolHandle< MuonCalib::IIdToFixedIdTool > m_idTool
AlignmentErrorTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
std::string_view stationNameString() const
bool isValid() const
check validity of the identifier.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
An object decorating a track and holding degrees of freedom reflecting alignment accuracy.
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
This class is the pure abstract base class for all fittable tracking measurements.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Eigen::Matrix< double, 3, 1 > Vector3D
Definition index.py:1