ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.21
Committed: Thu Feb 9 15:42:40 2012 UTC (13 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.20: +25 -2 lines
Log Message:
Added a special canvas with additional information so one can compare the computed limit directly

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