ATLAS Offline Software
Loading...
Searching...
No Matches
METTruthTool.cxx
Go to the documentation of this file.
1
2
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
19
20// MET EDM
24
25// Truth EDM
28
29// Base EDM
31
32// Truth Utilities
34
35namespace met {
36
37 using std::vector;
38 //
39 using xAOD::IParticle;
40 //
41 using xAOD::TruthEvent;
45 //
46 using xAOD::MissingET;
49
51 // Public methods:
53
54 // Constructors
56 METTruthTool::METTruthTool(const std::string& 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}
#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.
defines an "iterator" over instances of a given type in StoreGateSvc
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.