]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCut.cxx
Added event-mixing management in buffer and some new functions, plus some corrections...
[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
19 #include "AliLog.h"
20
21 #include "AliRsnDaughter.h"
22 #include "AliRsnMCInfo.h"
23 #include "AliRsnPairParticle.h"
24 #include "AliRsnPairDef.h"
25 #include "AliRsnEvent.h"
26 #include "AliRsnCut.h"
27
28 const Double_t AliRsnCut::fgkDSmallNumber = 1e-100;
29 const Double_t AliRsnCut::fgkDBigNumber = 1e10;
30 const Int_t    AliRsnCut::fgkIBigNumber = 32767;
31
32 ClassImp(AliRsnCut)
33
34 //________________________________________________________________________________________________________________
35 AliRsnCut::AliRsnCut() :
36     TNamed(),
37     fDMin(-fgkDBigNumber),
38     fDMax(fgkDBigNumber),
39     fIMin(-fgkIBigNumber),
40     fIMax(fgkIBigNumber),
41     fUIMin(0),
42     fUIMax(2 * (UInt_t) fgkIBigNumber),
43     fULMin(0),
44     fULMax(2 * (ULong_t) fgkIBigNumber),
45     fType(kLastCutType),
46     fVarType(kDouble_t)
47 {
48 //
49 // Constructor
50 //
51 }
52
53 //________________________________________________________________________________________________________________
54 AliRsnCut::AliRsnCut(const char *name, const char *title, EType type) :
55     TNamed(name,title),
56     fDMin(-fgkDBigNumber),
57     fDMax(fgkDBigNumber),
58     fIMin(-fgkIBigNumber),
59     fIMax(fgkIBigNumber),
60     fUIMin(0),
61     fUIMax(2 * (UInt_t) fgkIBigNumber),
62     fULMin(0),
63     fULMax(2 * (ULong_t) fgkIBigNumber),
64     fType(type),
65     fVarType(kDouble_t)
66 {
67 //
68 // Constructor with arguments but not limits
69 //
70 }
71
72 //________________________________________________________________________________________________________________
73 AliRsnCut::AliRsnCut(const char *name, const char *title, EType type, Double_t min, Double_t max) :
74     TNamed(name,title),
75     fDMin(min),
76     fDMax(max),
77     fIMin(-fgkIBigNumber),
78     fIMax(fgkIBigNumber),
79     fUIMin(0),
80     fUIMax(2 * (UInt_t) fgkIBigNumber),
81     fULMin(min),
82     fULMax(max),
83     fType(type),
84     fVarType(kDouble_t)
85 {
86 //
87 // Constructor with arguments and limits
88 //
89 }
90
91 //________________________________________________________________________________________________________________
92 AliRsnCut::AliRsnCut(const char * name, const char * title, EType type, Int_t min, Int_t max) :
93     TNamed(name,title),
94     fDMin(-fgkDBigNumber),
95     fDMax(fgkDBigNumber),
96     fIMin(min),
97     fIMax(max),
98     fUIMin(0),
99     fUIMax(2 * (UInt_t) fgkIBigNumber),
100     fULMin(min),
101     fULMax(max),
102     fType(type),
103     fVarType(kInt_t)
104 {
105 //
106 // Constructor with arguments and limits
107 //
108 }
109
110 //________________________________________________________________________________________________________________
111 AliRsnCut::AliRsnCut(const char * name, const char * title, EType type, UInt_t min, UInt_t max) :
112     TNamed(name,title),
113     fDMin(-fgkDBigNumber),
114     fDMax(fgkDBigNumber),
115     fIMin(-fgkIBigNumber),
116     fIMax(fgkIBigNumber),
117     fUIMin(min),
118     fUIMax(max),
119     fULMin(min),
120     fULMax(max),
121     fType(type),
122     fVarType(kUInt_t)
123 {
124 //
125 // Constructor with arguments and limits
126 //
127 }
128
129 //________________________________________________________________________________________________________________
130 AliRsnCut::AliRsnCut(const char * name, const char * title, EType type, ULong_t min, ULong_t max) :
131     TNamed(name,title),
132     fDMin(-fgkDBigNumber),
133     fDMax(fgkDBigNumber),
134     fIMin(-fgkIBigNumber),
135     fIMax(fgkIBigNumber),
136     fUIMin(min),
137     fUIMax(max),
138     fULMin(min),
139     fULMax(max),
140     fType(type),
141     fVarType(kUInt_t)
142 {
143 //
144 // Constructor with arguments and limits
145 //
146 }
147
148 //________________________________________________________________________________________________________________
149 AliRsnCut::~AliRsnCut()
150 {
151 //
152 // Destructor.
153 // Does absolutely nothing.
154 //
155 }
156
157 //________________________________________________________________________________________________________________
158 Bool_t AliRsnCut::IsBetween(const Double_t &theValue)
159 {
160 //
161 // Interval check.
162 // Question: "Is the argument included between fDMin and fDMax?"
163 // (not implemented for integer values because usually it is not used with them)
164 //
165   return ((theValue >= fDMin) && (theValue <= fDMax));
166 }
167
168 //________________________________________________________________________________________________________________
169 Bool_t AliRsnCut::IsBetween(const Int_t &theValue)
170 {
171 //
172 // Interval check.
173 // Question: "Is the argument included between fDMin and fDMax?"
174 // (not implemented for integer values because usually it is not used with them)
175 //
176   return ((theValue >= fIMin) && (theValue <= fIMax));
177 }
178
179 //________________________________________________________________________________________________________________
180 Bool_t AliRsnCut::MatchesValue(const Int_t &theValue)
181 {
182 //
183 // Reference check.
184 // Question: "Is the argument equal to fIMin?" (fIMax is assumed never used)
185 //
186   return (theValue == fIMin);
187 }
188
189 //________________________________________________________________________________________________________________
190 Bool_t AliRsnCut::MatchesValue(const UInt_t &theValue)
191 {
192 //
193 // Reference check.
194 // Question: "Is the argument equal to fUIMin?" (fUIMax is assumed never used)
195 //
196   return (theValue == fUIMin);
197 }
198
199 //________________________________________________________________________________________________________________
200 Bool_t AliRsnCut::MatchesValue(const ULong_t &theValue)
201 {
202   //
203 // Reference check.
204 // Question: "Is the argument equal to fUIMin?" (fUIMax is assumed never used)
205   //
206   return (theValue == fULMin);
207 }
208
209 //________________________________________________________________________________________________________________
210 Bool_t AliRsnCut::MatchesValue(const Double_t &theValue)
211 {
212 //
213 // Reference check.
214 // Question: "Is the argument reasonably close to fDMin?" (fDMax is assumed never used)
215 // Here, "reasonably close" means that the difference is smaller than the
216 // 'fgkSmallNumber' global static data member of this class
217 //
218   return (TMath::Abs(theValue - fDMin) < fgkDSmallNumber);
219 }
220
221 //________________________________________________________________________________________________________________
222 void AliRsnCut::SetCutValues(EType type, const Double_t &theValue, const Double_t &theValue2)
223 {
224 //
225 // (Re)assignment of cut values
226 //
227   fType = type;
228   fDMin = theValue;
229   fDMax = theValue2;
230 }
231
232 //________________________________________________________________________________________________________________
233 void AliRsnCut::SetCutValues(EType type, const Int_t &theValue, const Int_t &theValue2)
234 {
235 //
236 // (Re)assignment of cut values
237 //
238   fType = type;
239   fIMin = theValue;
240   fIMax = theValue2;
241 }
242
243 //________________________________________________________________________________________________________________
244 void AliRsnCut::SetCutValues(EType type, const UInt_t &theValue, const UInt_t &theValue2)
245 {
246 //
247 // (Re)assignment of cut values
248 //
249   fType = type;
250   fUIMin = theValue;
251   fUIMax = theValue2;
252 }
253
254 //________________________________________________________________________________________________________________
255 void AliRsnCut::SetCutValues(EType type, const ULong_t &theValue, const ULong_t &theValue2)
256 {
257   //
258 // (Re)assignment of cut values
259   //
260   fType = type;
261   fULMin = theValue;
262   fULMax = theValue2;
263 }
264
265 //________________________________________________________________________________________________________________
266 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnDaughter *daughter)
267 {
268 //
269 // Core of the whole class.
270 // According to the kind of cut selected in the enumeration,
271 // checks the cut taking the right values from the argument.
272 // Depending on the second argument type, only some cuts are checked
273 // (the ones for that type of object), otherwise kTRUE is returned in order
274 // not to act as a cleaning factor for an AND with other cuts.
275 //
276   AliDebug(AliLog::kDebug, "<-");
277   AliRsnMCInfo *mcinfo = daughter->GetMCInfo();
278
279   // check type
280   if (type != kParticle)
281   {
282     AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnDaughter)", type, kParticle, daughter->ClassName()));
283     return kTRUE;
284   }
285
286   // utility variables
287   AliRsnPID::EType pidType;
288   Double_t prob;
289
290   switch (fType)
291   {
292     case kMomentum:
293       return IsBetween(daughter->P());
294     case kTransMomentum:
295       return IsBetween(daughter->Pt());
296     case kEta:
297       return IsBetween(daughter->Eta());
298     case kRadialImpactParam:
299       return IsBetween(daughter->Dr());
300     case kMomentumMC:
301       if (mcinfo) return IsBetween(mcinfo->P());
302       else return kTRUE;
303     case kTransMomentumMC:
304       if (mcinfo) return IsBetween(mcinfo->P());
305       else return kTRUE;
306     case kStatus:
307       return daughter->CheckFlag(fUIMin);
308     case kChargePos:
309       return (daughter->Charge() > 0);
310     case kChargeNeg:
311       return (daughter->Charge() < 0);
312     case kPIDType:
313     case kPIDProb:
314       pidType = daughter->PIDType(prob);
315       if (fType == kPIDType) return MatchesValue((Int_t) pidType);
316       if (fType == kPIDProb) return IsBetween(prob);
317     case kEtaMC:
318       if (mcinfo) return IsBetween(mcinfo->Eta());
319       else return kTRUE;
320     case kNSigma:
321       return IsBetween(daughter->NSigmaToVertex());
322       /*
323       case kEsdNSigmaCalculate:
324       return IsBetween (daughter->GetESDInfo()->GetNSigmaCalculate());
325       */
326     default:
327       AliWarning("Requested a cut which cannot be applied to a single track");
328       return kTRUE;
329   }
330
331   return kTRUE;
332 }
333
334 //________________________________________________________________________________________________________________
335 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnPairParticle * pair)
336 {
337   AliDebug(AliLog::kDebug, "<-");
338
339   // check type
340   if (type != kPair)
341   {
342     AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnPairParticle)", type, kPair, pair->ClassName()));
343     return kTRUE;
344   }
345
346   switch (fType)
347   {
348     case kMomentum:
349       return IsBetween(pair->GetP());
350     case kTransMomentum:
351       return IsBetween(pair->GetPt());
352       /*
353       case kEta:
354           return IsBetween (daughter->Eta());
355       */
356     case kMomentumMC:
357       return IsBetween(pair->GetPMC());
358     case kTransMomentumMC:
359       return IsBetween(pair->GetPtMC());
360     case kIsLabelEqual:
361       return pair->IsLabelEqual();
362     case kIsTruePair:
363       return pair->IsTruePair(fIMin);
364     default:
365       AliWarning("Requested a cut which cannot be applied to a pair");
366       return kTRUE;
367   }
368
369   return kTRUE;
370 }
371
372 //________________________________________________________________________________________________________________
373 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnEvent * event)
374 {
375   AliDebug(AliLog::kDebug, "<-");
376
377   // check type
378   if (type != kEvent)
379   {
380     AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnEvent)", type, kEvent, event->ClassName()));
381     return kTRUE;
382   }
383
384   switch (fType)
385   {
386     case kMultiplicity:
387       return IsBetween((Int_t) event->GetMultiplicity());
388     default:
389       AliWarning("Requested a cut which cannot be applied to an event");
390       return kTRUE;
391   }
392
393   return kTRUE;
394 }
395
396 //________________________________________________________________________________________________________________
397 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnEvent * ev1, AliRsnEvent * ev2)
398 {
399   AliDebug(AliLog::kDebug, "<-");
400
401   Double_t valueD;
402   Int_t    valueI;
403
404   switch (fType)
405   {
406     case kMultiplicityDifference:
407       valueI = TMath::Abs(ev1->GetMultiplicity() - ev2->GetMultiplicity());
408       return IsBetween((Int_t)valueI);
409     case kVzDifference:
410       valueD = TMath::Abs(ev1->GetVz() - ev2->GetVz());
411       return IsBetween((Double_t)valueD);
412     case kPhiMeanDifference:
413       valueD = TMath::Abs(ev1->GetPhiMean() - ev2->GetPhiMean());
414       if (valueD > 180.0) valueD = 360.0 - valueD;
415       return IsBetween((Double_t)valueD);
416     default:
417       AliWarning("Requested a cut which cannot be applied to an event");
418       return kTRUE;
419   }
420
421   return kTRUE;
422 }
423
424 //________________________________________________________________________________________________________________
425 void AliRsnCut::PrintAllValues()
426 {
427   AliInfo(Form("fType=%d fVarType=%d",fType,fVarType));
428   AliInfo(Form("fDMin=%.2e fDMax=%.2e",fDMin,fDMax));
429   AliInfo(Form("fIMin=%d fIMax=%d",fIMin,fIMax));
430   AliInfo(Form("fUIMin=%d fUIMax=%d",fUIMin,fUIMax));
431   AliInfo(Form("fULMin=%d fULMax=%d",fULMin,fULMax));
432 }