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()]
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.
15 // authors: Martin Vala (martin.vala@cern.ch)
16 // Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
18 #include "Riostream.h"
21 #include "AliRsnDaughter.h"
22 #include "AliRsnMCInfo.h"
23 #include "AliRsnPairParticle.h"
24 #include "AliRsnPairDef.h"
25 #include "AliRsnEvent.h"
26 #include "AliRsnCut.h"
28 const Double_t AliRsnCut::fgkDSmallNumber = 1e-100;
29 const Double_t AliRsnCut::fgkDBigNumber = 1e10;
30 const Int_t AliRsnCut::fgkIBigNumber = 32767;
34 //________________________________________________________________________________________________________________
35 AliRsnCut::AliRsnCut() :
37 fDMin(-fgkDBigNumber),
39 fIMin(-fgkIBigNumber),
42 fUIMax(2 * (UInt_t) fgkIBigNumber),
44 fULMax(2 * (ULong_t) fgkIBigNumber),
53 //________________________________________________________________________________________________________________
54 AliRsnCut::AliRsnCut(const char *name, const char *title, EType type) :
56 fDMin(-fgkDBigNumber),
58 fIMin(-fgkIBigNumber),
61 fUIMax(2 * (UInt_t) fgkIBigNumber),
63 fULMax(2 * (ULong_t) fgkIBigNumber),
68 // Constructor with arguments but not limits
72 //________________________________________________________________________________________________________________
73 AliRsnCut::AliRsnCut(const char *name, const char *title, EType type, Double_t min, Double_t max) :
77 fIMin(-fgkIBigNumber),
80 fUIMax(2 * (UInt_t) fgkIBigNumber),
87 // Constructor with arguments and limits
91 //________________________________________________________________________________________________________________
92 AliRsnCut::AliRsnCut(const char * name, const char * title, EType type, Int_t min, Int_t max) :
94 fDMin(-fgkDBigNumber),
99 fUIMax(2 * (UInt_t) fgkIBigNumber),
106 // Constructor with arguments and limits
110 //________________________________________________________________________________________________________________
111 AliRsnCut::AliRsnCut(const char * name, const char * title, EType type, UInt_t min, UInt_t max) :
113 fDMin(-fgkDBigNumber),
114 fDMax(fgkDBigNumber),
115 fIMin(-fgkIBigNumber),
116 fIMax(fgkIBigNumber),
125 // Constructor with arguments and limits
129 //________________________________________________________________________________________________________________
130 AliRsnCut::AliRsnCut(const char * name, const char * title, EType type, ULong_t min, ULong_t max) :
132 fDMin(-fgkDBigNumber),
133 fDMax(fgkDBigNumber),
134 fIMin(-fgkIBigNumber),
135 fIMax(fgkIBigNumber),
144 // Constructor with arguments and limits
148 //________________________________________________________________________________________________________________
149 AliRsnCut::~AliRsnCut()
153 // Does absolutely nothing.
157 //________________________________________________________________________________________________________________
158 Bool_t AliRsnCut::IsBetween(const Double_t &theValue)
162 // Question: "Is the argument included between fDMin and fDMax?"
163 // (not implemented for integer values because usually it is not used with them)
165 return ((theValue >= fDMin) && (theValue <= fDMax));
168 //________________________________________________________________________________________________________________
169 Bool_t AliRsnCut::IsBetween(const Int_t &theValue)
173 // Question: "Is the argument included between fDMin and fDMax?"
174 // (not implemented for integer values because usually it is not used with them)
176 return ((theValue >= fIMin) && (theValue <= fIMax));
179 //________________________________________________________________________________________________________________
180 Bool_t AliRsnCut::MatchesValue(const Int_t &theValue)
184 // Question: "Is the argument equal to fIMin?" (fIMax is assumed never used)
186 return (theValue == fIMin);
189 //________________________________________________________________________________________________________________
190 Bool_t AliRsnCut::MatchesValue(const UInt_t &theValue)
194 // Question: "Is the argument equal to fUIMin?" (fUIMax is assumed never used)
196 return (theValue == fUIMin);
199 //________________________________________________________________________________________________________________
200 Bool_t AliRsnCut::MatchesValue(const ULong_t &theValue)
204 // Question: "Is the argument equal to fUIMin?" (fUIMax is assumed never used)
206 return (theValue == fULMin);
209 //________________________________________________________________________________________________________________
210 Bool_t AliRsnCut::MatchesValue(const Double_t &theValue)
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
218 return (TMath::Abs(theValue - fDMin) < fgkDSmallNumber);
221 //________________________________________________________________________________________________________________
222 void AliRsnCut::SetCutValues(EType type, const Double_t &theValue, const Double_t &theValue2)
225 // (Re)assignment of cut values
232 //________________________________________________________________________________________________________________
233 void AliRsnCut::SetCutValues(EType type, const Int_t &theValue, const Int_t &theValue2)
236 // (Re)assignment of cut values
243 //________________________________________________________________________________________________________________
244 void AliRsnCut::SetCutValues(EType type, const UInt_t &theValue, const UInt_t &theValue2)
247 // (Re)assignment of cut values
254 //________________________________________________________________________________________________________________
255 void AliRsnCut::SetCutValues(EType type, const ULong_t &theValue, const ULong_t &theValue2)
258 // (Re)assignment of cut values
265 //________________________________________________________________________________________________________________
266 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnDaughter *daughter)
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.
276 AliDebug(AliLog::kDebug, "<-");
277 AliRsnMCInfo *mcinfo = daughter->GetMCInfo();
280 if (type != kParticle)
282 AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnDaughter)", type, kParticle, daughter->ClassName()));
287 AliRsnPID::EType pidType;
295 return IsBetween(daughter->P());
297 return IsBetween(daughter->Pt());
299 return IsBetween(daughter->Eta());
300 case kRadialImpactParam:
301 return IsBetween(daughter->Dr());
302 case kRadialImpactParamMC:
303 if (mcinfo) return IsBetween(mcinfo->Dr());
306 if (mcinfo) return IsBetween(mcinfo->P());
308 case kTransMomentumMC:
309 if (mcinfo) return IsBetween(mcinfo->Pt());
312 return daughter->CheckFlag(fUIMin);
314 return (daughter->Charge() > 0);
316 return (daughter->Charge() < 0);
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;
327 pidType = daughter->AssignedPID();
328 return MatchesValue((Int_t)pidType);
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()));
336 if (mcinfo) return IsBetween(mcinfo->Eta());
339 if (mcinfo) return (mcinfo->Mother() < 0);
342 return (!daughter->IsKink() || daughter->IsKinkMother());
343 case kIsKinkDaughter:
344 return daughter->IsKinkDaughter();
346 return IsBetween(daughter->NSigmaToVertex());
348 case kEsdNSigmaCalculate:
349 return IsBetween (daughter->GetESDInfo()->GetNSigmaCalculate());
352 AliWarning("Requested a cut which cannot be applied to a single track");
359 //________________________________________________________________________________________________________________
360 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnPairParticle * pair)
362 AliDebug(AliLog::kDebug, "<-");
367 AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnPairParticle)", type, kPair, pair->ClassName()));
374 return IsBetween(pair->GetP());
376 return IsBetween(pair->GetPt());
378 return IsBetween(pair->GetEta());
380 return IsBetween(pair->GetEtaMC());
382 return IsBetween(pair->GetPMC());
383 case kTransMomentumMC:
384 return IsBetween(pair->GetPtMC());
386 return pair->IsLabelEqual();
388 return pair->IsTruePair(fIMin);
390 AliWarning("Requested a cut which cannot be applied to a pair");
397 //________________________________________________________________________________________________________________
398 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnEvent * event)
400 AliDebug(AliLog::kDebug, "<-");
405 AliWarning(Form("Mismatch: type = %d (expected %d), class type = %s (expected AliRsnEvent)", type, kEvent, event->ClassName()));
411 case kTrueMultiplicity:
412 return IsBetween((Int_t) event->GetTrueMultiplicity());
414 return IsBetween((Int_t) event->GetMultiplicity());
416 return IsBetween((Double_t)event->GetPrimaryVertexZ());
418 AliWarning("Requested a cut which cannot be applied to an event");
425 //________________________________________________________________________________________________________________
426 Bool_t AliRsnCut::IsSelected(ETarget type, AliRsnEvent * ev1, AliRsnEvent * ev2)
428 AliDebug(AliLog::kDebug, "<-");
431 if (type != kMixEvent)
433 AliWarning(Form("Mismatch: type = %d (expected %d)", type, kMixEvent));
437 Double_t valueD, mult1, mult2;
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);
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);
459 AliWarning("Requested a cut which cannot be applied to an event");
466 //________________________________________________________________________________________________________________
467 void AliRsnCut::PrintAllValues()
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));