5 import os, sys, ROOT, argparse
7 from DCubeHistograms
import MyHistoFiller
9 if __name__ ==
"__main__":
10 parser = argparse.ArgumentParser(prog=
'createDCubeDigitHistograms', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
11 parser.add_argument(
'-i',
'--inputFile', help=
'choose input ROOT file', default=
'NSWPRDValAlg.digi.ntuple.root', type=str)
12 parser.add_argument(
'-o',
'--outputFile', help=
'choose output ROOT file', default=
'NSWPRDValAlg.digi.dcube.root', type=str)
13 parser.add_argument(
'--doCSC', help=
'turn off CSC if using Run4 input ROOT file', default=
False, action=
'store_true')
14 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)
15 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)
16 parser.add_argument(
'--RPCsel', help=
'Choose eta_sector selections for RPC, e.g. positive_1 for positive eta and sector 1, None_None for no selection', default=
'None_None', type=str)
17 parser.add_argument(
'--MDTsel', help=
'Choose eta_sector selections for MDT, e.g. positive_1 for positive eta and sector 1, None_None for no selection', default=
'None_None', type=str)
19 Options = parser.parse_args()
21 ROOT.gROOT.SetBatch(
True)
23 if not os.path.exists(Options.inputFile):
24 print (
'ERROR: File %s does not exist'%Options.inputFile)
27 inputFile = ROOT.TFile(Options.inputFile,
"READ")
29 print (
'ERROR: Failed to open file %s'%Options.inputFile)
31 inputTree = inputFile.Get(
"NSWValTree")
33 print (
'ERROR: NSWValTree does not exist in file %s'%Options.inputFile)
36 nEntries = inputTree.GetEntries()
38 print (
'ERROR: NSWValTree of file %s has 0 entries'%Options.inputFile)
41 outputFile = ROOT.TFile(Options.outputFile,
"RECREATE")
43 print (
'ERROR: Failed to open file %s'%Options.outputFile)
48 outputFile.mkdir(
"digitization/")
49 ODir = outputFile.GetDirectory(
"digitization/")
52 CSCselections = Options.CSCsel.split(
"_")
53 CSC_eta = CSCselections[0]
54 if CSCselections[1] !=
"None":
55 CSC_sector = int (CSCselections[1])
57 CSC_sector = CSCselections[1]
59 TGCselections = Options.TGCsel.split(
"_")
60 TGC_eta = TGCselections[0]
61 if TGCselections[1] !=
"None":
62 TGC_sector = int (TGCselections[1])
64 TGC_sector = TGCselections[1]
66 RPCselections = Options.RPCsel.split(
"_")
67 RPC_eta = RPCselections[0]
68 if RPCselections[1] !=
"None":
69 RPC_sector = int (RPCselections[1])
71 RPC_sector = RPCselections[1]
73 MDTselections = Options.MDTsel.split(
"_")
74 MDT_eta = MDTselections[0]
75 if MDTselections[1] !=
"None":
76 MDT_sector = int (MDTselections[1])
78 MDT_sector = MDTselections[1]
83 for i
in range(inputTree.GetEntries()):
95 if Options.doCSC ==
True:
96 if CSC_eta ==
"positive":
97 csc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_CSC_stationEta[ncscDigit])) >= 0
98 elif CSC_eta ==
"negative":
99 csc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_CSC_stationEta[ncscDigit])) < 0
101 csc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_CSC_stationEta[ncscDigit])) < 9
103 if CSC_sector ==
"None":
104 csc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.Digits_CSC_stationPhi[ncscDigit])) < 10
106 csc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.Digits_CSC_stationPhi[ncscDigit])) == CSC_sector
108 for ncscDigit
in range(0,len(inputTree.Digits_CSC_globalPosX)):
109 cscDigitHists += [
MyHistoFiller( chamber_name =
"CSC_Digit", eta_sel = csc_eta_sel, sector_sel = csc_sector_sel )]
110 cscDigitHists[ncscDigit].
fill(inputTree, ncscDigit)
112 for ncscSDO
in range(0,len(inputTree.SDO_CSC_localPosX)):
113 cscSDOHists += [
MyHistoFiller( chamber_name =
"CSC_SDO", eta_sel = csc_eta_sel, sector_sel = csc_sector_sel )]
114 cscSDOHists[ncscSDO].
fill(inputTree, ncscSDO)
116 for ncscRDO
in range(0,len(inputTree.RDO_CSC_localPosX)):
117 cscRDOHists += [
MyHistoFiller( chamber_name =
"CSC_RDO", eta_sel = csc_eta_sel, sector_sel = csc_sector_sel )]
118 cscRDOHists[ncscRDO].
fill(inputTree, ncscRDO)
123 if TGC_eta ==
"positive":
124 tgc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_TGC_stationEta[ntgcDigit])) >= 0
125 elif TGC_eta ==
"negative":
126 tgc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_TGC_stationEta[ntgcDigit])) < 0
128 tgc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_TGC_stationEta[ntgcDigit])) < 9
130 if TGC_sector ==
"None":
131 tgc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.Digits_TGC_stationPhi[ntgcDigit])) < 51
133 tgc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.Digits_TGC_stationPhi[ntgcDigit])) == TGC_sector
135 for ntgcDigit
in range(0,len(inputTree.Digits_TGC_localPosX)):
136 tgcDigitHists += [
MyHistoFiller( chamber_name =
"TGC_Digit", eta_sel = tgc_eta_sel, sector_sel = tgc_sector_sel )]
137 tgcDigitHists[ntgcDigit].
fill(inputTree, ntgcDigit)
139 for ntgcSDO
in range(0,len(inputTree.SDO_TGC_localPosX)):
140 tgcSDOHists += [
MyHistoFiller( chamber_name =
"TGC_SDO", eta_sel = tgc_eta_sel, sector_sel = tgc_sector_sel )]
141 tgcSDOHists[ntgcSDO].
fill(inputTree, ntgcSDO)
143 for ntgcRDO
in range(0,len(inputTree.RDO_TGC_localPosX)):
144 tgcRDOHists += [
MyHistoFiller( chamber_name =
"TGC_RDO", eta_sel = tgc_eta_sel, sector_sel = tgc_sector_sel )]
145 tgcRDOHists[ntgcRDO].
fill(inputTree, ntgcRDO)
148 if RPC_eta ==
"positive":
149 rpc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_RPC_stationEta[nrpcDigit])) >= 0
150 elif RPC_eta ==
"negative":
151 rpc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_RPC_stationEta[nrpcDigit])) < 0
153 rpc_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_RPC_stationEta[nrpcDigit])) < 9
155 if RPC_sector ==
"None":
156 rpc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.Digits_RPC_stationPhi[nrpcDigit])) < 10
158 rpc_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.Digits_RPC_stationPhi[nrpcDigit])) == RPC_sector
160 for nrpcDigit
in range(0,len(inputTree.Digits_RPC_localPosX)):
161 rpcDigitHists += [
MyHistoFiller( chamber_name =
"RPC_Digit", eta_sel = rpc_eta_sel, sector_sel = rpc_sector_sel )]
162 rpcDigitHists[nrpcDigit].
fill(inputTree, nrpcDigit)
165 if MDT_eta ==
"positive":
166 mdt_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_MDT_stationEta[nmdtDigit])) >= 0
167 elif MDT_eta ==
"negative":
168 mdt_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_MDT_stationEta[nmdtDigit])) < 0
170 mdt_eta_sel =
lambda t: MyHistoFiller.Eta(ord(t.Digits_MDT_stationEta[nmdtDigit])) < 9
172 if MDT_sector ==
"None":
173 mdt_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.Digits_MDT_stationPhi[nmdtDigit])) < 10
175 mdt_sector_sel =
lambda s: MyHistoFiller.Eta(ord(s.Digits_MDT_stationPhi[nmdtDigit])) == MDT_sector
177 for nmdtDigit
in range(0,len(inputTree.Digits_MDT_localTubePosX)):
178 mdtDigitHists += [
MyHistoFiller( chamber_name =
"MDT_Digit", eta_sel = mdt_eta_sel, sector_sel = mdt_sector_sel )]
179 mdtDigitHists[nmdtDigit].
fill(inputTree, nmdtDigit)
183 if Options.doCSC ==
True:
184 cscDigitHist =
MyHistoFiller( chamber_name =
"CSC_Digit", eta_sel =
None, sector_sel =
None )
185 cscDigitHist.write(ODir)
187 cscSDOHist =
MyHistoFiller( chamber_name =
"CSC_SDO", eta_sel =
None, sector_sel =
None )
188 cscSDOHist.write(ODir)
190 cscRDOHist =
MyHistoFiller( chamber_name =
"CSC_RDO", eta_sel =
None, sector_sel =
None )
191 cscRDOHist.write(ODir)
193 tgcDigitHist =
MyHistoFiller( chamber_name =
"TGC_Digit", eta_sel =
None, sector_sel =
None )
194 tgcDigitHist.write(ODir)
196 tgcSDOHist =
MyHistoFiller( chamber_name =
"TGC_SDO", eta_sel =
None, sector_sel =
None )
197 tgcSDOHist.write(ODir)
199 tgcRDOHist =
MyHistoFiller( chamber_name =
"TGC_RDO", eta_sel =
None, sector_sel =
None )
200 tgcRDOHist.write(ODir)
202 rpcDigitHist =
MyHistoFiller( chamber_name =
"RPC_Digit", eta_sel =
None, sector_sel =
None )
203 rpcDigitHist.write(ODir)
205 mdtDigitHist =
MyHistoFiller( chamber_name =
"MDT_Digit", eta_sel =
None, sector_sel =
None )
206 mdtDigitHist.write(ODir)