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