ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.51
Committed: Tue Apr 9 14:13:08 2013 UTC (12 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.50: +51 -34 lines
Log Message:
Adapted style towards congergence: E_{T}^{miss} instead of MET, N_{jets} instead of N_{J}, mll plots starting at 20 GeV, lines at 70 GeV (end of SR), 81 and 101 (Z region)

File Contents

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