21 from __future__
import print_function
26 from DataQualityUtils
import pathExtract, returnFilesPath
28 from ROOT
import gStyle, TCanvas
29 from ROOT
import TChain
30 from ROOT
import TH1D, TH2D, TH1I
36 global nbLArNoisyRO_Std
37 global nbLArNoisyRO_SatTight
39 if (tree.LArFlags & 8):nbNoiseBurstVeto[tree.LumiBlockN] = nbNoiseBurstVeto[tree.LumiBlockN] + 1
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]]
54 for iCE
in coordEnergy:
55 if (iCE[0] > thresholdE):
56 if (
"MET" in objectType):
58 if not (tree.LArFlags & 8):
59 h0mapClean.Fill(iCE[2])
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):
65 if (fabs(iCE[1]-etaSpot)<deltaSpot
and fabs(iCE[2]-phiSpot)<deltaSpot):
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
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')
93 args = parser.parse_args()
98 lowerLumiBlock = args.lowerLB
99 upperLumiBlock = args.upperLB
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
115 gStyle.SetOptStat(
"em")
117 if (
"MET" in objectType):
121 print(
'---------------------------------')
122 print(
"Investigation on run "+
str(run)+
"/"+stream+
" stream with ami TAG "+amiTag)
124 tree = TChain(
"POOLCollectionTree")
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))
132 print(
"No file found on EOS.Exiting...")
136 if len(listOfFiles)>0:
137 for files
in listOfFiles:
138 tree.AddFile(
"%s"%(files))
139 print(
"I chained the file %s"%(files))
141 print(
"No TAG file found in directory %s.Exiting..."%(tagDirectory))
144 entries = tree.GetEntries()
147 nbHitInHot = [0] * nLB
148 cumEnergInHot = [0] * nLB
149 nbNoiseBurstVeto = [0] * nLB
150 nbLArNoisyRO_Std = [0] * nLB
151 nbLArNoisyRO_SatTight = [0] * nLB
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)
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)
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 ):
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):
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!!!")
172 print(
"The LArCleaning (LArEventInfo != ERROR) for noise bursts has been activated")
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
185 if (args.larcleaning):
186 suffix =
"NO LArFlags cut"
188 suffix =
"LArFlags != ERROR"
191 if (upperLB>lowerLB):
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])
212 if (objectType ==
"MET"):
218 if (objectType ==
"MET"):
221 h0mapClean.Draw(
"COLZ")
224 if (
not args.noplot):
226 for i
in range(
min(len(nLB_offending),4)):
227 canvas.append(TCanvas())
228 iCurrent = len(canvas)-1
230 if (args.larcleaning):
233 cutC =
"!(LArFlags & 8)"
235 if (
"TopoCluster" in objectType):
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")
254 canvas[iCurrent].SetGridx(1)
255 canvas[iCurrent].SetGridy(1)
258 canvas.append(TCanvas())
260 if (
"TopoCluster" in objectType):
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))
279 if (
"Tau" in objectType):
280 print(
'WARNING : in recent TAGs, the TauJet were not filled - A double check is welcome: tree.Draw(\"TauJetEta1\")')
282 input(
"I am done...")