1 |
pam-fi |
1.1 |
/* |
2 |
|
|
* EffCollection.cpp |
3 |
|
|
* |
4 |
|
|
* Created on: 10/ago/2009 |
5 |
|
|
* Author: Nicola Mori |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
/*! @file EffCollection.cpp The EffCollection class implementation file. */ |
9 |
|
|
|
10 |
|
|
#include "EffCollection.h" |
11 |
|
|
|
12 |
|
|
EffCollection::EffCollection(const char *collectionName, TString rigBinsFile, TString &outFileBase, bool absRig) : |
13 |
|
|
VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase( |
14 |
|
|
outFileBase), _absRig(absRig), _bins(0), _sel(0), _det(0), _outUp(0), _outDown(0) { |
15 |
|
|
|
16 |
|
|
ifstream rigBinListFile; |
17 |
|
|
rigBinListFile.open(rigBinsFile); |
18 |
|
|
|
19 |
|
|
TString auxString; |
20 |
|
|
while (!rigBinListFile.eof()) { |
21 |
|
|
rigBinListFile >> auxString; |
22 |
|
|
if (auxString != "") { |
23 |
|
|
_bins.push_back(auxString.Atof()); |
24 |
|
|
} |
25 |
|
|
} |
26 |
|
|
rigBinListFile.close(); |
27 |
|
|
|
28 |
|
|
_sel.resize(_bins.size() - 1, 0); |
29 |
|
|
_det.resize(_bins.size() - 1, 0); |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
void EffCollection::AddDetectorCut(PamCut &cut) { |
33 |
|
|
_detCollection.AddCut(cut); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
void EffCollection::AddSelectionCut(PamCut &cut) { |
37 |
|
|
_selCollection.AddCut(cut); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
void EffCollection::AddDetectorAction(CollectionAction &action) { |
41 |
|
|
_detCollection.AddAction(action); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
void EffCollection::AddSelectionAction(CollectionAction &action) { |
45 |
|
|
_selCollection.AddAction(action); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
int EffCollection::ApplyCut(PamLevel2 *event) { |
49 |
|
|
|
50 |
|
|
// See if the rigidity of the event is between the limits |
51 |
|
|
float rig; |
52 |
|
|
if (_absRig) |
53 |
|
|
rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity(); |
54 |
|
|
else |
55 |
|
|
rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection(); |
56 |
|
|
if (rig >= _bins[0]) { |
57 |
|
|
int i = 1; |
58 |
|
|
while (rig >= _bins[i] && i < (int) _bins.size()) { |
59 |
|
|
i++; |
60 |
|
|
} |
61 |
|
|
i--; |
62 |
|
|
if (i < (int) (_sel.size())) { |
63 |
|
|
_nEv++; |
64 |
|
|
// Rigidity is OK, let's apply the cuts |
65 |
|
|
if (_selCollection.ApplyCut(event) == CUTOK) { |
66 |
|
|
_sel[i]++; |
67 |
|
|
if (_detCollection.ApplyCut(event) == CUTOK) { |
68 |
|
|
_det[i]++; |
69 |
|
|
_nGood++; |
70 |
|
|
return CUTOK; |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
} |
74 |
|
|
else |
75 |
|
|
_outUp++; |
76 |
|
|
} |
77 |
|
|
else |
78 |
|
|
_outDown++; |
79 |
|
|
|
80 |
|
|
return 0; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
void EffCollection::Finalize() { |
84 |
|
|
// Let's add all the cuts to the vector of the collection before calling VerboseCollection::Finalize |
85 |
|
|
for (unsigned int i = 0; i < _selCollection.GetSize(); i++) |
86 |
|
|
_cuts.push_back(_selCollection.GetCut(i)); |
87 |
|
|
for (unsigned int i = 0; i < _detCollection.GetSize(); i++) |
88 |
|
|
_cuts.push_back(_detCollection.GetCut(i)); |
89 |
|
|
// Now all the cuts are in place, and VerboseCollection can print its report |
90 |
|
|
VerboseCollection::Finalize(); |
91 |
|
|
// Add some info about efficiency |
92 |
|
|
cout << " Events below the minimum rigidity: " << _outDown << "\n"; |
93 |
|
|
cout << " Events above the maximum rigidity: " << _outUp << "\n"; |
94 |
|
|
cout << " Integrated efficiency: " |
95 |
|
|
<< (float) _detCollection.GetNGood() / |
96 |
|
|
(float) (_selCollection.GetCut(_selCollection.GetSize() - 1)->GetNGood()) |
97 |
|
|
<< "\n" << endl; |
98 |
|
|
|
99 |
|
|
// Write the output files |
100 |
|
|
if (_outFileBase != "") { |
101 |
|
|
ofstream outTextFile((_outFileBase + "-sel.txt").Data(), ios_base::out); |
102 |
|
|
for (unsigned int i = 0; i < _sel.size(); i++) { |
103 |
|
|
outTextFile << _sel[i] << "\n"; |
104 |
|
|
} |
105 |
|
|
outTextFile.close(); |
106 |
|
|
|
107 |
|
|
outTextFile.open((_outFileBase + "-det.txt").Data(), ios_base::out); |
108 |
|
|
for (unsigned int i = 0; i < _det.size(); i++) { |
109 |
|
|
outTextFile << _det[i] << "\n"; |
110 |
|
|
} |
111 |
|
|
outTextFile.close(); |
112 |
|
|
|
113 |
|
|
outTextFile.open((_outFileBase + "-eff.txt").Data(), ios_base::out); |
114 |
|
|
for (unsigned int i = 0; i < _det.size(); i++) { |
115 |
|
|
if (_sel[i] != 0) |
116 |
|
|
outTextFile << (float) _det[i] / (float) _sel[i] << "\n"; |
117 |
|
|
else |
118 |
|
|
outTextFile << "0.\n"; |
119 |
|
|
} |
120 |
|
|
outTextFile.close(); |
121 |
|
|
|
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
} |