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 **************************************************************************/
16 //////////////////////////////////////////////////////////////////////////////
18 // AliTPCROCVoltError3D class //
19 // The class calculates the space point distortions due to residual voltage //
20 // errors on Read Out Chambers of the TPC in 3D. //
22 // The class allows "effective Omega Tau" corrections. //
24 // NOTE: This class is capable of calculating z distortions due to //
25 // misalignment and the vd dependency on the residual drift field //
27 // date: 08/08/2010 //
28 // Authors: Jim Thomas, Stefan Rossegger //
31 // AliTPCROCVoltError3D ROCerror; //
32 //////////////////////////////////////////////////////////////////////////////
35 #include "TGeoGlobalMagField.h"
36 #include "AliTPCcalibDB.h"
37 #include "AliTPCParam.h"
43 #include "AliTPCROC.h"
44 #include "AliTPCROCVoltError3D.h"
46 ClassImp(AliTPCROCVoltError3D)
48 AliTPCROCVoltError3D::AliTPCROCVoltError3D()
49 : AliTPCCorrection("ROCVoltErrors","ROC z alignment Errors"),
51 fROCdisplacement(kTRUE),
57 // default constructor
60 // Array which will contain the solution according to the setted boundary conditions
61 // main input: z alignment of the Read Out chambers
62 // see InitROCVoltError3D() function
63 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
64 fLookUpErOverEz[k] = new TMatrixD(kNR,kNZ);
65 fLookUpEphiOverEz[k] = new TMatrixD(kNR,kNZ);
66 fLookUpDeltaEz[k] = new TMatrixD(kNR,kNZ);
68 fROCDataFileName="$ALICE_ROOT/TPC/Calib/maps/TPCROCdzSurvey.root";
69 SetROCDataFileName(fROCDataFileName.Data()); // initialization of fdzDataLinFit is included
73 AliTPCROCVoltError3D::~AliTPCROCVoltError3D() {
78 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
79 delete fLookUpErOverEz[k];
80 delete fLookUpEphiOverEz[k];
81 delete fLookUpDeltaEz[k];
87 void AliTPCROCVoltError3D::SetROCData(TMatrixD * matrix){
89 // Set a z alignment map of the chambers not via a file, but
90 // directly via a TMatrix(72,3), where dz = p0 + p1*lx + p2*ly
92 if (!fdzDataLinFit) fdzDataLinFit=new TMatrixD(*matrix);
93 else *fdzDataLinFit = *matrix;
97 void AliTPCROCVoltError3D::Init() {
99 // Initialization funtion
102 AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
103 if (!magF) AliError("Magneticd field - not initialized");
104 Double_t bzField = magF->SolenoidField()/10.; //field in T
105 AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
106 if (!param) AliError("Parameters - not initialized");
107 Double_t vdrift = param->GetDriftV()/1000000.; // [cm/us] // From dataBase: to be updated: per second (ideally)
108 Double_t ezField = 400; // [V/cm] // to be updated: never (hopefully)
109 Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
110 // Correction Terms for effective omegaTau; obtained by a laser calibration run
111 SetOmegaTauT1T2(wt,fT1,fT2);
113 if (!fInitLookUp) InitROCVoltError3D();
116 void AliTPCROCVoltError3D::Update(const TTimeStamp &/*timeStamp*/) {
120 AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
121 if (!magF) AliError("Magneticd field - not initialized");
122 Double_t bzField = magF->SolenoidField()/10.; //field in T
123 AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
124 if (!param) AliError("Parameters - not initialized");
125 Double_t vdrift = param->GetDriftV()/1000000.; // [cm/us] // From dataBase: to be updated: per second (ideally)
126 Double_t ezField = 400; // [V/cm] // to be updated: never (hopefully)
127 Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
128 // Correction Terms for effective omegaTau; obtained by a laser calibration run
129 SetOmegaTauT1T2(wt,fT1,fT2);
133 void AliTPCROCVoltError3D::SetROCDataFileName(const char * fname) {
135 // Set / load the ROC data (linear fit of ROC misalignments)
138 fROCDataFileName = fname;
140 TFile f(fROCDataFileName.Data(),"READ");
141 TMatrixD *m = (TMatrixD*) f.Get("dzSurveyLinFitData");
144 // prepare some space
146 if (fdzDataLinFit) delete fdzDataLinFit;
147 fdzDataLinFit = new TMatrixD(72,3);
148 TMatrixD &dataIntern = *fdzDataLinFit;
150 for (Int_t iroc=0;iroc<72;iroc++) {
151 dataIntern(iroc,0) = mf(iroc,0); // z0 offset
152 dataIntern(iroc,1) = mf(iroc,1); // slope in x
153 dataIntern(iroc,2) = mf(iroc,2); // slope in y
158 fInitLookUp = kFALSE;
162 void AliTPCROCVoltError3D::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
164 // Calculates the correction due e.g. residual voltage errors on the TPC boundaries
168 AliInfo("Lookup table was not initialized! Perform the inizialisation now ...");
169 InitROCVoltError3D();
173 Int_t order = 1 ; // FIXME: hardcoded? Linear interpolation = 1, Quadratic = 2
175 Double_t intEr, intEphi, intDeltaEz;
179 r = TMath::Sqrt( x[0]*x[0] + x[1]*x[1] ) ;
180 phi = TMath::ATan2(x[1],x[0]) ;
181 if ( phi < 0 ) phi += TMath::TwoPi() ; // Table uses phi from 0 to 2*Pi
182 z = x[2] ; // Create temporary copy of x[2]
184 if ( (roc%36) < 18 ) {
185 sign = 1; // (TPC A side)
187 sign = -1; // (TPC C side)
190 if ( sign==1 && z < fgkZOffSet ) z = fgkZOffSet; // Protect against discontinuity at CE
191 if ( sign==-1 && z > -fgkZOffSet ) z = -fgkZOffSet; // Protect against discontinuity at CE
194 if ( (sign==1 && z<0) || (sign==-1 && z>0) ) // just a consistency check
195 AliError("ROC number does not correspond to z coordinate! Calculation of distortions is most likely wrong!");
197 // Get the Er and Ephi field integrals plus the integral over DeltaEz
198 intEr = Interpolate3DTable(order, r, z, phi, kNR, kNZ, kNPhi,
199 fgkRList, fgkZList, fgkPhiList, fLookUpErOverEz );
200 intEphi = Interpolate3DTable(order, r, z, phi, kNR, kNZ, kNPhi,
201 fgkRList, fgkZList, fgkPhiList, fLookUpEphiOverEz);
202 intDeltaEz = Interpolate3DTable(order, r, z, phi, kNR, kNZ, kNPhi,
203 fgkRList, fgkZList, fgkPhiList, fLookUpDeltaEz );
205 // printf("%lf %lf %lf\n",intEr,intEphi,intDeltaEz);
207 // Calculate distorted position
209 phi = phi + ( fC0*intEphi - fC1*intEr ) / r;
210 r = r + ( fC0*intEr + fC1*intEphi );
213 // Calculate correction in cartesian coordinates
214 dx[0] = r * TMath::Cos(phi) - x[0];
215 dx[1] = r * TMath::Sin(phi) - x[1];
216 dx[2] = intDeltaEz; // z distortion - (internally scaled with driftvelocity dependency
217 // on the Ez field plus the actual ROC misalignment (if set TRUE)
221 void AliTPCROCVoltError3D::InitROCVoltError3D() {
223 // Initialization of the Lookup table which contains the solutions of the
224 // Dirichlet boundary problem
225 // Calculation of the single 3D-Poisson solver is done just if needed
226 // (see basic lookup tables in header file)
229 const Int_t order = 1 ; // Linear interpolation = 1, Quadratic = 2
230 const Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius) / (kRows-1) ;
231 const Float_t gridSizeZ = fgkTPCZ0 / (kColumns-1) ;
232 const Float_t gridSizePhi = TMath::TwoPi() / ( 18.0 * kPhiSlicesPerSector);
234 // temporary arrays to create the boundary conditions
235 TMatrixD *arrayofArrayV[kPhiSlices], *arrayofCharge[kPhiSlices] ;
236 TMatrixD *arrayofEroverEz[kPhiSlices], *arrayofEphioverEz[kPhiSlices], *arrayofDeltaEz[kPhiSlices] ;
238 for ( Int_t k = 0 ; k < kPhiSlices ; k++ ) {
239 arrayofArrayV[k] = new TMatrixD(kRows,kColumns) ;
240 arrayofCharge[k] = new TMatrixD(kRows,kColumns) ;
241 arrayofEroverEz[k] = new TMatrixD(kRows,kColumns) ;
242 arrayofEphioverEz[k] = new TMatrixD(kRows,kColumns) ;
243 arrayofDeltaEz[k] = new TMatrixD(kRows,kColumns) ;
246 // list of point as used in the poisson relation and the interpolation (during sum up)
247 Double_t rlist[kRows], zedlist[kColumns] , philist[kPhiSlices];
248 for ( Int_t k = 0 ; k < kPhiSlices ; k++ ) {
249 philist[k] = gridSizePhi * k;
250 for ( Int_t i = 0 ; i < kRows ; i++ ) {
251 rlist[i] = fgkIFCRadius + i*gridSizeR ;
252 for ( Int_t j = 0 ; j < kColumns ; j++ ) { // Fill Vmatrix with Boundary Conditions
253 zedlist[j] = j * gridSizeZ ;
258 // ==========================================================================
259 // Solve Poisson's equation in 3D cylindrical coordinates by relaxation technique
260 // Allow for different size grid spacing in R and Z directions
262 const Int_t symmetry = 0;
264 // Set bondaries and solve Poisson's equation --------------------------
266 if ( !fInitLookUp ) {
268 AliInfo(Form("Solving the poisson equation (~ %d sec)",2*10*(int)(kPhiSlices/10)));
270 for ( Int_t side = 0 ; side < 2 ; side++ ) { // Solve Poisson3D twice; once for +Z and once for -Z
272 for ( Int_t k = 0 ; k < kPhiSlices ; k++ ) {
273 TMatrixD &arrayV = *arrayofArrayV[k] ;
274 TMatrixD &charge = *arrayofCharge[k] ;
276 //Fill arrays with initial conditions. V on the boundary and Charge in the volume.
277 for ( Int_t i = 0 ; i < kRows ; i++ ) {
278 for ( Int_t j = 0 ; j < kColumns ; j++ ) { // Fill Vmatrix with Boundary Conditions
282 Float_t radius0 = rlist[i] ;
283 Float_t phi0 = gridSizePhi * k ;
285 // To avoid problems at sector boundaries, use an average of +- 1 degree from actual phi location
286 if ( j == (kColumns-1) )
287 arrayV(i,j) = 0.5* ( GetROCVoltOffset( side, radius0, phi0+0.02 ) + GetROCVoltOffset( side, radius0, phi0-0.02 ) ) ;
292 for ( Int_t i = 1 ; i < kRows-1 ; i++ ) {
293 for ( Int_t j = 1 ; j < kColumns-1 ; j++ ) {
299 // Solve Poisson's equation in 3D cylindrical coordinates by relaxation technique
300 // Allow for different size grid spacing in R and Z directions
302 PoissonRelaxation3D( arrayofArrayV, arrayofCharge,
303 arrayofEroverEz, arrayofEphioverEz, arrayofDeltaEz,
304 kRows, kColumns, kPhiSlices, gridSizePhi, kIterations,
305 symmetry, fROCdisplacement) ;
308 //Interpolate results onto a custom grid which is used just for these calculations.
310 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
311 phi = fgkPhiList[k] ;
313 TMatrixD &erOverEz = *fLookUpErOverEz[k] ;
314 TMatrixD &ephiOverEz = *fLookUpEphiOverEz[k];
315 TMatrixD &deltaEz = *fLookUpDeltaEz[k] ;
317 for ( Int_t j = 0 ; j < kNZ ; j++ ) {
319 z = TMath::Abs(fgkZList[j]) ; // Symmetric solution in Z that depends only on ABS(Z)
321 if ( side == 0 && fgkZList[j] < 0 ) continue; // Skip rest of this loop if on the wrong side
322 if ( side == 1 && fgkZList[j] > 0 ) continue; // Skip rest of this loop if on the wrong side
324 for ( Int_t i = 0 ; i < kNR ; i++ ) {
327 // Interpolate basicLookup tables; once for each rod, then sum the results
328 erOverEz(i,j) = Interpolate3DTable(order, r, z, phi, kRows, kColumns, kPhiSlices,
329 rlist, zedlist, philist, arrayofEroverEz );
330 ephiOverEz(i,j) = Interpolate3DTable(order, r, z, phi, kRows, kColumns, kPhiSlices,
331 rlist, zedlist, philist, arrayofEphioverEz);
332 deltaEz(i,j) = Interpolate3DTable(order, r, z, phi, kRows, kColumns, kPhiSlices,
333 rlist, zedlist, philist, arrayofDeltaEz );
335 if (side == 1) deltaEz(i,j) = - deltaEz(i,j); // negative coordinate system on C side
341 if ( side == 0 ) AliInfo(" A side done");
342 if ( side == 1 ) AliInfo(" C side done");
346 // clear the temporary arrays lists
347 for ( Int_t k = 0 ; k < kPhiSlices ; k++ ) {
348 delete arrayofArrayV[k];
349 delete arrayofCharge[k];
350 delete arrayofEroverEz[k];
351 delete arrayofEphioverEz[k];
352 delete arrayofDeltaEz[k];
361 Float_t AliTPCROCVoltError3D::GetROCVoltOffset(Int_t side, Float_t r0, Float_t phi0) {
363 // Returns the dz alignment data (in voltage equivalents) at
364 // the given position
367 Float_t xp = r0*TMath::Cos(phi0);
368 Float_t yp = r0*TMath::Sin(phi0);
370 // phi0 should be between 0 and 2pi
371 if (phi0<0) phi0+=TMath::TwoPi();
372 Int_t roc = (Int_t)TMath::Floor((TMath::RadToDeg()*phi0)/20);
373 if (side==1) roc+=18; // C side
374 if (r0>132) roc+=36; // OROC
376 // linear-plane data: z = z0 + kx*lx + ky*ly (rotation in local coordinates)
377 TMatrixD &fitData = *fdzDataLinFit;
380 Double_t secAlpha = TMath::DegToRad()*(10.+20.*(((Int_t)roc)%18));
381 Float_t lx = xp*TMath::Cos(secAlpha)+yp*TMath::Sin(secAlpha);
382 Float_t ly = yp*TMath::Cos(secAlpha)-xp*TMath::Sin(secAlpha);
384 Float_t dz = fitData(roc,0)+fitData(roc,1)*lx + fitData(roc,2)*ly; // value in cm
386 // aproximated Voltage-offset-aquivalent to the z misalignment
387 // (linearly scaled with the z position)
388 Double_t ezField = (fgkCathodeV-fgkGG)/fgkTPCZ0; // = ALICE Electric Field (V/cm) Magnitude ~ -400 V/cm;
389 Float_t voltOff = dz*ezField; // values in "Volt equivalents"
394 TH2F * AliTPCROCVoltError3D::CreateHistoOfZSurvey(Int_t side, Int_t nx, Int_t ny) {
396 // return a simple histogramm containing the input to the poisson solver
397 // (z positions of the Read-out chambers, linearly interpolated)
400 if (side==0) sprintf(hname,"survey_dz_Aside");
401 if (side==1) sprintf(hname,"survey_dz_Cside");
403 TH2F *h = new TH2F(hname,hname,nx,-250.,250.,ny,-250.,250.);
405 for (Int_t iy=1;iy<=ny;++iy) {
406 Double_t yp = h->GetYaxis()->GetBinCenter(iy);
407 for (Int_t ix=1;ix<=nx;++ix) {
408 Double_t xp = h->GetXaxis()->GetBinCenter(ix);
410 Float_t r0 = TMath::Sqrt(xp*xp+yp*yp);
411 Float_t phi0 = TMath::ATan2(yp,xp);
413 Float_t dz = GetROCVoltOffset(side,r0,phi0); // in [volt]
415 Double_t ezField = (fgkCathodeV-fgkGG)/fgkTPCZ0; // = ALICE Electric Field (V/cm) Magnitude ~ -400 V/cm;
416 dz = dz/ezField; // in [cm]
418 if (85.<=r0 && r0<=245.) {
419 h->SetBinContent(ix,iy,dz);
421 h->SetBinContent(ix,iy,0.);
426 h->GetXaxis()->SetTitle("x [cm]");
427 h->GetYaxis()->SetTitle("y [cm]");
428 h->GetZaxis()->SetTitle("dz [cm]");
430 // h->DrawCopy("colz");
435 void AliTPCROCVoltError3D::Print(const Option_t* option) const {
437 // Print function to check the settings of the Rod shifts and the rotated clips
438 // option=="a" prints the C0 and C1 coefficents for calibration purposes
441 TString opt = option; opt.ToLower();
442 printf("%s\n",GetTitle());
443 printf(" - Voltage settings on the TPC Read-Out chambers - linearly interpolated\n");
444 printf(" info: Check the following data-file for more details: %s \n",fROCDataFileName.Data());
446 if (opt.Contains("a")) { // Print all details
447 printf(" - T1: %1.4f, T2: %1.4f \n",fT1,fT2);
448 printf(" - C1: %1.4f, C0: %1.4f \n",fC1,fC0);
451 if (!fInitLookUp) AliError("Lookup table was not initialized! You should do InitROCVoltError3D() ...");