]>
Commit | Line | Data |
---|---|---|
e0baff8c | 1 | // |
2 | // Class AliRsnCutSet | |
3 | // | |
4 | // This is the front-end for cut management and checking. | |
5 | // It must be prepared by adding all required single cuts, | |
6 | // and then with a logical expression which combines all cuts | |
7 | // with the "AND", "OR" and "NOT" operators. | |
8 | // | |
9 | ||
06351446 | 10 | #include "AliLog.h" |
11 | ||
06351446 | 12 | #include "AliRsnExpression.h" |
13 | ||
14 | #include "AliRsnCutSet.h" | |
15 | ||
aec0ec32 | 16 | ClassImp(AliRsnCutSet) |
e2bafbbc | 17 | |
18 | //_____________________________________________________________________________ | |
32992791 | 19 | AliRsnCutSet::AliRsnCutSet() : |
2a1c7696 | 20 | AliRsnTarget(), |
21 | fCuts(0), | |
22 | fNumOfCuts(0), | |
23 | fCutScheme(""), | |
24 | fCutSchemeIndexed(""), | |
25 | fBoolValues(0), | |
26 | fIsScheme(kFALSE), | |
27 | fExpression(0) | |
06351446 | 28 | { |
e2bafbbc | 29 | // |
30 | // Constructor without name (not recommended) | |
31 | // | |
32 | ||
2a1c7696 | 33 | fBoolValues = new Bool_t[1]; |
34 | AliRsnExpression::fgCutSet = this; | |
06351446 | 35 | } |
36 | ||
e2bafbbc | 37 | //_____________________________________________________________________________ |
32992791 | 38 | AliRsnCutSet::AliRsnCutSet(const char *name, RSNTARGET target) : |
2a1c7696 | 39 | AliRsnTarget(name, target), |
40 | fCuts(0), | |
41 | fNumOfCuts(0), | |
42 | fCutScheme(""), | |
43 | fCutSchemeIndexed(""), | |
44 | fBoolValues(0), | |
45 | fIsScheme(kFALSE), | |
46 | fExpression(0) | |
06351446 | 47 | { |
e2bafbbc | 48 | // |
49 | // Constructor with argument name (recommended) | |
50 | // | |
51 | ||
2a1c7696 | 52 | fBoolValues = new Bool_t[1]; |
53 | fExpression = 0; | |
54 | AliRsnExpression::fgCutSet = this; | |
06351446 | 55 | } |
56 | ||
e2bafbbc | 57 | //_____________________________________________________________________________ |
aec0ec32 | 58 | AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) : |
2a1c7696 | 59 | AliRsnTarget(copy), |
60 | fCuts(copy.fCuts), | |
61 | fNumOfCuts(copy.fNumOfCuts), | |
62 | fCutScheme(copy.fCutScheme), | |
63 | fCutSchemeIndexed(copy.fCutSchemeIndexed), | |
64 | fBoolValues(0), | |
65 | fIsScheme(copy.fIsScheme), | |
66 | fExpression(copy.fExpression) | |
06351446 | 67 | { |
e2bafbbc | 68 | // |
69 | // Copy constructor | |
70 | // | |
71 | ||
2a1c7696 | 72 | Int_t i; |
73 | fBoolValues = new Bool_t[fNumOfCuts]; | |
74 | for (i = 0; i < fNumOfCuts; ++i) { | |
75 | fBoolValues[i] = copy.fBoolValues[i]; | |
76 | } | |
77 | ||
78 | AliRsnExpression::fgCutSet = this; | |
32992791 | 79 | } |
80 | ||
81 | //_____________________________________________________________________________ | |
82 | AliRsnCutSet& AliRsnCutSet::operator=(const AliRsnCutSet & copy) | |
83 | { | |
84 | // | |
85 | // Assignment operator. | |
86 | // | |
2a1c7696 | 87 | |
88 | AliRsnTarget::operator=(copy); | |
89 | ||
90 | fCuts = copy.fCuts; | |
91 | fNumOfCuts = copy.fNumOfCuts; | |
92 | fCutScheme = copy.fCutScheme; | |
93 | fCutSchemeIndexed = copy.fCutSchemeIndexed; | |
94 | fIsScheme = copy.fIsScheme; | |
95 | fExpression = copy.fExpression; | |
96 | ||
97 | if (fBoolValues) delete [] fBoolValues; | |
98 | ||
99 | Int_t i; | |
100 | fBoolValues = new Bool_t[fNumOfCuts]; | |
101 | for (i = 0; i < fNumOfCuts; ++i) { | |
102 | fBoolValues[i] = copy.fBoolValues[i]; | |
103 | } | |
104 | ||
105 | AliRsnExpression::fgCutSet = this; | |
106 | ||
107 | return (*this); | |
06351446 | 108 | } |
109 | ||
e2bafbbc | 110 | //_____________________________________________________________________________ |
06351446 | 111 | AliRsnCutSet::~AliRsnCutSet() |
112 | { | |
e2bafbbc | 113 | // |
114 | // Destructor | |
115 | // | |
116 | ||
2a1c7696 | 117 | delete fExpression; |
118 | delete [] fBoolValues; | |
06351446 | 119 | } |
120 | ||
e2bafbbc | 121 | //_____________________________________________________________________________ |
aec0ec32 | 122 | void AliRsnCutSet::AddCut(AliRsnCut *cut) |
06351446 | 123 | { |
e2bafbbc | 124 | // |
125 | // Add a new cut. | |
2dab9030 | 126 | // This must be done for all components of the final expression. |
127 | // If the target of the cut does not match the target of this, | |
128 | // the cut is not added. | |
e2bafbbc | 129 | // |
06351446 | 130 | |
2a1c7696 | 131 | if (!cut->IsTarget(GetTargetType())) { |
132 | AliError(Form("Cannot add this cut (cut set name,target = [%s],[%s] --- cut name,target = [%s],[%s]", GetName(), GetTargetTypeName(), cut->GetName(), cut->GetTargetTypeName())); | |
133 | return; | |
134 | } | |
2dab9030 | 135 | |
2a1c7696 | 136 | Int_t i; |
aec0ec32 | 137 | |
2a1c7696 | 138 | AliDebug(AliLog::kDebug, "<-"); |
139 | fCuts.Add(cut); | |
140 | AliInfo(Form("====> Adding a new cut: [%s]", cut->GetName())); | |
141 | cut->Print(); | |
142 | fNumOfCuts++; | |
aec0ec32 | 143 | |
2a1c7696 | 144 | if (fBoolValues) delete [] fBoolValues; |
aec0ec32 | 145 | |
2a1c7696 | 146 | fBoolValues = new Bool_t[fNumOfCuts]; |
147 | for (i = 0; i < fNumOfCuts; i++) { | |
148 | fBoolValues[i] = kTRUE; | |
149 | } | |
aec0ec32 | 150 | |
2a1c7696 | 151 | AliDebug(AliLog::kDebug, Form("%d", fCuts.GetEntriesFast())); |
152 | AliDebug(AliLog::kDebug, "->"); | |
06351446 | 153 | } |
154 | ||
e2bafbbc | 155 | //_____________________________________________________________________________ |
4fbb2459 | 156 | void AliRsnCutSet::ShowCuts() const |
06351446 | 157 | { |
e2bafbbc | 158 | // |
159 | // Prints all cuts | |
160 | // | |
2a1c7696 | 161 | AliRsnCut *cut; |
162 | ||
163 | for (Int_t i = 0; i < fCuts.GetEntriesFast() ; i++) { | |
164 | cut = (AliRsnCut*)fCuts.At(i); | |
165 | cut->Print(); | |
166 | } | |
06351446 | 167 | } |
168 | ||
e2bafbbc | 169 | //_____________________________________________________________________________ |
32992791 | 170 | Bool_t AliRsnCutSet::IsSelected(TObject *object) |
06351446 | 171 | { |
e2bafbbc | 172 | // |
173 | // Checks an object according to the cut expression defined here. | |
174 | // | |
06351446 | 175 | |
2a1c7696 | 176 | Int_t i; |
177 | ||
178 | if (!fNumOfCuts) return kTRUE; | |
aec0ec32 | 179 | |
2a1c7696 | 180 | Bool_t boolReturn = kTRUE; |
181 | AliRsnCut *cut; | |
182 | for (i = 0; i < fNumOfCuts; i++) { | |
183 | cut = (AliRsnCut*)fCuts.At(i); | |
184 | fBoolValues[i] = cut->IsSelected(object); | |
185 | } | |
e0baff8c | 186 | |
2a1c7696 | 187 | if (fIsScheme) boolReturn = Passed(); |
188 | return boolReturn; | |
e0baff8c | 189 | } |
190 | ||
e2bafbbc | 191 | //_____________________________________________________________________________ |
5faf5a07 | 192 | void AliRsnCutSet::SetCutScheme(const char *theValue) |
06351446 | 193 | { |
e2bafbbc | 194 | // |
195 | // Define the combination of cuts with logical operators | |
196 | // and using the names given to all defined cuts. | |
197 | // | |
06351446 | 198 | |
2a1c7696 | 199 | AliDebug(AliLog::kDebug, "<-"); |
200 | ||
201 | fCutScheme = theValue; | |
202 | SetCutSchemeIndexed(theValue); | |
203 | fIsScheme = kTRUE; | |
204 | AliDebug(AliLog::kDebug, "->"); | |
e2bafbbc | 205 | } |
06351446 | 206 | |
e2bafbbc | 207 | //_____________________________________________________________________________ |
aec0ec32 | 208 | void AliRsnCutSet::SetCutSchemeIndexed(TString theValue) |
06351446 | 209 | { |
e2bafbbc | 210 | // |
211 | // Internal method which indexes all cuts to organize their combo | |
212 | // | |
213 | ||
2a1c7696 | 214 | AliDebug(AliLog::kDebug, "<-"); |
215 | theValue.Append(" "); | |
216 | // fCutSchemeIndexed = theValue; | |
217 | fCutSchemeIndexed = GetCutSchemeIndexed(); | |
218 | AliDebug(AliLog::kDebug, "->"); | |
06351446 | 219 | } |
220 | ||
e2bafbbc | 221 | //_____________________________________________________________________________ |
aec0ec32 | 222 | Int_t AliRsnCutSet::GetIndexByCutName(TString s) |
06351446 | 223 | { |
e2bafbbc | 224 | // |
225 | // Retrieve the cut index from its name | |
226 | // | |
06351446 | 227 | |
2a1c7696 | 228 | Int_t i; |
229 | AliRsnCut *cut; | |
aec0ec32 | 230 | |
2a1c7696 | 231 | for (i = 0; i < fCuts.GetEntriesFast(); i++) { |
232 | cut = (AliRsnCut*) fCuts.At(i); | |
233 | if (!s.CompareTo(cut->GetName())) return i; | |
234 | } | |
aec0ec32 | 235 | |
2a1c7696 | 236 | return -1; |
06351446 | 237 | } |
238 | ||
e2bafbbc | 239 | //_____________________________________________________________________________ |
06351446 | 240 | Bool_t AliRsnCutSet::Passed() |
241 | { | |
e2bafbbc | 242 | // |
243 | // Combines the cuts according to expression | |
244 | // and gives a global response to the cut check | |
245 | // | |
246 | ||
2a1c7696 | 247 | AliRsnExpression::fgCutSet = this; |
248 | if (!fExpression) { | |
249 | fExpression = new AliRsnExpression(fCutSchemeIndexed); | |
250 | AliDebug(AliLog::kDebug, "fExpression was created."); | |
251 | } | |
252 | ||
253 | if (fCuts.IsEmpty()) return kTRUE; | |
aec0ec32 | 254 | |
2a1c7696 | 255 | return fExpression->Value(*GetCuts()); |
06351446 | 256 | } |
257 | ||
e2bafbbc | 258 | //_____________________________________________________________________________ |
06351446 | 259 | Bool_t AliRsnCutSet::IsValidScheme() |
260 | { | |
e2bafbbc | 261 | // |
262 | // Validity check on cut expression specified by user | |
263 | // | |
264 | ||
2a1c7696 | 265 | TString str(fCutScheme); |
266 | AliRsnCut *cut; | |
267 | for (Int_t i = 0; i < fNumOfCuts; i++) { | |
268 | cut = (AliRsnCut*)fCuts.At(i); | |
269 | str.ReplaceAll(cut->GetName(), ""); | |
270 | } | |
271 | str.ReplaceAll("&", ""); | |
272 | str.ReplaceAll("!", ""); | |
273 | str.ReplaceAll("|", ""); | |
274 | str.ReplaceAll("(", ""); | |
275 | str.ReplaceAll(")", ""); | |
276 | ||
277 | if (!str.IsNull()) { | |
278 | AliError(Form("Cut scheme '%s' is not valid !!!", fCutScheme.Data())); | |
279 | return kFALSE; | |
280 | } | |
281 | ||
282 | return kTRUE; | |
cf4668f7 | 283 | // return (!(ShowCutScheme().Contains("Error"))); |
06351446 | 284 | } |
285 | ||
e2bafbbc | 286 | //_____________________________________________________________________________ |
06351446 | 287 | TString AliRsnCutSet::ShowCutScheme() |
288 | { | |
e2bafbbc | 289 | // |
290 | // Utility method to check validity of expression | |
291 | // | |
cf4668f7 | 292 | |
2a1c7696 | 293 | return fCutScheme; |
cf4668f7 | 294 | // return fExpression->Unparse(); |
06351446 | 295 | } |
296 | ||
e2bafbbc | 297 | //_____________________________________________________________________________ |
aec0ec32 | 298 | Int_t AliRsnCutSet::TestExpression(TString opt) |
06351446 | 299 | { |
e2bafbbc | 300 | |
301 | // AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa"); | |
302 | // cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0); | |
303 | // AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb"); | |
304 | // cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0); | |
305 | // AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc"); | |
306 | // cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0); | |
06351446 | 307 | // |
e2bafbbc | 308 | // AliRsnCutSet* set = new AliRsnCutSet ("setOne"); |
309 | // set->AddCut (cut1); | |
310 | // set->AddCut (cut2); | |
311 | // set->AddCut (cut3); | |
06351446 | 312 | // |
e2bafbbc | 313 | // set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))"); |
06351446 | 314 | // |
315 | // set->ShowCuts (); | |
316 | ||
2a1c7696 | 317 | AliDebug(1, opt.Data()); |
318 | return 0; | |
06351446 | 319 | } |
320 | ||
e2bafbbc | 321 | //_____________________________________________________________________________ |
06351446 | 322 | void AliRsnCutSet::PrintSetInfo() |
323 | { | |
e2bafbbc | 324 | // |
325 | // Show data about the cut set | |
326 | // | |
06351446 | 327 | |
2a1c7696 | 328 | Int_t i; |
aec0ec32 | 329 | |
2a1c7696 | 330 | AliInfo("========== Rsn Cut Set info =============="); |
331 | AliInfo(Form("Scheme : %s", fCutScheme.Data())); | |
332 | AliInfo(Form("Scheme : %s", fCutSchemeIndexed.Data())); | |
333 | AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast())); | |
334 | AliInfo("====== Cuts ======"); | |
335 | AliRsnCut *cut; | |
336 | for (i = 0; i < fCuts.GetEntriesFast(); i++) { | |
337 | cut = (AliRsnCut*) fCuts.At(i); | |
338 | if (cut) AliInfo(Form("%d %d", i, fBoolValues[i])); | |
339 | } | |
340 | AliInfo("========== END Rsn Cut Mgr info =============="); | |
06351446 | 341 | } |
342 | ||
e2bafbbc | 343 | //_____________________________________________________________________________ |
06351446 | 344 | TString AliRsnCutSet::GetCutSchemeIndexed() |
345 | { | |
e2bafbbc | 346 | // |
347 | // Internal method to retrieve the list of cuts with their indexes | |
348 | // for evaluation of cut expression | |
349 | // | |
06351446 | 350 | |
2a1c7696 | 351 | AliDebug(AliLog::kDebug, "<-"); |
352 | Int_t i; | |
353 | TString str(fCutScheme); | |
354 | AliDebug(AliLog::kDebug, Form("Num of cuts %d", fCuts.GetEntriesFast())); | |
355 | AliRsnCut *cut; | |
356 | for (i = 0; i < fCuts.GetEntriesFast(); i++) { | |
357 | cut = (AliRsnCut*) fCuts.At(i); | |
358 | str.ReplaceAll(cut->GetName(), Form("%d", i)); | |
359 | } | |
360 | AliDebug(AliLog::kDebug, "->"); | |
361 | return str; | |
e2bafbbc | 362 | } |