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);
92 fNumOfCuts = copy.fNumOfCuts;
93 fCutScheme = copy.fCutScheme;
94 fCutSchemeIndexed = copy.fCutSchemeIndexed;
95 fIsScheme = copy.fIsScheme;
96 fExpression = copy.fExpression;
98 if (fBoolValues) delete [] fBoolValues;
101 fBoolValues = new Bool_t[fNumOfCuts];
102 for (i = 0; i < fNumOfCuts; ++i) {
103 fBoolValues[i] = copy.fBoolValues[i];
106 AliRsnExpression::fgCutSet = this;
111 //_____________________________________________________________________________
112 AliRsnCutSet::~AliRsnCutSet()
119 delete [] fBoolValues;
122 //_____________________________________________________________________________
123 void AliRsnCutSet::AddCut(AliRsnCut *cut)
127 // This must be done for all components of the final expression.
128 // If the target of the cut does not match the target of this,
129 // the cut is not added.
132 if (!cut->IsTarget(GetTargetType())) {
133 AliError(Form("Cannot add this cut (cut set name,target = [%s],[%s] --- cut name,target = [%s],[%s]", GetName(), GetTargetTypeName(), cut->GetName(), cut->GetTargetTypeName()));
139 AliDebug(AliLog::kDebug, "<-");
141 AliInfo(Form("====> Adding a new cut: [%s]", cut->GetName()));
145 if (fBoolValues) delete [] fBoolValues;
147 fBoolValues = new Bool_t[fNumOfCuts];
148 for (i = 0; i < fNumOfCuts; i++) {
149 fBoolValues[i] = kTRUE;
152 AliDebug(AliLog::kDebug, Form("%d", fCuts.GetEntriesFast()));
153 AliDebug(AliLog::kDebug, "->");
156 //_____________________________________________________________________________
157 void AliRsnCutSet::ShowCuts() const
164 for (Int_t i = 0; i < fCuts.GetEntriesFast() ; i++) {
165 cut = (AliRsnCut*)fCuts.At(i);
170 //_____________________________________________________________________________
171 Bool_t AliRsnCutSet::IsSelected(TObject *object)
174 // Checks an object according to the cut expression defined here.
179 if (!fNumOfCuts) return kTRUE;
181 Bool_t boolReturn = kTRUE;
183 for (i = 0; i < fNumOfCuts; i++) {
184 cut = (AliRsnCut*)fCuts.At(i);
185 fBoolValues[i] = cut->IsSelected(object);
188 if (fIsScheme) boolReturn = Passed();
192 //_____________________________________________________________________________
193 void AliRsnCutSet::SetCutScheme(const char *theValue)
196 // Define the combination of cuts with logical operators
197 // and using the names given to all defined cuts.
200 AliDebug(AliLog::kDebug, "<-");
202 fCutScheme = theValue;
203 SetCutSchemeIndexed(theValue);
205 AliDebug(AliLog::kDebug, "->");
208 //_____________________________________________________________________________
209 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
212 // Internal method which indexes all cuts to organize their combo
215 AliDebug(AliLog::kDebug, "<-");
216 theValue.Append(" ");
217 // fCutSchemeIndexed = theValue;
218 fCutSchemeIndexed = GetCutSchemeIndexed();
219 AliDebug(AliLog::kDebug, "->");
222 //_____________________________________________________________________________
223 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
226 // Retrieve the cut index from its name
232 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
233 cut = (AliRsnCut*) fCuts.At(i);
234 if (!s.CompareTo(cut->GetName())) return i;
240 //_____________________________________________________________________________
241 Bool_t AliRsnCutSet::Passed()
244 // Combines the cuts according to expression
245 // and gives a global response to the cut check
248 AliRsnExpression::fgCutSet = this;
250 fExpression = new AliRsnExpression(fCutSchemeIndexed);
251 AliDebug(AliLog::kDebug, "fExpression was created.");
254 if (fCuts.IsEmpty()) return kTRUE;
256 return fExpression->Value(*GetCuts());
259 //_____________________________________________________________________________
260 Bool_t AliRsnCutSet::IsValidScheme()
263 // Validity check on cut expression specified by user
266 TString str(fCutScheme);
268 for (Int_t i = 0; i < fNumOfCuts; i++) {
269 cut = (AliRsnCut*)fCuts.At(i);
270 str.ReplaceAll(cut->GetName(), "");
272 str.ReplaceAll("&", "");
273 str.ReplaceAll("!", "");
274 str.ReplaceAll("|", "");
275 str.ReplaceAll("(", "");
276 str.ReplaceAll(")", "");
279 AliError(Form("Cut scheme '%s' is not valid !!!", fCutScheme.Data()));
284 // return (!(ShowCutScheme().Contains("Error")));
287 //_____________________________________________________________________________
288 TString AliRsnCutSet::ShowCutScheme() const
291 // Utility method to check validity of expression
295 // return fExpression->Unparse();
298 //_____________________________________________________________________________
299 Int_t AliRsnCutSet::TestExpression(TString opt)
302 // AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
303 // cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
304 // AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
305 // cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
306 // AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
307 // cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
309 // AliRsnCutSet* set = new AliRsnCutSet ("setOne");
310 // set->AddCut (cut1);
311 // set->AddCut (cut2);
312 // set->AddCut (cut3);
314 // set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
318 AliDebug(1, opt.Data());
322 //_____________________________________________________________________________
323 void AliRsnCutSet::PrintSetInfo()
326 // Show data about the cut set
331 AliInfo("========== Rsn Cut Set info ==============");
332 AliInfo(Form("Scheme : %s", fCutScheme.Data()));
333 AliInfo(Form("Scheme : %s", fCutSchemeIndexed.Data()));
334 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
335 AliInfo("====== Cuts ======");
337 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
338 cut = (AliRsnCut*) fCuts.At(i);
339 if (cut) AliInfo(Form("%d %d", i, fBoolValues[i]));
341 AliInfo("========== END Rsn Cut Mgr info ==============");
344 //_____________________________________________________________________________
345 TString AliRsnCutSet::GetCutSchemeIndexed()
348 // Internal method to retrieve the list of cuts with their indexes
349 // for evaluation of cut expression
352 AliDebug(AliLog::kDebug, "<-");
354 TString str(fCutScheme);
355 AliDebug(AliLog::kDebug, Form("Num of cuts %d", fCuts.GetEntriesFast()));
357 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
358 cut = (AliRsnCut*) fCuts.At(i);
359 str.ReplaceAll(cut->GetName(), Form("%d", i));
361 AliDebug(AliLog::kDebug, "->");