ATLAS Offline Software
plotBeamSpotMon.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 
5 
6 """
7 Plot histograms from beam spot monitoring file.
8 """
9 __author__ = 'Juerg Beringer'
10 __version__ = '$Id $'
11 __usage__ = '%prog [options] beamspotmonitoring.root'
12 
13 import os
14 #from math import *
15 import re
16 
17 from InDetBeamSpotExample.Utils import getRunFromName
18 
19 
20 # Histogram definition
21 hDef = {
22  'trkDPhi': {'opts': 'COLZ', 'stats': 'n'},
23  'trkDPhiCorr': {'opts': 'COLZ', 'stats': 'n'},
24  'pvYX': {'opts': 'COLZ', 'stats': 111},
25  'pvXZ': {'opts': 'COLZ', 'stats': 111},
26  'pvYZ': {'opts': 'COLZ', 'stats': 111},
27  'pvX': {'stats': 111111},
28  'pvY': {'stats': 111111},
29  'pvZ': {'stats': 111111},
30  'pvChiSqDof': {'stats': 101111},
31  'pvNTracks': {'stats': 101111},
32  'pvTrackPt': {'stats': 101111},
33 }
34 
35 
36 # Argument parsing
37 from optparse import OptionParser
38 parser = OptionParser(usage=__usage__, version=__version__)
39 parser.add_option('-i', '--interactive', dest='interactive', action='store_true', default=False, help='interactive')
40 parser.add_option('-b', '--batch', dest='batch', action='store_true', default=False, help='run in batch mode')
41 parser.add_option('-o', '--output', dest='output', default='.gif', help='comma-separated list of output files or formats (default: .gif')
42 (options,args) = parser.parse_args()
43 if len(args) != 1:
44  parser.error('wrong number of command line arguments')
45 filename = args[0]
46 run = getRunFromName(filename)
47 if run:
48  basename = run+'-'
49 else:
50  run = 'UNKNOWN'
51  basename = ''
52 
53 
54 # Setup ROOT
55 if options.batch:
56  os.unsetenv('DISPLAY')
57 import ROOT
58 from InDetBeamSpotExample import ROOTUtils
60 ROOT.gStyle.SetPalette(1)
61 c = ROOT.TCanvas('BeamSpotMonitoring','Beam Spot Monitoring',750,1000)
62 c.Divide(3,4)
63 
64 
65 # Open monitoring file
66 mon = ROOT.TFile(filename)
67 mondir = 'InDetGlobal/BeamSpot/'
68 mondirCA = 'run_'+run+'/InDetGlobal/BeamSpot/'
69 
70 
71 # Summary frame
72 c.cd(1)
73 ROOTUtils.drawText(0.14,0.9,0.06,'Beam spot monitoring for run %s:' % run)
74 yline = 0.83
75 for f in args:
76  b = f.split('/')[-1]
77  dsname = b.split('-')[0]
78  taskname = '-'.join(b.split('-')[1:-1])
79  ROOTUtils.drawText(0.14,yline,0.05,'- %s,; task %s' % (dsname,taskname),font=42)
80  yline -= 0.11
81 
82 nc = 2
83 for hname in ['trkDPhi', 'trkDPhiCorr',
84  'pvYX', 'pvXZ', 'pvYZ',
85  'pvX', 'pvY', 'pvZ',
86  'pvChiSqDof', 'pvNTracks', 'pvTrackPt'
87  ]:
88  c.cd(nc)
89  print ('Processing histogram',hname)
90  ROOT.gStyle.SetOptStat(hDef[hname].get('stats',0))
91  h = mon.Get(mondir+hname)
92  if h == None:
93  h = mon.Get(mondirCA+hname)
94  if h != None:
95  h.Draw(hDef[hname].get('opts',''))
96  else:
97  print ("... no histogram with name %s" % hname)
98  c.Modified()
99  c.Update()
100  nc += 1
101 
102 # Save and finalize
103 if options.output:
104  for o in options.output.split(','):
105  if o[0]=='.':
106  c.SaveAs(basename+'beamspotmon'+o)
107  else:
108  c.SaveAs(o)
109 
110 print()
111 if options.interactive:
112  os.environ['PYTHONINSPECT'] = '1'
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
ROOTUtils.setStyle
def setStyle(style=None)
Definition: roofit/ROOTUtils.py:413
python.Utils.getRunFromName
def getRunFromName(name, default='', asInt=False)
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:13
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127