]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnCutSet.cxx
Splitted the PID cuts into three classes for ITS, TPC and TOF, and added the possibil...
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutSet.cxx
CommitLineData
e0baff8c 1//
2// Class AliRsnCutSet
3//
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.
8//
9
06351446 10#include "AliLog.h"
11
06351446 12#include "AliRsnExpression.h"
13
14#include "AliRsnCutSet.h"
15
aec0ec32 16ClassImp(AliRsnCutSet)
e2bafbbc 17
18//_____________________________________________________________________________
32992791 19AliRsnCutSet::AliRsnCutSet() :
20 AliRsnTarget(),
2dab9030 21 fCuts(0),
22 fNumOfCuts(0),
23 fCutScheme(""),
24 fCutSchemeIndexed(""),
25 fBoolValues(0),
26 fIsScheme(kFALSE),
27 fExpression(0)
06351446 28{
e2bafbbc 29//
30// Constructor without name (not recommended)
31//
32
aec0ec32 33 fBoolValues = new Bool_t[1];
4fbb2459 34 AliRsnExpression::fgCutSet = this;
06351446 35}
36
e2bafbbc 37//_____________________________________________________________________________
32992791 38AliRsnCutSet::AliRsnCutSet(const char *name, RSNTARGET target) :
39 AliRsnTarget(name, target),
2dab9030 40 fCuts(0),
41 fNumOfCuts(0),
42 fCutScheme(""),
43 fCutSchemeIndexed(""),
44 fBoolValues(0),
45 fIsScheme(kFALSE),
46 fExpression(0)
06351446 47{
e2bafbbc 48//
49// Constructor with argument name (recommended)
50//
51
aec0ec32 52 fBoolValues = new Bool_t[1];
53 fExpression = 0;
4fbb2459 54 AliRsnExpression::fgCutSet = this;
06351446 55}
56
e2bafbbc 57//_____________________________________________________________________________
aec0ec32 58AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
32992791 59 AliRsnTarget(copy),
2dab9030 60 fCuts(copy.fCuts),
61 fNumOfCuts(copy.fNumOfCuts),
62 fCutScheme(copy.fCutScheme),
63 fCutSchemeIndexed(copy.fCutSchemeIndexed),
64 fBoolValues(0),
65 fIsScheme(copy.fIsScheme),
66 fExpression(copy.fExpression)
06351446 67{
e2bafbbc 68//
69// Copy constructor
70//
71
32992791 72 Int_t i;
73 fBoolValues = new Bool_t[fNumOfCuts];
74 for (i = 0; i < fNumOfCuts; ++i)
75 {
76 fBoolValues[i] = copy.fBoolValues[i];
77 }
78
79 AliRsnExpression::fgCutSet = this;
80}
81
82//_____________________________________________________________________________
83AliRsnCutSet& AliRsnCutSet::operator=(const AliRsnCutSet & copy)
84{
85//
86// Assignment operator.
87//
88
89 AliRsnTarget::operator=(copy);
90
91 fCuts = copy.fCuts;
92 fNumOfCuts = copy.fNumOfCuts;
93 fCutScheme = copy.fCutScheme;
94 fCutSchemeIndexed = copy.fCutSchemeIndexed;
95 fIsScheme = copy.fIsScheme;
96 fExpression = copy.fExpression;
97
98 if (fBoolValues) delete [] fBoolValues;
99
100 Int_t i;
101 fBoolValues = new Bool_t[fNumOfCuts];
102 for (i = 0; i < fNumOfCuts; ++i)
103 {
104 fBoolValues[i] = copy.fBoolValues[i];
105 }
106
4fbb2459 107 AliRsnExpression::fgCutSet = this;
32992791 108
109 return (*this);
06351446 110}
111
e2bafbbc 112//_____________________________________________________________________________
06351446 113AliRsnCutSet::~AliRsnCutSet()
114{
e2bafbbc 115//
116// Destructor
117//
118
aec0ec32 119 delete fExpression;
120 delete [] fBoolValues;
06351446 121}
122
e2bafbbc 123//_____________________________________________________________________________
aec0ec32 124void AliRsnCutSet::AddCut(AliRsnCut *cut)
06351446 125{
e2bafbbc 126//
127// Add a new cut.
2dab9030 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.
e2bafbbc 131//
06351446 132
32992791 133 if (!cut->IsTarget(GetTargetType()))
2dab9030 134 {
32992791 135 AliError(Form("Cannot add this cut (cut set name,target = [%s],[%s] --- cut name,target = [%s],[%s]", GetName(), GetTargetTypeName(), cut->GetName(), cut->GetTargetTypeName()));
2dab9030 136 return;
137 }
138
aec0ec32 139 Int_t i;
140
141 AliDebug(AliLog::kDebug,"<-");
142 fCuts.Add(cut);
aa24e021 143 AliInfo(Form("====> Adding a new cut: [%s]", cut->GetName()));
144 cut->Print();
aec0ec32 145 fNumOfCuts++;
146
413bbf44 147 if (fBoolValues) delete [] fBoolValues;
aec0ec32 148
149 fBoolValues = new Bool_t[fNumOfCuts];
2dab9030 150 for (i = 0; i < fNumOfCuts; i++)
151 {
aec0ec32 152 fBoolValues[i] = kTRUE;
153 }
154
155 AliDebug(AliLog::kDebug,Form("%d",fCuts.GetEntriesFast()));
156 AliDebug(AliLog::kDebug,"->");
06351446 157}
158
e2bafbbc 159//_____________________________________________________________________________
4fbb2459 160void AliRsnCutSet::ShowCuts() const
06351446 161{
e2bafbbc 162//
163// Prints all cuts
164//
aec0ec32 165 AliRsnCut *cut;
2dab9030 166
167 for (Int_t i = 0; i < fCuts.GetEntriesFast() ;i++)
168 {
169 cut = (AliRsnCut*)fCuts.At (i);
170 cut->Print();
aec0ec32 171 }
06351446 172}
173
e2bafbbc 174//_____________________________________________________________________________
32992791 175Bool_t AliRsnCutSet::IsSelected(TObject *object)
06351446 176{
e2bafbbc 177//
178// Checks an object according to the cut expression defined here.
179//
06351446 180
aec0ec32 181 Int_t i;
2dab9030 182
aec0ec32 183 if (!fNumOfCuts) return kTRUE;
184
185 Bool_t boolReturn = kTRUE;
186 AliRsnCut *cut;
4fbb2459 187 for (i = 0; i < fNumOfCuts; i++) {
2dab9030 188 cut = (AliRsnCut*)fCuts.At(i);
32992791 189 fBoolValues[i] = cut->IsSelected(object);
e0baff8c 190 }
191
192 if (fIsScheme) boolReturn = Passed();
193 return boolReturn;
194}
195
e2bafbbc 196//_____________________________________________________________________________
5faf5a07 197void AliRsnCutSet::SetCutScheme(const char *theValue)
06351446 198{
e2bafbbc 199//
200// Define the combination of cuts with logical operators
201// and using the names given to all defined cuts.
202//
06351446 203
aec0ec32 204 AliDebug(AliLog::kDebug,"<-");
cf4668f7 205
aec0ec32 206 fCutScheme = theValue;
207 SetCutSchemeIndexed(theValue);
208 fIsScheme = kTRUE;
209 AliDebug(AliLog::kDebug,"->");
e2bafbbc 210}
06351446 211
e2bafbbc 212//_____________________________________________________________________________
aec0ec32 213void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
06351446 214{
e2bafbbc 215//
216// Internal method which indexes all cuts to organize their combo
217//
218
aec0ec32 219 AliDebug(AliLog::kDebug,"<-");
220 theValue.Append(" ");
221 // fCutSchemeIndexed = theValue;
222 fCutSchemeIndexed = GetCutSchemeIndexed();
223 AliDebug(AliLog::kDebug,"->");
06351446 224}
225
e2bafbbc 226//_____________________________________________________________________________
aec0ec32 227Int_t AliRsnCutSet::GetIndexByCutName(TString s)
06351446 228{
e2bafbbc 229//
230// Retrieve the cut index from its name
231//
06351446 232
aec0ec32 233 Int_t i;
234 AliRsnCut *cut;
235
4fbb2459 236 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
aec0ec32 237 cut = (AliRsnCut*) fCuts.At(i);
238 if (!s.CompareTo(cut->GetName())) return i;
239 }
240
241 return -1;
06351446 242}
243
e2bafbbc 244//_____________________________________________________________________________
06351446 245Bool_t AliRsnCutSet::Passed()
246{
e2bafbbc 247//
248// Combines the cuts according to expression
249// and gives a global response to the cut check
250//
251
4fbb2459 252 AliRsnExpression::fgCutSet = this;
32992791 253 if (!fExpression)
254 {
aec0ec32 255 fExpression = new AliRsnExpression(fCutSchemeIndexed);
256 AliDebug(AliLog::kDebug,"fExpression was created.");
257 }
258
32992791 259 if (fCuts.IsEmpty()) return kTRUE;
260
aec0ec32 261 return fExpression->Value(*GetCuts());
06351446 262}
263
e2bafbbc 264//_____________________________________________________________________________
06351446 265Bool_t AliRsnCutSet::IsValidScheme()
266{
e2bafbbc 267//
268// Validity check on cut expression specified by user
269//
270
cf4668f7 271 TString str(fCutScheme);
272 AliRsnCut *cut;
273 for (Int_t i = 0; i < fNumOfCuts; i++) {
274 cut = (AliRsnCut*)fCuts.At(i);
275 str.ReplaceAll(cut->GetName(),"");
276 }
277 str.ReplaceAll("&","");
278 str.ReplaceAll("!","");
279 str.ReplaceAll("|","");
280 str.ReplaceAll("(","");
281 str.ReplaceAll(")","");
282
283 if (!str.IsNull()) {
284 AliError(Form("Cut scheme '%s' is not valid !!!",fCutScheme.Data()));
285 return kFALSE;
286 }
287
288 return kTRUE;
289// return (!(ShowCutScheme().Contains("Error")));
06351446 290}
291
e2bafbbc 292//_____________________________________________________________________________
06351446 293TString AliRsnCutSet::ShowCutScheme()
294{
e2bafbbc 295//
296// Utility method to check validity of expression
297//
cf4668f7 298
299 return fCutScheme;
300// return fExpression->Unparse();
06351446 301}
302
e2bafbbc 303//_____________________________________________________________________________
aec0ec32 304Int_t AliRsnCutSet::TestExpression(TString opt)
06351446 305{
e2bafbbc 306
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);
06351446 313//
e2bafbbc 314// AliRsnCutSet* set = new AliRsnCutSet ("setOne");
315// set->AddCut (cut1);
316// set->AddCut (cut2);
317// set->AddCut (cut3);
06351446 318//
e2bafbbc 319// set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
06351446 320//
321// set->ShowCuts ();
322
aec0ec32 323 AliDebug(1, opt.Data());
324 return 0;
06351446 325}
326
e2bafbbc 327//_____________________________________________________________________________
06351446 328void AliRsnCutSet::PrintSetInfo()
329{
e2bafbbc 330//
331// Show data about the cut set
332//
06351446 333
aec0ec32 334 Int_t i;
335
336 AliInfo("========== Rsn Cut Set info ==============");
413bbf44 337 AliInfo(Form("Scheme : %s",fCutScheme.Data()));
338 AliInfo(Form("Scheme : %s",fCutSchemeIndexed.Data()));
aec0ec32 339 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
340 AliInfo("====== Cuts ======");
341 AliRsnCut *cut;
4fbb2459 342 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
aec0ec32 343 cut = (AliRsnCut*) fCuts.At(i);
344 if (cut) AliInfo(Form("%d %d",i,fBoolValues[i]));
345 }
346 AliInfo("========== END Rsn Cut Mgr info ==============");
06351446 347}
348
e2bafbbc 349//_____________________________________________________________________________
06351446 350TString AliRsnCutSet::GetCutSchemeIndexed()
351{
e2bafbbc 352//
353// Internal method to retrieve the list of cuts with their indexes
354// for evaluation of cut expression
355//
06351446 356
aec0ec32 357 AliDebug(AliLog::kDebug,"<-");
358 Int_t i;
359 TString str(fCutScheme);
360 AliDebug(AliLog::kDebug,Form("Num of cuts %d",fCuts.GetEntriesFast()));
361 AliRsnCut *cut;
4fbb2459 362 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
aec0ec32 363 cut = (AliRsnCut*) fCuts.At(i);
364 str.ReplaceAll(cut->GetName(),Form("%d",i));
365 }
366 AliDebug(AliLog::kDebug,"->");
367 return str;
e2bafbbc 368}