71 f1 =
"%s::%s" % (db1, options.folderBS)
72 f2 =
"%s::%s" % (db2, options.folderLumi)
75 print(
"Comparing: " )
76 print(
" * ", f1, options.tagBS )
77 print(
" * ", f2, options.tagLumi )
80 requiredForNtuple = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ']
81 checkNtupleProd =
all(item
in varColl
for item
in requiredForNtuple)
82 if not checkNtupleProd:
83 print(
'Ntuple will not be filled missing vars' )
87 from PyCool
import cool
88 from CoolConvUtilities
import AtlCoolLib
89 cooldbBS = AtlCoolLib.indirectOpen(db1,
True,
False)
90 cooldbLumi = AtlCoolLib.indirectOpen(db2,
True,
False)
92 folderBS = cooldbBS.getFolder(options.folderBS)
93 folderLumi = cooldbLumi.getFolder(options.folderLumi)
96 coolQuery = COOLQuery()
98 if options.runMin
is not None:
99 iov1 = options.runMin << 32
100 if options.runMax
is not None:
101 iov2 = (options.runMax +1) << 32
103 iov2 = (options.runMin +1) << 32
104 print(
'Plotting iovs %i to %i ' % (iov1,iov2) )
106 print(
'No run selected -- ERROR' )
109 if (iov2>cool.ValidityKeyMax):
110 iov2=cool.ValidityKeyMax
112 print(
"Reading data from database" )
113 itrBS = folderBS.browseObjects(iov1, iov2, cool.ChannelSelection.all(), options.tagBS)
114 print(
"...finished getting BS data" )
118 startRLB =0x7FFFFFFFFFFFFFFF
121 outfile = ROOT.TFile(
"BeamspotLumi_%i.root" % (options.runMin),
"recreate")
122 ntuple = ROOT.TNtupleD(
'BeamspotLumi',
'BeamSpotLumi',
"x:y:z:sigma_x:sigma_y:sigma_z:run:mu:lumi:year:month:day:hour:minute:epoch" )
126 while itrBS.goToNext():
128 obj = itrBS.currentRef()
132 runBegin = since >> 32
133 lumiBegin = since & 0xFFFFFFFF
136 runUntil = until >> 32
137 lumiUntil = until & 0xFFFFFFFF
139 status =
int(obj.payloadValue(
'status'))
153 values[var] =
float(obj.payloadValue(var))
154 values[var+
'Err'] =
float(obj.payloadValue(var+
'Err'))
155 values[
'until'] = until
156 lbDict[since] = values
158 print(
'Runs: ',runs )
167 sqtrt2pi = math.sqrt(2*math.pi)
169 lblb = CoolDataReader(
'COOLONL_TRIGGER/CONDBR2',
'/TRIGGER/LUMI/LBLB')
170 from DQUtils.sugar
import RANGEIOV_VAL, RunLumi
171 from DQUtils
import IOVSet
174 grlIOVs=IOVSet.from_grl(
"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data22_13p6TeV/20221123/data22_13p6TeV.periodEFH_DetStatus-v108-pro28-01_MERGED_PHYS_StandardGRL_All_Good_25ns_ignore__TRIG_HLT_MUO_Upstream_Barrel_problem__TRIG_HLT_MUO_Upstream_Endcap_problem__TRIG_L1_MUB_coverage__TRIG_L1_MUE_misconf_electronics__TRIG_L1_MUB_lost_sync.xml")
184 iov2 = (run + 1) << 32
186 itrLumi = folderLumi.browseObjects(iov1, iov2, cool.ChannelSelection(0), options.tagLumi)
187 print(
"...finished getting Lumi data for run %i" % run )
189 lblb.setIOVRangeFromRun(run)
191 if len(lblb.data) < 1:
192 print(
'No LBLB data found!' )
196 for obj
in lblb.data:
197 lblbMap[obj.since()] = (obj.payload()[
'StartTime'], obj.payload()[
'EndTime'])
200 while itrLumi.goToNext():
201 obj = itrLumi.currentRef()
204 runBegin = since >> 32
205 lumiBegin = since & 0xFFFFFFFF
208 runUntil = until >> 32
209 lumiUntil = until & 0xFFFFFFFF
212 for sinceGRL, untilGRL, grl_states
in process_iovs(grlIOVs):
213 if grl_states[0].since==
None:
215 if ( sinceGRL.run <= runBegin
and untilGRL.run >= runUntil
and sinceGRL.lumi <= lumiBegin
and untilGRL.lumi >= lumiUntil ):
222 mu =
float(obj.payloadValue(
'LBAvEvtsPerBX'))
223 instlumi =
float(obj.payloadValue(
'LBAvInstLumi'))
229 if lbDict[ since ][
'sigmaX'] > 0.1 :
231 startTime = lblbMap.get(obj.since(), (0., 0.))[0]
232 endTime = lblbMap.get(lbDict[ since ][
'until'], (0., 0.))[0]
233 mylumi = (endTime - startTime)/1e9 * instlumi/1e9
234 thisTime = time.gmtime( startTime /1.e9 )
241 lumi.append( mylumi );
245 if options.plotSomething:
247 if not var
in ydDict:
248 ydDict[var] =
array(
'd')
249 ydDict2[var] =
array(
'd')
250 eydDict[var] =
array(
'd')
252 ydDict2[var].
append( mu/(lbDict[ since ][var] * sqtrt2pi ))
253 ydDict[var].
append( lbDict[ since ][var] )
254 eydDict[var].
append( lbDict[ since ][var+
'Err'] )
256 if checkNtupleProd
and lbDict[ since ][
'sigmaZErr'] < 5 :
257 ntuple.Fill( lbDict[ since ][
'posX'], lbDict[ since ][
'posY'], lbDict[ since ][
'posZ'], lbDict[ since ][
'sigmaX'], lbDict[ since ][
'sigmaY'], lbDict[ since ][
'sigmaZ'],runBegin, mu, mylumi, year, month, day,hour, mins, startTime /1.e9 )
260 runStart = startRLB >> 32
261 runEnd = endRLB >> 32
262 fillStart = fillEnd = 0
263 timeStart = timeEnd = 0
266 timeStart = coolQuery.lbTime(
int(startRLB >> 32),
int(startRLB & 0xFFFFFFFF) )[0]
270 timeEnd = coolQuery.lbTime(
int(endRLB >> 32),
int(endRLB & 0xFFFFFFFF)-1 )[1]
274 fillStart = coolQuery.getLHCInfo(timeStart).
get(
'FillNumber',0)
278 fillEnd = coolQuery.getLHCInfo(timeEnd).
get(
'FillNumber',0)
284 if not options.plotSomething:
287 from InDetBeamSpotExample
import ROOTUtils
289 canvas = ROOT.TCanvas(
'BeamSpotComparison',
'BeamSpotComparison', 1600, 1200)
292 ROOT.gPad.SetTopMargin(0.05)
293 ROOT.gPad.SetLeftMargin(0.15)
294 ROOT.gPad.SetRightMargin(0.05)
296 if not options.plotGraph:
297 ROOT.gPad.SetRightMargin(0.15)
302 if var
not in ydDict:
303 print(
'Missing yd: ',var )
304 if var
not in eydDict:
305 print(
'Missing eyd: ',var )
308 gr = ROOT.TGraphErrors(len(xd), xd, ydDict[var], exd, eydDict[var])
311 ymin =
min(ydDict[var])
312 ymax =
max(ydDict[var])
316 ymaxSmall = ymax + 0.25*h
319 ymin2 =
min(ydDict2[var])
320 ymax2 =
max(ydDict2[var])
331 histo = ROOT.TH2D(
'hd'+var,
'hd'+var, 100, xmin, xmax, 100, ymin, ymax)
332 histo.GetYaxis().SetTitle(
varDef(var,
'atit',var))
333 histo.GetXaxis().SetTitle(
'Average interactions per bunch crossing')
334 histo.GetZaxis().SetTitle(
'Entries')
336 histo2 = ROOT.TH2D(
'hd2'+var,
'hd2'+var, 100, xmin, xmax, 100, ymin2, ymax2)
337 histo2.GetYaxis().SetTitle(
"<Interaction density> @ z=0 [interactions/mm]")
338 histo2.GetXaxis().SetTitle(
'Average interactions per bunch crossing')
339 histo2.GetZaxis().SetTitle(
'Entries')
341 histo2W = ROOT.TH2D(
'hd3'+var,
'hd3'+var, 100, xmin, xmax, 100, ymin2, ymax2)
342 histo2W.GetYaxis().SetTitle(
"<Interaction density> @ z=0 [interactions/mm]")
343 histo2W.GetXaxis().SetTitle(
'Average interactions per bunch crossing')
344 histo2W.GetZaxis().SetTitle(
'Integrated Luminosity (fb^{-1}/bin)')
346 histoW = ROOT.TH2D(
'hdW'+var,
'hdW'+var, 100, xmin, xmax, 100, ymin, ymax)
347 histoW.GetYaxis().SetTitle(
varDef(var,
'atit',var))
348 histoW.GetXaxis().SetTitle(
'Average interactions per bunch crossing')
349 histoW.GetZaxis().SetTitle(
'Integrated Luminosity (fb^{-1}/bin)')
351 histoW1D = ROOT.TH1D(
'hd1D'+var,
'hd1D'+var, 100, ymin, ymaxSmall)
352 histoW1D.GetXaxis().SetTitle(
varDef(var,
'atit',var))
353 histoW1D.GetYaxis().SetTitle(
'Integrated Luminosity (fb^{-1}/bin)')
356 if options.plotGraph:
359 for mu, x, l
in zip(xd, ydDict[var], lumi):
361 histoW.Fill( mu, x , l)
363 for mu, x, l
in zip(xd, ydDict2[var], lumi):
365 histo2W.Fill( mu,x, l)
375 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
381 comments.append(
'Run %i' % runStart)
383 comments.append(
'Runs %i - %i' % (runStart,runEnd))
385 if fillStart==fillEnd:
386 comments.append(
'Fill %i' % fillStart)
388 comments.append(
'Fills %i - %i' % (fillStart,fillEnd))
390 t1 = time.strftime(
'%d %b %Y',time.localtime(timeStart))
391 t2 = time.strftime(
'%d %b %Y',time.localtime(timeEnd))
395 comments.append(
'%s - %s' % (t1,t2))
399 canvas.Print(
"Run_%d_%sVsMu.png" % ( options.runMin,var ) )
400 canvas.Print(
"Run_%d_%sVsMu.pdf" % ( options.runMin,var ) )
401 if not options.plotGraph:
403 canvas.Print(
"Run_%d_%sVsMuLog.png" % ( options.runMin,var ) )
404 canvas.Print(
"Run_%d_%sVsMuLog.pdf" % ( options.runMin,var ) )
405 canvas.SetLogz(
False)
408 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
411 canvas.Print(
"Run_%d_Mu%sVsMu.png" % ( options.runMin,var ) )
412 canvas.Print(
"Run_%d_Mu%sVsMu.pdf" % ( options.runMin,var ) )
414 canvas.Print(
"Run_%d_Mu%sVsMuLog.png" % ( options.runMin,var ) )
415 canvas.Print(
"Run_%d_Mu%sVsMuLog.pdf" % ( options.runMin,var ) )
416 canvas.SetLogz(
False)
419 histoW.SetMinimum(0.005);
420 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
423 canvas.Print(
"Run_%d_%sVsMuW.png" % ( options.runMin,var ) )
424 canvas.Print(
"Run_%d_%sVsMuW.pdf" % ( options.runMin,var ) )
426 canvas.Print(
"Run_%d_%sVsMuWLog.png" % ( options.runMin,var ) )
427 canvas.Print(
"Run_%d_%sVsMuWLog.pdf" % ( options.runMin,var ) )
428 canvas.SetLogz(
False)
430 histo2W.Draw(
"colz");
431 histo2W.SetMinimum(0.01);
433 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
436 canvas.Print(
"Run_%d_Mu%sVsMuW.png" % ( options.runMin,var ) )
437 canvas.Print(
"Run_%d_Mu%sVsMuW.pdf" % ( options.runMin,var ) )
439 canvas.Print(
"Run_%d_Mu%sVsMuWLog.png" % ( options.runMin,var ) )
440 canvas.Print(
"Run_%d_Mu%sVsMuWLog.pdf" % ( options.runMin,var ) )
441 canvas.SetLogz(
False)
443 histoW1D.Draw(
"colz");
444 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
446 ROOTUtils.drawText(0.18,0.81,0.05,
"#mu=%2.4f RMS=%2.4f" % ( histoW1D.GetMean(), histoW1D.GetRMS() ),font=42)
447 canvas.Print(
"Run_%d_%s1D.png" % ( options.runMin,var ) )
448 canvas.Print(
"Run_%d_%s1D.pdf" % ( options.runMin,var ) )
450 canvas.Print(
"Run_%d_%s1DLog.png" % ( options.runMin,var ) )
451 canvas.Print(
"Run_%d_%s1DLog.pdf" % ( options.runMin,var ) )
452 canvas.SetLogy(
False)