/[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.5 - (hide annotations) (download)
Tue Oct 27 10:18:20 2009 UTC (15 years, 4 months ago) by pam-fi
Branch: MAIN
Changes since 1.4: +5 -6 lines
Updates in the Doxygen documentation and some fixes.

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 pam-fi 1.5 _rootHisto.GetXaxis()->SetTitle("R [GV]");
21 pam-fi 1.2 _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 pam-fi 1.4 thresholdCoeff), _totalNorm(0.), _infBin(0.), _nGoodHisto(0), _nGoodInfBin(0)
37 pam-fi 1.2 #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 pam-fi 1.4 thresholdCoeff), _totalNorm(0.), _infBin(0.), _nGoodHisto(0), _nGoodInfBin(0)
47 pam-fi 1.1 #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 pam-fi 1.3 bins.push_back(auxString.Atof());
62 pam-fi 1.1 }
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 pam-fi 1.4 double lt = 0.16 * (double) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds
73    
74     // cout << 0.16 * event->GetTrigLevel2()->dltime[0] / 1000. << endl;
75     // cout << lt << endl;
76    
77 pam-fi 1.1 float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();
78     if (cRig >= _bins[0]) {
79     int i = 1;
80     int binningSize = _bins.size();
81     bool found = false;
82     while (!found && i < binningSize) {
83 pam-fi 1.4 if (cRig < _bins[i]) // less than bin[i-1] maximum edge
84 pam-fi 1.1 found = true;
85     else
86     i++;
87     }
88     if (found) {
89 pam-fi 1.4 _totalNorm += lt; // use double for sums of many real numbers
90     _textHisto[i - 1] += lt; // use double for sums of many real numbers
91 pam-fi 1.1 _rootHisto.Fill(cRig, lt);
92 pam-fi 1.4 _nGoodHisto++;
93 pam-fi 1.1 }
94    
95     #ifdef DEBUGPAMCUT
96     else
97     _outUp++;
98     #endif
99     }
100    
101 pam-fi 1.4 else if (cRig > 0.) {
102     _infBin += lt;
103     _nGoodInfBin++;
104 pam-fi 1.1 #ifdef DEBUGPAMCUT
105     _outDown++;
106     #endif
107     }
108     }
109    
110     void LiveTimeAction::Finalize() {
111    
112 pam-fi 1.2 if (_outFileBase != "") {
113    
114     // Write the text file
115 pam-fi 1.5 ofstream outTextFile((_outFileBase + "-" + GetName() + ".txt").Data(), ios_base::out);
116 pam-fi 1.2 streamsize oldPrec = cout.precision();
117     streamsize newPrec = 4;
118     outTextFile.precision(newPrec);
119     outTextFile.setf(ios::fixed, ios::floatfield);
120     for (unsigned int i = 0; i < _textHisto.size(); i++)
121     outTextFile << _textHisto[i] << "\n";
122     outTextFile.close();
123 pam-fi 1.5 outTextFile.open((_outFileBase + "-" + GetName() + "-InfBin.txt").Data(), ios_base::out);
124     outTextFile << GetLTInfBin() << endl;
125 pam-fi 1.2 outTextFile.close();
126     outTextFile.precision(oldPrec);
127     outTextFile << resetiosflags(ios::floatfield);
128    
129     // Write the ROOT file
130 pam-fi 1.5 TFile outRootFile((_outFileBase + "-" + GetName() + ".root"), "RECREATE");
131 pam-fi 1.2 outRootFile.cd();
132     _rootHisto.Write();
133     outRootFile.Close();
134    
135     }
136 pam-fi 1.1
137     #ifdef DEBUGPAMCUT
138     cout << "Debug informations from " << GetName() << ":\n";
139     cout << " Events below the lowest rigidity: " << _outDown << "\n";
140     cout << " Events above the highest rigidity: " << _outUp << endl;
141     #endif
142     }

  ViewVC Help
Powered by ViewVC 1.1.23