ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ExclusionPlot.C
Revision: 1.9
Committed: Mon Apr 30 08:39:44 2012 UTC (13 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.8: +15 -25 lines
Log Message:
fixed some uint vs int comparisons; commented out/removed unused variables; made Wall happy

File Contents

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