ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/ExclusionPlot.C
Revision: 1.14
Committed: Mon Dec 5 15:39:51 2011 UTC (13 years, 5 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.13: +15 -0 lines
Log Message:
Providing option to use alternative exclusion line finder

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