2 PerformanceCurvePlotter
4 Author: Evan K. Friis, UC Davis (friis@physics.ucdavis.edu)
6 Plot the efficiency for a given fake rate
7 for a series of cuts in a set pt range.
9 With the default cuts (20 < pt < 50), this is designed
10 to reproduce (independently) the TancBenchmark plots produced in
11 RecoTauTag/TauTagTools/test/MVABenchmarks.py
16 Add the releases to as shown. You must specify and signal
17 and backround file for each release, and a descriptive label.
18 To choose the chain of discriminators to plot, select the appropriate
19 EDProducer defined in Validation.RecoTau.TauTagValidation_cfi
21 PreFourTanc = TauValidationInfo("Signal.root",
24 Validation.RecoTau.RecoTauValidation_cfi.RunTancValidation)
26 PreFourIso = TauValidationInfo("Signal.root",
29 Validation.RecoTau.RecoTauValidation_cfi.PFTausHighEfficiencyLeadingPionBothProngs)
32 ReleasesToBuildFrom = []
33 ReleasesToBuildFrom.append(PreFourTanc)
34 ReleasesToBuildFrom.append(PreFourIso)
36 PlotPerformanceCurves(ReleasesToBuildFrom, "output.png")
40 from ROOT
import TH1F, TGraph, TCanvas, TPad, EColor, TFile, TGraphAsymmErrors, Double, TLegend, gPad, TPaveText, gROOT, gStyle
46 Kinematic cuts applied to the sample. The Validation histograms
47 will be integrated over this range. You can only select one variable.
51 LatexVar =
"True p_{T}"
57 HideMuonAndElectronRej =
True
61 gROOT.SetStyle(
"Plain")
64 gStyle.SetTitleBorderSize(0)
67 """ Atomic object to hold information about where files are located, which discriminants to plot """
68 DiscriminatorToMarkerStyleDict = {}
69 StaticMarkerStyleIterator = 20
70 StaticSummaryLineColorIterator = 2
71 StupidRootStupidNameCounter = 0
72 DiscriminatorLegend = TLegend(0.15, 0.6, 0.5, 0.92)
73 DiscriminatorLegend.SetFillColor(0)
74 DiscriminatorBackground = 0
75 SummaryLegend = TLegend(0.6, 0.3, 0.9, 0.4)
76 SummaryLegend.SetBorderSize(0)
77 SummaryLegend.SetFillColor(0)
79 def __init__(self, SignalFile, BackgroundFile, Label, ValidationProducer):
84 self.
InfoDictionary = {
'producer' : self.ValidationProducer.TauProducer.value(),
85 'label' : self.ValidationProducer.ExtensionName.value(),
86 'var' : KinematicVar }
91 if HideMuonAndElectronRej:
94 if aPoint[
'name'].
find(
"Electron") == -1
and aPoint[
'name'].
find(
"Muon") == -1:
95 NewPoints.append(aPoint)
99 self.
Denominator = {
'loc' :
"DQMData/RecoTauV/%(producer)s%(label)s_ReferenceCollection/nRef_Taus_vs_%(var)sTauVisible" % self.
InfoDictionary }
103 output =
"DQMData/RecoTauV/%(producer)s%(label)s_%(disc)s/%(disc)s_vs_%(var)sTauVisible" % self.
InfoDictionary
107 """ Rebin a range of an input histogram into a new histogram w/ 1 bin. """
108 OutputHisto = TH1F(
"temp_%i" % TauValidationInfo.StupidRootStupidNameCounter,
"temp", 1, MinBinValue, MaxBinValue)
109 TauValidationInfo.StupidRootStupidNameCounter += 1
110 MinBinNumber = Histo.FindBin(MinBinValue)
111 MaxBinNumber = Histo.FindBin(MaxBinValue)
113 OutputHisto.SetBinContent(1,Histo.Integral(MinBinNumber, MaxBinNumber))
118 print "Loading histograms for %s" % self.
Label
119 SignalDenominatorHisto = self.SignalFile.Get(self.
Denominator[
'loc'])
120 self.
Denominator[
'SignalHisto'] = SignalDenominatorHisto
122 BackgroundDenominatorHisto = self.BackgroundFile.Get(self.
Denominator[
'loc'])
123 self.
Denominator[
'BackgroundHisto'] = BackgroundDenominatorHisto
124 self.
Denominator[
'BackgroundHistoRebin'] = self.
RebinHistogram(BackgroundDenominatorHisto, KinematicVarMin, KinematicVarMax)
127 SignalPointHisto = self.SignalFile.Get(aPoint[
'loc'])
128 aPoint[
'SignalHisto'] = SignalPointHisto
129 aPoint[
'SignalHistoRebin'] = self.
RebinHistogram(SignalPointHisto, KinematicVarMin, KinematicVarMax)
130 BackgroundPointHisto = self.BackgroundFile.Get(aPoint[
'loc'])
131 aPoint[
'BackgroundHisto'] = BackgroundPointHisto
132 aPoint[
'BackgroundHistoRebin'] = self.
RebinHistogram(BackgroundPointHisto, KinematicVarMin, KinematicVarMax)
134 print "Computing efficiencies for %s" % self.
Label
135 print "-----------------------------------------------------"
136 print "%-40s %10s %10s" % (
"Discriminator",
"SignalEff",
"FakeRate")
137 print "-----------------------------------------------------"
139 SignalDenominatorHisto = self.
Denominator[
'SignalHistoRebin']
140 BackgroundDenominatorHisto = self.
Denominator[
'BackgroundHistoRebin']
142 SignalPointHisto = aPoint[
'SignalHistoRebin']
143 BackgroundPointHisto = aPoint[
'BackgroundHistoRebin']
145 TempSignalEffPoint = TGraphAsymmErrors(SignalPointHisto, SignalDenominatorHisto)
146 TempBackgroundEffPoint = TGraphAsymmErrors(BackgroundPointHisto, BackgroundDenominatorHisto)
148 PerformancePoint = TGraphAsymmErrors(1)
149 xValueSignal = Double(0)
150 yValueSignal = Double(0)
151 xValueBackground = Double(0)
152 yValueBackground = Double(0)
153 TempSignalEffPoint.GetPoint(0, xValueSignal, yValueSignal)
154 TempBackgroundEffPoint.GetPoint(0, xValueBackground, yValueBackground)
155 aPoint[
'SignalEff'] = yValueSignal
156 aPoint[
'BackgroundEff'] = yValueBackground
157 print "%-40s %10.3f %10.4f" % (aPoint[
'name'], aPoint[
'SignalEff'], aPoint[
'BackgroundEff'])
158 PerformancePoint.SetPoint(0, yValueSignal, yValueBackground)
159 PerformancePoint.SetPointError(0,
160 TempSignalEffPoint.GetErrorYlow(0),
161 TempSignalEffPoint.GetErrorYhigh(0),
162 TempBackgroundEffPoint.GetErrorYlow(0),
163 TempBackgroundEffPoint.GetErrorYhigh(0) )
164 PerformancePoint.SetMarkerSize(2)
166 PerformancePoint.SetMarkerStyle(TauValidationInfo.DiscriminatorToMarkerStyleDict[aPoint[
'name']])
168 PerformancePoint.SetMarkerStyle(TauValidationInfo.StaticMarkerStyleIterator)
169 TauValidationInfo.DiscriminatorToMarkerStyleDict[aPoint[
'name']] = TauValidationInfo.StaticMarkerStyleIterator
170 self.DiscriminatorLegend.AddEntry( PerformancePoint, aPoint[
'name'],
"P")
171 TauValidationInfo.StaticMarkerStyleIterator += 1
172 aPoint[
'PerformancePoint'] = PerformancePoint
174 print "Building summary"
177 self.SummaryTGraph.SetPoint(index, aPoint[
'SignalEff'], aPoint[
'BackgroundEff'])
178 self.SummaryTGraph.SetLineColor(TauValidationInfo.StaticSummaryLineColorIterator)
179 self.SummaryTGraph.SetLineWidth(2)
181 TauValidationInfo.StaticSummaryLineColorIterator += 1
186 myCanvas = TCanvas(
"Validation",
"Validation", 800, 800)
188 CutLabel = TPaveText(0.6, 0.1, 0.9, 0.27,
"brNDC")
189 CutLabel.AddText(
"%0.1f%s < %s < %0.1f%s" % (KinematicVarMin, VarUnit, LatexVar, KinematicVarMax, VarUnit))
190 CutLabel.SetFillStyle(0)
191 CutLabel.SetBorderSize(0)
194 for aRelease
in ReleasesToBuildFrom:
195 aRelease.LoadHistograms()
196 aRelease.ComputeEfficiencies()
197 aRelease.BuildTGraphSummary()
201 for aRelease
in ReleasesToBuildFrom:
202 if CurrentHistogram == 0:
203 aRelease.SummaryTGraph.Draw(
"ALP")
204 CurrentHistogram = aRelease.SummaryTGraph.GetHistogram()
206 aRelease.SummaryTGraph.Draw(
"LP")
209 CurrentHistogram.SetAxisRange(0, 1)
210 CurrentHistogram.GetYaxis().SetRangeUser(0.0001,1)
211 CurrentHistogram.GetXaxis().SetTitle(
"Efficiency")
212 CurrentHistogram.GetYaxis().SetTitle(
"Fake Rate")
213 CurrentHistogram.SetTitle(
"Performance Points")
217 for aRelease
in ReleasesToBuildFrom:
218 for aPoint
in aRelease.DiscriminatorPoints:
219 aPoint[
'PerformancePoint'].Draw(
"P")
221 TauValidationInfo.SummaryLegend.Draw()
222 TauValidationInfo.DiscriminatorLegend.Draw()
225 myCanvas.SaveAs(OutputFile)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)