| 1 |
/* |
| 2 |
* LiveTimeAction.cpp |
| 3 |
* |
| 4 |
* Created on: 13/lug/2009 |
| 5 |
* Author: Nicola Mori |
| 6 |
*/ |
| 7 |
|
| 8 |
/*! @file LiveTimeAction.cpp The LiveTimeAction class implementation file. */ |
| 9 |
|
| 10 |
#include "LiveTimeAction.h" |
| 11 |
|
| 12 |
LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : |
| 13 |
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff( |
| 14 |
thresholdCoeff), _total(0.), _zeroBin(0.) |
| 15 |
#ifdef DEBUGPAMCUT |
| 16 |
, _outUp(0), _outDown(0) |
| 17 |
#endif |
| 18 |
{ |
| 19 |
|
| 20 |
// Reading the bins from file |
| 21 |
ifstream rigBinListFile; |
| 22 |
rigBinListFile.open(rigBinsFile); |
| 23 |
|
| 24 |
TString auxString; |
| 25 |
while (!rigBinListFile.eof()) { |
| 26 |
rigBinListFile >> auxString; |
| 27 |
if (auxString != "") { |
| 28 |
_bins.push_back(auxString.Atof()); |
| 29 |
} |
| 30 |
} |
| 31 |
rigBinListFile.close(); |
| 32 |
|
| 33 |
// Initializing histograms |
| 34 |
_textHisto.assign(_bins.size() - 1, 0); |
| 35 |
_rootHisto.SetName("ltHisto"); |
| 36 |
_rootHisto.SetTitle(Form("Live time (thr.: %.2f)", _thresholdCoeff)); |
| 37 |
_rootHisto.GetXaxis()->SetTitle("R"); |
| 38 |
_rootHisto.GetYaxis()->SetTitle("Events"); |
| 39 |
|
| 40 |
Double_t *auxArray = new Double_t[_bins.size()]; |
| 41 |
|
| 42 |
for (unsigned int i = 1; i < _bins.size(); i++) { |
| 43 |
auxArray[i] = _bins[i]; |
| 44 |
} |
| 45 |
|
| 46 |
_rootHisto.SetBins(_bins.size() - 1, auxArray); |
| 47 |
|
| 48 |
delete[] auxArray; |
| 49 |
} |
| 50 |
|
| 51 |
void LiveTimeAction::OnGood(PamLevel2 *event) { |
| 52 |
|
| 53 |
float lt = 0.16 * (float) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds |
| 54 |
_total += lt; |
| 55 |
float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); |
| 56 |
if (cRig >= _bins[0]) { |
| 57 |
int i = 1; |
| 58 |
int binningSize = _bins.size(); |
| 59 |
bool found = false; |
| 60 |
while (!found && i < binningSize) { |
| 61 |
if (cRig < _bins[i]) |
| 62 |
found = true; |
| 63 |
else |
| 64 |
i++; |
| 65 |
} |
| 66 |
if (found) { |
| 67 |
_textHisto[i - 1] += lt; |
| 68 |
_rootHisto.Fill(cRig, lt); |
| 69 |
} |
| 70 |
|
| 71 |
#ifdef DEBUGPAMCUT |
| 72 |
else |
| 73 |
_outUp++; |
| 74 |
#endif |
| 75 |
} |
| 76 |
|
| 77 |
else { |
| 78 |
_zeroBin += lt; |
| 79 |
#ifdef DEBUGPAMCUT |
| 80 |
_outDown++; |
| 81 |
#endif |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
void LiveTimeAction::Finalize() { |
| 86 |
|
| 87 |
// Write the text file |
| 88 |
ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); |
| 89 |
streamsize oldPrec = cout.precision(); |
| 90 |
streamsize newPrec = 4; |
| 91 |
outTextFile.precision(newPrec); |
| 92 |
outTextFile.setf(ios::fixed, ios::floatfield); |
| 93 |
for (unsigned int i = 0; i < _textHisto.size(); i++) |
| 94 |
outTextFile << _textHisto[i] << "\n"; |
| 95 |
outTextFile.close(); |
| 96 |
outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out); |
| 97 |
outTextFile << "Zero bin: " << GetZeroBin() << "\n"; |
| 98 |
outTextFile << "Total live time: " << GetTotalLT() << "\n"; |
| 99 |
outTextFile.close(); |
| 100 |
outTextFile.precision(oldPrec); |
| 101 |
outTextFile << resetiosflags(ios::floatfield); |
| 102 |
|
| 103 |
// Write the ROOT file |
| 104 |
TFile outRootFile((_outFileBase + ".root"), "RECREATE"); |
| 105 |
outRootFile.cd(); |
| 106 |
_rootHisto.Write(); |
| 107 |
outRootFile.Close(); |
| 108 |
|
| 109 |
#ifdef DEBUGPAMCUT |
| 110 |
cout << "Debug informations from " << GetName() << ":\n"; |
| 111 |
cout << " Events below the lowest rigidity: " << _outDown << "\n"; |
| 112 |
cout << " Events above the highest rigidity: " << _outUp << endl; |
| 113 |
#endif |
| 114 |
} |