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(const EventContext& ctx) {
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(ctx)) {
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 std::vector<HepMC::GenVertexPtr> lambda_vertices_to_remove;
42 for (auto part: **evt){
43 const int abspid = std::abs(part->pdg_id());
44 if (abspid != 310 && abspid != 3122 && abspid != 3222 && abspid != 3112 && abspid != 3322 && abspid != 3312 && abspid != 3334 ) continue;
45 if (!part->end_vertex()) continue;
46 lambda_vertices_to_remove.push_back(part->end_vertex());
47 part->set_status(1);
48 }
49 for (auto v: lambda_vertices_to_remove) (*evt)->remove_vertex(std::move(v));
50 }
51
52 if (evtStore()->record(mcCollptra, m_keyout).isFailure()){
53 ATH_MSG_ERROR("Could not record McEventCollection");
54 return StatusCode::FAILURE;
55 }
56 }
57
58 // Loop over all events in McEventCollection
59 for(const HepMC::GenEvent* evt : *events_const(ctx)) {
60 auto pdfinfo = evt->pdf_info();
61 auto ion = evt->heavy_ion();
62 if (pdfinfo) {
63 std::cout << "PdfInfo: "
64 << pdfinfo->parton_id[0] << ", "
65 << pdfinfo->parton_id[1] << ", "
66 << pdfinfo->x[0] << ", "
67 << pdfinfo->x[1] << ", "
68 << pdfinfo->scale << ", "
69 << pdfinfo->xf[0] << ", "
70 << pdfinfo->xf[1] << ", "
71 << pdfinfo->pdf_id[0] << ", "
72 << pdfinfo->pdf_id[1]
73 << std::endl;
74 }
75
76 if (ion) {
77 std::cout << std::endl;
78 std::cout << "Heavy Ion: "
79 << ion->Ncoll_hard <<", "
80 << ion->Npart_proj <<" , "
81 << ion->Npart_targ<< ", "
82 << ion->Ncoll<< ", "
83 << ion->spectator_neutrons << ", "
84 << ion->spectator_protons << ", "
85 << ion->N_Nwounded_collisions << ", "
86 << ion->Nwounded_N_collisions << ", "
87 << ion->Nwounded_Nwounded_collisions << ", "
88 << ion->impact_parameter << ", "
89 << ion->event_plane_angle << ", "
90 << ion->eccentricity << ", "
91 << ion->sigma_inel_NN
92 << std::endl;
93 }
94 if (m_VerboseOutput) {
95 if (!m_EtaPhi) {
96 HepMC::Print::line(std::cout,*evt); // standard HepMc dump
97 } else { // sort particles by rapidity and then dump
98 // Loop over all particles in the event and build up the grid
99 for (auto part: *evt) {
100 double rapid =part->momentum().pseudoRapidity();
101 double phi = part->momentum().phi(); //phi is in range -pi to pi
102 double et=part->momentum().perp();
103 int p_stat=part->status();
104 int p_id = part->pdg_id();
105 std::cout << " eta = " << rapid<< " Phi = " << phi << " Et = " <<et/GeV << " Status= " << p_stat << " PDG ID= "<< p_id << std::endl;
106 }
107 }
109 for (const auto& pitr: *evt) {
110 int p_stat=pitr->status();
111 if(p_stat==2 && pitr->production_vertex() && pitr->end_vertex()) {
112 const auto& prodVtx = pitr->production_vertex()->position();
113 const auto& endVtx = pitr->end_vertex()->position();
114 const CLHEP::HepLorentzVector lv0( prodVtx.x(), prodVtx.y(), prodVtx.z(), prodVtx.t() );
115 const CLHEP::HepLorentzVector lv1( endVtx.x(), endVtx.y(), endVtx.z(), endVtx.t() );
116
117 CLHEP::HepLorentzVector dist4D(lv1);
118 dist4D-=lv0;
119 CLHEP::Hep3Vector dist3D=dist4D.vect();
120 if(dist3D.mag()>1*Gaudi::Units::mm) {
121 const auto& GenMom = pitr->momentum();
122 const CLHEP::HepLorentzVector mom( GenMom.x(), GenMom.y(), GenMom.z(), GenMom.t() );
123 ATH_MSG_INFO("Quasi stable particle "<<pitr);
124 ATH_MSG_INFO(" Prod V:"<<pitr->production_vertex ());
125 ATH_MSG_INFO(" Decay V:"<<pitr->end_vertex ());
126 ATH_MSG_INFO(" gamma(Momentum)="<<mom.gamma()<<" gamma(Vertices)="<<dist4D.gamma());
127 }
128 }
129 }
130 }
131 }
132 }
133 return StatusCode::SUCCESS;
134}
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)
ServiceHandle< StoreGateSvc > & evtStore()
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
bool m_EtaPhi
Definition DumpMC.h:22
DumpMC(const std::string &name, ISvcLocator *pSvcLocator)
Definition DumpMC.cxx:11
StatusCode execute(const EventContext &ctx)
Execute method.
Definition DumpMC.cxx:32
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:110
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 EventContext &ctx) const
Access the current event's McEventCollection (const).
Definition GenBase.h:95
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
Extra patterns decribing particle interation process.