/* * RigFillAction.cpp * * Created on: 14/lug/2009 * Author: Nicola Mori */ /*! @file RigFillAction.cpp The RigFillAction class implementation file. */ #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); TString auxString; while (!rigBinListFile.eof()) { rigBinListFile >> auxString; if (auxString != "") { _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; _textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0); } 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--; 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 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 ROOT file TFile outRootFile((_outFileBase + ".root"), "RECREATE"); outRootFile.cd(); _rootHisto.Write(); outRootFile.Close(); }