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_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("ParticleSelectionString", m_partString);
40  //declareProperty("VertexSelectionString", m_vtxString);
41  declareProperty("PreserveDescendants", m_preserveDescendants);
42  declareProperty("PreserveGeneratorDescendants", m_preserveGeneratorDescendants);
43  declareProperty("PreserveAncestors", m_preserveAncestors);
44  declareProperty("TauHandling", m_tauHandling);
45 }

◆ ~GenericTruthThinning()

DerivationFramework::GenericTruthThinning::~GenericTruthThinning ( )
virtual

Definition at line 48 of file GenericTruthThinning.cxx.

48  {
49 }

Member Function Documentation

◆ doThinning()

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

Definition at line 85 of file GenericTruthThinning.cxx.

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

◆ finalize()

StatusCode DerivationFramework::GenericTruthThinning::finalize ( )
overridevirtual

Definition at line 75 of file GenericTruthThinning.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::GenericTruthThinning::initialize ( )
overridevirtual

Definition at line 52 of file GenericTruthThinning.cxx.

53 {
54  ATH_MSG_VERBOSE("initialize() ...");
55  ATH_CHECK( m_particlesKey.initialize (m_streamName) );
56  ATH_CHECK( m_verticesKey.initialize (m_streamName) );
57  ATH_MSG_INFO("Using " << m_particlesKey.key() << " and "<< m_verticesKey.key() << " as the source collections for truth thinning");
58 
59  if (m_partString.empty()/* && m_vtxString==""*/) {
60  ATH_MSG_FATAL("No selection string provided either for vertices or particles!");
61  return StatusCode::FAILURE;
62  } else {ATH_MSG_INFO("Truth thinning selection strings: " << m_partString /*<< " " << m_vtxString*/);}
63 
65  ATH_MSG_FATAL("You are asking to keep both all descendants, and only those from the event generator. Please check your job options.");
66  return StatusCode::FAILURE;
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_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 44 of file GenericTruthThinning.h.

◆ m_preserveAncestors

bool DerivationFramework::GenericTruthThinning::m_preserveAncestors
private

Definition at line 48 of file GenericTruthThinning.h.

◆ m_preserveDescendants

bool DerivationFramework::GenericTruthThinning::m_preserveDescendants
private

Definition at line 46 of file GenericTruthThinning.h.

◆ m_preserveGeneratorDescendants

bool DerivationFramework::GenericTruthThinning::m_preserveGeneratorDescendants
private

Definition at line 47 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 49 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:
DerivationFramework::GenericTruthThinning::m_tauHandling
bool m_tauHandling
Definition: GenericTruthThinning.h:49
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:79
NSWL1::nVertices
int nVertices(const Polygon &p)
Definition: GeoUtils.cxx:35
DerivationFramework::GenericTruthThinning::m_preserveAncestors
bool m_preserveAncestors
Definition: GenericTruthThinning.h:48
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:44
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:84
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:209
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:727
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
DerivationFramework::GenericTruthThinning::m_preserveGeneratorDescendants
bool m_preserveGeneratorDescendants
Definition: GenericTruthThinning.h:47
isTau
bool isTau(const T &p)
Definition: AtlasPID.h:205
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:46
entries
double entries
Definition: listroot.cxx:49
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:72