--- PamCut/CollectionActions/LiveTimeAction/LiveTimeAction.cpp 2009/07/17 08:22:47 1.1 +++ PamCut/CollectionActions/LiveTimeAction/LiveTimeAction.cpp 2009/08/05 17:04:18 1.2 @@ -9,6 +9,38 @@ #include "LiveTimeAction.h" +void LiveTimeAction::_InitHistos(vector &bins) { + + _bins = bins; + + // 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; +} + +LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, vector &bins, float thresholdCoeff) : + CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff( + thresholdCoeff), _total(0.), _zeroBin(0.) +#ifdef DEBUGPAMCUT +, _outUp(0), _outDown(0) +#endif +{ + _InitHistos(bins); +} + 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.) @@ -22,6 +54,7 @@ rigBinListFile.open(rigBinsFile); TString auxString; + vector bins(0); while (!rigBinListFile.eof()) { rigBinListFile >> auxString; if (auxString != "") { @@ -30,22 +63,8 @@ } 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"); + _InitHistos(bins); - 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) { @@ -84,27 +103,31 @@ 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(); + if (_outFileBase != "") { + + // 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";