46 ClassImp(RooStats::HypoTestInverterPlot);
48 using namespace RooStats;
54 HypoTestInverterPlot::HypoTestInverterPlot(HypoTestInverterResult* results ) :
55 TNamed( results->GetName(), results->GetTitle() ),
63 HypoTestInverterPlot::HypoTestInverterPlot(
const char* name,
65 HypoTestInverterResult* results ) :
66 TNamed( TString(name), TString(title) ),
80 TGraphErrors* HypoTestInverterPlot::MakePlot(Option_t * opt)
85 if (option.Contains(
"CLB")) type = 1;
86 else if (option.Contains(
"CLS+B") || option.Contains(
"CLSPLUSB")) type = 2;
87 else if (option.Contains(
"CLS" )) type = 3;
89 const int nEntries = fResults->ArraySize();
92 std::vector<unsigned int> index(nEntries);
93 TMath::SortItr(fResults->fXValues.begin(), fResults->fXValues.end(), index.begin(),
false);
96 std::vector<Double_t> xArray(nEntries);
97 std::vector<Double_t> yArray(nEntries);
98 std::vector<Double_t> yErrArray(nEntries);
99 for (
int i=0; i<nEntries; i++) {
100 xArray[i] = fResults->GetXValue(index[i]);
102 yArray[i] = fResults->GetYValue(index[i]);
103 yErrArray[i] = fResults->GetYError(index[i]);
104 }
else if (type == 1) {
105 yArray[i] = fResults->CLb(index[i]);
106 yErrArray[i] = fResults->CLbError(index[i]);
107 }
else if (type == 2) {
108 yArray[i] = fResults->CLsplusb(index[i]);
109 yErrArray[i] = fResults->CLsplusbError(index[i]);
110 }
else if (type == 3) {
111 yArray[i] = fResults->CLs(index[i]);
112 yErrArray[i] = fResults->CLsError(index[i]);
116 TGraphErrors* graph =
new TGraphErrors(nEntries,&xArray.front(),&yArray.front(),0,&yErrArray.front());
117 TString pValueName =
"CLs";
118 if (type == 1 ) pValueName =
"CLb";
119 if (type == 2 || (type == 0 && !fResults->fUseCLs) ) pValueName =
"CLs+b";
120 TString name = pValueName + TString(
"_observed");
121 TString title = TString(
"Observed ") + pValueName;
122 graph->SetName(name);
123 graph->SetTitle(title);
124 graph->SetMarkerStyle(20);
125 graph->SetLineWidth(2);
137 TMultiGraph* HypoTestInverterPlot::MakeExpectedPlot(
double nsig1,
double nsig2 )
139 const int nEntries = fResults->ArraySize();
140 bool doFirstBand = (nsig1 > 0);
141 bool doSecondBand = (nsig2 > nsig1);
143 nsig1 = std::abs(nsig1);
144 nsig2 = std::abs(nsig2);
147 std::vector<unsigned int> index(nEntries);
148 TMath::SortItr(fResults->fXValues.begin(), fResults->fXValues.end(), index.begin(),
false);
151 TGraph * g0 =
new TGraph;
152 TString pValueName =
"CLs";
153 if (!fResults->fUseCLs) pValueName =
"CLs+b";
154 g0->SetTitle(TString::Format(
"Expected %s - Median",pValueName.Data()) );
155 TGraphAsymmErrors * g1 = 0;
156 TGraphAsymmErrors * g2 = 0;
158 g1 =
new TGraphAsymmErrors;
159 if (nsig1 -
int(nsig1) < 0.01)
160 g1->SetTitle(TString::Format(
"Expected %s #pm %d #sigma",pValueName.Data(),int(nsig1)) );
162 g1->SetTitle(TString::Format(
"Expected %s #pm %3.1f #sigma",pValueName.Data(),nsig1) );
165 g2 =
new TGraphAsymmErrors;
166 if (nsig2 -
int(nsig2) < 0.01)
167 g2->SetTitle(TString::Format(
"Expected %s #pm %d #sigma",pValueName.Data(),int(nsig2)) );
169 g2->SetTitle(TString::Format(
"Expected %s #pm %3.1f #sigma",pValueName.Data(),nsig2) );
173 p[0] = ROOT::Math::normal_cdf(-nsig2);
174 p[1] = ROOT::Math::normal_cdf(-nsig1);
176 p[3] = ROOT::Math::normal_cdf(nsig1);
177 p[4] = ROOT::Math::normal_cdf(nsig2);
179 bool resultIsAsymptotic = ( !fResults->GetNullTestStatDist(0) && !fResults->GetAltTestStatDist(0) );
181 for (
int j=0; j<nEntries; ++j) {
183 SamplingDistribution * s = fResults->GetExpectedPValueDist(i);
185 const std::vector<double> & values = s->GetSamplingDistribution();
187 if (resultIsAsymptotic) {
188 double maxSigma = fResults->fgAsymptoticMaxSigma;
189 double dsig = 2* maxSigma/ (values.size() -1) ;
190 int i0 = (int) TMath::Floor ( ( -nsig2 + maxSigma )/dsig + 0.5);
191 int i1 = (int) TMath::Floor ( (-nsig1 + maxSigma )/dsig + 0.5);
192 int i2 = (int) TMath::Floor ( ( maxSigma)/dsig + 0.5);
193 int i3 = (int) TMath::Floor ( ( nsig1 + maxSigma)/dsig + 0.5);
194 int i4 = (int) TMath::Floor ( ( nsig2 + maxSigma)/dsig + 0.5);
202 double * x =
const_cast<double *
>(&values[0]);
203 TMath::Quantiles(values.size(), 5, x,q,p,
false);
206 g0->SetPoint(np, fResults->GetXValue(i), q[2]);
208 g1->SetPoint(np, fResults->GetXValue(i), q[2]);
209 g1->SetPointEYlow(np, q[2] - q[1]);
210 g1->SetPointEYhigh(np, q[3] - q[2]);
213 g2->SetPoint(np, fResults->GetXValue(i), q[2]);
215 g2->SetPointEYlow(np, q[2]-q[0]);
216 g2->SetPointEYhigh(np, q[4]-q[2]);
222 TString name = GetName() + TString(
"_expected");
223 TString title = TString(
"Expected ") + GetTitle();
224 TMultiGraph* graph =
new TMultiGraph(name,title);
229 g2->SetFillColor(kYellow);
233 g1->SetFillColor(kGreen);
246 HypoTestInverterPlot::~HypoTestInverterPlot()
262 void HypoTestInverterPlot::Draw(Option_t * opt) {
266 bool drawAxis = !option.Contains(
"SAME");
267 bool drawObs = option.Contains(
"OBS") || !option.Contains(
"EXP");
268 bool drawExp = option.Contains(
"EXP") || !option.Contains(
"OBS");
269 bool drawCLb = option.Contains(
"CLB");
270 bool draw2CL = option.Contains(
"2CL");
272 TGraphErrors * gobs = 0;
277 if (gROOT) gROOT->Add(gobs);
281 gplot->GetHistogram()->SetTitle( GetTitle() );
283 else gobs->Draw(
"PL");
286 TMultiGraph * gexp = 0;
288 gexp = MakeExpectedPlot();
290 if (gROOT) gROOT->Add(gexp);
291 if (drawAxis && !drawObs) {
293 if (gexp->GetHistogram()) gexp->GetHistogram()->SetTitle( GetTitle() );
294 gplot = (TGraph*) gexp->GetListOfGraphs()->First();
303 double alpha = 1.-fResults->ConfidenceLevel();
304 double x1 = gplot->GetXaxis()->GetXmin();
305 double x2 = gplot->GetXaxis()->GetXmax();
306 TLine * line =
new TLine(x1, alpha, x2,alpha);
307 line->SetLineColor(kRed);
310 RooAbsArg * arg = fResults->fParameters.first();
311 if (arg) gplot->GetXaxis()->SetTitle(arg->GetName());
312 gplot->GetYaxis()->SetTitle(
"p value");
318 gclb = MakePlot(
"CLb");
319 if (gROOT) gROOT->Add(gclb);
320 gclb->SetMarkerColor(kBlue+4);
323 if (gobs) gobs->SetMarkerColor(kRed);
328 if (fResults->fUseCLs) {
329 gclsb = MakePlot(
"CLs+b");
330 if (gROOT) gROOT->Add(gclsb);
331 gclsb->SetMarkerColor(kBlue);
333 gclsb->SetLineStyle(3);
336 gcls = MakePlot(
"CLs");
337 if (gROOT) gROOT->Add(gcls);
338 gcls->SetMarkerColor(kBlue);
340 gcls->SetLineStyle(3);
350 double verticalSize = (gexp || draw2CL || drawCLb ) ? 0.3 : 0.15;
351 double y1 = y0 + verticalSize;
352 TLegend * l =
new TLegend(0.6,y0,0.9,y1);
353 if (gobs) l->AddEntry(gobs,
"",
"PEL");
354 if (gclsb) l->AddEntry(gclsb,
"",
"PEL");
355 if (gcls) l->AddEntry(gcls,
"",
"PEL");
356 if (gclb) l->AddEntry(gclb,
"",
"PEL");
359 int ngraphs = gexp->GetListOfGraphs()->GetSize();
360 for (
int i = ngraphs-1; i>=0; --i) {
361 TObject * obj = gexp->GetListOfGraphs()->At(i);
363 if (i == ngraphs-1) lopt =
"L";
364 if (obj) l->AddEntry(obj,
"",lopt);
369 if (gPad) gPad->RedrawAxis();
381 SamplingDistPlot * HypoTestInverterPlot::MakeTestStatPlot(
int index,
int type,
int nbins) {
382 SamplingDistPlot * pl = 0;
384 HypoTestResult * result = (HypoTestResult*) fResults->fYObjects.At(index);
386 pl =
new HypoTestPlot(*result, nbins );
390 SamplingDistribution * sbDist = fResults->GetSignalAndBackgroundTestStatDist(index);
392 pl =
new SamplingDistPlot( nbins);
393 pl->AddSamplingDistribution(sbDist);
398 SamplingDistribution * bDist = fResults->GetBackgroundTestStatDist(index);
400 pl =
new SamplingDistPlot( nbins);
401 pl->AddSamplingDistribution(bDist);