ATLAS Offline Software
Loading...
Searching...
No Matches
DumpMC.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 "TruthIO/DumpMC.h"
6#include "GaudiKernel/PhysicalConstants.h"
7#include <CLHEP/Vector/LorentzVector.h>
8using namespace Gaudi::Units;
9
10
11DumpMC::DumpMC(const std::string& name, ISvcLocator* pSvcLocator)
12 : GenBase(name, pSvcLocator)
13{
14 declareProperty("McEventOutputKey", m_keyout="GEN_EVENT");
15 declareProperty("VerboseOutput", m_VerboseOutput=true);
16 declareProperty("DeepCopy", m_DeepCopy=false);
17 declareProperty("EtaPhi", m_EtaPhi=false);
18 declareProperty("PrintQuasiStableParticles", m_PrintQuasiStableParticles=false);
19}
20
21
22StatusCode DumpMC::initialize() {
25 ATH_MSG_FATAL("Input and output MC event keys cannot be the same (" << m_mcEventKey << ")");
26 return StatusCode::FAILURE;
27 }
28 return StatusCode::SUCCESS;
29}
30
31
32StatusCode DumpMC::execute() {
33 if (m_DeepCopy) {
34 McEventCollection* mcCollptra = new McEventCollection();
35 // Fill the new McEventCollection with a copy of the initial HepMC::GenEvent
36 for(const HepMC::GenEvent* evt : *events_const()) {
37 mcCollptra->push_back(new HepMC::GenEvent(*evt));
38 }
39 // Loop over all events in McEventCollection
40 for (McEventCollection::iterator evt = mcCollptra->begin(); evt != mcCollptra->end(); ++evt) {
41#ifdef HEPMC3
42 std::vector<HepMC::GenVertexPtr> lambda_vertices_to_remove;
43 for (auto part: **evt){
44 const int abspid = std::abs(part->pdg_id());
45 if (abspid != 310 && abspid != 3122 && abspid != 3222 && abspid != 3112 && abspid != 3322 && abspid != 3312 && abspid != 3334 ) continue;
46 if (!part->end_vertex()) continue;
47 lambda_vertices_to_remove.push_back(part->end_vertex());
48 part->set_status(1);
49 }
50 for (auto v: lambda_vertices_to_remove) (*evt)->remove_vertex(std::move(v));
51#else
52 // Loop over the vertices of the event
53 std::set<int> Lambdas;
54 std::set<int> vtx_to_delete;
55 for (HepMC::GenEvent::vertex_const_iterator vtx = (*evt)->vertices_begin(); vtx != (*evt)->vertices_end(); ++vtx) {
56 // Loop over the particles that produced the vertex
57 if ( vtx_to_delete.find((*vtx)->barcode()) == vtx_to_delete.end() &&
58 (*vtx)->particles_in_const_begin() != (*vtx)->particles_in_const_end() ) {
59 HepMC::GenVertex::particles_in_const_iterator part = (*vtx)->particles_in_const_begin();
60 bool lambda_not_found = true;
61 const int abspid = std::abs((*part)->pdg_id());
62 do {
63 if (abspid == 310 || abspid == 3122 || abspid == 3222 || abspid == 3112 ||
64 abspid == 3322 || abspid == 3312 || abspid == 3334 ) {
65 lambda_not_found = false;
66 Lambdas.insert((*part)->barcode());
67 vtx_to_delete.insert((*vtx)->barcode());
68 // In case a lambda was found, store in vertices to be deleted all the vertices
69 // that the products of Lambda created
70 for (HepMC::GenVertex::vertex_iterator desc = (*vtx)->vertices_begin(HepMC::descendants);
71 desc != (*vtx)->vertices_end(HepMC::descendants); ++desc) {
72 vtx_to_delete.insert((*desc)->barcode());
73 }
74 }
75 ++part;
76 } while (part != (*vtx)->particles_in_const_end() && lambda_not_found);
77 }
78 }
79
80 // Set Lambda's status to stable
81 for (std::set<int>::iterator l = Lambdas.begin(); l != Lambdas.end(); ++l) {
82 HepMC::GenParticle* lam = (*evt)->barcode_to_particle(*l);
83 lam->set_status(1);
84 }
85 // Delete all Lambda vertices from the event
86 for (std::set<int>::iterator v = vtx_to_delete.begin(); v != vtx_to_delete.end(); ++v) {
87 HepMC::GenVertex* vdel = (*evt)->barcode_to_vertex(*v);
88 (*evt)->remove_vertex(vdel);
89 delete vdel;
90 }
91#endif
92 }
93
94 if (evtStore()->record(mcCollptra, m_keyout).isFailure()){
95 ATH_MSG_ERROR("Could not record McEventCollection");
96 return StatusCode::FAILURE;
97 }
98 }
99
100 // Loop over all events in McEventCollection
101 for(const HepMC::GenEvent* evt : *events_const()) {
102 auto pdfinfo = evt->pdf_info();
103 auto ion = evt->heavy_ion();
104#ifdef HEPMC3
105 if (pdfinfo) {
106 std::cout << "PdfInfo: "
107 << pdfinfo->parton_id[0] << ", "
108 << pdfinfo->parton_id[1] << ", "
109 << pdfinfo->x[0] << ", "
110 << pdfinfo->x[1] << ", "
111 << pdfinfo->scale << ", "
112 << pdfinfo->xf[0] << ", "
113 << pdfinfo->xf[1] << ", "
114 << pdfinfo->pdf_id[0] << ", "
115 << pdfinfo->pdf_id[1]
116 << std::endl;
117 }
118
119 if (ion) {
120 std::cout << std::endl;
121 std::cout << "Heavy Ion: "
122 << ion->Ncoll_hard <<", "
123 << ion->Npart_proj <<" , "
124 << ion->Npart_targ<< ", "
125 << ion->Ncoll<< ", "
126 << ion->spectator_neutrons << ", "
127 << ion->spectator_protons << ", "
128 << ion->N_Nwounded_collisions << ", "
129 << ion->Nwounded_N_collisions << ", "
130 << ion->Nwounded_Nwounded_collisions << ", "
131 << ion->impact_parameter << ", "
132 << ion->event_plane_angle << ", "
133 << ion->eccentricity << ", "
134 << ion->sigma_inel_NN
135 << std::endl;
136 }
137#else
138 if (pdfinfo) {
139 std::cout << "PdfInfo: "
140 << pdfinfo->id1() << ", "
141 << pdfinfo->id2() << ", "
142 << pdfinfo->x1() << ", "
143 << pdfinfo->x2() << ", "
144 << pdfinfo->scalePDF() << ", "
145 << pdfinfo->pdf1() << ", "
146 << pdfinfo->pdf2() << ", "
147 << pdfinfo->pdf_id1() << ", "
148 << pdfinfo->pdf_id2()
149 << std::endl;
150 }
151
152 if (ion) {
153 std::cout << std::endl;
154 std::cout << "Heavy Ion: "
155 << ion->Ncoll_hard() <<", "
156 << ion->Npart_proj() <<" , "
157 << ion->Npart_targ()<< ", "
158 << ion->Ncoll()<< ", "
159 << ion->spectator_neutrons() << ", "
160 << ion->spectator_protons() << ", "
161 << ion->N_Nwounded_collisions() << ", "
162 << ion->Nwounded_N_collisions() << ", "
163 << ion->Nwounded_Nwounded_collisions() << ", "
164 << ion->impact_parameter() << ", "
165 << ion->event_plane_angle() << ", "
166 << ion->eccentricity() << ", "
167 << ion->sigma_inel_NN()
168 << std::endl;
169 }
170#endif
171 if (m_VerboseOutput) {
172 if (!m_EtaPhi) {
173 HepMC::Print::line(std::cout,*evt); // standard HepMc dump
174 } else { // sort particles by rapidity and then dump
175 // Loop over all particles in the event and build up the grid
176 for (auto part: *evt) {
177 double rapid =part->momentum().pseudoRapidity();
178 double phi = part->momentum().phi(); //phi is in range -pi to pi
179 double et=part->momentum().perp();
180 int p_stat=part->status();
181 int p_id = part->pdg_id();
182 std::cout << " eta = " << rapid<< " Phi = " << phi << " Et = " <<et/GeV << " Status= " << p_stat << " PDG ID= "<< p_id << std::endl;
183 }
184 }
186 for (const auto& pitr: *evt) {
187 int p_stat=pitr->status();
188 if(p_stat==2 && pitr->production_vertex() && pitr->end_vertex()) {
189 const auto& prodVtx = pitr->production_vertex()->position();
190 const auto& endVtx = pitr->end_vertex()->position();
191 const CLHEP::HepLorentzVector lv0( prodVtx.x(), prodVtx.y(), prodVtx.z(), prodVtx.t() );
192 const CLHEP::HepLorentzVector lv1( endVtx.x(), endVtx.y(), endVtx.z(), endVtx.t() );
193
194 CLHEP::HepLorentzVector dist4D(lv1);
195 dist4D-=lv0;
196 CLHEP::Hep3Vector dist3D=dist4D.vect();
197 if(dist3D.mag()>1*Gaudi::Units::mm) {
198 const auto& GenMom = pitr->momentum();
199 const CLHEP::HepLorentzVector mom( GenMom.x(), GenMom.y(), GenMom.z(), GenMom.t() );
200 ATH_MSG_INFO("Quasi stable particle "<<pitr);
201 ATH_MSG_INFO(" Prod V:"<<pitr->production_vertex ());
202 ATH_MSG_INFO(" Decay V:"<<pitr->end_vertex ());
203 ATH_MSG_INFO(" gamma(Momentum)="<<mom.gamma()<<" gamma(Vertices)="<<dist4D.gamma());
204 }
205 }
206 }
207 }
208 }
209 }
210 return StatusCode::SUCCESS;
211}
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
std::string m_keyout
Definition DumpMC.h:19
bool m_PrintQuasiStableParticles
Definition DumpMC.h:23
StatusCode initialize()
Definition DumpMC.cxx:22
StatusCode execute()
Definition DumpMC.cxx:32
bool m_EtaPhi
Definition DumpMC.h:22
DumpMC(const std::string &name, ISvcLocator *pSvcLocator)
Definition DumpMC.cxx:11
bool m_DeepCopy
Definition DumpMC.h:21
bool m_VerboseOutput
Definition DumpMC.h:20
std::string m_mcEventKey
StoreGate key for the MC event collection (defaults to GEN_EVENT)
Definition GenBase.h:137
virtual StatusCode initialize() override
Definition GenBase.cxx:17
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition GenBase.cxx:11
const McEventCollection * events_const() const
Access the current event's McEventCollection (const)
Definition GenBase.h:96
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
void line(std::ostream &os, const GenEvent &e)
Definition GenEvent.h:677
Extra patterns decribing particle interation process.