1 |
pam-fi |
1.1 |
/* |
2 |
|
|
* FluxHistoAction.cpp |
3 |
|
|
* |
4 |
|
|
* Created on: 20-mag-2009 |
5 |
|
|
* Author: Nicola Mori |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
/*! @file FluxHistoAction.cpp The FluxHistoAction class implementation file */ |
9 |
|
|
|
10 |
|
|
#include "FluxHistoAction.h" |
11 |
|
|
|
12 |
|
|
FluxHistoAction::FluxHistoAction(const char *actionName, TString outFileBase, TString rigBinsFile) : |
13 |
|
|
CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0) |
14 |
|
|
#ifdef DEBUGPAMCUT |
15 |
|
|
, _outUp(0), _outDown(0) |
16 |
|
|
#endif |
17 |
|
|
{ |
18 |
|
|
|
19 |
|
|
// Reading the bins from file |
20 |
|
|
ifstream rigBinListFile; |
21 |
|
|
rigBinListFile.open(rigBinsFile); |
22 |
|
|
|
23 |
|
|
TString auxString; |
24 |
|
|
while (!rigBinListFile.eof()) { |
25 |
|
|
rigBinListFile >> auxString; |
26 |
|
|
if (auxString != "") { |
27 |
|
|
_bins.push_back(auxString.Atof()); |
28 |
|
|
} |
29 |
|
|
} |
30 |
|
|
rigBinListFile.close(); |
31 |
|
|
|
32 |
|
|
// Initializing histograms |
33 |
|
|
_textHisto.assign(_bins.size() - 1, 0); |
34 |
|
|
_rootHisto.SetName("rigHisto"); |
35 |
|
|
_rootHisto.SetTitle("Rigidity histogram"); |
36 |
|
|
_rootHisto.GetXaxis()->SetTitle("R"); |
37 |
|
|
_rootHisto.GetYaxis()->SetTitle("Events"); |
38 |
|
|
|
39 |
|
|
Double_t *auxArray = new Double_t[_bins.size()]; |
40 |
|
|
|
41 |
|
|
for (unsigned int i = 1; i < _bins.size(); i++) { |
42 |
|
|
auxArray[i] = _bins[i]; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
_rootHisto.SetBins(_bins.size() - 1, auxArray); |
46 |
|
|
|
47 |
|
|
delete[] auxArray; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
void FluxHistoAction::OnGood(PamLevel2 *event) { |
51 |
|
|
|
52 |
|
|
float rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection(); |
53 |
|
|
if (rig >= _bins[0]) { |
54 |
|
|
int i = 1; |
55 |
|
|
int binningSize = _bins.size(); |
56 |
|
|
bool found = false; |
57 |
|
|
while (!found && i < binningSize) { |
58 |
|
|
if (rig < _bins[i]) |
59 |
|
|
found = true; |
60 |
|
|
else |
61 |
|
|
i++; |
62 |
|
|
} |
63 |
|
|
if (found) { |
64 |
|
|
_textHisto[i - 1]++; |
65 |
|
|
_rootHisto.Fill(rig); |
66 |
|
|
} |
67 |
|
|
#ifdef DEBUGPAMCUT |
68 |
|
|
else |
69 |
|
|
_outUp++; |
70 |
|
|
#endif |
71 |
|
|
} |
72 |
|
|
#ifdef DEBUGPAMCUT |
73 |
|
|
else |
74 |
|
|
_outDown++; |
75 |
|
|
#endif |
76 |
|
|
|
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
void FluxHistoAction::Finalize() { |
80 |
|
|
|
81 |
|
|
// Write the text file |
82 |
|
|
ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out); |
83 |
|
|
streamsize oldPrec = cout.precision(); |
84 |
|
|
streamsize newPrec = 4; |
85 |
|
|
outTextFile.precision(newPrec); |
86 |
|
|
outTextFile.setf(ios::fixed, ios::floatfield); |
87 |
|
|
for (unsigned int i = 0; i < _textHisto.size(); i++) |
88 |
|
|
outTextFile << _bins[i] << " " << _bins[i + 1] << " " << _textHisto[i] << "\n"; |
89 |
|
|
outTextFile.close(); |
90 |
|
|
outTextFile.precision(oldPrec); |
91 |
|
|
outTextFile << resetiosflags(ios::floatfield); |
92 |
|
|
|
93 |
|
|
// Write the ROOT file |
94 |
|
|
TFile outRootFile((_outFileBase + ".root"), "RECREATE"); |
95 |
|
|
outRootFile.cd(); |
96 |
|
|
_rootHisto.Write(); |
97 |
|
|
//outRootFile.Close(); |
98 |
|
|
|
99 |
|
|
#ifdef DEBUGPAMCUT |
100 |
|
|
cout << "Debug informations from " << GetName() << ":\n"; |
101 |
|
|
cout << " Events below the lowest rigidity: " << _outDown << "\n"; |
102 |
|
|
cout << " Events above the highest rigidity: " << _outUp << endl; |
103 |
|
|
#endif |
104 |
|
|
} |