22#include "GaudiKernel/ThreadLocalContext.h"
44 Base_t::operator=( rhs );
62 const EventContext& ctx = Gaudi::Hive::currentContext();
64 msg << MSG::DEBUG <<
"Loading McEventCollection from persistent state..."
73 datapools.
vtx.prepareToAdd(nVertices);
75 datapools.
part.prepareToAdd(nParts);
76 const unsigned int nEvts = persObj->
m_genEvents.size();
77 datapools.
evt.prepareToAdd(nEvts);
79 for ( std::vector<GenEvent_p5>::const_iterator
91 genEvt->add_attribute (
HepMCStr::barcodes, std::make_shared<HepMC::GenEventBarcodes>());
94 genEvt->add_attribute(
HepMCStr::mpi, std::make_shared<HepMC3::IntAttribute>(persEvt.
m_mpi));
101 genEvt->set_units(
static_cast<HepMC3::Units::MomentumUnit
>(persEvt.
m_momentumUnit),
102 static_cast<HepMC3::Units::LengthUnit
>(persEvt.
m_lengthUnit));
105 if(!genEvt->run_info()) genEvt->set_run_info(std::make_shared<HepMC3::GenRunInfo>());
110 auto cs = std::make_shared<HepMC3::GenCrossSection>();
112 genEvt->set_cross_section(cs);
113 if(
static_cast<bool>(xsection[0]) )
114 cs->set_cross_section(xsection[2],xsection[1]);
116 cs->set_cross_section(-1.0, -1.0);
121 auto hi = std::make_shared<HepMC3::GenHeavyIon>();
122 const std::vector<float>& hIon = persEvt.
m_heavyIon;
125 static_cast<int>(hIon[12]),
126 static_cast<int>(hIon[11]),
127 static_cast<int>(hIon[10]),
128 static_cast<int>(hIon[9]),
129 static_cast<int>(hIon[8]),
130 static_cast<int>(hIon[7]),
131 static_cast<int>(hIon[6]),
132 static_cast<int>(hIon[5]),
133 static_cast<int>(hIon[4]),
138 genEvt->set_heavy_ion(std::move(hi));
146 const std::vector<double>& pdf = persEvt.
m_pdfinfo;
147 HepMC3::GenPdfInfoPtr
pi = std::make_shared<HepMC3::GenPdfInfo>();
148 pi->set(
static_cast<int>(pdf[8]),
149 static_cast<int>(pdf[7]),
155 static_cast<int>(pdf[6]),
156 static_cast<int>(pdf[5]));
157 genEvt->set_pdf_info(std::move(
pi));
167 std::map<int, HepMC::GenVertexPtr> brc_to_vertex;
171 for (
unsigned int iVtx = persEvt.
m_verticesBegin; iVtx != endVtx; ++iVtx ) {
173 brc_to_vertex[persObj->
m_genVertices[iVtx].m_barcode] = std::move(vtx);
178 if ( sigProcVtx != 0 && brc_to_vertex.count(sigProcVtx) ) {
183 for (
auto & p : partToEndVtx) {
184 if ( brc_to_vertex.count(p.second) ) {
185 auto decayVtx = brc_to_vertex[p.second];
186 decayVtx->add_particle_in( p.first );
188 msg << MSG::ERROR <<
"GenParticle points to null end vertex !!" <<
endmsg;
194 if ( beamPart1 != 0 && beamPart2 != 0 ) {
202 msg << MSG::DEBUG <<
"Loaded McEventCollection from persistent state [OK]"
210 const EventContext& ctx = Gaudi::Hive::currentContext();
212 msg << MSG::DEBUG <<
"Creating persistent state of McEventCollection..."
216 const std::pair<unsigned int,unsigned int> stats = nbrParticlesAndVertices( transObj );
228 if (genEvt->run_info()) {
229 if (!genEvt->run_info()->weight_names().empty()) {
230 m_hepMCWeightSvc->setWeightNames( names_to_name_index_map(genEvt->weight_names()), ctx ).ignore();
238 auto A_mpi=genEvt->attribute<HepMC3::IntAttribute>(
HepMCStr::mpi);
245 auto beams=genEvt->beams();
247 emplace_back(A_signal_process_id?(A_signal_process_id->value()):-1,
248 genEvt->event_number(),
249 A_mpi?(A_mpi->value()):-1,
250 A_event_scale?(A_event_scale->value()):0.0,
251 A_alphaQCD?(A_alphaQCD->value()):0.0,
252 A_alphaQED?(A_alphaQED->value()):0.0,
257 A_random_states?(A_random_states->value()):std::vector<long>(),
258 std::vector<double>(),
259 std::vector<float>(),
260 std::vector<double>(),
261 genEvt->momentum_unit(),
262 genEvt->length_unit(),
264 nPersVtx + genEvt->vertices().size(),
266 nPersParts + genEvt->particles().size() );
270 if (genEvt->cross_section()) {
271 auto cs=genEvt->cross_section();
274 crossSection.resize(3);
275 crossSection[2] = cs->xsec();
276 crossSection[1] = cs->xsec_err();
277 crossSection[0] =
static_cast<double>(cs->is_valid());
280 if (crossSection[2] < 0) {
281 crossSection[2] = 0.0;
282 if (crossSection[1] < 0) {
283 crossSection[1] = 0.0;
285 crossSection[0] = 0.0;
291 if (genEvt->heavy_ion()) {
292 auto hi=genEvt->heavy_ion();
294 std::vector<float>& heavyIon = persEvt.
m_heavyIon;
296 heavyIon[12] =
static_cast<float>(hi->Ncoll_hard);
297 heavyIon[11] =
static_cast<float>(hi->Npart_proj);
298 heavyIon[10] =
static_cast<float>(hi->Npart_targ);
299 heavyIon[9] =
static_cast<float>(hi->Ncoll);
300 heavyIon[8] =
static_cast<float>(hi->spectator_neutrons);
301 heavyIon[7] =
static_cast<float>(hi->spectator_protons);
302 heavyIon[6] =
static_cast<float>(hi->N_Nwounded_collisions);
303 heavyIon[5] =
static_cast<float>(hi->Nwounded_N_collisions);
304 heavyIon[4] =
static_cast<float>(hi->Nwounded_Nwounded_collisions);
305 heavyIon[3] = hi->impact_parameter;
306 heavyIon[2] = hi->event_plane_angle;
307 heavyIon[1] = hi->eccentricity;
308 heavyIon[0] = hi->sigma_inel_NN;
312 if (genEvt->pdf_info()) {
313 auto pi=genEvt->pdf_info();
315 std::vector<double>& pdfinfo = persEvt.
m_pdfinfo;
317 pdfinfo[8] =
static_cast<double>(
pi->parton_id[0]);
318 pdfinfo[7] =
static_cast<double>(
pi->parton_id[1]);
319 pdfinfo[6] =
static_cast<double>(
pi->pdf_id[0]);
320 pdfinfo[5] =
static_cast<double>(
pi->pdf_id[1]);
321 pdfinfo[4] =
pi->x[0];
322 pdfinfo[3] =
pi->x[1];
323 pdfinfo[2] =
pi->scale;
324 pdfinfo[1] =
pi->xf[0];
325 pdfinfo[0] =
pi->xf[1];
329 for (
const auto& v: genEvt->vertices()) {
335 msg << MSG::DEBUG <<
"Created persistent state of HepMC::GenEvent [OK]" <<
endmsg;
352 if (parent ) parent->add_vertex(vtx);
355 int persVtxStatus(persVtx.
m_id);
364 persVtxStatus = 1000;
373 for (
unsigned int i = 0; i != nPartsIn; ++i ) {
379 for (
unsigned int i = 0; i != nPartsOut; ++i ) {
396 if (parent) add_to_output?parent->add_particle_out(p):parent->add_particle_in(p);
397 p->set_pdg_id( persPart.
m_pdgId);
410 double temp_e = std::sqrt( (
long double)(persPart.
m_px)*persPart.
m_px +
411 (
long double)(persPart.
m_py)*persPart.
m_py +
412 (
long double)(persPart.
m_pz)*persPart.
m_pz +
413 (
long double)(persPart.
m_m) *persPart.
m_m );
416 const int signM2 = ( persPart.
m_m >= 0. ? 1 : -1 );
417 const double persPart_ene =
418 std::sqrt( std::abs((
long double)(persPart.
m_px)*persPart.
m_px +
419 (
long double)(persPart.
m_py)*persPart.
m_py +
420 (
long double)(persPart.
m_pz)*persPart.
m_pz +
421 signM2* (
long double)(persPart.
m_m)* persPart.
m_m));
422 const int signEne = ( persPart.
m_recoMethod == 1 ? 1 : -1 );
426 signEne * persPart_ene ));
430 std::vector<int> flows;
431 const unsigned int nFlow = persPart.
m_flow.size();
432 for (
unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
433 flows.push_back(persPart.
m_flow[iFlow].second );
436 p->add_attribute(
HepMCStr::flows, std::make_shared<HepMC3::VectorIntAttribute>(flows));
439 partToEndVtx[p] = persPart.
m_endVtx;
453 auto weights_d = A_weights->value();
454 for (
auto& w: weights_d)
weights.push_back(w);
463 A_barcode?(A_barcode->value()):vtx->id() );
468 for (
const auto& p: vtx->particles_in()) {
469 if ( !p->production_vertex() || p->production_vertex()->id() == 0 ) {
475 for (
const auto& p: vtx->particles_out()) {
485 const double ene = mom.e();
486 const double m2 = mom.m2();
489 const bool useP2M2 = !(m2 > 0) &&
491 !(std::abs(m2) < 2.0*DBL_EPSILON*ene*ene);
492 auto A_flows=p->attribute<HepMC3::VectorIntAttribute>(
HepMCStr::flows);
493 auto A_phi=p->attribute<HepMC3::DoubleAttribute>(
HepMCStr::phi);
496 const short recoMethod = ( !useP2M2 ? 0: ( ene >= 0.? 1: 2 ) );
498 emplace_back( mom.px(),
504 A_flows?(A_flows->value().size()):0,
505 A_theta?(A_theta->value()):0.0,
506 A_phi?(A_phi->value()):0.0,
513 std::vector< std::pair<int,int> > flow_hepmc2;
514 if(A_flows) flow_hepmc2=vector_to_vector_int_int(A_flows->value());
515 persEvt.
m_genParticles.back().m_flow.assign( flow_hepmc2.begin(),flow_hepmc2.end() );
DataModel_detail::const_iterator< DataVector > const_iterator
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.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
void clear()
Erase all the elements in the collection.
int m_lengthUnit
HepMC::Units::LengthUnit casted to int.
int m_eventNbr
Event number.
std::vector< double > m_weights
Weights for this event.
int m_signalProcessId
Id of the processus being generated.
unsigned int m_particlesBegin
Begin position in the vector of particles composing this event.
double m_alphaQED
value of the QED coupling.
int m_beamParticle1
Barcode of the beam particle 1.
double m_alphaQCD
value of the QCD coupling.
int m_momentumUnit
HepMC::Units::MomentumUnit casted to int.
unsigned int m_verticesEnd
End position in the vector of vertices composing this event.
unsigned int m_verticesBegin
Begin position in the vector of vertices composing this event.
double m_eventScale
Energy scale.
std::vector< float > m_heavyIon
Container of HepMC::HeavyIon object translated to vector<double>.
std::vector< double > m_crossSection
Container of HepMC::GenCrossSection object translated to vector<double>.
int m_mpi
Number of multi particle interactions.
unsigned int m_particlesEnd
End position in the vector of particles composing this event.
std::vector< long int > m_randomStates
Container of random numbers for the generator states.
int m_beamParticle2
Barcode of the beam particle 2.
int m_signalProcessVtx
Barcode of the GenVertex holding the signal process.
std::vector< double > m_pdfinfo
Container of HepMC::PdfInfo object translated to vector<double> for simplicity.
std::vector< std::pair< int, int > > m_flow
Flow for this particle.
float m_thetaPolarization
polarization
float m_py
y-component of the 4-momentum of this particle
float m_px
x-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.
float m_pz
z-component of the 4-momentum of this particle
int m_endVtx
Barcode of the decay vertex of this particle.
float m_phiPolarization
phi polarization
int m_pdgId
identity of this particle, according to the Particle Data Group notation
short m_recoMethod
switch to know which method to chose to better recover the original HepLorentzVector.
float m_m
m-component of the 4-momentum of this particle
float m_generated_mass
mass of this particle when it was generated
std::vector< float > m_weights
Weights for this vertex.
std::vector< int > m_particlesIn
collection of barcodes of in-going particles connected to this vertex
std::vector< int > m_particlesOut
collection of barcodes of out-going particles connected to this vertex
float m_y
y-coordinate of the vertex
float m_t
t-coordinate of the vertex
int m_id
Id of this vertex.
int m_barcode
barcode of this vertex (uniquely identifying a vertex within an event)
float m_z
z-coordinate of the vertex
float m_x
x-coordinate of the vertex
McEventCollectionCnv_p5 & operator=(const McEventCollectionCnv_p5 &rhs)
Assignement operator.
virtual void transToPers(const McEventCollection *transObj, McEventCollection_p5 *persObj, MsgStream &log)
Method creating the persistent representation McEventCollection_p5 from its transient representation ...
T_AthenaPoolTPCnvBase< McEventCollection, McEventCollection_p5 > Base_t
virtual ~McEventCollectionCnv_p5()
Destructor.
static int writeGenParticle(const HepMC::ConstGenParticlePtr &p, McEventCollection_p5 &persEvt)
Method to write a persistent GenParticle object It returns the index of the persistent GenParticle in...
McEventCollectionCnv_p5()
Default constructor:
HepMC::GenParticlePtr createGenParticle(const GenParticle_p5 &p, ParticlesMap_t &partToEndVtx, HepMC::DataPool &datapools, const HepMC::GenVertexPtr &parent=nullptr, bool add_to_output=true) const
Create a transient GenParticle from a persistent one (vers.1) It returns the new GenParticle.
std::unordered_map< HepMC::GenParticlePtr, int > ParticlesMap_t
virtual void persToTrans(const McEventCollection_p5 *persObj, McEventCollection *transObj, MsgStream &log)
Method creating the transient representation of McEventCollection from its persistent representation ...
static void writeGenVertex(const HepMC::ConstGenVertexPtr &vtx, McEventCollection_p5 &persEvt)
Method to write a persistent GenVertex object.
ServiceHandle< IHepMCWeightSvc > m_hepMCWeightSvc
HepMC::GenVertexPtr createGenVertex(const McEventCollection_p5 &persEvts, const GenVertex_p5 &vtx, ParticlesMap_t &bcToPart, HepMC::DataPool &datapools, HepMC::GenEvent *parent=nullptr) const
Create a transient GenVertex from a persistent one (version 1) It returns the new GenVertex.
std::vector< GenEvent_p5 > m_genEvents
The vector of persistent representation of GenEvents.
std::vector< GenVertex_p5 > m_genVertices
The vector of persistent representation of GenVertices.
std::vector< GenParticle_p5 > m_genParticles
The vector of persistent representation of GenParticles.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
const std::string event_scale
const std::string barcode
const std::string weights
const std::string signal_process_id
const std::string random_states
const std::string alphaQED
const std::string alphaQCD
const std::string barcodes
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (only to be used in legacy TP convert...
HepMC3::FourVector FourVector
ConstGenParticlePtr barcode_to_particle(const GenEvent *e, int id)
void set_signal_process_vertex(GenEvent *e, T &v)
ConstGenVertexPtr signal_process_vertex(const GenEvent *e)
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
bool suggest_barcode(T &p, int i)
int new_vertex_status_from_old(const int oldStatus, const int barcode)
Get vertex status in the new scheme from the barcode and status in the old scheme.
int old_vertex_status_from_new(const int newStatus)
Get vertex status in the old scheme from the status in the new scheme.
HepMC3::GenParticlePtr GenParticlePtr
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
HepMC3::GenVertexPtr GenVertexPtr
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
int new_particle_status_from_old(const int oldStatus, const int barcode)
Get particle status in the new scheme from the barcode and status in the old scheme.
int old_particle_status_from_new(const int newStatus)
Get particle status in the old scheme from the status in the new scheme.
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
HepMC3::GenEvent GenEvent
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
::DataPool< HepMC::GenEvent, ClearGenEvent > evt
::DataPool< HepMC::GenParticle, ClearGenParticle > part
HepMC::GenParticlePtr getGenParticle()
HepMC::GenEvent * getGenEvent()
HepMC::GenVertexPtr getGenVertex()
::DataPool< HepMC::GenVertex, ClearGenVertex > vtx