ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.52
Committed: Fri Apr 26 06:44:13 2013 UTC (12 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.51: +161 -97 lines
Log Message:
Added MC yields, made sure everything starts at 20 GeV in the dileptonic mass distribution (no underflow from 15); added cross-checks; added much more information about control regions 1&2, also compatibility for Aachen; adapted code not to use smeared DY for MC yields (in order to be compatible with Aachen)

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