1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include <TStopwatch.h>
21 #include <AliTPCROC.h>
23 #include "AliTPCCorrection.h"
25 #include "AliTPCCorrectionLookupTable.h"
27 ClassImp(AliTPCCorrectionLookupTable)
29 //_________________________________________________________________________________________
30 AliTPCCorrectionLookupTable::AliTPCCorrectionLookupTable()
49 //_________________________________________________________________________________________
50 AliTPCCorrectionLookupTable::~AliTPCCorrectionLookupTable()
59 //_________________________________________________________________________________________
60 void AliTPCCorrectionLookupTable::GetDistortion(const Float_t x[],const Short_t roc,Float_t dx[]) {
62 // Get interpolated Distortion
65 GetInterpolation(x,roc,dx,fLookUpDxDist,fLookUpDyDist,fLookUpDzDist);
68 //_________________________________________________________________________________________
69 void AliTPCCorrectionLookupTable::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
71 // Get interplolated correction
73 GetInterpolation(x,roc,dx,fLookUpDxCorr,fLookUpDyCorr,fLookUpDzCorr);
76 //_________________________________________________________________________________________
77 void AliTPCCorrectionLookupTable::GetInterpolation(const Float_t x[],const Short_t roc,Float_t dx[],
78 TMatrixF **mDx, TMatrixF **mDy, TMatrixF **mDz)
81 // Calculates the correction/distotring from a lookup table
82 // type: 0 = correction
86 // Float_t typeSign=-1;
87 // if (type==1) typeSign=1;
89 Int_t order = 1 ; // FIXME: hardcoded? Linear interpolation = 1, Quadratic = 2
94 r = TMath::Sqrt( x[0]*x[0] + x[1]*x[1] ) ;
95 phi = TMath::ATan2(x[1],x[0]) ;
96 if ( phi < 0 ) phi += TMath::TwoPi() ; // Table uses phi from 0 to 2*Pi
97 z = x[2] ; // Create temporary copy of x[2]
99 if ( (roc%36) < 18 ) {
100 sign = 1; // (TPC A side)
102 sign = -1; // (TPC C side)
105 if ( sign==1 && z < fgkZOffSet ) z = fgkZOffSet; // Protect against discontinuity at CE
106 if ( sign==-1 && z > -fgkZOffSet ) z = -fgkZOffSet; // Protect against discontinuity at CE
109 if ( (sign==1 && z<0) || (sign==-1 && z>0) ) // just a consistency check
110 AliError("ROC number does not correspond to z coordinate! Calculation of distortions is most likely wrong!");
112 // Get the Er and Ephi field integrals plus the integral over Z
113 dx[0] = Interpolate3DTable(order, r, z, phi,
115 fLimitsR.GetMatrixArray(),
116 fLimitsZ.GetMatrixArray(),
117 fLimitsPhi.GetMatrixArray(),
119 dx[1] = Interpolate3DTable(order, r, z, phi,
121 fLimitsR.GetMatrixArray(),
122 fLimitsZ.GetMatrixArray(),
123 fLimitsPhi.GetMatrixArray(),
125 dx[2] = Interpolate3DTable(order, r, z, phi,
127 fLimitsR.GetMatrixArray(),
128 fLimitsZ.GetMatrixArray(),
129 fLimitsPhi.GetMatrixArray(),
133 //_________________________________________________________________________________________
134 void AliTPCCorrectionLookupTable::CreateLookupTable(AliTPCCorrection &tpcCorr, Float_t stepSize/*=5.*/)
140 // create distortion lookup table
147 const Float_t delta=stepSize; // 5cm
148 Float_t x[3]={0.,0.,0.};
149 Float_t dx[3]={0.,0.,0.};
151 for (Int_t iPhi=0; iPhi<fNPhi; ++iPhi){
152 Double_t phi=fLimitsPhi(iPhi);
154 TMatrixF &mDxDist = *fLookUpDxDist[iPhi];
155 TMatrixF &mDyDist = *fLookUpDyDist[iPhi];
156 TMatrixF &mDzDist = *fLookUpDzDist[iPhi];
158 TMatrixF &mDxCorr = *fLookUpDxCorr[iPhi];
159 TMatrixF &mDyCorr = *fLookUpDyCorr[iPhi];
160 TMatrixF &mDzCorr = *fLookUpDzCorr[iPhi];
162 for (Int_t ir=0; ir<fNR; ++ir){
163 Double_t r=fLimitsR(ir);
164 x[0]=r * TMath::Cos(phi);
165 x[1]=r * TMath::Sin(phi);
167 for (Int_t iz=0; iz<fNZ; ++iz){
168 Double_t z=fLimitsZ(iz);
170 //TODO: change hardcoded value for r>133.?
171 Int_t roc=TMath::Nint(phi*TMath::RadToDeg()/20.)%18;
176 tpcCorr.GetDistortionIntegralDz(x,roc,dx,delta);
178 tpcCorr.GetDistortion(x,roc,dx);
179 mDxDist(ir,iz)=dx[0];
180 mDyDist(ir,iz)=dx[1];
181 mDzDist(ir,iz)=dx[2];
184 tpcCorr.GetCorrectionIntegralDz(x,roc,dx,delta);
186 tpcCorr.GetCorrection(x,roc,dx);
187 mDxCorr(ir,iz)=dx[0];
188 mDyCorr(ir,iz)=dx[1];
189 mDzCorr(ir,iz)=dx[2];
196 AliInfo("Required time for lookup table creation: %.2f (%.2f) sec. real (cpu)");
199 //_________________________________________________________________________________________
200 void AliTPCCorrectionLookupTable::InitTables()
205 fLookUpDxCorr = new TMatrixF*[fNPhi];
206 fLookUpDyCorr = new TMatrixF*[fNPhi];
207 fLookUpDzCorr = new TMatrixF*[fNPhi];
209 fLookUpDxDist = new TMatrixF*[fNPhi];
210 fLookUpDyDist = new TMatrixF*[fNPhi];
211 fLookUpDzDist = new TMatrixF*[fNPhi];
213 for (Int_t iPhi=0; iPhi<fNPhi; ++iPhi){
214 fLookUpDxCorr[iPhi] = new TMatrixF(fNR,fNZ);
215 fLookUpDyCorr[iPhi] = new TMatrixF(fNR,fNZ);
216 fLookUpDzCorr[iPhi] = new TMatrixF(fNR,fNZ);
218 fLookUpDxDist[iPhi] = new TMatrixF(fNR,fNZ);
219 fLookUpDyDist[iPhi] = new TMatrixF(fNR,fNZ);
220 fLookUpDzDist[iPhi] = new TMatrixF(fNR,fNZ);
223 SetupDefaultLimits();
226 //_________________________________________________________________________________________
227 void AliTPCCorrectionLookupTable::ResetTables()
230 // Reset the lookup tables
233 if (!fLookUpDxCorr) return;
235 for (Int_t iPhi=0; iPhi<fNPhi; ++iPhi){
236 delete fLookUpDxCorr[iPhi];
237 delete fLookUpDyCorr[iPhi];
238 delete fLookUpDzCorr[iPhi];
240 delete fLookUpDxDist[iPhi];
241 delete fLookUpDyDist[iPhi];
242 delete fLookUpDzDist[iPhi];
245 delete [] fLookUpDxCorr;
246 delete [] fLookUpDyCorr;
247 delete [] fLookUpDzCorr;
249 delete [] fLookUpDxDist;
250 delete [] fLookUpDyDist;
251 delete [] fLookUpDzDist;
261 fLimitsR.ResizeTo(1);
262 fLimitsPhi.ResizeTo(1);
263 fLimitsZ.ResizeTo(1);
266 //_________________________________________________________________________________________
267 void AliTPCCorrectionLookupTable::SetupDefaultLimits()
270 // Set default limits for tables
276 fLimitsR. ResizeTo(fNR);
277 fLimitsPhi.ResizeTo(fNPhi);
278 fLimitsZ. ResizeTo(fNZ);
279 fLimitsR. SetElements(fgkRList);
280 fLimitsPhi.SetElements(fgkPhiList);
281 fLimitsZ. SetElements(fgkZList);