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
26StatusCode AlignmentErrorTestAlg::execute(const EventContext& ctx) {
28 if (!trackCollection.isValid()) {
29 throw std::runtime_error("Cannot retrieve track collection");
30 }
31
33 if (eventInfo.isValid()) {
34 ATH_MSG_INFO("Reading event " << eventInfo->eventNumber()
35 << " from run " << eventInfo->runNumber()
36 << " with timestamp " << eventInfo->timeStamp());
37 }
38
39 ATH_MSG_INFO("Retrieved track collection with " << trackCollection->size()
40 << " entries");
41
42 auto getListOfHits = [](const Trk::Track* track) -> std::vector<const Trk::RIO_OnTrack*> {
43 std::vector<const Trk::RIO_OnTrack*> ret;
44 for (const auto *tsos : *(track->trackStateOnSurfaces())) {
46 continue;
47 }
48 const Trk::MeasurementBase* meas = tsos->measurementOnTrack();
49 const auto* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas);
50 if (!rot) {
51 const auto* crot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(meas);
52 if (crot) {
53 unsigned int index = crot->indexOfMaxAssignProb();
54 rot = &(crot->rioOnTrack(index));
55 }
56 }
57 if (!rot) continue;
58 ret.emplace_back(rot);
59 }
60 return ret;
61 };
62
63 auto makeChamberString = [&](const std::vector<const Trk::RIO_OnTrack*>& hits) -> std::string {
64 std::set<std::string> chambers;
65 for (const auto* rot : hits) {
67 m_idTool->idToFixedLongId(rot->identify());
68 if (calibId.isValid()) {
69 chambers.emplace(calibId.stationNameString());
70 }
71 }
72 std::string chambers_str;
73 bool first = true;
74 for (const auto& str : chambers) {
75 if (!first) {
76 chambers_str.append(",");
77 }
78 chambers_str.append(str);
79 first = false;
80 }
81 return chambers_str;
82 };
83
84 int itrack = 0;
85 for (const Trk::Track* track : *trackCollection) {
86 ATH_MSG_INFO("Track " << itrack++);
87 ATH_MSG_INFO("Collected chambers: " << makeChamberString(getListOfHits(track)));
88 std::vector<Trk::AlignmentDeviation*> deviations;
89 m_alignmentErrorTool->makeAlignmentDeviations(*track, deviations);
90 for (const Trk::AlignmentDeviation* np : deviations) {
91 const auto& hits = np->getListOfHits();
92 if (const auto* tdev =
93 dynamic_cast<const MuonAlign::AlignmentTranslationDeviation*>(np)) {
94 Amg::Vector3D u = tdev->getU();
95 double sigma = tdev->getSigma();
97 std::format("TranslationNP U = {:14.6f} {:14.6f} {:14.6f}"
98 " sigma = {:8.6f} chambers = {}",
99 u.x(), u.y(), u.z(), sigma, makeChamberString(hits)));
100 } else if (const auto* rdev =
101 dynamic_cast<const MuonAlign::AlignmentRotationDeviation*>(np)) {
102 Amg::Vector3D c = rdev->getCenter();
103 Amg::Vector3D a = rdev->getAxis();
104 double sigma = rdev->getSigma();
105 ATH_MSG_INFO(std::format(
106 "RotationNP C = {:14.6f} {:14.6f} {:14.6f} "
107 "A = {:14.6f} {:14.6f} {:14.6f} sigma = {:11.9f} chambers = {}",
108 c.x(), c.y(), c.z(), a.x(), a.y(), a.z(), sigma, makeChamberString(hits)));
109 } else {
110 throw std::runtime_error("Deviation type is not implemented");
111 }
112 }
113 }
114
115 return StatusCode::SUCCESS;
116}
117
118} // 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
StatusCode execute(const EventContext &ctx) override
Execute method.
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