1 |
pam-fi |
1.1 |
/* |
2 |
|
|
* RigFillAction.cpp |
3 |
|
|
* |
4 |
|
|
* Created on: 14/lug/2009 |
5 |
|
|
* Author: Nicola Mori |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
/*! @file RigFillAction.cpp The RigFillAction class implementation file. */ |
9 |
|
|
|
10 |
|
|
#include "RigFillAction.h" |
11 |
|
|
|
12 |
pam-fi |
1.2 |
void RigFillAction::_InitHistos(vector<float> &bins) { |
13 |
pam-fi |
1.1 |
|
14 |
pam-fi |
1.2 |
_bins = bins; |
15 |
pam-fi |
1.1 |
|
16 |
|
|
// Initializing histograms |
17 |
|
|
_rootHisto.SetName("rfHisto"); |
18 |
|
|
_rootHisto.SetTitle(Form("Rc Vs R (thr.: %.2f)", _thresholdCoeff)); |
19 |
|
|
_rootHisto.GetXaxis()->SetTitle("R (GV)"); |
20 |
|
|
_rootHisto.GetYaxis()->SetTitle("Rc (GV)"); |
21 |
|
|
|
22 |
|
|
Double_t *auxArray = new Double_t[_bins.size()]; |
23 |
|
|
|
24 |
|
|
for (unsigned int i = 1; i < _bins.size(); i++) { |
25 |
|
|
auxArray[i] = _bins[i]; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
_rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray); |
29 |
|
|
delete[] auxArray; |
30 |
|
|
|
31 |
pam-fi |
1.2 |
_zeroCutoffBins.resize(_bins.size() - 1, 0); |
32 |
pam-fi |
1.1 |
_textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0); |
33 |
|
|
} |
34 |
|
|
|
35 |
pam-fi |
1.2 |
RigFillAction::RigFillAction(const char *actionName, TString outFileBase, vector<float> &bins, float thresholdCoeff) : |
36 |
|
|
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), |
37 |
|
|
_zeroCutoffBins(0), _thresholdCoeff(thresholdCoeff) { |
38 |
|
|
|
39 |
|
|
_InitHistos(bins); |
40 |
|
|
|
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) : |
44 |
|
|
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0), |
45 |
|
|
_zeroCutoffBins(0), _thresholdCoeff(thresholdCoeff) { |
46 |
|
|
|
47 |
|
|
// Reading the bins from file |
48 |
|
|
ifstream rigBinListFile; |
49 |
|
|
rigBinListFile.open(rigBinsFile); |
50 |
|
|
|
51 |
|
|
TString auxString; |
52 |
|
|
vector<float> bins(0); |
53 |
|
|
while (!rigBinListFile.eof()) { |
54 |
|
|
rigBinListFile >> auxString; |
55 |
|
|
if (auxString != "") { |
56 |
|
|
bins.push_back(auxString.Atof()); |
57 |
|
|
} |
58 |
|
|
} |
59 |
|
|
rigBinListFile.close(); |
60 |
|
|
|
61 |
|
|
_InitHistos(bins); |
62 |
|
|
|
63 |
|
|
} |
64 |
|
|
|
65 |
pam-fi |
1.1 |
void RigFillAction::OnGood(PamLevel2 *event) { |
66 |
|
|
|
67 |
|
|
float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL(); |
68 |
|
|
float rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity(); |
69 |
|
|
|
70 |
|
|
_rootHisto.Fill(rigThreshold, rig); |
71 |
|
|
|
72 |
|
|
//Bin identification: value must be less than (<) bin maximum |
73 |
|
|
|
74 |
|
|
int i = 1; |
75 |
pam-fi |
1.2 |
while (rig >= _bins[i] && i < (int) _textHisto.GetNRows()) { |
76 |
pam-fi |
1.1 |
i++; |
77 |
|
|
} |
78 |
|
|
i--; |
79 |
|
|
|
80 |
pam-fi |
1.2 |
//Check the zero bins |
81 |
|
|
if (rigThreshold < _bins[0]) |
82 |
|
|
_zeroCutoffBins[i]++; |
83 |
|
|
else { |
84 |
|
|
int j = 1; |
85 |
|
|
while (rigThreshold >= _bins[j] && j < (int) _textHisto.GetNCols()) { |
86 |
|
|
j++; |
87 |
|
|
} |
88 |
|
|
j--; |
89 |
|
|
|
90 |
|
|
if (i < (int) _textHisto.GetNRows() && j < (int) _textHisto.GetNCols()) |
91 |
|
|
_textHisto[i][j]++; |
92 |
pam-fi |
1.1 |
} |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
void RigFillAction::Finalize() { |
96 |
|
|
|
97 |
|
|
// Write the text file |
98 |
pam-fi |
1.2 |
if (_outFileBase != "") { |
99 |
|
|
|
100 |
|
|
ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); |
101 |
|
|
for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) { |
102 |
|
|
for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) { |
103 |
|
|
outTextFile << setw(7) << _textHisto[i][j] << " "; |
104 |
|
|
} |
105 |
|
|
outTextFile << "\n"; |
106 |
pam-fi |
1.1 |
} |
107 |
pam-fi |
1.2 |
outTextFile.close(); |
108 |
pam-fi |
1.1 |
|
109 |
pam-fi |
1.2 |
// Write the report file, where zero bins are recorded |
110 |
|
|
outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out); |
111 |
|
|
outTextFile << "Zero bins for cutoff rigidity: \n"; |
112 |
|
|
for (unsigned int i = 0; i < _zeroCutoffBins.size(); i++) |
113 |
|
|
cout << GetCutoffZeroBins()[i] << "\n"; |
114 |
|
|
|
115 |
|
|
// Write the ROOT file |
116 |
|
|
TFile outRootFile((_outFileBase + ".root"), "RECREATE"); |
117 |
|
|
outRootFile.cd(); |
118 |
|
|
_rootHisto.Write(); |
119 |
|
|
outRootFile.Close(); |
120 |
pam-fi |
1.1 |
|
121 |
pam-fi |
1.2 |
} |
122 |
pam-fi |
1.1 |
} |