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 // _________________________________________________________________
19 // <h2> AliTPCSpaceCharge class </h2>
20 // The class calculates the space point distortions due to a rotational
21 // symmetric space charge distribution with the TPC drift volume.
23 // The class uses the PoissonRelaxation2D to calculate the resulting
24 // electrical field inhomogeneities in the (r,z)-plane. Then, the
25 // Langevin-integral formalism is used to calculate the space point distortions.
27 // The class assumes, that the distortions scales linearly with the magnitude
28 // of the space charge distribution $\rho(r,z)$. The in here assumed distribution is
29 // $$\rho(r,z) = \frac{(A-B\,z)}{r^2} $$ wherein the factors A and B scale with the
30 // event multiplicity and the interaction rate.
32 // The scaling factor can be set via the function SetCorrectionFactor. An example of
33 // the shape of the distortions is given below.
35 // MI modification - 22.05.2013
36 // As an optional input the Space charge histogram RZ is used in case it is provided
37 // - using the SetInputSpaceCharge function
41 // Begin_Macro(source)
43 // gROOT->SetStyle("Plain"); gStyle->SetPalette(1);
44 // TCanvas *c2 = new TCanvas("cAliTPCSpaceCharge","cAliTPCSpaceCharge",500,300);
45 // AliTPCSpaceCharge sc;
46 // sc.SetOmegaTauT1T2(-0.32,1,1); // B=0.5 Tesla
47 // sc.SetCorrectionFactor(0.0015);
48 // sc.CreateHistoDRinZR(0.)->Draw("surf2");
55 // Date: 23/08/2010 <br>
56 // Authors: Jim Thomas, Stefan Rossegger
58 // _________________________________________________________________
63 #include "TGeoGlobalMagField.h"
64 #include "AliTPCcalibDB.h"
65 #include "AliTPCParam.h"
71 #include "AliTPCROC.h"
72 #include "AliTPCSpaceCharge.h"
74 ClassImp(AliTPCSpaceCharge)
76 AliTPCSpaceCharge::AliTPCSpaceCharge()
77 : AliTPCCorrection("SpaceCharge2D","Space Charge 2D"),
78 fC0(0.),fC1(0.),fCorrectionFactor(0.001),fSpaceChargeHistogram(0),
82 // default constructor
87 AliTPCSpaceCharge::~AliTPCSpaceCharge() {
95 void AliTPCSpaceCharge::Init() {
97 // Initialization funtion
100 AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
101 if (!magF) AliError("Magneticd field - not initialized");
102 Double_t bzField = magF->SolenoidField()/10.; //field in T
103 AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
104 if (!param) AliError("Parameters - not initialized");
105 Double_t vdrift = param->GetDriftV()/1000000.; // [cm/us] // From dataBase: to be updated: per second (ideally)
106 Double_t ezField = 400; // [V/cm] // to be updated: never (hopefully)
107 Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
108 // Correction Terms for effective omegaTau; obtained by a laser calibration run
109 SetOmegaTauT1T2(wt,fT1,fT2);
111 InitSpaceChargeDistortion(); // fill the look up table
114 void AliTPCSpaceCharge::Update(const TTimeStamp &/*timeStamp*/) {
118 AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
119 if (!magF) AliError("Magneticd field - not initialized");
120 Double_t bzField = magF->SolenoidField()/10.; //field in T
121 AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
122 if (!param) AliError("Parameters - not initialized");
123 Double_t vdrift = param->GetDriftV()/1000000.; // [cm/us] // From dataBase: to be updated: per second (ideally)
124 Double_t ezField = 400; // [V/cm] // to be updated: never (hopefully)
125 Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
126 // Correction Terms for effective omegaTau; obtained by a laser calibration run
127 SetOmegaTauT1T2(wt,fT1,fT2);
129 // SetCorrectionFactor(1.); // should come from some database
135 void AliTPCSpaceCharge::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
137 // Calculates the correction due the Space Charge effect within the TPC drift volume
141 AliInfo("Lookup table was not initialized! Perform the inizialisation now ...");
142 InitSpaceChargeDistortion();
144 Int_t order = 1 ; // FIXME: hardcoded? Linear interpolation = 1, Quadratic = 2
146 Double_t intEr, intEphi, intdEz;
150 r = TMath::Sqrt( x[0]*x[0] + x[1]*x[1] ) ;
151 phi = TMath::ATan2(x[1],x[0]) ;
152 if ( phi < 0 ) phi += TMath::TwoPi() ; // Table uses phi from 0 to 2*Pi
153 z = x[2] ; // Create temporary copy of x[2]
155 if ( (roc%36) < 18 ) {
156 sign = 1; // (TPC A side)
158 sign = -1; // (TPC C side)
161 if ( sign==1 && z < fgkZOffSet ) z = fgkZOffSet; // Protect against discontinuity at CE
162 if ( sign==-1 && z > -fgkZOffSet ) z = -fgkZOffSet; // Protect against discontinuity at CE
165 if ( (sign==1 && z<0) || (sign==-1 && z>0) ) // just a consistency check
166 AliError("ROC number does not correspond to z coordinate! Calculation of distortions is most likely wrong!");
168 // Efield is symmetric in phi - 2D calculation
170 // Get the E field integrals
171 Interpolate2DEdistortion( order, r, z, fLookUpErOverEz, intEr );
172 // Get DeltaEz field integral
173 Interpolate2DEdistortion( order, r, z, fLookUpDeltaEz, intdEz );
176 // Calculate distorted position
178 phi = phi + fCorrectionFactor *( fC0*intEphi - fC1*intEr ) / r;
179 r = r + fCorrectionFactor *( fC0*intEr + fC1*intEphi );
181 Double_t dz = intdEz*fCorrectionFactor;
183 // Calculate correction in cartesian coordinates
184 dx[0] = - (r * TMath::Cos(phi) - x[0]);
185 dx[1] = - (r * TMath::Sin(phi) - x[1]);
186 dx[2] = - dz; // z distortion - (internally scaled with driftvelocity dependency
191 void AliTPCSpaceCharge::InitSpaceChargeDistortion() {
193 // Initialization of the Lookup table which contains the solutions of the
197 const Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius) / (kRows-1) ;
198 const Float_t gridSizeZ = fgkTPCZ0 / (kColumns-1) ;
200 TMatrixD voltArray(kRows,kColumns); // dummy boundary vectors
201 TMatrixD chargeDensity(kRows,kColumns); // charge
202 TMatrixD arrayErOverEz(kRows,kColumns); // solution in Er
203 TMatrixD arrayDeltaEz(kRows,kColumns); // solution in Ez
205 Double_t rList[kRows], zedList[kColumns] ;
207 // Fill arrays with initial conditions. V on the boundary and ChargeDensity in the volume.
208 for ( Int_t j = 0 ; j < kColumns ; j++ ) {
209 Double_t zed = j*gridSizeZ ;
211 for ( Int_t i = 0 ; i < kRows ; i++ ) {
212 Double_t radius = fgkIFCRadius + i*gridSizeR ;
214 voltArray(i,j) = 0; // Initialize voltArray to zero - not used in this class
215 chargeDensity(i,j) = 0; // Initialize ChargeDensity to zero
219 // Fill the initial conditions
220 for ( Int_t j = 1 ; j < kColumns-1 ; j++ ) {
221 Double_t zed = j*gridSizeZ ;
222 for ( Int_t i = 1 ; i < kRows-1 ; i++ ) {
223 Double_t radius = fgkIFCRadius + i*gridSizeR ;
225 Double_t zterm = (fgkTPCZ0-zed) * (fgkOFCRadius*fgkOFCRadius - fgkIFCRadius*fgkIFCRadius) / fgkTPCZ0 ;
226 // for 1/R**2 charge density in the TPC; then integrated in Z due to drifting ions
227 chargeDensity(i,j) = zterm / ( TMath::Log(fgkOFCRadius/fgkIFCRadius) * ( radius*radius ) ) ;
230 // Fill the initial space charge in case histogram exist
231 if (fSpaceChargeHistogram){
232 for ( Int_t j = 1 ; j < kColumns-1 ; j++ ) {
233 Double_t zed = j*gridSizeZ ;
234 for ( Int_t i = 1 ; i < kRows-1 ; i++ ) {
235 Double_t radius = fgkIFCRadius + i*gridSizeR ;
237 Double_t zterm = (fgkTPCZ0-zed) * (fgkOFCRadius*fgkOFCRadius - fgkIFCRadius*fgkIFCRadius) / fgkTPCZ0 ;
238 // for 1/R**2 charge density in the TPC; then integrated in Z due to drifting ions
239 chargeDensity(i,j) = fSpaceChargeHistogram->Interpolate(radius,zed);
245 // Solve the electrosatic problem in 2D
247 PoissonRelaxation2D( voltArray, chargeDensity, arrayErOverEz, arrayDeltaEz, kRows, kColumns, kIterations ) ;
249 //Interpolate results onto standard grid for Electric Fields
250 Int_t ilow=0, jlow=0 ;
252 Float_t saveEr[2], saveEz[2] ;
253 for ( Int_t i = 0 ; i < kNZ ; ++i ) {
254 z = TMath::Abs( fgkZList[i] ) ; // assume symmetric behaviour on A and C side
255 for ( Int_t j = 0 ; j < kNR ; ++j ) {
257 // Linear interpolation !!
259 Search( kRows, rList, r, ilow ) ; // Note switch - R in rows and Z in columns
260 Search( kColumns, zedList, z, jlow ) ;
261 if ( ilow < 0 ) ilow = 0 ; // check if out of range
262 if ( jlow < 0 ) jlow = 0 ;
263 if ( ilow + 1 >= kRows - 1 ) ilow = kRows - 2 ;
264 if ( jlow + 1 >= kColumns - 1 ) jlow = kColumns - 2 ;
266 saveEr[0] = arrayErOverEz(ilow,jlow) +
267 (arrayErOverEz(ilow,jlow+1)-arrayErOverEz(ilow,jlow))*(z-zedList[jlow])/gridSizeZ ;
268 saveEr[1] = arrayErOverEz(ilow+1,jlow) +
269 (arrayErOverEz(ilow+1,jlow+1)-arrayErOverEz(ilow+1,jlow))*(z-zedList[jlow])/gridSizeZ ;
270 saveEz[0] = arrayDeltaEz(ilow,jlow) +
271 (arrayDeltaEz(ilow,jlow+1)-arrayDeltaEz(ilow,jlow))*(z-zedList[jlow])/gridSizeZ ;
272 saveEz[1] = arrayDeltaEz(ilow+1,jlow) +
273 (arrayDeltaEz(ilow+1,jlow+1)-arrayDeltaEz(ilow+1,jlow))*(z-zedList[jlow])/gridSizeZ ;
276 fLookUpErOverEz[i][j] = saveEr[0] + (saveEr[1]-saveEr[0])*(r-rList[ilow])/gridSizeR ;
277 fLookUpDeltaEz[i][j] = saveEz[0] + (saveEz[1]-saveEz[0])*(r-rList[ilow])/gridSizeR ;
279 if (fgkZList[i]<0) fLookUpDeltaEz[i][j] *= -1; // C side is negative z
287 void AliTPCSpaceCharge::Print(const Option_t* option) const {
289 // Print function to check the settings of the boundary vectors
290 // option=="a" prints the C0 and C1 coefficents for calibration purposes
293 TString opt = option; opt.ToLower();
294 printf("%s\n",GetTitle());
295 printf(" - Space Charge effects assuming a radial symmetric z over r^2 SC-distribution.\n");
296 printf(" SC correction factor: %f \n",fCorrectionFactor);
298 if (opt.Contains("a")) { // Print all details
299 printf(" - T1: %1.4f, T2: %1.4f \n",fT1,fT2);
300 printf(" - C1: %1.4f, C0: %1.4f \n",fC1,fC0);
303 if (!fInitLookUp) AliError("Lookup table was not initialized! You should do InitSpaceChargeDistortion() ...");