5 #include "St_svtHybridDriftVelocityC.h"
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;
20 Double_t St_svtHybridDriftVelocityC::STcheb(Int_t N, Double_t *par, Double_t x) {
21 if (N < 0 || N > 12)
return 0;
23 Double_t T1 = 2*x - 1;
25 Double_t Sum = par[0]*T0;
29 for (
int n = 2; n <= N; n++) {
30 T2 = 2*(2*x - 1)*T1 - T0;
39 St_svtHybridDriftVelocityC::St_svtHybridDriftVelocityC (St_svtHybridDriftVelocity *table) :
TChair(table) {
40 if (fgsvtHybridDriftVelocityC)
delete fgsvtHybridDriftVelocityC; fgsvtHybridDriftVelocityC =
this;
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();
48 svtHybridDriftVelocity_st *Data = Table->GetTable();
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;
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];
72 Double_t St_svtHybridDriftVelocityC::uHat(svtHybridDriftVelocity_st *p, Double_t timeBin) {
74 Double_t u = 1 - (timeBin - p->tmin)/(p->tmax - p->tmin);
75 if (p->hybrid == 1) u = -u;
79 Double_t St_svtHybridDriftVelocityC::vHat(svtHybridDriftVelocity_st *p, Double_t anode) {
81 Double_t v = 1 - anode/mNoAnodes;
82 if (p->hybrid == 1) v = -v;
86 Double_t St_svtHybridDriftVelocityC::CalcDriftLength(svtHybridDriftVelocity_st *p, Double_t timeBin, Double_t anode) {
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;
95 Double_t v = vHat(p,anode);
96 uD -= STcheb(nv-1, &coef[nu], TMath::Abs(v));
101 Double_t St_svtHybridDriftVelocityC::UnCalcDriftLength(svtHybridDriftVelocity_st *p, Double_t x) {
103 Double_t d = TMath::Min(mWaferLength,TMath::Max(0.,x));
104 return p->tmin + (p->tmax - p->tmin)*d/mWaferLength;
107 Double_t St_svtHybridDriftVelocityC::DriftVelocity(svtHybridDriftVelocity_st *p) {
108 return p ? mSamplingFrequency*mWaferLength/(p->tmax - p->tmin): -1;
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);
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;
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);
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);
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;