CMS 3D CMS Logo

LRHelpFunctions.cc
Go to the documentation of this file.
2 #include "TopQuarkAnalysis/TopTools/test/tdrstyle.C"
3 
4 // constructors
6  constructPurity = false;
7  setTDRStyle();
8  gStyle->SetCanvasDefW(900);
9 }
10 
11 LRHelpFunctions::LRHelpFunctions(const std::vector<int>& obsNr,
12  int nrBins,
13  const std::vector<double>& obsMin,
14  const std::vector<double>& obsMax,
15  const std::vector<const char*>& functions) {
16  obsNumbers = obsNr;
17  constructPurity = false;
18  setTDRStyle();
19  gStyle->SetCanvasDefW(900);
20  for (size_t o = 0; o < obsNr.size(); o++) {
21  // create Signal, background and s/(s+b) histogram
22  TString htS = "Obs";
23  htS += obsNr[o];
24  htS += "_S";
25  TString htB = "Obs";
26  htB += obsNr[o];
27  htB += "_B";
28  TString htSB = "Obs";
29  htSB += obsNr[o];
30  htSB += "_SoverSplusB";
31  hObsS.push_back(new TH1F(htS, htS, nrBins, obsMin[o], obsMax[o]));
32  hObsB.push_back(new TH1F(htB, htB, nrBins, obsMin[o], obsMax[o]));
33  hObsSoverSplusB.push_back(new TH1F(htSB, htSB, nrBins, obsMin[o], obsMax[o]));
34 
35  // create the correlation 2D plots among the observables (for signal)
36  for (size_t o2 = o + 1; o2 < obsNr.size(); o2++) {
37  TString hcorr = "Corr_Obs";
38  hcorr += obsNr[o];
39  hcorr += "_Obs";
40  hcorr += obsNr[o2];
41  hObsCorr.push_back(new TH2F(hcorr, hcorr, nrBins, obsMin[o], obsMax[o], nrBins, obsMin[o2], obsMax[o2]));
42  }
43 
44  // create fit functions
45  TString ftSB = "F_Obs";
46  ftSB += obsNr[o];
47  ftSB += "_SoverSplusB";
48  fObsSoverSplusB.push_back(
49  new TF1(ftSB, functions[o], hObsS[o]->GetXaxis()->GetXmin(), hObsS[o]->GetXaxis()->GetXmax()));
50  }
51 }
52 
53 void LRHelpFunctions::recreateFitFct(const std::vector<int>& obsNr, const std::vector<const char*>& functions) {
54  if (!fObsSoverSplusB.empty())
55  fObsSoverSplusB.clear();
56  for (size_t o = 0; o < obsNr.size(); o++) {
57  // create fit functions
58  TString ftSB = "F_Obs";
59  ftSB += obsNr[o];
60  ftSB += "_SoverSplusB";
61  fObsSoverSplusB.push_back(
62  new TF1(ftSB, functions[o], hObsS[o]->GetXaxis()->GetXmin(), hObsS[o]->GetXaxis()->GetXmax()));
63  }
64 }
65 
66 LRHelpFunctions::LRHelpFunctions(int nrLRbins, double LRmin, double LRmax, const char* LRfunction) {
67  constructPurity = true;
68  setTDRStyle();
69  gStyle->SetCanvasDefW(900);
70 
71  // create LR histograms
72  hLRtotS = new TH1F("hLRtotS", "hLRtotS", nrLRbins, LRmin, LRmax);
73  hLRtotS->GetXaxis()->SetTitle("Combined LR");
74  hLRtotB = new TH1F("hLRtotB", "hLRtotB", nrLRbins, LRmin, LRmax);
75  hLRtotB->GetXaxis()->SetTitle("Combined LR");
76  hLRtotSoverSplusB = new TH1F("hLRtotSoverSplusB", "hLRtotSoverSplusB", nrLRbins, LRmin, LRmax);
77 
78  // create LR fit function
79  fLRtotSoverSplusB = new TF1("fLRtotSoverSplusB", LRfunction, LRmin, LRmax);
80 }
81 
82 // destructor
84 
85 // member function to initialize the LR hists and fits
86 void LRHelpFunctions::initLRHistsAndFits(int nrLRbins, double LRmin, double LRmax, const char* LRfunction) {
87  constructPurity = true;
88  // create LR histograms
89  hLRtotS = new TH1F("hLRtotS", "hLRtotS", nrLRbins, LRmin, LRmax);
90  hLRtotB = new TH1F("hLRtotB", "hLRtotB", nrLRbins, LRmin, LRmax);
91  hLRtotSoverSplusB = new TH1F("hLRtotSoverSplusB", "hLRtotSoverSplusB", nrLRbins, LRmin, LRmax);
92  // create LR fit function
93  fLRtotSoverSplusB = new TF1("fLRtotSoverSplusB", LRfunction, LRmin, LRmax);
94 }
95 
96 // member function to set initial values to the observable fit function
97 void LRHelpFunctions::setObsFitParameters(int obs, const std::vector<double>& fitPars) {
98  for (size_t fit = 0; fit < fObsSoverSplusB.size(); fit++) {
99  TString fn = "_Obs";
100  fn += obs;
101  if (((TString)fObsSoverSplusB[fit]->GetName()).Contains(fn)) {
102  for (size_t p = 0; p < fitPars.size(); p++) {
103  fObsSoverSplusB[fit]->SetParameter(p, fitPars[p]);
104  }
105  }
106  }
107 }
108 
109 // member function to add observable values to the signal histograms
110 void LRHelpFunctions::fillToSignalHists(const std::vector<double>& obsVals, double weight) {
111  int hIndex = 0;
112  for (size_t o = 0; o < obsVals.size(); o++) {
113  hObsS[o]->Fill(obsVals[o], weight);
114  for (size_t o2 = o + 1; o2 < obsVals.size(); o2++) {
115  hObsCorr[hIndex]->Fill(obsVals[o], obsVals[o2], weight);
116  ++hIndex;
117  }
118  }
119 }
120 
121 // member function to add observable values to the signal histograms
122 void LRHelpFunctions::fillToSignalHists(int obsNbr, double obsVal, double weight) {
123  TString obs = "Obs";
124  obs += obsNbr;
125  obs += "_";
126  for (size_t f = 0; f < hObsS.size(); f++) {
127  if (((TString)(hObsS[f]->GetName())).Contains(obs)) {
128  hObsS[f]->Fill(obsVal, weight);
129  return;
130  }
131  }
132 }
133 
134 // member function to add observable values to the signal histograms
135 void LRHelpFunctions::fillToSignalCorrelation(int obsNbr1, double obsVal1, int obsNbr2, double obsVal2, double weight) {
136  TString hcorr = "Corr_Obs";
137  hcorr += std::min(obsNbr1, obsNbr2);
138  hcorr += "_Obs";
139  hcorr += std::max(obsNbr1, obsNbr2);
140  for (size_t i = 0; i < hObsCorr.size(); i++) {
141  if (((TString)(hObsCorr[i]->GetName())) == hcorr) {
142  if (obsNbr1 < obsNbr2) {
143  hObsCorr[i]->Fill(obsVal1, obsVal2, weight);
144  } else {
145  hObsCorr[i]->Fill(obsVal2, obsVal1, weight);
146  }
147  return;
148  }
149  }
150 }
151 
152 // member function to add observable values to the background histograms
153 void LRHelpFunctions::fillToBackgroundHists(const std::vector<double>& obsVals, double weight) {
154  for (size_t o = 0; o < obsVals.size(); o++)
155  hObsB[o]->Fill(obsVals[o], weight);
156 }
157 
158 // member function to add observable values to the signal histograms
159 void LRHelpFunctions::fillToBackgroundHists(int obsNbr, double obsVal, double weight) {
160  TString obs = "Obs";
161  obs += obsNbr;
162  obs += "_";
163  for (size_t f = 0; f < hObsB.size(); f++) {
164  if (((TString)(hObsB[f]->GetName())).Contains(obs)) {
165  hObsB[f]->Fill(obsVal, weight);
166  return;
167  }
168  }
169 }
170 
171 // member function to normalize the S and B spectra
173  for (size_t o = 0; o < hObsS.size(); o++) {
174  // count entries in each histo. Do it this way instead of GetEntries method,
175  // since the latter does not account for the weights.
176  double nrSignEntries = 0, nrBackEntries = 0;
177  for (int i = 0; i <= hObsS[o]->GetNbinsX() + 1; i++) {
178  nrSignEntries += hObsS[o]->GetBinContent(i);
179  nrBackEntries += hObsB[o]->GetBinContent(i);
180  }
181  for (int b = 0; b <= hObsS[o]->GetNbinsX() + 1; b++) {
182  hObsS[o]->SetBinContent(b, hObsS[o]->GetBinContent(b) / (nrSignEntries));
183  hObsB[o]->SetBinContent(b, hObsB[o]->GetBinContent(b) / (nrBackEntries));
184  hObsS[o]->SetBinError(b, hObsS[o]->GetBinError(b) / (nrSignEntries));
185  hObsB[o]->SetBinError(b, hObsB[o]->GetBinError(b) / (nrBackEntries));
186  }
187  //std::cout<<"Integral for obs"<<o<<" S: "<<hObsS[o]->Integral(0,10000)<<" & obs"<<o<<" B: "<<hObsB[o]->Integral(0,10000)<<std::endl;
188  }
189 }
190 
191 // member function to produce and fit the S/(S+B) histograms
193  for (size_t o = 0; o < hObsS.size(); o++) {
194  for (int b = 0; b <= hObsS[o]->GetNbinsX() + 1; b++) {
195  if ((hObsS[o]->GetBinContent(b) + hObsB[o]->GetBinContent(b)) > 0) {
196  hObsSoverSplusB[o]->SetBinContent(
197  b, hObsS[o]->GetBinContent(b) / (hObsS[o]->GetBinContent(b) + hObsB[o]->GetBinContent(b)));
198  double error = sqrt(pow(hObsS[o]->GetBinError(b) * hObsB[o]->GetBinContent(b) /
199  pow(hObsS[o]->GetBinContent(b) + hObsB[o]->GetBinContent(b), 2),
200  2) +
201  pow(hObsB[o]->GetBinError(b) * hObsS[o]->GetBinContent(b) /
202  pow(hObsS[o]->GetBinContent(b) + hObsB[o]->GetBinContent(b), 2),
203  2));
204  hObsSoverSplusB[o]->SetBinError(b, error);
205  }
206  }
207  hObsSoverSplusB[o]->Fit(fObsSoverSplusB[o]->GetName(), "RQ");
208  }
209 }
210 
211 // member function to read the observable hists & fits from a root-file
213  const std::vector<int>& observables,
214  bool readLRplots) {
215  hObsS.clear();
216  hObsB.clear();
217  hObsSoverSplusB.clear();
218  fObsSoverSplusB.clear();
219  TFile* fitFile = new TFile(fileName, "READ");
220  if (observables[0] == -1) {
221  std::cout << " ... will read hists and fit for all available observables in file " << fileName << std::endl;
222  TList* list = fitFile->GetListOfKeys();
223  TIter next(list);
224  TKey* el;
225  while ((el = (TKey*)next())) {
226  TString keyName = el->GetName();
227  if (keyName.Contains("F_") && keyName.Contains("_SoverSplusB")) {
228  fObsSoverSplusB.push_back(new TF1(*((TF1*)el->ReadObj())));
229  } else if (keyName.Contains("_SoverSplusB")) {
230  hObsSoverSplusB.push_back(new TH1F(*((TH1F*)el->ReadObj())));
231  } else if (keyName.Contains("_S")) {
232  hObsS.push_back(new TH1F(*((TH1F*)el->ReadObj())));
233  } else if (keyName.Contains("_B")) {
234  hObsB.push_back(new TH1F(*((TH1F*)el->ReadObj())));
235  } else if (keyName.Contains("Corr")) {
236  hObsCorr.push_back(new TH2F(*((TH2F*)el->ReadObj())));
237  }
238  }
239  } else {
240  obsNumbers = observables;
241  for (unsigned int obs = 0; obs < observables.size(); obs++) {
242  std::cout << " ... will read hists and fit for obs " << observables[obs] << " from file " << fileName
243  << std::endl;
244  TString hStitle = "Obs";
245  hStitle += observables[obs];
246  hStitle += "_S";
247  hObsS.push_back(new TH1F(*((TH1F*)fitFile->GetKey(hStitle)->ReadObj())));
248  TString hBtitle = "Obs";
249  hBtitle += observables[obs];
250  hBtitle += "_B";
251  hObsB.push_back(new TH1F(*((TH1F*)fitFile->GetKey(hBtitle)->ReadObj())));
252  TString hSBtitle = "Obs";
253  hSBtitle += observables[obs];
254  hSBtitle += "_SoverSplusB";
255  TString fSBtitle = "F_";
256  fSBtitle += hSBtitle;
257  hObsSoverSplusB.push_back(new TH1F(*((TH1F*)fitFile->GetKey(hSBtitle)->ReadObj())));
258  fObsSoverSplusB.push_back(new TF1(*((TF1*)fitFile->GetKey(fSBtitle)->ReadObj())));
259  for (unsigned int obs2 = obs + 1; obs2 < observables.size(); obs2++) {
260  TString hCorrtitle = "Corr_Obs";
261  hCorrtitle += observables[obs];
262  hCorrtitle += "_Obs";
263  hCorrtitle += observables[obs2];
264  hObsCorr.push_back(new TH2F(*((TH2F*)fitFile->GetKey(hCorrtitle)->ReadObj())));
265  }
266  }
267  }
268 
269  if (readLRplots) {
270  constructPurity = true;
271  std::cout << " ... will LR s and B histos from file " << fileName << std::endl;
272  hLRtotS = new TH1F(*((TH1F*)fitFile->GetKey("hLRtotS")->ReadObj()));
273  hLRtotB = new TH1F(*((TH1F*)fitFile->GetKey("hLRtotB")->ReadObj()));
274  hLRtotSoverSplusB = new TH1F(*((TH1F*)fitFile->GetKey("hLRtotSoverSplusB")->ReadObj()));
275  fLRtotSoverSplusB = new TF1(*((TF1*)fitFile->GetKey("fLRtotSoverSplusB")->ReadObj()));
276  }
277 }
278 
279 // member function to store all observable plots and fits to a ROOT-file
281  TFile fOut(fname, "RECREATE");
282  fOut.cd();
283  for (size_t o = 0; o < hObsS.size(); o++) {
284  hObsS[o]->Write();
285  hObsB[o]->Write();
286  hObsSoverSplusB[o]->Write();
287  fObsSoverSplusB[o]->Write();
288  }
289  int hIndex = 0;
290  for (size_t o = 0; o < hObsS.size(); o++) {
291  for (size_t o2 = o + 1; o2 < hObsS.size(); o2++) {
292  hObsCorr[hIndex]->Write();
293  ++hIndex;
294  }
295  }
296  if (constructPurity) {
297  hLRtotS->Write();
298  hLRtotB->Write();
299  hLRtotSoverSplusB->Write();
300  fLRtotSoverSplusB->Write();
301  hEffvsPur->Write();
302  hLRValvsPur->Write();
303  hLRValvsEff->Write();
304  }
305  fOut.cd();
306  fOut.Write();
307  fOut.Close();
308 }
309 
310 // member function to make some simple control plots and store them in a ps-file
312  TCanvas c("dummy", "", 1);
313  c.Print(fname + "[", "landscape");
314  for (size_t o = 0; o < hObsS.size(); o++) {
315  TCanvas c2("c2", "", 1);
316  c2.Divide(2, 1);
317  c2.cd(1);
318  hObsS[o]->SetLineColor(2);
319  if (hObsB[o]->GetMaximum() > hObsS[o]->GetMaximum()) {
320  hObsB[o]->Draw("hist");
321  hObsS[o]->Draw("histsame");
322  } else {
323  hObsS[o]->Draw("hist");
324  hObsB[o]->Draw("histsame");
325  }
326  c2.cd(2);
327  hObsSoverSplusB[o]->Draw();
328  fObsSoverSplusB[o]->Draw("same");
329  c2.Print(fname, "Landscape");
330  }
331 
332  int hIndex = 0;
333  for (size_t o = 0; o < hObsS.size(); o++) {
334  for (size_t o2 = o + 1; o2 < hObsS.size(); o2++) {
335  TCanvas cc("cc", "", 1);
336  hObsCorr[hIndex]->Draw("box");
337  TPaveText pt(0.5, 0.87, 0.98, 0.93, "blNDC");
338  pt.SetFillStyle(1);
339  pt.SetFillColor(0);
340  pt.SetBorderSize(0);
341  TString tcorr = "Corr. of ";
342  tcorr += (int)(100. * hObsCorr[hIndex]->GetCorrelationFactor());
343  tcorr += " %";
344  //TText *text = pt.AddText(tcorr);
345  pt.Draw("same");
346  ++hIndex;
347  cc.Print(fname, "Landscape");
348  }
349  }
350 
351  if (constructPurity) {
352  TCanvas c3("c3", "", 1);
353  c3.Divide(2, 1);
354  c3.cd(1);
355  hLRtotB->Draw();
356  hLRtotS->SetLineColor(2);
357  hLRtotS->Draw("same");
358  c3.cd(2);
359  hLRtotSoverSplusB->Draw();
360  c3.Print(fname, "Landscape");
361 
362  TCanvas c4("c4", "", 1);
363  hEffvsPur->Draw("AL*");
364  c4.Print(fname, "Landscape");
365 
366  TCanvas c5("c5", "", 1);
367  hLRValvsPur->Draw("AL*");
368  c5.Print(fname, "Landscape");
369 
370  TCanvas c6("c6", "", 1);
371  hLRValvsEff->Draw("AL*");
372  c6.Print(fname, "Landscape");
373  }
374  c.Print(fname + "]", "landscape");
375 }
376 
377 // member function to calculate the LR value, using the S/N definition
378 double LRHelpFunctions::calcLRval(const std::vector<double>& vals) {
379  double logLR = 0.;
380  for (size_t o = 0; o < fObsSoverSplusB.size(); o++) {
381  double SoverSplusN = fObsSoverSplusB[o]->Eval(vals[o]);
382  double SoverN = 1. / ((1. / SoverSplusN) - 1.);
383  logLR += log(SoverN);
384  }
385  return logLR;
386 }
387 
388 // member function to calculate the LR value, using the definition that was
389 // used in the P-TDR: S/(S+N)
390 
391 double LRHelpFunctions::calcPtdrLRval(const std::vector<double>& vals, bool useCorrelation) {
392  double logLR = 1.;
393  for (size_t o = 0; o < fObsSoverSplusB.size(); o++) {
394  double SoverSplusN = fObsSoverSplusB[o]->Eval(vals[o]);
395  if (SoverSplusN < 0.0001)
396  SoverSplusN = 0.0001;
397  if (useCorrelation) {
398  double corr = 0;
399  for (size_t j = 0; j < fObsSoverSplusB.size(); j++) {
400  if (o == j)
401  ++corr;
402  else {
403  TString hcorr = "Corr_Obs";
404  hcorr += std::min(obsNumbers[o], obsNumbers[j]);
405  hcorr += "_Obs";
406  hcorr += std::max(obsNumbers[o], obsNumbers[j]);
407  for (size_t i = 0; i < hObsCorr.size(); i++) {
408  if (((TString)(hObsCorr[i]->GetName())) == hcorr)
409  corr += fabs(hObsCorr[i]->GetCorrelationFactor());
410  }
411  }
412  }
413  logLR *= pow(SoverSplusN / fObsSoverSplusB[o]->GetMaximum(), 1. / corr);
414  } else
415  logLR *= SoverSplusN / fObsSoverSplusB[o]->GetMaximum();
416  }
417  //std::cout <<logLR<<std::endl;
418  return logLR;
419 }
420 
421 // member function to fill a signal contribution to the LR histogram
423  // std::cout<< "@@@===> LRHelpf Signal LRval = "<< val<<std::endl;
424  hLRtotS->Fill(val, weight);
425 }
426 
427 // member function to fill a background contribution to the LR histogram
429  // std::cout<< "@@@===> LRHelpf Backgroud LRval = "<< val<<std::endl;
430  hLRtotB->Fill(val, weight);
431 }
432 
433 // member function to make and fit the purity vs. LRval histogram, and the purity vs. efficiency graph
435  for (int b = 0; b <= hLRtotS->GetNbinsX(); b++) {
436  float Sint = hLRtotS->Integral(b, hLRtotS->GetNbinsX() + 1);
437  float Bint = hLRtotB->Integral(b, hLRtotB->GetNbinsX() + 1);
438  if (Sint + Bint > 0) {
439  hLRtotSoverSplusB->SetBinContent(b, 1. * Sint / (Sint + Bint));
440  hLRtotSoverSplusB->SetBinError(
441  b, sqrt((pow(Sint * sqrt(Bint), 2) + pow(Bint * sqrt(Sint), 2))) / pow((Sint + Bint), 2));
442  }
443  }
444 
445  hLRtotS->GetXaxis()->SetTitle("Combined LR ratio");
446  hLRtotB->GetXaxis()->SetTitle("Combined LR ratio");
447  hLRtotSoverSplusB->GetXaxis()->SetTitle("Cut on Combined LR");
448  hLRtotSoverSplusB->GetYaxis()->SetTitle("Purity");
449 
450  hLRtotSoverSplusB->Fit(fLRtotSoverSplusB->GetName(), "RQ");
451  double totSignal = hLRtotS->Integral(0, hLRtotS->GetNbinsX() + 1);
452  double Eff[200], Pur[200], LRVal[200];
453  if (hLRtotS->GetNbinsX() > 200) {
454  std::cout << "Number of bins of LR histograms can not execeed 200!" << std::endl;
455  return;
456  }
457  for (int cut = 0; (cut <= hLRtotS->GetNbinsX()) && (cut < 200); cut++) {
458  double LRcutVal = hLRtotS->GetBinLowEdge(cut);
459  Eff[cut] = hLRtotS->Integral(cut, hLRtotS->GetNbinsX() + 1) / totSignal;
460  Pur[cut] = fLRtotSoverSplusB->Eval(LRcutVal);
461  LRVal[cut] = LRcutVal;
462  }
463  hEffvsPur = new TGraph(hLRtotS->GetNbinsX(), Eff, Pur);
464  hEffvsPur->SetName("hEffvsPur");
465  hEffvsPur->SetTitle("");
466  hEffvsPur->GetXaxis()->SetTitle((TString)("Efficiency of cut on log combined LR"));
467  hEffvsPur->GetYaxis()->SetTitle((TString)("Purity"));
468  hEffvsPur->GetYaxis()->SetRangeUser(0, 1.1);
469 
470  hLRValvsPur = new TGraph(hLRtotS->GetNbinsX(), LRVal, Pur);
471  hLRValvsPur->SetName("hLRValvsPur");
472  hLRValvsPur->SetTitle("");
473  hLRValvsPur->GetXaxis()->SetTitle((TString)("Cut on the log combined LR value"));
474  hLRValvsPur->GetYaxis()->SetTitle((TString)("Purity"));
475  hLRValvsPur->GetYaxis()->SetRangeUser(0, 1.1);
476 
477  hLRValvsEff = new TGraph(hLRtotS->GetNbinsX(), LRVal, Eff);
478  hLRValvsEff->SetName("hLRValvsEff");
479  hLRValvsEff->SetTitle("");
480  hLRValvsEff->GetXaxis()->SetTitle((TString)("Cut on the log combined LR value"));
481  hLRValvsEff->GetYaxis()->SetTitle((TString)("Efficiency of cut on log combined LR"));
482  hLRValvsEff->GetYaxis()->SetRangeUser(0, 1.1);
483 }
484 
485 // member function to calculate the probability for signal given a logLR value
486 double LRHelpFunctions::calcProb(double logLR) { return fLRtotSoverSplusB->Eval(logLR); }
487 
488 // member to check if a certain S/S+B fit function is read from the root-file
490  bool included = false;
491  TString obs = "_Obs";
492  obs += o;
493  obs += "_";
494  for (size_t f = 0; f < fObsSoverSplusB.size(); f++) {
495  if (((TString)(fObsSoverSplusB[f]->GetName())).Contains(obs))
496  included = true;
497  }
498  return included;
499 }
500 
501 void LRHelpFunctions::setXlabels(const std::vector<std::string>& xLabels) {
502  if (hObsS.size() != xLabels.size()) {
503  std::cout << "LRHelpFunctions::setXlabels: Number of labels (" << xLabels.size()
504  << ") does not match number of obervables(" << hObsS.size() << ").\n";
505  return;
506  }
507  for (size_t i = 0; i < hObsS.size(); ++i) {
508  hObsS[i]->GetXaxis()->SetTitle(TString(xLabels[i]));
509  hObsB[i]->GetXaxis()->SetTitle(TString(xLabels[i]));
510  hObsSoverSplusB[i]->GetXaxis()->SetTitle(TString(xLabels[i]));
511  hObsSoverSplusB[i]->GetYaxis()->SetTitle(TString("S/(S+B)"));
512  }
513 }
514 
515 void LRHelpFunctions::setYlabels(const std::vector<std::string>& yLabels) {
516  if (hObsS.size() != yLabels.size()) {
517  std::cout << "LRHelpFunctions::setYlabels: Number of labels (" << yLabels.size()
518  << ") does not match number of obervables(" << hObsS.size() << ").\n";
519  return;
520  }
521  for (size_t i = 0; i < hObsS.size(); ++i) {
522  hObsS[i]->GetYaxis()->SetTitle(TString(yLabels[i]));
523  hObsB[i]->GetYaxis()->SetTitle(TString(yLabels[i]));
524  }
525 }
526 
527 void LRHelpFunctions::singlePlot(const TString& fname, int obsNbr, const TString& extension) {
528  if (!obsFitIncluded(obsNbr))
529  return;
530 
531  TStyle* tdrStyle = gROOT->GetStyle("tdrStyle");
532  tdrStyle->SetOptFit(0);
533  tdrStyle->SetOptStat(0);
534  tdrStyle->SetOptTitle(0);
535  // tdrStyle->SetPadTopMargin(0.01);
536  // tdrStyle->SetPadBottomMargin(0.01);
537  // tdrStyle->SetPadLeftMargin(0.01);
538  // tdrStyle->SetPadRightMargin(0.01);
539 
540  TCanvas c2("c2", "", 600, 300);
541  c2.SetTopMargin(0.01);
542  c2.SetBottomMargin(0.01);
543  c2.SetLeftMargin(0.01);
544  c2.SetRightMargin(0.01);
545  std::cout << fname << std::endl;
546  c2.Divide(2, 1);
547 
548  TString obs = "Obs";
549  obs += obsNbr;
550  obs += "_";
551  for (size_t o = 0; o < hObsB.size(); ++o) {
552  if (((TString)(hObsB[o]->GetName())).Contains(obs)) {
553  c2.cd(1);
554  hObsS[o]->SetLineColor(2);
555  if (hObsB[o]->GetMaximum() > hObsS[o]->GetMaximum()) {
556  hObsB[o]->Draw("hist");
557  hObsS[o]->Draw("histsame");
558  } else {
559  hObsS[o]->Draw("hist");
560  hObsB[o]->Draw("histsame");
561  }
562  c2.cd(2);
563 
564  hObsSoverSplusB[o]->Draw();
565  fObsSoverSplusB[o]->Draw("same");
566  }
567  }
568  std::cout << fname + "." + extension << std::endl;
569  c2.Print(fname + "." + extension);
570 }
571 
572 void LRHelpFunctions::purityPlot(const TString& fname, const TString& extension) {
573  TStyle* tdrStyle = gROOT->GetStyle("tdrStyle");
574  tdrStyle->SetOptFit(0);
575  tdrStyle->SetOptStat(0);
576  tdrStyle->SetOptTitle(0);
577  // tdrStyle->SetPadTopMargin(0.01);
578  // tdrStyle->SetPadBottomMargin(0.01);
579  // tdrStyle->SetPadLeftMargin(0.01);
580  // tdrStyle->SetPadRightMargin(0.01);
581 
582  TCanvas c2("c2", "", 600, 300);
583  c2.SetTopMargin(0.01);
584  c2.SetBottomMargin(0.01);
585  c2.SetLeftMargin(0.01);
586  c2.SetRightMargin(0.01);
587  std::cout << fname << std::endl;
588  c2.Divide(2, 1);
589 
590  c2.cd(1);
591  hLRValvsPur->Draw("AP");
592  c2.cd(2);
593  hEffvsPur->Draw("AP");
594  c2.Print(fname + "Purity." + extension);
595 
596  hLRtotS->GetXaxis()->SetNdivisions(505);
597  hLRtotB->GetXaxis()->SetNdivisions(505);
598  TCanvas c3("c2", "", 300, 300);
599  // c3.SetTopMargin(0.01);
600  // c3.SetBottomMargin(0.01);
601  // c3.SetLeftMargin(0.01);
602  // c3.SetRightMargin(0.01);
603  hLRtotS->GetXaxis()->SetTitle("Combined LR");
604  hLRtotB->GetXaxis()->SetTitle("Combined LR");
605 
606  hLRtotB->Draw();
607  hLRtotS->SetLineColor(2);
608  hLRtotS->Draw("same");
609  c3.Print(fname + "Dist." + extension);
610 
611  TCanvas c5("c3", "", 900, 600);
612  c5.Divide(2, 2);
613  c5.cd(1);
614  hLRtotB->Draw();
615  hLRtotS->SetLineColor(2);
616  hLRtotS->Draw("same");
617  c5.cd(3);
618  hLRValvsEff->Draw("AP");
619  c5.cd(2);
620  hEffvsPur->Draw("AP");
621  c5.cd(4);
622  hLRtotSoverSplusB->Draw();
623  c5.Print(fname + "all." + extension);
624 }
void storeControlPlots(const TString &)
double calcLRval(const std::vector< double > &)
std::vector< TH1F * > hObsSoverSplusB
void setXlabels(const std::vector< std::string > &xLabels)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
std::vector< TH1F * > hObsS
double calcPtdrLRval(const std::vector< double > &vals, bool useCorrelation=false)
void makeAndFitPurityHists()
Definition: weight.py:1
double calcProb(double)
std::vector< TH1F * > hObsB
void setYlabels(const std::vector< std::string > &yLabels)
TGraph * hLRValvsEff
bool obsFitIncluded(int)
std::vector< TH2F * > hObsCorr
TGraph * hLRValvsPur
void fillToBackgroundHists(const std::vector< double > &, double weight=1.0)
void fillToSignalCorrelation(int obsNbr1, double obsVal1, int obsNbr2, double obsVal2, double weight)
void makeAndFitSoverSplusBHists()
dictionary corr
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T sqrt(T t)
Definition: SSEVec.h:23
def setTDRStyle()
Definition: plotscripts.py:89
double f[11][100]
void storeToROOTfile(const TString &)
std::vector< int > obsNumbers
void fillLRSignalHist(double, double weight=1.0)
void singlePlot(const TString &fname, int obsNbr, const TString &extension=TString("eps"))
void readObsHistsAndFits(const TString &, const std::vector< int > &, bool)
void fillToSignalHists(const std::vector< double > &, double weight=1.0)
void setObsFitParameters(int obs, const std::vector< double > &)
double b
Definition: hdecay.h:120
string fname
main script
std::vector< TF1 * > fObsSoverSplusB
void initLRHistsAndFits(int, double, double, const char *)
void fillLRBackgroundHist(double, double weight=1.0)
TH1F * hLRtotSoverSplusB
void recreateFitFct(const std::vector< int > &obsNr, const std::vector< const char *> &functions)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
void purityPlot(const TString &fname, const TString &extension=TString("eps"))