ATLAS Offline Software
Loading...
Searching...
No Matches
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 EventContext &ctx) 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 23 of file GenericTruthThinning.cxx.

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

◆ ~GenericTruthThinning()

DerivationFramework::GenericTruthThinning::~GenericTruthThinning ( )
virtual

Definition at line 47 of file GenericTruthThinning.cxx.

47 {
48}

Member Function Documentation

◆ doThinning()

StatusCode DerivationFramework::GenericTruthThinning::doThinning ( const EventContext & ctx) const
overridevirtual

Definition at line 84 of file GenericTruthThinning.cxx.

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

◆ finalize()

StatusCode DerivationFramework::GenericTruthThinning::finalize ( )
overridevirtual

Definition at line 74 of file GenericTruthThinning.cxx.

75{
76 ATH_MSG_VERBOSE("finalize() ...");
77 ATH_MSG_INFO("Processed "<< m_ntotvtx <<" truth vertices, "<< m_npassvtx << " were retained ");
78 ATH_MSG_INFO("Processed "<< m_ntotpart <<" truth particles, "<< m_npasspart << " were retained ");
79 ATH_CHECK(finalizeParser());
80 return StatusCode::SUCCESS;
81}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)

◆ initialize()

StatusCode DerivationFramework::GenericTruthThinning::initialize ( )
overridevirtual

Definition at line 51 of file GenericTruthThinning.cxx.

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

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.

41{ this, "ParticlesKey", "TruthParticles", "" };

◆ 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.

39{ this, "StreamName", "", "Name of the stream being thinned" };

◆ 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.

43{ this, "VerticesKey", "TruthVertices", "" };

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