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