--- PamCut/CollectionActions/RigFillAction/RigFillAction.cpp 2009/07/17 08:22:48 1.1 +++ PamCut/CollectionActions/RigFillAction/RigFillAction.cpp 2009/08/05 17:05:01 1.2 @@ -9,22 +9,9 @@ #include "RigFillAction.h" -RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : - CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), - _thresholdCoeff(thresholdCoeff) { +void RigFillAction::_InitHistos(vector &bins) { - // Reading the bins from file - ifstream rigBinListFile; - rigBinListFile.open(rigBinsFile); - - TString auxString; - while (!rigBinListFile.eof()) { - rigBinListFile >> auxString; - if (auxString != "") { - _bins.push_back(auxString.Atof()); - } - } - rigBinListFile.close(); + _bins = bins; // Initializing histograms _rootHisto.SetName("rfHisto"); @@ -41,9 +28,40 @@ _rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray); delete[] auxArray; + _zeroCutoffBins.resize(_bins.size() - 1, 0); _textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0); } +RigFillAction::RigFillAction(const char *actionName, TString outFileBase, vector &bins, float thresholdCoeff) : + CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), + _zeroCutoffBins(0), _thresholdCoeff(thresholdCoeff) { + + _InitHistos(bins); + +} + +RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : + CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), + _zeroCutoffBins(0), _thresholdCoeff(thresholdCoeff) { + + // Reading the bins from file + ifstream rigBinListFile; + rigBinListFile.open(rigBinsFile); + + TString auxString; + vector bins(0); + while (!rigBinListFile.eof()) { + rigBinListFile >> auxString; + if (auxString != "") { + bins.push_back(auxString.Atof()); + } + } + rigBinListFile.close(); + + _InitHistos(bins); + +} + void RigFillAction::OnGood(PamLevel2 *event) { float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); @@ -54,37 +72,51 @@ //Bin identification: value must be less than (<) bin maximum int i = 1; - while (rig >= _bins[i] && i < (int)_textHisto.GetNRows()) { + while (rig >= _bins[i] && i < (int) _textHisto.GetNRows()) { i++; } i--; - int j = 1; - while (rigThreshold >= _bins[j] && j < (int)_textHisto.GetNCols()) { - j++; - } - j--; + //Check the zero bins + if (rigThreshold < _bins[0]) + _zeroCutoffBins[i]++; + else { + int j = 1; + while (rigThreshold >= _bins[j] && j < (int) _textHisto.GetNCols()) { + j++; + } + j--; - if (i < (int)_textHisto.GetNRows() && j < (int)_textHisto.GetNCols()) - _textHisto[i][j]++; + if (i < (int) _textHisto.GetNRows() && j < (int) _textHisto.GetNCols()) + _textHisto[i][j]++; + } } void RigFillAction::Finalize() { // Write the text file - ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); - for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) { - for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) { - outTextFile << setw(7) << _textHisto[i][j] << " "; + if (_outFileBase != "") { + + ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); + for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) { + for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) { + outTextFile << setw(7) << _textHisto[i][j] << " "; + } + outTextFile << "\n"; } - outTextFile << "\n"; - } - outTextFile.close(); + outTextFile.close(); - // Write the ROOT file - TFile outRootFile((_outFileBase + ".root"), "RECREATE"); - outRootFile.cd(); - _rootHisto.Write(); - outRootFile.Close(); + // Write the report file, where zero bins are recorded + outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out); + outTextFile << "Zero bins for cutoff rigidity: \n"; + for (unsigned int i = 0; i < _zeroCutoffBins.size(); i++) + cout << GetCutoffZeroBins()[i] << "\n"; + + // Write the ROOT file + TFile outRootFile((_outFileBase + ".root"), "RECREATE"); + outRootFile.cd(); + _rootHisto.Write(); + outRootFile.Close(); + } }