1 |
pam-fi |
1.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, vector<float> &bins, float thresholdCoeff) : |
13 |
|
|
Histo1DAction<Double_t> (actionName, "", outFileBase, "RECREATE", false, true), _thresholdCoeff(thresholdCoeff), |
14 |
|
|
_totalNorm(0.), _nGoodHisto(0), _nGoodInfBin(0) { |
15 |
|
|
SetXAxis("Live Time [s]", bins); |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : |
19 |
|
|
Histo1DAction<Double_t> (actionName, "", outFileBase, "RECREATE", false, true), _thresholdCoeff(thresholdCoeff), |
20 |
|
|
_totalNorm(0.), _nGoodHisto(0), _nGoodInfBin(0) { |
21 |
|
|
SetXAxis("Live Time [s]", rigBinsFile); |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
void LiveTimeAction::OnGood(PamLevel2 *event) { |
25 |
|
|
|
26 |
|
|
double lt = 0.16 * (double) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds |
27 |
|
|
float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); |
28 |
|
|
|
29 |
|
|
Fill(cRig, lt); |
30 |
|
|
|
31 |
|
|
if (cRig >= _bins[0]) { |
32 |
|
|
|
33 |
|
|
if (cRig < _bins.back()) { |
34 |
|
|
_totalNorm += lt; // use double for sums of many real numbers |
35 |
|
|
_nGoodHisto++; |
36 |
|
|
} |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
else if (cRig > 0.) { |
40 |
|
|
_nGoodInfBin++; |
41 |
|
|
} |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
void LiveTimeAction::Finalize() { |
45 |
|
|
|
46 |
|
|
if (_outFileBase != "") { |
47 |
|
|
|
48 |
|
|
// Write the text file |
49 |
|
|
// Using custom output procedure (instead of standard Histo1D::Finalize) to set output precision |
50 |
|
|
ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); |
51 |
|
|
streamsize oldPrec = cout.precision(); |
52 |
|
|
streamsize newPrec = 4; |
53 |
|
|
outTextFile.precision(newPrec); |
54 |
|
|
outTextFile.setf(ios::fixed, ios::floatfield); |
55 |
pam-fi |
1.2 |
outTextFile << GetLTInfBin() << endl; |
56 |
pam-fi |
1.1 |
for (unsigned int i = 0; i < GetHisto().size(); i++) |
57 |
|
|
outTextFile << GetHisto()[i] << "\n"; |
58 |
|
|
outTextFile.close(); |
59 |
pam-fi |
1.2 |
//outTextFile.open((_outFileBase + "-InfBin.txt").Data(), ios_base::out); |
60 |
|
|
//outTextFile << GetLTInfBin() << endl; |
61 |
|
|
//outTextFile.close(); |
62 |
pam-fi |
1.1 |
outTextFile.precision(oldPrec); |
63 |
|
|
outTextFile << resetiosflags(ios::floatfield); |
64 |
|
|
|
65 |
|
|
} |
66 |
|
|
} |