ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.19
Committed: Wed Jan 18 14:03:15 2012 UTC (13 years, 3 months ago) by fronga
Content type: text/plain
Branch: MAIN
CVS Tags: cbaf_4p7ifb
Changes since 1.18: +115 -57 lines
Log Message:
Several cosmetic changes.

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