1 #ifndef ICHiggsTauTau_Core_Plotting_Countours_h
2 #define ICHiggsTauTau_Core_Plotting_Countours_h
28 TGraph *
bestFit(TTree *t, TString x, TString y, TCut cut);
30 TH2 *
treeToHist2D(TTree *t, TString x, TString y, TString name, TCut cut,
31 double xmin,
double xmax,
double ymin,
double ymax,
int xbins,
34 TList *
contourFromTH2(TH2 *h2in,
double threshold,
int minPoints = 20);
36 TH2D *
frameTH2D(TH2D *in,
double threshold);
43 void drawContours(TPad *pad, TString file, TString x_title, TString y_title,
69 void contour2D(TString filein, TString fileout, TString xvar,
int xbins,
float xmin,
float xmax, TString yvar,
70 int ybins,
float ymin,
float ymax, TString name =
"contour2D") {
73 TTree *tree = (TTree *)gFile->Get(
"limit");
74 TH2 *hist2d =
treeToHist2D(tree, xvar, yvar,
"h2d",
"", xmin, xmax, ymin,
76 hist2d->SetContour(200);
77 hist2d->GetZaxis()->SetRangeUser(0, 21);
78 TGraph *fit =
bestFit(tree, xvar, yvar,
"");
82 TFile fout(fileout,
"RECREATE");
84 hist2d->SetName(name +
"_h2d");
85 fout.WriteTObject(hist2d, 0);
86 fit->SetName(name +
"_best");
87 fout.WriteTObject(fit, 0);
88 c68->SetName(name +
"_c68");
89 fout.WriteTObject(c68, 0,
"SingleKey");
90 c95->SetName(name +
"_c95");
91 fout.WriteTObject(c95, 0,
"SingleKey");
92 c997->SetName(name +
"_c997");
93 fout.WriteTObject(c997, 0,
"SingleKey");
94 c68->At(1)->Write(
"second");
100 TGraph *
bestFit(TTree *t, TString x, TString y, TCut cut) {
101 int nfind = t->Draw(y +
":" + x, cut +
"deltaNLL == 0");
103 TGraph *gr0 =
new TGraph(1);
104 gr0->SetPoint(0, -999, -999);
105 gr0->SetMarkerStyle(34);
106 gr0->SetMarkerSize(2.0);
109 TGraph *gr0 = (TGraph *)gROOT->FindObject(
"Graph")->Clone();
110 gr0->SetMarkerStyle(34);
111 gr0->SetMarkerSize(2.0);
112 if (gr0->GetN() > 1) gr0->Set(1);
117 TH2 *
treeToHist2D(TTree *t, TString x, TString y, TString name, TCut cut,
118 double xmin,
double xmax,
double ymin,
double ymax,
int xbins,
120 t->Draw(Form(
"2*deltaNLL:%s:%s>>%s_prof(%d,%10g,%10g,%d,%10g,%10g)", y.Data(),
121 x.Data(), name.Data(), xbins, xmin, xmax, ybins, ymin, ymax),
122 cut +
"deltaNLL != 0",
"PROF");
123 TH2 *prof = (TH2 *)gROOT->FindObject(name +
"_prof");
124 TH2D *h2d =
new TH2D(name, name, xbins, xmin, xmax, ybins, ymin, ymax);
125 for (
int ix = 1; ix <= xbins; ++ix) {
126 for (
int iy = 1; iy <= ybins; ++iy) {
127 double z = prof->GetBinContent(ix, iy);
128 if (z == TMath::Infinity()) z = 999;
130 z = (name.Contains(
"bayes") ? 0 : 999);
131 h2d->SetBinContent(ix, iy, z);
134 h2d->GetXaxis()->SetTitle(x);
135 h2d->GetYaxis()->SetTitle(y);
136 h2d->SetDirectory(0);
141 std::cout <<
"Getting contour at threshold " << threshold <<
" from "
142 << h2in->GetName() << std::endl;
144 Double_t contours[1];
145 contours[0] = threshold;
146 if (h2in->GetNbinsX() * h2in->GetNbinsY() > 10000) minPoints = 50;
147 if (h2in->GetNbinsX() * h2in->GetNbinsY() <= 100) minPoints = 10;
149 TH2D *h2 =
frameTH2D((TH2D *)h2in, threshold);
151 h2->SetContour(1, contours);
154 h2->Draw(
"CONT Z LIST");
160 (TObjArray *)gROOT->GetListOfSpecials()->FindObject(
"contours");
161 TList *contLevel = NULL;
163 if (conts == NULL || conts->GetSize() == 0) {
164 printf(
"*** No Contours Were Extracted!\n");
168 TList *ret =
new TList();
169 for (
int i = 0; i < conts->GetSize(); i++) {
170 contLevel = (TList *)conts->At(i);
172 for (
int j = 0, n = contLevel->GetSize(); j < n; ++j) {
173 TGraph *gr1 = (TGraph *)contLevel->At(j);
175 if (gr1->GetN() > minPoints) ret->Add(gr1->Clone());
186 double frameValue = 1000;
187 if (TString(in->GetName()).Contains(
"bayes")) frameValue = -1000;
189 Double_t xw = in->GetXaxis()->GetBinWidth(1);
190 Double_t yw = in->GetYaxis()->GetBinWidth(1);
192 Int_t nx = in->GetNbinsX();
193 Int_t ny = in->GetNbinsY();
195 Double_t x0 = in->GetXaxis()->GetXmin();
196 Double_t x1 = in->GetXaxis()->GetXmax();
198 Double_t y0 = in->GetYaxis()->GetXmin();
199 Double_t y1 = in->GetYaxis()->GetXmax();
200 Double_t xbins[999], ybins[999];
204 xbins[0] = x0 - eps * xw - xw * mult;
205 xbins[1] = x0 + eps * xw - xw * mult;
206 for (
int ix = 2; ix <= nx; ++ix) xbins[ix] = x0 + (ix - 1) * xw;
207 xbins[nx + 1] = x1 - eps * xw + 0.5 * xw * mult;
208 xbins[nx + 2] = x1 + eps * xw + xw * mult;
210 ybins[0] = y0 - eps * yw - yw * mult;
211 ybins[1] = y0 + eps * yw - yw * mult;
212 for (
int iy = 2; iy <= ny; ++iy) ybins[iy] = y0 + (iy - 1) * yw;
213 ybins[ny + 1] = y1 - eps * yw + yw * mult;
214 ybins[ny + 2] = y1 + eps * yw + yw * mult;
217 new TH2D(Form(
"%s framed", in->GetName()),
218 Form(
"%s framed", in->GetTitle()), nx + 2, xbins, ny + 2, ybins);
221 for (
int ix = 1; ix <= nx; ix++) {
222 for (
int iy = 1; iy <= ny; iy++) {
223 framed->SetBinContent(1 + ix, 1 + iy, in->GetBinContent(ix, iy));
227 nx = framed->GetNbinsX();
228 ny = framed->GetNbinsY();
229 for (
int ix = 1; ix <= nx; ix++) {
230 framed->SetBinContent(ix, 1, frameValue);
231 framed->SetBinContent(ix, ny, frameValue);
233 for (
int iy = 2; iy <= ny - 1; iy++) {
234 framed->SetBinContent(1, iy, frameValue);
235 framed->SetBinContent(nx, iy, frameValue);
260 void drawContours(TPad *pad, TString file, TString x_title, TString y_title,
263 TH2D *h2d = (TH2D *)gDirectory->Get(
"contour2D_h2d");
265 h2d->GetXaxis()->SetTitle(x_title);
266 h2d->GetYaxis()->SetTitle(y_title);
271 TGraph *bestfit = (TGraph *)gDirectory->Get(
"contour2D_best");
272 std::vector<TGraph *> c68;
273 std::vector<TGraph *> c95;
275 TList * l68 = (TList *)gDirectory->Get(
"contour2D_c68");
276 for (
int i = 0; i < l68->GetSize(); ++i) {
277 c68.push_back((TGraph *)l68->At(i));
280 TList * l95 = (TList *)gDirectory->Get(
"contour2D_c95");
281 for (
int i = 0; i < l95->GetSize(); ++i) {
282 c95.push_back((TGraph *)l95->At(i));
289 for (
unsigned i = 0; i < c95.size(); ++i) {
290 c95[i]->SetLineStyle(1);
291 c95[i]->SetLineColor(kBlack);
293 c95[i]->SetFillColor(kBlue - 10);
294 c95[i]->Draw(
"F SAME");
297 for (
unsigned i = 0; i < c68.size(); ++i) {
298 c68[i]->SetLineStyle(1);
299 c68[i]->SetLineColor(kBlack);
301 c68[i]->SetFillColor(kBlue - 8);
302 c68[i]->Draw(
"F SAME");
305 for (
unsigned i = 0; i < c95.size(); ++i) c95[i]->Draw(
"L SAME");
306 for (
unsigned i = 0; i < c68.size(); ++i) c68[i]->Draw(
"L SAME");
308 bestfit->SetMarkerStyle(34);
309 bestfit->SetMarkerSize(3.0);
310 bestfit->SetMarkerColor(kBlack);
313 leg->AddEntry(c95[0],
"95% CL",
"F");
314 leg->AddEntry(c68[0],
"68% CL",
"F");
void styleMultiGraphMarker(TList *tmg, int markerColor, int markerSize, int markerStyle)
TH2D * frameTH2D(TH2D *in, double threshold)
TGraph * bestFit(TTree *t, TString x, TString y, TCut cut)
void contour2D(TString filein, TString fileout, TString xvar, int xbins, float xmin, float xmax, TString yvar, int ybins, float ymin, float ymax, TString name="contour2D")
Make a 2D contour plot from the output of MultiDimFit.
void styleMultiGraph(TList *tmg, int lineColor, int lineWidth, int lineStyle)
TList * contourFromTH2(TH2 *h2in, double threshold, int minPoints=20)
TH2 * treeToHist2D(TTree *t, TString x, TString y, TString name, TCut cut, double xmin, double xmax, double ymin, double ymax, int xbins, int ybins)
void drawContours(TPad *pad, TString file, TString x_title, TString y_title, TLegend *leg)