ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ExclusionPlot.C
Revision: 1.14
Committed: Wed Sep 19 09:16:24 2012 UTC (12 years, 7 months ago) by buchmann
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.13: +3 -3 lines
Error occurred while calculating annotation data.
Log Message:
Updated window to 10 GeV around 91 GeV

File Contents

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