ATLAS Offline Software
METTruthTool.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // METTruthTool.cxx
8 // Implementation file for class METTruthTool
9 //
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11 //
12 // Author: P Loch, S Resconi, TJ Khoo, AS Mete
14 
15 // METReconstruction includes
17 
18 #include "StoreGate/DataHandle.h"
19 
20 // MET EDM
24 
25 // Truth EDM
27 #include "xAODTruth/TruthVertex.h"
28 
29 // Base EDM
31 
32 // Truth Utilities
34 
35 namespace met {
36 
37  using std::vector;
38  //
39  using xAOD::IParticle;
40  //
41  using xAOD::TruthEvent;
43  using xAOD::TruthParticle;
45  //
46  using xAOD::MissingET;
49 
51  // Public methods:
53 
54  // Constructors
56  METTruthTool::METTruthTool(const std::string& name) :
57  AsgTool(name),
59  {
60  }
61 
62  // Athena algtool's Hooks
65  {
67  ATH_MSG_VERBOSE ("Initializing " << name() << "...");
68 
69  if(m_inputType=="NonInt") {
71  } else if(m_inputType=="Int") {
73  } else if(m_inputType=="IntOut") {
75  } else if(m_inputType=="IntMuons") {
77  } else {
78  ATH_MSG_FATAL("Invalid input type provided");
79  return StatusCode::FAILURE;
80  }
81 
82  ATH_CHECK( m_truthEventKey.initialize());
83 
84  return StatusCode::SUCCESS;
85  }
86 
88  // Protected methods:
90 
91  bool METTruthTool::accept(const xAOD::IParticle* object) const
92  {
93  // Apply cuts
94  ATH_MSG_VERBOSE("Check if truth particle is accepted");
95  if(!object){return false;}
96  if(object->type() != xAOD::Type::TruthParticle) {
97  ATH_MSG_WARNING("METTruthTool::accept given an object of type" << object->type());
98  return false;
99  }
100  const xAOD::TruthParticle* truth = static_cast<const xAOD::TruthParticle*>(object);
101 
102  if(truth->pt()<1e-9) return false; // reject particles with no pt
103  ATH_MSG_VERBOSE("My truth type: " << static_cast<MissingETBase::Types::bitmask_t>(m_truth_type));
104  switch(m_truth_type) {
106  return accept_nonint(truth);
108  return accept_int(truth);
110  return accept_intout(truth);
112  return accept_intmuons(truth);
113  default:
114  return false;
115  }
116  // should not get here
117  return false;
118  }
119 
121  {
122  ATH_MSG_VERBOSE("Check nonint");
123  // stable and non-interacting
124  return truth->isGenStable() && !MC::isInteracting(truth->pdgId());
125  }
126 
128  {
129  ATH_MSG_VERBOSE("Check int");
130  // not muon
131  if(truth->isMuon()) return false;
132  // stable
133  if(!truth->isGenStable()) return false;
134  // interacting
135  if(!MC::isInteracting(truth->pdgId())) return false;
136  // in acceptance
137  if(fabs(truth->eta())>m_det_maxEta) return false;
138 
139  return true;
140  }
141 
143  {
144  ATH_MSG_VERBOSE("Check intout");
145  // muon outside MS acceptance
146  if( truth->isMuon() ) {
147  if( fabs(truth->eta())<m_truthmu_maxEta) return false;
148  } else {
149  // other particle outside calo acceptance
150  if( (fabs(truth->eta())<m_det_maxEta) ) return false;
151  }
152  // stable
153  if(!truth->isGenStable()) return false;
154  // interacting
155  if(!MC::isInteracting(truth->pdgId())) return false;
156 
157  return true;
158  }
159 
161  {
162  ATH_MSG_VERBOSE("Check intmuon");
163  // muon
164  if(!truth->isMuon()) return false;
165  // stable
166  if(!truth->isGenStable()) return false;
167  // in acceptance
168  if(truth->pt()<m_truthmu_minPt || fabs(truth->eta())>m_truthmu_maxEta) return false;
169 
170  return true;
171  }
172 
174 
175  ATH_MSG_DEBUG ("In execute: " << name() << "...");
176 
178 
179  // Retrieve the truth container
181 
182  if (!truthEvents.isValid()) {
183  ATH_MSG_WARNING("Unable to retrieve input truth event container ");
184  return StatusCode::SUCCESS;
185  }
186 
187  // First truth event is the hard scatter
188  const TruthEvent* hsevent = truthEvents->front();
190  for(size_t itp=0; itp<hsevent->nTruthParticles(); ++itp) {
191  truthCont.push_back(hsevent->truthParticle(itp));
192  ATH_MSG_VERBOSE("Extracted truth particle with index " << hsevent->truthParticle(itp)->index());
193  }
194 
195  vector<const IParticle*> signalList;
196  signalList.reserve(truthCont.size());
197  // Loop over all truth particles
198  for( const auto truthp : truthCont ) {
199  // Check if truth particles satisfies the requirements
200  if( this->accept(truthp) ) {
201  // Add the selected truth particles to the list
202  signalList.push_back(truthp);
203  }
204  } // end loop over truth particles
205 
206  // Loop over the content and add to MET
207  MissingETBase::Types::weight_t unitWeight(1.,1.,1.);
208  MissingETBase::Types::weight_t minusWeight(-1.,-1.,1.);
209  vector<const IParticle*> dummyList;
210  for(const auto *iPart : signalList) {
212  // flip direction for nonint
213  this->addToMET(iPart,dummyList,metTerm,metMap,minusWeight);
214  } else {
215  this->addToMET(iPart,dummyList,metTerm,metMap,unitWeight);
216  }
217  }
218 
219  ATH_MSG_DEBUG( "Map contains " << (*MissingETComposition::find(metMap,metTerm))->objects().size() << " truth particles" );
220 
221  return StatusCode::SUCCESS;
222  }
223 
224 }
xAOD::MissingETComponentMap_v1
Definition: MissingETComponentMap_v1.h:25
TruthTest.itp
itp
Definition: TruthTest.py:46
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MissingETBase::Source::TruthType::TruthMuons
@ TruthMuons
Indicator for muons from MC truth (muons from the interaction)
met::METTruthTool::m_inputType
Gaudi::Property< std::string > m_inputType
Definition: METTruthTool.h:78
LArConditions2Ntuple.objects
objects
Definition: LArConditions2Ntuple.py:56
METTruthTool.h
MissingETBase::Source::TruthType::NonInt
@ NonInt
Indicator for MET from non-interacting particles generated in the collision.
met::METBuilderTool
Definition: METBuilderTool.h:39
met::METTruthTool::METTruthTool
METTruthTool()
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
met::METBuilderTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METBuilderTool.cxx:45
xAOD::MissingETComposition::find
static MissingETComponentMap::const_iterator find(const MissingETComponentMap *pMap, const MissingET *pmetObj)
Find non-modifiable contribution for a given MET object.
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:82
TruthParticleContainer.h
xAOD::TruthEvent
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition: TruthEvent.h:17
MissingETBase::Source::TruthType::IntOut
@ IntOut
Indicator for MET contributions from particles outside of the acceptance of the detector (typically ...
MissingETAuxComponentMap.h
met::METTruthTool::accept_intout
bool accept_intout(const xAOD::TruthParticle *truth) const
Definition: METTruthTool.cxx:142
xAOD::TruthEventBase_v1::truthParticle
const TruthParticle * truthParticle(size_t index) const
Get a pointer to one of the truth particles.
Definition: TruthEventBase_v1.cxx:50
xAOD::TruthParticle_v1::isGenStable
bool isGenStable() const
Check if this is generator stable particle.
Definition: TruthParticle_v1.cxx:316
met::METTruthTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METTruthTool.cxx:64
xAOD::MissingET
MissingET_v1 MissingET
Version control by type defintion.
Definition: Event/xAOD/xAODMissingET/xAODMissingET/MissingET.h:15
met::METTruthTool::m_truthmu_minPt
Gaudi::Property< double > m_truthmu_minPt
Definition: METTruthTool.h:82
MissingETComposition
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current MissingETComposition
Definition: RecTPCnv.cxx:86
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MissingETBase::Types::bitmask_t
uint64_t bitmask_t
Type for status word bit mask.
Definition: MissingETBase.h:39
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
xAOD::MissingET_v1::setSource
void setSource(MissingETBase::Types::bitmask_t src)
Set the source of the MET object.
met::METTruthTool::accept_int
bool accept_int(const xAOD::TruthParticle *truth) const
Definition: METTruthTool.cxx:127
DataHandle.h
met::METTruthTool::m_truthEventKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventKey
Definition: METTruthTool.h:84
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
met
Definition: IMETSignificance.h:24
met::METTruthTool::m_truthmu_maxEta
Gaudi::Property< double > m_truthmu_maxEta
Definition: METTruthTool.h:83
met::METTruthTool::m_truth_type
MissingETBase::Source::TruthType m_truth_type
Definition: METTruthTool.h:79
MissingETBase::Source::TruthType::Int
@ Int
Indicator for MET from interacting particles within the nominal acceptance of the detector.
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
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
MissingETAuxContainer.h
met::METBuilderTool::addToMET
virtual bool addToMET(const xAOD::IParticle *object, const std::vector< const xAOD::IParticle * > &acceptedSignals, xAOD::MissingET *metTerm, xAOD::MissingETComponentMap *metMap, MissingETBase::Types::weight_t &objWeight, MissingETBase::UsageHandler::Policy p=MissingETBase::UsageHandler::TrackCluster) const
Definition: METBuilderTool.cxx:77
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
met::METTruthTool::executeTool
virtual StatusCode executeTool(xAOD::MissingET *metTerm, xAOD::MissingETComponentMap *metMap) const override
Definition: METTruthTool.cxx:173
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
xAOD::TruthEvent_v1
Class describing a signal truth event in the MC record.
Definition: TruthEvent_v1.h:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TruthVertex.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
met::METTruthTool::m_det_maxEta
Gaudi::Property< double > m_det_maxEta
Definition: METTruthTool.h:81
xAOD::TruthEventBase_v1::nTruthParticles
size_t nTruthParticles() const
Get the number of truth particles.
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
xAOD::TruthParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:174
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
xAOD::TruthEventContainer
TruthEventContainer_v1 TruthEventContainer
Declare the latest version of the truth event container.
Definition: TruthEventContainer.h:18
xAOD::MissingETComponentMap
MissingETComponentMap_v1 MissingETComponentMap
Version control by type definition.
Definition: MissingETComponentMap.h:16
xAOD::TruthParticle_v1::isMuon
bool isMuon() const
Whether the particle is a muon (or antimuon)
met::METTruthTool::accept_intmuons
bool accept_intmuons(const xAOD::TruthParticle *truth) const
Definition: METTruthTool.cxx:160
xAOD::MissingETComponent_v1::Weight
Kinematic weight descriptor.
Definition: MissingETComponent_v1.h:28
met::METTruthTool::accept
virtual bool accept(const xAOD::IParticle *object) const override
Definition: METTruthTool.cxx:91
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
MC::isInteracting
bool isInteracting(const T &p)
Identify if the particle with given PDG ID would not interact with the detector, i....
Definition: HepMCHelpers.h:23
pickleTool.object
object
Definition: pickleTool.py:30
met::METTruthTool::accept_nonint
bool accept_nonint(const xAOD::TruthParticle *truth) const
Definition: METTruthTool.cxx:120
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
MissingETComposition.h
HepMCHelpers.h