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