ATLAS Offline Software
GenEventCnv_p1.cxx
Go to the documentation of this file.
1 
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 
24  m_pool( pool )
25 {}
26 
28 // Non-const methods:
30 
32 {
33  m_pool = pool;
34 }
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 #ifdef HEPMC3
63  transObj->add_attribute ("barcodes", std::make_shared<HepMC::GenEventBarcodes>());
64  transObj->add_attribute("signal_process_id",std::make_shared<HepMC3::IntAttribute>(persObj->m_signalProcessId ));
65  transObj->set_event_number(persObj->m_eventNbr);
66  transObj->add_attribute("event_scale",std::make_shared<HepMC3::DoubleAttribute>(persObj->m_eventScale));
67  transObj->add_attribute("alphaQCD",std::make_shared<HepMC3::DoubleAttribute>(persObj->m_alphaQCD));
68  transObj->add_attribute("alphaQED",std::make_shared<HepMC3::DoubleAttribute>(persObj->m_alphaQED));
69  transObj->weights()= persObj->m_weights;
70  transObj->add_attribute("random_states",std::make_shared<HepMC3::VectorLongIntAttribute>(persObj->m_randomStates));
71 
72 #else
73  transObj->set_signal_process_id( persObj->m_signalProcessId );
74  transObj->set_event_number( persObj->m_eventNbr );
75  transObj->set_event_scale ( persObj->m_eventScale );
76  transObj->set_alphaQCD ( persObj->m_alphaQCD );
77  transObj->set_alphaQED ( persObj->m_alphaQED );
78 
79  transObj->weights() = persObj->m_weights;
80  transObj->set_random_states( persObj->m_randomStates );
81 
82  // this is b/c, using DataPool(s), we are recycling old instances.
83  // => better have a clean new-old instance :)
84  transObj->m_vertex_barcodes.clear();
85  transObj->m_particle_barcodes.clear();
86 
87  transObj->m_pdf_info = 0; //> not available at that time...
88 
89 #endif
90  // create a temporary map associating the barcode of an end-vtx to its
91  // particle.
92  // As not all particles are stable (d'oh!) we take 50% of the number of
93  // particles as an initial size of the hash-map (to prevent re-hash)
94  ParticlesMap_t partToEndVtx(nParts/2);
95 
96  // create the vertices
97  for ( unsigned int iVtx = 0; iVtx != nVertices; ++iVtx ) {
98  const GenVertex_p1& persVtx = persObj->m_vertices[iVtx];
99  createGenVertex( *persObj, persVtx, partToEndVtx, *m_pool, transObj );
100  } //> end loop over vertices
101 
102  // set the signal process vertex
103  const int sigProcVtx = persObj->m_signalProcessVtx;
104  if ( sigProcVtx != 0 ) {
105  auto Vtx = HepMC::barcode_to_vertex(transObj,sigProcVtx );
107  }
108 
109  // connect particles to their end vertices
110  const ParticlesMap_t::iterator endItr= partToEndVtx.end();
111  for ( ParticlesMap_t::iterator p = partToEndVtx.begin();
112  p != endItr;
113  ++p ) {
114  auto decayVtx = HepMC::barcode_to_vertex(transObj, p->second );
115  if ( decayVtx ) {
116  decayVtx->add_particle_in( p->first );
117  } else {
118  msg << MSG::ERROR
119  << "GenParticle points to null end vertex !!"
120  << endmsg;
121  }
122  }
123 
124  msg << MSG::DEBUG << "Loaded HepMC::GenEvent from persistent state [OK]"
125  << endmsg;
126 }
127 
128 void GenEventCnv_p1::transToPers( const HepMC::GenEvent*,
129  GenEvent_p1*,
130  MsgStream& msg )
131 {
132  msg << MSG::DEBUG << "Creating persistent state of HepMC::GenEvent..."
133  << endmsg;
134 
135  msg << MSG::ERROR
136  << "This transient-to-persistent converter method has been RETIRED !!"
137  << endmsg
138  << "You are not supposed to end-up here ! Go away !"
139  << endmsg;
140 
141  throw std::runtime_error( "Retired GenEventCnv_p1::transToPers() !!" );
142 }
143 
145 // Protected methods:
147 
150  const GenVertex_p1& persVtx,
151  ParticlesMap_t& partToEndVtx,
152  HepMC::DataPool& datapools, HepMC::GenEvent* parent)
153 {
154  HepMC::GenVertexPtr vtx = datapools.getGenVertex();
155  if (parent) parent->add_vertex(vtx);
156 #ifdef HEPMC3
157  vtx->set_position( HepMC::FourVector(persVtx.m_x,persVtx.m_y,persVtx.m_z,persVtx.m_t) );
158  vtx->add_attribute("weights",std::make_shared<HepMC3::VectorDoubleAttribute>(persVtx.m_weights));
159  HepMC::suggest_barcode(vtx,persVtx.m_barcode);
160 
161  // handle the in-going (orphans) particles
162  const unsigned int nPartsIn = persVtx.m_particlesIn.size();
163  for ( unsigned int i = 0; i != nPartsIn; ++i ) {
164  createGenParticle( persEvt.m_particles[persVtx.m_particlesIn[i]], partToEndVtx, datapools);
165  }
166  // now handle the out-going particles
167  const unsigned int nPartsOut = persVtx.m_particlesOut.size();
168  for ( unsigned int i = 0; i != nPartsOut; ++i ) {
169  createGenParticle( persEvt.m_particles[persVtx.m_particlesOut[i]], partToEndVtx,datapools, vtx);
170  }
171 
172 #else
173  vtx->m_position.setX( persVtx.m_x );
174  vtx->m_position.setY( persVtx.m_y );
175  vtx->m_position.setZ( persVtx.m_z );
176  vtx->m_position.setT( persVtx.m_t );
177  vtx->m_particles_in.clear();
178  vtx->m_particles_out.clear();
179  vtx->m_id = persVtx.m_id;
180  vtx->m_weights = persVtx.m_weights;
181  vtx->m_event = 0;
182  vtx->m_barcode = persVtx.m_barcode;
183 
184 
185  // handle the in-going (orphans) particles
186  const unsigned int nPartsIn = persVtx.m_particlesIn.size();
187  for ( unsigned int i = 0; i != nPartsIn; ++i ) {
188  createGenParticle( persEvt.m_particles[persVtx.m_particlesIn[i]],
189  partToEndVtx,
190  datapools);
191  }
192 
193  // now handle the out-going particles
194  const unsigned int nPartsOut = persVtx.m_particlesOut.size();
195  for ( unsigned int i = 0; i != nPartsOut; ++i ) {
196  vtx->add_particle_out( createGenParticle( persEvt.m_particles[persVtx.m_particlesOut[i]],
197  partToEndVtx,
198  datapools) );
199  }
200 #endif
201  return vtx;
202 }
203 
206  ParticlesMap_t& partToEndVtx,
207  HepMC::DataPool& datapools, const HepMC::GenVertexPtr& parent)
208 {
209  HepMC::GenParticlePtr p = datapools.getGenParticle();
210  if (parent) parent->add_particle_out(p);
211 #ifdef HEPMC3
212  p->set_momentum( HepMC::FourVector(persPart.m_px,persPart.m_py,persPart.m_pz,persPart.m_ene));
213  p->set_pdg_id(persPart.m_pdgId);
214  p->set_status(persPart.m_status);
215  p->add_attribute("phi",std::make_shared<HepMC3::DoubleAttribute>(persPart.m_phiPolarization));
216  p->add_attribute("theta",std::make_shared<HepMC3::DoubleAttribute>(persPart.m_thetaPolarization));
218  // fillin' the flow
219  std::vector<int> flows;
220  const unsigned int nFlow = persPart.m_flow.size();
221  for ( unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
222  flows.push_back(persPart.m_flow[iFlow].second );
223  }
224  //We construct it here as vector w/o gaps.
225  p->add_attribute("flows", std::make_shared<HepMC3::VectorIntAttribute>(flows));
226 #else
227 
228 
229  p->m_momentum.setPx( persPart.m_px );
230  p->m_momentum.setPy( persPart.m_py );
231  p->m_momentum.setPz( persPart.m_pz );
232  p->m_momentum.setE ( persPart.m_ene );
233  p->m_pdg_id = persPart.m_pdgId;
234  p->m_status = persPart.m_status;
235  p->m_polarization.m_theta = persPart.m_thetaPolarization;
236  p->m_polarization.m_phi = persPart.m_phiPolarization;
237  p->m_production_vertex = 0;
238  p->m_end_vertex = 0;
239  p->m_barcode = persPart.m_barcode;
240 
241  // fillin' the flow
242  const unsigned int nFlow = persPart.m_flow.size();
243  for ( unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
244  p->m_flow.set_icode( persPart.m_flow[iFlow].first, persPart.m_flow[iFlow].second );
245  }
246 #endif
247 
248  if ( persPart.m_endVtx != 0 ) {
249  partToEndVtx[p] = persPart.m_endVtx;
250  }
251 
252  return p;
253 }
254 
HepMC::GenVertexPtr
HepMC::GenVertex * GenVertexPtr
Definition: GenVertex.h:59
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
HepMC::suggest_barcode
bool suggest_barcode(T &p, int i)
Definition: GenEvent.h:670
GenEventCnv_p1::ParticlesMap_t
std::unordered_map< HepMC::GenParticlePtr, int > ParticlesMap_t
Definition: GenEventCnv_p1.h:89
NSWL1::nVertices
int nVertices(const Polygon &p)
Definition: GeoUtils.cxx:35
Vtx
GenParticle_p1::m_px
double m_px
x-component of the 4-momentum of this particle
Definition: GenParticle_p1.h:65
HepMC::DataPool
Definition: HepMcDataPool.h:81
GenParticle_p1::m_status
int m_status
Status of this particle, as defined for HEPEVT.
Definition: GenParticle_p1.h:85
GenParticle_p1::m_endVtx
int m_endVtx
Barcode of the decay vertex of this particle.
Definition: GenParticle_p1.h:111
HepMC::GenParticlePtr
GenParticle * GenParticlePtr
Definition: GenParticle.h:37
pool
pool namespace
Definition: libname.h:15
GenEvent_p1::m_eventNbr
int m_eventNbr
Event number.
Definition: GenEvent_p1.h:55
HepMcDataPool.h
GenParticle_p1::m_flow
std::vector< std::pair< int, int > > m_flow
Flow for this particle.
Definition: GenParticle_p1.h:89
GenEvent_p1::m_alphaQCD
double m_alphaQCD
value of the QCD coupling.
Definition: GenEvent_p1.h:63
GenEventCnv_p1::createGenParticle
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.
Definition: GenEventCnv_p1.cxx:205
GenParticle_p1::m_thetaPolarization
double m_thetaPolarization
polarization
Definition: GenParticle_p1.h:97
HepMC::DataPool::getGenParticle
HepMC::GenParticlePtr getGenParticle()
Definition: HepMcDataPool.h:160
GenParticle_p1::m_barcode
int m_barcode
barcode of this particles (uniquely identifying this particle within a given GenEvent)
Definition: GenParticle_p1.h:116
GenEventCnv_p1::transToPers
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...
Definition: GenEventCnv_p1.cxx:128
GenEvent_p1::m_signalProcessId
int m_signalProcessId
Id of the processus being generated.
Definition: GenEvent_p1.h:51
GenEvent_p1::m_randomStates
std::vector< long int > m_randomStates
Container of random numbers for the generator states.
Definition: GenEvent_p1.h:82
GenParticle_p1::m_py
double m_py
y-component of the 4-momentum of this particle
Definition: GenParticle_p1.h:69
HepMC::set_signal_process_vertex
void set_signal_process_vertex(GenEvent *e, T v)
Definition: GenEvent.h:650
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
GenEventCnv_p1::GenEventCnv_p1
GenEventCnv_p1(HepMC::DataPool *pool=0)
constructor:
Definition: GenEventCnv_p1.cxx:23
GenVertex_p1::m_particlesOut
std::vector< int > m_particlesOut
collection of barcodes of out-going particles connected to this vertex
Definition: GenVertex_p1.h:74
GenParticle_p1::m_pdgId
int m_pdgId
identity of this particle, according to the Particle Data Group notation
Definition: GenParticle_p1.h:81
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
GenParticle_p1::m_ene
double m_ene
e-component of the 4-momentum of this particle
Definition: GenParticle_p1.h:77
GenParticle_p1::m_pz
double m_pz
z-component of the 4-momentum of this particle
Definition: GenParticle_p1.h:73
GenEventCnv_p1.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
HepMC::DataPool::vtx
GenVtxPool_t vtx
an arena of HepMC::GenVertex for efficient object instantiation
Definition: HepMcDataPool.h:144
GenParticle_p1::m_phiPolarization
double m_phiPolarization
phi polarization
Definition: GenParticle_p1.h:101
GenVertex_p1::m_particlesIn
std::vector< int > m_particlesIn
collection of barcodes of in-going particles connected to this vertex
Definition: GenVertex_p1.h:70
GenEventCnv_p1::m_pool
HepMC::DataPool * m_pool
a PIMPL idiom to hide the DataPools (and their specialized destructors) from the outside world
Definition: GenEventCnv_p1.h:123
GenEvent_p1::m_alphaQED
double m_alphaQED
value of the QED coupling.
Definition: GenEvent_p1.h:67
GenEventCnv_p1::setDataPool
void setDataPool(HepMC::DataPool *pool)
reset the @ HepMC::DataPool pointer
Definition: GenEventCnv_p1.cxx:31
GenVertex_p1::m_barcode
int m_barcode
barcode of this vertex (uniquely identifying a vertex within an event)
Definition: GenVertex_p1.h:86
GenEventCnv_p1::persToTrans
virtual void persToTrans(const GenEvent_p1 *persObj, HepMC::GenEvent *transObj, MsgStream &msg)
Destructor:
Definition: GenEventCnv_p1.cxx:36
GenEvent_p1::m_signalProcessVtx
int m_signalProcessVtx
Barcode of the GenVertex holding the signal process.
Definition: GenEvent_p1.h:73
GenVertex_p1
Definition: GenVertex_p1.h:25
GenEvent_p1::m_vertices
std::vector< GenVertex_p1 > m_vertices
Vector of vertices composing this event.
Definition: GenEvent_p1.h:87
GenEvent_p1::m_eventScale
double m_eventScale
Energy scale.
Definition: GenEvent_p1.h:59
GenEventCnv_p1::createGenVertex
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.
Definition: GenEventCnv_p1.cxx:149
GenVertex_p1::m_y
double m_y
y-coordinate of the vertex
Definition: GenVertex_p1.h:58
GenEvent_p1::m_weights
std::vector< double > m_weights
Weights for this event.
Definition: GenEvent_p1.h:78
DEBUG
#define DEBUG
Definition: page_access.h:11
GenVertex_p1::m_x
double m_x
x-coordinate of the vertex
Definition: GenVertex_p1.h:54
GenParticle_p1
Definition: GenParticle_p1.h:23
HepMC::barcode_to_vertex
GenVertex * barcode_to_vertex(const GenEvent *e, int id)
Definition: GenEvent.h:627
GenVertex_p1::m_id
int m_id
Id of this vertex.
Definition: GenVertex_p1.h:78
GenEvent_p1::m_particles
std::vector< GenParticle_p1 > m_particles
Vector of particles composing this event.
Definition: GenEvent_p1.h:92
GenEvent_p1
Definition: GenEvent_p1.h:27
GenVertex_p1::m_t
double m_t
t-coordinate of the vertex
Definition: GenVertex_p1.h:66
HepMC::DataPool::getGenVertex
HepMC::GenVertexPtr getGenVertex()
Definition: HepMcDataPool.h:155
GenVertex_p1::m_z
double m_z
z-coordinate of the vertex
Definition: GenVertex_p1.h:62
GenVertex_p1::m_weights
std::vector< double > m_weights
Weights for this vertex.
Definition: GenVertex_p1.h:82
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
HepMC::DataPool::part
GenPartPool_t part
an arena of HepMC::GenParticle for efficient object instantiation
Definition: HepMcDataPool.h:148