ATLAS Offline Software
Loading...
Searching...
No Matches
GenEvent.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4/* Author: Andrii Verbytskyi andrii.verbytskyi@mpp.mpg.de */
5
6#ifndef ATLASHEPMC_GENEVENT_H
7#define ATLASHEPMC_GENEVENT_H
8#include "HepMC3/GenEvent.h"
9#include "HepMC3/GenHeavyIon.h"
10#include "HepMC3/GenPdfInfo.h"
11#include "HepMC3/PrintStreams.h"
12#include "AtlasHepMC/Barcode.h"
17
18#include <algorithm>
19#include <cstdlib>
20#include <iomanip>
21#include <map>
22#include <memory>
23#include <sstream>
24#include <string>
25#include <vector>
26
27#include <unordered_map>
28
29namespace HepMC3 {
30inline std::vector<HepMC3::GenParticlePtr>::const_iterator begin(HepMC3::GenEvent& e) { return e.particles().begin(); }
31inline std::vector<HepMC3::GenParticlePtr>::const_iterator end(HepMC3::GenEvent& e) { return e.particles().end(); }
32inline std::vector<HepMC3::ConstGenParticlePtr>::const_iterator begin(const HepMC3::GenEvent& e) { return e.particles().begin(); }
33inline std::vector<HepMC3::ConstGenParticlePtr>::const_iterator end(const HepMC3::GenEvent& e) { return e.particles().end(); }
34}
35
36namespace HepMC {
37using Print = HepMC3::Print;
38using GenHeavyIon = HepMC3::GenHeavyIon;
39using GenEvent = HepMC3::GenEvent;
40
41class ShortEventAttribute : public HepMC3::Attribute {
42public:
43 ShortEventAttribute(): HepMC3::Attribute(){}
44 ShortEventAttribute(const HepMC3::GenEvent* e): HepMC3::Attribute(){ from_event(e); }
45
46 bool from_event(const HepMC3::GenEvent* e){
47 NUP=e->particles().size();
48 resize();
49 XWGTUP = e->weights().size() ? e->weights()[0] : 1.0;
50 auto A_signal_process_id = e->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_id);
51 IDPRUP = A_signal_process_id ? A_signal_process_id->value() : 0;
52 auto A_event_scale = e->attribute<HepMC3::DoubleAttribute>(HepMCStr::event_scale);
53 SCALUP = A_event_scale ? A_event_scale->value() : 0;
54 auto A_alphaQCD = e->attribute<HepMC3::DoubleAttribute>(HepMCStr::alphaQCD);
55 AQCDUP = A_alphaQCD ? A_alphaQCD->value() : 0;
56 auto A_alphaQED = e->attribute<HepMC3::DoubleAttribute>(HepMCStr::alphaQED);
57 AQEDUP = A_alphaQED ? A_alphaQED->value() : 0;
58 for ( int i = 0; i < NUP; ++i ){
59 const auto & thisParticle = e->particles().at(i);
60 PUP[i][0] = thisParticle->momentum().px();
61 PUP[i][1] = thisParticle->momentum().py();
62 PUP[i][2] = thisParticle->momentum().pz();
63 PUP[i][3] = thisParticle->momentum().e();
64 PUP[i][4] = thisParticle->momentum().m();
65 IDUP[i] = thisParticle->pdg_id();
66 const auto pv = thisParticle->production_vertex();
67 const auto ev = thisParticle->end_vertex();
68 if (pv && ev ) ISTUP[i] = 2;
69 if (pv && !ev ) ISTUP[i] = 1;
70 if (thisParticle->status() == 4 || !pv ) ISTUP[i] = -1;
71 const auto flow1 = thisParticle->attribute<HepMC3::IntAttribute>(HepMCStr::flow1);
72 const auto flow2 = thisParticle->attribute<HepMC3::IntAttribute>(HepMCStr::flow2);
73 ICOLUP[i].first = flow1 ? flow1->value() : 0;
74 ICOLUP[i].second = flow2 ? flow2->value() : 0;
75 int l = 0;
76 int h = 0;
77 if (pv && !pv->particles_in().empty()) {
78 l = pv->particles_in().front()->id();
79 h = l;
80 for (const auto& p : pv->particles_in()) {
81 const int id = p->id();
82 l = std::min(l, id);
83 h = std::max(h, id);
84 }
85 }
86 MOTHUP[i].first = h;
87 MOTHUP[i].second = l;
88 }
89 return true;
90 }
91
92 bool from_string(const std::string &att) override {
93 std::istringstream iss(att);
94 iss >> NUP;
95 iss >> IDPRUP;
96 iss >> XWGTUP;
97 iss >> SCALUP;
98 iss >> AQEDUP;
99 iss >> AQCDUP;
100 //assume input is a trusted source
101 //coverity[tainted_data]
102 resize();
103 for ( int i = 0; i < NUP; ++i ){
104 iss >> IDUP[i];
105 iss >> ISTUP[i];
106 iss >> MOTHUP[i].first;
107 iss >> MOTHUP[i].second;
108 iss >> ICOLUP[i].first;
109 iss >> ICOLUP[i].second;
110 iss >> PUP[i][0];
111 iss >> PUP[i][1];
112 iss >> PUP[i][2];
113 iss >> PUP[i][3];
114 iss >> PUP[i][4];
115 iss >> VTIMUP[i];
116 iss >> SPINUP[i];
117 }
118 set_is_parsed(true);
119 return true;
120 }
121
122 bool to_string(std::string &fl) const override {
123 std::ostringstream file;
124 file << " " << std::setw(4) << NUP
125 << " " << std::setw(6) << IDPRUP
126 << " " << std::setw(14) << XWGTUP
127 << " " << std::setw(14) << SCALUP
128 << " " << std::setw(14) << AQEDUP
129 << " " << std::setw(14) << AQCDUP << "\n";
130 for ( int i = 0; i < NUP; ++i )
131 file << " " << std::setw(8) << IDUP[i]
132 << " " << std::setw(2) << ISTUP[i]
133 << " " << std::setw(4) << MOTHUP[i].first
134 << " " << std::setw(4) << MOTHUP[i].second
135 << " " << std::setw(4) << ICOLUP[i].first
136 << " " << std::setw(4) << ICOLUP[i].second
137 << " " << std::setw(14) << PUP[i][0]
138 << " " << std::setw(14) << PUP[i][1]
139 << " " << std::setw(14) << PUP[i][2]
140 << " " << std::setw(14) << PUP[i][3]
141 << " " << std::setw(14) << PUP[i][4]
142 << " " << std::setw(1) << VTIMUP[i]
143 << " " << std::setw(1) << SPINUP[i] << std::endl;
144 fl += file.str();
145 return true;
146 }
147
148 void resize() {
149 IDUP.resize(NUP);
150 ISTUP.resize(NUP);
151 MOTHUP.resize(NUP);
152 ICOLUP.resize(NUP);
153 PUP.resize(NUP, std::vector<double>(5));
154 VTIMUP.resize(NUP);
155 SPINUP.resize(NUP);
156 }
157
158 int NUP = 0;
159 int IDPRUP = 0;
160 double XWGTUP = 0;
161 double SCALUP = 0;
162 double AQEDUP = 0;
163 double AQCDUP = 0;
164 std::vector<long> IDUP{};
165 std::vector<int> ISTUP{};
166 std::vector< std::pair<int,int> > MOTHUP{};
167 std::vector< std::pair<int,int> > ICOLUP{};
168 std::vector< std::vector<double> > PUP{};
169 std::vector<double> VTIMUP{};
170 std::vector<double> SPINUP{};
171};
172
173
174class GenEventBarcodes : public HepMC3::Attribute
175{
176public:
177 virtual bool from_string(const std::string & /*att*/) override { return false; }
178 virtual bool to_string(std::string &att) const override
179 {
180 att = "GenEventBarcodes";
181 return true;
182 }
184 const auto it = m_vertexBC.find (id);
185 if (it != m_vertexBC.end()) return it->second;
186 return nullptr;
187 }
189 const auto it = m_vertexBC.find (id);
190 if (it != m_vertexBC.end()) return it->second;
191 return nullptr;
192 }
194 const auto it = m_particleBC.find (id);
195 if (it != m_particleBC.end()) return it->second;
196 return nullptr;
197 }
199 const auto it = m_particleBC.find (id);
200 if (it != m_particleBC.end()) return it->second;
201 return nullptr;
202 }
203
204 void add (GenVertexPtr p) {
205 if (!p) return;
206 auto barcode = p->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
207 if (barcode) {
208 m_vertexBC[barcode->value()] = std::move(p);
209 }
210 }
211
213 if (!p) return;
214 auto barcode = p->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
215 if (barcode) {
216 const auto it = m_vertexBC.find (barcode->value());
217 if (it != m_vertexBC.end()) {
218 m_vertexBC.erase (it);
219 }
220 }
221 }
222
224 if (!p) return;
225 auto barcode = p->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
226 if (barcode) {
227 m_particleBC[barcode->value()] = std::move(p);
228 }
229 }
230
232 if (!p) return;
233 auto barcode = p->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
234 if (barcode) {
235 const auto it = m_particleBC.find (barcode->value());
236 if (it != m_particleBC.end()) {
237 m_particleBC.erase (it);
238 }
239 }
240 }
241
242 std::map<int, ConstGenVertexPtr> barcode_to_vertex_map() const {
243 std::map<int, ConstGenVertexPtr> ret;
244 for (const auto &bcvertpair: m_vertexBC)
245 ret.insert({bcvertpair.first, std::const_pointer_cast<const HepMC3::GenVertex>(bcvertpair.second)});
246 return ret;
247 }
248 std::map<int, ConstGenParticlePtr> barcode_to_particle_map() const {
249 std::map<int, ConstGenParticlePtr> ret;
250 for (const auto &bcpartpair: m_particleBC)
251 ret.insert({bcpartpair.first, std::const_pointer_cast<const HepMC3::GenParticle>(bcpartpair.second)});
252 return ret;
253 }
254 std::map<int,int> id_to_barcode_map() const {
255 std::map<int, int> ret;
256 for (const auto &bcvertpair: m_vertexBC) ret.insert({bcvertpair.second->id(), bcvertpair.first});
257 for (const auto &bcpartpair: m_particleBC) ret.insert({bcpartpair.second->id(), bcpartpair.first});
258 return ret;
259 }
260
261
263 const auto eventAttributes = e->attributes(); // this makes a copy
264 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
265 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
266
267 const auto &particles = e->particles();
268 for (size_t i = 1; i <= particles.size(); i++) {
269 if (hasBarcodeAttribute && barcodeAttributeIt->second.count(i) > 0) {
270 const auto &ptr = barcodeAttributeIt->second.at(i);
271 if (ptr->is_parsed()) {
272 m_particleBC[static_cast<HepMC3::IntAttribute*>(ptr.get())->value()] = ptr->particle();
273 }
274 else {
275 m_particleBC[std::atoi(ptr->unparsed_string().c_str())] = ptr->particle();
276 }
277 } else {
278 m_particleBC[i] = particles[i-1];
279 }
280 }
281 const auto &vertices = e->vertices();
282 for (size_t i = 1; i <= vertices.size(); i++) {
283 if (hasBarcodeAttribute && barcodeAttributeIt->second.count(-i) > 0) {
284 const auto &ptr = barcodeAttributeIt->second.at(-i);
285 if (ptr->is_parsed()) {
286 m_vertexBC[static_cast<HepMC3::IntAttribute*>(ptr.get())->value()] = ptr->vertex();
287 }
288 else {
289 m_vertexBC[std::atoi(ptr->unparsed_string().c_str())] = ptr->vertex();
290 }
291 } else {
292 m_vertexBC[-i] = vertices[i-1];
293 }
294 }
295 set_is_parsed(true);
296 }
297
298private:
299 std::unordered_map<int, GenVertexPtr> m_vertexBC;
300 std::unordered_map<int, GenParticlePtr> m_particleBC;
301};
302
308class ShadowParticle : public HepMC3::Attribute {
309public:
310
313
316 : Attribute(), m_shadow(p) {}
317
319 virtual bool from_string(const std::string &) override { return false; }
320
322 virtual bool to_string(std::string &att) const override
323 {
324 att = "ShadowParticle";
325 return true;
326 }
327
329 return m_shadow;
330 }
331
332private:
333
335};
336
337inline bool set_ll_event_number(HepMC3::GenEvent* e, long long int num){
338 e->add_attribute(HepMCStr::long_long_event_number, std::make_shared<HepMC3::LongLongAttribute>(num));
339 return true;
340}
341inline long long int get_ll_event_number(const HepMC3::GenEvent* e){
342 auto at = e->attribute<HepMC3::LongLongAttribute>(HepMCStr::long_long_event_number);
343 return at ? at->value() : e->event_number();
344}
345
346inline std::map<std::string, std::size_t> weights_map(const HepMC3::GenEvent* e) {
347 std::map<std::string, std::size_t> ret;
348 auto run = e->run_info();
349 if (!run) return ret;
350 const std::vector<std::string> names = run->weight_names();
351 for (const auto& name: names) ret[name] = run->weight_index(name);
352 return ret;
353}
354
355inline std::vector<HepMC3::GenParticlePtr>::const_iterator begin(HepMC3::GenEvent& e) { return e.particles().begin(); }
356inline std::vector<HepMC3::GenParticlePtr>::const_iterator end(HepMC3::GenEvent& e) { return e.particles().end(); }
357inline std::vector<HepMC3::ConstGenParticlePtr>::const_iterator begin(const HepMC3::GenEvent& e) { return e.particles().begin(); }
358inline std::vector<HepMC3::ConstGenParticlePtr>::const_iterator end(const HepMC3::GenEvent& e) { return e.particles().end(); }
359
360inline GenEvent* newGenEvent(const int signal_process_id, const int event_number) { // TODO Update event_number to long long int?
361 GenEvent* e = new GenEvent();
362 std::shared_ptr<HepMC3::IntAttribute> signal_process_id_A = std::make_shared<HepMC3::IntAttribute>(signal_process_id);
363 e->add_attribute(HepMCStr::signal_process_id, signal_process_id_A);
364 e->add_attribute(HepMCStr::barcodes, std::make_shared<GenEventBarcodes>());
365 e->set_event_number(event_number);
366 return e;
367}
368
369inline GenEvent* copyemptyGenEvent(const GenEvent* inEvt) {
370 GenEvent* e = new GenEvent();
371 e->set_event_number(inEvt->event_number());
372 e->weights() = inEvt->weights();
373 auto a_mpi = inEvt->attribute<HepMC3::IntAttribute>(HepMCStr::mpi);
374 if (a_mpi) e->add_attribute(HepMCStr::mpi, std::make_shared<HepMC3::IntAttribute>(*a_mpi));
375 auto a_signal_process_id = inEvt->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_id);
376 if (a_signal_process_id) e->add_attribute(HepMCStr::signal_process_id, std::make_shared<HepMC3::IntAttribute>(*a_signal_process_id));
377 auto a_event_scale = inEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::event_scale);
378 if (a_event_scale) e->add_attribute(HepMCStr::event_scale, std::make_shared<HepMC3::DoubleAttribute>(*a_event_scale));
379 auto a_alphaQCD = inEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::alphaQCD);
380 if (a_alphaQCD) e->add_attribute(HepMCStr::alphaQCD, std::make_shared<HepMC3::DoubleAttribute>(*a_alphaQCD));
381 auto a_alphaQED = inEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::alphaQED);
382 if (a_alphaQED) e->add_attribute(HepMCStr::alphaQED, std::make_shared<HepMC3::DoubleAttribute>(*a_alphaQED));
383 auto a_pi = inEvt->pdf_info();
384 if (a_pi) e->set_pdf_info(std::make_shared<HepMC3::GenPdfInfo>(*a_pi));
385 auto a_hi = inEvt->heavy_ion();
386 if (a_hi) e->set_heavy_ion(std::make_shared<HepMC3::GenHeavyIon>(*a_hi));
387 auto a_random_states = inEvt->attribute<HepMC3::VectorLongIntAttribute>(HepMCStr::random_states);
388 if (a_random_states) e->add_attribute(HepMCStr::random_states, std::make_shared<HepMC3::VectorLongIntAttribute>(*a_random_states));
389 e->add_attribute(HepMCStr::barcodes, std::make_shared<GenEventBarcodes>());
390 return e;
391}
392
394 auto barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
395 if (!barcodes) {
396 barcodes = std::make_shared<GenEventBarcodes>();
397 e->add_attribute(HepMCStr::barcodes, barcodes);
398 }
399 // force re-parsing as calling barcodes->is_parsed() returns true here
400 barcodes->fillAttribute(e);
401}
402
404 // Prefer to use optimized GenEvent barcodes attribute
405 const auto &barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
406 if (barcodes) {
407 ConstGenVertexPtr ptr = barcodes->barcode_to_vertex (id);
408 if (ptr) return ptr;
409 }
410 // Fallback to unoptimized GenVertex barcode attribute
411 const auto eventAttributes = e->attributes(); // this makes a copy
412 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
413 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
414
415 const auto &vertices = e->vertices();
416 if (hasBarcodeAttribute) {
417 for (size_t i = 1; i <= vertices.size(); i++) {
418 const auto &ptrIt = barcodeAttributeIt->second.find(-i);
419 if (ptrIt != barcodeAttributeIt->second.end()) {
420 const auto &ptr = ptrIt->second;
421 if (ptr->is_parsed()) {
422 if (id == static_cast<HepMC3::IntAttribute*>(ptr.get())->value()) {
423 return ptr->vertex();
424 }
425 }
426 else {
427 if (id == std::atoi(ptr->unparsed_string().c_str())) {
428 return ptr->vertex();
429 }
430 }
431 }
432 }
433 }
434 // No barcodes attribute, so assume that we are passing the id member variable instead of a barcode
435 if (-id > 0 && -id <= static_cast<int>(vertices.size())) {
436 if (!vertices[-id-1]->attribute<HepMC3::IntAttribute>(HepMCStr::barcode)) {
437 return vertices[-id-1];
438 }
439 }
440 return HepMC3::ConstGenVertexPtr();
441}
442
444 // Prefer to use optimized GenEvent barcodes attribute
445 const auto &barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
446 if (barcodes) {
447 ConstGenParticlePtr ptr = barcodes->barcode_to_particle (id);
448 if (ptr) return ptr;
449 }
450 // Fallback to unoptimized GenParticle barcode attribute
451 const auto eventAttributes = e->attributes(); // this makes a copy
452 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
453 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
454
455 const auto &particles = e->particles();
456 if (hasBarcodeAttribute) {
457 for (size_t i = 1; i <= particles.size(); i++) {
458 const auto &ptrIt = barcodeAttributeIt->second.find(i);
459 if (ptrIt != barcodeAttributeIt->second.end()) {
460 const auto &ptr = ptrIt->second;
461 if (ptr->is_parsed()) {
462 if (id == static_cast<HepMC3::IntAttribute*>(ptr.get())->value()) {
463 return ptr->particle();
464 }
465 }
466 else {
467 if (id == std::atoi(ptr->unparsed_string().c_str())) {
468 return ptr->particle();
469 }
470 }
471 }
472 }
473 }
474 // No barcodes attribute, so assume that we are passing the id member variable instead of a barcode
475 if (id > 0 && id <= static_cast<int>(particles.size())) {
476 if (!particles[id-1]->attribute<HepMC3::IntAttribute>(HepMCStr::barcode)) {
477 return particles[id-1];
478 }
479 }
480 return HepMC3::ConstGenParticlePtr();
481}
482
484 // Prefer to use optimized GenEvent barcodes attribute
485 const auto &barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
486 if (barcodes) {
487 GenVertexPtr ptr = barcodes->barcode_to_vertex (id);
488 if (ptr) return ptr;
489 }
490 // Fallback to unoptimized GenVertex barcode attribute
491 const auto eventAttributes = e->attributes(); // this makes a copy
492 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
493 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
494
495 const auto &vertices = e->vertices();
496 if (hasBarcodeAttribute) {
497 for (size_t i = 1; i <= vertices.size(); i++) {
498 const auto &ptrIt = barcodeAttributeIt->second.find(-i);
499 if (ptrIt != barcodeAttributeIt->second.end()) {
500 const auto &ptr = ptrIt->second;
501 if (ptr->is_parsed()) {
502 if (id == static_cast<HepMC3::IntAttribute*>(ptr.get())->value()) {
503 return ptr->vertex();
504 }
505 }
506 else {
507 if (id == std::atoi(ptr->unparsed_string().c_str())) {
508 return ptr->vertex();
509 }
510 }
511 }
512 }
513 }
514 // No barcodes attribute, so assume that we are passing the id member variable instead of a barcode
515 if (-id > 0 && -id <= static_cast<int>(vertices.size())) {
516 if (!vertices[-id-1]->attribute<HepMC3::IntAttribute>(HepMCStr::barcode)) {
517 return vertices[-id-1];
518 }
519 }
520 return HepMC3::GenVertexPtr();
521}
522
524 // Prefer to use optimized GenEvent barcodes attribute
525 const auto &barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
526 if (barcodes) {
527 GenParticlePtr ptr = barcodes->barcode_to_particle (id);
528 if (ptr) return ptr;
529 }
530 // Fallback to unoptimized GenParticle barcode attribute
531 const auto eventAttributes = e->attributes(); // this makes a copy
532 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
533 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
534
535 const auto &particles = e->particles();
536 if (hasBarcodeAttribute) {
537 for (size_t i = 1; i <= particles.size(); i++) {
538 const auto &ptrIt = barcodeAttributeIt->second.find(i);
539 if (ptrIt != barcodeAttributeIt->second.end()) {
540 const auto &ptr = ptrIt->second;
541 if (ptr->is_parsed()) {
542 if (id == static_cast<HepMC3::IntAttribute*>(ptr.get())->value()) {
543 return ptr->particle();
544 }
545 }
546 else {
547 if (id == std::atoi(ptr->unparsed_string().c_str())) {
548 return ptr->particle();
549 }
550 }
551 }
552 }
553 }
554 // No barcodes attribute, so assume that we are passing the id member variable instead of a barcode
555 if (id > 0 && id <= static_cast<int>(particles.size())) {
556 if (!particles[id-1]->attribute<HepMC3::IntAttribute>(HepMCStr::barcode)) {
557 return particles[id-1];
558 }
559 }
560 return HepMC3::GenParticlePtr();
561}
562
563inline int mpi(const GenEvent& evt) {
564 std::shared_ptr<HepMC3::IntAttribute> A_mpi = evt.attribute<HepMC3::IntAttribute>(HepMCStr::mpi);
565 return A_mpi ? (A_mpi->value()) : 0;
566}
567inline int mpi(const GenEvent* evt) {
568 std::shared_ptr<HepMC3::IntAttribute> A_mpi = evt->attribute<HepMC3::IntAttribute>(HepMCStr::mpi);
569 return A_mpi ? (A_mpi->value()) : 0;
570}
571
572inline int signal_process_id(const GenEvent& evt) {
573 std::shared_ptr<HepMC3::IntAttribute> A_signal_process_id = evt.attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_id);
574 return A_signal_process_id ? (A_signal_process_id->value()) : 0;
575}
576inline int signal_process_id(const GenEvent* evt) {
577 std::shared_ptr<HepMC3::IntAttribute> A_signal_process_id = evt->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_id);
578 return A_signal_process_id ? (A_signal_process_id->value()) : 0;
579}
580inline void set_signal_process_id(GenEvent* e, const int i = 0) {
581 std::shared_ptr<HepMC3::IntAttribute> signal_process_id = std::make_shared<HepMC3::IntAttribute>(i);
582 e->add_attribute(HepMCStr::signal_process_id, std::move(signal_process_id));
583}
584inline void set_mpi(GenEvent* e, const int i = 0) {
585 std::shared_ptr<HepMC3::IntAttribute> mpi = std::make_shared<HepMC3::IntAttribute>(i);
586 e->add_attribute(HepMCStr::mpi, std::move(mpi));
587}
588inline void set_random_states(GenEvent* e, std::vector<long int>& a) {
589 e->add_attribute(HepMCStr::random_states, std::make_shared<HepMC3::VectorLongIntAttribute>(a));
590}
591template <class T> void set_signal_process_vertex(GenEvent* e, T& v) {
592 if (!v || !e) return;
593/* AV: HepMC2 adds the vertex to event */
594 e->add_vertex(v);
595 v->add_attribute(HepMCStr::signal_process_vertex, std::make_shared<HepMC3::IntAttribute>(1));
596}
597inline ConstGenVertexPtr signal_process_vertex(const GenEvent* e) { for (auto& v: e->vertices()) if (v->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_vertex)) return v; return nullptr; }
598inline GenVertexPtr signal_process_vertex(GenEvent* e) { for (auto& v: e->vertices()) if (v->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_vertex)) return v; return nullptr; }
599inline bool valid_beam_particles(const GenEvent* e) {
600 if (!e) return false;
601 size_t nBeams = 0;
602 for (const auto& p : e->beams()) { if (p->status() == 4) ++nBeams; }
603 if (nBeams != 2) return false;
604 return true;
605}
606
607template <class T> bool suggest_barcode(T& p, int i) {
608 if (!p->parent_event()) return false;
609 auto barcodes = p->parent_event()->template attribute<GenEventBarcodes> (HepMCStr::barcodes);
610 if (!barcodes) {
611 barcodes = std::make_shared<GenEventBarcodes>();
612 p->parent_event()->add_attribute(HepMCStr::barcodes, barcodes);
613 }
614 barcodes->remove(p);
615 const bool ret = p->add_attribute(HepMCStr::barcode, std::make_shared<HepMC3::IntAttribute>(i));
616 if (ret) barcodes->add(p);
617 return ret;
618}
619
620}
621#endif
static Double_t a
Header file for AthHistogramAlgorithm.
virtual bool to_string(std::string &att) const override
Definition GenEvent.h:178
std::map< int, ConstGenVertexPtr > barcode_to_vertex_map() const
Definition GenEvent.h:242
void add(GenVertexPtr p)
Definition GenEvent.h:204
std::unordered_map< int, GenVertexPtr > m_vertexBC
Definition GenEvent.h:299
GenVertexPtr barcode_to_vertex(int id)
Definition GenEvent.h:188
void remove(GenParticlePtr p)
Definition GenEvent.h:231
ConstGenParticlePtr barcode_to_particle(int id) const
Definition GenEvent.h:193
void add(GenParticlePtr p)
Definition GenEvent.h:223
std::map< int, ConstGenParticlePtr > barcode_to_particle_map() const
Definition GenEvent.h:248
void remove(GenVertexPtr p)
Definition GenEvent.h:212
std::unordered_map< int, GenParticlePtr > m_particleBC
Definition GenEvent.h:300
GenParticlePtr barcode_to_particle(int id)
Definition GenEvent.h:198
void fillAttribute(GenEvent *e)
Definition GenEvent.h:262
virtual bool from_string(const std::string &) override
Definition GenEvent.h:177
ConstGenVertexPtr barcode_to_vertex(int id) const
Definition GenEvent.h:183
std::map< int, int > id_to_barcode_map() const
Definition GenEvent.h:254
ShadowParticle(ConstGenParticlePtr p)
Constructor initializing attribute value.
Definition GenEvent.h:315
virtual bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Definition GenEvent.h:322
virtual bool from_string(const std::string &) override
Implementation of Attribute::from_string.
Definition GenEvent.h:319
ShadowParticle()
Default constructor.
Definition GenEvent.h:312
ConstGenParticlePtr value() const
get a pointer to the shadow particle.
Definition GenEvent.h:328
ConstGenParticlePtr m_shadow
The shadow particle.
Definition GenEvent.h:334
bool from_event(const HepMC3::GenEvent *e)
Definition GenEvent.h:46
ShortEventAttribute(const HepMC3::GenEvent *e)
Definition GenEvent.h:44
std::vector< std::vector< double > > PUP
Definition GenEvent.h:168
bool to_string(std::string &fl) const override
Definition GenEvent.h:122
std::vector< std::pair< int, int > > ICOLUP
Definition GenEvent.h:167
std::vector< std::pair< int, int > > MOTHUP
Definition GenEvent.h:166
std::vector< long > IDUP
Definition GenEvent.h:164
std::vector< double > VTIMUP
Definition GenEvent.h:169
std::vector< double > SPINUP
Definition GenEvent.h:170
bool from_string(const std::string &att) override
Definition GenEvent.h:92
std::vector< int > ISTUP
Definition GenEvent.h:165
int ev
Definition globals.cxx:25
std::vector< HepMC3::GenParticlePtr >::const_iterator begin(HepMC3::GenEvent &e)
Definition GenEvent.h:30
std::vector< HepMC3::GenParticlePtr >::const_iterator end(HepMC3::GenEvent &e)
Definition GenEvent.h:31
const std::string event_scale
const std::string flow2
const std::string barcode
const std::string long_long_event_number
const std::string signal_process_vertex
const std::string flow1
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 mpi
void set_mpi(GenEvent *e, const int i=0)
Definition GenEvent.h:584
int signal_process_id(const GenEvent &evt)
Definition GenEvent.h:572
ConstGenVertexPtr barcode_to_vertex(const GenEvent *e, int id)
Definition GenEvent.h:403
std::map< std::string, std::size_t > weights_map(const HepMC3::GenEvent *e)
Definition GenEvent.h:346
int barcode(const T *p)
Definition Barcode.h:15
ConstGenParticlePtr barcode_to_particle(const GenEvent *e, int id)
Definition GenEvent.h:443
std::vector< HepMC3::GenParticlePtr >::const_iterator begin(HepMC3::GenEvent &e)
Definition GenEvent.h:355
void set_signal_process_vertex(GenEvent *e, T &v)
Definition GenEvent.h:591
void set_signal_process_id(GenEvent *e, const int i=0)
Definition GenEvent.h:580
int mpi(const GenEvent &evt)
Definition GenEvent.h:563
ConstGenVertexPtr signal_process_vertex(const GenEvent *e)
Definition GenEvent.h:597
void set_random_states(GenEvent *e, std::vector< long int > &a)
Definition GenEvent.h:588
std::vector< HepMC3::GenParticlePtr >::const_iterator end(HepMC3::GenEvent &e)
Definition GenEvent.h:356
void fillBarcodesAttribute(GenEvent *e)
Definition GenEvent.h:393
HepMC3::Print Print
Definition GenEvent.h:37
bool suggest_barcode(T &p, int i)
Definition GenEvent.h:607
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
GenEvent * newGenEvent(const int signal_process_id, const int event_number)
Definition GenEvent.h:360
GenEvent * copyemptyGenEvent(const GenEvent *inEvt)
Definition GenEvent.h:369
long long int get_ll_event_number(const HepMC3::GenEvent *e)
Definition GenEvent.h:341
HepMC3::GenHeavyIon GenHeavyIon
Definition GenEvent.h:38
bool set_ll_event_number(HepMC3::GenEvent *e, long long int num)
Definition GenEvent.h:337
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition GenVertex.h:24
bool valid_beam_particles(const GenEvent *e)
Definition GenEvent.h:599
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
TFile * file
int run(int argc, char *argv[])