ATLAS Offline Software
Functions | Variables
bsPlotVsMu Namespace Reference

Functions

def main ()
 

Variables

string __author__ = 'Anthony Morley'
 
string __version__ = ''
 
string __usage__
 
 varDefs
 
string lumiTag_default = 'OflLumi-Run3-001'
 
string indetbsTag_default = 'IndetBeampos-RUN3-ES1-UPD2-02'
 
 parser = OptionParser(usage=__usage__, version=__version__)
 
 dest
 
 default
 
 help
 
 type
 
 None
 
 action
 
 False
 
 True
 
 options
 
 args
 
int db1 = 1 else 'COOLOFL_INDET/CONDBR2'
 
int db2 = 2 else 'COOLOFL_TRIGGER/CONDBR2'
 
list varColl = []
 
list varPlot = []
 

Function Documentation

◆ main()

def bsPlotVsMu.main ( )

Definition at line 70 of file bsPlotVsMu.py.

70 def main():
71  f1 = "%s::%s" % (db1, options.folderBS)
72  f2 = "%s::%s" % (db2, options.folderLumi)
73 
74  print( "="*100 )
75  print( "Comparing: " )
76  print( " * ", f1, options.tagBS )
77  print( " * ", f2, options.tagLumi )
78  print( "="*100 )
79 
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' )
84 
85 
86  #Open up required databases
87  from PyCool import cool
88  from CoolConvUtilities import AtlCoolLib
89  cooldbBS = AtlCoolLib.indirectOpen(db1, True, False)
90  cooldbLumi = AtlCoolLib.indirectOpen(db2, True, False)
91 
92  folderBS = cooldbBS.getFolder(options.folderBS)
93  folderLumi = cooldbLumi.getFolder(options.folderLumi)
94 
95  from InDetBeamSpotExample.COOLUtils import COOLQuery
96  coolQuery = COOLQuery()
97 
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
102  else :
103  iov2 = (options.runMin +1) << 32
104  print( 'Plotting iovs %i to %i ' % (iov1,iov2) )
105  else :
106  print( 'No run selected -- ERROR' )
107  return
108 
109  if (iov2>cool.ValidityKeyMax):
110  iov2=cool.ValidityKeyMax
111 
112  print( "Reading data from database" )
113  itrBS = folderBS.browseObjects(iov1, iov2, cool.ChannelSelection.all(), options.tagBS)
114  print( "...finished getting BS data" )
115 
116  lbDict = dict()
117 
118  startRLB =0x7FFFFFFFFFFFFFFF
119  endRLB =0
120 
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" )
123 
124 
125  runs = set()
126  while itrBS.goToNext():
127 
128  obj = itrBS.currentRef()
129 
130  since = obj.since()
131 
132  runBegin = since >> 32
133  lumiBegin = since & 0xFFFFFFFF
134 
135  until = obj.until()
136  runUntil = until >> 32
137  lumiUntil = until & 0xFFFFFFFF
138 
139  status = int(obj.payloadValue('status'))
140  if status != 59:
141  continue
142 
143  runs.add(runBegin)
144 
145  if since < startRLB:
146  startRLB = since
147  if until > endRLB:
148  endRLB = until
149 
150 
151  values={}
152  for var in varColl:
153  values[var] = float(obj.payloadValue(var))
154  values[var+'Err'] = float(obj.payloadValue(var+'Err'))
155  values['until'] = until
156  lbDict[since] = values
157 
158  print( 'Runs: ',runs )
159 
160  lumi = array('d')
161  xd = array('d')
162  exd = array('d')
163  ydDict = {}
164  eydDict = {}
165  ydDict2 = {}
166 
167  sqtrt2pi = math.sqrt(2*math.pi)
168 
169  lblb = CoolDataReader('COOLONL_TRIGGER/CONDBR2', '/TRIGGER/LUMI/LBLB')
170  from DQUtils.sugar import RANGEIOV_VAL, RunLumi
171  from DQUtils import IOVSet
172 
173  # 2022 GRL
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")
175 
176  # Run 2 GRLs
177  #grlIOVs=IOVSet.from_grl("data15_13TeV.periodAllYear_DetStatus-v89-pro21-02_Unknown_PHYS_StandardGRL_All_Good_25ns.xml")
178  #grlIOVs+=IOVSet.from_grl("data16_13TeV.periodAllYear_DetStatus-v89-pro21-01_DQDefects-00-02-04_PHYS_StandardGRL_All_Good_25ns.xml")
179  #grlIOVs+=IOVSet.from_grl("data17_13TeV.periodAllYear_DetStatus-v99-pro22-01_Unknown_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.xml")
180  #grlIOVs+=IOVSet.from_grl("data18_13TeV.periodAllYear_DetStatus-v102-pro22-04_Unknown_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.xml")
181 
182  for run in runs:
183  iov1 = run << 32
184  iov2 = (run + 1) << 32
185 
186  itrLumi = folderLumi.browseObjects(iov1, iov2, cool.ChannelSelection(0), options.tagLumi)
187  print( "...finished getting Lumi data for run %i" % run )
188 
189  lblb.setIOVRangeFromRun(run)
190  lblb.readData()
191  if len(lblb.data) < 1:
192  print( 'No LBLB data found!' )
193  continue
194  # Make time map
195  lblbMap = dict()
196  for obj in lblb.data:
197  lblbMap[obj.since()] = (obj.payload()['StartTime'], obj.payload()['EndTime'])
198 
199 
200  while itrLumi.goToNext():
201  obj = itrLumi.currentRef()
202 
203  since = obj.since()
204  runBegin = since >> 32
205  lumiBegin = since & 0xFFFFFFFF
206 
207  until = obj.until()
208  runUntil = until >> 32
209  lumiUntil = until & 0xFFFFFFFF
210 
211  inGRL = False
212  for sinceGRL, untilGRL, grl_states in process_iovs(grlIOVs):
213  if grl_states[0].since==None:
214  continue
215  if ( sinceGRL.run <= runBegin and untilGRL.run >= runUntil and sinceGRL.lumi <= lumiBegin and untilGRL.lumi >= lumiUntil ):
216  inGRL = True
217  break
218 
219  if not inGRL:
220  continue
221 
222  mu = float(obj.payloadValue('LBAvEvtsPerBX'))
223  instlumi = float(obj.payloadValue('LBAvInstLumi'))
224 
225  #if( mu < 10 or mu > 65 ):
226  # print('Mu: %2.1f Run : %d LB: %d - %d Lumi: %f' % (mu,runBegin,lumiBegin,lumiUntil,instlumi))
227 
228  if since in lbDict:
229  if lbDict[ since ]['sigmaX'] > 0.1 :
230  continue
231  startTime = lblbMap.get(obj.since(), (0., 0.))[0]
232  endTime = lblbMap.get(lbDict[ since ]['until'], (0., 0.))[0] #[1] end of lumiblock
233  mylumi = (endTime - startTime)/1e9 * instlumi/1e9
234  thisTime = time.gmtime( startTime /1.e9 )
235  year = thisTime[0]
236  month = thisTime[1]
237  day = thisTime[2]
238  hour = thisTime[3]
239  mins = thisTime[4]
240  sec = thisTime[5]
241  lumi.append( mylumi ); # in fb^-1
242  xd.append(mu)
243  exd.append(0)
244 
245  if options.plotSomething:
246  for var in varColl:
247  if not var in ydDict:
248  ydDict[var] = array('d')
249  ydDict2[var] = array('d')
250  eydDict[var] = array('d')
251 
252  ydDict2[var].append( mu/(lbDict[ since ][var] * sqtrt2pi ))
253  ydDict[var].append( lbDict[ since ][var] )
254  eydDict[var].append( lbDict[ since ][var+'Err'] )
255 
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 )
258 
259 
260  runStart = startRLB >> 32
261  runEnd = endRLB >> 32
262  fillStart = fillEnd = 0
263  timeStart = timeEnd = 0
264  beamEnergy = 13.6
265  try:
266  timeStart = coolQuery.lbTime( int(startRLB >> 32), int(startRLB & 0xFFFFFFFF) )[0]
267  except:
268  pass
269  try:
270  timeEnd = coolQuery.lbTime( int(endRLB >> 32), int(endRLB & 0xFFFFFFFF)-1 )[1]
271  except:
272  pass
273  try:
274  fillStart = coolQuery.getLHCInfo(timeStart).get('FillNumber',0)
275  except:
276  pass
277  try:
278  fillEnd = coolQuery.getLHCInfo(timeEnd).get('FillNumber',0)
279  except:
280  pass
281 
282  ntuple.Write()
283 
284  if not options.plotSomething:
285  return
286 
287  from InDetBeamSpotExample import ROOTUtils
289  canvas = ROOT.TCanvas('BeamSpotComparison', 'BeamSpotComparison', 1600, 1200)
290 
291  canvas.cd()
292  ROOT.gPad.SetTopMargin(0.05)
293  ROOT.gPad.SetLeftMargin(0.15)
294  ROOT.gPad.SetRightMargin(0.05)
295 
296  if not options.plotGraph:
297  ROOT.gPad.SetRightMargin(0.15)
298 
299 
300  #Plot each variable
301  for var in varPlot:
302  if var not in ydDict:
303  print( 'Missing yd: ',var )
304  if var not in eydDict:
305  print( 'Missing eyd: ',var )
306  continue
307 
308  gr = ROOT.TGraphErrors(len(xd), xd, ydDict[var], exd, eydDict[var])
309  xmin = min(xd)
310  xmax = max(xd)
311  ymin = min(ydDict[var])
312  ymax = max(ydDict[var])
313 
314  h = (ymax-ymin)
315  ymin -= 0.25*h
316  ymaxSmall = ymax + 0.25*h
317  ymax += 0.75*h
318 
319  ymin2 = min(ydDict2[var])
320  ymax2 = max(ydDict2[var])
321 
322  h = (ymax2-ymin2)
323  ymin2 -= 0.25*h
324  ymax2 += 0.75*h
325 
326  h = (xmax-xmin)
327  xmin -= 0.05*h
328  xmax += 0.05*h
329 
330  #This histogram is made just to make it easier to manipulate the margins
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')
335 
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')
340 
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)')
345 
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)')
350 
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)')
354 
355  histo.Draw();
356  if options.plotGraph:
357  gr.Draw("p");
358  else:
359  for mu, x, l in zip(xd, ydDict[var], lumi):
360  histo.Fill( mu, x )
361  histoW.Fill( mu, x , l)
362  histoW1D.Fill( x, l)
363  for mu, x, l in zip(xd, ydDict2[var], lumi):
364  histo2.Fill( mu, x )
365  histo2W.Fill( mu,x, l)
366  histo.Draw("colz")
367 
368  histo.Write()
369  histoW.Write()
370  histo2.Write()
371  histo2W.Write()
372  histoW1D.Write()
373 
374  # Add some information to the graph
375  ROOTUtils.atlasLabel( 0.53,0.87,False,offset=0.12,isForApproval=False,customstring="Internal",energy='%2.1f' % beamEnergy,size=0.055)
376  ROOTUtils.drawText(0.18,0.87,0.055, varDef(var,'title',var) )
377 
378  comments = []
379 
380  if runStart==runEnd:
381  comments.append('Run %i' % runStart)
382  else:
383  comments.append('Runs %i - %i' % (runStart,runEnd))
384 
385  if fillStart==fillEnd:
386  comments.append('Fill %i' % fillStart)
387  else:
388  comments.append('Fills %i - %i' % (fillStart,fillEnd))
389 
390  t1 = time.strftime('%d %b %Y',time.localtime(timeStart))
391  t2 = time.strftime('%d %b %Y',time.localtime(timeEnd))
392  if t1==t2:
393  comments.append(t1)
394  else:
395  comments.append('%s - %s' % (t1,t2))
396 
397  ROOTUtils.drawText(0.18,0.81,0.05,';'.join(comments),font=42)
398 
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:
402  canvas.SetLogz(True)
403  canvas.Print( "Run_%d_%sVsMuLog.png" % ( options.runMin,var ) )
404  canvas.Print( "Run_%d_%sVsMuLog.pdf" % ( options.runMin,var ) )
405  canvas.SetLogz(False)
406 
407  histo2.Draw("colz");
408  ROOTUtils.atlasLabel( 0.53,0.87,False,offset=0.12,isForApproval=False,customstring="Internal",energy='%2.1f' % beamEnergy,size=0.055)
409  ROOTUtils.drawText(0.18,0.87,0.055, "Interaction density" )
410  ROOTUtils.drawText(0.18,0.81,0.05,';'.join(comments),font=42)
411  canvas.Print( "Run_%d_Mu%sVsMu.png" % ( options.runMin,var ) )
412  canvas.Print( "Run_%d_Mu%sVsMu.pdf" % ( options.runMin,var ) )
413  canvas.SetLogz(True)
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)
417 
418  histoW.Draw("colz");
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)
421  ROOTUtils.drawText(0.18,0.87,0.055, varDef(var,'title',var) )
422  ROOTUtils.drawText(0.18,0.81,0.05,';'.join(comments),font=42)
423  canvas.Print( "Run_%d_%sVsMuW.png" % ( options.runMin,var ) )
424  canvas.Print( "Run_%d_%sVsMuW.pdf" % ( options.runMin,var ) )
425  canvas.SetLogz(True)
426  canvas.Print( "Run_%d_%sVsMuWLog.png" % ( options.runMin,var ) )
427  canvas.Print( "Run_%d_%sVsMuWLog.pdf" % ( options.runMin,var ) )
428  canvas.SetLogz(False)
429 
430  histo2W.Draw("colz");
431  histo2W.SetMinimum(0.01);
432 
433  ROOTUtils.atlasLabel( 0.53,0.87,False,offset=0.12,isForApproval=False,customstring="Internal",energy='%2.1f' % beamEnergy,size=0.055)
434  ROOTUtils.drawText(0.18,0.87,0.055, "Interaction density" )
435  ROOTUtils.drawText(0.18,0.81,0.05,';'.join(comments),font=42)
436  canvas.Print( "Run_%d_Mu%sVsMuW.png" % ( options.runMin,var ) )
437  canvas.Print( "Run_%d_Mu%sVsMuW.pdf" % ( options.runMin,var ) )
438  canvas.SetLogz(True)
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)
442 
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)
445  ROOTUtils.drawText(0.18,0.87,0.055, varDef(var,'title',var) )
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 ) )
449  canvas.SetLogy(True)
450  canvas.Print( "Run_%d_%s1DLog.png" % ( options.runMin,var ) )
451  canvas.Print( "Run_%d_%s1DLog.pdf" % ( options.runMin,var ) )
452  canvas.SetLogy(False)
453 
454 
455 

Variable Documentation

◆ __author__

string bsPlotVsMu.__author__ = 'Anthony Morley'
private

Definition at line 10 of file bsPlotVsMu.py.

◆ __usage__

string bsPlotVsMu.__usage__
private
Initial value:
1 = '''%prog [options] [database1] [database2]
2 
3 Database can be either connection string or db file:
4 
5  e.g COOLOFL_INDET/CONDBR2 (default)
6  beamspot.db/BEAMSPOT
7 
8 Example:
9 
10  PlotVsMu --rl 341123 --ru 341123
11 
12 '''

Definition at line 12 of file bsPlotVsMu.py.

◆ __version__

string bsPlotVsMu.__version__ = ''
private

Definition at line 11 of file bsPlotVsMu.py.

◆ action

bsPlotVsMu.action

Definition at line 50 of file bsPlotVsMu.py.

◆ args

bsPlotVsMu.args

Definition at line 52 of file bsPlotVsMu.py.

◆ db1

int bsPlotVsMu.db1 = 1 else 'COOLOFL_INDET/CONDBR2'

Definition at line 54 of file bsPlotVsMu.py.

◆ db2

int bsPlotVsMu.db2 = 2 else 'COOLOFL_TRIGGER/CONDBR2'

Definition at line 55 of file bsPlotVsMu.py.

◆ default

bsPlotVsMu.default

Definition at line 43 of file bsPlotVsMu.py.

◆ dest

bsPlotVsMu.dest

Definition at line 43 of file bsPlotVsMu.py.

◆ False

bsPlotVsMu.False

Definition at line 50 of file bsPlotVsMu.py.

◆ help

bsPlotVsMu.help

Definition at line 43 of file bsPlotVsMu.py.

◆ indetbsTag_default

bsPlotVsMu.indetbsTag_default = 'IndetBeampos-RUN3-ES1-UPD2-02'

Definition at line 39 of file bsPlotVsMu.py.

◆ lumiTag_default

bsPlotVsMu.lumiTag_default = 'OflLumi-Run3-001'

Definition at line 38 of file bsPlotVsMu.py.

◆ None

bsPlotVsMu.None

Definition at line 47 of file bsPlotVsMu.py.

◆ options

bsPlotVsMu.options

Definition at line 52 of file bsPlotVsMu.py.

◆ parser

bsPlotVsMu.parser = OptionParser(usage=__usage__, version=__version__)

Definition at line 42 of file bsPlotVsMu.py.

◆ True

bsPlotVsMu.True

Definition at line 51 of file bsPlotVsMu.py.

◆ type

bsPlotVsMu.type

Definition at line 47 of file bsPlotVsMu.py.

◆ varColl

list bsPlotVsMu.varColl = []

Definition at line 58 of file bsPlotVsMu.py.

◆ varDefs

bsPlotVsMu.varDefs

Definition at line 31 of file bsPlotVsMu.py.

◆ varPlot

list bsPlotVsMu.varPlot = []

Definition at line 59 of file bsPlotVsMu.py.

ROOTUtils.drawText
def drawText(x=0.74, y=0.87, dy=0.06, text='', font=62, color=1, align=11, linesep=';')
Definition: roofit/ROOTUtils.py:243
max
#define max(a, b)
Definition: cfImp.cxx:41
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotCompare.varDef
dictionary varDef
Definition: plotBeamSpotCompare.py:25
ROOTUtils.setStyle
def setStyle(style=None)
Definition: roofit/ROOTUtils.py:413
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
ROOTUtils.atlasLabel
def atlasLabel(x, y, isPreliminary=False, color=1, offset=0.115, isForApproval=False, energy=8, customstring="", size=0.05)
Definition: roofit/ROOTUtils.py:303
python.events.process_iovs
def process_iovs(*iovsets)
Definition: events.py:30
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
min
#define min(a, b)
Definition: cfImp.cxx:40
array
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
COOLUtils
bsPlotVsMu.main
def main()
Definition: bsPlotVsMu.py:70
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
readCCLHist.float
float
Definition: readCCLHist.py:83