ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ExclusionPlot.C
Revision: 1.3
Committed: Fri Mar 23 10:49:23 2012 UTC (13 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.2: +12 -12 lines
Log Message:
Ported not writing numbers to the next generation cbaf

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