1 |
pam-fi |
1.1 |
/* |
2 |
|
|
* PamCutBase.cpp |
3 |
|
|
* |
4 |
|
|
* Created on: 12-feb-2009 |
5 |
|
|
* Author: Nicola Mori |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
/*! @file PamCutBase.cpp Implementation for classes defined in PamCut.h */ |
9 |
|
|
|
10 |
|
|
#include "PamCutBase.h" |
11 |
|
|
|
12 |
|
|
/* ************** * |
13 |
|
|
* PAMCUT |
14 |
|
|
* ************** */ |
15 |
|
|
int PamCut::ApplyCut(PamLevel2 *event) { |
16 |
|
|
|
17 |
|
|
_nEv++; |
18 |
|
|
int result = Check(event); |
19 |
|
|
if (result == CUTOK) { |
20 |
|
|
_nGood++; |
21 |
|
|
OnGood(event); |
22 |
|
|
} |
23 |
|
|
else { |
24 |
|
|
OnBad(event, result); |
25 |
|
|
} |
26 |
|
|
return result; |
27 |
|
|
|
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
void PamCut::Process(PamLevel2 *events, ULong_t firstEvent, ULong_t lastEvent) { |
31 |
|
|
|
32 |
|
|
// Check the range of events to analyze |
33 |
|
|
if (firstEvent > lastEvent) { |
34 |
|
|
return; |
35 |
|
|
} |
36 |
|
|
if (firstEvent < 0 || lastEvent > events->GetEntries() - 1) { |
37 |
|
|
return; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
// Prepare the counters for the new analysis |
41 |
|
|
Setup(events); |
42 |
|
|
|
43 |
|
|
// Apply the cuts |
44 |
|
|
for (ULong_t iev = firstEvent; iev < lastEvent + 1; iev++) { |
45 |
|
|
events->GetEntry(iev); |
46 |
|
|
ApplyCut(events); |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
// Closes the analysis |
50 |
|
|
Finalize(); |
51 |
|
|
|
52 |
|
|
} |
53 |
pam-fi |
1.2 |
void PamCut::Setup(PamLevel2 *events) { |
54 |
pam-fi |
1.1 |
_nEv = _nGood = 0; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
const char* PamCut::GetName() const { |
58 |
|
|
return _cutName; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void PamCut::SetName(const char *newName) { |
62 |
|
|
_cutName = newName; |
63 |
|
|
} |
64 |
|
|
|
65 |
pam-fi |
1.2 |
PamCut& PamCut::operator=(const PamCut &rightValue) { |
66 |
|
|
_cutName = rightValue._cutName; |
67 |
|
|
return *this; |
68 |
|
|
} |
69 |
pam-fi |
1.1 |
|
70 |
|
|
/* ************************ * |
71 |
|
|
* PAMCUTCOLLECTION |
72 |
|
|
* ************************ */ |
73 |
|
|
|
74 |
|
|
void PamCutCollection::AddCut(PamCut &cut) { |
75 |
|
|
_cuts.push_back(&cut); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
int PamCutCollection::Check(PamLevel2 *event) { |
79 |
|
|
|
80 |
|
|
// Apply the cuts |
81 |
|
|
if (_cuts.size() == 0) { |
82 |
|
|
return CUTOK; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
for (unsigned int icut = 0; icut < _cuts.size(); icut++) { |
86 |
|
|
if (_cuts[icut]->Check(event) != CUTOK) { |
87 |
|
|
return icut; |
88 |
|
|
} |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
return CUTOK; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
int PamCutCollection::ApplyCut(PamLevel2 *event) { |
95 |
|
|
|
96 |
|
|
_nEv++; |
97 |
|
|
// Apply the cuts |
98 |
|
|
if (_cuts.size() == 0) { |
99 |
|
|
_nGood++; |
100 |
|
|
OnGood(event); |
101 |
|
|
return CUTOK; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
for (unsigned int icut = 0; icut < _cuts.size(); icut++) { |
105 |
|
|
if (_cuts[icut]->ApplyCut(event) != CUTOK) { |
106 |
|
|
OnBad(event, icut); |
107 |
|
|
return icut; |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
_nGood++; |
112 |
|
|
OnGood(event); |
113 |
|
|
return CUTOK; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
PamCut *PamCutCollection::GetCut(unsigned int iCut) { |
117 |
|
|
if (_cuts.size() == 0) |
118 |
|
|
return NULL; |
119 |
|
|
if (iCut < 0 || iCut > _cuts.size() - 1) |
120 |
|
|
return NULL; |
121 |
|
|
else |
122 |
|
|
return _cuts[iCut]; |
123 |
|
|
} |
124 |
|
|
|
125 |
pam-fi |
1.3 |
PamCut *PamCutCollection::GetCut(const char *cutName) { |
126 |
|
|
if (_cuts.size() == 0) |
127 |
|
|
return NULL; |
128 |
|
|
for (unsigned int i = 0; i < _cuts.size(); i++){ |
129 |
|
|
if (strcmp(_cuts[i]->GetName(), cutName) == 0) |
130 |
|
|
return _cuts[i]; |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
return NULL; |
134 |
|
|
} |
135 |
|
|
|
136 |
pam-fi |
1.1 |
unsigned int PamCutCollection::GetSize() { |
137 |
|
|
return (unsigned int) _cuts.size(); |
138 |
|
|
|
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
PamCutCollection& PamCutCollection::operator=(const PamCutCollection &rightValue) { |
142 |
|
|
|
143 |
|
|
PamCut::operator=(rightValue); |
144 |
|
|
_cuts = rightValue._cuts; |
145 |
|
|
return *this; |
146 |
|
|
} |
147 |
|
|
|
148 |
pam-fi |
1.2 |
void PamCutCollection::Setup(PamLevel2 *events) { |
149 |
pam-fi |
1.1 |
|
150 |
|
|
PamCut::Setup(events); |
151 |
|
|
|
152 |
pam-fi |
1.2 |
for (unsigned int i = 0; i < GetSize(); i++) { |
153 |
pam-fi |
1.1 |
_cuts[i]->Setup(events); |
154 |
|
|
} |
155 |
|
|
} |
156 |
|
|
|
157 |
pam-fi |
1.2 |
void PamCutCollection::Finalize() { |
158 |
pam-fi |
1.1 |
|
159 |
pam-fi |
1.2 |
// PamCut::Finalize() is currently void, but in future it could contain something, so it's good to place a call here. |
160 |
pam-fi |
1.1 |
PamCut::Finalize(); |
161 |
|
|
|
162 |
pam-fi |
1.2 |
for (unsigned int i = 0; i < GetSize(); i++) { |
163 |
pam-fi |
1.1 |
_cuts[i]->Finalize(); |
164 |
|
|
} |
165 |
|
|
} |