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