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
229 fCharged = pid.fCharged;
230 for (Int_t i = 0; i < kSPECIESN; i++) {
231 fProbDensity[i] = pid.fProbDensity[i];
237 //_______________________________________________________________________
241 // Initialise the masses
243 // Initialise only once...
244 if(!fgkParticleMass[0]) {
245 AliPDG::AddParticlesToPdgDataBase();
246 for (Int_t i = 0; i < kSPECIESN + kSPECIESLN; i++)
247 fgkParticleMass[i] = M(i);
251 //_____________________________________________________________________________
252 Double_t AliPID::GetProbability(EParticleType iType,
253 const Double_t* prior) const
256 // Get the probability to be a particle of type "iType"
257 // assuming the a priori probabilities "prior"
260 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
261 for (Int_t i = 0; i < nSpecies; i++) {
262 sum += fProbDensity[i] * prior[i];
265 AliError("Invalid probability densities or priors");
268 return fProbDensity[iType] * prior[iType] / sum;
271 //_____________________________________________________________________________
272 Double_t AliPID::GetProbability(EParticleType iType) const
274 // get the probability to be a particle of type "iType"
275 // assuming the globaly set a priori probabilities
277 return GetProbability(iType, fgPrior);
280 //_____________________________________________________________________________
281 void AliPID::GetProbabilities(Double_t* probabilities,
282 const Double_t* prior) const
284 // get the probabilities to be a particle of given type
285 // assuming the a priori probabilities "prior"
288 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
289 for (Int_t i = 0; i < nSpecies; i++) {
290 sum += fProbDensity[i] * prior[i];
293 AliError("Invalid probability densities or priors");
294 for (Int_t i = 0; i < nSpecies; i++) probabilities[i] = -1;
297 for (Int_t i = 0; i < nSpecies; i++) {
298 probabilities[i] = fProbDensity[i] * prior[i] / sum;
302 //_____________________________________________________________________________
303 void AliPID::GetProbabilities(Double_t* probabilities) const
305 // get the probabilities to be a particle of given type
306 // assuming the globaly set a priori probabilities
308 GetProbabilities(probabilities, fgPrior);
311 //_____________________________________________________________________________
312 AliPID::EParticleType AliPID::GetMostProbable(const Double_t* prior) const
314 // get the most probable particle id hypothesis
315 // assuming the a priori probabilities "prior"
318 EParticleType id = kPion;
319 Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN);
320 for (Int_t i = 0; i < nSpecies; i++) {
321 Double_t prob = fProbDensity[i] * prior[i];
324 id = EParticleType(i);
328 AliError("Invalid probability densities or priors");
333 //_____________________________________________________________________________
334 AliPID::EParticleType AliPID::GetMostProbable() const
336 // get the most probable particle id hypothesis
337 // assuming the globaly set a priori probabilities
339 return GetMostProbable(fgPrior);
343 //_____________________________________________________________________________
344 void AliPID::SetPriors(const Double_t* prior, Bool_t charged)
346 // use the given priors as global a priori probabilities
349 for (Int_t i = 0; i < kSPECIESN; i++) {
350 if (charged && (i >= kSPECIES)) {
354 AliWarningClass(Form("negative prior (%g) for %ss. "
355 "Using 0 instead.", prior[i],
356 fgkParticleName[i]));
359 fgPrior[i] = prior[i];
365 AliWarningClass("all priors are zero.");
369 //_____________________________________________________________________________
370 void AliPID::SetPrior(EParticleType iType, Double_t prior)
372 // use the given prior as global a priori probability for particles
376 AliWarningClass(Form("negative prior (%g) for %ss. Using 0 instead.",
377 prior, fgkParticleName[iType]));
380 fgPrior[iType] = prior;
384 //_____________________________________________________________________________
385 AliPID& AliPID::operator *= (const AliPID& pid)
387 // combine this probability densities with the one of "pid"
389 for (Int_t i = 0; i < kSPECIESN; i++) {
390 fProbDensity[i] *= pid.fProbDensity[i];
395 //_____________________________________________________________________________
396 AliPID operator * (const AliPID& pid1, const AliPID& pid2)
398 // combine the two probability densities