Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DerivationFramework::TruthBornLeptonCollectionMaker Class Reference

#include <TruthBornLeptonCollectionMaker.h>

Inheritance diagram for DerivationFramework::TruthBornLeptonCollectionMaker:
Collaboration diagram for DerivationFramework::TruthBornLeptonCollectionMaker:

Public Member Functions

 TruthBornLeptonCollectionMaker (const std::string &t, const std::string &n, const IInterface *p)
 
 ~TruthBornLeptonCollectionMaker ()
 
StatusCode initialize ()
 
virtual StatusCode addBranches () const
 

Private Member Functions

bool hasBareDescendent (const xAOD::TruthParticle *p) const
 Helper function for finding bare descendents of born leptons. More...
 

Private Attributes

SG::ReadHandleKey< xAOD::TruthParticleContainerm_particlesKey {this, "ParticlesKey", "TruthParticles", "Name of TruthParticle key for input"}
 < Input particle collection key More...
 
SG::WriteHandleKey< xAOD::TruthParticleContainerm_collectionName {this, "NewCollectionName", "", "Name of TruthParticle key for output"}
 
SG::WriteDecorHandleKey< xAOD::TruthParticleContainerm_originDecoratorKey {this, "classifierParticleOrigin", "TruthParticles.classifierParticleOrigin", "Particle origin decoration, set at initialisation"}
 
SG::WriteDecorHandleKey< xAOD::TruthParticleContainerm_typeDecoratorKey {this, "classifierParticleType","TruthParticles.classifierParticleType", "Particle type decoration, set at initialisation"}
 
SG::WriteDecorHandleKey< xAOD::TruthParticleContainerm_outcomeDecoratorKey {this, "classifierParticleOutCome", "TruthParticles.classifierParticleOutCome", "Particle outcome decoration, set at initialisation"}
 
SG::WriteDecorHandleKey< xAOD::TruthParticleContainerm_classificationDecoratorKey {this, "Classification", "TruthParticles.Classification", "Classification code decorator, set at initialisation"}
 
ServiceHandle< StoreGateSvcm_metaStore
 Handle on the metadata store for init. More...
 

Detailed Description

Definition at line 31 of file TruthBornLeptonCollectionMaker.h.

Constructor & Destructor Documentation

◆ TruthBornLeptonCollectionMaker()

DerivationFramework::TruthBornLeptonCollectionMaker::TruthBornLeptonCollectionMaker ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Definition at line 27 of file TruthBornLeptonCollectionMaker.cxx.

30  : base_class(t,n,p)
31  , m_metaStore( "MetaDataStore", n )
32 {
33  declareProperty( "MetaDataStore", m_metaStore );
34 }

◆ ~TruthBornLeptonCollectionMaker()

DerivationFramework::TruthBornLeptonCollectionMaker::~TruthBornLeptonCollectionMaker ( )

Definition at line 37 of file TruthBornLeptonCollectionMaker.cxx.

37  {
38 }

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::TruthBornLeptonCollectionMaker::addBranches ( ) const
virtual

Definition at line 73 of file TruthBornLeptonCollectionMaker.cxx.

74 {
75  // Event context
76  const EventContext& ctx = Gaudi::Hive::currentContext();
77 
78  // Set up for some metadata handling
79  static const bool is_sherpa = [this]() {
80  bool is_sherpa = false;
81  // TODO: needs to be made MT-friendly
82  if (m_metaStore->contains<xAOD::TruthMetaDataContainer>("TruthMetaData")){
83  // Note that I'd like to get this out of metadata in general, but it seems that the
84  // metadata isn't fully available in initialize, and since this is a const function
85  // I can only do the retrieve every event, rather than lazy-initializing, since this
86  // metadata ought not change during a run
87  const xAOD::TruthMetaDataContainer* truthMetaData(nullptr);
88  // Shamelessly stolen from the file meta data tool
89 
90  if (m_metaStore->retrieve(truthMetaData).isSuccess() && !truthMetaData->empty()){
91  // Let's just be super sure...
92  const std::string gens = truthMetaData->at(0)->generators();
93  is_sherpa = (gens.find("sherpa")==std::string::npos &&
94  gens.find("Sherpa")==std::string::npos &&
95  gens.find("SHERPA")==std::string::npos) ? false : true;
96  } // Seems to be the only sure way...
97  else {
98  ATH_MSG_WARNING("Found xAODTruthMetaDataContainer empty! Configuring to be NOT Sherpa.");
99  }
100  ATH_MSG_INFO("From metadata configured: Sherpa? " << is_sherpa);
101  }
102  else {
103  ATH_MSG_WARNING("Could not find metadata container in storegate; assuming NOT Sherpa");
104  }
105  return is_sherpa;
106  }();
107 
108  // Retrieve truth collections
110  if (!truthParticles.isValid()) {
111  ATH_MSG_ERROR("Couldn't retrieve TruthParticle collection with name " << m_particlesKey);
112  return StatusCode::FAILURE;
113  }
114 
115  // Create the new particle containers and WriteHandles
117  ATH_CHECK(newParticlesWriteHandle.record(std::make_unique<xAOD::TruthParticleContainer>(),
118  std::make_unique<xAOD::TruthParticleAuxContainer>()));
119  ATH_MSG_DEBUG( "Recorded new TruthParticleContainer with key: " << (m_collectionName.key()));
120 
121  // Set up decorators
126 
127  static const SG::ConstAccessor<unsigned int> classifierParticleTypeAcc("classifierParticleType");
128  static const SG::ConstAccessor<unsigned int> classifierParticleOriginAcc("classifierParticleOrigin");
129  static const SG::ConstAccessor<unsigned int> classifierParticleOutComeAcc("classifierParticleOutCome");
130  static const SG::ConstAccessor<unsigned int> ClassificationAcc("Classification");
131 
132  // add relevant particles to new collection
133  for (unsigned int i=0; i<truthParticles->size(); ++i) {
134  // Grab the particle
135  const xAOD::TruthParticle* theParticle = (*truthParticles)[i];
136  if (!theParticle) continue; // Protection against null pointers
137  if (!theParticle->isLepton()) continue; // Only include leptons!
138 
139  if (is_sherpa) {
140  // For Sherpa, skip is not status 11
141  if (MC::isPhysical(theParticle)) continue;
142  // Sherpa may have two sets of status == 11 leptons. Here we take the first set.
143  // To do so, we check the first status == 11 leptons,
144  // check that it has a child a parent barecode corresponding the the lepton's uniqueID
145  // If so, then save this parent uniqueID and skip all status 11 leptons with this parent uniqueID.
146  bool has_parent_of_same_flavour = false;
147  if (theParticle->prodVtx())
148  for (size_t p = 0; p < theParticle->prodVtx()->nIncomingParticles(); ++p){
149  if (theParticle->parent(p)->pdg_id() == theParticle->pdg_id()) has_parent_of_same_flavour = true;
150  }
151  if (has_parent_of_same_flavour) continue;
152  } else {
153  // Some generators, look for leptons coming from vertices with other leptons
154  bool physical = false, has_V = false;
155  if (!MC::isPhysical(theParticle) && theParticle->hasProdVtx()){
156  const xAOD::TruthVertex * prod = theParticle->prodVtx();
157  // Look for other leptons in the production vertex and check if those are physical
158  for (size_t p = 0; p < prod->nOutgoingParticles(); ++p){
159  if (prod->outgoingParticle(p) && prod->outgoingParticle(p)->isLepton() && MC::isPhysical(prod->outgoingParticle(p))){
160  physical = true;
161  break;
162  }
163  }
164  // See if there was a boson going *into* the vertex
165  for (size_t p = 0; p < prod->nIncomingParticles(); ++p){
166  if (prod->incomingParticle(p) && (prod->incomingParticle(p)->isZ() || prod->incomingParticle(p)->isW() || prod->incomingParticle(p)->isHiggs()) ){
167  has_V = true; // Found a vector boson
168  break;
169  }
170  }
171  }
172 
173  // Now we have all the information for the special case of V->l(born) l(bare) l(born) l(bare)
174  // AV: The comment above, most likely is related to the case when the event is passed to PHOTOS with an option to keep
175  // the "documentation" particles, i.e. particles before the photon emission.
176  // These particles in PHOTOS are attached to the same vertex, but have different status, e.g. 3.
177  // The momentum conservation, is, of course, violated.
178  if ( !(physical && has_V && !MC::isPhysical(theParticle)) && !MC::Pythia8::isConditionB(theParticle)){
179  // Skip if it has no boson parent, or has no descendent that is a bare lepton
180  if (!hasBareDescendent( theParticle ) ) continue;
181  const xAOD::TruthVertex * prod = theParticle->prodVtx();
182  if (!prod) continue;
183  if (prod->nIncomingParticles() < 1) continue;
184  size_t bad_parent = 0;
185  for (size_t p = 0; p < prod->nIncomingParticles(); ++p){
186  if (!theParticle->parent(p)) { bad_parent++; continue;}
187  if (!theParticle->parent(p)->isZ() && !theParticle->parent(p)->isW() && !theParticle->parent(p)->isHiggs()) bad_parent++;
188  }
189  if (bad_parent != 0) continue;
190 
191  }
192  } // End of treatment for generators that are not Sherpa
193 
194  // Add this particle to the new collection
195  xAOD::TruthParticle* xTruthParticle = new xAOD::TruthParticle();
196  newParticlesWriteHandle->push_back( xTruthParticle );
197  // Fill with numerical content
198  *xTruthParticle=*theParticle;
199  // Copy over the decorations if they are available
200  typeDecorator(*xTruthParticle) = classifierParticleTypeAcc.withDefault(*theParticle, 0);
201  originDecorator(*xTruthParticle) = classifierParticleOriginAcc.withDefault(*theParticle, 0);
202  outcomeDecorator(*xTruthParticle) = classifierParticleOutComeAcc.withDefault(*theParticle, 0);
203  classificationDecorator(*xTruthParticle) = ClassificationAcc.withDefault(*theParticle, 0);
204  } // Loop over all particles
205 
206  return StatusCode::SUCCESS;
207 }

◆ hasBareDescendent()

bool DerivationFramework::TruthBornLeptonCollectionMaker::hasBareDescendent ( const xAOD::TruthParticle p) const
private

Helper function for finding bare descendents of born leptons.

Definition at line 210 of file TruthBornLeptonCollectionMaker.cxx.

211 {
212  // Null pointer check
213  if (!p) return false;
214  // If we hit a bare descendent, then we're a winnner
215  if (p->isLepton() && MC::isStable(p) ) return true;
216  // Otherwise look through all the children
217  for (size_t c=0;c<p->nChildren();++c){
218  if (!p->child(c)) continue; // Null pointer protection
219  if (p->pdgId()!=p->child(c)->pdgId()) continue; // Different particle child
220  if (hasBareDescendent( p->child(c) )) return true;
221  }
222  // No luck -- this branch is a dead end
223  return false;
224 }

◆ initialize()

StatusCode DerivationFramework::TruthBornLeptonCollectionMaker::initialize ( )

Definition at line 41 of file TruthBornLeptonCollectionMaker.cxx.

42 {
43  ATH_MSG_VERBOSE("initialize() ...");
44 
45  // Input truth particles
47  ATH_MSG_INFO("Using " << m_particlesKey.key() << " as the input truth container key");
48 
49  // Output truth particles
50  if (m_collectionName.empty()) {
51  ATH_MSG_FATAL("No key provided for the new truth particle collection");
52  return StatusCode::FAILURE;
53  } else {ATH_MSG_INFO("New truth particle collection key: " << m_collectionName.key() );}
55 
56  // Decoration keys
57  m_originDecoratorKey = m_collectionName.key() + ".classifierParticleOrigin";
59  m_typeDecoratorKey = m_collectionName.key() + ".classifierParticleType";
61  m_outcomeDecoratorKey = m_collectionName.key() + ".classifierParticleOutCome";
63  m_classificationDecoratorKey = m_collectionName.key() + ".Classification";
65 
66  // TODO: needs to be made MT-friendly
67  ATH_CHECK( m_metaStore.retrieve() );
68 
69  return StatusCode::SUCCESS;
70 }

Member Data Documentation

◆ m_classificationDecoratorKey

SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_classificationDecoratorKey {this, "Classification", "TruthParticles.Classification", "Classification code decorator, set at initialisation"}
private

Definition at line 52 of file TruthBornLeptonCollectionMaker.h.

◆ m_collectionName

SG::WriteHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_collectionName {this, "NewCollectionName", "", "Name of TruthParticle key for output"}
private

Definition at line 43 of file TruthBornLeptonCollectionMaker.h.

◆ m_metaStore

ServiceHandle<StoreGateSvc> DerivationFramework::TruthBornLeptonCollectionMaker::m_metaStore
private

Handle on the metadata store for init.

Definition at line 55 of file TruthBornLeptonCollectionMaker.h.

◆ m_originDecoratorKey

SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_originDecoratorKey {this, "classifierParticleOrigin", "TruthParticles.classifierParticleOrigin", "Particle origin decoration, set at initialisation"}
private

Definition at line 46 of file TruthBornLeptonCollectionMaker.h.

◆ m_outcomeDecoratorKey

SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_outcomeDecoratorKey {this, "classifierParticleOutCome", "TruthParticles.classifierParticleOutCome", "Particle outcome decoration, set at initialisation"}
private

Definition at line 50 of file TruthBornLeptonCollectionMaker.h.

◆ m_particlesKey

SG::ReadHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_particlesKey {this, "ParticlesKey", "TruthParticles", "Name of TruthParticle key for input"}
private

< Input particle collection key

Output particle collection key

Definition at line 40 of file TruthBornLeptonCollectionMaker.h.

◆ m_typeDecoratorKey

SG::WriteDecorHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthBornLeptonCollectionMaker::m_typeDecoratorKey {this, "classifierParticleType","TruthParticles.classifierParticleType", "Particle type decoration, set at initialisation"}
private

Definition at line 48 of file TruthBornLeptonCollectionMaker.h.


The documentation for this class was generated from the following files:
xAOD::TruthVertex_v1::nOutgoingParticles
size_t nOutgoingParticles() const
Get the number of outgoing particles.
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle< xAOD::TruthParticleContainer >
DerivationFramework::TruthBornLeptonCollectionMaker::m_originDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_originDecoratorKey
Definition: TruthBornLeptonCollectionMaker.h:47
DerivationFramework::TruthBornLeptonCollectionMaker::m_outcomeDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_outcomeDecoratorKey
Definition: TruthBornLeptonCollectionMaker.h:51
xAOD::TruthParticle_v1::isW
bool isW() const
Check if this particle is a W boson.
SG::ConstAccessor< unsigned int >
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
xAOD::TruthParticle_v1::pdg_id
int pdg_id() const
PDG ID code.
Definition: TruthParticle_v1.h:52
xAOD::TruthParticle_v1::isZ
bool isZ() const
Check if this particle is a Z boson.
MC::isPhysical
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
Definition: HepMCHelpers.h:51
xAOD::TruthParticle_v1::isLepton
bool isLepton() const
Whether the particle is a lepton.
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
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:37
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAOD::TruthParticle_v1::hasProdVtx
bool hasProdVtx() const
Check for a production vertex on this particle.
Definition: TruthParticle_v1.cxx:74
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TruthVertex_v1::incomingParticle
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
Definition: TruthVertex_v1.cxx:69
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DerivationFramework::TruthBornLeptonCollectionMaker::m_collectionName
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_collectionName
Definition: TruthBornLeptonCollectionMaker.h:44
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::TruthParticle_v1::prodVtx
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Definition: TruthParticle_v1.cxx:80
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
DerivationFramework::TruthBornLeptonCollectionMaker::m_typeDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_typeDecoratorKey
Definition: TruthBornLeptonCollectionMaker.h:49
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition: HepMCHelpers.h:45
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
xAOD::TruthParticle_v1::isHiggs
bool isHiggs() const
Check if this particle is a Higgs boson.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TruthVertex_v1::nIncomingParticles
size_t nIncomingParticles() const
Get the number of incoming particles.
Definition: TruthVertex_v1.cxx:47
DerivationFramework::TruthBornLeptonCollectionMaker::hasBareDescendent
bool hasBareDescendent(const xAOD::TruthParticle *p) const
Helper function for finding bare descendents of born leptons.
Definition: TruthBornLeptonCollectionMaker.cxx:210
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:131
DerivationFramework::TruthBornLeptonCollectionMaker::m_classificationDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_classificationDecoratorKey
Definition: TruthBornLeptonCollectionMaker.h:53
MC::Pythia8::isConditionB
bool isConditionB(const T &p)
Definition: HepMCHelpers.h:25
DerivationFramework::TruthBornLeptonCollectionMaker::m_metaStore
ServiceHandle< StoreGateSvc > m_metaStore
Handle on the metadata store for init.
Definition: TruthBornLeptonCollectionMaker.h:55
python.compressB64.c
def c
Definition: compressB64.py:93
xAOD::TruthVertex_v1::outgoingParticle
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
Definition: TruthVertex_v1.cxx:119
DerivationFramework::TruthBornLeptonCollectionMaker::m_particlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
< Input particle collection key
Definition: TruthBornLeptonCollectionMaker.h:41