Skip to content

Draft: Added example of pruning a HepMC event

Christian Holm Christensen requested to merge cholmcc_prune_example into master

The header examples/PruneExample/prune.h defines the generic function template

template <typename Select>
void prune(HepMC3::GenEvent& event, Select select, int verb=0)

which will remove all particles that are not selected by the functor argument select. The prototype of select is expected to be

bool select(HepMC3::ConstGenParticlePtr p);

and can be defined as a lambda-expression, for example,

auto select = [](HepMC3::ConstGenParticlePtr p) {
  switch(p->status()) {
  case 1: // final state
  case 2: // decayed
  case 4: // beam
    return true;
  }
  return false;
};

Particles that are not selected by select are removed from the event.

If the removed particle has an end-vertex, then all out-going particles of that end vertex is moved to be out-going of the removed particles production vertex.

If there are more than one in-coming particle to the removed particles end-vertex, then those are also moved to be incoming of the removed particles production vertex.

In this way, the event topology is kept which can be quite important for a number of applications (e.g., Rivet), while at the same time removing, f.ex., event generator specific particles which are of no use in the application.

The example prune_example.cc reads in data from file or standard input, prunes the events with the above selection, and then outputs the events to file (or standard output). The execution is timed. After processing an event, the a line containing

  • The original number of particles in the event,
  • the number of particles in the event after pruning,
  • and the time it took, in nanoseconds, to prune the event is written to standard error.

This is separated out of this MR

Merge request reports

Loading