/* * RigFillAction.cpp * * Created on: 14/lug/2009 * Author: Nicola Mori */ /*! @file RigFillAction.cpp The RigFillAction class implementation file. */ #include "RigFillAction.h" void RigFillAction::_InitHistos(vector &bins) { _bins = bins; // 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; _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(); float rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity(); _rootHisto.Fill(rigThreshold, rig); //Bin identification: value must be less than (<) bin maximum int i = 1; while (rig >= _bins[i] && i < (int) _textHisto.GetNRows()) { i++; } i--; //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]++; } } void RigFillAction::Finalize() { // Write the text file 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.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(); } }