]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnCut.cxx
Corrections after survey of Coverity tests
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCut.cxx
CommitLineData
e2bafbbc 1//
06351446 2// Class AliRsnCut
3//
4// General implementation of a single cut strategy, which can be:
e2bafbbc 5// - a value contained in a given interval [--> IsBetween() ]
6// - a value equal to a given reference [--> MatchesValue()]
7//
06351446 8// In all cases, the reference value(s) is (are) given as data members
9// and each kind of cut requires a given value type (Int, UInt, Double),
10// but the cut check procedure is then automatized and chosen thanks to
11// an enumeration of the implemented cut types.
12// At the end, the user (or any other point which uses this object) has
13// to use the method IsSelected() to check if this cut has been passed.
14//
15// authors: Martin Vala (martin.vala@cern.ch)
16// Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
e2bafbbc 17//
06351446 18#include "AliLog.h"
19
2dab9030 20#include "AliRsnDaughter.h"
21#include "AliRsnMother.h"
22#include "AliRsnEvent.h"
23
5eb970a4 24#include "AliRsnCut.h"
06351446 25
aec0ec32 26ClassImp(AliRsnCut)
06351446 27
5eb970a4 28//_________________________________________________________________________________________________
2dab9030 29AliRsnCut::AliRsnCut(ETarget target) :
30 TNamed(),
31 fVarType(kInt),
32 fTarget(target),
33 fMinI(0),
34 fMaxI(0),
35 fMinD(0.0),
36 fMaxD(0.0),
37 fCutValueI(0),
38 fCutValueD(0.0),
39 fCutResult(kTRUE),
40 fEvent(0x0)
06351446 41{
42//
5eb970a4 43// Default constructor.
06351446 44//
45}
46
413bbf44 47//_________________________________________________________________________________________________
48AliRsnCut::AliRsnCut(const AliRsnCut& copy) :
2dab9030 49 TNamed(copy),
50 fVarType(copy.fVarType),
51 fTarget(copy.fTarget),
52 fMinI(copy.fMinI),
53 fMaxI(copy.fMaxI),
54 fMinD(copy.fMinD),
55 fMaxD(copy.fMaxD),
56 fCutValueI(copy.fCutValueI),
57 fCutValueD(copy.fCutValueD),
58 fCutResult(copy.fCutResult),
59 fEvent(copy.fEvent)
413bbf44 60{
61//
62// Copy constructor.
63//
64}
65
5eb970a4 66//_________________________________________________________________________________________________
67AliRsnCut::AliRsnCut
2dab9030 68(const char *name, ETarget target, Int_t min, Int_t max) :
69 TNamed(name, ""),
70 fVarType(kInt),
71 fTarget(target),
72 fMinI(min),
73 fMaxI(max),
74 fMinD(0.0),
75 fMaxD(0.0),
76 fCutValueI(0),
77 fCutValueD(0.0),
78 fCutResult(kTRUE),
79 fEvent(0x0)
06351446 80{
81//
2dab9030 82// Constructor with integer values.
5eb970a4 83// If the cut must check values inside a range,
84// both 'value' arguments must be used, and they are, in the order,
85// the minimum and maximum of the allowed range.
86// If the cut must check a value, the second 'value' argument will never be used.
06351446 87//
88}
89
5eb970a4 90//_________________________________________________________________________________________________
91AliRsnCut::AliRsnCut
2dab9030 92(const char *name, ETarget target, Double_t min, Double_t max) :
93 TNamed(name, ""),
94 fVarType(kDouble),
95 fTarget(target),
96 fMinI(0),
97 fMaxI(0),
98 fMinD(min),
99 fMaxD(max),
100 fCutValueI(0),
101 fCutValueD(0.0),
102 fCutResult(kTRUE),
103 fEvent(0x0)
06351446 104{
105//
2dab9030 106// Constructor with double values.
5eb970a4 107// If the cut must check values inside a range,
108// both 'value' arguments must be used, and they are, in the order,
109// the minimum and maximum of the allowed range.
110// If the cut must check a value, the second 'value' argument will never be used.
06351446 111//
112}
113
413bbf44 114//_________________________________________________________________________________________________
115AliRsnCut& AliRsnCut::operator=(const AliRsnCut& copy)
116{
117//
118// Assignment operator
119// don't duplicate memory occupancy for pointer
120//
121
122 fVarType = copy.fVarType;
2dab9030 123 fTarget = copy.fTarget;
413bbf44 124 fMinI = copy.fMinI;
125 fMaxI = copy.fMaxI;
126 fMinD = copy.fMinD;
127 fMaxD = copy.fMaxD;
413bbf44 128 fCutValueI = copy.fCutValueI;
129 fCutValueD = copy.fCutValueD;
413bbf44 130 fCutResult = copy.fCutResult;
131 fEvent = copy.fEvent;
132
133 return (*this);
134}
135
5eb970a4 136//_________________________________________________________________________________________________
2dab9030 137Bool_t AliRsnCut::TargetOK(TObject *obj1, TObject *obj2)
aec0ec32 138{
139//
2dab9030 140// This method checks if the expected target and the passed object match.
aec0ec32 141//
aec0ec32 142
2dab9030 143 if (!obj1)
144 {
145 AliError("Cannot cut on a NULL object!");
146 return kFALSE;
147 }
148
149 switch (fTarget)
150 {
151 case kDaughter:
152 if (dynamic_cast<AliRsnDaughter*>(obj1) == 0x0)
153 {
154 AliError(Form("[%s] Target mismatch (obj #1): expected 'AliRsnDaughter', passed '%s'", GetName(), obj1->ClassName()));
155 Print();
156 return kFALSE;
157 }
158 break;
159 case kMother:
160 if (dynamic_cast<AliRsnMother*>(obj1) == 0x0)
161 {
162 AliError(Form("[%s] Target mismatch (obj #1): expected 'AliRsnMother', passed '%s'", GetName(), obj1->ClassName()));
163 Print();
164 return kFALSE;
165 }
166 break;
167 case kEvent:
168 if (dynamic_cast<AliRsnEvent*>(obj1) == 0x0)
169 {
170 AliError(Form("[%s] Target mismatch (obj #1): expected 'AliRsnEvent', passed '%s'", GetName(), obj1->ClassName()));
171 Print();
172 return kFALSE;
173 }
174 break;
175 case kMixEvent:
176 if (dynamic_cast<AliRsnEvent*>(obj1) == 0x0)
177 {
178 AliError(Form("[%s] Target mismatch (obj #1): expected 'AliRsnEvent', passed '%s' an", GetName(), obj1->ClassName()));
179 Print();
180 return kFALSE;
181 }
182 if (obj2)
183 {
184 if (dynamic_cast<AliRsnEvent*>(obj2) == 0x0)
185 {
186 AliError(Form("[%s] Target mismatch (obj #2): expected 'AliRsnEvent', passed '%s' an", GetName(), obj2->ClassName()));
187 Print();
188 return kFALSE;
189 }
190 }
191 else
192 {
193 AliError("Mix-event cuts require 2 not NULL objects");
194 Print();
195 return kFALSE;
196 }
197 break;
198 default:
199 return kTRUE;
200 }
201
5eb970a4 202 return kTRUE;
06351446 203}
204
5eb970a4 205//_________________________________________________________________________________________________
2dab9030 206Bool_t AliRsnCut::IsSelected(TObject* /*obj1*/, TObject* /*obj2*/)
06351446 207{
208//
2dab9030 209// Virtual cut-checking method for event mixing.
210// This method checks only that the target is the oner for mixing.
06351446 211//
06351446 212
2dab9030 213 AliWarning("Single-object cuts are not implemented here.");
5eb970a4 214 return kTRUE;
06351446 215}
216
5eb970a4 217//_________________________________________________________________________________________________
2dab9030 218Bool_t AliRsnCut::OkValue()
06351446 219{
220//
2dab9030 221// This method is used when the cut consists in comparing the cut value
222// with a reference value to which it must be equal (in case of doubles, 'almost' equal).
223// Then, the cut result is kTRUE if the cut value is equal to this reference value.
06351446 224//
06351446 225
2dab9030 226 switch (fVarType)
227 {
228 case kInt:
229 return OkValueI();
230 case kDouble:
231 return OkValueD();
232 default:
233 AliError(Form("fVarType = %d --> not allowed", fVarType));
234 return kFALSE;
235 }
06351446 236}
237
5eb970a4 238//_________________________________________________________________________________________________
2dab9030 239Bool_t AliRsnCut::OkRange()
06351446 240{
241//
2dab9030 242// This method is used when the cut consists in an allowed range
243// where the cut value must be included to pass the cut.
244// Then, the cut result is kTRUE if the cut value is inside this range.
06351446 245//
aec0ec32 246
2dab9030 247 switch (fVarType)
248 {
249 case kInt:
250 return OkRangeI();
251 case kDouble:
252 return OkRangeD();
253 default:
254 AliError(Form("fVarType = %d --> not allowed", fVarType));
255 return kFALSE;
256 }
06351446 257}
258
5eb970a4 259//_________________________________________________________________________________________________
2dab9030 260Bool_t AliRsnCut::OkValueI()
06351446 261{
262//
5eb970a4 263// This method is used when the cut consists in comparing the cut value
2dab9030 264// with a reference integer value to which it must be equal.
06351446 265//
aec0ec32 266
2dab9030 267 // eval result
268 fCutResult = (fCutValueI == fMinI);
269
270 // print debug message
2e521c29 271 AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ====================================");
272 AliDebug(AliLog::kDebug + 2, Form("Cut name : %s", GetName()));
273 AliDebug(AliLog::kDebug + 2, Form("Checked value: %d", fCutValueI));
274 AliDebug(AliLog::kDebug + 2, Form("Cut value : %d", fMinI));
275 AliDebug(AliLog::kDebug + 2, Form("Cut result : %s", (fCutResult ? "PASSED" : "NOT PASSED")));
276 AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ================================");
2dab9030 277
278 return fCutResult;
279}
aec0ec32 280
2dab9030 281//_________________________________________________________________________________________________
282Bool_t AliRsnCut::OkValueD()
283{
284//
285// This method is used when the cut consists in comparing the cut value
286// with a reference double value to which it must be equal (or at least, almost).
287//
288
289 // eval result
290 fCutResult = (TMath::Abs(fCutValueD - fMinD) < 1E-6);
291
292 // print debug message
2e521c29 293 AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ====================================");
294 AliDebug(AliLog::kDebug + 2, Form("Cut name : %s", GetName()));
295 AliDebug(AliLog::kDebug + 2, Form("Checked value: %f", fCutValueD));
296 AliDebug(AliLog::kDebug + 2, Form("Cut value : %f", fMinD));
297 AliDebug(AliLog::kDebug + 2, Form("Cut result : %s", (fCutResult ? "PASSED" : "NOT PASSED")));
298 AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ================================");
2dab9030 299
5eb970a4 300 return fCutResult;
06351446 301}
302
5eb970a4 303//_________________________________________________________________________________________________
2dab9030 304Bool_t AliRsnCut::OkRangeI()
e0baff8c 305{
5eb970a4 306//
307// This method is used when the cut consists in an allowed range
308// where the cut value must be included to pass the cut.
309// Then, the cut result is kTRUE if the cut value is inside this range.
310//
e0baff8c 311
2dab9030 312 // eval result
313 fCutResult = ((fCutValueI >= fMinI) && (fCutValueI <= fMaxI));
314
315 // print debug message
2e521c29 316 AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ====================================");
2dab9030 317 AliDebug(AliLog::kDebug + 2, Form("Cut name : %s", GetName()));
318 AliDebug(AliLog::kDebug + 2, Form("Checked value: %d", fCutValueI));
319 AliDebug(AliLog::kDebug + 2, Form("Cut range : %d , %d", fMinI, fMaxI));
320 AliDebug(AliLog::kDebug + 2, Form("Cut result : %s", (fCutResult ? "PASSED" : "NOT PASSED")));
2e521c29 321 AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ================================");
2dab9030 322
323 return fCutResult;
324}
325
326//_________________________________________________________________________________________________
327Bool_t AliRsnCut::OkRangeD()
328{
329//
330// This method is used when the cut consists in an allowed range
331// where the cut value must be included to pass the cut.
332// Then, the cut result is kTRUE if the cut value is inside this range.
333//
334
335 // eval result
336 fCutResult = ((fCutValueD >= fMinD) && (fCutValueD <= fMaxD));
337
338 // print debug message
2e521c29 339 AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ====================================");
2dab9030 340 AliDebug(AliLog::kDebug + 2, Form("Cut name : %s", GetName()));
341 AliDebug(AliLog::kDebug + 2, Form("Checked value: %f", fCutValueD));
342 AliDebug(AliLog::kDebug + 2, Form("Cut range : %f , %f", fMinD, fMaxD));
343 AliDebug(AliLog::kDebug + 2, Form("Cut result : %s", (fCutResult ? "PASSED" : "NOT PASSED")));
2e521c29 344 AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ================================");
e0baff8c 345
5eb970a4 346 return fCutResult;
e0baff8c 347}
348
2dab9030 349//_________________________________________________________________________________________________
350void AliRsnCut::Print(Option_t*) const
351{
352//
353// Override TObject::Print() method
354//
355
356 Char_t target[100];
357 switch (fTarget)
358 {
96e9d35d 359 case kDaughter: snprintf(target, strlen("DAUGHTER") , "DAUGHTER") ; break;
360 case kMother : snprintf(target, strlen("MOTHER") , "MOTHER") ; break;
361 case kEvent : snprintf(target, strlen("EVENT") , "EVENT") ; break;
362 case kMixEvent: snprintf(target, strlen("MIX EVENT"), "MIX EVENT"); break;
363 default : snprintf(target, strlen("UNDEFINED"), "UNDEFINED"); break;
2dab9030 364 }
365
366 AliInfo("=== CUT DETAILS ====================================");
367 AliInfo(Form("Cut name : [%s]", GetName()));
368 AliInfo(Form("Cut target : [%s]", target));
369 AliInfo(Form("Cut edges [D]: [%f - %f]", fMinD, fMaxD));
370 AliInfo(Form("Cut edges [I]: [%d - %d]", fMinI, fMaxI));
371 AliInfo("====================================================");
372}
373
374//_________________________________________________________________________________________________
375void AliRsnCut::SetEvent(AliRsnEvent *event)
376{
377//
378// Sets the reference event
379//
380
381 fEvent = event;
382}