--- PamCut/CollectionActions/RigFillAction/RigFillAction.cpp 2009/07/17 08:22:48 1.1 +++ PamCut/CollectionActions/RigFillAction/RigFillAction.cpp 2009/10/27 10:18:21 1.5 @@ -9,39 +9,58 @@ #include "RigFillAction.h" +void RigFillAction::_InitHistos(vector &bins) { + + _bins = bins; + + // Initializing histograms + _rootHisto.SetName("rfHisto"); + _rootHisto.SetTitle(Form("R Vs Rc (thr.: %.2f)", _thresholdCoeff)); + _rootHisto.GetXaxis()->SetTitle("Rc (GV)"); + _rootHisto.GetYaxis()->SetTitle("R (GV)"); + + Double_t *auxArray = new Double_t[_bins.size()]; + + for (unsigned int i = 1; i < _bins.size(); i++) { + auxArray[i] = _bins[i]; + } + + _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), - _thresholdCoeff(thresholdCoeff) { + _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()); + bins.push_back(auxString.Atof()); } } rigBinListFile.close(); - // Initializing histograms - _rootHisto.SetName("rfHisto"); - _rootHisto.SetTitle(Form("Rc Vs R (thr.: %.2f)", _thresholdCoeff)); - _rootHisto.GetXaxis()->SetTitle("R (GV)"); - _rootHisto.GetYaxis()->SetTitle("Rc (GV)"); - - Double_t *auxArray = new Double_t[_bins.size()]; - - for (unsigned int i = 1; i < _bins.size(); i++) { - auxArray[i] = _bins[i]; - } - - _rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray); - delete[] auxArray; + _InitHistos(bins); - _textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0); } void RigFillAction::OnGood(PamLevel2 *event) { @@ -49,42 +68,66 @@ 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 + + // Event rigidity bin identification. - //Bin identification: value must be less than (<) bin maximum + if (rig < _bins[0] || rig >= _bins[(int) _textHisto.GetNRows()]) { + 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++; + // Threshold rigidity bin identification. + + if (rigThreshold < 0 || rigThreshold >= _bins[(int) _textHisto.GetNRows()]) { + return; } - j--; - if (i < (int)_textHisto.GetNRows() && j < (int)_textHisto.GetNCols()) + if (0 <= rigThreshold && rigThreshold < _bins[0]) + _zeroCutoffBins[i]++; + else { + int j = 1; + while (rigThreshold >= _bins[j]) { + j++; + } + j--; + _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 + "-" + GetName() + ".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 + "-" + GetName() + "-InfBins.txt").Data(), ios_base::out); + for (unsigned int i = 0; i < _zeroCutoffBins.size(); i++) + outTextFile << GetHistoThreshInfBin()[i] << "\n"; + outTextFile.close(); + + // Write the ROOT file + TFile outRootFile((_outFileBase + "-" + GetName() + ".root"), "RECREATE"); + outRootFile.cd(); + _rootHisto.Write(); + outRootFile.Close(); + } }