ATLAS Offline Software
extractSporadic.py
Go to the documentation of this file.
1 #!/usr/bin env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 from __future__ import print_function
6 
7 # ======================================================================
8 def printProperties(h,q,hLB):
9 
10  print ("=======================Harware coordinates :",h.GetName()[0:h.GetName().find("Phi")-1])
11  print ("Coordinates : Eta = ",h.GetName()[h.GetName().find("Eta")+3:h.GetName().find("Eta")+7]," Phi = ",h.GetName()[h.GetName().find("Phi")+3:h.GetName().find("Phi")+7])
12 
13 
14  # Nb of events with E>20GeV and mean energy
15  nbEvts20GeV = 0
16  meanE = 0
17  for ix in range(61,h.GetNbinsX()+2):# Bin 61 = 20GeV
18  nbEvts20GeV = nbEvts20GeV+h.GetBinContent(ix)
19  meanE = meanE + h.GetBinContent(ix)*h.GetBinCenter(ix)
20  meanE = meanE / nbEvts20GeV/ 1000
21 
22  # Nb of events with q factor > 4000
23  nbEvts4000 = 0
24  for ix in range(11,q.GetNbinsX()+2):# Bin 11 = 4000
25  nbEvts4000 = nbEvts4000 + q.GetBinContent(ix)
26 
27  # Nb of LBs where at least one event with E>20GeV is found
28  nbLB20GeV = 0
29  allLBs = ""
30  for ix in range(1,hLB.GetNbinsX()+1):
31  lbAff = False
32  for iy in range(61,hLB.GetNbinsY()+2):# Bin 61 = 20GeV
33  if hLB.GetBinContent(ix,iy) != 0:
34  lbAff = True
35  if lbAff:
36  nbLB20GeV = nbLB20GeV+1
37  allLBs = allLBs + " %d"%ix
38 
39  print ("# of events: E>20GeV / E>20GeV && q>4000 : %d / %d"%(nbEvts4000,nbEvts20GeV))
40  print ("Mean energy above 20geV: %.2f GeV"%meanE)
41  print (nbLB20GeV," LBs contains energetic events: ", allLBs )
42  return
43 
44 # ======================================================================
45 def displayHistos(h,q,hLB,canvas):
46  canvas.Divide(1,2)
47  canvas.cd(1)
48  ROOT.gPad.Divide(2,1)
49  ROOT.gPad.cd(1)
50  ROOT.gPad.SetLogy()
51  gStyle.SetOptStat(100110)
52  h.Draw()
53 
54  canvas.cd(1)
55  ROOT.gPad.cd(2)
56  q.Draw()
57 
58  canvas.cd(2)
59  hLB.SetStats(0)
60  hLB.Draw("COLZ")
61 
62  canvas.cd()
63  return
64 
65 
66 # Main =================================================================
67 import sys
68 
69 if len(sys.argv)<4:
70  print ("python -i extractSporadic.py 159041 x29_m545 EMBA [FT29Sl2Ch68]")
71  print ("If no channel is specified, displays all with more than 20 events above 20 GeV")
72  sys.exit()
73 
74 #os.system("nsls /castor/cern.ch/grid/atlas/tzero/prod1/perm/data10_7TeV/physics_CosmicCalo/0"+sys.argv[1])
75 
76 import ROOT
77 from ROOT import gROOT, gDirectory
78 from ROOT import gStyle, TCanvas
79 from ROOT import TRFIOFile
80 
81 gROOT.Reset()
82 gStyle.SetPalette(1)
83 
84 nameFile = "/castor/cern.ch/grid/atlas/tzero/prod1/perm/data10_7TeV/physics_CosmicCalo/0"+sys.argv[1]+"/data10_7TeV.00"+sys.argv[1]+".physics_CosmicCalo.merge.HIST."+sys.argv[2]+"/data10_7TeV.00"+sys.argv[1]+".physics_CosmicCalo.merge.HIST."+sys.argv[2]+"._0001.1"
85 nameDir = "run_"+sys.argv[1]+"/CaloMonitoring/LArCellMon_NoTrigSel/Sporadic20GeV/"+sys.argv[3]
86 
87 myFile = TRFIOFile(nameFile)
88 
89 # General numbers
90 hNbEvts = myFile.Get("run_"+sys.argv[1]+"/LAr/FEBMon/perPartitionData/Eventtype")
91 print ("This stream contains %d events"%hNbEvts.GetEntries())
92 
93 myFile.cd(nameDir)
94 
95 # Compile all channels
96 if len(sys.argv) == 4:
97  h=[]
98  q=[]
99  hLB=[]
100  listOfKeys = gDirectory.GetListOfKeys()
101  for key in listOfKeys:
102  name = key.GetName()
103  type = key.GetClassName()
104  if type == "TH1F" and name.find("EN") != -1 :
105  h.append(myFile.Get(nameDir+"/"+name))
106  if type == "TH1F" and name.find("Quality") != -1 :
107  q.append(myFile.Get(nameDir+"/"+name))
108  if type == "TH2F" and name.find("ENLB") != -1 :
109  hLB.append(myFile.Get(nameDir+"/"+name))
110 
111  nhists = len(h)
112  print ("retrieved %i histos"%nhists)
113 
114  for i in range(0, nhists):
115  if h[i].Integral(61,h[i].GetNbinsX()+1) >= 20:
116  printProperties(h[i],q[i],hLB[i])
117 
118 # Extract the corresponding channel
119 if len(sys.argv) == 5:
120  nameHisto = sys.argv[4]
121  listOfKeys = gDirectory.GetListOfKeys()
122  for key in listOfKeys:
123  name = key.GetName()
124  type = key.GetClassName()
125  if type == "TH1F" and name.find("EN") != -1 and name.find(nameHisto) != -1:
126  h = myFile.Get(nameDir+"/"+name)
127  if type == "TH2F" and name.find("ENLB") != -1 and name.find(nameHisto) != -1:
128  hLB = myFile.Get(nameDir+"/"+name)
129  if type == "TH1F" and name.find("Quality") != -1 and name.find(nameHisto) != -1:
130  q = myFile.Get(nameDir+"/"+name)
131 
132  if (h != 0):
133  printProperties(h,q,hLB)
134  c1 = TCanvas('c1','c1',1000,600)
135  displayHistos(h,q,hLB,c1)
136 
137 
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
extractSporadic.printProperties
def printProperties(h, q, hLB)
Definition: extractSporadic.py:8
extractSporadic.displayHistos
def displayHistos(h, q, hLB, canvas)
Definition: extractSporadic.py:45