ATLAS Offline Software
Loading...
Searching...
No Matches
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"""
7Plot histograms from beam spot monitoring file.
8"""
9__author__ = 'Juerg Beringer'
10__version__ = '$Id $'
11__usage__ = '%prog [options] beamspotmonitoring.root'
12
13import os
14#from math import *
15import re
16
17from InDetBeamSpotExample.Utils import getRunFromName
18
19
20# Histogram definition
21hDef = {
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
37from optparse import OptionParser
38parser = OptionParser(usage=__usage__, version=__version__)
39parser.add_option('-i', '--interactive', dest='interactive', action='store_true', default=False, help='interactive')
40parser.add_option('-b', '--batch', dest='batch', action='store_true', default=False, help='run in batch mode')
41parser.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()
43if len(args) != 1:
44 parser.error('wrong number of command line arguments')
45filename = args[0]
46run = getRunFromName(filename)
47if run:
48 basename = run+'-'
49else:
50 run = 'UNKNOWN'
51 basename = ''
52
53
54# Setup ROOT
55if options.batch:
56 os.unsetenv('DISPLAY')
57import ROOT
58from InDetBeamSpotExample import ROOTUtils
60ROOT.gStyle.SetPalette(1)
61c = ROOT.TCanvas('BeamSpotMonitoring','Beam Spot Monitoring',750,1000)
62c.Divide(3,4)
63
64
65# Open monitoring file
66mon = ROOT.TFile(filename)
67mondir = 'InDetGlobal/BeamSpot/'
68mondirCA = 'run_'+run+'/InDetGlobal/BeamSpot/'
69
70
71# Summary frame
72c.cd(1)
73ROOTUtils.drawText(0.14,0.9,0.06,'Beam spot monitoring for run %s:' % run)
74yline = 0.83
75for 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
82nc = 2
83for 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
103if 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
110print()
111if options.interactive:
112 os.environ['PYTHONINSPECT'] = '1'
void print(char *figname, TCanvas *c1)
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
setStyle(style=None)
drawText(x=0.74, y=0.87, dy=0.06, text='', font=62, color=1, align=11, linesep=';')