ATLAS Offline Software
Loading...
Searching...
No Matches
McEventCollectionCnv_p3.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// McEventCollectionCnv_p3.cxx
8// Implementation file for class McEventCollectionCnv_p3
9// Author: S.Binet<binet@cern.ch>
11
12
13// STL includes
14#include <utility>
15#include <cmath>
16
17// GeneratorObjectsTPCnv includes
19#include "HepMcDataPool.h"
20
22// Constructors
24
25
29
31
32= default;
33
36{
37 if ( this != &rhs ) {
38 Base_t::operator=( rhs );
39 }
40 return *this;
41}
42
44// Destructor
46
48= default;
49
50
52 McEventCollection* transObj,
53 MsgStream& msg )
54{
55 msg << MSG::DEBUG << "Loading McEventCollection from persistent state..."
56 << endmsg;
57
58 // elements are managed by DataPool
59 transObj->clear(SG::VIEW_ELEMENTS);
60 HepMC::DataPool datapools;
61 const unsigned int nVertices = persObj->m_genVertices.size();
62 datapools.vtx.prepareToAdd(nVertices);
63 const unsigned int nParts = persObj->m_genParticles.size();
64 datapools.part.prepareToAdd(nParts);
65 const unsigned int nEvts = persObj->m_genEvents.size();
66 datapools.evt.prepareToAdd(nEvts);
67
68 transObj->reserve( nEvts );
69 for ( std::vector<GenEvent_p3>::const_iterator
70 itr = persObj->m_genEvents.begin(),
71 itrEnd = persObj->m_genEvents.end();
72 itr != itrEnd;
73 ++itr ) {
74 const GenEvent_p3& persEvt = *itr;
75
76 HepMC::GenEvent * genEvt = datapools.getGenEvent();
77 genEvt->add_attribute (HepMCStr::barcodes, std::make_shared<HepMC::GenEventBarcodes>());
78 genEvt->add_attribute(HepMCStr::signal_process_id,std::make_shared<HepMC3::IntAttribute>(persEvt.m_signalProcessId));
79 genEvt->set_event_number(persEvt.m_eventNbr);
80 genEvt->add_attribute(HepMCStr::event_scale,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_eventScale));
81 genEvt->add_attribute(HepMCStr::alphaQCD,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_alphaQCD));
82 genEvt->add_attribute(HepMCStr::alphaQED,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_alphaQED));
83 genEvt->weights()= persEvt.m_weights;
84 genEvt->add_attribute(HepMCStr::random_states,std::make_shared<HepMC3::VectorLongIntAttribute>(persEvt.m_randomStates));
85 transObj->push_back( genEvt );
86
87 ParticlesMap_t partToEndVtx( (persEvt.m_particlesEnd- persEvt.m_particlesBegin)/2 );
88
89 // create the vertices
90 const unsigned int endVtx = persEvt.m_verticesEnd;
91 for ( unsigned int iVtx= persEvt.m_verticesBegin; iVtx != endVtx; ++iVtx ) {
92 createGenVertex( *persObj, persObj->m_genVertices[iVtx],partToEndVtx, datapools, genEvt );
93 }
94
95 // set the signal process vertex
96 const int sigProcVtx = persEvt.m_signalProcessVtx;
97 if ( sigProcVtx != 0 ) {
98 auto Vtx=HepMC::barcode_to_vertex(genEvt, sigProcVtx );
100 }
101
102 // connect particles to their end vertices
103 for (auto & p : partToEndVtx) {
104 auto decayVtx=HepMC::barcode_to_vertex(genEvt, p.second );
105 if ( decayVtx ) {
106 decayVtx->add_particle_in( p.first );
107 } else {
108 msg << MSG::ERROR
109 << "GenParticle points to null end vertex !!"
110 << endmsg;
111 }
112 }
113 } //> end loop over m_genEvents
114
115 msg << MSG::DEBUG << "Loaded McEventCollection from persistent state [OK]"
116 << endmsg;
117}
118
120 McEventCollection_p3* /*persObj*/,
121 MsgStream& msg )
122{
123 msg << MSG::ERROR
124 << "This transient-to-persistent converter method has been RETIRED !!"
125 << endmsg
126 << "You are not supposed to end-up here ! Go away !"
127 << endmsg;
128
129 throw std::runtime_error( "Retired McEventCollectionCnv_p3::transToPers() !!" );
130}
131
132
135 const GenVertex_p3& persVtx,
136 ParticlesMap_t& partToEndVtx,
137 HepMC::DataPool& datapools, HepMC::GenEvent* parent )
138{
139 HepMC::GenVertexPtr vtx = datapools.getGenVertex();
140 if (parent) parent->add_vertex(vtx);
141
142 vtx->set_position( HepMC::FourVector(persVtx.m_x,persVtx.m_y,persVtx.m_z,persVtx.m_t) );
143 vtx->set_status(persVtx.m_id);
144 // cast from std::vector<float> to std::vector<double>
145 std::vector<double> weights( persVtx.m_weights.begin(), persVtx.m_weights.end() );
146 vtx->add_attribute(HepMCStr::weights,std::make_shared<HepMC3::VectorDoubleAttribute>(weights));
148 // handle the in-going (orphans) particles
149 const unsigned int nPartsIn = persVtx.m_particlesIn.size();
150 for ( unsigned int i = 0; i != nPartsIn; ++i ) {
151 createGenParticle( persEvt.m_genParticles[persVtx.m_particlesIn[i]], partToEndVtx, datapools, vtx, false );
152 }
153 // now handle the out-going particles
154 const unsigned int nPartsOut = persVtx.m_particlesOut.size();
155 for ( unsigned int i = 0; i != nPartsOut; ++i ) {
156 createGenParticle( persEvt.m_genParticles[persVtx.m_particlesOut[i]], partToEndVtx, datapools, vtx );
157 }
158
159 return vtx;
160}
161
164 ParticlesMap_t& partToEndVtx,
165 HepMC::DataPool& datapools, const HepMC::GenVertexPtr& parent, bool add_to_output )
166{
168 if (parent) add_to_output?parent->add_particle_out(p):parent->add_particle_in(p);
169
170 p->set_pdg_id(persPart.m_pdgId);
171 p->set_status(persPart.m_status);
172 // Note: do the E calculation in extended (long double) precision.
173 // That happens implicitly on x86 with optimization on; saying it
174 // explicitly ensures that we get the same results with and without
175 // optimization. (If this is a performance issue for platforms
176 // other than x86, one could change to double for those platforms.)
177 double temp_e=0.0;
178 if ( 0 == persPart.m_recoMethod ) {
179 temp_e = std::sqrt( (long double)(persPart.m_px)*persPart.m_px +
180 (long double)(persPart.m_py)*persPart.m_py +
181 (long double)(persPart.m_pz)*persPart.m_pz +
182 (long double)(persPart.m_m) *persPart.m_m );
183 } else {
184 const int signM2 = ( persPart.m_m >= 0. ? 1 : -1 );
185 const double persPart_ene =
186 std::sqrt( std::abs((long double)(persPart.m_px)*persPart.m_px +
187 (long double)(persPart.m_py)*persPart.m_py +
188 (long double)(persPart.m_pz)*persPart.m_pz +
189 signM2* (long double)(persPart.m_m)* persPart.m_m));
190 const int signEne = ( persPart.m_recoMethod == 1 ? 1 : -1 );
191 temp_e=signEne * persPart_ene;
192 }
193 p->set_momentum(HepMC::FourVector(persPart.m_px,persPart.m_py,persPart.m_pz,temp_e));
194 // setup flow
195 // fillin' the flow
196 std::vector<int> flows;
197 const unsigned int nFlow = persPart.m_flow.size();
198 for ( unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
199 flows.push_back(persPart.m_flow[iFlow].second );
200 }
201 //We construct it here as vector w/o gaps.
202 p->add_attribute(HepMCStr::flows, std::make_shared<HepMC3::VectorIntAttribute>(flows));
204
205 if ( persPart.m_endVtx != 0 ) {
206 partToEndVtx[p] = persPart.m_endVtx;
207 }
208
209 return p;
210}
#define endmsg
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
void clear()
Erase all the elements in the collection.
std::vector< long int > m_randomStates
Container of random numbers for the generator states.
Definition GenEvent_p3.h:97
double m_eventScale
Energy scale.
Definition GenEvent_p3.h:74
int m_signalProcessVtx
Barcode of the GenVertex holding the signal process.
Definition GenEvent_p3.h:88
unsigned int m_verticesEnd
End position in the vector of vertices composing this event.
double m_alphaQED
value of the QED coupling.
Definition GenEvent_p3.h:82
unsigned int m_particlesEnd
End position in the vector of particles composing this event.
int m_signalProcessId
Id of the processus being generated.
Definition GenEvent_p3.h:66
std::vector< double > m_weights
Weights for this event.
Definition GenEvent_p3.h:93
unsigned int m_particlesBegin
Begin position in the vector of particles composing this event.
double m_alphaQCD
value of the QCD coupling.
Definition GenEvent_p3.h:78
int m_eventNbr
Event number.
Definition GenEvent_p3.h:70
unsigned int m_verticesBegin
Begin position in the vector of vertices composing this event.
float m_pz
z-component of the 4-momentum of this particle
int m_status
Status of this particle.
short m_recoMethod
switch to know which method to chose to better recover the original HepLorentzVector.
int m_barcode
barcode of this particles (uniquely identifying this particle within a given GenEvent)
float m_m
m-component of the 4-momentum of this particle
float m_px
x-component of the 4-momentum of this particle
std::vector< std::pair< int, int > > m_flow
Flow for this particle.
float m_py
y-component of the 4-momentum of this particle
int m_endVtx
Barcode of the decay vertex of this particle.
int m_pdgId
identity of this particle, according to the Particle Data Group notation
std::vector< float > m_weights
Weights for this vertex.
std::vector< int > m_particlesOut
collection of barcodes of out-going particles connected to this vertex
int m_barcode
barcode of this vertex (uniquely identifying a vertex within an event)
float m_z
z-coordinate of the vertex
std::vector< int > m_particlesIn
collection of barcodes of in-going particles connected to this vertex
float m_x
x-coordinate of the vertex
float m_y
y-coordinate of the vertex
int m_id
Id of this vertex.
float m_t
t-coordinate of the vertex
virtual void transToPers(const McEventCollection *transObj, McEventCollection_p3 *persObj, MsgStream &log)
Method creating the persistent representation McEventCollection_p3 from its transient representation ...
McEventCollectionCnv_p3 & operator=(const McEventCollectionCnv_p3 &rhs)
Assignement operator.
static HepMC::GenVertexPtr createGenVertex(const McEventCollection_p3 &persEvts, const GenVertex_p3 &vtx, ParticlesMap_t &bcToPart, HepMC::DataPool &datapools, HepMC::GenEvent *parent=nullptr)
Create a transient GenVertex from a persistent one (version 1) It returns the new GenVertex.
McEventCollectionCnv_p3()
Default constructor:
static HepMC::GenParticlePtr createGenParticle(const GenParticle_p3 &p, ParticlesMap_t &partToEndVtx, HepMC::DataPool &datapools, const HepMC::GenVertexPtr &parent=nullptr, bool add_to_output=true)
Create a transient GenParticle from a persistent one (vers.1) It returns the new GenParticle.
virtual void persToTrans(const McEventCollection_p3 *persObj, McEventCollection *transObj, MsgStream &log)
Method creating the transient representation of McEventCollection from its persistent representation ...
std::unordered_map< HepMC::GenParticlePtr, int > ParticlesMap_t
T_AthenaPoolTPCnvBase< McEventCollection, McEventCollection_p3 > Base_t
virtual ~McEventCollectionCnv_p3()
Destructor.
std::vector< GenParticle_p3 > m_genParticles
The vector of persistent representation of GenParticles.
std::vector< GenEvent_p3 > m_genEvents
The vector of persistent representation of GenEvents.
std::vector< GenVertex_p3 > m_genVertices
The vector of persistent representation of GenVertices.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
ConstGenVertexPtr barcode_to_vertex(const GenEvent *e, int id)
Definition GenEvent.h:403
HepMC3::FourVector FourVector
void set_signal_process_vertex(GenEvent *e, T &v)
Definition GenEvent.h:591
bool suggest_barcode(T &p, int i)
Definition GenEvent.h:607
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
A namespace for all vertexing packages and related stuff.
::DataPool< HepMC::GenEvent, ClearGenEvent > evt
::DataPool< HepMC::GenParticle, ClearGenParticle > part
HepMC::GenParticlePtr getGenParticle()
HepMC::GenEvent * getGenEvent()
HepMC::GenVertexPtr getGenVertex()
::DataPool< HepMC::GenVertex, ClearGenVertex > vtx
MsgStream & msg
Definition testRead.cxx:32