ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.47
Committed: Mon Feb 25 15:40:17 2013 UTC (12 years, 2 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.46: +5 -4 lines
Log Message:
Only use fat lines (2) when comparing data with data, not data vs mc

File Contents

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