Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:48:42

0001 import ROOT
0002 import sys
0003 import os
0004 
0005 color=ROOT.kMagenta
0006 marker=20
0007 plots    = ['xy_view','thickness_vs_r','thickness_vs_eta']
0008 rangeMin = [   0,      0.5,      0.5]
0009 rangeMax = [ 200,      3.5,      3.5]
0010 
0011 def drawHeader(title=None):
0012 
0013     """ a lazy header for the plots """
0014 
0015     txt=ROOT.TLatex()
0016     txt.SetNDC(True)
0017     txt.SetTextFont(42)
0018     txt.SetTextSize(0.04)
0019     txt.SetTextAlign(ROOT.kHAlignLeft+ROOT.kVAlignCenter)
0020     txt.DrawLatex(0.12,0.93,'#bf{CMS} #it{preliminary}')
0021     txt.SetTextAlign(ROOT.kHAlignCenter+ROOT.kVAlignCenter)
0022     txt.SetTextSize(0.035)
0023     if title:
0024         txt.DrawLatex(0.80,0.93,title)
0025 
0026 def makePlotsFrom(key):
0027 
0028     """receives a TDirectoryFile with the plots from an analyzer and saves them in png/pdf"""
0029 
0030     c=ROOT.TCanvas('c','c',500,500)
0031     c.SetLeftMargin(0.12)
0032     c.SetRightMargin(0.12)
0033     c.SetBottomMargin(0.12)
0034 
0035     tag=key.GetName()
0036     tag=tag.replace('plotter','')
0037 
0038     for n, p in enumerate(plots):
0039         for d in [8,9]:
0040 
0041             #c.SetRightMargin(0.03)
0042             #c.SetTopMargin(0.3)
0043             layers=range(-28,29) if d==8 else range(-22,23)
0044             for l in layers:
0045                 if l == 0: continue
0046                 pname='d%d_layer%d_%s'%(d,l,p)
0047                 h=key.Get(pname)
0048                 h.SetLineColor(color)
0049                 h.SetMarkerColor(color)
0050                 h.SetMarkerStyle(marker)
0051                 h.Draw('COLZ')
0052 
0053                 drawHeader(h.GetTitle())
0054                 c.Modified()
0055                 c.Update()
0056                 for ext in ['png','pdf']:
0057                     c.SaveAs(outName+'/%s_%s_layer_%d.%s'%(p,d,l,ext))
0058 
0059 
0060 ROOT.gStyle.SetOptStat(0)
0061 ROOT.gStyle.SetOptTitle(0)
0062 ROOT.gROOT.SetBatch(True)
0063 
0064 url='geom_output.root'
0065 if len(sys.argv)>1 :
0066     url=sys.argv[1]
0067     outName=str(sys.argv[1])[:-5]
0068     if not os.path.isdir(outName):
0069         os.mkdir(outName)
0070 
0071 fIn=ROOT.TFile.Open(url)
0072 for key in fIn.GetListOfKeys(): makePlotsFrom(key.ReadObj())