Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
Histograms.h
Go to the documentation of this file.
1
8#ifndef PANDORA_HISTOGRAMS_H
9#define PANDORA_HISTOGRAMS_H 1
10
11#include <map>
12
13namespace pandora
14{
15
16class TiXmlDocument;
17class TiXmlHandle;
18
19//------------------------------------------------------------------------------------------------------------------------------------------
20
25{
26public:
34 Histogram(const unsigned int nBinsX, const float xLow, const float xHigh);
35
42 Histogram(const TiXmlHandle *const pXmlHandle, const std::string &xmlElementName);
43
49 Histogram(const Histogram &rhs);
50
56 int GetNBinsX() const;
57
63 float GetXLow() const;
64
70 float GetXHigh() const;
71
77 float GetXBinWidth() const;
78
86 float GetBinContent(const int binX) const;
87
95 int GetBinNumber(const float valueX) const;
96
103 int GetMinBinNumber() const;
104
111 int GetMaxBinNumber() const;
112
118 int GetUnderflowBinNumber() const;
119
125 int GetOverflowBinNumber() const;
126
133 float GetCumulativeSum() const;
134
144 float GetCumulativeSum(const int xLowBin, const int xHighBin) const;
145
153 void GetMaximum(float &maximumValue, int &maximumBinX) const;
154
164 void GetMaximum(const int xLowBin, const int xHighBin, float &maximumValue, int &maximumBinX) const;
165
172 float GetMeanX() const;
173
183 float GetMeanX(const int xLowBin, const int xHighBin) const;
184
191 float GetStandardDeviationX() const;
192
202 float GetStandardDeviationX(const int xLowBin, const int xHighBin) const;
203
210 void SetBinContent(const int binX, const float value);
211
218 void Fill(const float valueX, const float weight = 1.f);
219
225 void Scale(const float scaleFactor);
226
233 void WriteToXml(TiXmlDocument *const pTiXmlDocument, const std::string &xmlElementName) const;
234
235private:
236 typedef std::map<int, float> HistogramMap;
237
239
241 float m_xLow;
242 float m_xHigh;
244};
245
246//------------------------------------------------------------------------------------------------------------------------------------------
247//------------------------------------------------------------------------------------------------------------------------------------------
248
253{
254public:
265 TwoDHistogram(const unsigned int nBinsX, const float xLow, const float xHigh, const unsigned int nBinsY, const float yLow,
266 const float yHigh);
267
274 TwoDHistogram(const TiXmlHandle *const pXmlHandle, const std::string &xmlElementName);
275
281 TwoDHistogram(const TwoDHistogram &rhs);
282
288 int GetNBinsX() const;
289
295 float GetXLow() const;
296
302 float GetXHigh() const;
303
309 float GetXBinWidth() const;
310
316 int GetNBinsY() const;
317
323 float GetYLow() const;
324
330 float GetYHigh() const;
331
337 float GetYBinWidth() const;
338
347 float GetBinContent(const int binX, const int binY) const;
348
356 int GetBinNumberX(const float valueX) const;
357
364 int GetMinBinNumberX() const;
365
372 int GetMaxBinNumberX() const;
373
379 int GetUnderflowBinNumberX() const;
380
386 int GetOverflowBinNumberX() const;
387
395 int GetBinNumberY(const float valueY) const;
396
403 int GetMinBinNumberY() const;
404
411 int GetMaxBinNumberY() const;
412
418 int GetUnderflowBinNumberY() const;
419
425 int GetOverflowBinNumberY() const;
426
433 float GetCumulativeSum() const;
434
446 float GetCumulativeSum(const int xLowBin, const int xHighBin, const int yLowBin, const int yHighBin) const;
447
456 void GetMaximum(float &maximumValue, int &maximumBinX, int &maximumBinY) const;
457
470 void GetMaximum(const int xLowBin, const int xHighBin, const int yLowBin, const int yHighBin, float &maximumValue, int &maximumBinX,
471 int &maximumBinY) const;
472
479 float GetMeanX() const;
480
492 float GetMeanX(const int xLowBin, const int xHighBin, const int yLowBin, const int yHighBin) const;
493
500 float GetStandardDeviationX() const;
501
513 float GetStandardDeviationX(const int xLowBin, const int xHighBin, const int yLowBin, const int yHighBin) const;
514
521 float GetMeanY() const;
522
534 float GetMeanY(const int xLowBin, const int xHighBin, const int yLowBin, const int yHighBin) const;
535
542 float GetStandardDeviationY() const;
543
555 float GetStandardDeviationY(const int xLowBin, const int xHighBin, const int yLowBin, const int yHighBin) const;
556
564 void SetBinContent(const int binX, const int binY, const float value);
565
573 void Fill(const float valueX, const float valueY, const float weight = 1.f);
574
580 void Scale(const float scaleFactor);
581
588 void WriteToXml(TiXmlDocument *const pTiXmlDocument, const std::string &xmlElementName) const;
589
590private:
591 typedef std::map<int, float> HistogramMap;
592 typedef std::map<int, HistogramMap> TwoDHistogramMap;
593
596
598 float m_xLow;
599 float m_xHigh;
601
603 float m_yLow;
604 float m_yHigh;
606};
607
608//------------------------------------------------------------------------------------------------------------------------------------------
609//------------------------------------------------------------------------------------------------------------------------------------------
610
611inline int Histogram::GetNBinsX() const
612{
613 return m_nBinsX;
614}
615
616//------------------------------------------------------------------------------------------------------------------------------------------
617
618inline float Histogram::GetXLow() const
619{
620 return m_xLow;
621}
622
623//------------------------------------------------------------------------------------------------------------------------------------------
624
625inline float Histogram::GetXHigh() const
626{
627 return m_xHigh;
628}
629
630//------------------------------------------------------------------------------------------------------------------------------------------
631
632inline float Histogram::GetXBinWidth() const
633{
634 return m_xBinWidth;
635}
636
637//------------------------------------------------------------------------------------------------------------------------------------------
638
640{
641 return 0;
642}
643
644//------------------------------------------------------------------------------------------------------------------------------------------
645
647{
648 return (m_nBinsX - 1);
649}
650
651//------------------------------------------------------------------------------------------------------------------------------------------
652
654{
655 return (this->GetMinBinNumber() - 1);
656}
657
658//------------------------------------------------------------------------------------------------------------------------------------------
659
661{
662 return (this->GetMaxBinNumber() + 1);
663}
664
665//------------------------------------------------------------------------------------------------------------------------------------------
666
667inline float Histogram::GetCumulativeSum() const
668{
669 return this->GetCumulativeSum(this->GetMinBinNumber(), this->GetMaxBinNumber());
670}
671
672//------------------------------------------------------------------------------------------------------------------------------------------
673
674inline void Histogram::GetMaximum(float &maximumValue, int &maximumBinX) const
675{
676 return this->GetMaximum(this->GetMinBinNumber(), this->GetMaxBinNumber(), maximumValue, maximumBinX);
677}
678
679//------------------------------------------------------------------------------------------------------------------------------------------
680
681inline float Histogram::GetMeanX() const
682{
683 return this->GetMeanX(this->GetMinBinNumber(), this->GetMaxBinNumber());
684}
685
686//------------------------------------------------------------------------------------------------------------------------------------------
687
689{
690 return this->GetStandardDeviationX(this->GetMinBinNumber(), this->GetMaxBinNumber());
691}
692
693//------------------------------------------------------------------------------------------------------------------------------------------
694//------------------------------------------------------------------------------------------------------------------------------------------
695
696inline int TwoDHistogram::GetNBinsX() const
697{
698 return m_nBinsX;
699}
700
701//------------------------------------------------------------------------------------------------------------------------------------------
702
703inline float TwoDHistogram::GetXLow() const
704{
705 return m_xLow;
706}
707
708//------------------------------------------------------------------------------------------------------------------------------------------
709
710inline float TwoDHistogram::GetXHigh() const
711{
712 return m_xHigh;
713}
714
715//------------------------------------------------------------------------------------------------------------------------------------------
716
717inline float TwoDHistogram::GetXBinWidth() const
718{
719 return m_xBinWidth;
720}
721
722//------------------------------------------------------------------------------------------------------------------------------------------
723
724inline int TwoDHistogram::GetNBinsY() const
725{
726 return m_nBinsY;
727}
728
729//------------------------------------------------------------------------------------------------------------------------------------------
730
731inline float TwoDHistogram::GetYLow() const
732{
733 return m_yLow;
734}
735
736//------------------------------------------------------------------------------------------------------------------------------------------
737
738inline float TwoDHistogram::GetYHigh() const
739{
740 return m_yHigh;
741}
742
743//------------------------------------------------------------------------------------------------------------------------------------------
744
745inline float TwoDHistogram::GetYBinWidth() const
746{
747 return m_yBinWidth;
748}
749//------------------------------------------------------------------------------------------------------------------------------------------
750
752{
753 return 0;
754}
755
756//------------------------------------------------------------------------------------------------------------------------------------------
757
759{
760 return (m_nBinsX - 1);
761}
762
763//------------------------------------------------------------------------------------------------------------------------------------------
764
766{
767 return (this->GetMinBinNumberX() - 1);
768}
769
770//------------------------------------------------------------------------------------------------------------------------------------------
771
773{
774 return (this->GetMaxBinNumberX() + 1);
775}
776//------------------------------------------------------------------------------------------------------------------------------------------
777
779{
780 return 0;
781}
782
783//------------------------------------------------------------------------------------------------------------------------------------------
784
786{
787 return (m_nBinsY - 1);
788}
789
790//------------------------------------------------------------------------------------------------------------------------------------------
791
793{
794 return (this->GetMinBinNumberY() - 1);
795}
796
797//------------------------------------------------------------------------------------------------------------------------------------------
798
800{
801 return (this->GetMaxBinNumberY() + 1);
802}
803
804//------------------------------------------------------------------------------------------------------------------------------------------
805
807{
808 return this->GetCumulativeSum(this->GetMinBinNumberX(), this->GetMaxBinNumberX(), this->GetMinBinNumberY(), this->GetMaxBinNumberY());
809}
810
811//------------------------------------------------------------------------------------------------------------------------------------------
812
813inline void TwoDHistogram::GetMaximum(float &maximumValue, int &maximumBinX, int &maximumBinY) const
814{
815 return this->GetMaximum(this->GetMinBinNumberX(), this->GetMaxBinNumberX(), this->GetMinBinNumberY(), this->GetMaxBinNumberY(), maximumValue, maximumBinX, maximumBinY);
816}
817
818//------------------------------------------------------------------------------------------------------------------------------------------
819
820inline float TwoDHistogram::GetMeanX() const
821{
822 return this->GetMeanX(this->GetMinBinNumberX(), this->GetMaxBinNumberX(), this->GetMinBinNumberY(), this->GetMaxBinNumberY());
823}
824
825//------------------------------------------------------------------------------------------------------------------------------------------
826
828{
829 return this->GetStandardDeviationX(this->GetMinBinNumberX(), this->GetMaxBinNumberX(), this->GetMinBinNumberY(), this->GetMaxBinNumberY());
830}
831
832//------------------------------------------------------------------------------------------------------------------------------------------
833
834inline float TwoDHistogram::GetMeanY() const
835{
836 return this->GetMeanY(this->GetMinBinNumberX(), this->GetMaxBinNumberX(), this->GetMinBinNumberY(), this->GetMaxBinNumberY());
837}
838
839//------------------------------------------------------------------------------------------------------------------------------------------
840
842{
843 return this->GetStandardDeviationY(this->GetMinBinNumberX(), this->GetMaxBinNumberX(), this->GetMinBinNumberY(), this->GetMaxBinNumberY());
844}
845
846} // namespace pandora
847
848#endif // #ifndef PANDORA_HISTOGRAMS_H
Histogram class.
Definition Histograms.h:25
int GetNBinsX() const
Get the number of x bins.
Definition Histograms.h:611
float GetCumulativeSum() const
Get the cumulative sum of bin entries in the histogram (ignores overflow and underflow bins)
Definition Histograms.h:667
float GetMeanX() const
Get the mean x value of entries in the histogram (ignores overflow and underflow bins)
Definition Histograms.h:681
void GetMaximum(float &maximumValue, int &maximumBinX) const
Get the maximum value in the histogram and the corresponding bin number (ignores overflow and underfl...
Definition Histograms.h:674
std::map< int, float > HistogramMap
Definition Histograms.h:236
int GetBinNumber(const float valueX) const
Get the bin number for a specified value.
void Fill(const float valueX, const float weight=1.f)
Add an entry to the histogram.
float m_xBinWidth
The x bin width.
Definition Histograms.h:243
int GetOverflowBinNumber() const
Get the overflow bin number of the histogram.
Definition Histograms.h:660
int GetMinBinNumber() const
Get the min bin number of the histogram (ignores overflow and underflow bins)
Definition Histograms.h:639
void SetBinContent(const int binX, const float value)
Set the contents of a specified bin.
float m_xHigh
The max binned x value.
Definition Histograms.h:242
float GetStandardDeviationX() const
Get the standard deviation of entries in the histogram (ignores overflow and underflow bins)
Definition Histograms.h:688
int GetMaxBinNumber() const
Get the max bin number of the histogram (ignores overflow and underflow bins)
Definition Histograms.h:646
float GetXBinWidth() const
Get the x bin width.
Definition Histograms.h:632
void WriteToXml(TiXmlDocument *const pTiXmlDocument, const std::string &xmlElementName) const
Write the histogram to an xml document.
int m_nBinsX
The number of x bins.
Definition Histograms.h:240
float GetXHigh() const
Get the max binned x value.
Definition Histograms.h:625
float GetBinContent(const int binX) const
Get the content of a specified bin.
Definition Histograms.cc:91
HistogramMap m_histogramMap
The histogram map.
Definition Histograms.h:238
float GetXLow() const
Get the min binned x value.
Definition Histograms.h:618
int GetUnderflowBinNumber() const
Get the underflow bin number of the histogram.
Definition Histograms.h:653
float m_xLow
The min binned x value.
Definition Histograms.h:241
void Scale(const float scaleFactor)
Scale contents of all histogram bins by a specified factor.
TwoDHistogram class.
Definition Histograms.h:253
int GetOverflowBinNumberY() const
Get the overflow y bin number of the histogram.
Definition Histograms.h:799
TwoDHistogramMap m_yxHistogramMap
The y->x->value 2d histogram map.
Definition Histograms.h:595
float GetYLow() const
Get the min binned y value.
Definition Histograms.h:731
int GetOverflowBinNumberX() const
Get the overflow x bin number of the histogram.
Definition Histograms.h:772
int m_nBinsX
The number of x bins.
Definition Histograms.h:597
int m_nBinsY
The number of y bins.
Definition Histograms.h:602
float GetBinContent(const int binX, const int binY) const
Get the content of a specified bin.
std::map< int, float > HistogramMap
Definition Histograms.h:591
float m_xLow
The min binned x value.
Definition Histograms.h:598
int GetUnderflowBinNumberY() const
Get the underflow y bin number of the histogram.
Definition Histograms.h:792
float GetCumulativeSum() const
Get the cumulative sum of bin entries in the histogram (ignores overflow and underflow bins)
Definition Histograms.h:806
float GetMeanX() const
Get the mean x value of entries in the histogram (ignores overflow and underflow bins)
Definition Histograms.h:820
int GetBinNumberY(const float valueY) const
Get the y bin number for a specified value.
float m_yHigh
The max binned y value.
Definition Histograms.h:604
std::map< int, HistogramMap > TwoDHistogramMap
Definition Histograms.h:592
int GetNBinsX() const
Get the number of x bins.
Definition Histograms.h:696
float m_yLow
The min binned y value.
Definition Histograms.h:603
float GetYHigh() const
Get the max binned y value.
Definition Histograms.h:738
int GetNBinsY() const
Get the number of y bins.
Definition Histograms.h:724
float GetXLow() const
Get the min binned x value.
Definition Histograms.h:703
float GetStandardDeviationY() const
Get the standard deviation of y entries in the histogram (ignores overflow and underflow bins)
Definition Histograms.h:841
void GetMaximum(float &maximumValue, int &maximumBinX, int &maximumBinY) const
Get the maximum value in the histogram and the corresponding bin numbers (ignores overflow and underf...
Definition Histograms.h:813
int GetMaxBinNumberY() const
Get the max y bin number of the histogram (ignores overflow and underflow bins)
Definition Histograms.h:785
int GetBinNumberX(const float valueX) const
Get the x bin number for a specified x value.
void SetBinContent(const int binX, const int binY, const float value)
Set the contents of a specified bin.
float GetYBinWidth() const
Get the y bin width.
Definition Histograms.h:745
TwoDHistogramMap m_xyHistogramMap
The x->y->value 2d histogram map.
Definition Histograms.h:594
float GetStandardDeviationX() const
Get the standard deviation of x entries in the histogram (ignores overflow and underflow bins)
Definition Histograms.h:827
float m_xHigh
The max binned x value.
Definition Histograms.h:599
int GetUnderflowBinNumberX() const
Get the underflow x bin number of the histogram.
Definition Histograms.h:765
void WriteToXml(TiXmlDocument *const pTiXmlDocument, const std::string &xmlElementName) const
Write the histogram to an xml document.
float GetMeanY() const
Get the mean y value of entries in the histogram (ignores overflow and underflow bins)
Definition Histograms.h:834
float GetXBinWidth() const
Get the x bin width.
Definition Histograms.h:717
int GetMinBinNumberY() const
Get the min y bin number of the histogram (ignores overflow and underflow bins)
Definition Histograms.h:778
float m_yBinWidth
The y bin width.
Definition Histograms.h:605
void Fill(const float valueX, const float valueY, const float weight=1.f)
Add an entry to the histogram.
void Scale(const float scaleFactor)
Scale contents of all histogram bins by a specified factor.
int GetMinBinNumberX() const
Get the min x bin number of the histogram (ignores overflow and underflow bins)
Definition Histograms.h:751
float m_xBinWidth
The x bin width.
Definition Histograms.h:600
int GetMaxBinNumberX() const
Get the max x bin number of the histogram (ignores overflow and underflow bins)
Definition Histograms.h:758
float GetXHigh() const
Get the max binned x value.
Definition Histograms.h:710