ATLAS Offline Software
Loading...
Searching...
No Matches
TrackClusterAssValidation.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
14
15#include <cmath>
16
18// Destructor
20
22
23
25// Initialisation
27
29{
30
31 StatusCode sc;
32
33 if (m_rapcut == 0) {
34 m_tcut = 0;
35 }
36 else {
37 double den = tan(2.*atan(exp(-m_rapcut)));
38 if (den > 0) {
39 m_tcut = 1./den;
40 }
41 else {
42 m_tcut = std::numeric_limits<double>::max();
43 }
44 }
45
46 // Erase statistic information
47 //
48 m_pdg = std::abs(m_pdg) ;
49
50 m_trackCollectionStat.resize(m_tracklocation.size());
51 m_eventStat = EventStat_t();
52
53 if(!m_useTRT) m_clcutTRT = 0;
54 if(!m_clcutTRT) m_useTRT = false;
55
56 // Read Handle Key
60
64
66
69
70 ATH_CHECK( m_tracklocation.initialize());
71
72 // Read Cond Handle Key
73 ATH_CHECK(m_pixelDetEleCollKey.initialize());
74 ATH_CHECK(m_SCTDetEleCollKey.initialize());
75
76 if (msgLvl(MSG::DEBUG)) {
77 dumptools(msg(),MSG::DEBUG);
78 msg() << endmsg;
79 }
80
81 return sc;
82}
83
85// Execute
87
88StatusCode InDet::TrackClusterAssValidation::execute(const EventContext& ctx) const
89{
90
91 if(!m_usePIX && !m_useSCT) return StatusCode::SUCCESS;
92 EventData_t event_data(m_tracklocation.size() );
93
94 std::vector<SG::ReadHandle<PRD_MultiTruthCollection> > read_handle;
95 read_handle.reserve(3);
96 if(m_usePIX) {
97 read_handle.emplace_back(m_truth_locationPixel,ctx);
98 if (not read_handle.back().isValid()) {
99 ATH_MSG_FATAL( "Could not find TruthPIX" );
100 return StatusCode::FAILURE;
101 }
102 event_data.m_truthPIX = &(*read_handle.back());
103 }
104
105 if(m_useSCT) {
106 read_handle.emplace_back(m_truth_locationSCT,ctx);
107 if (not read_handle.back().isValid()) {
108 ATH_MSG_FATAL( "Could not find TruthSCT" );
109 return StatusCode::FAILURE;
110 }
111 event_data.m_truthSCT = &(*read_handle.back());
112 }
113
114 if(m_clcutTRT > 0) {
115 read_handle.emplace_back(m_truth_locationTRT,ctx);
116 if (not read_handle.back().isValid()) {
117 ATH_MSG_FATAL( "Could not find TruthTRT" );
118 return StatusCode::FAILURE;
119 }
120 event_data.m_truthTRT = &(*read_handle.back());
121 }
122
123 newClustersEvent (ctx,event_data);
124 newSpacePointsEvent (ctx,event_data);
125 event_data.m_nqtracks = qualityTracksSelection(event_data);
126 tracksComparison (ctx,event_data);
127 if(!event_data.m_particles[0].empty()) {
128
129 efficiencyReconstruction(event_data);
130 if(msgLvl(MSG::DEBUG)) noReconstructedParticles(event_data);
131
132 }
133
134 {
135 std::lock_guard<std::mutex> lock(m_statMutex);
136 assert( event_data.m_trackCollectionStat.size() == m_trackCollectionStat.size());
137 for (unsigned int i=0; i< m_trackCollectionStat.size(); ++i ) {
138 m_trackCollectionStat[i] += event_data.m_trackCollectionStat[i];
139 }
140 m_eventStat += event_data.m_eventStat;
141 }
142
143 if (msgLvl(MSG::DEBUG)) {
144 dumpevent(msg(),event_data);
145 msg() << endmsg;
146 }
147 return StatusCode::SUCCESS;
148}
149
151// Finalize
153
155 if(m_eventStat.m_events<=0) return StatusCode::SUCCESS;
156 const auto & w13 = std::setw(13);
157 const auto & p5 = std::setprecision(5);
158 const auto topNtail=[](const std::string & str){return "|" + str + "|";};
159 const std::string lineSeparator(83,'-');
160 const std::string spaceSeparator(83,' ');
161 std::stringstream out;
162 out<<std::fixed;
163 out<<topNtail(lineSeparator)<<"\n";
164 out<<"| TrackClusterAssValidation statistic for charge truth particles with |\n";
165 out<<topNtail(spaceSeparator)<<"\n";
166 out<<"| pT >="<<w13<<p5<<m_ptcut.value()<<" MeV"<<" |\n";
167 if(m_ptcutmax < 1000000.) {
168 out<<"| pT <="<<w13<<p5<<m_ptcutmax.value()<<" MeV"<<" |\n";
169 }
170 out<<"| |rapidity| <="<<w13<<p5<<m_rapcut.value()<<" |\n";
171 out<<"| max vertex radius <="<<w13<<p5<<m_rmax.value()<<" mm"<<" |\n";
172 out<<"| min vertex radius >="<<w13<<p5<<m_rmin.value()<<" mm"<<" |\n";
173 out<<"| particles pdg ="<<std::setw(8)<<m_pdg.value()<<" |\n";
174
175 auto yesNo=[](const bool predicate){return predicate ? "yes" : "no ";};
176 out<<"| use Pixels information "<<yesNo(m_usePIX)<<" |\n";
177 out<<"| use SCT information "<<yesNo(m_useSCT)<<" |\n";
178 out<<"| use TRT information "<<yesNo(m_useTRT)<<" |\n";
179 out<<"| take into account outliers "<<yesNo(m_useOutliers)<<" |\n";
180 out<<topNtail(spaceSeparator)<<"\n";
181 if(!m_usePIX && !m_useSCT) return StatusCode::SUCCESS;
182 enum Regions{Barrel, Transition, Endcap, Forward, NRegions};
183 auto incrementArray=[](auto & array, const int idx){for (int j{};j!=NRegions;++j) array[idx][j] += array[idx+1][j];};
184 for(int i=48; i>=0; --i) {
185 m_eventStat.m_particleClusters [i] +=m_eventStat.m_particleClusters [i+1];
186 incrementArray(m_eventStat.m_particleClustersBTE, i);
187 m_eventStat.m_particleSpacePoints [i] +=m_eventStat.m_particleSpacePoints [i+1];
188 incrementArray(m_eventStat.m_particleSpacePointsBTE, i);
189 }
190 auto coerceToOne=[](const double & initialVal)->double {return (initialVal<1.) ? 1. : initialVal; };
191 /* Note that in all cases below, the dimension of the target (i.e. result) array is 10
192 * whereas the dimension of the source, or input, array is 50. The first index of the source
193 * is used for totals, to act as a denominator(coerced to 1 if necessary). Bin 49 is used for overflows.
194 * Stats for single clusters (index 1) appear to be unused in printout.
195 */
196 //all
197 double pa = coerceToOne(m_eventStat.m_particleClusters[0]);
198 std::array<double, 10> pc2ff{};
199 size_t clusterIdx = 2;
200 for (auto & thisCluster: pc2ff){
201 thisCluster = double(m_eventStat.m_particleClusters[ clusterIdx++ ])/ pa;
202 }
203 //barrel
204 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Barrel]);
205 std::array<double, 10> pcBarrel2ff{};
206 size_t clusterBarrelIdx = 2;
207 for (auto & thisClusterB: pcBarrel2ff){
208 thisClusterB = double(m_eventStat.m_particleClustersBTE[ clusterBarrelIdx++ ][Barrel])/ pa;
209 }
210 //transition
211 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Transition]);
212 std::array<double, 10> pcTransition2ff{};
213 size_t clusterTransitionIdx = 2;
214 for (auto & thisClusterT: pcTransition2ff){
215 thisClusterT = double(m_eventStat.m_particleClustersBTE[ clusterTransitionIdx++ ][Transition])/ pa;
216 }
217 //endcap
218 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Endcap]);
219 std::array<double, 10> pcEndcap2ff{};
220 size_t clusterEndcapIdx = 2;
221 for (auto & thisClusterE: pcEndcap2ff){
222 thisClusterE = double(m_eventStat.m_particleClustersBTE[ clusterEndcapIdx++ ][Endcap])/ pa;
223 }
224 //fwd
225 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][3]);
226 std::array<double, 10> pcFwd2ff{};
227 size_t clusterFwdIdx = 2;
228 for (auto & thisClusterD: pcFwd2ff){
229 thisClusterD = double(m_eventStat.m_particleClustersBTE[ clusterFwdIdx++ ][Forward])/ pa;
230 }
231 //
232 //*** SPACE POINTS ***
233 //
234 //all
235 pa = coerceToOne(m_eventStat.m_particleSpacePoints[0]);
236 std::array<double, 10> sp2ff{};
237 size_t spacepointIdx = 2;
238 for (auto & thisSpacepoint: sp2ff){
239 thisSpacepoint = double(m_eventStat.m_particleSpacePoints[ spacepointIdx++ ])/ pa;
240 }
241 //barrel
242 pa = coerceToOne(m_eventStat.m_particleSpacePointsBTE[0][Barrel]);
243 std::array<double, 10> spBarrel2ff{};
244 size_t spacepointBarrelIdx = 2;
245 for (auto & thisSpacepoint: spBarrel2ff){
246 thisSpacepoint = double(m_eventStat.m_particleSpacePointsBTE[ spacepointBarrelIdx++ ][Barrel])/ pa;
247 }
248 //transition
249 pa = coerceToOne(m_eventStat.m_particleSpacePointsBTE[0][Transition]);
250 std::array<double, 10> spTransition2ff{};
251 size_t spacepointTransitionIdx = 2;
252 for (auto & thisSpacepoint: spTransition2ff){
253 thisSpacepoint = double(m_eventStat.m_particleSpacePointsBTE[ spacepointTransitionIdx++ ][Transition])/ pa;
254 }
255 //endcap
256 pa = coerceToOne(m_eventStat.m_particleSpacePointsBTE[0][Endcap]);
257 std::array<double, 10> spEndcap2ff{};
258 size_t spacepointEndcapIdx = 2;
259 for (auto & thisSpacepoint: spEndcap2ff){
260 thisSpacepoint = double(m_eventStat.m_particleSpacePointsBTE[ spacepointEndcapIdx++ ][Endcap])/ pa;
261 }
262 //Fwd
263 pa = coerceToOne(m_eventStat.m_particleSpacePointsBTE[0][Forward]);
264 std::array<double, 10> spFwd2ff{};
265 size_t spacepointFwdIdx = 2;
266 for (auto & thisSpacepoint: spFwd2ff){
267 thisSpacepoint = double(m_eventStat.m_particleSpacePointsBTE[ spacepointFwdIdx++ ][Forward])/ pa;
268 }
269 auto w8=std::setw(8);
270 out<<"| Probability for such charge particles to have some number silicon |\n";
271 out<<"| clusters | space points |\n";
272 out<<"| Total Barrel Transi Endcap Forward | Total Barrel Transi Endcap Forward |\n";
273
274 for (size_t idx{0};idx != 10;++idx){
275 out<<"| >= "<<idx+2<< std::string((idx<8)?" ":" ")
276 <<w8<<p5<<pc2ff[idx]
277 <<w8<<p5<<pcBarrel2ff[idx]
278 <<w8<<p5<<pcTransition2ff[idx]
279 <<w8<<p5<<pcEndcap2ff[idx]
280 <<w8<<p5<<pcFwd2ff[idx]<<" | "
281
282 <<w8<<p5<<sp2ff[idx]
283 <<w8<<p5<<spBarrel2ff[idx]
284 <<w8<<p5<<spTransition2ff[idx]
285 <<w8<<p5<<spEndcap2ff[idx]
286 <<w8<<p5<<spFwd2ff[idx]
287 <<" |\n";
288 }
289
290 out<<topNtail(spaceSeparator)<<"\n";
291 out<<"| Additional cuts for truth particles are |\n";
292 out<<"| number silicon clusters >="<<w13<<m_clcut.value()<<" |\n";
293 out<<"| number trt clusters >="<<w13<<m_clcutTRT.value()<<" |\n";
294 out<<"| number space points >="<<w13<<m_spcut.value()<<" |\n";
295
296 pa = coerceToOne(m_eventStat.m_particleClusters[0]);
297 out<<"| Probability find truth particles with this cuts is "<<w8<<p5<<double(m_eventStat.m_events)/pa<<" |\n";
298 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Barrel]);
299 out<<"| For barrel region "<<w8<<p5<<double(m_eventStat.m_eventsBTE[Barrel])/pa<<" |\n";
300 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Transition]);
301 out<<"| For transition region "<<w8<<p5<<double(m_eventStat.m_eventsBTE[Transition])/pa<<" |\n";
302 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Endcap]);
303 out<<"| For endcap region "<<w8<<p5<<double(m_eventStat.m_eventsBTE[Endcap])/pa<<" |\n";
304 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Forward]);
305 out<<"| For forward region "<<w8<<p5<<double(m_eventStat.m_eventsBTE[Forward])/pa<<" |\n";
306 out<<"| |\n";
307 pa = coerceToOne(m_eventStat.m_nclustersNegBP);
308 double ratio = double(m_eventStat.m_nclustersPosBP)/pa;
309 double eratio = std::sqrt(ratio*(1.+ratio)/pa);
310 out<<"| Ratio barrel pixels clusters for +/- particles ="<<w8<<p5<<ratio<<" +-"<<w8<<p5<<eratio<<" |\n";
311 pa = coerceToOne(m_eventStat.m_nclustersNegEP);
312 ratio = double(m_eventStat.m_nclustersPosEP)/pa;
313 eratio = std::sqrt(ratio*(1.+ratio)/pa);
314 out<<"| Ratio endcap pixels clusters for +/- particles ="<<w8<<p5<<ratio<<" +-"<<w8<<p5<<eratio<<" |\n";
315 pa = coerceToOne(m_eventStat.m_nclustersNegBS);
316 ratio = double(m_eventStat.m_nclustersPosBS)/pa;
317 eratio = std::sqrt(ratio*(1.+ratio)/pa);
318 out<<"| Ratio barrel SCT clusters for +/- particles ="<<w8<<p5<<ratio<<" +-"<<w8<<p5<<eratio<<" |\n";
319 pa = coerceToOne(m_eventStat.m_nclustersNegES);
320 ratio = double(m_eventStat.m_nclustersPosES)/pa;
321 eratio = std::sqrt(ratio*(1.+ratio)/pa);
322 out<<"| Ratio endcap SCT clusters for +/- particles ="<<w8<<p5<<ratio<<" +-"<<w8<<p5<<eratio<<" |\n";
323 pa = double(m_eventStat.m_eventsNEG); if(pa < 1.) pa = 1.;
324 ratio = double(m_eventStat.m_eventsPOS)/pa;
325 eratio = std::sqrt(ratio*(1.+ratio)/pa);
326 out<<"| Number truth particles and +/- ratio ="<<std::setw(10)<<m_eventStat.m_events<<w8<<p5<<ratio<<" +-"<<w8<<p5<<eratio<<" |\n";
327 ratio = 0.;
328 if(m_eventStat.m_nclustersPTOT!=0) ratio = double(m_eventStat.m_nclustersPTOTt)/double(m_eventStat.m_nclustersPTOT);
329
330 out<<"| Number pix clusters, truth clusters and ratio = "
331 <<std::setw(10)<<m_eventStat.m_nclustersPTOT
332 <<std::setw(10)<<m_eventStat.m_nclustersPTOTt
333 <<std::setw(12)<<std::setprecision(5)<<ratio<<" |\n";
334 ratio = 0.;
335 if(m_eventStat.m_nclustersSTOT!=0) ratio = double(m_eventStat.m_nclustersSTOTt)/double(m_eventStat.m_nclustersSTOT);
336 out<<"| Number sct clusters, truth clusters and ratio = "
337 <<std::setw(10)<<m_eventStat.m_nclustersSTOT
338 <<std::setw(10)<<m_eventStat.m_nclustersSTOTt
339 <<std::setw(12)<<std::setprecision(5)<<ratio<<" |\n";
340
341 out<<"|-----------------------------------------------------------------------------------|\n\n";
342
343 SG::ReadHandleKeyArray<TrackCollection>::const_iterator t=m_tracklocation.begin(),te=m_tracklocation.end();
344 int nc = 0;
345 for(; t!=te; ++t) {
346 int n = 47-(t->key().size());
347 std::string s1; for(int i=0; i<n; ++i) s1.append(" "); s1.append("|");
348
349
350 out<<"|-----------------------------------------------------------------------------------|\n";
351 out<<"| Statistic for "<<(t->key())<<s1<<"\n";
352
353 double ne = double(m_eventStat.m_events); if(ne < 1.) ne = 1.;
354 double ef [6]; for(int i=0; i!=6; ++i) ef [i] = double(m_trackCollectionStat[nc].m_efficiency [i]) /ne;
355 double ef0[6]; for(int i=0; i!=6; ++i) ef0[i] = double(m_trackCollectionStat[nc].m_efficiencyN [i][0])/ne;
356 double ef1[6]; for(int i=0; i!=6; ++i) ef1[i] = double(m_trackCollectionStat[nc].m_efficiencyN [i][1])/ne;
357 double ef2[6]; for(int i=0; i!=6; ++i) ef2[i] = double(m_trackCollectionStat[nc].m_efficiencyN [i][2])/ne;
358
359
360 using EffArray_t = std::array<double, 6>;
361 //
362 auto makeEffArray = [](const auto & threeDimArray, const size_t secondIdx, const size_t thirdIdx, const double denom){
363 EffArray_t result{};
364 size_t idx{0};
365 auto invDenom = 1./denom;
366 for (auto & entry: result){
367 entry = threeDimArray[idx++][secondIdx][thirdIdx]*invDenom;
368 }
369 return result;
370 };
371 //
372 const auto & efficiencyArrayInput = m_trackCollectionStat[nc].m_efficiencyBTE;
373 //
374 double neBTE = coerceToOne(m_eventStat.m_eventsBTE[Barrel]);
375 const EffArray_t efB0 = makeEffArray(efficiencyArrayInput,0,Barrel,neBTE);
376 const EffArray_t efB1 = makeEffArray(efficiencyArrayInput,1,Barrel,neBTE);
377 const EffArray_t efB2 = makeEffArray(efficiencyArrayInput,2,Barrel,neBTE);
378 const EffArray_t efB3 = makeEffArray(efficiencyArrayInput,3,Barrel,neBTE);
379 const EffArray_t efB4 = makeEffArray(efficiencyArrayInput,4,Barrel,neBTE);
380 //
381 neBTE = coerceToOne(m_eventStat.m_eventsBTE[Transition]);
382 const EffArray_t efT0 = makeEffArray(efficiencyArrayInput,0,Transition,neBTE);
383 const EffArray_t efT1 = makeEffArray(efficiencyArrayInput,1,Transition,neBTE);
384 const EffArray_t efT2 = makeEffArray(efficiencyArrayInput,2,Transition,neBTE);
385 const EffArray_t efT3 = makeEffArray(efficiencyArrayInput,3,Transition,neBTE);
386 const EffArray_t efT4 = makeEffArray(efficiencyArrayInput,4,Transition,neBTE);
387 //
388 neBTE = coerceToOne(m_eventStat.m_eventsBTE[Endcap]);
389 const EffArray_t efE0 = makeEffArray(efficiencyArrayInput,0,Endcap,neBTE);
390 const EffArray_t efE1 = makeEffArray(efficiencyArrayInput,1,Endcap,neBTE);
391 const EffArray_t efE2 = makeEffArray(efficiencyArrayInput,2,Endcap,neBTE);
392 const EffArray_t efE3 = makeEffArray(efficiencyArrayInput,3,Endcap,neBTE);
393 const EffArray_t efE4 = makeEffArray(efficiencyArrayInput,4,Endcap,neBTE);
394 //
395 neBTE = coerceToOne(m_eventStat.m_eventsBTE[Forward]);
396 const EffArray_t efD0 = makeEffArray(efficiencyArrayInput,0,Forward,neBTE);
397 const EffArray_t efD1 = makeEffArray(efficiencyArrayInput,1,Forward,neBTE);
398 const EffArray_t efD2 = makeEffArray(efficiencyArrayInput,2,Forward,neBTE);
399 const EffArray_t efD3 = makeEffArray(efficiencyArrayInput,3,Forward,neBTE);
400 const EffArray_t efD4 = makeEffArray(efficiencyArrayInput,4,Forward,neBTE);
401
402
403 double efrec = ef0[0]+ef0[1]+ef0[2]+ef1[0]+ef1[1]+ef2[0];
404 double efrecB = efB0[0]+efB0[1]+efB0[2]+efB1[0]+efB1[1]+efB2[0];
405 double efrecT = efT0[0]+efT0[1]+efT0[2]+efT1[0]+efT1[1]+efT2[0];
406 double efrecE = efE0[0]+efE0[1]+efE0[2]+efE1[0]+efE1[1]+efE2[0];
407 double efrecD = efD0[0]+efD0[1]+efD0[2]+efD1[0]+efD1[1]+efD2[0];
408
409 ne = coerceToOne(m_eventStat.m_eventsPOS);
410 double efP[6]; for(int i=0; i!=6; ++i) efP[i] = double(m_trackCollectionStat[nc].m_efficiencyPOS[i])/ne;
411 ne = coerceToOne(m_eventStat.m_eventsNEG);
412 double efN[6]; for(int i=0; i!=6; ++i) efN[i] = double(m_trackCollectionStat[nc].m_efficiencyNEG[i])/ne;
413
414 out<<"|-----------------------------------------------------------------------------------|\n";
415 out<<"| Probability to lose 0 1 2 3 4 >=5 clusters |\n";
416 out<<"|-----------------------------------------------------------------------------------|\n";
417
418 auto formattedOutput=[&out](auto & effArray){
419 for (size_t i{};i!=6;++i){
420 out<<std::setw(9)<<std::setprecision(4)<<effArray[i];
421 }
422 out<<" |\n";
423 };
424
425 out<<"| For all particles ";
426 formattedOutput(ef);
427 out<<"| For + particles ";
428 formattedOutput(efP);
429 out<<"| For - particles ";
430 formattedOutput(efN);
431 out<<"|-----------------------------------------------------------------------------------|\n";
432 out<<"| Barrel region |\n";
433 out<<"| 0 wrong clusters ";
434 formattedOutput(efB0);
435 out<<"| 1 wrong clusters ";
436 formattedOutput(efB1);
437 out<<"| 2 wrong clusters ";
438 formattedOutput(efB2);
439 out<<"| 3 wrong clusters ";
440 formattedOutput(efB3);
441 out<<"| >=4 wrong clusters ";
442 formattedOutput(efB4);
443 out<<"|-----------------------------------------------------------------------------------|\n";
444 out<<"| Transition region |\n";
445 out<<"| 0 wrong clusters ";
446 formattedOutput(efT0);
447 out<<"| 1 wrong clusters ";
448 formattedOutput(efT1);
449 out<<"| 2 wrong clusters ";
450 formattedOutput(efT2);
451 out<<"| 3 wrong clusters ";
452 formattedOutput(efT3);
453 out<<"| >=4 wrong clusters ";
454 formattedOutput(efT4);
455 out<<"|-----------------------------------------------------------------------------------|\n";
456 out<<"| Endcap region |\n";
457 out<<"| 0 wrong clusters ";
458 formattedOutput(efE0);
459 out<<"| 1 wrong clusters ";
460 formattedOutput(efE1);
461 out<<"| 2 wrong clusters ";
462 formattedOutput(efE2);
463 out<<"| 3 wrong clusters ";
464 formattedOutput(efE3);
465 out<<"| >=4 wrong clusters ";
466 formattedOutput(efE4);
467 out<<"|-----------------------------------------------------------------------------------|\n";
468 out<<"| Forward region |\n";
469 out<<"| 0 wrong clusters ";
470 formattedOutput(efD0);
471 out<<"| 1 wrong clusters ";
472 formattedOutput(efD1);
473 out<<"| 2 wrong clusters ";
474 formattedOutput(efD2);
475 out<<"| 3 wrong clusters ";
476 formattedOutput(efD3);
477 out<<"| >=4 wrong clusters ";
478 formattedOutput(efD4);
479
480 out<<"|-----------------------------------------------------------------------------------|\n";
481 pa = coerceToOne(m_eventStat.m_particleClusters[0]);
482 out<<"| Efficiency reconstruction (number lose+wrong < 3) = "
483 <<std::setw(9)<<std::setprecision(5)<<efrec
484 <<" ("
485 <<std::setw(9)<<std::setprecision(5)<<efrec*double(m_eventStat.m_events)/pa
486 <<" ) "
487 <<" |\n";
488 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Barrel]);
489 out<<"| For barrel region = "
490 <<std::setw(9)<<std::setprecision(5)<<efrecB
491 <<" ("
492 <<std::setw(9)<<std::setprecision(5)<<efrecB*double(m_eventStat.m_eventsBTE[Barrel])/pa
493 <<" ) "
494 <<" |\n";
495 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Transition]);
496 out<<"| For transition region = "
497 <<std::setw(9)<<std::setprecision(5)<<efrecT
498 <<" ("
499 <<std::setw(9)<<std::setprecision(5)<<efrecT*double(m_eventStat.m_eventsBTE[Transition])/pa
500 <<" ) "
501 <<" |\n";
502 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Endcap]);
503 out<<"| For endcap region = "
504 <<std::setw(9)<<std::setprecision(5)<<efrecE
505 <<" ("
506 <<std::setw(9)<<std::setprecision(5)<<efrecE*double(m_eventStat.m_eventsBTE[Endcap])/pa
507 <<" ) "
508 <<" |\n";
509 pa = coerceToOne(m_eventStat.m_particleClustersBTE[0][Forward]);
510 out<<"| For forward region = "
511 <<std::setw(9)<<std::setprecision(5)<<efrecD
512 <<" ("
513 <<std::setw(9)<<std::setprecision(5)<<efrecD*double(m_eventStat.m_eventsBTE[Forward])/pa
514 <<" ) "
515 <<" |\n";
516
517 out<<"|-----------------------------------------------------------------------------------|\n";
518 out<<"| Reconstructed tracks + - +/-ratio error |\n";
519 out<<"|-----------------------------------------------------------------------------------|\n";
520
521 pa = coerceToOne(m_trackCollectionStat[nc].m_ntracksNEGB);
522 ratio = double(m_trackCollectionStat[nc].m_ntracksPOSB)/pa;
523 eratio = std::sqrt(ratio*(1.+ratio)/pa);
524
525 out<<"| Barrel "
526 <<std::setw(10)<<m_trackCollectionStat[nc].m_ntracksPOSB
527 <<std::setw(11)<<m_trackCollectionStat[nc].m_ntracksNEGB
528 <<std::setw(11)<<std::setprecision(5)<<ratio
529 <<std::setw(11)<<std::setprecision(5)<<eratio<<" |\n";
530 pa = coerceToOne(m_trackCollectionStat[nc].m_ntracksNEGE);
531 ratio = double(m_trackCollectionStat[nc].m_ntracksPOSE)/pa;
532 eratio = std::sqrt(ratio*(1.+ratio)/pa);
533
534 out<<"| Endcap "
535 <<std::setw(10)<<m_trackCollectionStat[nc].m_ntracksPOSE
536 <<std::setw(11)<<m_trackCollectionStat[nc].m_ntracksNEGE
537 <<std::setw(11)<<std::setprecision(5)<<ratio
538 <<std::setw(11)<<std::setprecision(5)<<eratio<<" |\n";
539 pa = coerceToOne(m_trackCollectionStat[nc].m_ntracksNEGFWD);
540 ratio = double(m_trackCollectionStat[nc].m_ntracksPOSFWD)/pa;
541 eratio = std::sqrt(ratio*(1.+ratio)/pa);
542
543 out<<"| Forward "
544 <<std::setw(10)<<m_trackCollectionStat[nc].m_ntracksPOSFWD
545 <<std::setw(11)<<m_trackCollectionStat[nc].m_ntracksNEGFWD
546 <<std::setw(11)<<std::setprecision(5)<<ratio
547 <<std::setw(11)<<std::setprecision(5)<<eratio<<" |\n";
548
549
550
551 int nt=0;
552 int ft=0;
553 int kf=0;
554 for(int k = 0; k!=50; ++k) {
555 nt+=m_trackCollectionStat[nc].m_total[k];
556 ft+=m_trackCollectionStat[nc].m_fake [k];
557 if(!kf && nt) kf = k;
558 }
559
560 if(kf) {
561
562 out<<"|-----------------------------------------------------------------------------------|\n";
563 out<<"| Fake tracks rate for different number of clusters on track |\n";
564 out<<"|-----------------------------------------------------------------------------------|\n";
565
566 for(int k = kf; k!=kf+6; ++k) {
567 out<<"| >= "<<std::setw(2)<<k<<" ";
568 }
569 out<<"|\n";
570
571 for(int k = kf; k!=kf+6; ++k) {
572 double eff = 0.; if(nt>0) eff = double(ft)/double(nt);
573 out<<"|"<<std::setw(12)<<std::setprecision(5)<<eff<<" ";
574 nt-=m_trackCollectionStat[nc].m_total[k];
575 ft-=m_trackCollectionStat[nc].m_fake [k];
576 }
577 out<<"|\n";
578 out<<"|-----------------------------------------------------------------------------------|\n";
579 }
580 ++nc;
581 }
582 ATH_MSG_INFO("\n"<<out.str());
583 return StatusCode::SUCCESS;
584}
585
587// Dumps conditions information into the MsgStream
589
590MsgStream& InDet::TrackClusterAssValidation::dumptools( MsgStream& out, MSG::Level level) const
591{
592 SG::ReadHandleKeyArray<TrackCollection>::const_iterator t=m_tracklocation.begin(),te=m_tracklocation.end();
593
594 int n;
595 out << level <<"\n";
596 out<<"|--------------------------------------------------------------------------------------------------------------------|\n";
597 for(; t!=te; ++t) {
598 n = 65-t->key().size();
599 std::string s1; for(int i=0; i<n; ++i) s1.append(" "); s1.append("|");
600 out<<"| Location of input tracks | "<<t->key()<<s1<<"\n";
601 }
602 auto padString = [](const std::string & s){
603 const int n = 65 - s.size();
604 return s + std::string(n, ' ');
605 };
606 std::string s2 = padString(m_spacepointsPixelname.key());
607 std::string s3 = padString(m_spacepointsSCTname.key());
608 std::string s4 = padString(m_spacepointsOverlapname.key());
609 std::string s5 = padString(m_clustersPixelname.key());
610 std::string s6 = padString(m_clustersSCTname.key());
611 //
612 std::string s9 = padString(m_clustersTRTname.key());
613 //
614 std::string s7 = padString(m_truth_locationPixel.key());
615 std::string s8 = padString(m_truth_locationSCT.key());
616 //
617 std::string s10 = padString(m_truth_locationTRT.key());
618
619 out<<"| Pixel space points | "<<s2<<"|\n";
620 out<<"| SCT space points | "<<s3<<"|\n";
621 out<<"| Overlap space points | "<<s4<<"|\n";
622 out<<"| Pixel clusters | "<<s5<<"|\n";
623 out<<"| SCT clusters | "<<s6<<"|\n";
624 out<<"| TRT clusters | "<<s9<<"|\n";
625 out<<"| Truth location for pixels | "<<s7<<"|\n";
626 out<<"| Truth location for sct | "<<s8<<"|\n";
627 out<<"| Truth location for trt | "<<s10<<"|\n";
628 out<<"| pT cut | "
629 <<std::setw(14)<<std::setprecision(5)<<m_ptcut.value()
630 <<" |\n";
631 out<<"| max pT cut | "
632 <<std::setw(14)<<std::setprecision(5)<<m_ptcutmax.value()
633 <<" |\n";
634 out<<"| rapidity cut | "
635 <<std::setw(14)<<std::setprecision(5)<<m_rapcut.value()
636 <<" |\n";
637 out<<"| min Radius | "
638 <<std::setw(14)<<std::setprecision(5)<<m_rmin.value()
639 <<" |\n";
640 out<<"| max Radius | "
641 <<std::setw(14)<<std::setprecision(5)<<m_rmax.value()
642 <<" |\n";
643 out<<"| Min. number clusters for generated track | "
644 <<std::setw(14)<<std::setprecision(5)<<m_clcut.value()
645 <<" |\n";
646 out<<"| Min. number sp.points for generated track | "
647 <<std::setw(14)<<std::setprecision(5)<<m_spcut.value()
648 <<" |\n";
649 out<<"| Min. number TRT clusters for generated track | "
650 <<std::setw(14)<<std::setprecision(5)<<m_clcutTRT.value()
651 <<" |\n";
652 out<<"|--------------------------------------------------------------------------------------------------------------------|\n";
653 return out;
654}
655
657// Dumps event information into the ostream
659
661{
662 out << MSG::DEBUG << "\n";
663 auto formatOutput = [&out](const auto val){
664 out<<std::setw(12)<<val
665 <<" |\n";
666 };
667 out<<"|---------------------------------------------------------------------|\n";
668 out<<"| m_nspacepoints | ";
669 formatOutput(event_data.m_nspacepoints);
670 out<<"| m_nclusters | ";
671 formatOutput(event_data.m_nclusters);
672 out<<"| Kine-Clusters size | ";
673 formatOutput(event_data.m_kinecluster.size());
674 out<<"| Kine-TRTClusters size | ";
675 formatOutput(event_data.m_kineclusterTRT.size());
676 out<<"| Kine-SpacePoints size | ";
677 formatOutput(event_data.m_kinespacepoint.size());
678 out<<"| Number good kine tracks | ";
679 formatOutput(event_data.m_nqtracks);
680 out<<"|---------------------------------------------------------------------|\n";
681 return out;
682}
683
684
686// New event for clusters information
688
690{
691 std::lock_guard<std::mutex> lock(m_statMutex);
692
693 // Get pixel clusters container
694 //
695 std::unique_ptr<SG::ReadHandle<SiClusterContainer> > pixelcontainer;
696 std::unique_ptr<SG::ReadHandle<SiClusterContainer> > sctcontainer;
697 std::unique_ptr<SG::ReadHandle<TRT_DriftCircleContainer> > trtcontainer;
698
699 if(m_usePIX) {
700 pixelcontainer = std::make_unique<SG::ReadHandle<SiClusterContainer> >(m_clustersPixelname,ctx);
701 if (!pixelcontainer->isValid()) ATH_MSG_DEBUG("Failed to create Pixel clusters container read handle with key " << m_clustersPixelname.key());
702 }
703
704 // Get sct clusters container
705 //
706 if(m_useSCT) {
707 sctcontainer = std::make_unique<SG::ReadHandle<SiClusterContainer> >(m_clustersSCTname,ctx);
708 if (!sctcontainer->isValid()) ATH_MSG_DEBUG("Failed to create SCT clusters container read handle with key " << m_clustersSCTname.key());
709 }
710
711 // Get trt cluster container
712 //
713 if(m_clcutTRT > 0) {
714 trtcontainer = std::make_unique<SG::ReadHandle<TRT_DriftCircleContainer> >(m_clustersTRTname,ctx);
715 if (!trtcontainer->isValid()) ATH_MSG_DEBUG("Failed to create TRT drift circle container read handle with key " << m_clustersTRTname.key());
716 }
717
718 int Kine[1000];
719
720 event_data.m_clusterHandles.reserve(3);
721 // Loop through all pixel clusters
722 //
723 if(pixelcontainer && pixelcontainer->isValid()) {
724 InDet::SiClusterContainer::const_iterator w = (*pixelcontainer)->begin();
725 InDet::SiClusterContainer::const_iterator we = (*pixelcontainer)->end ();
726
727 for(; w!=we; ++w) {
728
729 InDet::SiClusterCollection::const_iterator c = (*w)->begin();
730 InDet::SiClusterCollection::const_iterator ce = (*w)->end ();
731
732 for(; c!=ce; ++c) {
733
734 ++event_data.m_nclusters;
735 ++m_eventStat.m_nclustersPTOT;
736 if(isTruth(event_data,(*c))) ++m_eventStat.m_nclustersPTOTt;
737
738
739 int nk = kine(event_data,(*c),Kine,999);
740 for(int i=0; i!=nk; ++i) {
741 if(!isTheSameDetElement(event_data,Kine[i],(*c))) {
742 event_data.m_kinecluster.insert(std::make_pair(Kine[i],(*c)));
743 }
744 }
745 }
746 }
747 event_data.m_clusterHandles.push_back(std::move(pixelcontainer));
748
749 }
750
751 // Loop through all sct clusters
752 //
753 if(sctcontainer && sctcontainer->isValid()) {
754 InDet::SiClusterContainer::const_iterator w = (*sctcontainer)->begin();
755 InDet::SiClusterContainer::const_iterator we = (*sctcontainer)->end ();
756
757 for(; w!=we; ++w) {
758
759 InDet::SiClusterCollection::const_iterator c = (*w)->begin();
760 InDet::SiClusterCollection::const_iterator ce = (*w)->end ();
761
762 for(; c!=ce; ++c) {
763
764 ++event_data.m_nclusters;
765 ++m_eventStat.m_nclustersSTOT;
766 if(isTruth(event_data,(*c))) ++m_eventStat.m_nclustersSTOTt;
767
768 int nk = kine(event_data,(*c),Kine,999);
769 for(int i=0; i!=nk; ++i) {
770 if(!isTheSameDetElement(event_data,Kine[i],(*c))) event_data.m_kinecluster.insert(std::make_pair(Kine[i],(*c)));
771 }
772 }
773 }
774 event_data.m_clusterHandles.push_back(std::move(sctcontainer));
775 }
776
777 if(trtcontainer && trtcontainer->isValid()) {
778 // Loop through all trt clusters
779 //
780 InDet::TRT_DriftCircleContainer::const_iterator w = (*trtcontainer)->begin();
781 InDet::TRT_DriftCircleContainer::const_iterator we = (*trtcontainer)->end ();
782
783 for(; w!=we; ++w) {
784
785 InDet::TRT_DriftCircleCollection::const_iterator c = (*w)->begin();
786 InDet::TRT_DriftCircleCollection::const_iterator ce = (*w)->end ();
787
788 for(; c!=ce; ++c) {
789
790 ++event_data.m_nclustersTRT;
791 int nk = kine(event_data,(*c),Kine,999);
792 for(int i=0; i!=nk; ++i) event_data.m_kineclusterTRT.insert(std::make_pair(Kine[i],(*c)));
793 }
794 }
795 event_data.m_clusterHandles.push_back(std::move(trtcontainer));
796 }
797}
798
800// New event for space points information
802
804{
805
806 int Kine[1000];
807
808 if(m_usePIX && !m_spacepointsPixelname.key().empty()) {
809 event_data.m_spacePointContainer.emplace_back(m_spacepointsPixelname,ctx);
810 if (!event_data.m_spacePointContainer.back().isValid()) {
811 ATH_MSG_DEBUG( "Invalid Pixels space points container read handle for key " << m_spacepointsPixelname.key() );
812 }
813 else {
814 SpacePointContainer::const_iterator spc = event_data.m_spacePointContainer.back()->begin();
815 SpacePointContainer::const_iterator spce = event_data.m_spacePointContainer.back()->end ();
816 for(; spc != spce; ++spc) {
818 SpacePointCollection::const_iterator spe = (*spc)->end ();
819
820 for(; sp != spe; ++sp) {
821
822 ++event_data.m_nspacepoints;
823 int nk = kine(event_data,(*sp)->clusterList().first,Kine,999);
824 for(int i=0; i!=nk; ++i) {
825
826 if(!isTheSameDetElement(event_data,Kine[i],(*sp))) {
827 event_data.m_kinespacepoint.insert(std::make_pair(Kine[i],(*sp)));
828 }
829 }
830 }
831 }
832 }
833 }
834 // Get sct space points containers from store gate
835 //
836 if(m_useSCT && !m_spacepointsSCTname.key().empty()) {
837 event_data.m_spacePointContainer.emplace_back(m_spacepointsSCTname,ctx);
838 if (!event_data.m_spacePointContainer.back().isValid()) {
839 ATH_MSG_DEBUG( "Invalid SCT space points container read handle for key " << m_spacepointsSCTname.key() );
840 }
841 else {
842 SpacePointContainer::const_iterator spc = event_data.m_spacePointContainer.back()->begin();
843 SpacePointContainer::const_iterator spce = event_data.m_spacePointContainer.back()->end ();
844
845 for(; spc != spce; ++spc) {
846
848 SpacePointCollection::const_iterator spe = (*spc)->end ();
849
850 for(; sp != spe; ++sp) {
851
852
853 ++event_data.m_nspacepoints;
854 int nk = kine(event_data,(*sp)->clusterList().first,(*sp)->clusterList().second,Kine,999);
855 for(int i=0; i!=nk; ++i) {
856 if(!isTheSameDetElement(event_data,Kine[i],(*sp))) {
857 event_data.m_kinespacepoint.insert(std::make_pair(Kine[i],(*sp)));
858 }
859 }
860 }
861 }
862 }
863 }
864 // Get sct overlap space points containers from store gate
865 //
866 if(m_useSCT && !m_spacepointsOverlapname.key().empty()) {
867 event_data.m_spacepointsOverlap=std::make_unique< SG::ReadHandle<SpacePointOverlapCollection> >(m_spacepointsOverlapname,ctx);
868 if (!event_data.m_spacepointsOverlap->isValid()) {
869 ATH_MSG_DEBUG( "Invalid overlap space points container read handle for key " << m_spacepointsOverlapname.key() );
870 }
871 else {
874
875 for (; sp!=spe; ++sp) {
876
877 ++event_data.m_nspacepoints;
878 int nk = kine(event_data,(*sp)->clusterList().first,(*sp)->clusterList().second,Kine,999);
879 for(int i=0; i!=nk; ++i) {
880 if(!isTheSameDetElement(event_data,Kine[i],(*sp))) {
881 event_data.m_kinespacepoint.insert(std::make_pair(Kine[i],(*sp)));
882 }
883 }
884 }
885 }
886 }
887}
888
889// Good kine tracks selection
891
893{
894 std::multimap<int,const Trk::PrepRawData*>::iterator c = event_data.m_kinecluster .begin();
895 std::multimap<int,const Trk::PrepRawData*>::iterator u = event_data.m_kineclusterTRT.begin();
896 std::multimap<int,const Trk::SpacePoint*>::iterator s = event_data.m_kinespacepoint.begin();
897
898 if( c == event_data.m_kinecluster.end()) {
899 return 0;
900 }
901
902 if( s == event_data.m_kinespacepoint.end()) {
903 return 0;
904 }
905
906 if( m_clcutTRT > 0 && u == event_data.m_kineclusterTRT.end()) {
907 return 0;
908 }
909
910 std::list<int> worskine;
911
912 int rp = 0;
913 int t = 0;
914 int k0 = (*c).first;
915 int q0 = k0*charge(event_data,(*c),rp);
916 unsigned int nc = 1 ;
917
918 auto coerceTo49 = [] (const size_t idx){
919 return (idx<50) ? idx : 49;
920 };
921
922 for(++c; c!=event_data.m_kinecluster.end(); ++c) {
923
924 if((*c).first==k0) {++nc; continue;}
925 q0 = charge(event_data,(*c),rp)*k0;
926 //
927 const size_t clusterIdx =coerceTo49(nc);
928 ++event_data.m_eventStat.m_particleClusters [clusterIdx];
929 ++event_data.m_eventStat.m_particleClustersBTE[clusterIdx][rp];
930 //
931 int ns = event_data.m_kinespacepoint.count(k0);
932 const size_t spacepointIdx =coerceTo49(ns);
933 ++event_data.m_eventStat.m_particleSpacePoints [spacepointIdx];
934 ++event_data.m_eventStat.m_particleSpacePointsBTE[spacepointIdx][rp];
935
936 if (nc < m_clcut ) worskine.push_back(k0);
937 else if(event_data.m_kinespacepoint.count(k0)< m_spcut ) worskine.push_back(k0);
938 else if(event_data.m_kineclusterTRT.count(k0)< m_clcutTRT) worskine.push_back(k0);
939 else {
940 event_data.m_particles[0].push_back(InDet::PartPropCache(q0,rp)); ++t;
941 }
942
943 k0 = (*c).first;
944 q0 =charge(event_data,(*c),rp)*k0;
945 nc = 1 ;
946 }
947
948 ++event_data.m_eventStat.m_particleClusters [coerceTo49(nc)];
949 ++event_data.m_eventStat.m_particleClustersBTE[coerceTo49(nc)][rp];
950 int ns = event_data.m_kinespacepoint.count(k0);
951 ++event_data.m_eventStat.m_particleSpacePoints [coerceTo49(ns)];
952 ++event_data.m_eventStat.m_particleSpacePointsBTE[coerceTo49(ns)][rp];
953
954 if (nc < m_clcut ) worskine.push_back(k0);
955 else if(event_data.m_kinespacepoint.count(k0)< m_spcut ) worskine.push_back(k0);
956 else if(event_data.m_kineclusterTRT.count(k0)< m_clcutTRT) worskine.push_back(k0);
957 else {
958 event_data.m_particles[0].push_back(InDet::PartPropCache(q0,rp)); ++t;
959 }
960 for(auto & pThisCluster: worskine) {
961 event_data.m_kinecluster .erase(pThisCluster);
962 event_data.m_kineclusterTRT.erase(pThisCluster);
963 event_data.m_kinespacepoint.erase(pThisCluster);
964 }
965
966 for(c = event_data.m_kinecluster.begin(); c!= event_data.m_kinecluster.end(); ++c) {
967 const Trk::PrepRawData*
968 d = (*c).second;
970 de= dynamic_cast<const InDetDD::SiDetectorElement*>(d->detectorElement());
971 if (not de) continue;
972 int q = charge(event_data,*c,rp);
973
974 if (q<0) {
975 if(de->isBarrel()) {
976 de->isPixel() ? ++event_data.m_eventStat.m_nclustersNegBP : ++event_data.m_eventStat.m_nclustersNegBS;
977 }
978 else {
979 de->isPixel() ? ++event_data.m_eventStat.m_nclustersNegEP : ++event_data.m_eventStat.m_nclustersNegES;
980 }
981
982 }
983 else if(q>0) {
984 if(de->isBarrel()) {
985 de->isPixel() ? ++event_data.m_eventStat.m_nclustersPosBP : ++event_data.m_eventStat.m_nclustersPosBS;
986 }
987 else {
988 de->isPixel() ? ++event_data.m_eventStat.m_nclustersPosEP : ++event_data.m_eventStat.m_nclustersPosES;
989 }
990 }
991 }
992
993
994
995 for(const auto& p: event_data.m_particles[0]) {
996 for(SG::ReadHandleKeyArray<TrackCollection>::size_type nc=1; nc<m_tracklocation.size(); ++nc) event_data.m_particles[nc].push_back(p);
997 }
998 return t;
999}
1000
1002// Recontructed track comparison with kine information
1004
1006{
1007 if(!event_data.m_nqtracks) return;
1008
1009
1010 int nc = -1;
1011 event_data.m_trackcontainer.reserve(m_tracklocation.size());
1012 for(const SG::ReadHandleKey<TrackCollection> &track_key : m_tracklocation ) {
1013 if(++nc >= 100) return;
1014 event_data.m_tracks[nc].clear();
1015
1016 event_data.m_trackcontainer.emplace_back(track_key,ctx );
1017 if (!event_data.m_trackcontainer.back().isValid()) {
1018 continue;
1019 }
1020
1021 // Loop through all found tracks
1022 //
1023 TrackCollection::const_iterator t,te = event_data.m_trackcontainer.back()->end();
1024
1025 int KINE[200],NKINE[200];
1026
1027 for (t=event_data.m_trackcontainer.back()->begin(); t!=te; ++t) {
1028
1029 Trk::TrackStates::const_iterator s = (*t)->trackStateOnSurfaces()->begin(),
1030 se = (*t)->trackStateOnSurfaces()->end();
1031
1032 int NK = 0;
1033 int NC = 0;
1034 int N0 = 0;
1035 int nkm = 0;
1036 bool qp = false;
1037
1038 const Trk::TrackParameters* tpf = (*s)->trackParameters(); if(!tpf) continue;
1039 const AmgVector(5)& Vpf = tpf ->parameters ();
1040 double pTf = std::abs(std::sin(Vpf[3])/Vpf[4]);
1041 bool qTf = pTf > m_ptcut;
1042 for(; s!=se; ++s) {
1043
1044 if(!qp) {
1045
1046 const Trk::TrackParameters* tp = (*s)->trackParameters();
1047
1048 if(tp) {
1049 qp = true;
1050 const AmgVector(5)& Vp = tp->parameters();
1051 double pT = std::sin(Vp[3])/Vp[4] ;
1052 double rap = std::abs(std::log(std::tan(.5*Vp[3])));
1053 if (pT > m_ptcut && pT < m_ptcutmax) {
1054 if (rap < 1. ) ++event_data.m_trackCollectionStat[nc].m_ntracksPOSB;
1055 else if(rap < 3.0) ++event_data.m_trackCollectionStat[nc].m_ntracksPOSE;
1056 else if(rap < m_rapcut) ++event_data.m_trackCollectionStat[nc].m_ntracksPOSFWD;
1057 }
1058 else if(pT < -m_ptcut && pT > -m_ptcutmax) {
1059 if (rap < 1. ) ++event_data.m_trackCollectionStat[nc].m_ntracksNEGB;
1060 else if(rap < 3.0) ++event_data.m_trackCollectionStat[nc].m_ntracksNEGE;
1061 else if(rap < m_rapcut) ++event_data.m_trackCollectionStat[nc].m_ntracksNEGFWD;
1062 }
1063 }
1064 }
1065
1066 if(!m_useOutliers && !(*s)->type(Trk::TrackStateOnSurface::Measurement)) continue;
1067
1068 const Trk::MeasurementBase* mb = (*s)->measurementOnTrack();
1069 if(!mb) continue;
1070
1071 const Trk::RIO_OnTrack* ri = dynamic_cast<const Trk::RIO_OnTrack*>(mb);
1072 if(!ri) continue;
1073
1074 const Trk::PrepRawData* rd = ri->prepRawData();
1075 if(!rd) continue;
1076
1077 const InDet::SiCluster* si = dynamic_cast<const InDet::SiCluster*>(rd);
1078 if(!si) continue;
1079
1080 if(!m_usePIX && dynamic_cast<const InDet::PixelCluster*>(si)) continue;
1081 if(!m_useSCT && dynamic_cast<const InDet::SCT_Cluster*> (si)) continue;
1082
1083
1084 int Kine[1000], nk=kine0(event_data,rd,Kine,999); ++NC; if(!nk) ++N0;
1085
1086 for(int k = 0; k!=nk; ++k) {
1087
1088 int n = 0;
1089 for(; n!=NK; ++n) {if(Kine[k]==KINE[n]) {++NKINE[n]; break;}}
1090 if(n==NK) {KINE[NK] = Kine[k]; NKINE[NK] = 1; if (NK < 200) ++NK;}
1091 }
1092 for(int n=0; n!=NK; ++n) {if(NKINE[n]>nkm) nkm = NKINE[n];}
1093 }
1094
1095 for(int n=0; n!=NK; ++n) {
1096 if(NKINE[n]==nkm) {
1097 int NQ = 1000*NKINE[n]+(NC-NKINE[n]);
1098
1099 event_data.m_tracks[nc].insert(std::make_pair(KINE[n],NQ));
1100 if(qTf) {
1101 if(NC-N0 > 2) {
1102 ++event_data.m_trackCollectionStat[nc].m_total[NC]; if(NC-NKINE[n] > 2) {++event_data.m_trackCollectionStat[nc].m_fake[NC];}
1103 }
1104 }
1105 }
1106 }
1107 }
1108
1109 }
1110}
1111
1113// Particles and reconstructed tracks comparision
1115
1117{
1119
1120 event_data.m_difference[nc].clear();
1121 auto p = event_data.m_particles[nc].begin(), pe =event_data.m_particles[nc].end();
1122 if(p==pe) return;
1123 std::multimap<int,int>::const_iterator t, te = event_data.m_tracks[nc].end();
1124
1125 while (p!=pe) {
1126
1127 const int uniqueID = HepMC::uniqueID(*p);
1128 int n = event_data.m_kinecluster.count(uniqueID);
1129 int m = 0;
1130 int w = 0;
1131 t = event_data.m_tracks[nc].find(uniqueID);
1132 for(; t!=te; ++t) {
1133 if((*t).first!=uniqueID) break;
1134 int ts = (*t).second/1000;
1135 int ws = (*t).second%1000;
1136 if (ts > m ) {m = ts; w = ws;}
1137 else if(ts==m && w > ws) { w = ws;}
1138 }
1139 int d = n-m; if(d<0) d = 0; else if(d > 5) d=5; if(w>4) w = 4;
1140 if(m) {
1141 ++event_data.m_trackCollectionStat[nc].m_efficiency [d];
1142 ++event_data.m_trackCollectionStat[nc].m_efficiencyN[d][w];
1143 }
1144 int ch = (*p).charge();
1145 if(m) {
1146 ++event_data.m_trackCollectionStat[nc].m_efficiencyBTE[d][w][(*p).rapidity()];
1147 ch > 0 ? ++event_data.m_trackCollectionStat[nc].m_efficiencyPOS[d] : ++event_data.m_trackCollectionStat[nc].m_efficiencyNEG[d];
1148 }
1149 if(nc==0) {
1150 ++event_data.m_eventStat.m_events; ch > 0 ? ++event_data.m_eventStat.m_eventsPOS : ++event_data.m_eventStat.m_eventsNEG;
1151 ++event_data.m_eventStat.m_eventsBTE[(*p).rapidity()];
1152 }
1153 if(d==0) event_data.m_particles[nc].erase(p++);
1154 else {event_data.m_difference[nc].push_back(n-m); ++p;}
1155 }
1156 }
1157}
1158
1160// Pointer to particle production for space point
1162
1164(const InDet::TrackClusterAssValidation::EventData_t &event_data,const Trk::PrepRawData* d1,const Trk::PrepRawData* d2,int* Kine,int nmax) const
1165{
1166 int nkine = 0;
1167 int Kine1[1000],Kine2[1000];
1168 int n1 = kine(event_data,d1,Kine1,nmax); if(!n1) return nkine;
1169 int n2 = kine(event_data,d2,Kine2,nmax); if(!n2) return nkine;
1170
1171 for(int i = 0; i!=n1; ++i) {
1172 for(int j = 0; j!=n2; ++j) {
1173 if(Kine1[i]==Kine2[j]) {Kine[nkine++] = Kine1[i]; break;}
1174 }
1175 }
1176 return nkine;
1177}
1178
1180// Pointer to particle production for cluster
1182
1184(const InDet::TrackClusterAssValidation::EventData_t &event_data,const Trk::PrepRawData* d,int* Kine,int nmax) const
1185{
1186
1187 PRD_MultiTruthCollection::const_iterator mce;
1188 PRD_MultiTruthCollection::const_iterator mc = findTruth(event_data,d,mce);
1189
1190 Identifier ID = d->identify();
1191 int nkine = 0;
1192
1193 for(; mc!=mce; ++mc) {
1194
1195 if( (*mc).first != ID ) return nkine;
1196
1197 const int uniqueID = HepMC::uniqueID((*mc).second); if(uniqueID<=0) continue;
1198
1199 const HepMC::ConstGenParticlePtr pa = (*mc).second.cptr();
1200 if(!pa or !pa->production_vertex()) continue;
1201
1202 int pdg = std::abs(pa->pdg_id()); if(m_pdg && m_pdg != pdg ) continue;
1203 if (MC::isNucleus(pdg)) continue; // ignore nuclei from hadronic interactions
1204 if (std::abs(MC::charge(pdg)) < .5) { continue; } // FIXME for fractionally charged particles
1205
1206 // pT cut
1207 //
1208 double px = pa->momentum().px();
1209 double py = pa->momentum().py();
1210 double pz = pa->momentum().pz();
1211 double pt = std::sqrt(px*px+py*py);
1212 if( pt < m_ptcut || pt > m_ptcutmax) continue;
1213
1214 // Rapidity cut
1215 //
1216 double t = std::abs(pz)/pt;
1217 if( t > m_tcut ) continue;
1218
1219 // Radius cut
1220 //
1221 double vx = pa->production_vertex()->position().x();
1222 double vy = pa->production_vertex()->position().y();
1223 double r = std::sqrt(vx*vx+vy*vy);
1224 if( r < m_rmin || r > m_rmax) continue;
1225
1226 Kine[nkine] = uniqueID; if(++nkine >= nmax) break;
1227 }
1228 return nkine;
1229}
1230
1232// Pointer to particle production for cluster
1234
1236(const InDet::TrackClusterAssValidation::EventData_t &event_data,const Trk::PrepRawData* d,int* Kine,int nmax)
1237{
1238
1239 PRD_MultiTruthCollection::const_iterator mce;
1240 PRD_MultiTruthCollection::const_iterator mc = findTruth(event_data, d,mce);
1241
1242 Identifier ID = d->identify();
1243 int nkine = 0;
1244
1245 for(; mc!=mce; ++mc) {
1246
1247 if( (*mc).first != ID ) return nkine;
1248
1249 const int uniqueID = HepMC::uniqueID((*mc).second); if(uniqueID<=0) continue;
1250 Kine[nkine] = uniqueID; if(++nkine >= nmax) break;
1251 }
1252 return nkine;
1253}
1254
1256// Test for cluster association with truth particles
1258
1261{
1262 PRD_MultiTruthCollection::const_iterator mce;
1263 PRD_MultiTruthCollection::const_iterator mc = findTruth(event_data,d,mce);
1264 return mc!=mce;
1265}
1266
1268// Test detector element
1270
1272(const InDet::TrackClusterAssValidation::EventData_t &event_data, int K,const Trk::PrepRawData* d)
1273{
1274 std::multimap<int,const Trk::PrepRawData*>::const_iterator k = event_data.m_kinecluster.find(K);
1275 for(; k!=event_data.m_kinecluster.end(); ++k) {
1276
1277 if((*k).first!= K) return false;
1278 if(d->detectorElement()==(*k).second->detectorElement()) return true;
1279 }
1280 return false;
1281}
1282
1284// Test detector element
1286
1289{
1290 const Trk::PrepRawData* p1 = sp->clusterList().first;
1291 const Trk::PrepRawData* p2 = sp->clusterList().second;
1292
1293 std::multimap<int,const Trk::SpacePoint*>::const_iterator k = event_data.m_kinespacepoint.find(K);
1294
1295 if(!p2) {
1296
1297 for(; k!=event_data.m_kinespacepoint.end(); ++k) {
1298 if((*k).first!= K) return false;
1299
1300 const Trk::PrepRawData* n1 = (*k).second->clusterList().first ;
1301 const Trk::PrepRawData* n2 = (*k).second->clusterList().second;
1302
1303 if(p1->detectorElement() == n1->detectorElement()) return true;
1304 if(!n2) continue;
1305 if(p1->detectorElement() == n2->detectorElement()) return true;
1306 }
1307 return false;
1308 }
1309
1310 for(; k!=event_data.m_kinespacepoint.end(); ++k) {
1311 if((*k).first!= K) return false;
1312
1313 const Trk::PrepRawData* n1 = (*k).second->clusterList().first ;
1314 const Trk::PrepRawData* n2 = (*k).second->clusterList().second;
1315
1316 if(p1->detectorElement() == n1->detectorElement()) return true;
1317 if(p2->detectorElement() == n1->detectorElement()) return true;
1318 if(!n2) continue;
1319 if(p1->detectorElement() == n2->detectorElement()) return true;
1320 if(p2->detectorElement() == n2->detectorElement()) return true;
1321 }
1322 return false;
1323}
1324
1326// Dump information about no recontructed particles
1328
1330{
1331
1333
1334 auto p = event_data.m_particles[nc].begin(), pe =event_data.m_particles[nc].end();
1335 if(p==pe) continue;
1336
1337 std::list<int>::const_iterator dif = event_data.m_difference[nc].begin();
1338
1339 std::multimap<int,const Trk::PrepRawData*>::const_iterator c,ce = event_data.m_kinecluster.end();
1340
1341 int n = 69-m_tracklocation[nc].key().size();
1342 std::string s1; for(int i=0; i<n; ++i) s1.append(" "); s1.append("|");
1343 std::stringstream out;
1344 out<<"|----------------------------------------------------------------------------------------|\n";
1345 out<<"| "<<m_tracklocation[nc]<<s1<<"\n";
1346 out<<"|----------------------------------------------------------------------------------------|\n";
1347 out<<"| # pdg kine Ncl Ntr Nsp Lose pT(MeV) rapidity radius z |\n";
1348 out<<"|----------------------------------------------------------------------------------------|\n";
1349
1350 n = 0;
1351 for(; p!=pe; ++p) {
1352
1353 const int uniqueID = HepMC::uniqueID(*p);
1354
1355 c = event_data.m_kinecluster.find(uniqueID); if(c==ce) continue;
1356 const Trk::PrepRawData* d = (*c).second;
1357
1358 PRD_MultiTruthCollection::const_iterator mce;
1359 PRD_MultiTruthCollection::const_iterator mc = findTruth(event_data,d,mce);
1360
1361 Identifier ID = d->identify();
1362 bool Q = false;
1363 for(; mc!=mce; ++mc) {
1364 if((*mc).first != ID) break;
1365 if(HepMC::uniqueID((*mc).second)==uniqueID) {Q=true; break;}
1366 }
1367
1368 if(!Q) continue;
1369
1370 const HepMC::ConstGenParticlePtr pa = (*mc).second.cptr();
1371
1372 double px = pa->momentum().px();
1373 double py = pa->momentum().py();
1374 double pz = pa->momentum().pz();
1375 double vx = pa->production_vertex()->position().x();
1376 double vy = pa->production_vertex()->position().y();
1377 double vz = pa->production_vertex()->position().z();
1378 double pt = std::sqrt(px*px+py*py);
1379 double t = std::atan2(pt,pz);
1380 double ra =-std::log(std::tan(.5*t));
1381 double r = std::sqrt(vx*vx+vy*vy);
1382 ++n;
1383 out<<"| "
1384 <<std::setw(4)<<n
1385 <<std::setw(6)<<pa->pdg_id()
1386 <<std::setw(10)<<HepMC::barcode(pa)
1387 <<std::setw(4)<<event_data.m_kinecluster .count(uniqueID)
1388 <<std::setw(4)<<event_data.m_kineclusterTRT.count(uniqueID)
1389 <<std::setw(4)<<event_data.m_kinespacepoint.count(uniqueID)
1390 <<std::setw(4)<<(*dif)
1391 <<std::setw(12)<<std::setprecision(5)<<pt
1392 <<std::setw(12)<<std::setprecision(5)<<ra
1393 <<std::setw(12)<<std::setprecision(5)<<r
1394 <<std::setw(12)<<std::setprecision(5)<<vz
1395 <<" |\n";
1396 ++dif;
1397
1398 }
1399 out<<"|----------------------------------------------------------------------------------------|\n";
1400 ATH_MSG_INFO("\n"<<out.str());
1401 }
1402 return true;
1403}
1404
1406// Cluster truth information
1408
1409PRD_MultiTruthCollection::const_iterator
1412 const Trk::PrepRawData* d,
1413 PRD_MultiTruthCollection::const_iterator& mce)
1414{
1415 const InDet::SCT_Cluster * si = dynamic_cast<const InDet::SCT_Cluster*> (d);
1416 const InDet::PixelCluster * px = dynamic_cast<const InDet::PixelCluster*> (d);
1417 const InDet::TRT_DriftCircle* tr = dynamic_cast<const InDet::TRT_DriftCircle*>(d);
1418
1419 PRD_MultiTruthCollection::const_iterator mc;
1420
1421 if (px && event_data.m_truthPIX) {mc=event_data.m_truthPIX->find(d->identify()); mce=event_data.m_truthPIX->end();}
1422 else if(si && event_data.m_truthSCT) {mc=event_data.m_truthSCT->find(d->identify()); mce=event_data.m_truthSCT->end();}
1423 else if(tr && event_data.m_truthTRT) {mc=event_data.m_truthTRT->find(d->identify()); mce=event_data.m_truthTRT->end();}
1424 else {
1425 const PRD_MultiTruthCollection *truth[] {event_data. m_truthPIX,event_data.m_truthSCT, event_data.m_truthTRT};
1426 for (int i=0; i<3; i++) {
1427 if (truth[i]) {
1428 mce=truth[i]->end();
1429 return truth[i]->end();
1430 }
1431 }
1432 throw std::runtime_error("Neither Pixel, SCT nor TRT truth.");
1433 }
1434 return mc;
1435}
1436
1438// Cluster truth information
1440
1441int InDet::TrackClusterAssValidation::charge(const InDet::TrackClusterAssValidation::EventData_t &event_data,std::pair<int,const Trk::PrepRawData*> pa,int& rap) const
1442{
1443 const int uniqueID = pa.first;
1444 const Trk::PrepRawData* d = pa.second;
1445 PRD_MultiTruthCollection::const_iterator mce;
1446 PRD_MultiTruthCollection::const_iterator mc = findTruth(event_data,d,mce);
1447
1448 for(; mc!=mce; ++mc) {
1449 if(HepMC::uniqueID((*mc).second)==uniqueID) {
1450
1451 const HepMC::ConstGenParticlePtr pat = (*mc).second.cptr();
1452
1453 rap = 0;
1454 double px = pat->momentum().px();
1455 double py = pat->momentum().py();
1456 double pz = pat->momentum().pz();
1457 double pt = std::sqrt(px*px+py*py) ;
1458 double t = std::atan2(pt,pz) ;
1459 double ra = std::abs(std::log(std::tan(.5*t)));
1460 // Forward
1461 if (ra > 3.0)
1462 rap = 3;
1463 else
1464 // other regions
1465 ra > 1.6 ? rap = 2 : ra > .8 ? rap = 1 : rap = 0;
1466
1467 int pdg = pat->pdg_id();
1468 if (MC::isNucleus(pdg)) { return 0; } // ignore nuclei from hadronic interactions
1469 const double ch = MC::charge(pdg);
1470 if(ch > .5) return 1;
1471 if(ch < -.5) return -1;
1472 return 0;
1473 }
1474 }
1475 return 0;
1476}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
#define AmgVector(rows)
std::string formatOutput(std::string_view title, const IdDictFieldImplementation &idDictFieldImp)
ATLAS-specific HepMC functions.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
ReadCards * rp
static Double_t sp
static Double_t sc
const int nmax(200)
Handle class for reading from StoreGate.
size_t size() const
Number of registered mappings.
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
Class to hold geometrical description of a silicon detector element.
static MsgStream & dumpevent(MsgStream &out, const InDet::TrackClusterAssValidation::EventData_t &event_data)
void tracksComparison(const EventContext &ctx, InDet::TrackClusterAssValidation::EventData_t &event_data) const
static bool isTruth(const InDet::TrackClusterAssValidation::EventData_t &, const Trk::PrepRawData *)
SG::ReadHandleKey< SpacePointContainer > m_spacepointsSCTname
SG::ReadHandleKey< SpacePointOverlapCollection > m_spacepointsOverlapname
MsgStream & dumptools(MsgStream &out, MSG::Level level) const
SG::ReadHandleKey< PRD_MultiTruthCollection > m_truth_locationPixel
SG::ReadHandleKeyArray< TrackCollection > m_tracklocation
bool noReconstructedParticles(const InDet::TrackClusterAssValidation::EventData_t &event_data) const
static int kine0(const InDet::TrackClusterAssValidation::EventData_t &event_data, const Trk::PrepRawData *, int *, int)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
SG::ReadHandleKey< SiClusterContainer > m_clustersPixelname
int charge(const InDet::TrackClusterAssValidation::EventData_t &event_data, std::pair< int, const Trk::PrepRawData * >, int &) const
void efficiencyReconstruction(InDet::TrackClusterAssValidation::EventData_t &event_data) const
StatusCode execute(const EventContext &ctx) const
SG::ReadHandleKey< PRD_MultiTruthCollection > m_truth_locationTRT
int qualityTracksSelection(InDet::TrackClusterAssValidation::EventData_t &event_data) const
void newSpacePointsEvent(const EventContext &ctx, InDet::TrackClusterAssValidation::EventData_t &event_data) const
static PRD_MultiTruthCollection::const_iterator findTruth(const InDet::TrackClusterAssValidation::EventData_t &event_data, const Trk::PrepRawData *, PRD_MultiTruthCollection::const_iterator &)
void newClustersEvent(const EventContext &ctx, InDet::TrackClusterAssValidation::EventData_t &event_data) const
SG::ReadHandleKey< TRT_DriftCircleContainer > m_clustersTRTname
SG::ReadHandleKey< SpacePointContainer > m_spacepointsPixelname
SG::ReadHandleKey< SiClusterContainer > m_clustersSCTname
SG::ReadHandleKey< PRD_MultiTruthCollection > m_truth_locationSCT
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
int kine(const InDet::TrackClusterAssValidation::EventData_t &event_data, const Trk::PrepRawData *, const Trk::PrepRawData *, int *, int) const
static bool isTheSameDetElement(const InDet::TrackClusterAssValidation::EventData_t &event_data, int, const Trk::PrepRawData *)
A PRD is mapped onto all contributing particles.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
This class is the pure abstract base class for all fittable tracking measurements.
virtual const TrkDetElementBase * detectorElement() const =0
return the detector element corresponding to this PRD The pointer will be zero if the det el is not d...
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
int ts
Definition globals.cxx:24
int r
Definition globals.cxx:22
int barcode(const T *p)
Definition Barcode.h:15
int uniqueID(const T &p)
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
double charge(const T &p)
bool isNucleus(const T &p)
PDG rule 16 Nuclear codes are given as 10-digit numbers ±10LZZZAAAI.
HandleKeyArray< ReadHandle< T >, ReadHandleKey< T >, Gaudi::DataHandle::Reader > ReadHandleKeyArray
ParametersBase< TrackParametersDim, Charged > TrackParameters
std::vector< SG::ReadHandle< TrackCollection > > m_trackcontainer
std::vector< std::list< PartPropCache > > m_particles
std::multimap< int, const Trk::PrepRawData * > m_kinecluster
std::vector< std::multimap< int, int > > m_tracks
std::vector< TrackCollectionStat_t > m_trackCollectionStat
std::vector< std::unique_ptr< SG::VarHandleBase > > m_clusterHandles
std::multimap< int, const Trk::PrepRawData * > m_kineclusterTRT
std::vector< SG::ReadHandle< SpacePointContainer > > m_spacePointContainer
std::unique_ptr< SG::ReadHandle< SpacePointOverlapCollection > > m_spacepointsOverlap
std::multimap< int, const Trk::SpacePoint * > m_kinespacepoint