ATLAS Offline Software
hotSpotInTAG.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 # Script to browse a TAG file and extract LBs for which at least N occurences of an object is found
5 # in a region defined as noisy.
6 # Uses the pathExtract library to extract the EOS path
7 # Options:
8 # -h, --help show this help message and exit
9 # -r RUN, --run=RUN Run number
10 # -s STREAMS, --stream=STREAMS Data stream : express/CosmicCalo/JetTauEtmiss/Egamma
11 # -a AMI, --amiTag=AMI ami Tag - Simply set x/f to choose express/bulk processing
12 # -e ETA, --eta=ETA Eta of hot spot
13 # -p PHI, --phi=PHI Phi of hot spot (or MET bump)
14 # -c THRESHOLD, --treshold=THRESHOLD Et/pt threshold (in MeV)
15 # -d DELTA, --delta=DELTA Distance to look around hot spot (or MET bump)
16 # -o OBJECT, --object=OBJECT TopoCluster/Jet/LoosePhoton/TauJet/MET
17 # -m MIN, --min=MIN Min number of object in a LB
18 # -n, --noplot Do not plot LB map
19 # Author : Benjamin Trocme (LPSC Grenoble) / Summer 2012, updated in 2015
20 
21 from __future__ import print_function
22 
23 import sys
24 from math import fabs
25 import argparse
26 from DataQualityUtils import pathExtract, returnFilesPath
27 
28 from ROOT import gStyle, TCanvas
29 from ROOT import TChain
30 from ROOT import TH1D, TH2D, TH1I
31 
32 # Analysis functions===========================================================================================================
34  global nbHitInHot
35  global cumEnergInHot
36  global nbLArNoisyRO_Std
37  global nbLArNoisyRO_SatTight
38 
39  if (tree.LArFlags & 8):nbNoiseBurstVeto[tree.LumiBlockN] = nbNoiseBurstVeto[tree.LumiBlockN] + 1
40  # Fill the list of coordinates depending on the object type
41  if ("TopoCluster" in objectType):
42  coordEnergy = [[tree.TopoClusterEt1,tree.TopoClusterEta1,tree.TopoClusterPhi1]]
43  if ("Jet" in objectType):
44  coordEnergy = [[tree.JetPt1,tree.JetEta1,tree.JetPhi1],[tree.JetPt2,tree.JetEta2,tree.JetPhi2],[tree.JetPt3,tree.JetEta3,tree.JetPhi3],[tree.JetPt4,tree.JetEta4,tree.JetPhi4],[tree.JetPt5,tree.JetEta5,tree.JetPhi5],[tree.JetPt6,tree.JetEta6,tree.JetPhi6]]
45  if ("LoosePhoton" in objectType):
46  coordEnergy = [[tree.LoosePhotonPt1,tree.LoosePhotonEta1,tree.LoosePhotonPhi1],[tree.LoosePhotonPt2,tree.LoosePhotonEta2,tree.LoosePhotonPhi2]]
47  if ("LooseElectron" in objectType):
48  coordEnergy = [[tree.LooseElectronPt1,tree.LooseElectronEta1,tree.LooseElectronPhi1],[tree.LooseElectronPt2,tree.LooseElectronEta2,tree.LooseElectronPhi2],[tree.LooseElectronPt3,tree.LooseElectronEta3,tree.LooseElectronPhi3],[tree.LooseElectronPt4,tree.LooseElectronEta4,tree.LooseElectronPhi4]]
49  if ("Tau" in objectType):
50  coordEnergy = [[tree.TauJetPt1,tree.TauJetEta1,tree.TauJetPhi1],[tree.TauJetPt2,tree.TauJetEta2,tree.TauJetPhi2]]
51  if ("MET" in objectType):
52  coordEnergy = [[tree.CellMissingET,0,tree.CellMissingETPhi]]
53  # Loop on the list of coordinates to analyze them
54  for iCE in coordEnergy:
55  if (iCE[0] > thresholdE):
56  if ("MET" in objectType): # Fill general map
57  h0map.Fill(iCE[2])
58  if not (tree.LArFlags & 8):
59  h0mapClean.Fill(iCE[2])
60  else:
61  h0map.Fill(iCE[1],iCE[2])
62  if not (tree.LArFlags & 8):
63  h0mapClean.Fill(iCE[1],iCE[2])
64  if not ((not args.larcleaning) and tree.LArFlags & 8): # Explicit cut LArEventInfo != ERROR to remove noise bursts is larcleaning is false
65  if (fabs(iCE[1]-etaSpot)<deltaSpot and fabs(iCE[2]-phiSpot)<deltaSpot): # A candidate has been found in suspicious region - Explict cut LArEventInfo != ERROR to remove noise bursts
66 # if (fabs(iCE[1]-etaSpot)<deltaSpot and fabs(iCE[2]-phiSpot)<deltaSpot and not (tree.LArFlags & 8)): # A candidate has been found in suspicious region - Explict cut LArEventInfo != ERROR to remove noise bursts
67  nbHitInHot[tree.LumiBlockN]=nbHitInHot[tree.LumiBlockN] + 1
68  cumEnergInHot[tree.LumiBlockN]=cumEnergInHot[tree.LumiBlockN]+iCE[0]
69  if (tree.LArFlags & 1): nbLArNoisyRO_Std[tree.LumiBlockN] = nbLArNoisyRO_Std[tree.LumiBlockN] + 1
70  if (tree.LArFlags & 4): nbLArNoisyRO_SatTight[tree.LumiBlockN] = nbLArNoisyRO_SatTight[tree.LumiBlockN] + 1
71 
72  return
73 
74 
75 # Main===========================================================================================================
76 parser = argparse.ArgumentParser()
77 parser.add_argument('-r','--run',type=int,dest='runNumber',default='267599',help="Run number",action='store')
78 parser.add_argument('-ll','--lowerlb',type=int,dest='lowerLB',default='0',help="Lower lb",action='store')
79 parser.add_argument('-ul','--upperlb',type=int,dest='upperLB',default='999999',help="Upper lb",action='store')
80 parser.add_argument('-s','--stream',dest='stream',default='express',help="Stream without prefix: express, CosmicCalo, Egamma...",action='store')
81 parser.add_argument('-t','--tag',dest='tag',default='data16_13TeV',help="DAQ tag: data12_8TeV, data12_calocomm...",action='store')
82 parser.add_argument('-a','--amiTag',dest='amiTag',default='x',help="First letter of AMI tag: x->express / f->bulk",action='store')
83 parser.add_argument('-e','--eta',type=float,dest='etaSpot',default='0',help='Eta of hot spot',action='store')
84 parser.add_argument('-p','--phi',type=float,dest='phiSpot',default='0.',help='Phi of hot spot (or MET bump)',action='store')
85 parser.add_argument('-c','--cut',type=int,dest='thresholdE',default='1000',help='Et/pt threshold (in MeV)',action='store')
86 parser.add_argument('-d','--delta',type=float,dest='deltaSpot',default='0.1',help='Distance to look around hot spot (or MET bump)',action='store')
87 parser.add_argument('-o','--object',dest='objectType',default='TopoCluster',help='TopoCluster/Jet/LoosePhoton/LooseElectron/TauJet/MET',action='store')
88 parser.add_argument('-m','--min',type=int,dest='minInLB',default='5',help='Min number of object in a LB',action='store')
89 parser.add_argument('-n','--noplot',dest='noplot',help='Do not plot LB map',action='store_true')
90 parser.add_argument('-l','--larcleaning',dest='larcleaning',help='Ignore LAr cleaning to find hot spot',action='store_true')
91 parser.add_argument('-f','--files',dest='fileDirectory',default='',help='Read directory TAG files from local directory specified',action='store')
92 
93 args = parser.parse_args()
94 
95 #parser.print_help()
96 
97 run = args.runNumber
98 lowerLumiBlock = args.lowerLB
99 upperLumiBlock = args.upperLB
100 stream = args.stream
101 tag = args.tag
102 amiTag = args.amiTag
103 etaSpot = args.etaSpot
104 phiSpot = args.phiSpot
105 thresholdE = args.thresholdE
106 deltaSpot = args.deltaSpot
107 objectType = args.objectType
108 minInLB = args.minInLB
109 tagDirectory = args.fileDirectory
110 
111 # Line below commented to work with release 21.
112 # Not sure what was its purpose...
113 #gROOT.Reset()
114 gStyle.SetPalette(1)
115 gStyle.SetOptStat("em")
116 
117 if ("MET" in objectType):
118  etaSpot=0
119 
120 print('\n')
121 print('---------------------------------')
122 print("Investigation on run "+str(run)+"/"+stream+" stream with ami TAG "+amiTag)
123 
124 tree = TChain("POOLCollectionTree")
125 if tagDirectory=="": # TAG files stored on EOS
126  listOfFiles = pathExtract.returnEosTagPath(run,stream,amiTag,tag)
127  if len(listOfFiles)>0:
128  for files in listOfFiles:
129  tree.AddFile("root://eosatlas/%s"%(files))
130  print("I chained the file %s"%(files))
131  else:
132  print("No file found on EOS.Exiting...")
133  sys.exit()
134 else: # TAG files on user account
135  listOfFiles = returnFilesPath(tagDirectory,"TAG")
136  if len(listOfFiles)>0:
137  for files in listOfFiles:
138  tree.AddFile("%s"%(files))
139  print("I chained the file %s"%(files))
140  else:
141  print("No TAG file found in directory %s.Exiting..."%(tagDirectory))
142 
143 
144 entries = tree.GetEntries()
145 
146 nLB=2500
147 nbHitInHot = [0] * nLB
148 cumEnergInHot = [0] * nLB
149 nbNoiseBurstVeto = [0] * nLB
150 nbLArNoisyRO_Std = [0] * nLB
151 nbLArNoisyRO_SatTight = [0] * nLB
152 
153 if ("MET" in objectType):
154  h0map = TH1D("map","General map of %s with MET > %d MeV"%(objectType,thresholdE),64,-3.14,3.14)
155  h0mapClean = TH1D("mapClean","General map of %s with MET > %d MeV - LArFlags != ERROR"%(objectType,thresholdE),64,-3.14,3.14)
156 else:
157  h0map = TH2D("map","General map of %s with Et/Pt > %d MeV"%(objectType,thresholdE),90,-4.5,4.5,64,-3.14,3.14)
158  h0mapClean = TH2D("mapClean","General map of %s with Et/Pt > %d MeV - LArFlags != ERROR"%(objectType,thresholdE),90,-4.5,4.5,64,-3.14,3.14)
159 
160 print("I am looking for LBs with at least %d %s in a region of %.2f around (%.2f,%.2f) and Et/Pt > %d MeV"%(minInLB,objectType,deltaSpot,etaSpot,phiSpot,thresholdE))
161 for jentry in range( entries ): # Loop on all events
162  if (jentry % 100000 == 0):
163  print("%d / %d evnt processed"%(jentry,entries))
164  nb = tree.GetEntry( jentry )
165  if (tree.LumiBlockN>lowerLumiBlock and tree.LumiBlockN<upperLumiBlock):
166  analyzeTree()
167 
168 print("I have looked for LBs with at least %d %s in a region of %.2f around (%.2f,%.2f) and Et/Pt > %d MeV"%(minInLB,objectType,deltaSpot,etaSpot,phiSpot,thresholdE))
169 if (args.larcleaning):
170  print("WARNING : The LArCleaning for noise bursts (LArEventInfo != ERROR) has been DEACTIVATED!!!")
171 else:
172  print("The LArCleaning (LArEventInfo != ERROR) for noise bursts has been activated")
173 
174 nLB_offending = []
175 lowerLB = 2500
176 upperLB = 0
177 for i in range(nLB):
178  if nbHitInHot[i]>=minInLB:
179  print("LB: %d -> %d hits (LAr flag in this LB : %d veto / In these events : %d Std / %d SatTight)"%(i,nbHitInHot[i],nbNoiseBurstVeto[i],nbLArNoisyRO_Std[i],nbLArNoisyRO_SatTight[i]))
180  nLB_offending.append(i)
181  if i<lowerLB : lowerLB = i
182  if i>upperLB : upperLB = i
183 
184 
185 if (args.larcleaning):
186  suffix = "NO LArFlags cut"
187 else:
188  suffix = "LArFlags != ERROR"
189 
190 # Plot evolution vs LB
191 if (upperLB>lowerLB): # check that at least one noisy LB was found
192  c0 = TCanvas()
193  h0Evol = TH1I("h0Evol","Nb of hits in a region of %.2f around (%.2f,%.2f) and Et/Pt > %d MeV - %s"%(deltaSpot,etaSpot,phiSpot,thresholdE,suffix),upperLB-lowerLB+1,lowerLB-0.5,upperLB+0.5)
194  h0Evol.SetXTitle("LumiBlock")
195  h0Evol_E = TH1I("h0Evol_E","Mean E/pt in a region of %.2f around (%.2f,%.2f) and Et/Pt > %d MeV - %s"%(deltaSpot,etaSpot,phiSpot,thresholdE,suffix),upperLB-lowerLB+1,lowerLB-0.5,upperLB+0.5)
196  h0Evol_E.SetXTitle("LumiBlock")
197  if ("MET" in objectType):
198  h0Evol.SetTitle("Nb of events with MET in a phi region of %.2f around %.2f and MET > %d MeV - %s"%(deltaSpot,phiSpot,thresholdE,suffix))
199  h0Evol_E.SetTitle("Mean MET in a phi region of %.2f around %.2f and MET > %d MeV - %s"%(deltaSpot,phiSpot,thresholdE,suffix))
200  for i in range(lowerLB,upperLB+1):
201  h0Evol.Fill(i,nbHitInHot[i])
202  if (nbHitInHot[i]>0):
203  h0Evol_E.Fill(i,cumEnergInHot[i]/nbHitInHot[i])
204  c0.Divide(1,2)
205  c0.cd(1)
206  h0Evol.Draw()
207  c0.cd(2)
208  h0Evol_E.Draw()
209  c0.Update()
210 
211 c0_2 = TCanvas()
212 if (objectType == "MET"):
213  h0map.Draw()
214 else:
215  h0map.Draw("COLZ")
216 
217 c0_3 = TCanvas()
218 if (objectType == "MET"):
219  h0mapClean.Draw()
220 else:
221  h0mapClean.Draw("COLZ")
222 
223 # Plot individual map for each LB. Can be switched off with "-n"
224 if (not args.noplot):
225  canvas = []
226  for i in range(min(len(nLB_offending),4)):
227  canvas.append(TCanvas())
228  iCurrent = len(canvas)-1
229 
230  if (args.larcleaning):
231  cutC = "1" # Accept all events
232  else:
233  cutC = "!(LArFlags & 8)" # Reject events flagged with LArEventInfo::ERROR
234 
235  if ("TopoCluster" in objectType):
236 # tree.Draw("TopoClusterPhi1:TopoClusterEta1 >> h1_%d"%(nLB_offending[i]),"TopoClusterEt1 > %d && LumiBlockN==%d && !(LArFlags & 8)"%(thresholdE,nLB_offending[i]),"COLZ")
237  tree.Draw("TopoClusterPhi1:TopoClusterEta1 >> h1_%d"%(nLB_offending[i]),"TopoClusterEt1 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
238  if ("Jet" in objectType):
239  tree.Draw("JetPhi1:JetEta1 >> h1_%d"%(nLB_offending[i]),"JetPt1 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
240  tree.Draw("JetPhi2:JetEta2 >> +h1_%d"%(nLB_offending[i]),"JetPt2 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
241  tree.Draw("JetPhi3:JetEta3 >> +h1_%d"%(nLB_offending[i]),"JetPt3 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
242  tree.Draw("JetPhi4:JetEta4 >> +h1_%d"%(nLB_offending[i]),"JetPt4 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
243  tree.Draw("JetPhi5:JetEta5 >> +h1_%d"%(nLB_offending[i]),"JetPt5 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
244  tree.Draw("JetPhi6:JetEta6 >> +h1_%d"%(nLB_offending[i]),"JetPt6 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
245  if ("MET" in objectType):
246  tree.Draw("CellMissingETPhi >> h1_%d"%(nLB_offending[i]),"CellMissingET > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC))
247  if ("LoosePhoton" in objectType):
248  tree.Draw("LoosePhotonPhi1:LoosePhotonEta1 >> h1_%d"%(nLB_offending[i]),"LoosePhotonPt1 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
249  tree.Draw("LoosePhotonPhi2:LoosePhotonEta2 >> +h1_%d"%(nLB_offending[i]),"LoosePhotonPt2 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
250  if ("Tau" in objectType):
251  tree.Draw("TauJetPhi1:TauJetEta1 >> h1_%d"%(nLB_offending[i]),"TauJetPt1 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
252  tree.Draw("TauJetPhi2:TauJetEta2 >> +h1_%d"%(nLB_offending[i]),"TauJetPt2 > %d && LumiBlockN==%d && %s"%(thresholdE,nLB_offending[i],cutC),"COLZ")
253 
254  canvas[iCurrent].SetGridx(1)
255  canvas[iCurrent].SetGridy(1)
256 # canvas[iCurrent].SetLogz(1)
257 
258  canvas.append(TCanvas())
259 
260  if ("TopoCluster" in objectType):
261 # tree.Draw("TopoClusterEt1 >> h1Et_%d"%(nLB_offending[i]),"abs(TopoClusterEta1-%.3f) < %.3f && abs(TopoClusterPhi1-%.3f) < %.3f && LumiBlockN==%d && !(LArFlags & 8)"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i]))
262  tree.Draw("TopoClusterEt1 >> h1Et_%d"%(nLB_offending[i]),"abs(TopoClusterEta1-%.3f) < %.3f && abs(TopoClusterPhi1-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
263  if ("Jet" in objectType):
264  tree.Draw("JetPt1 >> h1Pt_%d"%(nLB_offending[i]),"abs(JetEta1-%.3f) < %.3f && abs(JetPhi1-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
265  tree.Draw("JetPt2 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta2-%.3f) < %.3f && abs(JetPhi2-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
266  tree.Draw("JetPt3 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta3-%.3f) < %.3f && abs(JetPhi3-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
267  tree.Draw("JetPt4 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta4-%.3f) < %.3f && abs(JetPhi4-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
268  tree.Draw("JetPt5 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta5-%.3f) < %.3f && abs(JetPhi5-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
269  tree.Draw("JetPt6 >> +h1Pt_%d"%(nLB_offending[i]),"abs(JetEta6-%.3f) < %.3f && abs(JetPhi6-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
270  if ("MET" in objectType):
271  tree.Draw("CellMissingET >> h1Pt_%d"%(nLB_offending[i]),"abs(CellMissingETPhi-%.3f) < %.3f && LumiBlockN==%d && %s"%(phiSpot,deltaSpot,nLB_offending[i],cutC))
272  if ("LoosePhoton" in objectType):
273  tree.Draw("LoosePhotonPt1 >> h1Pt_%d"%(nLB_offending[i]),"abs(LoosePhotonEta1-%.3f) < %.3f && abs(LoosePhotonPhi1-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
274  tree.Draw("LoosePhotonPt2 >> +h1Pt_%d"%(nLB_offending[i]),"abs(LoosePhotonEta2-%.3f) < %.3f && abs(LoosePhotonPhi2-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
275  if ("Tau" in objectType):
276  tree.Draw("TauJetPt1 >> h1Pt_%d"%(nLB_offending[i]),"abs(TauJetEta1-%.3f) < %.3f && abs(TauJetPhi1-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
277  tree.Draw("TauJetPt2 >> +h1Pt_%d"%(nLB_offending[i]),"abs(TauJetEta2-%.3f) < %.3f && abs(TauJetPhi2-%.3f) < %.3f && LumiBlockN==%d && %s"%(etaSpot,deltaSpot,phiSpot,deltaSpot,nLB_offending[i],cutC))
278 
279 if ("Tau" in objectType):
280  print('WARNING : in recent TAGs, the TauJet were not filled - A double check is welcome: tree.Draw(\"TauJetEta1\")')
281 
282 input("I am done...")
hotSpotInTAG.analyzeTree
def analyzeTree()
Definition: hotSpotInTAG.py:33
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
min
#define min(a, b)
Definition: cfImp.cxx:40
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
str
Definition: BTagTrackIpAccessor.cxx:11
python.pathExtract.returnFilesPath
def returnFilesPath(directory=".", filterName="")
Definition: pathExtract.py:171