95 def CreateProfile( infile, HistDir, HistName, Var, MuonType, doAverage = False, doBinned = False ):
96 hist = infile.Get(HistDir).
Get(HistName)
97 if hist.IsA().InheritsFrom(ROOT.TProfile.Class()):
99 xtitle = MuonType +
' Muon '
107 prof_ave.SetName( HistName.replace(
'pT_vs',
'PtScale_vs' ) )
108 prof_ave.SetTitle(
'pT Scale vs ' + Var )
109 prof_ave.SetXTitle( xtitle )
110 prof_ave.SetYTitle(
'pT scale' )
112 prof_std.SetName( HistName.replace(
'pT_vs',
'PtResol_vs' ) )
113 prof_std.SetTitle(
'pT Resolution vs ' + Var )
114 prof_std.SetXTitle( xtitle )
115 prof_std.SetYTitle(
'pT resolution' )
117 if not infile.Get( HistDir ).WriteTObject( prof_ave, prof_ave.GetName(),
"Overwrite" ):
119 print(
'WARNING failed to write histogram to file: ' + HistDir +
'/' + prof_ave.GetName() )
120 if not infile.Get( HistDir ).WriteTObject( prof_std, prof_std.GetName(),
"Overwrite" ):
122 print(
'WARNING failed to write histogram to file: ' + HistDir +
'/' + prof_std.GetName() )
125 bindirname = Var.lower() +
'Bins'
126 bindirpath = HistDir +
'/' + bindirname
127 bindir = infile.GetDirectory( bindirpath )
129 bindir = infile.GetDirectory( HistDir ).
mkdir( bindirname )
132 canv = ROOT.TCanvas(
"canv",
"",800,800);
136 storePlots =
'resPlots/'+os.path.split(infile.GetName())[1].
replace(
'.root',
'')
137 if not os.path.exists(storePlots):
138 os.makedirs(storePlots)
139 print(
'Creating directory: '+storePlots)
141 for x1,name,plot
in sorted([ (
float(name.split(
'_')[0]), name, plot)
for name, plot
in binnedRes.iteritems() ]):
142 plot.SetName(
'bin_' + name.replace(
'-',
'm') )
143 plot.SetTitle(
'pT Resolution {0} < {1} < {2}'.
format( name.split(
'_')[0], Var, name.split(
'_')[1] ) )
144 plot.SetYTitle(
'Entries' )
151 canv.SaveAs(storePlots+
'/'+HistDir.replace(
'/',
'_')+
'_PtResFits_{0}_bins_{1}.pdf'.
format(Var,icanv))
158 t.SetNDC(); t.SetTextColor(1);
159 tit = name.replace(
'm',
'-').
replace(
'_',
'<'+Var+
'<')
160 mu = mu_err = sigma = sigma_err = 0
163 t.DrawLatex(0.2,0.96,plot.GetTitle())
164 resultMeanLab =
'#mu = {0:0.2g} #pm {1:0.2g}'.
format( mu, mu_err )
165 resultSigmaLab =
'#sigma = {0:0.2g} #pm {1:0.2g}'.
format( sigma, sigma_err )
166 t.DrawLatex(0.2,0.85,
'#splitline{'+resultMeanLab+
'}{'+resultSigmaLab+
'}')
169 canv.SaveAs(storePlots+
'/'+HistDir.replace(
'/',
'_')+
'_PtResFits_{0}_bins_{1}.pdf'.
format(Var,icanv))
172 del prof_ave, prof_std, binnedRes