ATLAS Offline Software
GenericTruthStrategy.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // GenericTruthStrategy.cxx, (c) ATLAS Detector software
8 
9 // class header include
10 #include "GenericTruthStrategy.h"
11 
12 // ISF includes
14 #include "ISF_Event/ISFParticle.h"
15 
17 ISF::GenericTruthStrategy::GenericTruthStrategy(const std::string& t, const std::string& n, const IInterface* p) :
18  base_class(t,n,p),
19  m_useParentPt(true),
20  m_parentPt2(-1.),
21  m_parentEkin(-1.),
22  m_useChildPt(true),
23  m_childPt2(-1.),
24  m_childEkin(-1.),
25  m_allowChildrenOrParentPass(false),
26  m_vertexTypesVector(0),
27  m_vertexTypes(),
28  m_doVertexRangeCheck(false),
29  m_vertexTypeRangeLow(0),
30  m_vertexTypeRangeHigh(0),
31  m_vertexTypeRangeLength(0),
32  m_parentPdgCodesVector(0),
33  m_parentPdgCodes()
34 {
35  // provide either a pT or Ekin cut for the parent and child particles respectively.
36  // if none are given for either type, it will not use pT or Ekin cuts
37  // (the Pt2 variables get squared in the initialize() method)
38  declareProperty("ParentMinPt" , m_parentPt2 );
39  declareProperty("ParentMinEkin" , m_parentEkin );
40  declareProperty("ChildMinPt" , m_childPt2 );
41  declareProperty("ChildMinEkin" , m_childEkin );
42  // if set to true, kinetic cuts are passed even if only child particles pass them
43  // (used for special cases such as de-excitation)
44  declareProperty("AllowChildrenOrParentPassKineticCuts" , m_allowChildrenOrParentPass );
45  declareProperty("VertexTypes" , m_vertexTypesVector );
46  declareProperty("VertexTypeRangeLow" , m_vertexTypeRangeLow );
47  declareProperty("VertexTypeRangeHigh" , m_vertexTypeRangeHigh );
48  declareProperty("ParentPDGCodes" , m_parentPdgCodesVector );
49  declareProperty("Regions" , m_regionListProperty );
50 }
51 
54 {
55 }
56 
57 // Athena algtool's Hooks
59 {
60  ATH_MSG_VERBOSE("Initializing ...");
61 
62  // (*) setup parent particle cuts
63  // -----
64  // (compute and store the squared cut parameters (faster comparisons))
65  // check whether the user input makes sense (error case)
66  if ( (m_parentPt2>=0.) && (m_parentEkin>=0.) ) {
67  ATH_MSG_ERROR("Both, pT and Ekin cuts are given for parent particles. Unclear which one to use! ABORT!");
68  return StatusCode::FAILURE;
69  }
70  // neither pT nor Energy cuts were given (never being used so far)
71  // -> enable pT cut and set it to 0.
72  else if ( (m_parentPt2<0.) && (m_parentEkin<0.) ) {
73  // we don't use a flag to disable energy/momentum checks, because
74  // all relevant truth strategies up to now do use such cuts
75  m_useParentPt = true;
76  m_parentPt2 = 0.;
77  m_parentEkin = 0.; // would not be needed actually
78  }
79  // either pT or Ekin cut is given (standard case)
80  else {
81  // enable pT cut if value given (greater than 0.):
82  m_useParentPt = !(m_parentPt2<0.);
83  m_parentPt2 *= m_parentPt2;
84  }
85 
86  // (*) setup child particle cuts
87  // -----
88  // (compute and store the squared cut parameters (faster comparisons))
89  // check whether the user input makes sense (error case)
90  if ( (m_childPt2>=0.) && (m_childEkin>=0.) ) {
91  ATH_MSG_ERROR("Both, pT and Ekin cuts are given for child particles. Unclear which one to use! ABORT!");
92  return StatusCode::FAILURE;
93  }
94  // neither pT nor Energy cuts were given (never being used so far)
95  // -> enable pT cut and set it to 0.
96  else if ( (m_childPt2<0.) && (m_childEkin<0.) ) {
97  // we don't use a flag to disable energy/momentum checks, because
98  // all relevant truth strategies up to now do use such cuts
99  m_useChildPt = true;
100  m_childPt2 = 0.;
101  m_childEkin = 0.; // would not be needed actually
102  }
103  // either pT or Ekin cut is given (standard case)
104  else {
105  // enable pT cut if value given (greater than 0.):
106  m_useChildPt = !(m_childPt2<0.);
107  m_childPt2 *= m_childPt2;
108  }
109 
110  // VertexTypeRanges:
111  //
112  // check whether user input makes sense:
113  if ( m_vertexTypeRangeHigh < m_vertexTypeRangeLow) {
114  ATH_MSG_ERROR("The given parameter VertexTypeRangeLow is bigger than VertexTypeRangeHigh. ABORT");
115  return StatusCode::FAILURE;
116  }
117  // the length of the given vertex type range
118  m_vertexTypeRangeLength = unsigned(m_vertexTypeRangeHigh - m_vertexTypeRangeLow) + 1;
119  // if neither lower now upper range limit given, disable range check
120  m_doVertexRangeCheck = m_vertexTypeRangeLow && m_vertexTypeRangeHigh;
121 
122 
123  // fill PDG code std::set used for optimized search
124  m_parentPdgCodes.insert( m_parentPdgCodesVector.begin(), m_parentPdgCodesVector.end());
125 
126  // fill vertex type std::set used for optimized search
127  m_vertexTypes.insert( m_vertexTypesVector.begin(), m_vertexTypesVector.end());
128 
129  for(auto region : m_regionListProperty.value()) {
130  if(region < AtlasDetDescr::fFirstAtlasRegion || region >= AtlasDetDescr::fNumAtlasRegions) {
131  ATH_MSG_ERROR("Unknown Region (" << region << ") specified. Please check your configuration.");
132  return StatusCode::FAILURE;
133  }
134  }
135  return StatusCode::SUCCESS;
136 }
137 
139 {
140  ATH_MSG_VERBOSE("Finalizing ...");
141  return StatusCode::SUCCESS;
142 }
143 
145 
146  // (1.) momentum/energy check
147  // ----
148  //
149  {
150  // check whether parent particle passes cut or not
151  bool primFail = (m_useParentPt) ? (ti.parentPt2()<m_parentPt2)
152  : (ti.parentEkin()<m_parentEkin) ;
153 
154 
155  // if parent particle failed and strategy does not
156  // allow for child-only pass -> failed
157  if ( ( primFail && (!m_allowChildrenOrParentPass) ) ) {
158  return false;
159  }
160 
161  // check child particles
162  bool secPass = m_useChildPt ? ti.childrenPt2Pass(m_childPt2)
163  : ti.childrenEkinPass(m_childEkin);
164 
165  // if child particles do not pass cuts
166  if (!secPass) {
167  if (!m_allowChildrenOrParentPass) {
168  // child particles were required to pass cuts but did not
169  return false;
170  } else if (primFail) {
171  // neither parent nor child particles passed cuts
172  return false;
173  }
174  }
175 
176  }
177 
178 
179  // (2.) parent particle PDG code check
180  // ----
181  // check whether parent PDG code matches with any of the given ones
182  if ( m_parentPdgCodes.size() &&
183  (m_parentPdgCodes.find(ti.parentPdgCode()) == m_parentPdgCodes.end()) ) {
184 
185  // parent particle PDG code not found
186  return false;
187  }
188 
189 
190  // (3.) vertex type check
191  // ----
192  if ( m_doVertexRangeCheck || m_vertexTypes.size()) {
193  int vxtype = ti.physicsProcessCode();
194 
195  // (3.1) vxtype in given range?: this is a small performance trick (only one comparison operator to check if within range)
196  // -> exactly equivalent to: m_doVertexRangeCheck && (m_vertexTypeLow<=vxtype) && (vxtype<=m_vertexTypeRangeHigh)
197  bool vtxTypeRangePassed = m_doVertexRangeCheck && ( unsigned(vxtype-m_vertexTypeRangeLow) < m_vertexTypeRangeLength );
198  // (3.2) if not in range or range check disabled, check whether vxtype
199  // std::set contains the given vertex type
200  if ( (!vtxTypeRangePassed) && (m_vertexTypes.find(vxtype)==m_vertexTypes.end()) ) {
201  // vxtype not registered -> not passed
202  return false;
203  }
204  }
205 
206  // all cuts passed
207  return true;
208 }
209 
210 bool ISF::GenericTruthStrategy::appliesToRegion(unsigned short geoID) const
211 {
212  return std::find( m_regionListProperty.begin(),
213  m_regionListProperty.end(),
214  geoID ) != m_regionListProperty.end();
215 }
AtlasDetDescr::fNumAtlasRegions
@ fNumAtlasRegions
Definition: AtlasRegion.h:39
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
ISF::ITruthIncident::physicsProcessCode
virtual int physicsProcessCode() const =0
Return specific physics process code of the truth incident (eg ionisation, bremsstrahlung,...
ISF::ITruthIncident::parentPdgCode
virtual int parentPdgCode() const =0
Return the PDG Code of the parent particle.
ISF::GenericTruthStrategy::m_allowChildrenOrParentPass
bool m_allowChildrenOrParentPass
pass cuts if parent did not
Definition: GenericTruthStrategy.h:64
ISF::GenericTruthStrategy::m_childPt2
double m_childPt2
pT momentum cut
Definition: GenericTruthStrategy.h:62
ISF::GenericTruthStrategy::~GenericTruthStrategy
~GenericTruthStrategy()
Destructor.
Definition: GenericTruthStrategy.cxx:53
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ISF::GenericTruthStrategy::m_parentEkin
double m_parentEkin
parent particle
Definition: GenericTruthStrategy.h:57
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
ISF::GenericTruthStrategy::m_vertexTypesVector
VertexTypesVector m_vertexTypesVector
vertex type (physics code) checks
Definition: GenericTruthStrategy.h:67
ISF::GenericTruthStrategy::finalize
virtual StatusCode finalize() override
Definition: GenericTruthStrategy.cxx:138
GenericTruthStrategy.h
ISF::GenericTruthStrategy::appliesToRegion
virtual bool appliesToRegion(unsigned short geoID) const override
Definition: GenericTruthStrategy.cxx:210
ISFParticle.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ISF::GenericTruthStrategy::m_vertexTypeRangeLow
int m_vertexTypeRangeLow
Definition: GenericTruthStrategy.h:70
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ITruthIncident.h
ISF::GenericTruthStrategy::m_vertexTypeRangeHigh
int m_vertexTypeRangeHigh
Definition: GenericTruthStrategy.h:71
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ISF::ITruthIncident
Definition: ITruthIncident.h:45
ISF::GenericTruthStrategy::m_parentPdgCodesVector
PDGCodesVector m_parentPdgCodesVector
PDG code checks.
Definition: GenericTruthStrategy.h:75
ISF::GenericTruthStrategy::pass
virtual bool pass(ITruthIncident &incident) const override
true if the ITruthStrategy implementation applies to the given ITruthIncident
Definition: GenericTruthStrategy.cxx:144
ISF::GenericTruthStrategy::m_parentPt2
double m_parentPt2
parent particle
Definition: GenericTruthStrategy.h:56
ISF::ITruthIncident::childrenPt2Pass
bool childrenPt2Pass(double pt2cut)
Return true if at least one child particle passes the given pT^2 cut (= at least one child with pT^2 ...
Definition: ITruthIncident.h:158
ISF::GenericTruthStrategy::initialize
virtual StatusCode initialize() override
Definition: GenericTruthStrategy.cxx:58
ISF::GenericTruthStrategy::GenericTruthStrategy
GenericTruthStrategy(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: GenericTruthStrategy.cxx:17
ISF::ITruthIncident::parentPt2
virtual double parentPt2() const =0
Return pT^2 of the parent particle.
ISF::GenericTruthStrategy::m_regionListProperty
IntegerArrayProperty m_regionListProperty
Definition: GenericTruthStrategy.h:78
ISF::ITruthIncident::parentEkin
virtual double parentEkin() const =0
Return Ekin of the parent particle.
ISF::GenericTruthStrategy::m_childEkin
double m_childEkin
Ekin cut.
Definition: GenericTruthStrategy.h:63
ISF::ITruthIncident::childrenEkinPass
bool childrenEkinPass(double ekincut)
Return true if at least one child particle passes the given Ekin cut (= at least one child with Ekin ...
Definition: ITruthIncident.h:170