]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCut.cxx
b8f92541c852b01d1b9d8be45ea6e6aa9852cb9f
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCut.cxx
1 //
2 // Class AliRsnCut
3 //
4 // General implementation of a single cut strategy, which can be:
5 // - a value contained in a given interval  [--> IsBetween()   ]
6 // - a value equal to a given reference     [--> MatchesValue()]
7 //
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)
17 //
18 #include "AliLog.h"
19
20 #include "AliRsnDaughter.h"
21 #include "AliRsnMother.h"
22 #include "AliRsnEvent.h"
23
24 #include "AliRsnCut.h"
25
26 ClassImp(AliRsnCut)
27
28 //_________________________________________________________________________________________________
29 AliRsnCut::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)
41 {
42 //
43 // Default constructor.
44 //
45 }
46
47 //_________________________________________________________________________________________________
48 AliRsnCut::AliRsnCut(const AliRsnCut& copy) :
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)
60 {
61 //
62 // Copy constructor.
63 //
64 }
65
66 //_________________________________________________________________________________________________
67 AliRsnCut::AliRsnCut
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)
80 {
81 //
82 // Constructor with integer values.
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.
87 //
88 }
89
90 //_________________________________________________________________________________________________
91 AliRsnCut::AliRsnCut
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)
104 {
105 //
106 // Constructor with double values.
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.
111 //
112 }
113
114 //_________________________________________________________________________________________________
115 AliRsnCut& AliRsnCut::operator=(const AliRsnCut& copy)
116 {
117 //
118 // Assignment operator
119 // don't duplicate memory occupancy for pointer
120 //
121
122   fVarType   = copy.fVarType;
123   fTarget    = copy.fTarget;
124   fMinI      = copy.fMinI;
125   fMaxI      = copy.fMaxI;
126   fMinD      = copy.fMinD;
127   fMaxD      = copy.fMaxD;
128   fCutValueI = copy.fCutValueI;
129   fCutValueD = copy.fCutValueD;
130   fCutResult = copy.fCutResult;
131   fEvent     = copy.fEvent;
132
133   return (*this);
134 }
135
136 //_________________________________________________________________________________________________
137 Bool_t AliRsnCut::TargetOK(TObject *obj1, TObject *obj2)
138 {
139 //
140 // This method checks if the expected target and the passed object match.
141 //
142
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   
202   return kTRUE;
203 }
204
205 //_________________________________________________________________________________________________
206 Bool_t AliRsnCut::IsSelected(TObject* /*obj1*/, TObject* /*obj2*/)
207 {
208 //
209 // Virtual cut-checking method for event mixing.
210 // This method checks only that the target is the oner for mixing.
211 //
212
213   AliWarning("Single-object cuts are not implemented here.");
214   return kTRUE;
215 }
216
217 //_________________________________________________________________________________________________
218 Bool_t AliRsnCut::OkValue()
219 {
220 //
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.
224 //
225
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   }
236 }
237
238 //_________________________________________________________________________________________________
239 Bool_t AliRsnCut::OkRange()
240 {
241 //
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.
245 //
246
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   }
257 }
258
259 //_________________________________________________________________________________________________
260 Bool_t AliRsnCut::OkValueI()
261 {
262 //
263 // This method is used when the cut consists in comparing the cut value
264 // with a reference integer value to which it must be equal.
265 //
266
267   // eval result
268   fCutResult = (fCutValueI == fMinI);
269   
270   // print debug message
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 ================================");
277   
278   return fCutResult;
279 }
280
281 //_________________________________________________________________________________________________
282 Bool_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
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 ================================");
299   
300   return fCutResult;
301 }
302
303 //_________________________________________________________________________________________________
304 Bool_t AliRsnCut::OkRangeI()
305 {
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 //
311
312   // eval result
313   fCutResult = ((fCutValueI >= fMinI) && (fCutValueI <= fMaxI));
314   
315   // print debug message
316   AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ====================================");
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")));
321   AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ================================");
322   
323   return fCutResult;
324 }
325
326 //_________________________________________________________________________________________________
327 Bool_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
339   AliDebug(AliLog::kDebug + 2, "=== CUT DEBUG ====================================");
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")));
344   AliDebug(AliLog::kDebug + 2, "=== END CUT DEBUG ================================");
345
346   return fCutResult;
347 }
348
349 //_________________________________________________________________________________________________
350 void AliRsnCut::Print(Option_t*) const
351 {
352 //
353 // Override TObject::Print() method
354 //
355
356   Char_t target[100];
357   switch (fTarget)
358   {
359     case kDaughter: sprintf(target, "DAUGHTER"); break;
360     case kMother  : sprintf(target, "MOTHER"); break;
361     case kEvent   : sprintf(target, "EVENT"); break;
362     case kMixEvent: sprintf(target, "MIX EVENT"); break;
363     default       : sprintf(target, "UNDEFINED"); break;
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 //_________________________________________________________________________________________________
375 void AliRsnCut::SetEvent(AliRsnEvent *event)
376 {
377 //
378 // Sets the reference event
379 //
380
381   fEvent = event;
382 }