ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.24
Committed: Fri Mar 23 09:51:45 2012 UTC (13 years, 1 month ago) by fronga
Content type: text/plain
Branch: MAIN
Changes since 1.23: +0 -1 lines
Log Message:
Do not write the numbers in the "source of best limits" plot.

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