51 if (eventID == -999) {
throw HepMCInvalidEventError(); }
54 const int nparticles = evt.particles_size();
56 B2DEBUG(20,
"Found eventID " << eventID <<
" with " << nparticles <<
" particles.");
58 if (nparticles <= 0) {
59 throw (HepMCInvalidEventError());
61 const int event_offset = graph.
size();
63 for (
int i = 0; i < nparticles; i++) {
67 std::unordered_map<int, int> hash_index_map;
68 HepMC::GenEvent::particle_iterator tmp_particle = evt.particles_begin();
69 for (
int i = 0; i < nparticles; ++i) {
71 const int hash = (*tmp_particle)->barcode();
72 hash_index_map[hash] = i;
75 const double len_conv = HepMC::Units::conversion_factor(evt.length_unit(), HepMC::Units::CM);
76 const double mom_conv = HepMC::Units::conversion_factor(evt.momentum_unit(), HepMC::Units::GEV);
77 auto read_particle = evt.particles_begin();
79 for (
int i = 0; i < nparticles; ++i) {
80 auto* decay_vertex = (*read_particle)->end_vertex();
81 auto* production_vertex = (*read_particle)->production_vertex();
85 const int status = (*read_particle)->status();
86 const bool isFinalstate = !decay_vertex && status == 1;
88 const bool isVirtual = (status == 4) || (status == 21) || (status == 22) || (status == 23)
90 || (status == 41) || (status == 42) || (status == 43) || (status == 44)
92 || (status == 51) || (status == 52) || (status == 71) || (status == 73)
94 || (status == 83) || (status == 84)
96 const int pdg_code = (*read_particle)->pdg_id() ;
97 const double mass = (*read_particle)->generated_mass() * mom_conv;
98 auto const mom_tmp = (*read_particle)->momentum();
100 const HepMC::FourVector momentum(
107 B2DEBUG(20,
"Read particle: status " << status <<
" isFinal " << isFinalstate <<
" isVirtual " << isVirtual <<
" pdg " << pdg_code
108 <<
" mass " << mass <<
" px " << momentum.x() <<
" py " << momentum.y() <<
" px " << momentum.z() <<
" E " << momentum.t());
111 p.setMomentum(ROOT::Math::XYZVector(momentum.x(), momentum.y(), momentum.z()));
112 p.setEnergy(momentum.t());
114 if (production_vertex) {
115 const auto pos = production_vertex->position();
116 p.setProductionVertex(ROOT::Math::XYZVector(pos.x(), pos.y(), pos.z()) * len_conv *
Unit::cm);
118 p.setValidVertex(
true);
121 if ((status == 21) || (status == 41)
129 if (production_vertex) {
130 if (production_vertex->particles_in_const_begin() != production_vertex->particles_in_const_end()) {
131 auto parent = production_vertex->particles_begin(HepMC::parents);
132 const int parent_index_in_graph = hash_index_map[(*parent)->barcode()];
133 p.comesFrom(graph[event_offset + parent_index_in_graph]);
138 ROOT::Math::PxPyPzEVector p4 = p.get4Vector();
139 p4.SetPz(-1.0 * p4.Pz());
151 B2DEBUG(20,
"Returning event id " << eventID);
Class to represent Particle data in graph.
Class to build, validate and sort a particle decay chain.
size_t size() const
Return the number of particles in the graph.
@ c_PrimaryParticle
bit 0: Particle is primary particle.