diff --git a/scripts/checkTrackSelection.py b/scripts/checkTrackSelection.py index 2676036..488dd7d 100644 --- a/scripts/checkTrackSelection.py +++ b/scripts/checkTrackSelection.py @@ -3,10 +3,11 @@ # @Author: Elena Graverini # @Date: 2015-10-27 18:26:49 # @Last Modified by: Elena Graverini -# @Last Modified time: 2017-05-03 17:03:17 +# @Last Modified time: 2017-05-03 18:58:44 -import ROOT as r import os +from math import sqrt +import ROOT as r location = {'TT': "/disk/data1/hep/elena/data/ST/Aging_Tuples/TT/TTaU/", 'IT': "/disk/data1/hep/elena/data/ST/Aging_Tuples/IT/T3X2/"} @@ -35,26 +36,39 @@ r.gStyle.SetPadTopMargin(0.05) -def printSelection(f, t_sig, det, fill, stat): - r.gStyle.SetPadLeftMargin(0.20) - r.gStyle.SetPadRightMargin(0.25) - r.gStyle.SetPadBottomMargin(0.15) - r.gStyle.SetPadTopMargin(0.05) - print t_sig.Draw("GhostP : TrChi2/TrNDoF>>hsig(100,0., 5,100, 0.,1.)", "val%s>%s" % (val[det], cut[det]), "goff", stat, 0) - h_sig = r.gDirectory.Get('hsig') - print t_sig.Draw("GhostP : TrChi2/TrNDoF>>hnoise(100,0., 5,100, 0.,1.)", "val%s<%s" % (val[det], cut[det]), "goff", stat, 0) - h_noise = r.gDirectory.Get('hnoise') - c = r.TCanvas() - h_sig.Divide(h_noise) - # h_sig.Draw("colz") - h_sig.GetZaxis().SetRangeUser(0, 10) - h_sig.SetTitle('TTaU S/B ratio for fill %s' % fill) - h_sig.GetXaxis().SetTitle(r'#chi^{2}_{track}/ndf') - h_sig.GetYaxis().SetTitle(r'Ghost Prob.') - h_sig.GetZaxis().SetTitle(r'S/B ratio') - h_sig.Draw("colz") - c.Update() - c, line = putLine(c, det) +def sqrt_of_2d_histogram(h): + new = h.Clone() + nbins = h.GetNbinsX() * h.GetNbinsY() + for i in range(nbins): + new.SetBinContent(i, sqrt(h.GetBinContent(i))) + return new + + +def s_over_b(s, b): + h = s.Clone() + res = h.Divide(b) + res.name = 's_over_b' + return res + + +def s_over_sqrtb(s, b): + h = s.Clone() + sqrtb = sqrt_of_2d_histogram(b) + res = h.Divide(sqrtb) + res.name = 's_over_sqrtb' + return res + + +def punzi_significance(s, b): + h = s.Clone() + sb = s.Add(b) + sqrt_sb = sqrt_of_2d_histogram(sb) + res = h.Divide(sqrt_sb) + res.name = 'punzi_significance' + return res + + +def put_fill(c, fill): label = r.TPaveText( 0.74 - r.gStyle.GetPadRightMargin(), 0.87 - r.gStyle.GetPadTopMargin(), 0.95 - r.gStyle.GetPadRightMargin(), 0.95 - r.gStyle.GetPadTopMargin(), "BRNDC") label.SetFillColor(0) @@ -67,7 +81,51 @@ label.Draw('same') c.Modified() c.Update() - c.SaveAs('%s/%s_fill%s.pdf' % (out_location, det, fill)) + return c + + +def printSelection(f, t_sig, det, fill, stat): + r.gStyle.SetPadLeftMargin(0.20) + r.gStyle.SetPadRightMargin(0.25) + r.gStyle.SetPadBottomMargin(0.15) + r.gStyle.SetPadTopMargin(0.05) + print t_sig.Draw("GhostP : TrChi2/TrNDoF>>hsig(100,0., 5,100, 0.,1.)", "val%s>%s" % (val[det], cut[det]), "goff", stat, 0) + h_sig = r.gDirectory.Get('hsig') + print t_sig.Draw("GhostP : TrChi2/TrNDoF>>hnoise(100,0., 5,100, 0.,1.)", "val%s<%s" % (val[det], cut[det]), "goff", stat, 0) + h_noise = r.gDirectory.Get('hnoise') + # c = r.TCanvas() + csaver = [] + h_s_over_b = s_over_b(h_sig, h_noise) + h_s_over_b.GetZaxis().SetRangeUser(0, 10) + h_s_over_b.GetZaxis().SetTitle('S/B ratio') + h_s_over_sqrtb = s_over_sqrtb(h_sig, h_noise) + h_s_over_sqrtb.GetZaxis().SetRangeUser(0, 50) + h_s_over_sqrtb.GetZaxis().SetTitle('S/#sqrt{B}') + h_punzi_significance = punzi_significance(h_sig, h_noise) + h_punzi_significance.GetZaxis().SetRangeUser(0, 10) + h_punzi_significance.GetZaxis().SetTitle('S/#sqrt{S+B}') + for h in [h_s_over_b, h_s_over_sqrtb, h_punzi_significance]: + csaver.append(r.TCanvas()) + csaver[-1].cd() + h.GetXaxis().SetTitle(r'#chi^{2}_{track}/ndf') + h.GetYaxis().SetTitle(r'Ghost Prob.') + h.Draw('colz') + csaver[-1].Update() + csaver[-1], line = putLine(c, det) + csaver[-1] = put_fill(fill) + csaver[-1].SaveAs('%s/%s_%s_fill%s.pdf' % (out_location, det, h.name, fill)) + h.Delete() + # h_sig.Divide(h_noise) + # h_sig.GetZaxis().SetRangeUser(0, 10) + # h_sig.SetTitle('TTaU S/B ratio for fill %s' % fill) + # h_sig.GetXaxis().SetTitle(r'#chi^{2}_{track}/ndf') + # h_sig.GetYaxis().SetTitle(r'Ghost Prob.') + # h_sig.GetZaxis().SetTitle(r'S/B ratio') + # h_sig.Draw("colz") + # c.Update() + # c, line = putLine(c, det) + # c = put_fill(c, fill) + # c.SaveAs('%s/%s_fill%s.pdf' % (out_location, det, fill)) h_sig.Delete() h_noise.Delete() return f, t_sig