From e7786ec1ef5f67070c431f0b79b47181332e8b4f Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Tue, 9 Apr 2024 17:25:01 +0200 Subject: [PATCH 1/4] move parser and rename args --- CLDConfig/CLDReconstruction.py | 38 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index 2353b8c..fa21c83 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -22,10 +22,17 @@ from Configurables import k4DataSvc, MarlinProcessorWrapper from k4MarlinWrapper.parseConstants import * +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) @@ -57,21 +64,8 @@ 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 +if reco_args.inputFiles is not None: + input_files = reco_args.inputFiles print(f"opts: {my_opts}") print(f"input_files: {input_files}") @@ -128,7 +122,7 @@ MyAIDAProcessor.ProcessorType = "AIDAProcessor" MyAIDAProcessor.Parameters = { "Compress": ["1"], - "FileName": [f"{output_basename}_aida"], + "FileName": [f"{reco_args.outputBasename}_aida"], "FileType": ["root"] } @@ -1130,7 +1124,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"]]) @@ -1140,7 +1134,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) @@ -1166,7 +1160,7 @@ "DropCollectionTypes": [], "FullSubsetCollections": ["EfficientMCParticles", "InefficientMCParticles"], "KeepCollectionNames": [], - "LCIOOutputFile": [f"{output_basename}_REC.slcio"], + "LCIOOutputFile": [f"{reco_args.outputBasename}_REC.slcio"], "LCIOWriteMode": ["WRITE_NEW"] } @@ -1178,7 +1172,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) @@ -1196,7 +1190,7 @@ 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) From a42b7e7c5a075ea4f6209c6c4d48a70e6243fbf0 Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Tue, 9 Apr 2024 17:26:46 +0200 Subject: [PATCH 2/4] explicitly import output levels --- CLDConfig/CLDReconstruction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index fa21c83..b972e1b 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -18,7 +18,7 @@ # 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 0c239950667635793535f8c3934ca1ff4db7fd4e Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Tue, 9 Apr 2024 17:27:58 +0200 Subject: [PATCH 3/4] remove unused constant parsing --- CLDConfig/CLDReconstruction.py | 1 - 1 file changed, 1 deletion(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index b972e1b..2adeb80 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -21,7 +21,6 @@ from Gaudi.Configuration import INFO, WARNING, DEBUG from Configurables import k4DataSvc, MarlinProcessorWrapper -from k4MarlinWrapper.parseConstants import * from k4FWCore.parseArgs import parser From 507fddc3e7ba8c06f18d40d7c3bd90a36610df57 Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Thu, 11 Apr 2024 10:42:23 +0200 Subject: [PATCH 4/4] use new convenience functions for reading --- CLDConfig/CLDReconstruction.py | 88 ++++------------------------------ 1 file changed, 9 insertions(+), 79 deletions(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index 2adeb80..b82f84a 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -17,10 +17,10 @@ # limitations under the License. # import os -import sys from Gaudi.Configuration import INFO, WARNING, DEBUG from Configurables import k4DataSvc, MarlinProcessorWrapper +from k4MarlinWrapper.inputReader import create_reader, attach_edm4hep2lcio_conversion from k4FWCore.parseArgs import parser @@ -44,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 } @@ -63,58 +61,12 @@ cellIDSvc.OutputLevel = INFO svcList.append(cellIDSvc) -if reco_args.inputFiles is not None: - input_files = reco_args.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 @@ -125,31 +77,6 @@ "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"], @@ -1193,6 +1120,9 @@ 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',