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 ///////////////////////////////////////////////////////////////////////////////
45 #include <TDatabasePDG.h>
48 #define M(PID) TDatabasePDG::Instance()->GetParticle(fgkParticleCode[(PID)])->Mass()
53 const char* AliPID::fgkParticleName[AliPID::kSPECIESN+1] = {
67 const Int_t AliPID::fgkParticleCode[AliPID::kSPECIESN+1] = {
81 const Float_t AliPID::fgkParticleMass[AliPID::kSPECIESN+1] = {
82 M(kElectron), // electron
89 M(kNeutron), // neutron
91 M(kEleCon), // electron conversion
95 Double_t AliPID::fgPrior[kSPECIESN] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
98 //_______________________________________________________________________
103 // set default values (= equal probabilities)
105 for (Int_t i = 0; i < kSPECIESN; i++) {
106 fProbDensity[i] = 1./kSPECIESN;
110 //_______________________________________________________________________
111 AliPID::AliPID(const Double_t* probDensity, Bool_t charged) :
116 // set given probability densities
118 for (Int_t i = 0; i < kSPECIES; i++) {
119 fProbDensity[i] = probDensity[i];
121 for (Int_t i = kSPECIES; i < kSPECIESN; i++) {
122 fProbDensity[i] = ((charged) ? 0 : probDensity[i]);
126 //_______________________________________________________________________
127 AliPID::AliPID(const Float_t* probDensity, Bool_t charged) :
132 // set given probability densities
134 for (Int_t i = 0; i < kSPECIES; i++) {
135 fProbDensity[i] = probDensity[i];
137 for (Int_t i = kSPECIES; i < kSPECIESN; i++) {
138 fProbDensity[i] = ((charged) ? 0 : probDensity[i]);
142 //_______________________________________________________________________
143 AliPID::AliPID(const AliPID& pid) :
145 fCharged(pid.fCharged)
150 for (Int_t i = 0; i < kSPECIESN; i++) {
151 fProbDensity[i] = pid.fProbDensity[i];
155 //_______________________________________________________________________
156 AliPID& AliPID::operator = (const AliPID& pid)
158 // assignment operator
160 fCharged = pid.fCharged;
161 for (Int_t i = 0; i < kSPECIESN; i++) {
162 fProbDensity[i] = pid.fProbDensity[i];
168 //_____________________________________________________________________________
169 Double_t AliPID::GetProbability(EParticleType iType,
170 const Double_t* prior) const
172 // get the probability to be a particle of type "iType"
173 // assuming the a priori probabilities "prior"
176 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
177 for (Int_t i = 0; i < nSpecies; i++) {
178 sum += fProbDensity[i] * prior[i];
181 AliError("Invalid probability densities or priors");
184 return fProbDensity[iType] * prior[iType] / sum;
187 //_____________________________________________________________________________
188 Double_t AliPID::GetProbability(EParticleType iType) const
190 // get the probability to be a particle of type "iType"
191 // assuming the globaly set a priori probabilities
193 return GetProbability(iType, fgPrior);
196 //_____________________________________________________________________________
197 void AliPID::GetProbabilities(Double_t* probabilities,
198 const Double_t* prior) const
200 // get the probabilities to be a particle of given type
201 // assuming the a priori probabilities "prior"
204 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
205 for (Int_t i = 0; i < nSpecies; i++) {
206 sum += fProbDensity[i] * prior[i];
209 AliError("Invalid probability densities or priors");
210 for (Int_t i = 0; i < nSpecies; i++) probabilities[i] = -1;
213 for (Int_t i = 0; i < nSpecies; i++) {
214 probabilities[i] = fProbDensity[i] * prior[i] / sum;
218 //_____________________________________________________________________________
219 void AliPID::GetProbabilities(Double_t* probabilities) const
221 // get the probabilities to be a particle of given type
222 // assuming the globaly set a priori probabilities
224 GetProbabilities(probabilities, fgPrior);
227 //_____________________________________________________________________________
228 AliPID::EParticleType AliPID::GetMostProbable(const Double_t* prior) const
230 // get the most probable particle id hypothesis
231 // assuming the a priori probabilities "prior"
234 EParticleType id = kPion;
235 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
236 for (Int_t i = 0; i < nSpecies; i++) {
237 Double_t prob = fProbDensity[i] * prior[i];
240 id = EParticleType(i);
244 AliError("Invalid probability densities or priors");
249 //_____________________________________________________________________________
250 AliPID::EParticleType AliPID::GetMostProbable() const
252 // get the most probable particle id hypothesis
253 // assuming the globaly set a priori probabilities
255 return GetMostProbable(fgPrior);
259 //_____________________________________________________________________________
260 void AliPID::SetPriors(const Double_t* prior, Bool_t charged)
262 // use the given priors as global a priori probabilities
265 for (Int_t i = 0; i < kSPECIESN; i++) {
266 if (charged && (i >= kSPECIES)) {
270 AliWarningClass(Form("negative prior (%g) for %ss. "
271 "Using 0 instead.", prior[i],
272 fgkParticleName[i]));
275 fgPrior[i] = prior[i];
281 AliWarningClass("all priors are zero.");
285 //_____________________________________________________________________________
286 void AliPID::SetPrior(EParticleType iType, Double_t prior)
288 // use the given prior as global a priori probability for particles
292 AliWarningClass(Form("negative prior (%g) for %ss. Using 0 instead.",
293 prior, fgkParticleName[iType]));
296 fgPrior[iType] = prior;
300 //_____________________________________________________________________________
301 AliPID& AliPID::operator *= (const AliPID& pid)
303 // combine this probability densities with the one of "pid"
305 for (Int_t i = 0; i < kSPECIESN; i++) {
306 fProbDensity[i] *= pid.fProbDensity[i];
311 //_____________________________________________________________________________
312 AliPID operator * (const AliPID& pid1, const AliPID& pid2)
314 // combine the two probability densities