ATLAS Offline Software
createDCubeDigitHistograms_withSel.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2 
3 # this script can be used to create DCube histograms from the output ntuples of NSWPRDValAlg
4 
5 import os, sys, ROOT, argparse
6 import math
7 from DCubeHistograms import MyHistoFiller
8 
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)
18 
19  Options = parser.parse_args()
20 
21  ROOT.gROOT.SetBatch(True)
22 
23  if not os.path.exists(Options.inputFile):
24  print ('ERROR: File %s does not exist'%Options.inputFile)
25  sys.exit(1)
26 
27  inputFile = ROOT.TFile(Options.inputFile, "READ")
28  if not inputFile:
29  print ('ERROR: Failed to open file %s'%Options.inputFile)
30  sys.exit(1)
31  inputTree = inputFile.Get("NSWValTree")
32  if not inputTree:
33  print ('ERROR: NSWValTree does not exist in file %s'%Options.inputFile)
34  sys.exit(1)
35 
36  nEntries = inputTree.GetEntries()
37  if nEntries==0:
38  print ('ERROR: NSWValTree of file %s has 0 entries'%Options.inputFile)
39  sys.exit(1)
40 
41  outputFile = ROOT.TFile(Options.outputFile, "RECREATE")
42  if not outputFile:
43  print ('ERROR: Failed to open file %s'%Options.outputFile)
44  sys.exit(1)
45 
46 
47  outputFile.cd()
48  outputFile.mkdir("digitization/")
49  ODir = outputFile.GetDirectory("digitization/")
50  ODir.cd()
51 
52  CSCselections = Options.CSCsel.split("_")
53  CSC_eta = CSCselections[0]
54  if CSCselections[1] != "None":
55  CSC_sector = int (CSCselections[1])
56  else:
57  CSC_sector = CSCselections[1]
58 
59  TGCselections = Options.TGCsel.split("_")
60  TGC_eta = TGCselections[0]
61  if TGCselections[1] != "None":
62  TGC_sector = int (TGCselections[1])
63  else:
64  TGC_sector = TGCselections[1]
65 
66  RPCselections = Options.RPCsel.split("_")
67  RPC_eta = RPCselections[0]
68  if RPCselections[1] != "None":
69  RPC_sector = int (RPCselections[1])
70  else:
71  RPC_sector = RPCselections[1]
72 
73  MDTselections = Options.MDTsel.split("_")
74  MDT_eta = MDTselections[0]
75  if MDTselections[1] != "None":
76  MDT_sector = int (MDTselections[1])
77  else:
78  MDT_sector = MDTselections[1]
79 
80 
81 
82  #Filling
83  for i in range(inputTree.GetEntries()):
84  inputTree.GetEntry(i)
85  cscDigitHists = []
86  cscSDOHists = []
87  cscRDOHists = []
88  tgcDigitHists = []
89  tgcSDOHists = []
90  tgcRDOHists = []
91  rpcDigitHists = []
92  mdtDigitHists = []
93 
94  # CSCs
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
100  else:
101  csc_eta_sel = lambda t: MyHistoFiller.Eta(ord(t.Digits_CSC_stationEta[ncscDigit])) < 9
102 
103  if CSC_sector == "None":
104  csc_sector_sel = lambda s: MyHistoFiller.Eta(ord(s.Digits_CSC_stationPhi[ncscDigit])) < 10
105  else:
106  csc_sector_sel = lambda s: MyHistoFiller.Eta(ord(s.Digits_CSC_stationPhi[ncscDigit])) == CSC_sector
107 
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)
111 
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)
115 
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)
119 
120 
121 
122  # TGCs
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
127  else:
128  tgc_eta_sel = lambda t: MyHistoFiller.Eta(ord(t.Digits_TGC_stationEta[ntgcDigit])) < 9
129 
130  if TGC_sector == "None":
131  tgc_sector_sel = lambda s: MyHistoFiller.Eta(ord(s.Digits_TGC_stationPhi[ntgcDigit])) < 51
132  else:
133  tgc_sector_sel = lambda s: MyHistoFiller.Eta(ord(s.Digits_TGC_stationPhi[ntgcDigit])) == TGC_sector
134 
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)
138 
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)
142 
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)
146 
147  # RPCs
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
152  else:
153  rpc_eta_sel = lambda t: MyHistoFiller.Eta(ord(t.Digits_RPC_stationEta[nrpcDigit])) < 9
154 
155  if RPC_sector == "None":
156  rpc_sector_sel = lambda s: MyHistoFiller.Eta(ord(s.Digits_RPC_stationPhi[nrpcDigit])) < 10
157  else:
158  rpc_sector_sel = lambda s: MyHistoFiller.Eta(ord(s.Digits_RPC_stationPhi[nrpcDigit])) == RPC_sector
159 
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)
163 
164  # MDTs
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
169  else:
170  mdt_eta_sel = lambda t: MyHistoFiller.Eta(ord(t.Digits_MDT_stationEta[nmdtDigit])) < 9
171 
172  if MDT_sector == "None":
173  mdt_sector_sel = lambda s: MyHistoFiller.Eta(ord(s.Digits_MDT_stationPhi[nmdtDigit])) < 10
174  else:
175  mdt_sector_sel = lambda s: MyHistoFiller.Eta(ord(s.Digits_MDT_stationPhi[nmdtDigit])) == MDT_sector
176 
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)
180 
181 
182  #Writing
183  if Options.doCSC == True:
184  cscDigitHist = MyHistoFiller( chamber_name = "CSC_Digit", eta_sel = None, sector_sel = None )
185  cscDigitHist.write(ODir)
186 
187  cscSDOHist = MyHistoFiller( chamber_name = "CSC_SDO", eta_sel = None, sector_sel = None )
188  cscSDOHist.write(ODir)
189 
190  cscRDOHist = MyHistoFiller( chamber_name = "CSC_RDO", eta_sel = None, sector_sel = None )
191  cscRDOHist.write(ODir)
192 
193  tgcDigitHist = MyHistoFiller( chamber_name = "TGC_Digit", eta_sel = None, sector_sel = None )
194  tgcDigitHist.write(ODir)
195 
196  tgcSDOHist = MyHistoFiller( chamber_name = "TGC_SDO", eta_sel = None, sector_sel = None )
197  tgcSDOHist.write(ODir)
198 
199  tgcRDOHist = MyHistoFiller( chamber_name = "TGC_RDO", eta_sel = None, sector_sel = None )
200  tgcRDOHist.write(ODir)
201 
202  rpcDigitHist = MyHistoFiller( chamber_name = "RPC_Digit", eta_sel = None, sector_sel = None )
203  rpcDigitHist.write(ODir)
204 
205  mdtDigitHist = MyHistoFiller( chamber_name = "MDT_Digit", eta_sel = None, sector_sel = None )
206  mdtDigitHist.write(ODir)
207 
208 
DCubeHistograms.MyHistoFiller
Definition: DCubeHistograms.py:7
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95