ATLAS Offline Software
Loading...
Searching...
No Matches
McEventCollectionCnv_p2.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_p2.cxx
8// Implementation file for class McEventCollectionCnv_p2
9// Author: S.Binet<binet@cern.ch>
11
12
13// STL includes
14#include <utility>
15
16// GeneratorObjectsTPCnv includes
18#include "HepMcDataPool.h"
19
21// Constructors
23
27
29
30= default;
31
34{
35 if ( this != &rhs ) {
36 Base_t::operator=( rhs );
37 }
38 return *this;
39}
40
42// Destructor
44
46= default;
47
48
50 McEventCollection* transObj,
51 MsgStream& msg )
52{
53 msg << MSG::DEBUG << "Loading McEventCollection from persistent state..."
54 << endmsg;
55
56 // elements are managed by DataPool
57 transObj->clear(SG::VIEW_ELEMENTS);
58 HepMC::DataPool datapools;
59 const unsigned int nVertices = persObj->m_genVertices.size();
60 if ( datapools.vtx.capacity() - datapools.vtx.allocated() < nVertices ) {
61 datapools.vtx.reserve( datapools.vtx.allocated() + nVertices );
62 }
63 const unsigned int nParts = persObj->m_genParticles.size();
64 if ( datapools.part.capacity() - datapools.part.allocated() < nParts ) {
65 datapools.part.reserve( datapools.part.allocated() + nParts );
66 }
67 const unsigned int nEvts = persObj->m_genEvents.size();
68 if ( datapools.evt.capacity() - datapools.evt.allocated() < nEvts ) {
69 datapools.evt.reserve( datapools.evt.allocated() + nEvts );
70 }
71
72 transObj->reserve( nEvts );
73 const std::vector<GenEvent_p2>::const_iterator itrEnd = persObj->m_genEvents.end();
74 for ( std::vector<GenEvent_p2>::const_iterator itr = persObj->m_genEvents.begin();
75 itr != itrEnd;
76 ++itr ) {
77 const GenEvent_p2& persEvt = *itr;
78 HepMC::GenEvent * genEvt = datapools.getGenEvent();
79 genEvt->add_attribute (HepMCStr::barcodes, std::make_shared<HepMC::GenEventBarcodes>());
80 genEvt->add_attribute(HepMCStr::signal_process_id,std::make_shared<HepMC3::IntAttribute>(persEvt.m_signalProcessId));
81 genEvt->set_event_number(persEvt.m_eventNbr);
82 genEvt->add_attribute(HepMCStr::event_scale,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_eventScale));
83 genEvt->add_attribute(HepMCStr::alphaQCD,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_alphaQCD));
84 genEvt->add_attribute(HepMCStr::alphaQED,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_alphaQED));
85 genEvt->weights()= persEvt.m_weights;
86 genEvt->add_attribute(HepMCStr::random_states,std::make_shared<HepMC3::VectorLongIntAttribute>(persEvt.m_randomStates));
87
88 transObj->push_back( genEvt );
89
90 ParticlesMap_t partToEndVtx( (persEvt.m_particlesEnd-persEvt.m_particlesBegin)/2 );
91
92 // create the vertices
93 const unsigned int endVtx = persEvt.m_verticesEnd;
94 for ( unsigned int iVtx= persEvt.m_verticesBegin; iVtx != endVtx; ++iVtx ) {
95 genEvt->add_vertex( createGenVertex( *persObj,
96 persObj->m_genVertices[iVtx],
97 partToEndVtx,
98 datapools ) );
99 } //> end loop over vertices
100
101 // set the signal process vertex
102 const int sigProcVtx = persEvt.m_signalProcessVtx;
103 if ( sigProcVtx ) {
104 auto Vtx=HepMC::barcode_to_vertex(genEvt, sigProcVtx );
106 }
107 // connect particles to their end vertices
108 for ( const auto& p: partToEndVtx) {
109 auto decayVtx = HepMC::barcode_to_vertex(genEvt, p.second );
110 if ( decayVtx ) {
111 decayVtx->add_particle_in( p.first );
112 } else {
113 msg << MSG::ERROR<< "GenParticle points to null end vertex !!"<< endmsg;
114 }
115 }
116 } //> end loop over m_genEvents
117
118 msg << MSG::DEBUG << "Loaded McEventCollection from persistent state [OK]"
119 << endmsg;
120}
121
124 MsgStream& msg )
125{
126 msg << MSG::DEBUG << "Creating persistent state of McEventCollection..."
127 << endmsg;
128
129 msg << MSG::ERROR
130 << "This transient-to-persistent converter method has been RETIRED !!"
131 << endmsg
132 << "You are not supposed to end-up here ! Go away !"
133 << endmsg;
134
135 throw std::runtime_error( "Retired McEventCollectionCnv_p2::transToPers() !!" );
136}
137
138
141 const GenVertex_p2& persVtx,
142 ParticlesMap_t& partToEndVtx, HepMC::DataPool& datapools, HepMC::GenEvent* parent )
143{
144 HepMC::GenVertexPtr vtx = datapools.getGenVertex();
145 if (parent) parent->add_vertex(vtx);
146 vtx->set_position( HepMC::FourVector(persVtx.m_x,persVtx.m_y, persVtx.m_z, persVtx.m_t) );
147 vtx->set_status(persVtx.m_id);
148 // cast from std::vector<float> to std::vector<double>
149 std::vector<double> weights( persVtx.m_weights.begin(), persVtx.m_weights.end() );
150 vtx->add_attribute(HepMCStr::weights,std::make_shared<HepMC3::VectorDoubleAttribute>(weights));
152
153 // handle the in-going (orphans) particles
154 const unsigned int nPartsIn = persVtx.m_particlesIn.size();
155 for ( unsigned int i = 0; i != nPartsIn; ++i ) {
156 createGenParticle( persEvt.m_genParticles[persVtx.m_particlesIn[i]], partToEndVtx, datapools );
157 }
158
159 // now handle the out-going particles
160 const unsigned int nPartsOut = persVtx.m_particlesOut.size();
161 for ( unsigned int i = 0; i != nPartsOut; ++i ) {
162 createGenParticle( persEvt.m_genParticles[persVtx.m_particlesOut[i]], partToEndVtx, datapools, vtx );
163 }
164
165 return vtx;
166}
167
170 ParticlesMap_t& partToEndVtx, HepMC::DataPool& datapools, const HepMC::GenVertexPtr& parent )
171{
173
174 if (parent) parent->add_particle_out(p);
175 p->set_momentum( HepMC::FourVector(persPart.m_px,persPart.m_py,persPart.m_pz, persPart.m_ene ));
176 p->set_pdg_id( persPart.m_pdgId);
177 p->set_status( persPart.m_status);
178 p->add_attribute(HepMCStr::phi,std::make_shared<HepMC3::DoubleAttribute>(persPart.m_phiPolarization));
179 p->add_attribute(HepMCStr::theta,std::make_shared<HepMC3::DoubleAttribute>(persPart.m_thetaPolarization));
181
182 // fillin' the flow
183 std::vector<int> flows;
184 const unsigned int nFlow = persPart.m_flow.size();
185 for ( unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
186 flows.push_back(persPart.m_flow[iFlow].second );
187 }
188 //We construct it here as vector w/o gaps.
189 p->add_attribute(HepMCStr::flows, std::make_shared<HepMC3::VectorIntAttribute>(flows));
190
191 if ( persPart.m_endVtx != 0 ) {
192 partToEndVtx[p] = persPart.m_endVtx;
193 }
194
195 return p;
196}
#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.
double m_alphaQED
value of the QED coupling.
Definition GenEvent_p2.h:82
std::vector< long int > m_randomStates
Container of random numbers for the generator states.
Definition GenEvent_p2.h:97
std::vector< double > m_weights
Weights for this event.
Definition GenEvent_p2.h:93
unsigned int m_particlesEnd
End position in the vector of particles composing this event.
double m_eventScale
Energy scale.
Definition GenEvent_p2.h:74
unsigned int m_particlesBegin
Begin position in the vector of particles composing this event.
int m_signalProcessId
Id of the processus being generated.
Definition GenEvent_p2.h:66
unsigned int m_verticesEnd
End position in the vector of vertices composing this event.
int m_signalProcessVtx
Barcode of the GenVertex holding the signal process.
Definition GenEvent_p2.h:88
int m_eventNbr
Event number.
Definition GenEvent_p2.h:70
unsigned int m_verticesBegin
Begin position in the vector of vertices composing this event.
double m_alphaQCD
value of the QCD coupling.
Definition GenEvent_p2.h:78
int m_endVtx
Barcode of the decay vertex of this particle.
double m_py
y-component of the 4-momentum of this particle
int m_pdgId
identity of this particle, according to the Particle Data Group notation
double m_px
x-component of the 4-momentum of this particle
int m_status
Status of this particle.
std::vector< std::pair< int, int > > m_flow
Flow for this particle.
float m_thetaPolarization
polarization
float m_phiPolarization
phi polarization
double m_ene
e-component of the 4-momentum of this particle
int m_barcode
barcode of this particles (uniquely identifying this particle within a given GenEvent)
double m_pz
z-component of the 4-momentum of this particle
double m_t
t-coordinate of the 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)
std::vector< float > m_weights
Weights for this vertex.
int m_id
Id of this vertex.
double m_x
x-coordinate of the vertex
double m_z
z-coordinate of the vertex
double m_y
y-coordinate of the vertex
std::vector< int > m_particlesIn
collection of barcodes of in-going particles connected to this vertex
static HepMC::GenVertexPtr createGenVertex(const McEventCollection_p2 &persEvts, const GenVertex_p2 &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_p2 & operator=(const McEventCollectionCnv_p2 &rhs)
Assignement operator.
virtual void persToTrans(const McEventCollection_p2 *persObj, McEventCollection *transObj, MsgStream &log)
Method creating the transient representation of McEventCollection from its persistent representation ...
McEventCollectionCnv_p2()
Default constructor:
std::unordered_map< HepMC::GenParticlePtr, int > ParticlesMap_t
virtual void transToPers(const McEventCollection *transObj, McEventCollection_p2 *persObj, MsgStream &log)
Method creating the persistent representation McEventCollection_p2 from its transient representation ...
T_AthenaPoolTPCnvBase< McEventCollection, McEventCollection_p2 > Base_t
static HepMC::GenParticlePtr createGenParticle(const GenParticle_p2 &p, ParticlesMap_t &partToEndVtx, HepMC::DataPool &datapools, const HepMC::GenVertexPtr &parent=nullptr)
Create a transient GenParticle from a persistent one (vers.1) It returns the new GenParticle.
virtual ~McEventCollectionCnv_p2()
Destructor.
std::vector< GenParticle_p2 > m_genParticles
The vector of persistent representation of GenParticles.
std::vector< GenEvent_p2 > m_genEvents
The vector of persistent representation of GenEvents.
std::vector< GenVertex_p2 > m_genVertices
The vector of persistent representation of GenVertices.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
const std::string event_scale
const std::string phi
const std::string flows
const std::string weights
const std::string theta
const std::string signal_process_id
const std::string random_states
const std::string alphaQED
const std::string alphaQCD
const std::string barcodes
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