ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.67
Committed: Thu Sep 15 15:50:34 2011 UTC (13 years, 7 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.66: +7 -5 lines
Log Message:
All plots containing a ratio plot are saved twice, once with and once without the ratio plot (referring to kin. vars)

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <vector>
3     #include <sys/stat.h>
4    
5     #include <TCut.h>
6     #include <TROOT.h>
7     #include <TCanvas.h>
8     #include <TMath.h>
9     #include <TColor.h>
10     #include <TPaveText.h>
11     #include <TRandom.h>
12     #include <TH1.h>
13     #include <TH2.h>
14     #include <TF1.h>
15     #include <TSQLResult.h>
16 buchmann 1.13 #include <TProfile.h>
17 fronga 1.24 #include <TLegendEntry.h>
18 buchmann 1.1
19 buchmann 1.9 //#include "TTbar_stuff.C"
20 buchmann 1.1 using namespace std;
21    
22     using namespace PlottingSetup;
23    
24 buchmann 1.22 void todo() {
25     dout << "My to do list: " << endl;
26 buchmann 1.38 dout << " - ExperimentalModule::Poisson_ratio_plot : Get the second part to work!" << endl;
27 buchmann 1.22 dout << " - update script for limits " << endl;
28     dout << " - get expected and observed limits, get sigma (edit the current table)" << endl;
29 buchmann 1.64 dout << " - Finish up saving to root file (currently deactivated)" << endl;
30     dout << " - Exclusion plots" << endl;
31 buchmann 1.22 }
32    
33 buchmann 1.1 void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, float &MCSigma, float &DataSigma, stringstream &result)
34     {
35 buchmann 1.21 TCanvas *tempcan = new TCanvas("tempcan","Temporary canvas for peak finding preparations");
36 buchmann 1.17 TH1F *rawJZBeemmMC = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc, luminosity);
37     TH1F *rawJZBeemmData = allsamples.Draw("rawJZBeemmData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
38     TH1F *rawJZBemMC = allsamples.Draw("rawJZBemMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc, luminosity);
39     TH1F *rawJZBemData = allsamples.Draw("rawJZBemData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
40 buchmann 1.1 TH1F *rawttbarjzbeemmMC;
41    
42     if(method==doKM) {
43     //we only need this histo for the KM fitting...
44 buchmann 1.17 rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,100, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJet"));
45 buchmann 1.1 MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
46     DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
47     }
48     else {
49     TH1F *reducedMC = (TH1F*)rawJZBeemmMC->Clone();
50     TH1F *reducedData = (TH1F*)rawJZBeemmData->Clone();
51     reducedMC->Add(rawJZBemMC,-1);
52     reducedData->Add(rawJZBemData,-1);
53     //this is Kostas' way of doing it - we subtract em to get rid of some of the ttbar contribution (in reality, of flavor-symmetric contribution)
54     MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
55     DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
56 buchmann 1.11
57 buchmann 1.1 }
58 buchmann 1.11
59 buchmann 1.1
60     // MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
61     // DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
62 buchmann 1.21 dout << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
63 buchmann 1.1 result << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
64 buchmann 1.21 dout << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
65 buchmann 1.1 result << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
66     }
67    
68     void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
69    
70     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
71    
72     TH1F *datahistoOSSF = allsamples.Draw("datahistoOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,data,luminosity);
73     THStack mcstackOSSF = allsamples.DrawStack("mcstackOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,mc,luminosity);
74 fronga 1.24 TH1F *datahistoOSOF = allsamples.Draw("datahistoOSOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&cutnJets&&basiccut,data,luminosity);
75 buchmann 1.1
76     if(logscale) ckin->SetLogy(1);
77 buchmann 1.17 datahistoOSSF->SetMarkerSize(DataMarkerSize);
78 buchmann 1.1 datahistoOSSF->GetXaxis()->SetTitle(xlabel.c_str());
79     datahistoOSSF->GetXaxis()->CenterTitle();
80     datahistoOSSF->GetYaxis()->SetTitle("events");
81     datahistoOSSF->GetYaxis()->CenterTitle();
82 buchmann 1.17 datahistoOSOF->SetMarkerSize(DataMarkerSize);
83     datahistoOSSF->SetMarkerSize(DataMarkerSize);
84 buchmann 1.1 datahistoOSSF->Draw();
85 fronga 1.24
86 buchmann 1.1 mcstackOSSF.Draw("same");
87     datahistoOSSF->Draw("same");
88 fronga 1.24
89 buchmann 1.49 datahistoOSOF->SetMarkerColor(TColor::GetColor("#FE642E"));
90 fronga 1.24 datahistoOSOF->SetLineColor(kRed);
91 buchmann 1.17 datahistoOSOF->SetMarkerStyle(21);
92 buchmann 1.1 datahistoOSOF->Draw("same");
93 fronga 1.24
94     // Try to re-arrange legend...
95     TLegend *bgleg = allsamples.allbglegend("",datahistoOSSF);
96     TLegend *kinleg = make_legend();
97 fronga 1.41 kinleg->AddEntry(datahistoOSSF,"SF (data)","p");
98     kinleg->AddEntry(datahistoOSOF,"OF (data)","p");\
99 fronga 1.24 TIter next(bgleg->GetListOfPrimitives());
100     TObject* obj;
101     // Copy the nice bkgd legend skipping the "data"
102     while ( obj = next() )
103     if ( strcmp(((TLegendEntry*)obj)->GetObject()->GetName(),"datahistoOSSF") )
104     kinleg->GetListOfPrimitives()->Add(obj);
105    
106 buchmann 1.1 kinleg->Draw();
107     CompleteSave(ckin,"kin/mll_ossf_osof_distribution");
108 buchmann 1.18
109     delete datahistoOSOF;
110     delete datahistoOSSF;
111 buchmann 1.34 delete ckin;
112 buchmann 1.1 }
113    
114    
115 fronga 1.35 void draw_ratio_plot(TH1* hdata, THStack& hmc, float ymin=0.5, float ymax=1.5) {
116    
117     // Make a histogram from stack
118     TIter next(hmc.GetHists());
119     TObject* obj;
120     TH1* hratio = NULL;
121     while ( obj = next() ) {
122     if ( !hratio ) {
123     hratio = (TH1*)obj->Clone();
124     hratio->SetName("hratio");
125     } else hratio->Add( (TH1*)obj );
126     }
127     hratio->Divide(hdata);
128     hratio->SetMaximum(ymax);
129     hratio->SetMinimum(ymin);
130     hratio->SetMarkerStyle(2);
131     hratio->SetLineWidth(1);
132    
133     TPad* rpad = new TPad("rpad","",0.15,0.7,0.4,0.9);
134     rpad->Draw();
135     rpad->cd();
136     hratio->Draw("e1x0");
137    
138     TF1* oneline = new TF1("","1.0",0,1000);
139     oneline->SetLineColor(kBlue);
140     oneline->SetLineStyle(1);
141     oneline->SetLineWidth(1);
142     oneline->Draw("same");
143    
144     }
145    
146 fronga 1.25 void make_kin_plot(string variable, int nbins, float min, float max, bool logscale,
147 fronga 1.35 string xlabel, string filename, bool isPF=true, bool plotratio=false ) {
148 buchmann 1.1 // TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
149     TCut ibasiccut=basiccut;
150    
151     if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
152     //Step 1: Adapt the variable (if we're dealing with PF we need to adapt the variable!)
153     if(isPF) {
154     if(variable=="mll") variable="pfmll[0]";
155     if(variable=="jetpt[0]") variable="pfJetGoodPt[0]";
156     if(variable=="jeteta[0]") variable="pfJetGoodEta[0]";
157     if(variable=="pt") variable="pfpt[0]";
158     if(variable=="pt1") variable="pfpt1[0]";
159 buchmann 1.19 if(variable=="pt2") variable="pfpt2[0]";
160 buchmann 1.1 if(variable=="eta1") variable="pfeta1[0]";
161     if(variable=="jzb[1]") variable="pfjzb[0]";
162     //if(variable=="pfJetGoodNum") variable="pfJetGoodNum"; // pointless.
163     }
164    
165     //Step 2: Refine the cut
166     TCut cut;
167     cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
168     if(filename=="nJets") cut=cutmass&&cutOSSF&&ibasiccut;
169     if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
170     if(filename=="mll") cut=cutOSSF&&cutnJets&&ibasiccut;
171 buchmann 1.18 if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
172 buchmann 1.63 if(filename=="mll_osof") cut=cutOSOF&&cutnJets&&ibasiccut;
173 buchmann 1.18 if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
174 buchmann 1.17 if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
175 buchmann 1.18 if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
176     if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
177 buchmann 1.59 if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
178     if(filename=="pfJetGoodPt_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
179 buchmann 1.1
180 fronga 1.25 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
181     ckin->SetLogy(logscale);
182 buchmann 1.1 TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
183 buchmann 1.17 datahisto->SetMarkerSize(DataMarkerSize);
184 buchmann 1.1 THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
185     if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
186     if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
187     if(filename=="mll_inclusive") datahisto->SetMinimum(1);
188 buchmann 1.67 if(filename=="mll_osof") datahisto->SetMaximum(10*datahisto->GetMaximum());
189     if(filename=="mll_osof") datahisto->SetMinimum(9);
190 buchmann 1.1 datahisto->Draw("e1");
191     mcstack.Draw("same");
192     datahisto->Draw("same,e1");
193     TLegend *kinleg = allsamples.allbglegend();
194     kinleg->Draw();
195 buchmann 1.16 TText* write_cut = write_cut_on_canvas(decipher_cut(cut,basicqualitycut));
196 buchmann 1.1 write_cut->Draw();
197     TText* write_variable = write_text(0.99,0.01,variable);
198     write_variable->SetTextAlign(31);
199     write_variable->SetTextSize(0.02);
200 fronga 1.35
201 buchmann 1.1 if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
202     else CompleteSave(ckin,"kin/"+filename);
203 buchmann 1.67 if ( plotratio ) {
204     draw_ratio_plot( datahisto, mcstack );
205     if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF_withratio");
206     else CompleteSave(ckin,"kin/"+filename+"_withratio");
207     }
208 buchmann 1.1 datahisto->Delete();
209 buchmann 1.47 delete ckin;
210 buchmann 1.1 }
211    
212     void do_kinematic_plots(bool doPF=false)
213     {
214     bool dolog=true;
215     bool nolog=false;
216 buchmann 1.65 make_kin_plot("mll",21,55,160,dolog,"m_{ll} [GeV]","mll",doPF,true);
217     make_kin_plot("mll",21,55,160,dolog,"m_{ll} [GeV]","mll_ee",doPF);
218     make_kin_plot("mll",21,55,160,dolog,"m_{ll} [GeV]","mll_mm",doPF);
219     make_kin_plot("mll",21,55,160,dolog,"m_{ll} [GeV]","mll_osof",doPF);
220     make_kin_plot("mll",105,55,160,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
221     make_kin_plot("mll",105,55,160,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
222     make_kin_plot("mll",105,55,160,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
223     make_kin_plot("mll",305,55,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
224 fronga 1.25 make_kin_plot("jetpt[0]",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
225     make_kin_plot("jeteta[0]",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
226     make_kin_plot("pt",50,0,200,dolog,"Z p_{T} [GeV]","Zpt",doPF);
227     make_kin_plot("pt1",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
228     make_kin_plot("pt2",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
229     make_kin_plot("eta1",40,-5,5,nolog,"#eta_{l}","eta",doPF);
230     make_kin_plot("jzb[1]",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
231     make_kin_plot("pfJetGoodNum",8,0.5,8.5,dolog,"nJets","nJets",doPF);
232     make_kin_plot("pfJetGoodNum",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
233 buchmann 1.65 make_special_mll_plot(21,55,160,dolog,"m_{ll} [GeV]");
234 buchmann 1.1 }
235    
236 fronga 1.25 void make_comp_plot( string var, string xlabel, string filename, string mcjzb, string datajzb,
237     int nbins, float xmin, float xmax, bool log,
238 fronga 1.26 float ymin=0, float ymax=0, bool leftJustified=false ) {
239 buchmann 1.60 TCut weightbackup=cutWeight;//backing up the correct weight (restoring below!)
240     if(weightbackup==TCut("1.0")||weightbackup==TCut("1")) write_warning(__FUNCTION__,"WATCH OUT THE WEIGHT HAS POSSIBLY NOT BEEN RESET!!!! PLEASE CHANGE LINE "+any2string(__LINE__));
241     if(var=="numVtx") cutWeight=TCut("1.0");
242 fronga 1.25 TCut jzbData[]= { TCut(TString(datajzb+">100")),TCut(TString(datajzb+"<-100")) };
243     TCut jzbMC[] = { TCut(TString(mcjzb+">100")),TCut(TString(mcjzb+"<-100")) };
244    
245 buchmann 1.64 if(!RestrictToMassPeak) write_warning(__FUNCTION__,"Watch out, once we go offpeak this function needs rewriting!");//need to redefine the regions: only SF and OF remain
246 fronga 1.25 string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
247     TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass, cutOSOF&&cutnJets&&cutmass,
248     cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
249    
250     for ( int iregion=0; iregion<4; ++iregion )
251     for ( int ijzb=0; ijzb<2; ++ijzb ) {
252     TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
253     ccomp->SetLogy(log);
254     TH1F *datahisto = allsamples.Draw("datahisto", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
255 buchmann 1.56 TH1F *lm4histo = signalsamples.Draw("lm4histo", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity,signalsamples.FindSample("LM4"));
256 fronga 1.25 THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb], mc, luminosity);
257     datahisto->SetMarkerSize(DataMarkerSize);
258     if (ymax>ymin) datahisto->SetMaximum(ymax);
259 buchmann 1.56 lm4histo->SetLineStyle(2);
260 fronga 1.25 datahisto->Draw("e1");
261     mcstack.Draw("same");
262     datahisto->Draw("same,e1");
263 buchmann 1.57 // lm4histo->Draw("hist,same");
264 fronga 1.25 TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
265 fronga 1.26 if ( leftJustified ) {
266     Float_t w = kinleg->GetX2()-kinleg->GetX1();
267     kinleg->SetX1(0.2);
268     kinleg->SetX2(0.2+w);
269     }
270 buchmann 1.57 // kinleg->AddEntry(lm4histo,"LM4","l");
271 fronga 1.25 kinleg->Draw();
272     TText* write_variable = write_text(0.99,0.01,var);
273     write_variable->SetTextAlign(31);
274     write_variable->SetTextSize(0.02);
275     ccomp->RedrawAxis();
276 buchmann 1.52 CompleteSave(ccomp,"compare/"+filename+"/"+filename+sRegions[iregion]+(ijzb?"neg":"pos"));
277 buchmann 1.27 delete datahisto;
278 buchmann 1.34 delete ccomp;
279 buchmann 1.56 delete lm4histo;
280 fronga 1.25 }
281 buchmann 1.60 cutWeight=weightbackup;
282 fronga 1.25 }
283    
284    
285     void region_comparison_plots(string mcjzb, string datajzb) {
286     dout << "Creating comparison plots for signal and control regions" << endl;
287     // Compare a few quantities in the signal region and all 7 control regions
288 buchmann 1.55
289     switch_overunderflow(true); // switching overflow/underflow bins on
290    
291 buchmann 1.52 make_comp_plot("mll","m_{ll} [GeV]","mll",mcjzb,datajzb,30,50,170,false,0,16.);
292     make_comp_plot("met[4]","pfMET [GeV]","pfmet",mcjzb,datajzb,18,0,360,false,0,16.);
293     make_comp_plot("pfJetGoodNum","#(jets)","njets",mcjzb,datajzb,10,0,10, false,0,35.);
294     make_comp_plot("pt","Z p_{T} [GeV]","Zpt",mcjzb,datajzb,26,0,525,false,0.,21.);
295 buchmann 1.60 make_comp_plot("numVtx","#(prim. vertices)","nvtx",mcjzb,datajzb,20,0.,20.,false,0,16.);
296 buchmann 1.52 make_comp_plot("TMath::Abs(dphi)","#Delta#phi(leptons)","dphilep",mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
297     make_comp_plot("TMath::Abs(dphi_sumJetVSZ[1])","#Delta#phi(Z,jets)","dphiZjets",mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
298 fronga 1.25
299 buchmann 1.55 switch_overunderflow(false); // switching overflow/underflow bins off
300 fronga 1.25 }
301    
302 buchmann 1.1 void do_kinematic_PF_plots()
303     {
304     do_kinematic_plots(true);
305     }
306    
307 buchmann 1.11 void signal_bg_comparison()
308 buchmann 1.1 {
309 buchmann 1.11 TCanvas *can = new TCanvas("can","Signal Background Comparison Canvas");
310 fronga 1.45 can->SetLogy(1);
311    
312     int sbg_nbins=130;
313     float sbg_min=-500; //-110;
314     float sbg_max=800; //jzbHigh;
315 buchmann 1.44
316 buchmann 1.58 float simulatedlumi=luminosity;//in pb please - adjust to your likings
317 buchmann 1.44
318     TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
319     TH1F *JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM4"));
320     TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
321 buchmann 1.1
322     JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
323     JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
324     JZBplotZJETs->SetLineColor(kBlack);
325     JZBplotLM4->SetLineStyle(2);
326 fronga 1.45 JZBplotZJETs->SetMaximum(JZBplotZJETs->GetMaximum()*5);
327     JZBplotZJETs->SetMinimum(1);
328    
329     JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
330     JZBplotTtbar->SetMinimum(0.01);
331     JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
332     JZBplotTtbar->DrawClone("histo");
333     JZBplotZJETs->Draw("histo,same");
334     JZBplotTtbar->SetFillColor(0);
335     JZBplotTtbar->DrawClone("histo,same");
336     JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
337 buchmann 1.44 JZBplotLM4->Draw("histo,same");
338 fronga 1.45
339    
340     TLegend *signal_bg_comparison_leg2 = make_legend("",0.55,0.75,false);
341 buchmann 1.1 signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
342     signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
343     signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
344     signal_bg_comparison_leg2->Draw();
345 fronga 1.53 DrawMCPrelim(simulatedlumi);
346 buchmann 1.39 CompleteSave(can,"jzb_bg_vs_signal_distribution");
347 buchmann 1.31
348 fronga 1.45 // Define illustrative set of SMS points
349     TCut kSMS1("MassGlu==250&&MassLSP==75");
350     TCut kSMS2("MassGlu==800&&MassLSP==200");
351     TCut kSMS3("MassGlu==1050&&MassLSP==850");
352     TCut kSMS4("MassGlu==1200&&MassLSP==100");
353 buchmann 1.47 TH1F *JZBplotSMS1 = scansample.Draw("JZBplotSMS1",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS1,mc,simulatedlumi,scansample.FindSample("t"));
354 fronga 1.45 JZBplotSMS1->Scale(JZBplotLM4->Integral()/JZBplotSMS1->Integral());
355 buchmann 1.47
356     TH1F *JZBplotSMS2 = scansample.Draw("JZBplotSMS2",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS2,mc,simulatedlumi,scansample.FindSample("t"));
357 buchmann 1.31 JZBplotSMS2->Scale(JZBplotLM4->Integral()/JZBplotSMS2->Integral());
358 buchmann 1.47
359     TH1F *JZBplotSMS3 = scansample.Draw("JZBplotSMS3",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS3,mc,simulatedlumi,scansample.FindSample("t"));
360 buchmann 1.31 JZBplotSMS3->Scale(JZBplotLM4->Integral()/JZBplotSMS3->Integral());
361    
362 buchmann 1.47 TH1F *JZBplotSMS4 = scansample.Draw("JZBplotSMS4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS4,mc,simulatedlumi,scansample.FindSample("t"));
363 buchmann 1.31 JZBplotSMS4->Scale(JZBplotLM4->Integral()/JZBplotSMS4->Integral());
364 fronga 1.45
365     // Draw all plots overlaid
366     JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
367     JZBplotTtbar->SetMinimum(0.01);
368     JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
369     JZBplotTtbar->DrawClone("histo");
370     JZBplotZJETs->Draw("histo,same");
371     JZBplotTtbar->SetFillColor(0);
372     JZBplotTtbar->DrawClone("histo,same");
373     JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
374    
375     JZBplotSMS1->SetLineColor(kRed+1);
376     JZBplotSMS2->SetLineColor(kBlue+1);
377     JZBplotSMS3->SetLineColor(kRed+1);
378     JZBplotSMS4->SetLineColor(kBlue+1);
379 buchmann 1.31 JZBplotSMS3->SetLineStyle(2);
380     JZBplotSMS4->SetLineStyle(2);
381    
382     JZBplotSMS1->Draw("histo,same");
383     JZBplotSMS2->Draw("histo,same");
384     JZBplotSMS3->Draw("histo,same");
385     JZBplotSMS4->Draw("histo,same");
386 buchmann 1.50 JZBplotLM4->SetLineColor(kGreen);JZBplotLM4->Draw("histo,same");
387 fronga 1.45 TLegend *signal_bg_comparison_leg6 = make_legend("",0.55,0.55,false);
388 buchmann 1.31 signal_bg_comparison_leg6->AddEntry(JZBplotZJETs,"Z+Jets","f");
389     signal_bg_comparison_leg6->AddEntry(JZBplotTtbar,"t#bar{t}","f");
390     signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"","");
391 fronga 1.45 signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"SMS parameters","");
392     signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"(250,75) [GeV]","f");
393     signal_bg_comparison_leg6->AddEntry(JZBplotSMS2,"(800,200) [GeV]","f");
394     signal_bg_comparison_leg6->AddEntry(JZBplotSMS3,"(1050,850) [GeV]","f");
395     signal_bg_comparison_leg6->AddEntry(JZBplotSMS4,"(1200,100) [GeV]","f");
396 buchmann 1.49 signal_bg_comparison_leg6->AddEntry(JZBplotLM4,"LM4","f");
397 buchmann 1.31 signal_bg_comparison_leg6->Draw();
398 buchmann 1.47 DrawMCPrelim(simulatedlumi);
399 buchmann 1.31 CompleteSave(can,"jzb_bg_vs_signal_distribution_SMS__summary");
400 buchmann 1.1 }
401    
402 buchmann 1.9 vector<TF1*> do_cb_fit_to_plot(TH1F *histo, float Sigma, float doingfitacrosstheboard=false) {
403     TF1 *BpredFunc = new TF1("BpredFunc",InvCrystalBall,0,1000,5);
404 buchmann 1.1 BpredFunc->SetParameter(0,histo->GetBinContent(1));
405 buchmann 1.6 if(doingfitacrosstheboard) BpredFunc->SetParameter(0,histo->GetMaximum());
406 buchmann 1.1 BpredFunc->SetParameter(1,0.);
407     if(method==1) BpredFunc->SetParameter(2,10*Sigma);//KM
408     else BpredFunc->SetParameter(2,Sigma);//Gaussian based methods
409     if(method==-99) BpredFunc->SetParameter(2,2.0*Sigma);//Kostas
410     BpredFunc->SetParameter(3,1.8);
411     BpredFunc->SetParameter(4,2.5);
412 buchmann 1.11 histo->Fit(BpredFunc,"QN0");
413 buchmann 1.1 BpredFunc->SetLineColor(kBlue);
414    
415 buchmann 1.9 TF1 *BpredFuncP = new TF1("BpredFuncP",InvCrystalBallP,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
416     TF1 *BpredFuncN = new TF1("BpredFuncN",InvCrystalBallN,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
417 buchmann 1.1
418     BpredFuncP->SetParameters(BpredFunc->GetParameters());
419     BpredFuncP->SetLineColor(kBlue);
420     BpredFuncP->SetLineStyle(2);
421    
422     BpredFuncN->SetParameters(BpredFunc->GetParameters());
423     BpredFuncN->SetLineColor(kBlue);
424     BpredFuncN->SetLineStyle(2);
425 buchmann 1.9
426     vector<TF1*> functions;
427     functions.push_back(BpredFuncN);
428     functions.push_back(BpredFunc);
429     functions.push_back(BpredFuncP);
430     return functions;
431 buchmann 1.1 }
432 buchmann 1.38
433    
434     TF1* do_logpar_fit_to_plot(TH1F *osof) {
435     TCanvas *logpar_fit_can = new TCanvas("logpar_fit_can","Fit canvas for LogPar");
436 buchmann 1.39 TF1 *logparfunc = new TF1("logparfunc",LogParabola,0,300,3);
437 buchmann 1.38 TF1 *logparfunc2 = new TF1("logparfunc2",LogParabola,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
438     TF1 *logparfuncN = new TF1("logparfuncN",LogParabolaN,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
439     TF1 *logparfuncP = new TF1("logparfuncP",LogParabolaP,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
440     osof->SetMinimum(0);
441     osof->Fit(logparfunc,"QR");
442     osof->Draw();
443     logparfunc->SetLineWidth(2);
444     logparfunc2->SetParameters(logparfunc->GetParameters());
445     logparfuncN->SetParameters(logparfunc->GetParameters());
446     logparfuncP->SetParameters(logparfunc->GetParameters());
447     stringstream fitinfo;
448     fitinfo << "#Chi^{2} / NDF : " << logparfunc->GetChisquare() << " / " << logparfunc->GetNDF();
449     TText *writefitinfo = write_text(0.8,0.8,fitinfo.str());
450     writefitinfo->SetTextSize(0.03);
451     DrawPrelim();
452     writefitinfo->Draw();
453     logparfunc->Draw("same");
454     logparfunc2->Draw("same");
455     logparfuncN->SetLineStyle(2);
456     logparfuncP->SetLineStyle(2);
457     logparfuncN->Draw("same");
458     logparfuncP->Draw("same");
459 buchmann 1.39 CompleteSave(logpar_fit_can,"Bpred_Data_LogPar_Fit_To_TTbarPred");
460 buchmann 1.38 delete logpar_fit_can;
461     return logparfunc2;
462     }
463    
464 buchmann 1.42 vector<TF1*> do_extended_fit_to_plot(TH1F *prediction, TH1F *Tprediction, TH1F *ossf, TH1F *osof,int isdata) {
465 buchmann 1.38 /* there are mainly two background contributions: Z+Jets (a) and ttbar (b). So:
466     a) The case is clear - we take the OSSF prediction - OSOF prediction, and fit a crystal ball function to it. We then extract the CB parameters.
467     b) For ttbar, we use the OSOF distribution and look at the [10,100] GeV JZB range, and fit our log parabola. We then extract the LP parameters.
468     Once we have these two components, we use the combined parameters to get the final function and we're done.
469     */
470     //Step 1: take the OSSF prediction - OSOF prediction, and fit a crystal ball function to it
471     TH1F *step1cb = (TH1F*)ossf->Clone("step1cb");
472     step1cb->Add(osof,-1);
473     vector<TF1*> functions = do_cb_fit_to_plot(step1cb,PlottingSetup::JZBPeakWidthData);
474     TF1 *zjetscrystalball = functions[1];
475    
476     //Step 2: use the OSOF distribution and look at the [10,100] GeV JZB range, and fit our log parabola
477 buchmann 1.39 // TH1F *ttbarprediction=(TH1F*)prediction->Clone("ttbarprediction");
478     // ttbarprediction->Add(ossf,-1);//without the Z+Jets estimate, this is really just the ttbar estimate!
479     // the line above is not necessary anymore as we're now looking at a prediction without Z+Jets, and not multiplied with (1.0/3)
480     TF1 *ttbarlogpar = do_logpar_fit_to_plot(Tprediction);
481     ttbarlogpar->SetParameter(0,1.0/3*ttbarlogpar->GetParameter(0));//correcting for the fact that we didn't multiply with (1.0/3);
482    
483 buchmann 1.38 TF1 *ttbarlogparP = new TF1("ttbarlogparP",LogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
484     TF1 *ttbarlogparN = new TF1("ttbarlogparN",LogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
485    
486     //and now fuse the two!
487     TF1 *kmlp = new TF1("kmlp", CrystalBallPlusLogParabola, 0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
488     TF1 *kmlpP= new TF1("kmlpP",CrystalBallPlusLogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
489     TF1 *kmlpN= new TF1("kmlpN",CrystalBallPlusLogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
490     double kmlp_pars[10];
491     for(int i=0;i<5;i++) kmlp_pars[i]=zjetscrystalball->GetParameter(i);
492     for(int i=0;i<3;i++) kmlp_pars[5+i]=ttbarlogpar->GetParameter(i);
493     ttbarlogparP->SetParameters(ttbarlogpar->GetParameters());
494     ttbarlogparN->SetParameters(ttbarlogpar->GetParameters());
495     kmlp->SetParameters(kmlp_pars);
496 buchmann 1.39 prediction->Fit(kmlp,"Q");//fitting the final result (done this in the past but kicked it)
497 buchmann 1.62 /*
498     if you want to start from scratch (without the partial fitting and only fitting the whole thing, some good start values could be :
499     // kmlp_pars[0]=2579.38 // get this from the maximum !!!!
500     kmlp_pars[0]=kmlp->GetParameter(0);
501     kmlp_pars[1]=3.6198;
502     kmlp_pars[2]=16.4664;
503     kmlp_pars[3]=1.92253;
504     kmlp_pars[4]=3.56099;
505     kmlp_pars[5]=5.83;
506     kmlp_pars[6]=0.000757479;
507     kmlp_pars[7]=95.6157;
508     kmlp_pars[8]=0;
509     kmlp_pars[9]=0;
510     kmlp->SetParameters(kmlp_pars);
511     */
512    
513 buchmann 1.39 kmlpP->SetParameters(kmlp->GetParameters());
514     kmlpN->SetParameters(kmlp->GetParameters());
515 buchmann 1.38
516     // now that we're done, let's save all of this so we can have a look at it afterwards.
517     TCanvas *can = new TCanvas("can","Prediction Fit Canvas");
518     can->SetLogy(1);
519     prediction->SetMarkerColor(kRed);
520     prediction->Draw();
521    
522     kmlp->SetLineColor(TColor::GetColor("#04B404"));
523     kmlpP->SetLineColor(TColor::GetColor("#04B404"));
524     kmlpN->SetLineColor(TColor::GetColor("#04B404"));
525     kmlp->Draw("same");
526     kmlpN->SetLineStyle(2);
527     kmlpP->SetLineStyle(2);
528     kmlpN->Draw("same");
529     kmlpP->Draw("same");
530    
531     ttbarlogpar->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
532     ttbarlogpar->Draw("same");
533     ttbarlogparP->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
534     ttbarlogparN->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
535     ttbarlogparP->SetLineStyle(2);
536     ttbarlogparN->SetLineStyle(2);
537     ttbarlogparP->Draw("same");
538     ttbarlogparN->Draw("same");
539    
540     functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
541 buchmann 1.62
542 buchmann 1.38 TLegend *analyticalBpredLEG = make_legend("",0.5,0.55);
543     analyticalBpredLEG->AddEntry(prediction,"predicted","p");
544     analyticalBpredLEG->AddEntry(functions[1],"Crystal Ball fit","l");
545     analyticalBpredLEG->AddEntry(functions[0],"1#sigma Crystal Ball fit","l");
546     analyticalBpredLEG->AddEntry(ttbarlogparN,"TTbar fit","l");
547     analyticalBpredLEG->AddEntry(ttbarlogpar,"1#sigma TTbar fit","l");
548     analyticalBpredLEG->AddEntry(kmlp,"Combined function","l");
549     analyticalBpredLEG->AddEntry(kmlpN,"1#sigma combined function","l");
550     analyticalBpredLEG->Draw("same");
551    
552 buchmann 1.42 if(isdata==0) CompleteSave(can,"MakingOfBpredFunction/Bpred_MC_Analytical_Function_Composition");
553     if(isdata==1) CompleteSave(can,"MakingOfBpredFunction/Bpred_data_Analytical_Function_Composition");
554     if(isdata==2) CompleteSave(can,"MakingOfBpredFunction/Bpred_MCBnS_Analytical_Function_Composition");
555 buchmann 1.38 delete can;
556    
557     //and finally: prep return functions
558     vector<TF1*> return_functions;
559     return_functions.push_back(kmlpN);
560     return_functions.push_back(kmlp);
561     return_functions.push_back(kmlpP);
562    
563     return_functions.push_back(ttbarlogparN);
564     return_functions.push_back(ttbarlogpar);
565     return_functions.push_back(ttbarlogparP);
566    
567     return_functions.push_back(functions[0]);
568     return_functions.push_back(functions[1]);
569     return_functions.push_back(functions[2]);
570    
571     return return_functions;
572     }
573    
574 fronga 1.24 void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, bool is_data, bool overlay_signal = false )
575 buchmann 1.1 {
576     int nbins=100;
577     if(is_data) nbins=50;
578     float low=0;
579     float hi=500;
580    
581 buchmann 1.17 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity);
582     TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity);
583     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity);
584     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity);
585 buchmann 1.1
586 buchmann 1.17 TH1F *RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity);
587     TH1F *LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity);
588 buchmann 1.13
589 buchmann 1.17 TH1F *RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity);
590     TH1F *LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity);
591 buchmann 1.13
592 buchmann 1.17 TH1F *lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM4"));
593 buchmann 1.13
594 buchmann 1.64 if(!RestrictToMassPeak) write_warning(__FUNCTION__,"Watch out, once we go offpeak this function needs rewriting!"); // the TH1F Bpred below needs to be adapted (remove "1/3" and SBs)
595    
596 buchmann 1.17 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
597 fronga 1.24 Bpred->Add(RcorrJZBem,1.0/3.);
598     Bpred->Add(LcorrJZBem,-1.0/3.);
599     Bpred->Add(RcorrJZBSBem,1.0/3.);
600     Bpred->Add(LcorrJZBSBem,-1.0/3.);
601     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
602     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
603 buchmann 1.39
604     TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
605     Tpred->Add(LcorrJZBem,-1.0);
606     Tpred->Add(RcorrJZBSBem,1.0);
607     Tpred->Add(LcorrJZBSBem,-1.0);
608     Tpred->Add(RcorrJZBSBeemm,1.0);
609     Tpred->Add(LcorrJZBSBeemm,-1.0);
610    
611 buchmann 1.1 globalcanvas->cd();
612     globalcanvas->SetLogy(1);
613 fronga 1.24
614     RcorrJZBeemm->SetMarkerStyle(20);
615     RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
616 fronga 1.46 RcorrJZBeemm->SetMinimum(0.1);
617 fronga 1.24 RcorrJZBeemm->Draw("e1x0");
618    
619 buchmann 1.1 Bpred->SetLineColor(kRed);
620     Bpred->SetStats(0);
621 fronga 1.24 Bpred->Draw("hist,same");
622    
623     if ( overlay_signal ) {
624     lm4RcorrJZBeemm->SetLineColor(TColor::GetColor("#088A08"));
625     lm4RcorrJZBeemm->Draw("histo,same");
626     }
627 buchmann 1.17 RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
628 buchmann 1.13
629 fronga 1.24 TLegend *legBpred = make_legend("",0.6,0.55);
630 buchmann 1.1 if(is_data)
631     {
632 buchmann 1.42 vector<TF1*> analytical_function = do_extended_fit_to_plot(Bpred,Tpred,LcorrJZBeemm,LcorrJZBem,is_data);
633 buchmann 1.38 globalcanvas->cd();
634     analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
635 buchmann 1.47 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
636 fronga 1.24 legBpred->AddEntry(RcorrJZBeemm,"observed","p");
637     legBpred->AddEntry(Bpred,"predicted","l");
638 buchmann 1.38 legBpred->AddEntry(analytical_function[1],"predicted fit","l");
639     legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
640 fronga 1.24 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
641 buchmann 1.1 legBpred->Draw();
642     CompleteSave(globalcanvas,"Bpred_Data");
643     }
644     else {
645 buchmann 1.47 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
646 fronga 1.24 legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
647     legBpred->AddEntry(Bpred,"MC predicted","l");
648 buchmann 1.29 legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
649 buchmann 1.28 // legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
650 fronga 1.24 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
651 buchmann 1.1 legBpred->Draw();
652 buchmann 1.13
653 buchmann 1.1 CompleteSave(globalcanvas,"Bpred_MC");
654     }
655 buchmann 1.64 if(!RestrictToMassPeak) write_warning(__FUNCTION__,"Watch out, once we go offpeak this second part is superfluous (comparison of SB estimates and OF estimate)!");
656 buchmann 1.28 TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
657 buchmann 1.13 Bpredem->Add(RcorrJZBem);
658     Bpredem->Add(LcorrJZBem,-1);
659 buchmann 1.28 TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
660 buchmann 1.13 BpredSBem->Add(RcorrJZBSBem);
661     Bpred->Add(LcorrJZBSBem,-1);
662 buchmann 1.28 TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");
663 buchmann 1.17 BpredSBeemm->Add(RcorrJZBSBeemm);
664     BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
665 buchmann 1.13 globalcanvas->cd();
666     globalcanvas->SetLogy(1);
667 fronga 1.24
668     RcorrJZBeemm->SetMarkerStyle(20);
669     RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
670     RcorrJZBeemm->Draw("e1x0");
671     RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
672    
673     Bpredem->SetLineColor(kRed+1);
674 buchmann 1.13 Bpredem->SetStats(0);
675 fronga 1.24 Bpredem->Draw("hist,same");
676    
677     BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
678     BpredSBem->SetLineStyle(2);
679 buchmann 1.13 BpredSBem->Draw("hist,same");
680 fronga 1.24
681     BpredSBeemm->SetLineColor(kBlue+1);
682     BpredSBeemm->SetLineStyle(3);
683 buchmann 1.13 BpredSBeemm->Draw("hist,same");
684 buchmann 1.47 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
685 fronga 1.24
686 fronga 1.46
687 fronga 1.24 TLegend *legBpredc = make_legend("",0.6,0.55);
688 buchmann 1.13 if(is_data)
689     {
690 fronga 1.24 legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
691     legBpredc->AddEntry(Bpredem,"OFZP","l");
692     legBpredc->AddEntry(BpredSBem,"OFSB","l");
693     legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
694 buchmann 1.13 legBpredc->Draw();
695     CompleteSave(globalcanvas,"Bpred_Data_comparison");
696     }
697     else {
698 fronga 1.24 legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
699     legBpredc->AddEntry(Bpredem,"MC OFZP","l");
700     legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
701     legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
702 buchmann 1.13 legBpredc->Draw();
703     legBpredc->Draw();
704     CompleteSave(globalcanvas,"Bpred_MC_comparison");
705     }
706     delete RcorrJZBeemm;
707     delete LcorrJZBeemm;
708     delete RcorrJZBem;
709     delete LcorrJZBem;
710     delete RcorrJZBSBem;
711     delete LcorrJZBSBem;
712     delete RcorrJZBSBeemm;
713     delete LcorrJZBSBeemm;
714     delete lm4RcorrJZBeemm;
715 buchmann 1.1 }
716    
717 fronga 1.24 void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
718 buchmann 1.11 TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
719 fronga 1.24 do_prediction_plot(datajzb,globalcanvas,DataSigma,jzbHigh ,data,overlay_signal);
720     do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mc,overlay_signal);
721 buchmann 1.1 }
722    
723     void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
724     bool do_data=0;
725     bool dosignal=0;
726     if(is_data==1) do_data=1;
727     if(is_data==2) dosignal=1;
728 buchmann 1.17 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
729     TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
730     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
731     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
732    
733     TH1F *RcorrJZBSBem = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
734     TH1F *LcorrJZBSBem = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
735     TH1F *RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
736     TH1F *LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
737 buchmann 1.13
738 buchmann 1.64 if(!RestrictToMassPeak) write_warning(__FUNCTION__,"Watch out, once we go offpeak this function needs rewriting!");//the bpred below needs to be adapted
739 buchmann 1.17 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
740 buchmann 1.13 Bpred->Add(RcorrJZBem,1.0/3);
741     Bpred->Add(LcorrJZBem,-1.0/3);
742     Bpred->Add(RcorrJZBSBem,1.0/3);
743     Bpred->Add(LcorrJZBSBem,-1.0/3);
744     Bpred->Add(RcorrJZBSBeemm,1.0/3);
745     Bpred->Add(LcorrJZBSbeemm,-1.0/3);
746 buchmann 1.1 can->cd();
747     can->SetLogy(0);
748     Bpred->SetLineColor(kRed);
749     Bpred->SetStats(0);
750     if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
751 buchmann 1.17 TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
752     JZBratioforfitting->Divide(Bpred);
753 buchmann 1.36 TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
754 buchmann 1.17
755 buchmann 1.1
756     JZBratio->SetTitle("");
757     JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
758 fronga 1.24 // if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
759 buchmann 1.1
760     TF1 *pol0 = new TF1("pol0","[0]",0,1000);
761     TF1 *pol0d = new TF1("pol0","[0]",0,1000);
762     // straightline_fit->SetParameter(0,1);
763     JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
764     pol0d->SetParameter(0,pol0->GetParameter(0));
765    
766     JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
767 buchmann 1.17 JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
768 fronga 1.24 if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
769 buchmann 1.1 JZBratio->GetYaxis()->SetNdivisions(519);
770 buchmann 1.59 JZBratio->GetYaxis()->SetRangeUser(0.0,4.0);
771 buchmann 1.17 JZBratio->GetYaxis()->CenterTitle();
772     JZBratio->GetXaxis()->CenterTitle();
773     JZBratio->SetMarkerSize(DataMarkerSize);
774 buchmann 1.1 JZBratio->Draw("AP");
775     /////----------------------------
776 fronga 1.24 TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
777 buchmann 1.1 writeresult->SetFillStyle(4000);
778     writeresult->SetFillColor(kWhite);
779     writeresult->SetTextFont(42);
780 fronga 1.24 writeresult->SetTextSize(0.03);
781     writeresult->SetTextAlign(12);
782 buchmann 1.1 ostringstream jzb_agreement_data_text;
783     jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) << pol0->GetParError(0);
784     if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
785     if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
786     /* if(is_data) writeresult->AddText("Data closure test");
787     else writeresult->AddText("MC closure test");
788     */
789     writeresult->AddText(jzb_agreement_data_text.str().c_str());
790 buchmann 1.60 // writeresult->Draw("same");
791 buchmann 1.59 // pol0d->Draw("same");
792 fronga 1.24 TF1 *topline = new TF1("","1.5",0,1000);
793     TF1 *bottomline = new TF1("","0.5",0,1000);
794 buchmann 1.1 topline->SetLineColor(kBlue);
795     topline->SetLineStyle(2);
796     bottomline->SetLineColor(kBlue);
797     bottomline->SetLineStyle(2);
798 buchmann 1.59 // topline->Draw("same");
799     // bottomline->Draw("same");
800 buchmann 1.1 TF1 *oneline = new TF1("","1.0",0,1000);
801     oneline->SetLineColor(kBlue);
802     oneline->SetLineStyle(1);
803     oneline->Draw("same");
804 buchmann 1.63 TLegend *phony_leg = make_legend("ratio",0.6,0.55,false);//this line is just to have the default CMS Preliminary (...) on the canvas as well.
805     if(is_data==1) DrawPrelim();
806     else DrawMCPrelim();
807 buchmann 1.61 TLegend *leg = new TLegend(0.55,0.75,0.89,0.89);
808 buchmann 1.1 leg->SetTextFont(42);
809 fronga 1.24 leg->SetTextSize(0.04);
810     // if(is_data==1) leg->SetHeader("Ratio (data)");
811     // else leg->SetHeader("Ratio (MC)");
812    
813     TString MCtitle("MC ");
814     if (is_data==1) MCtitle = "";
815    
816 buchmann 1.1 leg->SetFillStyle(4000);
817     leg->SetFillColor(kWhite);
818     leg->SetTextFont(42);
819     // leg->AddEntry(topline,"+20\% sys envelope","l");
820 fronga 1.24 leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
821 buchmann 1.1 leg->AddEntry(oneline,"ratio = 1","l");
822 buchmann 1.59 // leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
823     // leg->AddEntry(bottomline,"#pm50% envelope","l");
824 buchmann 1.61
825    
826     //leg->Draw("same"); // no longer drawing legend
827    
828 buchmann 1.1 if(is_data==1) CompleteSave(can, "jzb_ratio_data");
829     if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
830     if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
831 buchmann 1.17
832 buchmann 1.1 delete RcorrJZBeemm;
833     delete LcorrJZBeemm;
834     delete RcorrJZBem;
835     delete LcorrJZBem;
836 buchmann 1.17
837     delete RcorrJZBSBem;
838     delete LcorrJZBSBem;
839     delete RcorrJZBSBeemm;
840     delete LcorrJZBSbeemm;
841 buchmann 1.1 }
842    
843 buchmann 1.23 void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
844 buchmann 1.11 TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
845 buchmann 1.1 globalc->SetLogy(0);
846    
847 fronga 1.24 do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh );
848     do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh );
849     do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh );
850 buchmann 1.1 }
851    
852 buchmann 1.8 string give_jzb_expression(float peak, int type) {
853 buchmann 1.1 stringstream val;
854 buchmann 1.8 if(type==data) {
855     if(peak<0) val << jzbvariabledata << "+" << TMath::Abs(peak);
856     if(peak>0) val << jzbvariabledata << "-" << TMath::Abs(peak);
857     if(peak==0) val << jzbvariabledata;
858     }
859     if(type==mc) {
860     if(peak<0) val << jzbvariablemc << "+" << TMath::Abs(peak);
861     if(peak>0) val << jzbvariablemc << "-" << TMath::Abs(peak);
862     if(peak==0) val << jzbvariablemc;
863     }
864 buchmann 1.1 return val.str();
865     }
866    
867    
868 buchmann 1.11 void lepton_comparison_plots() {
869 fronga 1.24 Float_t ymin = 1.e-5, ymax = 0.25;
870 buchmann 1.11 TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
871 buchmann 1.1 can->SetLogy(1);
872 buchmann 1.17 TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
873     TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
874 buchmann 1.1 eemc->SetLineColor(kBlue);
875     mmmc->SetLineColor(kRed);
876     eemc->SetMinimum(0.1);
877     eemc->SetMaximum(10*eemc->GetMaximum());
878     eemc->Draw("histo");
879     mmmc->Draw("histo,same");
880     TLegend *leg = make_legend();
881 buchmann 1.17 leg->AddEntry(eemc,"ZJets->ee (MC)","l");
882     leg->AddEntry(mmmc,"ZJets->#mu#mu (MC)","l");
883 buchmann 1.11 leg->Draw("same");
884 buchmann 1.1 CompleteSave(can, "mll_effratio_mc");
885    
886 buchmann 1.17 TH1F *eed = allsamples.Draw("eed","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
887     TH1F *mmd = allsamples.Draw("mmd","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
888 buchmann 1.1 eed->SetLineColor(kBlue);
889     mmd->SetLineColor(kRed);
890     eed->SetMinimum(0.1);
891     eed->SetMaximum(10*eed->GetMaximum());
892     eed->Draw("histo");
893     mmd->Draw("histo,same");
894     TLegend *leg2 = make_legend();
895 buchmann 1.17 leg2->AddEntry(eed,"ZJets->ee (data)","l");
896     leg2->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
897 buchmann 1.1 leg2->Draw();
898     CompleteSave(can, "mll_effratio_data");
899    
900 fronga 1.24 TH1F *jeed = allsamples.Draw("jeed",jzbvariabledata, 100,-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
901     TH1F *jmmd = allsamples.Draw("jmmd",jzbvariabledata, 100,-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
902     TH1F *jeemmd = allsamples.Draw("jeemmd",jzbvariabledata,100,-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
903 buchmann 1.21 dout << "ee : " << jeed->GetMean() << "+/-" << jeed->GetMeanError() << endl;
904     dout << "ee : " << jmmd->GetMean() << "+/-" << jmmd->GetMeanError() << endl;
905     dout << "eemd : " << jeemmd->GetMean() << "+/-" << jeemmd->GetMeanError() << endl;
906 buchmann 1.1 jeemmd->SetLineColor(kBlack);
907     jeemmd->SetMarkerStyle(25);
908     jeed->SetLineColor(kBlue);
909     jmmd->SetLineColor(kRed);
910     jeed->SetMinimum(0.1);
911     jeed->SetMaximum(10*eed->GetMaximum());
912 fronga 1.24 TH1* njeemmd = jeemmd->DrawNormalized();
913     njeemmd->SetMinimum(ymin);
914     njeemmd->SetMaximum(ymax);
915    
916 buchmann 1.1 jeed->DrawNormalized("histo,same");
917     jmmd->DrawNormalized("histo,same");
918     jeemmd->DrawNormalized("same");
919 fronga 1.24 TLegend *jleg2 = make_legend(" ");
920 buchmann 1.1 jleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
921     jleg2->AddEntry(jeed,"ee","l");
922     jleg2->AddEntry(jmmd,"#mu#mu","l");
923     jleg2->Draw();
924     CompleteSave(can,"jzb_effratio_data");
925    
926 fronga 1.24 TH1F *zjeed = allsamples.Draw("zjeed",jzbvariablemc, 100,-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJets"));
927     TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc, 100,-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJets"));
928     TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,100,-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets, mc, luminosity,allsamples.FindSample("DYJets"));
929 buchmann 1.21 dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
930     dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
931     dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
932 buchmann 1.11 zjeemmd->SetLineColor(kBlack);
933     zjeemmd->SetMarkerStyle(25);
934     zjeed->SetLineColor(kBlue);
935     zjmmd->SetLineColor(kRed);
936     zjeed->SetMinimum(0.1);
937     zjeed->SetMaximum(10*eed->GetMaximum());
938 fronga 1.24
939     TH1* nzjeemmd = zjeemmd->DrawNormalized();
940     nzjeemmd->SetMinimum(ymin);
941     nzjeemmd->SetMaximum(ymax);
942 buchmann 1.11 zjeed->DrawNormalized("histo,same");
943     zjmmd->DrawNormalized("histo,same");
944     zjeemmd->DrawNormalized("same");
945 fronga 1.24 TLegend *zjleg2 = make_legend("Z+jets MC");
946 buchmann 1.11 zjleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
947     zjleg2->AddEntry(jeed,"ee","l");
948     zjleg2->AddEntry(jmmd,"#mu#mu","l");
949     zjleg2->Draw();
950     CompleteSave(can,"jzb_effratio_ZJets");
951    
952 buchmann 1.17 TH1F *ld = allsamples.Draw("ld","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
953 buchmann 1.1 ld->DrawNormalized("e1");
954     eed->DrawNormalized("histo,same");
955     mmd->DrawNormalized("histo,same");
956     TLegend *leg3 = make_legend();
957     leg3->AddEntry(ld,"ZJets->ll (data)","p");
958 buchmann 1.17 leg3->AddEntry(eed,"ZJets->ee (data)","l");
959     leg3->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
960 buchmann 1.1 leg3->Draw();
961     CompleteSave(can,"mll_effratio_data__all_compared");
962     /*
963 buchmann 1.17 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
964     TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
965 buchmann 1.1 */
966 fronga 1.24 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariabledata,92,-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
967     TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariabledata,92,-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
968 buchmann 1.1 jzbld->SetMarkerColor(kBlack);
969     jzbld->SetMarkerStyle(26);
970     jzbemd->SetMarkerStyle(25);
971     jzbemd->SetMarkerColor(kRed);
972     jzbemd->SetLineColor(kRed);
973     jzbld->SetMinimum(0.35);
974     jzbld->Draw("e1");
975     jzbemd->Draw("e1,same");
976 fronga 1.24 TLegend *leg4 = make_legend();
977     leg4->AddEntry(jzbld,"SFZP","p");
978     leg4->AddEntry(jzbemd,"OFZP","p");
979 buchmann 1.29 leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
980     leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
981 buchmann 1.1 leg4->Draw();
982     CompleteSave(can,"jzb_eemumu_emu_data");
983    
984 buchmann 1.17 TH1F *ttbarjzbld = allsamples.Draw("ttbarjzbld",jzbvariablemc,110,-150,400, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
985     TH1F *ttbarjzbemd = allsamples.Draw("ttbarjzbemd",jzbvariablemc,110,-150,400, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
986 buchmann 1.1 ttbarjzbld->SetLineColor(allsamples.GetColor("TTJet"));
987     ttbarjzbemd->SetLineColor(allsamples.GetColor("TTJet"));
988     ttbarjzbld->Draw("histo");
989     ttbarjzbemd->SetLineStyle(2);
990     ttbarjzbemd->Draw("histo,same");
991     TLegend *leg5 = make_legend();
992 buchmann 1.17 leg5->AddEntry(ttbarjzbld,"t#bar{t}->(ee or #mu#mu)","l");
993     leg5->AddEntry(ttbarjzbemd,"t#bar{t}->e#mu","l");
994 buchmann 1.1 leg5->Draw();
995     CompleteSave(can,"ttbar_emu_mc");
996    
997    
998    
999     }
1000    
1001     bool is_OF(TCut cut) {
1002     string scut = (const char*) cut;
1003     if((int)scut.find("id1!=id2")>-1) return true;
1004     if((int)scut.find("id1==id2")>-1) return false;
1005     return false;
1006     }
1007    
1008 fronga 1.24 bool is_ZP(TCut cut) {
1009     string scut = (const char*) cut;
1010     if((int)scut.find("91")>-1) return true;
1011     return false;
1012     }
1013    
1014    
1015 buchmann 1.23 void draw_pure_jzb_histo(TCut cut,string variable,string savename, TCanvas *can,vector<float> binning) {
1016 buchmann 1.1 can->cd();
1017     can->SetLogy(1);
1018 buchmann 1.17 string xlabel="JZB [GeV]";
1019 buchmann 1.1
1020 buchmann 1.23 TH1F *datahisto = allsamples.Draw("datahisto",variable,binning, xlabel, "events",cut,data,luminosity);
1021     THStack mcstack = allsamples.DrawStack("mcstack",variable,binning, xlabel, "events",cut,mc,luminosity);
1022 buchmann 1.1
1023     datahisto->SetMinimum(0.1);
1024 buchmann 1.12 //if(savename=="jzb_OSOF") datahisto->SetMaximum(10);
1025 buchmann 1.17 datahisto->SetMarkerSize(DataMarkerSize);
1026 buchmann 1.1 datahisto->Draw("e1");
1027     mcstack.Draw("same");
1028     datahisto->Draw("same,e1");
1029    
1030     TLegend *leg;
1031 fronga 1.24 if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
1032     else if(!is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
1033     else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
1034     else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
1035     else {
1036     std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
1037     exit(-1);
1038     }
1039 buchmann 1.1 leg->Draw();
1040     string write_cut = decipher_cut(cut,"");
1041 buchmann 1.16 TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
1042 buchmann 1.1 writeline1->SetTextSize(0.035);
1043     writeline1->Draw();
1044     CompleteSave(can, ("jzb/"+savename));
1045    
1046     datahisto->Delete();
1047     mcstack.Delete();
1048     }
1049    
1050     Double_t GausR(Double_t *x, Double_t *par) {
1051     return gRandom->Gaus(x[0],par[0]);
1052     }
1053    
1054 buchmann 1.23 void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1055 buchmann 1.11 TCanvas *can = new TCanvas("can","JZB Plots Canvas");
1056 fronga 1.24 float max=jzbHigh ;
1057 buchmann 1.1 float min=-120;
1058     int nbins=(max-min)/5.0; // we want 5 GeV/bin
1059 buchmann 1.23 int coarserbins=int(nbins/2.0);
1060     int rebinnedbins=int(nbins/4.0);
1061 buchmann 1.1
1062 buchmann 1.23 // stringstream ss;
1063 buchmann 1.1 // ss << "GausRandom(" << datajzb << ",0)";
1064 buchmann 1.23 vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
1065     for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
1066     for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
1067     for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
1068    
1069     /* draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OSSF_altbins",can,ratio_binning);
1070     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OSOF_altbins",can,ratio_binning);
1071     draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OSSF_SB_altbins",can,ratio_binning);
1072     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OSOF_SB_altbins",can,ratio_binning);*/
1073 fronga 1.24 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OS_SFZP",can,binning);
1074     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OS_OFZP",can,binning);
1075     draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_SFSB",can,binning);
1076     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_OFSB",can,binning);
1077    
1078     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
1079     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
1080     draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
1081     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
1082    
1083     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OS_SFZP_coarsest",can,coarsest_binning);
1084     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OS_OFZP_coarsest",can,coarsest_binning);
1085     draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_SFSB_coarsest",can,coarsest_binning);
1086     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_OFSB_coarsest",can,coarsest_binning);
1087 buchmann 1.1 }
1088    
1089     void calculate_all_yields(string mcdrawcommand,vector<float> jzb_cuts) {
1090 buchmann 1.21 dout << "Calculating background yields in MC:" << endl;
1091 buchmann 1.1 jzb_cuts.push_back(14000);
1092 buchmann 1.17 TH1F *allbgs = allsamples.Draw("allbgs",jzbvariablemc,jzb_cuts, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,luminosity);
1093 buchmann 1.1 float cumulative=0;
1094     for(int i=allbgs->GetNbinsX();i>=1;i--) {
1095     cumulative+=allbgs->GetBinContent(i);
1096 buchmann 1.21 dout << "Above " << allbgs->GetBinLowEdge(i) << " GeV/c : " << cumulative << endl;
1097 buchmann 1.1 }
1098     }
1099    
1100 buchmann 1.4 void draw_ttbar_and_zjets_shape_for_one_configuration(string mcjzb, string datajzb, int leptontype=-1, int scenario=0,bool floating=false) {
1101 buchmann 1.10 //Step 1: Establishing cuts
1102 buchmann 1.3 stringstream jetcutstring;
1103 buchmann 1.10 string writescenario="";
1104    
1105 buchmann 1.3 if(scenario==0) jetcutstring << "(pfJetGoodNum>=3)&&"<<(const char*) basicqualitycut;
1106     if(scenario==1) jetcutstring << "(pfJetPt[0]>50&&pfJetPt[1]>50)&&"<<(const char*)basicqualitycut;
1107     TCut jetcut(jetcutstring.str().c_str());
1108     string leptoncut="mll>0";
1109     if(leptontype==0||leptontype==1) {
1110 buchmann 1.10 if(leptontype==0) {
1111     leptoncut="id1==0";
1112     writescenario="__ee";
1113     }
1114     else {
1115     leptoncut="id1==1";
1116     writescenario="__ee";
1117     }
1118 buchmann 1.3 }
1119     TCut lepcut(leptoncut.c_str());
1120    
1121 buchmann 1.6 TCanvas *c5 = new TCanvas("c5","c5",1500,500);
1122 buchmann 1.10 TCanvas *c6 = new TCanvas("c6","c6");
1123 buchmann 1.3 c5->Divide(3,1);
1124 buchmann 1.10
1125     //STEP 2: Extract Zjets shape in data
1126     c5->cd(1);
1127 buchmann 1.3 c5->cd(1)->SetLogy(1);
1128     TCut massat40("mll>40");
1129 buchmann 1.17 TH1F *ossfleft = allsamples.Draw("ossfleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1130     TH1F *osofleft = allsamples.Draw("osofleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
1131 buchmann 1.3 ossfleft->SetLineColor(kRed);
1132     ossfleft->SetMarkerColor(kRed);
1133     ossfleft->Add(osofleft,-1);
1134 buchmann 1.9 vector<TF1*> functions = do_cb_fit_to_plot(ossfleft,10);
1135 buchmann 1.17 ossfleft->SetMarkerSize(DataMarkerSize);
1136 buchmann 1.3 ossfleft->Draw();
1137 buchmann 1.9 functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
1138     TF1 *zjetsfunc = (TF1*) functions[1]->Clone();
1139     TF1 *zjetsfuncN = (TF1*) functions[0]->Clone();
1140     TF1 *zjetsfuncP = (TF1*) functions[2]->Clone();
1141 buchmann 1.6 zjetsfunc->Draw("same");zjetsfuncN->Draw("same");zjetsfuncP->Draw("same");
1142 buchmann 1.3 TLegend *leg1 = new TLegend(0.6,0.6,0.89,0.80);
1143     leg1->SetFillColor(kWhite);
1144     leg1->SetLineColor(kWhite);
1145     leg1->AddEntry(ossfleft,"OSSF (sub),JZB<peak","p");
1146 buchmann 1.6 leg1->AddEntry(zjetsfunc,"OSSF fit ('zjets')","l");
1147 buchmann 1.3 leg1->Draw("same");
1148     TText *titleleft = write_title("Extracting Z+Jets shape");
1149     titleleft->Draw();
1150    
1151 buchmann 1.10 //Step 3: Extract ttbar shape (in data or MC?)
1152     c5->cd(2);
1153 buchmann 1.3 c5->cd(2)->SetLogy(1);
1154 buchmann 1.4 TH1F *osof;
1155     TText *titlecenter;
1156 buchmann 1.10 bool frommc=false;
1157     if(frommc) {
1158 buchmann 1.17 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
1159 buchmann 1.4 titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
1160     }
1161     else {
1162 buchmann 1.17 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
1163 buchmann 1.4 titlecenter = write_title("Extracting ttbar shape (from osof data)");
1164     }
1165 buchmann 1.17 osof->SetMarkerSize(DataMarkerSize);
1166 buchmann 1.3 osof->Draw();
1167 buchmann 1.10 vector<TF1*> ttbarfunctions = do_cb_fit_to_plot(osof,35,true);
1168     ttbarfunctions[0]->SetLineColor(kRed); ttbarfunctions[0]->SetLineStyle(2); ttbarfunctions[0]->Draw("same");
1169     ttbarfunctions[1]->SetLineColor(kRed); ttbarfunctions[1]->Draw("same");
1170     ttbarfunctions[2]->SetLineColor(kRed); ttbarfunctions[2]->SetLineStyle(2); ttbarfunctions[2]->Draw("same");
1171    
1172 buchmann 1.3 TLegend *leg2 = new TLegend(0.15,0.8,0.4,0.89);
1173     leg2->SetFillColor(kWhite);
1174     leg2->SetLineColor(kWhite);
1175 buchmann 1.10 if(frommc) {
1176 buchmann 1.4 leg2->AddEntry(osof,"t#bar{t} OSSF, MC","p");
1177 buchmann 1.10 leg2->AddEntry(ttbarfunctions[1],"Fit to t#bar{t} OSSF,MC","l");
1178 buchmann 1.4 } else {
1179     leg2->AddEntry(osof,"OSOF","p");
1180 buchmann 1.10 leg2->AddEntry(ttbarfunctions[1],"Fit to OSOF","l");
1181 buchmann 1.4 }
1182 buchmann 1.3 leg2->Draw("same");
1183     titlecenter->Draw();
1184 buchmann 1.10
1185     //--------------------------------------------------------------------------------------------------------------------------------
1186 buchmann 1.4 //STEP 4: Present it!
1187     // actually: if we wanna let it float we need to do that first :-)
1188 buchmann 1.3 c5->cd(3);
1189     c5->cd(3)->SetLogy(1);
1190 buchmann 1.17 TH1F *observed = allsamples.Draw("observed",datajzb,100,0,500, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1191     observed->SetMarkerSize(DataMarkerSize);
1192 buchmann 1.4
1193 buchmann 1.6 TF1 *logparc = new TF1("logparc",InvCrystalBall,0,1000,5); logparc->SetLineColor(kRed);
1194 buchmann 1.8 TF1 *logparcn = new TF1("logparcn",InvCrystalBallN,0,1000,5); logparcn->SetLineColor(kRed); logparcn->SetLineStyle(2);
1195     TF1 *logparcp = new TF1("logparcp",InvCrystalBallP,0,1000,5); logparcp->SetLineColor(kRed); logparcp->SetLineStyle(2);
1196 buchmann 1.6
1197     TF1 *zjetsc = new TF1("zjetsc",InvCrystalBall,0,1000,5); zjetsc->SetLineColor(kBlue);
1198     TF1 *zjetscn = new TF1("zjetscn",InvCrystalBallN,0,1000,5); zjetscn->SetLineColor(kBlue); zjetscn->SetLineStyle(2);
1199     TF1 *zjetscp = new TF1("zjetscp",InvCrystalBallP,0,1000,5); zjetscp->SetLineColor(kBlue); zjetscp->SetLineStyle(2);
1200    
1201 buchmann 1.10 TF1 *ZplusJetsplusTTbar = new TF1("ZplusJetsplusTTbar", DoubleInvCrystalBall,0,1000,10); ZplusJetsplusTTbar->SetLineColor(kBlue);
1202     TF1 *ZplusJetsplusTTbarP= new TF1("ZplusJetsplusTTbarP",DoubleInvCrystalBallP,0,1000,10); ZplusJetsplusTTbarP->SetLineColor(kBlue); ZplusJetsplusTTbarP->SetLineStyle(2);
1203     TF1 *ZplusJetsplusTTbarN= new TF1("ZplusJetsplusTTbarN",DoubleInvCrystalBallN,0,1000,10); ZplusJetsplusTTbarN->SetLineColor(kBlue); ZplusJetsplusTTbarN->SetLineStyle(2);
1204    
1205 buchmann 1.6 zjetsc->SetParameters(zjetsfunc->GetParameters());
1206     zjetscp->SetParameters(zjetsfunc->GetParameters());
1207     zjetscn->SetParameters(zjetsfunc->GetParameters());
1208 buchmann 1.10
1209 fronga 1.24 TH1F *observeda = allsamples.Draw("observeda",datajzb,53,80,jzbHigh, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1210 buchmann 1.7 //blublu
1211 buchmann 1.10 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
1212     logparcn->SetParameters(ttbarfunctions[1]->GetParameters());
1213     logparcp->SetParameters(ttbarfunctions[1]->GetParameters());
1214 buchmann 1.4 if(floating) {
1215 buchmann 1.21 dout << "TTbar contribution assumed (before fitting) : " << logparc->GetParameter(0) << endl;
1216 buchmann 1.10 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
1217 buchmann 1.7 for(int i=0;i<10;i++) {
1218     if(i<5) ZplusJetsplusTTbar->FixParameter(i,zjetsfunc->GetParameter(i));
1219     if(i>=5) {
1220     if (i>5) ZplusJetsplusTTbar->FixParameter(i,logparc->GetParameter(i-5));
1221     if (i==5) ZplusJetsplusTTbar->SetParameter(i,logparc->GetParameter(i-5));
1222     }
1223     }//end of setting parameters
1224     observeda->Draw("same");
1225     ZplusJetsplusTTbar->Draw("same");
1226     observeda->Fit(ZplusJetsplusTTbar);
1227 buchmann 1.21 dout << "--> Quality of Z+Jets / TTbar fit : chi2/ndf = " << ZplusJetsplusTTbar->GetChisquare() << "/" << ZplusJetsplusTTbar->GetNDF() << endl;
1228 buchmann 1.7 ZplusJetsplusTTbar->Draw("same");
1229 buchmann 1.8 ZplusJetsplusTTbarP->SetParameters(ZplusJetsplusTTbar->GetParameters());
1230     ZplusJetsplusTTbarN->SetParameters(ZplusJetsplusTTbar->GetParameters());
1231 buchmann 1.21 dout << "TTbar contribution found (after fitting) : " << ZplusJetsplusTTbar->GetParameter(5) << endl;
1232 buchmann 1.7 float factor = ZplusJetsplusTTbar->GetParameter(5) / logparc->GetParameter(0);
1233 buchmann 1.21 dout << "FACTOR: " << factor << endl;
1234 buchmann 1.10 logparc->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1235     logparcn->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1236     logparcp->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1237 buchmann 1.4 }
1238 buchmann 1.6
1239 buchmann 1.4 c5->cd(3);
1240 buchmann 1.6 c5->cd(3)->SetLogy(1);
1241     observed->Draw();
1242     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1243 buchmann 1.3 logparc->Draw("same");
1244 buchmann 1.6 logparcn->Draw("same");
1245     logparcp->Draw("same");
1246    
1247 buchmann 1.3 TLegend *leg3 = new TLegend(0.6,0.6,0.89,0.80);
1248     leg3->SetFillColor(kWhite);
1249     leg3->SetLineColor(kWhite);
1250     leg3->AddEntry(observed,"OSSF,JZB>peak","p");
1251 buchmann 1.10 leg3->AddEntry(ttbarfunctions[1],"OSOF fit ('ttbar')","l");
1252 buchmann 1.6 leg3->AddEntry(zjetsfunc,"OSSF,JZB<0 fit ('zjets')","l");
1253 buchmann 1.3 leg3->Draw("same");
1254     TText *titleright = write_title("Summary of shapes and observed shape");
1255     titleright->Draw();
1256    
1257     c6->cd()->SetLogy(1);
1258 buchmann 1.6 observed->Draw();
1259     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1260 buchmann 1.3 logparc->Draw("same");
1261 buchmann 1.6 logparcn->Draw("same");
1262     logparcp->Draw("same");
1263 buchmann 1.3 leg3->Draw("same");
1264     titleright->Draw();
1265    
1266     if(scenario==0) {
1267     CompleteSave(c5,"Shapes2/Making_of___3jetsabove30"+writescenario);
1268 buchmann 1.6 CompleteSave(c5->cd(1),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd1");
1269     CompleteSave(c5->cd(2),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd2");
1270     CompleteSave(c5->cd(3),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd3");
1271 buchmann 1.3 CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30"+writescenario);
1272     } else {
1273     CompleteSave(c5,"Shapes2/Making_of___2jetsabove50"+writescenario);
1274 buchmann 1.6 CompleteSave(c5->cd(1),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd1");
1275     CompleteSave(c5->cd(2),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd2");
1276     CompleteSave(c5->cd(3),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd3");
1277 buchmann 1.3 CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50"+writescenario);
1278     }
1279 buchmann 1.21 dout << "Statistics about our fits: " << endl;
1280     dout << "Z+Jets shape: Chi2/ndf = " << zjetsfunc->GetChisquare() << "/" << ossfleft->GetNbinsX() << endl;
1281     dout << "ttbar shape: Chi2/ndf = " << ttbarfunctions[1]->GetChisquare() << "/" << osof->GetNbinsX() << endl;
1282 buchmann 1.4
1283 buchmann 1.7 c6->cd();
1284 buchmann 1.8 TLegend *additionallegend = new TLegend(0.6,0.6,0.89,0.89);
1285     additionallegend->SetFillColor(kWhite);
1286     additionallegend->SetLineColor(kWhite);
1287     additionallegend->AddEntry(observed,"Data","p");
1288     additionallegend->AddEntry(ZplusJetsplusTTbar,"Fitted Z+jets & TTbar","l");
1289     additionallegend->AddEntry(zjetsc,"Z+jets","l");
1290     additionallegend->AddEntry(logparc,"TTbar","l");
1291 buchmann 1.7 observed->Draw();
1292     ZplusJetsplusTTbar->SetLineColor(kGreen);
1293 buchmann 1.8 ZplusJetsplusTTbarP->SetLineColor(kGreen);
1294     ZplusJetsplusTTbarN->SetLineColor(kGreen);
1295     ZplusJetsplusTTbarP->SetLineStyle(2);
1296     ZplusJetsplusTTbarN->SetLineStyle(2);
1297     TF1 *ZplusJetsplusTTbar2 = new TF1("ZplusJetsplusTTbar2",DoubleInvCrystalBall,0,1000,10);
1298     ZplusJetsplusTTbar2->SetParameters(ZplusJetsplusTTbar->GetParameters());
1299     ZplusJetsplusTTbar2->SetLineColor(kGreen);
1300     ZplusJetsplusTTbarP->SetFillColor(TColor::GetColor("#81F781"));
1301     ZplusJetsplusTTbarN->SetFillColor(kWhite);
1302     ZplusJetsplusTTbarP->Draw("fcsame");
1303     ZplusJetsplusTTbarN->Draw("fcsame");
1304     TH1F *hZplusJetsplusTTbar = (TH1F*)ZplusJetsplusTTbar2->GetHistogram();
1305     TH1F *hZplusJetsplusTTbarN = (TH1F*)ZplusJetsplusTTbarN->GetHistogram();
1306     TH1F *hZplusJetsplusTTbarP = (TH1F*)ZplusJetsplusTTbarP->GetHistogram();
1307     hZplusJetsplusTTbar->SetMarkerSize(0);
1308     hZplusJetsplusTTbarP->SetMarkerSize(0);
1309     hZplusJetsplusTTbarN->SetMarkerSize(0);
1310     for (int i=1;i<=hZplusJetsplusTTbar->GetNbinsX();i++) {
1311     float newerror=hZplusJetsplusTTbarP->GetBinContent(i)-hZplusJetsplusTTbar->GetBinContent(i);
1312     hZplusJetsplusTTbar->SetBinError(i,newerror);
1313     if(hZplusJetsplusTTbar->GetBinContent(i)<0.05) hZplusJetsplusTTbar->SetBinContent(i,0); //avoiding a displaying probolem
1314     }
1315     hZplusJetsplusTTbarP->SetFillColor(kGreen);
1316     hZplusJetsplusTTbarN->SetFillColor(kWhite);
1317     hZplusJetsplusTTbarN->Draw("same");
1318    
1319     ZplusJetsplusTTbar2->SetMarkerSize(0);
1320     ZplusJetsplusTTbar2->Draw("same");
1321    
1322 buchmann 1.7 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1323     logparc->Draw("same");
1324     logparcn->Draw("same");
1325     logparcp->Draw("same");
1326 buchmann 1.8 additionallegend->Draw("same");
1327     if(scenario==0) {
1328     CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30__allfits__"+writescenario);
1329     } else {
1330     CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50__allfits__"+writescenario);
1331     }
1332 buchmann 1.10 //--------------------------------------------------------------------------------------------------------------------------------
1333 buchmann 1.3 }
1334    
1335 buchmann 1.2 void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
1336 buchmann 1.3 int all_leptons=-1;
1337     int electrons_only=0;
1338     int mu_only=1;
1339     int twojetswith50gev=1;
1340     int threejetswith30gev=0;
1341 buchmann 1.4 /*
1342 buchmann 1.3 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
1343     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
1344    
1345     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,twojetswith50gev);
1346     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,threejetswith30gev);
1347    
1348     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,twojetswith50gev);
1349     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,threejetswith30gev);
1350 buchmann 1.4 */
1351 buchmann 1.2
1352 buchmann 1.10 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
1353 buchmann 1.2 }
1354 buchmann 1.6
1355 buchmann 1.8 void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
1356 buchmann 1.13 //first: colorful plots
1357     TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
1358 buchmann 1.14 cancorr->SetLogz();
1359 fronga 1.26 cancorr->SetRightMargin(0.13);
1360 buchmann 1.13 TCut zptforresponsepresentation("pt<600&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)&&((sumJetPt[1]/pt)<5.0)");
1361 fronga 1.26 TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
1362 buchmann 1.48 (allsamples.collection)[allsamples.FindSample("Data")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
1363 buchmann 1.13 niceresponseplotd->SetStats(0);
1364 fronga 1.26 niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
1365 buchmann 1.13 niceresponseplotd->GetYaxis()->SetTitle("Response");
1366     niceresponseplotd->GetXaxis()->CenterTitle();
1367     niceresponseplotd->GetYaxis()->CenterTitle();
1368     niceresponseplotd->Draw("COLZ");
1369 fronga 1.26 TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
1370     profd->SetMarkerSize(DataMarkerSize);
1371     profd->Fit("pol0","","same,e1",30,400);
1372 buchmann 1.13 DrawPrelim();
1373 buchmann 1.32 TText* title = write_text(0.5,0.7,"Data");
1374     title->SetTextAlign(12);
1375 fronga 1.26 title->Draw();
1376 buchmann 1.32 TF1 *datapol=(TF1*)profd->GetFunction("pol0");
1377     float datacorrection=datapol->GetParameter(0);
1378     stringstream dataresstring;
1379     dataresstring<<"Response: "<<std::setprecision(2)<<100*datacorrection<<" %";
1380     TText* restitle = write_text(0.5,0.65,dataresstring.str());
1381     restitle->SetTextAlign(12);
1382     restitle->SetTextSize(0.03);
1383     restitle->Draw();
1384 buchmann 1.13 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
1385    
1386 fronga 1.26 TH2F *niceresponseplotm = new TH2F("niceresponseplotm","",100,0,600,100,0,5);
1387     (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotm",zptforresponsepresentation);
1388     niceresponseplotm->SetStats(0);
1389     niceresponseplotm->GetXaxis()->SetTitle("Z p_{T} [GeV]");
1390     niceresponseplotm->GetYaxis()->SetTitle("Response");
1391     niceresponseplotm->GetXaxis()->CenterTitle();
1392     niceresponseplotm->GetYaxis()->CenterTitle();
1393     niceresponseplotm->Draw("COLZ");
1394 buchmann 1.13 (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt",zptforresponsepresentation,"PROF,same");
1395 fronga 1.26 TProfile * profm = (TProfile*)niceresponseplotm->ProfileX();
1396     profm->SetMarkerSize(DataMarkerSize);
1397     profm->Fit("pol0","","same,e1",30,400);
1398 buchmann 1.13 DrawPrelim();
1399 buchmann 1.32 title = write_text(0.5,0.7,"MC simulation");
1400     title->SetTextAlign(12);
1401 fronga 1.26 title->Draw();
1402 buchmann 1.32 TF1 *mcpol=(TF1*)profm->GetFunction("pol0");
1403     float mccorrection=mcpol->GetParameter(0);
1404     stringstream mcresstring;
1405     mcresstring<<"Response: "<<std::setprecision(2)<<100*mccorrection<<" %";
1406     TText* mcrestitle = write_text(0.5,0.65,mcresstring.str());
1407     mcrestitle->SetTextAlign(12);
1408     mcrestitle->SetTextSize(0.03);
1409     mcrestitle->Draw();
1410 buchmann 1.13 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_MC");
1411    
1412 buchmann 1.32
1413 buchmann 1.13 //Step 2: Getting the result
1414 buchmann 1.32 // TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
1415 buchmann 1.8 stringstream jzbvardatas;
1416 buchmann 1.9 if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
1417     if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
1418 buchmann 1.8 jzbvardata=jzbvardatas.str();
1419     stringstream jzbvarmcs;
1420 buchmann 1.33 if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
1421 buchmann 1.9 if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
1422 buchmann 1.8 jzbvarmc=jzbvarmcs.str();
1423 buchmann 1.21 dout << "JZB Z pt correction summary : " << endl;
1424 buchmann 1.32 dout << " Data: The response is " << datacorrection << " --> jzb variable is now : " << jzbvardata << endl;
1425     dout << " MC : The response is " << mccorrection << " --> jzb variable is now : " << jzbvarmc << endl;
1426 buchmann 1.8 }
1427 buchmann 1.11
1428 buchmann 1.12 void pick_up_events(string cut) {
1429 buchmann 1.21 dout << "Picking up events with cut " << cut << endl;
1430 buchmann 1.12 allsamples.PickUpEvents(cut);
1431 buchmann 1.11 }
1432    
1433 buchmann 1.38 void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError) {
1434     cout << "Saving configuration template!" << endl;
1435 buchmann 1.30 ofstream configfile;
1436 buchmann 1.31 configfile.open("../DistributedModelCalculations/last_configuration.C");
1437 buchmann 1.30 configfile<<"#include <iostream>\n";
1438     configfile<<"#include <vector>\n";
1439     configfile<<"\nusing namespace std;\n\n";
1440 buchmann 1.31
1441     configfile<<"namespace PlottingSetup { \n";
1442     configfile<<"string datajzb=\"datajzb_ERROR\";\n";
1443     configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
1444     configfile<<"vector<float>jzb_cuts;\n";
1445     configfile<<"float MCPeakError=-999;\n";
1446     configfile<<"}\n\n";
1447    
1448    
1449    
1450 buchmann 1.30 configfile<<"void read_config() {\n";
1451     configfile<<"datajzb=\""<<datajzb<<"\";\n";
1452     configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
1453 buchmann 1.31 configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n\n";
1454 buchmann 1.30 for(int i=0;i<jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<");\n";
1455     configfile<<"\n\n";
1456     for(int i=0;i<Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<");\n";
1457     for(int i=0;i<Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<");\n";
1458     for(int i=0;i<Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<");\n";
1459 buchmann 1.37 configfile<<"\n\n";
1460 buchmann 1.38 configfile<<"luminosity="<<luminosity<<";\n";
1461 buchmann 1.30
1462     configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
1463    
1464     configfile.close();
1465    
1466     }
1467    
1468 buchmann 1.40 float get_nonzero_minimum(TH1F *histo) {
1469     float min=histo->GetMaximum();
1470     for(int ibin=1;ibin<=histo->GetNbinsX();ibin++) {
1471     float curcont=histo->GetBinContent(ibin);
1472     if(curcont<min&&curcont>0) min=curcont;
1473     }
1474     return min;
1475     }
1476    
1477     void draw_all_ttbar_histos(TCanvas *can, vector<TH1F*> histos, string drawoption="", float manualmin=-9) {
1478     can->cd();
1479     float min=1;
1480     float max=histos[0]->GetMaximum();
1481     if(manualmin>=0) min=manualmin;
1482     else {
1483     for(int i=1;i<histos.size();i++) {
1484     float curmin=get_nonzero_minimum(histos[i]);
1485     float curmax=histos[i]->GetMaximum();
1486     if(curmin<min) min=curmin;
1487     if(curmax>max) max=curmax;
1488     }
1489     }
1490     histos[0]->GetYaxis()->SetRangeUser(min,4*max);
1491     histos[0]->Draw(drawoption.c_str());
1492     stringstream drawopt;
1493     drawopt << drawoption << ",same";
1494     for(int i=1;i<histos.size();i++) {
1495     histos[i]->Draw(drawopt.str().c_str());
1496     }
1497     }
1498    
1499     void ttbar_sidebands_comparison(string mcjzb) {
1500 buchmann 1.64 if(!RestrictToMassPeak) write_warning(__FUNCTION__,"Watch out, once we go offpeak this function needs rewriting!");//need to build in a warning that this function is pointless for the off peak analysis
1501 buchmann 1.60 TCut weightbackup=cutWeight;
1502     cutWeight="1.0";
1503 buchmann 1.40 float sbg_min=-110;
1504     float sbg_max=jzbHigh;
1505 buchmann 1.63 int sbg_nbins=(sbg_max-sbg_min)/20.0;
1506 buchmann 1.58 float simulatedlumi = luminosity; //in pb please - adjust to your likings
1507 buchmann 1.40
1508 fronga 1.51 TH1F *TZem = allsamples.Draw("TZem",mcjzb,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
1509     TH1F *TSem = allsamples.Draw("TSem",mcjzb,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
1510     TH1F *TZeemm = allsamples.Draw("TZeemm",mcjzb,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
1511     TH1F *TSeemm = allsamples.Draw("TSeemm",mcjzb,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
1512 buchmann 1.40
1513     TCanvas *tcan = new TCanvas("tcan","tcan");
1514    
1515     tcan->SetLogy(1);
1516    
1517     TZeemm->SetLineColor(kBlack);
1518     TZem->SetLineColor(kRed);
1519     TSem->SetLineColor(kGreen);
1520     TSeemm->SetLineColor(kBlue);
1521    
1522     TZeemm->SetMarkerColor(kBlack);
1523     TZem->SetMarkerColor(kRed);
1524     TSem->SetMarkerColor(kGreen);
1525     TSeemm->SetMarkerColor(kBlue);
1526    
1527     TSem->SetLineStyle(2);
1528     TSeemm->SetLineStyle(2);
1529    
1530     vector<TH1F*> histos;
1531     histos.push_back(TZem);
1532     histos.push_back(TZeemm);
1533     histos.push_back(TSem);
1534     histos.push_back(TSeemm);
1535     draw_all_ttbar_histos(tcan,histos,"histo",0.04);
1536    
1537 fronga 1.51 TLegend *leg = make_legend("MC ttbar",0.55,0.65,false);
1538 buchmann 1.42 leg->AddEntry(TZeemm,"SFZP","l");
1539     leg->AddEntry(TZem,"OFZP","l");
1540     leg->AddEntry(TSeemm,"SFSB","l");
1541     leg->AddEntry(TSem,"OFSB","l");
1542 buchmann 1.40 leg->Draw("same");
1543 fronga 1.51 DrawMCPrelim(simulatedlumi);
1544 buchmann 1.40 CompleteSave(tcan,"ttbar_comparison");
1545    
1546     TZem->Divide(TZeemm);
1547     TSem->Divide(TZeemm);
1548     TSeemm->Divide(TZeemm);
1549    
1550 buchmann 1.62 TZem->SetMarkerStyle(21);
1551     TSem->SetMarkerStyle(24);
1552     TSeemm->SetMarkerStyle(30);
1553    
1554 buchmann 1.40 tcan->SetLogy(0);
1555     TZem->GetYaxis()->SetRangeUser(0,2.5);
1556     TZem->GetYaxis()->SetTitle("predicted/MC truth");
1557     TZem->Draw();
1558     TSem->Draw("same");
1559     TSeemm->Draw("same");
1560    
1561     TLine *top = new TLine(sbg_min,1.5,sbg_max,1.5);
1562     TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
1563     TLine *bottom = new TLine(sbg_min,0.5,sbg_max,0.5);
1564    
1565     top->SetLineColor(kBlue);top->SetLineStyle(2);
1566     bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
1567     center->SetLineColor(kBlue);
1568    
1569     top->Draw("same");
1570     center->Draw("same");
1571     bottom->Draw("same");
1572    
1573 fronga 1.51 TLegend *leg2 = make_legend("MC ttbar",0.55,0.75,false);
1574 buchmann 1.43 leg2->AddEntry(TZem,"OFZP / SFZP","ple");
1575     leg2->AddEntry(TSeemm,"SFSB / SFZP","ple");
1576     leg2->AddEntry(TSem,"OFSB / SFZP","ple");
1577 buchmann 1.40 leg2->AddEntry(bottom,"syst. envelope","l");
1578 buchmann 1.62 leg2->SetX1(0.25);leg2->SetX2(0.6);
1579 buchmann 1.40 leg2->SetY1(0.65);
1580    
1581     leg2->Draw("same");
1582    
1583 fronga 1.51 DrawMCPrelim(simulatedlumi);
1584 buchmann 1.40 CompleteSave(tcan,"ttbar_comparison_ratio");
1585    
1586     delete tcan;
1587 buchmann 1.60 cutWeight=weightbackup;
1588 buchmann 1.40 }
1589    
1590 fronga 1.45 void zjets_prediction_comparison(string mcjzb) {
1591 buchmann 1.64 if(!RestrictToMassPeak) write_warning(__FUNCTION__,"Watch out, once we go offpeak this function needs rewriting!");
1592 buchmann 1.60 TCut weightbackup=cutWeight;
1593     cutWeight="1.0";
1594 fronga 1.45 float sbg_min=0.;
1595     float sbg_max=100.;
1596     int sbg_nbins=5;
1597 buchmann 1.58 float simulatedlumi = luminosity;//in pb please - adjust to your likings
1598 fronga 1.45
1599     TCut kPos((mcjzb+">0").c_str());
1600     TCut kNeg((mcjzb+"<0").c_str());
1601     string var( "abs("+mcjzb+")" );
1602    
1603     TCut kcut(cutmass&&cutOSSF&&"pfJetGoodNum>2");
1604     TH1F *hJZBpos = allsamples.Draw("hJZBpos",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
1605 fronga 1.51 kcut&&kPos,mc,simulatedlumi,allsamples.FindSample("DYJets"));
1606 fronga 1.45 TH1F *hJZBneg = allsamples.Draw("hJZBneg",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
1607 fronga 1.51 kcut&&kNeg,mc,simulatedlumi,allsamples.FindSample("DYJets"));
1608 fronga 1.45 hJZBpos->SetLineColor(kBlack);
1609     hJZBneg->SetLineColor(kRed);
1610    
1611     Int_t nbins = 5;
1612     Float_t xmax = 100.;
1613    
1614    
1615     TCanvas *zcan = new TCanvas("zcan","zcan");
1616     zcan->SetLogy(1);
1617    
1618     hJZBpos->Draw("e1");
1619     hJZBneg->Draw("same,hist");
1620     hJZBpos->Draw("same,e1"); // So it's on top...
1621    
1622 fronga 1.51 TLegend *leg = make_legend("MC Z+jets",0.55,0.75,false);
1623 fronga 1.45 leg->AddEntry(hJZBpos,"Observed","pe");
1624     leg->AddEntry(hJZBneg,"Predicted","l");
1625     leg->Draw("same");
1626 fronga 1.51 DrawMCPrelim(simulatedlumi);
1627 fronga 1.45 CompleteSave(zcan,"zjets_prediction");
1628    
1629     TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
1630     hratio->Divide(hJZBneg);
1631    
1632     zcan->SetLogy(0);
1633     hratio->GetYaxis()->SetRangeUser(0,2.5);
1634     hratio->GetYaxis()->SetTitle("Observed/Predicted");
1635     hratio->Draw("e1");
1636    
1637     TLine *top = new TLine(sbg_min,1.25,sbg_max,1.25);
1638     TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
1639     TLine *bottom = new TLine(sbg_min,0.75,sbg_max,0.75);
1640    
1641    
1642     top->SetLineColor(kBlue);top->SetLineStyle(2);
1643     bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
1644     center->SetLineColor(kBlue);
1645    
1646     top->Draw("same");
1647     center->Draw("same");
1648     bottom->Draw("same");
1649    
1650 fronga 1.51 TLegend *leg2 = make_legend("MC Z+jets",0.25,0.75,false);
1651 fronga 1.45 leg2->AddEntry(hratio,"obs / pred","pe");
1652     leg2->AddEntry(bottom,"syst. envelope","l");
1653     leg2->Draw("same");
1654 fronga 1.51 DrawMCPrelim(simulatedlumi);
1655 fronga 1.45 CompleteSave(zcan,"zjets_prediction_ratio");
1656    
1657     delete zcan;
1658 buchmann 1.60 cutWeight=weightbackup;
1659    
1660 fronga 1.45 }
1661    
1662 buchmann 1.30
1663 buchmann 1.11 void test() {
1664 buchmann 1.19
1665 buchmann 1.11 TCanvas *testcanv = new TCanvas("testcanv","testcanv");
1666     testcanv->cd();
1667     switch_overunderflow(true);
1668 buchmann 1.17 TH1F *ptdistr = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
1669 buchmann 1.11 switch_overunderflow(false);
1670     ptdistr->Draw();
1671     testcanv->SaveAs("test.png");
1672 buchmann 1.21 dout << "HELLO there!" << endl;
1673 buchmann 1.19
1674 buchmann 1.11 }