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 "HepMC3AccessStrings.h"
19#include "HepMcDataPool.h"
20
21using namespace GeneratorObjectsTPCnv;
23// Constructors
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 if ( datapools.vtx.capacity() - datapools.vtx.allocated() < nVertices ) {
63 datapools.vtx.reserve( datapools.vtx.allocated() + nVertices );
64 }
65 const unsigned int nParts = persObj->m_genParticles.size();
66 if ( datapools.part.capacity() - datapools.part.allocated() < nParts ) {
67 datapools.part.reserve( datapools.part.allocated() + nParts );
68 }
69 const unsigned int nEvts = persObj->m_genEvents.size();
70 if ( datapools.evt.capacity() - datapools.evt.allocated() < nEvts ) {
71 datapools.evt.reserve( datapools.evt.allocated() + nEvts );
72 }
73
74 transObj->reserve( nEvts );
75 const std::vector<GenEvent_p2>::const_iterator itrEnd = persObj->m_genEvents.end();
76 for ( std::vector<GenEvent_p2>::const_iterator itr = persObj->m_genEvents.begin();
77 itr != itrEnd;
78 ++itr ) {
79 const GenEvent_p2& persEvt = *itr;
80 HepMC::GenEvent * genEvt = datapools.getGenEvent();
81#ifdef HEPMC3
82 genEvt->add_attribute (barcodesStr, std::make_shared<HepMC::GenEventBarcodes>());
83 genEvt->add_attribute(signalProcessIdStr,std::make_shared<HepMC3::IntAttribute>(persEvt.m_signalProcessId));
84 genEvt->set_event_number(persEvt.m_eventNbr);
85 genEvt->add_attribute(eventScaleStr,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_eventScale));
86 genEvt->add_attribute(alphaQcdStr,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_alphaQCD));
87 genEvt->add_attribute(alphaQedStr,std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_alphaQED));
88 genEvt->weights()= persEvt.m_weights;
89 genEvt->add_attribute(randomStatesStr,std::make_shared<HepMC3::VectorLongIntAttribute>(persEvt.m_randomStates));
90
91 transObj->push_back( genEvt );
92
93 ParticlesMap_t partToEndVtx( (persEvt.m_particlesEnd-persEvt.m_particlesBegin)/2 );
94
95 // create the vertices
96 const unsigned int endVtx = persEvt.m_verticesEnd;
97 for ( unsigned int iVtx= persEvt.m_verticesBegin; iVtx != endVtx; ++iVtx ) {
98 genEvt->add_vertex( createGenVertex( *persObj,
99 persObj->m_genVertices[iVtx],
100 partToEndVtx,
101 datapools ) );
102 } //> end loop over vertices
103
104 // set the signal process vertex
105 const int sigProcVtx = persEvt.m_signalProcessVtx;
106 if ( sigProcVtx ) {
107 auto Vtx=HepMC::barcode_to_vertex(genEvt, sigProcVtx );
109 }
110 // connect particles to their end vertices
111 for ( const auto& p: partToEndVtx) {
112 auto decayVtx = HepMC::barcode_to_vertex(genEvt, p.second );
113 if ( decayVtx ) {
114 decayVtx->add_particle_in( p.first );
115 } else {
116 msg << MSG::ERROR<< "GenParticle points to null end vertex !!"<< endmsg;
117 }
118 }
119#else
120 genEvt->m_signal_process_id = persEvt.m_signalProcessId;
121 genEvt->m_event_number = persEvt.m_eventNbr;
122 genEvt->m_event_scale = persEvt.m_eventScale;
123 genEvt->m_alphaQCD = persEvt.m_alphaQCD;
124 genEvt->m_alphaQED = persEvt.m_alphaQED;
125 genEvt->m_signal_process_vertex = 0;
126 genEvt->m_weights = persEvt.m_weights;
127 genEvt->m_random_states = persEvt.m_randomStates;
128 genEvt->m_vertex_barcodes.clear();
129 genEvt->m_particle_barcodes.clear();
130 genEvt->m_pdf_info = 0; //> not available at that time...
131
132 transObj->push_back( genEvt );
133
134 // create a temporary map associating the barcode of an end-vtx to its
135 // particle.
136 // As not all particles are stable (d'oh!) we take 50% of the number of
137 // particles as an initial size of the hash-map (to prevent re-hash)
138 ParticlesMap_t partToEndVtx( (persEvt.m_particlesEnd-
139 persEvt.m_particlesBegin)/2 );
140
141 // create the vertices
142 const unsigned int endVtx = persEvt.m_verticesEnd;
143 for ( unsigned int iVtx= persEvt.m_verticesBegin; iVtx != endVtx; ++iVtx ) {
144 genEvt->add_vertex( createGenVertex( *persObj,
145 persObj->m_genVertices[iVtx],
146 partToEndVtx,
147 datapools ) );
148 } //> end loop over vertices
149
150 // set the signal process vertex
151 const int sigProcVtx = persEvt.m_signalProcessVtx;
152 if ( sigProcVtx != 0 ) {
153 genEvt->set_signal_process_vertex( genEvt->barcode_to_vertex( sigProcVtx ) );
154 }
155
156 // connect particles to their end vertices
157 const ParticlesMap_t::iterator endItr = partToEndVtx.end();
158 for ( ParticlesMap_t::iterator p = partToEndVtx.begin();
159 p != endItr;
160 ++p ) {
161 auto decayVtx = genEvt->barcode_to_vertex( p->second );
162 if ( decayVtx ) {
163 decayVtx->add_particle_in( p->first );
164 } else {
165 msg << MSG::ERROR
166 << "GenParticle points to null end vertex !!"
167 << endmsg;
168 }
169 }
170#endif
171 } //> end loop over m_genEvents
172
173 msg << MSG::DEBUG << "Loaded McEventCollection from persistent state [OK]"
174 << endmsg;
175}
176
179 MsgStream& msg )
180{
181 msg << MSG::DEBUG << "Creating persistent state of McEventCollection..."
182 << endmsg;
183
184 msg << MSG::ERROR
185 << "This transient-to-persistent converter method has been RETIRED !!"
186 << endmsg
187 << "You are not supposed to end-up here ! Go away !"
188 << endmsg;
189
190 throw std::runtime_error( "Retired McEventCollectionCnv_p2::transToPers() !!" );
191}
192
193
196 const GenVertex_p2& persVtx,
197 ParticlesMap_t& partToEndVtx, HepMC::DataPool& datapools, HepMC::GenEvent* parent )
198{
199 HepMC::GenVertexPtr vtx = datapools.getGenVertex();
200 if (parent) parent->add_vertex(vtx);
201#ifdef HEPMC3
202 vtx->set_position( HepMC::FourVector(persVtx.m_x,persVtx.m_y, persVtx.m_z, persVtx.m_t) );
203 vtx->set_status(persVtx.m_id);
204 // cast from std::vector<float> to std::vector<double>
205 std::vector<double> weights( persVtx.m_weights.begin(), persVtx.m_weights.end() );
206 vtx->add_attribute("weights",std::make_shared<HepMC3::VectorDoubleAttribute>(weights));
208
209 // handle the in-going (orphans) particles
210 const unsigned int nPartsIn = persVtx.m_particlesIn.size();
211 for ( unsigned int i = 0; i != nPartsIn; ++i ) {
212 createGenParticle( persEvt.m_genParticles[persVtx.m_particlesIn[i]], partToEndVtx, datapools );
213 }
214
215 // now handle the out-going particles
216 const unsigned int nPartsOut = persVtx.m_particlesOut.size();
217 for ( unsigned int i = 0; i != nPartsOut; ++i ) {
218 createGenParticle( persEvt.m_genParticles[persVtx.m_particlesOut[i]], partToEndVtx, datapools, vtx );
219 }
220#else
221 vtx->m_position.setX( persVtx.m_x );
222 vtx->m_position.setY( persVtx.m_y );
223 vtx->m_position.setZ( persVtx.m_z );
224 vtx->m_position.setT( persVtx.m_t );
225 vtx->m_particles_in.clear();
226 vtx->m_particles_out.clear();
227 vtx->m_id = persVtx.m_id;
228 vtx->m_weights.m_weights.reserve( persVtx.m_weights.size() );
229 vtx->m_weights.m_weights.assign ( persVtx.m_weights.begin(),
230 persVtx.m_weights.end() );
231 vtx->m_event = 0;
232 vtx->m_barcode = persVtx.m_barcode;
233
234 // handle the in-going (orphans) particles
235 const unsigned int nPartsIn = persVtx.m_particlesIn.size();
236 for ( unsigned int i = 0; i != nPartsIn; ++i ) {
238 partToEndVtx,
239 datapools );
240 }
241
242 // now handle the out-going particles
243 const unsigned int nPartsOut = persVtx.m_particlesOut.size();
244 for ( unsigned int i = 0; i != nPartsOut; ++i ) {
245 vtx->add_particle_out( createGenParticle( persEvt.m_genParticles[persVtx.m_particlesOut[i]],
246 partToEndVtx,
247 datapools ) );
248 }
249#endif
250
251 return vtx;
252}
253
256 ParticlesMap_t& partToEndVtx, HepMC::DataPool& datapools, const HepMC::GenVertexPtr& parent )
257{
259
260 if (parent) parent->add_particle_out(p);
261#ifdef HEPMC3
262 p->set_momentum( HepMC::FourVector(persPart.m_px,persPart.m_py,persPart.m_pz, persPart.m_ene ));
263 p->set_pdg_id( persPart.m_pdgId);
264 p->set_status( persPart.m_status);
265 p->add_attribute("phi",std::make_shared<HepMC3::DoubleAttribute>(persPart.m_phiPolarization));
266 p->add_attribute("theta",std::make_shared<HepMC3::DoubleAttribute>(persPart.m_thetaPolarization));
268
269 // fillin' the flow
270 std::vector<int> flows;
271 const unsigned int nFlow = persPart.m_flow.size();
272 for ( unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
273 flows.push_back(persPart.m_flow[iFlow].second );
274 }
275 //We construct it here as vector w/o gaps.
276 p->add_attribute("flows", std::make_shared<HepMC3::VectorIntAttribute>(flows));
277
278#else
279 p->m_momentum.setPx( persPart.m_px );
280 p->m_momentum.setPy( persPart.m_py );
281 p->m_momentum.setPz( persPart.m_pz );
282 p->m_momentum.setE ( persPart.m_ene );
283 p->m_pdg_id = persPart.m_pdgId;
284 p->m_status = persPart.m_status;
285 p->m_polarization.m_theta= static_cast<double>(persPart.m_thetaPolarization);
286 p->m_polarization.m_phi = static_cast<double>(persPart.m_phiPolarization );
287 p->m_production_vertex = 0;
288 p->m_end_vertex = 0;
289 p->m_barcode = persPart.m_barcode;
290
291 // fillin' the flow
292 const unsigned int nFlow = persPart.m_flow.size();
293 p->m_flow.clear();
294 for ( unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
295 p->m_flow.set_icode( persPart.m_flow[iFlow].first,
296 persPart.m_flow[iFlow].second );
297 }
298#endif
299
300 if ( persPart.m_endVtx != 0 ) {
301 partToEndVtx[p] = persPart.m_endVtx;
302 }
303
304 return p;
305}
#define endmsg
void reserve(unsigned int size)
Set the desired capacity.
unsigned int capacity()
return capacity of pool OK
unsigned int allocated()
return size already allocated OK
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, as defined for HEPEVT.
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...
void set_signal_process_vertex(GenEvent *e, T v)
Definition GenEvent.h:670
GenVertex * barcode_to_vertex(const GenEvent *e, int id)
Definition GenEvent.h:647
HepMC::GenVertex * GenVertexPtr
Definition GenVertex.h:59
bool suggest_barcode(T &p, int i)
Definition GenEvent.h:690
GenParticle * GenParticlePtr
Definition GenParticle.h:37
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
A namespace for all vertexing packages and related stuff.
HepMC::GenParticlePtr getGenParticle()
GenPartPool_t part
an arena of HepMC::GenParticle for efficient object instantiation
HepMC::GenEvent * getGenEvent()
HepMC::GenVertexPtr getGenVertex()
GenVtxPool_t vtx
an arena of HepMC::GenVertex for efficient object instantiation
GenEvtPool_t evt
an arena of HepMC::GenEvent for efficient object instantiation
MsgStream & msg
Definition testRead.cxx:32