--- PamCut/CollectionActions/RigFillAction/RigFillAction.cpp 2009/07/17 08:22:48 1.1 +++ PamCut/CollectionActions/RigFillAction/RigFillAction.cpp 2009/08/26 16:34:15 1.4 @@ -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) { - - // Reading the bins from file - ifstream rigBinListFile; - rigBinListFile.open(rigBinsFile); +void RigFillAction::_InitHistos(vector &bins) { - TString auxString; - while (!rigBinListFile.eof()) { - rigBinListFile >> auxString; - if (auxString != "") { - _bins.push_back(auxString.Atof()); - } - } - rigBinListFile.close(); + _bins = bins; // Initializing histograms _rootHisto.SetName("rfHisto"); @@ -41,7 +28,39 @@ _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); + _totalTextHisto.resize(_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), _totalTextHisto(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), _totalTextHisto(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) { @@ -49,42 +68,67 @@ float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); float rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity(); - _rootHisto.Fill(rigThreshold, rig); + _rootHisto.Fill(rigThreshold, rig); // X,Y in the ROOT histogram - //Bin identification: value must be less than (<) bin maximum + // Event rigidity bin identification. + +// cout << rig << endl; + if (rig < _bins[0] || rig >= _bins[(int) _textHisto.GetNRows()]) { +// cout << "found!" << endl; + return; + } int i = 1; - while (rig >= _bins[i] && i < (int)_textHisto.GetNRows()) { + while (rig >= _bins[i]) { i++; } i--; - int j = 1; - while (rigThreshold >= _bins[j] && j < (int)_textHisto.GetNCols()) { - j++; - } - j--; + // Threshold rigidity bin identification. + + if (rigThreshold < 0 || rigThreshold >= _bins[(int) _textHisto.GetNRows()]) return; + + if (0 <= rigThreshold && rigThreshold < _bins[0]) + _zeroCutoffBins[i]++; + else { + int j = 1; + while (rigThreshold >= _bins[j]) { + j++; + } + j--; - if (i < (int)_textHisto.GetNRows() && j < (int)_textHisto.GetNCols()) _textHisto[i][j]++; + _totalTextHisto[i]++; + + } } 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++) + outTextFile << GetHistoThreshInfBin()[i] << "\n"; + outTextFile.close(); + + // Write the ROOT file + TFile outRootFile((_outFileBase + ".root"), "RECREATE"); + outRootFile.cd(); + _rootHisto.Write(); + outRootFile.Close(); + } }