ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.83
Committed: Mon Oct 24 15:05:37 2011 UTC (13 years, 6 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.82: +180 -104 lines
Log Message:
Upgrade from HoneyPot to IceCreamBowl: merged in offpeak stuff, different warning color for frederic, saving to rootfile, only 3 attempts when computing limits and much, much more

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