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.
12 #include "AliRsnExpression.h"
13 #include "AliRsnCut.h"
15 #include "AliRsnCutSet.h"
17 ClassImp(AliRsnCutSet)
19 //_____________________________________________________________________________
20 AliRsnCutSet::AliRsnCutSet() :
25 fCutSchemeIndexed(""),
33 // Constructor without name (not recommended)
36 fBoolValues = new Bool_t[1];
37 AliRsnExpression::fgCutSet = this;
40 //_____________________________________________________________________________
41 AliRsnCutSet::AliRsnCutSet(const char *name, RSNTARGET target) :
42 AliRsnTarget(name, target),
46 fCutSchemeIndexed(""),
54 // Constructor with argument name (recommended)
57 fBoolValues = new Bool_t[1];
59 AliRsnExpression::fgCutSet = this;
62 //_____________________________________________________________________________
63 AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet ©) :
66 fNumOfCuts(copy.fNumOfCuts),
67 fCutScheme(copy.fCutScheme),
68 fCutSchemeIndexed(copy.fCutSchemeIndexed),
70 fIsScheme(copy.fIsScheme),
71 fExpression(copy.fExpression),
72 fMonitors(copy.fMonitors),
73 fUseMonitor(copy.fUseMonitor)
80 fBoolValues = new Bool_t[fNumOfCuts];
81 for (i = 0; i < fNumOfCuts; ++i) {
82 fBoolValues[i] = copy.fBoolValues[i];
85 AliRsnExpression::fgCutSet = this;
88 //_____________________________________________________________________________
89 AliRsnCutSet &AliRsnCutSet::operator=(const AliRsnCutSet ©)
92 // Assignment operator.
95 AliRsnTarget::operator=(copy);
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;
108 if (fBoolValues) delete [] fBoolValues;
111 fBoolValues = new Bool_t[fNumOfCuts];
112 for (i = 0; i < fNumOfCuts; ++i) {
113 fBoolValues[i] = copy.fBoolValues[i];
116 AliRsnExpression::fgCutSet = this;
121 //_____________________________________________________________________________
122 AliRsnCutSet::~AliRsnCutSet()
129 delete [] fBoolValues;
132 //_____________________________________________________________________________
133 void AliRsnCutSet::AddCut(AliRsnCut *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.
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()));
149 AliDebug(AliLog::kDebug, "<-");
151 AliInfo(Form("====> Adding a new cut: [%s]", cut->GetName()));
155 if (fBoolValues) delete [] fBoolValues;
157 fBoolValues = new Bool_t[fNumOfCuts];
158 for (i = 0; i < fNumOfCuts; i++) {
159 fBoolValues[i] = kTRUE;
162 AliDebug(AliLog::kDebug, Form("%d", fCuts.GetEntriesFast()));
163 AliDebug(AliLog::kDebug, "->");
166 //_____________________________________________________________________________
167 void AliRsnCutSet::ShowCuts() const
174 for (Int_t i = 0; i < fCuts.GetEntriesFast() ; i++) {
175 cut = (AliRsnCut *)fCuts.At(i);
180 //_____________________________________________________________________________
181 Bool_t AliRsnCutSet::IsSelected(TObject *object)
184 // Checks an object according to the cut expression defined here.
189 if (!fNumOfCuts) return kTRUE;
191 Bool_t boolReturn = kTRUE;
193 for (i = 0; i < fNumOfCuts; i++) {
194 cut = (AliRsnCut *)fCuts.At(i);
195 fBoolValues[i] = cut->IsSelected(object);
198 if (fIsScheme) boolReturn = Passed();
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);
214 //_____________________________________________________________________________
215 void AliRsnCutSet::SetCutScheme(const char *theValue)
218 // Define the combination of cuts with logical operators
219 // and using the names given to all defined cuts.
222 AliDebug(AliLog::kDebug, "<-");
224 fCutScheme = theValue;
225 SetCutSchemeIndexed(theValue);
227 AliDebug(AliLog::kDebug, "->");
230 //_____________________________________________________________________________
231 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
234 // Internal method which indexes all cuts to organize their combo
237 AliDebug(AliLog::kDebug, "<-");
238 theValue.Append(" ");
239 // fCutSchemeIndexed = theValue;
240 fCutSchemeIndexed = GetCutSchemeIndexed();
241 AliDebug(AliLog::kDebug, "->");
244 //_____________________________________________________________________________
245 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
248 // Retrieve the cut index from its name
254 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
255 cut = (AliRsnCut *) fCuts.At(i);
256 if (!s.CompareTo(cut->GetName())) return i;
262 //_____________________________________________________________________________
263 Bool_t AliRsnCutSet::Passed()
266 // Combines the cuts according to expression
267 // and gives a global response to the cut check
270 AliRsnExpression::fgCutSet = this;
272 fExpression = new AliRsnExpression(fCutSchemeIndexed);
273 AliDebug(AliLog::kDebug, "fExpression was created.");
276 if (fCuts.IsEmpty()) return kTRUE;
278 return fExpression->Value(*GetCuts());
281 //_____________________________________________________________________________
282 Bool_t AliRsnCutSet::IsValidScheme()
285 // Validity check on cut expression specified by user
288 TString str(fCutScheme);
290 for (Int_t i = 0; i < fNumOfCuts; i++) {
291 cut = (AliRsnCut *)fCuts.At(i);
292 str.ReplaceAll(cut->GetName(), "");
294 str.ReplaceAll("&", "");
295 str.ReplaceAll("!", "");
296 str.ReplaceAll("|", "");
297 str.ReplaceAll("(", "");
298 str.ReplaceAll(")", "");
301 AliError(Form("Cut scheme '%s' is not valid !!!", fCutScheme.Data()));
306 // return (!(ShowCutScheme().Contains("Error")));
309 //_____________________________________________________________________________
310 TString AliRsnCutSet::ShowCutScheme() const
313 // Utility method to check validity of expression
317 // return fExpression->Unparse();
320 //_____________________________________________________________________________
321 Int_t AliRsnCutSet::TestExpression(TString opt)
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);
331 // AliRsnCutSet* set = new AliRsnCutSet ("setOne");
332 // set->AddCut (cut1);
333 // set->AddCut (cut2);
334 // set->AddCut (cut3);
336 // set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
340 AliDebug(1, opt.Data());
344 //_____________________________________________________________________________
345 void AliRsnCutSet::PrintSetInfo()
348 // Show data about the cut set
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 ======");
359 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
360 cut = (AliRsnCut *) fCuts.At(i);
361 if (cut) AliInfo(Form("%d %d", i, fBoolValues[i]));
363 AliInfo("========== END Rsn Cut Mgr info ==============");
366 //_____________________________________________________________________________
367 TString AliRsnCutSet::GetCutSchemeIndexed()
370 // Internal method to retrieve the list of cuts with their indexes
371 // for evaluation of cut expression
374 AliDebug(AliLog::kDebug, "<-");
376 TString str(fCutScheme);
377 AliDebug(AliLog::kDebug, Form("Num of cuts %d", fCuts.GetEntriesFast()));
379 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
380 cut = (AliRsnCut *) fCuts.At(i);
381 str.ReplaceAll(cut->GetName(), Form("%d", i));
383 AliDebug(AliLog::kDebug, "->");
387 Bool_t AliRsnCutSet::Init(TList *list)
389 if (!fUseMonitor) return kTRUE;
391 TIter next(&fMonitors);
392 AliRsnListOutput *mo;
393 while ((mo = (AliRsnListOutput *) next())) {
394 mo->Init(GetName(),list);
401 void AliRsnCutSet::AddMonitor(AliRsnListOutput *mon)