23#include "GaudiKernel/ThreadLocalContext.h"
35 "GenCrossSection",
"GenPdfInfo",
"GenHeavyIon"};
55 Base_t::operator=( rhs );
73 const EventContext& ctx = Gaudi::Hive::currentContext();
75 msg << MSG::DEBUG <<
"Loading McEventCollection from persistent state..."
84 datapools.
vtx.prepareToAdd(nVertices);
86 datapools.
part.prepareToAdd(nParts);
87 const unsigned int nEvts = persObj->
m_genEvents.size();
88 datapools.
evt.prepareToAdd(nEvts);
91 for ( std::vector<GenEvent_p7>::const_iterator
103 genEvt->add_attribute (
HepMCStr::barcodes, std::make_shared<HepMC::GenEventBarcodes>());
112 genEvt->add_attribute(
HepMCStr::mpi, std::make_shared<HepMC3::IntAttribute>(persEvt.
m_mpi));
122 genEvt->set_units(
static_cast<HepMC3::Units::MomentumUnit
>(persEvt.
m_momentumUnit),
123 static_cast<HepMC3::Units::LengthUnit
>(persEvt.
m_lengthUnit));
126 if(!genEvt->run_info()) {
127 HepMC3::GenRunInfoData ri_read;
134 auto ri = std::make_shared<HepMC3::GenRunInfo>();
135 ri->read_data(ri_read);
136 genEvt->set_run_info(std::move(ri));
141 auto cs = std::make_shared<HepMC3::GenCrossSection>();
143 if(
static_cast<bool>(xsection[0]) )
144 cs->set_cross_section(xsection[2],xsection[1]);
146 cs->set_cross_section(-1.0, -1.0);
147 genEvt->set_cross_section(std::move(cs));
152 auto hi = std::make_shared<HepMC3::GenHeavyIon>();
153 const std::vector<float>& hIon = persEvt.
m_heavyIon;
156 static_cast<int>(hIon[12]),
157 static_cast<int>(hIon[11]),
158 static_cast<int>(hIon[10]),
159 static_cast<int>(hIon[9]),
160 static_cast<int>(hIon[8]),
161 static_cast<int>(hIon[7]),
162 static_cast<int>(hIon[6]),
163 static_cast<int>(hIon[5]),
164 static_cast<int>(hIon[4]),
169 genEvt->set_heavy_ion(std::move(hi));
177 const std::vector<double>& pdf = persEvt.
m_pdfinfo;
178 HepMC3::GenPdfInfoPtr
pi = std::make_shared<HepMC3::GenPdfInfo>();
179 pi->set(
static_cast<int>(pdf[8]),
180 static_cast<int>(pdf[7]),
186 static_cast<int>(pdf[6]),
187 static_cast<int>(pdf[5]));
188 genEvt->set_pdf_info(std::move(
pi));
198 std::map<int, HepMC::GenVertexPtr> brc_to_vertex;
202 for (
unsigned int iVtx = persEvt.
m_verticesBegin; iVtx != endVtx; ++iVtx ) {
204 brc_to_vertex[persObj->
m_genVertices[iVtx].m_barcode] = std::move(vtx);
209 if ( sigProcVtx != 0 && brc_to_vertex.count(sigProcVtx) ) {
214 for (
auto & p : partToEndVtx) {
215 if ( brc_to_vertex.count(p.second) ) {
216 auto decayVtx = brc_to_vertex[p.second];
217 decayVtx->add_particle_in( p.first );
219 msg << MSG::ERROR <<
"GenParticle points to null end vertex !!" <<
endmsg;
225 if ( beamPart1 != 0 && beamPart2 != 0 ) {
233 msg << MSG::DEBUG <<
"Loaded McEventCollection from persistent state [OK]"
241 const EventContext& ctx = Gaudi::Hive::currentContext();
243 msg << MSG::DEBUG <<
"Creating persistent state of McEventCollection..."
247 const std::pair<unsigned int,unsigned int> stats = nbrParticlesAndVertices( transObj );
259 auto ri = genEvt->run_info();
260 HepMC3::GenRunInfoData ri_data;
262 ri->write_data(ri_data);
263 if (!ri_data.weight_names.empty()) {
264 m_hepMCWeightSvc->setWeightNames( names_to_name_index_map(ri_data.weight_names), ctx ).ignore();
272 auto A_mpi=genEvt->attribute<HepMC3::IntAttribute>(
HepMCStr::mpi);
283 if (!signal_process_vertex) {
287 if (event_spv) signal_process_vertex = genEvt->vertices().at(-event_spv->value()-1);
291 auto beams=genEvt->beams();
293 emplace_back(A_signal_process_id?(A_signal_process_id->value()):-1,
294 genEvt->event_number(),
295 A_mpi?(A_mpi->value()):-1,
296 A_event_scale?(A_event_scale->value()):0.0,
297 A_alphaQCD?(A_alphaQCD->value()):0.0,
298 A_alphaQED?(A_alphaQED->value()):0.0,
299 A_filterWeight?(A_filterWeight->value()):1.0,
300 A_filterHT?(A_filterHT->value()):-13.,
301 A_filterMET?(A_filterMET->value()):-13.0,
306 A_random_states?(A_random_states->value()):std::vector<long>(),
307 std::vector<double>(),
308 std::vector<float>(),
309 std::vector<double>(),
310 genEvt->momentum_unit(),
311 genEvt->length_unit(),
313 nPersVtx + genEvt->vertices().size(),
315 nPersParts + genEvt->particles().size() );
318 std::map< std::string, std::map<int, std::shared_ptr<HepMC3::Attribute> > > e_atts = genEvt->attributes();
322 for (
auto& attmap: e_atts) {
326 for (
auto& att: attmap.second) {
330 att.second->to_string(st);
353 if (genEvt->cross_section()) {
354 auto cs=genEvt->cross_section();
357 crossSection.resize(3);
358 crossSection[2] = cs->xsec();
359 crossSection[1] = cs->xsec_err();
360 crossSection[0] =
static_cast<double>(cs->is_valid());
363 if (crossSection[2] < 0) {
364 crossSection[2] = 0.0;
365 if (crossSection[1] < 0) {
366 crossSection[1] = 0.0;
368 crossSection[0] = 0.0;
374 if (genEvt->heavy_ion()) {
375 auto hi=genEvt->heavy_ion();
377 std::vector<float>& heavyIon = persEvt.
m_heavyIon;
379 heavyIon[12] =
static_cast<float>(hi->Ncoll_hard);
380 heavyIon[11] =
static_cast<float>(hi->Npart_proj);
381 heavyIon[10] =
static_cast<float>(hi->Npart_targ);
382 heavyIon[9] =
static_cast<float>(hi->Ncoll);
383 heavyIon[8] =
static_cast<float>(hi->spectator_neutrons);
384 heavyIon[7] =
static_cast<float>(hi->spectator_protons);
385 heavyIon[6] =
static_cast<float>(hi->N_Nwounded_collisions);
386 heavyIon[5] =
static_cast<float>(hi->Nwounded_N_collisions);
387 heavyIon[4] =
static_cast<float>(hi->Nwounded_Nwounded_collisions);
388 heavyIon[3] = hi->impact_parameter;
389 heavyIon[2] = hi->event_plane_angle;
390 heavyIon[1] = hi->eccentricity;
391 heavyIon[0] = hi->sigma_inel_NN;
395 if (genEvt->pdf_info()) {
396 auto pi=genEvt->pdf_info();
398 std::vector<double>& pdfinfo = persEvt.
m_pdfinfo;
400 pdfinfo[8] =
static_cast<double>(
pi->parton_id[0]);
401 pdfinfo[7] =
static_cast<double>(
pi->parton_id[1]);
402 pdfinfo[6] =
static_cast<double>(
pi->pdf_id[0]);
403 pdfinfo[5] =
static_cast<double>(
pi->pdf_id[1]);
404 pdfinfo[4] =
pi->x[0];
405 pdfinfo[3] =
pi->x[1];
406 pdfinfo[2] =
pi->scale;
407 pdfinfo[1] =
pi->xf[0];
408 pdfinfo[0] =
pi->xf[1];
412 for (
const auto& v: genEvt->vertices()) {
418 msg << MSG::DEBUG <<
"Created persistent state of HepMC::GenEvent [OK]" <<
endmsg;
435 if (parent ) parent->add_vertex(vtx);
438 vtx->set_status(persVtx.
m_id);
445 for (
unsigned int i = 0; i != nPartsIn; ++i ) {
451 for (
unsigned int i = 0; i != nPartsOut; ++i ) {
468 if (parent) add_to_output?parent->add_particle_out(p):parent->add_particle_in(p);
469 p->set_pdg_id( persPart.
m_pdgId);
482 double temp_e = std::sqrt( (
long double)(persPart.
m_px)*persPart.
m_px +
483 (
long double)(persPart.
m_py)*persPart.
m_py +
484 (
long double)(persPart.
m_pz)*persPart.
m_pz +
485 (
long double)(persPart.
m_m) *persPart.
m_m );
488 const int signM2 = ( persPart.
m_m >= 0. ? 1 : -1 );
489 const double persPart_ene =
490 std::sqrt( std::abs((
long double)(persPart.
m_px)*persPart.
m_px +
491 (
long double)(persPart.
m_py)*persPart.
m_py +
492 (
long double)(persPart.
m_pz)*persPart.
m_pz +
493 signM2* (
long double)(persPart.
m_m)* persPart.
m_m));
494 const int signEne = ( persPart.
m_recoMethod == 1 ? 1 : -1 );
498 signEne * persPart_ene ));
502 std::vector<int> flows;
503 const unsigned int nFlow = persPart.
m_flow.size();
504 for (
unsigned int iFlow= 0; iFlow != nFlow; ++iFlow ) {
505 flows.push_back(persPart.
m_flow[iFlow].second );
508 p->add_attribute(
HepMCStr::flows, std::make_shared<HepMC3::VectorIntAttribute>(flows));
511 partToEndVtx[p] = persPart.
m_endVtx;
525 auto weights_d = A_weights->value();
526 for (
auto& w: weights_d)
weights.push_back(w);
535 A_barcode?(A_barcode->value()):vtx->id() );
540 for (
const auto& p: vtx->particles_in()) {
541 if ( !p->production_vertex() || p->production_vertex()->id() == 0 ) {
547 for (
const auto& p: vtx->particles_out()) {
557 const double ene = mom.e();
558 const double m2 = mom.m2();
561 const bool useP2M2 = !(m2 > 0) &&
563 !(std::abs(m2) < 2.0*DBL_EPSILON*ene*ene);
564 auto A_flows=p->attribute<HepMC3::VectorIntAttribute>(
HepMCStr::flows);
565 auto A_phi=p->attribute<HepMC3::DoubleAttribute>(
HepMCStr::phi);
568 const short recoMethod = ( !useP2M2 ? 0: ( ene >= 0.? 1: 2 ) );
570 emplace_back( mom.px(),
576 A_flows?(A_flows->value().size()):0,
577 A_theta?(A_theta->value()):0.0,
578 A_phi?(A_phi->value()):0.0,
585 std::vector< std::pair<int,int> > flow_hepmc2;
586 if(A_flows) flow_hepmc2=vector_to_vector_int_int(A_flows->value());
587 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.
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_signalProcessId
Id of the processus being generated.
int m_beamParticle2
Barcode of the beam particle 2.
std::vector< double > m_crossSection
Container of HepMC::GenCrossSection object translated to vector<double>.
int m_signalProcessVtx
Barcode of the GenVertex holding the signal process.
int m_eventNbr
Event number.
std::vector< std::string > m_r_weight_names
The weight names.
int m_lengthUnit
HepMC::Units::LengthUnit casted to int.
std::vector< std::string > m_r_tool_name
Name of the used tool.
int m_beamParticle1
Barcode of the beam particle 1.
std::vector< int > m_e_attribute_id
We define those exactly as in the HepMC3::GenEvent.
double m_eventScale
Energy scale.
std::vector< double > m_weights
Weights for this event.
double m_filterWeight
value of the extra weight introduced during reweighting events in filter and value of some variables ...
unsigned int m_particlesBegin
Begin position in the vector of particles composing this event.
std::vector< std::string > m_r_attribute_string
Attribute serialized as string for run info.
unsigned int m_verticesEnd
End position in the vector of vertices composing this event.
std::vector< std::string > m_r_tool_description
Description of the used tool.
double m_alphaQCD
value of the QCD coupling.
int m_mpi
Number of multi particle interactions.
int m_momentumUnit
HepMC::Units::MomentumUnit casted to int.
std::vector< double > m_pdfinfo
Container of HepMC::PdfInfo object translated to vector<double> for simplicity.
unsigned int m_verticesBegin
Begin position in the vector of vertices composing this event.
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>.
std::vector< std::string > m_r_tool_version
Version of the used tool.
std::vector< std::string > m_r_attribute_name
Attribute name for run info.
std::vector< std::string > m_e_attribute_string
Attribute serialized as string for event.
double m_alphaQED
value of the QED coupling.
float m_m
m-component of the 4-momentum of this particle
float m_py
y-component of the 4-momentum of this particle
float m_generated_mass
mass of this particle when it was generated
int m_barcode
barcode of this particles (uniquely identifying this particle within a given GenEvent)
float m_pz
z-component of the 4-momentum 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_px
x-component of the 4-momentum of this particle
float m_thetaPolarization
polarization
int m_pdgId
identity of this particle, according to the Particle Data Group notation
int m_status
Status of this particle.
float m_phiPolarization
phi polarization
std::vector< std::pair< int, int > > m_flow
Flow for this particle.
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_barcode
barcode of this vertex (uniquely identifying a vertex within an event)
float m_y
y-coordinate of the vertex
int m_id
Id of this vertex.
float m_z
z-coordinate of the vertex
float m_t
t-coordinate of the vertex
std::vector< int > m_particlesOut
collection of barcodes of out-going particles connected to this vertex
std::vector< float > m_weights
Weights for this vertex.
HepMC::GenVertexPtr createGenVertex(const McEventCollection_p7 &persEvts, const GenVertex_p7 &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.
static int writeGenParticle(const HepMC::ConstGenParticlePtr &p, McEventCollection_p7 &persEvt)
Method to write a persistent GenParticle object It returns the index of the persistent GenParticle in...
virtual void persToTrans(const McEventCollection_p7 *persObj, McEventCollection *transObj, MsgStream &log)
Method creating the transient representation of McEventCollection from its persistent representation ...
McEventCollectionCnv_p7 & operator=(const McEventCollectionCnv_p7 &rhs)
Assignement operator.
HepMC::GenParticlePtr createGenParticle(const GenParticle_p7 &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 ~McEventCollectionCnv_p7()
Destructor.
virtual void transToPers(const McEventCollection *transObj, McEventCollection_p7 *persObj, MsgStream &log)
Method creating the persistent representation McEventCollection_p7 from its transient representation ...
McEventCollectionCnv_p7()
Default constructor:
ServiceHandle< IHepMCWeightSvc > m_hepMCWeightSvc
T_AthenaPoolTPCnvBase< McEventCollection, McEventCollection_p7 > Base_t
static void writeGenVertex(const HepMC::ConstGenVertexPtr &vtx, McEventCollection_p7 &persEvt)
Method to write a persistent GenVertex object.
std::unordered_map< HepMC::GenParticlePtr, int > ParticlesMap_t
std::vector< GenEvent_p7 > m_genEvents
The vector of persistent representation of GenEvents.
std::vector< GenVertex_p7 > m_genVertices
The vector of persistent representation of GenVertices.
std::vector< GenParticle_p7 > 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 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)
HepMC3::GenParticlePtr GenParticlePtr
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
HepMC3::GenVertexPtr GenVertexPtr
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
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