ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.50
Committed: Fri Mar 22 17:17:20 2013 UTC (12 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.49: +127 -10 lines
Log Message:
Added function to compute r_{\mu e} ; split results up into ee/mm and split OF up into em/me

File Contents

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