ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.41
Committed: Tue Dec 11 09:11:11 2012 UTC (12 years, 4 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.40: +120 -14 lines
Log Message:
Added ratio with systematic band

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