ATLAS Offline Software
Loading...
Searching...
No Matches
D3PD::PhotonTruthTool Class Reference

#include <PhotonTruthTool.h>

Inheritance diagram for D3PD::PhotonTruthTool:
Collaboration diagram for D3PD::PhotonTruthTool:

Public Member Functions

 PhotonTruthTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard Gaudi tool constructor.
virtual StatusCode initialize ()
 Standard Gaudi initialize method.
const xAOD::TruthParticletoTruthParticle (const xAOD::Photon &g) const
 Go from a photon to a matching TruthParticle.
bool getMCConv (const xAOD::TruthParticle *truePart, float &RconvMC, float &ZconvMC) const
 Check a truth particle for a conversion.
bool isPromptPhotonMC (const xAOD::TruthParticle *truePart) const
 Test for a prompt photon.
bool isPromptParticleMC (const xAOD::TruthParticle *truePart) const
 Test for a prompt particle.
bool isQuarkBremMC (const xAOD::TruthParticle *truePart) const
 Test for a brem.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

bool isFinalStatePhotonMC (const xAOD::TruthParticle *truePart) const
 Test for a final-state photon.
bool isFinalState (const xAOD::TruthParticle *truePart) const
 Test for a final-state particle.
const xAOD::TruthParticlegetMother (const xAOD::TruthParticle *p) const
 Get the (first) mother particle of p.
const xAOD::TruthVertexgetMotherVert (const xAOD::TruthParticle *p) const
 Get the mother vertex for p.
std::vector< const xAOD::TruthParticle * > getMothers (const xAOD::TruthParticle *p) const
 Return list of mother particles of p.
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

ToolHandle< IMCTruthClassifierm_classifier
 Property: classifier tool.
float m_zTruthConv
 Property: Conversion vertex z cut.
float m_rTruthConv
 Property: Conversion vertex r cut.
bool m_useG4Particles
 Property.
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default).
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default).
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 33 of file PhotonTruthTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ PhotonTruthTool()

D3PD::PhotonTruthTool::PhotonTruthTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Standard Gaudi tool constructor.

Parameters
typeThe name of the tool type.
nameThe tool name.
parentThe tool's Gaudi parent.

Definition at line 30 of file PhotonTruthTool.cxx.

33 : AthAlgTool (type, name, parent),
34 m_classifier ("MCTruthClassifier")
35{
36 declareProperty ("Classifier", m_classifier, "Classifier tool instance.");
37 declareProperty ("ZTruthConv", m_zTruthConv = 50e3);
38 declareProperty ("RTruthConv", m_rTruthConv = 800);
39 declareProperty ("UseG4Particles", m_useG4Particles = false);
40}
AthAlgTool()
Default constructor:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ToolHandle< IMCTruthClassifier > m_classifier
Property: classifier tool.
bool m_useG4Particles
Property.
float m_zTruthConv
Property: Conversion vertex z cut.
float m_rTruthConv
Property: Conversion vertex r cut.

Member Function Documentation

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ getMCConv()

bool D3PD::PhotonTruthTool::getMCConv ( const xAOD::TruthParticle * truePart,
float & RconvMC,
float & ZconvMC ) const

Check a truth particle for a conversion.

Parameters
truePartThe particle to check.
[out]RconvMCRadius of the conversion.
[out]ZconvMCZ of the conversion.
Returns
True if this is a conversion; otherwise false.

Definition at line 74 of file PhotonTruthTool.cxx.

77{
78 RconvMC = +9.999e+10 ;
79 ZconvMC = +9.999e+10 ;
80 if (!truePart) return false;
81
82 const xAOD::TruthVertex* v = truePart->decayVtx();
83 if (!v || v->nOutgoingParticles() < 2)
84 return false;
85
86 int pdgId = truePart->pdgId();
87
88 RconvMC = v->perp();
89 ZconvMC = v->z();
90
91 bool OKint = ( RconvMC < m_rTruthConv ) && ( fabs(ZconvMC) < m_zTruthConv );
92
93 if ( pdgId == 22 ) { // photon
94 if ( v->nOutgoingParticles() == 2 ) {
95 int pdgChild[2] = {0};
96 for ( unsigned u=0; u<2 ; ++u) {
97 const xAOD::TruthParticle* p = v->outgoingParticle(u);
98 if (p)
99 pdgChild[u] = p->pdgId();
100 }
101 if ( pdgChild[0]+pdgChild[1]==0 && pdgChild[0]*pdgChild[1]==-121 ) {
102 // gamma -> e+e-
103 return OKint ;
104 }
105 }
106 }
107 else if ( std::abs(pdgId) == 11 ) { // e+/e-
108 v = truePart->prodVtx();
109 if ( v->nIncomingParticles()==1 && v->nOutgoingParticles()==2 ) {
110 int pdgBrother[2] = {0};
111 for ( unsigned u=0 ; u<2 ; ++u ) {
112 const xAOD::TruthParticle* p = v->outgoingParticle(u);
113 if (p)
114 pdgBrother[u] = p->pdgId();
115 }
116 if ( pdgBrother[0]+pdgBrother[1]==(22+pdgId) &&
117 pdgBrother[0]*pdgBrother[1]==(22*pdgId) )
118 {
119 // e(+/-) -> e(+/-)gamma
120 return OKint ;
121 }
122 }
123 }
124 return false ;
125}
int pdgId() const
PDG ID code.
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ getMother()

const xAOD::TruthParticle * D3PD::PhotonTruthTool::getMother ( const xAOD::TruthParticle * p) const
private

Get the (first) mother particle of p.

Definition at line 251 of file PhotonTruthTool.cxx.

252{
253 const xAOD::TruthVertex* v = getMotherVert (p);
254
255 if (!v || v->nIncomingParticles() == 0)
256 return 0;
257
258 return v->incomingParticle(0);
259}
const xAOD::TruthVertex * getMotherVert(const xAOD::TruthParticle *p) const
Get the mother vertex for p.

◆ getMothers()

std::vector< const xAOD::TruthParticle * > D3PD::PhotonTruthTool::getMothers ( const xAOD::TruthParticle * p) const
private

Return list of mother particles of p.

Definition at line 266 of file PhotonTruthTool.cxx.

267{
268 std::vector<const xAOD::TruthParticle*> out;
269 const xAOD::TruthVertex* v = getMotherVert (p);
270
271 if (v) {
272 int n = v->nIncomingParticles();
273 out.reserve (n);
274 for (int i = 0; i < n; i++)
275 out.push_back (v->incomingParticle(i));
276 }
277
278 return out;
279}

◆ getMotherVert()

const xAOD::TruthVertex * D3PD::PhotonTruthTool::getMotherVert ( const xAOD::TruthParticle * p) const
private

Get the mother vertex for p.

Definition at line 231 of file PhotonTruthTool.cxx.

232{
233 const xAOD::TruthVertex* v = p->prodVtx();
234
235 // if mother is a duplicate, try climbing up the tree by one step...
236 while (v && v->nIncomingParticles() == 1 &&
237 v->incomingParticle(0)->pdgId() == p->pdgId())
238 {
239 p = v->incomingParticle(0);
240 v = p->prodVtx();
241 }
242
243 return v;
244}

◆ initialize()

StatusCode D3PD::PhotonTruthTool::initialize ( )
virtual

Standard Gaudi initialize method.

Definition at line 46 of file PhotonTruthTool.cxx.

47{
48 CHECK( AthAlgTool::initialize() );
49 CHECK( m_classifier.retrieve() );
50 return StatusCode::SUCCESS;
51}
#define CHECK(...)
Evaluate an expression and check for errors.

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ isFinalState()

bool D3PD::PhotonTruthTool::isFinalState ( const xAOD::TruthParticle * truePart) const
private

Test for a final-state particle.

Definition at line 203 of file PhotonTruthTool.cxx.

204{
205 if ( truePart == nullptr ) return false;
206 if ( !MC::isStable(truePart)) return false;
207 if ( !m_useG4Particles ) return ( !HepMC::is_simulation_particle(truePart) );
208 // if it is a photon, keep it regardless of its Geant interaction
209 if ( MC::isPhoton(truePart) ) return true ;
210 // reject Geant electron from conversion
211 if ( MC::isElectron(truePart) && HepMC::is_simulation_particle(truePart) ) {
212 const xAOD::TruthParticle* mother = getMother(truePart) ;
213 if ( mother!=0 && MC::isPhoton(mother) ) return false ;
214 }
215
216 // reject particles interacted in detector
217 const xAOD::TruthVertex* v = truePart->decayVtx();
218 if (!v) return false;// should never happen, but just in case...
219 if ( v->nOutgoingParticles()>0 ) {
220 if ( v->perp()<m_rTruthConv
221 && fabs(v->z())<m_zTruthConv ) return false ;
222 }
223 return true ;
224}
const xAOD::TruthParticle * getMother(const xAOD::TruthParticle *p) const
Get the (first) mother particle of p.
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
bool isPhoton(const T &p)
bool isElectron(const T &p)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.

◆ isFinalStatePhotonMC()

bool D3PD::PhotonTruthTool::isFinalStatePhotonMC ( const xAOD::TruthParticle * truePart) const
private

Test for a final-state photon.

Definition at line 192 of file PhotonTruthTool.cxx.

194{
195 return ( isFinalState(truePart) && MC::isPhoton(truePart) ) ;
196}
bool isFinalState(const xAOD::TruthParticle *truePart) const
Test for a final-state particle.

◆ isPromptParticleMC()

bool D3PD::PhotonTruthTool::isPromptParticleMC ( const xAOD::TruthParticle * truePart) const

Test for a prompt particle.

Definition at line 141 of file PhotonTruthTool.cxx.

143{
144 if ( truePart == 0 ) return false ;
145 const std::vector<const xAOD::TruthParticle*> mothers =
146 getMothers(truePart);
147 unsigned nmothers = mothers.size() ;
148 if ( nmothers == 0 ) {
149 // particles with NO mother are NEVER classified as PROMPT:
150 return false ;
151 }
152 else if ( nmothers == 1 ) {
153 // particles with ONE mother are classified as PROMPT if coming
154 // from non-QCD-boson decay:
155 // (including exotics like heavy bosons, MSSM Higgs, graviton)
156 int aPdgMother = abs(mothers[0]->pdgId());
157 return (( aPdgMother>=23 && aPdgMother<=39 ) || aPdgMother==5000039 ) ;
158 }
159 else {
160 // particles with more mothers are classified as PROMPT
161 // if they come from at least 1 parton:
162 // (is this sensible?)
163 int nParentPartons = 0 ;
164 for ( unsigned u=0 ; u<nmothers ; ++u ) {
165 int pdgMother = mothers[u]->pdgId() ;
166 if ( pdgMother==21 || ( std::abs(pdgMother)<7 && pdgMother!=0 ) )
167 ++nParentPartons ;
168 }
169 return ( nParentPartons >= 1 ) ;
170 }
171}
std::vector< const xAOD::TruthParticle * > getMothers(const xAOD::TruthParticle *p) const
Return list of mother particles of p.

◆ isPromptPhotonMC()

bool D3PD::PhotonTruthTool::isPromptPhotonMC ( const xAOD::TruthParticle * truePart) const

Test for a prompt photon.

Definition at line 131 of file PhotonTruthTool.cxx.

133{
134 return ( isFinalStatePhotonMC(truePart) && isPromptParticleMC(truePart) ) ;
135}
bool isFinalStatePhotonMC(const xAOD::TruthParticle *truePart) const
Test for a final-state photon.
bool isPromptParticleMC(const xAOD::TruthParticle *truePart) const
Test for a prompt particle.

◆ isQuarkBremMC()

bool D3PD::PhotonTruthTool::isQuarkBremMC ( const xAOD::TruthParticle * truePart) const

Test for a brem.

Definition at line 177 of file PhotonTruthTool.cxx.

179{
180 if ( ! isFinalStatePhotonMC(truePart) ) return false ;
181 const std::vector<const xAOD::TruthParticle*> mothers =
182 getMothers(truePart) ;
183 if ( mothers.size() != 1 ) return false ;
184 int pdgMother = mothers[0]->pdgId() ;
185 return ( pdgMother==21 || ( std::abs(pdgMother)<7 && pdgMother!=0 ) ) ;
186}

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, and AthCheckedComponent<::AthAlgTool >.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ toTruthParticle()

const xAOD::TruthParticle * D3PD::PhotonTruthTool::toTruthParticle ( const xAOD::Photon & g) const

Go from a photon to a matching TruthParticle.

Parameters
gThe input photon.
cacheTruth classifier association cache.
Returns
The matching TruthParticle, or null.
Parameters
gThe input photon.
Returns
The matching TruthParticle, or null.

Definition at line 60 of file PhotonTruthTool.cxx.

61{
62 return std::get<2>(m_classifier->particleTruthClassifier_full(&g));
63}

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_classifier

ToolHandle<IMCTruthClassifier> D3PD::PhotonTruthTool::m_classifier
private

Property: classifier tool.

Definition at line 110 of file PhotonTruthTool.h.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default).

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default).

Definition at line 390 of file AthCommonDataStore.h.

◆ m_rTruthConv

float D3PD::PhotonTruthTool::m_rTruthConv
private

Property: Conversion vertex r cut.

Definition at line 116 of file PhotonTruthTool.h.

◆ m_useG4Particles

bool D3PD::PhotonTruthTool::m_useG4Particles
private

Property.

Definition at line 119 of file PhotonTruthTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.

◆ m_zTruthConv

float D3PD::PhotonTruthTool::m_zTruthConv
private

Property: Conversion vertex z cut.

Definition at line 113 of file PhotonTruthTool.h.


The documentation for this class was generated from the following files: