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 "AliRsnCut.h"
13 #include "AliRsnExpression.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::sCutSet = this;
38 //_____________________________________________________________________________
39 AliRsnCutSet::AliRsnCutSet(TString name) :
44 fCutSchemeIndexed(""),
50 // Constructor with argument name (recommended)
53 fBoolValues = new Bool_t[1];
55 AliRsnExpression::sCutSet = this;
58 //_____________________________________________________________________________
59 AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
60 TNamed((TNamed) copy),
62 fNumOfCuts(copy.fNumOfCuts),
63 fCutScheme(copy.fCutScheme),
64 fCutSchemeIndexed(copy.fCutSchemeIndexed),
66 fIsScheme(copy.fIsScheme),
67 fExpression(copy.fExpression)
73 AliRsnExpression::sCutSet = this;
76 //_____________________________________________________________________________
77 AliRsnCutSet::~AliRsnCutSet()
84 delete [] fBoolValues;
87 //_____________________________________________________________________________
88 void AliRsnCutSet::AddCut(AliRsnCut *cut)
92 // This must be done for all components of the final expression
97 AliDebug(AliLog::kDebug,"<-");
101 if (fBoolValues) delete fBoolValues;
103 fBoolValues = new Bool_t[fNumOfCuts];
104 for (i = 0; i < fNumOfCuts; i++)
106 fBoolValues[i] = kTRUE;
109 AliDebug(AliLog::kDebug,Form("%d",fCuts.GetEntriesFast()));
110 AliDebug(AliLog::kDebug,"->");
113 //_____________________________________________________________________________
114 void AliRsnCutSet::ShowCuts()
120 // for (Int_t i=0; i<fCuts.GetEntriesFast() ;i++)
122 // cut = (AliRsnCut*) fCuts.At (i);
123 // AliInfo (Form ("%s (\"%s\") [%.2f - %.2f]",cut->GetName(),cut->GetTitle(),cut->GetMin(),cut->GetMax()));
127 //_____________________________________________________________________________
128 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnDaughter *daughter)
131 // Checks an object according to the cut expression defined here.
136 if (!fNumOfCuts) return kTRUE;
138 Bool_t boolReturn = kTRUE;
140 for (i = 0; i < fNumOfCuts; i++)
142 cut = (AliRsnCut*)fCuts.At(i);
143 fBoolValues[i] = cut->IsSelected(type,daughter);
146 if (fIsScheme) boolReturn = Passed();
150 //_____________________________________________________________________________
151 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnPairParticle * pair)
154 // Checks an object according to the cut expression defined here.
159 if (!fNumOfCuts) return kTRUE;
161 Bool_t boolReturn = kTRUE;
163 for (i = 0; i < fNumOfCuts; i++)
165 cut = (AliRsnCut*) fCuts.At(i);
166 fBoolValues[i] = cut->IsSelected(type,pair);
169 if (fIsScheme) boolReturn = Passed();
173 //_____________________________________________________________________________
174 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnEvent * event)
177 // 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++)
187 cut = (AliRsnCut*) fCuts.At(i);
188 fBoolValues[i] = cut->IsSelected(type,event);
191 if (fIsScheme) boolReturn = Passed();
195 //_____________________________________________________________________________
196 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnEvent * ev1, AliRsnEvent *ev2)
199 // Checks an object according to the cut expression defined here.
203 if (!fNumOfCuts) return kTRUE;
205 Bool_t boolReturn = kTRUE;
207 for (i = 0; i < fNumOfCuts; i++)
209 cut = (AliRsnCut*) fCuts.At(i);
210 fBoolValues[i] = cut->IsSelected(type,ev1,ev2);
213 if (fIsScheme) boolReturn = Passed();
217 //_____________________________________________________________________________
218 void AliRsnCutSet::SetCutScheme(const TString & theValue)
221 // Define the combination of cuts with logical operators
222 // and using the names given to all defined cuts.
225 AliDebug(AliLog::kDebug,"<-");
226 fCutScheme = theValue;
227 SetCutSchemeIndexed(theValue);
229 AliDebug(AliLog::kDebug,"->");
232 //_____________________________________________________________________________
233 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
236 // Internal method which indexes all cuts to organize their combo
239 AliDebug(AliLog::kDebug,"<-");
240 theValue.Append(" ");
241 // fCutSchemeIndexed = theValue;
242 fCutSchemeIndexed = GetCutSchemeIndexed();
243 AliDebug(AliLog::kDebug,"->");
246 //_____________________________________________________________________________
247 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
250 // Retrieve the cut index from its name
256 for (i = 0; i < fCuts.GetEntriesFast(); i++)
258 cut = (AliRsnCut*) fCuts.At(i);
259 if (!s.CompareTo(cut->GetName())) return i;
265 //_____________________________________________________________________________
266 Bool_t AliRsnCutSet::Passed()
269 // Combines the cuts according to expression
270 // and gives a global response to the cut check
273 AliRsnExpression::sCutSet = this;
276 fExpression = new AliRsnExpression(fCutSchemeIndexed);
277 AliDebug(AliLog::kDebug,"fExpression was created.");
280 return fExpression->Value(*GetCuts());
283 //_____________________________________________________________________________
284 Bool_t AliRsnCutSet::IsValidScheme()
287 // Validity check on cut expression specified by user
290 return (!(ShowCutScheme().Contains("Error")));
293 //_____________________________________________________________________________
294 TString AliRsnCutSet::ShowCutScheme()
297 // Utility method to check validity of expression
299 return fExpression->Unparse();
302 //_____________________________________________________________________________
303 Int_t AliRsnCutSet::TestExpression(TString opt)
306 // AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
307 // cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
308 // AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
309 // cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
310 // AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
311 // cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
313 // AliRsnCutSet* set = new AliRsnCutSet ("setOne");
314 // set->AddCut (cut1);
315 // set->AddCut (cut2);
316 // set->AddCut (cut3);
318 // set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
322 AliDebug(1, opt.Data());
326 //_____________________________________________________________________________
327 void AliRsnCutSet::PrintSetInfo()
330 // Show data about the cut set
335 AliInfo("========== Rsn Cut Set info ==============");
336 AliInfo(Form("Sheme : %s",fCutScheme.Data()));
337 AliInfo(Form("Sheme : %s",fCutSchemeIndexed.Data()));
338 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
339 AliInfo("====== Cuts ======");
341 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++)
364 cut = (AliRsnCut*) fCuts.At(i);
365 str.ReplaceAll(cut->GetName(),Form("%d",i));
367 AliDebug(AliLog::kDebug,"->");