--- PamCut/CollectionActions/Histo2DActions/Histo2DAction/Histo2DAction.h 2009/09/25 15:36:45 1.1 +++ PamCut/CollectionActions/Histo2DActions/Histo2DAction/Histo2DAction.h 2009/12/08 17:38:39 1.5 @@ -106,17 +106,19 @@ */ void SetYAxis(TString label, unsigned int nBins, float min, float max, bool logBinning = false); + /*! @brief Sets the ROOT histogram's title. + * + * @param title The histogram title as it will appear on the histogram itself. + */ + void SetTitle(TString &title) { + _title = title; + } /*! @brief Sets up the histogram * * This routine effectively prepares the histogram, after the desired parameters has been set by #SetXAxis() and #SetYAxis(). * * @param events Pointer to PamLevel2 events (unused). */ - - /*! @brief Sets the ROOT histogram's title. */ - void SetTitle(TString &title){ - _title = title; - } void Setup(PamLevel2 *events) { CollectionAction::Setup(events); _InitHistos(); @@ -141,7 +143,20 @@ return _histo; } - /*! Fills the ROOT and the vector histogram. */ + /*! @brief Returns a pointer to the ROOT histogram. + * + * @return A pointer to the root histogram + */ + TH2 *GetRootHisto() { + return _rootHisto; + } + + /*! Fills the ROOT and the vector histogram. + * + * @param xValue The value of the X coordinate associated to the event. + * @param yValue The value of the Y coordinate associated to the event. + * @param weight The weight which will be applied to the event. + */ void Fill(double xValue, double yValue, double weight = 1.); /*! @brief Gets the X overflow histogram. @@ -236,9 +251,13 @@ protected: + /*! @brief The vector containing the limits of the X bins(from lower to higher). */ std::vector _xBins; + /*! @brief The vector containing the limits of the Y bins(from lower to higher). */ std::vector _yBins; + /*! @brief A matrix containing the value of the histogram for each X-Y bin. */ SimpleMatrix _histo; + /*! @brief The ROOT histogram. */ TH2 *_rootHisto; private: @@ -262,22 +281,24 @@ _rootHisto = NULL; } +// Specializations for _CreateHistos(). See Histo2DAction.cpp +template<> +void Histo2DAction::_CreateHisto(); + +template<> +void Histo2DAction::_CreateHisto(); + +template<> +void Histo2DAction::_CreateHisto(); + template void Histo2DAction::_InitHistos() { _CreateHisto(); - - if (_xBins.size() < 2){ - _xBins.resize(2); - _xBins[0] = 0.; - _xBins[1] = 1.; - } - - if (_yBins.size() < 2){ - _yBins.resize(2); - _yBins[0] = 0.; - _yBins[1] = 1.; - } + if (_xBins.size() < 2) // SetXAxis not called by the main program, or wrongly filled (only 1 bin limit) + SetXAxis("Default X", 10, 0., 1.); + if (_yBins.size() < 2) // SetYAxis not called by the main program, or wrongly filled (only 1 bin limit) + SetYAxis("Default Y", 10, 0., 1.); if (_rootHisto) { Double_t *auxXArray = new Double_t[_xBins.size()]; @@ -314,6 +335,9 @@ template Histo2DAction::~Histo2DAction() { + + delete _rootHisto; + _rootHisto = NULL; } template @@ -444,7 +468,7 @@ } template -inline void Histo2DAction::Fill(double xValue, double yValue, double weight) { +void Histo2DAction::Fill(double xValue, double yValue, double weight) { _rootHisto->Fill(xValue, yValue, weight); @@ -457,7 +481,7 @@ UOflow = true; } - if (xValue > _xBins.back()) { + if (xValue >= _xBins.back()) { xBin = _xBins.size(); UOflow = true; } @@ -467,7 +491,7 @@ UOflow = true; } - if (yValue > _yBins.back()) { + if (yValue >= _yBins.back()) { yBin = _yBins.size(); UOflow = true; } @@ -501,7 +525,7 @@ return; } else { - if (yBin == (int)_yBins.size()) { + if (yBin == (int) _yBins.size()) { _xUnderYOverflow += (HistoType) weight; return; } @@ -512,13 +536,13 @@ } } - if (xBin == (int)_xBins.size()) { + if (xBin == (int) _xBins.size()) { if (yBin == -1) { _xOverYUnderflow += (HistoType) weight; return; } else { - if (yBin ==(int) _yBins.size()) { + if (yBin == (int) _yBins.size()) { _xOverYOverflow += (HistoType) weight; return; } @@ -534,7 +558,7 @@ return; } - if (yBin == (int)_yBins.size()) { + if (yBin == (int) _yBins.size()) { _yOverflow[xBin] += (HistoType) weight; return; }