]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/Attic/AliTPCTransformation.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / TPC / Attic / AliTPCTransformation.cxx
1 /// \class AliTPCTransformation
2 /// \brief Should represent general non linear transformation.
3 ///
4 /// Currently tune for TPConly.
5 ///
6 /// To be used:
7 /// 1. Simulation-Digitization
8 /// 2. Reconstruction - AliTPCTransform
9 /// 3. Calibration/Alignment (KalmanFilter, Milipedde)
10 /// 4. Set of transformation to be stored/retrieved as OCDB entry
11 ///
12 /// Base functionality:
13 ///
14 /// 1. Double_t GetDeltaXYZ(Int_t coord, Int_t volID, Double_t param, Double_t x, Double_t y, Double_t z)
15 /// Get correction - return the delta of coordinate coord dx or dy or dz for given volID for point at point (x,y,z)
16 /// All coordinates are global
17 ///
18 /// 2. The transformation should work only for given volIDs and detector IDs
19 ///    Currently Bitmask is used for filtering
20 ///
21 /// Transformation - naming convention:
22 ///
23 /// XXX(local)YYYZZZ
24 /// TPClocaldLxdGX
25 /// XXX   - detector if detector specific
26 /// local - if local transforamtion
27 /// YYY   - type of transformation
28 /// ZZZ   - return type of transformation
29
30 #include <string.h>
31 #include "TRandom.h"
32 #include "TMath.h"
33 #include "TBits.h"
34 #include "TFormula.h"
35 #include "TF1.h"
36 #include "TLinearFitter.h"
37 #include "TFile.h"
38 #include "TObjString.h"
39
40 #include "TTreeStream.h"
41 #include "AliTrackPointArray.h"
42 #include "AliLog.h"
43 #include "AliTPCTransformation.h"
44
45 /// \cond CLASSIMP
46 ClassImp(AliTPCTransformation)
47 /// \endcond
48
49 AliTPCTransformation::GenFuncG    AliTPCTransformation::fgFormulas[10000];
50 TObjArray*  AliTPCTransformation::fgFormulasName = new TObjArray(10000);
51
52
53 void AliTPCTransformation::RegisterFormula(const char * name, GenFuncG formula){
54   /// Add Formula to the list of formulas
55
56   Int_t last= fgFormulasName->GetEntries();
57   fgFormulasName->AddLast(new TObjString(name));
58   fgFormulas[last]=formula;
59 }
60
61 Int_t  AliTPCTransformation::BuildBasicFormulas(){
62   ///
63
64   //
65   //build list of basic TPC formulas - corrections
66   //
67   RegisterFormula("TPCscalingRPol",(GenFuncG)(AliTPCTransformation::TPCscalingRPol));
68   RegisterFormula("TPCscalingRIFC",(GenFuncG)(AliTPCTransformation::TPCscalingRIFC));
69   RegisterFormula("TPCscalingROFC",(GenFuncG)(AliTPCTransformation::TPCscalingROFC));
70   //
71   RegisterFormula("TPCdeltaFCROC",(GenFuncG)(AliTPCTransformation::TPCdeltaFCROC));
72   RegisterFormula("TPCdeltaFCCE",(GenFuncG)(AliTPCTransformation::TPCdeltaFCCE));
73   //
74   RegisterFormula("TPCscalingZDr",(GenFuncG)(AliTPCTransformation::TPCscalingZDrift));
75   RegisterFormula("TPCscalingZDrGy",(GenFuncG)(AliTPCTransformation::TPCscalingZDriftGy));
76   RegisterFormula("TPCscalingZDriftT0",(GenFuncG)(AliTPCTransformation::TPCscalingZDriftT0));
77   RegisterFormula("TPCscalingPhiLocal",(GenFuncG)(AliTPCTransformation::TPCscalingPhiLocal));
78   RegisterFormula("TPClocalRPhiEdge",(GenFuncG)(AliTPCTransformation::TPClocalRPhiEdge));
79   //
80   // TPC Local X and Y misalignment + rotation 
81   //
82   RegisterFormula("TPClocaldLxdGX",(GenFuncG)(AliTPCTransformation::TPClocaldLxdGX));
83   RegisterFormula("TPClocaldLxdGY",(GenFuncG)(AliTPCTransformation::TPClocaldLxdGY));
84   RegisterFormula("TPClocaldLydGX",(GenFuncG)(AliTPCTransformation::TPClocaldLydGX));
85   RegisterFormula("TPClocaldLydGY",(GenFuncG)(AliTPCTransformation::TPClocaldLydGY));
86   RegisterFormula("TPClocaldRzdGX",(GenFuncG)(AliTPCTransformation::TPClocaldRzdGX));
87   RegisterFormula("TPClocaldRzdGY",(GenFuncG)(AliTPCTransformation::TPClocaldRzdGY));
88
89   //
90   // Z offset
91   //
92   RegisterFormula("TPCDeltaZ",(GenFuncG)(AliTPCTransformation::TPCDeltaZ));
93   RegisterFormula("TPCDeltaZMediumLong",(GenFuncG)(AliTPCTransformation::TPCDeltaZMediumLong));
94   RegisterFormula("TPCTiltingZ",(GenFuncG)(AliTPCTransformation::TPCTiltingZ));
95   return 0;
96 }
97
98 AliTPCTransformation::GenFuncG  AliTPCTransformation::FindFormula(const char * name){
99   /// find formula - if registered
100
101   if (fgFormulasName->FindObject(name)==0) return 0;
102   Int_t entries = fgFormulasName->GetEntries();
103   for (Int_t i=0;i<entries;i++){
104     if (strcmp(fgFormulasName->At(i)->GetName(), name)==0){
105       return fgFormulas[i];
106     }
107   }
108   return 0;
109 }
110
111 Double_t AliTPCTransformation::Eval(const char * name, const Double_t*x,const Double_t*par){
112   /// Only for test purposes - very slow
113
114   GenFuncG fun = FindFormula(name);
115   if (!fun) return 0;
116   return fun(x,par);
117 }
118
119
120 AliTPCTransformation::AliTPCTransformation():
121   TNamed(),
122   fNameX(0),          // x formula name
123   fNameY(0),          // y formula name
124   fNameZ(0),          // z formula name 
125   //
126   fBitMask(0),        // bitmaps - transformation only for specified volID
127   fCoordSystem(0),    // coord system of  output deltas 
128   fParam(0),          // free parameter of transformation 
129   fSigma(0),          // uncertainty of the parameter
130   fSigmaMax(0),       //maximal sigma (Not allowed to increase in propagate time by bigger factor)
131   fSigma2Time(0),     // change of the error in time - (For kalman filter) 
132   fFixedParam(0),     // fixed parameters of tranformation  
133   fIsActive(kTRUE),   // swith - On/Off
134   //
135   fInit(kFALSE),      // initialization flag - set to kTRUE if corresponding formulas found
136   fFormulaX(0),       // x formula - pointer to the function
137   fFormulaY(0),       // y formula - pointer to the function
138   fFormulaZ(0)       // z formula - pointer to the function
139   //
140 {
141   /// default constructor
142
143 }
144
145
146
147 AliTPCTransformation::AliTPCTransformation(const char *name, TBits *mask, const char *fx, const char *fy, const char *fz, Int_t coordSystem):
148   TNamed(name,name),
149   fNameX(0),       // x formula name
150   fNameY(0),       // y formula name
151   fNameZ(0),       // z formula name
152   fBitMask(mask),   // bitmaps - transformation only for specified volID
153   fCoordSystem(coordSystem), // coordinate system of output deltas
154   fParam(0),          // free parameter of transformation 
155   fSigma(0),
156   fSigmaMax(0),       //maximal sigma (Not allowed to increase in propagate time by bigger factor)
157   fSigma2Time(0),     // change of sigma in time
158   fFixedParam(0),     // fixed parameters of tranformation  
159   fIsActive(kTRUE),   // swith - On/Off
160   //
161   fInit(kFALSE),      // initialization flag - set to kTRUE if corresponding formulas found
162   fFormulaX(0),       // x formula - pointer to the function
163   fFormulaY(0),       // y formula - pointer to the function
164   fFormulaZ(0)       // z formula - pointer to the function
165 {
166   /// non default constructor
167
168   if (fx) fNameX= new TString(fx);
169   if (fy) fNameY= new TString(fy);
170   if (fz) fNameZ= new TString(fz);
171   Init();
172 }
173
174 AliTPCTransformation::AliTPCTransformation(const AliTPCTransformation&trafo):
175   TNamed(trafo),
176   fNameX(0),          // x formula name
177   fNameY(0),          // y formula name
178   fNameZ(0),          // z formula name 
179                      //
180   fBitMask(0),        // bitmaps - transformation only for specified volID
181   fCoordSystem(0),    // coord system of  output deltas 
182   fParam(trafo.fParam),          // free parameter of transformation 
183   fSigma(trafo.fSigma),          // uncertainty of the parameter
184   fSigmaMax(trafo.fSigma),       //maximal sigma (Not allowed to increase in propagate time by bigger factor)
185   fSigma2Time(trafo.fSigma2Time),     // change of the error in time - (For kalman filter) 
186   fFixedParam(0),     // fixed parameters of tranformation
187   fIsActive(trafo.fIsActive),   // swith - On/Off
188   //
189   fInit(kFALSE),      // initialization flag - set to kTRUE if corresponding formulas found
190   fFormulaX(0),       // x formula - pointer to the function
191   fFormulaY(0),       // y formula - pointer to the function
192   fFormulaZ(0)       // z formula - pointer to the function
193 {
194   /// comment are above
195
196   if (trafo.fNameX) fNameX = new TString(*(trafo.fNameX)); 
197   if (trafo.fNameY) fNameY = new TString(*(trafo.fNameY)); 
198   if (trafo.fNameZ) fNameZ = new TString(*(trafo.fNameZ)); 
199   if (trafo.fBitMask)  fBitMask = new TBits(*(trafo.fBitMask)); 
200 }
201
202 AliTPCTransformation::~AliTPCTransformation(){
203   /// destructor
204
205   delete fNameX;
206   delete fNameY;
207   delete fNameZ;
208   delete fBitMask;
209   delete fFixedParam;
210 }
211 void AliTPCTransformation::SetParams(Double_t param, Double_t sigma, Double_t sigma2Time, const TVectorD *const fixedParams){
212   /// Set parameters of transformation
213
214   fParam = param;
215   fSigma = sigma;
216   fSigmaMax = sigma;
217   fSigma2Time = sigma2Time;
218   if (fFixedParam) delete fFixedParam;
219   fFixedParam = new TVectorD(*fixedParams);
220   Init();
221 }
222
223
224 Bool_t AliTPCTransformation::Init(){
225   /// associate formulas with pointer to the function
226
227   Bool_t isOK=kTRUE;
228   if (fNameX) {
229     fFormulaX=FindFormula(fNameX->Data());
230     if (fFormulaX==0) isOK=kFALSE;
231   }
232   if (fNameY) {
233     fFormulaY=FindFormula(fNameY->Data());
234     if (fFormulaY==0) isOK=kFALSE;
235   }
236   if (fNameZ) {
237     fFormulaZ=FindFormula(fNameZ->Data());
238     if (!fFormulaZ) isOK=kFALSE;
239   }
240   return isOK;
241 }
242
243
244
245 TBits * AliTPCTransformation::BitsSide(Bool_t aside){
246   /// Set bits for given side
247
248   TBits * bits = new TBits(72);
249   for (Int_t i=0; i<72;i++){
250     if (i%36<18 && aside) (*bits)[i]=kTRUE;
251     if (i%36<18 && (!aside)) (*bits)[i]=kFALSE;
252     if (i%36>=18 && aside) (*bits)[i]=kFALSE;
253     if (i%36>=18 && (!aside)) (*bits)[i]=kTRUE;
254   }
255   return bits;
256 }
257
258 TBits * AliTPCTransformation::BitsAll(){
259   /// Set all bits to kTRUE
260
261   TBits * bits = new TBits(72);
262   for (Int_t i=0; i<72;i++){
263     (*bits)[i]=kTRUE;
264   }
265   return bits;
266 }
267
268 // Double_t AliTPCTransformation::GetDeltaXYZ(Int_t coord, Int_t volID, Double_t param, Double_t x, Double_t y, Double_t z){
269 //   //
270 //   //
271 //   // coord - type of coordinate
272 //   //       - 0 -X
273 //   //         1 -Y
274 //   //         2 -Z
275 //   //         3 -R
276 //   //         4 -RPhi
277 //   if (!fIsActive) return 0;
278 //   if (fBitMask && (!(*fBitMask)[volID])) return 0;
279 //   Double_t xyz[5]={x,y,z, param,volID};
280 //   if (fCoordSystem==0){
281 //     // cartezian system
282 //     if (coord==0 && fFormulaX) return fFormulaX(xyz,fFixedParam->GetMatrixArray()); 
283 //     if (coord==1 && fFormulaY) return fFormulaY(xyz,fFixedParam->GetMatrixArray()); 
284 //     if (coord==2 && fFormulaZ) return fFormulaZ(xyz,fFixedParam->GetMatrixArray());
285 //   }
286 //   if (fCoordSystem==1){  
287 //     // cylindrical system
288 //     if (coord==2) {
289 //       if (fFormulaZ==0) return 0;
290 //       return fFormulaZ(xyz,fFixedParam->GetMatrixArray());
291 //     }
292 //     Double_t rrphiz[3]={0,0,0};
293 //     if (fFormulaX) rrphiz[0] = fFormulaX(xyz,fFixedParam->GetMatrixArray());
294 //     if (fFormulaY) rrphiz[1] = fFormulaY(xyz,fFixedParam->GetMatrixArray());
295 //     Double_t alpha = TMath::ATan2(y,x);
296 //     Double_t ca    = TMath::Cos(alpha);
297 //     Double_t sa    = TMath::Sin(alpha);
298 //     if (coord==0) return ca*rrphiz[0]-sa*rrphiz[1];
299 //     if (coord==1) return sa*rrphiz[0]+ca*rrphiz[1];
300 //   }
301 //   return 0;
302 // }
303
304
305 Double_t AliTPCTransformation::GetDeltaXYZ(Int_t coord, Int_t volID, Double_t param, Double_t x, Double_t y, Double_t z){
306   /// coord - type of coordinate
307   ///       - 0 -X
308   ///         1 -Y
309   ///         2 -Z
310   ///         3 -R
311   ///         4 -RPhi
312   ///         5 -Z
313
314   if (!fIsActive) return 0;
315   if (fBitMask && (!(*fBitMask)[volID])) return 0;
316   Double_t xyz[5]={x,y,z, param,volID};
317   Double_t alpha = TMath::ATan2(y,x);
318   Double_t ca    = TMath::Cos(alpha);
319   Double_t sa    = TMath::Sin(alpha);
320
321   if (fCoordSystem==0){
322     // cartezian system
323     Double_t dxdydz[3]={0,0,0};
324     if(fFormulaX) dxdydz[0]=fFormulaX(xyz,fFixedParam->GetMatrixArray());
325     if(fFormulaY) dxdydz[1]=fFormulaY(xyz,fFixedParam->GetMatrixArray());
326     if(fFormulaZ) dxdydz[2]=fFormulaZ(xyz,fFixedParam->GetMatrixArray());
327
328     if (coord==0) return dxdydz[0];
329     if (coord==1) return dxdydz[1];
330     if (coord==2) return dxdydz[2];
331     if (coord==3) return dxdydz[0]*ca+dxdydz[1]*sa;
332     if (coord==4) return -dxdydz[0]*sa+dxdydz[1]*ca;
333     if (coord==5) return dxdydz[2];
334   }
335   if (fCoordSystem==1){  
336     // cylindrical system
337     if (coord==2||coord==5) {
338       if (fFormulaZ==0) return 0;
339       return fFormulaZ(xyz,fFixedParam->GetMatrixArray());
340     }
341     Double_t rrphiz[3]={0,0,0};
342     if (fFormulaX) rrphiz[0] = fFormulaX(xyz,fFixedParam->GetMatrixArray());
343     if (fFormulaY) rrphiz[1] = fFormulaY(xyz,fFixedParam->GetMatrixArray());
344     alpha = TMath::ATan2(y,x);
345     ca    = TMath::Cos(alpha);
346     sa    = TMath::Sin(alpha);
347     if (coord==0) return ca*rrphiz[0]-sa*rrphiz[1];
348     if (coord==1) return sa*rrphiz[0]+ca*rrphiz[1];
349     if (coord==3) return rrphiz[0];
350     if (coord==4) return rrphiz[1];
351   }
352   return 0;
353 }
354
355
356
357 Double_t  AliTPCTransformation::TPCscalingRPol(Double_t *xyz, const Double_t * const param){
358   /// Scaling and shift of TPC radius
359   /// xyz[0..2] - global xyz of point
360   /// xyz[3]    - scale parameter
361   /// param[0]  - radial scaling power
362   /// param[1]  - drift  scaling power
363   /// radius  from -1(at rInner)   to 1 (rOuter)
364   /// driftM  from -1(at 0 drift)  to 1 (250 cm drift)
365
366   Double_t rInner=78.8;
367   Double_t rOuter=258.0; 
368   Double_t deltaR  = rOuter-rInner;  
369   Double_t radius  = (TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1])-rInner)*2./deltaR; 
370   Double_t driftM  = (0.5 - TMath::Abs(xyz[2]/250.))*2.0;
371   Double_t delta   = TMath::Power(radius,param[0])*TMath::Power(driftM,param[1]);
372   return delta*xyz[3];
373 }
374
375
376 Double_t  AliTPCTransformation::TPCscalingZDrift(Double_t *xyz, const Double_t * const param){
377   /// Scaling and shift of TPC radius
378   /// xyz[0..2] - global xyz of point
379   /// xyz[3]    - scale parameter
380
381   Double_t driftP  = TMath::Power(1. - TMath::Abs(xyz[2]/250.), param[0]);
382   Int_t    sector = TMath::Nint(xyz[4]);
383   Double_t deltaZ  = (sector%36<18) ? -driftP : driftP;
384   return deltaZ*xyz[3];
385 }
386
387 Double_t  AliTPCTransformation::TPCscalingZDriftT0(Double_t *xyz, const Double_t * const /*param*/){
388   /// Z shift because time 0 offset
389   /// opposite on A and C side
390   ///
391   /// xyz[0..2] - global xyz of point
392   /// xyz[3]    - scale parameter
393
394   Int_t    sector = TMath::Nint(xyz[4]);
395   Double_t sign  = (sector%36<18) ? -1 : 1;
396   return sign*xyz[3];
397 }
398
399
400 Double_t  AliTPCTransformation::TPCscalingZDriftGy(Double_t *xyz, const Double_t * const param){
401   /// Scaling and shift of TPC radius
402   /// xyz[0..2] - global xyz of point
403   /// xyz[3]    - scale parameter
404
405   Double_t driftP  = TMath::Power(1. - TMath::Abs(xyz[2]/250.), param[0]);
406   Double_t gy      = xyz[1]/250.;
407   Int_t    sector = TMath::Nint(xyz[4]);
408   Double_t deltaZ  = (sector%36<18) ? -driftP : driftP;
409   return deltaZ*xyz[3]*gy;
410 }
411
412
413
414 Double_t  AliTPCTransformation::TPCscalingPhiLocal(Double_t *xyz, const Double_t * const param){
415   /// Scaling if the local y -phi
416   /// xyz[0..2] - global xyz of point
417   /// xyz[3]    - scale parameter
418   /// value = 1 for ful drift length and parameter 1
419
420   Double_t alpha       = TMath::ATan2(xyz[1],xyz[0]);
421   Double_t sector      = TMath::Nint(9*alpha/TMath::Pi()-0.5);
422   Double_t localAlpha  = (alpha-(sector+0.5)*TMath::Pi()/9.);
423   Double_t radius      = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1])/250.;
424   //
425   Double_t deltaAlpha  = radius*TMath::Power(2.*9.*localAlpha/TMath::Pi(),param[0]);
426   return deltaAlpha*xyz[3];
427 }
428
429 Double_t  AliTPCTransformation::TPClocalRPhiEdge(Double_t *xyz, const Double_t *const param){
430   /// Scaling if the local y -phi
431   /// xyz[0..2] - global xyz of point
432   /// xyz[3]    - scale parameter
433   /// param[0]  - dedge offset - should be around gap size/2.
434   /// param[1]  - dedge factor - should be around gap size/2.
435
436   Double_t alpha       = TMath::ATan2(xyz[1],xyz[0]);
437   Double_t sector      = TMath::Nint(9*alpha/TMath::Pi()-0.5);
438   Double_t localAlpha  = (alpha-(sector+0.5)*TMath::Pi()/9.);
439   Double_t radius      = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
440   Double_t deltaAlpha  = TMath::Pi()/18.-TMath::Abs(localAlpha);
441   Double_t distEdge    = (deltaAlpha*radius);
442   Double_t factor      = 1./(1.+(distEdge-param[0])/param[1]);
443   return factor*xyz[3]*((localAlpha>0)? -1.:1.);
444 }
445
446
447 Double_t       AliTPCTransformation::TPCscalingRIFC(Double_t *xyz, const Double_t * const param){
448   /// inner field cage r distorion - proportinal to 1 over distance to the IFC
449   /// param[0] - drift polynom order
450   /// distortion at first pad row - is normalized to
451
452   Double_t rInner=78.8;
453   Double_t rFirst=85.2; 
454   Double_t deltaR  = rFirst-rInner;
455   Double_t ndistR  = (TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1])-rInner)/deltaR;
456   Double_t driftM  = (0.5 - TMath::Abs(xyz[2]/250.))*2.;
457   Double_t value   = TMath::Power(driftM,param[0])/ndistR;
458   return xyz[3]*value;
459 }
460
461 Double_t       AliTPCTransformation::TPCscalingROFC(Double_t *xyz, const Double_t * const param){
462   /// outer field cage r distorion - proportinal to 1 over distance to the OFC
463   /// param[0] - drift polynom order
464   /// driftM   - from -1 to 1
465
466   Double_t rLast=245.8;
467   Double_t rOuter=258.0;  
468   Double_t deltaR  = rOuter-rLast;
469   Double_t ndistR  = (rOuter-TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]))/deltaR;
470   Double_t driftM  = (0.5 - TMath::Abs(xyz[2]/250.))*2.;
471   Double_t value   = TMath::Power(driftM,param[0])/ndistR;
472   return xyz[3]*value;
473 }
474
475
476 Double_t       AliTPCTransformation::TPCdeltaFCROC(Double_t *xyz, const Double_t *const param){
477   /// delta R(Z) ROC induced
478   /// param[0] - switch  0 - use distance to IFC - 1 - distance to IFC
479   /// param[1] - kFC scaling factor  (multiplication factor  of (OFC-IFC))
480   /// param[2] - kROC scaling factor
481   /// parameters [1] and [2] should be obtained from the electric field
482   ///            simulation
483
484   Double_t rInner=78.8;
485   Double_t rFirst=85.2; 
486   Double_t rLast=245.8;
487   Double_t rOuter=258.0;  
488
489   Double_t radius  = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
490   //calculate distance to the FC - inner or outer 
491   Double_t deltaFC = (param[0]<0.5)? TMath::Abs(radius-rFirst) : TMath::Abs(radius-rLast);
492   deltaFC/=(rOuter-rInner);
493   Double_t scalingFC = 1./(1.+deltaFC/(param[1]));
494   //
495   Double_t drift = 1.-TMath::Abs(xyz[2]/250.);  // normalized drift length
496   Double_t scalingROC = (1.-1./(1.+drift/param[2]));
497   //
498   return xyz[3]*scalingFC*scalingROC;
499 }
500
501
502 Double_t       AliTPCTransformation::TPCdeltaFCCE(Double_t *xyz, const Double_t *const param){
503   /// delta R(Z) CE (central electrode) induced
504   /// param[0] - switch  0 - use distance to IFC - 1 - distance to IFC
505   /// param[1] - kFC scaling factor  (multiplication factor  of (OFC-IFC))
506   /// param[2] - kCE scaling factor
507   /// parameters [1] and [2] should be obtained from the electric field
508   ///            simulation
509
510   Double_t rInner=78.8;
511   Double_t rFirst=85.2; 
512   Double_t rLast =245.8;
513   Double_t rOuter=258.0;  
514
515   Double_t radius  = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
516   //calculate distance to the FC - inner or outer 
517   Double_t deltaFC = (param[0]<0.5)? TMath::Abs(radius-rFirst) : TMath::Abs(radius-rLast);
518   deltaFC/=(rOuter-rInner);
519   Double_t scalingFC = 1./(1.+deltaFC/(param[1]));
520   //
521   Double_t drift     = 1.-TMath::Abs(xyz[2]/250.);  // normalized drift length
522   Double_t scalingCE = 1/(1.+(1.-drift)/param[2]);  // 
523   //
524   return xyz[3]*scalingFC*scalingCE;
525 }
526
527
528
529
530
531
532
533 //
534 // TPC sector local misalignment 
535 //
536 //
537 //
538 Double_t AliTPCTransformation:: TPClocaldLxdGX(Double_t *xyz, const Double_t *const param){
539   /// xyz - [0..2] - position
540   ///       [3]    - scale parameter
541   ///       [4]    - volID
542   /// param[0]= n  - cos(n *alpha)
543   /// param[1]= n  - sin(n *alpha)
544   /// param[2]     - indication - 0 - the same for IROC OROC 1 - opposite
545   /// return delta in global coordiante system
546
547   Int_t    sector = TMath::Nint(xyz[4]);
548   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
549   Double_t ca     = TMath::Cos(alpha);
550   //  Double_t sa     = TMath::Sin(alpha); 
551   const Double_t xIROCOROC = 133.4;
552   Double_t factor = xyz[3];
553   if (param[0]>0)  factor*=TMath::Cos(alpha*param[0]);
554   if (param[1]>0)  factor*=TMath::Sin(alpha*param[1]);
555   if (param[2]>0.5 && TMath::Sqrt(xyz[1]*xyz[1]+xyz[0]*xyz[0])>xIROCOROC) factor*=-1;
556   return ca*factor;    
557 }
558
559 Double_t AliTPCTransformation::TPClocaldLxdGY(Double_t *xyz, const Double_t *const param){
560   /// xyz - [0..2] - position
561   ///       [3]    - scale parameter
562   ///       [4]    - volID
563   /// param[0]= n  - cos(n *alpha)
564   /// param[1]= n  - sin(n *alpha)
565   /// param[2]     - indication - 0 - the same for IROC OROC 1 - opposite
566   /// return delta in global coordiante system
567
568   Int_t    sector = TMath::Nint(xyz[4]);
569   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
570   //Double_t ca     = TMath::Cos(alpha);
571   Double_t sa     = TMath::Sin(alpha);
572   const Double_t xIROCOROC = 133.4;
573   Double_t factor = xyz[3];
574   if (param[0]>0)  factor*=TMath::Cos(alpha*param[0]);
575   if (param[1]>0)  factor*=TMath::Sin(alpha*param[1]);
576   if (param[2]>0.5 && TMath::Sqrt(xyz[1]*xyz[1]+xyz[0]*xyz[0])>xIROCOROC) factor*=-1;  
577   return   sa*factor;  
578 }
579
580 Double_t AliTPCTransformation:: TPClocaldLydGX(Double_t *xyz, const Double_t *const param){
581   /// xyz - [0..2] - position
582   ///       [3]    - scale parameter
583   ///       [4]    - volID
584   /// param[0]= n  - cos(n *alpha)
585   /// param[1]= n  - sin(n *alpha)
586   /// param[2]     - indication - 0 - the same for IROC OROC 1 - opposite
587   /// return delta in global coordiante system
588
589   Int_t    sector = TMath::Nint(xyz[4]);
590   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
591   //Double_t ca     = TMath::Cos(alpha);
592   Double_t sa     = TMath::Sin(alpha);
593   const Double_t xIROCOROC = 133.4;
594   Double_t factor = xyz[3];
595   if (param[0]>0)  factor*=TMath::Cos(alpha*param[0]);
596   if (param[1]>0)  factor*=TMath::Sin(alpha*param[1]);
597   if (param[2]>0.5 && TMath::Sqrt(xyz[1]*xyz[1]+xyz[0]*xyz[0])>xIROCOROC) factor*=-1;  
598   return            -sa*factor;  
599 }
600
601 Double_t AliTPCTransformation::TPClocaldLydGY(Double_t *xyz, const Double_t *const param){
602   /// xyz - [0..2] - position
603   ///       [3]    - scale parameter
604   ///       [4]    - volID
605   /// param[0]= n  - cos(n *alpha)
606   /// param[1]= n  - sin(n *alpha)
607   /// param[2]     - indication - 0 - the same for IROC OROC 1 - opposite
608   /// return delta in global coordiante system
609
610   Int_t    sector = TMath::Nint(xyz[4]);
611   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
612   Double_t ca     = TMath::Cos(alpha);
613   //Double_t sa     = TMath::Sin(alpha);
614   const Double_t xIROCOROC = 133.4;
615   Double_t factor = xyz[3];
616   if (param[0]>0)  factor*=TMath::Cos(alpha*param[0]);
617   if (param[1]>0)  factor*=TMath::Sin(alpha*param[1]);
618   if (param[2]>0.5 && TMath::Sqrt(xyz[1]*xyz[1]+xyz[0]*xyz[0])>xIROCOROC) factor*=-1;  
619   return   ca*factor;  
620 }
621
622
623 Double_t AliTPCTransformation::TPClocaldRzdGX(Double_t *xyz, const Double_t *const param){
624   /// xyz - [0..2] - position
625   ///       [3]    - scale parameter - rotation angle in mrad
626   ///       [4]    - volID
627   /// param[0]= n  - cos(n *alpha)
628   /// param[1]= n  - sin(n *alpha)
629   /// param[2]     - indication - 0 - the same for IROC OROC 1 - opposite
630   /// return delta in global coordiante system
631
632   Int_t    sector = TMath::Nint(xyz[4]);
633   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
634   Double_t ca     = TMath::Cos(alpha);  
635   Double_t sa     = TMath::Sin(alpha);
636   Double_t lx     =  xyz[0]*ca + xyz[1]*sa;
637   Double_t ly     = -xyz[0]*sa + xyz[1]*ca;
638   //
639   const Double_t xIROCOROC = 133.4;  
640   lx-=xIROCOROC;
641   Double_t rot      =  xyz[3]*0.001;    // rotation in mrad
642   if (param[0]>0)  rot*=TMath::Cos(alpha*param[0]);
643   if (param[1]>0)  rot*=TMath::Sin(alpha*param[1]);
644   if (param[2]>0.5 && lx>0) rot*=-1;  
645   //
646   Double_t dlxR     =  - ly*rot; 
647   Double_t dlyR     =    lx*rot;
648   Double_t dgxR     =  dlxR*ca - dlyR*sa;
649   //Double_t dgyR     =  dlxR*sa + dlyR*ca;
650   return  dgxR;            
651 }
652
653 Double_t AliTPCTransformation::TPClocaldRzdGY(Double_t *xyz, const Double_t *const param){
654   /// xyz - [0..2] - position
655   ///       [3]    - scale parameter - rotation angle in mrad
656   ///       [4]    - volID
657   /// param[0]= n  - cos(n *alpha)
658   /// param[1]= n  - sin(n *alpha)
659   /// param[2]     - indication - 0 - the same for IROC OROC 1 - opposite
660   /// return delta in global coordiante system
661
662   Int_t    sector = TMath::Nint(xyz[4]);
663   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
664   Double_t ca     = TMath::Cos(alpha);  
665   Double_t sa     = TMath::Sin(alpha);
666   Double_t lx     =  xyz[0]*ca + xyz[1]*sa;
667   Double_t ly     = -xyz[0]*sa + xyz[1]*ca;
668   //
669   const Double_t xIROCOROC = 133.4;  
670   lx-=xIROCOROC;
671   Double_t rot      =  xyz[3]*0.001;    // rotation in mrad
672   if (param[0]>0)  rot*=TMath::Cos(alpha*param[0]);
673   if (param[1]>0)  rot*=TMath::Sin(alpha*param[1]);
674   if (param[2]>0.5 && lx>0) rot*=-1;  
675   Double_t dlxR     =  - ly*rot; 
676   Double_t dlyR     =    lx*rot;
677   //Double_t dgxR     =  dlxR*ca - dlyR*sa;
678   Double_t dgyR     =  dlxR*sa + dlyR*ca;
679   return  dgyR;            
680 }
681
682
683
684 Double_t        AliTPCTransformation::TPCDeltaZMediumLong(Double_t *xyz, Double_t * /*param*/){
685   /// xyz - [0..2] - position
686   ///        [3]    - scale parameter
687   ///        [4]    - volID
688   /// return delta in global coordinate system
689
690   Int_t    sector = TMath::Nint(xyz[4]);
691   Double_t signZ  = (sector%36<18) ? 1: -1;  // drift direction
692   if    (sector<36) return 0;     
693   //
694   const Double_t radiusLong = 198.1;
695   //
696   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
697   Double_t ca     = TMath::Cos(alpha);  
698   Double_t sa     = TMath::Sin(alpha);
699   Double_t lx     =  xyz[0]*ca + xyz[1]*sa;
700   Double_t sign   = (lx<radiusLong) ? 1:-1;
701   return xyz[3]*sign*signZ;
702 }
703
704 Double_t        AliTPCTransformation::TPCDeltaZ(Double_t *xyz, const Double_t *const param){
705   /// xyz - [0..2] - position
706   ///        [3]    - scale parameter
707   ///        [4]    - volID
708   /// return delta in global coordiante system
709
710   Int_t    sector = TMath::Nint(xyz[4]);
711   Double_t delta  = (sector%36<18) ? 1: -1;  // drift direction
712   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
713   Double_t ca     = TMath::Cos(alpha);  
714   Double_t sa     = TMath::Sin(alpha);
715   Double_t lx     =  xyz[0]*ca + xyz[1]*sa;
716   //
717   const Double_t xIROCOROC = 133.4;  
718   if (param[0]>0) delta     *= TMath::Cos(param[0]*alpha);
719   if (param[1]>0) delta     *= TMath::Sin(param[1]*alpha);
720   if (param[2]>0.5 && lx >xIROCOROC) delta *=-1;
721   return delta*xyz[3];     // IROC shift
722 }
723
724
725 Double_t       AliTPCTransformation::TPCTiltingZ(Double_t *xyz, const Double_t *const param){
726   /// xyz - [0..2] - position
727   ///        [3]    - scale parameter
728   ///        [4]    - volID
729   /// param[0]      - n for cos
730   /// param[1]      - n for sin
731   /// param[2]      - IROC-ORC relative (if >0.5 )
732   /// return delta in global coordinate system
733
734   const Double_t rFirst=85.2; 
735   const Double_t rLast =245.8;
736   const Double_t xIROCOROC = 133.4;  
737   //
738   Int_t    sector = TMath::Nint(xyz[4]);
739   Double_t alpha  = TMath::Pi()*(sector+0.5)/9;
740   Double_t ca     = TMath::Cos(alpha);  
741   Double_t sa     = TMath::Sin(alpha);
742   Double_t lx     =  xyz[0]*ca + xyz[1]*sa;
743   Double_t deltaR = 2.0*(lx-xIROCOROC)/(rLast-rFirst);  
744   if (param[0]>0) deltaR *= TMath::Cos(param[0]*alpha);
745   if (param[1]>0) deltaR *= TMath::Sin(param[1]*alpha);
746   if (param[2]>0.5 && lx >xIROCOROC) deltaR *=-1;
747   return deltaR*xyz[3];
748 }
749