StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_svtCorrectionC.cxx
1 #include <assert.h>
2 #include "TMath.h"
3 #include "St_svtCorrectionC.h"
4 ClassImp(St_svtCorrectionC);
5 //________________________________________________________________________________
6 Double_t St_svtCorrectionC::STcheb(Int_t N, Double_t *par, Double_t x) {// N polynome degree, dimension is par[N+1]
7  if (N < 0 || N > 12) return 0;
8  Double_t T0 = 1;
9  Double_t T1 = 2*x - 1;
10  Double_t T2;
11  Double_t Sum = par[0]*T0;
12  if (N >= 1) {
13  T1 = 2*x - 1;
14  Sum += par[1]*T1;
15  for (int n = 2; n <= N; n++) {
16  T2 = 2*(2*x - 1)*T1 - T0;
17  Sum += par[n]*T2;
18  T0 = T1;
19  T1 = T2;
20  }
21  }
22  return Sum;
23 }
24 //________________________________________________________________________________
25 svtCorrection_st *St_svtCorrectionC::pCorrection(Int_t layer, Int_t ladder, Int_t wafer, Int_t hybrid) {
26  St_svtCorrection *Table = (St_svtCorrection *) GetThisTable();
27  if (! Table) return 0;
28  svtCorrection_st *Data = Table->GetTable();
29  static Int_t N = 0;
30  static svtCorrection_st *pointers[6][16][7][2];
31  if (N == 0 || ! Table->IsMarked()) {
32  N = Table->GetNRows();
33  memset (pointers,0, 6*16*7*2*sizeof(svtCorrection_st *));
34  Table->Mark();
35  }
36  assert(layer >= 1 && layer <= 6);
37  assert(ladder >= 1 && ladder <= 16);
38  assert(wafer >= 1 && wafer <= 7);
39  svtCorrection_st *p = pointers[layer-1][ladder-1][wafer-1][hybrid-1];
40  if (! p) {
41  for (Int_t i = 0; i < N; i++) {
42  if (Data[i].layer == layer &&
43  Data[i].ladder == ladder &&
44  Data[i].wafer == wafer &&
45  Data[i].hybrid == hybrid) {
46  if (Data[i].Npar > -1) {
47  p = Data + i;
48  pointers[layer-1][ladder-1][wafer-1][hybrid-1] = p;
49  }
50  break;
51  }
52  }
53  }
54  return p;
55 }
56 //________________________________________________________________________________
57 Double_t St_svtCorrectionC::CalcCorrection(Int_t layer, Int_t ladder, Int_t wafer, Int_t hybrid, Double_t u) {
58  svtCorrection_st *p = pCorrection(layer, ladder, wafer, hybrid);
59  return p ? STcheb(p->Npar, p->param, TMath::Abs(u/3.)) : 0;
60 }