ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimTrackMonitor.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
9
11#include "TH1D.h"
12#include "TH2D.h"
13#include "TTree.h"
14#include <bit>
16
17
19FPGATrackSimTrackMonitor::FPGATrackSimTrackMonitor(const std::string& algname, const std::string &name, const IInterface *ifc) :
20 AthAlgTool(algname, name, ifc)
21{
23 ATH_MSG_INFO("constructor");
24}
25
28{
29 // print all configured properties (debugging)
30 auto props = this->getProperties();
31 for( Gaudi::Details::PropertyBase* prop : props ) {
32 if (prop->ownerTypeName()==this->type()) {
33 ATH_MSG_DEBUG("Property:\t" << prop->name() << "\t : \t" << prop->toString());
34 }
35 }
36 ATH_MSG_INFO("Initialize Track Monitoring");
37
39 ATH_CHECK(m_tHistSvc.retrieve());
40
41 return StatusCode::SUCCESS;
42
43}
44
45
46
48
49
51void FPGATrackSimTrackMonitor::fillRoad(const std::vector<FPGATrackSimRoad>& roads,
52 const std::vector<FPGATrackSimTruthTrack>& truthTracks,
53 size_t nLogicalLayers)
54{
55 // overall number of roads
56 auto nRoads = Monitored::Scalar<int>("nRoads", roads.size());
57 // push them into the monitoring tool (this->MonTool set in python)
59
60 // update counter of total roads
61 m_totNElements += roads.size();
62
63 // loop over all roads in the event
64 for (const auto& road : roads) {
65 // layerIDs
66 unsigned bitmask = road.getHitLayers();
67 for (size_t l = 0; l < nLogicalLayers; l++) {
68 if (bitmask & (1 << l)) {
69 auto mon_layerIDs = Monitored::Scalar<unsigned>("layerIDs",l);
70 Monitored::Group(m_monTool, mon_layerIDs);
71 }
72 }
73 // number of layers represented in this road
74 auto mon_nLayers = Monitored::Scalar<int>("nLayers", road.getNLayers());
75 // number of hits
76 auto mon_nHits = Monitored::Scalar<int>("nHits", road.getNHits());
77 // push all of the above scalars into the monitoring tool
78 Monitored::Group(m_monTool, mon_nLayers, mon_nHits);
79 // roads with 4 hits
80 if (road.getNHits() == 4) {
81 // fit chi2 in this road
82 auto mon_fitChi2_4 = Monitored::Scalar<float>("chi2_4", road.getFitChi2());
83 // fit chi2Eta
84 auto mon_fitChi2Eta_4 = Monitored::Scalar<float>("chi2Eta_4", road.getFitChi2Eta());
85 // fit chi2Phi
86 auto mon_fitChi2Phi_4 = Monitored::Scalar<float>("chi2Phi_4", road.getFitChi2Phi());
87 // push all of the above scalars into the monitoring tool
88 Monitored::Group(m_monTool, mon_fitChi2_4, mon_fitChi2Eta_4, mon_fitChi2Phi_4);
89 } else if (road.getNHits() == 5) {
90 auto mon_fitChi2_5 = Monitored::Scalar<float>("chi2_5", road.getFitChi2());
91 auto mon_fitChi2Eta_5 = Monitored::Scalar<float>("chi2Eta_5", road.getFitChi2Eta());
92 auto mon_fitChi2Phi_5 = Monitored::Scalar<float>("chi2Phi_5", road.getFitChi2Phi());
93 Monitored::Group(m_monTool, mon_fitChi2_5, mon_fitChi2Eta_5, mon_fitChi2Phi_5);
94 }
95 }
96
97 // only monitor efficiency for events with truth tracks
98 if (truthTracks.size() > 0) {
99 // update road counter
100 if (roads.size() > 0) ++m_nElements;
101 // update the max number of elements
102 if (roads.size() > m_maxNElements) m_maxNElements=roads.size();
103 // use the first truth track (the primary one)
104 const auto& truthTrack = truthTracks.front();
105 // efficiency monitor
106 auto mon_eff = Monitored::Scalar<bool>("eff_road", (roads.size() > 0));
107 auto mon_truth_pt_zoom = Monitored::Scalar<float>("pT_zoom", truthTrack.getPt()*0.001);
108 auto mon_truth_pt = Monitored::Scalar<float>("pT", truthTrack.getPt()*0.001);
109 auto mon_truth_eta = Monitored::Scalar<float>("eta", truthTrack.getEta());
110 auto mon_truth_phi = Monitored::Scalar<float>("phi", truthTrack.getPhi());
111 auto mon_truth_d0 = Monitored::Scalar<float>("d0", truthTrack.getD0());
112 auto mon_truth_z0 = Monitored::Scalar<float>("z0", truthTrack.getZ0());
113 Monitored::Group( m_monTool, mon_eff, mon_truth_pt_zoom, mon_truth_pt, mon_truth_eta, mon_truth_phi, mon_truth_d0, mon_truth_z0 );
114 }
115}
116
117
119void FPGATrackSimTrackMonitor::fillTrack(const std::vector<const FPGATrackSimTrack*>& tracks,
120 const std::vector<FPGATrackSimTruthTrack>& truthTracks,
121 float chi2Cut)
122{
123 // monitor chi2 for all tracks and find the best
124 float bestChi2 = chi2Cut;
125 float chi2_best = chi2Cut;
126 float chi2Eta_best = chi2Cut;
127 float chi2Phi_best = chi2Cut;
128 float chi2_best_4 = chi2Cut;
129 float chi2Eta_best_4 = chi2Cut;
130 float chi2Phi_best_4 = chi2Cut;
131 float chi2_best_5 = chi2Cut;
132 float chi2Eta_best_5 = chi2Cut;
133 float chi2Phi_best_5 = chi2Cut;
134
135 // lambda function to monitor chi2 (all) and keep track of the best one
136 auto monitorChi2 = [&](const std::string& chi2_name, float chi2_value, float& best_value, const std::string& suffix="") {
137 if (chi2_value < chi2Cut) {
138 // monitor all chi2
139 auto mon = Monitored::Scalar<float>(chi2_name + suffix, chi2_value);
141 // update best chi2
142 if (chi2_value < best_value) best_value = chi2_value;
143 }
144 };
145
146
147 // overall number of tracks
148 auto mon_nTracks = Monitored::Scalar<int>("nTracks", tracks.size());
149 // push them into the monitoring tool (this->MonTool set in python)
150 Monitored::Group(m_monTool, mon_nTracks);
151
152 // update counter of total tracks
153 m_totNElements += tracks.size();
154
155 // loop over all tracks in the event
156 for (const auto& track : tracks) {
157 // number of real hits
158 int nValidHits = 0;
159 for (const auto& hit : track->getFPGATrackSimHits()) {
160 if (hit.isReal()) {
161 ++nValidHits;
162 }
163 }
164 auto mon_nHits = Monitored::Scalar<int>("nHits", nValidHits);
165 Monitored::Group(m_monTool, mon_nHits);
166
167 // monitor chi2 for tracks
168 float chi2_all = track->getChi2ndof();
169 if (chi2_all < chi2Cut) {
170 auto mon_chi2_all = Monitored::Scalar<float>("chi2_all", chi2_all);
171 Monitored::Group(m_monTool, mon_chi2_all);
172 // update best chi2
173 if (chi2_all < bestChi2) {
174 bestChi2 = chi2_all;
175 }
176 }
177
178 // monitor base chi2 values
179 monitorChi2("chi2", track->getChi2(), chi2_best);
180 monitorChi2("chi2Eta", track->getChi2Eta(), chi2Eta_best);
181 monitorChi2("chi2Phi", track->getChi2Phi(), chi2Phi_best);
182
183 // monitor nHits-dependent chi2 values
184 if (nValidHits == 4) {
185 monitorChi2("chi2", track->getChi2(), chi2_best_4, "_4");
186 monitorChi2("chi2Eta", track->getChi2Eta(), chi2Eta_best_4, "_4");
187 monitorChi2("chi2Phi", track->getChi2Phi(), chi2Phi_best_4, "_4");
188 } else if (nValidHits == 5) {
189 monitorChi2("chi2", track->getChi2(), chi2_best_5, "_5");
190 monitorChi2("chi2Eta", track->getChi2Eta(), chi2Eta_best_5, "_5");
191 monitorChi2("chi2Phi", track->getChi2Phi(), chi2Phi_best_5, "_5");
192 }
193 }
194 // monitor the best chi2 found
195 if (bestChi2 < chi2Cut) {
196 auto mon_best_chi2 = Monitored::Scalar<float>("best_chi2", bestChi2);
197 Monitored::Group(m_monTool, mon_best_chi2);
198 }
199
200 // lambda function to monitor the best chi2 value
201 auto monitorBestChi2 = [&](const std::string& best_name, float best_value) {
202 if (best_value < chi2Cut) {
203 auto mon_best = Monitored::Scalar<float>(best_name, best_value);
204 Monitored::Group(m_monTool, mon_best);
205 }
206 };
207
208 // best chi2 values
209 monitorBestChi2("chi2_best", chi2_best);
210 monitorBestChi2("chi2Eta_best", chi2Eta_best);
211 monitorBestChi2("chi2Phi_best", chi2Phi_best);
212 monitorBestChi2("chi2_best_4", chi2_best_4);
213 monitorBestChi2("chi2Eta_best_4", chi2Eta_best_4);
214 monitorBestChi2("chi2Phi_best_4", chi2Phi_best_4);
215 monitorBestChi2("chi2_best_5", chi2_best_5);
216 monitorBestChi2("chi2Eta_best_5", chi2Eta_best_5);
217 monitorBestChi2("chi2Phi_best_5", chi2Phi_best_5);
218
219
220 // only monitor efficiency for events with truth tracks
221 if (truthTracks.size() > 0) {
222 // update track counter
223 if (tracks.size() > 0) ++m_nElements;
224 // update the max number of elements
225 if (tracks.size() > m_maxNElements) m_maxNElements=tracks.size();
226 // use the first truth track (the primary one)
227 const auto& truthTrack = truthTracks.front();
228 // efficiency monitor
229 auto mon_eff = Monitored::Scalar<bool>("eff_track", (tracks.size() > 0));
230 auto mon_truth_pt_zoom = Monitored::Scalar<float>("pT_zoom", truthTrack.getPt()*0.001);
231 auto mon_truth_pt = Monitored::Scalar<float>("pT", truthTrack.getPt()*0.001f);
232 auto mon_truth_eta = Monitored::Scalar<float>("eta", truthTrack.getEta());
233 auto mon_truth_phi = Monitored::Scalar<float>("phi", truthTrack.getPhi());
234 auto mon_truth_d0 = Monitored::Scalar<float>("d0", truthTrack.getD0());
235 auto mon_truth_z0 = Monitored::Scalar<float>("z0", truthTrack.getZ0());
236 Monitored::Group( m_monTool, mon_eff, mon_truth_pt_zoom, mon_truth_pt, mon_truth_eta, mon_truth_phi, mon_truth_d0, mon_truth_z0 );
237 }
238}
239
240
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This is the monitoring for the FPGATrackSimTrackMonitor.
Header file to be included by clients of the Monitored infrastructure.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
FPGATrackSimTrackMonitor(const std::string &, const std::string &, const IInterface *)
void fillTrack(const std::vector< const FPGATrackSimTrack * > &tracks, const std::vector< FPGATrackSimTruthTrack > &truthTracks, float chi2Cut)
virtual StatusCode initialize() override
ToolHandle< GenericMonitoringTool > m_monTool
void fillRoad(const std::vector< FPGATrackSimRoad > &roads, const std::vector< FPGATrackSimTruthTrack > &truthTracks, size_t nLogicalLayers)
ServiceHandle< ITHistSvc > m_tHistSvc
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.