StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_svtHybridDriftVelocityC.cxx
1 #include <assert.h>
2 #include "TMath.h"
3 #include "TString.h"
4 #include "Stiostream.h"
5 #include "St_svtHybridDriftVelocityC.h"
7 St_svtHybridDriftVelocityC *St_svtHybridDriftVelocityC::fgsvtHybridDriftVelocityC = 0;
8 Double_t St_svtHybridDriftVelocityC::mAnodePitch = 0.0250;
9 Double_t St_svtHybridDriftVelocityC::mWaferLength = 2.9928;
10 Double_t St_svtHybridDriftVelocityC::mWaferWidth = 3.0000;
11 Double_t St_svtHybridDriftVelocityC::mNoAnodes = 2*St_svtHybridDriftVelocityC::mWaferWidth/St_svtHybridDriftVelocityC::mAnodePitch;
12 Double_t St_svtHybridDriftVelocityC::mSamplingFrequency = 25000000.0;
13 static const Int_t NB = 3;
14 static const Int_t NL = 16;
15 static const Int_t NW = 7;
16 static const Int_t NH = 2;
17 static svtHybridDriftVelocity_st *pointers[3][16][7][2];
18 static svtHybridDriftVelocity_st *DataOld = 0;
19 //________________________________________________________________________________
20 Double_t St_svtHybridDriftVelocityC::STcheb(Int_t N, Double_t *par, Double_t x) {// N polynome degree, dimension is par[N+1]
21  if (N < 0 || N > 12) return 0;
22  Double_t T0 = 1;
23  Double_t T1 = 2*x - 1;
24  Double_t T2;
25  Double_t Sum = par[0]*T0;
26  if (N >= 1) {
27  T1 = 2*x - 1;
28  Sum += par[1]*T1;
29  for (int n = 2; n <= N; n++) {
30  T2 = 2*(2*x - 1)*T1 - T0;
31  Sum += par[n]*T2;
32  T0 = T1;
33  T1 = T2;
34  }
35  }
36  return Sum;
37 }
38 //________________________________________________________________________________
39 St_svtHybridDriftVelocityC::St_svtHybridDriftVelocityC (St_svtHybridDriftVelocity *table) : TChair(table) {
40  if (fgsvtHybridDriftVelocityC) delete fgsvtHybridDriftVelocityC; fgsvtHybridDriftVelocityC = this;
41  Init();
42 }
43 //________________________________________________________________________________
44 void St_svtHybridDriftVelocityC::Init() {
45  memset (&pointers[0][0][0][0], 0, NB*NL*NW*NH*sizeof(svtHybridDriftVelocity_st *));
46  St_svtHybridDriftVelocity *Table = (St_svtHybridDriftVelocity *) GetThisTable();
47  if (Table) {
48  svtHybridDriftVelocity_st *Data = Table->GetTable();
49  DataOld = Data;
50  Int_t N = Table->GetNRows();
51  for (Int_t j = 0; j < N; j++, Data++) {
52  if (Data->barrel < 1 || Data->barrel > NB ||
53  Data->ladder < 1 || Data->ladder > NL ||
54  Data->wafer < 1 || Data->wafer > NW ||
55  Data->hybrid < 1 || Data->hybrid > NH) continue;
56  pointers[Data->barrel-1][Data->ladder-1][Data->wafer-1][Data->hybrid-1] = Data;
57  }
58  }
59 }
60 //________________________________________________________________________________
61 svtHybridDriftVelocity_st *St_svtHybridDriftVelocityC::p(Int_t barrel, Int_t ladder, Int_t wafer, Int_t hybrid) {
62  svtHybridDriftVelocity_st *p = 0;
63  if (! GetThisTable()) return p;
64  if (((St_svtHybridDriftVelocity *)GetThisTable())->GetTable() != DataOld) Init();
65  if (barrel >= 1 && barrel <= NB &&
66  ladder >= 1 && ladder <= NL &&
67  wafer >= 1 && wafer <= NW &&
68  hybrid >= 1 && hybrid <= NH) p = pointers[barrel-1][ladder-1][wafer-1][hybrid-1];
69  return p;
70 }
71 //________________________________________________________________________________
72 Double_t St_svtHybridDriftVelocityC::uHat(svtHybridDriftVelocity_st *p, Double_t timeBin) {
73  if (! p) return -99;
74  Double_t u = 1 - (timeBin - p->tmin)/(p->tmax - p->tmin);
75  if (p->hybrid == 1) u = -u;
76  return u;
77 }
78 //________________________________________________________________________________
79 Double_t St_svtHybridDriftVelocityC::vHat(svtHybridDriftVelocity_st *p, Double_t anode) {
80  if (! p) return -99;
81  Double_t v = 1 - anode/mNoAnodes;
82  if (p->hybrid == 1) v = -v;
83  return v;
84 }
85 //________________________________________________________________________________
86 Double_t St_svtHybridDriftVelocityC::CalcDriftLength(svtHybridDriftVelocity_st *p, Double_t timeBin, Double_t anode) {
87  if (! p) return -99;
88  Double_t u = uHat(p,timeBin);
89  Double_t uD = mWaferLength*u;
90  Double_t *coef = &p->v0;
91  Int_t nu = p->npar%10;
92  if (nu > 0) uD -= STcheb(nu-1, coef, TMath::Abs(u));
93  Int_t nv = (p->npar/10)%10;
94  if (nv > 0) {
95  Double_t v = vHat(p,anode);
96  uD -= STcheb(nv-1, &coef[nu], TMath::Abs(v));
97  }
98  return uD;
99 }
100 //________________________________________________________________________________
101 Double_t St_svtHybridDriftVelocityC::UnCalcDriftLength(svtHybridDriftVelocity_st *p, Double_t x) {
102  if (! p) return -99;
103  Double_t d = TMath::Min(mWaferLength,TMath::Max(0.,x));
104  return p->tmin + (p->tmax - p->tmin)*d/mWaferLength;
105 }
106 //________________________________________________________________________________
107 Double_t St_svtHybridDriftVelocityC::DriftVelocity(svtHybridDriftVelocity_st *p) {
108  return p ? mSamplingFrequency*mWaferLength/(p->tmax - p->tmin): -1;
109 }
110 //________________________________________________________________________________
111 Double_t St_svtHybridDriftVelocityC::CalcU(Int_t barrel, Int_t ladder, Int_t wafer, Int_t hybrid, Double_t timeBin, Double_t anode) {
112  return CalcDriftLength(barrel, ladder, wafer, hybrid, timeBin, anode);
113 }
114 //________________________________________________________________________________
115 Double_t St_svtHybridDriftVelocityC::CalcV(Int_t hybrid, Double_t x) {
116  Double_t vd = CalcTransLength(x);
117  if (hybrid == 1) vd = vd - WaferWidth();
118  else vd = WaferWidth() - vd;
119  return vd;
120 }
121 //________________________________________________________________________________
122 Double_t St_svtHybridDriftVelocityC::UnCalcU(Int_t barrel, Int_t ladder, Int_t wafer, Int_t hybrid, Double_t ud) {
123  if (hybrid == 1) ud = ud + WaferLength();
124  else ud = WaferLength() - ud;
125  return UnCalcDriftLength(barrel, ladder, wafer, hybrid, ud);
126 }
127 //________________________________________________________________________________
128 Double_t St_svtHybridDriftVelocityC::UnCalcV(Int_t hybrid, Double_t vd) {
129  if (hybrid == 1) vd = vd + WaferWidth();
130  else vd = WaferWidth() - vd;
131  return UnCalcTransLength(vd);
132 }
133 //________________________________________________________________________________
134 Bool_t St_svtHybridDriftVelocityC::IsValidDriftRegion(Int_t barrel, Int_t ladder, Int_t wafer, Int_t hybrid, Double_t timeBin) {
135  svtHybridDriftVelocity_st *pp = p(barrel, ladder, wafer, hybrid);
136  if (! pp) return kFALSE;
137  Int_t I = (pp->npar/100)%10;
138  if (! I) return kTRUE;
139  Double_t u = TMath::Abs(uHat(pp,timeBin));
140  if (u >= pp->dtmin && u <= pp->dtmax) return kTRUE;
141  return kFALSE;
142 }
Definition: TChair.h:27