2from argparse
import ArgumentParser
7parser = ArgumentParser()
8parser.add_argument(
"-f",
"--inputFile", dest=
"inputFile", help=
"single input file", required=
True)
9parser.add_argument(
"-g",
"--geoFile", dest=
"geoFile", help=
"geofile", required=
False)
10parser.add_argument(
"-o",
"--withOutput", dest=
"withOutput", help=
"persistent output", action=
'store_true',default=
False)
11parser.add_argument(
"-s",
"--saveTo", dest=
"outPath", help=
"output storage path", type=str,default=
"",required=
False)
12parser.add_argument(
"-par",
"--parFile", dest=
"parFile", help=
"parameter file", required=
False, default=os.environ[
'SNDSW_ROOT']+
"/python/TrackingParams.xml")
13parser.add_argument(
"-c",
"--case", dest=
"trackingCase", help=
"type of tracks to build. Should match the 'tracking_case' name in parFile, use quotes", required=
True)
14parser.add_argument(
"-hf",
"--HoughSpaceFormat", dest=
"HspaceFormat", help=
"Hough space representation. Should match the 'Hough_space_format' name in parFile, use quotes", required=
True)
15parser.add_argument(
"-n",
"--nEvents", dest=
"nEvents", type=int, help=
"number of events to process", default=1100000)
16parser.add_argument(
"-i",
"--firstEvent",dest=
"firstEvent", help=
"First event of input file to use", required=
False, default=0, type=int)
17parser.add_argument(
"-sc",
"--scale",dest=
"scaleFactor", help=
"Run reconstruction once for a randomly selected event in every [scaleFactor] events.", required=
False, default=1, type=int)
19options = parser.parse_args()
22filename = x[x.rfind(
'/')+1:]
24 runN = x[x.rfind(
'/run_')+5:x.rfind(
'/run_')+11]
25 path = x[:x.rfind(
'/run_')+1]
28 path = x[:x.rfind(
'/')+1]
29outFileName = options.outPath+filename.replace(
'.root',
'_'+runN+
'_muonReco.root')
34if not options.geoFile:
36 print(
'\033[91m'+
'Error!'+
'\033[0m'+
' No run number detected. Must provide a geo file then!')
38 if options.inputFile.find(
'TI18')<0:
39 if options.inputFile.find(
'physics/2022')>=0: options.geoFile = path+
"geofile_sndlhc_TI18_V0_2022.root"
42 options.geoFile =
"geofile_sndlhc_TI18_V3_08August2022.root"
43 elif int(runN) < 4855:
44 options.geoFile =
"geofile_sndlhc_TI18_V5_14August2022.root"
45 elif int(runN) < 5172:
46 options.geoFile =
"geofile_sndlhc_TI18_V6_08October2022.root"
48 options.geoFile =
"geofile_sndlhc_TI18_V7_22November2022.root"
51 if int(runN) >= 4791
and int(runN) <= 5429: path =
"/eos/experiment/sndlhc/convertedData/physics/2022/"
52 options.geoFile = path + options.geoFile
55if (options.inputFile.find(
'/TI18')>=0
and options.geoFile.find(
'V0_2022')>=0 )
or \
56 (options.inputFile.find(
'physics/2022')>=0
and options.geoFile.find(
'/TI18')>=0 )
or \
57 (options.inputFile.find(
'/TI18')>=0
and options.geoFile.find(
'/TI18')>=0
and int(runN) >= 4791
and int(runN) <= 5429 ):
58 print(
'\033[91m'+
'Error!'+
'\033[0m'+
' Consider a different geo file for that input file! Exitting..')
62lsOfGlobals = ROOT.gROOT.GetListOfGlobals()
63lsOfGlobals.Add(geo.modules[
'Scifi'])
64lsOfGlobals.Add(geo.modules[
'MuFilter'])
66fullPath = options.inputFile
67if options.inputFile.find(
'/eos/experiment')==0:
68 fullPath = os.environ[
'EOSSHIP']+options.inputFile
69F = ROOT.TFile.Open(fullPath)
72 outFile = ROOT.TFile(outFileName,
'RECREATE')
74 outFile = ROOT.TMemFile(outFileName,
'CREATE')
77for test_treename
in [
"rawConv",
"cbmsim"] :
78 if hasattr(F, test_treename) :
79 treename = test_treename
83 raise RuntimeError(
"File {0} contains no object with a valid SND@LHC TTree name".format(fullPath))
85fairRootManager = ROOT.FairRootManager.Instance()
86fairRootManager.SetTreeName(treename)
88run = ROOT.FairRunAna()
89print(
"Initialized FairRunAna")
91source = ROOT.FairFileSource(F)
94sink = ROOT.FairRootFileSink(outFile)
96fairRootManager.InitSink()
98run.SetEventHeaderPersistence(
False)
101run.AddTask(muon_reco_task)
107muon_reco_task.SetParFile(options.parFile)
108muon_reco_task.SetTrackingCase(options.trackingCase)
109muon_reco_task.SetHoughSpaceFormat(options.HspaceFormat)
112muon_reco_task.SetStandalone()
116print(
"Setting a scale factor to:", options.scaleFactor)
117muon_reco_task.SetScaleFactor(options.scaleFactor)
120nEvents = min( options.nEvents, source.GetEntries())
122run.Run(options.firstEvent, options.firstEvent + nEvents)
124print(
'Real Time:', w.RealTime(),
' CPU time: ', w.CpuTime())