ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
DerivationFramework::GenericTruthThinning Class Reference

#include <GenericTruthThinning.h>

Inheritance diagram for DerivationFramework::GenericTruthThinning:
Collaboration diagram for DerivationFramework::GenericTruthThinning:

Public Member Functions

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

Private Attributes

std::atomic< unsigned int > m_ntotvtx
 
std::atomic< unsigned int > m_ntotpart
 
std::atomic< unsigned int > m_npassvtx
 
std::atomic< unsigned int > m_npasspart
 
StringProperty m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
 
SG::ThinningHandleKey< xAOD::TruthParticleContainerm_particlesKey { this, "ParticlesKey", "TruthParticles", "" }
 
SG::ThinningHandleKey< xAOD::TruthVertexContainerm_verticesKey { this, "VerticesKey", "TruthVertices", "" }
 
std::string m_eventsKey
 
std::string m_partString
 
bool m_preserveDescendants
 
bool m_preserveGeneratorDescendants
 
bool m_preserveAncestors
 
bool m_tauHandling
 

Detailed Description

Definition at line 28 of file GenericTruthThinning.h.

Constructor & Destructor Documentation

◆ GenericTruthThinning()

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

Definition at line 24 of file GenericTruthThinning.cxx.

26  :
27 base_class(t,n,p),
28 m_ntotvtx(0),
29 m_ntotpart(0),
30 m_npassvtx(0),
31 m_npasspart(0),
32 m_partString(""),
33 //m_vtxString(""),
36 m_preserveAncestors(false),
37 m_tauHandling(true)
38 {
39  declareProperty("EventsKey", m_eventsKey);
40  declareProperty("ParticleSelectionString", m_partString);
41  //declareProperty("VertexSelectionString", m_vtxString);
42  declareProperty("PreserveDescendants", m_preserveDescendants);
43  declareProperty("PreserveGeneratorDescendants", m_preserveGeneratorDescendants);
44  declareProperty("PreserveAncestors", m_preserveAncestors);
45  declareProperty("TauHandling", m_tauHandling);
46 }

◆ ~GenericTruthThinning()

DerivationFramework::GenericTruthThinning::~GenericTruthThinning ( )
virtual

Definition at line 49 of file GenericTruthThinning.cxx.

49  {
50 }

Member Function Documentation

◆ doThinning()

StatusCode DerivationFramework::GenericTruthThinning::doThinning ( ) const
overridevirtual

Definition at line 86 of file GenericTruthThinning.cxx.

87 {
88  const EventContext& ctx = Gaudi::Hive::currentContext();
89 
90  // Retrieve truth collections
92  (m_particlesKey, ctx);
94  (m_verticesKey, ctx);
95 
96  const xAOD::TruthEventContainer* importedTruthEvents;
97  if (evtStore()->retrieve(importedTruthEvents,m_eventsKey).isFailure()) {
98  ATH_MSG_ERROR("No TruthEventContainer with name " << m_eventsKey << " found in StoreGate!");
99  return StatusCode::FAILURE;
100  }
101 
102 
103 
104  // Set up a mask with the same entries as the full collections
105  unsigned int nParticles = importedTruthParticles->size();
106  unsigned int nVertices = importedTruthVertices->size();
107  std::vector<bool> partMask, vertMask;
108  partMask.assign(nParticles,false); // default: don't keep any truth items
109  vertMask.assign(nVertices,false);
110  m_ntotvtx += nVertices; m_ntotpart += nParticles;
111 
112  // Execute the text parsers and update the mask
113  if (!m_partString.empty()) {
114  std::vector<int> entries = m_parser->evaluateAsVector();
115  unsigned int nEntries = entries.size();
116  // check the sizes are compatible
117  if (nParticles != nEntries ) {
118  ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used TruthParticles?");
119  return StatusCode::FAILURE;
120  } else {
121  // set mask
122  for (unsigned int i=0; i<nParticles; ++i) if (entries[i]==1) partMask[i]=true;
123  }
124  }
125 
126  // Special treatment of taus such that only the last one in the chain is kept
127  // Needs another run over the particle collection
128  if (m_tauHandling) {
130  for (unsigned int i=0; i<nParticles; ++i) {
131  const xAOD::TruthParticle* particle = (*importedTruthParticles)[i];
132  if ( MC::isTau(particle) ) { // This is a tau
133  bool last(true);
134  std::vector<int> tauDecayProducts; // all decay products of the tau
135  std::unordered_set<int> tauDecayEncounteredUniqueIDs; // loop checking
136  tauDecayHelper.descendants(particle,tauDecayProducts,tauDecayEncounteredUniqueIDs); // recursive
137  for (unsigned int tauDecIt=0; tauDecIt<tauDecayProducts.size(); ++tauDecIt) {
138  if (abs(tauDecayProducts[tauDecIt])==15) { // any taus in the decay products?
139  last = false;
140  break;
141  }
142  }
143  if (!last) partMask[i]=false;
144  } // end of code for tau
145  } // end of loop over particles for tau checking
146  } // end of tau handling option
147 
148  // If user requested preservation of descendants/ancestors:
149  // - loop over the masks and work out which particles need to be descended/ascended from
150  // - do the recursive loop
151  // - update the masks including the descendants/ancestors
152  // To ensure graph completeness, this over-rides anything set by the special treatment
153  // of taus in the section above
155  std::unordered_set<int> encounteredUniqueIDs; // to enable loop handling
157  for (unsigned int i=0; i<nParticles; ++i) {
158  bool toKeep = partMask[i];
159  if (!toKeep) continue;
160  const xAOD::TruthParticle* particle = (*importedTruthParticles)[i];
161  encounteredUniqueIDs.clear();
162  if (m_preserveDescendants) decayHelper.descendants(particle,partMask,vertMask,encounteredUniqueIDs,true);
163  encounteredUniqueIDs.clear();
164  if (m_preserveGeneratorDescendants) decayHelper.descendants(particle,partMask,vertMask,encounteredUniqueIDs,false);
165  encounteredUniqueIDs.clear();
166  if (m_preserveAncestors) decayHelper.ancestors(particle,partMask,vertMask,encounteredUniqueIDs);
167  encounteredUniqueIDs.clear();
168  }
169  }
170  //for (unsigned int i=0; i<nVertices; ++i) {
171  // bool toKeep = vertMask[i];
172  // if (!toKeep) continue;
173  // const xAOD::TruthVertex* vertex = (*importedTruthVertices)[i];
174  // decayHelper.descend(vertex,partMask,vertMask);
175  //}
176 
177  // Count the masks
178  m_npasspart += std::count (partMask.begin(), partMask.end(), true);
179  m_npassvtx += std::count (vertMask.begin(), vertMask.end(), true);
180 
181  // Execute the thinning service based on the mask. Finish.
182  importedTruthParticles.keep (partMask);
183  importedTruthVertices.keep (vertMask);
184 
185  return StatusCode::SUCCESS;
186 }

◆ finalize()

StatusCode DerivationFramework::GenericTruthThinning::finalize ( )
overridevirtual

Definition at line 76 of file GenericTruthThinning.cxx.

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

◆ initialize()

StatusCode DerivationFramework::GenericTruthThinning::initialize ( )
overridevirtual

Definition at line 53 of file GenericTruthThinning.cxx.

54 {
55  ATH_MSG_VERBOSE("initialize() ...");
56  ATH_CHECK( m_particlesKey.initialize (m_streamName) );
57  ATH_CHECK( m_verticesKey.initialize (m_streamName) );
58  ATH_MSG_INFO("Using " << m_particlesKey.key() << " and "<< m_verticesKey.key() << " as the source collections for truth thinning");
59 
60  if (m_partString.empty()/* && m_vtxString==""*/) {
61  ATH_MSG_FATAL("No selection string provided either for vertices or particles!");
62  return StatusCode::FAILURE;
63  } else {ATH_MSG_INFO("Truth thinning selection strings: " << m_partString /*<< " " << m_vtxString*/);}
64 
66  ATH_MSG_FATAL("You are asking to keep both all descendants, and only those from the event generator. Please check your job options.");
67  return StatusCode::FAILURE;
68  }
69  // Set up the text-parsing machinery for thinning the truth directly according to user cuts
70  if (!m_partString.empty()) {
71  ATH_CHECK( initializeParser(m_partString) );
72  }
73  return StatusCode::SUCCESS;
74 }

Member Data Documentation

◆ m_eventsKey

std::string DerivationFramework::GenericTruthThinning::m_eventsKey
private

Definition at line 44 of file GenericTruthThinning.h.

◆ m_npasspart

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

Definition at line 37 of file GenericTruthThinning.h.

◆ m_npassvtx

std::atomic<unsigned int> DerivationFramework::GenericTruthThinning::m_npassvtx
private

Definition at line 37 of file GenericTruthThinning.h.

◆ m_ntotpart

std::atomic<unsigned int> DerivationFramework::GenericTruthThinning::m_ntotpart
private

Definition at line 37 of file GenericTruthThinning.h.

◆ m_ntotvtx

std::atomic<unsigned int> DerivationFramework::GenericTruthThinning::m_ntotvtx
mutableprivate

Definition at line 37 of file GenericTruthThinning.h.

◆ m_particlesKey

SG::ThinningHandleKey<xAOD::TruthParticleContainer> DerivationFramework::GenericTruthThinning::m_particlesKey { this, "ParticlesKey", "TruthParticles", "" }
private

Definition at line 40 of file GenericTruthThinning.h.

◆ m_partString

std::string DerivationFramework::GenericTruthThinning::m_partString
private

Definition at line 45 of file GenericTruthThinning.h.

◆ m_preserveAncestors

bool DerivationFramework::GenericTruthThinning::m_preserveAncestors
private

Definition at line 49 of file GenericTruthThinning.h.

◆ m_preserveDescendants

bool DerivationFramework::GenericTruthThinning::m_preserveDescendants
private

Definition at line 47 of file GenericTruthThinning.h.

◆ m_preserveGeneratorDescendants

bool DerivationFramework::GenericTruthThinning::m_preserveGeneratorDescendants
private

Definition at line 48 of file GenericTruthThinning.h.

◆ m_streamName

StringProperty DerivationFramework::GenericTruthThinning::m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
private

Definition at line 38 of file GenericTruthThinning.h.

◆ m_tauHandling

bool DerivationFramework::GenericTruthThinning::m_tauHandling
private

Definition at line 50 of file GenericTruthThinning.h.

◆ m_verticesKey

SG::ThinningHandleKey<xAOD::TruthVertexContainer> DerivationFramework::GenericTruthThinning::m_verticesKey { this, "VerticesKey", "TruthVertices", "" }
private

Definition at line 42 of file GenericTruthThinning.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::GenericTruthThinning::m_tauHandling
bool m_tauHandling
Definition: GenericTruthThinning.h:50
DerivationFramework::GenericTruthThinning::m_eventsKey
std::string m_eventsKey
Definition: GenericTruthThinning.h:44
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
NSWL1::nVertices
int nVertices(const Polygon &p)
Definition: GeoUtils.cxx:35
DerivationFramework::GenericTruthThinning::m_preserveAncestors
bool m_preserveAncestors
Definition: GenericTruthThinning.h:49
DerivationFramework::GenericTruthThinning::m_ntotvtx
std::atomic< unsigned int > m_ntotvtx
Definition: GenericTruthThinning.h:37
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::GenericTruthThinning::m_partString
std::string m_partString
Definition: GenericTruthThinning.h:45
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::GenericTruthThinning::m_streamName
StringProperty m_streamName
Definition: GenericTruthThinning.h:39
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
DerivationFramework::DecayGraphHelper::descendants
void descendants(const xAOD::TruthParticle *pHead, std::vector< int > &particleList, std::unordered_set< int > &encounteredUniqueIDs)
Definition: DecayGraphHelper.h:116
DerivationFramework::GenericTruthThinning::m_verticesKey
SG::ThinningHandleKey< xAOD::TruthVertexContainer > m_verticesKey
Definition: GenericTruthThinning.h:43
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
DerivationFramework::GenericTruthThinning::m_npasspart
std::atomic< unsigned int > m_npasspart
Definition: GenericTruthThinning.h:37
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
DerivationFramework::GenericTruthThinning::m_npassvtx
std::atomic< unsigned int > m_npassvtx
Definition: GenericTruthThinning.h:37
DerivationFramework::GenericTruthThinning::m_ntotpart
std::atomic< unsigned int > m_ntotpart
Definition: GenericTruthThinning.h:37
DerivationFramework::GenericTruthThinning::m_particlesKey
SG::ThinningHandleKey< xAOD::TruthParticleContainer > m_particlesKey
Definition: GenericTruthThinning.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DerivationFramework::GenericTruthThinning::m_preserveGeneratorDescendants
bool m_preserveGeneratorDescendants
Definition: GenericTruthThinning.h:48
isTau
bool isTau(const T &p)
Definition: AtlasPID.h:173
DerivationFramework::DecayGraphHelper::ancestors
void ancestors(const xAOD::TruthParticle *pHead, std::vector< bool > &particleMask, std::vector< bool > &vertexMask, std::unordered_set< int > &encounteredUniqueIDs)
Definition: DecayGraphHelper.h:186
DerivationFramework::DecayGraphHelper
Definition: DecayGraphHelper.h:26
DerivationFramework::GenericTruthThinning::m_preserveDescendants
bool m_preserveDescendants
Definition: GenericTruthThinning.h:47
entries
double entries
Definition: listroot.cxx:49
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73