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 fLimitsRows.GetMatrixArray(),
116 fLimitsColumns.GetMatrixArray(),
117 fLimitsPhiSlices.GetMatrixArray(),
119 dx[1] = Interpolate3DTable(order, r, z, phi,
121 fLimitsRows.GetMatrixArray(),
122 fLimitsColumns.GetMatrixArray(),
123 fLimitsPhiSlices.GetMatrixArray(),
125 dx[2] = Interpolate3DTable(order, r, z, phi,
127 fLimitsRows.GetMatrixArray(),
128 fLimitsColumns.GetMatrixArray(),
129 fLimitsPhiSlices.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=fLimitsPhiSlices(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=fLimitsRows(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=fLimitsColumns(iz);
170 //TODO: change hardcoded value for r>133.?
171 Int_t roc=TMath::Nint(phi*TMath::RadToDeg()/20.)%18;
175 tpcCorr.GetDistortionIntegralDz(x,roc,dx,delta);
176 mDxDist(ir,iz)=dx[0];
177 mDyDist(ir,iz)=dx[1];
178 mDzDist(ir,iz)=dx[2];
180 tpcCorr.GetCorrectionIntegralDz(x,roc,dx,delta);
181 mDxCorr(ir,iz)=dx[0];
182 mDyCorr(ir,iz)=dx[1];
183 mDzCorr(ir,iz)=dx[2];
190 AliInfo("Required time for lookup table creation: %.2f (%.2f) sec. real (cpu)");
193 //_________________________________________________________________________________________
194 void AliTPCCorrectionLookupTable::InitTables()
199 fLookUpDxCorr = new TMatrixF*[fNPhi];
200 fLookUpDyCorr = new TMatrixF*[fNPhi];
201 fLookUpDzCorr = new TMatrixF*[fNPhi];
203 fLookUpDxDist = new TMatrixF*[fNPhi];
204 fLookUpDyDist = new TMatrixF*[fNPhi];
205 fLookUpDzDist = new TMatrixF*[fNPhi];
207 for (Int_t iPhi=0; iPhi<fNPhi; ++iPhi){
208 fLookUpDxCorr[iPhi] = new TMatrixF(fNR,fNZ);
209 fLookUpDyCorr[iPhi] = new TMatrixF(fNR,fNZ);
210 fLookUpDzCorr[iPhi] = new TMatrixF(fNR,fNZ);
212 fLookUpDxDist[iPhi] = new TMatrixF(fNR,fNZ);
213 fLookUpDyDist[iPhi] = new TMatrixF(fNR,fNZ);
214 fLookUpDzDist[iPhi] = new TMatrixF(fNR,fNZ);
217 SetupDefaultLimits();
220 //_________________________________________________________________________________________
221 void AliTPCCorrectionLookupTable::ResetTables()
224 // Reset the lookup tables
227 if (!fLookUpDxCorr) return;
229 for (Int_t iPhi=0; iPhi<fNPhi; ++iPhi){
230 delete fLookUpDxCorr[iPhi];
231 delete fLookUpDyCorr[iPhi];
232 delete fLookUpDzCorr[iPhi];
234 delete fLookUpDxDist[iPhi];
235 delete fLookUpDyDist[iPhi];
236 delete fLookUpDzDist[iPhi];
239 delete [] fLookUpDxCorr;
240 delete [] fLookUpDyCorr;
241 delete [] fLookUpDzCorr;
243 delete [] fLookUpDxDist;
244 delete [] fLookUpDyDist;
245 delete [] fLookUpDzDist;
255 fLimitsRows.ResizeTo(1);
256 fLimitsPhiSlices.ResizeTo(1);
257 fLimitsColumns.ResizeTo(1);
260 //_________________________________________________________________________________________
261 void AliTPCCorrectionLookupTable::SetupDefaultLimits()
264 // Set default limits for tables
267 fLimitsRows.ResizeTo(fNR);
268 fLimitsPhiSlices.ResizeTo(fNPhi);
269 fLimitsColumns.ResizeTo(fNZ);
271 Double_t *limRList = fLimitsRows.GetMatrixArray();
272 Double_t *limPhiList = fLimitsPhiSlices.GetMatrixArray();
273 Double_t *limZList = fLimitsColumns.GetMatrixArray();
275 AliTPCROC * roc = AliTPCROC::Instance();
276 const Double_t rLow = TMath::Floor(roc->GetPadRowRadii(0,0))-1; // first padRow plus some margin
280 for (Int_t i = 1; i<fNR; i++) {
281 limRList[i] = limRList[i-1] + 3.5; // 3.5 cm spacing
282 if (limRList[i]<90 ||limRList[i]>245){
283 limRList[i] = limRList[i-1] + 0.5; // 0.5 cm spacing
284 } else if (limRList[i]<100 || limRList[i]>235){
285 limRList[i] = limRList[i-1] + 1.5; // 1.5 cm spacing
286 } else if (limRList[i]<120 || limRList[i]>225){
287 limRList[i] = limRList[i-1] + 2.5; // 2.5 cm spacing
292 limZList[0] = -249.5;
293 limZList[fNZ-1] = 249.5;
294 for (Int_t j = 1; j<fNZ/2; j++) {
295 limZList[j] = limZList[j-1];
296 if (TMath::Abs(limZList[j])< 0.15){
297 limZList[j] = limZList[j-1] + 0.09; // 0.09 cm spacing
298 } else if(TMath::Abs(limZList[j])< 0.6){
299 limZList[j] = limZList[j-1] + 0.4; // 0.4 cm spacing
300 } else if (TMath::Abs(limZList[j])< 2.5 || TMath::Abs(limZList[j])>248){
301 limZList[j] = limZList[j-1] + 0.5; // 0.5 cm spacing
302 } else if (TMath::Abs(limZList[j])<10 || TMath::Abs(limZList[j])>235){
303 limZList[j] = limZList[j-1] + 1.5; // 1.5 cm spacing
304 } else if (TMath::Abs(limZList[j])<25 || TMath::Abs(limZList[j])>225){
305 limZList[j] = limZList[j-1] + 2.5; // 2.5 cm spacing
307 limZList[j] = limZList[j-1] + 4; // 4 cm spacing
310 limZList[fNZ-j-1] = -limZList[j];
314 for (Int_t k = 0; k<fNPhi; k++)
315 limPhiList[k] = TMath::TwoPi()*k/(fNPhi-1);