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)
20 #include "AliExternalTrackParam.h"
22 #include "AliRsnDaughter.h"
23 #include "AliRsnCutPID.h"
25 ClassImp(AliRsnCutPID)
27 //_________________________________________________________________________________________________
28 AliRsnCutPID::AliRsnCutPID() :
29 AliRsnCut(AliRsnCut::kDaughter),
34 // Default constructor.
35 // Sets the cut to realistic PID with default weights,
36 // and defines the 'fMinI' value of the base class as the PID
37 // to which we want to compare this object.
42 for (i = 0; i < kDetectors; i++)
44 fUseDetector[i] = kFALSE;
45 fPtThreshold[i] = 0.0;
46 fGoAboveThreshold[i] = kTRUE;
49 for (i = 0; i < AliPID::kSPECIES; i++)
56 //_________________________________________________________________________________________________
57 AliRsnCutPID::AliRsnCutPID(const char *name, AliPID::EParticleType pid, Double_t probMin, Bool_t perfectPID) :
58 AliRsnCut(name, AliRsnCut::kDaughter, (Int_t)pid),
63 // Default constructor.
64 // Sets the cut to realistic PID with default weights,
65 // and defines the 'fMinI' value of the base class as the PID
66 // to which we want to compare this object.
71 for (i = 0; i < kDetectors; i++)
73 fUseDetector[i] = kFALSE;
74 fPtThreshold[i] = 0.0;
75 fGoAboveThreshold[i] = kTRUE;
78 for (i = 0; i < AliPID::kSPECIES; i++)
88 //_____________________________________________________________________________
89 Bool_t AliRsnCutPID::CheckThreshold(EDetector det, Double_t value)
92 // Checks if the passed value (track pT) stays in the
93 // interval where the detector should be accepted
96 if (!CheckBounds(det)) return kFALSE;
98 if (fGoAboveThreshold[det]) return (value >= fPtThreshold[det]);
99 else return (value <= fPtThreshold[det]);
102 //_________________________________________________________________________________________________
103 Bool_t AliRsnCutPID::ComputeWeights(AliRsnDaughter *daughter)
106 // Compute the PID weights using the class settings.
107 // If the argument is an ESD track, customized weights can be computed
108 // It the argument is a track (ESD or AOD), at least default weights
109 // can be computed, otherwise, no weights can be defined.
110 // The return value tells if the operation was successful.
114 Bool_t useDefault = fUseDefault;
115 Bool_t perfectPID = fPerfect;
116 if (perfectPID && !daughter->GetRefMC()) return kFALSE;
117 if (!daughter->GetRefESDtrack()) useDefault = kTRUE;
118 if (!daughter->GetRefESDtrack() && !daughter->GetRefAODtrack()) return kFALSE;
120 // if perfect PID ise required,
121 // compare the PDG code of the type stored in 'fMinI' of the cut
122 // and that of the particle which is checked, looking at its MC
125 i = TMath::Abs(AliPID::ParticleCode(fMinI));
126 j = TMath::Abs(daughter->GetRefMC()->Particle()->GetPdgCode());
130 // if default weights are (or need to be) used,
131 // they are taken directly and function exits
134 if (daughter->GetRefESDtrack())
135 daughter->GetRefESDtrack()->GetESDpid(fWeight);
138 for (i = 0; i < AliPID::kSPECIES; i++)
139 fWeight[i] = daughter->GetRefAODtrack()->PID()[i];
144 // if we arrive here, this means that we have an ESD track
145 // and we want to customize the PID
146 AliESDtrack *track = daughter->GetRefESDtrack();
147 Double_t w[kDetectors][AliPID::kSPECIES];
148 track->GetITSpid(w[kITS]);
149 track->GetTPCpid(w[kTPC]);
150 track->GetTRDpid(w[kTRD]);
151 track->GetTOFpid(w[kTOF]);
152 track->GetHMPIDpid(w[kHMPID]);
154 // if a detector is excluded or the track has not the right pT
155 // all related weights are set to 1 in order not to contribute
156 // to final multiplication
157 for (i = 0; i < kDetectors; i++)
159 if (!fUseDetector[i] || !CheckThreshold((EDetector)i, track->Pt()))
161 for (j = 0; j < AliPID::kSPECIES; j++) {
167 // multiplicate all weights to compute final one
168 for (i = 0; i < AliPID::kSPECIES; i++)
170 fWeight[i] = w[kITS][i] * w[kTPC][i] * w[kTRD][i] * w[kTOF][i] * w[kHMPID][i];
176 //_________________________________________________________________________________________________
177 Int_t AliRsnCutPID::RealisticPID(AliRsnDaughter * const daughter, Double_t &prob)
180 // Combines the weights collected from chosen detectors with the priors
181 // and gives the corresponding particle with the largest probability,
182 // in terms of the AliPID particle type enumeration.
183 // The argument, passed by reference, gives the corresponding probability,
184 // since the cut could require that it is larger than a threshold.
187 // try to compute the weights
188 if (!ComputeWeights(daughter))
191 return AliPID::kUnknown;
194 // combine with priors and normalize
196 Double_t sum = 0.0, w[AliPID::kSPECIES];
197 for (i = 0; i < AliPID::kSPECIES; i++)
199 w[i] = fWeight[i] * fPrior[i];
206 return AliPID::kUnknown;
208 for (i = 0; i < AliPID::kSPECIES; i++) w[i] /= sum;
210 // find the largest probability and related PID
213 for (i = 1; i < AliPID::kSPECIES; i++)
222 // return the value, while the probability
223 // will be consequentially set
227 //_________________________________________________________________________________________________
228 Int_t AliRsnCutPID::PerfectPID(AliRsnDaughter * const daughter)
231 // If MC is present, retrieve the particle corresponding to the used track
232 // (using the fRefMC data member) and then return the true particle type
233 // taken from the PDG code of the reference particle itself, converted
234 // into the enumeration from AliPID object.
237 // works only if the MC is present
238 if (!daughter->GetRefMC()) return AliPID::kUnknown;
240 // get the PDG code of the particle
241 TParticle *part = daughter->GetRefMC()->Particle();
242 Int_t pdg = TMath::Abs(part->GetPdgCode());
244 // loop over all species listed in AliPID to find the match
246 for (i = 0; i < AliPID::kSPECIES; i++)
248 if (AliPID::ParticleCode(i) == pdg) return i;
251 return AliPID::kUnknown;
254 //_________________________________________________________________________________________________
255 Bool_t AliRsnCutPID::IsSelected(TObject *obj1, TObject* /*obj2*/)
261 // convert the object into the unique correct type
262 AliRsnDaughter *daughter = dynamic_cast<AliRsnDaughter*>(obj1);
265 AliError(Form("[%s]: this cut works only with AliRsnDaughter objects", GetName()));
269 // depending on the PID type, recalls the appropriate method:
270 // in case of perfect PID, checks only if the PID type is
271 // corresponding to the request in the cut (fMinI)
272 // while in case of realistic PID checks also the probability
273 // to be within the required interval
276 fCutValueI = PerfectPID(daughter);
281 fCutValueI = RealisticPID(daughter, fCutValueD);
282 return OkValueI() && OkRangeD();
286 //__________________________________________________________________________________________________
287 void AliRsnCutPID::IncludeDetector(EDetector det, Double_t threshold, Bool_t goAbove)
290 // Include a detector for a customized weight computing
291 // and specify also its eventual threshold and if the detector
292 // must be used above or below the threshold.
293 // By default the threshold is zero and detector is always used.
296 if (!CheckBounds(det)) return;
298 fUseDetector[det] = kTRUE;
299 fPtThreshold[det] = threshold;
300 fGoAboveThreshold[det] = goAbove;