ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.56
Committed: Thu Jun 13 07:36:08 2013 UTC (11 years, 10 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.55: +61 -13 lines
Log Message:
Writing eta range on plots; Making DY test more globally accessible (using EventZToTaus instead of expecting specific sample name); Using both Z prediction methods to get combined prediction

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