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 |
pam-fi |
1.3 |
EffCollection::EffCollection(const char *collectionName, TString outFileBase) : |
13 |
pam-fi |
1.1 |
VerboseCollection(collectionName), _selCollection("selCollection"), _detCollection("detCollection"), _outFileBase( |
14 |
pam-fi |
1.3 |
outFileBase), _det(0), _sel(0) { |
15 |
pam-fi |
1.1 |
|
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
void EffCollection::AddDetectorCut(PamCut &cut) { |
19 |
|
|
_detCollection.AddCut(cut); |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
void EffCollection::AddSelectionCut(PamCut &cut) { |
23 |
|
|
_selCollection.AddCut(cut); |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
void EffCollection::AddDetectorAction(CollectionAction &action) { |
27 |
|
|
_detCollection.AddAction(action); |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
void EffCollection::AddSelectionAction(CollectionAction &action) { |
31 |
|
|
_selCollection.AddAction(action); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
int EffCollection::ApplyCut(PamLevel2 *event) { |
35 |
|
|
|
36 |
pam-fi |
1.3 |
_nEv++; |
37 |
|
|
if (_selCollection.ApplyCut(event) == CUTOK) { |
38 |
|
|
_sel++; |
39 |
|
|
if (_detCollection.ApplyCut(event) == CUTOK) { |
40 |
|
|
_det++; |
41 |
|
|
_nGood++; |
42 |
|
|
return CUTOK; |
43 |
pam-fi |
1.1 |
} |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
return 0; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
void EffCollection::Finalize() { |
50 |
|
|
// Let's add all the cuts to the vector of the collection before calling VerboseCollection::Finalize |
51 |
|
|
for (unsigned int i = 0; i < _selCollection.GetSize(); i++) |
52 |
|
|
_cuts.push_back(_selCollection.GetCut(i)); |
53 |
|
|
for (unsigned int i = 0; i < _detCollection.GetSize(); i++) |
54 |
|
|
_cuts.push_back(_detCollection.GetCut(i)); |
55 |
|
|
// Now all the cuts are in place, and VerboseCollection can print its report |
56 |
|
|
VerboseCollection::Finalize(); |
57 |
pam-fi |
1.3 |
|
58 |
pam-fi |
1.1 |
// Add some info about efficiency |
59 |
pam-fi |
1.3 |
float eff; |
60 |
|
|
if (_sel != 0.) |
61 |
pam-fi |
1.4 |
eff = (float)_det / (float)_sel; |
62 |
pam-fi |
1.3 |
else |
63 |
|
|
eff = 0.; |
64 |
pam-fi |
1.2 |
cout << " ****** Efficiency informations ******\n"; |
65 |
|
|
cout << " Detector cuts:\n"; |
66 |
|
|
for (unsigned int i = 0; i < _detCollection.GetSize(); i++) |
67 |
|
|
cout << " - " << _detCollection.GetCut(i)->GetName() << "\n"; |
68 |
pam-fi |
1.3 |
cout << " Total detector efficiency: " << eff << endl; |
69 |
pam-fi |
1.1 |
|
70 |
pam-fi |
1.3 |
// Write the output file |
71 |
pam-fi |
1.1 |
if (_outFileBase != "") { |
72 |
pam-fi |
1.3 |
ofstream outTextFile((_outFileBase + "-eff.txt").Data(), ios_base::out); |
73 |
|
|
outTextFile << _det << " " << _sel << " " << eff << endl; |
74 |
pam-fi |
1.1 |
outTextFile.close(); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
} |