ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ExclusionPlot.C
Revision: 1.1
Committed: Mon Jan 30 14:46:25 2012 UTC (13 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Log Message:
Initial commit of Ice Cream versions

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