/[PAMELA software]/PamCut/CollectionActions/LiveTimeAction/LiveTimeAction.cpp
ViewVC logotype

Annotation of /PamCut/CollectionActions/LiveTimeAction/LiveTimeAction.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Aug 5 17:04:18 2009 UTC (15 years, 6 months ago) by pam-fi
Branch: MAIN
Changes since 1.1: +59 -36 lines
Constructor added;  now save on file is optional.

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 pam-fi 1.2 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");
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), _total(0.), _zeroBin(0.)
37     #ifdef DEBUGPAMCUT
38     , _outUp(0), _outDown(0)
39     #endif
40     {
41     _InitHistos(bins);
42     }
43    
44 pam-fi 1.1 LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) :
45     CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff(
46     thresholdCoeff), _total(0.), _zeroBin(0.)
47     #ifdef DEBUGPAMCUT
48     , _outUp(0), _outDown(0)
49     #endif
50     {
51    
52     // Reading the bins from file
53     ifstream rigBinListFile;
54     rigBinListFile.open(rigBinsFile);
55    
56     TString auxString;
57 pam-fi 1.2 vector<float> bins(0);
58 pam-fi 1.1 while (!rigBinListFile.eof()) {
59     rigBinListFile >> auxString;
60     if (auxString != "") {
61     _bins.push_back(auxString.Atof());
62     }
63     }
64     rigBinListFile.close();
65    
66 pam-fi 1.2 _InitHistos(bins);
67 pam-fi 1.1
68     }
69    
70     void LiveTimeAction::OnGood(PamLevel2 *event) {
71    
72     float lt = 0.16 * (float) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds
73     _total += lt;
74     float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();
75     if (cRig >= _bins[0]) {
76     int i = 1;
77     int binningSize = _bins.size();
78     bool found = false;
79     while (!found && i < binningSize) {
80     if (cRig < _bins[i])
81     found = true;
82     else
83     i++;
84     }
85     if (found) {
86     _textHisto[i - 1] += lt;
87     _rootHisto.Fill(cRig, lt);
88     }
89    
90     #ifdef DEBUGPAMCUT
91     else
92     _outUp++;
93     #endif
94     }
95    
96     else {
97     _zeroBin += lt;
98     #ifdef DEBUGPAMCUT
99     _outDown++;
100     #endif
101     }
102     }
103    
104     void LiveTimeAction::Finalize() {
105    
106 pam-fi 1.2 if (_outFileBase != "") {
107    
108     // Write the text file
109     ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);
110     streamsize oldPrec = cout.precision();
111     streamsize newPrec = 4;
112     outTextFile.precision(newPrec);
113     outTextFile.setf(ios::fixed, ios::floatfield);
114     for (unsigned int i = 0; i < _textHisto.size(); i++)
115     outTextFile << _textHisto[i] << "\n";
116     outTextFile.close();
117     outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out);
118     outTextFile << "Zero bin: " << GetZeroBin() << "\n";
119     outTextFile << "Total live time: " << GetTotalLT() << "\n";
120     outTextFile.close();
121     outTextFile.precision(oldPrec);
122     outTextFile << resetiosflags(ios::floatfield);
123    
124     // Write the ROOT file
125     TFile outRootFile((_outFileBase + ".root"), "RECREATE");
126     outRootFile.cd();
127     _rootHisto.Write();
128     outRootFile.Close();
129    
130     }
131 pam-fi 1.1
132     #ifdef DEBUGPAMCUT
133     cout << "Debug informations from " << GetName() << ":\n";
134     cout << " Events below the lowest rigidity: " << _outDown << "\n";
135     cout << " Events above the highest rigidity: " << _outUp << endl;
136     #endif
137     }

  ViewVC Help
Powered by ViewVC 1.1.23