--- PamCut/CollectionActions/Histo2DActions/Histo2DAction/Histo2DAction.h 2009/10/29 09:42:44 1.3 +++ PamCut/CollectionActions/Histo2DActions/Histo2DAction/Histo2DAction.h 2010/03/11 19:14:03 1.6 @@ -143,6 +143,14 @@ return _histo; } + /*! @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. @@ -252,16 +260,16 @@ /*! @brief The ROOT histogram. */ TH2 *_rootHisto; + TString _outFileBase; + TString _mode; + TString _title, _xLabel, _yLabel; + private: vector _xUnderflow, _xOverflow, _yUnderflow, _yOverflow; HistoType _xUnderYUnderflow, _xOverYOverflow, _xUnderYOverflow, _xOverYUnderflow; - TString _outFileBase; - TString _mode; - TString _title, _xLabel, _yLabel; bool _outRoot; bool _outText; - void _CreateHisto(); void _InitHistos(); }; @@ -273,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()]; @@ -316,10 +326,10 @@ /* The row index (first) corresponds to the position on the vertical (Y) axis. */ _histo.Resize(_yBins.size() - 1, _xBins.size() - 1); - _xUnderflow.resize(_yBins.size()); - _xOverflow.resize(_yBins.size()); - _yUnderflow.resize(_xBins.size()); - _yOverflow.resize(_xBins.size()); + _xUnderflow.resize(_yBins.size() - 1); + _xOverflow.resize(_yBins.size() - 1); + _yUnderflow.resize(_xBins.size() - 1); + _yOverflow.resize(_xBins.size() - 1); } @@ -333,9 +343,10 @@ template Histo2DAction::Histo2DAction(const char *actionName, TString title, TString outFileBase, TString mode, bool outRoot, bool outText) : - CollectionAction(actionName), _xBins(0), _yBins(0), _histo(0, 0), _rootHisto(NULL), _xUnderflow(0), _xOverflow(0), - _yUnderflow(0), _yOverflow(0), _outFileBase(outFileBase), _mode(mode), _title(title), _xLabel(""), _yLabel(""), - _outRoot(outRoot), _outText(outText) { + CollectionAction(actionName), _xBins(0), _yBins(0), _histo(0, 0), _rootHisto(NULL), _outFileBase(outFileBase), _mode( + mode), _title(title), _xLabel(""), _yLabel(""), _xUnderflow(0), _xOverflow(0), _yUnderflow(0), _yOverflow(0), + _xUnderYUnderflow((HistoType) 0), _xOverYOverflow((HistoType) 0), _xUnderYOverflow((HistoType) 0), + _xOverYUnderflow((HistoType) 0), _outRoot(outRoot), _outText(outText) { } @@ -458,7 +469,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); @@ -471,7 +482,7 @@ UOflow = true; } - if (xValue > _xBins.back()) { + if (xValue >= _xBins.back()) { xBin = _xBins.size(); UOflow = true; } @@ -481,7 +492,7 @@ UOflow = true; } - if (yValue > _yBins.back()) { + if (yValue >= _yBins.back()) { yBin = _yBins.size(); UOflow = true; } @@ -517,6 +528,8 @@ else { if (yBin == (int) _yBins.size()) { _xUnderYOverflow += (HistoType) weight; + cout << "_xUnderYOverflow: " << GetXUnderYOverflow() << ", weight: " << weight << ", (HistoType) weight: " + << (HistoType) weight << endl; return; } else { @@ -573,11 +586,10 @@ ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); for (unsigned int i = 0; i < _histo.GetNRows(); i++) { for (unsigned int j = 0; j < _histo.GetNCols(); j++) { - outTextFile << _histo[i][j] << " "; + outTextFile << setw(7) << _histo[i][j] << " "; } outTextFile << "\n"; } - outTextFile << endl; outTextFile.close(); } }