ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.45
Committed: Fri Feb 1 11:42:49 2013 UTC (12 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.44: +77 -8 lines
Log Message:
Added MC yields for signal regions; added selection on each canvas; adapted y range for Aachen selection

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