Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions CLDConfig/CLDReconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import os
from Gaudi.Configuration import INFO, WARNING, DEBUG

from Configurables import k4DataSvc, MarlinProcessorWrapper
from k4MarlinWrapper.inputReader import create_reader, attach_edm4hep2lcio_conversion
from Gaudi.Configurables import EventDataSvc, MarlinProcessorWrapper, GeoSvc, TrackingCellIDEncodingSvc
from k4FWCore import ApplicationMgr, IOSvc
from k4FWCore.parseArgs import parser
from py_utils import SequenceLoader, attach_lcio2edm4hep_conversion, create_writer, parse_collection_patch_file
from py_utils import SequenceLoader, parse_collection_patch_file
from k4MarlinWrapper.io_helpers import IOHandlerHelper

parser_group = parser.add_argument_group("CLDReconstruction.py custom options")
parser_group.add_argument("--inputFiles", action="extend", nargs="+", metavar=("file1", "file2"), help="One or multiple input files")
# Need the dummy input such that the IOHandlerHelper.add_reader call below does not crash when called with --help
parser_group.add_argument("--inputFiles", action="store", nargs="+", metavar=("file1", "file2"), help="One or multiple input files", default=["dummy_input.edm4hep.root"])
parser_group.add_argument("--outputBasename", help="Basename of the output file(s)", default="output")
parser_group.add_argument("--trackingOnly", action="store_true", help="Run only track reconstruction", default=False)
parser_group.add_argument("--enableLCFIJet", action="store_true", help="Enable LCFIPlus jet clustering parts", default=False)
Expand All @@ -36,11 +38,12 @@
tracking_group.add_argument("--truthTracking", action="store_true", default=False, help="Cheat tracking pattern recognition")
reco_args = parser.parse_known_args()[0]

algList = []
svcList = []

evtsvc = k4DataSvc("EventDataSvc")
svcList.append(evtsvc)
evtsvc = EventDataSvc("EventDataSvc")
iosvc = IOSvc()

svcList = [evtsvc, iosvc]
algList = []

CONFIG = {
"CalorimeterIntegrationTimeWindow": "10ns",
Expand All @@ -55,7 +58,6 @@

REC_COLLECTION_CONTENTS_FILE = "collections_rec_level.txt" # file with the collections to be patched in when writing from LCIO to EDM4hep

from Configurables import GeoSvc, TrackingCellIDEncodingSvc, Lcio2EDM4hepTool
geoservice = GeoSvc("GeoSvc")
geoservice.detectors = [reco_args.compactFile]
geoservice.OutputLevel = INFO
Expand Down Expand Up @@ -88,13 +90,8 @@
},
)

if reco_args.inputFiles:
read = create_reader(reco_args.inputFiles, evtsvc)
read.OutputLevel = INFO
algList.append(read)
else:
print('WARNING: No input files specified, the CLD Reconstruction will fail')
read = None
io_handler = IOHandlerHelper(algList, iosvc)
io_handler.add_reader(reco_args.inputFiles)

MyAIDAProcessor = MarlinProcessorWrapper("MyAIDAProcessor")
MyAIDAProcessor.OutputLevel = WARNING
Expand Down Expand Up @@ -149,11 +146,22 @@

# TODO: replace all the ugly strings by something sensible like Enum
if CONFIG["OutputMode"] == "LCIO":
Output_REC = create_writer("lcio", "Output_REC", f"{reco_args.outputBasename}_REC")
algList.append(Output_REC)
Output_REC = io_handler.add_lcio_writer("Output_REC")
Output_REC.Parameters = {
"LCIOOutputFile": [f"{reco_args.outputBasename}_REC.slcio"],
"LCIOWriteMode": ["WRITE_NEW"],
}

Output_DST = create_writer("lcio", "Output_DST", f"{reco_args.outputBasename}_DST", DST_KEEPLIST, DST_SUBSETLIST)
algList.append(Output_DST)
Output_DST = io_handler.add_lcio_writer("Output_DST")
dropped_types = ["MCParticle", "LCRelation", "SimCalorimeterHit", "CalorimeterHit", "SimTrackerHit", "TrackerHit", "TrackerHitPlane", "Track", "ReconstructedParticle", "LCFloatVec"]
Output_DST.Parameters = {
"LCIOOutputFile": [f"{reco_args.outputBasename}_DST.slcio"],
"LCIOWriteMode": ["WRITE_NEW"],
"DropCollectionNames": [],
"DropCollectionTypes": dropped_types,
"FullSubsetCollections": DST_SUBSETLIST,
"KeepCollectionNames": DST_KEEPLIST,
}

if CONFIG["OutputMode"] == "EDM4Hep":
# Make sure that all collections are always available by patching in missing ones on-the-fly
Expand All @@ -165,21 +173,14 @@
}
algList.append(collPatcherRec)

Output_REC = create_writer("edm4hep", "Output_REC", f"{reco_args.outputBasename}_REC")
algList.append(Output_REC)

io_handler.add_edm4hep_writer(f"{reco_args.outputBasename}_REC.edm4hep.root", ["keep *"])
# FIXME: needs https://github.com/key4hep/k4FWCore/issues/226
# Output_DST = create_writer("edm4hep", "Output_DST", f"{reco_args.outputBasename}_DST", DST_KEEPLIST)
# algList.append(Output_DST)

# <DST output for edm4hep>

# We need to convert the inputs in case we have EDM4hep input
attach_edm4hep2lcio_conversion(algList, read)

# We need to convert the outputs in case we have EDM4hep output
attach_lcio2edm4hep_conversion(algList)
# We need to attach all the necessary converters
io_handler.finalize_converters()

from Configurables import ApplicationMgr
ApplicationMgr( TopAlg = algList,
EvtSel = 'NONE',
EvtMax = 3, # Overridden by the --num-events switch to k4run
Expand Down