00001 #include <assert.h>
00002 #include "TMath.h"
00003 #include "St_svtCorrectionC.h"
00004 ClassImp(St_svtCorrectionC);
00005
00006 Double_t St_svtCorrectionC::STcheb(Int_t N, Double_t *par, Double_t x) {
00007 if (N < 0 || N > 12) return 0;
00008 Double_t T0 = 1;
00009 Double_t T1 = 2*x - 1;
00010 Double_t T2;
00011 Double_t Sum = par[0]*T0;
00012 if (N >= 1) {
00013 T1 = 2*x - 1;
00014 Sum += par[1]*T1;
00015 for (int n = 2; n <= N; n++) {
00016 T2 = 2*(2*x - 1)*T1 - T0;
00017 Sum += par[n]*T2;
00018 T0 = T1;
00019 T1 = T2;
00020 }
00021 }
00022 return Sum;
00023 }
00024
00025 svtCorrection_st *St_svtCorrectionC::pCorrection(Int_t layer, Int_t ladder, Int_t wafer, Int_t hybrid) {
00026 St_svtCorrection *Table = (St_svtCorrection *) GetThisTable();
00027 if (! Table) return 0;
00028 svtCorrection_st *Data = Table->GetTable();
00029 static Int_t N = 0;
00030 static svtCorrection_st *pointers[6][16][7][2];
00031 if (N == 0 || ! Table->IsMarked()) {
00032 N = Table->GetNRows();
00033 memset (pointers,0, 6*16*7*2*sizeof(svtCorrection_st *));
00034 Table->Mark();
00035 }
00036 assert(layer >= 1 && layer <= 6);
00037 assert(ladder >= 1 && ladder <= 16);
00038 assert(wafer >= 1 && wafer <= 7);
00039 svtCorrection_st *p = pointers[layer-1][ladder-1][wafer-1][hybrid-1];
00040 if (! p) {
00041 for (Int_t i = 0; i < N; i++) {
00042 if (Data[i].layer == layer &&
00043 Data[i].ladder == ladder &&
00044 Data[i].wafer == wafer &&
00045 Data[i].hybrid == hybrid) {
00046 if (Data[i].Npar > -1) {
00047 p = Data + i;
00048 pointers[layer-1][ladder-1][wafer-1][hybrid-1] = p;
00049 }
00050 break;
00051 }
00052 }
00053 }
00054 return p;
00055 }
00056
00057 Double_t St_svtCorrectionC::CalcCorrection(Int_t layer, Int_t ladder, Int_t wafer, Int_t hybrid, Double_t u) {
00058 svtCorrection_st *p = pCorrection(layer, ladder, wafer, hybrid);
00059 return p ? STcheb(p->Npar, p->param, TMath::Abs(u/3.)) : 0;
00060 }