10 from commands
import getstatusoutput
11 from MuonValidation_CreateSlides_config
import *
16 can = ROOT.TCanvas(
"",
"",860,900)
17 can.SaveAs( filename )
22 maximum =
max(refHist.GetMaximum(), testHist.GetMaximum())
23 maximum = maximum + 0.1*abs(maximum)
24 minimum =
min(refHist.GetMinimum(), testHist.GetMinimum())
25 minimum = minimum - 0.1*abs(minimum)
26 refHist.SetMinimum(minimum)
27 refHist.SetMaximum(maximum)
38 print(
'WARNING Ref Histogram not found: '+plotName)
41 print(
'WARNING Test histogram not found: '+plotName)
42 print(
' Creating empty plot')
48 refint = refHist.Integral()
51 testint = testHist.Integral()
55 refHist.Scale( 1./refint )
57 print(
'WARNING empty ref plot ' + plotName )
60 testHist.Scale( 1./testint )
62 print(
'WARNING empty test plot ' + plotName )
64 canvas = ROOT.TCanvas(
"",
"", 860, 900 )
65 canvas.SetLeftMargin( 0 )
66 padMain = ROOT.TPad(
'padMain',
'padMain', 0, 0.3, 1, 1 )
67 padMain.SetBottomMargin( 0 )
71 padRatio = ROOT.TPad(
'padRatio',
'padRatio', 0, 0, 1, 0.3 )
72 padRatio.SetTopMargin( 0 )
73 padRatio.SetBottomMargin( 0.4 )
77 if 'cone' in plotName:
80 leg = ROOT.TLegend( 0.82, 0.77, 0.96, .96 )
81 leg.SetFillColor( ROOT.kWhite )
82 leg.SetTextSizePixels(20)
84 testHist.SetMarkerColor(ROOT.kRed)
85 testHist.SetLineColor(ROOT.kRed)
86 leg.AddEntry(testHist,
"test",
'P')
88 testHist.GetYaxis().SetTitleOffset( 1.4 )
89 testHist.GetYaxis().SetTitleSize( labelsize*0.4 )
90 testHist.SetLabelSize( labelsize*0.4,
'Y' )
92 for i
in testHist.GetListOfFunctions():
93 testHist.GetFunction(i.GetName()).SetBit(ROOT.TF1.kNotDraw)
96 for i
in refHist.GetListOfFunctions():
97 refHist.GetFunction(i.GetName()).SetBit(ROOT.TF1.kNotDraw)
99 refHist.SetMarkerColor(ROOT.kBlack)
100 refHist.SetLineColor(ROOT.kBlack)
101 leg.AddEntry(refHist,
"ref",
'P')
102 if 'cone' not in plotName:
105 refHist.Draw(
"PESAME")
106 testHist.Draw(
"PESAME")
123 if refint == 0
or testint == 0:
124 print(
'WARNING No ratio plot available: '+ plotName )
126 print(
'INFO skipping ratio plot for '+ plotName )
129 ratioHist = testHist.Clone()
130 ratioHist.Divide( refHist )
131 ratioHist.SetMarkerColor( ROOT.kBlack )
132 ratioHist.SetMaximum(1.2)
133 ratioHist.SetMinimum(0.8)
134 ratioHist.SetLineColor( ROOT.kBlack )
135 ratioHist.GetYaxis().SetTitle(
"test / ref" )
136 xtitle = ratioHist.GetXaxis().GetTitle()
137 if 'Transverse Momentum' in xtitle:
138 ratioHist.GetXaxis().SetTitle(xtitle.replace(
'Transverse Momentum',
'pT'))
140 ratioHist.GetXaxis().SetTitleSize( titlesize )
141 ratioHist.GetYaxis().SetTitleSize( labelsize )
142 ratioHist.SetLabelSize( labelsize,
'XY' )
143 ratioHist.GetXaxis().SetTitleOffset( 1.0 )
144 ratioHist.GetYaxis().SetTitleOffset( .4 )
147 lineRatio = ROOT.TLine( ratioHist.GetXaxis().GetXmin(), 1,
148 ratioHist.GetXaxis().GetXmax(), 1 )
149 lineRatio.SetLineColor( ROOT.kRed )
150 lineRatio.SetLineWidth( 2 )
151 lineRatio.Draw(
"same")
154 canvas.SaveAs( path +
'/' + plotName +
'.png' )
155 del canvas, padRatio, padMain
161 parser = argparse.ArgumentParser( description =
'Create Muon Validation Slides in LaTeX Beamer' )
162 parser.add_argument(
'-r',
'--reference', help =
'reference sample ROOT file' )
163 parser.add_argument(
'-t',
'--test', required=
True, help =
'test sample ROOT file' )
164 parser.add_argument(
'-d',
'--directory', default =
'beamer', help =
'directory to put new files' )
165 parser.add_argument(
'-n',
'--notitlepage', action =
'store_true', help =
'set to remove title page' )
166 parser.add_argument(
'-c',
'--compile', action=
'store_true', help =
'compile beamer file' )
167 args = parser.parse_args()
168 args.directory = os.path.dirname( args.directory +
'/' )
169 outdir = args.directory +
'/plots'
170 if not os.path.isdir( outdir ):
171 os.makedirs( outdir )
174 testfile = ROOT.TFile.Open( args.test,
'read' )
175 reffile = ROOT.TFile.Open( args.reference,
'read' )
179 specialTypes = [
'RecoFrac',
'PtRes',
'Res_pT_vs',
'PtScale',
'Eff' ]
180 for PlotList
in PlotPages.values():
181 for PlotPath
in PlotList:
182 HistDir, HistName = os.path.split( PlotPath )
183 if testfile.GetDirectory( HistDir ):
184 testhist = testfile.GetDirectory( HistDir ).
Get( HistName )
187 if reffile.GetDirectory( HistDir ):
188 refhist = reffile.GetDirectory( HistDir ).
Get( HistName )
192 doNorm =
not sum([ HistName.__contains__(i)
for i
in specialTypes ])
194 MakeComparisonPlot( refhist, testhist, HistName, outdir, doNorm = doNorm, doRatio =
True )
201 output =
r'\documentclass{beamer}' + endl
202 output +=
r'\definecolor{links}{HTML}{0000FF}' + endl
203 output +=
r'\hypersetup{colorlinks=true,urlcolor=links}' + endl
204 output +=
r'\usepackage[latin1]{inputenc}' + endl
205 output +=
r'\usetheme{Warsaw}' + endl*2
206 output +=
r'\definecolor{LightBlue}{cmyk}{0.248,0.0609,0,0.098}' + endl
207 output +=
r'\setbeamercolor{author in head/foot}{fg=white, bg=blue}'+endl
208 output +=
r'\setbeamercolor{title in head/foot}{fg=white, bg=LightBlue}'+endl
209 output +=
r'\makeatother' + endl
210 output +=
r'\setbeamertemplate{footline}{' + endl
211 output +=
r'\leavevmode' + endl
212 output +=
r'\hbox{%' + endl
216 output +=
r'\begin{beamercolorbox}[wd=0.4\paperwidth,ht=%0.3fex,dp=%0.3fex,center]{author in head/foot}'%( ht, dp ) +
r'%' + endl
217 output +=
r' \usebeamerfont{author in head/foot}\insertshortauthor' + endl
219 output +=
r'\end{beamercolorbox}%' + endl
220 output +=
r'\begin{beamercolorbox}[wd=0.5\paperwidth,ht=%0.3fex,dp=%0.3fex,center]{title in head/foot}'%( ht, dp ) +
r'%' + endl
221 output +=
r' \usebeamerfont{author in head/foot}\insertshorttitle' + endl
222 output +=
r'\end{beamercolorbox}%' + endl
223 output +=
r'\begin{beamercolorbox}[wd=0.1\paperwidth,ht=%0.3fex,dp=%0.3fex,center]{author in head/foot}'%( ht, dp ) +
r'%' + endl
224 output +=
r' \insertframenumber{}/\inserttotalframenumber' + endl
225 output +=
r'\end{beamercolorbox}}%' + endl
226 output +=
r'\vskip0pt}' + endl*2
228 output +=
r'\makeatletter' + endl
229 output +=
r'\setbeamertemplate{navigation symbols}{}' + endl*2
230 output +=
r'\setbeamerfont{footline}{size=\fontsize{10}{11}\selectfont}' + endl
232 output +=
r'\setbeamersize{text margin left=0.5cm}' + endl
233 output +=
r'\setbeamersize{text margin right=0.5cm}' + endl
235 output +=
r'\title[%s]{%s}'%(ShortTitle, Title) + endl
236 output +=
r'\subtitle{%s}'%(Subtitle) + endl
237 output +=
r'\author[%s]{%s}'%(ShortAuthor, Author) + endl
238 output +=
r'\institute[%s]{%s}'%(ShortInstitute, Institute) + endl
239 output +=
r'\date{%s}'%(Date) + endl
240 output +=
r'\begin{document}' + endl*2
241 output +=
r'%%%%%%%%%%%%%%%%%%%% BEGIN DOCUMENT %%%%%%%%%%%%%%%%%%%%' + endl*2
242 if not args.notitlepage:
243 output +=
r'{\setbeamertemplate{footline}{}' + endl
244 output +=
r'\begin{frame} \titlepage \end{frame} }' + endl
245 output +=
r'\addtocounter{framenumber}{-1}' + endl*2
248 output +=
r'\begin{frame}' + endl
249 output +=
r'\frametitle{Introduction}' + endl
250 output +=
'Reference:' + endl*2
251 output +=
'{0}: {1}'.
format(RefVersion, RefDescription) + endl*2
252 output += RefDataset + endl*2
253 output +=
r'\vspace{12pt}' + endl
254 output +=
'Test:' + endl*2
255 output +=
'{0}: {1}'.
format(TestVersion, TestDescription) + endl*2
256 output += TestDataset + endl*2
257 output +=
r'\vspace{12pt}' + Intro + endl
258 output +=
r'\end{frame}' + endl*2
260 for page
in PlotPages:
261 plotlist = PlotPages[page]
262 output +=
r'\begin{frame}' + endl
263 output +=
r'\frametitle{%s}'%(page) + endl
264 output +=
r'\hspace*{-4pt}\makebox[\linewidth][c]{' + endl
265 output +=
r'\begin{tabular}{c%s}'%(
r'@{\hspace{1pt}}c'*(len(plotlist)-1)) + endl
266 for n, plotpath
in enumerate(plotlist):
267 output +=
r'\includegraphics[width=%0.2f\textwidth]{%s/%s.png}'%( 0.35, outdir.replace( args.directory+
'/',
'' ), os.path.split(plotpath)[1] )
268 if n+1 < len(plotlist):
271 output +=
r'\end{tabular} }' + endl
272 if page
in PlotComments:
273 output += PlotComments[page] + endl
274 output +=
r'\end{frame}' + endl*2
278 output +=
r'\begin{frame}' + endl
279 output +=
'Summary' + endl
280 output +=
r'\begin{itemize}' + endl
283 output +=
r'\item %s'%(item) + endl
285 output +=
r'\end{itemize}' + endl
286 output +=
r'\end{frame}' + endl
287 output +=
r'\end{document}'
289 with open( args.directory +
'/' + texfile,
'w' )
as f:
292 badEnvVars = [
'TEXMFCNF',
'TEXINPUTS',
'TEXMFHOME' ]
296 stat, out = getstatusoutput(
'cd %s; pdflatex -halt-on-error %s; pdflatex -halt-on-error %s'%( args.directory, texfile, texfile ) )
303 if __name__ ==
"__main__":
304 if sys.version_info < (2,7):
305 print(
'INFO This program requires Python version 2.7 or greater' )
309 ROOT.gROOT.SetBatch()