ATLAS Offline Software
Loading...
Searching...
No Matches
METTruthTool.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 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// MET EDM
22
23// Truth EDM
26
27// Base EDM
29
30// Truth Utilities
32
33namespace met {
34
35 using std::vector;
36 //
37 using xAOD::IParticle;
38 //
39 using xAOD::TruthEvent;
43 //
44 using xAOD::MissingET;
47
49 // Public methods:
51
52 // Constructors
54 METTruthTool::METTruthTool(const std::string& name) :
57 {
58 }
59
60 // Athena algtool's Hooks
63 {
65 ATH_MSG_VERBOSE ("Initializing " << name() << "...");
66
67 if(m_inputType=="NonInt") {
69 } else if(m_inputType=="Int") {
71 } else if(m_inputType=="IntOut") {
73 } else if(m_inputType=="IntMuons") {
75 } else {
76 ATH_MSG_FATAL("Invalid input type provided");
77 return StatusCode::FAILURE;
78 }
79
80 ATH_CHECK( m_truthEventKey.initialize());
81
82 return StatusCode::SUCCESS;
83 }
84
86 // Protected methods:
88
89 bool METTruthTool::accept(const xAOD::IParticle* object) const
90 {
91 // Apply cuts
92 ATH_MSG_VERBOSE("Check if truth particle is accepted");
93 if(!object){return false;}
94 if(object->type() != xAOD::Type::TruthParticle) {
95 ATH_MSG_WARNING("METTruthTool::accept given an object of type" << object->type());
96 return false;
97 }
98 const xAOD::TruthParticle* truth = static_cast<const xAOD::TruthParticle*>(object);
99
100 if(truth->pt()<1e-9) return false; // reject particles with no pt
101 ATH_MSG_VERBOSE("My truth type: " << static_cast<MissingETBase::Types::bitmask_t>(m_truth_type));
102 switch(m_truth_type) {
104 return accept_nonint(truth);
106 return accept_int(truth);
108 return accept_intout(truth);
110 return accept_intmuons(truth);
111 default:
112 return false;
113 }
114 // should not get here
115 return false;
116 }
117
119 {
120 ATH_MSG_VERBOSE("Check nonint");
121 // stable and non-interacting
122 return truth->isGenStable() && !MC::isInteracting(truth->pdgId());
123 }
124
126 {
127 ATH_MSG_VERBOSE("Check int");
128 // not muon
129 if(truth->isMuon()) return false;
130 // stable
131 if(!truth->isGenStable()) return false;
132 // interacting
133 if(!MC::isInteracting(truth->pdgId())) return false;
134 // in acceptance
135 if(fabs(truth->eta())>m_det_maxEta) return false;
136
137 return true;
138 }
139
141 {
142 ATH_MSG_VERBOSE("Check intout");
143 // muon outside MS acceptance
144 if( truth->isMuon() ) {
145 if( fabs(truth->eta())<m_truthmu_maxEta) return false;
146 } else {
147 // other particle outside calo acceptance
148 if( (fabs(truth->eta())<m_det_maxEta) ) return false;
149 }
150 // stable
151 if(!truth->isGenStable()) return false;
152 // interacting
153 if(!MC::isInteracting(truth->pdgId())) return false;
154
155 return true;
156 }
157
159 {
160 ATH_MSG_VERBOSE("Check intmuon");
161 // muon
162 if(!truth->isMuon()) return false;
163 // stable
164 if(!truth->isGenStable()) return false;
165 // in acceptance
166 if(truth->pt()<m_truthmu_minPt || fabs(truth->eta())>m_truthmu_maxEta) return false;
167
168 return true;
169 }
170
172
173 ATH_MSG_DEBUG ("In execute: " << name() << "...");
174
176
177 // Retrieve the truth container
179
180 if (!truthEvents.isValid()) {
181 ATH_MSG_WARNING("Unable to retrieve input truth event container ");
182 return StatusCode::SUCCESS;
183 }
184
185 // First truth event is the hard scatter
186 const TruthEvent* hsevent = truthEvents->front();
188 for(size_t itp=0; itp<hsevent->nTruthParticles(); ++itp) {
189 truthCont.push_back(hsevent->truthParticle(itp));
190 ATH_MSG_VERBOSE("Extracted truth particle with index " << hsevent->truthParticle(itp)->index());
191 }
192
193 vector<const IParticle*> signalList;
194 signalList.reserve(truthCont.size());
195 // Loop over all truth particles
196 for( const auto truthp : truthCont ) {
197 // Check if truth particles satisfies the requirements
198 if( this->accept(truthp) ) {
199 // Add the selected truth particles to the list
200 signalList.push_back(truthp);
201 }
202 } // end loop over truth particles
203
204 // Loop over the content and add to MET
205 MissingETBase::Types::weight_t unitWeight(1.,1.,1.);
206 MissingETBase::Types::weight_t minusWeight(-1.,-1.,1.);
207 vector<const IParticle*> dummyList;
208 for(const auto *iPart : signalList) {
210 // flip direction for nonint
211 this->addToMET(iPart,dummyList,metTerm,metMap,minusWeight);
212 } else {
213 this->addToMET(iPart,dummyList,metTerm,metMap,unitWeight);
214 }
215 }
216
217 ATH_MSG_DEBUG( "Map contains " << (*MissingETComposition::find(metMap,metTerm))->objects().size() << " truth particles" );
218
219 return StatusCode::SUCCESS;
220 }
221
222}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
DataVector adapter that acts like it holds const pointers.
ATLAS-specific HepMC functions.
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_t index() const
Return the index of this element within its container.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
METBuilderTool(const std::string &name)
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
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
bool accept_intmuons(const xAOD::TruthParticle *truth) const
MissingETBase::Source::TruthType m_truth_type
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventKey
Gaudi::Property< std::string > m_inputType
virtual bool accept(const xAOD::IParticle *object) const override
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Gaudi::Property< double > m_truthmu_minPt
virtual StatusCode executeTool(xAOD::MissingET *metTerm, xAOD::MissingETComponentMap *metMap) const override
bool accept_int(const xAOD::TruthParticle *truth) const
bool accept_nonint(const xAOD::TruthParticle *truth) const
bool accept_intout(const xAOD::TruthParticle *truth) const
Gaudi::Property< double > m_truthmu_maxEta
Gaudi::Property< double > m_det_maxEta
Class providing the definition of the 4-vector interface.
void setSource(MissingETBase::Types::bitmask_t src)
Set the source of the MET object.
const TruthParticle * truthParticle(size_t index) const
Get a pointer to one of the truth particles.
size_t nTruthParticles() const
Get the number of truth particles.
int pdgId() const
PDG ID code.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
bool isGenStable() const
Check if this is generator stable particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
bool isMuon() const
Whether the particle is a muon (or antimuon)
bool isInteracting(const T &p)
Identify if the particle with given PDG ID would not interact with the detector, i....
uint64_t bitmask_t
Type for status word bit mask.
xAOD::MissingETComponent_v1::Weight weight_t
Type for kinematic weight.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
@ TruthParticle
The object is a truth particle.
Definition ObjectType.h:67
TruthEventContainer_v1 TruthEventContainer
Declare the latest version of the truth event container.
MissingETComponentMap_v1 MissingETComponentMap
Version control by type definition.
MissingET_v1 MissingET
Version control by type defintion.
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition TruthEvent.h:17
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
@ Int
Indicator for MET from interacting particles within the nominal acceptance of the detector.
@ TruthMuons
Indicator for muons from MC truth (muons from the interaction)
@ NonInt
Indicator for MET from non-interacting particles generated in the collision.
@ IntOut
Indicator for MET contributions from particles outside of the acceptance of the detector (typically ...
static MissingETComponentMap::const_iterator find(const MissingETComponentMap *pMap, const MissingET *pmetObj)
Find non-modifiable contribution for a given MET object.
Collection of functions managing the MET composition map and association map.