]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCut.cxx
few modifications on package, waiting for AOD compliance 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 #include "Riostream.h"
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((ULong_t)min),
82     fULMax((ULong_t)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   Int_t pdg;
290   Bool_t cut;
291
292   switch (fType)
293   {
294     case kMomentum:
295       return IsBetween(daughter->P());
296     case kTransMomentum:
297       return IsBetween(daughter->Pt());
298     case kEta:
299       return IsBetween(daughter->Eta());
300     case kRadialImpactParam:
301       return IsBetween(daughter->Dr());
302     case kRadialImpactParamMC:
303       if (mcinfo) return IsBetween(mcinfo->Dr());
304       else return kTRUE;
305     case kMomentumMC:
306       if (mcinfo) return IsBetween(mcinfo->P());
307       else return kTRUE;
308     case kTransMomentumMC:
309       if (mcinfo) return IsBetween(mcinfo->Pt());
310       else return kTRUE;
311     case kStatus:
312       return daughter->CheckFlag(fUIMin);
313     case kChargePos:
314       return (daughter->Charge() > 0);
315     case kChargeNeg:
316       return (daughter->Charge() < 0);
317     case kPIDType:
318     case kPIDProb:
319       pidType = daughter->PIDType(prob);
320       if (fType == kPIDType) return MatchesValue((Int_t) pidType);
321       if (fType == kPIDProb) return IsBetween(prob);
322     case kPIDProbForSpecies:
323       cut = IsBetween(daughter->PIDProb()[(AliRsnPID::EType)fIMin]);
324       //cout << (AliRsnPID::EType)fIMin << ' ' << daughter->PIDProb()[(AliRsnPID::EType)fIMin] << ' ' << (cut?"OK":"NO") << endl;
325       return cut;
326     case kAssignedPID:
327       pidType = daughter->AssignedPID();
328       return MatchesValue((Int_t)pidType);
329     case kTruePID:
330       pdg = TMath::Abs(mcinfo->PDG());
331       cut = MatchesValue(pdg);
332       //AliError(Form("PDG = %d -- CUT = %s", pdg, (cut ? "passed" : "not passed")));
333       if (mcinfo) return MatchesValue((Int_t) TMath::Abs(mcinfo->PDG()));
334       else return kTRUE;
335     case kEtaMC:
336       if (mcinfo) return IsBetween(mcinfo->Eta());
337       else return kTRUE;
338     case kIsPrimary:
339       if (mcinfo) return (mcinfo->Mother() < 0);
340       else return kTRUE;
341     case kIsKinkMother:
342       return (!daughter->IsKink() || daughter->IsKinkMother());
343     case kIsKinkDaughter:
344       return daughter->IsKinkDaughter();
345     case kNSigma:
346       return IsBetween(daughter->NSigmaToVertex());
347       /*
348       case kEsdNSigmaCalculate:
349       return IsBetween (daughter->GetESDInfo()->GetNSigmaCalculate());
350       */
351     default:
352       AliWarning("Requested a cut which cannot be applied to a single track");
353       return kTRUE;
354   }
355
356   return kTRUE;
357 }
358
359 //________________________________________________________________________________________________________________
360 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnPairParticle * pair)
361 {
362   AliDebug(AliLog::kDebug, "<-");
363
364   // check type
365   if (type != kPair)
366   {
367     AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnPairParticle)", type, kPair, pair->ClassName()));
368     return kTRUE;
369   }
370
371   switch (fType)
372   {
373     case kMomentum:
374       return IsBetween(pair->GetP());
375     case kTransMomentum:
376       return IsBetween(pair->GetPt());
377     case kEta:
378       return IsBetween(pair->GetEta());
379     case kEtaMC:
380       return IsBetween(pair->GetEtaMC());
381     case kMomentumMC:
382       return IsBetween(pair->GetPMC());
383     case kTransMomentumMC:
384       return IsBetween(pair->GetPtMC());
385     case kIsLabelEqual:
386       return pair->IsLabelEqual();
387     case kIsTruePair:
388       return pair->IsTruePair(fIMin);
389     default:
390       AliWarning("Requested a cut which cannot be applied to a pair");
391       return kTRUE;
392   }
393
394   return kTRUE;
395 }
396
397 //________________________________________________________________________________________________________________
398 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnEvent * event)
399 {
400   AliDebug(AliLog::kDebug, "<-");
401
402   // check type
403   if (type != kEvent)
404   {
405     AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnEvent)", type, kEvent, event->ClassName()));
406     return kTRUE;
407   }
408
409   switch (fType)
410   {
411     case kTrueMultiplicity:
412       return IsBetween((Int_t) event->GetTrueMultiplicity());
413     case kMultiplicity:
414       return IsBetween((Int_t) event->GetMultiplicity());
415     case kVz:
416       return IsBetween((Double_t)event->GetPrimaryVertexZ());
417     default:
418       AliWarning("Requested a cut which cannot be applied to an event");
419       return kTRUE;
420   }
421
422   return kTRUE;
423 }
424
425 //________________________________________________________________________________________________________________
426 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnEvent * ev1, AliRsnEvent * ev2)
427 {
428   AliDebug(AliLog::kDebug, "<-");
429
430   // check type
431   if (type != kMixEvent)
432   {
433     AliWarning(Form("Mismatch: type = %d (expected %d)", type, kMixEvent));
434     return kTRUE;
435   }
436
437   Double_t valueD, mult1, mult2;
438   Int_t    valueI;
439
440   switch (fType)
441   {
442     case kMultiplicityDifference:
443       valueI = TMath::Abs(ev1->GetTrueMultiplicity() - ev2->GetTrueMultiplicity());
444       return IsBetween((Int_t)valueI);
445     case kMultiplicityRatio:
446       mult1 = (Double_t)ev1->GetMultiplicity();
447       mult2 = (Double_t)ev2->GetMultiplicity();
448       if (mult1 == 0.0  && mult2 == 0.0) return kTRUE;
449       valueD = 100.0 * TMath::Abs(mult1 - mult2) / TMath::Max(mult1, mult2); // in %
450       return IsBetween((Double_t)valueD);
451     case kVzDifference:
452       valueD = TMath::Abs(ev1->GetVz() - ev2->GetVz());
453       return IsBetween((Double_t)valueD);
454     case kPhiMeanDifference:
455       valueD = TMath::Abs(ev1->GetPhiMean() - ev2->GetPhiMean());
456       if (valueD > 180.0) valueD = 360.0 - valueD;
457       return IsBetween((Double_t)valueD);
458     default:
459       AliWarning("Requested a cut which cannot be applied to an event");
460       return kTRUE;
461   }
462
463   return kTRUE;
464 }
465
466 //________________________________________________________________________________________________________________
467 void AliRsnCut::PrintAllValues()
468 {
469   AliInfo(Form("fType=%d fVarType=%d",fType,fVarType));
470   AliInfo(Form("fDMin=%.2e fDMax=%.2e",fDMin,fDMax));
471   AliInfo(Form("fIMin=%d fIMax=%d",fIMin,fIMax));
472   AliInfo(Form("fUIMin=%d fUIMax=%d",fUIMin,fUIMax));
473   AliInfo(Form("fULMin=%d fULMax=%d",fULMin,fULMax));
474 }