ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ExclusionPlot.C
Revision: 1.10
Committed: Fri May 4 12:05:03 2012 UTC (13 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.9: +24 -6 lines
Log Message:
Adapted exclusion plots to take into account updated limit sources (bins)

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