5 import os, sys, ROOT, argparse
7 from DCubeHistograms
import MyHistoFiller
9 if __name__ ==
"__main__":
10 parser = argparse.ArgumentParser(prog=
'createDCubeRecoHistograms', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
11 parser.add_argument(
'-i',
'--inputFile', help=
'choose input ROOT file', default=
'NSWPRDValAlg.reco.ntuple.root', type=str)
12 parser.add_argument(
'-o',
'--outputFile', help=
'choose output ROOT file', default=
'NSWPRDValAlg.reco.dcube.root', type=str)
13 parser.add_argument(
'--doCSC', help=
'turn on CSC if using Run4 input ROOT file', default=
False, action=
'store_true')
14 parser.add_argument(
'--doTGC', help=
'turn on TGC', default=
False, action=
'store_true')
15 parser.add_argument(
'--CSCsel', help=
'Choose eta_sector selections for CSC, e.g. positive_1 for positive eta and sector 1, None_None for no selection', default=
'None_None', type=str)
16 parser.add_argument(
'--TGCsel', help=
'Choose eta_sector selections for TGC, e.g. positive_1 for positive eta and sector 1, None_None for no selection', default=
'None_None', type=str)
18 Options = parser.parse_args()
20 ROOT.gROOT.SetBatch(
True)
22 if not os.path.exists(Options.inputFile):
23 print (
'ERROR: File %s does not exist'%Options.inputFile)
26 inputFile = ROOT.TFile(Options.inputFile,
"READ")
28 print (
'ERROR: Failed to open file %s'%Options.inputFile)
30 inputTree = inputFile.Get(
"NSWValTree")
32 print (
'ERROR: NSWValTree does not exist in file %s'%Options.inputFile)
35 nEntries = inputTree.GetEntries()
37 print (
'ERROR: NSWValTree of file %s has 0 entries'%Options.inputFile)
40 outputFile = ROOT.TFile(Options.outputFile,
"RECREATE")
42 print (
'ERROR: Failed to open file %s'%Options.outputFile)
46 outputFile.mkdir(
"reconstruction/")
47 ODir = outputFile.GetDirectory(
"reconstruction/")
50 CSCselections = Options.CSCsel.split(
"_")
51 CSC_eta = CSCselections[0]
52 if CSCselections[1] !=
"None":
53 CSC_sector = int (CSCselections[1])
55 CSC_sector = CSCselections[1]
57 TGCselections = Options.TGCsel.split(
"_")
58 TGC_eta = TGCselections[0]
59 if TGCselections[1] !=
"None":
60 TGC_sector = int (TGCselections[1])
62 TGC_sector = TGCselections[1]
65 for i
in range(inputTree.GetEntries()):
72 if CSC_eta ==
"positive":
73 csc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.PRD_CSC_stationEta[ncscPRD])) >= 0
74 elif CSC_eta ==
"negative":
75 csc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.PRD_CSC_stationEta[ncscPRD])) < 0
77 csc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.PRD_CSC_stationEta[ncscPRD])) < 9
79 if CSC_sector ==
"None":
80 csc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.PRD_CSC_stationPhi[ncscPRD])) < 10
82 csc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.PRD_CSC_stationPhi[ncscPRD])) == CSC_sector
84 for ncscPRD
in range(0,len(inputTree.PRD_CSC_localPosX)):
85 cscPRDHists += [
MyHistoFiller( chamber_name =
"CSC_PRD", eta_sel = csc_eta_sel, sector_sel = csc_sector_sel )]
86 cscPRDHists[ncscPRD].
fill(inputTree, ncscPRD)
92 if TGC_eta ==
"positive":
93 tgc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.PRD_TGC_stationEta[ntgcPRD])) >= 0
94 elif TGC_eta ==
"negative":
95 tgc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.PRD_TGC_stationEta[ntgcPRD])) < 0
97 tgc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.PRD_TGC_stationEta[ntgcPRD])) < 9
99 if TGC_sector ==
"None":
100 tgc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.PRD_TGC_stationPhi[ntgcPRD])) < 51
102 tgc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.PRD_TGC_stationPhi[ntgcPRD])) == TGC_sector
104 for ntgcPRD
in range(0,len(inputTree.PRD_TGC_localPosX)):
105 tgcPRDHists += [
MyHistoFiller( chamber_name =
"TGC_PRD", eta_sel = tgc_eta_sel, sector_sel = tgc_sector_sel )]
106 tgcPRDHists[ntgcPRD].
fill(inputTree, ntgcPRD)
111 cscPRDHist =
MyHistoFiller( chamber_name =
"CSC_PRD", eta_sel =
None, sector_sel =
None )
112 cscPRDHist.write(ODir)
115 tgcPRDHist =
MyHistoFiller( chamber_name =
"TGC_PRD", eta_sel =
None, sector_sel =
None )
116 tgcPRDHist.write(ODir)