StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTpcDedxPidAlgorithm.cxx
1 /***************************************************************************
2  *
3  * $Id: StTpcDedxPidAlgorithm.cxx,v 2.31 2016/09/18 23:02:11 fisyak Exp $
4  *
5  * Author: Thomas Ullrich, Sep 1999
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StTpcDedxPidAlgorithm.cxx,v $
13  * Revision 2.31 2016/09/18 23:02:11 fisyak
14  * Add dNdx
15  *
16  * Revision 2.30 2014/01/09 20:06:45 fisyak
17  * Add numberOfSigma() for kLikelihoodFitId method
18  *
19  * Revision 2.29 2012/05/07 14:42:58 fisyak
20  * Add handilings for Track to Fast Detectors Matching
21  *
22  * Revision 2.28 2010/11/15 22:11:45 fisyak
23  * Restore proper nSigma
24  *
25  * Revision 2.27 2010/08/31 20:15:11 fisyak
26  * Clean up
27  *
28  * Revision 2.26 2008/03/13 16:56:39 ullrich
29  * Add protection against missing or wrong mTraits->mean()
30  *
31  * Revision 2.25 2005/05/13 20:31:14 fisyak
32  * Calculated nSigma wrt modified Bichsel I70M to account saturation
33  *
34  * Revision 2.24 2004/03/30 02:45:07 fisyak
35  * return DBL_MAX instead of 0 if No mTraits
36  *
37  * Revision 2.23 2003/10/25 00:12:48 fisyak
38  * Replace BetheBloch::Sirrf by m_Bichsel->GetI70 for nSigma calculations
39  *
40  * Revision 2.22 2003/10/21 14:23:23 fisyak
41  * Switch from primary to global track momentum for Nsigma calculations
42  *
43  * Revision 2.21 2003/09/02 17:58:06 perev
44  * gcc 3.2 updates + WarnOff
45  *
46  * Revision 2.20 2003/08/02 01:14:11 perev
47  * warnOff
48  *
49  * Revision 2.19 2003/04/30 18:05:55 fisyak
50  * Add P03ia flag, which fixes P03ia MuDst
51  *
52  * Revision 2.18 2002/04/04 01:42:34 jeromel
53  * Extra fix for multiple instantiation (and multiple delete).
54  *
55  * Revision 2.17 2002/04/01 20:13:56 jeromel
56  * Heuu !! if (theBetheBloch) delete ...
57  *
58  * Revision 2.16 2002/03/26 23:10:09 ullrich
59  * Changed instantiaton of BetheBloch.
60  *
61  * Revision 2.15 2002/03/25 21:02:51 ullrich
62  * Made BetheBloch a static global variable.
63  *
64  * Revision 2.14 2002/02/06 23:00:54 ullrich
65  * Added float.h.
66  *
67  * Revision 2.13 2001/04/27 21:41:07 ullrich
68  * Fixed bug.
69  *
70  * Revision 2.12 2001/04/24 15:38:08 fisyak
71  * Add switch (use length) for calibrated and non calibrated data
72  *
73  * Revision 2.11 2001/04/05 04:00:56 ullrich
74  * Replaced all (U)Long_t by (U)Int_t and all redundant ROOT typedefs.
75  *
76  * Revision 2.10 2000/10/26 18:33:20 calderon
77  * Return DBL_MAX in the numberOfSigma() function when
78  * the number of dE/dx points is equal to zero.
79  * The function sigmaPidFunction() already checked this, but
80  * when this happens, it probably means that mTraits->mean()
81  * is undefined, so it's better to exit immediately from the
82  * function.
83  *
84  * Revision 2.9 2000/07/28 16:55:35 calderon
85  * Mike's version of StTpcDedxPidAlgorithm using BetheBloch
86  * class lookup table from
87  * StarClassLibrary and parameterization of resolution obtained
88  * from the first two weeks of July 2000 Data.
89  *
90  * Revision 2.8 2000/05/19 18:33:45 ullrich
91  * Minor changes (add const) to cope with modified StArray.
92  *
93  * Revision 2.7 2000/04/20 16:47:31 ullrich
94  * Check for null pointer added.
95  *
96  * Revision 2.6 2000/03/02 12:43:49 ullrich
97  * Method can be passed as argument to constructor. Default
98  * method is truncated mean.
99  *
100  * Revision 2.5 1999/12/21 15:09:11 ullrich
101  * Modified to cope with new compiler version on Sun (CC5.0).
102  *
103  * Revision 2.4 1999/12/03 13:18:18 ullrich
104  * Fixed problem on Sun CC4.2 (dynamic_cast) and switched
105  * off cut on number of points.
106  *
107  * Revision 2.3 1999/12/02 16:35:34 ullrich
108  * Added method to return the stored dE/dx traits
109  *
110  * Revision 2.2 1999/10/28 22:27:01 ullrich
111  * Adapted new StArray version. First version to compile on Linux and Sun.
112  *
113  * Revision 2.1 1999/10/13 19:45:24 ullrich
114  * Initial Revision
115  *
116  **************************************************************************/
117 #include <typeinfo>
118 #include <cmath>
119 #include <float.h>
120 #include "StTpcDedxPidAlgorithm.h"
121 #include "StTrack.h"
122 #include "StGlobalTrack.h"
123 #include "StParticleTypes.hh"
124 #include "StEnumerations.h"
125 #include "StDedxPidTraits.h"
126 #include "StTrackNode.h"
127 #include "StTrackGeometry.h"
128 #if 0
129 #include "BetheBloch.h"
130 #endif
131 #include "StBichsel/Bichsel.h"
132 #include "StBichsel/StdEdxModel.h"
133 #include "TMath.h"
134 static Bichsel *m_Bichsel = 0;
135 static const char rcsid[] = "$Id: StTpcDedxPidAlgorithm.cxx,v 2.31 2016/09/18 23:02:11 fisyak Exp $";
136 
137 StTpcDedxPidAlgorithm::StTpcDedxPidAlgorithm(StDedxMethod dedxMethod)
138  : mTraits(0), mTrack(0), mDedxMethod(dedxMethod)
139 {
140  //
141  // Add all particles we want to get
142  // checked in operator().
143  //
144  mParticles.push_back(StPionMinus::instance());
145  mParticles.push_back(StPionPlus::instance());
146  mParticles.push_back(StKaonMinus::instance());
147  mParticles.push_back(StKaonPlus::instance());
148  mParticles.push_back(StProton::instance());
149 }
150 
152 StTpcDedxPidAlgorithm::operator() (const StTrack& track, const StSPtrVecTrackPidTraits& vec)
153 {
154  //
155  // Select the info we need.
156  // Here we ignore different kinds of dE/dx calculations in
157  // the TPC and select the method
158  //
159  mTraits = 0;
160  mTrack = &track;
161  for (UInt_t i=0; i<vec.size(); i++) {
162  const StDedxPidTraits *p = dynamic_cast<const StDedxPidTraits*>(vec[i]);
163  if (p && p->detector() == kTpcId && p->method() == mDedxMethod) mTraits = p;
164  }
165  if (!mTraits) return 0; // no info available
166 
167  //
168  // Scan the list of particles we want to check and
169  // return the most probable.
170  //
171  Double_t sigma, minSigma = 100000;
172  UInt_t minIndex = mParticles.size();
173  for (UInt_t k=0; k<mParticles.size(); k++) {
174  if (mParticles[k]->charge()*mTrack->geometry()->charge() > 0) { // require same charge sign
175  if ((sigma = fabs(numberOfSigma(mParticles[k]))) < minSigma) {
176  minIndex = k;
177  minSigma = fabs(sigma);
178  }
179  }
180  }
181  return minIndex < mParticles.size() ? mParticles[minIndex] : 0;
182 }
183 
184 Double_t
185 StTpcDedxPidAlgorithm::numberOfSigma(const StParticleDefinition* particle) const
186 {
187  if (!mTraits) return DBL_MAX;
188 
189  if (mTraits->numberOfPoints()==0) return DBL_MAX;
190  // sigmaPidFunction already checks this, but when number of dE/dx points is = 0,
191  // mTraits->mean() is probably undefined too (have to check this)
192  // so might as well exit here.
193 
194  // returns the number of sigma a tracks dedx is away from
195  // the expected mean for a track for a particle of this mass
196  Double_t dedx_expected;
197  Double_t dedx_resolution;
198  Double_t momentum;
199  Double_t z = -999;
200  if (mTraits->mean() > 0) {
201  const StGlobalTrack *gTrack =
202  static_cast<const StGlobalTrack*>( mTrack->node()->track(global));
203  if (gTrack && mTraits->length() > 0 ) {
204  Double_t pq = abs(gTrack->geometry()->momentum())*TMath::Abs(particle->charge());
205  Double_t bg = pq/particle->mass();
206  if (! m_Bichsel) m_Bichsel = Bichsel::Instance();
207  if (mDedxMethod == kTruncatedMeanId) {
208  Double_t log2dX = mTraits->log2dX();
209  if (log2dX <= 0) log2dX = 1;
210  dedx_expected = 1.e-6*m_Bichsel->GetI70M(TMath::Log10(bg),log2dX);
211  dedx_resolution = mTraits->errorOnMean();
212  if (dedx_resolution > 0)
213  z = TMath::Log(mTraits->mean()/dedx_expected)/dedx_resolution;
214  } else if (mDedxMethod == kLikelihoodFitId) {
215  dedx_expected = 1.e-6*TMath::Exp(m_Bichsel->GetMostProbableZ(TMath::Log10(bg)));
216  dedx_resolution = mTraits->errorOnMean();
217  if (dedx_resolution > 0)
218  z = TMath::Log(mTraits->mean()/dedx_expected)/dedx_resolution;
219  } else if (mDedxMethod == kOtherMethodId) {
220  dedx_expected = StdEdxModel::instance()->dNdx(bg);
221  dedx_resolution = mTraits->errorOnMean();
222  if (dedx_resolution > 0)
223  z = TMath::Log(mTraits->mean()/dedx_expected)/dedx_resolution;
224  }
225  }
226  }
227  return z;
228 }