ATLAS Offline Software
Loading...
Searching...
No Matches
ISF::TruthPreselectionTool Class Reference

#include <TruthPreselectionTool.h>

Inheritance diagram for ISF::TruthPreselectionTool:
Collaboration diagram for ISF::TruthPreselectionTool:

Public Member Functions

 TruthPreselectionTool (const std::string &t, const std::string &n, const IInterface *p)
 Constructor with parameters.
virtual ~TruthPreselectionTool ()=default
 Destructor.
virtual StatusCode initialize () override final
 Athena algorithm's interface method initialize().
virtual std::unique_ptr< HepMC::GenEventfilterGenEvent (const HepMC::GenEvent &inputEvent) const override final
 IGenEventFilter interface.

Private Member Functions

bool passesFilters (HepMC::ConstGenParticlePtr &part, const ToolHandleArray< IGenParticleFilter > &filters) const
 check if the given particle passes all filters
bool identifiedQuasiStableParticleForSim (HepMC::ConstGenParticlePtr &part) const
bool hasQuasiStableAncestorParticle (HepMC::ConstGenParticlePtr &part) const
bool isPostQuasiStableParticleVertex (HepMC::ConstGenVertexPtr &vtx) const

Private Attributes

ToolHandleArray< IGenParticleFilterm_genParticleFilters {this, "GenParticleFilters", {}, "Tools for filtering out GenParticles"}
 Filter passes if a difference between the decision of m_genParticleOldFilters and m_genParticleNewFilters is found.
ToolHandle< IGenParticleFilterm_quasiStableFilter {this, "QuasiStableParticleFilter", "", "Tools for finding quasi-stable particles"}

Detailed Description

Definition at line 21 of file TruthPreselectionTool.h.

Constructor & Destructor Documentation

◆ TruthPreselectionTool()

ISF::TruthPreselectionTool::TruthPreselectionTool ( const std::string & t,
const std::string & n,
const IInterface * p )

Constructor with parameters.

Definition at line 15 of file TruthPreselectionTool.cxx.

15 :
16 base_class( t, n, p )
17{
18}

◆ ~TruthPreselectionTool()

virtual ISF::TruthPreselectionTool::~TruthPreselectionTool ( )
virtualdefault

Destructor.

Member Function Documentation

◆ filterGenEvent()

std::unique_ptr< HepMC::GenEvent > ISF::TruthPreselectionTool::filterGenEvent ( const HepMC::GenEvent & inputEvent) const
finaloverridevirtual

IGenEventFilter interface.

The algorithm makes a deep copy of the event and drops the particles and vertices created by the simulation from the copied event.

Definition at line 79 of file TruthPreselectionTool.cxx.

79 {
82 std::unique_ptr<HepMC::GenEvent> outputEvent = std::make_unique<HepMC::GenEvent>(inputEvent);
83 if (inputEvent.run_info()) {
84 outputEvent->set_run_info(std::make_shared<HepMC3::GenRunInfo>(*(inputEvent.run_info().get())));
85 }
86 if (inputEvent.heavy_ion()) {
87 outputEvent->set_heavy_ion(std::make_shared<HepMC::GenHeavyIon>(*(inputEvent.heavy_ion())));
88 }
89 HepMC::fillBarcodesAttribute(outputEvent.get());
90
91 // First loop: flag the particles which should be passed to simulation
92 for (auto& particle: outputEvent->particles()) {
94 if (passesFilters(cparticle, m_genParticleFilters)) {
95 // Particle to be simulated
96 const int shadowId = particle->id();
97 // Version 1 Use the Id
99 std::make_shared<HepMC3::IntAttribute>(shadowId));
100 // Version 2 Directly save the ConstGenParticlePtr - needs to link to a version of the GenEvent after zero-lifetime positioner as been applied.
101 // HepMC::ConstGenParticlePtr& shadow = inputEvent.particles().at(shadowId);
102 // particle->add_attribute(HepMCStr::ShadowParticle,
103 // std::make_shared<HepMC::ShadowParticle>(particle));
104 }
105 }
106 // Second loop(s): flag particles (and vertices) to be removed (i.e. those
107 // with ancestor particle flagged to be passed to simulation).
108 for (;;) {
109 std::vector<HepMC::GenParticlePtr> p_to_remove;
110 std::vector<HepMC::GenVertexPtr> v_to_remove;
111 for (auto& particle: outputEvent->particles()) {
113 if (hasQuasiStableAncestorParticle(cparticle)) {
114 p_to_remove.push_back(particle);
115 }
116 }
117 for (auto& particle: p_to_remove) outputEvent->remove_particle(particle);
118 for (auto& vertex: outputEvent->vertices()) {
120 if (isPostQuasiStableParticleVertex(cvertex)) {
121 v_to_remove.push_back(vertex);
122 }
123 }
124 for (auto& vertex: v_to_remove) outputEvent->remove_vertex(vertex);
125 if (p_to_remove.empty() && v_to_remove.empty()) break;
126 }
127
128 return outputEvent;
129}
ToolHandleArray< IGenParticleFilter > m_genParticleFilters
Filter passes if a difference between the decision of m_genParticleOldFilters and m_genParticleNewFil...
bool hasQuasiStableAncestorParticle(HepMC::ConstGenParticlePtr &part) const
bool passesFilters(HepMC::ConstGenParticlePtr &part, const ToolHandleArray< IGenParticleFilter > &filters) const
check if the given particle passes all filters
bool isPostQuasiStableParticleVertex(HepMC::ConstGenVertexPtr &vtx) const
const std::string ShadowParticleId
void fillBarcodesAttribute(GenEvent *e)
Definition GenEvent.h:393
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition GenVertex.h:24
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses

◆ hasQuasiStableAncestorParticle()

bool ISF::TruthPreselectionTool::hasQuasiStableAncestorParticle ( HepMC::ConstGenParticlePtr & part) const
private

Definition at line 59 of file TruthPreselectionTool.cxx.

60{
61 // TODO: investigate making this more efficient
62 // Recursively loop over ancestral particles looking for a quasi-stable particle
63 if (!part->production_vertex() || part->production_vertex()->particles_in().empty()) { return false; }
64 for ( auto ancestor: part->production_vertex()->particles_in() ) {
65 // Check ancestor particle for Attribute
66 if ( ancestor->attribute<HepMC3::IntAttribute>(HepMCStr::ShadowParticleId) ) { return true; }
67 if (hasQuasiStableAncestorParticle(ancestor)) { return true; }
68 }
69 return false;
70}

◆ identifiedQuasiStableParticleForSim()

bool ISF::TruthPreselectionTool::identifiedQuasiStableParticleForSim ( HepMC::ConstGenParticlePtr & part) const
private

Definition at line 50 of file TruthPreselectionTool.cxx.

51{
52 bool b_sim = false;
53 if (m_quasiStableFilter->pass(part)) {
55 }
56 return b_sim;
57}
ToolHandle< IGenParticleFilter > m_quasiStableFilter

◆ initialize()

StatusCode ISF::TruthPreselectionTool::initialize ( )
finaloverridevirtual

Athena algorithm's interface method initialize().

Definition at line 22 of file TruthPreselectionTool.cxx.

23{
24 ATH_MSG_VERBOSE ( "Initializing TruthPreselectionTool Algorithm" );
25
26 if (!m_genParticleFilters.empty()) ATH_CHECK(m_genParticleFilters.retrieve());
28
29 // intialziation successful
30 return StatusCode::SUCCESS;
31}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)

◆ isPostQuasiStableParticleVertex()

bool ISF::TruthPreselectionTool::isPostQuasiStableParticleVertex ( HepMC::ConstGenVertexPtr & vtx) const
private

Definition at line 72 of file TruthPreselectionTool.cxx.

73{
74 // All outgoing particles have already been removed.
75 if ( vtx->particles_out().empty() ) { return true; }
76 return false;
77}

◆ passesFilters()

bool ISF::TruthPreselectionTool::passesFilters ( HepMC::ConstGenParticlePtr & part,
const ToolHandleArray< IGenParticleFilter > & filters ) const
private

check if the given particle passes all filters

Definition at line 34 of file TruthPreselectionTool.cxx.

35{
36 // TODO: implement this as a std::find_if with a lambda function
37 for ( const auto& filter : filters ) {
38 // determine if the particle passes current filter
39 bool passFilter = filter->pass(part);
40 ATH_MSG_VERBOSE("Filter '" << filter.typeAndName() << "' returned: "
41 << (passFilter ? "true, will keep particle."
42 : "false, will remove particle."));
43
44 if (!passFilter) return false;
45 }
46
47 return true;
48}

Member Data Documentation

◆ m_genParticleFilters

ToolHandleArray<IGenParticleFilter> ISF::TruthPreselectionTool::m_genParticleFilters {this, "GenParticleFilters", {}, "Tools for filtering out GenParticles"}
private

Filter passes if a difference between the decision of m_genParticleOldFilters and m_genParticleNewFilters is found.

m_genParticleCommonFilters is applied before to select relevant particles. If only m_genParticleCommonFilters is specified, filter passes if any particle passes this one HepMC::GenParticle filters for both selections

Definition at line 44 of file TruthPreselectionTool.h.

44{this, "GenParticleFilters", {}, "Tools for filtering out GenParticles"};

◆ m_quasiStableFilter

ToolHandle<IGenParticleFilter> ISF::TruthPreselectionTool::m_quasiStableFilter {this, "QuasiStableParticleFilter", "", "Tools for finding quasi-stable particles"}
private

Definition at line 45 of file TruthPreselectionTool.h.

45{this, "QuasiStableParticleFilter", "", "Tools for finding quasi-stable particles"};

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