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 const std::string titleStr{";|#eta| ;frequency"};
26 for (const auto& track_tool : m_track_sel_tools) {
27 const auto & tname = track_tool->name();
28 for (const auto& time_tool : m_track_time_tools) {
29 const auto & timetoolName = time_tool->name();
30 static const std::string effVsEta{"m_eff_vs_eta"};
31 bookEffSubdir(tname, timetoolName, effVsEta, titleStr, 32, 2.4, 4.0);
32 static const std::string primesVsEta{"m_eff_gt50pcprimes_vs_eta"};
33 bookEffSubdir(tname, timetoolName, primesVsEta, titleStr, 32, 2.4, 4.0);
34 static const std::string primesVsEtaMistag{"m_eff_gt50pcprimes_vs_eta_mistag"};
35 bookEffSubdir(tname, timetoolName, primesVsEtaMistag, titleStr, 32, 2.4, 4.0);
36 for (const auto& primes_fraction_i : m_primes_fractions) {
37 std::string name = "m_eff_vs_eta_primesfrac" + primes_fraction_i;
38 bookEffSubdir(tname, timetoolName, name, titleStr, 32, 2.4, 4.0);
39 std::string name_res = "m_hist_timeres_outlier_cases" + primes_fraction_i;
40 static const std::string thisTitle{";t_{reco} - t_{truth} [ns]; number of tracks"};
41 bookSubdir<TH1F>(tname, timetoolName, name_res, thisTitle, 200, -.4, 0.4);
42 }
43 }
44 }
45
46 ATH_CHECK(m_track_particles_key.initialize());
49
50 return StatusCode::SUCCESS;
51}
52
53StatusCode HGTD_TrkTimePerformanceStudies::execute(const EventContext& ctx) {
54
57 const xAOD::TrackParticleContainer* track_particles =
58 track_particles_hdl.cptr();
59
60 for (const auto* track : *track_particles) {
61 for (const auto& track_tool : m_track_sel_tools) {
62 for (const auto& time_tool : m_track_time_tools) {
63
64 const float trk_eta = track->eta();
65
66 if (!track_tool->trackPassesSelection(track)) {
67 continue;
68 }
69
70 const xAOD::TruthParticle* truth_particle =
72
73 auto purity = time_tool->fracPrimaryHits(*track);
74 int n_potential_primes = time_tool->numberPotentialPrimaryHits(*track);
75 bool has_time = time_tool->expertHasTime(*track);
76
78 if (purity < 0.01) {
79 switch (n_potential_primes) {
80 case 0:
82 break;
83 case 1:
85 break;
86 case 2:
88 break;
89 case 3:
91 break;
92 case 4:
94 break;
95 }
96 } else if (purity > 0.01 and purity < 0.48) {
98 } else if (purity > 0.48 and purity < 0.52) {
100 } else if (purity > 0.52 and purity < 0.98) {
101 primes_fraction = PrimesFractions::MoreThanHalfPrimes;
102 } else if (purity > 0.98) {
103 primes_fraction = PrimesFractions::AllPrimes;
104 }
105
106 bool morethanhalfprimes =
107 primes_fraction == PrimesFractions::AllPrimes or
108 primes_fraction == PrimesFractions::MoreThanHalfPrimes;
109 fillEffSubDir(track_tool->name(), time_tool->name(), "m_eff_vs_eta",
110 has_time, std::abs(trk_eta));
111
112 bool count_primesfrac_category_as_good = false;
113 for (size_t i = 0; i < m_primes_fractions.size(); i++) {
114 if (i == static_cast<size_t>(primes_fraction)) {
115 count_primesfrac_category_as_good = has_time;
116 } else {
117 count_primesfrac_category_as_good = false;
118 }
119 fillEffSubDir(track_tool->name(), time_tool->name(),
120 "m_eff_vs_eta_primesfrac" + m_primes_fractions.at(i),
121 count_primesfrac_category_as_good, std::abs(trk_eta));
122 }
123
124 if (has_time) {
125 auto truth_vertex = getTruthVertex(truth_particle);
126 if (truth_particle and truth_vertex) {
127 float track_time = time_tool->expertTime(*track);
128 float truth_time = time_tool->getTruthTime(*truth_vertex);
129 float time_res = track_time - truth_time;
130 fillSubdir<TH1F>(track_tool->name(), time_tool->name(),
131 "m_hist_timeres_outlier_cases" +
132 m_primes_fractions.at(primes_fraction),
133 time_res);
134 }
135 fillEffSubDir(track_tool->name(), time_tool->name(),
136 "m_eff_gt50pcprimes_vs_eta", morethanhalfprimes,
137 std::abs(trk_eta));
138 fillEffSubDir(track_tool->name(), time_tool->name(),
139 "m_eff_gt50pcprimes_vs_eta_mistag",
140 not morethanhalfprimes, std::abs(trk_eta));
141 } else {
142 fillEffSubDir(track_tool->name(), time_tool->name(),
143 "m_eff_gt50pcprimes_vs_eta", false, std::abs(trk_eta));
144 fillEffSubDir(track_tool->name(), time_tool->name(),
145 "m_eff_gt50pcprimes_vs_eta_mistag", false,
146 std::abs(trk_eta));
147 }
148 } // loop over track-time tools
149 } // loop over track selection tools
150 } // loop over tracks
151
152 return StatusCode::SUCCESS;
153}
154
156 const xAOD::TruthParticle* truth_particle) {
157 if (not truth_particle) {
158 return nullptr;
159 }
160
161 SG::ReadHandle<xAOD::TruthEventContainer> truth_event_container_hdl(
163 const xAOD::TruthEventContainer* truth_event_container =
164 truth_event_container_hdl.cptr();
165
166 if (not truth_event_container or truth_event_container->empty()) {
167 ATH_MSG_DEBUG("getTruthVertex: no " << m_truth_event_container_key.key()
168 << " container in this event");
169 return nullptr;
170 }
171
172 // check if truth particle is from HS event
173 auto truth_hs_event = truth_event_container->at(0);
174 if (not truth_hs_event) {
175 return nullptr;
176 }
177 int n_hs_truthparticles = truth_hs_event->nTruthParticles();
178 auto truth_hs_vtx = truth_event_container->at(0)->signalProcessVertex();
179
180 for (int i = 0; i < n_hs_truthparticles; i++) {
181 if (not truth_hs_event->truthParticle(i)) {
182 continue;
183 }
184 if (not truth_hs_event->truthParticle(i)->isSimulationParticle() and
185 truth_hs_event->truthParticle(i)->isStable() and
186 truth_hs_event->truthParticle(i)->isCharged() and
187 truth_hs_event->truthParticle(i)->index() == truth_particle->index()) {
188 return truth_hs_vtx;
189 }
190 }
191
192 SG::ReadHandle<xAOD::TruthPileupEventContainer> pileup_truth_container_hdl(
194 const xAOD::TruthPileupEventContainer* pileup_truth_container =
195 pileup_truth_container_hdl.cptr();
196
197 ATH_MSG_DEBUG("getTruthVertex: no HS vertex found");
198
199 // TruthPileupEvents is only written to the AOD for samples digitised with
200 // pile-up, so on a no-pile-up sample there is simply no pile-up vertex to
201 // associate the track to.
202 if (not pileup_truth_container) {
203 ATH_MSG_DEBUG("getTruthVertex: no " << m_pileup_truth_container_key.key()
204 << " container in this event");
205 return nullptr;
206 }
207
208 // if not, then check if from PU event
209 for (size_t pu_event = 0; pu_event < pileup_truth_container->size();
210 pu_event++) {
211 auto truth_pu_event = pileup_truth_container->at(pu_event);
212 auto truth_pu_vertex = truth_pu_event->truthVertex(1);
213 int n_pu_truthparticles = truth_pu_event->nTruthParticles();
214
215 for (int i = 0; i < n_pu_truthparticles; i++) {
216 if (not truth_pu_event->truthParticle(i)) {
217 continue;
218 }
219 if (not truth_pu_event->truthParticle(i)->isSimulationParticle() and
220 truth_pu_event->truthParticle(i)->isStable() and
221 truth_pu_event->truthParticle(i)->isCharged() and
222 truth_particle->index() ==
223 truth_pu_event->truthParticle(i)->index()) {
224 return truth_pu_vertex;
225 }
226 }
227 } // LOOP PU events
228 // can't be associated to any vertex
229 return nullptr;
230}
#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 bookEffSubdir(const std::string &trk_sel_name, const std::string &time_wp, const std::string &hist_name, const std::string &title, Ts... args)
void fillEffSubDir(std::string_view trk_sel_name, std::string_view wp_name, std::string_view hist_name, Ts... args)
void fillSubdir(std::string_view trk_sel_name, std::string_view time_wp, std::string_view 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".