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 Attributes | List of all members
DerivationFramework::Truth3CollectionMaker Class Reference

#include <Truth3CollectionMaker.h>

Inheritance diagram for DerivationFramework::Truth3CollectionMaker:
Collaboration diagram for DerivationFramework::Truth3CollectionMaker:

Public Member Functions

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

Private Attributes

std::atomic< unsigned int > m_ntotpart
 
std::atomic< unsigned int > m_npasspart
 
std::string m_particlesKey
 
std::string m_collectionName
 
std::string m_partString
 
ToolHandle< IMCTruthClassifierm_classifier
 
bool m_runClassifier
 

Detailed Description

Definition at line 23 of file Truth3CollectionMaker.h.

Constructor & Destructor Documentation

◆ Truth3CollectionMaker()

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

Definition at line 20 of file Truth3CollectionMaker.cxx.

22  :
23 base_class(t,n,p),
24 //m_ntotvtx(0),
25 m_ntotpart(0),
26 //m_npassvtx(0),
27 m_npasspart(0),
28 m_particlesKey("TruthParticles"),
29 //m_verticesKey("TruthVertices"),
31 m_partString(""),
32 m_classifier("MCTruthClassifier/MCTruthClassifier"),
33 m_runClassifier(true)
34 {
35  declareProperty("ParticlesKey", m_particlesKey);
36  //declareProperty("VerticesKey", m_verticesKey);
37  declareProperty("NewCollectionName", m_collectionName);
38  declareProperty("ParticleSelectionString", m_partString);
39  declareProperty("MCTruthClassifier", m_classifier);
40  declareProperty("RunClassifier", m_runClassifier);
41 }

◆ ~Truth3CollectionMaker()

DerivationFramework::Truth3CollectionMaker::~Truth3CollectionMaker ( )

Definition at line 44 of file Truth3CollectionMaker.cxx.

44  {
45 }

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::Truth3CollectionMaker::addBranches ( ) const
overridevirtual

Definition at line 85 of file Truth3CollectionMaker.cxx.

86 {
87 
88  // Retrieve truth collections
89  const xAOD::TruthParticleContainer* importedTruthParticles;
90  if (evtStore()->retrieve(importedTruthParticles,m_particlesKey).isFailure()) {
91  ATH_MSG_ERROR("No TruthParticle collection with name " << m_particlesKey << " found in StoreGate!");
92  return StatusCode::FAILURE;
93  }
94 
95  // Create the new containers
96  xAOD::TruthParticleContainer* newParticleCollection = new xAOD::TruthParticleContainer();
97  CHECK( evtStore()->record( newParticleCollection, m_collectionName ) );
98  xAOD::TruthParticleAuxContainer* newParticleAuxCollection = new xAOD::TruthParticleAuxContainer();
99  CHECK( evtStore()->record( newParticleAuxCollection, m_collectionName + "Aux." ) );
100  newParticleCollection->setStore( newParticleAuxCollection );
101  ATH_MSG_DEBUG( "Recorded new TruthParticleContainer with key: " << m_collectionName);
102 
103  // Set up a mask with the same entries as the full collections
104  unsigned int nParticles = importedTruthParticles->size();
105  m_ntotpart += nParticles;
106 
107  // Set up decorators
108  static const SG::AuxElement::Decorator< ElementLink<xAOD::TruthParticleContainer> > linkDecorator("originalTruthParticle");
109  static const SG::AuxElement::Decorator< int > originDecorator("particleMotherPdgId");
110  static const SG::AuxElement::Decorator< int > typeDecorator("particleOriginBarcode"); // FIXME barcode-based
111  static const SG::AuxElement::Decorator< float > typeDecoratorMass("particleOriginMass");
112  static const SG::AuxElement::Decorator< int > tauprongDecorator("nprong");
113  static const SG::AuxElement::Decorator< int > tautypeDecorator("islep");
114 
115  std::vector<int> entries;
116 
117  // Execute the text parsers and update the mask
118  if (!m_partString.empty()) {
119  entries = m_parser->evaluateAsVector();
120  // check the sizes are compatible
121  if (nParticles != entries.size() ) {
122  ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used TruthParticles?");
123  return StatusCode::FAILURE;
124  } else {
125  // add relevant particles to new collection
126  for (unsigned int i=0; i<nParticles; ++i) {
127  ElementLink<xAOD::TruthParticleContainer> eltp(*importedTruthParticles,i);
128  if (entries[i]==1) {
129 
130  const xAOD::TruthParticle* theParticle = (*importedTruthParticles)[i];
131 
132  //SUSYTRUTH definitions are based on Appendix A in http://arxiv.org/pdf/1403.4853v1.pdf.
133 
134  //SUSYTRUTH Leptons
135  if (theParticle->isLepton()){
136  bool drop = false;
137  if (!theParticle->hasProdVtx()) drop = true;
138  else{
139  const int parentPDGID = abs(theParticle->prodVtx()->incomingParticle(0)->pdgId());
140  const double parentMass = theParticle->prodVtx()->incomingParticle(0)->p4().M()/1000.;
141  if (MC::isW(parentPDGID) && parentMass < 20){ //semi-leptonic b-decays in Herwig++ where the off-shell W is saved
142  drop = true;
143  }
144  else if (!MC::isW(parentPDGID) && !MC::isTau(parentPDGID)){ //what about W decays in Sherpa?
145  drop = true;
146  }
147  else if (MC::isTau(parentPDGID)){//check to make sure the tau came from a W
148  if (theParticle->prodVtx()->incomingParticle(0)->hasProdVtx()){
149  const xAOD::TruthParticle * mother_hold = theParticle->prodVtx()->incomingParticle(0)->prodVtx()->incomingParticle(0);
150  int mcount = 0;
151  while (mother_hold->hasProdVtx() && MC::isTau(mother_hold)){
152  mcount++;
153  if (mcount > 10){ //should not ever come in here, but just in case there is a closed loop somewhere.
154  break;
155  }
156  mother_hold = mother_hold->prodVtx()->incomingParticle(0);
157  }
158  if (mcount > 10 || !MC::isW(mother_hold)){
159  drop = true;
160  }
161  else{
162  //keep
163  }
164  }
165  else{
166  drop = true;
167  }
168  }
169  }
170  if (drop){
171  entries[i]=0;
172  continue;
173  }
174  }
175 
176  xAOD::TruthParticle* xTruthParticle = new xAOD::TruthParticle();
177  newParticleCollection->push_back( xTruthParticle );
178 
179  int motherBarcode = HepMC::INVALID_PARTICLE_ID;
180  int motherPDGid = 0;
181  float mothermass = 0.;
182  if (theParticle->hasProdVtx()){
183  const xAOD::TruthParticle * mother_hold = theParticle->prodVtx()->incomingParticle(0);
184  motherBarcode = HepMC::barcode(mother_hold);
185  motherPDGid = mother_hold->pdgId();
186  mothermass = mother_hold->p4().M()/1000.;
187  xTruthParticle->setBarcode(motherBarcode); // FIXME barcode-based
188  int mcount = 0;
189  //Let's find the first mother of mothers that has a different PDGid
190  while (mother_hold->hasProdVtx() && mother_hold->pdgId()==theParticle->pdgId()){
191  mcount++;
192  if (mcount > 10){
193  break; //should not come in here, but just in case we have a closed loop from a bug
194  }
195  mother_hold = mother_hold->prodVtx()->incomingParticle(0);
196  motherBarcode = HepMC::barcode(mother_hold); // FIXME barcode-based
197  motherPDGid = mother_hold->pdgId();
198  mothermass = mother_hold->p4().M()/1000.;
199  }
200  }
201 
202  *xTruthParticle=*theParticle;
203  xTruthParticle->setBarcode(motherBarcode); // FIXME barcode-based
204  originDecorator(*xTruthParticle) = motherPDGid;
205  typeDecorator(*xTruthParticle) = motherBarcode; // FIXME barcode-based
206  typeDecoratorMass(*xTruthParticle) = mothermass;
207 
208  //Check for tau decays
209  if ( MC::isTau(theParticle) && theParticle->hasDecayVtx() ) {
210  int nprong = 0;
211  int islep = 0;
212 
213  //Algorithm:
214  //Make a vector of all children of the tau. While one of the children has a child:
215  //Go down one level and store all of the children of the children. If no children have a child, stop.
216 
217  /*
218  std::vector< std::vector<const xAOD::TruthParticle *> > tau_family;
219  bool has_a_child = 0;
220  std::vector<const xAOD::TruthParticle *> tau_daughts_first;
221  for (unsigned int j=0; j<theParticle->nChildren(); j++){
222  const xAOD::TruthParticle * daught_hold = theParticle->decayVtx()->outgoingParticle(j);
223  tau_daughts_first.push_back(daught_hold);
224  if (daught_hold->hasDecayVtx()){
225  has_a_child = 1;
226  }
227  }
228  tau_family.push_back(tau_daughts_first);
229  int level = -1;
230  while (has_a_child){
231  level++;
232  has_a_child = 0;
233  std::vector<const xAOD::TruthParticle *> tau_daughts;
234  for (unsigned int j=0; j<tau_family[level].size(); j++){
235  for (unsigned int k=0; k<tau_family[level][j]->nChildren(); k++){
236  const xAOD::TruthParticle * daught_hold = tau_family[level][j]->decayVtx()->outgoingParticle(k);
237  tau_daughts.push_back(daught_hold);
238  if (daught_hold->hasDecayVtx()){
239  has_a_child = 1;
240  }
241  }
242  }
243  tau_family.push_back(tau_daughts);
244  }
245 
246  for (unsigned int i=0; i<tau_family.size(); i++){
247  for (unsigned int j=0; j<tau_family[i].size(); j++){
248  if (tau_family[i][j]->isChLepton()){
249  islep=1;
250  }
251  if (tau_family[i][j]->hasDecayVtx()){
252  continue;
253  }
254  if (tau_family[i][j]->isCharged()){
255  nprong++;
256  }
257  }
258  }
259  */
260 
261  //std::cout << "nprong " << nprong << " " << islep << std::endl;
262  tauprongDecorator(*xTruthParticle) = nprong;
263  tautypeDecorator(*xTruthParticle) = islep;
264  }
265  }
266  }
267  }
268  }
269  // Count the mask
270  for (unsigned int i=0; i<nParticles; ++i){
271  if (entries[i]) ++m_npasspart;
272  }
273 
274  return StatusCode::SUCCESS;
275 }

◆ finalize()

StatusCode DerivationFramework::Truth3CollectionMaker::finalize ( )
overridevirtual

Definition at line 75 of file Truth3CollectionMaker.cxx.

76 {
77  ATH_MSG_VERBOSE("finalize() ...");
78  //ATH_MSG_INFO("Processed "<< m_ntotvtx <<" truth vertices, "<< m_npassvtx << " were retained ");
79  ATH_MSG_INFO("Processed "<< m_ntotpart <<" truth particles, "<< m_npasspart << " were retained ");
80  ATH_CHECK( finalizeParser() );
81  return StatusCode::SUCCESS;
82 }

◆ initialize()

StatusCode DerivationFramework::Truth3CollectionMaker::initialize ( )
overridevirtual

Definition at line 48 of file Truth3CollectionMaker.cxx.

49 {
50  ATH_MSG_VERBOSE("initialize() ...");
51  if (m_runClassifier) ATH_CHECK(m_classifier.retrieve());
52 
53  if (m_particlesKey=="" /*|| m_verticesKey==""*/) {
54  ATH_MSG_FATAL("No truth particle collection provided to use as a basis for new collections");
55  return StatusCode::FAILURE;
56  } else {ATH_MSG_INFO("Using " << m_particlesKey << " as the source collections for new truth collections");}
57 
58  if (m_collectionName=="") {
59  ATH_MSG_FATAL("No key provided for the new truth particle collection");
60  return StatusCode::FAILURE;
61  } else {ATH_MSG_INFO("New truth particle collection key: " << m_collectionName );}
62 
63  if (m_partString=="") {
64  ATH_MSG_FATAL("No selection string provided");
65  return StatusCode::FAILURE;
66  } else {ATH_MSG_INFO("Truth particle selection string: " << m_partString );}
67 
68  // Set up the text-parsing machinery for thinning the truth directly according to user cuts
69  if ( !m_partString.empty() ) {
70  ATH_CHECK( initializeParser(m_partString) );
71  }
72  return StatusCode::SUCCESS;
73 }

Member Data Documentation

◆ m_classifier

ToolHandle<IMCTruthClassifier> DerivationFramework::Truth3CollectionMaker::m_classifier
private

Definition at line 37 of file Truth3CollectionMaker.h.

◆ m_collectionName

std::string DerivationFramework::Truth3CollectionMaker::m_collectionName
private

Definition at line 35 of file Truth3CollectionMaker.h.

◆ m_npasspart

std::atomic<unsigned int> DerivationFramework::Truth3CollectionMaker::m_npasspart
private

Definition at line 32 of file Truth3CollectionMaker.h.

◆ m_ntotpart

std::atomic<unsigned int> DerivationFramework::Truth3CollectionMaker::m_ntotpart
mutableprivate

Definition at line 32 of file Truth3CollectionMaker.h.

◆ m_particlesKey

std::string DerivationFramework::Truth3CollectionMaker::m_particlesKey
private

Definition at line 33 of file Truth3CollectionMaker.h.

◆ m_partString

std::string DerivationFramework::Truth3CollectionMaker::m_partString
private

Definition at line 36 of file Truth3CollectionMaker.h.

◆ m_runClassifier

bool DerivationFramework::Truth3CollectionMaker::m_runClassifier
private

Definition at line 38 of file Truth3CollectionMaker.h.


The documentation for this class was generated from the following files:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
DerivationFramework::Truth3CollectionMaker::m_collectionName
std::string m_collectionName
Definition: Truth3CollectionMaker.h:35
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::Truth3CollectionMaker::m_partString
std::string m_partString
Definition: Truth3CollectionMaker.h:36
DerivationFramework::Truth3CollectionMaker::m_particlesKey
std::string m_particlesKey
Definition: Truth3CollectionMaker.h:33
xAOD::TruthParticle_v1::setBarcode
void setBarcode(int value)
Set barcode.
HepMC::INVALID_PARTICLE_ID
constexpr int INVALID_PARTICLE_ID
Definition: MagicNumbers.h:57
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::Truth3CollectionMaker::m_ntotpart
std::atomic< unsigned int > m_ntotpart
Definition: Truth3CollectionMaker.h:32
xAOD::TruthParticle_v1::isLepton
bool isLepton() const
Whether the particle is a lepton.
xAOD::TruthParticleAuxContainer_v1
Auxiliary store for the truth vertices.
Definition: TruthParticleAuxContainer_v1.h:27
xAOD::TruthParticle_v1::hasDecayVtx
bool hasDecayVtx() const
Check for a decay vertex on this particle.
xAOD::TruthParticleAuxContainer
TruthParticleAuxContainer_v1 TruthParticleAuxContainer
Declare the latest version of the truth particle auxiliary container.
Definition: TruthParticleAuxContainer.h:15
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
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
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::TruthVertex_v1::incomingParticle
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
Definition: TruthVertex_v1.cxx:69
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
isTau
bool isTau(const T &p)
Definition: AtlasPID.h:197
xAOD::TruthParticle_v1::prodVtx
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Definition: TruthParticle_v1.cxx:80
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DerivationFramework::Truth3CollectionMaker::m_npasspart
std::atomic< unsigned int > m_npasspart
Definition: Truth3CollectionMaker.h:32
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
isW
bool isW(const T &p)
Definition: AtlasPID.h:355
DerivationFramework::Truth3CollectionMaker::m_runClassifier
bool m_runClassifier
Definition: Truth3CollectionMaker.h:38
entries
double entries
Definition: listroot.cxx:49
xAOD::TruthParticle_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
Definition: TruthParticle_v1.cxx:196
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DerivationFramework::Truth3CollectionMaker::m_classifier
ToolHandle< IMCTruthClassifier > m_classifier
Definition: Truth3CollectionMaker.h:37