ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ExclusionPlot.C
Revision: 1.4
Committed: Fri Mar 23 10:51:56 2012 UTC (13 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.3: +10 -1 lines
Log Message:
Added new features from ice cream (previous version) to jelly fish (this version)

File Contents

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