Skip to content

Commit

Permalink
Use std::shared_ptr for compatibility with HepMC3 3.3.0 (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: jmcarcell <[email protected]>
  • Loading branch information
jmcarcell and jmcarcell authored Aug 21, 2024
1 parent b09f294 commit 02e8d99
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
19 changes: 9 additions & 10 deletions k4Gen/src/components/EDMToHepMCConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ StatusCode EDMToHepMCConverter::execute(const EventContext&) const {
event->set_units(HepMC3::Units::GEV, HepMC3::Units::MM);


for (auto p : *(particles)) {
for (auto p : *particles) {
if (p.getGeneratorStatus() == 1) { // only final state particles
const auto& mom = p.getMomentum();
auto* pHepMC =
new GenParticle(HepMC3::FourVector(mom.x, mom.y, mom.z, p.getMass()),
p.getPDG(),
p.getGeneratorStatus()); // hepmc status code for final state particle
auto pHepMC = std::make_shared<GenParticle>(HepMC3::FourVector(mom.x, mom.y, mom.z, p.getMass()),
p.getPDG(),
p.getGeneratorStatus()); // hepmc status code for final state particle

const auto& pos = p.getVertex();
auto* v =
new HepMC3::GenVertex(HepMC3::FourVector(pos.x,
pos.y,
pos.z,
p.getTime() / Gaudi::Units::c_light));
auto v =
std::make_shared<HepMC3::GenVertex>(HepMC3::FourVector(pos.x,
pos.y,
pos.z,
p.getTime() / Gaudi::Units::c_light));

v->add_particle_out(pHepMC);
event->add_vertex(v);
Expand Down
20 changes: 10 additions & 10 deletions k4Gen/src/components/HepMCFullMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ StatusCode HepMCFullMerge::initialize() {
StatusCode HepMCFullMerge::merge(HepMC3::GenEvent& signalEvent, const std::vector<HepMC3::GenEvent>& eventVector) {
for (auto it = eventVector.cbegin(), end = eventVector.cend(); it != end; ++it) {
// keep track of which vertex in full event corresponds to which vertex in merged event
std::unordered_map<const HepMC3::GenVertex*, HepMC3::GenVertex*> inputToMergedVertexMap;
for (auto v: (*it).vertices()) {
HepMC3::GenVertex* outvertex = new HepMC3::GenVertex(v->position());
inputToMergedVertexMap[v.get()] = outvertex;
std::unordered_map<std::shared_ptr<const HepMC3::GenVertex>, std::shared_ptr<HepMC3::GenVertex>> inputToMergedVertexMap;
for (auto& v: it->vertices()) {
auto outvertex = std::make_shared<HepMC3::GenVertex>(v->position());
inputToMergedVertexMap[v] = outvertex;
signalEvent.add_vertex(outvertex);
}
for (auto p: (*it).particles()) {
for (auto& p: it->particles()) {
// ownership of the particle is given to the vertex
HepMC3::GenParticle* newparticle = new HepMC3::GenParticle(*p);
auto newparticle = std::make_shared<HepMC3::GenParticle>(*p);
// attach particles to correct vertices in merged event
if (nullptr != p->end_vertex()) {
inputToMergedVertexMap[p->end_vertex().get()]->add_particle_in(newparticle);
if (p->end_vertex()) {
inputToMergedVertexMap[p->end_vertex()]->add_particle_in(newparticle);
}
if (nullptr != p->production_vertex()) {
inputToMergedVertexMap[p->production_vertex().get()]->add_particle_out(newparticle);
if (p->production_vertex()) {
inputToMergedVertexMap[p->production_vertex()]->add_particle_out(newparticle);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions k4Gen/src/components/HepMCSimpleMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ StatusCode HepMCSimpleMerge::initialize() {
StatusCode HepMCSimpleMerge::merge(HepMC3::GenEvent& signalEvent, const std::vector<HepMC3::GenEvent>& eventVector) {
// iterate over vertices and add them to signalEvent
for (auto it = eventVector.cbegin(), end = eventVector.cend(); it != end; ++it) {
std::unordered_map<const HepMC3::GenVertex*, HepMC3::GenVertex*> inputToMergedVertexMap;
for (auto v: (*it).vertices()) {
HepMC3::GenVertex* newVertex = new HepMC3::GenVertex(v->position());
inputToMergedVertexMap[v.get()] = newVertex;
std::unordered_map<std::shared_ptr<const HepMC3::GenVertex>, std::shared_ptr<HepMC3::GenVertex>> inputToMergedVertexMap;
for (auto& v: it->vertices()) {
auto newVertex = std::make_shared<HepMC3::GenVertex>(v->position());
inputToMergedVertexMap[v] = newVertex;
}
for (auto p: (*it).particles()) {
for (auto& p: it->particles()) {
// simple check if final-state particle:
// has no end vertex and correct status code meaning no further decays
if (!p->end_vertex() && p->status() == 1) {
// ownership of the particle (newParticle) is then given to the vertex (newVertex)
HepMC3::GenParticle* newParticle = new HepMC3::GenParticle(*p);
auto newParticle = std::make_shared<HepMC3::GenParticle>(*p);
// each pile up particle is associated to a new production vertex
// the position information is preserved
// ownership of the vertex (newVertex) is given to the event (newEvent)
HepMC3::GenVertex* newVertex = inputToMergedVertexMap[p->production_vertex().get()];
auto newVertex = inputToMergedVertexMap[p->production_vertex()];
newVertex->add_particle_out(newParticle);
signalEvent.add_vertex(newVertex);
}
Expand Down

0 comments on commit 02e8d99

Please sign in to comment.