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::fgCutSet = this;
38 //_____________________________________________________________________________
39 AliRsnCutSet::AliRsnCutSet(TString name) :
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) :
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::fgCutSet = 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++) {
105 fBoolValues[i] = kTRUE;
108 AliDebug(AliLog::kDebug,Form("%d",fCuts.GetEntriesFast()));
109 AliDebug(AliLog::kDebug,"->");
112 //_____________________________________________________________________________
113 void AliRsnCutSet::ShowCuts() const
119 // for (Int_t i=0; i<fCuts.GetEntriesFast() ;i++)
121 // cut = (AliRsnCut*) fCuts.At (i);
122 // AliInfo (Form ("%s (\"%s\") [%.2f - %.2f]",cut->GetName(),cut->GetTitle(),cut->GetMin(),cut->GetMax()));
126 //_____________________________________________________________________________
127 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnDaughter *daughter)
130 // Checks an object according to the cut expression defined here.
135 if (!fNumOfCuts) return kTRUE;
137 Bool_t boolReturn = kTRUE;
139 for (i = 0; i < fNumOfCuts; i++) {
140 cut = (AliRsnCut*)fCuts.At(i);
141 fBoolValues[i] = cut->IsSelected(type,daughter);
144 if (fIsScheme) boolReturn = Passed();
148 //_____________________________________________________________________________
149 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnPairParticle * pair)
152 // Checks an object according to the cut expression defined here.
157 if (!fNumOfCuts) return kTRUE;
159 Bool_t boolReturn = kTRUE;
161 for (i = 0; i < fNumOfCuts; i++) {
162 cut = (AliRsnCut*) fCuts.At(i);
163 fBoolValues[i] = cut->IsSelected(type,pair);
166 if (fIsScheme) boolReturn = Passed();
170 //_____________________________________________________________________________
171 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnEvent * event)
174 // Checks an object according to the cut expression defined here.
178 if (!fNumOfCuts) return kTRUE;
180 Bool_t boolReturn = kTRUE;
182 for (i = 0; i < fNumOfCuts; i++) {
183 cut = (AliRsnCut*) fCuts.At(i);
184 fBoolValues[i] = cut->IsSelected(type,event);
187 if (fIsScheme) boolReturn = Passed();
191 //_____________________________________________________________________________
192 Bool_t AliRsnCutSet::IsSelected(AliRsnCut::ETarget type, AliRsnEvent * ev1, AliRsnEvent *ev2)
195 // Checks an object according to the cut expression defined here.
199 if (!fNumOfCuts) return kTRUE;
201 Bool_t boolReturn = kTRUE;
203 for (i = 0; i < fNumOfCuts; i++) {
204 cut = (AliRsnCut*) fCuts.At(i);
205 fBoolValues[i] = cut->IsSelected(type,ev1,ev2);
208 if (fIsScheme) boolReturn = Passed();
212 //_____________________________________________________________________________
213 void AliRsnCutSet::SetCutScheme(const TString & theValue)
216 // Define the combination of cuts with logical operators
217 // and using the names given to all defined cuts.
220 AliDebug(AliLog::kDebug,"<-");
221 fCutScheme = theValue;
222 SetCutSchemeIndexed(theValue);
224 AliDebug(AliLog::kDebug,"->");
227 //_____________________________________________________________________________
228 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
231 // Internal method which indexes all cuts to organize their combo
234 AliDebug(AliLog::kDebug,"<-");
235 theValue.Append(" ");
236 // fCutSchemeIndexed = theValue;
237 fCutSchemeIndexed = GetCutSchemeIndexed();
238 AliDebug(AliLog::kDebug,"->");
241 //_____________________________________________________________________________
242 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
245 // Retrieve the cut index from its name
251 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
252 cut = (AliRsnCut*) fCuts.At(i);
253 if (!s.CompareTo(cut->GetName())) return i;
259 //_____________________________________________________________________________
260 Bool_t AliRsnCutSet::Passed()
263 // Combines the cuts according to expression
264 // and gives a global response to the cut check
267 AliRsnExpression::fgCutSet = this;
269 fExpression = new AliRsnExpression(fCutSchemeIndexed);
270 AliDebug(AliLog::kDebug,"fExpression was created.");
273 return fExpression->Value(*GetCuts());
276 //_____________________________________________________________________________
277 Bool_t AliRsnCutSet::IsValidScheme()
280 // Validity check on cut expression specified by user
283 return (!(ShowCutScheme().Contains("Error")));
286 //_____________________________________________________________________________
287 TString AliRsnCutSet::ShowCutScheme()
290 // Utility method to check validity of expression
292 return fExpression->Unparse();
295 //_____________________________________________________________________________
296 Int_t AliRsnCutSet::TestExpression(TString opt)
299 // AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
300 // cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
301 // AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
302 // cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
303 // AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
304 // cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
306 // AliRsnCutSet* set = new AliRsnCutSet ("setOne");
307 // set->AddCut (cut1);
308 // set->AddCut (cut2);
309 // set->AddCut (cut3);
311 // set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
315 AliDebug(1, opt.Data());
319 //_____________________________________________________________________________
320 void AliRsnCutSet::PrintSetInfo()
323 // Show data about the cut set
328 AliInfo("========== Rsn Cut Set info ==============");
329 AliInfo(Form("Sheme : %s",fCutScheme.Data()));
330 AliInfo(Form("Sheme : %s",fCutSchemeIndexed.Data()));
331 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
332 AliInfo("====== Cuts ======");
334 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
335 cut = (AliRsnCut*) fCuts.At(i);
336 if (cut) AliInfo(Form("%d %d",i,fBoolValues[i]));
338 AliInfo("========== END Rsn Cut Mgr info ==============");
341 //_____________________________________________________________________________
342 TString AliRsnCutSet::GetCutSchemeIndexed()
345 // Internal method to retrieve the list of cuts with their indexes
346 // for evaluation of cut expression
349 AliDebug(AliLog::kDebug,"<-");
351 TString str(fCutScheme);
352 AliDebug(AliLog::kDebug,Form("Num of cuts %d",fCuts.GetEntriesFast()));
354 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
355 cut = (AliRsnCut*) fCuts.At(i);
356 str.ReplaceAll(cut->GetName(),Form("%d",i));
358 AliDebug(AliLog::kDebug,"->");