]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/AliRsnCut.cxx
Fix for coverity 24399, 24400, 24401
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / AliRsnCut.cxx
1 //
2 // *** Class AliRsnCut ***
3 //
4 // Cut base class: all other cuts inherit from it.
5 // The 'core' of the class is the method "IsSelected()" which
6 // must be overloaded by any specific cut implementation.
7 //
8 // This class provides some default instruments to check values
9 // agains a reference or an allowed range, in order to permit
10 // a unique way to execute such kind of checks.
11 //
12 // authors: Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
13 //          Martin Vala (martin.vala@cern.ch)
14 //
15
16 #include <TFormula.h>
17 #include "AliRsnCut.h"
18
19 ClassImp(AliRsnCut)
20
21 //______________________________________________________________________________
22 AliRsnCut::AliRsnCut(const char *name, RSNTARGET target) :
23    AliRsnTarget(name, target),
24    fMinI(0),
25    fMaxI(0),
26    fMinD(0.),
27    fMaxD(0.),
28    fMinIptdep(0),
29    fMaxIptdep(0),
30    fMinDptdep(0),
31    fMaxDptdep(0),
32    fCutValueI(0),
33    fCutValueD(0.0),
34    fPtDepCut(kFALSE),
35    fRefPtValueD(0.0),
36    fMaxPt(1E20),
37    fMinPt(0.0),
38    fPtDepCutMaxFormula(""),
39    fPtDepCutMinFormula(""),
40    fCutResult(kTRUE)
41 {
42 //
43 // Default constructor.
44 //
45 }
46
47 //______________________________________________________________________________
48 AliRsnCut::AliRsnCut
49 (const char *name, RSNTARGET target, Int_t imin, Int_t imax, Double_t dmin, Double_t dmax) :
50    AliRsnTarget(name, target),
51    fMinI(imin),
52    fMaxI(imax),
53    fMinD(dmin),
54    fMaxD(dmax),
55    fMinIptdep(0),
56    fMaxIptdep(0),
57    fMinDptdep(0),
58    fMaxDptdep(0),
59    fCutValueI(0),
60    fCutValueD(0.0),
61    fPtDepCut(kFALSE),
62    fRefPtValueD(0.0),
63    fMaxPt(1E20),
64    fMinPt(0.0),
65    fPtDepCutMaxFormula(""),
66    fPtDepCutMinFormula(""),
67    fCutResult(kTRUE)
68 {
69 //
70 // Constructor with arguments.
71 // This is provided to allow a quick setting of all data members.
72 //
73 }
74
75 //______________________________________________________________________________
76 AliRsnCut::AliRsnCut
77 (const char *name, RSNTARGET target, Double_t dmin, Double_t dmax, Int_t imin, Int_t imax) :
78    AliRsnTarget(name, target),
79    fMinI(imin),
80    fMaxI(imax),
81    fMinD(dmin),
82    fMaxD(dmax),
83    fMinIptdep(0),
84    fMaxIptdep(0),
85    fMinDptdep(0),
86    fMaxDptdep(0),
87    fCutValueI(0),
88    fCutValueD(0.0),
89    fPtDepCut(kFALSE),
90    fRefPtValueD(0.0),
91    fMaxPt(1E20),
92    fMinPt(0.0),
93    fPtDepCutMaxFormula(""),
94    fPtDepCutMinFormula(""),
95    fCutResult(kTRUE)
96 {
97 //
98 // Constructor with arguments.
99 // This is provided to allow a quick setting of all data members.
100 //
101 }
102
103 //______________________________________________________________________________
104 AliRsnCut::AliRsnCut(const AliRsnCut &copy) :
105    AliRsnTarget(copy),
106    fMinI(copy.fMinI),
107    fMaxI(copy.fMaxI),
108    fMinD(copy.fMinD),
109    fMaxD(copy.fMaxD),
110    fMinIptdep(copy.fMinIptdep),
111    fMaxIptdep(copy.fMaxIptdep),
112    fMinDptdep(copy.fMinDptdep),
113    fMaxDptdep(copy.fMaxDptdep),
114    fCutValueI(copy.fCutValueI),
115    fCutValueD(copy.fCutValueD),
116    fPtDepCut(copy.fPtDepCut),
117    fRefPtValueD(copy.fRefPtValueD),
118    fMaxPt(copy.fMaxPt),
119    fMinPt(copy.fMinPt),
120    fPtDepCutMaxFormula(copy.fPtDepCutMaxFormula),
121    fPtDepCutMinFormula(copy.fPtDepCutMinFormula),
122    fCutResult(copy.fCutResult)
123 {
124 //
125 // Copy constructor.
126 // Don't duplicate memory occupancy for pointer
127 //
128 }
129
130 //______________________________________________________________________________
131 AliRsnCut &AliRsnCut::operator=(const AliRsnCut &copy)
132 {
133 //
134 // Assignment operator.
135 // Don't duplicate memory occupancy for pointer
136 //
137
138    AliRsnTarget::operator=(copy);
139    if (this == &copy)
140       return *this;
141
142    fMinI      = copy.fMinI;
143    fMaxI      = copy.fMaxI;
144    fMinD      = copy.fMinD;
145    fMaxD      = copy.fMaxD;
146    fMinIptdep = copy.fMinIptdep;
147    fMaxIptdep = copy.fMaxIptdep;
148    fMinDptdep = copy.fMinDptdep;
149    fMaxDptdep = copy.fMaxDptdep;
150    fCutValueI = copy.fCutValueI;
151    fCutValueD = copy.fCutValueD;
152    fPtDepCut = copy.fPtDepCut;
153    fRefPtValueD = copy.fRefPtValueD;
154    fMaxPt = copy.fMaxPt;
155    fMinPt = copy.fMinPt;
156    fPtDepCutMaxFormula = copy.fPtDepCutMaxFormula;
157    fPtDepCutMinFormula = copy.fPtDepCutMinFormula;
158    fCutResult = copy.fCutResult;
159
160    return (*this);
161 }
162
163 //______________________________________________________________________________
164 Bool_t AliRsnCut::IsSelected(TObject * /*object*/)
165 {
166 //
167 // Virtual cut-checking method.
168 // In this implementation, it does nothing, and all classes
169 // inheriting from this, should provide a proper implementation
170 // which must return kTRUE if the cut is passed, and kFALSE otherwise.
171 //
172
173    AliWarning("This virtual function must be implemented properly");
174    return kTRUE;
175 }
176
177 //______________________________________________________________________________
178 Bool_t AliRsnCut::OkValueI()
179 {
180 //
181 // This method is used to compare a value with a reference.
182 // In the case of integers, the equality must be exact.
183 //
184
185    // eval result
186    
187    if (fPtDepCut){
188         if(fRefPtValueD > fMaxPt) {
189         AliDebug(2,Form("pt = %f (> %f), cutting at %d\n",fRefPtValueD, fMaxPt, fMinI)); 
190         fCutResult = (fCutValueI == fMinI);
191         } else if (fRefPtValueD < fMinPt){
192         AliDebug(2,Form("pt = %f (< %f), cutting at %d\n",fRefPtValueD, fMinPt, fMinI));
193         fCutResult = (fCutValueI == fMinI);
194         }else{ 
195         TString str(fPtDepCutMinFormula);
196         str.ReplaceAll("pt", "x");
197         TFormula ptdepcut(Form("%s_ptdepcut", GetName()), str.Data());
198         fMinIptdep = static_cast<int> (ptdepcut.Eval(fRefPtValueD));    
199         AliDebug(2,Form("pt = %f (> %f and < %f), cutting  at %d\n",fRefPtValueD, fMinPt, fMaxPt, fMinIptdep)); 
200         fCutResult = (fCutValueI == fMinIptdep);
201         }
202   }
203   else fCutResult = (fCutValueI == fMinI);
204
205    // print debug message
206    AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ========================================================");
207    AliDebug(AliLog::kDebug + 2, Form("Cut name     : %s", GetName()));
208    AliDebug(AliLog::kDebug + 2, Form("Checked value: %d", fCutValueI));
209    AliDebug(AliLog::kDebug + 2, Form("Cut value    : %d", fMinI));
210    AliDebug(AliLog::kDebug + 2, Form("Cut result   : %s", (fCutResult ? "PASSED" : "NOT PASSED")));
211    AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ====================================================");
212
213    return fCutResult;
214 }
215
216 //______________________________________________________________________________
217 Bool_t AliRsnCut::OkValueD()
218 {
219 //
220 // This method is used to compare a value with a reference.
221 // In the case of doubles, the equality consists in being very close.
222 //
223
224    // eval result
225    
226     if (fPtDepCut){
227         if(fRefPtValueD > fMaxPt) {
228         AliDebug(2,Form("pt = %f (> %f), cutting at %f\n",fRefPtValueD, fMaxPt, fMinD)); 
229         fCutResult = (TMath::Abs(fCutValueD - fMinD) < 1E-6);
230         } else if (fRefPtValueD < fMinPt){
231         AliDebug(2,Form("pt = %f (< %f), cutting at %f\n",fRefPtValueD, fMinPt, fMinD));
232         fCutResult = (TMath::Abs(fCutValueD - fMinD) < 1E-6);
233         }else{
234         TString str(fPtDepCutMinFormula);
235         str.ReplaceAll("pt", "x");
236         TFormula ptdepcut(Form("%s_ptdepcut", GetName()), str.Data());
237         fMinDptdep = ptdepcut.Eval(fRefPtValueD);       
238         AliDebug(2,Form("pt = %f (> %f and < %f), cutting  at %f\n",fRefPtValueD, fMinPt, fMaxPt, fMinDptdep)); 
239         fCutResult = (TMath::Abs(fCutValueD - fMinDptdep) < 1E-6);
240         }
241   }
242   else fCutResult = (TMath::Abs(fCutValueD - fMinD) < 1E-6);
243
244    // print debug message
245    AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG =======================================================");
246    AliDebug(AliLog::kDebug + 2, Form("Cut name     : %s", GetName()));
247    AliDebug(AliLog::kDebug + 2, Form("Checked value: %f", fCutValueD));
248    AliDebug(AliLog::kDebug + 2, Form("Cut value    : %f", fMinD));
249    AliDebug(AliLog::kDebug + 2, Form("Cut result   : %s", (fCutResult ? "PASSED" : "NOT PASSED")));
250    AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ===================================================");
251
252    return fCutResult;
253 }
254
255 //______________________________________________________________________________
256 Bool_t AliRsnCut::OkRangeI()
257 {
258 //
259 // This method is used to compare a value with an integer range.
260 //
261
262   // eval result
263   if (fPtDepCut){
264     if(fRefPtValueD > fMaxPt) {
265       AliDebug(2,Form("pt = %f (> %f), cutting between [%d, %d]\n",fRefPtValueD, fMaxPt, fMinI, fMaxI)); 
266       fCutResult = ((fCutValueI >= fMinI) && (fCutValueD <= fMaxI));
267     } else if (fRefPtValueD < fMinPt){
268       AliDebug(2,Form("pt = %f (< %f), cutting between [%d, %d]\n",fRefPtValueD, fMinPt, fMinI, fMaxI));
269       fCutResult = ((fCutValueI >= fMinI) && (fCutValueD <= fMaxI));
270     } else {
271       TString str(fPtDepCutMinFormula);
272       str.ReplaceAll("pt", "x");
273       TFormula ptdepcut(Form("%s_ptdepcut", GetName()), str.Data());
274       fMinIptdep = static_cast<int> (ptdepcut.Eval(fRefPtValueD));
275         
276       TString str2(fPtDepCutMaxFormula);
277       str2.ReplaceAll("pt", "x");
278       TFormula ptdepcut2(Form("%s_ptdepcut", GetName()), str2.Data());
279       fMaxIptdep = static_cast<int> (ptdepcut2.Eval(fRefPtValueD));
280                     
281       AliDebug(2,Form("pt = %f (> %f and < %f), cutting  according to the fiducial zone [%d, %d]\n",fRefPtValueD, fMinPt, fMaxPt, fMinIptdep, fMaxIptdep)); 
282       fCutResult = ((fCutValueI >= fMinIptdep) && (fCutValueI <= fMaxIptdep));
283     }
284   }
285   else fCutResult = ((fCutValueI >= fMinI) && (fCutValueI <= fMaxI));
286
287    // print debug message
288    AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ========================================================");
289    AliDebug(AliLog::kDebug + 2, Form("Cut name     : %s", GetName()));
290    AliDebug(AliLog::kDebug + 2, Form("Checked value: %d", fCutValueI));
291    AliDebug(AliLog::kDebug + 2, Form("Cut range    : %d , %d", fMinI, fMaxI));
292    AliDebug(AliLog::kDebug + 2, Form("Cut result   : %s", (fCutResult ? "PASSED" : "NOT PASSED")));
293    AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ====================================================");
294
295    return fCutResult;
296 }
297
298 //______________________________________________________________________________
299 Bool_t AliRsnCut::OkRangeD()
300 {
301 //
302 // This method is used to compare a value with a double-float range.
303 //
304
305   // eval result
306    
307   if (fPtDepCut){
308     if(fRefPtValueD > fMaxPt) {
309       AliDebug(2,Form("pt = %f (> %f), cutting between [%f, %f]\n",fRefPtValueD, fMaxPt, fMinD, fMaxD)); 
310       fCutResult = ((fCutValueD >= fMinD) && (fCutValueD <= fMaxD));
311     } else if (fRefPtValueD < fMinPt) {
312       AliDebug(2,Form("pt = %f (< %f), cutting between [%f, %f]\n",fRefPtValueD, fMinPt, fMinD, fMaxD));
313       fCutResult = ((fCutValueD >= fMinD) && (fCutValueD <= fMaxD));
314     } else {
315       TString str(fPtDepCutMinFormula);
316       str.ReplaceAll("pt", "x");
317       TFormula ptdepcut(Form("%s_ptdepcut", GetName()), str.Data());
318       fMinDptdep = ptdepcut.Eval(fRefPtValueD);
319       
320       TString str2(fPtDepCutMaxFormula);
321       str2.ReplaceAll("pt", "x");
322       TFormula ptdepcut2(Form("%s_ptdepcut", GetName()), str2.Data());
323       fMaxDptdep = ptdepcut2.Eval(fRefPtValueD);   
324       
325       AliDebug(2,Form("pt = %f (> %f and < %f), cutting  according to the fiducial zone [%f, %f]\n",fRefPtValueD, fMinPt, fMaxPt, fMinDptdep, fMaxDptdep)); 
326       fCutResult = ((fCutValueD >= fMinDptdep) && (fCutValueD <= fMaxDptdep));
327     }
328   }
329   else fCutResult = ((fCutValueD >= fMinD) && (fCutValueD <= fMaxD));
330
331    // print debug message
332    AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ========================================================");
333    AliDebug(AliLog::kDebug + 2, Form("Cut name     : %s", GetName()));
334    AliDebug(AliLog::kDebug + 2, Form("Checked value: %f", fCutValueD));
335    AliDebug(AliLog::kDebug + 2, Form("Cut range    : %f , %f", fMinD, fMaxD));
336    AliDebug(AliLog::kDebug + 2, Form("Cut result   : %s", (fCutResult ? "PASSED" : "NOT PASSED")));
337    AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ====================================================");
338
339    return fCutResult;
340 }
341
342
343 //______________________________________________________________________________
344 void AliRsnCut::Print(Option_t *) const
345 {
346 //
347 // Override TObject::Print() method,
348 // and print some useful info about the cut general parameters.
349 //
350
351    AliInfo("=== CUT DETAILS ====================================");
352    AliInfo(Form("Cut name     : [%s]", GetName()));
353    AliInfo(Form("Cut target   : [%s]", GetTargetTypeName()));
354    AliInfo(Form("Cut edges [D]: [%f - %f]", fMinD, fMaxD));
355    AliInfo(Form("Cut edges [I]: [%d - %d]", fMinI, fMaxI));
356    AliInfo(Form("Cut pt dependent: %s", (fPtDepCut ? "YES" : "NO")));
357    AliInfo("====================================================");
358 }