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