2 #include "TopQuarkAnalysis/TopTools/test/tdrstyle.C"
8 gStyle->SetCanvasDefW(900);
13 const std::vector<double>& obsMin,
14 const std::vector<double>& obsMax,
15 const std::vector<const char*>& functions) {
19 gStyle->SetCanvasDefW(900);
20 for (
size_t o = 0;
o < obsNr.size();
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]));
36 for (
size_t o2 = o + 1; o2 < obsNr.size(); o2++) {
37 TString hcorr =
"Corr_Obs";
41 hObsCorr.push_back(
new TH2F(hcorr, hcorr, nrBins, obsMin[o], obsMax[o], nrBins, obsMin[o2], obsMax[o2]));
45 TString ftSB =
"F_Obs";
47 ftSB +=
"_SoverSplusB";
49 new TF1(ftSB, functions[o],
hObsS[o]->GetXaxis()->GetXmin(),
hObsS[o]->GetXaxis()->GetXmax()));
56 for (
size_t o = 0;
o < obsNr.size();
o++) {
58 TString ftSB =
"F_Obs";
60 ftSB +=
"_SoverSplusB";
62 new TF1(ftSB, functions[
o],
hObsS[o]->GetXaxis()->GetXmin(),
hObsS[o]->GetXaxis()->GetXmax()));
69 gStyle->SetCanvasDefW(900);
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);
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);
102 for (
size_t p = 0;
p < fitPars.size();
p++) {
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);
126 for (
size_t f = 0;
f <
hObsS.size();
f++) {
127 if (((TString)(
hObsS[
f]->GetName())).Contains(obs)) {
128 hObsS[
f]->Fill(obsVal, weight);
136 TString hcorr =
"Corr_Obs";
137 hcorr +=
std::min(obsNbr1, obsNbr2);
139 hcorr +=
std::max(obsNbr1, obsNbr2);
141 if (((TString)(
hObsCorr[
i]->GetName())) == hcorr) {
142 if (obsNbr1 < obsNbr2) {
143 hObsCorr[
i]->Fill(obsVal1, obsVal2, weight);
145 hObsCorr[
i]->Fill(obsVal2, obsVal1, weight);
154 for (
size_t o = 0;
o < obsVals.size();
o++)
163 for (
size_t f = 0;
f <
hObsB.size();
f++) {
164 if (((TString)(
hObsB[
f]->GetName())).Contains(obs)) {
165 hObsB[
f]->Fill(obsVal, weight);
173 for (
size_t o = 0;
o <
hObsS.size();
o++) {
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);
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));
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) {
213 const std::vector<int>& observables,
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();
225 while ((el = (TKey*)
next())) {
226 TString keyName = el->GetName();
227 if (keyName.Contains(
"F_") && keyName.Contains(
"_SoverSplusB")) {
229 }
else if (keyName.Contains(
"_SoverSplusB")) {
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())));
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
244 TString hStitle =
"Obs";
245 hStitle += observables[obs];
247 hObsS.push_back(
new TH1F(*((TH1F*)fitFile->GetKey(hStitle)->ReadObj())));
248 TString hBtitle =
"Obs";
249 hBtitle += observables[obs];
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())));
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()));
281 TFile fOut(fname,
"RECREATE");
283 for (
size_t o = 0;
o <
hObsS.size();
o++) {
290 for (
size_t o = 0;
o <
hObsS.size();
o++) {
291 for (
size_t o2 =
o + 1; o2 <
hObsS.size(); o2++) {
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);
318 hObsS[
o]->SetLineColor(2);
321 hObsS[
o]->Draw(
"histsame");
324 hObsB[
o]->Draw(
"histsame");
329 c2.Print(fname,
"Landscape");
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);
337 TPaveText
pt(0.5, 0.87, 0.98, 0.93,
"blNDC");
341 TString tcorr =
"Corr. of ";
342 tcorr += (int)(100. *
hObsCorr[hIndex]->GetCorrelationFactor());
347 cc.Print(fname,
"Landscape");
352 TCanvas c3(
"c3",
"", 1);
360 c3.Print(fname,
"Landscape");
362 TCanvas c4(
"c4",
"", 1);
364 c4.Print(fname,
"Landscape");
366 TCanvas c5(
"c5",
"", 1);
368 c5.Print(fname,
"Landscape");
370 TCanvas c6(
"c6",
"", 1);
372 c6.Print(fname,
"Landscape");
374 c.Print(fname +
"]",
"landscape");
382 double SoverN = 1. / ((1. / SoverSplusN) - 1.);
383 logLR +=
log(SoverN);
395 if (SoverSplusN < 0.0001)
396 SoverSplusN = 0.0001;
397 if (useCorrelation) {
403 TString hcorr =
"Corr_Obs";
408 if (((TString)(
hObsCorr[
i]->GetName())) == hcorr)
409 corr += fabs(
hObsCorr[
i]->GetCorrelationFactor());
435 for (
int b = 0;
b <=
hLRtotS->GetNbinsX();
b++) {
438 if (Sint + Bint > 0) {
445 hLRtotS->GetXaxis()->SetTitle(
"Combined LR ratio");
446 hLRtotB->GetXaxis()->SetTitle(
"Combined LR ratio");
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;
458 double LRcutVal =
hLRtotS->GetBinLowEdge(
cut);
461 LRVal[
cut] = LRcutVal;
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);
473 hLRValvsPur->GetXaxis()->SetTitle((TString)(
"Cut on the log combined LR value"));
474 hLRValvsPur->GetYaxis()->SetTitle((TString)(
"Purity"));
480 hLRValvsEff->GetXaxis()->SetTitle((TString)(
"Cut on the log combined LR value"));
481 hLRValvsEff->GetYaxis()->SetTitle((TString)(
"Efficiency of cut on log combined LR"));
490 bool included =
false;
491 TString obs =
"_Obs";
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";
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]));
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";
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]));
531 TStyle*
tdrStyle = gROOT->GetStyle(
"tdrStyle");
532 tdrStyle->SetOptFit(0);
533 tdrStyle->SetOptStat(0);
534 tdrStyle->SetOptTitle(0);
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);
551 for (
size_t o = 0;
o <
hObsB.size(); ++
o) {
552 if (((TString)(
hObsB[
o]->GetName())).Contains(obs)) {
554 hObsS[
o]->SetLineColor(2);
557 hObsS[
o]->Draw(
"histsame");
560 hObsB[
o]->Draw(
"histsame");
568 std::cout << fname +
"." + extension << std::endl;
569 c2.Print(fname +
"." + extension);
573 TStyle*
tdrStyle = gROOT->GetStyle(
"tdrStyle");
574 tdrStyle->SetOptFit(0);
575 tdrStyle->SetOptStat(0);
576 tdrStyle->SetOptTitle(0);
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);
594 c2.Print(fname +
"Purity." + extension);
596 hLRtotS->GetXaxis()->SetNdivisions(505);
597 hLRtotB->GetXaxis()->SetNdivisions(505);
598 TCanvas c3(
"c2",
"", 300, 300);
603 hLRtotS->GetXaxis()->SetTitle(
"Combined LR");
604 hLRtotB->GetXaxis()->SetTitle(
"Combined LR");
609 c3.Print(fname +
"Dist." + extension);
611 TCanvas c5(
"c3",
"", 900, 600);
623 c5.Print(fname +
"all." + extension);
void storeControlPlots(const TString &)
double calcLRval(const std::vector< double > &)
std::vector< TH1F * > hObsSoverSplusB
void setXlabels(const std::vector< std::string > &xLabels)
static std::vector< std::string > checklist log
const edm::EventSetup & c
void recreateFitFct(const std::vector< int > &obsNr, const std::vector< const char * > &functions)
std::vector< TH1F * > hObsS
double calcPtdrLRval(const std::vector< double > &vals, bool useCorrelation=false)
void makeAndFitPurityHists()
std::vector< TH1F * > hObsB
void setYlabels(const std::vector< std::string > &yLabels)
std::vector< TH2F * > hObsCorr
void fillToBackgroundHists(const std::vector< double > &, double weight=1.0)
void fillToSignalCorrelation(int obsNbr1, double obsVal1, int obsNbr2, double obsVal2, double weight)
void makeAndFitSoverSplusBHists()
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
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 > &)
std::vector< TF1 * > fObsSoverSplusB
void initLRHistsAndFits(int, double, double, const char *)
void fillLRBackgroundHist(double, double weight=1.0)
Power< A, B >::type pow(const A &a, const B &b)
void normalizeSandBhists()
void purityPlot(const TString &fname, const TString &extension=TString("eps"))