24#include "GaudiKernel/ThreadLocalContext.h"
36 "GenCrossSection",
"GenPdfInfo",
"GenHeavyIon"};
56 Base_t::operator=( rhs );
74 const EventContext& ctx = Gaudi::Hive::currentContext();
76 msg << MSG::DEBUG <<
"Loading McEventCollection from persistent state..."
85 datapools.
vtx.prepareToAdd(nVertices);
87 datapools.
part.prepareToAdd(nParts);
88 const unsigned int nEvts = persObj->
m_genEvents.size();
89 datapools.
evt.prepareToAdd(nEvts);
92 for ( std::vector<GenEvent_p6>::const_iterator
104 genEvt->add_attribute (
HepMCStr::barcodes, std::make_shared<HepMC::GenEventBarcodes>());
113 genEvt->add_attribute(
HepMCStr::mpi, std::make_shared<HepMC3::IntAttribute>(persEvt.
m_mpi));
123 genEvt->set_units(
static_cast<HepMC3::Units::MomentumUnit
>(persEvt.
m_momentumUnit),
124 static_cast<HepMC3::Units::LengthUnit
>(persEvt.
m_lengthUnit));
127 if(!genEvt->run_info()) {
128 HepMC3::GenRunInfoData ri_read;
130 ri_read.tool_name = std::vector<std::string>();
131 ri_read.tool_version = std::vector<std::string>();
132 ri_read.tool_description = std::vector<std::string>();
135 auto ri = std::make_shared<HepMC3::GenRunInfo>();
136 ri->read_data(ri_read);
137 genEvt->set_run_info(std::move(ri));
142 auto cs = std::make_shared<HepMC3::GenCrossSection>();
144 genEvt->set_cross_section(cs);
145 if(
static_cast<bool>(xsection[0]) )
146 cs->set_cross_section(xsection[2],xsection[1]);
148 cs->set_cross_section(-1.0, -1.0);
153 auto hi = std::make_shared<HepMC3::GenHeavyIon>();
154 const std::vector<float>& hIon = persEvt.
m_heavyIon;
157 static_cast<int>(hIon[12]),
158 static_cast<int>(hIon[11]),
159 static_cast<int>(hIon[10]),
160 static_cast<int>(hIon[9]),
161 static_cast<int>(hIon[8]),
162 static_cast<int>(hIon[7]),
163 static_cast<int>(hIon[6]),
164 static_cast<int>(hIon[5]),
165 static_cast<int>(hIon[4]),
170 genEvt->set_heavy_ion(std::move(hi));
178 const std::vector<double>& pdf = persEvt.
m_pdfinfo;
179 HepMC3::GenPdfInfoPtr
pi = std::make_shared<HepMC3::GenPdfInfo>();
180 pi->set(
static_cast<int>(pdf[8]),
181 static_cast<int>(pdf[7]),
187 static_cast<int>(pdf[6]),
188 static_cast<int>(pdf[5]));
189 genEvt->set_pdf_info(std::move(
pi));
199 std::map<int, HepMC::GenVertexPtr> brc_to_vertex;
203 for (
unsigned int iVtx = persEvt.
m_verticesBegin; iVtx != endVtx; ++iVtx ) {
205 brc_to_vertex[persObj->
m_genVertices[iVtx].m_barcode] = std::move(vtx);
210 if ( sigProcVtx != 0 && brc_to_vertex.count(sigProcVtx) ) {
215 for (
auto & p : partToEndVtx) {
216 if ( brc_to_vertex.count(p.second) ) {
217 auto decayVtx = brc_to_vertex[p.second];
218 decayVtx->add_particle_in( p.first );
220 msg << MSG::ERROR <<
"GenParticle points to null end vertex !!" <<
endmsg;
226 if ( beamPart1 != 0 && beamPart2 != 0 ) {
235 msg << MSG::DEBUG <<
"Loaded McEventCollection from persistent state [OK]"
243 const EventContext& ctx = Gaudi::Hive::currentContext();
245 msg << MSG::DEBUG <<
"Creating persistent state of McEventCollection..."
249 const std::pair<unsigned int,unsigned int> stats = nbrParticlesAndVertices( transObj );
261 auto ri = genEvt->run_info();
262 HepMC3::GenRunInfoData ri_data;
264 ri->write_data(ri_data);
265 if (!ri_data.weight_names.empty()) {
266 m_hepMCWeightSvc->setWeightNames( names_to_name_index_map(ri_data.weight_names), ctx ).ignore();
274 auto A_mpi=genEvt->attribute<HepMC3::IntAttribute>(
HepMCStr::mpi);
285 if (!signal_process_vertex) {
289 if (event_spv) signal_process_vertex = genEvt->vertices().at(-event_spv->value()-1);
293 auto beams=genEvt->beams();
295 emplace_back(A_signal_process_id?(A_signal_process_id->value()):-1,
296 genEvt->event_number(),
297 A_mpi?(A_mpi->value()):-1,
298 A_event_scale?(A_event_scale->value()):0.0,
299 A_alphaQCD?(A_alphaQCD->value()):0.0,
300 A_alphaQED?(A_alphaQED->value()):0.0,
301 A_filterWeight?(A_filterWeight->value()):1.0,
302 A_filterHT?(A_filterHT->value()):-13.,
303 A_filterMET?(A_filterMET->value()):-13.0,
308 A_random_states?(A_random_states->value()):std::vector<long>(),
309 std::vector<double>(),
310 std::vector<float>(),
311 std::vector<double>(),
312 genEvt->momentum_unit(),
313 genEvt->length_unit(),
315 nPersVtx + genEvt->vertices().size(),
317 nPersParts + genEvt->particles().size() );
320 std::map< std::string, std::map<int, std::shared_ptr<HepMC3::Attribute> > > e_atts = genEvt->attributes();
324 for (
auto& attmap: e_atts) {
328 for (
auto& att: attmap.second) {
332 att.second->to_string(st);
352 if (genEvt->cross_section()) {
353 auto cs=genEvt->cross_section();
356 crossSection.resize(3);
357 crossSection[2] = cs->xsec();
358 crossSection[1] = cs->xsec_err();
359 crossSection[0] =
static_cast<double>(cs->is_valid());
362 if (crossSection[2] < 0) {
363 crossSection[2] = 0.0;
364 if (crossSection[1] < 0) {
365 crossSection[1] = 0.0;
367 crossSection[0] = 0.0;
373 if (genEvt->heavy_ion()) {
374 auto hi=genEvt->heavy_ion();
376 std::vector<float>& heavyIon = persEvt.
m_heavyIon;
378 heavyIon[12] =
static_cast<float>(hi->Ncoll_hard);
379 heavyIon[11] =
static_cast<float>(hi->Npart_proj);
380 heavyIon[10] =
static_cast<float>(hi->Npart_targ);
381 heavyIon[9] =
static_cast<float>(hi->Ncoll);
382 heavyIon[8] =
static_cast<float>(hi->spectator_neutrons);
383 heavyIon[7] =
static_cast<float>(hi->spectator_protons);
384 heavyIon[6] =
static_cast<float>(hi->N_Nwounded_collisions);
385 heavyIon[5] =
static_cast<float>(hi->Nwounded_N_collisions);
386 heavyIon[4] =
static_cast<float>(hi->Nwounded_Nwounded_collisions);
387 heavyIon[3] = hi->impact_parameter;
388 heavyIon[2] = hi->event_plane_angle;
389 heavyIon[1] = hi->eccentricity;
390 heavyIon[0] = hi->sigma_inel_NN;
394 if (genEvt->pdf_info()) {
395 auto pi=genEvt->pdf_info();
397 std::vector<double>& pdfinfo = persEvt.
m_pdfinfo;
399 pdfinfo[8] =
static_cast<double>(
pi->parton_id[0]);
400 pdfinfo[7] =
static_cast<double>(
pi->parton_id[1]);
401 pdfinfo[6] =
static_cast<double>(
pi->pdf_id[0]);
402 pdfinfo[5] =
static_cast<double>(
pi->pdf_id[1]);
403 pdfinfo[4] =
pi->x[0];
404 pdfinfo[3] =
pi->x[1];
405 pdfinfo[2] =
pi->scale;
406 pdfinfo[1] =
pi->xf[0];
407 pdfinfo[0] =
pi->xf[1];
411 for (
const auto& v: genEvt->vertices()) {
417 msg << MSG::DEBUG <<
"Created persistent state of HepMC::GenEvent [OK]" <<
endmsg;
434 if (parent ) parent->add_vertex(vtx);
444 for (
unsigned int i = 0; i != nPartsIn; ++i ) {
450 for (
unsigned int i = 0; i != nPartsOut; ++i ) {
466 if (parent) add_to_output?parent->add_particle_out(p):parent->add_particle_in(p);
467 p->set_pdg_id( persPart.
m_pdgId);
480 double temp_e = std::sqrt( (
long double)(persPart.
m_px)*persPart.
m_px +
481 (
long double)(persPart.
m_py)*persPart.
m_py +
482 (
long double)(persPart.
m_pz)*persPart.
m_pz +
483 (
long double)(persPart.
m_m) *persPart.
m_m );
486 const int signM2 = ( persPart.
m_m >= 0. ? 1 : -1 );
487 const double persPart_ene =
488 std::sqrt( std::abs((
long double)(persPart.
m_px)*persPart.
m_px +
489 (
long double)(persPart.
m_py)*persPart.
m_py +
490 (
long double)(persPart.
m_pz)*persPart.
m_pz +
491 signM2* (
long double)(persPart.
m_m)* persPart.
m_m));
492 const int signEne = ( persPart.
m_recoMethod == 1 ? 1 : -1 );
496 signEne * persPart_ene ));
500 std::vector<int> flows;
501 const unsigned int nFlow = persPart.
m_flow.size();
502 for (
unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
503 flows.push_back(persPart.
m_flow[iFlow].second );
506 p->add_attribute(
HepMCStr::flows, std::make_shared<HepMC3::VectorIntAttribute>(flows));
509 partToEndVtx[p] = persPart.
m_endVtx;
523 auto weights_d = A_weights->value();
524 for (
auto& w: weights_d)
weights.push_back(w);
533 A_barcode?(A_barcode->value()):vtx->id() );
538 for (
const auto& p: vtx->particles_in()) {
539 if ( !p->production_vertex() || p->production_vertex()->id() == 0 ) {
545 for (
const auto& p: vtx->particles_out()) {
554 const double ene = mom.e();
555 const double m2 = mom.m2();
558 const bool useP2M2 = !(m2 > 0) &&
560 !(std::abs(m2) < 2.0*DBL_EPSILON*ene*ene);
561 auto A_flows=p->attribute<HepMC3::VectorIntAttribute>(
HepMCStr::flows);
562 auto A_phi=p->attribute<HepMC3::DoubleAttribute>(
HepMCStr::phi);
565 const short recoMethod = ( !useP2M2 ? 0: ( ene >= 0.? 1: 2 ) );
567 emplace_back( mom.px(),
573 A_flows?(A_flows->value().size()):0,
574 A_theta?(A_theta->value()):0.0,
575 A_phi?(A_phi->value()):0.0,
582 std::vector< std::pair<int,int> > flow_hepmc2;
583 if(A_flows) flow_hepmc2=vector_to_vector_int_int(A_flows->value());
584 persEvt.
m_genParticles.back().m_flow.assign( flow_hepmc2.begin(),flow_hepmc2.end() );
static const std::set< std::string > attributes_to_ignore
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.
double m_alphaQED
value of the QED coupling.
int m_momentumUnit
HepMC::Units::MomentumUnit casted to int.
int m_signalProcessId
Id of the processus being generated.
unsigned int m_particlesBegin
Begin position in the vector of particles composing this event.
std::vector< double > m_crossSection
Container of HepMC::GenCrossSection object translated to vector<double>.
int m_mpi
Number of multi particle interactions.
int m_eventNbr
Event number.
std::vector< long int > m_randomStates
Container of random numbers for the generator states.
std::vector< std::string > m_r_attribute_name
Attribute name for run info.
unsigned int m_verticesEnd
End position in the vector of vertices composing this event.
std::vector< int > m_e_attribute_id
We define those exactly as in the HepMC3::GenEvent.
unsigned int m_verticesBegin
Begin position in the vector of vertices composing this event.
std::vector< double > m_pdfinfo
Container of HepMC::PdfInfo object translated to vector<double> for simplicity.
std::vector< double > m_weights
Weights for this event.
int m_beamParticle1
Barcode of the beam particle 1.
std::vector< std::string > m_e_attribute_string
Attribute serialized as string for event.
int m_signalProcessVtx
Barcode of the GenVertex holding the signal process.
int m_beamParticle2
Barcode of the beam particle 2.
unsigned int m_particlesEnd
End position in the vector of particles composing this event.
double m_eventScale
Energy scale.
double m_alphaQCD
value of the QCD coupling.
int m_lengthUnit
HepMC::Units::LengthUnit casted to int.
std::vector< std::string > m_r_attribute_string
Attribute serialized as string for run info.
double m_filterWeight
value of the extra weight introduced during reweighting events in filter and value of some variables ...
std::vector< std::string > m_e_attribute_name
Attribute name for event.
std::vector< float > m_heavyIon
Container of HepMC::HeavyIon object translated to vector<double>.
float m_py
y-component of the 4-momentum of this particle
float m_m
m-component of the 4-momentum of this particle
int m_barcode
barcode of this particles (uniquely identifying this particle within a given GenEvent)
std::vector< std::pair< int, int > > m_flow
Flow for this particle.
int m_status
Status of this particle.
int m_endVtx
Barcode of the decay vertex of this particle.
short m_recoMethod
switch to know which method to chose to better recover the original HepLorentzVector.
float m_generated_mass
mass of this particle when it was generated
float m_phiPolarization
phi polarization
float m_pz
z-component of the 4-momentum of this particle
int m_pdgId
identity of this particle, according to the Particle Data Group notation
float m_thetaPolarization
polarization
float m_px
x-component of the 4-momentum of this particle
int m_barcode
barcode of this vertex (uniquely identifying a vertex within an event)
float m_t
t-coordinate of the vertex
std::vector< float > m_weights
Weights for this vertex.
float m_x
x-coordinate of the vertex
std::vector< int > m_particlesIn
collection of barcodes of in-going particles connected to this vertex
int m_id
Id of this vertex.
float m_z
z-coordinate of the vertex
float m_y
y-coordinate of the vertex
std::vector< int > m_particlesOut
collection of barcodes of out-going particles connected to this vertex
McEventCollectionCnv_p6()
Default constructor:
HepMC::GenParticlePtr createGenParticle(const GenParticle_p6 &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.
virtual void persToTrans(const McEventCollection_p6 *persObj, McEventCollection *transObj, MsgStream &log)
Method creating the transient representation of McEventCollection from its persistent representation ...
virtual ~McEventCollectionCnv_p6()
Destructor.
ServiceHandle< IHepMCWeightSvc > m_hepMCWeightSvc
static int writeGenParticle(const HepMC::ConstGenParticlePtr &p, McEventCollection_p6 &persEvt)
Method to write a persistent GenParticle object It returns the index of the persistent GenParticle in...
HepMC::GenVertexPtr createGenVertex(const McEventCollection_p6 &persEvts, const GenVertex_p6 &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.
McEventCollectionCnv_p6 & operator=(const McEventCollectionCnv_p6 &rhs)
Assignement operator.
std::unordered_map< HepMC::GenParticlePtr, int > ParticlesMap_t
static void writeGenVertex(const HepMC::ConstGenVertexPtr &vtx, McEventCollection_p6 &persEvt)
Method to write a persistent GenVertex object.
T_AthenaPoolTPCnvBase< McEventCollection, McEventCollection_p6 > Base_t
virtual void transToPers(const McEventCollection *transObj, McEventCollection_p6 *persObj, MsgStream &log)
Method creating the persistent representation McEventCollection_p6 from its transient representation ...
std::vector< GenParticle_p6 > m_genParticles
The vector of persistent representation of GenParticles.
std::vector< GenEvent_p6 > m_genEvents
The vector of persistent representation of GenEvents.
std::vector< GenVertex_p6 > m_genVertices
The vector of persistent representation of GenVertices.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
const std::string filterMET
const std::string event_scale
const std::string barcode
const std::string ShadowParticleId
const std::string signal_process_vertex
const std::string filterHT
const std::string weights
const std::string signal_vertex_id
const std::string signal_process_id
const std::string random_states
const std::string alphaQED
const std::string alphaQCD
const std::string barcodes
const std::string filterWeight
const std::string ShadowParticle
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