Key Points

Introduction


  • This tutorial builds a simple electron-ID algorithm that selects particles with 0.9 < E/p < 1.2.
  • The algorithm needs reconstructed tracks, calorimeter clusters, and a track-to-cluster matching (here, truth matching).
  • Inputs and outputs are stored as PODIO collections such as edm4eic::ReconstructedParticle and edm4eic::Cluster.

Creating a factory


  • Algorithms do framework-independent calculation; factories attach algorithms to JANA2.
  • Plugins control what gets compiled; register factory generators in a plugin’s InitPlugin().
  • Reusable algorithms go in src/algorithms and their factories in src/factories.
  • Always use JOmniFactory for new code; declare inputs, outputs, parameters, and services as registered members.

Calling a factory


  • A JOmniFactoryGeneratorT is a recipe JANA2 uses to instantiate factories, one per thread.
  • Each generator assigns a unique prefix plus positional input and output collection names.
  • Use podio:output_collections (or JEventProcessorPODIO.cc) to persist outputs, and InputTags (or the generator) to rewire inputs.
  • Collection names and prefixes must be globally unique across plugins.

Parameterizing a factory


  • Parameters are registered members; in EICrecon we back them with a Config struct via ParameterRef.
  • Pass the Config type as the second JOmniFactory template argument to make it available through config().
  • Override parameters in the generator with brace-initialization, or on the command line with -P<prefix>:<name>=<value>.
  • Access shared resources (geometry, fields) through thread-safe Service members.

Adding an algorithm


  • Algorithms do framework-independent work; their core is a const process(const Input&, const Output&) method.
  • Reusable algorithms live under src/algorithms (here src/algorithms/reco).
  • Algorithms inherit logging and declare inputs/outputs as template types; config lives in m_cfg via WithPodConfig.
  • A factory constructs the algorithm in Configure() (applyConfig, init) and calls process() in Process().

Working with PODIO


  • edm4eic (on top of edm4hep) is generated by PODIO from a YAML specification.
  • PODIO manages memory, separates layout from accessors, and enforces immutability, but object references are fragile.
  • Every PODIO object is owned by exactly one collection; use a subset collection (setSubsetCollection()) to reference objects owned elsewhere.
  • Factory inputs are immutable const *; the output collection becomes immutable once JANA2 moves it into a Frame.

Putting everything together


  • The final electron finder is one factory (ReconstructedElectrons_factory), one algorithm (ElectronReconstruction), and a Config struct, wired up in src/global/reco/reco.cc.
  • Reading the pre-merged ReconstructedParticles (with its getClusters() relation) makes the algorithm short — no truth-association inputs are needed.
  • The output is a subset collection of selected electrons; register additional generator instances (e.g. ReconstructedElectronsForDIS) for different E/p windows.
  • Omit ChangeRun() when a factory has no run-dependent state; the base class provides a no-op default.