| 9 |
|
|
| 10 |
#include "LiveTimeAction.h" |
#include "LiveTimeAction.h" |
| 11 |
|
|
| 12 |
|
void LiveTimeAction::_InitHistos(vector<float> &bins) { |
| 13 |
|
|
| 14 |
|
_bins = bins; |
| 15 |
|
|
| 16 |
|
// Initializing histograms |
| 17 |
|
_textHisto.assign(_bins.size() - 1, 0); |
| 18 |
|
_rootHisto.SetName("ltHisto"); |
| 19 |
|
_rootHisto.SetTitle(Form("Live time (thr.: %.2f)", _thresholdCoeff)); |
| 20 |
|
_rootHisto.GetXaxis()->SetTitle("R [GV]"); |
| 21 |
|
_rootHisto.GetYaxis()->SetTitle("Events"); |
| 22 |
|
|
| 23 |
|
Double_t *auxArray = new Double_t[_bins.size()]; |
| 24 |
|
|
| 25 |
|
for (unsigned int i = 1; i < _bins.size(); i++) { |
| 26 |
|
auxArray[i] = _bins[i]; |
| 27 |
|
} |
| 28 |
|
|
| 29 |
|
_rootHisto.SetBins(_bins.size() - 1, auxArray); |
| 30 |
|
|
| 31 |
|
delete[] auxArray; |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, vector<float> &bins, float thresholdCoeff) : |
| 35 |
|
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff( |
| 36 |
|
thresholdCoeff), _totalNorm(0.), _infBin(0.), _nGoodHisto(0), _nGoodInfBin(0) |
| 37 |
|
#ifdef DEBUGPAMCUT |
| 38 |
|
, _outUp(0), _outDown(0) |
| 39 |
|
#endif |
| 40 |
|
{ |
| 41 |
|
_InitHistos(bins); |
| 42 |
|
} |
| 43 |
|
|
| 44 |
LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : |
LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : |
| 45 |
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff( |
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff( |
| 46 |
thresholdCoeff), _total(0.), _zeroBin(0.) |
thresholdCoeff), _totalNorm(0.), _infBin(0.), _nGoodHisto(0), _nGoodInfBin(0) |
| 47 |
#ifdef DEBUGPAMCUT |
#ifdef DEBUGPAMCUT |
| 48 |
, _outUp(0), _outDown(0) |
, _outUp(0), _outDown(0) |
| 49 |
#endif |
#endif |
| 54 |
rigBinListFile.open(rigBinsFile); |
rigBinListFile.open(rigBinsFile); |
| 55 |
|
|
| 56 |
TString auxString; |
TString auxString; |
| 57 |
|
vector<float> bins(0); |
| 58 |
while (!rigBinListFile.eof()) { |
while (!rigBinListFile.eof()) { |
| 59 |
rigBinListFile >> auxString; |
rigBinListFile >> auxString; |
| 60 |
if (auxString != "") { |
if (auxString != "") { |
| 61 |
_bins.push_back(auxString.Atof()); |
bins.push_back(auxString.Atof()); |
| 62 |
} |
} |
| 63 |
} |
} |
| 64 |
rigBinListFile.close(); |
rigBinListFile.close(); |
| 65 |
|
|
| 66 |
// Initializing histograms |
_InitHistos(bins); |
|
_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); |
|
| 67 |
|
|
|
delete[] auxArray; |
|
| 68 |
} |
} |
| 69 |
|
|
| 70 |
void LiveTimeAction::OnGood(PamLevel2 *event) { |
void LiveTimeAction::OnGood(PamLevel2 *event) { |
| 71 |
|
|
| 72 |
float lt = 0.16 * (float) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds |
double lt = 0.16 * (double) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds |
| 73 |
_total += lt; |
|
| 74 |
|
// cout << 0.16 * event->GetTrigLevel2()->dltime[0] / 1000. << endl; |
| 75 |
|
// cout << lt << endl; |
| 76 |
|
|
| 77 |
float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); |
float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); |
| 78 |
if (cRig >= _bins[0]) { |
if (cRig >= _bins[0]) { |
| 79 |
int i = 1; |
int i = 1; |
| 80 |
int binningSize = _bins.size(); |
int binningSize = _bins.size(); |
| 81 |
bool found = false; |
bool found = false; |
| 82 |
while (!found && i < binningSize) { |
while (!found && i < binningSize) { |
| 83 |
if (cRig < _bins[i]) |
if (cRig < _bins[i]) // less than bin[i-1] maximum edge |
| 84 |
found = true; |
found = true; |
| 85 |
else |
else |
| 86 |
i++; |
i++; |
| 87 |
} |
} |
| 88 |
if (found) { |
if (found) { |
| 89 |
_textHisto[i - 1] += lt; |
_totalNorm += lt; // use double for sums of many real numbers |
| 90 |
|
_textHisto[i - 1] += lt; // use double for sums of many real numbers |
| 91 |
_rootHisto.Fill(cRig, lt); |
_rootHisto.Fill(cRig, lt); |
| 92 |
|
_nGoodHisto++; |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
#ifdef DEBUGPAMCUT |
#ifdef DEBUGPAMCUT |
| 98 |
#endif |
#endif |
| 99 |
} |
} |
| 100 |
|
|
| 101 |
else { |
else if (cRig > 0.) { |
| 102 |
_zeroBin += lt; |
_infBin += lt; |
| 103 |
|
_nGoodInfBin++; |
| 104 |
#ifdef DEBUGPAMCUT |
#ifdef DEBUGPAMCUT |
| 105 |
_outDown++; |
_outDown++; |
| 106 |
#endif |
#endif |
| 109 |
|
|
| 110 |
void LiveTimeAction::Finalize() { |
void LiveTimeAction::Finalize() { |
| 111 |
|
|
| 112 |
// Write the text file |
if (_outFileBase != "") { |
| 113 |
ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); |
|
| 114 |
streamsize oldPrec = cout.precision(); |
// Write the text file |
| 115 |
streamsize newPrec = 4; |
ofstream outTextFile((_outFileBase + "-" + GetName() + ".txt").Data(), ios_base::out); |
| 116 |
outTextFile.precision(newPrec); |
streamsize oldPrec = cout.precision(); |
| 117 |
outTextFile.setf(ios::fixed, ios::floatfield); |
streamsize newPrec = 4; |
| 118 |
for (unsigned int i = 0; i < _textHisto.size(); i++) |
outTextFile.precision(newPrec); |
| 119 |
outTextFile << _textHisto[i] << "\n"; |
outTextFile.setf(ios::fixed, ios::floatfield); |
| 120 |
outTextFile.close(); |
for (unsigned int i = 0; i < _textHisto.size(); i++) |
| 121 |
outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out); |
outTextFile << _textHisto[i] << "\n"; |
| 122 |
outTextFile << "Zero bin: " << GetZeroBin() << "\n"; |
outTextFile.close(); |
| 123 |
outTextFile << "Total live time: " << GetTotalLT() << "\n"; |
outTextFile.open((_outFileBase + "-" + GetName() + "-InfBin.txt").Data(), ios_base::out); |
| 124 |
outTextFile.close(); |
outTextFile << GetLTInfBin() << endl; |
| 125 |
outTextFile.precision(oldPrec); |
outTextFile.close(); |
| 126 |
outTextFile << resetiosflags(ios::floatfield); |
outTextFile.precision(oldPrec); |
| 127 |
|
outTextFile << resetiosflags(ios::floatfield); |
| 128 |
// Write the ROOT file |
|
| 129 |
TFile outRootFile((_outFileBase + ".root"), "RECREATE"); |
// Write the ROOT file |
| 130 |
outRootFile.cd(); |
TFile outRootFile((_outFileBase + "-" + GetName() + ".root"), "RECREATE"); |
| 131 |
_rootHisto.Write(); |
outRootFile.cd(); |
| 132 |
outRootFile.Close(); |
_rootHisto.Write(); |
| 133 |
|
outRootFile.Close(); |
| 134 |
|
|
| 135 |
|
} |
| 136 |
|
|
| 137 |
#ifdef DEBUGPAMCUT |
#ifdef DEBUGPAMCUT |
| 138 |
cout << "Debug informations from " << GetName() << ":\n"; |
cout << "Debug informations from " << GetName() << ":\n"; |