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(""),
31 // Constructor without name (not recommended)
34 fBoolValues = new Bool_t[1];
35 AliRsnExpression::fgCutSet = this;
38 //_____________________________________________________________________________
39 AliRsnCutSet::AliRsnCutSet(const char *name, RSNTARGET target) :
40 AliRsnTarget(name, target),
44 fCutSchemeIndexed(""),
50 // Constructor with argument name (recommended)
53 fBoolValues = new Bool_t[1];
55 AliRsnExpression::fgCutSet = this;
58 //_____________________________________________________________________________
59 AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
62 fNumOfCuts(copy.fNumOfCuts),
63 fCutScheme(copy.fCutScheme),
64 fCutSchemeIndexed(copy.fCutSchemeIndexed),
66 fIsScheme(copy.fIsScheme),
67 fExpression(copy.fExpression)
74 fBoolValues = new Bool_t[fNumOfCuts];
75 for (i = 0; i < fNumOfCuts; ++i) {
76 fBoolValues[i] = copy.fBoolValues[i];
79 AliRsnExpression::fgCutSet = this;
82 //_____________________________________________________________________________
83 AliRsnCutSet& AliRsnCutSet::operator=(const AliRsnCutSet & copy)
86 // Assignment operator.
89 AliRsnTarget::operator=(copy);
94 fNumOfCuts = copy.fNumOfCuts;
95 fCutScheme = copy.fCutScheme;
96 fCutSchemeIndexed = copy.fCutSchemeIndexed;
97 fIsScheme = copy.fIsScheme;
98 fExpression = copy.fExpression;
100 if (fBoolValues) delete [] fBoolValues;
103 fBoolValues = new Bool_t[fNumOfCuts];
104 for (i = 0; i < fNumOfCuts; ++i) {
105 fBoolValues[i] = copy.fBoolValues[i];
108 AliRsnExpression::fgCutSet = this;
113 //_____________________________________________________________________________
114 AliRsnCutSet::~AliRsnCutSet()
121 delete [] fBoolValues;
124 //_____________________________________________________________________________
125 void AliRsnCutSet::AddCut(AliRsnCut *cut)
129 // This must be done for all components of the final expression.
130 // If the target of the cut does not match the target of this,
131 // the cut is not added.
134 if (!cut->IsTarget(GetTargetType())) {
135 AliError(Form("Cannot add this cut (cut set name,target = [%s],[%s] --- cut name,target = [%s],[%s]", GetName(), GetTargetTypeName(), cut->GetName(), cut->GetTargetTypeName()));
141 AliDebug(AliLog::kDebug, "<-");
143 AliInfo(Form("====> Adding a new cut: [%s]", cut->GetName()));
147 if (fBoolValues) delete [] fBoolValues;
149 fBoolValues = new Bool_t[fNumOfCuts];
150 for (i = 0; i < fNumOfCuts; i++) {
151 fBoolValues[i] = kTRUE;
154 AliDebug(AliLog::kDebug, Form("%d", fCuts.GetEntriesFast()));
155 AliDebug(AliLog::kDebug, "->");
158 //_____________________________________________________________________________
159 void AliRsnCutSet::ShowCuts() const
166 for (Int_t i = 0; i < fCuts.GetEntriesFast() ; i++) {
167 cut = (AliRsnCut*)fCuts.At(i);
172 //_____________________________________________________________________________
173 Bool_t AliRsnCutSet::IsSelected(TObject *object)
176 // Checks an object according to the cut expression defined here.
181 if (!fNumOfCuts) return kTRUE;
183 Bool_t boolReturn = kTRUE;
185 for (i = 0; i < fNumOfCuts; i++) {
186 cut = (AliRsnCut*)fCuts.At(i);
187 fBoolValues[i] = cut->IsSelected(object);
190 if (fIsScheme) boolReturn = Passed();
194 //_____________________________________________________________________________
195 void AliRsnCutSet::SetCutScheme(const char *theValue)
198 // Define the combination of cuts with logical operators
199 // and using the names given to all defined cuts.
202 AliDebug(AliLog::kDebug, "<-");
204 fCutScheme = theValue;
205 SetCutSchemeIndexed(theValue);
207 AliDebug(AliLog::kDebug, "->");
210 //_____________________________________________________________________________
211 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
214 // Internal method which indexes all cuts to organize their combo
217 AliDebug(AliLog::kDebug, "<-");
218 theValue.Append(" ");
219 // fCutSchemeIndexed = theValue;
220 fCutSchemeIndexed = GetCutSchemeIndexed();
221 AliDebug(AliLog::kDebug, "->");
224 //_____________________________________________________________________________
225 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
228 // Retrieve the cut index from its name
234 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
235 cut = (AliRsnCut*) fCuts.At(i);
236 if (!s.CompareTo(cut->GetName())) return i;
242 //_____________________________________________________________________________
243 Bool_t AliRsnCutSet::Passed()
246 // Combines the cuts according to expression
247 // and gives a global response to the cut check
250 AliRsnExpression::fgCutSet = this;
252 fExpression = new AliRsnExpression(fCutSchemeIndexed);
253 AliDebug(AliLog::kDebug, "fExpression was created.");
256 if (fCuts.IsEmpty()) return kTRUE;
258 return fExpression->Value(*GetCuts());
261 //_____________________________________________________________________________
262 Bool_t AliRsnCutSet::IsValidScheme()
265 // Validity check on cut expression specified by user
268 TString str(fCutScheme);
270 for (Int_t i = 0; i < fNumOfCuts; i++) {
271 cut = (AliRsnCut*)fCuts.At(i);
272 str.ReplaceAll(cut->GetName(), "");
274 str.ReplaceAll("&", "");
275 str.ReplaceAll("!", "");
276 str.ReplaceAll("|", "");
277 str.ReplaceAll("(", "");
278 str.ReplaceAll(")", "");
281 AliError(Form("Cut scheme '%s' is not valid !!!", fCutScheme.Data()));
286 // return (!(ShowCutScheme().Contains("Error")));
289 //_____________________________________________________________________________
290 TString AliRsnCutSet::ShowCutScheme() const
293 // Utility method to check validity of expression
297 // return fExpression->Unparse();
300 //_____________________________________________________________________________
301 Int_t AliRsnCutSet::TestExpression(TString opt)
304 // AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
305 // cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
306 // AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
307 // cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
308 // AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
309 // cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
311 // AliRsnCutSet* set = new AliRsnCutSet ("setOne");
312 // set->AddCut (cut1);
313 // set->AddCut (cut2);
314 // set->AddCut (cut3);
316 // set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
320 AliDebug(1, opt.Data());
324 //_____________________________________________________________________________
325 void AliRsnCutSet::PrintSetInfo()
328 // Show data about the cut set
333 AliInfo("========== Rsn Cut Set info ==============");
334 AliInfo(Form("Scheme : %s", fCutScheme.Data()));
335 AliInfo(Form("Scheme : %s", fCutSchemeIndexed.Data()));
336 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
337 AliInfo("====== Cuts ======");
339 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
340 cut = (AliRsnCut*) fCuts.At(i);
341 if (cut) AliInfo(Form("%d %d", i, fBoolValues[i]));
343 AliInfo("========== END Rsn Cut Mgr info ==============");
346 //_____________________________________________________________________________
347 TString AliRsnCutSet::GetCutSchemeIndexed()
350 // Internal method to retrieve the list of cuts with their indexes
351 // for evaluation of cut expression
354 AliDebug(AliLog::kDebug, "<-");
356 TString str(fCutScheme);
357 AliDebug(AliLog::kDebug, Form("Num of cuts %d", fCuts.GetEntriesFast()));
359 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
360 cut = (AliRsnCut*) fCuts.At(i);
361 str.ReplaceAll(cut->GetName(), Form("%d", i));
363 AliDebug(AliLog::kDebug, "->");