ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.42
Committed: Mon Jan 21 14:44:22 2013 UTC (12 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.41: +19 -25 lines
Log Message:
New MET plot style

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2    
3     using namespace std;
4    
5 buchmann 1.17 float Get_Met_Z_Prediction(TCut JetCut, float MetCut, int isdata, bool isDYonly);
6    
7 buchmann 1.24 namespace MetPlotsSpace {
8 buchmann 1.28 float Zprediction_Uncertainty=0.2;
9 buchmann 1.41 float OFprediction_Uncertainty=0.07;
10    
11    
12    
13    
14    
15    
16 buchmann 1.30 float Zestimate__data=-1;
17     float Zestimate__data_sys=-1;
18     float Zestimate__data_stat=-1;
19     float Zestimate__mc=-1;
20     float Zestimate__mc_sys=-1;
21     float Zestimate__mc_stat=-1;
22     float Zestimate__dy=-1;
23     float Zestimate__dy_sys=-1;
24     float Zestimate__dy_stat=-1;
25 buchmann 1.24 }
26 buchmann 1.17
27 buchmann 1.30 void ExperimentalMetPrediction(bool QuickRun);
28    
29 fronga 1.36 void makeOneRinoutPlot( TH2F* hrange, Int_t* bins, Int_t nBins, TString var, string name, bool doMC, TCut kCut = "" ) {
30    
31     Float_t systematics = 0.25;
32    
33     // mll settings
34     Int_t nbins = 100;
35     Float_t xmin = 20., xmax = 120.;
36     TCanvas* mycan = new TCanvas("mycan","Canvas");
37     mycan->SetLeftMargin(0.2);
38     mycan->SetLogy(0);
39    
40    
41     TCut kbase("pfJetGoodNum40>1&&pfJetGoodID[0]!=0"&&passtrig&&kCut);
42     TCut kSF("id1==id2");
43     TCut kOF("id1!=id2");
44    
45     // Reference: inclusive selection
46     TCut kZP("pfJetGoodNum40==2");
47     TH1F* h1, *h1OF;
48     if ( !doMC ) {
49     h1 = allsamples.Draw("h1", "mll",nbins,xmin,xmax,"m_{ll}","events",kbase&&kZP&&kSF,data,luminosity);
50     h1OF = allsamples.Draw("h1OF","mll",nbins,xmin,xmax,"m_{ll}","events",kbase&&kZP&&kOF,data,luminosity);
51     } else {
52     h1 = allsamples.Draw("h1", "mll",nbins,xmin,xmax,"m_{ll}","events",kbase&&kZP&&kSF,mc,luminosity,allsamples.FindSample("Z_em"));
53     h1OF = allsamples.Draw("h1OF","mll",nbins,xmin,xmax,"m_{ll}","events",kbase&&kZP&&kOF,mc,luminosity,allsamples.FindSample("Z_em"));
54     }
55    
56     Int_t minBinSR = h1->FindBin(20.);
57     Int_t maxBinSR = h1->FindBin(70.)-1;
58    
59     Int_t minBinZP = h1->FindBin(81.);
60     Int_t maxBinZP = h1->FindBin(101.)-1;
61    
62     dout << "Integrating SR from " << h1->GetBinLowEdge(minBinSR) << " to " << h1->GetBinLowEdge(maxBinSR)+h1->GetBinWidth(maxBinSR) << std::endl;
63     dout << "Integrating ZP from " << h1->GetBinLowEdge(minBinZP) << " to " << h1->GetBinLowEdge(maxBinZP)+h1->GetBinWidth(maxBinZP) << std::endl;
64    
65     // Subtract OF
66     h1->Add(h1OF,-1);
67     h1->SetLineColor(kRed);
68    
69     // Compute ratio
70     Double_t yZP, eyZP, ySR, eySR;
71     ySR = h1->IntegralAndError(minBinSR,maxBinSR,eySR);
72     yZP = h1->IntegralAndError(minBinZP,maxBinZP,eyZP);
73 fronga 1.39 dout << "Ratio: " << ySR/yZP << "+-" << computeRatioError(ySR,eySR,yZP,eyZP) << std::endl;
74 fronga 1.36
75     std::stringstream twoJetsLegend;
76     twoJetsLegend << std::setprecision(1) << std::fixed;
77     twoJetsLegend << "2-jets ratio: (" << ySR/yZP*100. << "#pm" << computeRatioError(ySR,eySR,yZP,eyZP)*100. << "#pm" << systematics*ySR/yZP*100. << ")%";
78    
79     TLine* line = new TLine(hrange->GetXaxis()->GetXmin(),ySR/yZP,hrange->GetXaxis()->GetXmax(),ySR/yZP);
80     line->SetLineColor(kRed);
81     TBox* errorBox = new TBox(hrange->GetXaxis()->GetXmin(),ySR/yZP*(1-systematics),hrange->GetXaxis()->GetXmax(),ySR/yZP*(1+systematics));
82     errorBox->SetFillColor(kCyan);
83     errorBox->SetFillStyle(1001);
84     errorBox->SetLineColor(kWhite);
85    
86     TGraphErrors* ratio = new TGraphErrors(nBins);
87     // Various cuts
88     for ( int ibin = 0; ibin<nBins; ++ibin ) {
89     std::stringstream cut;
90     cut << var << ">=" << bins[ibin];
91     if ( ibin+1<nBins ) cut << "&&" << var << "<" << bins[ibin+1];
92     TCut kadd(cut.str().c_str());
93    
94     TH1F* h2, *h2OF;
95     if ( !doMC ) {
96     h2 = allsamples.Draw("h2", "mll",nbins,xmin,xmax,"var","events",kbase&&kadd&&kSF,data,luminosity);
97     h2OF = allsamples.Draw("h2OF","mll",nbins,xmin,xmax,"var","events",kbase&&kadd&&kOF,data,luminosity);
98     } else {
99     h2 = allsamples.Draw("h2", "mll",nbins,xmin,xmax,"var","events",kbase&&kadd&&kSF,mc,luminosity,allsamples.FindSample("Z_em"));
100     h2OF = allsamples.Draw("h2OF","mll",nbins,xmin,xmax,"var","events",kbase&&kadd&&kOF,mc,luminosity,allsamples.FindSample("Z_em"));
101     }
102     h2->Add(h2OF,-1);
103     h2->SetLineColor(kBlue);
104    
105     ySR = h2->IntegralAndError(minBinSR,maxBinSR,eySR);
106     yZP = h2->IntegralAndError(minBinZP,maxBinZP,eyZP);
107    
108     if ( ibin+1<nBins ) {
109     ratio->SetPoint(ibin,(bins[ibin+1]+bins[ibin])/2.0,ySR/yZP);
110     ratio->SetPointError(ibin,(bins[ibin+1]-bins[ibin])/2.0,computeRatioError(ySR,eySR,yZP,eyZP));
111     } else {
112     Float_t width = ratio->GetErrorX(ibin-1);
113     ratio->SetPoint(ibin,bins[ibin]+width,ySR/yZP);
114     ratio->SetPointError(ibin,width,computeRatioError(ySR,eySR,yZP,eyZP));
115     }
116    
117     dout << "Ratio " << cut.str() << ": " << ySR/yZP << "+-" << computeRatioError(ySR,eySR,yZP,eyZP) << std::endl;
118    
119     h2->Delete();
120     h2OF->Delete();
121    
122     }
123    
124     std::stringstream syserrLegend;
125     syserrLegend << std::setprecision(0) << std::fixed << systematics*100. << "% systematic unc.";
126    
127     hrange->GetYaxis()->SetTitleOffset(1.3);
128     hrange->GetYaxis()->SetDecimals(kTRUE);
129     hrange->Draw();
130     errorBox->Draw();
131     line->Draw();
132     ratio->Draw("P");
133    
134     TLegend* legend = new TLegend(0.25,0.6,0.8,0.9);
135     legend->SetFillStyle(0);
136     legend->SetBorderSize(0);
137     if ( doMC ) legend->AddEntry(ratio,"DY Z+jets MC","lp");
138     else legend->AddEntry(ratio,"Data","lp");
139     legend->AddEntry(line,twoJetsLegend.str().c_str(),"l");
140     legend->AddEntry(errorBox,syserrLegend.str().c_str(),"f");
141     legend->Draw();
142    
143     mycan->RedrawAxis();
144     if (!doMC) DrawPrelim();
145     else DrawMCPrelim();
146    
147     CompleteSave(mycan,"MetPlots/Zlineshape_vs_"+name+(doMC?"_mc_":""));
148    
149     h1->Delete();
150     h1OF->Delete();
151     delete mycan;
152    
153     }
154    
155     int zlineshapeMet(bool doMC=true, string suffix="", float ymax = 0.2, TCut kCut = "" ) {
156    
157     TH2F* hrange = new TH2F("hrange","Range ; MET [GeV] ; Ratio low mass / Z peak",2,-1,61,2,0,ymax);
158     Int_t metBins[] = { 0, 10, 20, 30, 40, 50 };
159     Int_t nMetBins = sizeof(metBins)/sizeof(Int_t);
160     makeOneRinoutPlot( hrange, metBins, nMetBins, "met[4]", "met"+suffix, doMC, kCut );
161     hrange->Delete();
162     return 0;
163    
164     }
165    
166     int zlineshapeJets(bool doMC=true, string suffix="", float ymax = 0.2, TCut kCut = "" ) {
167     TH2F* hrange = new TH2F("hrange","Range ; #(jets) ; Ratio low mass / Z peak",2,1.9,6.1,2,0,ymax);
168     Int_t bins[] = { 2, 3, 4, 5 };
169    
170     Int_t nBins = sizeof(bins)/sizeof(Int_t);
171     makeOneRinoutPlot( hrange, bins, nBins, "pfJetGoodNum40", "njets"+suffix, doMC, kCut );
172     hrange->Delete();
173     return 0;
174    
175     }
176    
177     int zlineshapes(string suffix = "", TCut cut="" ) {
178    
179     dout << "--- Calculating R_in/out" << std::endl;
180     zlineshapeMet(false,suffix,0.2,cut);
181     zlineshapeJets(false,suffix,0.2,cut);
182     zlineshapeMet(true,suffix,0.2,cut);
183     zlineshapeJets(true,suffix,0.2,cut);
184     dout << "--- DONE (Calculating R_in/out)" << std::endl;
185    
186     return 0;
187     }
188    
189 buchmann 1.30 void ExtractScaleFactor(TH1F *mllSF,TH1F *mllOF, THStack* mcMllSF, THStack* mcMllOF, TH1F *prediction, TLegend *leg, string saveasSig, TBox *srbox) {
190     Int_t minbin = mllSF->FindBin(20.);
191     Int_t maxbin = mllSF->FindBin(70.-1);
192    
193     // Get yields in OF region
194     Float_t iDataOF = mllOF->Integral();
195     Float_t iDataOFSR = mllOF->Integral(minbin,maxbin);
196     Float_t iMCOF = 0.0;
197     Float_t iMCOFSR = 0.0;
198     TIter nextOF(mcMllOF->GetHists());
199     TH1F* h;
200     while ( h = (TH1F*)nextOF() ) {
201     iMCOF += h->Integral();
202     iMCOFSR += h->Integral(minbin,maxbin);
203     }
204     Float_t scale = iDataOF/iMCOF;
205    
206     // Re-scale OF
207     nextOF = TIter(mcMllOF->GetHists());
208    
209     while ( h = (TH1F*)nextOF() ) {
210     h->Scale(scale);
211     }
212    
213     nextOF = TIter(mcMllOF->GetHists());
214    
215     // Rescale SF and count in signal region
216 fronga 1.39 dout << "Integrating from " << mllSF->GetBinLowEdge(minbin) << " to " << mllSF->GetBinLowEdge(maxbin)+mllSF->GetBinWidth(maxbin) << std::endl;
217 buchmann 1.30
218     Float_t iDataSFSR = mllSF->Integral(minbin,maxbin);
219     Float_t iMCSFSR = 0.0;
220     TIter nextSF = TIter(mcMllSF->GetHists());
221     while ( h = (TH1F*)nextSF() ) {
222     h->Scale(scale);
223     iMCSFSR += h->Integral(minbin,maxbin);
224     }
225    
226     nextSF = TIter(mcMllSF->GetHists());
227     while ( h = (TH1F*)nextSF() ) {
228     iMCSFSR += h->Integral(minbin,maxbin);
229     }
230     mcMllSF->Modified();
231    
232     TPad* rcan2 = new TPad("rcan2","rcan2",0,0,1,1);
233     rcan2->cd();
234     mllSF->Draw();
235 fronga 1.40 mcMllSF->Draw("histo,same");
236 buchmann 1.30 prediction->Draw("histo,same");
237     mllSF->Draw("same");
238     DrawPrelim();
239     stringstream leghead;
240     leghead << "MC scaled by " << std::setprecision(2) << scale << "";
241 fronga 1.39 dout << "SCALE: " << scale << endl;
242 buchmann 1.30 TH1F *histo = new TH1F("histo","histo",1,0,1);histo->SetLineColor(kWhite);
243     leg->AddEntry(histo,leghead.str().c_str(),"l");
244     leg->Draw();
245     srbox->Draw();
246     stringstream saveasSig2;
247     saveasSig2 << saveasSig << "__mcScaled";
248     rcan2->Update();
249     save_with_ratio( mllSF, *mcMllSF, rcan2, saveasSig2.str() );
250 buchmann 1.32
251     // restore original stacks
252     nextOF = TIter(mcMllOF->GetHists());
253    
254     while ( h = (TH1F*)nextOF() ) {
255     h->Scale(1/scale);
256     }
257    
258     nextSF = TIter(mcMllSF->GetHists());
259     while ( h = (TH1F*)nextSF() ) {
260     h->Scale(1/scale);
261     }
262     mcMllSF->Modified();
263     mcMllOF->Modified();
264    
265 buchmann 1.30 }
266    
267    
268    
269    
270    
271    
272    
273    
274    
275 buchmann 1.1 TGraphErrors* MakeErrorGraph(TH1F *histo) {
276    
277     float dx[histo->GetNbinsX()];
278     float dy[histo->GetNbinsX()];
279     float x[histo->GetNbinsX()];
280     float y[histo->GetNbinsX()];
281     for(int i=1;i<=histo->GetNbinsX();i++) {
282     x[i-1]=histo->GetBinCenter(i);
283     y[i-1]=histo->GetBinContent(i);
284     if(i>1) dx[i-1]=(histo->GetBinCenter(i)-histo->GetBinCenter(i-1))/2.0;
285     else dx[i-1]=(histo->GetBinCenter(i+1)-histo->GetBinCenter(i))/2.0;
286     dy[i-1]=histo->GetBinError(i);
287     }
288    
289     TGraphErrors *gr = new TGraphErrors(histo->GetNbinsX(),x,y,dx,dy);
290     gr->SetFillColor(TColor::GetColor("#2E9AFE"));
291     return gr;
292     }
293 buchmann 1.41
294     TGraphErrors* MakeErrorGraphSystematicAndStatistical(TH1F *ofpred, TH1F *sfpred, TH1F *prediction, TH1F *SystHisto) {
295 buchmann 1.1
296 buchmann 1.41 float dx[ofpred->GetNbinsX()];
297     float dy[ofpred->GetNbinsX()];
298     float x[ofpred->GetNbinsX()];
299     float y[ofpred->GetNbinsX()];
300     for(int i=1;i<=ofpred->GetNbinsX();i++) {
301     x[i-1]=prediction->GetBinCenter(i);
302     y[i-1]=prediction->GetBinContent(i);
303     if(i>1) dx[i-1]=(prediction->GetBinCenter(i)-prediction->GetBinCenter(i-1))/2.0;
304     else dx[i-1]=(prediction->GetBinCenter(i+1)-prediction->GetBinCenter(i))/2.0;
305     if(ofpred->GetBinCenter(i)>20 && ofpred->GetBinCenter(i)<70) {
306     //need to increase uncertainty by 5% due to extrapolation
307     dy[i-1] = (MetPlotsSpace::Zprediction_Uncertainty+0.05)*(MetPlotsSpace::Zprediction_Uncertainty+0.05)*sfpred->GetBinContent(i)*sfpred->GetBinContent(i); //systematic for Z+Jets prediction
308     } else {
309     dy[i-1] = MetPlotsSpace::Zprediction_Uncertainty*MetPlotsSpace::Zprediction_Uncertainty*sfpred->GetBinContent(i)*sfpred->GetBinContent(i); //systematic for Z+Jets prediction
310     }
311     dy[i-1]+= MetPlotsSpace::OFprediction_Uncertainty*MetPlotsSpace::OFprediction_Uncertainty* ofpred->GetBinContent(i) * ofpred->GetBinContent(i); //systematic for OF prediction
312     float sys=sqrt(dy[i-1])/prediction->GetBinContent(i);
313     if(prediction->GetBinContent(i)==0) sys=0.0;
314     if(sys!=sys || sys<0) sys=0;
315     SystHisto->SetBinContent(i,sys);
316     dy[i-1]+= prediction->GetBinError(i) * prediction->GetBinError(i); // plus statistical!
317     dy[i-1]=sqrt(dy[i-1]);
318     }
319    
320     TGraphErrors *gr = new TGraphErrors(ofpred->GetNbinsX(),x,y,dx,dy);
321     gr->SetFillColor(TColor::GetColor("#2E9AFE"));//blue
322     // gr->SetFillColor(TColor::GetColor("#FF8000"));//orange
323     return gr;
324     }
325    
326    
327 fronga 1.22 void ProduceMetPlotsWithCut(TCut cut, string name, float cutat, int njets, bool doMC = false, float ymax = 80 ) {
328 buchmann 1.30
329     bool UseSpecialZprediction=false;
330    
331 buchmann 1.42 write_warning(__FUNCTION__,"JZB estimate has been deactivated!!!");
332     /*
333 buchmann 1.30 if(cutat==100 && name=="") {
334     UseSpecialZprediction=true;
335     bool ReRunEstimate=false;
336     //need to check if the results have already been stored; if not, need to get the estimate!
337     if(MetPlotsSpace::Zestimate__data<0) ReRunEstimate=true;
338     if(MetPlotsSpace::Zestimate__data_stat<0) ReRunEstimate=true;
339     if(MetPlotsSpace::Zestimate__data_sys<0) ReRunEstimate=true;
340     if(MetPlotsSpace::Zestimate__mc<0) ReRunEstimate=true;
341     if(MetPlotsSpace::Zestimate__mc_stat<0) ReRunEstimate=true;
342     if(MetPlotsSpace::Zestimate__mc_sys<0) ReRunEstimate=true;
343     if(MetPlotsSpace::Zestimate__dy<0) ReRunEstimate=true;
344     if(MetPlotsSpace::Zestimate__dy_stat<0) ReRunEstimate=true;
345     if(MetPlotsSpace::Zestimate__dy_sys<0) ReRunEstimate=true;
346 fronga 1.39 dout << "****************** About to do Z prediction " << endl;
347 buchmann 1.30 if(ReRunEstimate) ExperimentalMetPrediction(true);//doing quick run (i.e. only data)
348 fronga 1.39 dout << "****************** Done predicting the Z " << endl;
349 buchmann 1.42 }*/
350 fronga 1.16
351 buchmann 1.41
352 buchmann 1.1 TCanvas *tcan = new TCanvas("tcan","tcan");
353 fronga 1.39 dout << "Doing met plots" << endl;
354 buchmann 1.2 stringstream MetBaseCuts;
355 fronga 1.7 MetBaseCuts << "met[4]>" << cutat << "&&" << cut.GetTitle();
356     stringstream snjets;
357     snjets << njets;
358 buchmann 1.2 TCut MetBaseCut(MetBaseCuts.str().c_str());
359 fronga 1.10 TCut nJetsSignal(PlottingSetup::basicqualitycut&&("pfJetGoodNum40>="+snjets.str()).c_str());
360 fronga 1.36 TCut nJetsControl(PlottingSetup::basiccut&&"met[4]>100&&met[4]<150&&pfJetGoodID[0]!=0&&pfJetGoodNum40==2"); // Common CR (modulo lepton selection)
361 fronga 1.39 //TCut nJetsControl(PlottingSetup::basiccut&&"met[4]>75&&met[4]<150&&pfJetGoodNumBtag30>0&&pfJetGoodID[0]!=0&&pfJetGoodNum40==2"); // Alternative CR
362 fronga 1.16
363 buchmann 1.1 //compute SF / OF rate in (CR1+CR2), should give 0.941 +/- 0.05
364 fronga 1.7
365     // Create histograms
366 fronga 1.9 //int nbins = 30;
367 buchmann 1.41 int nbins = 60-3;
368     float xmin=15., xmax = 300.;
369 buchmann 1.17 TH1F *mllsigEE = allsamples.Draw("mllsigEE","mll",nbins,xmin,xmax,"m_{ee} [GeV]", "events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal&&"id1==0"),data,PlottingSetup::luminosity);
370     TH1F *mllsigMM = allsamples.Draw("mllsigMM","mll",nbins,xmin,xmax,"m_{#mu#mu} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal&&"id1==1"),data,PlottingSetup::luminosity);
371 fronga 1.22 TH1F *mllscon = allsamples.Draw("mllscon","mll",nbins,xmin,xmax,"m_{ll} [GeV]", "events",TCut(cutOSSF&&cut&&nJetsControl),data,PlottingSetup::luminosity);
372 fronga 1.7 TH1F *mllOsig = allsamples.Draw("mllOsig", "mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSOF&&MetBaseCut&&nJetsSignal),data,PlottingSetup::luminosity);
373 fronga 1.22 TH1F *mllOscon = allsamples.Draw("mllOscon","mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSOF&&cut&&nJetsControl),data,PlottingSetup::luminosity);
374 buchmann 1.37 TH1F *ptsig = allsamples.Draw("ptsig", "pt",40,xmin,400,"m_{T}^{ll} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal),data,PlottingSetup::luminosity);
375     TH1F *ptOsig = allsamples.Draw("ptOsig", "pt",40,xmin,400,"p_{T}^{ll} [GeV]","events",TCut(cutOSOF&&MetBaseCut&&nJetsSignal),data,PlottingSetup::luminosity);
376 fronga 1.7
377 fronga 1.8 TH1F* mllsig = (TH1F*)mllsigEE->Clone("mllsig");
378     mllsig->Add(mllsigMM);
379     mllsig->GetXaxis()->SetTitle("m_{ll} [GeV]");
380    
381 buchmann 1.37 THStack *mcMllsig, *mcMllsigEE,*mcMllsigMM,*mcMllscon,*mcMllsconEE,*mcMllsconMM, *mcMllOsig, *mcMllOscon, *mcptsig, *mcptOsig;
382 fronga 1.7 if ( doMC ) {
383     name += "_mc";
384 fronga 1.8 mcMllsig = new THStack(allsamples.DrawStack("mcMllsig","mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal),mc,PlottingSetup::luminosity));
385     mcMllsigEE = new THStack(allsamples.DrawStack("mcMllsigEE","mll",nbins,xmin,xmax,"m_{ee} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal&&"id1==0"),mc,PlottingSetup::luminosity));
386     mcMllsigMM = new THStack(allsamples.DrawStack("mcMllsigMM","mll",nbins,xmin,xmax,"m_{#mu#mu} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal&&"id1==1"),mc,PlottingSetup::luminosity));
387 fronga 1.22 mcMllscon = new THStack(allsamples.DrawStack("mcMllscon","mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSSF&&cut&&nJetsControl),mc,PlottingSetup::luminosity));
388 fronga 1.8 mcMllOsig = new THStack(allsamples.DrawStack("mcMllOsig","mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSOF&&MetBaseCut&&nJetsSignal),mc,PlottingSetup::luminosity));
389 fronga 1.22 mcMllOscon= new THStack(allsamples.DrawStack("mcMllOscon","mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSOF&&cut&&nJetsControl),mc,PlottingSetup::luminosity));
390 buchmann 1.37 mcptsig = new THStack(allsamples.DrawStack("mcptsig", "pt",40,xmin,400,"m_{T}^{ll} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal),mc,PlottingSetup::luminosity));
391     mcptOsig = new THStack(allsamples.DrawStack("mcptOsig", "pt",40,xmin,400,"p_{T}^{ll} [GeV]","events",TCut(cutOSOF&&MetBaseCut&&nJetsSignal),mc,PlottingSetup::luminosity));
392 fronga 1.7 }
393 fronga 1.8
394 buchmann 1.1 mllOsig->SetLineColor(kRed);
395     mllOscon->SetLineColor(kRed);
396    
397 buchmann 1.28 TH1F *zlineshape = allsamples.Draw("zlineshape","mll",nbins,xmin,xmax,"m_{ll} (GeV)","events",cutOSSF&&TCut("pfJetGoodNum40==2")&&cut,data,PlottingSetup::luminosity);
398     TH1F *Ozlineshape = allsamples.Draw("Ozlineshape","mll",nbins,xmin,xmax,"m_{ll} (GeV)","events",cutOSOF&&TCut("pfJetGoodNum40==2")&&cut,data,PlottingSetup::luminosity);
399     zlineshape->Add(Ozlineshape,-1);
400 buchmann 1.13 TH1F *zlineshapeControl = (TH1F*)zlineshape->Clone("zlineshapeControl");
401 buchmann 1.21 // TH1F *zlineshapeFINE = allsamples.Draw("zlineshapeFINE","mll",50*nbins,xmin,xmax,"m_{ll} (GeV)","events",cutOSSF&&TCut("pfJetGoodNum40==1")&&cut,data,PlottingSetup::luminosity);
402     //
403     // float scalefactor = Get_Met_Z_Prediction(nJetsSignal,cutat, data, false) / (zlineshapeFINE->Integral(zlineshapeFINE->FindBin(91.1-20),zlineshapeFINE->FindBin(91.1+20)));
404     // float scalefactor_Control = Get_Met_Z_Prediction(nJetsControl,cutat, data, false) / (zlineshapeFINE->Integral(zlineshapeFINE->FindBin(91.1-20),zlineshapeFINE->FindBin(91.1+20)));
405     // delete zlineshapeFINE;
406    
407    
408     Int_t scaleBinLow = mllsig->FindBin(86);
409     Int_t scaleBinHigh = mllsig->FindBin(94);
410     float scalefactor = (mllsig->Integral(scaleBinLow,scaleBinHigh)-mllOsig->Integral(scaleBinLow,scaleBinHigh));
411     scalefactor /= zlineshape->Integral(scaleBinLow,scaleBinHigh);
412 buchmann 1.30
413 buchmann 1.21 float scalefactor_Control = (mllscon->Integral(scaleBinLow,scaleBinHigh)-mllOscon->Integral(scaleBinLow,scaleBinHigh));
414     scalefactor_Control /= zlineshapeControl->Integral(scaleBinLow,scaleBinHigh);
415    
416 fronga 1.39 dout << "Bins for scaling : " << scaleBinLow << " : " << scaleBinHigh << endl;
417 buchmann 1.30
418     if(UseSpecialZprediction) {
419 buchmann 1.33 scaleBinLow = mllsig->FindBin(81);
420     scaleBinHigh = mllsig->FindBin(101);
421 buchmann 1.30 scalefactor = MetPlotsSpace::Zestimate__data/ (zlineshape->Integral(scaleBinLow,scaleBinHigh));
422 fronga 1.39 dout << "Dividing: " << MetPlotsSpace::Zestimate__data << " by " << (zlineshape->Integral(scaleBinLow,scaleBinHigh)) << endl;
423 buchmann 1.30 write_warning(__FUNCTION__,"Not using JZB prediction for control region!");
424     }
425    
426 fronga 1.39 dout << "Scale factors : " << scalefactor << " : " << scalefactor_Control << endl;
427     if(UseSpecialZprediction) dout << " NOTE: Used JZB prediction for scaling! (Bins )" << scaleBinLow << " to " << scaleBinHigh << endl;
428 buchmann 1.17
429 buchmann 1.3 zlineshape->Scale(scalefactor);
430 buchmann 1.30
431 buchmann 1.3 zlineshape->SetLineColor(kBlue);
432     zlineshape->SetLineStyle(2);
433    
434 buchmann 1.30 if(UseSpecialZprediction) {
435     //need to update each bin with correct stat uncert
436     float relDYerr = MetPlotsSpace::Zestimate__data_stat/MetPlotsSpace::Zestimate__data;
437     for(int iz=1;iz<=zlineshape->GetNbinsX();iz++) {
438     float bincontent=zlineshape->GetBinContent(iz);
439     float binerror=zlineshape->GetBinError(iz);
440     float finalerr=0;
441     if(bincontent>0) finalerr+= (binerror/bincontent) * (binerror/bincontent);
442     if(MetPlotsSpace::Zestimate__data>0) finalerr+= relDYerr*relDYerr;
443     finalerr=bincontent * TMath::Sqrt(finalerr);
444     zlineshape->SetBinError(iz,finalerr);
445     }
446     }
447    
448 buchmann 1.13 zlineshapeControl->Scale(scalefactor_Control);
449     zlineshapeControl->SetLineColor(kBlue);
450     zlineshapeControl->SetLineStyle(2);
451    
452 buchmann 1.3 TH1F *subtracted = (TH1F*)mllsig->Clone("subtracted");
453 buchmann 1.13 TH1F *subtractedControl = (TH1F*)mllscon->Clone("subtractedControl");
454 buchmann 1.3 TH1F *baseline = (TH1F*)mllOsig->Clone("baseline");
455 buchmann 1.13 TH1F *baselineControl = (TH1F*)mllOscon->Clone("baselineControl");
456 buchmann 1.3 for(int i=1;i<=subtracted->GetNbinsX();i++) {
457     subtracted->SetBinContent(i,mllsig->GetBinContent(i)-mllOsig->GetBinContent(i));
458 buchmann 1.13 subtractedControl->SetBinContent(i,mllscon->GetBinContent(i)-mllOscon->GetBinContent(i));
459 buchmann 1.3 baseline->SetBinContent(i,0);
460 buchmann 1.13 baselineControl->SetBinContent(i,0);
461 buchmann 1.3 }
462    
463     TH1F *prediction = (TH1F*)mllOsig->Clone("prediction");
464     prediction->Add(zlineshape);
465     prediction->SetLineColor(TColor::GetColor("#CF35CA"));
466 fronga 1.7
467     TH1F *control_prediction = (TH1F*)mllOscon->Clone("control_prediction");
468     control_prediction->SetLineColor(TColor::GetColor("#CF35CA"));
469 buchmann 1.42
470     prediction->SetLineColor(TColor::GetColor("#cc0066"));
471     mllOsig->SetLineColor(TColor::GetColor("#0000cc"));
472    
473     mllOsig->SetLineStyle(2);
474     zlineshape->SetLineColor(TColor::GetColor("#006600"));
475     zlineshape->SetFillColor(TColor::GetColor("#006600"));
476     zlineshape->SetFillStyle(3002); // light dots, not crushing other information
477     mllOsig->SetLineWidth(2);
478     prediction->SetLineWidth(2);
479     zlineshape->SetLineWidth(2);
480    
481    
482 fronga 1.7
483     // FIX Y RANGE TO EASE COMPARISON
484 fronga 1.22 mllsig->SetMaximum(ymax);
485 buchmann 1.30 float PreviousMinimum=mllsig->GetMinimum();
486     mllsig->SetMinimum(0);
487 fronga 1.22 mllsigEE->SetMaximum(ymax);
488     mllsigMM->SetMaximum(ymax);
489     mllOsig->SetMaximum(ymax);
490     mllOscon->SetMaximum(ymax);
491     subtracted->SetMaximum(60);
492     subtracted->SetMinimum(-30);
493     subtractedControl->SetMaximum(65);
494     subtractedControl->SetMinimum(-30);
495 fronga 1.7
496 buchmann 1.3
497 fronga 1.7 // 1.- Signal region comparison
498 buchmann 1.30 TBox *srbox = new TBox(20,0,70,mllsig->GetMaximum());
499 buchmann 1.1 srbox->SetFillStyle(0);
500     srbox->SetLineColor(TColor::GetColor("#298A08"));
501     srbox->SetLineWidth(3);
502 buchmann 1.23
503 fronga 1.10
504 buchmann 1.2 stringstream MetHeader;
505 fronga 1.19 MetHeader << "N_{j}#geq" << snjets.str() << ", MET>" << cutat << " GeV";
506     stringstream MetHeaderCon;
507 fronga 1.39 // MetHeaderCon << "N_{j}=2, N_{b}>0, 75<MET<150 GeV";
508 fronga 1.36 MetHeaderCon << "N_{j}=2, 100<MET<150 GeV";
509 fronga 1.10 stringstream saveasSig;
510     saveasSig << "MetPlots/mll_sig" << cutat << "__" << name;
511 buchmann 1.41
512     TLegend* leg;
513    
514    
515    
516     srbox->SetLineColor(TColor::GetColor("#00cc33"));
517 fronga 1.10
518 buchmann 1.41
519 fronga 1.10 if ( !doMC ) {
520 fronga 1.39 TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
521     rcan->cd();
522 fronga 1.10 mllsig->Draw();
523     TGraphErrors *stat3j = MakeErrorGraph(prediction);
524     stat3j->Draw("2,same");
525     mllOsig->Draw("histo,same");
526     zlineshape->Draw("histo,same");
527     prediction->Draw("histo,same");
528     mllsig->Draw("same");
529     DrawPrelim();
530     leg = make_legend();
531 fronga 1.19 leg->SetX1(0.52);
532     leg->SetHeader(MetHeader.str().c_str());
533 fronga 1.10 leg->AddEntry(mllsig,"Data","PL");
534     leg->AddEntry(prediction,"All bg prediction","L");
535 fronga 1.7 leg->AddEntry(mllOsig,"bg without Z","L");
536 buchmann 1.30 if(!UseSpecialZprediction) leg->AddEntry(zlineshape,"Z lineshape","L");
537     else leg->AddEntry(zlineshape,"bg with Z (JZB)","L");
538 fronga 1.7 leg->AddEntry(stat3j,"stat. uncert.","F");
539 fronga 1.10 leg->AddEntry(srbox,"SR","F");
540     leg->Draw();
541     srbox->Draw();
542 fronga 1.39 save_with_ratio( mllsig, prediction, rcan, saveasSig.str() );
543 buchmann 1.41
544     //now also add systematic as a nice touch :-)
545     TPad* rcan2 = new TPad("rcan2","rcan2",0,0,1,1);
546    
547     rcan2->cd();
548     mllsig->Draw();
549     TH1F *SystHisto = (TH1F*)prediction->Clone("SystHisto");
550     TGraphErrors *stat3jS = MakeErrorGraphSystematicAndStatistical(mllOsig,zlineshape,prediction,SystHisto);
551     stat3jS->Draw("2,same");
552     zlineshape->Draw("histo,same");
553     prediction->Draw("histo,same");
554     mllsig->Draw("same");
555     DrawPrelim();
556     leg = make_legend();
557     leg->SetX1(0.52);
558     leg->SetHeader(MetHeader.str().c_str());
559     leg->AddEntry(mllsig,"Data","PL");
560     leg->AddEntry(prediction,"Total backgrounds","L");
561     if(!UseSpecialZprediction) leg->AddEntry(zlineshape,"DY (scaled) ","FL");
562     else leg->AddEntry(zlineshape,"DY (JZB)","L");
563     leg->AddEntry(stat3jS,"Total uncert.","F");
564     leg->Draw();
565    
566     save_with_ratio_and_sys_band( mllsig, prediction, rcan2, (saveasSig.str()+"__WithSys"), false, false, "data/pred",SystHisto );
567    
568     mllsig->GetYaxis()->SetRangeUser(0.1,ymax);
569    
570     TPad *rcan3 = new TPad("rcan3","rcan3",0,0,1,1);
571     rcan3->cd();
572     rcan3->SetLogy(1);
573     rcan3->cd(); //need to switch back to pad (otherwise it's blank for some reason)
574     mllsig->Draw();
575     stat3jS->Draw("2,same");
576     zlineshape->Draw("histo,same");
577     prediction->Draw("histo,same");
578     mllsig->Draw("same");
579     DrawPrelim();
580     save_with_ratio_and_sys_band( mllsig, prediction, rcan3, (saveasSig.str()+"__WithSys___LOG"), false, false, "data/pred",SystHisto );
581    
582 fronga 1.10 } else {
583 fronga 1.19
584 fronga 1.10 TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
585     rcan->cd();
586     mllsig->Draw();
587 fronga 1.39 mcMllsig->Draw("same,hist");
588 fronga 1.10 prediction->Draw("histo,same");
589     mllsig->Draw("same");
590     DrawPrelim();
591     leg = allsamples.allbglegend();
592 fronga 1.19 leg->SetHeader(MetHeader.str().c_str());
593     leg->SetX1(0.52);
594 fronga 1.10 leg->AddEntry(prediction,"All bg prediction","L");
595     leg->AddEntry(srbox,"SR","F");
596     leg->Draw();
597     srbox->Draw();
598     save_with_ratio( mllsig, *mcMllsig, rcan, saveasSig.str() );
599 buchmann 1.30
600     ExtractScaleFactor(mllsig,mllOsig,mcMllsig,mcMllOsig,prediction,leg,saveasSig.str(),srbox);
601 fronga 1.7 }
602 buchmann 1.1
603 fronga 1.8 // 1b. MC: split ee and mumu
604     if ( doMC ) {
605 fronga 1.10 TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
606     rcan->cd();
607 fronga 1.8 mllsigEE->Draw();
608 fronga 1.39 mcMllsigEE->Draw("same,hist");
609 fronga 1.8 mllsigEE->Draw("same");
610     DrawPrelim();
611     leg->Draw();
612     srbox->Draw();
613 fronga 1.10 save_with_ratio( mllsigEE, *mcMllsigEE,rcan->cd(),saveasSig.str()+"_ee" );
614 fronga 1.8
615 fronga 1.10 rcan = new TPad("rcan","rcan",0,0,1,1);
616     rcan->cd();
617 fronga 1.8 mllsigMM->Draw();
618 fronga 1.40 mcMllsigMM->Draw("histo,same");
619 fronga 1.8 mllsigMM->Draw("same");
620     DrawPrelim();
621     leg->Draw();
622     srbox->Draw();
623 fronga 1.10 save_with_ratio( mllsigMM, *mcMllsigMM,rcan,saveasSig.str()+"_mm" );
624 fronga 1.8 }
625 fronga 1.14
626     // 1c. MC: compare of and sf
627     if ( doMC ) {
628     TH1F* hMcMllsig = CollapseStack( *mcMllsig);
629 fronga 1.15 leg = allsamples.allbglegend("");
630 fronga 1.19 leg->SetHeader(MetHeader.str().c_str());
631 fronga 1.15 // Change "Data" label by hand
632     ((TLegendEntry*)leg->GetListOfPrimitives()->At(0))->SetLabel("Same-flavor (MC)");
633 fronga 1.14 TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
634     rcan->cd();
635 fronga 1.22 hMcMllsig->SetMaximum(ymax);
636 fronga 1.14 hMcMllsig->Draw("E");
637     mcMllOsig->Draw("same,hist");
638     hMcMllsig->Draw("same,E");
639     DrawMCPrelim();
640 fronga 1.19 leg->SetX1(0.52);
641 fronga 1.14 leg->AddEntry(srbox,"SR","F");
642     leg->Draw();
643     srbox->Draw();
644     save_with_ratio( hMcMllsig, *mcMllOsig, rcan, saveasSig.str()+"_mconly");
645    
646     }
647 buchmann 1.1
648 fronga 1.7 // 2.- Signal region comparison - LOG scale
649 fronga 1.10 if ( !doMC ) {
650     tcan->cd();
651     mllsig->SetMinimum(0.2); // FIX Y RANGE TO EASE COMPARISON
652     //mllsig->SetMaximum(mllsig->GetMaximum()*4.0);
653     srbox->SetY2(mllsig->GetMaximum());
654     tcan->SetLogy(1);
655     stringstream saveasSig2;
656     saveasSig2 << "MetPlots/mll_sig_ZLINESHAPE_" << cutat << "__" << name;
657    
658     CompleteSave(tcan,saveasSig2.str());
659     tcan->SetLogy(0);
660     }
661 buchmann 1.1
662 fronga 1.7
663     // 3.- Signal region, background subtracted
664 fronga 1.8 if ( !doMC ) {
665 fronga 1.10 tcan->cd();
666 buchmann 1.13 for(int i=1;i<=subtracted->GetNbinsX();i++) {
667 fronga 1.8 subtracted->SetBinContent(i,subtracted->GetBinContent(i)-zlineshape->GetBinContent(i));
668 buchmann 1.13 subtractedControl->SetBinContent(i,subtractedControl->GetBinContent(i)-zlineshapeControl->GetBinContent(i));
669 fronga 1.8 }
670 buchmann 1.3
671 fronga 1.8 TGraphErrors *subtrerr = MakeErrorGraph(baseline);
672     subtracted->Draw();
673     subtrerr->Draw("2,same");
674     subtracted->Draw("same");
675     DrawPrelim();
676     TLegend *DiffLeg = make_legend();
677 fronga 1.22 DiffLeg->SetX1(0.4);
678 fronga 1.8 DiffLeg->SetFillStyle(0);
679 fronga 1.19 DiffLeg->SetHeader(MetHeader.str().c_str());
680 fronga 1.8 DiffLeg->AddEntry(subtracted,"observed - predicted","PL");
681 fronga 1.19 DiffLeg->AddEntry(subtrerr,"stat. uncert","F");
682 fronga 1.8 DiffLeg->AddEntry((TObject*)0,"","");
683     DiffLeg->AddEntry((TObject*)0,"","");
684     DiffLeg->Draw();
685    
686     stringstream saveasSigSub;
687     saveasSigSub << "MetPlots/mll_sig_SUBTRACTED_" << cutat << "__" << name;
688    
689 fronga 1.22 //CompleteSave(tcan,saveasSigSub.str());
690 buchmann 1.13
691     // 3a.- Control region, background subtracted
692     TGraphErrors *subtrerrControl = MakeErrorGraph(baselineControl);
693     subtractedControl->Draw();
694     subtrerrControl->Draw("2,same");
695     subtractedControl->Draw("same");
696     DrawPrelim();
697 fronga 1.19 DiffLeg->SetHeader(MetHeaderCon.str().c_str());
698 buchmann 1.13 DiffLeg->Draw();
699     saveasSigSub.str("");
700 fronga 1.16 saveasSigSub << "MetPlots/mll_con_SUBTRACTED_" << cutat << "__" << name;
701 fronga 1.22 //CompleteSave(tcan,saveasSigSub.str());
702 buchmann 1.13
703    
704    
705 fronga 1.8 // 4.- Signal region, background subtracted, errors added in quadrature
706     TGraphErrors *subtrerr2 = (TGraphErrors*)subtrerr->Clone("subtrerr2");
707 buchmann 1.13 for(int i=1;i<=subtrerr2->GetN();i++) {
708     subtrerr2->SetPoint(i-1,subtracted->GetBinCenter(i),subtracted->GetBinContent(i));
709     subtrerr2->SetPointError(i-1,subtrerr2->GetErrorX(i),TMath::Sqrt(subtrerr2->GetErrorY(i)*subtrerr2->GetErrorY(i)+subtracted->GetBinError(i)*subtracted->GetBinError(i)));
710 fronga 1.8 }
711     TLine* l = new TLine(subtracted->GetBinLowEdge(1),0.,subtracted->GetBinLowEdge(subtracted->GetNbinsX()-1)+subtracted->GetBinWidth(1),0.);
712     l->SetLineWidth(subtracted->GetLineWidth());
713     subtracted->Draw();
714     subtrerr2->Draw("2,same");
715     l->Draw("same");
716     subtracted->Draw("same");
717     DrawPrelim();
718     TLegend *DiffLeg2 = make_legend();
719 fronga 1.22 DiffLeg2->SetX1(0.4);
720 fronga 1.19 DiffLeg2->SetHeader(MetHeader.str().c_str());
721 fronga 1.8 DiffLeg2->SetFillStyle(0);
722     DiffLeg2->AddEntry(subtracted,"observed - predicted","PL");
723 fronga 1.19 DiffLeg2->AddEntry(subtrerr2,"stat. uncert","F");
724 fronga 1.8 DiffLeg2->AddEntry((TObject*)0,"","");
725     DiffLeg2->AddEntry((TObject*)0,"","");
726     DiffLeg2->Draw();
727    
728     stringstream saveasSigSub2;
729     saveasSigSub2 << "MetPlots/mll_sig_SUBTRACTED_quadr_" << cutat << "__" << name;
730 fronga 1.5
731 fronga 1.8 CompleteSave(tcan,saveasSigSub2.str());
732 fronga 1.5
733 buchmann 1.13
734    
735     //4a.- Control region, background subtracted, errors added in quadrature
736     TGraphErrors *subtrerr2Control = (TGraphErrors*)subtrerrControl->Clone("subtrerr2Control");
737     for(int i=1;i<=subtrerr2Control->GetN();i++) {
738     subtrerr2Control->SetPoint(i-1,subtractedControl->GetBinCenter(i),subtractedControl->GetBinContent(i));
739     float width=subtrerr2Control->GetErrorX(i);
740     if(i==subtrerr2Control->GetN()) width=subtrerr2Control->GetErrorX(i-1);
741     subtrerr2Control->SetPointError(i-1,width,TMath::Sqrt(subtrerr2Control->GetErrorY(i)*subtrerr2Control->GetErrorY(i)+subtractedControl->GetBinError(i)*subtractedControl->GetBinError(i)));
742     }
743     TLine* lControl = new TLine(subtractedControl->GetBinLowEdge(1),0.,subtractedControl->GetBinLowEdge(subtractedControl->GetNbinsX()-1)+subtractedControl->GetBinWidth(1),0.);
744     lControl->SetLineWidth(subtractedControl->GetLineWidth());
745     subtractedControl->Draw();
746     subtrerr2Control->Draw("2,same");
747     lControl->Draw("same");
748     subtractedControl->Draw("same");
749     DrawPrelim();
750 fronga 1.22 DiffLeg2->SetHeader(MetHeaderCon.str().c_str());
751 buchmann 1.13 DiffLeg2->Draw();
752    
753     saveasSigSub2.str("");
754 fronga 1.16 saveasSigSub2 << "MetPlots/mll_con_SUBTRACTED_quadr_" << cutat << "__" << name;
755 buchmann 1.13
756     CompleteSave(tcan,saveasSigSub2.str());
757    
758 fronga 1.8 delete DiffLeg;
759     delete DiffLeg2;
760 buchmann 1.13
761 fronga 1.8 } // !doMC
762 buchmann 1.3
763    
764 fronga 1.7 // 5.- Control region comparison
765 fronga 1.16 // scalefactor = (mllscon->Integral(scaleBinLow,scaleBinHigh)-mllOscon->Integral(scaleBinLow,scaleBinHigh));
766     // scalefactor /= zlineshape->Integral(scaleBinLow,scaleBinHigh);
767     // zlineshape->Scale(scalefactor);
768     control_prediction->Add(zlineshapeControl);
769    
770 fronga 1.22 control_prediction->SetMaximum(ymax); // FIX MAXIMUM TO EASE COMPARISON
771 buchmann 1.37 control_prediction->SetMinimum(0);
772 fronga 1.7
773 buchmann 1.37 TBox *cr1box = new TBox(20,0,70,control_prediction->GetMaximum());
774 buchmann 1.1 cr1box->SetFillStyle(0);
775     cr1box->SetLineColor(TColor::GetColor("#0404B4"));
776     cr1box->SetLineWidth(3);
777    
778 fronga 1.14 TBox *cr2box = new TBox(120,0,xmax,control_prediction->GetMaximum());
779 buchmann 1.1 cr2box->SetFillStyle(0);
780     cr2box->SetLineColor(TColor::GetColor("#0404B4"));
781     cr2box->SetLineWidth(3);
782     cr2box->SetLineStyle(2);
783    
784 fronga 1.10 stringstream saveasCon;
785     saveasCon << "MetPlots/mll_con" << cutat << "__" << name;
786    
787 fronga 1.7 TLegend *legc;
788 fronga 1.10 //control_prediction->GetYaxis()->SetRangeUser(0,control_prediction->GetMaximum()*1.3);
789     if ( !doMC ) {
790 fronga 1.39 TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
791     rcan->cd();
792 buchmann 1.41 Color_t control_prediction_color = control_prediction->GetLineColor();
793     int LineWidth = control_prediction->GetLineWidth();
794     control_prediction->SetLineColor(TColor::GetColor("#FF4000"));
795     control_prediction->SetLineWidth(2);
796    
797     TH1F *ControlSystHisto = (TH1F*)control_prediction->Clone("SystHisto");
798     TGraphErrors *stat3jS = MakeErrorGraphSystematicAndStatistical(mllOscon,zlineshapeControl,control_prediction,ControlSystHisto);
799 fronga 1.10 control_prediction->Draw("hist");
800 buchmann 1.41 stat3jS->Draw("2,same");
801 fronga 1.16 zlineshapeControl->Draw("histo,same");
802 fronga 1.10 control_prediction->Draw("histo,same");
803     mllscon->Draw("same");
804     DrawPrelim();
805 fronga 1.7 legc = make_legend();
806 fronga 1.19 legc->SetX1(0.52);
807     legc->SetHeader(MetHeaderCon.str().c_str());
808 fronga 1.10 legc->AddEntry(mllscon,"Data","PL");
809 buchmann 1.41 legc->AddEntry(control_prediction,"Total backgrounds","L");
810     legc->AddEntry(zlineshapeControl,"DY (scaled)","FL");
811     legc->AddEntry(stat3jS,"Total uncert.","F");
812 fronga 1.10 legc->AddEntry(cr1box,"CR1","F");
813     legc->AddEntry(cr2box,"CR2","F");
814     legc->Draw();
815     cr1box->Draw();
816     cr2box->Draw();
817 buchmann 1.41
818    
819     save_with_ratio_and_sys_band( mllscon, control_prediction, rcan, saveasCon.str() , false, false, "data/pred",ControlSystHisto );
820    
821     control_prediction->SetLineColor(control_prediction_color);
822     control_prediction->SetLineWidth(LineWidth);
823 fronga 1.10 } else {
824 buchmann 1.41 control_prediction->SetLineColor(TColor::GetColor("#FF4000"));
825 fronga 1.10 TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
826     rcan->cd();
827     control_prediction->Draw("hist");
828 fronga 1.39 mcMllscon->Draw("same,hist");
829 fronga 1.10 control_prediction->Draw("histo,same");
830     mllscon->Draw("same");
831     DrawPrelim();
832     legc = allsamples.allbglegend();
833 fronga 1.19 legc->SetX1(0.52);
834     legc->SetHeader(MetHeaderCon.str().c_str());
835 fronga 1.10 legc->AddEntry(control_prediction,"All bg","L");
836     legc->AddEntry(cr1box,"CR1","F");
837     legc->AddEntry(cr2box,"CR2","F");
838     legc->Draw();
839     cr1box->Draw();
840     cr2box->Draw();
841     save_with_ratio( mllscon, *mcMllscon, rcan, saveasCon.str());
842     }
843 buchmann 1.1
844 fronga 1.7 // 6. - Opposite-flavour data/MC comparison
845     if ( doMC ) {
846 fronga 1.10 TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
847     rcan->cd();
848 fronga 1.7 mllOsig->SetLineColor(kBlack);
849     mllOsig->Draw();
850 fronga 1.39 mcMllOsig->Draw("same,hist");
851 fronga 1.7 mllOsig->Draw("same");
852     TLegend *legsdm = allsamples.allbglegend();
853 fronga 1.19 legsdm->SetHeader((MetHeader.str()+", OF").c_str());
854     legsdm->SetX1(0.52);
855 fronga 1.7 legsdm->Draw();
856     stringstream saveasSigOF;
857     saveasSigOF << "MetPlots/mll_sig_of_" << cutat << "__" << name;
858 fronga 1.10 save_with_ratio( mllOsig, *mcMllOsig, rcan, saveasSigOF.str());
859 fronga 1.7
860 fronga 1.10 rcan = new TPad("rcan","rcan",0,0,1,1);
861     rcan->cd();
862 fronga 1.7 mllOscon->SetLineColor(kBlack);
863     mllOscon->Draw();
864 fronga 1.39 mcMllOscon->Draw("same,hist");
865 fronga 1.7 mllOscon->Draw("same");
866     TLegend *legcdm = allsamples.allbglegend();
867 fronga 1.19 legcdm->SetHeader((MetHeaderCon.str()+", OF").c_str());
868     legcdm->SetX1(0.52);
869 fronga 1.7 legcdm->Draw();
870     stringstream saveasConOF;
871     saveasConOF << "MetPlots/mll_con_of_" << cutat << "__" << name;
872 fronga 1.10 save_with_ratio( mllOscon, *mcMllOscon, rcan, saveasConOF.str());
873    
874 fronga 1.7 delete legsdm;
875     delete legcdm;
876 fronga 1.10 }
877 buchmann 1.37
878     // 7. - Opposite flavor data/MC comparison for pt (!)
879     if ( doMC ) {
880     TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
881     rcan->cd();
882     rcan->SetLogy(1);
883    
884     ptsig->SetLineColor(kBlack);
885     ptsig->Draw();
886 fronga 1.39 mcptsig->Draw("same,hist");
887 buchmann 1.37 ptsig->Draw("same");
888     TLegend *legsdm = allsamples.allbglegend();
889     legsdm->SetHeader((MetHeader.str()+", SF").c_str());
890     legsdm->SetX1(0.52);
891     legsdm->Draw();
892     stringstream saveasSigOF2;
893     saveasSigOF2 << "MetPlots/mll_sig_sf_PTdist_" << cutat << "__" << name;
894     save_with_ratio( ptsig, *mcptsig, rcan, saveasSigOF2.str());
895    
896     delete legsdm;
897     }
898    
899    
900     // 8. - Opposite flavor data/MC comparison for pt (!)
901     if ( doMC ) {
902     TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
903     rcan->cd();
904     rcan->SetLogy(1);
905    
906     ptOsig->SetLineColor(kBlack);
907     ptOsig->Draw();
908 fronga 1.39 mcptOsig->Draw("same,hist");
909 buchmann 1.37 ptOsig->Draw("same");
910     TLegend *legsdm = allsamples.allbglegend();
911     legsdm->SetHeader((MetHeader.str()+", OF").c_str());
912     legsdm->SetX1(0.52);
913     legsdm->Draw();
914     stringstream saveasSigOF3;
915     saveasSigOF3 << "MetPlots/mll_sig_of_PTdist_" << cutat << "__" << name;
916     save_with_ratio( ptOsig, *mcptOsig, rcan, saveasSigOF3.str());
917    
918     delete legsdm;
919     }
920    
921 fronga 1.39 // 9. - Shape comparison between SR and CR
922     if ( !doMC ) { // SF
923     TH1F* scaled_conSF = (TH1F*)mllscon->Clone("scaled_conSF");
924     scaled_conSF->SetLineColor(kBlue);
925     scaled_conSF->Scale(mllsig->Integral()/scaled_conSF->Integral());
926     TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
927     rcan->cd();
928     mllsig->Draw();
929     scaled_conSF->Draw("same,hist");
930     mllsig->Draw("same");
931     TLegend *leg9 = make_legend("Same-flavor",0.5,0.7,false);
932     leg9->SetHeader("Same-flavor");
933     leg9->AddEntry(mllsig,"SR","pl");
934     leg9->AddEntry(scaled_conSF,"CR (scaled)","l");
935     leg9->Draw();
936     DrawPrelim();
937     stringstream saveas9;
938     saveas9 << "MetPlots/mll_compSF_" << cutat << "__" << name;
939     save_with_ratio( mllsig, scaled_conSF, rcan, saveas9.str());
940     delete leg9;
941     } else {
942     TH1F* hMcMllsig = CollapseStack( *mcMllsig,"hMcMllSig");
943     TH1F* scaled_conSF = CollapseStack( *mcMllscon,"scaled_conSF");
944     scaled_conSF->SetLineColor(kBlue);
945     scaled_conSF->SetFillStyle(0);
946     scaled_conSF->Scale(hMcMllsig->Integral()/scaled_conSF->Integral());
947     TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
948     rcan->cd();
949     hMcMllsig->SetMaximum(ymax);
950     hMcMllsig->Draw();
951     scaled_conSF->Draw("same,hist");
952     hMcMllsig->Draw("same");
953     TLegend *leg9 = make_legend("Same-flavor MC",0.5,0.7,false);
954     leg9->SetHeader("Same-flavor MC");
955     leg9->AddEntry(hMcMllsig,"SF SR","pl");
956     leg9->AddEntry(scaled_conSF,"SF CR (scaled)","l");
957     leg9->Draw();
958     DrawMCPrelim();
959     stringstream saveas9;
960     saveas9 << "MetPlots/mll_compSF_" << cutat << "__" << name;
961     save_with_ratio( hMcMllsig, scaled_conSF, rcan, saveas9.str());
962     delete leg9;
963     }
964     if ( !doMC ) { // OF
965     TH1F* scaled_conOF = (TH1F*)control_prediction->Clone("scaled_conOF");
966     scaled_conOF->SetLineColor(kBlue);
967     scaled_conOF->Scale(mllOsig->Integral()/scaled_conOF->Integral());
968     TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
969     rcan->cd();
970     mllOsig->SetLineColor(kBlack);
971     mllOsig->Draw();
972     scaled_conOF->Draw("same,hist");
973     mllOsig->Draw("same");
974     TLegend *leg9 = make_legend("Opposite-flavor",0.5,0.7,false);
975     leg9->AddEntry(mllOsig,"OF SR","pl");
976     leg9->AddEntry(scaled_conOF,"OF CR (scaled)","l");
977     leg9->Draw();
978     DrawPrelim();
979     stringstream saveas9;
980     saveas9 << "MetPlots/mll_compOF_" << cutat << "__" << name;
981     save_with_ratio( mllOsig, scaled_conOF, rcan, saveas9.str());
982    
983     delete leg9;
984     } else { // SF MC
985     TH1F* hMcMllOsig = CollapseStack( *mcMllOsig, "hMcMllOsig");
986     TH1F* scaled_conOF = CollapseStack( *mcMllOscon, "scaled_conOF");
987     scaled_conOF->SetLineColor(kBlue);
988     scaled_conOF->SetFillStyle(0);
989     scaled_conOF->Scale(hMcMllOsig->Integral()/scaled_conOF->Integral());
990     TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
991     rcan->cd();
992     hMcMllOsig->SetMaximum(ymax);
993     hMcMllOsig->Draw();
994     scaled_conOF->Draw("same,hist");
995     hMcMllOsig->Draw("same");
996     TLegend *leg9 = make_legend("Opposite-flavor MC",0.5,0.7,false);
997     leg9->AddEntry(hMcMllOsig, "OF SR","pl");
998     leg9->AddEntry(scaled_conOF,"OF CR (scaled)","l");
999     leg9->Draw();
1000     DrawMCPrelim();
1001     stringstream saveas9;
1002     saveas9 << "MetPlots/mll_compOF_" << cutat << "__" << name;
1003     save_with_ratio( hMcMllOsig, scaled_conOF, rcan, saveas9.str());
1004     delete leg9;
1005     }
1006 buchmann 1.37
1007 fronga 1.7
1008 fronga 1.10 // Memory clean-up
1009     if (doMC) {
1010 fronga 1.7 delete mcMllscon;
1011     delete mcMllOscon;
1012     delete mcMllsig;
1013 fronga 1.8 delete mcMllsigEE;
1014     delete mcMllsigMM;
1015 fronga 1.7 delete mcMllOsig;
1016     }
1017 buchmann 1.1
1018     delete cr1box;
1019     delete cr2box;
1020     delete srbox;
1021     delete legc;
1022     delete leg;
1023 fronga 1.7
1024 buchmann 1.1 delete mllscon;
1025     delete mllOscon;
1026     delete mllsig;
1027 fronga 1.8 delete mllsigEE;
1028     delete mllsigMM;
1029 buchmann 1.1 delete mllOsig;
1030 buchmann 1.41 delete ptsig;
1031     delete ptOsig;
1032 fronga 1.7 delete zlineshape;
1033 buchmann 1.37 delete Ozlineshape;
1034 fronga 1.16 delete zlineshapeControl;
1035 buchmann 1.6 delete tcan;
1036 buchmann 1.1 }
1037    
1038 buchmann 1.37
1039 buchmann 1.42 void DoMetPlots(string datajzb, string mcjzb) {
1040     //DoMCSystPlot("mll",30,0,150,TCut("pfJetGoodNum40>=3"), false, "m_{ll} [GeV]", "mll_comparison");
1041     //cout << __FUNCTION__ << " : " << __LINE__ << " : quitting because of testing. " << endl;assert(0);
1042 buchmann 1.37
1043 buchmann 1.27 switch_overunderflow(true);
1044 fronga 1.7 float metCuts[] = { 100., 150. };
1045 fronga 1.39 //float ymax[] = { 180., 170. };
1046 buchmann 1.41 float ymax[] = { 90., 240. };
1047 fronga 1.7 int jetCuts[] = { 3, 2 };
1048 buchmann 1.35 string leptCuts[] = { "pt1>20&&pt2>20", "pt1>20&&pt2>10&&pfTightHT>100" };
1049 fronga 1.7 bool nomc(0),domc(1);
1050 buchmann 1.37 string backup_basicqualitycut = (const char*) basicqualitycut;
1051     string backup_essentialcut = (const char*) essentialcut;
1052     string backup_basiccut = (const char*) basiccut;
1053    
1054 fronga 1.39 //zlineshapes(); // Rinout plots
1055 fronga 1.7 for ( int i=0; i<2; ++i ) {
1056 buchmann 1.37 //need to make sure that the above changes actually have some effect. we therefore check all relevant cuts and
1057     //set the pt condition to 10/10 (yes you read that right). the addition cut (above) will therefore elevate it
1058     // to 20,10 or 20,20. otherwise basicqualitycut will impose 20,20 ...
1059     string Sbasicqualitycut = backup_basicqualitycut;
1060     Sbasicqualitycut = ReplaceAll(Sbasicqualitycut,"pt2>20","pt2>10");
1061     basicqualitycut=TCut(Sbasicqualitycut.c_str());
1062    
1063     string Sbasiccut = backup_basiccut;
1064     Sbasiccut = ReplaceAll(Sbasiccut,"pt2>20","pt2>10");
1065     basiccut=TCut(Sbasiccut.c_str());
1066 fronga 1.39
1067 buchmann 1.37 string Sessentialcut = backup_essentialcut;
1068     Sessentialcut = ReplaceAll(Sessentialcut,"pt2>20","pt2>10");
1069     essentialcut=TCut(Sessentialcut.c_str());
1070    
1071 fronga 1.36 ProduceMetPlotsWithCut(TCut(("mll>15&&"+leptCuts[i]).c_str()),"",metCuts[i],jetCuts[i],nomc,ymax[i]);
1072 fronga 1.22 ProduceMetPlotsWithCut(TCut(("mll>15&&"+leptCuts[i]).c_str()),"",metCuts[i],jetCuts[i],domc,ymax[i]);
1073 fronga 1.36 ProduceMetPlotsWithCut(TCut(("mll>15&&pfJetGoodNumBtag30==0&&"+leptCuts[i]).c_str()),"bTagVeto30",metCuts[i], jetCuts[i],nomc,ymax[i]);
1074     ProduceMetPlotsWithCut(TCut(("mll>15&&pfJetGoodNumBtag30>0&&"+leptCuts[i]).c_str()),"AtLeastOneBJet30",metCuts[i],jetCuts[i],nomc,ymax[i]);
1075     ProduceMetPlotsWithCut(TCut(("mll>15&&pfJetGoodNumBtag30==0&&"+leptCuts[i]).c_str()),"bTagVeto30",metCuts[i], jetCuts[i],domc,ymax[i]);
1076     ProduceMetPlotsWithCut(TCut(("mll>15&&pfJetGoodNumBtag30>0&&"+leptCuts[i]).c_str()),"AtLeastOneBJet30",metCuts[i], jetCuts[i],domc,ymax[i]);
1077 fronga 1.7 }
1078 buchmann 1.37 basicqualitycut=TCut(backup_basicqualitycut.c_str());
1079     basiccut =TCut(backup_basiccut.c_str());
1080     essentialcut =TCut(backup_essentialcut.c_str());
1081 buchmann 1.27 switch_overunderflow(false);
1082 buchmann 1.1 }
1083 buchmann 1.12
1084 buchmann 1.17 void LabelHisto(TH1 *MET_ratio,string titlex, string titley) {
1085     MET_ratio->GetXaxis()->SetTitle(titlex.c_str());
1086     MET_ratio->GetXaxis()->CenterTitle();
1087     MET_ratio->GetYaxis()->SetTitle(titley.c_str());
1088     MET_ratio->GetYaxis()->CenterTitle();
1089     }
1090    
1091 buchmann 1.23 TH1F* GetPredictedAndObservedMetShapes(TCut JetCut, string sPositiveCut,string sNegativeCut,string CorrectedMet,string ObservedMet, string JZBPosvar, string JZBNegvar, float MetCut, int is_data, bool isDYonly, bool isAachen) {
1092 buchmann 1.17
1093     //Steps:
1094     // 1) Prepare samples and histo definition (with "optimal" binning for MET cut)
1095     // 2) Fill MET histograms
1096     // 3) Fill JZB histograms
1097     // 4) Draw them and store them
1098     // 5) return predicted MET distribution as is (i.e. not scaled by factor of 2!)
1099    
1100 fronga 1.39 dout << "*************************************" << endl;
1101 buchmann 1.26 // cout << "** SUMMARY BEFORE STARTING DRAWING **" << endl;
1102     // cout << "MET variable: " << ObservedMet << endl;
1103     // cout << "Corr. MET var:" << CorrectedMet << endl;
1104     // cout << "JZB pos. var: " << JZBPosvar << endl;
1105     // cout << "JZB neg. var: " << JZBNegvar << endl;
1106     // cout << "JZB pos cut : " << sPositiveCut << endl;
1107     // cout << "JZB neg cut : " << sNegativeCut << endl;
1108 buchmann 1.30
1109    
1110     if(isAachen) MetPlotsSpace::Zprediction_Uncertainty=0.3;
1111 buchmann 1.17 //Step 1: Prepare samples and histo definition
1112     vector<int> SelectedSamples;
1113     if(is_data==mc&&isDYonly) {
1114     SelectedSamples=allsamples.FindSample("Z_em_DYJetsToL");
1115     if(SelectedSamples.size()==0) {
1116     write_error(__FUNCTION__,"Cannot continue, there seems to be no DY sample without Taus - goodbye!");
1117     assert(SelectedSamples.size()>0);
1118     }
1119     }
1120    
1121     float DisplayedBinSize=10.0; // this is the bin size that we use for plotting
1122    
1123 buchmann 1.21 float BinWidth=1.0;
1124 buchmann 1.17 float xmin=0;
1125 buchmann 1.37 float xmax=150;
1126 buchmann 1.23 if(isAachen) xmax=160;
1127 buchmann 1.21 if(MetCut>=xmax) xmax=MetCut+10;
1128 buchmann 1.17 int nbins=int((xmax-xmin)/BinWidth);
1129 buchmann 1.23
1130     float pt2cut=20;
1131     if(isAachen)pt2cut=10;
1132    
1133 buchmann 1.17 stringstream basiccut;
1134 buchmann 1.23 basiccut << (const char*) JetCut << "&&" << (const char*) Restrmasscut << "&&" << (const char*) leptoncut << "&&pt1>20&&pt2>" << pt2cut;
1135 buchmann 1.17
1136    
1137     stringstream cMET_observed;
1138     cMET_observed << "(" << basiccut.str() << "&&(" << sPositiveCut << ")&&" << (const char*) cutOSSF << ")";
1139     stringstream cMET_ttbar_pred;
1140     cMET_ttbar_pred << "(" << basiccut.str() << "&&(" << sPositiveCut << ")&&" << (const char*) cutOSOF << ")";
1141     stringstream cMET_osof_pred;
1142     cMET_osof_pred << "(" << basiccut.str() << "&&(" << sNegativeCut << ")&&" << (const char*) cutOSOF << ")";
1143     stringstream cMET_ossf_pred;
1144     cMET_ossf_pred << "(" << basiccut.str() << "&&(" << sNegativeCut << ")&&" << (const char*) cutOSSF << ")";
1145    
1146     write_warning(__FUNCTION__,"Once the rush is over you might want to define the potential sidebands ... ");
1147 buchmann 1.28
1148 buchmann 1.17 //Step 2: Fill Met histograms
1149 buchmann 1.28 float bottommargin=gStyle->GetPadBottomMargin();
1150     float canvas_height=gStyle->GetCanvasDefH();
1151     float canvas_width=gStyle->GetCanvasDefW();
1152     float ratiospace=0.25;// space the ratio should take up (relative to original pad)
1153    
1154     float ratiobottommargin=0.3;
1155     float ratiotopmargin=0.1;
1156    
1157     float xstretchfactor=((1-ratiospace)*(1-gStyle->GetPadTopMargin()))/((1)*ratiospace);
1158    
1159     TCanvas *main_canvas = new TCanvas("main_canvas","main_canvas",(Int_t)canvas_width,(Int_t)(canvas_height*(1+ratiospace)));
1160     TPad *mainpad = new TPad("mainpad","mainpad",0,1-(1.0/(1+ratiospace)),1,1);//top (main) pad
1161     TPad *coverpad = new TPad("coverpad","coverpad",gStyle->GetPadLeftMargin()-0.008,1-(1.0/(1+ratiospace))-0.04,1,1-(1.0/(1+ratiospace))+0.103);//pad covering up the x scale
1162     TPad *bottompad = new TPad("bottompad", "Ratio Pad",0,0,1,(1-(1-bottommargin)/(1+ratiospace))-0.015); //bottom pad
1163    
1164     main_canvas->Range(0,0,1,1);
1165     main_canvas->SetBorderSize(0);
1166     main_canvas->SetFrameFillColor(0);
1167    
1168     mainpad->Draw();
1169     mainpad->cd();
1170     mainpad->SetLogy(1);
1171     mainpad->Range(0,0,1,1);
1172     mainpad->SetFillColor(kWhite);
1173     mainpad->SetBorderSize(0);
1174     mainpad->SetFrameFillColor(0);
1175    
1176    
1177    
1178    
1179 buchmann 1.17 TH1F *MET_observed = allsamples.Draw("MET_observed",ObservedMet,nbins,xmin,xmax,"MET [GeV]","events",
1180 buchmann 1.26 TCut(cMET_observed.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1181 buchmann 1.17 TH1F *MET_ossf_pred = allsamples.Draw("MET_ossf_pred",CorrectedMet,nbins,xmin,xmax,"MET [GeV]","events",
1182 buchmann 1.26 TCut(cMET_ossf_pred.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1183 buchmann 1.17 TH1F *MET_osof_pred = allsamples.Draw("MET_osof_pred",CorrectedMet,nbins,xmin,xmax,"MET [GeV]","events",
1184 buchmann 1.26 TCut(cMET_osof_pred.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1185 buchmann 1.17 TH1F *MET_ttbar_pred= allsamples.Draw("MET_ttbar_pred",ObservedMet,nbins,xmin,xmax,"MET [GeV]","events",
1186 buchmann 1.26 TCut(cMET_ttbar_pred.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1187 buchmann 1.17
1188 buchmann 1.25
1189 buchmann 1.37 if((isDYonly && is_data==mc) || is_data==data) {
1190 buchmann 1.25 TH1F *MET_truth = allsamples.Draw("MET_truth",ObservedMet,1,MetCut,10000,"MET [GeV]","events",TCut(((string)"met[4]>"+any2string(MetCut)).c_str())&&cutOSSF&&TCut(basiccut.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1191 buchmann 1.37 TH1F *MET_otruth = allsamples.Draw("MET_otruth",ObservedMet,1,MetCut,10000,"MET [GeV]","events",TCut(((string)"met[4]>"+any2string(MetCut)).c_str())&&cutOSOF&&TCut(basiccut.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1192     if(is_data==mc) write_info(__FUNCTION__,"DY Truth is : "+any2string(MET_truth->Integral()));
1193     if(is_data==data) {
1194     write_info(__FUNCTION__,"Observed : " +any2string(MET_truth->Integral()));
1195     write_info(__FUNCTION__,"TTbar est: " +any2string(MET_otruth->Integral()));
1196     }
1197 buchmann 1.25 delete MET_truth;
1198 buchmann 1.37 delete MET_otruth;
1199 buchmann 1.25 }
1200    
1201    
1202 buchmann 1.17 TH1F *MET_predicted=(TH1F*)MET_ossf_pred->Clone("MET_predicted");
1203     MET_predicted->Add(MET_osof_pred,-1);
1204     MET_predicted->Add(MET_ttbar_pred);
1205     MET_predicted->SetLineColor(kRed);
1206     MET_observed->SetLineColor(kBlack);
1207    
1208     TH1F *MET_Z_prediction=(TH1F*)MET_ossf_pred->Clone("MET_Z_prediction");
1209     MET_Z_prediction->Add(MET_osof_pred,-1);
1210     MET_Z_prediction->SetLineColor(kBlue);
1211    
1212     LabelHisto(MET_observed,"MET (GeV)","events");
1213    
1214     //Step 3: Fill JZB histograms
1215 buchmann 1.25
1216 buchmann 1.17 TH1F *JZB_observed = allsamples.Draw("JZB_observed",JZBPosvar,nbins,xmin,xmax,"JZB [GeV]","events",
1217     TCut(cMET_observed.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1218     TH1F *JZB_ossf_pred = allsamples.Draw("JZB_ossf_pred",JZBNegvar,nbins,xmin,xmax,"JZB [GeV]","events",
1219     TCut(cMET_ossf_pred.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1220     TH1F *JZB_osof_pred = allsamples.Draw("JZB_osof_pred",JZBNegvar,nbins,xmin,xmax,"JZB [GeV]","events",
1221     TCut(cMET_osof_pred.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1222     TH1F *JZB_ttbar_pred= allsamples.Draw("JZB_ttbar_pred",JZBPosvar,nbins,xmin,xmax,"JZB [GeV]","events",
1223     TCut(cMET_ttbar_pred.str().c_str()),is_data,PlottingSetup::luminosity,SelectedSamples);
1224    
1225     TH1F *JZB_predicted=(TH1F*)JZB_ossf_pred->Clone("JZB_predicted");
1226     JZB_predicted->Add(JZB_osof_pred,-1);
1227     JZB_predicted->Add(JZB_ttbar_pred);
1228     JZB_predicted->SetLineColor(kRed);
1229     JZB_observed->SetLineColor(kBlack);
1230    
1231     TH1F *JZB_Z_prediction=(TH1F*)JZB_ossf_pred->Clone("JZB_Z_prediction");
1232     JZB_Z_prediction->Add(JZB_osof_pred,-1);
1233     MET_Z_prediction->SetLineColor(kBlue);
1234    
1235     LabelHisto(JZB_observed,"JZB (GeV)","events");
1236    
1237     // Step 4: Draw them and store them
1238    
1239     TLegend *legend = new TLegend(0.6,0.6,0.89,0.89);
1240    
1241     MET_ttbar_pred->SetLineColor(TColor::GetColor("#005C00"));
1242     JZB_ttbar_pred->SetLineColor(TColor::GetColor("#005C00"));
1243    
1244     legend->SetFillColor(kWhite);
1245     legend->SetBorderSize(0);
1246     legend->AddEntry(MET_predicted,"prediction","l");
1247     legend->AddEntry(MET_observed,"observed","p");
1248     legend->AddEntry(MET_Z_prediction,"predicted Z","l");
1249     legend->AddEntry(MET_ttbar_pred,"OF-based prediction","l");
1250    
1251     if(is_data==mc) legend->SetHeader("Simulation:");
1252     if(is_data==mc&&isDYonly) legend->SetHeader("DY #rightarrow ee,#mu#mu only:");
1253     if(is_data==data) legend->SetHeader("Data:");
1254    
1255     stringstream SaveJZBname;
1256     stringstream SaveMETname;
1257     if(is_data==data) {
1258     SaveJZBname << "MetPrediction/JZBdistribution_Data_METCutAt" << MetCut;
1259     SaveMETname << "MetPrediction/METdistribution_Data_METCutAt" << MetCut;
1260     }
1261     if(is_data==mc&&!isDYonly) {
1262     SaveJZBname << "MetPrediction/JZBdistribution_FullMC_METCutAt" << MetCut;
1263     SaveMETname << "MetPrediction/METdistribution_FullMC_METCutAt" << MetCut;
1264     }
1265     if(is_data==mc&&isDYonly) {
1266     SaveJZBname << "MetPrediction/JZBdistribution_DYMC_METCutAt" << MetCut;
1267     SaveMETname << "MetPrediction/METdistribution_DYMC_METCutAt" << MetCut;
1268     }
1269    
1270 buchmann 1.26 dout << "Shape summary (MET>50) for ";
1271 fronga 1.39 if(is_data==data) dout << "data";
1272     if(is_data==mc&&isDYonly) dout<< "DY ";
1273     if(is_data==mc&&!isDYonly) dout << " Full MC";
1274     dout << " : " << endl;
1275 buchmann 1.26
1276 buchmann 1.24 dout << " observed : " << MET_observed->Integral(MET_observed->FindBin(50),MET_observed->FindBin(xmax)) << endl;
1277     dout << " predicted : " << MET_predicted->Integral(MET_predicted->FindBin(50),MET_predicted->FindBin(xmax)) << endl;
1278     dout << " Z pred : " << MET_Z_prediction->Integral(MET_Z_prediction->FindBin(50),MET_Z_prediction->FindBin(xmax)) << endl;
1279     dout << " ttbar : " << MET_ttbar_pred->Integral(MET_ttbar_pred->FindBin(50),MET_ttbar_pred->FindBin(xmax)) << endl;
1280    
1281    
1282 buchmann 1.17 TH1F *ZpredClone = (TH1F*)MET_Z_prediction->Clone("ZpredClone");
1283     ZpredClone->SetLineColor(kBlue);
1284     MET_observed->Rebin(int(DisplayedBinSize/BinWidth));
1285     ZpredClone->Rebin(int(DisplayedBinSize/BinWidth));
1286     MET_predicted->Rebin(int(DisplayedBinSize/BinWidth));
1287     MET_ttbar_pred->Rebin(int(DisplayedBinSize/BinWidth));
1288    
1289     TH1F *JZBZpredClone = (TH1F*)JZB_Z_prediction->Clone("ZpredClone");
1290     JZBZpredClone->SetLineColor(kBlue);
1291     JZB_observed->Rebin(int(DisplayedBinSize/BinWidth));
1292     JZBZpredClone->Rebin(int(DisplayedBinSize/BinWidth));
1293     JZB_predicted->Rebin(int(DisplayedBinSize/BinWidth));
1294     JZB_ttbar_pred->Rebin(int(DisplayedBinSize/BinWidth));
1295    
1296     TH1F *JZB_ratio = (TH1F*)JZB_observed->Clone("JZB_ratio");
1297     JZB_ratio->Divide(JZB_predicted);
1298     LabelHisto(JZB_ratio,"JZB (GeV)","obs/pred");
1299     TH1F *MET_ratio = (TH1F*)MET_observed->Clone("MET_ratio");
1300     MET_ratio->Divide(MET_predicted);
1301 buchmann 1.28 MET_observed->SetMaximum(5*MET_observed->GetMaximum());
1302     JZB_observed->SetMaximum(5*JZB_observed->GetMaximum());
1303     MET_observed->SetMinimum(0.5);
1304     JZB_observed->SetMinimum(0.5);
1305 buchmann 1.17 LabelHisto(MET_ratio,"MET (GeV)","obs/pred");
1306 buchmann 1.24 TBox *sysenvelope = new TBox(xmin,1.0-MetPlotsSpace::Zprediction_Uncertainty,xmax,1.0+MetPlotsSpace::Zprediction_Uncertainty);
1307 buchmann 1.17 sysenvelope->SetFillColor(TColor::GetColor("#82FA58")); // light green
1308     sysenvelope->SetLineWidth(0);
1309 buchmann 1.24 TBox *dsysenvelope = new TBox(xmin,1.0-2*MetPlotsSpace::Zprediction_Uncertainty,xmax,1.0+2*MetPlotsSpace::Zprediction_Uncertainty);
1310     dsysenvelope->SetFillColor(TColor::GetColor("#F3F781")); // light yellow
1311     dsysenvelope->SetLineWidth(0);
1312 buchmann 1.28
1313     MET_ratio->GetYaxis()->SetNdivisions(502,false);
1314     JZB_ratio->GetYaxis()->SetNdivisions(502,false);
1315    
1316 buchmann 1.17
1317     MET_observed->Draw("e1");
1318     MET_ttbar_pred->Draw("histo,same");
1319     ZpredClone->Draw("histo,same");
1320     MET_predicted->Draw("histo,same");
1321     MET_observed->Draw("e1,same");
1322     legend->Draw();
1323     if(is_data==data) DrawPrelim();
1324     else DrawMCPrelim();
1325    
1326 buchmann 1.28 mainpad->Modified();
1327     main_canvas->cd();
1328     coverpad->Draw();
1329     coverpad->cd();
1330     coverpad->Range(0,0,1,1);
1331     coverpad->SetFillColor(kWhite);
1332     coverpad->SetBorderSize(0);
1333     coverpad->SetFrameFillColor(0);
1334     coverpad->Modified();
1335     main_canvas->cd();
1336     bottompad->SetTopMargin(ratiotopmargin);
1337     bottompad->SetBottomMargin(ratiobottommargin);
1338     bottompad->Draw();
1339 buchmann 1.17 bottompad->cd();
1340 buchmann 1.28 bottompad->Range(0,0,1,1);
1341     bottompad->SetFillColor(kWhite);
1342    
1343 buchmann 1.17 MET_ratio->GetYaxis()->SetRangeUser(0,2);
1344 buchmann 1.28 MET_ratio->GetXaxis()->SetLabelSize(xstretchfactor*MET_ratio->GetXaxis()->GetLabelSize());
1345     MET_ratio->GetYaxis()->SetLabelSize(xstretchfactor*MET_ratio->GetYaxis()->GetLabelSize());
1346     MET_ratio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1347     MET_ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1348    
1349 buchmann 1.17 MET_ratio->Draw("e1");
1350 buchmann 1.28 // dsysenvelope->Draw();
1351 buchmann 1.17 sysenvelope->Draw();
1352     MET_ratio->Draw("AXIS,same");
1353     MET_ratio->Draw("e1,same");
1354     TLine *metl = new TLine(xmin,1.0,xmax,1.0);
1355     metl->SetLineColor(kBlue);
1356     metl->Draw();
1357 buchmann 1.28 CompleteSave(main_canvas,SaveMETname.str());
1358    
1359     mainpad->cd();
1360 buchmann 1.17
1361     JZB_observed->Draw("e1");
1362     JZB_ttbar_pred->Draw("histo,same");
1363     JZBZpredClone->Draw("histo,same");
1364     JZB_predicted->Draw("histo,same");
1365     JZB_observed->Draw("e1,same");
1366     legend->Draw();
1367     if(is_data==data) DrawPrelim();
1368     else DrawMCPrelim();
1369    
1370 buchmann 1.28 main_canvas->cd();
1371     coverpad->Draw();
1372     main_canvas->cd();
1373     bottompad->Draw();
1374 buchmann 1.17 bottompad->cd();
1375     JZB_ratio->GetYaxis()->SetRangeUser(0,2);
1376 buchmann 1.28
1377     JZB_ratio->GetXaxis()->SetLabelSize(xstretchfactor*JZB_ratio->GetXaxis()->GetLabelSize());
1378     JZB_ratio->GetYaxis()->SetLabelSize(xstretchfactor*JZB_ratio->GetYaxis()->GetLabelSize());
1379     JZB_ratio->GetXaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1380     JZB_ratio->GetYaxis()->SetTitleSize(xstretchfactor*gStyle->GetTitleSize());
1381    
1382 buchmann 1.17 JZB_ratio->Draw("e1");
1383 buchmann 1.28 // dsysenvelope->Draw();
1384 buchmann 1.17 sysenvelope->Draw();
1385     JZB_ratio->Draw("AXIS,same");
1386     JZB_ratio->Draw("e1,same");
1387     metl->Draw();
1388    
1389 buchmann 1.28 CompleteSave(main_canvas,SaveJZBname.str());
1390 buchmann 1.17
1391 buchmann 1.28 delete main_canvas;
1392 buchmann 1.17 delete MET_observed;
1393     delete MET_predicted;
1394     //do NOT delete MET_Z_prediction (it's the return value)
1395     delete MET_osof_pred;
1396     delete MET_ossf_pred;
1397     delete MET_ttbar_pred;
1398    
1399     delete JZB_observed;
1400     delete JZB_predicted;
1401     delete JZB_osof_pred;
1402     delete JZB_ossf_pred;
1403     delete JZB_Z_prediction;
1404     delete JZB_ttbar_pred;
1405    
1406     return MET_Z_prediction;
1407     }
1408    
1409 buchmann 1.25 float extract_correction(string jzbvariable) {
1410     int position = (int)jzbvariable.find("[1]");
1411     if(position==-1) return 0.0;
1412     string correction=jzbvariable.substr(position+3,jzbvariable.length()-position-3);
1413     position = (int)correction.find("*");
1414     if(position==-1) return 0.0;
1415     correction=correction.substr(0,position);
1416     float correctionvalue=atof(correction.c_str());
1417     assert(correctionvalue<1&&correctionvalue>0);
1418     return correctionvalue;
1419     }
1420    
1421 buchmann 1.23 float Get_Met_Z_Prediction(TCut JetCut, float MetCut, int isdata, bool isDYonly, bool isAachen=false) {
1422 buchmann 1.17 dout << "Going to compute Z region prediction for a MET cut at " << MetCut << " GeV" << endl;
1423     // Steps:
1424 buchmann 1.25 // 1) Get peak
1425     // 2) use the peak and pt correction for sample splitting
1426     // and for MET distribution shifting
1427 buchmann 1.17 // 3) compute the estimate for MET>MetCut
1428    
1429     // do this for data if isdata==data, otherwise for MC (full closure if isDYonly==false, otherwise use only DY sample)
1430    
1431 buchmann 1.28 // Step 0 : If we're dealing with DY, we need to make sure PURW is off!
1432     // string bkpcutweight = (const char*) cutWeight;
1433     // if(isdata==mc && isDYonly) cutWeight=TCut("1.0");
1434    
1435    
1436 buchmann 1.25 // Step 1) Get peak
1437 buchmann 1.17 float MCPeakNoPtCorr=0,MCPeakErrorNoPtCorr=0,DataPeakNoPtCorr=0,DataPeakErrorNoPtCorr=0,MCSigma=0,DataSigma=0;
1438     stringstream resultsNoPtCorr;
1439     stringstream NoPtCorrdatajzb;
1440     stringstream NoPtCorrmcjzb;
1441    
1442 buchmann 1.24 if(isAachen) {
1443     //need to make sure that none of the typical basic cuts contain problematic selections!
1444     string Sleptoncut = (const char*) leptoncut;
1445     if((int)Sleptoncut.find("pt2>20")>-1) {
1446     write_error(__FUNCTION__,"You're trying to compute the Aachen estimate but are requiring pt2>20 ... please check your config.");
1447     assert((int)Sleptoncut.find("pt2>20")==-1);
1448     }
1449     } else {
1450     string Sleptoncut = (const char*) leptoncut;
1451     if((int)Sleptoncut.find("pt2>10")>-1) {
1452     write_error(__FUNCTION__,"You're trying to compute the ETH estimate but are requiring pt2>10 ... please check your config.");
1453     assert((int)Sleptoncut.find("pt2>10")==-1);
1454     }
1455     }
1456    
1457    
1458 buchmann 1.25 float Ptcorrection=0.0;
1459 buchmann 1.24
1460 buchmann 1.25 if(isdata==data) Ptcorrection=extract_correction(PlottingSetup::jzbvariabledata);
1461     else Ptcorrection=extract_correction(PlottingSetup::jzbvariablemc);
1462 buchmann 1.24
1463 buchmann 1.29 bool OverFlowStatus=addoverunderflowbins;
1464    
1465 buchmann 1.25 find_peaks(MCPeakNoPtCorr,MCPeakErrorNoPtCorr, DataPeakNoPtCorr,DataPeakErrorNoPtCorr,resultsNoPtCorr,true,NoPtCorrdatajzb,NoPtCorrmcjzb,(const char*) JetCut, true);
1466 buchmann 1.17
1467 buchmann 1.29 switch_overunderflow(OverFlowStatus);
1468 buchmann 1.28
1469 buchmann 1.25 float PeakPosition=0.0;
1470     string jzbvariable;
1471 buchmann 1.17 if(isdata==data) {
1472     PeakPosition=DataPeakNoPtCorr;
1473 buchmann 1.25 jzbvariable=jzbvariabledata;
1474 buchmann 1.17 dout << "Found peak in data at " << DataPeakNoPtCorr << " +/- " << DataPeakErrorNoPtCorr << " ; will use this result (" << PeakPosition << ")" << endl;
1475     } else {
1476     PeakPosition=MCPeakNoPtCorr;
1477 buchmann 1.25 jzbvariable=jzbvariablemc;
1478 buchmann 1.17 dout << "Found peak in mc at " << MCPeakNoPtCorr << " +/- " << MCPeakErrorNoPtCorr << " ; will use this result (" << PeakPosition << ")" << endl;
1479     }
1480    
1481     // Step 2: Use peak for sample splitting and MET shifting
1482 buchmann 1.25 string CorrectedMet="met[4]-"+any2string(Ptcorrection)+"*pt +"+any2string(abs(1.0*(PeakPosition)));
1483     if(2*(PeakPosition)<0) CorrectedMet="met[4]-"+any2string(Ptcorrection)+"*pt -"+any2string(abs(1.0*(PeakPosition)));
1484 buchmann 1.17
1485     stringstream sPositiveCut;
1486 buchmann 1.25 if(PeakPosition>0) sPositiveCut << "((" << jzbvariable << "-" << PeakPosition << ")>0)";
1487     else sPositiveCut << "( " << jzbvariable << "+" << abs(PeakPosition) << ")>0)";
1488 buchmann 1.17
1489     stringstream sNegativeCut;
1490 buchmann 1.25 if(PeakPosition<0) sNegativeCut << "((" << jzbvariable << "+" << abs(PeakPosition) << ")<0)";
1491     else sNegativeCut << "(( " << jzbvariable << "-" << abs(PeakPosition) << ")<0)";
1492 buchmann 1.17
1493     string ObservedMet="met[4]";
1494    
1495     stringstream JZBPosvar;
1496 buchmann 1.25 JZBPosvar<<jzbvariable;
1497     if(PeakPosition>0) JZBPosvar << "-" << PeakPosition;
1498     else JZBPosvar << "+" << abs(PeakPosition);
1499    
1500 buchmann 1.17 stringstream JZBNegvar;
1501 buchmann 1.25 JZBNegvar<<"-(" << jzbvariable;
1502     if(PeakPosition>0) JZBNegvar << "-" << PeakPosition << ")";
1503     else JZBNegvar << "+" << abs(PeakPosition) << ")";
1504    
1505 buchmann 1.17
1506     // Step 3: Compute estimate
1507 buchmann 1.23 TH1F *predicted = GetPredictedAndObservedMetShapes(JetCut, sPositiveCut.str(),sNegativeCut.str(),CorrectedMet,ObservedMet,JZBPosvar.str(),JZBNegvar.str(), MetCut, isdata, isDYonly, isAachen);
1508 buchmann 1.17 float ZregionZestimate=0;
1509     for(int ibin=1;ibin<=(int)predicted->GetNbinsX();ibin++) {
1510     if(predicted->GetBinLowEdge(ibin)+predicted->GetBinWidth(ibin)>MetCut) {
1511     ZregionZestimate+=2*(predicted->GetBinContent(ibin));
1512     }
1513     }
1514    
1515 fronga 1.39 dout << " Z region estimate in MET>" << MetCut << " for this sample: " << ZregionZestimate << endl;
1516 buchmann 1.30 if(isdata==data) {
1517     MetPlotsSpace::Zestimate__data=ZregionZestimate;
1518     MetPlotsSpace::Zestimate__data_stat=2*TMath::Sqrt(ZregionZestimate/2);
1519     MetPlotsSpace::Zestimate__data_sys=ZregionZestimate*MetPlotsSpace::Zprediction_Uncertainty;
1520     }
1521     if(isdata==mc && isDYonly) {
1522     MetPlotsSpace::Zestimate__dy=ZregionZestimate;
1523     MetPlotsSpace::Zestimate__dy_stat=2*TMath::Sqrt(ZregionZestimate/2);
1524     MetPlotsSpace::Zestimate__dy_sys=ZregionZestimate*MetPlotsSpace::Zprediction_Uncertainty;
1525     }
1526     if(isdata==mc && !isDYonly) {
1527     MetPlotsSpace::Zestimate__mc=ZregionZestimate;
1528     MetPlotsSpace::Zestimate__mc_stat=2*TMath::Sqrt(ZregionZestimate/2);
1529     MetPlotsSpace::Zestimate__mc_sys=ZregionZestimate*MetPlotsSpace::Zprediction_Uncertainty;
1530     }
1531    
1532    
1533 buchmann 1.25
1534 buchmann 1.28 // if(isdata==mc && isDYonly) cutWeight=TCut(bkpcutweight.c_str());
1535    
1536 buchmann 1.17 return ZregionZestimate;
1537     }
1538    
1539 buchmann 1.30 void ExperimentalMetPrediction(bool QuickRun=false) {
1540 buchmann 1.17
1541 buchmann 1.28 switch_overunderflow(true);
1542 buchmann 1.23 bool isAachen=false;
1543 buchmann 1.24
1544 buchmann 1.37 bool HighPurityMode=true; // High Purity = |mll-91|<10 GeV , else <20
1545 buchmann 1.24
1546 buchmann 1.30 if(QuickRun) {
1547 buchmann 1.32 HighPurityMode=true;
1548 buchmann 1.30 }
1549    
1550 buchmann 1.24 string restrmasscutbkp=(const char*) PlottingSetup::Restrmasscut;
1551    
1552 buchmann 1.32 if(HighPurityMode) PlottingSetup::Restrmasscut=TCut("abs(mll-91)<10");
1553     else PlottingSetup::Restrmasscut= TCut("abs(mll-91)<20");
1554 buchmann 1.24
1555    
1556    
1557 fronga 1.39 dout << "Aachen mode (20/10, 2 jets) ? " << isAachen << endl;
1558     dout << "High Purity mode? " << HighPurityMode << endl;
1559 buchmann 1.24
1560 buchmann 1.23
1561     if(isAachen) write_warning(__FUNCTION__,"Please don't forget to adapt the global lepton cut (to 20/10) for Aachen!");
1562 buchmann 1.24 stringstream snjets;
1563     if(isAachen) snjets << 2;
1564     else snjets << 3;
1565     float maxMET=100;
1566     if(isAachen) maxMET=150;
1567 buchmann 1.12
1568 buchmann 1.17 TCut nJetsSignal(PlottingSetup::basicqualitycut&&("pfJetGoodNum40>="+snjets.str()).c_str());
1569 buchmann 1.37
1570 fronga 1.39 dout << " ***** TESTING Z PREDICTION ***** " << endl;
1571     dout << "Notation (you can copy & paste this to evaluate it further)" << endl;
1572     dout << "Cut;Data;MC;DY;" << endl;
1573 buchmann 1.37 float DataEstimate = -1;
1574     DataEstimate = Get_Met_Z_Prediction(Restrmasscut&&nJetsSignal,maxMET, data, false, isAachen);
1575     float DYEstimate=-1;
1576 buchmann 1.30 if(!QuickRun) DYEstimate = Get_Met_Z_Prediction(Restrmasscut&&nJetsSignal,maxMET, mc, true, isAachen);
1577 buchmann 1.37 float MCEstimate=-1;
1578 buchmann 1.30 if(!QuickRun) MCEstimate = Get_Met_Z_Prediction(Restrmasscut&&nJetsSignal,maxMET, mc, false, isAachen);
1579    
1580 buchmann 1.37 dout << "Found estimate in data of " << DataEstimate << endl;
1581 buchmann 1.30 if(QuickRun) return;
1582 fronga 1.39 dout << maxMET << ";" << DataEstimate << ";" << MCEstimate << ";" << DYEstimate << endl;
1583 buchmann 1.37
1584 buchmann 1.24 float Diff=20.0;
1585     if(HighPurityMode) Diff=10;
1586     TCut cut("mll>20&&pt1>20&&pt2>20");
1587 buchmann 1.35 if (isAachen) cut = TCut("mll>20&&pt1>20&&pt2>10&&pfTightHT>100");
1588 buchmann 1.28
1589     TCanvas *qcan = new TCanvas("qcan","qcan");
1590 buchmann 1.35 TH1F *zlineshape = allsamples.Draw("zlineshape","mll",int((91+25-18)*5),18,91+25,"m_{ll} (GeV)","events",cutOSSF&&TCut("pfJetGoodNum40==2")&&cut,data,PlottingSetup::luminosity); // bins of 0.2 GeV
1591     TH1F *Ozlineshape = allsamples.Draw("Ozlineshape","mll",int((91+25-18)*5),18,91+25,"m_{ll} (GeV)","events",cutOSOF&&TCut("pfJetGoodNum40==2")&&cut,data,PlottingSetup::luminosity); // bins of 0.2 GeV
1592 buchmann 1.28 zlineshape->Add(Ozlineshape,-1);
1593     delete qcan;
1594 buchmann 1.24 float a = (zlineshape->Integral(zlineshape->FindBin(20),zlineshape->FindBin(70)));
1595 buchmann 1.32 float b = (zlineshape->Integral(zlineshape->FindBin(91-Diff),zlineshape->FindBin(91+Diff)));
1596 buchmann 1.24 float r = a/b;
1597     float dr= (a/b)*TMath::Sqrt(1/a+1/b);
1598 buchmann 1.37
1599 buchmann 1.24 float SysUncertainty = TMath::Sqrt(DataEstimate*DataEstimate*dr*dr + r*r*(DataEstimate*MetPlotsSpace::Zprediction_Uncertainty*DataEstimate*MetPlotsSpace::Zprediction_Uncertainty));
1600     float StatUncertainty = TMath::Sqrt(DataEstimate);
1601    
1602 fronga 1.39 dout << "Z estimate in peak : " << DataEstimate << " +/- " << DataEstimate*MetPlotsSpace::Zprediction_Uncertainty << " (sys) +/- " << TMath::Sqrt(2*DataEstimate) << " (stat) " << endl;
1603     dout << "Z ESTIMATE IN SR : " << DataEstimate*r << " +/- " << SysUncertainty << " (sys) +/- " << StatUncertainty << " (stat) " << endl;
1604 buchmann 1.37 // cout << endl;
1605 fronga 1.39 dout << "r = " << r << " +/- " << dr << endl;
1606 buchmann 1.24
1607    
1608 buchmann 1.37 delete Ozlineshape;
1609 buchmann 1.24 delete zlineshape;
1610    
1611     PlottingSetup::Restrmasscut=TCut(restrmasscutbkp.c_str());
1612 buchmann 1.28 switch_overunderflow(false);
1613 buchmann 1.24
1614 buchmann 1.12 }
1615 buchmann 1.17