1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // particle id probability densities //
22 // The AliPID class stores the probability densities for the different //
23 // particle type hypotheses electron, muon, pion, kaon, proton, photon, //
24 // pi0, neutron, K0 and electron conversion. These probability densities //
25 // are determined from the detector response functions. //
26 // The * and *= operators are overloaded for AliPID to combine the PIDs //
27 // from different detectors. //
29 // The Bayesian probability to be a particle of a given type can be //
30 // calculated from the probability densities, if the a priori probabilities //
31 // (or abundences, concentrations) of particle species are known. These //
32 // priors can be given as argument to the GetProbability or GetMostProbable //
33 // method or they can be set globally by calling the static method //
36 // The implementation of this class is based on the note ... //
37 // by Iouri Belikov and Karel Safarik. //
39 ///////////////////////////////////////////////////////////////////////////////
42 #include <TDatabasePDG.h>
49 #define M(PID) TDatabasePDG::Instance()->GetParticle(fgkParticleCode[(PID)])->Mass()
53 const char* AliPID::fgkParticleName[AliPID::kSPECIESCN+1] = {
74 const char* AliPID::fgkParticleShortName[AliPID::kSPECIESCN+1] = {
95 const char* AliPID::fgkParticleLatexName[AliPID::kSPECIESCN+1] = {
116 const Int_t AliPID::fgkParticleCode[AliPID::kSPECIESCN+1] = {
136 /*const*/ Float_t AliPID::fgkParticleMass[AliPID::kSPECIESCN+1] = {
137 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
139 M(kElectron), // electron
143 M(kProton), // proton
144 M(kPhoton), // photon
146 M(kNeutron), // neutron
148 M(kEleCon), // electron conversion
149 M(kDeuteron), // deuteron
150 M(kTriton), // triton
156 /*const*/ Float_t AliPID::fgkParticleMassZ[AliPID::kSPECIESCN+1] = {
157 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
159 M(kElectron), // electron
163 M(kProton), // proton
164 M(kPhoton), // photon
166 M(kNeutron), // neutron
168 M(kEleCon), // electron conversion
169 M(kDeuteron), // deuteron
170 M(kTriton), // triton
172 M(kAlpha)/2, // alpha
177 Double_t AliPID::fgPrior[kSPECIESCN] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
180 //_______________________________________________________________________
186 // Default constructor
189 // set default values (= equal probabilities)
190 for (Int_t i = 0; i < kSPECIESCN; i++)
191 fProbDensity[i] = 1./kSPECIESCN;
194 //_______________________________________________________________________
195 AliPID::AliPID(const Double_t* probDensity, Bool_t charged) :
200 // Standard constructor
203 // set given probability densities
204 for (Int_t i = 0; i < kSPECIESC; i++)
205 fProbDensity[i] = probDensity[i];
207 for (Int_t i = kSPECIESC; i < kSPECIESCN; i++)
208 fProbDensity[i] = ((charged) ? 0 : probDensity[i]);
211 //_______________________________________________________________________
212 AliPID::AliPID(const Float_t* probDensity, Bool_t charged) :
217 // Standard constructor
220 // set given probability densities
221 for (Int_t i = 0; i < kSPECIESC; i++)
222 fProbDensity[i] = probDensity[i];
224 for (Int_t i = kSPECIESC; i < kSPECIESCN; i++)
225 fProbDensity[i] = ((charged) ? 0 : probDensity[i]);
228 //_______________________________________________________________________
229 AliPID::AliPID(const AliPID& pid) :
231 fCharged(pid.fCharged)
236 // We do not call init here, MUST already be done
237 for (Int_t i = 0; i < kSPECIESCN; i++)
238 fProbDensity[i] = pid.fProbDensity[i];
241 //_______________________________________________________________________
242 void AliPID::SetProbabilities(const Double_t* probDensity, Bool_t charged)
245 // Set the probability densities
247 for (Int_t i = 0; i < kSPECIESC; i++)
248 fProbDensity[i] = probDensity[i];
250 for (Int_t i = kSPECIESC; i < kSPECIESCN; i++)
251 fProbDensity[i] = ((charged) ? 0 : probDensity[i]);
254 //_______________________________________________________________________
255 AliPID& AliPID::operator = (const AliPID& pid)
257 // assignment operator
260 fCharged = pid.fCharged;
261 for (Int_t i = 0; i < kSPECIESCN; i++) {
262 fProbDensity[i] = pid.fProbDensity[i];
268 //_______________________________________________________________________
272 // Initialise the masses
274 // Initialise only once...
275 if(!fgkParticleMass[0]) {
276 AliPDG::AddParticlesToPdgDataBase();
277 for (Int_t i = 0; i < kSPECIESC; i++) {
278 fgkParticleMass[i] = M(i);
279 if (i == kHe3 || i == kAlpha) fgkParticleMassZ[i] = M(i)/2.;
280 else fgkParticleMassZ[i]=M(i);
285 //_____________________________________________________________________________
286 Double_t AliPID::GetProbability(EParticleType iType,
287 const Double_t* prior) const
290 // Get the probability to be a particle of type "iType"
291 // assuming the a priori probabilities "prior"
294 Int_t nSpecies = ((fCharged) ? kSPECIESC : kSPECIESCN);
295 for (Int_t i = 0; i < nSpecies; i++) {
296 sum += fProbDensity[i] * prior[i];
299 AliError("Invalid probability densities or priors");
302 return fProbDensity[iType] * prior[iType] / sum;
305 //_____________________________________________________________________________
306 Double_t AliPID::GetProbability(EParticleType iType) const
308 // get the probability to be a particle of type "iType"
309 // assuming the globaly set a priori probabilities
311 return GetProbability(iType, fgPrior);
314 //_____________________________________________________________________________
315 void AliPID::GetProbabilities(Double_t* probabilities,
316 const Double_t* prior) const
318 // get the probabilities to be a particle of given type
319 // assuming the a priori probabilities "prior"
322 Int_t nSpecies = ((fCharged) ? kSPECIESC : kSPECIESCN);
323 for (Int_t i = 0; i < nSpecies; i++) {
324 sum += fProbDensity[i] * prior[i];
327 AliError("Invalid probability densities or priors");
328 for (Int_t i = 0; i < nSpecies; i++) probabilities[i] = -1;
331 for (Int_t i = 0; i < nSpecies; i++) {
332 probabilities[i] = fProbDensity[i] * prior[i] / sum;
336 //_____________________________________________________________________________
337 void AliPID::GetProbabilities(Double_t* probabilities) const
339 // get the probabilities to be a particle of given type
340 // assuming the globaly set a priori probabilities
342 GetProbabilities(probabilities, fgPrior);
345 //_____________________________________________________________________________
346 AliPID::EParticleType AliPID::GetMostProbable(const Double_t* prior) const
348 // get the most probable particle id hypothesis
349 // assuming the a priori probabilities "prior"
352 EParticleType id = kPion;
353 Int_t nSpecies = ((fCharged) ? kSPECIESC : kSPECIESCN);
354 for (Int_t i = 0; i < nSpecies; i++) {
355 Double_t prob = fProbDensity[i] * prior[i];
358 id = EParticleType(i);
362 AliError("Invalid probability densities or priors");
367 //_____________________________________________________________________________
368 AliPID::EParticleType AliPID::GetMostProbable() const
370 // get the most probable particle id hypothesis
371 // assuming the globaly set a priori probabilities
373 return GetMostProbable(fgPrior);
377 //_____________________________________________________________________________
378 void AliPID::SetPriors(const Double_t* prior, Bool_t charged)
380 // use the given priors as global a priori probabilities
383 for (Int_t i = 0; i < kSPECIESCN; i++) {
384 if (charged && (i >= kSPECIESC)) {
388 AliWarningClass(Form("negative prior (%g) for %ss. "
389 "Using 0 instead.", prior[i],
390 fgkParticleName[i]));
393 fgPrior[i] = prior[i];
399 AliWarningClass("all priors are zero.");
403 //_____________________________________________________________________________
404 void AliPID::SetPrior(EParticleType iType, Double_t prior)
406 // use the given prior as global a priori probability for particles
410 AliWarningClass(Form("negative prior (%g) for %ss. Using 0 instead.",
411 prior, fgkParticleName[iType]));
414 fgPrior[iType] = prior;
418 //_____________________________________________________________________________
419 AliPID& AliPID::operator *= (const AliPID& pid)
421 // combine this probability densities with the one of "pid"
423 for (Int_t i = 0; i < kSPECIESCN; i++) {
424 fProbDensity[i] *= pid.fProbDensity[i];
429 //_____________________________________________________________________________
430 AliPID operator * (const AliPID& pid1, const AliPID& pid2)
432 // combine the two probability densities