ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.44
Committed: Fri Jan 25 14:00:32 2013 UTC (12 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.43: +20 -1 lines
Log Message:
Added ee/mm ratio using the 2jet bin

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