ATLAS Offline Software
Loading...
Searching...
No Matches
HGTD_TrkTimePerformanceStudies.cxx
Go to the documentation of this file.
1
8
11
13 const std::string& name, ISvcLocator* svc_locator)
14 : HGTD_AnalysisAlgBase(name, svc_locator) {}
15
17
20
21 ATH_MSG_INFO("Initializing HGTD_TrkTimePerformanceStudies ...");
22
23 ATH_CHECK(m_track_sel_tools.retrieve());
24 ATH_CHECK(m_track_time_tools.retrieve());
25
26 for (const auto& track_tool : m_track_sel_tools) {
27 for (const auto& time_tool : m_track_time_tools) {
28
29 bookEffSubdir(track_tool->name(), time_tool->name(), "m_eff_vs_eta",
30 ";|#eta| ;frequency", 32, 2.4, 4.0);
31 bookEffSubdir(track_tool->name(), time_tool->name(),
32 "m_eff_gt50pcprimes_vs_eta", ";|#eta| ;frequency", 32, 2.4,
33 4.0);
34 bookEffSubdir(track_tool->name(), time_tool->name(),
35 "m_eff_gt50pcprimes_vs_eta_mistag", ";|#eta| ;frequency",
36 32, 2.4, 4.0);
37
38 for (const auto& primes_fraction_i : m_primes_fractions) {
39 std::string name = "m_eff_vs_eta_primesfrac" + primes_fraction_i;
40 bookEffSubdir(track_tool->name(), time_tool->name(), name,
41 ";|#eta| ;frequency", 32, 2.4, 4.0);
42
43 std::string name_res =
44 "m_hist_timeres_outlier_cases" + primes_fraction_i;
45 bookSubdir<TH1F>(track_tool->name(), time_tool->name(), name_res,
46 ";t_{reco} - t_{truth} [ns]; number of tracks", 200,
47 -.4, 0.4);
48 }
49 }
50 }
51
52 ATH_CHECK(m_track_particles_key.initialize());
55
56 return StatusCode::SUCCESS;
57}
58
59StatusCode HGTD_TrkTimePerformanceStudies::execute(const EventContext& ctx) {
60
63 const xAOD::TrackParticleContainer* track_particles =
64 track_particles_hdl.cptr();
65
66 for (const auto* track : *track_particles) {
67 for (const auto& track_tool : m_track_sel_tools) {
68 for (const auto& time_tool : m_track_time_tools) {
69
70 const float trk_eta = track->eta();
71
72 if (!track_tool->trackPassesSelection(track)) {
73 continue;
74 }
75
76 const xAOD::TruthParticle* truth_particle =
78
79 auto purity = time_tool->fracPrimaryHits(*track);
80 int n_potential_primes = time_tool->numberPotentialPrimaryHits(*track);
81 bool has_time = time_tool->expertHasTime(*track);
82
84 if (purity < 0.01) {
85 switch (n_potential_primes) {
86 case 0:
88 break;
89 case 1:
91 break;
92 case 2:
94 break;
95 case 3:
97 break;
98 case 4:
100 break;
101 }
102 } else if (purity > 0.01 and purity < 0.48) {
103 primes_fraction = PrimesFractions::LessThanHalfPrimes;
104 } else if (purity > 0.48 and purity < 0.52) {
105 primes_fraction = PrimesFractions::HalfPrimesHasPrimes;
106 } else if (purity > 0.52 and purity < 0.98) {
107 primes_fraction = PrimesFractions::MoreThanHalfPrimes;
108 } else if (purity > 0.98) {
109 primes_fraction = PrimesFractions::AllPrimes;
110 }
111
112 bool morethanhalfprimes =
113 primes_fraction == PrimesFractions::AllPrimes or
114 primes_fraction == PrimesFractions::MoreThanHalfPrimes;
115
116 fillEffSubDir(track_tool->name(), time_tool->name(), "m_eff_vs_eta",
117 has_time, std::abs(trk_eta));
118
119 bool count_primesfrac_category_as_good = false;
120 for (size_t i = 0; i < m_primes_fractions.size(); i++) {
121 if (i == static_cast<size_t>(primes_fraction)) {
122 count_primesfrac_category_as_good = has_time;
123 } else {
124 count_primesfrac_category_as_good = false;
125 }
126 fillEffSubDir(track_tool->name(), time_tool->name(),
127 "m_eff_vs_eta_primesfrac" + m_primes_fractions.at(i),
128 count_primesfrac_category_as_good, std::abs(trk_eta));
129 }
130
131 if (has_time) {
132 auto truth_vertex = getTruthVertex(truth_particle);
133 if (truth_particle and truth_vertex) {
134 float track_time = time_tool->expertTime(*track);
135 float truth_time = time_tool->getTruthTime(*truth_vertex);
136 float time_res = track_time - truth_time;
137 fillSubdir<TH1F>(track_tool->name(), time_tool->name(),
138 "m_hist_timeres_outlier_cases" +
139 m_primes_fractions.at(primes_fraction),
140 time_res);
141 }
142 fillEffSubDir(track_tool->name(), time_tool->name(),
143 "m_eff_gt50pcprimes_vs_eta", morethanhalfprimes,
144 std::abs(trk_eta));
145 fillEffSubDir(track_tool->name(), time_tool->name(),
146 "m_eff_gt50pcprimes_vs_eta_mistag",
147 not morethanhalfprimes, std::abs(trk_eta));
148 } else {
149 fillEffSubDir(track_tool->name(), time_tool->name(),
150 "m_eff_gt50pcprimes_vs_eta", false, std::abs(trk_eta));
151 fillEffSubDir(track_tool->name(), time_tool->name(),
152 "m_eff_gt50pcprimes_vs_eta_mistag", false,
153 std::abs(trk_eta));
154 }
155 } // loop over track-time tools
156 } // loop over track selection tools
157 } // loop over tracks
158
159 return StatusCode::SUCCESS;
160}
161
163 const xAOD::TruthParticle* truth_particle) {
164 if (not truth_particle) {
165 return nullptr;
166 }
167
168 SG::ReadHandle<xAOD::TruthEventContainer> truth_event_container_hdl(
170 const xAOD::TruthEventContainer* truth_event_container =
171 truth_event_container_hdl.cptr();
172
173 if (not truth_event_container or truth_event_container->empty()) {
174 ATH_MSG_DEBUG("getTruthVertex: no " << m_truth_event_container_key.key()
175 << " container in this event");
176 return nullptr;
177 }
178
179 // check if truth particle is from HS event
180 auto truth_hs_event = truth_event_container->at(0);
181 if (not truth_hs_event) {
182 return nullptr;
183 }
184 int n_hs_truthparticles = truth_hs_event->nTruthParticles();
185 auto truth_hs_vtx = truth_event_container->at(0)->signalProcessVertex();
186
187 for (int i = 0; i < n_hs_truthparticles; i++) {
188 if (not truth_hs_event->truthParticle(i)) {
189 continue;
190 }
191 if (not truth_hs_event->truthParticle(i)->isSimulationParticle() and
192 truth_hs_event->truthParticle(i)->isStable() and
193 truth_hs_event->truthParticle(i)->isCharged() and
194 truth_hs_event->truthParticle(i)->index() == truth_particle->index()) {
195 return truth_hs_vtx;
196 }
197 }
198
199 SG::ReadHandle<xAOD::TruthPileupEventContainer> pileup_truth_container_hdl(
201 const xAOD::TruthPileupEventContainer* pileup_truth_container =
202 pileup_truth_container_hdl.cptr();
203
204 ATH_MSG_DEBUG("getTruthVertex: no HS vertex found");
205
206 // TruthPileupEvents is only written to the AOD for samples digitised with
207 // pile-up, so on a no-pile-up sample there is simply no pile-up vertex to
208 // associate the track to.
209 if (not pileup_truth_container) {
210 ATH_MSG_DEBUG("getTruthVertex: no " << m_pileup_truth_container_key.key()
211 << " container in this event");
212 return nullptr;
213 }
214
215 // if not, then check if from PU event
216 for (size_t pu_event = 0; pu_event < pileup_truth_container->size();
217 pu_event++) {
218 auto truth_pu_event = pileup_truth_container->at(pu_event);
219 auto truth_pu_vertex = truth_pu_event->truthVertex(1);
220 int n_pu_truthparticles = truth_pu_event->nTruthParticles();
221
222 for (int i = 0; i < n_pu_truthparticles; i++) {
223 if (not truth_pu_event->truthParticle(i)) {
224 continue;
225 }
226 if (not truth_pu_event->truthParticle(i)->isSimulationParticle() and
227 truth_pu_event->truthParticle(i)->isStable() and
228 truth_pu_event->truthParticle(i)->isCharged() and
229 truth_particle->index() ==
230 truth_pu_event->truthParticle(i)->index()) {
231 return truth_pu_vertex;
232 }
233 }
234 } // LOOP PU events
235 // can't be associated to any vertex
236 return nullptr;
237}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_INFO(x,...)
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
void bookSubdir(const std::string &trk_sel_name, const std::string &time_wp, const std::string &hist_name, const std::string &title, Ts... args)
Templated function for booking histograms The type of the histogram is passed as a template parameter...
virtual StatusCode initialize()
HGTD_AnalysisAlgBase(const std::string &name, ISvcLocator *svc_locator)
void fillEffSubDir(const std::string &trk_sel_name, const std::string &wp_name, const std::string &hist_name, Ts... args)
void bookEffSubdir(const std::string &trk_sel_name, const std::string &time_wp, const std::string &hist_name, const std::string &title, Ts... args)
void fillSubdir(const std::string &trk_sel_name, const std::string &time_wp, const std::string &hist_name, Ts... args)
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truth_event_container_key
const std::vector< std::string > m_primes_fractions
Histogram-name suffixes, indexed by PrimesFractions.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_track_particles_key
SG::ReadHandleKey< xAOD::TruthPileupEventContainer > m_pileup_truth_container_key
ToolHandleArray< IHGTD_ExpertTrackTimeAccessor > m_track_time_tools
ToolHandleArray< IHGTD_TrackSelectionTool > m_track_sel_tools
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
const xAOD::TruthVertex * getTruthVertex(const xAOD::TruthParticle *truth_particle)
HGTD_TrkTimePerformanceStudies(const std::string &name, ISvcLocator *svc_locator)
const_pointer_type cptr()
Dereference the pointer.
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any).
TruthEventContainer_v1 TruthEventContainer
Declare the latest version of the truth event container.
TruthPileupEventContainer_v1 TruthPileupEventContainer
Declare the latest version of the truth event container.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".