]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCut.cxx
Code:
[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 kIsPrimary:
321       if (mcinfo) return (mcinfo->Mother() < 0);
322       else return kTRUE;
323     case kNSigma:
324       return IsBetween(daughter->NSigmaToVertex());
325       /*
326       case kEsdNSigmaCalculate:
327       return IsBetween (daughter->GetESDInfo()->GetNSigmaCalculate());
328       */
329     default:
330       AliWarning("Requested a cut which cannot be applied to a single track");
331       return kTRUE;
332   }
333
334   return kTRUE;
335 }
336
337 //________________________________________________________________________________________________________________
338 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnPairParticle * pair)
339 {
340   AliDebug(AliLog::kDebug, "<-");
341
342   // check type
343   if (type != kPair)
344   {
345     AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnPairParticle)", type, kPair, pair->ClassName()));
346     return kTRUE;
347   }
348
349   switch (fType)
350   {
351     case kMomentum:
352       return IsBetween(pair->GetP());
353     case kTransMomentum:
354       return IsBetween(pair->GetPt());
355       /*
356       case kEta:
357           return IsBetween (daughter->Eta());
358       */
359     case kMomentumMC:
360       return IsBetween(pair->GetPMC());
361     case kTransMomentumMC:
362       return IsBetween(pair->GetPtMC());
363     case kIsLabelEqual:
364       return pair->IsLabelEqual();
365     case kIsTruePair:
366       return pair->IsTruePair(fIMin);
367     default:
368       AliWarning("Requested a cut which cannot be applied to a pair");
369       return kTRUE;
370   }
371
372   return kTRUE;
373 }
374
375 //________________________________________________________________________________________________________________
376 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnEvent * event)
377 {
378   AliDebug(AliLog::kDebug, "<-");
379
380   // check type
381   if (type != kEvent)
382   {
383     AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnEvent)", type, kEvent, event->ClassName()));
384     return kTRUE;
385   }
386
387   switch (fType)
388   {
389     case kMultiplicity:
390       return IsBetween((Int_t) event->GetMultiplicity());
391     default:
392       AliWarning("Requested a cut which cannot be applied to an event");
393       return kTRUE;
394   }
395
396   return kTRUE;
397 }
398
399 //________________________________________________________________________________________________________________
400 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnEvent * ev1, AliRsnEvent * ev2)
401 {
402   AliDebug(AliLog::kDebug, "<-");
403   
404   // check type
405   if (type != kMixEvent)
406   {
407     AliWarning(Form("Mismatch: type = %d (expected %d)", type, kMixEvent));
408     return kTRUE;
409   }
410
411   Double_t valueD, mult1, mult2;
412   Int_t    valueI;
413
414   switch (fType)
415   {
416     case kMultiplicityDifference:
417       valueI = TMath::Abs(ev1->GetMultiplicity() - ev2->GetMultiplicity());
418       return IsBetween((Int_t)valueI);
419     case kMultiplicityRatio:
420       mult1 = (Double_t)ev1->GetMultiplicity();
421       mult2 = (Double_t)ev2->GetMultiplicity();
422       if (mult1 == 0.0  && mult2 == 0.0) return kTRUE;
423       valueD = 100.0 * TMath::Abs(mult1 - mult2) / TMath::Max(mult1, mult2); // in %
424       return IsBetween((Double_t)valueD);
425     case kVzDifference:
426       valueD = TMath::Abs(ev1->GetVz() - ev2->GetVz());
427       return IsBetween((Double_t)valueD);
428     case kPhiMeanDifference:
429       valueD = TMath::Abs(ev1->GetPhiMean() - ev2->GetPhiMean());
430       if (valueD > 180.0) valueD = 360.0 - valueD;
431       return IsBetween((Double_t)valueD);
432     default:
433       AliWarning("Requested a cut which cannot be applied to an event");
434       return kTRUE;
435   }
436
437   return kTRUE;
438 }
439
440 //________________________________________________________________________________________________________________
441 void AliRsnCut::PrintAllValues()
442 {
443   AliInfo(Form("fType=%d fVarType=%d",fType,fVarType));
444   AliInfo(Form("fDMin=%.2e fDMax=%.2e",fDMin,fDMax));
445   AliInfo(Form("fIMin=%d fIMax=%d",fIMin,fIMax));
446   AliInfo(Form("fUIMin=%d fUIMax=%d",fUIMin,fUIMax));
447   AliInfo(Form("fULMin=%d fULMax=%d",fULMin,fULMax));
448 }