2 #ifndef FlavourHistograms_H
3 #define FlavourHistograms_H
15 #include "TEfficiency.h"
34 const double& lowerBound_,
35 const double& upperBound_,
38 const unsigned int& mc,
44 const double& lowerBound_,
45 const double& upperBound_,
46 const bool& statistics_,
48 const bool& plotNormalized_,
51 const unsigned int& mc,
59 void fill(
const int&
flavour,
const T& variable,
const T&
w)
const;
160 const double& lowerBound_,
161 const double& upperBound_,
164 const unsigned int& mc,
166 : theMaxDimension(-1),
168 theBaseNameTitle(baseNameTitle_),
169 theBaseNameDescription(baseNameDescription_),
171 theLowerBound(lowerBound_),
172 theUpperBound(upperBound_),
173 theStatistics(
false),
175 thePlotNormalized(
false),
176 thePlotFirst(plotFirst_),
188 std::cout <<
"FlavourHistograms::FlavourHistograms : thePlotFirst was not correct : " <<
thePlotFirst << std::endl;
189 std::cout <<
"FlavourHistograms::FlavourHistograms : Set it to default value (l)! " << std::endl;
236 const double& lowerBound_,
237 const double& upperBound_,
238 const bool& statistics_,
239 const bool& plotLog_,
240 const bool& plotNormalized_,
243 const unsigned int& mc,
245 : theMaxDimension(-1),
247 theBaseNameTitle(baseNameTitle_),
248 theBaseNameDescription(baseNameDescription_),
250 theLowerBound(lowerBound_),
251 theUpperBound(upperBound_),
252 theStatistics(statistics_),
253 thePlotLog(plotLog_),
254 thePlotNormalized(plotNormalized_),
255 thePlotFirst(plotFirst_),
267 std::cout <<
"FlavourHistograms::FlavourHistograms : thePlotFirst was not correct : " <<
thePlotFirst << std::endl;
268 std::cout <<
"FlavourHistograms::FlavourHistograms : Set it to default value (l)! " << std::endl;
354 fillVariable(flavour, variable, 1.);
360 fillVariable(flavour, variable, w);
365 if (theArrayDimension ==
nullptr) {
367 fillVariable(flavour, *variable, 1.);
370 int iMax = (*theArrayDimension > theMaxDimension) ? theMaxDimension : *theArrayDimension;
372 for (
int i = 0;
i != iMax; ++
i) {
374 if ((theIndexToPlot < 0) || (
i == theIndexToPlot)) {
375 fillVariable(flavour, *(variable +
i), 1.);
380 if (theIndexToPlot >= iMax) {
382 const T& theZero =
static_cast<T>(0.0);
383 fillVariable(flavour, theZero, 1.);
391 theHisto_all->setAxisTitle(title);
394 theHisto_d->setAxisTitle(title);
395 theHisto_u->setAxisTitle(title);
396 theHisto_s->setAxisTitle(title);
397 theHisto_g->setAxisTitle(title);
398 theHisto_dus->setAxisTitle(title);
400 theHisto_c->setAxisTitle(title);
401 theHisto_b->setAxisTitle(title);
402 theHisto_ni->setAxisTitle(title);
403 theHisto_dusg->setAxisTitle(title);
404 theHisto_pu->setAxisTitle(title);
412 bool btppColour =
true;
418 gPad->UseCurrentStyle();
431 gPad->SetTitle(
nullptr);
434 int col[4], lineStyle[4], markerStyle[4];
437 const double markerSize = gPad->GetWh() * gPad->GetHNDC() / 500.;
440 histo[0] = theHisto_dusg;
442 histo[1] = theHisto_b;
443 histo[2] = theHisto_c;
448 max = theHisto_dusg->getTH1F()->GetMaximum();
449 if (theHisto_b->getTH1F()->GetMaximum() >
max)
450 max = theHisto_b->getTH1F()->GetMaximum();
451 if (theHisto_c->getTH1F()->GetMaximum() >
max)
452 max = theHisto_c->getTH1F()->GetMaximum();
456 histo[3] = theHisto_ni;
457 if (theHisto_ni->getTH1F()->GetMaximum() >
max)
458 max = theHisto_ni->
getTH1F()->GetMaximum();
493 if (thePlotFirst ==
"c") {
494 histo[0] = theHisto_c;
499 histo[2] = theHisto_dusg;
507 if (thePlotFirst ==
"b") {
508 histo[0] = theHisto_b;
513 histo[1] = theHisto_dusg;
521 histo[0]->
getTH1F()->GetYaxis()->SetTitle(
"Arbitrary Units");
522 histo[0]->
getTH1F()->GetYaxis()->SetTitleOffset(1.25);
524 for (
int i = 0;
i != 4; ++
i) {
525 if (histo[
i] ==
nullptr)
527 histo[
i]->
getTH1F()->SetStats(
false);
528 histo[
i]->
getTH1F()->SetLineStyle(lineStyle[
i]);
529 histo[
i]->
getTH1F()->SetLineWidth(lineWidth);
530 histo[
i]->
getTH1F()->SetLineColor(col[i]);
531 histo[
i]->
getTH1F()->SetMarkerStyle(markerStyle[i]);
532 histo[
i]->
getTH1F()->SetMarkerColor(col[i]);
533 histo[
i]->
getTH1F()->SetMarkerSize(markerSize);
536 if (thePlotNormalized) {
537 if (histo[0]->getTH1F()->GetEntries() != 0) {
538 histo[0]->
getTH1F()->DrawNormalized();
540 histo[0]->
getTH1F()->SetMaximum(1.0);
543 if (histo[1]->getTH1F()->GetEntries() != 0)
544 histo[1]->
getTH1F()->DrawNormalized(
"Same");
545 if (histo[2]->getTH1F()->GetEntries() != 0)
546 histo[2]->
getTH1F()->DrawNormalized(
"Same");
547 if ((histo[3] !=
nullptr) && (histo[3]->getTH1F()->GetEntries() != 0))
548 histo[3]->
getTH1F()->DrawNormalized(
"Same");
550 histo[0]->
getTH1F()->SetMaximum(max * 1.05);
552 histo[0]->
getTH1F()->SetMinimum(theMin);
554 histo[1]->
getTH1F()->Draw(
"Same");
555 histo[2]->
getTH1F()->Draw(
"Same");
556 if (histo[3] !=
nullptr)
557 histo[3]->
getTH1F()->Draw(
"Same");
563 TCanvas tc(theBaseNameTitle.c_str(), theBaseNameDescription.c_str());
566 tc.Print((name + theBaseNameTitle +
".eps").c_str());
571 double effVal = num / den;
572 double errLo = TEfficiency::ClopperPearson(static_cast<int>(den), static_cast<int>(num), 0.683,
false);
573 double errUp = TEfficiency::ClopperPearson(static_cast<int>(den), static_cast<int>(num), 0.683,
true);
574 return std::max(effVal - errLo, errUp - effVal);
581 double numVal = num->GetBinContent(bin);
582 double denVal = den->GetBinContent(bin);
583 if (denVal > 0 && numVal <= denVal) {
584 effVal = numVal / denVal;
585 errVal = ClopperPearsonUnc(numVal, denVal);
587 num->SetBinContent(bin, effVal);
588 num->SetBinError(bin, errVal);
593 for (
int bin = 0;
bin < theNBins + 2;
bin++) {
595 ComputeEfficiency(theHisto_all->getTH1F(), bHD.
histo_all(),
bin);
598 ComputeEfficiency(theHisto_d->getTH1F(), bHD.
histo_d(),
bin);
599 ComputeEfficiency(theHisto_u->getTH1F(), bHD.
histo_u(),
bin);
600 ComputeEfficiency(theHisto_s->getTH1F(), bHD.
histo_s(),
bin);
601 ComputeEfficiency(theHisto_g->getTH1F(), bHD.
histo_g(),
bin);
602 ComputeEfficiency(theHisto_dus->getTH1F(), bHD.
histo_dus(),
bin);
604 ComputeEfficiency(theHisto_c->getTH1F(), bHD.
histo_c(),
bin);
605 ComputeEfficiency(theHisto_b->getTH1F(), bHD.
histo_b(),
bin);
606 ComputeEfficiency(theHisto_ni->getTH1F(), bHD.
histo_ni(),
bin);
607 ComputeEfficiency(theHisto_dusg->getTH1F(), bHD.
histo_dusg(),
bin);
608 ComputeEfficiency(theHisto_pu->getTH1F(), bHD.
histo_pu(),
bin);
616 theHisto_all->setEfficiencyFlag();
619 theHisto_d->setEfficiencyFlag();
620 theHisto_u->setEfficiencyFlag();
621 theHisto_s->setEfficiencyFlag();
622 theHisto_g->setEfficiencyFlag();
623 theHisto_dus->setEfficiencyFlag();
625 theHisto_c->setEfficiencyFlag();
626 theHisto_b->setEfficiencyFlag();
627 theHisto_ni->setEfficiencyFlag();
628 theHisto_dusg->setEfficiencyFlag();
629 theHisto_pu->setEfficiencyFlag();
636 if ((theBaseNameDescription !=
"Jet Multiplicity" || flavour == -1) && theHisto_all)
637 theHisto_all->Fill(var, w);
640 if (!mcPlots_ || (theBaseNameDescription ==
"Jet Multiplicity" && flavour == -1))
646 theHisto_d->Fill(var, w);
647 if (theBaseNameDescription !=
"Jet Multiplicity")
648 theHisto_dus->Fill(var, w);
650 if (theBaseNameDescription !=
"Jet Multiplicity")
651 theHisto_dusg->Fill(var, w);
655 theHisto_u->Fill(var, w);
656 if (theBaseNameDescription !=
"Jet Multiplicity")
657 theHisto_dus->Fill(var, w);
659 if (theBaseNameDescription !=
"Jet Multiplicity")
660 theHisto_dusg->Fill(var, w);
664 theHisto_s->Fill(var, w);
665 if (theBaseNameDescription !=
"Jet Multiplicity")
666 theHisto_dus->Fill(var, w);
668 if (theBaseNameDescription !=
"Jet Multiplicity")
669 theHisto_dusg->Fill(var, w);
672 theHisto_c->Fill(var, w);
675 theHisto_b->Fill(var, w);
679 theHisto_g->Fill(var, w);
680 if (theBaseNameDescription !=
"Jet Multiplicity")
681 theHisto_dusg->Fill(var, w);
684 if (mcPlots_ > 2 && theBaseNameDescription ==
"Jet Multiplicity")
685 theHisto_dus->Fill(var, w);
688 if (theBaseNameDescription ==
"Jet Multiplicity")
689 theHisto_dusg->Fill(var, w);
692 theHisto_pu->Fill(var, w);
695 theHisto_ni->Fill(var, w);
702 std::vector<TH1F*> histoVector;
704 histoVector.push_back(theHisto_all->getTH1F());
707 histoVector.push_back(theHisto_d->getTH1F());
708 histoVector.push_back(theHisto_u->getTH1F());
709 histoVector.push_back(theHisto_s->getTH1F());
710 histoVector.push_back(theHisto_g->getTH1F());
711 histoVector.push_back(theHisto_dus->getTH1F());
713 histoVector.push_back(theHisto_c->getTH1F());
714 histoVector.push_back(theHisto_b->getTH1F());
715 histoVector.push_back(theHisto_ni->getTH1F());
716 histoVector.push_back(theHisto_dusg->getTH1F());
717 histoVector.push_back(theHisto_pu->getTH1F());
double lowerBound() const
MonitorElement * theHisto_g
MonitorElement * theHisto_c
void SetMinimum(const double &min)
void plot(TPad *theCanvas=nullptr)
virtual TH1F * getTH1F() const
MonitorElement * theHisto_u
void fill(const int &flavour, const T &variable) const
MonitorElement * theHisto_all
dqm::legacy::DQMStore DQMStore
std::string baseNameDescription() const
std::vector< TH1F * > getHistoVector() const
void ComputeEfficiency(TH1F *num, TH1F *den, int bin)
void SetMaximum(const double &max)
void epsPlot(const std::string &name)
dqm::legacy::MonitorElement MonitorElement
virtual MonitorElement * get(std::string const &fullpath) const
std::string baseNameTitle() const
MonitorElement * theHisto_pu
void settitle(const char *title)
int * arrayDimension() const
MonitorElement * theHisto_d
MonitorElement * theHisto_dusg
double ClopperPearsonUnc(double num, double den)
std::string theBaseNameDescription
virtual ~FlavourHistograms()
MonitorElement * theHisto_b
std::string plotFirst() const
bool plotNormalized() const
virtual MonitorElement * book1D(const std::string &name, const std::string &title, const int &nchX, const double &lowX, const double &highX)
std::string theBaseNameTitle
void fillVariable(const int &flavour, const T &var, const T &w) const
virtual void enableSumw2()
double upperBound() const
MonitorElement * theHisto_s
void divide(const FlavourHistograms< T > &bHD)
TH1F * histo_dusg() const
MonitorElement * theHisto_dus
MonitorElement * theHisto_ni
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)