StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StProbPidTraits.cxx
1 /***************************************************************************
2  *
3  * $Id: StProbPidTraits.cxx,v 2.5 2004/07/21 14:09:57 fisyak Exp $
4  *
5  * Author: Yuri Fisyak, Oct 2002
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StProbPidTraits.cxx,v $
13  * Revision 2.5 2004/07/21 14:09:57 fisyak
14  * Add GetChi2Prob method
15  *
16  * Revision 2.4 2004/07/15 16:36:24 ullrich
17  * Removed all clone() declerations and definitions. Use StObject::clone() only.
18  *
19  * Revision 2.3 2003/09/07 03:49:02 perev
20  * gcc 3.2 + WarnOff
21  *
22  * Revision 2.2 2003/09/02 17:58:05 perev
23  * gcc 3.2 updates + WarnOff
24  *
25  * Revision 2.1 2002/10/31 22:47:11 fisyak
26  * Add new class to keep H.Bichsel probabilities for each mass hypothesis
27  *
28  **************************************************************************/
29 #include <Stiostream.h>
30 #include "StProbPidTraits.h"
31 #include "StParticleTypes.hh"
32 #include "TMath.h"
33 ClassImp(StProbPidTraits)
34 
35 static const char rcsid[] = "$Id: StProbPidTraits.cxx,v 2.5 2004/07/21 14:09:57 fisyak Exp $";
36 StParticleDefinition *StProbPidTraits::mPidParticleDefinitions[KPidParticles] = {
37  StElectron::instance(),
38  StProton::instance(),
39  StKaonMinus::instance(),
40  StPionMinus::instance(),
41  StMuonMinus::instance(),
42  StDeuteron::instance(),
43  StTriton::instance(),
44  StHe3::instance(),
45  StAlpha::instance()
46 };
47 
48 //________________________________________________________________________________
49 StProbPidTraits::StProbPidTraits(const Int_t NDF, const StDetectorId Id, const StPidParticle N,
50  const Float_t *PidArray, Double_t *Fractions) :
51  StTrackPidTraits(Id), mNDF(NDF), mSum(0), mFractions(Fractions) {
52  if (PidArray) mPidArray = new TArrayF(N,PidArray);
53  else mPidArray = new TArrayF(N);
54  }
55 
56 //________________________________________________________________________________
57 StProbPidTraits::~StProbPidTraits() { delete mPidArray;}
58 
59 //________________________________________________________________________________
60 Double_t StProbPidTraits::GetProbability(Int_t PartId) {
61  if (mSum > 0) return mProbability[PartId];
62  Int_t N = mPidArray->GetSize();
63  mSum = 0;
64  memset(&mProbability[0],0,KPidParticles*sizeof(Double_t));
65  const Float_t *Array = mPidArray->GetArray();
66  Int_t i;
67  for (i=kPidElectron; i< N; i++) {
68  if (mFractions)
69  mProbability[i] = TMath::Exp(-Array[i]/2.)*mFractions[i];
70  else
71  mProbability[i] = TMath::Exp(-Array[i]/2.);
72  mSum += mProbability[i];
73  }
74  if (mSum > 0) for (i=kPidElectron; i< N; i++) mProbability[i] /= mSum;
75  return mSum > 0 ? mProbability[PartId] : 0;
76 }
77 //________________________________________________________________________________
78 Double_t StProbPidTraits::GetChi2Prob(Int_t k) const {
79  if (mNDF < 1 || ! mPidArray ) return -1;
80  Int_t N = mPidArray->GetSize();
81  if (k >= N) return -1;
82  const Float_t *Array = mPidArray->GetArray();
83  return TMath::Prob(Array[k],mNDF);
84 }
85 //________________________________________________________________________________
86 void StProbPidTraits::Print(Option_t *opt) const {
87  StProbPidTraits *This = (StProbPidTraits *) this;
88  Int_t N = mPidArray->GetSize();
89  const Float_t *Array = mPidArray->GetArray();
90  Int_t i;
91  cout << "\tNDF = \t" << mNDF << endl;
92  for (i = kPidElectron; i < N; i++) {
93  cout << "Particle : \t" << mPidParticleDefinitions[i]->name();
94  if (mFractions) cout << "\tFraction : \t" << mFractions[i];
95  cout << "\tProbability :\t" << This->GetProbability(i)
96  << "\tChisq :\t" << Array[i];
97  if (mNDF > 0) cout << "\t Chisq Prob:\t" << GetChi2Prob(i);
98  cout << endl;
99  }
100 }