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