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