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