ATLAS Offline Software
Loading...
Searching...
No Matches
FixHepMC.cxx File Reference
#include "EvgenProdTools/FixHepMC.h"
#include "TruthUtils/HepMCHelpers.h"
#include "AtlasHepMC/GenVertex.h"
#include "AtlasHepMC/GenEvent.h"
#include <vector>
Include dependency graph for FixHepMC.cxx:

Go to the source code of this file.

Functions

Event reduction functions
static void reduce (HepMC::GenEvent *ge, HepMC::GenParticle *gp)
 Remove an unwanted particle from the event, collapsing the graph structure consistently.
void reduce (HepMC::GenEvent *ge, std::vector< HepMC::GenParticlePtr > toremove)
 Remove unwanted particles from the event, collapsing the graph structure consistently.

Function Documentation

◆ reduce() [1/2]

void reduce ( HepMC::GenEvent * ge,
HepMC::GenParticle * gp )
inlinestatic

Remove an unwanted particle from the event, collapsing the graph structure consistently.

Note
The disconnected end vertex will be picked up by the final "sweeper" loop if necessary.
We do the reassigning this way since GV::add_particle_*() modifies the end vertex
Todo
Can we be a bit more efficient rather than having to run over all vertices every time? Or allow disabling of this clean-up, with a single clean being run at the end of filtering.
Todo
Todo
Use neater looping via vertices_match (or iterated vertex_match)
Todo
Todo
Also look for and report changes in number of no-parent and no-child vertices

Definition at line 39 of file FixHepMC.cxx.

39 {
40 // Do nothing if for some reason this particle is not actually in this event
41 if (gp->parent_event() != ge) return;
42
43 // Get start and end vertices
44 HepMC::GenVertex* vstart = gp->production_vertex();
45 HepMC::GenVertex* vend = gp->end_vertex();
46
47 // Disconnect the unwanted particle from its vertices and delete it
48 if (vstart != nullptr) vstart->remove_particle(gp);
49 if (vend != nullptr) vend->remove_particle(gp);
50 delete gp;
51
52 // If start/end vertices are valid and distinct, and this was the only particle that
53 // connected them, then reassign the end vertex decay products to the start vertex
54 // and rewrite the vertex position as most appropriate.
57 if (vstart != nullptr && vend != nullptr && vend != vstart) {
58 bool is_only_link = true;
59 for (auto pchild=vstart->particles_out_const_begin();pchild!=vstart->particles_out_const_end();++pchild) {
60 if ((*pchild)->end_vertex() == vend) is_only_link = false;
61 }
62 if (is_only_link) {
63 if (vend->position() != HepMC::FourVector())
64 vstart->set_position(vend->position()); //< @todo Always use end position if defined... ok?
65 while (vend->particles_out_size() > 0) {
66 vstart->add_particle_out(*vend->particles_out_const_begin());
67 }
68 while (vend->particles_in_size() > 0) {
69 vstart->add_particle_in(*vend->particles_in_const_begin());
70 }
71 }
72 }
73
74 // Sweep up any vertices orphaned by the particle removal
79 std::vector<HepMC::GenVertex*> orphaned_vtxs;
80 for (HepMC::GenEvent::vertex_const_iterator vi = ge->vertices_begin(); vi != ge->vertices_end(); ++vi) {
81 if ((*vi)->particles_in_size() == 0 && (*vi)->particles_out_size() == 0) orphaned_vtxs.push_back(*vi);
82 }
83 for (HepMC::GenVertex* gv : orphaned_vtxs) delete gv;
84 }

◆ reduce() [2/2]

void reduce ( HepMC::GenEvent * ge,
std::vector< HepMC::GenParticlePtr > toremove )
inline

Remove unwanted particles from the event, collapsing the graph structure consistently.

Definition at line 87 of file FixHepMC.cxx.

87 {
88 while (toremove.size()) {
89 auto gp = toremove.back();
90 toremove.pop_back();
91 reduce(ge, gp);
92 }
93 }
static void reduce(HepMC::GenEvent *ge, HepMC::GenParticle *gp)
Remove an unwanted particle from the event, collapsing the graph structure consistently.
Definition FixHepMC.cxx:39