ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.13
Committed: Mon Dec 5 14:26:51 2011 UTC (13 years, 5 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.12: +216 -39 lines
Log Message:
Adapted the way the exclusion line is computed

File Contents

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