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::kSPECIESN+AliPID::kSPECIESLN+1] = {
71 const char* AliPID::fgkParticleShortName[AliPID::kSPECIESN+AliPID::kSPECIESLN+1] = {
89 const char* AliPID::fgkParticleLatexName[AliPID::kSPECIESN+AliPID::kSPECIESLN+1] = {
107 const Int_t AliPID::fgkParticleCode[AliPID::kSPECIESN+AliPID::kSPECIESLN+1] = {
125 /*const*/ Float_t AliPID::fgkParticleMass[AliPID::kSPECIESN+AliPID::kSPECIESLN+1] = {
126 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
128 M(kElectron), // electron
132 M(kProton), // proton
133 M(kPhoton), // photon
135 M(kNeutron), // neutron
137 M(kEleCon), // electron conversion
138 M(kDeuteron), // deuteron
139 M(kTriton), // triton
146 Double_t AliPID::fgPrior[kSPECIESN] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
149 //_______________________________________________________________________
155 // Default constructor
158 // set default values (= equal probabilities)
159 for (Int_t i = 0; i < kSPECIESN; i++)
160 fProbDensity[i] = 1./kSPECIESN;
163 //_______________________________________________________________________
164 AliPID::AliPID(const Double_t* probDensity, Bool_t charged) :
169 // Standard constructor
172 // set given probability densities
173 for (Int_t i = 0; i < kSPECIES; i++)
174 fProbDensity[i] = probDensity[i];
176 for (Int_t i = kSPECIES; i < kSPECIESN; i++)
177 fProbDensity[i] = ((charged) ? 0 : probDensity[i]);
180 //_______________________________________________________________________
181 AliPID::AliPID(const Float_t* probDensity, Bool_t charged) :
186 // Standard constructor
189 // set given probability densities
190 for (Int_t i = 0; i < kSPECIES; i++)
191 fProbDensity[i] = probDensity[i];
193 for (Int_t i = kSPECIES; i < kSPECIESN; i++)
194 fProbDensity[i] = ((charged) ? 0 : probDensity[i]);
197 //_______________________________________________________________________
198 AliPID::AliPID(const AliPID& pid) :
200 fCharged(pid.fCharged)
205 // We do not call init here, MUST already be done
206 for (Int_t i = 0; i < kSPECIESN; i++)
207 fProbDensity[i] = pid.fProbDensity[i];
210 //_______________________________________________________________________
211 void AliPID::SetProbabilities(const Double_t* probDensity, Bool_t charged)
214 // Set the probability densities
216 for (Int_t i = 0; i < kSPECIES; i++)
217 fProbDensity[i] = probDensity[i];
219 for (Int_t i = kSPECIES; i < kSPECIESN; i++)
220 fProbDensity[i] = ((charged) ? 0 : probDensity[i]);
223 //_______________________________________________________________________
224 AliPID& AliPID::operator = (const AliPID& pid)
226 // assignment operator
228 fCharged = pid.fCharged;
229 for (Int_t i = 0; i < kSPECIESN; i++) {
230 fProbDensity[i] = pid.fProbDensity[i];
235 //_______________________________________________________________________
239 // Initialise the masses
241 // Initialise only once...
242 if(!fgkParticleMass[0]) {
243 AliPDG::AddParticlesToPdgDataBase();
244 for (Int_t i = 0; i < kSPECIESN + kSPECIESLN; i++)
245 fgkParticleMass[i] = M(i);
249 //_____________________________________________________________________________
250 Double_t AliPID::GetProbability(EParticleType iType,
251 const Double_t* prior) const
254 // Get the probability to be a particle of type "iType"
255 // assuming the a priori probabilities "prior"
258 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
259 for (Int_t i = 0; i < nSpecies; i++) {
260 sum += fProbDensity[i] * prior[i];
263 AliError("Invalid probability densities or priors");
266 return fProbDensity[iType] * prior[iType] / sum;
269 //_____________________________________________________________________________
270 Double_t AliPID::GetProbability(EParticleType iType) const
272 // get the probability to be a particle of type "iType"
273 // assuming the globaly set a priori probabilities
275 return GetProbability(iType, fgPrior);
278 //_____________________________________________________________________________
279 void AliPID::GetProbabilities(Double_t* probabilities,
280 const Double_t* prior) const
282 // get the probabilities to be a particle of given type
283 // assuming the a priori probabilities "prior"
286 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
287 for (Int_t i = 0; i < nSpecies; i++) {
288 sum += fProbDensity[i] * prior[i];
291 AliError("Invalid probability densities or priors");
292 for (Int_t i = 0; i < nSpecies; i++) probabilities[i] = -1;
295 for (Int_t i = 0; i < nSpecies; i++) {
296 probabilities[i] = fProbDensity[i] * prior[i] / sum;
300 //_____________________________________________________________________________
301 void AliPID::GetProbabilities(Double_t* probabilities) const
303 // get the probabilities to be a particle of given type
304 // assuming the globaly set a priori probabilities
306 GetProbabilities(probabilities, fgPrior);
309 //_____________________________________________________________________________
310 AliPID::EParticleType AliPID::GetMostProbable(const Double_t* prior) const
312 // get the most probable particle id hypothesis
313 // assuming the a priori probabilities "prior"
316 EParticleType id = kPion;
317 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
318 for (Int_t i = 0; i < nSpecies; i++) {
319 Double_t prob = fProbDensity[i] * prior[i];
322 id = EParticleType(i);
326 AliError("Invalid probability densities or priors");
331 //_____________________________________________________________________________
332 AliPID::EParticleType AliPID::GetMostProbable() const
334 // get the most probable particle id hypothesis
335 // assuming the globaly set a priori probabilities
337 return GetMostProbable(fgPrior);
341 //_____________________________________________________________________________
342 void AliPID::SetPriors(const Double_t* prior, Bool_t charged)
344 // use the given priors as global a priori probabilities
347 for (Int_t i = 0; i < kSPECIESN; i++) {
348 if (charged && (i >= kSPECIES)) {
352 AliWarningClass(Form("negative prior (%g) for %ss. "
353 "Using 0 instead.", prior[i],
354 fgkParticleName[i]));
357 fgPrior[i] = prior[i];
363 AliWarningClass("all priors are zero.");
367 //_____________________________________________________________________________
368 void AliPID::SetPrior(EParticleType iType, Double_t prior)
370 // use the given prior as global a priori probability for particles
374 AliWarningClass(Form("negative prior (%g) for %ss. Using 0 instead.",
375 prior, fgkParticleName[iType]));
378 fgPrior[iType] = prior;
382 //_____________________________________________________________________________
383 AliPID& AliPID::operator *= (const AliPID& pid)
385 // combine this probability densities with the one of "pid"
387 for (Int_t i = 0; i < kSPECIESN; i++) {
388 fProbDensity[i] *= pid.fProbDensity[i];
393 //_____________________________________________________________________________
394 AliPID operator * (const AliPID& pid1, const AliPID& pid2)
396 // combine the two probability densities