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"
14 #include "AliRsnCutSet.h"
16 ClassImp(AliRsnCutSet)
18 //_____________________________________________________________________________
19 AliRsnCutSet::AliRsnCutSet() :
24 fCutSchemeIndexed(""),
30 // Constructor without name (not recommended)
33 fBoolValues = new Bool_t[1];
34 AliRsnExpression::fgCutSet = this;
37 //_____________________________________________________________________________
38 AliRsnCutSet::AliRsnCutSet(const char *name, RSNTARGET target) :
39 AliRsnTarget(name, target),
43 fCutSchemeIndexed(""),
49 // Constructor with argument name (recommended)
52 fBoolValues = new Bool_t[1];
54 AliRsnExpression::fgCutSet = this;
57 //_____________________________________________________________________________
58 AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
61 fNumOfCuts(copy.fNumOfCuts),
62 fCutScheme(copy.fCutScheme),
63 fCutSchemeIndexed(copy.fCutSchemeIndexed),
65 fIsScheme(copy.fIsScheme),
66 fExpression(copy.fExpression)
73 fBoolValues = new Bool_t[fNumOfCuts];
74 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)
104 fBoolValues[i] = copy.fBoolValues[i];
107 AliRsnExpression::fgCutSet = this;
112 //_____________________________________________________________________________
113 AliRsnCutSet::~AliRsnCutSet()
120 delete [] fBoolValues;
123 //_____________________________________________________________________________
124 void AliRsnCutSet::AddCut(AliRsnCut *cut)
128 // This must be done for all components of the final expression.
129 // If the target of the cut does not match the target of this,
130 // the cut is not added.
133 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++)
152 fBoolValues[i] = kTRUE;
155 AliDebug(AliLog::kDebug,Form("%d",fCuts.GetEntriesFast()));
156 AliDebug(AliLog::kDebug,"->");
159 //_____________________________________________________________________________
160 void AliRsnCutSet::ShowCuts() const
167 for (Int_t i = 0; i < fCuts.GetEntriesFast() ;i++)
169 cut = (AliRsnCut*)fCuts.At (i);
174 //_____________________________________________________________________________
175 Bool_t AliRsnCutSet::IsSelected(TObject *object)
178 // Checks an object according to the cut expression defined here.
183 if (!fNumOfCuts) return kTRUE;
185 Bool_t boolReturn = kTRUE;
187 for (i = 0; i < fNumOfCuts; i++) {
188 cut = (AliRsnCut*)fCuts.At(i);
189 fBoolValues[i] = cut->IsSelected(object);
192 if (fIsScheme) boolReturn = Passed();
196 //_____________________________________________________________________________
197 void AliRsnCutSet::SetCutScheme(const TString & theValue)
200 // Define the combination of cuts with logical operators
201 // and using the names given to all defined cuts.
204 AliDebug(AliLog::kDebug,"<-");
206 fCutScheme = theValue;
207 SetCutSchemeIndexed(theValue);
209 AliDebug(AliLog::kDebug,"->");
212 //_____________________________________________________________________________
213 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
216 // Internal method which indexes all cuts to organize their combo
219 AliDebug(AliLog::kDebug,"<-");
220 theValue.Append(" ");
221 // fCutSchemeIndexed = theValue;
222 fCutSchemeIndexed = GetCutSchemeIndexed();
223 AliDebug(AliLog::kDebug,"->");
226 //_____________________________________________________________________________
227 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
230 // Retrieve the cut index from its name
236 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
237 cut = (AliRsnCut*) fCuts.At(i);
238 if (!s.CompareTo(cut->GetName())) return i;
244 //_____________________________________________________________________________
245 Bool_t AliRsnCutSet::Passed()
248 // Combines the cuts according to expression
249 // and gives a global response to the cut check
252 AliRsnExpression::fgCutSet = this;
255 fExpression = new AliRsnExpression(fCutSchemeIndexed);
256 AliDebug(AliLog::kDebug,"fExpression was created.");
259 if (fCuts.IsEmpty()) return kTRUE;
261 return fExpression->Value(*GetCuts());
264 //_____________________________________________________________________________
265 Bool_t AliRsnCutSet::IsValidScheme()
268 // Validity check on cut expression specified by user
271 TString str(fCutScheme);
273 for (Int_t i = 0; i < fNumOfCuts; i++) {
274 cut = (AliRsnCut*)fCuts.At(i);
275 str.ReplaceAll(cut->GetName(),"");
277 str.ReplaceAll("&","");
278 str.ReplaceAll("!","");
279 str.ReplaceAll("|","");
280 str.ReplaceAll("(","");
281 str.ReplaceAll(")","");
284 AliError(Form("Cut scheme '%s' is not valid !!!",fCutScheme.Data()));
289 // return (!(ShowCutScheme().Contains("Error")));
292 //_____________________________________________________________________________
293 TString AliRsnCutSet::ShowCutScheme()
296 // Utility method to check validity of expression
300 // return fExpression->Unparse();
303 //_____________________________________________________________________________
304 Int_t AliRsnCutSet::TestExpression(TString opt)
307 // AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
308 // cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
309 // AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
310 // cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
311 // AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
312 // cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
314 // AliRsnCutSet* set = new AliRsnCutSet ("setOne");
315 // set->AddCut (cut1);
316 // set->AddCut (cut2);
317 // set->AddCut (cut3);
319 // set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
323 AliDebug(1, opt.Data());
327 //_____________________________________________________________________________
328 void AliRsnCutSet::PrintSetInfo()
331 // Show data about the cut set
336 AliInfo("========== Rsn Cut Set info ==============");
337 AliInfo(Form("Scheme : %s",fCutScheme.Data()));
338 AliInfo(Form("Scheme : %s",fCutSchemeIndexed.Data()));
339 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
340 AliInfo("====== Cuts ======");
342 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
343 cut = (AliRsnCut*) fCuts.At(i);
344 if (cut) AliInfo(Form("%d %d",i,fBoolValues[i]));
346 AliInfo("========== END Rsn Cut Mgr info ==============");
349 //_____________________________________________________________________________
350 TString AliRsnCutSet::GetCutSchemeIndexed()
353 // Internal method to retrieve the list of cuts with their indexes
354 // for evaluation of cut expression
357 AliDebug(AliLog::kDebug,"<-");
359 TString str(fCutScheme);
360 AliDebug(AliLog::kDebug,Form("Num of cuts %d",fCuts.GetEntriesFast()));
362 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
363 cut = (AliRsnCut*) fCuts.At(i);
364 str.ReplaceAll(cut->GetName(),Form("%d",i));
366 AliDebug(AliLog::kDebug,"->");
370 //_____________________________________________________________________________
371 void AliRsnCutSet::SetEvent(AliRsnEvent *event)
374 // Set the reference event to all contained cuts
379 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
380 cut = (AliRsnCut*) fCuts.At(i);
381 if (cut) cut->SetEvent(event);