ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ExclusionPlot.C
Revision: 1.6
Committed: Wed Apr 18 09:21:36 2012 UTC (13 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.5: +1 -1 lines
Log Message:
Loading central XS file

File Contents

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