ATLAS Offline Software
Loading...
Searching...
No Matches
McEventCollectionCnv_p6.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// McEventCollectionCnv_p6.cxx
8// Implementation file for class McEventCollectionCnv_p6
9// Author: S.Binet<binet@cern.ch>
11
12// STL includes
13#include <utility>
14#include <cmath>
15#include <cfloat> // for DBL_EPSILON
16
17// GeneratorObjectsTPCnv includes
19#include "HepMcDataPool.h"
24#include "GaudiKernel/ThreadLocalContext.h"
25
26
37
39// Constructors
41
43 Base_t( ),
44 m_isPileup(false),m_hepMCWeightSvc("HepMCWeightSvc","McEventCollectionCnv_p6")
45{}
46
48 Base_t( rhs ),
49 m_isPileup(false),m_hepMCWeightSvc("HepMCWeightSvc","McEventCollectionCnv_p6")
50{}
51
54{
55 if ( this != &rhs ) {
56 Base_t::operator=( rhs );
58 }
59 return *this;
60}
61
63// Destructor
65
67= default;
68
69
71 McEventCollection* transObj,
72 MsgStream& msg )
73{
74 const EventContext& ctx = Gaudi::Hive::currentContext();
75
76 msg << MSG::DEBUG << "Loading McEventCollection from persistent state..."
77 << endmsg;
78
79 // elements are managed by DataPool
80 if (!m_isPileup) {
81 transObj->clear(SG::VIEW_ELEMENTS);
82 }
83 HepMC::DataPool datapools;
84 const unsigned int nVertices = persObj->m_genVertices.size();
85 datapools.vtx.prepareToAdd(nVertices);
86 const unsigned int nParts = persObj->m_genParticles.size();
87 datapools.part.prepareToAdd(nParts);
88 const unsigned int nEvts = persObj->m_genEvents.size();
89 datapools.evt.prepareToAdd(nEvts);
90
91 transObj->reserve( nEvts );
92 for ( std::vector<GenEvent_p6>::const_iterator
93 itr = persObj->m_genEvents.begin(),
94 itrEnd = persObj->m_genEvents.end();
95 itr != itrEnd;
96 ++itr ) {
97 const GenEvent_p6& persEvt = *itr;
98 HepMC::GenEvent * genEvt(nullptr);
99 if(m_isPileup) {
100 genEvt = new HepMC::GenEvent();
101 } else {
102 genEvt = datapools.getGenEvent();
103 }
104 genEvt->add_attribute (HepMCStr::barcodes, std::make_shared<HepMC::GenEventBarcodes>());
105 for (unsigned int i = 0; i < persEvt.m_e_attribute_id.size(); ++i) {
106 if (attributes_to_ignore.count(persEvt.m_e_attribute_name[i])) continue;
107 genEvt->add_attribute(persEvt.m_e_attribute_name[i], std::make_shared<HepMC3::StringAttribute>(persEvt.m_e_attribute_string[i]), persEvt.m_e_attribute_id[i]);
108 }
110
111 genEvt->add_attribute(HepMCStr::signal_process_id, std::make_shared<HepMC3::IntAttribute>(persEvt.m_signalProcessId));
112 genEvt->set_event_number(persEvt.m_eventNbr);
113 genEvt->add_attribute(HepMCStr::mpi, std::make_shared<HepMC3::IntAttribute>(persEvt.m_mpi));
114 genEvt->add_attribute(HepMCStr::event_scale, std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_eventScale));
115 genEvt->add_attribute(HepMCStr::alphaQCD, std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_alphaQCD));
116 genEvt->add_attribute(HepMCStr::alphaQED, std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_alphaQED));
117 genEvt->add_attribute(HepMCStr::filterWeight, std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_filterWeight));
118 genEvt->add_attribute(HepMCStr::filterHT, std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_filterHT));
119 genEvt->add_attribute(HepMCStr::filterMET, std::make_shared<HepMC3::DoubleAttribute>(persEvt.m_filterMET));
120 genEvt->weights()= persEvt.m_weights;
121 genEvt->add_attribute(HepMCStr::random_states, std::make_shared<HepMC3::VectorLongIntAttribute>(persEvt.m_randomStates));
122
123 genEvt->set_units(static_cast<HepMC3::Units::MomentumUnit>(persEvt.m_momentumUnit),
124 static_cast<HepMC3::Units::LengthUnit>(persEvt.m_lengthUnit));
125
126 //restore weight names from the dedicated svc (which was keeping them in metadata for efficiency)
127 if(!genEvt->run_info()) {
128 HepMC3::GenRunInfoData ri_read;
129 ri_read.weight_names = m_hepMCWeightSvc->weightNameVec(ctx);
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>();
133 ri_read.attribute_name = persEvt.m_r_attribute_name;
134 ri_read.attribute_string = persEvt.m_r_attribute_string;
135 auto ri = std::make_shared<HepMC3::GenRunInfo>();
136 ri->read_data(ri_read);
137 genEvt->set_run_info(std::move(ri));
138 }
139 // cross-section restore
140
141 if (!persEvt.m_crossSection.empty()) {
142 auto cs = std::make_shared<HepMC3::GenCrossSection>();
143 const std::vector<double>& xsection = persEvt.m_crossSection;
144 genEvt->set_cross_section(cs);
145 if( static_cast<bool>(xsection[0]) )
146 cs->set_cross_section(xsection[2],xsection[1]);
147 else
148 cs->set_cross_section(-1.0, -1.0);
149 }
150
151 // heavyIon restore
152 if (!persEvt.m_heavyIon.empty()) {
153 auto hi = std::make_shared<HepMC3::GenHeavyIon>();
154 const std::vector<float>& hIon = persEvt.m_heavyIon;
155 //AV NOTE THE ORDER
156 hi->set(
157 static_cast<int>(hIon[12]), // Ncoll_hard
158 static_cast<int>(hIon[11]), // Npart_proj
159 static_cast<int>(hIon[10]), // Npart_targ
160 static_cast<int>(hIon[9]), // Ncoll
161 static_cast<int>(hIon[8]), // spectator_neutrons
162 static_cast<int>(hIon[7]), // spectator_protons
163 static_cast<int>(hIon[6]), // N_Nwounded_collisions
164 static_cast<int>(hIon[5]), // Nwounded_N_collisions
165 static_cast<int>(hIon[4]), // Nwounded_Nwounded_collisions
166 hIon[3], // impact_parameter
167 hIon[2], // event_plane_angle
168 hIon[1], // eccentricity
169 hIon[0] ); // sigma_inel_NN
170 genEvt->set_heavy_ion(std::move(hi));
171 }
172
173
174
175 // pdfinfo restore
176 if (!persEvt.m_pdfinfo.empty())
177 {
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]), // id1
181 static_cast<int>(pdf[7]), // id2
182 pdf[4], // x1
183 pdf[3], // x2
184 pdf[2], // scalePDF
185 pdf[1], // pdf1
186 pdf[0], // pdf2
187 static_cast<int>(pdf[6]), // pdf_id1
188 static_cast<int>(pdf[5]));// pdf_id2
189 genEvt->set_pdf_info(std::move(pi));
190 }
191 transObj->push_back( genEvt );
192
193 // create a temporary map associating the barcode of an end-vtx to its
194 // particle.
195 // As not all particles are stable (d'oh!) we take 50% of the number of
196 // particles as an initial size of the hash-map (to prevent re-hash)
197 ParticlesMap_t partToEndVtx( (persEvt.m_particlesEnd - persEvt.m_particlesBegin)/2 );
198 // This is faster than the HepMC::barcode_to_vertex
199 std::map<int, HepMC::GenVertexPtr> brc_to_vertex;
200
201 // create the vertices
202 const unsigned int endVtx = persEvt.m_verticesEnd;
203 for ( unsigned int iVtx = persEvt.m_verticesBegin; iVtx != endVtx; ++iVtx ) {
204 auto vtx = createGenVertex( *persObj, persObj->m_genVertices[iVtx], partToEndVtx, datapools, genEvt );
205 brc_to_vertex[persObj->m_genVertices[iVtx].m_barcode] = std::move(vtx);
206 } //> end loop over vertices
207
208 // set the signal process vertex
209 const int sigProcVtx = persEvt.m_signalProcessVtx;
210 if ( sigProcVtx != 0 && brc_to_vertex.count(sigProcVtx) ) {
211 HepMC::set_signal_process_vertex(genEvt, brc_to_vertex[sigProcVtx] );
212 }
213
214 // connect particles to their end vertices
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 );
219 } else {
220 msg << MSG::ERROR << "GenParticle points to null end vertex !!" << endmsg;
221 }
222 }
223 // set the beam particles
224 const int beamPart1 = persEvt.m_beamParticle1;
225 const int beamPart2 = persEvt.m_beamParticle2;
226 if ( beamPart1 != 0 && beamPart2 != 0 ) {
227 genEvt->set_beam_particles(HepMC::barcode_to_particle(genEvt, beamPart1),
228 HepMC::barcode_to_particle(genEvt, beamPart2));
229 }
230
231
232
233 } //> end loop over m_genEvents
234
235 msg << MSG::DEBUG << "Loaded McEventCollection from persistent state [OK]"
236 << endmsg;
237}
238
240 McEventCollection_p6* persObj,
241 MsgStream& msg )
242{
243 const EventContext& ctx = Gaudi::Hive::currentContext();
244
245 msg << MSG::DEBUG << "Creating persistent state of McEventCollection..."
246 << endmsg;
247 persObj->m_genEvents.reserve( transObj->size() );
248
249 const std::pair<unsigned int,unsigned int> stats = nbrParticlesAndVertices( transObj );
250 persObj->m_genParticles.reserve( stats.first );
251 persObj->m_genVertices.reserve ( stats.second );
252
253 const McEventCollection::const_iterator itrEnd = transObj->end();
254 for ( McEventCollection::const_iterator itr = transObj->begin();
255 itr != itrEnd;
256 ++itr ) {
257 const unsigned int nPersVtx = persObj->m_genVertices.size();
258 const unsigned int nPersParts = persObj->m_genParticles.size();
259 const HepMC::GenEvent* genEvt = *itr;
260 //save the weight names to metadata via the HepMCWeightSvc
261 auto ri = genEvt->run_info();
262 HepMC3::GenRunInfoData ri_data;
263 if (ri) {
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();
267 } else {
268 //AV : This to be decided if one would like to have default names.
269 //std::vector<std::string> names{"0"};
270 //m_hepMCWeightSvc->setWeightNames( names_to_name_index_map(names), ctx );
271 }
272 }
273
274 auto A_mpi=genEvt->attribute<HepMC3::IntAttribute>(HepMCStr::mpi);
275 auto A_signal_process_id=genEvt->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_id);
276 auto A_event_scale=genEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::event_scale);
277 auto A_alphaQCD=genEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::alphaQCD);
278 auto A_alphaQED=genEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::alphaQED);
279 auto A_filterWeight=genEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::filterWeight);
280 auto A_filterHT=genEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::filterHT);
281 auto A_filterMET=genEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::filterMET);
282 auto signal_process_vertex = HepMC::signal_process_vertex(genEvt);
283
284 // If signal vertex not found on the vertices, look on the event (Sherpa)
285 if (!signal_process_vertex) {
286 auto event_spv = genEvt->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_vertex);
287
288 // If the attribute exists, get the vertex
289 if (event_spv) signal_process_vertex = genEvt->vertices().at(-event_spv->value()-1);
290 }
291
292 auto A_random_states=genEvt->attribute<HepMC3::VectorLongIntAttribute>(HepMCStr::random_states);
293 auto beams=genEvt->beams();
294 persObj->m_genEvents.
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,
304 signal_process_vertex?HepMC::barcode(signal_process_vertex):0,
305 !beams.empty()?HepMC::barcode(beams[0]):0,
306 beams.size()>1?HepMC::barcode(beams[1]):0,
307 genEvt->weights(),
308 A_random_states?(A_random_states->value()):std::vector<long>(),
309 std::vector<double>(), // cross section
310 std::vector<float>(), // heavyion
311 std::vector<double>(), // pdf info
312 genEvt->momentum_unit(),
313 genEvt->length_unit(),
314 nPersVtx,
315 nPersVtx + genEvt->vertices().size(),
316 nPersParts,
317 nPersParts + genEvt->particles().size() );
318 {
319 GenEvent_p6& persEvt = persObj->m_genEvents.back();
320 std::map< std::string, std::map<int, std::shared_ptr<HepMC3::Attribute> > > e_atts = genEvt->attributes();
321 persEvt.m_e_attribute_name.clear();
322 persEvt.m_e_attribute_id.clear();
323 persEvt.m_e_attribute_string.clear();
324 for (auto& attmap: e_atts) {
325 if (attributes_to_ignore.count(attmap.first)) continue;
326 if (attmap.first == HepMCStr::ShadowParticle) continue;
327 if (attmap.first == HepMCStr::ShadowParticleId) continue;
328 for (auto& att: attmap.second) {
329 persEvt.m_e_attribute_name.push_back(attmap.first);
330 persEvt.m_e_attribute_id.push_back(att.first);
331 std::string st;
332 att.second->to_string(st);
335 persEvt.m_e_attribute_string.push_back(std::move(st));
336 }
337 }
338 persEvt.m_r_attribute_name.clear();
339 persEvt.m_r_attribute_string.clear();
340 if (ri) {
341 persEvt.m_r_attribute_string = std::move(ri_data.attribute_string);
342 persEvt.m_r_attribute_name = std::move(ri_data.attribute_name);
343 /*** This is for the future
344 persEvt.m_r_tool_name = ri_data.tool_name;
345 persEvt.m_r_tool_version = ri_data.tool_version;
346 persEvt.m_r_tool_description = ri_data.tool_description;
347 */
348 }
349 //Actually, with this piece there is no need to treat the CS and HI separately.
350 }
351 //HepMC::GenCrossSection encoding
352 if (genEvt->cross_section()) {
353 auto cs=genEvt->cross_section();
354 GenEvent_p6& persEvt = persObj->m_genEvents.back();
355 std::vector<double>& crossSection = persEvt.m_crossSection;
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;
366 }
367 crossSection[0] = 0.0;
368 }
369
370 }
371
372 //HepMC::HeavyIon encoding
373 if (genEvt->heavy_ion()) {
374 auto hi=genEvt->heavy_ion();
375 GenEvent_p6& persEvt = persObj->m_genEvents.back();
376 std::vector<float>& heavyIon = persEvt.m_heavyIon;
377 heavyIon.resize(13);
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;
391 }
392
393 //PdfInfo encoding
394 if (genEvt->pdf_info()) {
395 auto pi=genEvt->pdf_info();
396 GenEvent_p6& persEvt = persObj->m_genEvents.back();
397 std::vector<double>& pdfinfo = persEvt.m_pdfinfo;
398 pdfinfo.resize(9);
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];
408 }
409
410 // create vertices
411 for (const auto& v: genEvt->vertices()) {
412 writeGenVertex( v, *persObj );
413 }
414
415 } //> end loop over GenEvents
416
417 msg << MSG::DEBUG << "Created persistent state of HepMC::GenEvent [OK]" << endmsg;
418}
419
420
423 const GenVertex_p6& persVtx,
424 ParticlesMap_t& partToEndVtx, HepMC::DataPool& datapools
425 ,HepMC::GenEvent* parent
426 ) const
427{
428 HepMC::GenVertexPtr vtx(nullptr);
429 if(m_isPileup) {
431 } else {
432 vtx = datapools.getGenVertex();
433 }
434 if (parent ) parent->add_vertex(vtx);
435 vtx->set_position(HepMC::FourVector( persVtx.m_x , persVtx.m_y , persVtx.m_z ,persVtx.m_t ));
436 //AV ID cannot be assigned in HepMC3. And its meaning in HepMC2 is not clear.
437 vtx->set_status(HepMC::new_vertex_status_from_old(persVtx.m_id, persVtx.m_barcode)); // UPDATED STATUS VALUE TO NEW SCHEME
438 // cast from std::vector<float> to std::vector<double>
439 std::vector<double> weights( persVtx.m_weights.begin(), persVtx.m_weights.end() );
440 vtx->add_attribute(HepMCStr::weights,std::make_shared<HepMC3::VectorDoubleAttribute>(weights));
441 HepMC::suggest_barcode (vtx, persVtx.m_barcode);
442 // handle the in-going (orphans) particles
443 const unsigned int nPartsIn = persVtx.m_particlesIn.size();
444 for ( unsigned int i = 0; i != nPartsIn; ++i ) {
445 createGenParticle( persEvt.m_genParticles[persVtx.m_particlesIn[i]], partToEndVtx, datapools, vtx, false );
446 }
447
448 // now handle the out-going particles
449 const unsigned int nPartsOut = persVtx.m_particlesOut.size();
450 for ( unsigned int i = 0; i != nPartsOut; ++i ) {
451 createGenParticle( persEvt.m_genParticles[persVtx.m_particlesOut[i]], partToEndVtx, datapools, vtx );
452 }
453 return vtx;
454}
455
458 ParticlesMap_t& partToEndVtx, HepMC::DataPool& datapools ,const HepMC::GenVertexPtr& parent, bool add_to_output ) const
459{
460 HepMC::GenParticlePtr p(nullptr);
461 if (m_isPileup) {
463 } else {
464 p = datapools.getGenParticle();
465 }
466 if (parent) add_to_output?parent->add_particle_out(p):parent->add_particle_in(p);
467 p->set_pdg_id( persPart.m_pdgId);
468 p->set_status(HepMC::new_particle_status_from_old(persPart.m_status, persPart.m_barcode)); // UPDATED STATUS VALUE TO NEW SCHEME
469 p->add_attribute(HepMCStr::phi,std::make_shared<HepMC3::DoubleAttribute>(persPart.m_phiPolarization));
470 p->add_attribute(HepMCStr::theta,std::make_shared<HepMC3::DoubleAttribute>(persPart.m_thetaPolarization));
471 HepMC::suggest_barcode (p, persPart.m_barcode);
472 p->set_generated_mass(persPart.m_generated_mass);
473
474 // Note: do the E calculation in extended (long double) precision.
475 // That happens implicitly on x86 with optimization on; saying it
476 // explicitly ensures that we get the same results with and without
477 // optimization. (If this is a performance issue for platforms
478 // other than x86, one could change to double for those platforms.)
479 if ( 0 == persPart.m_recoMethod ) {
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 );
484 p->set_momentum( HepMC::FourVector(persPart.m_px,persPart.m_py,persPart.m_pz,temp_e));
485 } else {
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 );
493 p->set_momentum(HepMC::FourVector( persPart.m_px,
494 persPart.m_py,
495 persPart.m_pz,
496 signEne * persPart_ene ));
497 }
498
499 // setup flow
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 );
504 }
505 //We construct it here as vector w/o gaps.
506 p->add_attribute(HepMCStr::flows, std::make_shared<HepMC3::VectorIntAttribute>(flows));
507
508 if ( persPart.m_endVtx != 0 ) {
509 partToEndVtx[p] = persPart.m_endVtx;
510 }
511
512 return p;
513}
514
516 McEventCollection_p6& persEvt )
517{
518 const HepMC::FourVector& position = vtx->position();
519 auto A_weights=vtx->attribute<HepMC3::VectorDoubleAttribute>(HepMCStr::weights);
520 auto A_barcode=vtx->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
521 std::vector<float> weights;
522 if (A_weights) {
523 auto weights_d = A_weights->value();
524 for (auto& w: weights_d) weights.push_back(w);
525 }
526 persEvt.m_genVertices.emplace_back( position.x(),
527 position.y(),
528 position.z(),
529 position.t(),
530 HepMC::old_vertex_status_from_new(vtx->status()), // REVERTED STATUS VALUE TO OLD SCHEME
531 weights.begin(),
532 weights.end(),
533 A_barcode?(A_barcode->value()):vtx->id() );
534 GenVertex_p6& persVtx = persEvt.m_genVertices.back();
535
536 // we write only the orphans in-coming particles and beams
537 persVtx.m_particlesIn.reserve(vtx->particles_in().size());
538 for (const auto& p: vtx->particles_in()) {
539 if ( !p->production_vertex() || p->production_vertex()->id() == 0 ) {
540 persVtx.m_particlesIn.push_back( writeGenParticle( p, persEvt ) );
541 }
542 }
543
544 persVtx.m_particlesOut.reserve(vtx->particles_out().size());
545 for (const auto& p: vtx->particles_out()) {
546 persVtx.m_particlesOut.push_back( writeGenParticle( p, persEvt ) );
547 }
548
549 }
551 McEventCollection_p6& persEvt )
552{
553 const HepMC::FourVector mom = p->momentum();
554 const double ene = mom.e();
555 const double m2 = mom.m2();
556
557 // Definitions of Bool isTimeLilike, isSpacelike and isLightlike according to HepLorentzVector definition
558 const bool useP2M2 = !(m2 > 0) && // !isTimelike
559 (m2 < 0) && // isSpacelike
560 !(std::abs(m2) < 2.0*DBL_EPSILON*ene*ene); // !isLightlike
561 auto A_flows=p->attribute<HepMC3::VectorIntAttribute>(HepMCStr::flows);
562 auto A_phi=p->attribute<HepMC3::DoubleAttribute>(HepMCStr::phi);
563 auto A_theta=p->attribute<HepMC3::DoubleAttribute>(HepMCStr::theta);
564
565 const short recoMethod = ( !useP2M2 ? 0: ( ene >= 0.? 1: 2 ) );
566 persEvt.m_genParticles.
567 emplace_back( mom.px(),
568 mom.py(),
569 mom.pz(),
570 mom.m(),
571 p->pdg_id(),
572 HepMC::old_particle_status_from_new(p->status()), // REVERTED STATUS VALUE TO OLD SCHEME
573 A_flows?(A_flows->value().size()):0,
574 A_theta?(A_theta->value()):0.0,
575 A_phi?(A_phi->value()):0.0,
576 p->production_vertex()? HepMC::barcode(p->production_vertex()):0,
577 p->end_vertex()? HepMC::barcode(p->end_vertex()):0,
579 p->generated_mass(),
580 recoMethod );
581
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() );
585
586 // we return the index of the particle in the big vector of particles
587 // (contained by the persistent GenEvent)
588 return (persEvt.m_genParticles.size() - 1);
589
590}
591
592
#define endmsg
static const std::set< std::string > attributes_to_ignore
#define pi
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
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_filterMET
double m_alphaQED
value of the QED coupling.
Definition GenEvent_p6.h:99
int m_momentumUnit
HepMC::Units::MomentumUnit casted to int.
int m_signalProcessId
Id of the processus being generated.
Definition GenEvent_p6.h:79
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.
Definition GenEvent_p6.h:87
int m_eventNbr
Event number.
Definition GenEvent_p6.h:83
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.
Definition GenEvent_p6.h:91
double m_alphaQCD
value of the QCD coupling.
Definition GenEvent_p6.h:95
double m_filterHT
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 flow2
const std::string phi
const std::string barcode
const std::string ShadowParticleId
const std::string flows
const std::string flow3
const std::string signal_process_vertex
const std::string flow1
const std::string filterHT
const std::string weights
const std::string signal_vertex_id
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
const std::string filterWeight
const std::string ShadowParticle
const std::string mpi
int barcode(const T *p)
Definition Barcode.h:15
HepMC3::FourVector FourVector
ConstGenParticlePtr barcode_to_particle(const GenEvent *e, int id)
Definition GenEvent.h:443
void set_signal_process_vertex(GenEvent *e, T &v)
Definition GenEvent.h:591
ConstGenVertexPtr signal_process_vertex(const GenEvent *e)
Definition GenEvent.h:597
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Definition GenParticle.h:21
bool suggest_barcode(T &p, int i)
Definition GenEvent.h:607
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
Definition GenParticle.h:19
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
Definition GenVertex.h:25
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
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
Definition GenVertex.h:24
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
@ 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
MsgStream & msg
Definition testRead.cxx:32