ATLAS Offline Software
TruthQualitySelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 
11  : asg::AsgTool( name ) { }
12 
14 {
15  ATH_CHECK( m_truthTool.retrieve() );
16  ATH_CHECK( m_trackTruthOriginTool.retrieve() );
17  return StatusCode::SUCCESS;
18 }
19 
20 
22 {
23  std::vector< const xAOD::TruthParticle* > selected;
24  for( const xAOD::TruthParticle* truth :
26  if( accept( truth ) ) selected.push_back( truth );
27  }
28 
29  ATH_MSG_DEBUG( "Size before selection: " <<
30  trkAnaColls.truthPartVec( TrackAnalysisCollections::FS ).size() <<
31  "\t Size after selection: " << selected.size() );
32 
34  ATH_CHECK( trkAnaColls.fillTruthPartVec( selected, TrackAnalysisCollections::FS ) );
35 
36  return StatusCode::SUCCESS;
37 }
38 
39 
40 
42  return getParentRec( truth, flav, 0 );
43 }
44 
46 
47  if ( truth == nullptr ) return nullptr;
48 
49  if ( depth > 30 ) return nullptr;
50 
51  if( flav != MC::BQUARK && flav != MC::CQUARK && flav != MC::TAU ) return nullptr;
52 
53  if( flav == MC::BQUARK && truth->isBottomHadron() ) return truth;
54 
55  if( flav == MC::CQUARK && truth->isCharmHadron() ) return truth;
56 
57  if( flav == MC::TAU && MC::isTau(truth) ) return truth;
58 
59 
60  for(unsigned int p=0; p<truth->nParents(); p++) {
61  const xAOD::TruthParticle* parent = truth->parent(p);
62  if(parent == truth ) continue ; // avoid infinite recursion
63  if( getParentRec(parent, flav, depth+1)!= nullptr ) return parent;
64  }
65 
66  return nullptr;
67 }
68 
69 
70 
72 {
74  if( not m_truthTool->accept( truth ) ) return false;
75 
77  if (m_maxEta!=-9999. and (eta(*truth)) > m_maxEta ) return false;
78  if (m_minEta!=-9999. and (eta(*truth)) < m_minEta ) return false;
79  if (m_minPhi!=-9999. and (phi(*truth)) < m_minPhi ) return false;
80  if (m_maxPhi!=-9999. and (phi(*truth)) > m_maxPhi ) return false;
81  if (m_minD0!=-9999. and (d0(*truth)) < m_minD0 ) return false;
82  if (m_maxD0!=-9999. and (d0(*truth)) > m_maxD0 ) return false;
83  if (m_minZ0!=-9999. and (z0(*truth)) < m_minZ0 ) return false;
84  if (m_maxZ0!=-9999. and (z0(*truth)) > m_maxZ0 ) return false;
85  if (m_minQoPT!=-9999. and (qOverPT(*truth)) < m_minQoPT ) return false;
86  if (m_maxQoPT!=-9999. and (qOverPT(*truth)) > m_maxQoPT ) return false;
87  if (m_minAbsEta!=-9999. and std::fabs(eta(*truth)) < m_minAbsEta ) return false;
88  if (m_minAbsPhi!=-9999. and std::fabs(phi(*truth)) < m_minAbsPhi ) return false;
89  if (m_maxAbsPhi!=-9999. and std::fabs(phi(*truth)) > m_maxAbsPhi ) return false;
90  if (m_minAbsD0!=-9999. and std::fabs(d0(*truth)) < m_minAbsD0 ) return false;
91  if (m_maxAbsD0!=-9999. and std::fabs(d0(*truth)) > m_maxAbsD0 ) return false;
92  if (m_minAbsZ0!=-9999. and std::fabs(z0(*truth)) < m_minAbsZ0 ) return false;
93  if (m_maxAbsZ0!=-9999. and std::fabs(z0(*truth)) > m_maxAbsZ0 ) return false;
94  if (m_minAbsQoPT!=-9999. and std::fabs(qOverPT(*truth)) < m_minAbsQoPT ) return false;
95  if (m_maxAbsQoPT!=-9999. and std::fabs(qOverPT(*truth)) > m_maxAbsQoPT ) return false;
96  if (m_isHadron and not isHadron(*truth) ) return false;
97  if (m_isPion and not isPion(*truth) ) return false;
98 
99  if ( m_isFromTau or m_isFromB or m_isFromC or m_isFromHeavyFlav or m_isFromLightFlav ) {
100  const xAOD::TruthParticle* truthParent = nullptr;
101  if( m_isFromTau ) truthParent = getParent(truth, MC::TAU);
102  if( m_isFromB ) truthParent = getParent(truth, MC::BQUARK);
103  if( m_isFromC ) truthParent = getParent(truth, MC::CQUARK);
104  if(m_isFromHeavyFlav or m_isFromLightFlav){
105  const xAOD::TruthParticle* truthParentB = getParent(truth, MC::BQUARK);
106  const xAOD::TruthParticle* truthParentC = getParent(truth, MC::CQUARK);
107  truthParent = truthParentB ? truthParentB : (truthParentC ? truthParentC : nullptr);
108  }
109  if (m_isFromLightFlav and truthParent ) return false;
110  if (not m_isFromLightFlav and not truthParent) return false;
111  if (m_minParentPt!=-9999. and truthParent->pt() < m_minParentPt ) return false;
112  if (m_maxParentPt!=-9999. and truthParent->pt() > m_maxParentPt ) return false;
113  }
114 
115  return true;
116 }
117 
118 
119 
egammaParameters::depth
@ depth
pointing depth of the shower as calculated in egammaqgcld
Definition: egammaParamDefs.h:276
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:46
xAOD::TruthParticle_v1::isCharmHadron
bool isCharmHadron() const
Determine if the PID is that of a c-hadron.
IDTPM::TruthQualitySelectionTool::accept
bool accept(const xAOD::TruthParticle *truth)
Definition: TruthQualitySelectionTool.cxx:71
IDTPM::TruthQualitySelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: TruthQualitySelectionTool.cxx:13
IDTPM::TruthQualitySelectionTool::selectTracks
virtual StatusCode selectTracks(TrackAnalysisCollections &trkAnaColls) override
Definition: TruthQualitySelectionTool.cxx:21
IDTPM::z0
float z0(const U &p)
Definition: TrackParametersHelper.h:72
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
IDTPM::isHadron
float isHadron(const U &p)
Definition: TrackParametersHelper.h:258
asg
Definition: DataHandleTestTool.h:28
IDTPM::phi
float phi(const U &p)
Definition: TrackParametersHelper.h:61
IDTPM::TrackAnalysisCollections::fillTruthPartVec
StatusCode fillTruthPartVec(const std::vector< const xAOD::TruthParticle * > &vec, Stage stage=FULL)
fill truth/offline/trigger track vector (TEST or REFERENCE)
Definition: TrackAnalysisCollections.cxx:319
TrackParametersHelper.h
Utility methods to access track/truth particles parmeters in a consitent way in this package.
xAOD::TruthParticle_v1::nParents
size_t nParents() const
Number of parents of this particle.
Definition: TruthParticle_v1.cxx:117
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
IDTPM::qOverPT
float qOverPT(const U &p)
Definition: TrackParametersHelper.h:114
IDTPM::TruthQualitySelectionTool::TruthQualitySelectionTool
TruthQualitySelectionTool(const std::string &name)
Definition: TruthQualitySelectionTool.cxx:10
IDTPM::eta
float eta(const U &p)
Accessor utility function for getting the value of eta.
Definition: TrackParametersHelper.h:43
TruthQualitySelectionTool.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IDTPM::TrackAnalysisCollections::FS
@ FS
Definition: TrackAnalysisCollections.h:54
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
IDTPM::d0
float d0(const U &p)
Definition: TrackParametersHelper.h:84
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IDTPM::isPion
float isPion(const U &p)
Definition: TrackParametersHelper.h:264
isTau
bool isTau(const T &p)
Definition: AtlasPID.h:208
xAOD::TruthParticle_v1::isBottomHadron
bool isBottomHadron() const
Determine if the PID is that of a b-hadron.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
IDTPM::TruthQualitySelectionTool::getParent
const xAOD::TruthParticle * getParent(const xAOD::TruthParticle *truth, int flav) const
Definition: TruthQualitySelectionTool.cxx:41
IDTPM::TruthQualitySelectionTool::getParentRec
const xAOD::TruthParticle * getParentRec(const xAOD::TruthParticle *truth, int flav, int depth) const
Definition: TruthQualitySelectionTool.cxx:45
IDTPM::TrackAnalysisCollections::truthPartVec
const std::vector< const xAOD::TruthParticle * > & truthPartVec(Stage stage=FULL)
get truth/offline/trigger track vector (TEST or REFERENCE)
Definition: TrackAnalysisCollections.h:229
xAOD::TruthParticle_v1::parent
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Definition: TruthParticle_v1.cxx:126
HepMCHelpers.h