ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.20
Committed: Tue Feb 7 17:04:55 2012 UTC (13 years, 3 months ago) by fronga
Content type: text/plain
Branch: MAIN
Changes since 1.19: +5 -4 lines
Log Message:
Maria's comments.

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