ATLAS Offline Software
RPCPostProcessing.py
Go to the documentation of this file.
1 #
2 #Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 
4 #
5 # import ROOT
6 
7 # local
8 import RpcRawDataMonitoring.RPCRawDataMonUtils as RPCRawDataMonUtils
9 import RpcRawDataMonitoring.CoreClass as CoreClass
10 import RpcRawDataMonitoring.GetLBInfoFromCOOL as GetLBInfoFromCOOL
11 
12 
14  # from xml.dom.minidom import parse
15  import xml.dom.minidom as Dom
16  import os
17  import ROOT
18 
19  # -- Get the validation xml file path
20  xml_file = ROOT.PathResolver.find_file("Element.xml", "DATAPATH", ROOT.PathResolver.RecursiveSearch)
21 
22  if not os.path.isfile(xml_file):
23  print ("ERROR: can NOT find xml file: %s!" %xml_file)
24  return
25 
26  dom = Dom.parse(xml_file)
27  root_node = dom.documentElement
28  ele_nodes = root_node.childNodes
29 
30  Dic_panels = {}
31  panel_property = {}
32  BMBO_StationNames = {2, 3, 4, 5, 8, 9, 10, 53}
33  for i_node in ele_nodes:
34  if i_node.nodeType != 1:
35  continue
36 
37  # node_name = i_node.nodeName
38  ele_index = int(i_node.getAttribute("index"))
39 
40  panel_property["stationName"] = int(i_node.getAttribute("stationName"))
41  panel_property["stationEta" ] = int(i_node.getAttribute("stationEta"))
42  panel_property["stationPhi" ] = int(i_node.getAttribute("stationPhi"))
43  panel_property["doubletR" ] = int(i_node.getAttribute("doubletR"))
44  panel_property["doubletZ" ] = int(i_node.getAttribute("doubletZ"))
45 
46  if panel_property["stationName"] in BMBO_StationNames:
47  ngasgap = 2
48  else:
49  ngasgap = 3
50 
51  for dbPhi in [1,2]:
52  for gasgap in range(1, ngasgap+1):
53  for measPhi in [0, 1]:
54  panel_property["doubletPhi"] = dbPhi
55  panel_property["gasGap"] = gasgap
56  panel_property["measPhi"] = measPhi
57 
58  panel_index = (ele_index-1)*8 + (dbPhi - 1)*4 + (gasgap - 1)*2 + measPhi
59  i_panel = RPCRawDataMonUtils.Panel(panel_property, panel_index)
60 
61  if not (panel_index in Dic_panels):
62  Dic_panels[panel_index] = i_panel
63  else:
64  print ("ERROR: duplicated panel index!!!")
65 
66  print ("RPCPostProcessing::readElementFromXML::INFO: count of read panels = %d" %(len(Dic_panels)))
67 
68  return Dic_panels
69 
70 
71 def getRun(h_run):
72  xbins = h_run.GetNbinsX()
73  runs = []
74 
75  for i_bin in range(1, xbins+1):
76  if h_run.GetBinContent(i_bin) > 0:
77  runs.append(int(h_run.GetBinLowEdge(i_bin))+1)
78 
79  return runs
80 
81 
82 def make_evt_lumi(inputs):
83  h_NEvt_LB = inputs[0][1][0].Clone()
84  h_run = inputs[0][1][1].Clone()
85  runs = getRun(h_run)
86 
87  Dic_LBLumi = GetLBInfoFromCOOL.GetLumiInfoDic(runs[0], runs[-1]+1)
88 
89  g_name = 'NEvent_VS_Lumi'
90  g_title = 'NEvent VS Lumi'
91  g_Xtitle = 'Inst Luminosity [10^{34} cm^{-2}s^{-1}]'
92  g_Ytitle = 'NEvent'
93 
94  x = []
95  y = []
96  y_err = []
97 
98  if Dic_LBLumi is not None:
99  print ("len(Dic_LBLumi) = ", len(Dic_LBLumi))
100 
101  for LB, lbInfo in Dic_LBLumi.items():
102  if lbInfo['AtlasPhysics'] == 'false' or float(lbInfo['Duration'])<50.:
103  continue
104 
105  hit_content = h_NEvt_LB.GetBinContent(LB)
106  hit_err = h_NEvt_LB.GetBinError(LB)
107 
108  x.append( float(lbInfo['InstLumi']) )
109  y.append( hit_content )
110  y_err.append( hit_err )
111 
112  x_err = [0]*len(x)
113 
114  g = RPCRawDataMonUtils.creatGraph(x, y, x_err, y_err, g_name, g_title, g_Xtitle, g_Ytitle)
115 
116  return [g]
117 
118 
119 def make_hit_rate(inputs):
120  h_hit_panels = inputs[0][1][0].Clone() # "NPRDHit_Panels_All"
121  h_NEvt_LB = inputs[0][1][1].Clone() # evtLB
122  h_run = inputs[0][1][2].Clone() # run
123 
124  runs = getRun(h_run)
125  if len(runs) > 1:
126  print ("make_hit_rate::WARNING - Input file contain data in ", len(runs), " **runs**, which should only include 1-run and full data !!!")
127  return
128 
129  dic_hists = {}
130 
131  Dic_LBLumi = GetLBInfoFromCOOL.GetLumiInfoDic(runs[0], runs[0]+1)
132 
133  if Dic_LBLumi is not None:
134  print ("len(Dic_LBLumi) = ", len(Dic_LBLumi))
135  # GetLBInfoFromCOOL.printLumiInfo(Dic_LBLumi)
136 
137  DicPanels = readElementFromXML()
138 
139 
140  draw_occu = CoreClass.Draw_Occupancy(h_hit_panels)
141  draw_occu.SetPanelDic(DicPanels)
142  draw_occu.SetLumiInfoDic(Dic_LBLumi)
143  draw_occu.doNEvtScale(h_NEvt_LB)
144 
145  h_name = "NPRDHit_Panels_All"
146 
147  # -----------------------------------------------------------------------
148  list_hist_all = []
149  list_hist_layer = []
150  list_hist_subDetector = []
151  for i_var in ["p0", "p1", "chi2", "predRate", "meanRate"]:
152 
155  list_hist1D_secLayer = draw_occu.GetHist1D_ySectorsAndLayers([h_name, i_var])
156 
157 
160  list_hist1D_panels = draw_occu.GetHist1D_yPanels([h_name, i_var])
161 
162  list_hist_all += list_hist1D_secLayer+list_hist1D_panels
163 
164 
167  list_summary_allSectorsAndLayers = draw_occu.GetSummary_allSectorsAndLayers([h_name, i_var])
168 
169 
172  list_hist2d_EtaPhi_allLayer = draw_occu.GetHist2D_EtaPhi_allLayer([h_name, i_var])
173 
174  list_hist_layer += list_summary_allSectorsAndLayers+list_hist2d_EtaPhi_allLayer
175 
176 
179  if i_var in ["p0", "chi2", "predRate"]:
180  list_summary_eachSectorsAndLayers = draw_occu.GetSummary_eachSectorsAndLayers([h_name, i_var])
181 
182  list_hist_subDetector += list_summary_eachSectorsAndLayers
183 
184  getHistNames(list_hist_all, "Muon/MuonRawDataMonitoring/RPC/RpcOccupancy/HitRate_vs_InstLumi", dic_hists)
185  getHistNames(list_hist_layer, "Muon/MuonRawDataMonitoring/RPC/RpcOccupancy/HitRate_vs_InstLumi/Layers", dic_hists)
186  getHistNames(list_hist_subDetector, "Muon/MuonRawDataMonitoring/RPC/RpcOccupancy/HitRate_vs_InstLumi/SubDetector", dic_hists)
187 
188  return dic_hists
189 
190 
191 def make_2dhits(inputs):
192  hist_2dhits = inputs[0][1][0].Clone() #"NPRDHit_Panels_All"
193  hist_projY = hist_2dhits.ProjectionY("NPRDHit_Panels_All_py")
194  DicPanels = readElementFromXML()
195 
196  draw_hits = CoreClass.Draw_2DCount(hist_projY)
197  draw_hits.SetPanelDic(DicPanels)
198 
199  h_name = "NPRDHit_Panels_All_py"
200 
201  # -----------------------------------------------------------------------
202  variable = "prdhits"
203  config = [h_name, variable]
204  dic_histos = {}
205 
206 
209  list_hist2d_EtaPhi_allLayer = draw_hits.GetHist2D_EtaPhi_allLayer(config, doSetZRange = False)
210  getHistNames(list_hist2d_EtaPhi_allLayer, "Muon/MuonRawDataMonitoring/RPC/RpcOccupancy/Hits", dic_histos)
211 
212  return dic_histos
213 
214 
215 
216 def make_hitMulti(inputs):
217  hist = inputs[0][1][0].Clone()
218  DicPanels = readElementFromXML()
219 
220  print ("make_hitMulti - hist = ", hist)
221 
222  draw_hitmulti = CoreClass.Draw_HitMultiplicity(hist)
223  draw_hitmulti.SetPanelDic(DicPanels)
224 
225  # -----------------------------------------------------------------------
226  # draw hit multiplicity
227  h_name = "HitMultiplicity_Panels"
228  variable = "hitMultiplicity"
229 
230 
233  list_hist1D_secLayer_hitMu = draw_hitmulti.GetHist1D_ySectorsAndLayers([h_name, variable])
234 
235 
238  list_hist1D_panels_hitMu = draw_hitmulti.GetHist1D_yPanels([h_name, variable])
239 
240  # -----------------------------------------------------------------------
241  # draw cluster size
242  h2_CS = "ClusterSize_Panels"
243  variable = "averageClusterSize"
244  hist_clus = inputs[0][1][1].Clone()
245  draw_clus = CoreClass.Draw_HitMultiplicity(hist_clus)
246  draw_clus.SetPanelDic(DicPanels)
247 
248 
251  list_hist1D_secLayer_cluster = draw_hitmulti.GetHist1D_ySectorsAndLayers([h2_CS, variable])
252 
253 
256  list_hist1D_panels_cluster = draw_hitmulti.GetHist1D_yPanels([h2_CS, variable])
257 
258  return list_hist1D_secLayer_hitMu+list_hist1D_panels_hitMu+list_hist1D_secLayer_cluster+list_hist1D_panels_cluster
259 
260 
261 def make_detection_eff(inputs):
262  hist = inputs[0][1][0].Clone()
263  DicPanels = readElementFromXML()
264 
265  draw_eff = CoreClass.Draw_DetectEfficiency(hist)
266  draw_eff.SetPanelDic(DicPanels)
267 
268  h_name = "Detection_Efficiency_MuonFromZ"
269 
270  # -----------------------------------------------------------------------
271  variable = "detEff"
272  config = [h_name, variable]
273  dic_histos = {}
274 
275 
278  list_summary_allSectorsAndLayers = draw_eff.GetSummary_allSectorsAndLayers(config)
279  getHistNames(list_summary_allSectorsAndLayers, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/MuonDetectionEff", dic_histos)
280 
281 
284  list_summary_eachSectorsAndLayers= draw_eff.GetSummary_eachSectorsAndLayers(config)
285  getHistNames(list_summary_eachSectorsAndLayers, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/MuonDetectionEff/SubDetector", dic_histos)
286 
287 
290  list_hist2d_EtaPhi_allLayer = draw_eff.GetHist2D_EtaPhi_allLayer(config)
291  getHistNames(list_hist2d_EtaPhi_allLayer, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/MuonDetectionEff", dic_histos)
292 
293 
296  list_hist1D_secLayer = draw_eff.GetHist1D_ySectorsAndLayers(config)
297  getHistNames(list_hist1D_secLayer, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/MuonDetectionEff", dic_histos)
298 
299 
302  list_hist1D_panels = draw_eff.GetHist1D_yPanels(config)
303  getHistNames(list_hist1D_panels, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/MuonDetectionEff", dic_histos)
304 
305  return dic_histos
306 
307 
308 def make_2d_nmuons_Z(inputs):
309  hist_eff = inputs[0][1][0].Clone() #"Detection_Efficiency_MuonFromZ"
310  DicPanels = readElementFromXML()
311 
312  dic_histos = {}
313 
316  hist_num = hist_eff.GetPassedHistogram()
317  draw_hits = CoreClass.Draw_2DCount(hist_num)
318  draw_hits.SetPanelDic(DicPanels)
319 
320  # -----------------------------------------------------------------------
321  h_name = "Muon_Z_ex2RpcPanelWithHit"
322  variable = "muon_Z_num"
323  config = [h_name, variable]
324 
325  # "muon_Z_num_layer[1-8]_measPhi[01]",
326  list_hist2d_EtaPhi_allLayer = draw_hits.GetHist2D_EtaPhi_allLayer(config, doSetZRange = False)
327  getHistNames(list_hist2d_EtaPhi_allLayer, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/NMuon", dic_histos)
328 
329 
332  hist_num = hist_eff.GetTotalHistogram()
333  draw_hits = CoreClass.Draw_2DCount(hist_num)
334  draw_hits.SetPanelDic(DicPanels)
335 
336  # -----------------------------------------------------------------------
337  h_name = "Muon_Z_ex2RpcPanel"
338  variable = "muon_Z_den"
339  config = [h_name, variable]
340 
341  # "muon_Z_den_layer[1-8]_measPhi[01]",
342  list_hist2d_EtaPhi_allLayer = draw_hits.GetHist2D_EtaPhi_allLayer(config, doSetZRange = False)
343  getHistNames(list_hist2d_EtaPhi_allLayer, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/NMuon", dic_histos)
344 
345  return dic_histos
346 
347 
348 def make_2d_nmuons_all(inputs):
349  hist_eff = inputs[0][1][0].Clone() #"Detection_Efficiency_AllMuons"
350  DicPanels = readElementFromXML()
351 
352  dic_histos = {}
353 
356  hist_num = hist_eff.GetPassedHistogram()
357  draw_hits = CoreClass.Draw_2DCount(hist_num)
358  draw_hits.SetPanelDic(DicPanels)
359 
360  # -----------------------------------------------------------------------
361  h_name = "Muon_all_ex2RpcPanelWithHit"
362  variable = "muon_all_num"
363  config = [h_name, variable]
364 
365  # "muon_all_num_layer[1-8]_measPhi[01]",
366  list_hist2d_EtaPhi_allLayer = draw_hits.GetHist2D_EtaPhi_allLayer(config, doSetZRange = False)
367  getHistNames(list_hist2d_EtaPhi_allLayer, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/NMuon", dic_histos)
368 
369 
372  hist_num = hist_eff.GetTotalHistogram()
373  draw_hits = CoreClass.Draw_2DCount(hist_num)
374  draw_hits.SetPanelDic(DicPanels)
375 
376  # -----------------------------------------------------------------------
377  h_name = "Muon_all_ex2RpcPanel"
378  variable = "muon_all_den"
379  config = [h_name, variable]
380 
381  # "muon_all_den_layer[1-8]_measPhi[01]",
382  list_hist2d_EtaPhi_allLayer = draw_hits.GetHist2D_EtaPhi_allLayer(config, doSetZRange = False)
383  getHistNames(list_hist2d_EtaPhi_allLayer, "Muon/MuonRawDataMonitoring/RPC/TrackMatch/NMuon", dic_histos)
384 
385  return dic_histos
386 
387 
388 def make_hitFrac(inputs):
389  DicPanels = readElementFromXML()
390 
391 
392  # -----------------------------------------------------------------------
393  # out-of-time fraction of hits
394  # -----------------------------------------------------------------------
395  hist = inputs[0][1][0].Clone()
396  draw_histFrac = CoreClass.Draw_HitOuttimeFraction(hist)
397  draw_histFrac.SetPanelDic(DicPanels)
398 
399  h_name = "OuttimeHitFraction_PRDHit"
400  var = "outTimeHitFrac"
401  config = [h_name, var]
402 
403 
406  list_hist1D_secLayer_hitFrac = draw_histFrac.GetHist1D_ySectorsAndLayers(config)
407 
408 
411  list_hist1D_panels_hitFrac = draw_histFrac.GetHist1D_yPanels(config)
412 
413  # -----------------------------------------------------------------------
414  # out-of-time fraction of hits on track
415  # -----------------------------------------------------------------------
416  hist_onTrack = inputs[0][1][1].Clone()
417  draw_histFrac_onTrack = CoreClass.Draw_HitOuttimeFraction(hist_onTrack)
418  draw_histFrac_onTrack.SetPanelDic(DicPanels)
419 
420  h_name = "OuttimeHitFraction_PRDHit_onTrack"
421  var = "outTimeHitFrac_onTrack"
422  config = [h_name, var]
423 
424 
427  list_hist1D_secLayer_hitFracOnTrack = draw_histFrac_onTrack.GetHist1D_ySectorsAndLayers(config)
428 
429 
432  list_hist1D_panels_hitFracOnTrack = draw_histFrac_onTrack.GetHist1D_yPanels(config)
433 
434  return list_hist1D_secLayer_hitFrac+list_hist1D_panels_hitFrac+list_hist1D_secLayer_hitFracOnTrack+list_hist1D_panels_hitFracOnTrack
435 
436 
437 
438 def getHistNames(hist_list, prefix, dic_hist):
439  for i_hist in hist_list:
440  i_name = "%s/%s" %(prefix, i_hist.GetName())
441  dic_hist[i_name] = i_hist
442 
443 
444 
445 if __name__ == '__main__':
446  print ("RPCPostProcessing: Hello, World !")
447 
448  # infile = ROOT.TFile("ExampleMonitorOutput.root", "READ")
449  # hist = infile.Get("run_358615/Muon/MuonRawDataMonitoring/RPC/RpcOccupancy/NPRDHit_Panels_All")
450  # inputs = [[0, [hist]]]
451  # dic_ = make_2dhits(inputs)
452 
RPCPostProcessing.getHistNames
def getHistNames(hist_list, prefix, dic_hist)
Definition: RPCPostProcessing.py:438
RPCRawDataMonUtils.Panel
Definition: RPCRawDataMonUtils.py:76
RPCPostProcessing.make_2d_nmuons_Z
def make_2d_nmuons_Z(inputs)
Definition: RPCPostProcessing.py:308
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CoreClass.Draw_HitMultiplicity
Definition: CoreClass.py:875
RPCRawDataMonUtils.creatGraph
def creatGraph(xs, ys, x_errs, y_errs, g_name, g_title, g_Xtitle, g_Ytitle)
Definition: RPCRawDataMonUtils.py:8
CoreClass.Draw_DetectEfficiency
Definition: CoreClass.py:974
GetLBInfoFromCOOL.GetLumiInfoDic
def GetLumiInfoDic(beg_run, end_run)
Definition: GetLBInfoFromCOOL.py:193
CoreClass.Draw_2DCount
Definition: CoreClass.py:1148
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
RPCPostProcessing.make_2d_nmuons_all
def make_2d_nmuons_all(inputs)
Definition: RPCPostProcessing.py:348
RPCPostProcessing.make_hitFrac
def make_hitFrac(inputs)
Definition: RPCPostProcessing.py:388
RPCPostProcessing.make_detection_eff
def make_detection_eff(inputs)
Definition: RPCPostProcessing.py:261
RPCPostProcessing.make_2dhits
def make_2dhits(inputs)
Definition: RPCPostProcessing.py:191
RPCPostProcessing.make_hitMulti
def make_hitMulti(inputs)
Definition: RPCPostProcessing.py:216
RPCPostProcessing.getRun
def getRun(h_run)
Definition: RPCPostProcessing.py:71
RPCPostProcessing.make_evt_lumi
def make_evt_lumi(inputs)
Definition: RPCPostProcessing.py:82
RPCPostProcessing.make_hit_rate
def make_hit_rate(inputs)
Definition: RPCPostProcessing.py:119
RPCPostProcessing.readElementFromXML
def readElementFromXML()
Definition: RPCPostProcessing.py:13
CoreClass.Draw_Occupancy
Definition: CoreClass.py:661
readCCLHist.float
float
Definition: readCCLHist.py:83
CoreClass.Draw_HitOuttimeFraction
Definition: CoreClass.py:1073