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 // Clear the maps before filling them, so that keys from an earlier fill are not kept.
264 m_particleBC.clear();
265 m_vertexBC.clear();
266 const auto eventAttributes = e->attributes(); // this makes a copy
267 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
268 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
269
270 const auto &particles = e->particles();
271 for (size_t i = 1; i <= particles.size(); i++) {
272 if (hasBarcodeAttribute && barcodeAttributeIt->second.count(i) > 0) {
273 const auto &ptr = barcodeAttributeIt->second.at(i);
274 if (ptr->is_parsed()) {
275 m_particleBC[static_cast<HepMC3::IntAttribute*>(ptr.get())->value()] = ptr->particle();
276 }
277 else {
278 m_particleBC[std::atoi(ptr->unparsed_string().c_str())] = ptr->particle();
279 }
280 } else {
281 m_particleBC[i] = particles[i-1];
282 }
283 }
284 const auto &vertices = e->vertices();
285 for (size_t i = 1; i <= vertices.size(); i++) {
286 if (hasBarcodeAttribute && barcodeAttributeIt->second.count(-i) > 0) {
287 const auto &ptr = barcodeAttributeIt->second.at(-i);
288 if (ptr->is_parsed()) {
289 m_vertexBC[static_cast<HepMC3::IntAttribute*>(ptr.get())->value()] = ptr->vertex();
290 }
291 else {
292 m_vertexBC[std::atoi(ptr->unparsed_string().c_str())] = ptr->vertex();
293 }
294 } else {
295 m_vertexBC[-i] = vertices[i-1];
296 }
297 }
298 set_is_parsed(true);
299 }
300
301private:
302 std::unordered_map<int, GenVertexPtr> m_vertexBC;
303 std::unordered_map<int, GenParticlePtr> m_particleBC;
304};
305
311class ShadowParticle : public HepMC3::Attribute {
312public:
313
316
319 : Attribute(), m_shadow(p) {}
320
322 virtual bool from_string(const std::string &) override { return false; }
323
325 virtual bool to_string(std::string &att) const override
326 {
327 att = "ShadowParticle";
328 return true;
329 }
330
332 return m_shadow;
333 }
334
335private:
336
338};
339
340inline bool set_ll_event_number(HepMC3::GenEvent* e, long long int num){
341 e->add_attribute(HepMCStr::long_long_event_number, std::make_shared<HepMC3::LongLongAttribute>(num));
342 return true;
343}
344inline long long int get_ll_event_number(const HepMC3::GenEvent* e){
345 auto at = e->attribute<HepMC3::LongLongAttribute>(HepMCStr::long_long_event_number);
346 return at ? at->value() : e->event_number();
347}
348
349inline std::map<std::string, std::size_t> weights_map(const HepMC3::GenEvent* e) {
350 std::map<std::string, std::size_t> ret;
351 auto run = e->run_info();
352 if (!run) return ret;
353 const std::vector<std::string> names = run->weight_names();
354 for (const auto& name: names) ret[name] = run->weight_index(name);
355 return ret;
356}
357
358inline std::vector<HepMC3::GenParticlePtr>::const_iterator begin(HepMC3::GenEvent& e) { return e.particles().begin(); }
359inline std::vector<HepMC3::GenParticlePtr>::const_iterator end(HepMC3::GenEvent& e) { return e.particles().end(); }
360inline std::vector<HepMC3::ConstGenParticlePtr>::const_iterator begin(const HepMC3::GenEvent& e) { return e.particles().begin(); }
361inline std::vector<HepMC3::ConstGenParticlePtr>::const_iterator end(const HepMC3::GenEvent& e) { return e.particles().end(); }
362
363inline GenEvent* newGenEvent(const int signal_process_id, const int event_number) { // TODO Update event_number to long long int?
364 GenEvent* e = new GenEvent();
365 std::shared_ptr<HepMC3::IntAttribute> signal_process_id_A = std::make_shared<HepMC3::IntAttribute>(signal_process_id);
366 e->add_attribute(HepMCStr::signal_process_id, signal_process_id_A);
367 e->add_attribute(HepMCStr::barcodes, std::make_shared<GenEventBarcodes>());
368 e->set_event_number(event_number);
369 return e;
370}
371
372inline GenEvent* copyemptyGenEvent(const GenEvent* inEvt) {
373 GenEvent* e = new GenEvent();
374 e->set_event_number(inEvt->event_number());
375 e->weights() = inEvt->weights();
376 auto a_mpi = inEvt->attribute<HepMC3::IntAttribute>(HepMCStr::mpi);
377 if (a_mpi) e->add_attribute(HepMCStr::mpi, std::make_shared<HepMC3::IntAttribute>(*a_mpi));
378 auto a_signal_process_id = inEvt->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_id);
379 if (a_signal_process_id) e->add_attribute(HepMCStr::signal_process_id, std::make_shared<HepMC3::IntAttribute>(*a_signal_process_id));
380 auto a_event_scale = inEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::event_scale);
381 if (a_event_scale) e->add_attribute(HepMCStr::event_scale, std::make_shared<HepMC3::DoubleAttribute>(*a_event_scale));
382 auto a_alphaQCD = inEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::alphaQCD);
383 if (a_alphaQCD) e->add_attribute(HepMCStr::alphaQCD, std::make_shared<HepMC3::DoubleAttribute>(*a_alphaQCD));
384 auto a_alphaQED = inEvt->attribute<HepMC3::DoubleAttribute>(HepMCStr::alphaQED);
385 if (a_alphaQED) e->add_attribute(HepMCStr::alphaQED, std::make_shared<HepMC3::DoubleAttribute>(*a_alphaQED));
386 auto a_pi = inEvt->pdf_info();
387 if (a_pi) e->set_pdf_info(std::make_shared<HepMC3::GenPdfInfo>(*a_pi));
388 auto a_hi = inEvt->heavy_ion();
389 if (a_hi) e->set_heavy_ion(std::make_shared<HepMC3::GenHeavyIon>(*a_hi));
390 auto a_random_states = inEvt->attribute<HepMC3::VectorLongIntAttribute>(HepMCStr::random_states);
391 if (a_random_states) e->add_attribute(HepMCStr::random_states, std::make_shared<HepMC3::VectorLongIntAttribute>(*a_random_states));
392 e->add_attribute(HepMCStr::barcodes, std::make_shared<GenEventBarcodes>());
393 return e;
394}
395
397 auto barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
398 if (!barcodes) {
399 barcodes = std::make_shared<GenEventBarcodes>();
400 e->add_attribute(HepMCStr::barcodes, barcodes);
401 }
402 // force re-parsing as calling barcodes->is_parsed() returns true here
403 barcodes->fillAttribute(e);
404}
405
407 // Prefer to use optimized GenEvent barcodes attribute
408 const auto &barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
409 if (barcodes) {
410 ConstGenVertexPtr ptr = barcodes->barcode_to_vertex (id);
411 if (ptr) return ptr;
412 }
413 // Fallback to unoptimized GenVertex barcode attribute
414 const auto eventAttributes = e->attributes(); // this makes a copy
415 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
416 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
417
418 const auto &vertices = e->vertices();
419 if (hasBarcodeAttribute) {
420 for (size_t i = 1; i <= vertices.size(); i++) {
421 const auto &ptrIt = barcodeAttributeIt->second.find(-i);
422 if (ptrIt != barcodeAttributeIt->second.end()) {
423 const auto &ptr = ptrIt->second;
424 if (ptr->is_parsed()) {
425 if (id == static_cast<HepMC3::IntAttribute*>(ptr.get())->value()) {
426 return ptr->vertex();
427 }
428 }
429 else {
430 if (id == std::atoi(ptr->unparsed_string().c_str())) {
431 return ptr->vertex();
432 }
433 }
434 }
435 }
436 }
437 // No barcodes attribute, so assume that we are passing the id member variable instead of a barcode
438 if (-id > 0 && -id <= static_cast<int>(vertices.size())) {
439 if (!vertices[-id-1]->attribute<HepMC3::IntAttribute>(HepMCStr::barcode)) {
440 return vertices[-id-1];
441 }
442 }
443 return HepMC3::ConstGenVertexPtr();
444}
445
447 // Prefer to use optimized GenEvent barcodes attribute
448 const auto &barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
449 if (barcodes) {
450 ConstGenParticlePtr ptr = barcodes->barcode_to_particle (id);
451 if (ptr) return ptr;
452 }
453 // Fallback to unoptimized GenParticle barcode attribute
454 const auto eventAttributes = e->attributes(); // this makes a copy
455 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
456 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
457
458 const auto &particles = e->particles();
459 if (hasBarcodeAttribute) {
460 for (size_t i = 1; i <= particles.size(); i++) {
461 const auto &ptrIt = barcodeAttributeIt->second.find(i);
462 if (ptrIt != barcodeAttributeIt->second.end()) {
463 const auto &ptr = ptrIt->second;
464 if (ptr->is_parsed()) {
465 if (id == static_cast<HepMC3::IntAttribute*>(ptr.get())->value()) {
466 return ptr->particle();
467 }
468 }
469 else {
470 if (id == std::atoi(ptr->unparsed_string().c_str())) {
471 return ptr->particle();
472 }
473 }
474 }
475 }
476 }
477 // No barcodes attribute, so assume that we are passing the id member variable instead of a barcode
478 if (id > 0 && id <= static_cast<int>(particles.size())) {
479 if (!particles[id-1]->attribute<HepMC3::IntAttribute>(HepMCStr::barcode)) {
480 return particles[id-1];
481 }
482 }
483 return HepMC3::ConstGenParticlePtr();
484}
485
487 // Prefer to use optimized GenEvent barcodes attribute
488 const auto &barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
489 if (barcodes) {
490 GenVertexPtr ptr = barcodes->barcode_to_vertex (id);
491 if (ptr) return ptr;
492 }
493 // Fallback to unoptimized GenVertex barcode attribute
494 const auto eventAttributes = e->attributes(); // this makes a copy
495 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
496 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
497
498 const auto &vertices = e->vertices();
499 if (hasBarcodeAttribute) {
500 for (size_t i = 1; i <= vertices.size(); i++) {
501 const auto &ptrIt = barcodeAttributeIt->second.find(-i);
502 if (ptrIt != barcodeAttributeIt->second.end()) {
503 const auto &ptr = ptrIt->second;
504 if (ptr->is_parsed()) {
505 if (id == static_cast<HepMC3::IntAttribute*>(ptr.get())->value()) {
506 return ptr->vertex();
507 }
508 }
509 else {
510 if (id == std::atoi(ptr->unparsed_string().c_str())) {
511 return ptr->vertex();
512 }
513 }
514 }
515 }
516 }
517 // No barcodes attribute, so assume that we are passing the id member variable instead of a barcode
518 if (-id > 0 && -id <= static_cast<int>(vertices.size())) {
519 if (!vertices[-id-1]->attribute<HepMC3::IntAttribute>(HepMCStr::barcode)) {
520 return vertices[-id-1];
521 }
522 }
523 return HepMC3::GenVertexPtr();
524}
525
527 // Prefer to use optimized GenEvent barcodes attribute
528 const auto &barcodes = e->attribute<GenEventBarcodes> (HepMCStr::barcodes);
529 if (barcodes) {
530 GenParticlePtr ptr = barcodes->barcode_to_particle (id);
531 if (ptr) return ptr;
532 }
533 // Fallback to unoptimized GenParticle barcode attribute
534 const auto eventAttributes = e->attributes(); // this makes a copy
535 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
536 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
537
538 const auto &particles = e->particles();
539 if (hasBarcodeAttribute) {
540 for (size_t i = 1; i <= particles.size(); i++) {
541 const auto &ptrIt = barcodeAttributeIt->second.find(i);
542 if (ptrIt != barcodeAttributeIt->second.end()) {
543 const auto &ptr = ptrIt->second;
544 if (ptr->is_parsed()) {
545 if (id == static_cast<HepMC3::IntAttribute*>(ptr.get())->value()) {
546 return ptr->particle();
547 }
548 }
549 else {
550 if (id == std::atoi(ptr->unparsed_string().c_str())) {
551 return ptr->particle();
552 }
553 }
554 }
555 }
556 }
557 // No barcodes attribute, so assume that we are passing the id member variable instead of a barcode
558 if (id > 0 && id <= static_cast<int>(particles.size())) {
559 if (!particles[id-1]->attribute<HepMC3::IntAttribute>(HepMCStr::barcode)) {
560 return particles[id-1];
561 }
562 }
563 return HepMC3::GenParticlePtr();
564}
565
566inline int mpi(const GenEvent& evt) {
567 std::shared_ptr<HepMC3::IntAttribute> A_mpi = evt.attribute<HepMC3::IntAttribute>(HepMCStr::mpi);
568 return A_mpi ? (A_mpi->value()) : 0;
569}
570inline int mpi(const GenEvent* evt) {
571 std::shared_ptr<HepMC3::IntAttribute> A_mpi = evt->attribute<HepMC3::IntAttribute>(HepMCStr::mpi);
572 return A_mpi ? (A_mpi->value()) : 0;
573}
574
575inline int signal_process_id(const GenEvent& evt) {
576 std::shared_ptr<HepMC3::IntAttribute> A_signal_process_id = evt.attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_id);
577 return A_signal_process_id ? (A_signal_process_id->value()) : 0;
578}
579inline int signal_process_id(const GenEvent* evt) {
580 std::shared_ptr<HepMC3::IntAttribute> A_signal_process_id = evt->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_id);
581 return A_signal_process_id ? (A_signal_process_id->value()) : 0;
582}
583inline void set_signal_process_id(GenEvent* e, const int i = 0) {
584 std::shared_ptr<HepMC3::IntAttribute> signal_process_id = std::make_shared<HepMC3::IntAttribute>(i);
585 e->add_attribute(HepMCStr::signal_process_id, std::move(signal_process_id));
586}
587inline void set_mpi(GenEvent* e, const int i = 0) {
588 std::shared_ptr<HepMC3::IntAttribute> mpi = std::make_shared<HepMC3::IntAttribute>(i);
589 e->add_attribute(HepMCStr::mpi, std::move(mpi));
590}
591inline void set_random_states(GenEvent* e, std::vector<long int>& a) {
592 e->add_attribute(HepMCStr::random_states, std::make_shared<HepMC3::VectorLongIntAttribute>(a));
593}
594template <class T> void set_signal_process_vertex(GenEvent* e, T& v) {
595 if (!v || !e) return;
596/* AV: HepMC2 adds the vertex to event */
597 e->add_vertex(v);
598 v->add_attribute(HepMCStr::signal_process_vertex, std::make_shared<HepMC3::IntAttribute>(1));
599}
600inline 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; }
601inline GenVertexPtr signal_process_vertex(GenEvent* e) { for (auto& v: e->vertices()) if (v->attribute<HepMC3::IntAttribute>(HepMCStr::signal_process_vertex)) return v; return nullptr; }
602inline bool valid_beam_particles(const GenEvent* e) {
603 if (!e) return false;
604 size_t nBeams = 0;
605 for (const auto& p : e->beams()) { if (p->status() == 4) ++nBeams; }
606 if (nBeams != 2) return false;
607 return true;
608}
609
610template <class T> bool suggest_barcode(T& p, int i) {
611 if (!p->parent_event()) return false;
612 auto barcodes = p->parent_event()->template attribute<GenEventBarcodes> (HepMCStr::barcodes);
613 if (!barcodes) {
614 barcodes = std::make_shared<GenEventBarcodes>();
615 p->parent_event()->add_attribute(HepMCStr::barcodes, barcodes);
616 }
617 barcodes->remove(p);
618 const bool ret = p->add_attribute(HepMCStr::barcode, std::make_shared<HepMC3::IntAttribute>(i));
619 if (ret) barcodes->add(p);
620 return ret;
621}
622
623}
624#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:302
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:303
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:318
virtual bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Definition GenEvent.h:325
virtual bool from_string(const std::string &) override
Implementation of Attribute::from_string.
Definition GenEvent.h:322
ShadowParticle()
Default constructor.
Definition GenEvent.h:315
ConstGenParticlePtr value() const
get a pointer to the shadow particle.
Definition GenEvent.h:331
ConstGenParticlePtr m_shadow
The shadow particle.
Definition GenEvent.h:337
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
void set_mpi(GenEvent *e, const int i=0)
Definition GenEvent.h:587
int signal_process_id(const GenEvent &evt)
Definition GenEvent.h:575
ConstGenVertexPtr barcode_to_vertex(const GenEvent *e, int id)
Definition GenEvent.h:406
std::map< std::string, std::size_t > weights_map(const HepMC3::GenEvent *e)
Definition GenEvent.h:349
int barcode(const T *p)
Definition Barcode.h:15
ConstGenParticlePtr barcode_to_particle(const GenEvent *e, int id)
Definition GenEvent.h:446
std::vector< HepMC3::GenParticlePtr >::const_iterator begin(HepMC3::GenEvent &e)
Definition GenEvent.h:358
void set_signal_process_vertex(GenEvent *e, T &v)
Definition GenEvent.h:594
void set_signal_process_id(GenEvent *e, const int i=0)
Definition GenEvent.h:583
int mpi(const GenEvent &evt)
Definition GenEvent.h:566
ConstGenVertexPtr signal_process_vertex(const GenEvent *e)
Definition GenEvent.h:600
void set_random_states(GenEvent *e, std::vector< long int > &a)
Definition GenEvent.h:591
std::vector< HepMC3::GenParticlePtr >::const_iterator end(HepMC3::GenEvent &e)
Definition GenEvent.h:359
void fillBarcodesAttribute(GenEvent *e)
Definition GenEvent.h:396
HepMC3::Print Print
Definition GenEvent.h:37
bool suggest_barcode(T &p, int i)
Definition GenEvent.h:610
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:363
GenEvent * copyemptyGenEvent(const GenEvent *inEvt)
Definition GenEvent.h:372
long long int get_ll_event_number(const HepMC3::GenEvent *e)
Definition GenEvent.h:344
HepMC3::GenHeavyIon GenHeavyIon
Definition GenEvent.h:38
bool set_ll_event_number(HepMC3::GenEvent *e, long long int num)
Definition GenEvent.h:340
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition GenVertex.h:24
bool valid_beam_particles(const GenEvent *e)
Definition GenEvent.h:602
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
TFile * file
int run(int argc, char *argv[])