4 // Processes the tracks to compute PID probabilities,
5 // by combining the prior probabilities with the PID weights
6 // stored in each AliRsnDaughter
8 // authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
9 // M. Vala (martin.vala@cern.ch)
14 #include <TDirectory.h>
17 #include "AliRsnMCInfo.h"
18 #include "AliRsnDaughter.h"
19 #include "AliRsnEvent.h"
21 #include "AliRsnPID.h"
25 const Double_t AliRsnPID::fgkParticleMass[AliRsnPID::kSpeciesAll + 1] =
27 0.00051099892, // electron
37 const char* AliRsnPID::fgkParticleNameLong[AliRsnPID::kSpeciesAll + 1] =
49 const char* AliRsnPID::fgkParticleNameShort[AliRsnPID::kSpeciesAll + 1] =
61 const char* AliRsnPID::fgkParticleNameLatex[AliRsnPID::kSpeciesAll + 1] =
73 const Int_t AliRsnPID::fgkParticlePDG[AliRsnPID::kSpeciesAll + 1] =
85 //_____________________________________________________________________________
86 AliRsnPID::AliRsnPID() :
94 // Adds also the object in the default directory of the session.
98 for (i = 0; i < kSpecies; i++) fPrior[i] = 0.2;
101 //_____________________________________________________________________________
102 AliRsnPID::EType AliRsnPID::InternalType(Int_t pdg)
104 // Return the internal enum value corresponding to the PDG
105 // code passed as argument, if possible.
106 // Otherwise, returns 'kUnknown' by default.
110 Int_t absPDG = TMath::Abs(pdg);
142 //_____________________________________________________________________________
143 Int_t AliRsnPID::PDGCode(EType type)
146 // Returns the PDG code of the particle type
147 // specified as argument (w.r. to the internal enum)
150 if (type >= kElectron && type <= kUnknown)
152 return fgkParticlePDG[type];
160 //_____________________________________________________________________________
161 const char* AliRsnPID::ParticleName(EType type, Bool_t shortName)
164 // Returns the name of the particle type
165 // specified as argument (w.r. to the internal enum)
168 if (type >= 0 && type <= kSpeciesAll)
170 return shortName ? fgkParticleNameShort[type] : fgkParticleNameLong[type];
174 return shortName ? "unk" : "unknown";
178 //_____________________________________________________________________________
179 const char* AliRsnPID::ParticleNameLatex(EType type)
182 // Returns the name of the particle type
183 // specified as argument (w.r. to the internal enum)
186 if (type >= kElectron && type <= kSpeciesAll)
188 return fgkParticleNameLatex[type];
196 //_____________________________________________________________________________
197 Double_t AliRsnPID::ParticleMass(EType type)
200 // Returns the mass corresponding to the particle type
201 // specified as argument (w.r. to the internal enum)
204 TDatabasePDG *db = TDatabasePDG::Instance();
205 Int_t pdg = PDGCode(type);
206 return db->GetParticle(pdg)->Mass();
208 if (type >= kElectron && type < kSpeciesAll) return fgkParticleMass[type];
212 //_____________________________________________________________________________
213 Bool_t AliRsnPID::ComputeProbs(AliRsnDaughter *daughter)
216 // Uses the Bayesian combination of prior probabilities
217 // with the PID weights of the passed object to compute
218 // the overall PID probabilities for each particle type.
220 // Once this computation is done, the argument is assigned
221 // the PID corresponding to the largest probability,
222 // and its data members are updated accordingly.
223 // If the track Pt is larger than the cut defined (fMaxPt)
224 // or the probability is smaller than the cut defined (fMinProb),
225 // the track is considered unidentified.
227 // If the identification procedure encounters errors,
228 // the return value will be "FALSE", otherwise it is "TRUE".
231 // reset all PID probabilities to 0.0
233 for (i = 0; i < kSpecies; i++) daughter->SetPIDProb(i, 1.0 / (Double_t) kSpecies);
235 // multiply weights and priors
236 Double_t sum = 0.0, prob[kSpecies];
237 for (i = 0; i < kSpecies; i++)
239 prob[i] = fPrior[i] * daughter->PID()[i];
242 if (sum <= (Double_t) 0.)
244 AliError(Form("Sum of weights = %f <= 0", sum));
249 for (i = 0; i < kSpecies; i++)
252 daughter->SetPIDProb(i, prob[i]);
255 daughter->AssignRealisticPID();
257 AliRsnDaughter::SetPIDMethod(AliRsnDaughter::kRealistic);
258 AliRsnPID::EType type = daughter->PIDType(assprob);
259 AliDebug(5, Form("Assigned PID: %s [%.2f %]", AliRsnPID::ParticleName(type), assprob*100.));
264 //_____________________________________________________________________________
265 Bool_t AliRsnPID::IdentifiedAs(AliRsnDaughter *d, EType type, Short_t charge)
268 // Tells if a particle has can be identified to be of a given tipe and charge.
269 // If the charge is zero, the check is done only on the PID type, otherwise
270 // both charge and PID type are required to match.
271 // If the track momentum is larger than the pt threshold passed to this object,
272 // or the maximum probability is smaller than the prob thrashold, the return value
273 // is kFALSE even when the type and charge are matched.
276 EType dType = TrackType(d);
277 if (dType != type) return kFALSE;
284 return (d->Charge() > 0);
288 return (d->Charge() < 0);
292 //_____________________________________________________________________________
293 AliRsnPID::EType AliRsnPID::TrackType(AliRsnDaughter *d)
296 // Returns the track type according to the object settings
297 // and to the static settings in the AliRsnDaughter object.
301 EType type = d->PIDType(prob);
303 if (d->Pt() > fMaxPt) return kUnknown;
304 if (prob < fMinProb) return kUnknown;
309 //_____________________________________________________________________________
310 Bool_t AliRsnPID::Process(AliRsnEvent *event)
313 // Performs identification for all tracks in a given event.
314 // Returns the logical AND of all PID operations.
317 Bool_t check = kTRUE;
318 if (!event) return check;
319 if (!event->GetTracks()) return check;
320 if (event->GetTracks()->IsEmpty()) return check;
322 AliRsnDaughter *daughter = 0;
323 TObjArrayIter iter(event->GetTracks());
324 while ((daughter = (AliRsnDaughter*) iter.Next()))
326 check = check && ComputeProbs(daughter);
328 event->FillPIDArrays(fPIDArraysSize);
334 //_____________________________________________________________________________
335 void AliRsnPID::SetPriorProbability(EType type, Double_t p)
338 // Sets the prior probability for Realistic PID, for a
339 // given particle species.
342 if (type >= kElectron && type < kSpecies)
348 //_____________________________________________________________________________
349 void AliRsnPID::DumpPriors()
352 // Print all prior probabilities
358 for (i = 0; i < kSpecies; i++)
360 sprintf(msg, "Prior probability for '%s' = %3.5f", fgkParticleNameLong[i], fPrior[i]);