ATLAS Offline Software
Loading...
Searching...
No Matches
GenEventCnv_p1.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// GenEventCnv_p1.cxx
8// Implementation file for class GenEventCnv_p1
9// Author: S.Binet<binet@cern.ch>
11
12// Framework includes
13#include "GaudiKernel/MsgStream.h"
14
15// GeneratorObjectsTPCnv includes
17#include "HepMcDataPool.h"
18
22
26
28// Non-const methods:
30
35
37 HepMC::GenEvent* transObj,
38 MsgStream& msg )
39{
40 msg << MSG::DEBUG << "Loading HepMC::GenEvent from persistent state..."
41 << endmsg;
42
43 if ( nullptr == m_pool ) {
44 msg << MSG::ERROR
45 << "This instance of GenEventCnv_p1 has a null pointer to "
46 << "HepMC::DataPool !" << endmsg
47 << "This probably means the T/P converter (McEventCollectionCnv_pX) "
48 << "is misconfigured !!"
49 << endmsg;
50 throw std::runtime_error("Null pointer to HepMC::DataPool !!");
51 }
52
53 const unsigned int nVertices = persObj->m_vertices.size();
54 if ( m_pool->vtx.capacity() - m_pool->vtx.allocated() < nVertices ) {
55 m_pool->vtx.reserve( m_pool->vtx.allocated() + nVertices );
56 }
57 const unsigned int nParts = persObj->m_particles.size();
58 if ( m_pool->part.capacity() - m_pool->part.allocated() < nParts ) {
59 m_pool->part.reserve( m_pool->part.allocated() + nParts );
60 }
61
62 transObj->add_attribute (HepMCStr::barcodes, std::make_shared<HepMC::GenEventBarcodes>());
63 transObj->add_attribute(HepMCStr::signal_process_id,std::make_shared<HepMC3::IntAttribute>(persObj->m_signalProcessId ));
64 transObj->set_event_number(persObj->m_eventNbr);
65 transObj->add_attribute(HepMCStr::event_scale,std::make_shared<HepMC3::DoubleAttribute>(persObj->m_eventScale));
66 transObj->add_attribute(HepMCStr::alphaQCD,std::make_shared<HepMC3::DoubleAttribute>(persObj->m_alphaQCD));
67 transObj->add_attribute(HepMCStr::alphaQED,std::make_shared<HepMC3::DoubleAttribute>(persObj->m_alphaQED));
68 transObj->weights()= persObj->m_weights;
69 transObj->add_attribute(HepMCStr::random_states,std::make_shared<HepMC3::VectorLongIntAttribute>(persObj->m_randomStates));
70
71 // create a temporary map associating the barcode of an end-vtx to its
72 // particle.
73 // As not all particles are stable (d'oh!) we take 50% of the number of
74 // particles as an initial size of the hash-map (to prevent re-hash)
75 ParticlesMap_t partToEndVtx(nParts/2);
76
77 // create the vertices
78 for ( unsigned int iVtx = 0; iVtx != nVertices; ++iVtx ) {
79 const GenVertex_p1& persVtx = persObj->m_vertices[iVtx];
80 createGenVertex( *persObj, persVtx, partToEndVtx, *m_pool, transObj );
81 } //> end loop over vertices
82
83 // set the signal process vertex
84 const int sigProcVtx = persObj->m_signalProcessVtx;
85 if ( sigProcVtx != 0 ) {
86 auto Vtx = HepMC::barcode_to_vertex(transObj,sigProcVtx );
88 }
89
90 // connect particles to their end vertices
91 const ParticlesMap_t::iterator endItr= partToEndVtx.end();
92 for ( ParticlesMap_t::iterator p = partToEndVtx.begin();
93 p != endItr;
94 ++p ) {
95 auto decayVtx = HepMC::barcode_to_vertex(transObj, p->second );
96 if ( decayVtx ) {
97 decayVtx->add_particle_in( p->first );
98 } else {
99 msg << MSG::ERROR
100 << "GenParticle points to null end vertex !!"
101 << endmsg;
102 }
103 }
104
105 msg << MSG::DEBUG << "Loaded HepMC::GenEvent from persistent state [OK]"
106 << endmsg;
107}
108
110 GenEvent_p1*,
111 MsgStream& msg )
112{
113 msg << MSG::DEBUG << "Creating persistent state of HepMC::GenEvent..."
114 << endmsg;
115
116 msg << MSG::ERROR
117 << "This transient-to-persistent converter method has been RETIRED !!"
118 << endmsg
119 << "You are not supposed to end-up here ! Go away !"
120 << endmsg;
121
122 throw std::runtime_error( "Retired GenEventCnv_p1::transToPers() !!" );
123}
124
126// Protected methods:
128
131 const GenVertex_p1& persVtx,
132 ParticlesMap_t& partToEndVtx,
133 HepMC::DataPool& datapools, HepMC::GenEvent* parent)
134{
135 HepMC::GenVertexPtr vtx = datapools.getGenVertex();
136 if (parent) parent->add_vertex(vtx);
137 vtx->set_position( HepMC::FourVector(persVtx.m_x,persVtx.m_y,persVtx.m_z,persVtx.m_t) );
138 vtx->add_attribute(HepMCStr::weights,std::make_shared<HepMC3::VectorDoubleAttribute>(persVtx.m_weights));
140
141 // handle the in-going (orphans) particles
142 const unsigned int nPartsIn = persVtx.m_particlesIn.size();
143 for ( unsigned int i = 0; i != nPartsIn; ++i ) {
144 createGenParticle( persEvt.m_particles[persVtx.m_particlesIn[i]], partToEndVtx, datapools);
145 }
146 // now handle the out-going particles
147 const unsigned int nPartsOut = persVtx.m_particlesOut.size();
148 for ( unsigned int i = 0; i != nPartsOut; ++i ) {
149 createGenParticle( persEvt.m_particles[persVtx.m_particlesOut[i]], partToEndVtx,datapools, vtx);
150 }
151
152 return vtx;
153}
154
157 ParticlesMap_t& partToEndVtx,
158 HepMC::DataPool& datapools, const HepMC::GenVertexPtr& parent)
159{
161 if (parent) parent->add_particle_out(p);
162 p->set_momentum( HepMC::FourVector(persPart.m_px,persPart.m_py,persPart.m_pz,persPart.m_ene));
163 p->set_pdg_id(persPart.m_pdgId);
164 p->set_status(persPart.m_status);
165 p->add_attribute(HepMCStr::phi,std::make_shared<HepMC3::DoubleAttribute>(persPart.m_phiPolarization));
166 p->add_attribute(HepMCStr::theta,std::make_shared<HepMC3::DoubleAttribute>(persPart.m_thetaPolarization));
168 // fillin' the flow
169 std::vector<int> flows;
170 const unsigned int nFlow = persPart.m_flow.size();
171 for ( unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
172 flows.push_back(persPart.m_flow[iFlow].second );
173 }
174 //We construct it here as vector w/o gaps.
175 p->add_attribute(HepMCStr::flows, std::make_shared<HepMC3::VectorIntAttribute>(flows));
176
177 if ( persPart.m_endVtx != 0 ) {
178 partToEndVtx[p] = persPart.m_endVtx;
179 }
180
181 return p;
182}
183
#define endmsg
virtual void transToPers(const HepMC::GenEvent *transObj, GenEvent_p1 *persObj, MsgStream &msg)
Method creating the persistent representation GenEvent_p1 from its transient representation HepMC::Ge...
HepMC::DataPool * m_pool
a PIMPL idiom to hide the DataPools (and their specialized destructors) from the outside world
static HepMC::GenParticlePtr createGenParticle(const GenParticle_p1 &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.
static HepMC::GenVertexPtr createGenVertex(const GenEvent_p1 &persEvt, const GenVertex_p1 &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.
virtual void persToTrans(const GenEvent_p1 *persObj, HepMC::GenEvent *transObj, MsgStream &msg)
Destructor:
void setDataPool(HepMC::DataPool *pool)
reset the @ HepMC::DataPool pointer
std::unordered_map< HepMC::GenParticlePtr, int > ParticlesMap_t
GenEventCnv_p1(HepMC::DataPool *pool=0)
constructor:
int m_eventNbr
Event number.
Definition GenEvent_p1.h:55
double m_alphaQCD
value of the QCD coupling.
Definition GenEvent_p1.h:63
std::vector< long int > m_randomStates
Container of random numbers for the generator states.
Definition GenEvent_p1.h:82
std::vector< GenVertex_p1 > m_vertices
Vector of vertices composing this event.
Definition GenEvent_p1.h:87
double m_eventScale
Energy scale.
Definition GenEvent_p1.h:59
double m_alphaQED
value of the QED coupling.
Definition GenEvent_p1.h:67
int m_signalProcessId
Id of the processus being generated.
Definition GenEvent_p1.h:51
std::vector< GenParticle_p1 > m_particles
Vector of particles composing this event.
Definition GenEvent_p1.h:92
int m_signalProcessVtx
Barcode of the GenVertex holding the signal process.
Definition GenEvent_p1.h:73
std::vector< double > m_weights
Weights for this event.
Definition GenEvent_p1.h:78
double m_phiPolarization
phi polarization
double m_px
x-component of the 4-momentum of this particle
int m_pdgId
identity of this particle, according to the Particle Data Group notation
double m_thetaPolarization
polarization
double m_py
y-component of the 4-momentum of this particle
int m_barcode
barcode of this particles (uniquely identifying this particle within a given GenEvent)
int m_status
Status of this particle.
int m_endVtx
Barcode of the decay vertex of this particle.
double m_pz
z-component of the 4-momentum of this particle
double m_ene
e-component of the 4-momentum of this particle
std::vector< std::pair< int, int > > m_flow
Flow for this particle.
std::vector< int > m_particlesOut
collection of barcodes of out-going particles connected to this vertex
double m_t
t-coordinate of the vertex
std::vector< int > m_particlesIn
collection of barcodes of in-going particles connected to this vertex
std::vector< double > m_weights
Weights for this vertex.
int m_barcode
barcode of this vertex (uniquely identifying a vertex within an event)
double m_x
x-coordinate of the vertex
double m_z
z-coordinate of the vertex
double m_y
y-coordinate of the vertex
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
A namespace for all vertexing packages and related stuff.
Framework include files.
Definition libname.h:15
HepMC::GenParticlePtr getGenParticle()
HepMC::GenVertexPtr getGenVertex()
MsgStream & msg
Definition testRead.cxx:32