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::ReconstructedParticleandedm4eic::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/algorithmsand their factories insrc/factories. - Always use
JOmniFactoryfor new code; declare inputs, outputs, parameters, and services as registered members.
Calling a factory
- A
JOmniFactoryGeneratorTis 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(orJEventProcessorPODIO.cc) to persist outputs, andInputTags(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
JOmniFactorytemplate argument to make it available throughconfig(). - 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
Servicemembers.
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(heresrc/algorithms/reco). - Algorithms inherit logging and declare inputs/outputs as template
types; config lives in
m_cfgviaWithPodConfig. - A factory constructs the algorithm in
Configure()(applyConfig,init) and callsprocess()inProcess().
Working with PODIO
-
edm4eic(on top ofedm4hep) 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 aFrame.
Putting everything together
- The final electron finder is one factory
(
ReconstructedElectrons_factory), one algorithm (ElectronReconstruction), and a Config struct, wired up insrc/global/reco/reco.cc. - Reading the pre-merged
ReconstructedParticles(with itsgetClusters()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.