ATLAS Offline Software
Loading...
Searching...
No Matches
TruthResetAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TruthResetAlg.h"
6//
12
15
16#include "CLHEP/Vector/LorentzVector.h"
17#include "CLHEP/Units/SystemOfUnits.h"
18//
19#include "CLHEP/Geometry/Point3D.h"
21#include <climits>
22
23//----------------------------------------------------
25//----------------------------------------------------
26
29 return StatusCode::SUCCESS;
30
31}
32
33//-------------------------------------------------
34StatusCode TruthResetAlg::execute(const EventContext& ctx) const {
35//-------------------------------------------------
36
37 ATH_MSG_DEBUG( " execute..... " );
39 if (!inputMcEventCollection.isValid()) {
40 ATH_MSG_ERROR("Could not find input McEventCollection called " << inputMcEventCollection.name() << " in store " << inputMcEventCollection.store() << ".");
41 return StatusCode::FAILURE;
42 }
43 const HepMC::GenEvent& inputEvent(**(inputMcEventCollection->begin()));
44
45 //Sanity check
46 bool inputProblem(false);
47 for (const auto& particle: inputEvent) {
48 if (MC::isStable(particle)) {
49 if (!particle->production_vertex()) {
50 ATH_MSG_ERROR("Stable particle without a production vertex!! " << particle);
51 inputProblem = true;
52 }
53 }
54 else if (MC::isDecayed(particle)) {
55 if (!particle->production_vertex()) {
56 ATH_MSG_ERROR("Decyed particle without a production vertex!! " << particle);
57 inputProblem = true;
58 }
59 if (!particle->end_vertex()) {
60 ATH_MSG_ERROR("Decyed particle without an end vertex!! " << particle);
61 inputProblem = true;
62 }
63 }
64 }
65 if (inputProblem) {
66 ATH_MSG_FATAL("Problems in input GenEvent - bailing out.");
67 return StatusCode::FAILURE;
68 }
71 std::unique_ptr<HepMC::GenEvent> outputEvent = std::make_unique<HepMC::GenEvent>(inputEvent);
72 if (inputEvent.run_info()) outputEvent->set_run_info(std::make_shared<HepMC3::GenRunInfo>(*(inputEvent.run_info().get())));
73 for (;;) {
74 std::vector<HepMC::GenParticlePtr> p_to_remove;
75 std::vector<HepMC::GenVertexPtr> v_to_remove;
76 for (auto& particle: outputEvent->particles()) {
77 if (HepMC::is_simulation_particle(particle)) {
78 p_to_remove.push_back(particle);
79 }
80 }
81 for (auto& particle: p_to_remove) outputEvent->remove_particle(particle);
82 for (auto& vertex: outputEvent->vertices()) {
83 if (HepMC::is_simulation_vertex(vertex) || vertex->particles_out().empty() ) {
84 v_to_remove.push_back(vertex);
85 }
86 }
87 for (auto& vertex: v_to_remove) outputEvent->remove_vertex(vertex);
88 if (p_to_remove.empty() && v_to_remove.empty()) break;
89 }
90
91
92 //Sanity check
93 bool outputProblem(false);
94 for (const auto& particle: *(outputEvent.get())) {
95 if (MC::isStable(particle)) {
96 if (!particle->production_vertex()) {
97 ATH_MSG_ERROR("Stable particle without a production vertex!! " << particle);
98 outputProblem = true;
99 }
100 if (particle->end_vertex()) {
101 ATH_MSG_ERROR("Stable particle with an end vertex!! " << particle);
102 outputProblem = true;
103 }
104 }
105 else if (MC::isDecayed(particle)) {
106 if (!particle->production_vertex()) {
107 ATH_MSG_ERROR("Decayed particle without a production vertex!! " << particle);
108 outputProblem = true;
109 }
110 if (!particle->end_vertex()) {
111 ATH_MSG_ERROR("Decayed particle without an end vertex!! " << particle);
112 outputProblem = true;
113 }
114 }
115 }
116 if (outputProblem) {
117 ATH_MSG_FATAL("Problems in output GenEvent - bailing out.");
118 return StatusCode::FAILURE;
119 }
120
122 ATH_CHECK(outputMcEventCollection.record(std::make_unique<McEventCollection>()));
123 outputMcEventCollection->push_back(outputEvent.release());
124 if (!outputMcEventCollection.isValid()) {
125 ATH_MSG_ERROR("Could not record output McEventCollection called " << outputMcEventCollection.name() << " in store " << outputMcEventCollection.store() << ".");
126 return StatusCode::FAILURE;
127 }
128
129 ATH_MSG_DEBUG( "succeded TruthResetAlg ..... " );
130
131 return StatusCode::SUCCESS;
132
133}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
ATLAS-specific HepMC functions.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual StatusCode execute(const EventContext &ctx) const override final
virtual StatusCode initialize() override final
SG::WriteHandleKey< McEventCollection > m_outputMcEventCollection
SG::ReadHandleKey< McEventCollection > m_inputMcEventCollection
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (TODO migrate to be based on status).
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isDecayed(const T &p)
Identify if the particle decayed.