StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDetectorDbInterpolator.h
1 #ifndef StDetectorDbInterpolator_h
2 #define StDetectorDbInterpolator_h
3 
18 template<class T>
20 public:
21  StDetectorDbInterpolator(unsigned int numEntries,unsigned int* times,T* array);
22  T interpolate(unsigned int time);
23  T getLowerValue(unsigned int time);
24 private:
25  unsigned int mNumEntries;
26  unsigned int* mTimes;
27  T* mArray;
28 };
29 
31 template<class T>
32 StDetectorDbInterpolator<T>::StDetectorDbInterpolator(unsigned int numEntries,unsigned int* times,T* array){
33  mNumEntries = numEntries;
34  mTimes = times;
35  mArray = array;
36 };
37 
39 template<class T>
41 
42  if( mNumEntries == 0)
43  return 0;
44 
45  if(time <= mTimes[0])
46  return mArray[0];
47  if(time >= mTimes[mNumEntries-1])
48  return mArray[mNumEntries-1];
49  unsigned int i = 0;
50  while(mTimes[i] < time && i < mNumEntries)
51  i++;
52  double relTime = (time - mTimes[i-1]);
53  double denominator = (mTimes[i]-mTimes[i-1]);
54 
55  if(denominator == 0)
56  return mArray[i];
57  else
58  return (relTime/denominator)*(mArray[i]-mArray[i-1])+mArray[i-1];
59 
60 };
61 
65 template<class T>
67 
68  if( mNumEntries == 0)
69  return 0;
70 
71  if(time <= mTimes[0])
72  return mArray[0];
73  if(time >= mTimes[mNumEntries-1])
74  return mArray[mNumEntries-1];
75 
76  unsigned int i = 0;
77 
78 
79  while(mTimes[i] < time && i < mNumEntries){
80  i++;
81  }
82 
83  if(i > 0){
84  i--;
85  }
86 
87  return mArray[i];
88 
89 };
90 
91 #endif
StDetectorDbInterpolator(unsigned int numEntries, unsigned int *times, T *array)
Constructor for time interpolator.
T interpolate(unsigned int time)
Interpolates value based on timestamp.
T getLowerValue(unsigned int time)