]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/AliRsnCutSet.cxx
Modified primary vtx cut to activate pile-up cut also for AOD analysis
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / AliRsnCutSet.cxx
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(),
30    fUseMonitor(kFALSE)
31 {
32 //
33 // Constructor without name (not recommended)
34 //
35
36    fBoolValues = new Bool_t[1];
37    AliRsnExpression::fgCutSet = this;
38 }
39
40 //_____________________________________________________________________________
41 AliRsnCutSet::AliRsnCutSet(const char *name, RSNTARGET target) :
42    AliRsnTarget(name, target),
43    fCuts(0),
44    fNumOfCuts(0),
45    fCutScheme(""),
46    fCutSchemeIndexed(""),
47    fBoolValues(0),
48    fIsScheme(kFALSE),
49    fExpression(0),
50    fMonitors(),
51    fUseMonitor(kFALSE)
52 {
53 //
54 // Constructor with argument name (recommended)
55 //
56
57    fBoolValues = new Bool_t[1];
58    fExpression = 0;
59    AliRsnExpression::fgCutSet = this;
60 }
61
62 //_____________________________________________________________________________
63 AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet &copy) :
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),
71    fExpression(copy.fExpression),
72    fMonitors(copy.fMonitors),
73    fUseMonitor(copy.fUseMonitor)
74 {
75 //
76 // Copy constructor
77 //
78
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;
86 }
87
88 //_____________________________________________________________________________
89 AliRsnCutSet &AliRsnCutSet::operator=(const AliRsnCutSet &copy)
90 {
91 //
92 // Assignment operator.
93 //
94
95    AliRsnTarget::operator=(copy);
96    if (this == &copy)
97       return *this;
98
99    fCuts = copy.fCuts;
100    fNumOfCuts = copy.fNumOfCuts;
101    fCutScheme = copy.fCutScheme;
102    fCutSchemeIndexed = copy.fCutSchemeIndexed;
103    fIsScheme = copy.fIsScheme;
104    fExpression = copy.fExpression;
105    fMonitors = copy.fMonitors;
106    fUseMonitor = copy.fUseMonitor;
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);
119 }
120
121 //_____________________________________________________________________________
122 AliRsnCutSet::~AliRsnCutSet()
123 {
124 //
125 // Destructor
126 //
127
128    delete fExpression;
129    delete [] fBoolValues;
130 }
131
132 //_____________________________________________________________________________
133 void AliRsnCutSet::AddCut(AliRsnCut *cut)
134 {
135 //
136 // Add a new cut.
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.
140 //
141
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    }
146
147    Int_t i;
148
149    AliDebug(AliLog::kDebug, "<-");
150    fCuts.Add(cut);
151    AliInfo(Form("====> Adding a new cut: [%s]", cut->GetName()));
152    //cut->Print();
153    fNumOfCuts++;
154
155    if (fBoolValues) delete [] fBoolValues;
156
157    fBoolValues = new Bool_t[fNumOfCuts];
158    for (i = 0; i < fNumOfCuts; i++) {
159       fBoolValues[i] = kTRUE;
160    }
161
162    AliDebug(AliLog::kDebug, Form("%d", fCuts.GetEntriesFast()));
163    AliDebug(AliLog::kDebug, "->");
164 }
165
166 //_____________________________________________________________________________
167 void AliRsnCutSet::ShowCuts() const
168 {
169 //
170 // Prints all cuts
171 //
172    AliRsnCut *cut;
173
174    for (Int_t i = 0; i < fCuts.GetEntriesFast() ; i++) {
175       cut = (AliRsnCut *)fCuts.At(i);
176       cut->Print();
177    }
178 }
179
180 //_____________________________________________________________________________
181 Bool_t AliRsnCutSet::IsSelected(TObject *object)
182 {
183 //
184 // Checks an object according to the cut expression defined here.
185 //
186
187    Int_t i;
188
189    if (!fNumOfCuts) return kTRUE;
190
191    Bool_t boolReturn = kTRUE;
192    AliRsnCut *cut;
193    for (i = 0; i < fNumOfCuts; i++) {
194       cut = (AliRsnCut *)fCuts.At(i);
195       fBoolValues[i] = cut->IsSelected(object);
196    }
197
198    if (fIsScheme) boolReturn = Passed();
199
200    // fill monitoring info
201    if (boolReturn && fUseMonitor) {
202       if (TargetOK(object)) {
203          TIter next(&fMonitors);
204          AliRsnListOutput *mo;
205          while ((mo = (AliRsnListOutput *) next())) {
206             mo->Fill(fEvent,fDaughter);
207          }
208       }
209    }
210
211    return boolReturn;
212 }
213
214 //_____________________________________________________________________________
215 void AliRsnCutSet::SetCutScheme(const char *theValue)
216 {
217 //
218 // Define the combination of cuts with logical operators
219 // and using the names given to all defined cuts.
220 //
221
222    AliDebug(AliLog::kDebug, "<-");
223
224    fCutScheme = theValue;
225    SetCutSchemeIndexed(theValue);
226    fIsScheme = kTRUE;
227    AliDebug(AliLog::kDebug, "->");
228 }
229
230 //_____________________________________________________________________________
231 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
232 {
233 //
234 // Internal method which indexes all cuts to organize their combo
235 //
236
237    AliDebug(AliLog::kDebug, "<-");
238    theValue.Append(" ");
239    // fCutSchemeIndexed = theValue;
240    fCutSchemeIndexed = GetCutSchemeIndexed();
241    AliDebug(AliLog::kDebug, "->");
242 }
243
244 //_____________________________________________________________________________
245 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
246 {
247 //
248 // Retrieve the cut index from its name
249 //
250
251    Int_t i;
252    AliRsnCut *cut;
253
254    for (i = 0; i < fCuts.GetEntriesFast(); i++) {
255       cut = (AliRsnCut *) fCuts.At(i);
256       if (!s.CompareTo(cut->GetName())) return i;
257    }
258
259    return -1;
260 }
261
262 //_____________________________________________________________________________
263 Bool_t AliRsnCutSet::Passed()
264 {
265 //
266 // Combines the cuts according to expression
267 // and gives a global response to the cut check
268 //
269
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;
277
278    return fExpression->Value(*GetCuts());
279 }
280
281 //_____________________________________________________________________________
282 Bool_t AliRsnCutSet::IsValidScheme()
283 {
284 //
285 // Validity check on cut expression specified by user
286 //
287
288    TString str(fCutScheme);
289    AliRsnCut *cut;
290    for (Int_t i = 0; i < fNumOfCuts; i++) {
291       cut = (AliRsnCut *)fCuts.At(i);
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;
306 //   return (!(ShowCutScheme().Contains("Error")));
307 }
308
309 //_____________________________________________________________________________
310 TString AliRsnCutSet::ShowCutScheme() const
311 {
312 //
313 // Utility method to check validity of expression
314 //
315
316    return fCutScheme;
317 //   return fExpression->Unparse();
318 }
319
320 //_____________________________________________________________________________
321 Int_t AliRsnCutSet::TestExpression(TString opt)
322 {
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);
330 //
331 //   AliRsnCutSet* set  = new AliRsnCutSet ("setOne");
332 //   set->AddCut (cut1);
333 //   set->AddCut (cut2);
334 //   set->AddCut (cut3);
335 //
336 //   set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
337 //
338 //   set->ShowCuts ();
339
340    AliDebug(1, opt.Data());
341    return 0;
342 }
343
344 //_____________________________________________________________________________
345 void AliRsnCutSet::PrintSetInfo()
346 {
347 //
348 // Show data about the cut set
349 //
350
351    Int_t i;
352
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++) {
360       cut = (AliRsnCut *) fCuts.At(i);
361       if (cut) AliInfo(Form("%d %d", i, fBoolValues[i]));
362    }
363    AliInfo("========== END Rsn Cut Mgr info ==============");
364 }
365
366 //_____________________________________________________________________________
367 TString AliRsnCutSet::GetCutSchemeIndexed()
368 {
369 //
370 // Internal method to retrieve the list of cuts with their indexes
371 // for evaluation of cut expression
372 //
373
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++) {
380       cut = (AliRsnCut *) fCuts.At(i);
381       str.ReplaceAll(cut->GetName(), Form("%d", i));
382    }
383    AliDebug(AliLog::kDebug, "->");
384    return str;
385 }
386
387 Bool_t AliRsnCutSet::Init(TList *list)
388 {
389    if (!fUseMonitor) return kTRUE;
390
391    TIter next(&fMonitors);
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 {
403    fMonitors.Add(mon);
404 }
405