Skip to content

Commit

Permalink
feat: accept HepMC3 ROOT input files in ddsim
Browse files Browse the repository at this point in the history
This enables ddsim to accept `--inputFiles example.hepmc3.tree.root` files as produced by the [HepMC3 rootIO writers](https://gitlab.cern.ch/hepmc/HepMC3/-/tree/master/rootIO/include/HepMC3).

There are two rootIO writers: `WriterRoot` writes HepMC3 objects to a ROOT file, while `WriterRootTree` writes a ROOT TTree with events. There are two corresponding rootIO readers. When HepMC3's `deduce_reader` is passed a `.root` file, it only [attempts to use](https://gitlab.cern.ch/hepmc/HepMC3/-/blob/master/include/HepMC3/ReaderFactory.h#L107) the `WriterRootTree`.

Since `.root` is a bit too generic as an extension (it does not indicate the data model) and since ddsim already uses multiple extensions in output formates, e.g. `.edm4hep.root`, I considered that the intent is best conveyed with `.hepmc3.tree.root` (making it clear that the HepMC3 data model is used, stored in TTrees, inside the ROOT file format).

With this change it is now also possible to run ddsim against remote HepMC3 events on an xrootd server, e.g.
```
ddsim --compactFile $DD4hepINSTALL/DDDetectors/compact/SiD.xml -N 10 --inputFiles root://dtn-eic.jlab.org//work/eic2/users/wdconinc/pythia8NCDIS_5x41_minQ2\=1_beamEffects_xAngle\=-0.025_hiDiv_vtxfix_1.hepmc3.tree.root --outputFile output.edm4hep.root
```
  • Loading branch information
wdconinc authored and andresailer committed Nov 11, 2022
1 parent cc4c4c5 commit 7ff5d95
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
except ImportError:
ARGCOMPLETEENABLED = False

POSSIBLEINPUTFILES = (".stdhep", ".slcio", ".HEPEvt", ".hepevt", ".hepmc", ".hepmc3", ".pairs")
POSSIBLEINPUTFILES = (".stdhep", ".slcio", ".HEPEvt", ".hepevt", ".hepmc", ".hepmc3", ".hepmc3.tree.root", ".pairs")


class DD4hepSimulation(object):
Expand Down Expand Up @@ -403,7 +403,7 @@ def run(self):
elif inputFile.endswith(".hepevt"):
gen = DDG4.GeneratorAction(kernel, "Geant4InputAction/hepevt%d" % index)
gen.Input = "Geant4EventReaderHepEvtLong|" + inputFile
elif inputFile.endswith((".hepmc", ".hepmc3")):
elif inputFile.endswith((".hepmc", ".hepmc3", ".hepmc3.tree.root")):
if self.hepmc3.useHepMC3:
gen = DDG4.GeneratorAction(kernel, "Geant4InputAction/hepmc%d" % index)
gen.Parameters = self.hepmc3.getParameters()
Expand Down Expand Up @@ -527,7 +527,7 @@ def __checkFileFormat(self, fileNames, extensions):
fileNames = [fileNames]
if not all(fileName.endswith(extensions) for fileName in fileNames):
self._errorMessages.append("ERROR: Unknown fileformat for file: %s" % fileNames)
if not self.hepmc3.useHepMC3 and any(fileName.endswith(".hepmc3") for fileName in fileNames):
if not self.hepmc3.useHepMC3 and any(fileName.endswith((".hepmc3", ".hepmc3.tree.root")) for fileName in fileNames):
self._errorMessages.append("ERROR: HepMC3 files require the use of HepMC3 library")
return fileNames

Expand Down

0 comments on commit 7ff5d95

Please sign in to comment.