70 f1 =
"%s::%s" % (db1, options.folderBS)
71 f2 =
"%s::%s" % (db2, options.folderLumi)
74 print(
"Comparing: " )
75 print(
" * ", f1, options.tagBS )
76 print(
" * ", f2, options.tagLumi )
79 requiredForNtuple = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ']
80 checkNtupleProd =
all(item
in varColl
for item
in requiredForNtuple)
81 if not checkNtupleProd:
82 print(
'Ntuple will not be filled missing vars' )
86 from PyCool
import cool
87 from CoolConvUtilities
import AtlCoolLib
88 cooldbBS = AtlCoolLib.indirectOpen(db1,
True,
False)
89 cooldbLumi = AtlCoolLib.indirectOpen(db2,
True,
False)
91 folderBS = cooldbBS.getFolder(options.folderBS)
92 folderLumi = cooldbLumi.getFolder(options.folderLumi)
95 coolQuery = COOLQuery()
97 if options.runMin
is not None:
98 iov1 = options.runMin << 32
99 if options.runMax
is not None:
100 iov2 = (options.runMax +1) << 32
102 iov2 = (options.runMin +1) << 32
103 print(
'Plotting iovs %i to %i ' % (iov1,iov2) )
105 print(
'No run selected -- ERROR' )
108 if (iov2>cool.ValidityKeyMax):
109 iov2=cool.ValidityKeyMax
111 print(
"Reading data from database" )
112 itrBS = folderBS.browseObjects(iov1, iov2, cool.ChannelSelection.all(), options.tagBS)
113 print(
"...finished getting BS data" )
117 startRLB =0x7FFFFFFFFFFFFFFF
120 outfile = ROOT.TFile(
"BeamspotLumi_%i.root" % (options.runMin),
"recreate")
121 ntuple = ROOT.TNtupleD(
'BeamspotLumi',
'BeamSpotLumi',
"x:y:z:sigma_x:sigma_y:sigma_z:run:mu:lumi:year:month:day:hour:minute:epoch" )
125 while itrBS.goToNext():
127 obj = itrBS.currentRef()
131 runBegin = since >> 32
132 lumiBegin = since & 0xFFFFFFFF
135 runUntil = until >> 32
136 lumiUntil = until & 0xFFFFFFFF
138 status =
int(obj.payloadValue(
'status'))
152 values[var] =
float(obj.payloadValue(var))
153 values[var+
'Err'] =
float(obj.payloadValue(var+
'Err'))
154 values[
'until'] = until
155 lbDict[since] = values
157 print(
'Runs: ',runs )
166 sqtrt2pi = math.sqrt(2*math.pi)
168 lblb = CoolDataReader(
'COOLONL_TRIGGER/CONDBR2',
'/TRIGGER/LUMI/LBLB')
169 from DQUtils.sugar
import RANGEIOV_VAL, RunLumi
170 from DQUtils
import IOVSet
173 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")
183 iov2 = (run + 1) << 32
185 itrLumi = folderLumi.browseObjects(iov1, iov2, cool.ChannelSelection(0), options.tagLumi)
186 print(
"...finished getting Lumi data for run %i" % run )
188 lblb.setIOVRangeFromRun(run)
190 if len(lblb.data) < 1:
191 print(
'No LBLB data found!' )
195 for obj
in lblb.data:
196 lblbMap[obj.since()] = (obj.payload()[
'StartTime'], obj.payload()[
'EndTime'])
199 while itrLumi.goToNext():
200 obj = itrLumi.currentRef()
203 runBegin = since >> 32
204 lumiBegin = since & 0xFFFFFFFF
207 runUntil = until >> 32
208 lumiUntil = until & 0xFFFFFFFF
211 for sinceGRL, untilGRL, grl_states
in process_iovs(grlIOVs):
212 if grl_states[0].since==
None:
214 if ( sinceGRL.run <= runBegin
and untilGRL.run >= runUntil
and sinceGRL.lumi <= lumiBegin
and untilGRL.lumi >= lumiUntil ):
221 mu =
float(obj.payloadValue(
'LBAvEvtsPerBX'))
222 instlumi =
float(obj.payloadValue(
'LBAvInstLumi'))
228 if lbDict[ since ][
'sigmaX'] > 0.1 :
230 startTime = lblbMap.get(obj.since(), (0., 0.))[0]
231 endTime = lblbMap.get(lbDict[ since ][
'until'], (0., 0.))[0]
232 mylumi = (endTime - startTime)/1e9 * instlumi/1e9
233 thisTime = time.gmtime( startTime /1.e9 )
240 lumi.append( mylumi );
244 if options.plotSomething:
246 if not var
in ydDict:
247 ydDict[var] =
array(
'd')
248 ydDict2[var] =
array(
'd')
249 eydDict[var] =
array(
'd')
251 ydDict2[var].
append( mu/(lbDict[ since ][var] * sqtrt2pi ))
252 ydDict[var].
append( lbDict[ since ][var] )
253 eydDict[var].
append( lbDict[ since ][var+
'Err'] )
255 if checkNtupleProd
and lbDict[ since ][
'sigmaZErr'] < 5 :
256 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 )
259 runStart = startRLB >> 32
260 runEnd = endRLB >> 32
261 fillStart = fillEnd = 0
262 timeStart = timeEnd = 0
265 timeStart = coolQuery.lbTime(
int(startRLB >> 32),
int(startRLB & 0xFFFFFFFF) )[0]
269 timeEnd = coolQuery.lbTime(
int(endRLB >> 32),
int(endRLB & 0xFFFFFFFF)-1 )[1]
273 fillStart = coolQuery.getLHCInfo(timeStart).
get(
'FillNumber',0)
277 fillEnd = coolQuery.getLHCInfo(timeEnd).
get(
'FillNumber',0)
283 if not options.plotSomething:
286 from InDetBeamSpotExample
import ROOTUtils
288 canvas = ROOT.TCanvas(
'BeamSpotComparison',
'BeamSpotComparison', 1600, 1200)
291 ROOT.gPad.SetTopMargin(0.05)
292 ROOT.gPad.SetLeftMargin(0.15)
293 ROOT.gPad.SetRightMargin(0.05)
295 if not options.plotGraph:
296 ROOT.gPad.SetRightMargin(0.15)
301 if var
not in ydDict:
302 print(
'Missing yd: ',var )
303 if var
not in eydDict:
304 print(
'Missing eyd: ',var )
307 gr = ROOT.TGraphErrors(len(xd), xd, ydDict[var], exd, eydDict[var])
310 ymin =
min(ydDict[var])
311 ymax =
max(ydDict[var])
315 ymaxSmall = ymax + 0.25*h
318 ymin2 =
min(ydDict2[var])
319 ymax2 =
max(ydDict2[var])
330 histo = ROOT.TH2D(
'hd'+var,
'hd'+var, 100, xmin, xmax, 100, ymin, ymax)
331 histo.GetYaxis().SetTitle(
varDef(var,
'atit',var))
332 histo.GetXaxis().SetTitle(
'Average interactions per bunch crossing')
333 histo.GetZaxis().SetTitle(
'Entries')
335 histo2 = ROOT.TH2D(
'hd2'+var,
'hd2'+var, 100, xmin, xmax, 100, ymin2, ymax2)
336 histo2.GetYaxis().SetTitle(
"<Interaction density> @ z=0 [interactions/mm]")
337 histo2.GetXaxis().SetTitle(
'Average interactions per bunch crossing')
338 histo2.GetZaxis().SetTitle(
'Entries')
340 histo2W = ROOT.TH2D(
'hd3'+var,
'hd3'+var, 100, xmin, xmax, 100, ymin2, ymax2)
341 histo2W.GetYaxis().SetTitle(
"<Interaction density> @ z=0 [interactions/mm]")
342 histo2W.GetXaxis().SetTitle(
'Average interactions per bunch crossing')
343 histo2W.GetZaxis().SetTitle(
'Integrated Luminosity (fb^{-1}/bin)')
345 histoW = ROOT.TH2D(
'hdW'+var,
'hdW'+var, 100, xmin, xmax, 100, ymin, ymax)
346 histoW.GetYaxis().SetTitle(
varDef(var,
'atit',var))
347 histoW.GetXaxis().SetTitle(
'Average interactions per bunch crossing')
348 histoW.GetZaxis().SetTitle(
'Integrated Luminosity (fb^{-1}/bin)')
350 histoW1D = ROOT.TH1D(
'hd1D'+var,
'hd1D'+var, 100, ymin, ymaxSmall)
351 histoW1D.GetXaxis().SetTitle(
varDef(var,
'atit',var))
352 histoW1D.GetYaxis().SetTitle(
'Integrated Luminosity (fb^{-1}/bin)')
355 if options.plotGraph:
358 for mu, x, l
in zip(xd, ydDict[var], lumi):
360 histoW.Fill( mu, x , l)
362 for mu, x, l
in zip(xd, ydDict2[var], lumi):
364 histo2W.Fill( mu,x, l)
374 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
380 comments.append(
'Run %i' % runStart)
382 comments.append(
'Runs %i - %i' % (runStart,runEnd))
384 if fillStart==fillEnd:
385 comments.append(
'Fill %i' % fillStart)
387 comments.append(
'Fills %i - %i' % (fillStart,fillEnd))
389 t1 = time.strftime(
'%d %b %Y',time.localtime(timeStart))
390 t2 = time.strftime(
'%d %b %Y',time.localtime(timeEnd))
394 comments.append(
'%s - %s' % (t1,t2))
398 canvas.Print(
"Run_%d_%sVsMu.png" % ( options.runMin,var ) )
399 canvas.Print(
"Run_%d_%sVsMu.pdf" % ( options.runMin,var ) )
400 if not options.plotGraph:
402 canvas.Print(
"Run_%d_%sVsMuLog.png" % ( options.runMin,var ) )
403 canvas.Print(
"Run_%d_%sVsMuLog.pdf" % ( options.runMin,var ) )
404 canvas.SetLogz(
False)
407 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
410 canvas.Print(
"Run_%d_Mu%sVsMu.png" % ( options.runMin,var ) )
411 canvas.Print(
"Run_%d_Mu%sVsMu.pdf" % ( options.runMin,var ) )
413 canvas.Print(
"Run_%d_Mu%sVsMuLog.png" % ( options.runMin,var ) )
414 canvas.Print(
"Run_%d_Mu%sVsMuLog.pdf" % ( options.runMin,var ) )
415 canvas.SetLogz(
False)
418 histoW.SetMinimum(0.005);
419 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
422 canvas.Print(
"Run_%d_%sVsMuW.png" % ( options.runMin,var ) )
423 canvas.Print(
"Run_%d_%sVsMuW.pdf" % ( options.runMin,var ) )
425 canvas.Print(
"Run_%d_%sVsMuWLog.png" % ( options.runMin,var ) )
426 canvas.Print(
"Run_%d_%sVsMuWLog.pdf" % ( options.runMin,var ) )
427 canvas.SetLogz(
False)
429 histo2W.Draw(
"colz");
430 histo2W.SetMinimum(0.01);
432 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
435 canvas.Print(
"Run_%d_Mu%sVsMuW.png" % ( options.runMin,var ) )
436 canvas.Print(
"Run_%d_Mu%sVsMuW.pdf" % ( options.runMin,var ) )
438 canvas.Print(
"Run_%d_Mu%sVsMuWLog.png" % ( options.runMin,var ) )
439 canvas.Print(
"Run_%d_Mu%sVsMuWLog.pdf" % ( options.runMin,var ) )
440 canvas.SetLogz(
False)
442 histoW1D.Draw(
"colz");
443 ROOTUtils.atlasLabel( 0.53,0.87,
False,offset=0.12,isForApproval=
False,customstring=
"Internal",energy=
'%2.1f' % beamEnergy,size=0.055)
445 ROOTUtils.drawText(0.18,0.81,0.05,
"#mu=%2.4f RMS=%2.4f" % ( histoW1D.GetMean(), histoW1D.GetRMS() ),font=42)
446 canvas.Print(
"Run_%d_%s1D.png" % ( options.runMin,var ) )
447 canvas.Print(
"Run_%d_%s1D.pdf" % ( options.runMin,var ) )
449 canvas.Print(
"Run_%d_%s1DLog.png" % ( options.runMin,var ) )
450 canvas.Print(
"Run_%d_%s1DLog.pdf" % ( options.runMin,var ) )
451 canvas.SetLogy(
False)