ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.16
Committed: Tue Dec 13 09:54:38 2011 UTC (13 years, 5 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.15: +15 -9 lines
Log Message:
Updated exclusion line algorithm so that the connection from the last point to the diagonal is orthogonal to the diagonal (the angle is no longer conserved)

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
716 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) {
717 if(obslimits.size()==0) {
718 write_warning(__FUNCTION__,"There are no observed limits! Cannot continue!");
719 TH2F *err;
720 return err;
721 }
722 if(explimits.size()==0) {
723 write_warning(__FUNCTION__,"There are no expected limits! Will compute best limits based on observed limits! (WATCH OUT THIS IS DISCOURAGED!");
724 for(int i=0;i<obslimits.size();i++) explimits.push_back(obslimits[i]);
725 }
726 TH2F *bestlimit=(TH2F*)obslimits[0]->Clone("bestlimits");
727 TH2F *bestexplimit=(TH2F*)obslimits[0]->Clone("bestexplimits");
728 TH2F *bestlimitsource=(TH2F*)obslimits[0]->Clone("bestlimitsource");
729 TH2F *bestexp1plimit=(TH2F*)obslimits[0]->Clone("bestexp1plimit");
730 TH2F *bestexp1mlimit=(TH2F*)obslimits[0]->Clone("bestexp1mlimit");
731 TH2F *bestexp2plimit=(TH2F*)obslimits[0]->Clone("bestexp2plimit");
732 TH2F *bestexp2mlimit=(TH2F*)obslimits[0]->Clone("bestexp2mlimit");
733
734 for(int i=1;i<=explimits[0]->GetNbinsX();i++) {
735 for(int j=1;j<=explimits[0]->GetNbinsY();j++) {
736 float min=explimits[0]->GetBinContent(i,j);
737 float omin=obslimits[0]->GetBinContent(i,j);
738 int source=1;
739 for(int k=0;k<explimits.size();k++) {
740 float currlim=explimits[k]->GetBinContent(i,j);
741 if(currlim<min&&currlim>0) {
742 min=currlim;
743 omin=obslimits[k]->GetBinContent(i,j);
744 source=k+1;
745 }
746 }
747 if(min>0) {
748 bestlimitsource->SetBinContent(i,j,source);
749 bestlimit->SetBinContent(i,j,omin);
750 bestexplimit->SetBinContent(i,j,min);
751 if(scantype==PlottingSetup::mSUGRA) {
752 bestexp1plimit->SetBinContent(i,j,exp1plimits[source-1]->GetBinContent(i,j));
753 bestexp1mlimit->SetBinContent(i,j,exp1mlimits[source-1]->GetBinContent(i,j));
754 bestexp2plimit->SetBinContent(i,j,exp2plimits[source-1]->GetBinContent(i,j));
755 bestexp2mlimit->SetBinContent(i,j,exp2mlimits[source-1]->GetBinContent(i,j));
756 }
757 }
758 }
759 }
760 gStyle->SetPadRightMargin(standardmargin);
761 TCanvas *canlimsource = new TCanvas("limsource","Source of best limits");
762 set_range(bestlimitsource,scantype,false);
763 bestlimitsource->SetTitle("Source of limit for best limits");
764 bestlimitsource->GetZaxis()->SetRangeUser(0,explimits.size()+1);
765 bestlimitsource->Draw("COL");
766 gPad->Update();
767 if(scantype!=PlottingSetup::mSUGRA) bestlimitsource->Draw("TEXT,same");
768 TLegend *sourceleg = new TLegend(0.2,0.6,0.55,0.85);
769 for(int i=0;i<explimits.size();i++) {
770 stringstream legendentry;
771 legendentry << i+1 << " = " << give_nice_source_label(explimits[i]->GetName());
772 Int_t currcol=get_exclusion_region_color(i+1,bestlimitsource);
773 explimits[i]->SetFillColor(currcol);
774 explimits[i]->SetLineColor(currcol);
775 sourceleg->AddEntry(explimits[i], legendentry.str().c_str(),"f");
776 }
777 sourceleg->SetLineColor(kWhite);sourceleg->SetFillColor(kWhite);
778 sourceleg->SetTextSize(0.03);
779 sourceleg->Draw("same");
780 DrawPrelim();
781
782 CompleteSave(canlimsource,"Limits/SourceOfBestLimits");
783 gStyle->SetPadRightMargin(indentedmargin);
784 allbestexplimits.push_back(bestexplimit);
785 allbestexplimits.push_back(bestexp1plimit);
786 allbestexplimits.push_back(bestexp1mlimit);
787 allbestexplimits.push_back(bestexp2plimit);
788 allbestexplimits.push_back(bestexp2mlimit);
789
790 delete canlimsource;
791 delete bestexplimit;
792 delete bestlimitsource;
793 return bestlimit;
794 }
795
796
797 void create_exclusion_plots(vector<TH2F*> limits, int scantype) {
798 TFile *xsecfile;
799 if(scantype!=PlottingSetup::mSUGRA) {
800 xsecfile = new TFile(xsecfilename.c_str());
801 if(xsecfile->IsZombie()&&(scantype!=PlottingSetup::mSUGRA)) {
802 write_error(__FUNCTION__,"Cross section file is invalid!!!!");
803 return;
804 }
805 xsecfile->Close();
806 }
807 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
808
809 vector<TH2F*> explimits;
810 vector<TH2F*> exp1mlimits;
811 vector<TH2F*> exp1plimits;
812 vector<TH2F*> exp2mlimits;
813 vector<TH2F*> exp2plimits;
814 vector<TH2F*> obslimits;
815 vector<TH2F*> flipmaps;
816 vector<TH2F*> crosssections;
817
818 for(int ilim=0;ilim<limits.size();ilim++) {
819 if(TString(limits[ilim]->GetName()).Contains("_explimitmap")) explimits.push_back(limits[ilim]);
820 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp1plimitmap")) exp1plimits.push_back(limits[ilim]);
821 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp1mlimitmap")) exp1mlimits.push_back(limits[ilim]);
822 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp2plimitmap")) exp2plimits.push_back(limits[ilim]);
823 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp2mlimitmap")) exp2mlimits.push_back(limits[ilim]);
824 if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_absolutecrosssectionmap")) crosssections.push_back(limits[ilim]);
825 if(TString(limits[ilim]->GetName()).Contains("_limitmap")) obslimits.push_back(limits[ilim]);
826 // if(TString(limits[ilim]->GetName()).Contains("_limitflipmap")) flipmaps.push_back(limits[ilim]);
827 }
828
829 TH2F *xsec;
830 if(scantype!=PlottingSetup::mSUGRA) xsec = adjust_histo(get_XS(xsecfilename,"gluino",limits[0]),limits[0]);
831 vector<TH2F*> bestexplimits;
832 TH2F *bestlimits = make_best_limits(explimits,obslimits,scantype, exp1mlimits, exp1plimits, exp2mlimits, exp2plimits, bestexplimits);
833 bestlimits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
834
835 for(int ilim=0;ilim<limits.size();ilim++) {
836 limits[ilim]->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
837 }
838
839 if(scantype!=PlottingSetup::mSUGRA) {
840 for(int ilim=0;ilim<obslimits.size();ilim++) make_SMS_exclusion(obslimits[ilim],xsec,scantype);
841 make_SMS_exclusion(bestlimits,xsec,scantype);
842 } else {
843 for(int ilim=0;ilim<obslimits.size();ilim++) {
844 draw_mSUGRA_exclusion(crosssections[0], obslimits[ilim], explimits[ilim], exp1mlimits[ilim], exp1plimits[ilim], exp2mlimits[ilim], exp2plimits[ilim]);
845 }
846 draw_mSUGRA_exclusion(crosssections[0], bestlimits, bestexplimits[0], bestexplimits[1], bestexplimits[2], bestexplimits[3], bestexplimits[4]);
847 }
848 delete bestlimits;
849 }
850
851 void decorate_mSUGRA(TH2F *cleanhisto, TVirtualPad *cvsSys,TGraph *expected,TGraph *expected2,TGraph *observed) {
852 cvsSys->SetRightMargin(standardmargin);
853 Int_t tanBeta_ = 10;
854 Bool_t plotLO_ = false;
855
856 //convert tanb value to string
857 std::stringstream tmp;
858 tmp << tanBeta_;
859 TString tanb( tmp.str() );
860
861 //set old exclusion Limits
862 TGraph* LEP_ch = set_lep_ch(tanBeta_);
863 TGraph* LEP_sl = set_lep_sl(tanBeta_);//slepton curve
864 TGraph* TEV_sg_cdf = set_tev_sg_cdf(tanBeta_);//squark gluino cdf
865 TGraph* TEV_sg_d0 = set_tev_sg_d0(tanBeta_);//squark gluino d0
866 TGraph* stau = set_tev_stau(tanBeta_);//stau
867 TGraph* NoEWSB = set_NoEWSB(tanBeta_);
868
869 TGraph* TEV_sn_d0_1 = set_sneutrino_d0_1(tanBeta_);
870 TGraph* TEV_sn_d0_2 = set_sneutrino_d0_2(tanBeta_);
871
872 //constant ssqquark and gluino lines
873 TF1* lnsq[10];
874 TF1* lngl[10];
875
876 TLatex* sq_text[10];
877 TLatex* gl_text[10];
878
879 for(int i = 0; i < 6; i++){
880 lnsq[i] = constant_squark(tanBeta_,i);
881 sq_text[i] = constant_squark_text(i,*lnsq[i],tanBeta_);
882 lngl[i] = constant_gluino(tanBeta_,i);
883 gl_text[i] = constant_gluino_text(i,*lngl[i]);
884 }
885
886 //Legends
887 TLegend* legst = makeStauLegend(0.05,tanBeta_);
888 TLegend* legNoEWSB = makeNoEWSBLegend(0.05,tanBeta_);
889 TLegend* legexp = makeExpLegend( *TEV_sg_cdf,*TEV_sg_d0,*LEP_ch,*LEP_sl,*TEV_sn_d0_1,0.035,tanBeta_);
890
891 TEV_sn_d0_1->SetLineWidth(1);
892 TEV_sn_d0_2->SetLineWidth(1);
893 TEV_sg_d0->SetLineWidth(1);
894
895 double m0min = 0;
896 if (tanBeta_ == 50) m0min=200;
897 TH2F* hist = new TH2F("h","h",100,m0min,1000,100,120,700);
898 hist->Draw();
899 hist->GetXaxis()->SetTitle("m_{0} [GeV]");
900 hist->GetXaxis()->CenterTitle();
901 hist->GetYaxis()->SetTitle("m_{1/2} [GeV]");
902 hist->GetYaxis()->CenterTitle();
903 hist->GetXaxis()->SetTitleSize(0.04);
904 hist->GetYaxis()->SetTitleSize(0.04);
905 hist->GetXaxis()->SetTitleOffset(1.2);
906 hist->GetYaxis()->SetTitleOffset(1.5);
907 hist->GetXaxis()->SetNdivisions(506);
908 hist->GetYaxis()->SetNdivisions(506);
909
910 int col[]={2,3,4};
911
912 TLegend* myleg;
913
914 if( plotLO_ ) myleg = new TLegend(0.3,0.65,0.65,0.8,NULL,"brNDC");
915 else myleg = new TLegend(0.25,0.76,0.44,0.91,NULL,"brNDC");
916
917 myleg->SetFillColor(0);
918 myleg->SetShadowColor(0);
919 myleg->SetTextSize(0.04);
920 myleg->SetBorderSize(0);
921
922 //constant squark and gluino mass contours
923 for (int it=0;it<5;it++) {
924 lngl[it]->Draw("same");
925 lnsq[it]->Draw("same");
926 sq_text[it]->Draw();
927 gl_text[it]->Draw();
928 }
929
930 //exclusion limits previous experiments
931 if(tanBeta_ == 3){
932 TEV_sn_d0_1->Draw("fsame");
933 TEV_sn_d0_2->Draw("fsame");
934 }
935 LEP_ch->Draw("fsame");
936 if (tanBeta_ != 50) LEP_sl->Draw("fsame");
937
938 //remove CDF/D0 excluded regions
939 TEV_sg_cdf->Draw("fsame");
940 TEV_sg_d0->Draw("same");
941 TEV_sg_d0->Draw("fsame");
942
943 //other labels
944 Double_t xpos = 0;
945 Double_t xposi = 0;
946 Double_t ypos = 0;
947 if(tanBeta_ == 50) xposi = 100;
948 if(tanBeta_ == 50) xpos = 200;
949 if(tanBeta_ == 50) ypos = -10;
950
951 TString text_tanBeta;
952 text_tanBeta = "tan#beta = "+tanb+", A_{0} = 0, #mu > 0";
953 TLatex* cmssmpars = new TLatex(/*530.+xpos,690.+ypos-130*/150,650,text_tanBeta);
954
955 cmssmpars->SetTextSize(0.03);
956 cmssmpars->Draw("same");
957
958 TLatex* lep_chargino = new TLatex(250,135,"LEP2 #tilde{#chi}_{1}^{#pm}");
959 lep_chargino->SetTextSize(0.03);
960 lep_chargino->SetTextFont(42);
961
962 TLatex* lep_slepton = new TLatex(26,190,"LEP2 #tilde{#font[12]{l}}^{#pm}");
963 lep_slepton->SetTextSize(0.03);
964 lep_slepton->SetTextAngle(-83);
965 lep_slepton->SetTextFont(42);
966
967 if(draw2sigma) expected2->Draw("f");
968 expected->SetLineColor(expected->GetFillColor());
969 expected2->SetLineColor(expected2->GetFillColor());
970 expected->Draw("f");
971 observed->Draw("c");
972
973 stau->Draw("fsame");
974 NoEWSB->Draw("fsame");
975
976 legexp->AddEntry(observed,"Observed limit","l");
977 legexp->AddEntry(expected,"Expected 1#sigma limit","f");
978 if(draw2sigma) legexp->AddEntry(expected2,"Expected 2#sigma limit","f");
979 legexp->SetY1(0.60);
980 legexp->SetX1(0.55);
981 legexp->Draw();
982 legst->Draw();
983
984 hist->Draw("sameaxis");
985 cvsSys->RedrawAxis();
986 cvsSys->Update();
987 DrawPrelim();
988 }
989
990 void smooth_line_once(TGraph *gr) {
991 //going to smooth graph
992 //need to take into account the DIRECTION we're heading so we noticed for expected shape when we turn around and go back
993 float previousX=-100;
994 int sign=1;
995 for(int i=0;i<gr->GetN();i++) {
996 Double_t x,y,x1,y1,x2,y2;
997 bool turning=false;
998 gr->GetPoint(i,x,y);
999 gr->GetPoint(i+1,x1,y1);//need to handle exception here
1000 gr->GetPoint(i-1,x2,y2);//need to handle exception here
1001 if(i!=gr->GetN()-1&& (sign*x<=sign*previousX||sign*x1<=sign*x)) {
1002 //turned around!
1003 sign=(-1)*sign;
1004 // do NOT do any smoothing on this point!
1005 } else {
1006 float newval=y;
1007 if(i>0&&i<(gr->GetN())-1) newval=(1.0/3.0)*(y+y1+y2);
1008 if(i==0) newval=(1.0/2.0)*(y+y1);
1009 if(i==gr->GetN()-1) newval=(1.0/2.0)*(y+y2);
1010 gr->SetPoint(i,x,newval);
1011 }
1012 previousX=x;
1013 }
1014 }
1015
1016 void smooth_line(TGraph *gr) {
1017 smooth_line_once(gr);
1018 smooth_line_once(gr);
1019 smooth_line_once(gr);
1020 }
1021 void set_range(TH2F *histo, int scantype, bool pushoutyz=false) {
1022 if(scantype==PlottingSetup::mSUGRA) {
1023 histo->GetXaxis()->SetRangeUser(0,2000);
1024 histo->GetYaxis()->SetRangeUser(0,800);
1025 histo->GetXaxis()->SetTitle("m_{0} [GeV]");
1026 histo->GetYaxis()->SetTitle("m_{1/2} [GeV]");
1027 histo->GetXaxis()->SetRangeUser(0,2000);
1028 histo->GetXaxis()->SetNdivisions(504,true);
1029 }
1030 if(scantype==PlottingSetup::SMS) {
1031 histo->GetXaxis()->SetRangeUser(50,1200);
1032 histo->GetYaxis()->SetRangeUser(50,1200);
1033 histo->GetXaxis()->SetTitle("m_{#tilde{g}} [GeV]");
1034 histo->GetYaxis()->SetTitle("m_{LSP} [GeV]");
1035 histo->GetXaxis()->SetTitleSize(0.04);
1036 histo->GetYaxis()->SetTitleSize(0.04);
1037 histo->GetZaxis()->SetTitleSize(0.04);
1038 histo->GetXaxis()->SetTitleOffset(1.2);
1039 histo->GetYaxis()->SetTitleOffset(1.5);
1040 if(pushoutyz) histo->GetZaxis()->SetTitleOffset(1.6);
1041 }
1042 if(scantype==PlottingSetup::GMSB) {
1043 histo->GetXaxis()->SetRangeUser(100,1200);
1044 histo->GetYaxis()->SetRangeUser(100,1200);
1045 histo->GetXaxis()->SetTitle("m_{#tilde{g}} [GeV]");
1046 histo->GetYaxis()->SetTitle("m_{#chi} [GeV]");
1047 histo->GetXaxis()->SetTitleSize(0.04);
1048 histo->GetYaxis()->SetTitleSize(0.04);
1049 histo->GetZaxis()->SetTitleSize(0.04);
1050 histo->GetXaxis()->SetTitleOffset(1.2);
1051 histo->GetYaxis()->SetTitleOffset(1.5);
1052 if(pushoutyz) histo->GetZaxis()->SetTitleOffset(1.6);
1053 }
1054
1055 histo->GetXaxis()->CenterTitle();
1056 histo->GetYaxis()->CenterTitle();
1057 histo->SetStats(0);
1058 }
1059
1060 TH2F* adjust_histo(TH2F *oldhist, TH2F *refhisto) {
1061 TH2F *histo = new TH2F(refhisto->GetName(),refhisto->GetName(),
1062 refhisto->GetNbinsX(),refhisto->GetXaxis()->GetBinLowEdge(1),refhisto->GetXaxis()->GetBinLowEdge(refhisto->GetNbinsX())+refhisto->GetXaxis()->GetBinWidth(refhisto->GetNbinsX()),
1063 refhisto->GetNbinsY(),refhisto->GetYaxis()->GetBinLowEdge(1),refhisto->GetYaxis()->GetBinLowEdge(refhisto->GetNbinsY())+refhisto->GetYaxis()->GetBinWidth(refhisto->GetNbinsY()));
1064
1065 for(int ix=1;ix<=refhisto->GetNbinsX();ix++) {
1066 for(int iy=1;iy<=refhisto->GetNbinsX();iy++) {
1067 int binnum=refhisto->FindBin(refhisto->GetXaxis()->GetBinCenter(ix),refhisto->GetYaxis()->GetBinCenter(iy));
1068 histo->SetBinContent(binnum,oldhist->GetBinContent(ix,iy));
1069 }
1070 }
1071 return histo;
1072 }
1073
1074 void process_syst_plot(TH2F *rhisto,string saveto,int scantype) {
1075 TH2F *histo = prep_histo(rhisto,scantype); // this is to be independent of the style used at creation time
1076 float rightmargin=gStyle->GetPadRightMargin();
1077 gStyle->SetPadRightMargin(0.20);
1078 TString name = rhisto->GetName();
1079 if(name.Contains("Nevents")) gStyle->SetPadRightMargin(0.22);
1080 TCanvas *can = new TCanvas("syst_plot","Systematics Plot");
1081 set_range(histo,scantype,true);
1082
1083
1084 if(name.Contains("efficiency")) {
1085 histo->GetZaxis()->SetTitle("A #times #varepsilon (#geq 1 Z(ll))");
1086 //histo->GetZaxis()->SetRangeUser(0.0,0.3);
1087 }
1088 if(name.Contains("Nevents")) {
1089 histo->GetZaxis()->SetTitle("N(events)");
1090 histo->GetZaxis()->SetTitleOffset(histo->GetZaxis()->GetTitleOffset()+0.4);
1091 }
1092 if(name.Contains("sysjes")) {
1093 histo->GetZaxis()->SetTitle("Jet Energy Scale");
1094 histo->GetZaxis()->SetRangeUser(0.0,0.2);
1095 }
1096 if(name.Contains("sysjsu")) {
1097 histo->GetZaxis()->SetTitle("JZB Scale Uncertainty");
1098 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1099 }
1100 if(name.Contains("sysresmap")) {
1101 histo->GetZaxis()->SetTitle("Resulution");
1102 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1103 }
1104 if(name.Contains("sysstatmap")) {
1105 histo->GetZaxis()->SetTitle("Statistical Error");
1106 histo->GetZaxis()->SetRangeUser(0.0,0.01);
1107 }
1108 if(name.Contains("systotmap")) {
1109 histo->GetZaxis()->SetTitle("All Systematic Errors");
1110 histo->GetZaxis()->SetRangeUser(0.0,0.5);
1111 }
1112
1113 histo->GetZaxis()->CenterTitle();
1114 gStyle->SetStripDecimals(false);
1115 histo->GetXaxis()->SetDecimals(true);
1116
1117 histo->Draw("COLZ");
1118 DrawPrelim();
1119
1120 CompleteSave(can,(saveto+(string)histo->GetName()));
1121
1122 gStyle->SetPadRightMargin(rightmargin);
1123
1124 delete can;
1125 }
1126
1127 void make_all_syst_plots(vector<TH2F*> all_histos,int scantype) {
1128 string saveto="Systematics/";
1129 for(int iplot=0;iplot<all_histos.size();iplot++) {
1130 process_syst_plot(all_histos[iplot],saveto,scantype);
1131 }
1132 }
1133
1134 void process_file(TFile* file, float stdmargin) {
1135 standardmargin=stdmargin;
1136 xsecfilename="reference_xSec_SMS.root";
1137
1138 // can receive a file with systematics and limits mixed, or a file with systematics only , or a file with limits only.
1139 TIter nextkey(file->GetListOfKeys());
1140 TKey *key;
1141
1142 int scantype=PlottingSetup::SMS;
1143
1144 vector<TH2F*> systematics_histos;
1145 vector<TH2F*> limits_histos;
1146 while ((key = (TKey*)nextkey()))
1147 {
1148 TObject *obj = key->ReadObj();
1149 if (!(obj->IsA()->InheritsFrom("TH2"))) continue;
1150 TString name=(TString)(obj->GetName());
1151 bool is_limit=false;
1152 bool is_systematic=false;
1153
1154 if(name.Contains("limitmap")) is_limit=true;
1155 if(name.Contains("explimitmap")) is_limit=true;
1156 if(name.Contains("exp1plimitmap")) is_limit=true;
1157 if(name.Contains("exp2plimitmap")) is_limit=true;
1158 if(name.Contains("exp1mlimitmap")) is_limit=true;
1159 if(name.Contains("exp2mlimitmap")) is_limit=true;
1160 if(name.Contains("exclusionmap")) is_limit=true;
1161 if(name.Contains("crosssectionmap")) is_limit=true;
1162 if(name.Contains("absolutecrosssectionmap")) is_limit=true;
1163 if(name.Contains("limitflipmap")) is_limit=true;
1164
1165 if(name.Contains("sysjes")) is_systematic=true;
1166 if(name.Contains("sysjsu")) is_systematic=true;
1167 if(name.Contains("sysresmap")) is_systematic=true;
1168 if(name.Contains("efficiencymap")) is_systematic=true;
1169 if(name.Contains("efficiencymapAcc")) is_systematic=true;
1170 if(name.Contains("efficiencymapID")) is_systematic=true;
1171 if(name.Contains("efficiencymapJets")) is_systematic=true;
1172 if(name.Contains("efficiencymapSignal")) is_systematic=true;
1173 if(name.Contains("noscefficiencymap")) is_systematic=true;
1174 if(name.Contains("Neventsmap")) is_systematic=true;
1175 if(name.Contains("ipointmap")) is_systematic=true;
1176 if(name.Contains("syspdfmap")) is_systematic=true;
1177 if(name.Contains("systotmap")) is_systematic=true;
1178 if(name.Contains("sysstatmap")) is_systematic=true;
1179 if(name.Contains("timemap")) is_systematic=true;
1180 if(name.Contains("flipmap")) is_systematic=true;
1181
1182 if(is_limit) limits_histos.push_back((TH2F*) obj);
1183 else if(is_systematic) systematics_histos.push_back((TH2F*) obj);
1184 if(name.Contains("mSUGRA")) scantype=PlottingSetup::mSUGRA;
1185 if(name.Contains("GMSB")) scantype=PlottingSetup::GMSB;
1186 }
1187 if(systematics_histos.size()>0) make_all_syst_plots(systematics_histos,scantype);
1188 if(limits_histos.size()>0) create_exclusion_plots(limits_histos,scantype);
1189 }
1190