/* * LiveTimeAction.cpp * * Created on: 13/lug/2009 * Author: Nicola Mori */ /*! @file LiveTimeAction.cpp The LiveTimeAction class implementation file. */ #include "LiveTimeAction.h" LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff( thresholdCoeff), _total(0.), _zeroBin(0.) #ifdef DEBUGPAMCUT , _outUp(0), _outDown(0) #endif { // 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 _textHisto.assign(_bins.size() - 1, 0); _rootHisto.SetName("ltHisto"); _rootHisto.SetTitle(Form("Live time (thr.: %.2f)", _thresholdCoeff)); _rootHisto.GetXaxis()->SetTitle("R"); _rootHisto.GetYaxis()->SetTitle("Events"); 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); delete[] auxArray; } void LiveTimeAction::OnGood(PamLevel2 *event) { float lt = 0.16 * (float) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds _total += lt; float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); if (cRig >= _bins[0]) { int i = 1; int binningSize = _bins.size(); bool found = false; while (!found && i < binningSize) { if (cRig < _bins[i]) found = true; else i++; } if (found) { _textHisto[i - 1] += lt; _rootHisto.Fill(cRig, lt); } #ifdef DEBUGPAMCUT else _outUp++; #endif } else { _zeroBin += lt; #ifdef DEBUGPAMCUT _outDown++; #endif } } void LiveTimeAction::Finalize() { // Write the text file ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); streamsize oldPrec = cout.precision(); streamsize newPrec = 4; outTextFile.precision(newPrec); outTextFile.setf(ios::fixed, ios::floatfield); for (unsigned int i = 0; i < _textHisto.size(); i++) outTextFile << _textHisto[i] << "\n"; outTextFile.close(); outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out); outTextFile << "Zero bin: " << GetZeroBin() << "\n"; outTextFile << "Total live time: " << GetTotalLT() << "\n"; outTextFile.close(); outTextFile.precision(oldPrec); outTextFile << resetiosflags(ios::floatfield); // Write the ROOT file TFile outRootFile((_outFileBase + ".root"), "RECREATE"); outRootFile.cd(); _rootHisto.Write(); outRootFile.Close(); #ifdef DEBUGPAMCUT cout << "Debug informations from " << GetName() << ":\n"; cout << " Events below the lowest rigidity: " << _outDown << "\n"; cout << " Events above the highest rigidity: " << _outUp << endl; #endif }