ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.17
Committed: Tue Dec 13 10:44:44 2011 UTC (13 years, 5 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.16: +11 -2 lines
Log Message:
Fix special case: if the first histo of expected limits has an empty bin (i.e. bin content 0), then there's no chance any of the following histos will ever beat that and fill in something meaningful ...

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