ATLAS Offline Software
TRT_ElectronPidToolRun2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TRT_ElectronPidToolRun2.cxx, (c) ATLAS Detector software
8 
9 
12 
13 // StoreGate, Athena, and Database stuff:
14 #include "Identifier/Identifier.h"
17 #include "CoralBase/AttributeListSpecification.h"
18 #include "CoralBase/Blob.h"
21 
22 // Tracking:
23 #include "TrkTrack/Track.h"
29 #include "TrkSurfaces/Surface.h"
30 #include "TrkTrack/TrackInfo.h"
31 
32 // Drift circles and TRT identifiers:
34 #include "InDetIdentifier/TRT_ID.h"
35 
36 // ToT Tool Interface
38 
39 // For the track length in straw calculations
40 #include "TRT_ToT_dEdx.h"
41 
42 
43 // Math functions:
44 #include <cmath>
45 
46 //STL includes
47 #include <sstream>
48 
49 
50 // Helper method to store NN input variables into maps
51 template <typename T>
52 void storeNNVariable(std::map<std::string, T>& theMap, const std::string& name, const T& value) {
53  auto it = theMap.find(name);
54  if (it != theMap.end()) {
55  it->second = value;
56  }
57 }
58 
59 
60 
61 /*****************************************************************************\
62 |*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*|
63 |*%%% PID Tool Constructor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*|
64 |*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*|
65 \*****************************************************************************/
66 
67 InDet::TRT_ElectronPidToolRun2::TRT_ElectronPidToolRun2(const std::string& t, const std::string& n, const IInterface* p )
68  :
69  AthAlgTool(t,n,p),
70  m_trtId(nullptr),
71  m_minTRThits(5),
72  m_ptMinNN(2000.),
73  m_calculateNN(true)
74 {
75  declareInterface<ITRT_ElectronPidTool>(this);
76  declareInterface<ITRT_ElectronToTTool>(this);
77  declareProperty("MinimumTRThitsForIDpid", m_minTRThits);
78  declareProperty("MinimumTrackPtForNNPid", m_ptMinNN);
79  declareProperty("CalculateNNPid", m_calculateNN);
80 }
81 
82 
83 /*****************************************************************************\
84 |*%%% PID Tool Destructor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*|
85 \*****************************************************************************/
86 
88 = default;
89 
90 /*****************************************************************************\
91 |*%%% Initialisation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*|
92 \*****************************************************************************/
93 
95 {
97  if (sc.isFailure()) return sc;
98 
99  // Get the TRT Identifier-helper:
100  CHECK (detStore()->retrieve(m_trtId, "TRT_ID"));
101 
102  /* Get the TRT_ToT_dEdx tool */
103  CHECK( m_TRTdEdxTool.retrieve() );
104 
105  CHECK( m_LocalOccTool.retrieve() );
106 
108 
110 
111  CHECK( m_TRTStrawSummaryTool.retrieve() );
112 
113  return StatusCode::SUCCESS;
114 }
115 
116 
117 
118 /*****************************************************************************\
119 |*%%% Finalisation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*|
120 \*****************************************************************************/
121 
123 {
124  return AthAlgTool::finalize();
125 }
126 
127 // Kept for backward compatibility.
128 // See TRT_ElectronPidTools-01-00-28 for the full (commented) code.
130 {
131  // Simply return values without calculation
132  std::vector<float> PIDvalues = Trk::eProbabilityDefault;
133  const Trk::TrackParameters* perigee = track.perigeeParameters();
134  if (!perigee) { return PIDvalues; }
135  return PIDvalues;
136 }
137 
138 
139 /*****************************************************************************\
140 |*%%% electronProbability - The interface method during reconstruction %%%%*|
141 \*****************************************************************************/
142 
143 std::vector<float>
145  const EventContext& ctx,
146  const Trk::Track& track) const
147 {
148 
149  // Get the probability calculator
151  const HTcalculator* HTcalc = (*readHandle);
152  // make sure some calibration is available
153  if(HTcalc==nullptr) {
154  ATH_MSG_WARNING (" No Pid calibration from the DB.");
155  }
156 
157  // Get the PID NN
158  const InDet::TRTPIDNN* PIDNN = nullptr;
159  if (m_calculateNN) {
161  PIDNN = (*readHandlePIDNN);
162  // make sure some calibration is available
163  if(PIDNN==nullptr) {
164  ATH_MSG_WARNING (" No PID NN available from the DB.");
165  }
166  }
167 
168  // Initialize the vector with default PID values
169  std::vector<float> PIDvalues = Trk::eProbabilityDefault;
170 
171  // Check for perigee:
172  const Trk::TrackParameters* perigee = track.perigeeParameters();
173  if (!perigee) return PIDvalues;
174 
175  // Get parameters at perigee and check that they are reasonable:
176  const AmgVector(Trk::TrackParameters::dim)& parameterVector = perigee->parameters();
177  double qOverP = parameterVector[Trk::qOverP];
178  double theta = parameterVector[Trk::theta];
179  double phi = parameterVector[Trk::phi];
180 
181  // Check the parameters are reasonable:
182  if (tan(theta/2.0) < 0.0001) {
183  ATH_MSG_DEBUG(" Track has negative theta or is VERY close to beampipe! "
184  "(tan(theta/2) < 0.0001). Returning default Pid values.");
185  return PIDvalues;
186  }
187 
188  if (qOverP == 0.0) {
189  ATH_MSG_DEBUG (" Track momentum infinite! (i.e. q/p = 0). Returning default Pid values.");
190  return PIDvalues;
191  }
192 
193  double pTrk = fabs(1.0 / qOverP);
194  double pT = pTrk * sin(theta);
195  double eta = -log(tan(theta/2.0));
196 
197  // Check the tool to get the local occupancy (i.e. for the track in question):
198  PIDvalues[Trk::TRTTrackOccupancy] = m_LocalOccTool->LocalOccupancy(ctx,track);
199 
200  if (PIDvalues[Trk::TRTTrackOccupancy] > 1.0 || PIDvalues[Trk::TRTTrackOccupancy] < 0.0) {
201  ATH_MSG_WARNING(" Occupancy was outside allowed range! Returning default Pid values. Occupancy = "
202  << PIDvalues[Trk::TRTTrackOccupancy] );
203  return PIDvalues;
204  }
205 
206  ATH_MSG_DEBUG ("");
207  ATH_MSG_DEBUG ("");
208  ATH_MSG_DEBUG ("check---------------------------------------------------------------------------------------");
209  ATH_MSG_DEBUG ("check Got track: pT: " << pT << " eta: " << eta << " phi: " << phi);
210  ATH_MSG_DEBUG ("check---------------------------------------------------------------------------------------");
211 
212  // For calculation of HT probability:
213  double pHTel_prod = 1.0;
214  double pHTpi_prod = 1.0;
215 
216  // ------------------------------------------------------------------------------------
217  // Loop over TRT hits on track, and calculate HT and R-ToT probability:
218  // ------------------------------------------------------------------------------------
219 
220  std::vector<double> hit_HTMB;
221  std::vector<double> hit_gasType;
222  std::vector<double> hit_tot;
223  std::vector<double> hit_L;
224  std::vector<double> hit_rTrkWire;
225  std::vector<double> hit_HitZ;
226  std::vector<double> hit_HitR;
227  std::vector<double> hit_isPrec;
228 
229  unsigned int nTRThits = 0;
230  unsigned int nTRThitsHTMB = 0;
231  unsigned int nXehits = 0;
232  unsigned int nArhits = 0;
233  unsigned int nPrecHits = 0;
234 
235 
236  // Check for track states:
237  const Trk::TrackStates* recoTrackStates = track.trackStateOnSurfaces();
238  if (not recoTrackStates) {
239  ATH_MSG_DEBUG("track.trackStateOnSurfaces() was zero");
240  //m_timingProfile->chronoStop("Tool::electronProb");
241  return PIDvalues;
242  }
243 
244  Trk::TrackStates::const_iterator tsosIter = recoTrackStates->begin();
245  Trk::TrackStates::const_iterator tsosIterEnd = recoTrackStates->end();
246 
247  // Loop over track states on surfaces (i.e. generalized hits):
248  for ( ; tsosIter != tsosIterEnd; ++tsosIter) {
249 
250  const Trk::MeasurementBase *measurement = (*tsosIter)->measurementOnTrack();
251  if (!measurement) continue;
252 
253  // Get drift circle (ensures that hit is from TRT):
254  // use the type methods to avoid dynamic_cast in a loop
255  const InDet::TRT_DriftCircleOnTrack* driftcircle = nullptr;
256  if (measurement->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
257  const Trk::RIO_OnTrack* tmpRio =
258  static_cast<const Trk::RIO_OnTrack*>(measurement);
260  driftcircle = static_cast<const InDet::TRT_DriftCircleOnTrack*>(tmpRio);
261  }
262  }
263 
264  if (!driftcircle) continue;
265 
266  // From now (May 2015) onwards, we ONLY USE MIDDLE HT BIT:
267  bool isHTMB = (driftcircle->prepRawData()->getWord() & 0x00020000) > 0;
268 
269  nTRThits++;
270  if (isHTMB) nTRThitsHTMB++;
271  hit_HTMB.push_back(static_cast<double>(isHTMB));
272 
273 
274  // ------------------------------------------------------------------------------------
275  // Get the necessary input for the probability calculations:
276  // ------------------------------------------------------------------------------------
277  Identifier DCid = driftcircle->identify();
278 
279  // Part of TRT hit belongs to (TrtPart = 0: Barrel, 1: EndcapA, 2: EndcapB).
280  int TrtPart = 0; // 0: Barrel, 1: EndcapA, 2: EndcapB
281  if (abs(m_trtId->barrel_ec(DCid)) == 2)
282  TrtPart = (m_trtId->layer_or_wheel(DCid) < 6) ? 1 : 2;
283 
284  // Get Straw Layer (Barrel: 0-72, EndcapA: 0-95 (16 layers in 6 modules), EndcapB: 0-63 (8 layers in 8 modules)):
285  int StrawLayer = 0;
286  if (TrtPart == 0) {
287  // Barrel:
288  if (m_trtId->layer_or_wheel(DCid) == 0) {
289  StrawLayer = m_trtId->straw_layer(DCid);
290  } else if (m_trtId->layer_or_wheel(DCid) == 1) {
291  StrawLayer = 19 + m_trtId->straw_layer(DCid);
292  } else {
293  StrawLayer = 19 + 24 + m_trtId->straw_layer(DCid);
294  }
295  } else {
296  // Endcap:
297  if (m_trtId->layer_or_wheel(DCid) < 6) {
298  StrawLayer =
299  16 * m_trtId->layer_or_wheel(DCid) + m_trtId->straw_layer(DCid);
300  } else {
301  StrawLayer =
302  8 * (m_trtId->layer_or_wheel(DCid) - 6) + m_trtId->straw_layer(DCid);
303  }
304  }
305 
306  // Get Z (Barrel) or R (Endcap) location of the hit, and distance from track to wire (i.e. anode) in straw:
307  double HitZ = 0.;
308  double HitR = 0.;
309  double rTrkWire = 0.;
310  bool hasTrackParameters = true; // Keep track of this for HT prob calculation
311  if ((*tsosIter)->trackParameters()) {
312  // If we have precise information (from hit), get that:
313  const Amg::Vector3D& gp = driftcircle->globalPosition();
314  HitR = gp.perp();
315  HitZ = gp.z();
316  rTrkWire = fabs((*tsosIter)->trackParameters()->parameters()[Trk::driftRadius]);
317  if (rTrkWire > 2.2) rTrkWire = 2.175; // cut off track-to-wire distance for outliers
318  } else {
319  // Otherwise just use the straw coordinates:
320  hasTrackParameters = false; // Jared - pass this to HT calculation
321  HitZ = driftcircle->associatedSurface().center().z();
322  HitR = driftcircle->associatedSurface().center().perp();
323  rTrkWire = 0;
324  }
325 
326  // fill vectors for NN PID
327  if (m_calculateNN and pT >= m_ptMinNN) {
328  hit_HitZ.push_back(HitZ);
329  hit_HitR.push_back(HitR);
330  hit_rTrkWire.push_back(rTrkWire);
331  hit_L.push_back(TRT_ToT_dEdx::calculateTrackLengthInStraw((*tsosIter), m_trtId));
332  hit_tot.push_back(driftcircle->timeOverThreshold());
333  }
334 
335  // ------------------------------------------------------------------------------------
336  // Collection and checks of input variables for HT probability calculation:
337  // ------------------------------------------------------------------------------------
338 
339  int SL_max[3] = {73, 96, 64};
340  if (StrawLayer > SL_max[TrtPart] || StrawLayer < 0) {
341  ATH_MSG_WARNING(" StrawLayer was outside allowed range! TrtPart = " << TrtPart << " SL = " << StrawLayer);
342  continue;
343  }
344 
345  double ZRpos[3] = {fabs(HitZ), HitR, HitR};
346  double ZRpos_min[3] = { 0.0, 630.0, 630.0};
347  double ZRpos_max[3] = {720.0, 1030.0, 1030.0};
348  if (ZRpos[TrtPart] > ZRpos_max[TrtPart]) {
349  ATH_MSG_WARNING(" ZRpos was above allowed range - adjusted! TrtPart = " << TrtPart << " ZRpos = " << ZRpos[TrtPart]);
350  ZRpos[TrtPart] = ZRpos_max[TrtPart] - 0.001;
351  }
352  if (ZRpos[TrtPart] < ZRpos_min[TrtPart]) {
353  ATH_MSG_WARNING(" ZRpos was below allowed range - adjusted! TrtPart = " << TrtPart << " ZRpos = " << ZRpos[TrtPart]);
354  ZRpos[TrtPart] = ZRpos_min[TrtPart] + 0.001;
355  }
356 
357  // ------------------------------------------------------------------------------------
358  // Calculate the HT probability:
359  // ------------------------------------------------------------------------------------
360 
361  // getStatusHT returns enum {Undefined, Dead, Good, Xenon, Argon, Krypton, EmulatedArgon, EmulatedKrypton}.
362  // Our representation of 'GasType' is 0:Xenon, 1:Argon, 2:Krypton
363  int GasType=0; // Xenon is default
364  if (!m_TRTStrawSummaryTool.empty()) {
365  int stat = m_TRTStrawSummaryTool->getStatusHT(DCid,ctx);
366  if ( stat==2 || stat==3 ) { GasType = 0; } // Xe
367  else if ( stat==1 || stat==4 ) { GasType = 1; } // Ar
368  else if ( stat==5 ) { GasType = 1; } // Kr -- ESTIMATED AS AR UNTIL PID IS TUNED TO HANDLE KR
369  else if ( stat==6 ) { GasType = 1; } // Emulated Ar
370  else if ( stat==7 ) { GasType = 1;
371  } // Emulated Kr -- ESTIMATED AS AR UNTIL PID IS TUNED TO HANDLE KR
372  else {
374  "getStatusHT = "
375  << stat
376  << ", must be 'Good(2)||Xenon(3)' or 'Dead(1)||Argon(4)' or "
377  "'Krypton(5)' or 'EmulatedArgon(6)' or 'EmulatedKr(7)'!");
378  throw std::exception();
379  }
380  }
381 
382  ATH_MSG_DEBUG("check Hit: "
383  << nTRThits << " TrtPart: " << TrtPart
384  << " GasType: " << GasType << " SL: " << StrawLayer
385  << " ZRpos: " << ZRpos[TrtPart] << " TWdist: " << rTrkWire
386  << " Occ_Local: " << PIDvalues[Trk::TRTTrackOccupancy] << " HTMB: " << isHTMB);
387 
388  if (m_calculateNN and pT >= m_ptMinNN) {
389  // RNN gas type observables
390  hit_gasType.push_back(static_cast<double>(GasType));
391  if (GasType == 0) {
392  nXehits++;
393  } else if (GasType == 1) {
394  nArhits++;
395  }
396 
397  // RNN hit preciion observables
398  float errDc = sqrt(driftcircle->localCovariance()(Trk::driftRadius, Trk::driftRadius));
399  bool isPrec = false;
400  if (errDc < 1.0) {
401  isPrec = true;
402  nPrecHits++;
403  }
404  hit_isPrec.push_back(static_cast<double>(isPrec));
405  }
406 
407  // Then call pHT functions with these values:
408  // ------------------------------------------
409 
410  double pHTel = HTcalc->getProbHT(pTrk,
412  TrtPart,
413  GasType,
414  StrawLayer,
415  ZRpos[TrtPart],
416  rTrkWire,
417  PIDvalues[Trk::TRTTrackOccupancy] ,
418  hasTrackParameters);
419  double pHTpi = HTcalc->getProbHT(pTrk,
420  Trk::pion,
421  TrtPart,
422  GasType,
423  StrawLayer,
424  ZRpos[TrtPart],
425  rTrkWire,
426  PIDvalues[Trk::TRTTrackOccupancy] ,
427  hasTrackParameters);
428 
429  if (pHTel > 0.999 || pHTpi > 0.999 || pHTel < 0.001 || pHTpi < 0.001) {
430  ATH_MSG_DEBUG(" pHT outside allowed range! pHTel = "
431  << pHTel << " pHTpi = " << pHTpi
432  << " TrtPart: " << TrtPart << " SL: " << StrawLayer
433  << " ZRpos: " << ZRpos[TrtPart] << " TWdist: " << rTrkWire
434  << " Occ_Local: " << PIDvalues[Trk::TRTTrackOccupancy] );
435  continue;
436  }
437 
438  if (pHTel > 0.80 || pHTpi > 0.50 || pHTel < 0.025 || pHTpi < 0.010) {
439  ATH_MSG_DEBUG(" pHT has abnormal value! pHTel = "
440  << pHTel << " pHTpi = " << pHTpi
441  << " TrtPart: " << TrtPart << " SL: " << StrawLayer
442  << " ZRpos: " << ZRpos[TrtPart] << " TWdist: " << rTrkWire
443  << " Occ_Local: " << PIDvalues[Trk::TRTTrackOccupancy] );
444  continue;
445  }
446 
447  // From now (May 2015) onwards, we ONLY USE MIDDLE HT BIT:
448  if (isHTMB) {pHTel_prod *= pHTel; pHTpi_prod *= pHTpi;}
449  else {pHTel_prod *= 1.0-pHTel; pHTpi_prod *= 1.0-pHTpi;}
450  ATH_MSG_DEBUG ("check pHT(el): " << pHTel << " pHT(pi): " << pHTpi );
451 
452  } // end of loop over hits
453 
454 
455  // If number of hits is adequate (default is 5 hits), calculate HT and ToT probability.
456  if (not (nTRThits >= m_minTRThits)) return PIDvalues;
457 
458  // Calculate electron probability (HT)
459  PIDvalues[Trk::eProbabilityHT] = pHTel_prod / (pHTel_prod + pHTpi_prod);
460 
461  ATH_MSG_DEBUG ("check nTRThits: " << nTRThits << " : " << nTRThitsHTMB
462  << " pHTel_prod: " << pHTel_prod
463  << " pHTpi_prod: " << pHTpi_prod
464  << " probEl: " << PIDvalues[Trk::eProbabilityHT]);
465 
466  PIDvalues[Trk::TRTdEdx] = m_TRTdEdxTool->dEdx(
467  ctx,
468  &track,
469  true, //be expicit as optional below can be converted to bool
470  PIDvalues[Trk::TRTTrackOccupancy]); // default dEdx using all hits
471 
473  m_TRTdEdxTool->usedHits(ctx, &track);
474  double dEdx_noHTHits = m_TRTdEdxTool->dEdx(
475  ctx,
476  &track,
477  false,//be expicit as optional below can be converted to bool
478  PIDvalues[Trk::TRTTrackOccupancy]); // Divide by L, exclude HT hits
479 
480  double dEdx_usedHits_noHTHits = m_TRTdEdxTool->usedHits(ctx, &track, false);
481  PIDvalues[Trk::eProbabilityToT] = m_TRTdEdxTool->getTest(
482  ctx, dEdx_noHTHits, pTrk, Trk::electron, Trk::pion, dEdx_usedHits_noHTHits);
483 
484  // Limit the probability values the upper and lower limits that are given/trusted for each part:
485  double limProbHT = HTcalculator::Limit(PIDvalues[Trk::eProbabilityHT]);
486  double limProbToT = HTcalculator::Limit(PIDvalues[Trk::eProbabilityToT]);
487 
488  // Calculate the combined probability, assuming no correlations (none are expected).
489  PIDvalues[Trk::eProbabilityComb] =
490  (limProbHT * limProbToT) /
491  ((limProbHT * limProbToT) + ((1.0 - limProbHT) * (1.0 - limProbToT)));
492 
493  // Troels: VERY NASTY NAMING, BUT AGREED UPON FOR NOW (for debugging, 27. NOV. 2014):
494  PIDvalues[Trk::eProbabilityBrem] = pHTel_prod; // decorates electron LH to el brem for now... (still used?)
495 
496  if (!m_calculateNN or pT < m_ptMinNN) {
497  return PIDvalues;
498  }
499 
500  // Calculate RNN PID score
501  std::map<std::string, std::map<std::string, double>> scalarInputs_NN = PIDNN->getScalarInputs();
502  std::map<std::string, std::map<std::string, std::vector<double>>> vectorInputs_NN = PIDNN->getVectorInputs();
503 
504  // Calculate the hit fraction
505  double fAr = static_cast<double>(nArhits) / nTRThits;
506  double fHTMB = static_cast<double>(nTRThitsHTMB) / nTRThits;
507  double PHF = static_cast<double>(nPrecHits) / nTRThits;
508 
509  if (!scalarInputs_NN.empty()) {
510  std::map<std::string, double>& trackVarMap = scalarInputs_NN.begin()->second;
511  storeNNVariable(trackVarMap, "trkOcc", static_cast<double>(PIDvalues[Trk::TRTTrackOccupancy]));
512  storeNNVariable(trackVarMap, "p", pTrk);
513  storeNNVariable(trackVarMap, "pT", pT);
514  storeNNVariable(trackVarMap, "nXehits", static_cast<double>(nXehits));
515  storeNNVariable(trackVarMap, "fAr", fAr);
516  storeNNVariable(trackVarMap, "fHTMB", fHTMB);
517  storeNNVariable(trackVarMap, "PHF", PHF);
518  storeNNVariable(trackVarMap, "dEdx", static_cast<double>(dEdx_noHTHits));
519  }
520 
521  if (!vectorInputs_NN.empty()) {
522  std::map<std::string, std::vector<double>>& hitVarMap = vectorInputs_NN.begin()->second;
523  storeNNVariable(hitVarMap, "hit_HTMB", hit_HTMB);
524  storeNNVariable(hitVarMap, "hit_gasType", hit_gasType);
525  storeNNVariable(hitVarMap, "hit_tot", hit_tot);
526  storeNNVariable(hitVarMap, "hit_L", hit_L);
527  storeNNVariable(hitVarMap, "hit_rTrkWire", hit_rTrkWire);
528  storeNNVariable(hitVarMap, "hit_HitZ", hit_HitZ);
529  storeNNVariable(hitVarMap, "hit_HitR", hit_HitR);
530  storeNNVariable(hitVarMap, "hit_isPrec", hit_isPrec);
531  }
532  PIDvalues[Trk::eProbabilityNN] = PIDNN->evaluate(scalarInputs_NN, vectorInputs_NN);
533 
534  ATH_MSG_DEBUG ("check NN PID calculation: ");
535  for (const auto& scalarInputs : scalarInputs_NN) {
536  ATH_MSG_DEBUG (" scalar inputs: " << scalarInputs.first);
537  for (const auto& variable : scalarInputs.second) {
538  ATH_MSG_DEBUG (" " << variable.first << " = " << variable.second);
539  }
540  }
541  for (const auto& vectorInputs : vectorInputs_NN) {
542  ATH_MSG_DEBUG (" vector inputs: " << vectorInputs.first);
543  for (const auto& variable : vectorInputs.second) {
544  ATH_MSG_DEBUG (" " << variable.first << " = " << variable.second);
545  }
546  }
547  ATH_MSG_DEBUG (" eProbilityNN: " << PIDvalues[Trk::eProbabilityNN]);
548 
549  return PIDvalues;
550 }
551 
552 /*****************************************************************************\
553 |*%%% TRT straw address check, done once per hit. %%%%%%%%%%%%%%%%%%%%%%%%%*|
554 |*%%% Nowhere else are these numbers checked. If this is deemed %%%%%%%%%%%*|
555 |*%%% unnecessary it can be taken out by simply letting the function %%%%%%%*|
556 |*%%% return true every time %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*|
557 \*****************************************************************************/
558 
559 bool InDet::TRT_ElectronPidToolRun2::CheckGeometry(int BEC, int Layer, int StrawLayer) const {
560 
561  //first check that the BEC is valid:
562  if( BEC!=-2 && BEC !=-1 && BEC!=1 && BEC!=2){
563  ATH_MSG_ERROR("Found a wrong TRT part: "<<BEC<<" expected one of (-2,-1,1,2)");
564  return false;
565  }
566  const int part = abs(BEC)-1;
567 
568  //next check that the layer is valid
569  if( Layer < 0){
570  ATH_MSG_ERROR("Found a negative TRT Layer");
571  return false; //must be positive
572  }
573 
574  static const int nlayers[2]={3,14};
575 
576  if( not ( Layer < nlayers[part] ) ){
577  ATH_MSG_ERROR("Found TRT Layer index "<<Layer<<" in part "<<BEC<<" but part only has "<<nlayers[part]<<" layers.");
578  return false;
579  }
580 
581  //and finally check that the StrawLayer is valid:
582  if( StrawLayer < 0){
583  ATH_MSG_ERROR("Found a negative TRT StrawLayer");
584  return false; //must be positive
585  }
586 
587  static const int strawsPerBEC[2][14]={{19,24,30, 0, 0, 0,0,0,0,0,0,0,0,0},
588  {16,16,16,16,16,16,8,8,8,8,8,8,8,8}};
589 
590  if(not(StrawLayer < strawsPerBEC[part][Layer])){
591  ATH_MSG_ERROR("TRT part " << BEC << " Layer " << Layer << " only has "
592  << strawsPerBEC[part][Layer]
593  << " straws. Found index " << StrawLayer);
594  return false;
595  }
596 
597  return true;
598 }
599 
600 /*****************************************************************************\
601 |*%%% Auxiliary function to return the HT probability to Atlfast %%%%%%%%%%*|
602 |*%%% a geometry check is performed every time here %%%%%%%%%%%%%%%%%%%%%%%*|
603 \*****************************************************************************/
604 
605 double
607  const double /*pTrk*/,
608  const Trk::ParticleHypothesis /*hypothesis*/,
609  const int HitPart,
610  const int Layer,
611  const int StrawLayer) const
612 {
613  if (not CheckGeometry(HitPart,Layer,StrawLayer) ){
614  ATH_MSG_ERROR("TRT geometry fail. Returning default value.");
615  return 0.5;
616  }
617 
618  return 1.0;
619 }
620 
621 double
623  float pTrk,
624  Trk::ParticleHypothesis hypothesis,
625  int TrtPart,
626  int GasType,
627  int StrawLayer,
628  float ZR,
629  float rTrkWire,
630  float Occupancy) const
631 {
633  bool hasTrackPar = true;
634  return (*readHandle)
635  ->getProbHT(pTrk,
636  hypothesis,
637  TrtPart,
638  GasType,
639  StrawLayer,
640  ZR,
641  rTrkWire,
642  Occupancy,
643  hasTrackPar);
644 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
InDet::TRT_ElectronPidToolRun2::m_HTReadKey
SG::ReadCondHandleKey< HTcalculator > m_HTReadKey
Definition: TRT_ElectronPidToolRun2.h:157
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
InDet::TRTPIDNN
Definition: TRTPIDNN.h:28
Trk::eProbabilityToT
@ eProbabilityToT
Electron probability from Time-Over-Threshold (ToT) information.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:214
InDet::TRT_DriftCircleOnTrack::prepRawData
virtual const TRT_DriftCircle * prepRawData() const override final
returns the PrepRawData - is a TRT_DriftCircle in this scope
Definition: TRT_DriftCircleOnTrack.h:202
InDet::TRT_ElectronPidToolRun2::~TRT_ElectronPidToolRun2
virtual ~TRT_ElectronPidToolRun2()
default destructor
LArNewCalib_Delay_OFC_Cali.BEC
BEC
Definition: LArNewCalib_Delay_OFC_Cali.py:115
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
TrackParameters.h
MeasurementBase.h
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
Trk::eProbabilityBrem
@ eProbabilityBrem
Electron probability from Brem fitting (DNA).
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:216
InDet::TRT_ElectronPidToolRun2::m_TRTdEdxTool
ToolHandle< ITRT_ToT_dEdx > m_TRTdEdxTool
Definition: TRT_ElectronPidToolRun2.h:140
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Surface.h
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
initialize
void initialize()
Definition: run_EoverP.cxx:894
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
TRT_ElectronPidToolRun2.h
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
InDet::TRTPIDNN::getScalarInputs
std::map< std::string, std::map< std::string, double > > getScalarInputs() const
Definition: TRTPIDNN.h:42
InDet::TRT_DriftCircleOnTrack::associatedSurface
virtual const Trk::Surface & associatedSurface() const override final
returns the surface for the local to global transformation
Definition: TRT_DriftCircleOnTrack.cxx:154
HTcalculator::Limit
static float Limit(float prob)
Definition: HTcalculator.cxx:12
athena.value
value
Definition: athena.py:122
Trk::RIO_OnTrack::rioType
virtual bool rioType(RIO_OnTrackType::Type type) const =0
Method checking the Rio On Track type.
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
InDet::TRT_ElectronPidToolRun2::finalize
virtual StatusCode finalize() override
standard Athena-Algorithm method
Definition: TRT_ElectronPidToolRun2.cxx:122
InDet::TRTPIDNN::getVectorInputs
std::map< std::string, std::map< std::string, std::vector< double > > > getVectorInputs() const
Definition: TRTPIDNN.h:47
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
InDetAccessor::qOverP
@ qOverP
perigee
Definition: InDetAccessor.h:35
Trk::Surface::center
const Amg::Vector3D & center() const
Returns the center position of the Surface.
InDet::TRT_ElectronPidToolRun2::m_ptMinNN
float m_ptMinNN
Definition: TRT_ElectronPidToolRun2.h:137
InDet::TRT_ElectronPidToolRun2::m_trtId
const TRT_ID * m_trtId
Definition: TRT_ElectronPidToolRun2.h:135
InDet::TRT_DriftCircleOnTrack
Definition: TRT_DriftCircleOnTrack.h:53
AthenaAttributeList.h
Trk::eProbabilityHT
@ eProbabilityHT
Electron probability from High Threshold (HT) information.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:212
ITRT_ToT_dEdx.h
Trk::TRTdEdx
@ TRTdEdx
dEdx from TRT ToT measurement.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:219
Trk::ParametersCommon::dim
static constexpr int dim
Definition: ParametersCommon.h:50
python.RingerConstants.Layer
Layer
Definition: RingerConstants.py:42
ReadCondHandle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trk::eProbabilityNumberOfTRTHitsUsedFordEdx
@ eProbabilityNumberOfTRTHitsUsedFordEdx
Number of TRT hits used for dEdx measurement.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:220
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
Track.h
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
HTcalculator
Definition: HTcalculator.h:27
CondAttrListVec.h
A CondAttrListVec is an Athena DataObject holding a vector of CORAL AttributeLists,...
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::eProbabilityComb
@ eProbabilityComb
Electron probability from combining the below probabilities.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:210
InDet::TRT_ElectronPidToolRun2::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: TRT_ElectronPidToolRun2.cxx:94
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
beamspotman.n
n
Definition: beamspotman.py:731
Trk::theta
@ theta
Definition: ParamDefs.h:72
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::electron
@ electron
Definition: ParticleHypothesis.h:27
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDet::TRT_ElectronPidToolRun2::m_TRTPIDNNReadKey
SG::ReadCondHandleKey< InDet::TRTPIDNN > m_TRTPIDNNReadKey
Definition: TRT_ElectronPidToolRun2.h:162
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
Trk::eProbabilityNN
@ eProbabilityNN
Electron probability from NN.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:217
Trk::driftRadius
@ driftRadius
trt, straws
Definition: ParamDefs.h:59
Trk::pion
@ pion
Definition: ParticleHypothesis.h:29
calibdata.exception
exception
Definition: calibdata.py:496
InDet::TRT_ElectronPidToolRun2::m_minTRThits
unsigned int m_minTRThits
Definition: TRT_ElectronPidToolRun2.h:136
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.selection.variable
variable
Definition: selection.py:33
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Trk::MeasurementBase::type
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
InDet::TRT_ElectronPidToolRun2::TRT_ElectronPidToolRun2
TRT_ElectronPidToolRun2(const std::string &, const std::string &, const IInterface *)
Definition: TRT_ElectronPidToolRun2.cxx:67
TRT_ToT_dEdx.h
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
TrackSummary.h
Trk::ParametersBase
Definition: ParametersBase.h:55
TRT_DriftCircleOnTrack.h
InDet::TRT_ElectronPidToolRun2::m_TRTStrawSummaryTool
ToolHandle< ITRT_StrawStatusSummaryTool > m_TRTStrawSummaryTool
Definition: TRT_ElectronPidToolRun2.h:150
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:893
DataVector< const Trk::TrackStateOnSurface >
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:884
InDet::TRT_ElectronPidToolRun2::electronProbability
virtual std::vector< float > electronProbability(const EventContext &ctx, const Trk::Track &track) const override final
Electron probabilities to be returned.
Definition: TRT_ElectronPidToolRun2.cxx:144
beamspotman.stat
stat
Definition: beamspotman.py:266
BaseTRTPIDCalculator.h
Trk::MeasurementBase::localCovariance
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
Definition: MeasurementBase.h:138
Trk::RIO_OnTrackType::TRT_DriftCircle
@ TRT_DriftCircle
Definition: RIO_OnTrack.h:59
Trk::MeasurementBase
Definition: MeasurementBase.h:58
InDet::TRT_DriftCircleOnTrack::timeOverThreshold
double timeOverThreshold() const
returns time over threshold in ns for valid digits; zero otherwise
Definition: TRT_DriftCircleOnTrack.h:239
InDet::TRT_ElectronPidToolRun2::probHTRun2
virtual double probHTRun2(const EventContext &ctx, float pTrk, Trk::ParticleHypothesis hypothesis, int TrtPart, int GasType, int StrawLayer, float ZR, float rTrkWire, float Occupancy) const override final
Definition: TRT_ElectronPidToolRun2.cxx:622
InDet::TRT_ElectronPidToolRun2::electronProbability_old
static std::vector< float > electronProbability_old(const Trk::Track &track)
Electron probabilities to be returned.
Definition: TRT_ElectronPidToolRun2.cxx:129
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrackInfo.h
RIO_OnTrack.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDet::TRT_ElectronPidToolRun2::m_LocalOccTool
ToolHandle< InDet::ITRT_LocalOccupancy > m_LocalOccTool
Definition: TRT_ElectronPidToolRun2.h:144
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TRT_ToT_dEdx::calculateTrackLengthInStraw
static double calculateTrackLengthInStraw(const Trk::TrackStateOnSurface *trackState, const TRT_ID *identifier)
Definition: TRT_ToT_dEdx.cxx:1208
Trk::MeasurementBaseType::RIO_OnTrack
@ RIO_OnTrack
Definition: MeasurementBase.h:49
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:73
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Trk::RIO_OnTrack::identify
virtual Identifier identify() const final
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:155
InDet::TRT_ElectronPidToolRun2::CheckGeometry
bool CheckGeometry(int BEC, int Layer, int Strawlayer) const
Definition: TRT_ElectronPidToolRun2.cxx:559
InDet::TRTPIDNN::evaluate
double evaluate(std::map< std::string, std::map< std::string, double >> &scalarInputs, std::map< std::string, std::map< std::string, std::vector< double >>> &vectorInputs) const
Definition: TRTPIDNN.h:52
Trk::phi
@ phi
Definition: ParamDefs.h:81
Trk::TRTTrackOccupancy
@ TRTTrackOccupancy
TRT track occupancy.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:218
InDet::TRT_ElectronPidToolRun2::probHT
virtual double probHT(const double pTrk, const Trk::ParticleHypothesis hypothesis, const int HitPart, const int Layer, const int Strawlayer) const override final
return high threshold probability
Definition: TRT_ElectronPidToolRun2.cxx:606
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
InDet::TRT_DriftCircleOnTrack::globalPosition
virtual const Amg::Vector3D & globalPosition() const override final
return the global position of this RIO_OnTrack
Definition: TRT_DriftCircleOnTrack.cxx:160
storeNNVariable
void storeNNVariable(std::map< std::string, T > &theMap, const std::string &name, const T &value)
Definition: TRT_ElectronPidToolRun2.cxx:52
AthAlgTool
Definition: AthAlgTool.h:26
InDet::TRT_DriftCircle::getWord
unsigned int getWord() const
returns the TRT dataword
HTcalculator::getProbHT
float getProbHT(float pTrk, Trk::ParticleHypothesis hypothesis, int TrtPart, int GasType, int StrawLayer, float ZR, float rTrkAnode, float Occupancy, bool hasTrackPars) const
Definition: HTcalculator.cxx:27
TrackStateOnSurface.h
InDet::TRT_ElectronPidToolRun2::m_calculateNN
bool m_calculateNN
Definition: TRT_ElectronPidToolRun2.h:138
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35