ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.46
Committed: Fri Feb 15 22:24:23 2013 UTC (12 years, 2 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.45: +92 -28 lines
Log Message:
Super re-enforce Aachen selection when in use (to avoid accidentally restricting the eta range through 'leptoncut', or computing the peak position with tight selection etc.

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