Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #29

Merged
merged 4 commits into from
Apr 12, 2024
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
125 changes: 24 additions & 101 deletions CLDConfig/CLDReconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
# limitations under the License.
#
import os
import sys
from Gaudi.Configuration import *
from Gaudi.Configuration import INFO, WARNING, DEBUG

from Configurables import k4DataSvc, MarlinProcessorWrapper
from k4MarlinWrapper.parseConstants import *
from k4MarlinWrapper.inputReader import create_reader, attach_edm4hep2lcio_conversion
from k4FWCore.parseArgs import parser


parser.add_argument("--inputFiles", action="extend", nargs="+", metavar=("file1", "file2"), help="One or multiple input files")
parser.add_argument("--outputBasename", help="Basename of the output file(s)", default="output")
parser.add_argument("--trackingOnly", action="store_true", help="Run only track reconstruction", default=False)
reco_args = parser.parse_known_args()[0]

algList = []
svcList = []


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

Expand All @@ -38,8 +44,6 @@
"TrackingChoices": ["Truth", "Conformal"],
"VertexUnconstrained": "OFF",
"VertexUnconstrainedChoices": ["ON", "OFF"],
"InputMode": "LCIO",
"InputModeChoices": ["LCIO", "EDM4hep"], # could also mix inputs but then things get ugly
"OutputMode": "EDM4Hep",
"OutputModeChoices": ["LCIO", "EDM4hep"] #, "both"] FIXME: both is not implemented yet
}
Expand All @@ -57,106 +61,22 @@
cellIDSvc.OutputLevel = INFO
svcList.append(cellIDSvc)

output_basename = "output"

from k4FWCore.parseArgs import parser
parser.add_argument("--inputFiles", action="extend", nargs="+", metavar=("file1", "file2"), help="One or multiple input files")
parser.add_argument("--outputBasename", help="Basename of the output file(s)", default=output_basename)
parser.add_argument("--trackingOnly", action="store_true", help="Run only track reconstruction", default=False)
my_opts = parser.parse_known_args()[0]

output_basename = my_opts.outputBasename

# Set input files here or via --inputFiles
input_files = []

if my_opts.inputFiles is not None:
input_files = my_opts.inputFiles
print(f"opts: {my_opts}")
print(f"input_files: {input_files}")

if not input_files:
print("Error: missing input files, set them via --inputFiles")
sys.exit(1)

if input_files[0].endswith(".slcio"):
CONFIG["InputMode"] = "LCIO"
elif input_files[0].endswith(".root"):
CONFIG["InputMode"] = "EDM4hep"

if CONFIG["InputMode"] == "LCIO":
from Configurables import LcioEvent
read = LcioEvent()
read.OutputLevel = WARNING
read.Files = input_files
if reco_args.inputFiles:
read = create_reader(reco_args.inputFiles, evtsvc)
read.OutputLevel = INFO
algList.append(read)
elif CONFIG["InputMode"] == "EDM4hep":
evtsvc.inputs = input_files
from Configurables import PodioInput
inp = PodioInput('InputReader')
inp.collections = [
'EventHeader',
'MCParticles',
'VertexBarrelCollection',
'VertexEndcapCollection',
'InnerTrackerBarrelCollection',
'OuterTrackerBarrelCollection',
'ECalEndcapCollection',
'ECalEndcapCollectionContributions',
'ECalBarrelCollection',
'ECalBarrelCollectionContributions',
'HCalBarrelCollection',
'HCalBarrelCollectionContributions',
'InnerTrackerEndcapCollection',
'OuterTrackerEndcapCollection',
'HCalEndcapCollection',
'HCalEndcapCollectionContributions',
'HCalRingCollection',
'HCalRingCollectionContributions',
'YokeBarrelCollection',
'YokeBarrelCollectionContributions',
'YokeEndcapCollection',
'YokeEndcapCollectionContributions',
'LumiCalCollection',
'LumiCalCollectionContributions',
]
inp.OutputLevel = WARNING
algList.append(inp)
else:
read = None

MyAIDAProcessor = MarlinProcessorWrapper("MyAIDAProcessor")
MyAIDAProcessor.OutputLevel = WARNING
MyAIDAProcessor.ProcessorType = "AIDAProcessor"
MyAIDAProcessor.Parameters = {
"Compress": ["1"],
"FileName": [f"{output_basename}_aida"],
"FileName": [f"{reco_args.outputBasename}_aida"],
"FileType": ["root"]
}

if CONFIG["InputMode"] == "EDM4hep":
from Configurables import EDM4hep2LcioTool
EDM4hep2Lcio = EDM4hep2LcioTool("EDM4hep2Lcio")
EDM4hep2Lcio.convertAll = False
EDM4hep2Lcio.collNameMapping = {
'EventHeader': 'EventHeader',
'MCParticles': 'MCParticle',
'VertexBarrelCollection': 'VertexBarrelCollection',
'VertexEndcapCollection': 'VertexEndcapCollection',
'InnerTrackerBarrelCollection': 'InnerTrackerBarrelCollection',
'OuterTrackerBarrelCollection': 'OuterTrackerBarrelCollection',
'InnerTrackerEndcapCollection': 'InnerTrackerEndcapCollection',
'OuterTrackerEndcapCollection': 'OuterTrackerEndcapCollection',
'ECalEndcapCollection': 'ECalEndcapCollection',
'ECalBarrelCollection': 'ECalBarrelCollection',
'HCalBarrelCollection': 'HCalBarrelCollection',
'HCalEndcapCollection': 'HCalEndcapCollection',
'HCalRingCollection': 'HCalRingCollection',
'YokeBarrelCollection': 'YokeBarrelCollection',
'YokeEndcapCollection': 'YokeEndcapCollection',
'LumiCalCollection': 'LumiCalCollection',
}
EDM4hep2Lcio.OutputLevel = DEBUG
MyAIDAProcessor.EDM4hep2LcioTool = EDM4hep2Lcio

OverlayParameters = {
"MCParticleCollectionName": ["MCParticle"],
"MCPhysicsParticleCollectionName": ["MCPhysicsParticles"],
Expand Down Expand Up @@ -1130,7 +1050,7 @@
algList.append(Refit)

# calorimeter digitization and pandora
if not my_opts.trackingOnly:
if not reco_args.trackingOnly:
algList.append(MyDDCaloDigi[CONFIG["CalorimeterIntegrationTimeWindow"]])
algList.append(MyDDSimpleMuonDigi)
algList.append(MyDDMarlinPandora[CONFIG["CalorimeterIntegrationTimeWindow"]])
Expand All @@ -1140,7 +1060,7 @@
algList.append(MyRecoMCTruthLinker)
algList.append(MyTrackChecker)
# pfo selector (might need re-optimisation)
if not my_opts.trackingOnly:
if not reco_args.trackingOnly:
algList.append(MyCLICPfoSelectorDefault)
algList.append(MyCLICPfoSelectorLoose)
algList.append(MyCLICPfoSelectorTight)
Expand All @@ -1166,7 +1086,7 @@
"DropCollectionTypes": [],
"FullSubsetCollections": ["EfficientMCParticles", "InefficientMCParticles"],
"KeepCollectionNames": [],
"LCIOOutputFile": [f"{output_basename}_REC.slcio"],
"LCIOOutputFile": [f"{reco_args.outputBasename}_REC.slcio"],
"LCIOWriteMode": ["WRITE_NEW"]
}

Expand All @@ -1178,7 +1098,7 @@
"DropCollectionTypes": ["MCParticle", "LCRelation", "SimCalorimeterHit", "CalorimeterHit", "SimTrackerHit", "TrackerHit", "TrackerHitPlane", "Track", "ReconstructedParticle", "LCFloatVec"],
"FullSubsetCollections": ["EfficientMCParticles", "InefficientMCParticles", "MCPhysicsParticles"],
"KeepCollectionNames": ["MCParticlesSkimmed", "MCPhysicsParticles", "RecoMCTruthLink", "SiTracks", "SiTracks_Refitted", "PandoraClusters", "PandoraPFOs", "SelectedPandoraPFOs", "LooseSelectedPandoraPFOs", "TightSelectedPandoraPFOs", "RefinedVertexJets", "RefinedVertexJets_rel", "RefinedVertexJets_vtx", "RefinedVertexJets_vtx_RP", "BuildUpVertices", "BuildUpVertices_res", "BuildUpVertices_RP", "BuildUpVertices_res_RP", "BuildUpVertices_V0", "BuildUpVertices_V0_res", "BuildUpVertices_V0_RP", "BuildUpVertices_V0_res_RP", "PrimaryVertices", "PrimaryVertices_res", "PrimaryVertices_RP", "PrimaryVertices_res_RP", "RefinedVertices", "RefinedVertices_RP"],
"LCIOOutputFile": [f"{output_basename}_DST.slcio"],
"LCIOOutputFile": [f"{reco_args.outputBasename}_DST.slcio"],
"LCIOWriteMode": ["WRITE_NEW"]
}
algList.append(Output_REC)
Expand All @@ -1196,10 +1116,13 @@
EventNumber.Lcio2EDM4hepTool = lcioConvTool

from Configurables import PodioOutput
out = PodioOutput("PodioOutput", filename = f"{output_basename}_edm4hep.root")
out = PodioOutput("PodioOutput", filename = f"{reco_args.outputBasename}_edm4hep.root")
out.outputCommands = ["keep *"]
algList.append(out)

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

from Configurables import ApplicationMgr
ApplicationMgr( TopAlg = algList,
EvtSel = 'NONE',
Expand Down
Loading