ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.25
Committed: Wed Apr 18 12:09:47 2012 UTC (13 years ago) by fronga
Content type: text/plain
Branch: MAIN
CVS Tags: cbaf_4_98ifb_paper, beforeFR20120418, HEAD
Changes since 1.24: +89 -40 lines
Log Message:
Modifications for paper (more bold, and others)

File Contents

# Content
1 #include <iostream>
2 #include <vector>
3 #include <sys/stat.h>
4 #include <sstream>
5
6 #include <TCut.h>
7 #include <TLatex.h>
8 #include <TROOT.h>
9 #include <TCanvas.h>
10 #include <TPad.h>
11 #include <TFile.h>
12 #include <TTree.h>
13 #include <TString.h>
14 #include <TPRegexp.h>
15 #include <TMath.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <TH2.h>
19 #include <TColor.h>
20 #include <TStyle.h>
21 #include <TText.h>
22 #include <TKey.h>
23 #include <TPaletteAxis.h>
24 #include <TGraph.h>
25 #include <TLegend.h>
26 #include <TLegendEntry.h>
27 #include "external/ExclusionPlot/Functions.C"
28
29 using namespace std;
30
31 bool draweachone=false;
32 bool draw2sigma=true;
33
34 //float limits_lower_bound=0.05;
35 float limits_lower_bound=1e-3; // For uniformity
36 float limits_upper_bound=10;
37 float limits_ratio_lower_bound=0.005;
38 float limits_ratio_upper_bound=10;
39
40 float standardmargin=0.1;
41 float indentedmargin=0.16;
42
43 bool drawefficiencydesertline=false;
44
45 string xsecfilename;
46
47 void set_range(TH2F *histo, int scantype, bool pushoutlabels);
48 void smooth_line(TGraph *gr);
49 void decorate_mSUGRA(TH2F *cleanhisto, TVirtualPad *cvsSys,TGraph *expected,TGraph *expected2,TGraph *observed);
50 void draw_diagonal_xchange(int scantype, std::string scanx);
51 TH2F* adjust_histo(TH2F *oldhist, TH2F *refhisto);
52 TGraph* get_mSUGRA_exclusion_line(TH2F *exclusionhisto, int scantype);
53 TGraph* thin_line(TGraph *gr);
54 TGraph *MarcosExclusionLine(TH2F *exclusionshape, int scantype);
55
56 void write_SMS_text(int scantype, std::string& scanx, float xpos = 0.22 ) {
57 string legT5zz="pp #rightarrow #tilde{g} #tilde{g}, #tilde{g} #rightarrow 2j + #chi^{0}_{2}, #chi^{0}_{2} #rightarrow Z #chi^{0}_{1}";
58 if ( scantype==PlottingSetup::GMSB) legT5zz="pp #rightarrow #tilde{g} #tilde{g}, #tilde{g} #rightarrow 2j + #chi^{0}_{1}, #chi^{0}_{1} #rightarrow Z #tilde{G}";
59
60 string legT5zzl2="m(#tilde{q}) >> m(#tilde{g})";
61 if (scantype==PlottingSetup::SMS) legT5zzl2 += ", x = "+scanx;
62 string legT5zzl3="JZB";
63
64 TText *title = write_text(xpos,0.85,legT5zz);
65 title->SetTextAlign(11);
66 title->SetTextFont(62);
67 title->SetTextSize(0.04);
68 if(scantype!=PlottingSetup::mSUGRA) title->Draw("same");
69 TText *title2 = write_text(xpos,0.79,legT5zzl2);
70 title2->SetTextAlign(11);
71 title2->SetTextFont(62);
72 title2->SetTextSize(0.04);
73 if(scantype!=PlottingSetup::mSUGRA) title2->Draw("same");
74 TText *title3 = write_text(0.40,0.79,legT5zzl3);
75 title3->SetTextAlign(11);
76 title3->SetTextFont(62);
77 title3->SetTextSize(0.04);
78 title3->SetTextColor(kRed);
79 // if(scantype==PlottingSetup::GMSB) title3->Draw("same");
80 }
81
82 void draw_diagonal_xchange(int scantype, std::string scanx = "" ) {
83 // Line marking the diagonal
84 TLine *line;
85 float verticaloffset=0.0;
86 if(scantype==PlottingSetup::GMSB) verticaloffset=75.0;
87 line = new TLine(50.+75.0, 50.0+verticaloffset, 1200., 1200.0-75.0+verticaloffset);
88 line->SetLineStyle(7);
89 line->SetLineWidth(4);
90 //line->Draw("same"); // Do not draw: draw the other one instead
91
92 // Add a dashed line to indicate where x changes
93 float offset = 0.;
94 if ( 0 == scanx.compare("0.5") ) { offset = 91.2/0.5; }
95 else if ( 0 == scanx.compare("0.25") ) { offset = 91.2/0.25; }
96 else if ( 0 == scanx.compare("0.75") ) { offset = 91.2/0.75; }
97 else if ( scantype==PlottingSetup::GMSB) { offset = 0; };
98
99 if ( offset>0. ) {
100 line->DrawLine(50+offset, 50.0, 1175., 1175.0-offset);
101 } else if ( scantype==PlottingSetup::GMSB ) {
102 line->DrawLine(100, 100, 1175., 1175.0-offset);
103 }
104 }
105
106 void fill_with_text(TGraph *real, TGraph *down, TGraph *up, TVirtualPad *can, int scantype, std::string scanx = "") {
107 can->cd();
108 float xpos_of_text = 0.22;
109 TLegend* this_leg = new TLegend(xpos_of_text,0.55,0.45,0.75,"n_{jets} #geq 3");
110 this_leg->SetFillColor(0);
111 this_leg->SetBorderSize(0);
112 // FR - BH this_leg->SetTextSize(0.035);
113 this_leg->SetTextSize(0.04);
114 if(scantype==PlottingSetup::SMS||scantype==PlottingSetup::GMSB) {
115 //this_leg->AddEntry(real,"#sigma^{prod} = #sigma^{NLO-QCD}" , "l");
116 //this_leg->AddEntry(up,"#sigma^{prod} = 3 #times #sigma^{NLO-QCD}" , "l");
117 //this_leg->AddEntry(down,"#sigma^{prod} = 1/3 #times #sigma^{NLO-QCD}" , "l");
118 this_leg->AddEntry(real,"#sigma^{NLO-QCD}" , "l");
119 this_leg->AddEntry(up,"3 #times #sigma^{NLO-QCD}" , "l");
120 this_leg->AddEntry(down,"1/3 #times #sigma^{NLO-QCD}" , "l");
121 } else {
122 write_warning(__FUNCTION__,"Not implemented yet for mSUGRA");
123 }
124
125 this_leg->Draw();
126
127 TText *title = write_text(xpos_of_text+0.005,0.52,"JZB");
128 title->SetTextSize(0.04);
129 title->SetTextAlign(13);
130 title->SetTextFont(62);
131 title->Draw();
132
133 write_SMS_text( scantype, scanx, xpos_of_text );
134
135
136 // //string legT5zz="pp #rightarrow #tilde{g} #tilde{g}, #tilde{g} #rightarrow 2j + #chi^{0}_{1}, #chi^{0}_{1} #rightarrow Z + #tilde{G}";
137 // string legT5zz="pp #rightarrow #tilde{g} #tilde{g}, #tilde{g} #rightarrow 2j + #chi^{0}_{2}, #chi^{0}_{2} #rightarrow Z #chi^{0}_{1}";
138 // string legT5zzl2="m(#tilde{q}) >> m(#tilde{g}), x = "+scanx;
139 // string legT5zzl3=" GMSB";
140 // TText *title = write_text(xpos_of_text,0.85,legT5zz);
141 // title->SetTextAlign(11);
142 // title->SetTextSize(0.035);
143 // if(scantype!=PlottingSetup::mSUGRA) title->Draw("same");
144 // TText *title2 = write_text(xpos_of_text,0.79,legT5zzl2);
145 // title2->SetTextAlign(11);
146 // title2->SetTextSize(0.035);
147 // if(scantype!=PlottingSetup::mSUGRA) title2->Draw("same");
148 // TText *title3 = write_text(0.40,0.79,legT5zzl3);
149 // title3->SetTextAlign(11);
150 // title3->SetTextSize(0.035);
151 // title3->SetTextColor(kRed);
152 //// if(scantype==PlottingSetup::GMSB) title3->Draw("same");
153 DrawPrelim();
154
155 draw_diagonal_xchange( scantype, scanx );
156
157 }
158
159 TH2F* prep_histo(TH2F *oldhist, int scantype) {///DONE
160 TH2F *histo = new TH2F(oldhist->GetName(),oldhist->GetName(),
161 oldhist->GetNbinsX(),oldhist->GetXaxis()->GetBinLowEdge(1),oldhist->GetXaxis()->GetBinLowEdge(oldhist->GetNbinsX())+oldhist->GetXaxis()->GetBinWidth(oldhist->GetNbinsX()),
162 oldhist->GetNbinsY(),oldhist->GetYaxis()->GetBinLowEdge(1),oldhist->GetYaxis()->GetBinLowEdge(oldhist->GetNbinsY())+oldhist->GetYaxis()->GetBinWidth(oldhist->GetNbinsY()));
163
164 for(int ix=1;ix<=oldhist->GetNbinsX();ix++) {
165 for(int iy=1;iy<=oldhist->GetNbinsX();iy++) {
166 histo->SetBinContent(ix,iy,oldhist->GetBinContent(ix,iy));
167 }
168 }
169 return histo;
170 }
171
172 TH2F *hardlimit(TH2F *limit) {
173 TH2F *co = (TH2F*)limit->Clone("hcopy");
174 for(int i=1;i<limit->GetNbinsX();i++) {
175 for(int j=1;j<limit->GetNbinsY();j++) {
176 if(limit->GetBinContent(i,j)<1&&limit->GetBinContent(i,j)>0) co->SetBinContent(i,j,1);
177 else co->SetBinContent(i,j,0);
178 }
179 }
180 return co;
181 }
182
183 TH2F* make_exclusion_shape(TH2F *excl, int isprimary) {
184 TH2F *exclusion = (TH2F*)excl->Clone("exclusion");
185 for(int i=1; i<(excl->GetNbinsX()+1); i++) {
186 for(int j=1; j<(excl->GetNbinsY()+1); j++) {
187 if(excl->GetBinContent(i,j)<1&&excl->GetBinContent(i,j)>0) exclusion->SetBinContent(i,j,0.01);
188 else exclusion->SetBinContent(i,j,0);
189 }
190 }
191 exclusion->SetLineColor(kBlue);
192 exclusion->SetLineWidth(4);
193 exclusion->SetLineStyle(isprimary);
194 return exclusion;
195 }
196
197 void produce_extensive_plots(TH2F *xsec,TH2F *limits,TH2F *rellimits, TH2F *rellimitsd3, TH2F *rellimitst3, int scantype) {
198 TCanvas *ca = new TCanvas("ca","ca",2400,1200);
199 ca->Divide(4,2);
200 ca->cd(1);
201 ca->cd(1)->SetLogz(1);
202 xsec->GetZaxis()->SetRangeUser(0.001,1000);
203 xsec->Draw("COLZ");
204 TText *title0 = write_title("Reference Cross Section");
205 title0->Draw("same");
206 ca->cd(2);
207 ca->cd(2)->SetLogz(1);
208 limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
209 limits->Draw("COLZ");
210 TText *title = write_title("Cross Section Upper Limit");
211 title->Draw("same");
212 ca->cd(3);
213 ca->cd(3)->SetLogz(1);
214 TH2F *limit_ref = (TH2F*)limits->Clone("limit_ref");
215 limit_ref->Divide(xsec);
216 limit_ref->GetZaxis()->SetRangeUser(limits_ratio_lower_bound,limits_ratio_upper_bound);
217 limit_ref->Draw("COLZ");
218 TText *title2 = write_title("Cross Section UL / XS");
219 title2->Draw("same");
220 ca->cd(4);
221 ca->cd(4)->SetLogz(1);
222 limits->SetTitle("");
223 limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
224 limits->SetZTitle("95% CL upper limit on #sigma [pb]");
225
226 // limits->GetZaxis()->SetTitleOffset(1.1); // This is set in set_range
227 // limits->GetZaxis()->CenterTitle(); // This is set in set_range
228 limits->Draw("COLZ");
229
230 TGraph *exclline = MarcosExclusionLine(rellimits, scantype);
231 TGraph *thinexclline = thin_line(exclline);
232
233 TGraph *excllinet3 = MarcosExclusionLine(rellimitst3, scantype);
234 excllinet3->SetLineStyle(2);
235 TGraph *thinexcllinet3 = thin_line(excllinet3);
236
237 TGraph *excllined3 = MarcosExclusionLine(rellimitsd3, scantype);
238 excllined3->SetLineStyle(3);
239 TGraph *thinexcllined3 = thin_line(excllined3);
240
241 ca->cd(4);
242 exclline->Draw();
243 thinexclline->Draw();
244 excllinet3->Draw();
245 thinexcllinet3->Draw();
246 excllined3->Draw();
247 thinexcllined3->Draw();
248 stringstream partial;
249 partial << "Limits/exclusion__" << limits->GetName();
250 fill_with_text(exclline,excllined3,excllinet3,ca->cd(4),scantype);
251 CompleteSave(ca,partial.str());
252
253 ca->cd(5);
254 (hardlimit(rellimits))->Draw("COL");
255 exclline->Draw("same");
256 ca->cd(6);
257 (hardlimit(rellimitst3))->Draw("COL");
258 excllinet3->Draw("same");
259 ca->cd(7);
260 (hardlimit(rellimitsd3))->Draw("COLZ");
261 excllined3->Draw("same");
262
263 CompleteSave(ca,partial.str()+"__PlusInfo");
264 delete ca;
265 }
266
267 bool fail(double xs, double xsLimit) {return xsLimit>1 or !xsLimit;}
268
269 void get_Marias_exclusion_line(TH2F *limit_ref, float pointsX[200], float pointsY[200], int &ixNew, int &counter, int &foundDiag) {
270 // part of Mariarosaria's getRefXsecGraph function
271 double refMult = 3.0;
272 bool enough = false;
273 Int_t nBinX= limit_ref->GetXaxis()->GetNbins();
274 Int_t nBinY= limit_ref->GetYaxis()->GetNbins();
275 for(int i=1; i<(nBinX+1); i++) {
276 for(int j=1; j<(nBinY+1); j++) {
277 if(limit_ref->GetBinContent(i,j-1)==0) continue;
278 if(limit_ref->GetBinContent(i,j+1)==0) continue;
279 if(limit_ref->GetBinContent(i,j)==0) continue;
280 if( limit_ref->GetBinContent(i,j)>0. && limit_ref->GetBinContent(i,j)<=1.) {
281 double xsLimitAbove = limit_ref->GetBinContent(i, j+1);
282 double xsLimitBelow = limit_ref->GetBinContent(i, j-1);
283
284 double xsLimit = limit_ref->GetBinContent(i, j);
285 if((fail(1.0,xsLimitAbove)) && (!fail(1.0,xsLimit)) ) {
286 pointsX[counter]=limit_ref->GetXaxis()->GetBinCenter(i);
287 pointsY[counter]=limit_ref->GetYaxis()->GetBinCenter(j);
288 counter++;
289 enough = !xsLimitAbove;
290 if(!enough && !foundDiag) foundDiag=counter;
291 // cout << "enough " << enough << " foundDiag " << foundDiag << endl;
292 }
293 }
294 }
295 }
296
297 }
298
299 TH2F* flipth2f(TH2F *histo) {
300 if(histo->GetNbinsX()!=histo->GetNbinsY()) {
301 write_error(__FUNCTION__,"number of bins is not the same for x & y !!!");
302 return NULL;
303 }
304 TH2F *rethisto = (TH2F*)histo->Clone();
305 for(int i=1;i<histo->GetNbinsX();i++) {
306 for(int j=1;j<histo->GetNbinsY();j++) {
307 rethisto->SetBinContent(j,i,histo->GetBinContent(i,j));
308 }
309 }
310 return rethisto;
311 }
312
313 TGraph* get_exclusion_line(TH2F *limit_ref) {
314
315 float pointsX[200];
316 float pointsY[200];
317 int ixNew=0;
318 int counter=0;
319 int foundDiag=0;
320
321 TH2F *fakehisto = flipth2f(limit_ref);
322 get_Marias_exclusion_line(fakehisto,pointsY,pointsX,ixNew,counter,foundDiag);// x&y deliberately switched!
323 if(counter>1) {
324 pointsX[counter]=pointsX[counter-1];
325 pointsY[counter]=50;
326 }
327
328 const int newCounter=counter;
329 Double_t newPointsX[newCounter+1];
330 Double_t newPointsY[newCounter+1];
331 float lastx=-100;
332 float lasty=-100;
333
334
335 for (int ix = 0; ix < counter+1; ++ix) {
336 if(ix<(foundDiag-2)) continue;
337 if(ix!=counter && pointsX[ix+1]==pointsX[ix]) continue;
338 if(pointsX[ix]<PlottingSetup::mglustart) continue;
339 if(lasty>-100&&pointsY[ix]<51) continue;
340 // cout << pointsX[ix] << " , " << pointsY[ix] << endl;
341 newPointsX[ixNew]=pointsX[ix];
342 newPointsY[ixNew]=pointsY[ix];
343 ixNew++;
344 lastx=pointsX[ix];
345 lasty=pointsY[ix];
346 }
347 string titleHisto="tester";
348 // sprintf(titleHisto,"graph_%s_%f",limit_ref->GetName(),refMult);
349 // cout << "HERE " << titleHisto << endl;
350
351 TGraph * gr = new TGraph(ixNew,newPointsX,newPointsY);
352 gr->SetName(titleHisto.c_str());
353 gr->Draw("same");
354 return gr;
355 }
356
357 TGraph *MarcosExclusionLine(TH2F *exclusionshape, int scantype) {
358 // write_warning(__FUNCTION__,"USING MARIAS ALGORITHM...");
359 // return get_exclusion_line(exclusionshape);
360
361 TH2F *fakehisto = flipth2f(exclusionshape);
362 TGraph *fakegraph = get_mSUGRA_exclusion_line(fakehisto, scantype);
363 TGraph *realgraph = new TGraph(fakegraph->GetN());
364 double x,y;
365 float last_x=0;
366 float last_y=0;
367 int counter=0;
368 for(int i=0;i<fakegraph->GetN();i++) {
369 fakegraph->GetPoint(i,x,y);
370 if(scantype==PlottingSetup::SMS) {
371 if(y-x<75) {
372 realgraph->SetPoint(counter,last_x,last_y);
373 counter++;
374 continue;
375 }
376 }
377 realgraph->SetPoint(counter,y,x);
378 last_x=y;
379 last_y=x;
380 counter++;
381 }
382 realgraph->SetLineColor(TColor::GetColor("#151515")); //nice black
383 realgraph->SetLineWidth(4); // FR -> 3 for better display
384
385 return realgraph;
386 }
387
388 TGraph* thin_line(TGraph *gr) {
389 TGraph *thin = (TGraph*) gr->Clone(concatenate("thin",gr->GetTitle()));
390 thin->SetLineWidth(1);
391 thin->SetLineColor(kWhite);
392 return thin;
393 }
394
395 void make_SMS_exclusion(TH2F *rawlimits,TH2F *xsec,int scantype,std::string& scanx) {
396 TH2F *limits = prep_histo(rawlimits,scantype); // this is to be independent of the style used at creation time
397 //here we get some limits and the cross section; we want to make an exclusion plot!
398 TH2F *rellimits = (TH2F*)limits->Clone("rellimits");
399 TH2F *rellimitsd3 = (TH2F*)limits->Clone("rellimitsd3"); // one third the cross section ("divided by 3" -> d3)
400 TH2F *rellimitst3 = (TH2F*)limits->Clone("rellimitst3"); // three times the cross section ("times 3" -> t3)
401
402 if(!xsec ) {
403 cout << "Watch out, cross section map is invalid!" << endl;
404 return;
405 }
406
407 rellimits->Divide(xsec);
408
409
410 for(int i=1;i<=rellimits->GetNbinsX();i++) {
411 for(int j=1;j<=rellimits->GetNbinsY();j++) {
412 rellimitst3->SetBinContent(i,j,(rellimits->GetBinContent(i,j))/3.0);
413 rellimitsd3->SetBinContent(i,j,(rellimits->GetBinContent(i,j))*3.0);
414 }
415 }
416
417
418 // TH2F *exclusionshape = make_exclusion_shape(rellimits,1);
419 // TH2F *exclusionshapet3 = make_exclusion_shape(rellimitst3,2);
420 // TH2F *exclusionshaped3 = make_exclusion_shape(rellimitsd3,3);
421
422 //Now let's produce the plots!
423
424 set_range(xsec,scantype,false);
425 set_range(limits,scantype,false);
426
427 bool drawdoubleline = false; //draw nice thin line on top of thick outer line
428 TGraph *exclline = MarcosExclusionLine(rellimits, scantype);
429 TGraph *thinexcline = thin_line(exclline);
430
431 TGraph *excllinet3 = MarcosExclusionLine(rellimitst3, scantype);
432 excllinet3->SetLineStyle(2);
433 TGraph *thinexclinet3 = thin_line(excllinet3);
434
435 TGraph *excllined3 = MarcosExclusionLine(rellimitsd3, scantype);
436 excllined3->SetLineStyle(3);
437 TGraph *thinexclined3 = thin_line(excllined3);
438
439 produce_extensive_plots(xsec,limits,rellimits, rellimitst3, rellimitsd3,scantype);
440
441 TCanvas *finalcanvas = new TCanvas("finalcanvas","finalcanvas");
442 finalcanvas->SetLogz(1);
443 finalcanvas->cd();
444
445 // Dirty range setting to harmonize for paper
446 if ( scantype == PlottingSetup::SMS ) {
447 TH2F* hrange = new TH2F("hrange","range",2,-12.5,1200-12.5,2,50,1200-12.5);
448 set_range(hrange,scantype,false);
449 hrange->Draw();
450 limits->Draw("COLZ,same");
451 } else if ( scantype == PlottingSetup::GMSB ) {
452 TH2F* hrange = new TH2F("hrange","range",2,-12.5,1200-12.5,2,100,1200-12.5);
453 set_range(hrange,scantype,false);
454 hrange->Draw();
455 limits->Draw("COLZ,same");
456 } else {
457 limits->Draw("COLZ");
458 }
459
460
461 TLine *desertline;
462 if(drawefficiencydesertline) {
463 desertline = new TLine(375,50,1200,875);
464 desertline->SetLineWidth(4);
465 desertline->SetLineColor(kBlack);
466 desertline->Draw("same");
467 }
468
469 fill_with_text(exclline,excllined3,excllinet3,finalcanvas,scantype,scanx);
470 stringstream real;
471 real << "Limits/final_exclusion__" << limits->GetName();
472 exclline->Draw("l");
473 if(drawdoubleline) thinexcline->Draw("");
474 excllinet3->Draw("");
475 if(drawdoubleline) thinexclinet3->Draw("");
476 excllined3->Draw("");
477 if(drawdoubleline) thinexclined3->Draw("");
478 CompleteSave(finalcanvas,real.str());
479
480 delete finalcanvas;
481 }
482
483 TH1* getHisto(char * filename, char* histoName, char * dirName, int nBin, double lumi)
484 {
485 TH1 * hpt_=0;
486 TFile *file0 = TFile::Open(filename);
487 if(!file0) return hpt_;
488 TDirectory *dir;
489 TH2D * hMuPt;
490 TH1* H;
491
492 if(dirName == "0") {
493 hMuPt = (TH2D*) file0->Get(histoName);
494 } else {
495 dir = (TDirectory*) file0->Get(dirName);
496 if(!dir) return hpt_;
497 hMuPt = (TH2D*) dir->Get(histoName);
498 }
499
500 if(hMuPt) {
501 hpt_ = (TH1*) hMuPt->Clone();
502 hpt_->Sumw2();
503 hpt_->Scale(1./lumi); // this take into into account the luminosity
504 hpt_->SetLineWidth(2);
505 hpt_->Rebin(nBin);
506 double nBinX=hpt_->GetNbinsX();
507
508 // overFlow
509 hpt_->SetBinContent((int)nBinX,hpt_->GetBinContent((int)nBinX)+hpt_->GetBinContent((int)nBinX+1));
510 hpt_->SetDirectory(0);
511 file0->Close();
512 hpt_->SetLineWidth(3);
513 }
514 return hpt_;
515 }
516
517 pair <float,float> find_point(TH2F* histo, int xbin, bool mSUGRA=true) {
518 TH1F *flathisto;
519 if(mSUGRA) flathisto = new TH1F("flat","flat",histo->GetNbinsY(),histo->GetYaxis()->GetBinLowEdge(1),histo->GetYaxis()->GetBinLowEdge(histo->GetNbinsY())+histo->GetYaxis()->GetBinWidth(histo->GetNbinsY()));
520 else flathisto = new TH1F("flat","flat",histo->GetNbinsX(),histo->GetXaxis()->GetBinLowEdge(1),histo->GetXaxis()->GetBinLowEdge(histo->GetNbinsX())+histo->GetXaxis()->GetBinWidth(histo->GetNbinsX()));
521
522 int nbins=histo->GetNbinsY();
523 if(!mSUGRA) nbins=histo->GetNbinsX();
524 for(int i=1;i<nbins;i++) {
525 float value=(histo->GetBinContent(xbin,i));
526 if(value<20&&value>0) flathisto->SetBinContent(i,value);
527 }
528
529 float pointone=-100;
530 nbins=flathisto->GetNbinsX();
531 if(!mSUGRA) nbins=flathisto->GetNbinsY();
532 for(int i=nbins;i>=1;i--) {
533 if(pointone<0&&flathisto->GetBinContent(i)<1&&flathisto->GetBinContent(i)>0) pointone=flathisto->GetBinLowEdge(i)+flathisto->GetBinWidth(i);
534 }
535 pair <float,float> anything;
536 if(mSUGRA) anything.first=histo->GetXaxis()->GetBinCenter(xbin);
537 else anything.first=histo->GetYaxis()->GetBinCenter(xbin);
538 anything.second=pointone;
539 delete flathisto;
540 return anything;
541 }
542
543 pair <float,float> find_interpolated_point(TH2F* histo, int xbin, bool mSUGRA=true) {
544
545 int minaccept=4;
546 TCanvas *flatcan = new TCanvas("flatcan","flatcan");
547 stringstream histoname;
548 histoname << "exclusion shape for x bin " << xbin;
549 TH1F *flathisto;
550 if(mSUGRA) flathisto = new TH1F("flat",histoname.str().c_str(),histo->GetNbinsY(),histo->GetYaxis()->GetBinLowEdge(1),histo->GetYaxis()->GetBinLowEdge(histo->GetNbinsY())+histo->GetYaxis()->GetBinWidth(histo->GetNbinsY()));
551 else flathisto = new TH1F("flat",histoname.str().c_str(),histo->GetNbinsX(),histo->GetXaxis()->GetBinLowEdge(1),histo->GetXaxis()->GetBinLowEdge(histo->GetNbinsX())+histo->GetXaxis()->GetBinWidth(histo->GetNbinsX()));
552
553 int acceptedpoints=0;
554 int nbins=histo->GetNbinsY();
555 if(!mSUGRA) histo->GetNbinsX();
556 for(int i=1;i<nbins;i++) {
557 float value=0;
558 if(i<=nbins-2) value=((1/3.0)*(histo->GetBinContent(xbin,i)+histo->GetBinContent(xbin+1,i)+histo->GetBinContent(xbin+2,i)));
559 if(i==nbins-1) value=((1/2.0)*(histo->GetBinContent(xbin,i)+histo->GetBinContent(xbin,i+1)));
560 if(i==nbins) value=(histo->GetBinContent(xbin,i));
561 if(value<20&&value>0) {
562 flathisto->SetBinContent(i,value);
563 flathisto->SetBinError(i,TMath::Sqrt(value));
564 acceptedpoints++;
565 }
566 }
567
568 float pointone=-100;
569 TLine *excluded;
570 if(acceptedpoints>minaccept) {
571 flathisto->Fit("expo","Q");
572 TF1 *fitfunc = (TF1*)flathisto->GetFunction("expo");
573 pointone=-(fitfunc->GetParameter(0)/fitfunc->GetParameter(1));
574 excluded=new TLine(pointone,0,pointone,10);
575 }
576
577 pair <float,float> anything;
578 anything.first=histo->GetXaxis()->GetBinCenter(xbin);
579 anything.second=pointone;
580 stringstream flatname;
581 flathisto->GetYaxis()->SetRangeUser(0,10);
582 flathisto->Draw();
583 if(acceptedpoints>minaccept) excluded->SetLineColor(kGreen);
584 if(acceptedpoints>minaccept) excluded->SetLineStyle(2);
585 if(acceptedpoints>minaccept) excluded->SetLineWidth(2);
586 if(acceptedpoints>minaccept) excluded->Draw("same");
587 flatname << "Limits/partials/partial_" << xbin << "___" << histo->GetName() << ".png";
588 if(draweachone) CompleteSave(flatcan,flatname.str());
589 delete flatcan;
590 delete flathisto;
591 return anything;
592 }
593
594 void project_to_last_point_on_line(float x2, float y2, float x1, float y1, float &x, float &y, int scantype) {
595 // original code: continue the same way to the diagonal (i.e. conserve the angle to the diagonal)
596 /*
597 float deltax=x2-x1;
598 float deltay=y2-y1;
599 float b = (y1-x1)/(deltax-deltay);
600 if(scantype==PlottingSetup::SMS) b = (y1-75.-x1)/(deltax-deltay);
601 x = x1 + b * deltax;
602 y = y1 + b * deltay;
603 if(x<0||y<0) x=-1;
604 if((scantype==PlottingSetup::GMSB||scantype==PlottingSetup::SMS) && (x>PlottingSetup::mgluend||y>PlottingSetup::mLSPend)) x=-1;
605 */
606 //new code: just connect directly with the diagonal
607 float b = 0;
608 if(scantype==PlottingSetup::SMS) b = -75;
609 //float alpha = (b+x2-y2)/2.0;
610 x = floor((x2+y2-b)/2.0);
611 y = floor(x + b);
612 }
613
614 TGraph* get_mSUGRA_exclusion_line(TH2F *exclusionhisto, int scantype) {
615 exclusionhisto->SetStats(0);
616 exclusionhisto->GetZaxis()->SetRangeUser(0,2);
617
618 vector<pair <float,float> > points;
619
620 for(int i=1;i<exclusionhisto->GetNbinsX();i++) {
621 pair<float,float> anything = find_point(exclusionhisto,i);
622 pair<float,float> intthing = find_interpolated_point(exclusionhisto,i);
623 float value=anything.second;
624 if(intthing.second>anything.second) anything.second=intthing.second;
625 if(anything.second>100&&anything.second<1500) points.push_back(anything);
626 }
627
628 Double_t xpoints[points.size()];
629 Double_t spoints[points.size()];
630
631 TGraph *graph = new TGraph(points.size()+1);
632 graph->SetLineColor(kBlack);
633 graph->SetLineWidth(2);
634
635 int pointcounter=0;
636 float lastx=0;
637 float lasty=0;
638 float lastx2=0;
639 float lasty2=0;
640
641 for(int i=0;i<points.size();i++) {
642 xpoints[i]=points[i].first;
643 spoints[i]=points[i].second;
644 if(scantype==PlottingSetup::mSUGRA) {
645 if(i>1&&i<points.size()-1) spoints[i]=(1.0/3.0)*(points[i-1].second+points[i].second+points[i+1].second);
646 if(i>2&&i<points.size()-2) spoints[i]=(1.0/5.0)*(points[i-2].second+points[i-1].second+points[i].second+points[i+1].second+points[i+2].second);
647 if(i>3&&i<points.size()-3) spoints[i]=(1.0/7.0)*(points[i-3].second+points[i-2].second+points[i-1].second+points[i].second+points[i+1].second+points[i+2].second+points[i+3].second);
648 }
649
650 bool usethispoint=true;
651 if(scantype==PlottingSetup::GMSB) if(spoints[i]<points[i].first) usethispoint=false;
652 if(scantype==PlottingSetup::SMS) if(spoints[i]-75.<points[i].first) usethispoint=false;
653
654 if((scantype==PlottingSetup::GMSB||scantype==PlottingSetup::SMS) && (spoints[i]>PlottingSetup::mgluend||points[i].first>PlottingSetup::mLSPend)) usethispoint=false;
655
656 if(usethispoint) {
657 graph->SetPoint(pointcounter,points[i].first,spoints[i]);
658 lastx2=lastx;
659 lasty2=lasty;
660 lastx=points[i].first;
661 lasty=spoints[i];
662 pointcounter++;
663 }
664 }
665 for(int i=pointcounter;i<points.size();i++) graph->SetPoint(i,lastx,lasty);
666 if(scantype==PlottingSetup::GMSB||scantype==PlottingSetup::SMS) {
667 //The final point will be a continuation of the last one, towards the diagonal
668 float x,y;
669 project_to_last_point_on_line(lastx,lasty,lastx2,lasty2,x,y,scantype);
670 if(x>0&&y>0) graph->SetPoint(points.size(),y,x);
671 else graph->SetPoint(points.size(),lastx,lasty);
672 }
673
674 return graph;
675 }
676
677 void draw_mSUGRA_exclusion(TH2F *crosssection, TH2F *limitmap, TH2F *expmap, TH2F *expplusmap, TH2F *expminusmap, TH2F *exp2plusmap, TH2F *exp2minusmap) {
678 TH2F *cleanhisto = (TH2F*)limitmap->Clone("clean");
679 for(int ix=1;ix<=cleanhisto->GetNbinsX();ix++) {
680 for(int iy=1;iy<=cleanhisto->GetNbinsY();iy++) {
681 cleanhisto->SetBinContent(ix,iy,0);
682 }
683 }
684
685 TH2F *limits = (TH2F*)limitmap->Clone("limits");
686 set_range(limits,true,false);
687 limitmap->Divide(crosssection);
688 expminusmap->Divide(crosssection);
689 expplusmap->Divide(crosssection);
690 exp2minusmap->Divide(crosssection);
691 exp2plusmap->Divide(crosssection);
692 expmap->Divide(crosssection);
693 TGraph *observed = get_mSUGRA_exclusion_line(limitmap, PlottingSetup::mSUGRA);
694 observed->SetLineColor(kRed);
695 TGraph *expminus = get_mSUGRA_exclusion_line(expminusmap, PlottingSetup::mSUGRA);
696 TGraph *expplus = get_mSUGRA_exclusion_line(expplusmap, PlottingSetup::mSUGRA);
697 TGraph *exp2minus;
698 if(draw2sigma) exp2minus = get_mSUGRA_exclusion_line(exp2minusmap, PlottingSetup::mSUGRA);
699 TGraph *exp2plus;
700 if(draw2sigma) exp2plus = get_mSUGRA_exclusion_line(exp2plusmap, PlottingSetup::mSUGRA);
701
702 TGraph *expected = new TGraph(expminus->GetN()+expplus->GetN());
703 TGraph *expected2;
704 if(draw2sigma) expected2 = new TGraph(exp2minus->GetN()+exp2plus->GetN());
705 for(int i=0;i<=expminus->GetN();i++) {
706 Double_t x,y;
707 expminus->GetPoint(i,x,y);
708 expected->SetPoint(i,x,y);
709 }
710
711 for(int i=0;i<=exp2minus->GetN();i++) {
712 Double_t x,y;
713 exp2minus->GetPoint(i,x,y);
714 expected2->SetPoint(i,x,y);
715 }
716 for(int i=exp2plus->GetN()-1;i>=0;i--) {
717 Double_t x,y;
718 exp2plus->GetPoint(i,x,y);
719 expected2->SetPoint(exp2minus->GetN()+(exp2plus->GetN()-i),x,y);
720 }
721 for(int i=expplus->GetN()-1;i>=0;i--) {
722 Double_t x,y;
723 expplus->GetPoint(i,x,y);
724 expected->SetPoint(expminus->GetN()+(expplus->GetN()-i),x,y);
725 }
726 expected->SetFillColor(TColor::GetColor("#9FF781"));
727 if(draw2sigma) expected2->SetFillColor(TColor::GetColor("#F3F781"));
728
729 smooth_line(observed);
730 smooth_line(expected);
731 if(draw2sigma) smooth_line(expected2);
732
733 TCanvas *te = new TCanvas("te","te");
734 decorate_mSUGRA(cleanhisto,te,expected,expected2,observed);
735 stringstream saveas;
736 if((int)((string)limitmap->GetName()).find("limitmap")>0) saveas << "Limits/final_exclusion_for_JZB_geq_" << ((string)limitmap->GetName()).substr(((string)limitmap->GetName()).find("limitmap")+8,10);
737 else saveas << "Limits/final_exclusion_for_bestlimits";
738 CompleteSave(te,saveas.str());
739 delete te;
740
741 TCanvas *overview = new TCanvas("overview","overview",1000,1000);
742 set_range(crosssection,true,false);
743 set_range(limits,true,false);
744 set_range(limitmap,true,false);
745
746 overview->Divide(2,2);
747 overview->cd(1);
748 overview->cd(1)->SetLogz(1);
749 crosssection->GetZaxis()->SetRangeUser(0.0001,100);
750 crosssection->Draw("COLZ");
751 TText *title0 = write_title("Cross Section");
752 title0->Draw("same");
753 overview->cd(2);
754 overview->cd(2)->SetLogz(1);
755 limits->GetZaxis()->SetRangeUser(0.1,100);
756 limits->Draw("COLZ");
757 TText *title1 = write_title("Cross Section Upper Limit");
758 title1->Draw("same");
759 overview->cd(3);
760 limitmap->Draw("COLZ");
761 TText *title2 = write_title("UL/XS");
762 title2->Draw("same");
763 observed->Draw("c");
764 overview->cd(4);
765 decorate_mSUGRA(cleanhisto,overview->cd(4),expected,expected2,observed);
766 stringstream saveas2;
767 if((int)((string)limitmap->GetName()).find("limitmap")>0) saveas2 << "Limits/exclusion_overview_for_JZB_geq_" << ((string)limitmap->GetName()).substr(((string)limitmap->GetName()).find("limitmap")+8,10);
768 else saveas2 << "Limits/exclusion_overview_for_bestlimits";
769 CompleteSave(overview,saveas2.str());
770 delete overview;
771
772
773 }
774
775 TH2F* get_XS(string filename, string mass, TH2F *histo) {///DONE
776 TH1 *hRef=getHisto((char*) filename.c_str(), (char*) mass.c_str(), (char*) "0", 1,1);
777 TH2F * xsec= new TH2F("xsec","xsec",60, 0., 1500., 60, 0., 1500.);
778 for(int i=1; i<(histo->GetNbinsX()+1); i++) {
779 for(int j=1; j<(histo->GetNbinsY()+1); j++) {
780 if(!(histo->GetBinContent(i,j)==0)) xsec->SetBinContent(i,j,hRef->GetBinContent(hRef->FindBin(xsec->GetXaxis()->GetBinCenter(i))));
781 }
782 }
783 return xsec;
784 }
785
786 string give_nice_source_label(string name) {
787 int mappoint=name.find("map");
788 if(mappoint<0||mappoint>500) return name; // this mean that something weird is happening
789 stringstream nice_label;
790 nice_label << "JZB > " << name.substr(mappoint+3,name.size()) << " GeV";
791 return nice_label.str();
792 }
793
794 Int_t get_exclusion_region_color(double value, TH2F *histo) {
795 Double_t wmin = histo->GetMinimum();
796 Double_t wmax = histo->GetMaximum();
797 Double_t wlmin = wmin;
798 Double_t wlmax = wmax;
799
800
801 Int_t ncolors = gStyle->GetNumberOfColors();
802 Int_t ndivz = histo->GetContour();
803 if (ndivz == 0) return 0;
804 ndivz = TMath::Abs(ndivz);
805 Int_t theColor, color;
806 Double_t scale = ndivz / (wlmax - wlmin);
807
808 if (value < wlmin) value = wlmin;
809
810 color = Int_t(0.01 + (value - wlmin) * scale);
811
812 theColor = Int_t((color + 0.99) * Double_t(ncolors) / Double_t(ndivz));
813 return gStyle->GetColorPalette(theColor);
814 }
815
816 float findmaxentry(vector<TH2F*> histos, int i, int j) {
817 float max = histos[0]->GetBinContent(i,j);
818 for(int k=0;k<histos.size();k++) {
819 float entry = histos[k]->GetBinContent(i,j);
820 if(entry>=max) max=entry;
821 }
822
823 return max;
824 }
825
826 TH2F *make_best_limits(vector<TH2F*> explimits,vector<TH2F*> obslimits, int scantype, std::string& scanx, vector<TH2F*> exp1mlimits, vector<TH2F*> exp1plimits, vector<TH2F*> exp2mlimits, vector<TH2F*> exp2plimits, vector<TH2F*> &allbestexplimits) {
827 if(obslimits.size()==0) {
828 write_warning(__FUNCTION__,"There are no observed limits! Cannot continue!");
829 TH2F *err;
830 return err;
831 }
832 if(explimits.size()==0) {
833 write_warning(__FUNCTION__,"There are no expected limits! Will compute best limits based on observed limits! (WATCH OUT THIS IS DISCOURAGED!");
834 for(int i=0;i<obslimits.size();i++) explimits.push_back(obslimits[i]);
835 }
836 TH2F *bestlimit=(TH2F*)obslimits[0]->Clone("bestlimits");
837 TH2F *bestexplimit=(TH2F*)obslimits[0]->Clone("bestexplimits");
838 TH2F *bestlimitsource=(TH2F*)obslimits[0]->Clone("bestlimitsource");
839 TH2F *bestexp1plimit=(TH2F*)obslimits[0]->Clone("bestexp1plimit");
840 TH2F *bestexp1mlimit=(TH2F*)obslimits[0]->Clone("bestexp1mlimit");
841 TH2F *bestexp2plimit=(TH2F*)obslimits[0]->Clone("bestexp2plimit");
842 TH2F *bestexp2mlimit=(TH2F*)obslimits[0]->Clone("bestexp2mlimit");
843
844 for(int i=1;i<=explimits[0]->GetNbinsX();i++) {
845 for(int j=1;j<=explimits[0]->GetNbinsY();j++) {
846 float min=findmaxentry(explimits,i,j);
847 float omin=obslimits[0]->GetBinContent(i,j);
848 int source=0;
849 for(int k=0;k<explimits.size();k++) {
850 float currlim=explimits[k]->GetBinContent(i,j);
851 if(currlim<min&&currlim>0) {
852 min=currlim;
853 omin=obslimits[k]->GetBinContent(i,j);
854 source=k+1;
855 }
856 }
857 if(min>0) {
858 bestlimitsource->SetBinContent(i,j,source);
859 bestlimit->SetBinContent(i,j,omin);
860 bestexplimit->SetBinContent(i,j,min);
861 if(scantype==PlottingSetup::mSUGRA) {
862 bestexp1plimit->SetBinContent(i,j,exp1plimits[source-1]->GetBinContent(i,j));
863 bestexp1mlimit->SetBinContent(i,j,exp1mlimits[source-1]->GetBinContent(i,j));
864 bestexp2plimit->SetBinContent(i,j,exp2plimits[source-1]->GetBinContent(i,j));
865 bestexp2mlimit->SetBinContent(i,j,exp2mlimits[source-1]->GetBinContent(i,j));
866 }
867 }
868 }
869 }
870 gStyle->SetPadRightMargin(standardmargin);
871 gStyle->SetPadLeftMargin(0.18);
872
873 TCanvas *canlimsource = new TCanvas("limsource","Source of best limits");
874 set_range(bestlimitsource,scantype,false);
875 bestlimitsource->SetTitle("Source of limit for best limits");
876 bestlimitsource->GetZaxis()->SetRangeUser(0,explimits.size()+1);
877 bestlimitsource->GetXaxis()->CenterTitle(0);
878 bestlimitsource->GetYaxis()->CenterTitle(0);
879 bestlimitsource->Draw("COL");
880 gPad->Update();
881 TLegend *sourceleg = new TLegend(0.2,0.5,0.55,0.75);
882 for(int i=0;i<explimits.size();i++) {
883 stringstream legendentry;
884 legendentry << i+1 << " = " << give_nice_source_label(explimits[i]->GetName());
885 Int_t currcol=get_exclusion_region_color(i+1,bestlimitsource);
886 explimits[i]->SetFillColor(currcol);
887 explimits[i]->SetLineColor(currcol);
888 sourceleg->AddEntry(explimits[i], legendentry.str().c_str(),"f");
889 }
890 sourceleg->SetLineColor(kWhite);sourceleg->SetFillColor(kWhite);
891 sourceleg->SetTextSize(0.03);
892 sourceleg->Draw("same");
893 DrawPrelim();
894 write_SMS_text(scantype,scanx);
895
896 CompleteSave(canlimsource,"Limits/SourceOfBestLimits");
897 gStyle->SetPadRightMargin(indentedmargin);
898 allbestexplimits.push_back(bestexplimit);
899 allbestexplimits.push_back(bestexp1plimit);
900 allbestexplimits.push_back(bestexp1mlimit);
901 allbestexplimits.push_back(bestexp2plimit);
902 allbestexplimits.push_back(bestexp2mlimit);
903
904 delete canlimsource;
905 delete bestexplimit;
906 delete bestlimitsource;
907 return bestlimit;
908 }
909
910
911 void create_exclusion_plots(vector<TH2F*> limits, int scantype, std::string& scanx) {
912 TFile *xsecfile;
913 if(scantype!=PlottingSetup::mSUGRA) {
914 xsecfile = new TFile(xsecfilename.c_str());
915 if(xsecfile->IsZombie()&&(scantype!=PlottingSetup::mSUGRA)) {
916 write_error(__FUNCTION__,"Cross section file is invalid!!!!");
917 return;
918 }
919 xsecfile->Close();
920 }
921 if(scantype!=PlottingSetup::mSUGRA) for(int i=0;i<limits.size();i++) limits[i]->Scale(1./0.19); // because for T5zz we forced one z to decay leptonically
922
923 vector<TH2F*> explimits;
924 vector<TH2F*> exp1mlimits;
925 vector<TH2F*> exp1plimits;
926 vector<TH2F*> exp2mlimits;
927 vector<TH2F*> exp2plimits;
928 vector<TH2F*> obslimits;
929 vector<TH2F*> flipmaps;
930 vector<TH2F*> crosssections;
931
932 for(int ilim=0;ilim<limits.size();ilim++) {
933 if(TString(limits[ilim]->GetName()).Contains("_explimitmap")) explimits.push_back(limits[ilim]);
934 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp1plimitmap")) exp1plimits.push_back(limits[ilim]);
935 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp1mlimitmap")) exp1mlimits.push_back(limits[ilim]);
936 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp2plimitmap")) exp2plimits.push_back(limits[ilim]);
937 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp2mlimitmap")) exp2mlimits.push_back(limits[ilim]);
938 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_absolutecrosssectionmap")) crosssections.push_back(limits[ilim]);
939 if(TString(limits[ilim]->GetName()).Contains("_limitmap")) obslimits.push_back(limits[ilim]);
940 // if(TString(limits[ilim]->GetName()).Contains("_limitflipmap")) flipmaps.push_back(limits[ilim]);
941 }
942
943 TH2F *xsec;
944 if(scantype!=PlottingSetup::mSUGRA) xsec = adjust_histo(get_XS(xsecfilename,"gluino",limits[0]),limits[0]);
945 vector<TH2F*> bestexplimits;
946 TH2F *bestlimits = make_best_limits(explimits,obslimits,scantype, scanx, exp1mlimits, exp1plimits, exp2mlimits, exp2plimits, bestexplimits);
947 bestlimits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
948
949 for(int ilim=0;ilim<limits.size();ilim++) {
950 limits[ilim]->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
951 }
952
953 if(scantype!=PlottingSetup::mSUGRA) {
954 for(int ilim=0;ilim<obslimits.size();ilim++) make_SMS_exclusion(obslimits[ilim],xsec,scantype,scanx);
955 make_SMS_exclusion(bestlimits,xsec,scantype,scanx);
956 } else {
957 for(int ilim=0;ilim<obslimits.size();ilim++) {
958 draw_mSUGRA_exclusion(crosssections[0], obslimits[ilim], explimits[ilim], exp1mlimits[ilim], exp1plimits[ilim], exp2mlimits[ilim], exp2plimits[ilim]);
959 }
960 draw_mSUGRA_exclusion(crosssections[0], bestlimits, bestexplimits[0], bestexplimits[1], bestexplimits[2], bestexplimits[3], bestexplimits[4]);
961 }
962 delete bestlimits;
963 }
964
965 void decorate_mSUGRA(TH2F *cleanhisto, TVirtualPad *cvsSys,TGraph *expected,TGraph *expected2,TGraph *observed) {
966 cvsSys->SetRightMargin(standardmargin);
967 Int_t tanBeta_ = 10;
968 Bool_t plotLO_ = false;
969
970 //convert tanb value to string
971 std::stringstream tmp;
972 tmp << tanBeta_;
973 TString tanb( tmp.str() );
974
975 //set old exclusion Limits
976 TGraph* LEP_ch = set_lep_ch(tanBeta_);
977 TGraph* LEP_sl = set_lep_sl(tanBeta_);//slepton curve
978 TGraph* TEV_sg_cdf = set_tev_sg_cdf(tanBeta_);//squark gluino cdf
979 TGraph* TEV_sg_d0 = set_tev_sg_d0(tanBeta_);//squark gluino d0
980 TGraph* stau = set_tev_stau(tanBeta_);//stau
981 TGraph* NoEWSB = set_NoEWSB(tanBeta_);
982
983 TGraph* TEV_sn_d0_1 = set_sneutrino_d0_1(tanBeta_);
984 TGraph* TEV_sn_d0_2 = set_sneutrino_d0_2(tanBeta_);
985
986 //constant ssqquark and gluino lines
987 TF1* lnsq[10];
988 TF1* lngl[10];
989
990 TLatex* sq_text[10];
991 TLatex* gl_text[10];
992
993 for(int i = 0; i < 6; i++){
994 lnsq[i] = constant_squark(tanBeta_,i);
995 sq_text[i] = constant_squark_text(i,*lnsq[i],tanBeta_);
996 lngl[i] = constant_gluino(tanBeta_,i);
997 gl_text[i] = constant_gluino_text(i,*lngl[i]);
998 }
999
1000 //Legends
1001 TLegend* legst = makeStauLegend(0.05,tanBeta_);
1002 TLegend* legNoEWSB = makeNoEWSBLegend(0.05,tanBeta_);
1003 TLegend* legexp = makeExpLegend( *TEV_sg_cdf,*TEV_sg_d0,*LEP_ch,*LEP_sl,*TEV_sn_d0_1,0.035,tanBeta_);
1004
1005 TEV_sn_d0_1->SetLineWidth(1);
1006 TEV_sn_d0_2->SetLineWidth(1);
1007 TEV_sg_d0->SetLineWidth(1);
1008
1009 double m0min = 0;
1010 if (tanBeta_ == 50) m0min=200;
1011 TH2F* hist = new TH2F("h","h",100,m0min,1000,100,120,700);
1012 hist->Draw();
1013 hist->GetXaxis()->SetTitle("m_{0} [GeV]");
1014 hist->GetXaxis()->CenterTitle();
1015 hist->GetYaxis()->SetTitle("m_{1/2} [GeV]");
1016 hist->GetYaxis()->CenterTitle();
1017 hist->GetXaxis()->SetTitleSize(0.04);
1018 hist->GetYaxis()->SetTitleSize(0.04);
1019 hist->GetXaxis()->SetTitleOffset(1.2);
1020 hist->GetYaxis()->SetTitleOffset(1.5);
1021 hist->GetXaxis()->SetNdivisions(506);
1022 hist->GetYaxis()->SetNdivisions(506);
1023
1024 int col[]={2,3,4};
1025
1026 TLegend* myleg;
1027
1028 if( plotLO_ ) myleg = new TLegend(0.3,0.65,0.65,0.8,NULL,"brNDC");
1029 else myleg = new TLegend(0.25,0.76,0.44,0.91,NULL,"brNDC");
1030
1031 myleg->SetFillColor(0);
1032 myleg->SetShadowColor(0);
1033 myleg->SetTextSize(0.04);
1034 myleg->SetBorderSize(0);
1035
1036 //constant squark and gluino mass contours
1037 for (int it=0;it<5;it++) {
1038 lngl[it]->Draw("same");
1039 lnsq[it]->Draw("same");
1040 sq_text[it]->Draw();
1041 gl_text[it]->Draw();
1042 }
1043
1044 //exclusion limits previous experiments
1045 if(tanBeta_ == 3){
1046 TEV_sn_d0_1->Draw("fsame");
1047 TEV_sn_d0_2->Draw("fsame");
1048 }
1049 LEP_ch->Draw("fsame");
1050 if (tanBeta_ != 50) LEP_sl->Draw("fsame");
1051
1052 //remove CDF/D0 excluded regions
1053 TEV_sg_cdf->Draw("fsame");
1054 TEV_sg_d0->Draw("same");
1055 TEV_sg_d0->Draw("fsame");
1056
1057 //other labels
1058 Double_t xpos = 0;
1059 Double_t xposi = 0;
1060 Double_t ypos = 0;
1061 if(tanBeta_ == 50) xposi = 100;
1062 if(tanBeta_ == 50) xpos = 200;
1063 if(tanBeta_ == 50) ypos = -10;
1064
1065 TString text_tanBeta;
1066 text_tanBeta = "tan#beta = "+tanb+", A_{0} = 0, #mu > 0";
1067 TLatex* cmssmpars = new TLatex(/*530.+xpos,690.+ypos-130*/150,650,text_tanBeta);
1068
1069 cmssmpars->SetTextSize(0.03);
1070 cmssmpars->Draw("same");
1071
1072 TLatex* lep_chargino = new TLatex(250,135,"LEP2 #tilde{#chi}_{1}^{#pm}");
1073 lep_chargino->SetTextSize(0.03);
1074 lep_chargino->SetTextFont(42);
1075
1076 TLatex* lep_slepton = new TLatex(26,190,"LEP2 #tilde{#font[12]{l}}^{#pm}");
1077 lep_slepton->SetTextSize(0.03);
1078 lep_slepton->SetTextAngle(-83);
1079 lep_slepton->SetTextFont(42);
1080
1081 if(draw2sigma) expected2->Draw("f");
1082 expected->SetLineColor(expected->GetFillColor());
1083 expected2->SetLineColor(expected2->GetFillColor());
1084 expected->Draw("f");
1085 observed->Draw("c");
1086
1087 stau->Draw("fsame");
1088 NoEWSB->Draw("fsame");
1089
1090 legexp->AddEntry(observed,"Observed limit","l");
1091 legexp->AddEntry(expected,"Expected 1#sigma limit","f");
1092 if(draw2sigma) legexp->AddEntry(expected2,"Expected 2#sigma limit","f");
1093 legexp->SetY1(0.60);
1094 legexp->SetX1(0.55);
1095 legexp->Draw();
1096 legst->Draw();
1097
1098 hist->Draw("sameaxis");
1099 cvsSys->RedrawAxis();
1100 cvsSys->Update();
1101 DrawPrelim();
1102 }
1103
1104 void smooth_line_once(TGraph *gr) {
1105 //going to smooth graph
1106 //need to take into account the DIRECTION we're heading so we noticed for expected shape when we turn around and go back
1107 float previousX=-100;
1108 int sign=1;
1109 for(int i=0;i<gr->GetN();i++) {
1110 Double_t x,y,x1,y1,x2,y2;
1111 bool turning=false;
1112 gr->GetPoint(i,x,y);
1113 gr->GetPoint(i+1,x1,y1);//need to handle exception here
1114 gr->GetPoint(i-1,x2,y2);//need to handle exception here
1115 if(i!=gr->GetN()-1&& (sign*x<=sign*previousX||sign*x1<=sign*x)) {
1116 //turned around!
1117 sign=(-1)*sign;
1118 // do NOT do any smoothing on this point!
1119 } else {
1120 float newval=y;
1121 if(i>0&&i<(gr->GetN())-1) newval=(1.0/3.0)*(y+y1+y2);
1122 if(i==0) newval=(1.0/2.0)*(y+y1);
1123 if(i==gr->GetN()-1) newval=(1.0/2.0)*(y+y2);
1124 gr->SetPoint(i,x,newval);
1125 }
1126 previousX=x;
1127 }
1128 }
1129
1130 void smooth_line(TGraph *gr) {
1131 smooth_line_once(gr);
1132 smooth_line_once(gr);
1133 smooth_line_once(gr);
1134 }
1135 void set_range(TH2F *histo, int scantype, bool pushoutyz=false) {
1136 gStyle->SetPadLeftMargin(0.18);
1137 gStyle->SetPadRightMargin(0.19);
1138 histo->GetXaxis()->SetLabelSize(0.035);
1139 histo->GetYaxis()->SetLabelSize(0.035);
1140 if(scantype==PlottingSetup::mSUGRA) {
1141 histo->GetXaxis()->SetRangeUser(0,2000);
1142 histo->GetYaxis()->SetRangeUser(0,800);
1143 histo->GetXaxis()->SetTitle("m_{0} [GeV]");
1144 histo->GetYaxis()->SetTitle("m_{1/2} [GeV]");
1145 histo->GetXaxis()->SetNdivisions(504,true);
1146 }
1147 if(scantype==PlottingSetup::SMS) {
1148 histo->GetXaxis()->SetRangeUser(0,1200);
1149 histo->GetYaxis()->SetRangeUser(50,1200);
1150 histo->GetXaxis()->SetTitle("gluino mass [GeV]");
1151 histo->GetYaxis()->SetTitle("#chi_{1}^{0} mass [GeV]");
1152 histo->GetXaxis()->SetTitleSize(0.06);
1153 histo->GetYaxis()->SetTitleSize(0.06);
1154 histo->GetZaxis()->SetTitleSize(0.06);
1155 histo->GetXaxis()->SetTitleOffset(1.0);
1156 histo->GetYaxis()->SetTitleOffset(1.4);
1157 histo->GetZaxis()->SetTitleOffset(1.2);
1158 if(pushoutyz) histo->GetZaxis()->SetTitleOffset(1.2);
1159 }
1160 if(scantype==PlottingSetup::GMSB) {
1161 histo->GetXaxis()->SetRangeUser(0,1200);
1162 histo->GetYaxis()->SetRangeUser(100,1200);
1163 histo->GetXaxis()->SetTitle("gluino mass [GeV]");
1164 histo->GetYaxis()->SetTitle("#chi_{1}^{0} mass [GeV]");
1165 histo->GetXaxis()->SetTitleSize(0.06);
1166 histo->GetYaxis()->SetTitleSize(0.06);
1167 histo->GetZaxis()->SetTitleSize(0.06);
1168 histo->GetXaxis()->SetTitleOffset(1.0);
1169 histo->GetYaxis()->SetTitleOffset(1.4);
1170 histo->GetZaxis()->SetTitleOffset(1.2);
1171 if(pushoutyz) histo->GetZaxis()->SetTitleOffset(1.2);
1172 }
1173
1174 //histo->GetXaxis()->CenterTitle();
1175 //histo->GetYaxis()->CenterTitle();
1176 histo->SetStats(0);
1177 }
1178
1179 TH2F* adjust_histo(TH2F *oldhist, TH2F *refhisto) {
1180 TH2F *histo = new TH2F(refhisto->GetName(),refhisto->GetName(),
1181 refhisto->GetNbinsX(),refhisto->GetXaxis()->GetBinLowEdge(1),refhisto->GetXaxis()->GetBinLowEdge(refhisto->GetNbinsX())+refhisto->GetXaxis()->GetBinWidth(refhisto->GetNbinsX()),
1182 refhisto->GetNbinsY(),refhisto->GetYaxis()->GetBinLowEdge(1),refhisto->GetYaxis()->GetBinLowEdge(refhisto->GetNbinsY())+refhisto->GetYaxis()->GetBinWidth(refhisto->GetNbinsY()));
1183
1184 for(int ix=1;ix<=refhisto->GetNbinsX();ix++) {
1185 for(int iy=1;iy<=refhisto->GetNbinsX();iy++) {
1186 int binnum=refhisto->FindBin(refhisto->GetXaxis()->GetBinCenter(ix),refhisto->GetYaxis()->GetBinCenter(iy));
1187 histo->SetBinContent(binnum,oldhist->GetBinContent(ix,iy));
1188 }
1189 }
1190 return histo;
1191 }
1192
1193 void process_syst_plot(TH2F *rhisto,string saveto,int scantype, std::string scanx = "") {
1194 TH2F *histo = prep_histo(rhisto,scantype); // this is to be independent of the style used at creation time
1195 float rightmargin=gStyle->GetPadRightMargin();
1196 gStyle->SetPadRightMargin(0.20);
1197 TString name = rhisto->GetName();
1198 if(name.Contains("Nevents")) gStyle->SetPadRightMargin(0.22);
1199 TCanvas *can = new TCanvas("syst_plot","Systematics Plot");
1200 set_range(histo,scantype,true);
1201
1202 histo->GetZaxis()->CenterTitle();
1203 gStyle->SetStripDecimals(false);
1204 histo->GetXaxis()->SetDecimals(true);
1205
1206 if(name.Contains("efficiency")) {
1207 histo->GetZaxis()->SetTitle("A #times #varepsilon (#geq 1 Z(ll))");
1208 histo->GetZaxis()->CenterTitle(0);
1209 //histo->GetZaxis()->SetRangeUser(0.0,0.15);
1210 }
1211 if(name.Contains("Nevents")) {
1212 histo->GetZaxis()->SetTitle("N(events)");
1213 histo->GetZaxis()->SetTitleOffset(histo->GetZaxis()->GetTitleOffset()+0.4);
1214 }
1215 if(name.Contains("sysjes")) {
1216 histo->GetZaxis()->SetTitle("Jet Energy Scale");
1217 histo->GetZaxis()->SetRangeUser(0.0,0.2);
1218 }
1219 if(name.Contains("sysjsu")) {
1220 histo->GetZaxis()->SetTitle("JZB Scale Uncertainty");
1221 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1222 }
1223 if(name.Contains("sysresmap")) {
1224 histo->GetZaxis()->SetTitle("Resulution");
1225 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1226 }
1227 if(name.Contains("sysstatmap")) {
1228 histo->GetZaxis()->SetTitle("Statistical Error");
1229 histo->GetZaxis()->SetRangeUser(0.0,0.01);
1230 }
1231 if(name.Contains("systotmap")) {
1232 histo->GetZaxis()->SetTitle("All Systematic Errors");
1233 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1234 }
1235
1236
1237 // Dirty range setting to harmonize for paper
1238 if ( scantype == PlottingSetup::SMS ) {
1239 TH2F* hrange = new TH2F("hrange","range",2,-12.5,1200-12.5,2,50,1200-12.5);
1240 set_range(hrange,scantype,false);
1241 hrange->Draw();
1242 histo->Draw("COLZ,same");
1243 } else if ( scantype == PlottingSetup::GMSB ) {
1244 TH2F* hrange = new TH2F("hrange","range",2,-12.5,1200-12.5,2,100,1200-12.5);
1245 set_range(hrange,scantype,false);
1246 hrange->Draw();
1247 histo->Draw("COLZ,same");
1248 } else {
1249 histo->Draw("COLZ");
1250 }
1251 DrawPrelim();
1252 float xpos_of_text = 0.22;
1253 if(name.Contains("_noscefficiencymap")) {
1254 // Add some more decorations on these publication plots
1255 write_SMS_text( scantype, scanx, xpos_of_text );
1256 // Decode name and get JZB cut
1257 TPRegexp pat("\\d+$");
1258 size_t index = name.Index(pat,0);
1259 string cut = string("#splitline{JZB > ")+(name(index,name.Length()-index).Data())+" GeV}{n_{jets} #geq 3}";
1260 TText *text = write_text(xpos_of_text,0.71,cut);
1261 text->SetTextAlign(11);
1262 text->SetTextFont(62);
1263 text->SetTextSize(0.035);
1264 text->Draw();
1265 draw_diagonal_xchange( scantype, scanx );
1266 }
1267
1268 CompleteSave(can,(saveto+(string)histo->GetName()));
1269
1270 gStyle->SetPadRightMargin(rightmargin);
1271
1272 delete can;
1273 }
1274
1275 void make_all_syst_plots(vector<TH2F*> all_histos,int scantype,std::string& scanx) {
1276 string saveto="Systematics/";
1277 for(int iplot=0;iplot<all_histos.size();iplot++) {
1278 process_syst_plot(all_histos[iplot],saveto,scantype,scanx);
1279 }
1280 }
1281
1282 void process_file(TFile* file, float stdmargin) {
1283 standardmargin=stdmargin;
1284 xsecfilename="reference_xSec_SMS.root";
1285
1286 // can receive a file with systematics and limits mixed, or a file with systematics only , or a file with limits only.
1287 TIter nextkey(file->GetListOfKeys());
1288 TKey *key;
1289
1290 int scantype=PlottingSetup::SMS;
1291 std::string scanx = "0"; // Just for the legend
1292 if (TString(file->GetName()).Contains("T5zzl")) scanx = "0.75";
1293 else if(TString(file->GetName()).Contains("T5zzh")) scanx = "0.25";
1294 else if(TString(file->GetName()).Contains("T5zz")) scanx = "0.5";
1295
1296 vector<TH2F*> systematics_histos;
1297 vector<TH2F*> limits_histos;
1298 while ((key = (TKey*)nextkey()))
1299 {
1300 TObject *obj = key->ReadObj();
1301 if (!(obj->IsA()->InheritsFrom("TH2"))) continue;
1302 TString name=(TString)(obj->GetName());
1303 bool is_limit=false;
1304 bool is_systematic=false;
1305
1306 if(name.Contains("limitmap")) is_limit=true;
1307 if(name.Contains("explimitmap")) is_limit=true;
1308 if(name.Contains("exp1plimitmap")) is_limit=true;
1309 if(name.Contains("exp2plimitmap")) is_limit=true;
1310 if(name.Contains("exp1mlimitmap")) is_limit=true;
1311 if(name.Contains("exp2mlimitmap")) is_limit=true;
1312 if(name.Contains("exclusionmap")) is_limit=true;
1313 if(name.Contains("crosssectionmap")) is_limit=true;
1314 if(name.Contains("absolutecrosssectionmap")) is_limit=true;
1315 if(name.Contains("limitflipmap")) is_limit=true;
1316
1317 if(name.Contains("sysjes")) is_systematic=true;
1318 if(name.Contains("sysjsu")) is_systematic=true;
1319 if(name.Contains("sysresmap")) is_systematic=true;
1320 if(name.Contains("efficiencymap")) is_systematic=true;
1321 if(name.Contains("efficiencymapAcc")) is_systematic=true;
1322 if(name.Contains("efficiencymapID")) is_systematic=true;
1323 if(name.Contains("efficiencymapJets")) is_systematic=true;
1324 if(name.Contains("efficiencymapSignal")) is_systematic=true;
1325 if(name.Contains("noscefficiencymap")) is_systematic=true;
1326 if(name.Contains("Neventsmap")) is_systematic=true;
1327 if(name.Contains("ipointmap")) is_systematic=true;
1328 if(name.Contains("syspdfmap")) is_systematic=true;
1329 if(name.Contains("systotmap")) is_systematic=true;
1330 if(name.Contains("sysstatmap")) is_systematic=true;
1331 if(name.Contains("timemap")) is_systematic=true;
1332 if(name.Contains("flipmap")) is_systematic=true;
1333
1334 if(is_limit) limits_histos.push_back((TH2F*) obj);
1335 else if(is_systematic) systematics_histos.push_back((TH2F*) obj);
1336 if(name.Contains("mSUGRA")) scantype=PlottingSetup::mSUGRA;
1337 if(name.Contains("GMSB")) scantype=PlottingSetup::GMSB;
1338 }
1339 if(systematics_histos.size()>0) make_all_syst_plots(systematics_histos,scantype,scanx);
1340 if(limits_histos.size()>0) create_exclusion_plots(limits_histos,scantype,scanx);
1341 }
1342