ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.15
Committed: Mon Dec 5 18:07:06 2011 UTC (13 years, 5 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.14: +16 -3 lines
Log Message:
Added a sanity check for points on the exclusion line

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("#2E2EFE")); //dark blue
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 float deltax=x2-x1;
495 float deltay=y2-y1;
496 float b = (y1-x1)/(deltax-deltay);
497 if(scantype==PlottingSetup::SMS) b = (y1-75.-x1)/(deltax-deltay);
498 x = x1 + b * deltax;
499 y = y1 + b * deltay;
500 if(x<0||y<0) x=-1;
501 if((scantype==PlottingSetup::GMSB||scantype==PlottingSetup::SMS) && (x>PlottingSetup::mgluend||y>PlottingSetup::mLSPend)) x=-1;
502 }
503
504 TGraph* get_mSUGRA_exclusion_line(TH2F *exclusionhisto, int scantype) {
505 exclusionhisto->SetStats(0);
506 exclusionhisto->GetZaxis()->SetRangeUser(0,2);
507
508 vector<pair <float,float> > points;
509
510 for(int i=1;i<exclusionhisto->GetNbinsX();i++) {
511 pair<float,float> anything = find_point(exclusionhisto,i);
512 pair<float,float> intthing = find_interpolated_point(exclusionhisto,i);
513 float value=anything.second;
514 if(intthing.second>anything.second) anything.second=intthing.second;
515 if(anything.second>100&&anything.second<1500) points.push_back(anything);
516 }
517
518 Double_t xpoints[points.size()];
519 Double_t spoints[points.size()];
520
521 TGraph *graph = new TGraph(points.size()+1);
522 graph->SetLineColor(kBlack);
523 graph->SetLineWidth(2);
524
525 int pointcounter=0;
526 float lastx=0;
527 float lasty=0;
528 float lastx2=0;
529 float lasty2=0;
530
531 for(int i=0;i<points.size();i++) {
532 xpoints[i]=points[i].first;
533 spoints[i]=points[i].second;
534 if(scantype==PlottingSetup::mSUGRA) {
535 if(i>1&&i<points.size()-1) spoints[i]=(1.0/3.0)*(points[i-1].second+points[i].second+points[i+1].second);
536 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);
537 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);
538 }
539
540 bool usethispoint=true;
541 if(scantype==PlottingSetup::GMSB) {
542 if(spoints[i]<points[i].first) usethispoint=false;
543 }
544 if(scantype==PlottingSetup::SMS) {
545 if(spoints[i]-50.<points[i].first) usethispoint=false;
546 }
547 if((scantype==PlottingSetup::GMSB||scantype==PlottingSetup::SMS) && (spoints[i]>PlottingSetup::mgluend||points[i].first>PlottingSetup::mLSPend)) usethispoint=false;
548
549 if(usethispoint) {
550 graph->SetPoint(pointcounter,points[i].first,spoints[i]);
551 lastx2=lastx;
552 lasty2=lasty;
553 lastx=points[i].first;
554 lasty=spoints[i];
555 pointcounter++;
556 }
557 }
558 for(int i=pointcounter;i<points.size();i++) graph->SetPoint(i,lastx,lasty);
559 if(scantype==PlottingSetup::GMSB||scantype==PlottingSetup::SMS) {
560 //The final point will be a continuation of the last one, towards the diagonal
561 float x,y;
562 project_to_last_point_on_line(lastx,lasty,lastx2,lasty2,x,y,scantype);
563 if(x>0&&y>0) graph->SetPoint(points.size(),x,y);
564 else graph->SetPoint(points.size(),lastx,lasty);
565 }
566
567 return graph;
568 }
569
570 void draw_mSUGRA_exclusion(TH2F *crosssection, TH2F *limitmap, TH2F *expmap, TH2F *expplusmap, TH2F *expminusmap, TH2F *exp2plusmap, TH2F *exp2minusmap) {
571 TH2F *cleanhisto = (TH2F*)limitmap->Clone("clean");
572 for(int ix=1;ix<=cleanhisto->GetNbinsX();ix++) {
573 for(int iy=1;iy<=cleanhisto->GetNbinsY();iy++) {
574 cleanhisto->SetBinContent(ix,iy,0);
575 }
576 }
577
578 TH2F *limits = (TH2F*)limitmap->Clone("limits");
579 set_range(limits,true,false);
580 limitmap->Divide(crosssection);
581 expminusmap->Divide(crosssection);
582 expplusmap->Divide(crosssection);
583 exp2minusmap->Divide(crosssection);
584 exp2plusmap->Divide(crosssection);
585 expmap->Divide(crosssection);
586 TGraph *observed = get_mSUGRA_exclusion_line(limitmap, PlottingSetup::mSUGRA);
587 observed->SetLineColor(kRed);
588 TGraph *expminus = get_mSUGRA_exclusion_line(expminusmap, PlottingSetup::mSUGRA);
589 TGraph *expplus = get_mSUGRA_exclusion_line(expplusmap, PlottingSetup::mSUGRA);
590 TGraph *exp2minus;
591 if(draw2sigma) exp2minus = get_mSUGRA_exclusion_line(exp2minusmap, PlottingSetup::mSUGRA);
592 TGraph *exp2plus;
593 if(draw2sigma) exp2plus = get_mSUGRA_exclusion_line(exp2plusmap, PlottingSetup::mSUGRA);
594
595 TGraph *expected = new TGraph(expminus->GetN()+expplus->GetN());
596 TGraph *expected2;
597 if(draw2sigma) expected2 = new TGraph(exp2minus->GetN()+exp2plus->GetN());
598 for(int i=0;i<=expminus->GetN();i++) {
599 Double_t x,y;
600 expminus->GetPoint(i,x,y);
601 expected->SetPoint(i,x,y);
602 }
603
604 for(int i=0;i<=exp2minus->GetN();i++) {
605 Double_t x,y;
606 exp2minus->GetPoint(i,x,y);
607 expected2->SetPoint(i,x,y);
608 }
609 for(int i=exp2plus->GetN()-1;i>=0;i--) {
610 Double_t x,y;
611 exp2plus->GetPoint(i,x,y);
612 expected2->SetPoint(exp2minus->GetN()+(exp2plus->GetN()-i),x,y);
613 }
614 for(int i=expplus->GetN()-1;i>=0;i--) {
615 Double_t x,y;
616 expplus->GetPoint(i,x,y);
617 expected->SetPoint(expminus->GetN()+(expplus->GetN()-i),x,y);
618 }
619 expected->SetFillColor(TColor::GetColor("#9FF781"));
620 if(draw2sigma) expected2->SetFillColor(TColor::GetColor("#F3F781"));
621
622 smooth_line(observed);
623 smooth_line(expected);
624 if(draw2sigma) smooth_line(expected2);
625
626 TCanvas *te = new TCanvas("te","te");
627 decorate_mSUGRA(cleanhisto,te,expected,expected2,observed);
628 stringstream saveas;
629 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);
630 else saveas << "Limits/final_exclusion_for_bestlimits";
631 CompleteSave(te,saveas.str());
632 delete te;
633
634 TCanvas *overview = new TCanvas("overview","overview",1000,1000);
635 set_range(crosssection,true,false);
636 set_range(limits,true,false);
637 set_range(limitmap,true,false);
638
639 overview->Divide(2,2);
640 overview->cd(1);
641 overview->cd(1)->SetLogz(1);
642 crosssection->GetZaxis()->SetRangeUser(0.0001,100);
643 crosssection->Draw("COLZ");
644 TText *title0 = write_title("Cross Section");
645 title0->Draw("same");
646 overview->cd(2);
647 overview->cd(2)->SetLogz(1);
648 limits->GetZaxis()->SetRangeUser(0.1,100);
649 limits->Draw("COLZ");
650 TText *title1 = write_title("Cross Section Upper Limit");
651 title1->Draw("same");
652 overview->cd(3);
653 limitmap->Draw("COLZ");
654 TText *title2 = write_title("UL/XS");
655 title2->Draw("same");
656 observed->Draw("c");
657 overview->cd(4);
658 decorate_mSUGRA(cleanhisto,overview->cd(4),expected,expected2,observed);
659 stringstream saveas2;
660 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);
661 else saveas2 << "Limits/exclusion_overview_for_bestlimits";
662 CompleteSave(overview,saveas2.str());
663 delete overview;
664
665
666 }
667
668 TH2F* get_XS(string filename, string mass, TH2F *histo) {///DONE
669 TH1 *hRef=getHisto((char*) filename.c_str(), (char*) mass.c_str(), (char*) "0", 1,1);
670 TH2F * xsec= new TH2F("xsec","xsec",60, 0., 1500., 60, 0., 1500.);
671 for(int i=1; i<(histo->GetNbinsX()+1); i++) {
672 for(int j=1; j<(histo->GetNbinsY()+1); j++) {
673 if(!(histo->GetBinContent(i,j)==0)) xsec->SetBinContent(i,j,hRef->GetBinContent(hRef->FindBin(xsec->GetXaxis()->GetBinCenter(i))));
674 }
675 }
676 return xsec;
677 }
678
679 string give_nice_source_label(string name) {
680 int mappoint=name.find("map");
681 if(mappoint<0||mappoint>500) return name; // this mean that something weird is happening
682 stringstream nice_label;
683 nice_label << "JZB > " << name.substr(mappoint+3,name.size()) << " GeV";
684 return nice_label.str();
685 }
686
687 Int_t get_exclusion_region_color(double value, TH2F *histo) {
688 Double_t wmin = histo->GetMinimum();
689 Double_t wmax = histo->GetMaximum();
690 Double_t wlmin = wmin;
691 Double_t wlmax = wmax;
692
693
694 Int_t ncolors = gStyle->GetNumberOfColors();
695 Int_t ndivz = histo->GetContour();
696 if (ndivz == 0) return 0;
697 ndivz = TMath::Abs(ndivz);
698 Int_t theColor, color;
699 Double_t scale = ndivz / (wlmax - wlmin);
700
701 if (value < wlmin) value = wlmin;
702
703 color = Int_t(0.01 + (value - wlmin) * scale);
704
705 theColor = Int_t((color + 0.99) * Double_t(ncolors) / Double_t(ndivz));
706 return gStyle->GetColorPalette(theColor);
707 }
708
709
710 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) {
711 if(obslimits.size()==0) {
712 write_warning(__FUNCTION__,"There are no observed limits! Cannot continue!");
713 TH2F *err;
714 return err;
715 }
716 if(explimits.size()==0) {
717 write_warning(__FUNCTION__,"There are no expected limits! Will compute best limits based on observed limits! (WATCH OUT THIS IS DISCOURAGED!");
718 for(int i=0;i<obslimits.size();i++) explimits.push_back(obslimits[i]);
719 }
720 TH2F *bestlimit=(TH2F*)obslimits[0]->Clone("bestlimits");
721 TH2F *bestexplimit=(TH2F*)obslimits[0]->Clone("bestexplimits");
722 TH2F *bestlimitsource=(TH2F*)obslimits[0]->Clone("bestlimitsource");
723 TH2F *bestexp1plimit=(TH2F*)obslimits[0]->Clone("bestexp1plimit");
724 TH2F *bestexp1mlimit=(TH2F*)obslimits[0]->Clone("bestexp1mlimit");
725 TH2F *bestexp2plimit=(TH2F*)obslimits[0]->Clone("bestexp2plimit");
726 TH2F *bestexp2mlimit=(TH2F*)obslimits[0]->Clone("bestexp2mlimit");
727
728 for(int i=1;i<=explimits[0]->GetNbinsX();i++) {
729 for(int j=1;j<=explimits[0]->GetNbinsY();j++) {
730 float min=explimits[0]->GetBinContent(i,j);
731 float omin=obslimits[0]->GetBinContent(i,j);
732 int source=1;
733 for(int k=0;k<explimits.size();k++) {
734 float currlim=explimits[k]->GetBinContent(i,j);
735 if(currlim<min&&currlim>0) {
736 min=currlim;
737 omin=obslimits[k]->GetBinContent(i,j);
738 source=k+1;
739 }
740 }
741 if(min>0) {
742 bestlimitsource->SetBinContent(i,j,source);
743 bestlimit->SetBinContent(i,j,omin);
744 bestexplimit->SetBinContent(i,j,min);
745 if(scantype==PlottingSetup::mSUGRA) {
746 bestexp1plimit->SetBinContent(i,j,exp1plimits[source-1]->GetBinContent(i,j));
747 bestexp1mlimit->SetBinContent(i,j,exp1mlimits[source-1]->GetBinContent(i,j));
748 bestexp2plimit->SetBinContent(i,j,exp2plimits[source-1]->GetBinContent(i,j));
749 bestexp2mlimit->SetBinContent(i,j,exp2mlimits[source-1]->GetBinContent(i,j));
750 }
751 }
752 }
753 }
754 gStyle->SetPadRightMargin(standardmargin);
755 TCanvas *canlimsource = new TCanvas("limsource","Source of best limits");
756 set_range(bestlimitsource,scantype,false);
757 bestlimitsource->SetTitle("Source of limit for best limits");
758 bestlimitsource->GetZaxis()->SetRangeUser(0,explimits.size()+1);
759 bestlimitsource->Draw("COL");
760 gPad->Update();
761 if(scantype!=PlottingSetup::mSUGRA) bestlimitsource->Draw("TEXT,same");
762 TLegend *sourceleg = new TLegend(0.2,0.6,0.55,0.85);
763 for(int i=0;i<explimits.size();i++) {
764 stringstream legendentry;
765 legendentry << i+1 << " = " << give_nice_source_label(explimits[i]->GetName());
766 Int_t currcol=get_exclusion_region_color(i+1,bestlimitsource);
767 explimits[i]->SetFillColor(currcol);
768 explimits[i]->SetLineColor(currcol);
769 sourceleg->AddEntry(explimits[i], legendentry.str().c_str(),"f");
770 }
771 sourceleg->SetLineColor(kWhite);sourceleg->SetFillColor(kWhite);
772 sourceleg->SetTextSize(0.03);
773 sourceleg->Draw("same");
774 DrawPrelim();
775
776 CompleteSave(canlimsource,"Limits/SourceOfBestLimits");
777 gStyle->SetPadRightMargin(indentedmargin);
778 allbestexplimits.push_back(bestexplimit);
779 allbestexplimits.push_back(bestexp1plimit);
780 allbestexplimits.push_back(bestexp1mlimit);
781 allbestexplimits.push_back(bestexp2plimit);
782 allbestexplimits.push_back(bestexp2mlimit);
783
784 delete canlimsource;
785 delete bestexplimit;
786 delete bestlimitsource;
787 return bestlimit;
788 }
789
790
791 void create_exclusion_plots(vector<TH2F*> limits, int scantype) {
792 TFile *xsecfile;
793 if(scantype!=PlottingSetup::mSUGRA) {
794 xsecfile = new TFile(xsecfilename.c_str());
795 if(xsecfile->IsZombie()&&(scantype!=PlottingSetup::mSUGRA)) {
796 write_error(__FUNCTION__,"Cross section file is invalid!!!!");
797 return;
798 }
799 xsecfile->Close();
800 }
801 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
802
803 vector<TH2F*> explimits;
804 vector<TH2F*> exp1mlimits;
805 vector<TH2F*> exp1plimits;
806 vector<TH2F*> exp2mlimits;
807 vector<TH2F*> exp2plimits;
808 vector<TH2F*> obslimits;
809 vector<TH2F*> flipmaps;
810 vector<TH2F*> crosssections;
811
812 for(int ilim=0;ilim<limits.size();ilim++) {
813 if(TString(limits[ilim]->GetName()).Contains("_explimitmap")) explimits.push_back(limits[ilim]);
814 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp1plimitmap")) exp1plimits.push_back(limits[ilim]);
815 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp1mlimitmap")) exp1mlimits.push_back(limits[ilim]);
816 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp2plimitmap")) exp2plimits.push_back(limits[ilim]);
817 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp2mlimitmap")) exp2mlimits.push_back(limits[ilim]);
818 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_absolutecrosssectionmap")) crosssections.push_back(limits[ilim]);
819 if(TString(limits[ilim]->GetName()).Contains("_limitmap")) obslimits.push_back(limits[ilim]);
820 // if(TString(limits[ilim]->GetName()).Contains("_limitflipmap")) flipmaps.push_back(limits[ilim]);
821 }
822
823 TH2F *xsec;
824 if(scantype!=PlottingSetup::mSUGRA) xsec = adjust_histo(get_XS(xsecfilename,"gluino",limits[0]),limits[0]);
825 vector<TH2F*> bestexplimits;
826 TH2F *bestlimits = make_best_limits(explimits,obslimits,scantype, exp1mlimits, exp1plimits, exp2mlimits, exp2plimits, bestexplimits);
827 bestlimits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
828
829 for(int ilim=0;ilim<limits.size();ilim++) {
830 limits[ilim]->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
831 }
832
833 if(scantype!=PlottingSetup::mSUGRA) {
834 for(int ilim=0;ilim<obslimits.size();ilim++) make_SMS_exclusion(obslimits[ilim],xsec,scantype);
835 make_SMS_exclusion(bestlimits,xsec,scantype);
836 } else {
837 for(int ilim=0;ilim<obslimits.size();ilim++) {
838 draw_mSUGRA_exclusion(crosssections[0], obslimits[ilim], explimits[ilim], exp1mlimits[ilim], exp1plimits[ilim], exp2mlimits[ilim], exp2plimits[ilim]);
839 }
840 draw_mSUGRA_exclusion(crosssections[0], bestlimits, bestexplimits[0], bestexplimits[1], bestexplimits[2], bestexplimits[3], bestexplimits[4]);
841 }
842 delete bestlimits;
843 }
844
845 void decorate_mSUGRA(TH2F *cleanhisto, TVirtualPad *cvsSys,TGraph *expected,TGraph *expected2,TGraph *observed) {
846 cvsSys->SetRightMargin(standardmargin);
847 Int_t tanBeta_ = 10;
848 Bool_t plotLO_ = false;
849
850 //convert tanb value to string
851 std::stringstream tmp;
852 tmp << tanBeta_;
853 TString tanb( tmp.str() );
854
855 //set old exclusion Limits
856 TGraph* LEP_ch = set_lep_ch(tanBeta_);
857 TGraph* LEP_sl = set_lep_sl(tanBeta_);//slepton curve
858 TGraph* TEV_sg_cdf = set_tev_sg_cdf(tanBeta_);//squark gluino cdf
859 TGraph* TEV_sg_d0 = set_tev_sg_d0(tanBeta_);//squark gluino d0
860 TGraph* stau = set_tev_stau(tanBeta_);//stau
861 TGraph* NoEWSB = set_NoEWSB(tanBeta_);
862
863 TGraph* TEV_sn_d0_1 = set_sneutrino_d0_1(tanBeta_);
864 TGraph* TEV_sn_d0_2 = set_sneutrino_d0_2(tanBeta_);
865
866 //constant ssqquark and gluino lines
867 TF1* lnsq[10];
868 TF1* lngl[10];
869
870 TLatex* sq_text[10];
871 TLatex* gl_text[10];
872
873 for(int i = 0; i < 6; i++){
874 lnsq[i] = constant_squark(tanBeta_,i);
875 sq_text[i] = constant_squark_text(i,*lnsq[i],tanBeta_);
876 lngl[i] = constant_gluino(tanBeta_,i);
877 gl_text[i] = constant_gluino_text(i,*lngl[i]);
878 }
879
880 //Legends
881 TLegend* legst = makeStauLegend(0.05,tanBeta_);
882 TLegend* legNoEWSB = makeNoEWSBLegend(0.05,tanBeta_);
883 TLegend* legexp = makeExpLegend( *TEV_sg_cdf,*TEV_sg_d0,*LEP_ch,*LEP_sl,*TEV_sn_d0_1,0.035,tanBeta_);
884
885 TEV_sn_d0_1->SetLineWidth(1);
886 TEV_sn_d0_2->SetLineWidth(1);
887 TEV_sg_d0->SetLineWidth(1);
888
889 double m0min = 0;
890 if (tanBeta_ == 50) m0min=200;
891 TH2F* hist = new TH2F("h","h",100,m0min,1000,100,120,700);
892 hist->Draw();
893 hist->GetXaxis()->SetTitle("m_{0} [GeV]");
894 hist->GetXaxis()->CenterTitle();
895 hist->GetYaxis()->SetTitle("m_{1/2} [GeV]");
896 hist->GetYaxis()->CenterTitle();
897 hist->GetXaxis()->SetTitleSize(0.04);
898 hist->GetYaxis()->SetTitleSize(0.04);
899 hist->GetXaxis()->SetTitleOffset(1.2);
900 hist->GetYaxis()->SetTitleOffset(1.5);
901 hist->GetXaxis()->SetNdivisions(506);
902 hist->GetYaxis()->SetNdivisions(506);
903
904 int col[]={2,3,4};
905
906 TLegend* myleg;
907
908 if( plotLO_ ) myleg = new TLegend(0.3,0.65,0.65,0.8,NULL,"brNDC");
909 else myleg = new TLegend(0.25,0.76,0.44,0.91,NULL,"brNDC");
910
911 myleg->SetFillColor(0);
912 myleg->SetShadowColor(0);
913 myleg->SetTextSize(0.04);
914 myleg->SetBorderSize(0);
915
916 //constant squark and gluino mass contours
917 for (int it=0;it<5;it++) {
918 lngl[it]->Draw("same");
919 lnsq[it]->Draw("same");
920 sq_text[it]->Draw();
921 gl_text[it]->Draw();
922 }
923
924 //exclusion limits previous experiments
925 if(tanBeta_ == 3){
926 TEV_sn_d0_1->Draw("fsame");
927 TEV_sn_d0_2->Draw("fsame");
928 }
929 LEP_ch->Draw("fsame");
930 if (tanBeta_ != 50) LEP_sl->Draw("fsame");
931
932 //remove CDF/D0 excluded regions
933 TEV_sg_cdf->Draw("fsame");
934 TEV_sg_d0->Draw("same");
935 TEV_sg_d0->Draw("fsame");
936
937 //other labels
938 Double_t xpos = 0;
939 Double_t xposi = 0;
940 Double_t ypos = 0;
941 if(tanBeta_ == 50) xposi = 100;
942 if(tanBeta_ == 50) xpos = 200;
943 if(tanBeta_ == 50) ypos = -10;
944
945 TString text_tanBeta;
946 text_tanBeta = "tan#beta = "+tanb+", A_{0} = 0, #mu > 0";
947 TLatex* cmssmpars = new TLatex(/*530.+xpos,690.+ypos-130*/150,650,text_tanBeta);
948
949 cmssmpars->SetTextSize(0.03);
950 cmssmpars->Draw("same");
951
952 TLatex* lep_chargino = new TLatex(250,135,"LEP2 #tilde{#chi}_{1}^{#pm}");
953 lep_chargino->SetTextSize(0.03);
954 lep_chargino->SetTextFont(42);
955
956 TLatex* lep_slepton = new TLatex(26,190,"LEP2 #tilde{#font[12]{l}}^{#pm}");
957 lep_slepton->SetTextSize(0.03);
958 lep_slepton->SetTextAngle(-83);
959 lep_slepton->SetTextFont(42);
960
961 if(draw2sigma) expected2->Draw("f");
962 expected->SetLineColor(expected->GetFillColor());
963 expected2->SetLineColor(expected2->GetFillColor());
964 expected->Draw("f");
965 observed->Draw("c");
966
967 stau->Draw("fsame");
968 NoEWSB->Draw("fsame");
969
970 legexp->AddEntry(observed,"Observed limit","l");
971 legexp->AddEntry(expected,"Expected 1#sigma limit","f");
972 if(draw2sigma) legexp->AddEntry(expected2,"Expected 2#sigma limit","f");
973 legexp->SetY1(0.60);
974 legexp->SetX1(0.55);
975 legexp->Draw();
976 legst->Draw();
977
978 hist->Draw("sameaxis");
979 cvsSys->RedrawAxis();
980 cvsSys->Update();
981 DrawPrelim();
982 }
983
984 void smooth_line_once(TGraph *gr) {
985 //going to smooth graph
986 //need to take into account the DIRECTION we're heading so we noticed for expected shape when we turn around and go back
987 float previousX=-100;
988 int sign=1;
989 for(int i=0;i<gr->GetN();i++) {
990 Double_t x,y,x1,y1,x2,y2;
991 bool turning=false;
992 gr->GetPoint(i,x,y);
993 gr->GetPoint(i+1,x1,y1);//need to handle exception here
994 gr->GetPoint(i-1,x2,y2);//need to handle exception here
995 if(i!=gr->GetN()-1&& (sign*x<=sign*previousX||sign*x1<=sign*x)) {
996 //turned around!
997 sign=(-1)*sign;
998 // do NOT do any smoothing on this point!
999 } else {
1000 float newval=y;
1001 if(i>0&&i<(gr->GetN())-1) newval=(1.0/3.0)*(y+y1+y2);
1002 if(i==0) newval=(1.0/2.0)*(y+y1);
1003 if(i==gr->GetN()-1) newval=(1.0/2.0)*(y+y2);
1004 gr->SetPoint(i,x,newval);
1005 }
1006 previousX=x;
1007 }
1008 }
1009
1010 void smooth_line(TGraph *gr) {
1011 smooth_line_once(gr);
1012 smooth_line_once(gr);
1013 smooth_line_once(gr);
1014 }
1015 void set_range(TH2F *histo, int scantype, bool pushoutyz=false) {
1016 if(scantype==PlottingSetup::mSUGRA) {
1017 histo->GetXaxis()->SetRangeUser(0,2000);
1018 histo->GetYaxis()->SetRangeUser(0,800);
1019 histo->GetXaxis()->SetTitle("m_{0} [GeV]");
1020 histo->GetYaxis()->SetTitle("m_{1/2} [GeV]");
1021 histo->GetXaxis()->SetRangeUser(0,2000);
1022 histo->GetXaxis()->SetNdivisions(504,true);
1023 }
1024 if(scantype==PlottingSetup::SMS) {
1025 histo->GetXaxis()->SetRangeUser(50,1200);
1026 histo->GetYaxis()->SetRangeUser(50,1200);
1027 histo->GetXaxis()->SetTitle("m_{#tilde{g}} [GeV]");
1028 histo->GetYaxis()->SetTitle("m_{LSP} [GeV]");
1029 histo->GetXaxis()->SetTitleSize(0.04);
1030 histo->GetYaxis()->SetTitleSize(0.04);
1031 histo->GetZaxis()->SetTitleSize(0.04);
1032 histo->GetXaxis()->SetTitleOffset(1.2);
1033 histo->GetYaxis()->SetTitleOffset(1.5);
1034 if(pushoutyz) histo->GetZaxis()->SetTitleOffset(1.6);
1035 }
1036 if(scantype==PlottingSetup::GMSB) {
1037 histo->GetXaxis()->SetRangeUser(100,1200);
1038 histo->GetYaxis()->SetRangeUser(100,1200);
1039 histo->GetXaxis()->SetTitle("m_{#tilde{g}} [GeV]");
1040 histo->GetYaxis()->SetTitle("m_{#chi} [GeV]");
1041 histo->GetXaxis()->SetTitleSize(0.04);
1042 histo->GetYaxis()->SetTitleSize(0.04);
1043 histo->GetZaxis()->SetTitleSize(0.04);
1044 histo->GetXaxis()->SetTitleOffset(1.2);
1045 histo->GetYaxis()->SetTitleOffset(1.5);
1046 if(pushoutyz) histo->GetZaxis()->SetTitleOffset(1.6);
1047 }
1048
1049 histo->GetXaxis()->CenterTitle();
1050 histo->GetYaxis()->CenterTitle();
1051 histo->SetStats(0);
1052 }
1053
1054 TH2F* adjust_histo(TH2F *oldhist, TH2F *refhisto) {
1055 TH2F *histo = new TH2F(refhisto->GetName(),refhisto->GetName(),
1056 refhisto->GetNbinsX(),refhisto->GetXaxis()->GetBinLowEdge(1),refhisto->GetXaxis()->GetBinLowEdge(refhisto->GetNbinsX())+refhisto->GetXaxis()->GetBinWidth(refhisto->GetNbinsX()),
1057 refhisto->GetNbinsY(),refhisto->GetYaxis()->GetBinLowEdge(1),refhisto->GetYaxis()->GetBinLowEdge(refhisto->GetNbinsY())+refhisto->GetYaxis()->GetBinWidth(refhisto->GetNbinsY()));
1058
1059 for(int ix=1;ix<=refhisto->GetNbinsX();ix++) {
1060 for(int iy=1;iy<=refhisto->GetNbinsX();iy++) {
1061 int binnum=refhisto->FindBin(refhisto->GetXaxis()->GetBinCenter(ix),refhisto->GetYaxis()->GetBinCenter(iy));
1062 histo->SetBinContent(binnum,oldhist->GetBinContent(ix,iy));
1063 }
1064 }
1065 return histo;
1066 }
1067
1068 void process_syst_plot(TH2F *rhisto,string saveto,int scantype) {
1069 TH2F *histo = prep_histo(rhisto,scantype); // this is to be independent of the style used at creation time
1070 float rightmargin=gStyle->GetPadRightMargin();
1071 gStyle->SetPadRightMargin(0.20);
1072 TString name = rhisto->GetName();
1073 if(name.Contains("Nevents")) gStyle->SetPadRightMargin(0.22);
1074 TCanvas *can = new TCanvas("syst_plot","Systematics Plot");
1075 set_range(histo,scantype,true);
1076
1077
1078 if(name.Contains("efficiency")) {
1079 histo->GetZaxis()->SetTitle("A #times #varepsilon (#geq 1 Z(ll))");
1080 //histo->GetZaxis()->SetRangeUser(0.0,0.3);
1081 }
1082 if(name.Contains("Nevents")) {
1083 histo->GetZaxis()->SetTitle("N(events)");
1084 histo->GetZaxis()->SetTitleOffset(histo->GetZaxis()->GetTitleOffset()+0.4);
1085 }
1086 if(name.Contains("sysjes")) {
1087 histo->GetZaxis()->SetTitle("Jet Energy Scale");
1088 histo->GetZaxis()->SetRangeUser(0.0,0.2);
1089 }
1090 if(name.Contains("sysjsu")) {
1091 histo->GetZaxis()->SetTitle("JZB Scale Uncertainty");
1092 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1093 }
1094 if(name.Contains("sysresmap")) {
1095 histo->GetZaxis()->SetTitle("Resulution");
1096 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1097 }
1098 if(name.Contains("sysstatmap")) {
1099 histo->GetZaxis()->SetTitle("Statistical Error");
1100 histo->GetZaxis()->SetRangeUser(0.0,0.01);
1101 }
1102 if(name.Contains("systotmap")) {
1103 histo->GetZaxis()->SetTitle("All Systematic Errors");
1104 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1105 }
1106
1107 histo->GetZaxis()->CenterTitle();
1108 gStyle->SetStripDecimals(false);
1109 histo->GetXaxis()->SetDecimals(true);
1110
1111 histo->Draw("COLZ");
1112 DrawPrelim();
1113
1114 CompleteSave(can,(saveto+(string)histo->GetName()));
1115
1116 gStyle->SetPadRightMargin(rightmargin);
1117
1118 delete can;
1119 }
1120
1121 void make_all_syst_plots(vector<TH2F*> all_histos,int scantype) {
1122 string saveto="Systematics/";
1123 for(int iplot=0;iplot<all_histos.size();iplot++) {
1124 process_syst_plot(all_histos[iplot],saveto,scantype);
1125 }
1126 }
1127
1128 void process_file(TFile* file, float stdmargin) {
1129 standardmargin=stdmargin;
1130 xsecfilename="reference_xSec_SMS.root";
1131
1132 // can receive a file with systematics and limits mixed, or a file with systematics only , or a file with limits only.
1133 TIter nextkey(file->GetListOfKeys());
1134 TKey *key;
1135
1136 int scantype=PlottingSetup::SMS;
1137
1138 vector<TH2F*> systematics_histos;
1139 vector<TH2F*> limits_histos;
1140 while ((key = (TKey*)nextkey()))
1141 {
1142 TObject *obj = key->ReadObj();
1143 if (!(obj->IsA()->InheritsFrom("TH2"))) continue;
1144 TString name=(TString)(obj->GetName());
1145 bool is_limit=false;
1146 bool is_systematic=false;
1147
1148 if(name.Contains("limitmap")) is_limit=true;
1149 if(name.Contains("explimitmap")) is_limit=true;
1150 if(name.Contains("exp1plimitmap")) is_limit=true;
1151 if(name.Contains("exp2plimitmap")) is_limit=true;
1152 if(name.Contains("exp1mlimitmap")) is_limit=true;
1153 if(name.Contains("exp2mlimitmap")) is_limit=true;
1154 if(name.Contains("exclusionmap")) is_limit=true;
1155 if(name.Contains("crosssectionmap")) is_limit=true;
1156 if(name.Contains("absolutecrosssectionmap")) is_limit=true;
1157 if(name.Contains("limitflipmap")) is_limit=true;
1158
1159 if(name.Contains("sysjes")) is_systematic=true;
1160 if(name.Contains("sysjsu")) is_systematic=true;
1161 if(name.Contains("sysresmap")) is_systematic=true;
1162 if(name.Contains("efficiencymap")) is_systematic=true;
1163 if(name.Contains("efficiencymapAcc")) is_systematic=true;
1164 if(name.Contains("efficiencymapID")) is_systematic=true;
1165 if(name.Contains("efficiencymapJets")) is_systematic=true;
1166 if(name.Contains("efficiencymapSignal")) is_systematic=true;
1167 if(name.Contains("noscefficiencymap")) is_systematic=true;
1168 if(name.Contains("Neventsmap")) is_systematic=true;
1169 if(name.Contains("ipointmap")) is_systematic=true;
1170 if(name.Contains("syspdfmap")) is_systematic=true;
1171 if(name.Contains("systotmap")) is_systematic=true;
1172 if(name.Contains("sysstatmap")) is_systematic=true;
1173 if(name.Contains("timemap")) is_systematic=true;
1174 if(name.Contains("flipmap")) is_systematic=true;
1175
1176 if(is_limit) limits_histos.push_back((TH2F*) obj);
1177 else if(is_systematic) systematics_histos.push_back((TH2F*) obj);
1178 if(name.Contains("mSUGRA")) scantype=PlottingSetup::mSUGRA;
1179 if(name.Contains("GMSB")) scantype=PlottingSetup::GMSB;
1180 }
1181 if(systematics_histos.size()>0) make_all_syst_plots(systematics_histos,scantype);
1182 if(limits_histos.size()>0) create_exclusion_plots(limits_histos,scantype);
1183 }
1184