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> AliTPCSpaceCharge3D class </h2>
20 // The class calculates the space point distortions due to an arbitrary space
21 // charge distribution in 3D.
23 // The method of calculation is based on the analytical solution for the Poisson
24 // problem in 3D (cylindrical coordinates). The solution is used in form of
25 // look up tables, where the pre calculated solutions for different voxel
26 // positions are stored. These voxel solutions can be summed up according
27 // to the weight of the position of the applied space charge distribution.
28 // Further details can be found in \cite[chap.5]{PhD-thesis_S.Rossegger}.
30 // The class also allows a simple scaling of the resulting distortions
31 // via the function SetCorrectionFactor. This speeds up the calculation
32 // time under the assumption, that the distortions scales linearly with the
33 // magnitude of the space charge distribution $\rho(r,z)$ and the shape stays
34 // the same at higher luminosities.
36 // In contrast to the implementation in 2D (see the class AliTPCSpaceChargeabove),
37 // the input charge distribution can be of arbitrary character. An example on how
38 // to produce a corresponding charge distribution can be found in the function
39 // WriteChargeDistributionToFile. In there, a $\rho(r,z) = (A-B\,z)/r^2$,
40 // with slightly different magnitude on the A and C side (due to the muon absorber),
41 // is superpositioned with a few leaking wires at arbitrary positions.
44 // Marian Ivanov change: 26.06.2013
45 // Usage of the realy 3D space charge map as an optional input
46 // SetInputSpaceCharge map.
47 // In case given map is used 2 2D maps are ignored and scaling functions $\rho(r,z) = (A-B\,z)/r^2$,
54 // Begin_Macro(source)
56 // gROOT->SetStyle("Plain"); gStyle->SetPalette(1);
57 // TCanvas *c2 = new TCanvas("cAliTPCSpaceCharge3D","cAliTPCSpaceCharge3D",500,400);
58 // AliTPCSpaceCharge3D sc;
59 // sc.WriteChargeDistributionToFile("SC_zr2_GGleaks.root");
60 // sc.SetSCDataFileName("SC_zr2_GGleaks.root");
61 // sc.SetOmegaTauT1T2(0,1,1); // B=0
62 // sc.InitSpaceCharge3DDistortion();
63 // sc.CreateHistoDRinXY(15,300,300)->Draw("colz");
70 // Date: 19/06/2010 <br>
71 // Authors: Stefan Rossegger
73 // _________________________________________________________________
77 #include "TGeoGlobalMagField.h"
78 #include "AliTPCcalibDB.h"
79 #include "AliTPCParam.h"
89 #include "AliTPCROC.h"
90 #include "AliTPCSpaceCharge3D.h"
91 #include "AliSysInfo.h"
93 ClassImp(AliTPCSpaceCharge3D)
95 AliTPCSpaceCharge3D::AliTPCSpaceCharge3D()
96 : AliTPCCorrection("SpaceCharge3D","Space Charge - 3D"),
98 fCorrectionFactor(1.),
101 fSCLookUpPOCsFileName3D(""),
102 fSCLookUpPOCsFileNameRZ(""),
103 fSCLookUpPOCsFileNameRPhi(""),
105 fSCdensityInRPhiA(0),
106 fSCdensityInRPhiC(0),
107 fSpaceChargeHistogram3D(0),
108 fSpaceChargeHistogramRPhi(0),
109 fSpaceChargeHistogramRZ(0)
112 // default constructor
115 // Array which will contain the solution according to the setted charge density distribution
116 // see InitSpaceCharge3DDistortion() function
117 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
118 fLookUpErOverEz[k] = new TMatrixF(kNR,kNZ);
119 fLookUpEphiOverEz[k] = new TMatrixF(kNR,kNZ);
120 fLookUpDeltaEz[k] = new TMatrixF(kNR,kNZ);
121 fSCdensityDistribution[k] = new TMatrixF(kNR,kNZ);
123 fSCdensityInRZ = new TMatrixD(kNR,kNZ);
124 fSCdensityInRPhiA = new TMatrixD(kNR,kNPhi);
125 fSCdensityInRPhiC = new TMatrixD(kNR,kNPhi);
127 // location of the precalculated look up tables
129 fSCLookUpPOCsFileName3D="$(ALICE_ROOT)/TPC/Calib/maps/sc_3D_raw_18-18-26_17p-18p-25p-MN30.root"; // rough estimate
130 fSCLookUpPOCsFileNameRZ="$(ALICE_ROOT)/TPC/Calib/maps/sc_radSym_35-01-51_34p-01p-50p_MN60.root";
131 fSCLookUpPOCsFileNameRPhi="$(ALICE_ROOT)/TPC/Calib/maps/sc_cChInZ_35-144-26_34p-18p-01p-MN30.root";
132 // fSCLookUpPOCsFileNameRPhi="$(ALICE_ROOT)/TPC/Calib/maps/sc_cChInZ_35-36-26_34p-18p-01p-MN40.root";
136 // standard location of the space charge distibution ... can be changes
137 fSCDataFileName="$(ALICE_ROOT)/TPC/Calib/maps/sc_3D_distribution_Sim.root";
139 // SetSCDataFileName(fSCDataFileName.Data()); // should be done by the user
144 AliTPCSpaceCharge3D::~AliTPCSpaceCharge3D() {
146 // default destructor
149 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
150 delete fLookUpErOverEz[k];
151 delete fLookUpEphiOverEz[k];
152 delete fLookUpDeltaEz[k];
153 delete fSCdensityDistribution[k];
155 delete fSCdensityInRZ;
156 delete fSCdensityInRPhiA;
157 delete fSCdensityInRPhiC;
158 delete fSpaceChargeHistogram3D;
159 delete fSpaceChargeHistogramRPhi;
160 delete fSpaceChargeHistogramRZ;
164 void AliTPCSpaceCharge3D::Init() {
166 // Initialization funtion
169 AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
170 if (!magF) AliError("Magneticd field - not initialized");
171 Double_t bzField = magF->SolenoidField()/10.; //field in T
172 AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
173 if (!param) AliError("Parameters - not initialized");
174 Double_t vdrift = param->GetDriftV()/1000000.; // [cm/us] // From dataBase: to be updated: per second (ideally)
175 Double_t ezField = 400; // [V/cm] // to be updated: never (hopefully)
176 Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
177 // Correction Terms for effective omegaTau; obtained by a laser calibration run
178 SetOmegaTauT1T2(wt,fT1,fT2);
180 InitSpaceCharge3DDistortion(); // fill the look up table
183 void AliTPCSpaceCharge3D::Update(const TTimeStamp &/*timeStamp*/) {
187 AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
188 if (!magF) AliError("Magneticd field - not initialized");
189 Double_t bzField = magF->SolenoidField()/10.; //field in T
190 AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
191 if (!param) AliError("Parameters - not initialized");
192 Double_t vdrift = param->GetDriftV()/1000000.; // [cm/us] // From dataBase: to be updated: per second (ideally)
193 Double_t ezField = 400; // [V/cm] // to be updated: never (hopefully)
194 Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
195 // Correction Terms for effective omegaTau; obtained by a laser calibration run
196 SetOmegaTauT1T2(wt,fT1,fT2);
198 // SetCorrectionFactor(1.); // should come from some database
203 void AliTPCSpaceCharge3D::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
205 // Calculates the correction due the Space Charge effect within the TPC drift volume
209 AliInfo("Lookup table was not initialized! Performing the inizialisation now ...");
210 InitSpaceCharge3DDistortion();
213 Int_t order = 1 ; // FIXME: hardcoded? Linear interpolation = 1, Quadratic = 2
215 Float_t intEr, intEphi, intdEz ;
219 r = TMath::Sqrt( x[0]*x[0] + x[1]*x[1] ) ;
220 phi = TMath::ATan2(x[1],x[0]) ;
221 if ( phi < 0 ) phi += TMath::TwoPi() ; // Table uses phi from 0 to 2*Pi
222 z = x[2] ; // Create temporary copy of x[2]
224 if ( (roc%36) < 18 ) {
225 sign = 1; // (TPC A side)
227 sign = -1; // (TPC C side)
230 if ( sign==1 && z < fgkZOffSet ) z = fgkZOffSet; // Protect against discontinuity at CE
231 if ( sign==-1 && z > -fgkZOffSet ) z = -fgkZOffSet; // Protect against discontinuity at CE
234 if ( (sign==1 && z<0) || (sign==-1 && z>0) ) // just a consistency check
235 AliError("ROC number does not correspond to z coordinate! Calculation of distortions is most likely wrong!");
237 // Get the Er and Ephi field integrals plus the integral over DeltaEz
238 intEr = Interpolate3DTable(order, r, z, phi, kNR, kNZ, kNPhi,
239 fgkRList, fgkZList, fgkPhiList, fLookUpErOverEz );
240 intEphi = Interpolate3DTable(order, r, z, phi, kNR, kNZ, kNPhi,
241 fgkRList, fgkZList, fgkPhiList, fLookUpEphiOverEz);
242 intdEz = Interpolate3DTable(order, r, z, phi, kNR, kNZ, kNPhi,
243 fgkRList, fgkZList, fgkPhiList, fLookUpDeltaEz );
245 // Calculate distorted position
247 phi = phi + fCorrectionFactor *( fC0*intEphi - fC1*intEr ) / r;
248 r = r + fCorrectionFactor *( fC0*intEr + fC1*intEphi );
250 Double_t dz = intdEz * fCorrectionFactor * fgkdvdE;
252 // Calculate correction in cartesian coordinates
253 dx[0] = - (r * TMath::Cos(phi) - x[0]);
254 dx[1] = - (r * TMath::Sin(phi) - x[1]);
255 dx[2] = - dz; // z distortion - (scaled with driftvelocity dependency on the Ez field and the overall scaling factor)
259 void AliTPCSpaceCharge3D::InitSpaceCharge3DDistortion() {
261 // Initialization of the Lookup table which contains the solutions of the
262 // "space charge" (poisson) problem - Faster and more accureate
264 // Method: Weighted sum-up of the different fields within the look up table
265 // but using two lookup tables with higher granularity in the (r,z) and the (rphi)- plane to emulate
266 // more realistic space charges. (r,z) from primary ionisation. (rphi) for possible Gating leaks
269 AliInfo("Lookup table was already initialized! Doing it again anyway ...");
273 // ------------------------------------------------------------------------------------------------------
274 // step 1: lookup table in rz, fine grid, radial symetric, to emulate primary ionization
276 AliInfo("Step 1: Preparation of the weighted look-up tables.");
278 // lookup table in rz, fine grid
280 TFile *fZR = new TFile(fSCLookUpPOCsFileNameRZ.Data(),"READ");
282 AliError("Precalculated POC-looup-table in ZR could not be found");
287 TVector *gridf1 = (TVector*) fZR->Get("constants");
288 TVector &grid1 = *gridf1;
289 TMatrix *coordf1 = (TMatrix*) fZR->Get("coordinates");
290 TMatrix &coord1 = *coordf1;
291 TMatrix *coordPOCf1 = (TMatrix*) fZR->Get("POCcoord");
292 TMatrix &coordPOC1 = *coordPOCf1;
294 Int_t rows = (Int_t)grid1(0); // number of points in r direction - from RZ or RPhi table
295 Int_t phiSlices = (Int_t)grid1(1); // number of points in phi - from RPhi table
296 Int_t columns = (Int_t)grid1(2); // number of points in z direction - from RZ table
298 Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius)/(rows-1); // unit in [cm]
299 Float_t gridSizeZ = fgkTPCZ0/(columns-1); // unit in [cm]
301 // temporary matrices needed for the calculation // for rotational symmetric RZ table, phislices is 1
303 TMatrixD *arrayofErA[kNPhiSlices], *arrayofdEzA[kNPhiSlices];
304 TMatrixD *arrayofErC[kNPhiSlices], *arrayofdEzC[kNPhiSlices];
306 TMatrixD *arrayofEroverEzA[kNPhiSlices], *arrayofDeltaEzA[kNPhiSlices];
307 TMatrixD *arrayofEroverEzC[kNPhiSlices], *arrayofDeltaEzC[kNPhiSlices];
310 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
312 arrayofErA[k] = new TMatrixD(rows,columns) ;
313 arrayofdEzA[k] = new TMatrixD(rows,columns) ;
314 arrayofErC[k] = new TMatrixD(rows,columns) ;
315 arrayofdEzC[k] = new TMatrixD(rows,columns) ;
317 arrayofEroverEzA[k] = new TMatrixD(rows,columns) ;
318 arrayofDeltaEzA[k] = new TMatrixD(rows,columns) ;
319 arrayofEroverEzC[k] = new TMatrixD(rows,columns) ;
320 arrayofDeltaEzC[k] = new TMatrixD(rows,columns) ;
322 // zero initialization not necessary, it is done in the constructor of TMatrix
326 // list of points as used during sum up
327 Double_t rlist1[kNRows], zedlist1[kNColumns];// , philist1[phiSlices];
328 for ( Int_t i = 0 ; i < rows ; i++ ) {
329 rlist1[i] = fgkIFCRadius + i*gridSizeR ;
330 for ( Int_t j = 0 ; j < columns ; j++ ) {
331 zedlist1[j] = j * gridSizeZ ;
335 TTree *treePOC = (TTree*)fZR->Get("POCall");
337 TVector *bEr = 0; //TVector *bEphi= 0;
340 treePOC->SetBranchAddress("Er",&bEr);
341 treePOC->SetBranchAddress("Ez",&bEz);
344 // Read the complete tree and do a weighted sum-up over the POC configurations
345 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
347 Int_t treeNumPOC = (Int_t)treePOC->GetEntries(); // Number of POC conf. in the look-up table
348 Int_t ipC = 0; // POC Conf. counter (note: different to the POC number in the tree!)
350 for (Int_t itreepC=0; itreepC<treeNumPOC; itreepC++) { // ------------- loop over POC configurations in tree
352 treePOC->GetEntry(itreepC);
354 // center of the POC voxel in [meter]
355 Double_t r0 = coordPOC1(ipC,0);
356 Double_t phi0 = coordPOC1(ipC,1);
357 Double_t z0 = coordPOC1(ipC,2);
359 ipC++; // POC configuration counter
361 // weights (charge density) at POC position on the A and C side (in C/m^3/e0)
362 // note: coordinates are in [cm]
363 Double_t weightA = GetSpaceChargeDensity(r0*100,phi0, z0*100, 1); // partial load in r,z
364 Double_t weightC = GetSpaceChargeDensity(r0*100,phi0,-z0*100, 1); // partial load in r,z
366 // Summing up the vector components according to their weight
369 for ( Int_t j = 0 ; j < columns ; j++ ) {
370 for ( Int_t i = 0 ; i < rows ; i++ ) {
371 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
373 // check wether the coordinates were screwed
374 if (TMath::Abs((coord1(0,ip)*100-rlist1[i]))>1 ||
375 TMath::Abs((coord1(2,ip)*100-zedlist1[j])>1)) {
376 AliError("internal error: coordinate system was screwed during the sum-up");
377 printf("sum-up: (r,z)=(%f,%f)\n",rlist1[i],zedlist1[j]);
378 printf("lookup: (r,z)=(%f,%f)\n",coord1(0,ip)*100,coord1(2,ip)*100);
379 AliError("Don't trust the results of the space charge calculation!");
382 // unfortunately, the lookup tables were produced to be faster for phi symmetric charges
383 // This will be the most frequent usage (hopefully)
384 // That's why we have to do this here ...
386 TMatrixD &erA = *arrayofErA[k] ;
387 TMatrixD &dEzA = *arrayofdEzA[k] ;
389 TMatrixD &erC = *arrayofErC[k] ;
390 TMatrixD &dEzC = *arrayofdEzC[k] ;
392 // Sum up - Efield values in [V/m] -> transition to [V/cm]
393 erA(i,j) += ((*bEr)(ip)) * weightA /100;
394 erC(i,j) += ((*bEr)(ip)) * weightC /100;
395 dEzA(i,j) += ((*bEz)(ip)) * weightA /100;
396 dEzC(i,j) += ((*bEz)(ip)) * weightC /100;
398 // increase the counter
402 } // end coordinate loop
406 // -------------------------------------------------------------------------------
407 // Division by the Ez (drift) field and integration along z
409 // AliInfo("Step 1: Division and integration");
411 Double_t ezField = (fgkCathodeV-fgkGG)/fgkTPCZ0; // = Electric Field (V/cm) Magnitude ~ -400 V/cm;
413 for ( Int_t k = 0 ; k < phiSlices ; k++ ) { // phi loop
415 // matrices holding the solution - summation of POC charges // see above
416 TMatrixD &erA = *arrayofErA[k] ;
417 TMatrixD &dezA = *arrayofdEzA[k] ;
418 TMatrixD &erC = *arrayofErC[k] ;
419 TMatrixD &dezC = *arrayofdEzC[k] ;
421 // matrices which will contain the integrated fields (divided by the drift field)
422 TMatrixD &erOverEzA = *arrayofEroverEzA[k] ;
423 TMatrixD &deltaEzA = *arrayofDeltaEzA[k];
424 TMatrixD &erOverEzC = *arrayofEroverEzC[k] ;
425 TMatrixD &deltaEzC = *arrayofDeltaEzC[k];
427 for ( Int_t i = 0 ; i < rows ; i++ ) { // r loop
428 for ( Int_t j = columns-1 ; j >= 0 ; j-- ) {// z loop
429 // Count backwards to facilitate integration over Z
431 Int_t index = 1 ; // Simpsons rule if N=odd.If N!=odd then add extra point
432 // by trapezoidal rule.
434 erOverEzA(i,j) = 0; //ephiOverEzA(i,j) = 0;
436 erOverEzC(i,j) = 0; //ephiOverEzC(i,j) = 0;
439 for ( Int_t m = j ; m < columns ; m++ ) { // integration
441 erOverEzA(i,j) += index*(gridSizeZ/3.0)*erA(i,m)/(-1*ezField) ;
442 erOverEzC(i,j) += index*(gridSizeZ/3.0)*erC(i,m)/(-1*ezField) ;
443 deltaEzA(i,j) += index*(gridSizeZ/3.0)*dezA(i,m)/(-1) ;
444 deltaEzC(i,j) += index*(gridSizeZ/3.0)*dezC(i,m)/(-1) ;
446 if ( index != 4 ) index = 4; else index = 2 ;
451 erOverEzA(i,j) -= (gridSizeZ/3.0)*erA(i,columns-1)/(-1*ezField) ;
452 erOverEzC(i,j) -= (gridSizeZ/3.0)*erC(i,columns-1)/(-1*ezField) ;
453 deltaEzA(i,j) -= (gridSizeZ/3.0)*dezA(i,columns-1)/(-1) ;
454 deltaEzC(i,j) -= (gridSizeZ/3.0)*dezC(i,columns-1)/(-1) ;
457 erOverEzA(i,j) += (gridSizeZ/3.0)*(0.5*erA(i,columns-2)-2.5*erA(i,columns-1))/(-1*ezField) ;
458 erOverEzC(i,j) += (gridSizeZ/3.0)*(0.5*erC(i,columns-2)-2.5*erC(i,columns-1))/(-1*ezField) ;
459 deltaEzA(i,j) += (gridSizeZ/3.0)*(0.5*dezA(i,columns-2)-2.5*dezA(i,columns-1))/(-1) ;
460 deltaEzC(i,j) += (gridSizeZ/3.0)*(0.5*dezC(i,columns-2)-2.5*dezC(i,columns-1))/(-1) ;
462 if ( j == columns-2 ) {
463 erOverEzA(i,j) = (gridSizeZ/3.0)*(1.5*erA(i,columns-2)+1.5*erA(i,columns-1))/(-1*ezField) ;
464 erOverEzC(i,j) = (gridSizeZ/3.0)*(1.5*erC(i,columns-2)+1.5*erC(i,columns-1))/(-1*ezField) ;
465 deltaEzA(i,j) = (gridSizeZ/3.0)*(1.5*dezA(i,columns-2)+1.5*dezA(i,columns-1))/(-1) ;
466 deltaEzC(i,j) = (gridSizeZ/3.0)*(1.5*dezC(i,columns-2)+1.5*dezC(i,columns-1))/(-1) ;
468 if ( j == columns-1 ) {
479 // AliInfo("Step 1: Interpolation to Standard grid");
481 // -------------------------------------------------------------------------------
482 // Interpolate results onto the standard grid which is used for all AliTPCCorrections classes
484 const Int_t order = 1 ; // Linear interpolation = 1, Quadratic = 2
486 Double_t r, z;//phi, z ;
487 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
488 // phi = fgkPhiList[k] ;
490 // final lookup table
491 TMatrixF &erOverEzFinal = *fLookUpErOverEz[k] ;
492 TMatrixF &deltaEzFinal = *fLookUpDeltaEz[k] ;
494 // calculated and integrated tables - just one phi slice
495 TMatrixD &erOverEzA = *arrayofEroverEzA[0] ;
496 TMatrixD &deltaEzA = *arrayofDeltaEzA[0];
497 TMatrixD &erOverEzC = *arrayofEroverEzC[0] ;
498 TMatrixD &deltaEzC = *arrayofDeltaEzC[0];
501 for ( Int_t j = 0 ; j < kNZ ; j++ ) {
503 z = TMath::Abs(fgkZList[j]) ; // z position is symmetric
505 for ( Int_t i = 0 ; i < kNR ; i++ ) {
508 // Interpolate Lookup tables onto standard grid
510 erOverEzFinal(i,j) = Interpolate2DTable(order, r, z, rows, columns, rlist1, zedlist1, erOverEzA );
511 deltaEzFinal(i,j) = Interpolate2DTable(order, r, z, rows, columns, rlist1, zedlist1, deltaEzA );
513 erOverEzFinal(i,j) = Interpolate2DTable(order, r, z, rows, columns, rlist1, zedlist1, erOverEzC );
514 deltaEzFinal(i,j) = - Interpolate2DTable(order, r, z, rows, columns, rlist1, zedlist1, deltaEzC );
515 // negative coordinate system on C side
523 // clear the temporary arrays lists
524 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
526 delete arrayofErA[k];
527 delete arrayofdEzA[k];
528 delete arrayofErC[k];
529 delete arrayofdEzC[k];
531 delete arrayofEroverEzA[k];
532 delete arrayofDeltaEzA[k];
533 delete arrayofEroverEzC[k];
534 delete arrayofDeltaEzC[k];
540 // ------------------------------------------------------------------------------------------------------
541 // Step 2: Load and sum up lookup table in rphi, fine grid, to emulate for example a GG leak
543 // AliInfo("Step 2: Preparation of the weighted look-up table");
545 TFile *fRPhi = new TFile(fSCLookUpPOCsFileNameRPhi.Data(),"READ");
547 AliError("Precalculated POC-looup-table in RPhi could not be found");
552 TVector *gridf2 = (TVector*) fRPhi->Get("constants");
553 TVector &grid2 = *gridf2;
554 TMatrix *coordf2 = (TMatrix*) fRPhi->Get("coordinates");
555 TMatrix &coord2 = *coordf2;
556 TMatrix *coordPOCf2 = (TMatrix*) fRPhi->Get("POCcoord");
557 TMatrix &coordPOC2 = *coordPOCf2;
559 rows = (Int_t)grid2(0); // number of points in r direction
560 phiSlices = (Int_t)grid2(1); // number of points in phi
561 columns = (Int_t)grid2(2); // number of points in z direction
563 gridSizeR = (fgkOFCRadius-fgkIFCRadius)/(rows-1); // unit in [cm]
564 Float_t gridSizePhi = TMath::TwoPi()/phiSlices; // unit in [rad]
565 gridSizeZ = fgkTPCZ0/(columns-1); // unit in [cm]
567 // list of points as used during sum up
568 Double_t rlist2[kNRows], philist2[kNPhiSlices], zedlist2[kNColumns];
569 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
570 philist2[k] = gridSizePhi * k;
571 for ( Int_t i = 0 ; i < rows ; i++ ) {
572 rlist2[i] = fgkIFCRadius + i*gridSizeR ;
573 for ( Int_t j = 0 ; j < columns ; j++ ) {
574 zedlist2[j] = j * gridSizeZ ;
579 // temporary matrices needed for the calculation
581 TMatrixD *arrayofErA2[kNPhiSlices], *arrayofEphiA2[kNPhiSlices], *arrayofdEzA2[kNPhiSlices];
582 TMatrixD *arrayofErC2[kNPhiSlices], *arrayofEphiC2[kNPhiSlices], *arrayofdEzC2[kNPhiSlices];
584 TMatrixD *arrayofEroverEzA2[kNPhiSlices], *arrayofEphioverEzA2[kNPhiSlices], *arrayofDeltaEzA2[kNPhiSlices];
585 TMatrixD *arrayofEroverEzC2[kNPhiSlices], *arrayofEphioverEzC2[kNPhiSlices], *arrayofDeltaEzC2[kNPhiSlices];
588 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
590 arrayofErA2[k] = new TMatrixD(rows,columns) ;
591 arrayofEphiA2[k] = new TMatrixD(rows,columns) ;
592 arrayofdEzA2[k] = new TMatrixD(rows,columns) ;
593 arrayofErC2[k] = new TMatrixD(rows,columns) ;
594 arrayofEphiC2[k] = new TMatrixD(rows,columns) ;
595 arrayofdEzC2[k] = new TMatrixD(rows,columns) ;
597 arrayofEroverEzA2[k] = new TMatrixD(rows,columns) ;
598 arrayofEphioverEzA2[k] = new TMatrixD(rows,columns) ;
599 arrayofDeltaEzA2[k] = new TMatrixD(rows,columns) ;
600 arrayofEroverEzC2[k] = new TMatrixD(rows,columns) ;
601 arrayofEphioverEzC2[k] = new TMatrixD(rows,columns) ;
602 arrayofDeltaEzC2[k] = new TMatrixD(rows,columns) ;
604 // zero initialization not necessary, it is done in the constructor of TMatrix
609 treePOC = (TTree*)fRPhi->Get("POCall");
611 // TVector *bEr = 0; // done above
613 // TVector *bEz = 0; // done above
615 treePOC->SetBranchAddress("Er",&bEr);
616 treePOC->SetBranchAddress("Ephi",&bEphi);
617 treePOC->SetBranchAddress("Ez",&bEz);
619 // Read the complete tree and do a weighted sum-up over the POC configurations
620 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
622 treeNumPOC = (Int_t)treePOC->GetEntries(); // Number of POC conf. in the look-up table
623 ipC = 0; // POC Conf. counter (note: different to the POC number in the tree!)
625 for (Int_t itreepC=0; itreepC<treeNumPOC; itreepC++) { // ------------- loop over POC configurations in tree
627 treePOC->GetEntry(itreepC);
629 // center of the POC voxel in [meter]
630 Double_t r0 = coordPOC2(ipC,0);
631 Double_t phi0 = coordPOC2(ipC,1);
632 // Double_t z0 = coordPOC2(ipC,2);
634 // weights (charge density) at POC position on the A and C side (in C/m^3/e0)
635 // note: coordinates are in [cm]
636 Double_t weightA = GetSpaceChargeDensity(r0*100,phi0, 0.499, 2); // partial load in r,phi
637 Double_t weightC = GetSpaceChargeDensity(r0*100,phi0,-0.499, 2); // partial load in r,phi
639 // printf("-----\n%f %f : %e %e\n",r0,phi0,weightA,weightC);
641 // Summing up the vector components according to their weight
644 for ( Int_t j = 0 ; j < columns ; j++ ) {
645 for ( Int_t i = 0 ; i < rows ; i++ ) {
646 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
648 // check wether the coordinates were screwed
649 if (TMath::Abs((coord2(0,ip)*100-rlist2[i]))>1 ||
650 TMath::Abs((coord2(1,ip)-philist2[k]))>1 ||
651 TMath::Abs((coord2(2,ip)*100-zedlist2[j]))>1) {
652 AliError("internal error: coordinate system was screwed during the sum-up");
653 printf("lookup: (r,phi,z)=(%f,%f,%f)\n",coord2(0,ip)*100,coord2(1,ip),coord2(2,ip)*100);
654 printf("sum-up: (r,phi,z)=(%f,%f,%f)\n",rlist2[i],philist2[k],zedlist2[j]);
655 AliError("Don't trust the results of the space charge calculation!");
658 // unfortunately, the lookup tables were produced to be faster for phi symmetric charges
659 // This will be the most frequent usage (hopefully)
660 // That's why we have to do this here ...
662 TMatrixD &erA = *arrayofErA2[k] ;
663 TMatrixD &ephiA = *arrayofEphiA2[k];
664 TMatrixD &dEzA = *arrayofdEzA2[k] ;
666 TMatrixD &erC = *arrayofErC2[k] ;
667 TMatrixD &ephiC = *arrayofEphiC2[k];
668 TMatrixD &dEzC = *arrayofdEzC2[k] ;
670 // Sum up - Efield values in [V/m] -> transition to [V/cm]
671 erA(i,j) += ((*bEr)(ip)) * weightA /100;
672 erC(i,j) += ((*bEr)(ip)) * weightC /100;
673 ephiA(i,j) += ((*bEphi)(ip)) * weightA/100; // [V/rad]
674 ephiC(i,j) += ((*bEphi)(ip)) * weightC/100; // [V/rad]
675 dEzA(i,j) += ((*bEz)(ip)) * weightA /100;
676 dEzC(i,j) += ((*bEz)(ip)) * weightC /100;
678 // increase the counter
682 } // end coordinate loop
685 // Rotation and summation in the rest of the dPhiSteps
686 // which were not stored in the this tree due to storage & symmetry reasons
689 Int_t phiPoints = (Int_t) grid2(1);
690 Int_t phiPOC = (Int_t) grid2(4);
692 // printf("%d %d\n",phiPOC,flagRadSym);
694 for (Int_t phiiC = 1; phiiC<phiPOC; phiiC++) { // just used for non-radial symetric table
696 Double_t phi0R = phiiC*phi0*2 + phi0; // rotate further
698 // weights (charge density) at POC position on the A and C side (in C/m^3/e0)
699 // note: coordinates are in [cm] // ecxept z
700 weightA = GetSpaceChargeDensity(r0*100,phi0R, 0.499, 2); // partial load in r,phi
701 weightC = GetSpaceChargeDensity(r0*100,phi0R,-0.499, 2); // partial load in r,phi
703 // printf("%f %f : %e %e\n",r0,phi0R,weightA,weightC);
705 // Summing up the vector components according to their weight
707 for ( Int_t j = 0 ; j < columns ; j++ ) {
708 for ( Int_t i = 0 ; i < rows ; i++ ) {
709 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
711 // Note: rotating the coordinated during the sum up
713 Int_t rotVal = (phiPoints/phiPOC)*phiiC;
716 if ((ip%phiPoints)>=rotVal) {
719 ipR = ip+(phiPoints-rotVal);
722 // unfortunately, the lookup tables were produced to be faster for phi symmetric charges
723 // This will be the most frequent usage
724 // That's why we have to do this here and not outside the loop ...
726 TMatrixD &erA = *arrayofErA2[k] ;
727 TMatrixD &ephiA = *arrayofEphiA2[k];
728 TMatrixD &dEzA = *arrayofdEzA2[k] ;
730 TMatrixD &erC = *arrayofErC2[k] ;
731 TMatrixD &ephiC = *arrayofEphiC2[k];
732 TMatrixD &dEzC = *arrayofdEzC2[k] ;
734 // Sum up - Efield values in [V/m] -> transition to [V/cm]
735 erA(i,j) += ((*bEr)(ipR)) * weightA /100;
736 erC(i,j) += ((*bEr)(ipR)) * weightC /100;
737 ephiA(i,j) += ((*bEphi)(ipR)) * weightA/100; // [V/rad]
738 ephiC(i,j) += ((*bEphi)(ipR)) * weightC/100; // [V/rad]
739 dEzA(i,j) += ((*bEz)(ipR)) * weightA /100;
740 dEzC(i,j) += ((*bEz)(ipR)) * weightC /100;
742 // increase the counter
746 } // end coordinate loop
748 } // end phi-POC summation (phiiC)
750 ipC++; // POC configuration counter
752 // printf("POC: (r,phi,z) = (%f %f %f) | weight(A,C): %03.1lf %03.1lf\n",r0,phi0,z0, weightA, weightC);
759 // -------------------------------------------------------------------------------
760 // Division by the Ez (drift) field and integration along z
762 // AliInfo("Step 2: Division and integration");
765 for ( Int_t k = 0 ; k < phiSlices ; k++ ) { // phi loop
767 // matrices holding the solution - summation of POC charges // see above
768 TMatrixD &erA = *arrayofErA2[k] ;
769 TMatrixD &ephiA = *arrayofEphiA2[k];
770 TMatrixD &dezA = *arrayofdEzA2[k] ;
771 TMatrixD &erC = *arrayofErC2[k] ;
772 TMatrixD &ephiC = *arrayofEphiC2[k];
773 TMatrixD &dezC = *arrayofdEzC2[k] ;
775 // matrices which will contain the integrated fields (divided by the drift field)
776 TMatrixD &erOverEzA = *arrayofEroverEzA2[k] ;
777 TMatrixD &ephiOverEzA = *arrayofEphioverEzA2[k];
778 TMatrixD &deltaEzA = *arrayofDeltaEzA2[k];
779 TMatrixD &erOverEzC = *arrayofEroverEzC2[k] ;
780 TMatrixD &ephiOverEzC = *arrayofEphioverEzC2[k];
781 TMatrixD &deltaEzC = *arrayofDeltaEzC2[k];
783 for ( Int_t i = 0 ; i < rows ; i++ ) { // r loop
784 for ( Int_t j = columns-1 ; j >= 0 ; j-- ) {// z loop
785 // Count backwards to facilitate integration over Z
787 Int_t index = 1 ; // Simpsons rule if N=odd.If N!=odd then add extra point by trapezoidal rule.
790 ephiOverEzA(i,j) = 0;
793 ephiOverEzC(i,j) = 0;
796 for ( Int_t m = j ; m < columns ; m++ ) { // integration
798 erOverEzA(i,j) += index*(gridSizeZ/3.0)*erA(i,m)/(-1*ezField) ;
799 erOverEzC(i,j) += index*(gridSizeZ/3.0)*erC(i,m)/(-1*ezField) ;
800 ephiOverEzA(i,j) += index*(gridSizeZ/3.0)*ephiA(i,m)/(-1*ezField) ;
801 ephiOverEzC(i,j) += index*(gridSizeZ/3.0)*ephiC(i,m)/(-1*ezField) ;
802 deltaEzA(i,j) += index*(gridSizeZ/3.0)*dezA(i,m)/(-1) ;
803 deltaEzC(i,j) += index*(gridSizeZ/3.0)*dezC(i,m)/(-1) ;
805 if ( index != 4 ) index = 4; else index = 2 ;
810 erOverEzA(i,j) -= (gridSizeZ/3.0)*erA(i,columns-1)/(-1*ezField) ;
811 erOverEzC(i,j) -= (gridSizeZ/3.0)*erC(i,columns-1)/(-1*ezField) ;
812 ephiOverEzA(i,j) -= (gridSizeZ/3.0)*ephiA(i,columns-1)/(-1*ezField) ;
813 ephiOverEzC(i,j) -= (gridSizeZ/3.0)*ephiC(i,columns-1)/(-1*ezField) ;
814 deltaEzA(i,j) -= (gridSizeZ/3.0)*dezA(i,columns-1)/(-1) ;
815 deltaEzC(i,j) -= (gridSizeZ/3.0)*dezC(i,columns-1)/(-1) ;
818 erOverEzA(i,j) += (gridSizeZ/3.0)*(0.5*erA(i,columns-2)-2.5*erA(i,columns-1))/(-1*ezField) ;
819 erOverEzC(i,j) += (gridSizeZ/3.0)*(0.5*erC(i,columns-2)-2.5*erC(i,columns-1))/(-1*ezField) ;
820 ephiOverEzA(i,j) += (gridSizeZ/3.0)*(0.5*ephiA(i,columns-2)-2.5*ephiA(i,columns-1))/(-1*ezField) ;
821 ephiOverEzC(i,j) += (gridSizeZ/3.0)*(0.5*ephiC(i,columns-2)-2.5*ephiC(i,columns-1))/(-1*ezField) ;
822 deltaEzA(i,j) += (gridSizeZ/3.0)*(0.5*dezA(i,columns-2)-2.5*dezA(i,columns-1))/(-1) ;
823 deltaEzC(i,j) += (gridSizeZ/3.0)*(0.5*dezC(i,columns-2)-2.5*dezC(i,columns-1))/(-1) ;
825 if ( j == columns-2 ) {
826 erOverEzA(i,j) = (gridSizeZ/3.0)*(1.5*erA(i,columns-2)+1.5*erA(i,columns-1))/(-1*ezField) ;
827 erOverEzC(i,j) = (gridSizeZ/3.0)*(1.5*erC(i,columns-2)+1.5*erC(i,columns-1))/(-1*ezField) ;
828 ephiOverEzA(i,j) = (gridSizeZ/3.0)*(1.5*ephiA(i,columns-2)+1.5*ephiA(i,columns-1))/(-1*ezField) ;
829 ephiOverEzC(i,j) = (gridSizeZ/3.0)*(1.5*ephiC(i,columns-2)+1.5*ephiC(i,columns-1))/(-1*ezField) ;
830 deltaEzA(i,j) = (gridSizeZ/3.0)*(1.5*dezA(i,columns-2)+1.5*dezA(i,columns-1))/(-1) ;
831 deltaEzC(i,j) = (gridSizeZ/3.0)*(1.5*dezC(i,columns-2)+1.5*dezC(i,columns-1))/(-1) ;
833 if ( j == columns-1 ) {
836 ephiOverEzA(i,j) = 0;
837 ephiOverEzC(i,j) = 0;
846 AliInfo("Step 2: Interpolation to Standard grid");
848 // -------------------------------------------------------------------------------
849 // Interpolate results onto the standard grid which is used for all AliTPCCorrections classes
852 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
853 Double_t phi = fgkPhiList[k] ;
855 // final lookup table
856 TMatrixF &erOverEzFinal = *fLookUpErOverEz[k] ;
857 TMatrixF &ephiOverEzFinal = *fLookUpEphiOverEz[k];
858 TMatrixF &deltaEzFinal = *fLookUpDeltaEz[k] ;
860 for ( Int_t j = 0 ; j < kNZ ; j++ ) {
862 z = TMath::Abs(fgkZList[j]) ; // z position is symmetric
864 for ( Int_t i = 0 ; i < kNR ; i++ ) {
867 // Interpolate Lookup tables onto standard grid
869 erOverEzFinal(i,j) += Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
870 rlist2, zedlist2, philist2, arrayofEroverEzA2 );
871 ephiOverEzFinal(i,j) += Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
872 rlist2, zedlist2, philist2, arrayofEphioverEzA2);
873 deltaEzFinal(i,j) += Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
874 rlist2, zedlist2, philist2, arrayofDeltaEzA2 );
876 erOverEzFinal(i,j) += Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
877 rlist2, zedlist2, philist2, arrayofEroverEzC2 );
878 ephiOverEzFinal(i,j) += Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
879 rlist2, zedlist2, philist2, arrayofEphioverEzC2);
880 deltaEzFinal(i,j) -= Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
881 rlist2, zedlist2, philist2, arrayofDeltaEzC2 );
889 // clear the temporary arrays lists
890 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
892 delete arrayofErA2[k];
893 delete arrayofEphiA2[k];
894 delete arrayofdEzA2[k];
895 delete arrayofErC2[k];
896 delete arrayofEphiC2[k];
897 delete arrayofdEzC2[k];
899 delete arrayofEroverEzA2[k];
900 delete arrayofEphioverEzA2[k];
901 delete arrayofDeltaEzA2[k];
902 delete arrayofEroverEzC2[k];
903 delete arrayofEphioverEzC2[k];
904 delete arrayofDeltaEzC2[k];
916 void AliTPCSpaceCharge3D::InitSpaceCharge3DDistortionCourse() {
918 // Initialization of the Lookup table which contains the solutions of the
919 // "space charge" (poisson) problem
921 // The sum-up uses a look-up table which contains different discretized Space charge fields
922 // in order to calculate the corresponding field deviations due to a given (discretized)
923 // space charge distribution ....
925 // Method of calculation: Weighted sum-up of the different fields within the look up table
926 // Note: Full 3d version: Course and slow ...
929 AliInfo("Lookup table was already initialized!");
933 AliInfo("Preparation of the weighted look-up table");
935 TFile *f = new TFile(fSCLookUpPOCsFileName3D.Data(),"READ");
937 AliError("Precalculated POC-looup-table could not be found");
942 TVector *gridf = (TVector*) f->Get("constants");
943 TVector &grid = *gridf;
944 TMatrix *coordf = (TMatrix*) f->Get("coordinates");
945 TMatrix &coord = *coordf;
946 TMatrix *coordPOCf = (TMatrix*) f->Get("POCcoord");
947 TMatrix &coordPOC = *coordPOCf;
949 Bool_t flagRadSym = 0;
950 if (grid(1)==1 && grid(4)==1) {
951 // AliInfo("LOOK UP TABLE IS RADIAL SYMETTRIC - Field in Phi is ZERO");
955 Int_t rows = (Int_t)grid(0); // number of points in r direction
956 Int_t phiSlices = (Int_t)grid(1); // number of points in phi
957 Int_t columns = (Int_t)grid(2); // number of points in z direction
959 const Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius)/(rows-1); // unit in [cm]
960 const Float_t gridSizePhi = TMath::TwoPi()/phiSlices; // unit in [rad]
961 const Float_t gridSizeZ = fgkTPCZ0/(columns-1); // unit in [cm]
963 // temporary matrices needed for the calculation
964 TMatrixD *arrayofErA[kNPhiSlices], *arrayofEphiA[kNPhiSlices], *arrayofdEzA[kNPhiSlices];
965 TMatrixD *arrayofErC[kNPhiSlices], *arrayofEphiC[kNPhiSlices], *arrayofdEzC[kNPhiSlices];
967 TMatrixD *arrayofEroverEzA[kNPhiSlices], *arrayofEphioverEzA[kNPhiSlices], *arrayofDeltaEzA[kNPhiSlices];
968 TMatrixD *arrayofEroverEzC[kNPhiSlices], *arrayofEphioverEzC[kNPhiSlices], *arrayofDeltaEzC[kNPhiSlices];
971 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
973 arrayofErA[k] = new TMatrixD(rows,columns) ;
974 arrayofEphiA[k] = new TMatrixD(rows,columns) ; // zero if radial symmetric
975 arrayofdEzA[k] = new TMatrixD(rows,columns) ;
976 arrayofErC[k] = new TMatrixD(rows,columns) ;
977 arrayofEphiC[k] = new TMatrixD(rows,columns) ; // zero if radial symmetric
978 arrayofdEzC[k] = new TMatrixD(rows,columns) ;
980 arrayofEroverEzA[k] = new TMatrixD(rows,columns) ;
981 arrayofEphioverEzA[k] = new TMatrixD(rows,columns) ; // zero if radial symmetric
982 arrayofDeltaEzA[k] = new TMatrixD(rows,columns) ;
983 arrayofEroverEzC[k] = new TMatrixD(rows,columns) ;
984 arrayofEphioverEzC[k] = new TMatrixD(rows,columns) ; // zero if radial symmetric
985 arrayofDeltaEzC[k] = new TMatrixD(rows,columns) ;
987 // Set the values to zero the lookup tables
988 // not necessary, it is done in the constructor of TMatrix - code deleted
992 // list of points as used in the interpolation (during sum up)
993 Double_t rlist[kNRows], zedlist[kNColumns] , philist[kNPhiSlices];
994 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
995 philist[k] = gridSizePhi * k;
996 for ( Int_t i = 0 ; i < rows ; i++ ) {
997 rlist[i] = fgkIFCRadius + i*gridSizeR ;
998 for ( Int_t j = 0 ; j < columns ; j++ ) {
999 zedlist[j] = j * gridSizeZ ;
1005 TTree *treePOC = (TTree*)f->Get("POCall");
1007 TVector *bEr = 0; TVector *bEphi= 0; TVector *bEz = 0;
1009 treePOC->SetBranchAddress("Er",&bEr);
1010 if (!flagRadSym) treePOC->SetBranchAddress("Ephi",&bEphi);
1011 treePOC->SetBranchAddress("Ez",&bEz);
1014 // Read the complete tree and do a weighted sum-up over the POC configurations
1015 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1017 Int_t treeNumPOC = (Int_t)treePOC->GetEntries(); // Number of POC conf. in the look-up table
1018 Int_t ipC = 0; // POC Conf. counter (note: different to the POC number in the tree!)
1020 for (Int_t itreepC=0; itreepC<treeNumPOC; itreepC++) { // ------------- loop over POC configurations in tree
1022 treePOC->GetEntry(itreepC);
1024 // center of the POC voxel in [meter]
1025 Double_t r0 = coordPOC(ipC,0);
1026 Double_t phi0 = coordPOC(ipC,1);
1027 Double_t z0 = coordPOC(ipC,2);
1029 ipC++; // POC configuration counter
1031 // weights (charge density) at POC position on the A and C side (in C/m^3/e0)
1032 // note: coordinates are in [cm]
1033 Double_t weightA = GetSpaceChargeDensity(r0*100,phi0, z0*100,0);
1034 Double_t weightC = GetSpaceChargeDensity(r0*100,phi0,-z0*100,0);
1036 // Summing up the vector components according to their weight
1039 for ( Int_t j = 0 ; j < columns ; j++ ) {
1040 for ( Int_t i = 0 ; i < rows ; i++ ) {
1041 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
1043 // check wether the coordinates were screwed
1044 if (TMath::Abs((coord(0,ip)*100-rlist[i]))>1 ||
1045 TMath::Abs((coord(1,ip)-philist[k]))>1 ||
1046 TMath::Abs((coord(2,ip)*100-zedlist[j]))>1) {
1047 AliError("internal error: coordinate system was screwed during the sum-up");
1048 printf("lookup: (r,phi,z)=(%f,%f,%f)\n",coord(0,ip)*100,coord(1,ip),coord(2,ip)*100);
1049 printf("sum-up: (r,phi,z)=(%f,%f,%f)\n",rlist[i],philist[k],zedlist[j]);
1050 AliError("Don't trust the results of the space charge calculation!");
1053 // unfortunately, the lookup tables were produced to be faster for phi symmetric charges
1054 // This will be the most frequent usage (hopefully)
1055 // That's why we have to do this here ...
1057 TMatrixD &erA = *arrayofErA[k] ;
1058 TMatrixD &ephiA = *arrayofEphiA[k];
1059 TMatrixD &dEzA = *arrayofdEzA[k] ;
1061 TMatrixD &erC = *arrayofErC[k] ;
1062 TMatrixD &ephiC = *arrayofEphiC[k];
1063 TMatrixD &dEzC = *arrayofdEzC[k] ;
1065 // Sum up - Efield values in [V/m] -> transition to [V/cm]
1066 erA(i,j) += ((*bEr)(ip)) * weightA /100;
1067 erC(i,j) += ((*bEr)(ip)) * weightC /100;
1069 ephiA(i,j) += ((*bEphi)(ip)) * weightA/100; // [V/rad]
1070 ephiC(i,j) += ((*bEphi)(ip)) * weightC/100; // [V/rad]
1072 dEzA(i,j) += ((*bEz)(ip)) * weightA /100;
1073 dEzC(i,j) += ((*bEz)(ip)) * weightC /100;
1075 // increase the counter
1079 } // end coordinate loop
1082 // Rotation and summation in the rest of the dPhiSteps
1083 // which were not stored in the this tree due to storage & symmetry reasons
1085 Int_t phiPoints = (Int_t) grid(1);
1086 Int_t phiPOC = (Int_t) grid(4);
1088 // printf("%d %d\n",phiPOC,flagRadSym);
1090 for (Int_t phiiC = 1; phiiC<phiPOC; phiiC++) { // just used for non-radial symetric table
1092 r0 = coordPOC(ipC,0);
1093 phi0 = coordPOC(ipC,1);
1094 z0 = coordPOC(ipC,2);
1096 ipC++; // POC conf. counter
1098 // weights (charge density) at POC position on the A and C side (in C/m^3/e0)
1099 // note: coordinates are in [cm]
1100 weightA = GetSpaceChargeDensity(r0*100,phi0, z0*100,0);
1101 weightC = GetSpaceChargeDensity(r0*100,phi0,-z0*100,0);
1103 // printf("%f %f %f: %e %e\n",r0,phi0,z0,weightA,weightC);
1105 // Summing up the vector components according to their weight
1107 for ( Int_t j = 0 ; j < columns ; j++ ) {
1108 for ( Int_t i = 0 ; i < rows ; i++ ) {
1109 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
1111 // Note: rotating the coordinated during the sum up
1113 Int_t rotVal = (phiPoints/phiPOC)*phiiC;
1116 if ((ip%phiPoints)>=rotVal) {
1119 ipR = ip+(phiPoints-rotVal);
1122 // unfortunately, the lookup tables were produced to be faster for phi symmetric charges
1123 // This will be the most frequent usage
1124 // That's why we have to do this here and not outside the loop ...
1126 TMatrixD &erA = *arrayofErA[k] ;
1127 TMatrixD &ephiA = *arrayofEphiA[k];
1128 TMatrixD &dEzA = *arrayofdEzA[k] ;
1130 TMatrixD &erC = *arrayofErC[k] ;
1131 TMatrixD &ephiC = *arrayofEphiC[k];
1132 TMatrixD &dEzC = *arrayofdEzC[k] ;
1134 // Sum up - Efield values in [V/m] -> transition to [V/cm]
1135 erA(i,j) += ((*bEr)(ipR)) * weightA /100;
1136 erC(i,j) += ((*bEr)(ipR)) * weightC /100;
1138 ephiA(i,j) += ((*bEphi)(ipR)) * weightA/100; // [V/rad]
1139 ephiC(i,j) += ((*bEphi)(ipR)) * weightC/100; // [V/rad]
1141 dEzA(i,j) += ((*bEz)(ipR)) * weightA /100;
1142 dEzC(i,j) += ((*bEz)(ipR)) * weightC /100;
1144 // increase the counter
1148 } // end coordinate loop
1150 } // end phi-POC summation (phiiC)
1153 // printf("POC: (r,phi,z) = (%f %f %f) | weight(A,C): %03.1lf %03.1lf\n",r0,phi0,z0, weightA, weightC);
1159 // -------------------------------------------------------------------------------
1160 // Division by the Ez (drift) field and integration along z
1162 AliInfo("Division and integration");
1164 Double_t ezField = (fgkCathodeV-fgkGG)/fgkTPCZ0; // = Electric Field (V/cm) Magnitude ~ -400 V/cm;
1166 for ( Int_t k = 0 ; k < phiSlices ; k++ ) { // phi loop
1168 // matrices holding the solution - summation of POC charges // see above
1169 TMatrixD &erA = *arrayofErA[k] ;
1170 TMatrixD &ephiA = *arrayofEphiA[k];
1171 TMatrixD &dezA = *arrayofdEzA[k] ;
1172 TMatrixD &erC = *arrayofErC[k] ;
1173 TMatrixD &ephiC = *arrayofEphiC[k];
1174 TMatrixD &dezC = *arrayofdEzC[k] ;
1176 // matrices which will contain the integrated fields (divided by the drift field)
1177 TMatrixD &erOverEzA = *arrayofEroverEzA[k] ;
1178 TMatrixD &ephiOverEzA = *arrayofEphioverEzA[k];
1179 TMatrixD &deltaEzA = *arrayofDeltaEzA[k];
1180 TMatrixD &erOverEzC = *arrayofEroverEzC[k] ;
1181 TMatrixD &ephiOverEzC = *arrayofEphioverEzC[k];
1182 TMatrixD &deltaEzC = *arrayofDeltaEzC[k];
1184 for ( Int_t i = 0 ; i < rows ; i++ ) { // r loop
1185 for ( Int_t j = columns-1 ; j >= 0 ; j-- ) {// z loop
1186 // Count backwards to facilitate integration over Z
1188 Int_t index = 1 ; // Simpsons rule if N=odd.If N!=odd then add extra point by trapezoidal rule.
1190 erOverEzA(i,j) = 0; ephiOverEzA(i,j) = 0; deltaEzA(i,j) = 0;
1191 erOverEzC(i,j) = 0; ephiOverEzC(i,j) = 0; deltaEzC(i,j) = 0;
1193 for ( Int_t m = j ; m < columns ; m++ ) { // integration
1195 erOverEzA(i,j) += index*(gridSizeZ/3.0)*erA(i,m)/(-1*ezField) ;
1196 erOverEzC(i,j) += index*(gridSizeZ/3.0)*erC(i,m)/(-1*ezField) ;
1198 ephiOverEzA(i,j) += index*(gridSizeZ/3.0)*ephiA(i,m)/(-1*ezField) ;
1199 ephiOverEzC(i,j) += index*(gridSizeZ/3.0)*ephiC(i,m)/(-1*ezField) ;
1201 deltaEzA(i,j) += index*(gridSizeZ/3.0)*dezA(i,m)/(-1) ;
1202 deltaEzC(i,j) += index*(gridSizeZ/3.0)*dezC(i,m)/(-1) ;
1204 if ( index != 4 ) index = 4; else index = 2 ;
1209 erOverEzA(i,j) -= (gridSizeZ/3.0)*erA(i,columns-1)/(-1*ezField) ;
1210 erOverEzC(i,j) -= (gridSizeZ/3.0)*erC(i,columns-1)/(-1*ezField) ;
1212 ephiOverEzA(i,j) -= (gridSizeZ/3.0)*ephiA(i,columns-1)/(-1*ezField) ;
1213 ephiOverEzC(i,j) -= (gridSizeZ/3.0)*ephiC(i,columns-1)/(-1*ezField) ;
1215 deltaEzA(i,j) -= (gridSizeZ/3.0)*dezA(i,columns-1)/(-1) ;
1216 deltaEzC(i,j) -= (gridSizeZ/3.0)*dezC(i,columns-1)/(-1) ;
1219 erOverEzA(i,j) += (gridSizeZ/3.0)*(0.5*erA(i,columns-2)-2.5*erA(i,columns-1))/(-1*ezField) ;
1220 erOverEzC(i,j) += (gridSizeZ/3.0)*(0.5*erC(i,columns-2)-2.5*erC(i,columns-1))/(-1*ezField) ;
1222 ephiOverEzA(i,j) += (gridSizeZ/3.0)*(0.5*ephiA(i,columns-2)-2.5*ephiA(i,columns-1))/(-1*ezField) ;
1223 ephiOverEzC(i,j) += (gridSizeZ/3.0)*(0.5*ephiC(i,columns-2)-2.5*ephiC(i,columns-1))/(-1*ezField) ;
1225 deltaEzA(i,j) += (gridSizeZ/3.0)*(0.5*dezA(i,columns-2)-2.5*dezA(i,columns-1))/(-1) ;
1226 deltaEzC(i,j) += (gridSizeZ/3.0)*(0.5*dezC(i,columns-2)-2.5*dezC(i,columns-1))/(-1) ;
1228 if ( j == columns-2 ) {
1229 erOverEzA(i,j) = (gridSizeZ/3.0)*(1.5*erA(i,columns-2)+1.5*erA(i,columns-1))/(-1*ezField) ;
1230 erOverEzC(i,j) = (gridSizeZ/3.0)*(1.5*erC(i,columns-2)+1.5*erC(i,columns-1))/(-1*ezField) ;
1232 ephiOverEzA(i,j) = (gridSizeZ/3.0)*(1.5*ephiA(i,columns-2)+1.5*ephiA(i,columns-1))/(-1*ezField) ;
1233 ephiOverEzC(i,j) = (gridSizeZ/3.0)*(1.5*ephiC(i,columns-2)+1.5*ephiC(i,columns-1))/(-1*ezField) ;
1235 deltaEzA(i,j) = (gridSizeZ/3.0)*(1.5*dezA(i,columns-2)+1.5*dezA(i,columns-1))/(-1) ;
1236 deltaEzC(i,j) = (gridSizeZ/3.0)*(1.5*dezC(i,columns-2)+1.5*dezC(i,columns-1))/(-1) ;
1238 if ( j == columns-1 ) {
1242 ephiOverEzA(i,j) = 0;
1243 ephiOverEzC(i,j) = 0;
1255 AliInfo("Interpolation to Standard grid");
1257 // -------------------------------------------------------------------------------
1258 // Interpolate results onto the standard grid which is used for all AliTPCCorrections classes
1260 const Int_t order = 1 ; // Linear interpolation = 1, Quadratic = 2
1262 Double_t r, phi, z ;
1263 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
1264 phi = fgkPhiList[k] ;
1266 TMatrixF &erOverEz = *fLookUpErOverEz[k] ;
1267 TMatrixF &ephiOverEz = *fLookUpEphiOverEz[k];
1268 TMatrixF &deltaEz = *fLookUpDeltaEz[k] ;
1270 for ( Int_t j = 0 ; j < kNZ ; j++ ) {
1272 z = TMath::Abs(fgkZList[j]) ; // z position is symmetric
1274 for ( Int_t i = 0 ; i < kNR ; i++ ) {
1277 // Interpolate Lookup tables onto standard grid
1278 if (fgkZList[j]>0) {
1279 erOverEz(i,j) = Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
1280 rlist, zedlist, philist, arrayofEroverEzA );
1281 ephiOverEz(i,j) = Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
1282 rlist, zedlist, philist, arrayofEphioverEzA);
1283 deltaEz(i,j) = Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
1284 rlist, zedlist, philist, arrayofDeltaEzA );
1286 erOverEz(i,j) = Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
1287 rlist, zedlist, philist, arrayofEroverEzC );
1288 ephiOverEz(i,j) = Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
1289 rlist, zedlist, philist, arrayofEphioverEzC);
1290 deltaEz(i,j) = - Interpolate3DTable(order, r, z, phi, rows, columns, phiSlices,
1291 rlist, zedlist, philist, arrayofDeltaEzC );
1292 // negative coordinate system on C side
1300 // clear the temporary arrays lists
1301 for ( Int_t k = 0 ; k < phiSlices ; k++ ) {
1303 delete arrayofErA[k];
1304 delete arrayofEphiA[k];
1305 delete arrayofdEzA[k];
1306 delete arrayofErC[k];
1307 delete arrayofEphiC[k];
1308 delete arrayofdEzC[k];
1310 delete arrayofEroverEzA[k];
1311 delete arrayofEphioverEzA[k];
1312 delete arrayofDeltaEzA[k];
1313 delete arrayofEroverEzC[k];
1314 delete arrayofEphioverEzC[k];
1315 delete arrayofDeltaEzC[k];
1319 fInitLookUp = kTRUE;
1324 void AliTPCSpaceCharge3D::SetSCDataFileName(TString fname) {
1326 // Set & load the Space charge density distribution from a file
1327 // (linear interpolation onto a standard grid)
1331 fSCDataFileName = fname;
1333 TFile *f = new TFile(fSCDataFileName.Data(),"READ");
1335 AliError(Form("File %s, which should contain the space charge distribution, could not be found",
1336 fSCDataFileName.Data()));
1340 TH2F *densityRZ = (TH2F*) f->Get("SpaceChargeInRZ");
1342 AliError(Form("The indicated file (%s) does not contain a histogram called %s",
1343 fSCDataFileName.Data(),"SpaceChargeInRZ"));
1347 TH3F *densityRPhi = (TH3F*) f->Get("SpaceChargeInRPhi");
1349 AliError(Form("The indicated file (%s) does not contain a histogram called %s",
1350 fSCDataFileName.Data(),"SpaceChargeInRPhi"));
1355 Double_t r, phi, z ;
1357 TMatrixD &scDensityInRZ = *fSCdensityInRZ;
1358 TMatrixD &scDensityInRPhiA = *fSCdensityInRPhiA;
1359 TMatrixD &scDensityInRPhiC = *fSCdensityInRPhiC;
1360 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
1361 phi = fgkPhiList[k] ;
1362 TMatrixF &scDensity = *fSCdensityDistribution[k] ;
1363 for ( Int_t j = 0 ; j < kNZ ; j++ ) {
1365 for ( Int_t i = 0 ; i < kNR ; i++ ) {
1368 // partial load in (r,z)
1369 if (k==0) // do just once
1370 scDensityInRZ(i,j) = densityRZ->Interpolate(r,z);
1372 // partial load in (r,phi)
1373 if ( j==0 || j == kNZ/2 ) {
1375 scDensityInRPhiA(i,k) = densityRPhi->Interpolate(r,phi,0.499); // A side
1377 scDensityInRPhiC(i,k) = densityRPhi->Interpolate(r,phi,-0.499); // C side
1380 // Full 3D configuration ...
1382 scDensity(i,j) = scDensityInRZ(i,j) + scDensityInRPhiA(i,k);
1384 scDensity(i,j) = scDensityInRZ(i,j) + scDensityInRPhiC(i,k);
1391 fInitLookUp = kFALSE;
1396 void AliTPCSpaceCharge3D::SetInputSpaceCharge(TH3 * hisSpaceCharge3D, TH2 * hisRPhi, TH2* hisRZ, Double_t norm){
1398 // Use 3D space charge map as an optional input
1399 // The layout of the input histogram is assumed to be: (phi,r,z)
1400 // Density histogram is expreseed is expected to bin in C/m^3
1402 // Standard histogram interpolation is used in order to use the density at center of voxel
1405 fSpaceChargeHistogram3D = hisSpaceCharge3D;
1406 fSpaceChargeHistogramRPhi = hisRPhi;
1407 fSpaceChargeHistogramRZ = hisRZ;
1409 Double_t r, phi, z ;
1410 TMatrixD &scDensityInRZ = *fSCdensityInRZ;
1411 TMatrixD &scDensityInRPhiA = *fSCdensityInRPhiA;
1412 TMatrixD &scDensityInRPhiC = *fSCdensityInRPhiC;
1414 Double_t rmin=hisSpaceCharge3D->GetYaxis()->GetBinCenter(0);
1415 Double_t rmax=hisSpaceCharge3D->GetYaxis()->GetBinUpEdge(hisSpaceCharge3D->GetYaxis()->GetNbins());
1416 Double_t zmin=hisSpaceCharge3D->GetZaxis()->GetBinCenter(0);
1417 Double_t zmax=hisSpaceCharge3D->GetZaxis()->GetBinCenter(hisSpaceCharge3D->GetZaxis()->GetNbins());
1419 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
1420 phi = fgkPhiList[k] ;
1421 TMatrixF &scDensity = *fSCdensityDistribution[k] ;
1422 for ( Int_t j = 0 ; j < kNZ ; j++ ) {
1424 for ( Int_t i = 0 ; i < kNR ; i++ ) {
1425 // Full 3D configuration ...
1427 if (r>rmin && r<rmax && z>zmin && z< zmax){
1428 // partial load in (r,z)
1430 if (fSpaceChargeHistogramRZ) scDensityInRZ(i,j) = norm*fSpaceChargeHistogramRZ->Interpolate(r,z) ;
1432 // partial load in (r,phi)
1433 if ( (j==0 || j == kNZ/2) && fSpaceChargeHistogramRPhi) {
1435 scDensityInRPhiA(i,k) = norm*fSpaceChargeHistogramRPhi->Interpolate(phi,r); // A side
1437 scDensityInRPhiC(i,k) = norm*fSpaceChargeHistogramRPhi->Interpolate(phi+TMath::TwoPi(),r); // C side
1441 scDensity(i,j) = norm*fSpaceChargeHistogram3D->Interpolate(phi,r,z);
1443 scDensity(i,j) = norm*fSpaceChargeHistogram3D->Interpolate(phi,r,z);
1449 fInitLookUp = kFALSE;
1454 Float_t AliTPCSpaceCharge3D::GetSpaceChargeDensity(Float_t r, Float_t phi, Float_t z, Int_t mode) {
1456 // returns the (input) space charge density at a given point according
1457 // Note: input in [cm], output in [C/m^3/e0] !!
1460 while (phi<0) phi += TMath::TwoPi();
1461 while (phi>TMath::TwoPi()) phi -= TMath::TwoPi();
1464 // Float_t sc =fSCdensityDistribution->Interpolate(r0,phi0,z0);
1468 if (mode == 0) { // return full load
1469 sc = Interpolate3DTable(order, r, z, phi, kNR, kNZ, kNPhi,
1470 fgkRList, fgkZList, fgkPhiList, fSCdensityDistribution );
1472 } else if (mode == 1) { // return partial load in (r,z)
1473 TMatrixD &scDensityInRZ = *fSCdensityInRZ;
1474 sc = Interpolate2DTable(order, r, z, kNR, kNZ, fgkRList, fgkZList, scDensityInRZ );
1476 } else if (mode == 2) { // return partial load in (r,phi)
1479 TMatrixD &scDensityInRPhi = *fSCdensityInRPhiA;
1480 sc = Interpolate2DTable(order, r, phi, kNR, kNPhi, fgkRList, fgkPhiList, scDensityInRPhi );
1482 TMatrixD &scDensityInRPhi = *fSCdensityInRPhiC;
1483 sc = Interpolate2DTable(order, r, phi, kNR, kNPhi, fgkRList, fgkPhiList, scDensityInRPhi );
1487 // should i give a warning?
1491 // printf("%f %f %f: %f\n",r,phi,z,sc);
1497 TH2F * AliTPCSpaceCharge3D::CreateHistoSCinXY(Float_t z, Int_t nx, Int_t ny, Int_t mode) {
1499 // return a simple histogramm containing the space charge distribution (input for the calculation)
1502 TH2F *h=CreateTH2F("spaceCharge",GetTitle(),"x [cm]","y [cm]","#rho_{sc} [C/m^{3}/e_{0}]",
1503 nx,-250.,250.,ny,-250.,250.);
1505 for (Int_t iy=1;iy<=ny;++iy) {
1506 Double_t yp = h->GetYaxis()->GetBinCenter(iy);
1507 for (Int_t ix=1;ix<=nx;++ix) {
1508 Double_t xp = h->GetXaxis()->GetBinCenter(ix);
1510 Float_t r = TMath::Sqrt(xp*xp+yp*yp);
1511 Float_t phi = TMath::ATan2(yp,xp);
1513 if (85.<=r && r<=250.) {
1514 Float_t sc = GetSpaceChargeDensity(r,phi,z,mode)/fgke0; // in [C/m^3/e0]
1515 h->SetBinContent(ix,iy,sc);
1517 h->SetBinContent(ix,iy,0.);
1525 TH2F * AliTPCSpaceCharge3D::CreateHistoSCinZR(Float_t phi, Int_t nz, Int_t nr,Int_t mode ) {
1527 // return a simple histogramm containing the space charge distribution (input for the calculation)
1530 TH2F *h=CreateTH2F("spaceCharge",GetTitle(),"z [cm]","r [cm]","#rho_{sc} [C/m^{3}/e_{0}]",
1531 nz,-250.,250.,nr,85.,250.);
1533 for (Int_t ir=1;ir<=nr;++ir) {
1534 Float_t r = h->GetYaxis()->GetBinCenter(ir);
1535 for (Int_t iz=1;iz<=nz;++iz) {
1536 Float_t z = h->GetXaxis()->GetBinCenter(iz);
1537 Float_t sc = GetSpaceChargeDensity(r,phi,z,mode)/fgke0; // in [C/m^3/e0]
1538 h->SetBinContent(iz,ir,sc);
1545 void AliTPCSpaceCharge3D::WriteChargeDistributionToFile(const char* fname) {
1547 // Example on how to write a Space charge distribution into a File
1548 // (see below: estimate from scaling STAR measurements to Alice)
1549 // Charge distribution is splitted into two (RZ and RPHI) in order to speed up
1550 // the needed calculation time
1553 TFile *f = new TFile(fname,"RECREATE");
1555 // some grid, not too course
1560 Double_t dr = (fgkOFCRadius-fgkIFCRadius)/(nr+1);
1561 Double_t dphi = TMath::TwoPi()/(nphi+1);
1562 Double_t dz = 500./(nz+1);
1563 Double_t safty = 0.; // due to a root bug which does not interpolate the boundary (first and last bin) correctly
1566 // Charge distribution in ZR (rotational symmetric) ------------------
1568 TH2F *histoZR = new TH2F("chargeZR","chargeZR",
1569 nr,fgkIFCRadius-dr-safty,fgkOFCRadius+dr+safty,
1570 nz,-250-dz-safty,250+dz+safty);
1572 for (Int_t ir=1;ir<=nr;++ir) {
1573 Double_t rp = histoZR->GetXaxis()->GetBinCenter(ir);
1574 for (Int_t iz=1;iz<=nz;++iz) {
1575 Double_t zp = histoZR->GetYaxis()->GetBinCenter(iz);
1577 // recalculation to meter
1578 Double_t lZ = 2.5; // approx. TPC drift length
1579 Double_t rpM = rp/100.; // in [m]
1580 Double_t zpM = TMath::Abs(zp/100.); // in [m]
1582 // setting of mb multiplicity and Interaction rate
1583 Double_t multiplicity = 950;
1584 Double_t intRate = 7800;
1586 // calculation of "scaled" parameters
1587 Double_t a = multiplicity*intRate/79175;
1590 Double_t charge = (a - b*zpM)/(rpM*rpM); // charge in [C/m^3/e0]
1592 charge = charge*fgke0; // [C/m^3]
1594 if (zp<0) charge *= 0.9; // e.g. slightly less on C side due to front absorber
1596 // charge = 0; // for tests
1597 histoZR->SetBinContent(ir,iz,charge);
1601 histoZR->Write("SpaceChargeInRZ");
1604 // Charge distribution in RPhi (e.g. Floating GG wire) ------------
1606 TH3F *histoRPhi = new TH3F("chargeRPhi","chargeRPhi",
1607 nr,fgkIFCRadius-dr-safty,fgkOFCRadius+dr+safty,
1608 nphi,0-dphi-safty,TMath::TwoPi()+dphi+safty,
1609 2,-1,1); // z part - to allow A and C side differences
1611 // some 'arbitrary' GG leaks
1613 Double_t secPosA[5] = {3,6,6,11,13}; // sector
1614 Double_t radialPosA[5] = {125,100,160,200,230}; // radius in cm
1615 Double_t secPosC[5] = {1,8,12,15,15}; // sector
1616 Double_t radialPosC[5] = {245,120,140,120,190}; // radius in cm
1618 for (Int_t ir=1;ir<=nr;++ir) {
1619 Double_t rp = histoRPhi->GetXaxis()->GetBinCenter(ir);
1620 for (Int_t iphi=1;iphi<=nphi;++iphi) {
1621 Double_t phip = histoRPhi->GetYaxis()->GetBinCenter(iphi);
1622 for (Int_t iz=1;iz<=2;++iz) {
1623 Double_t zp = histoRPhi->GetZaxis()->GetBinCenter(iz);
1625 Double_t charge = 0;
1627 for (Int_t igg = 0; igg<nGGleaks; igg++) { // loop over GG leaks
1630 Double_t secPos = secPosA[igg];
1631 Double_t radialPos = radialPosA[igg];
1633 if (zp<0) { // C side
1634 secPos = secPosC[igg];
1635 radialPos = radialPosC[igg];
1638 // some 'arbitrary' GG leaks
1639 if ( (phip<(TMath::Pi()/9*(secPos+1)) && phip>(TMath::Pi()/9*secPos) ) ) { // sector slice
1640 if ( rp>(radialPos-2.5) && rp<(radialPos+2.5)) // 5 cm slice
1646 charge = charge*fgke0; // [C/m^3]
1648 histoRPhi->SetBinContent(ir,iphi,iz,charge);
1653 histoRPhi->Write("SpaceChargeInRPhi");
1660 void AliTPCSpaceCharge3D::Print(const Option_t* option) const {
1662 // Print function to check the settings of the boundary vectors
1663 // option=="a" prints the C0 and C1 coefficents for calibration purposes
1666 TString opt = option; opt.ToLower();
1667 printf("%s\n",GetTitle());
1668 printf(" - Space Charge effect with arbitrary 3D charge density (as input).\n");
1669 printf(" SC correction factor: %f \n",fCorrectionFactor);
1671 if (opt.Contains("a")) { // Print all details
1672 printf(" - T1: %1.4f, T2: %1.4f \n",fT1,fT2);
1673 printf(" - C1: %1.4f, C0: %1.4f \n",fC1,fC0);
1676 if (!fInitLookUp) AliError("Lookup table was not initialized! You should do InitSpaceCharge3DDistortion() ...");
1682 void AliTPCSpaceCharge3D::InitSpaceCharge3DPoisson(Int_t kRows, Int_t kColumns, Int_t kPhiSlices, Int_t kIterations){
1684 // MI extension - calculate E field
1685 // - inspired by AliTPCROCVoltError3D::InitROCVoltError3D()
1686 // Initialization of the Lookup table which contains the solutions of the
1687 // Dirichlet boundary problem
1688 // Calculation of the single 3D-Poisson solver is done just if needed
1689 // (see basic lookup tables in header file)
1691 Int_t kPhiSlicesPerSector = kPhiSlices/18;
1693 const Int_t order = 1 ; // Linear interpolation = 1, Quadratic = 2
1694 const Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius) / (kRows-1) ;
1695 const Float_t gridSizeZ = fgkTPCZ0 / (kColumns-1) ;
1696 const Float_t gridSizePhi = TMath::TwoPi() / ( 18.0 * kPhiSlicesPerSector);
1698 // temporary arrays to create the boundary conditions
1699 TMatrixD *arrayofArrayV[kPhiSlices], *arrayofCharge[kPhiSlices] ;
1700 TMatrixD *arrayofEroverEz[kPhiSlices], *arrayofEphioverEz[kPhiSlices], *arrayofDeltaEz[kPhiSlices] ;
1702 for ( Int_t k = 0 ; k < kPhiSlices ; k++ ) {
1703 arrayofArrayV[k] = new TMatrixD(kRows,kColumns) ;
1704 arrayofCharge[k] = new TMatrixD(kRows,kColumns) ;
1705 arrayofEroverEz[k] = new TMatrixD(kRows,kColumns) ;
1706 arrayofEphioverEz[k] = new TMatrixD(kRows,kColumns) ;
1707 arrayofDeltaEz[k] = new TMatrixD(kRows,kColumns) ;
1710 // list of point as used in the poisson relation and the interpolation (during sum up)
1711 Double_t rlist[kRows], zedlist[kColumns] , philist[kPhiSlices];
1712 for ( Int_t k = 0 ; k < kPhiSlices ; k++ ) {
1713 philist[k] = gridSizePhi * k;
1714 for ( Int_t i = 0 ; i < kRows ; i++ ) {
1715 rlist[i] = fgkIFCRadius + i*gridSizeR ;
1716 for ( Int_t j = 0 ; j < kColumns ; j++ ) { // Fill Vmatrix with Boundary Conditions
1717 zedlist[j] = j * gridSizeZ ;
1722 // ==========================================================================
1723 // Solve Poisson's equation in 3D cylindrical coordinates by relaxation technique
1724 // Allow for different size grid spacing in R and Z directions
1726 const Int_t symmetry = 0;
1728 // Set bondaries and solve Poisson's equation --------------------------
1730 if ( !fInitLookUp ) {
1732 AliInfo(Form("Solving the poisson equation (~ %d sec)",2*10*(int)(kPhiSlices/10)));
1734 for ( Int_t side = 0 ; side < 2 ; side++ ) { // Solve Poisson3D twice; once for +Z and once for -Z
1735 AliSysInfo::AddStamp("RunSide", 1,side,0);
1736 for ( Int_t k = 0 ; k < kPhiSlices ; k++ ) {
1737 TMatrixD &arrayV = *arrayofArrayV[k] ;
1738 TMatrixD &charge = *arrayofCharge[k] ;
1740 //Fill arrays with initial conditions. V on the boundary and Charge in the volume.
1741 // for ( Int_t i = 0 ; i < kRows ; i++ ) {
1742 // for ( Int_t j = 0 ; j < kColumns ; j++ ) { // Fill Vmatrix with Boundary Conditions
1743 // arrayV(i,j) = 0.0 ;
1744 // charge(i,j) = 0.0 ;
1746 // // Float_t radius0 = rlist[i] ;
1747 // // Float_t phi0 = gridSizePhi * k ;
1749 // // To avoid problems at sector boundaries, use an average of +- 1 degree from actual phi location
1750 // // if ( j == (kColumns-1) ) {
1751 // // arrayV(i,j) = 0.5* ( GetROCVoltOffset( side, radius0, phi0+0.02 ) + GetROCVoltOffset( side, radius0, phi0-0.02 ) ) ;
1753 // // if (side==1) // C side
1754 // // arrayV(i,j) = -arrayV(i,j); // minus sign on the C side to allow a consistent usage of global z when setting the boundaries
1759 for ( Int_t i = 1 ; i < kRows-1 ; i++ ) {
1760 for ( Int_t j = 1 ; j < kColumns-1 ; j++ ) {
1761 Float_t radius0 = rlist[i] ;
1762 Float_t phi0 = gridSizePhi * k ;
1763 Double_t z0 = zedlist[j];
1764 if (side==1) z0= -TMath::Abs(zedlist[j]);
1766 charge(i,j) = fSpaceChargeHistogram3D->Interpolate(phi0,radius0,z0);
1770 AliSysInfo::AddStamp("RunPoisson", 2,side,0);
1772 // Solve Poisson's equation in 3D cylindrical coordinates by relaxation technique
1773 // Allow for different size grid spacing in R and Z directions
1775 // PoissonRelaxation3D( arrayofArrayV, arrayofCharge,
1776 // arrayofEroverEz, arrayofEphioverEz, arrayofDeltaEz,
1777 // kRows, kColumns, kPhiSlices, gridSizePhi, kIterations,
1778 // symmetry , fROCdisplacement) ;
1779 PoissonRelaxation3D( arrayofArrayV, arrayofCharge,
1780 arrayofEroverEz, arrayofEphioverEz, arrayofDeltaEz,
1781 kRows, kColumns, kPhiSlices, gridSizePhi, kIterations,
1784 //Interpolate results onto a custom grid which is used just for these calculations.
1785 Double_t r, phi, z ;
1786 for ( Int_t k = 0 ; k < kNPhi ; k++ ) {
1787 phi = fgkPhiList[k] ;
1789 TMatrixF &erOverEz = *fLookUpErOverEz[k] ;
1790 TMatrixF &ephiOverEz = *fLookUpEphiOverEz[k];
1791 TMatrixF &deltaEz = *fLookUpDeltaEz[k] ;
1793 for ( Int_t j = 0 ; j < kNZ ; j++ ) {
1795 z = TMath::Abs(fgkZList[j]) ; // Symmetric solution in Z that depends only on ABS(Z)
1797 if ( side == 0 && fgkZList[j] < 0 ) continue; // Skip rest of this loop if on the wrong side
1798 if ( side == 1 && fgkZList[j] > 0 ) continue; // Skip rest of this loop if on the wrong side
1800 for ( Int_t i = 0 ; i < kNR ; i++ ) {
1803 // Interpolate basicLookup tables; once for each rod, then sum the results
1804 erOverEz(i,j) = Interpolate3DTable(order, r, z, phi, kRows, kColumns, kPhiSlices,
1805 rlist, zedlist, philist, arrayofEroverEz );
1806 ephiOverEz(i,j) = Interpolate3DTable(order, r, z, phi, kRows, kColumns, kPhiSlices,
1807 rlist, zedlist, philist, arrayofEphioverEz);
1808 deltaEz(i,j) = Interpolate3DTable(order, r, z, phi, kRows, kColumns, kPhiSlices,
1809 rlist, zedlist, philist, arrayofDeltaEz );
1811 if (side == 1) deltaEz(i,j) = - deltaEz(i,j); // negative coordinate system on C side
1816 AliSysInfo::AddStamp("Interpolate Poisson", 3,side,0);
1817 if ( side == 0 ) AliInfo(" A side done");
1818 if ( side == 1 ) AliInfo(" C side done");
1822 // clear the temporary arrays lists
1823 for ( Int_t k = 0 ; k < kPhiSlices ; k++ ) {
1824 delete arrayofArrayV[k];
1825 delete arrayofCharge[k];
1826 delete arrayofEroverEz[k];
1827 delete arrayofEphioverEz[k];
1828 delete arrayofDeltaEz[k];
1832 fInitLookUp = kTRUE;