]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackParam.cxx
Simplified ValidateTracksWithTrigger method
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackParam.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////
19 //
20 // Track parameters
21 // in
22 // ALICE
23 // dimuon
24 // spectrometer
25 //
26 ///////////////////////////////////////////////////
27
28 #include <Riostream.h>
29
30 #include "AliCallf77.h" 
31 #include "AliMUON.h"
32 #include "AliMUONTrackParam.h" 
33 #include "AliMUONChamber.h"
34 #include "AliRun.h" 
35 #include "AliMagF.h" 
36
37 ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
38
39   // A few calls in Fortran or from Fortran (extrap.F).
40   // Needed, instead of calls to Geant subroutines,
41   // because double precision is necessary for track fit converging with Minuit.
42   // The "extrap" functions should be translated into C++ ????
43 #ifndef WIN32 
44 # define extrap_onestep_helix extrap_onestep_helix_
45 # define extrap_onestep_helix3 extrap_onestep_helix3_
46 # define extrap_onestep_rungekutta extrap_onestep_rungekutta_
47 # define gufld_double gufld_double_
48 #else 
49 # define extrap_onestep_helix EXTRAP_ONESTEP_HELIX
50 # define extrap_onestep_helix3 EXTRAP_ONESTEP_HELIX3
51 # define extrap_onestep_rungekutta EXTRAP_ONESTEP_RUNGEKUTTA
52 # define gufld_double GUFLD_DOUBLE
53 #endif 
54
55 extern "C" {
56   void type_of_call extrap_onestep_helix
57   (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
58
59   void type_of_call extrap_onestep_helix3
60   (Double_t &Field, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
61
62   void type_of_call extrap_onestep_rungekutta
63   (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
64
65   void type_of_call gufld_double(Double_t *Position, Double_t *Field) {
66     // interface to "gAlice->Field()->Field" for arguments in double precision
67     Float_t x[3], b[3];
68     x[0] = Position[0]; x[1] = Position[1]; x[2] = Position[2];
69     gAlice->Field()->Field(x, b);
70     Field[0] = b[0]; Field[1] = b[1]; Field[2] = b[2];
71   }
72 }
73   //_________________________________________________________________________
74
75 AliMUONTrackParam& AliMUONTrackParam::operator=(const AliMUONTrackParam& MUONTrackParam)
76 {
77   if (this == &MUONTrackParam)
78     return *this;
79
80   fInverseBendingMomentum =  MUONTrackParam.fInverseBendingMomentum; 
81   fBendingSlope           =  MUONTrackParam.fBendingSlope; 
82   fNonBendingSlope        =  MUONTrackParam.fNonBendingSlope; 
83   fZ                      =  MUONTrackParam.fZ; 
84   fBendingCoor            =  MUONTrackParam.fBendingCoor; 
85   fNonBendingCoor         =  MUONTrackParam.fNonBendingCoor;
86
87   return *this;
88 }
89   //_________________________________________________________________________
90 AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& MUONTrackParam):TObject(MUONTrackParam)
91 {
92   fInverseBendingMomentum =  MUONTrackParam.fInverseBendingMomentum; 
93   fBendingSlope           =  MUONTrackParam.fBendingSlope; 
94   fNonBendingSlope        =  MUONTrackParam.fNonBendingSlope; 
95   fZ                      =  MUONTrackParam.fZ; 
96   fBendingCoor            =  MUONTrackParam.fBendingCoor; 
97   fNonBendingCoor         =  MUONTrackParam.fNonBendingCoor;
98 }
99
100   //__________________________________________________________________________
101 void AliMUONTrackParam::ExtrapToZ(Double_t Z)
102 {
103   // Track parameter extrapolation to the plane at "Z".
104   // On return, the track parameters resulting from the extrapolation
105   // replace the current track parameters.
106   if (this->fZ == Z) return; // nothing to be done if same Z
107   Double_t forwardBackward; // +1 if forward, -1 if backward
108   if (Z < this->fZ) forwardBackward = 1.0; // spectro. z<0 
109   else forwardBackward = -1.0;
110   Double_t vGeant3[7], vGeant3New[7]; // 7 in parameter ????
111   Int_t iGeant3, stepNumber;
112   Int_t maxStepNumber = 5000; // in parameter ????
113   // For safety: return kTRUE or kFALSE ????
114   // Parameter vector for calling EXTRAP_ONESTEP
115   SetGeant3Parameters(vGeant3, forwardBackward);
116   // sign of charge (sign of fInverseBendingMomentum if forward motion)
117   // must be changed if backward extrapolation
118   Double_t chargeExtrap = forwardBackward *
119     TMath::Sign(Double_t(1.0), this->fInverseBendingMomentum);
120   Double_t stepLength = 6.0; // in parameter ????
121   // Extrapolation loop
122   stepNumber = 0;
123   while (((-forwardBackward * (vGeant3[2] - Z)) <= 0.0) &&  // spectro. z<0
124          (stepNumber < maxStepNumber)) {
125     stepNumber++;
126     // Option for switching between helix and Runge-Kutta ???? 
127     // extrap_onestep_rungekutta(chargeExtrap, stepLength, vGeant3, vGeant3New);
128     extrap_onestep_helix(chargeExtrap, stepLength, vGeant3, vGeant3New);
129     if ((-forwardBackward * (vGeant3New[2] - Z)) > 0.0) break; // one is beyond Z spectro. z<0
130     // better use TArray ????
131     for (iGeant3 = 0; iGeant3 < 7; iGeant3++)
132       {vGeant3[iGeant3] = vGeant3New[iGeant3];}
133   }
134   // check maxStepNumber ????
135   // Interpolation back to exact Z (2nd order)
136   // should be in function ???? using TArray ????
137   Double_t dZ12 = vGeant3New[2] - vGeant3[2]; // 1->2
138   Double_t dZ1i = Z - vGeant3[2]; // 1-i
139   Double_t dZi2 = vGeant3New[2] - Z; // i->2
140   Double_t xPrime = (vGeant3New[0] - vGeant3[0]) / dZ12;
141   Double_t xSecond =
142     ((vGeant3New[3] / vGeant3New[5]) - (vGeant3[3] / vGeant3[5])) / dZ12;
143   Double_t yPrime = (vGeant3New[1] - vGeant3[1]) / dZ12;
144   Double_t ySecond =
145     ((vGeant3New[4] / vGeant3New[5]) - (vGeant3[4] / vGeant3[5])) / dZ12;
146   vGeant3[0] = vGeant3[0] + xPrime * dZ1i - 0.5 * xSecond * dZ1i * dZi2; // X
147   vGeant3[1] = vGeant3[1] + yPrime * dZ1i - 0.5 * ySecond * dZ1i * dZi2; // Y
148   vGeant3[2] = Z; // Z
149   Double_t xPrimeI = xPrime - 0.5 * xSecond * (dZi2 - dZ1i);
150   Double_t yPrimeI = yPrime - 0.5 * ySecond * (dZi2 - dZ1i);
151   // (PX, PY, PZ)/PTOT assuming forward motion
152   vGeant3[5] =
153     1.0 / TMath::Sqrt(1.0 + xPrimeI * xPrimeI + yPrimeI * yPrimeI); // PZ/PTOT
154   vGeant3[3] = xPrimeI * vGeant3[5]; // PX/PTOT
155   vGeant3[4] = yPrimeI * vGeant3[5]; // PY/PTOT
156   // Track parameters from Geant3 parameters,
157   // with charge back for forward motion
158   GetFromGeant3Parameters(vGeant3, chargeExtrap * forwardBackward);
159 }
160
161   //__________________________________________________________________________
162 void AliMUONTrackParam::SetGeant3Parameters(Double_t *VGeant3, Double_t ForwardBackward)
163 {
164   // Set vector of Geant3 parameters pointed to by "VGeant3"
165   // from track parameters in current AliMUONTrackParam.
166   // Since AliMUONTrackParam is only geometry, one uses "ForwardBackward"
167   // to know whether the particle is going forward (+1) or backward (-1).
168   VGeant3[0] = this->fNonBendingCoor; // X
169   VGeant3[1] = this->fBendingCoor; // Y
170   VGeant3[2] = this->fZ; // Z
171   Double_t pYZ = TMath::Abs(1.0 / this->fInverseBendingMomentum);
172   Double_t pZ =
173     pYZ / TMath::Sqrt(1.0 + this->fBendingSlope * this->fBendingSlope);
174   VGeant3[6] =
175     TMath::Sqrt(pYZ * pYZ +
176                 pZ * pZ * this->fNonBendingSlope * this->fNonBendingSlope); // PTOT
177   VGeant3[5] = -ForwardBackward * pZ / VGeant3[6]; // PZ/PTOT spectro. z<0
178   VGeant3[3] = this->fNonBendingSlope * VGeant3[5]; // PX/PTOT
179   VGeant3[4] = this->fBendingSlope * VGeant3[5]; // PY/PTOT
180 }
181
182   //__________________________________________________________________________
183 void AliMUONTrackParam::GetFromGeant3Parameters(Double_t *VGeant3, Double_t Charge)
184 {
185   // Get track parameters in current AliMUONTrackParam
186   // from Geant3 parameters pointed to by "VGeant3",
187   // assumed to be calculated for forward motion in Z.
188   // "InverseBendingMomentum" is signed with "Charge".
189   this->fNonBendingCoor = VGeant3[0]; // X
190   this->fBendingCoor = VGeant3[1]; // Y
191   this->fZ = VGeant3[2]; // Z
192   Double_t pYZ = VGeant3[6] * TMath::Sqrt(1.0 - VGeant3[3] * VGeant3[3]);
193   this->fInverseBendingMomentum = Charge / pYZ;
194   this->fBendingSlope = VGeant3[4] / VGeant3[5];
195   this->fNonBendingSlope = VGeant3[3] / VGeant3[5];
196 }
197
198   //__________________________________________________________________________
199 void AliMUONTrackParam::ExtrapToStation(Int_t Station, AliMUONTrackParam *TrackParam)
200 {
201   // Track parameters extrapolated from current track parameters ("this")
202   // to both chambers of the station(0..) "Station"
203   // are returned in the array (dimension 2) of track parameters
204   // pointed to by "TrackParam" (index 0 and 1 for first and second chambers).
205   Double_t extZ[2], z1, z2;
206   Int_t i1 = -1, i2 = -1; // = -1 to avoid compilation warnings
207   AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
208   // range of Station to be checked ????
209   z1 = (&(pMUON->Chamber(2 * Station)))->Z(); // Z of first chamber
210   z2 = (&(pMUON->Chamber(2 * Station + 1)))->Z(); // Z of second chamber
211   // First and second Z to extrapolate at
212   if ((z1 > this->fZ) && (z2 > this->fZ)) {i1 = 0; i2 = 1;}
213   else if ((z1 < this->fZ) && (z2 < this->fZ)) {i1 = 1; i2 = 0;}
214   else {
215     cout << "ERROR in AliMUONTrackParam::CreateExtrapSegmentInStation" << endl;
216     cout << "Starting Z (" << this->fZ << ") in between z1 (" << z1 <<
217       ") and z2 (" << z2 << ") of station(0..) " << Station << endl;
218   }
219   extZ[i1] = z1;
220   extZ[i2] = z2;
221   // copy of track parameters
222   TrackParam[i1] = *this;
223   // first extrapolation
224   (&(TrackParam[i1]))->ExtrapToZ(extZ[0]);
225   TrackParam[i2] = TrackParam[i1];
226   // second extrapolation
227   (&(TrackParam[i2]))->ExtrapToZ(extZ[1]);
228   return;
229 }
230
231   //__________________________________________________________________________
232 void AliMUONTrackParam::ExtrapToVertex()
233 {
234   // Extrapolation to the vertex.
235   // Returns the track parameters resulting from the extrapolation,
236   // in the current TrackParam.
237   // Changes parameters according to Branson correction through the absorber 
238   
239   Double_t zAbsorber = -503.0; // to be coherent with the Geant absorber geometry !!!!
240                                // spectro. (z<0) 
241   // Extrapolates track parameters upstream to the "Z" end of the front absorber
242   ExtrapToZ(zAbsorber); // !!!
243   // Makes Branson correction (multiple scattering + energy loss)
244   BransonCorrection();
245   // Makes a simple magnetic field correction through the absorber
246   FieldCorrection(zAbsorber);
247 }
248
249
250 //  Keep this version for future developments
251   //__________________________________________________________________________
252 // void AliMUONTrackParam::BransonCorrection()
253 // {
254 //   // Branson correction of track parameters
255 //   // the entry parameters have to be calculated at the end of the absorber
256 //   Double_t zEndAbsorber, zBP, xBP, yBP;
257 //   Double_t  pYZ, pX, pY, pZ, pTotal, xEndAbsorber, yEndAbsorber, radiusEndAbsorber2, pT, theta;
258 //   Int_t sign;
259 //   // Would it be possible to calculate all that from Geant configuration ????
260 //   // and to get the Branson parameters from a function in ABSO module ????
261 //   // with an eventual contribution from other detectors like START ????
262 //   // Radiation lengths outer part theta > 3 degres
263 //   static Double_t x01[9] = { 18.8,    // C (cm)
264 //                           10.397,   // Concrete (cm)
265 //                           0.56,    // Plomb (cm)
266 //                           47.26,   // Polyethylene (cm)
267 //                           0.56,   // Plomb (cm)
268 //                           47.26,   // Polyethylene (cm)
269 //                           0.56,   // Plomb (cm)
270 //                           47.26,   // Polyethylene (cm)
271 //                           0.56 };   // Plomb (cm)
272 //   // inner part theta < 3 degres
273 //   static Double_t x02[3] = { 18.8,    // C (cm)
274 //                           10.397,   // Concrete (cm)
275 //                           0.35 };    // W (cm) 
276 //   // z positions of the materials inside the absober outer part theta > 3 degres
277 //   static Double_t z1[10] = { 90, 315, 467, 472, 477, 482, 487, 492, 497, 502 };
278 //   // inner part theta < 3 degres
279 //   static Double_t z2[4] = { 90, 315, 467, 503 };
280 //   static Bool_t first = kTRUE;
281 //   static Double_t zBP1, zBP2, rLimit;
282 //   // Calculates z positions of the Branson's planes: zBP1 for outer part and zBP2 for inner part (only at the first call)
283 //   if (first) {
284 //     first = kFALSE;
285 //     Double_t aNBP = 0.0;
286 //     Double_t aDBP = 0.0;
287 //     Int_t iBound;
288     
289 //     for (iBound = 0; iBound < 9; iBound++) {
290 //       aNBP = aNBP +
291 //      (z1[iBound+1] * z1[iBound+1] * z1[iBound+1] -
292 //       z1[iBound]   * z1[iBound]   * z1[iBound]    ) / x01[iBound];
293 //       aDBP = aDBP +
294 //      (z1[iBound+1] * z1[iBound+1] - z1[iBound]   * z1[iBound]    ) / x01[iBound];
295 //     }
296 //     zBP1 = (2.0 * aNBP) / (3.0 * aDBP);
297 //     aNBP = 0.0;
298 //     aDBP = 0.0;
299 //     for (iBound = 0; iBound < 3; iBound++) {
300 //       aNBP = aNBP +
301 //      (z2[iBound+1] * z2[iBound+1] * z2[iBound+1] -
302 //       z2[iBound]   * z2[iBound ]  * z2[iBound]    ) / x02[iBound];
303 //       aDBP = aDBP +
304 //      (z2[iBound+1] * z2[iBound+1] - z2[iBound] * z2[iBound]) / x02[iBound];
305 //     }
306 //     zBP2 = (2.0 * aNBP) / (3.0 * aDBP);
307 //     rLimit = z2[3] * TMath::Tan(3.0 * (TMath::Pi()) / 180.);
308 //   }
309
310 //   pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
311 //   sign = 1;      
312 //   if (fInverseBendingMomentum < 0) sign = -1;     
313 //   pZ = pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); 
314 //   pX = pZ * fNonBendingSlope; 
315 //   pY = pZ * fBendingSlope; 
316 //   pTotal = TMath::Sqrt(pYZ *pYZ + pX * pX);
317 //   xEndAbsorber = fNonBendingCoor; 
318 //   yEndAbsorber = fBendingCoor; 
319 //   radiusEndAbsorber2 = xEndAbsorber * xEndAbsorber + yEndAbsorber * yEndAbsorber;
320
321 //   if (radiusEndAbsorber2 > rLimit*rLimit) {
322 //     zEndAbsorber = z1[9];
323 //     zBP = zBP1;
324 //   } else {
325 //     zEndAbsorber = z2[3];
326 //     zBP = zBP2;
327 //   }
328
329 //   xBP = xEndAbsorber - (pX / pZ) * (zEndAbsorber - zBP);
330 //   yBP = yEndAbsorber - (pY / pZ) * (zEndAbsorber - zBP);
331
332 //   // new parameters after Branson and energy loss corrections
333 //   pZ = pTotal * zBP / TMath::Sqrt(xBP * xBP + yBP * yBP + zBP * zBP);
334 //   pX = pZ * xBP / zBP;
335 //   pY = pZ * yBP / zBP;
336 //   fBendingSlope = pY / pZ;
337 //   fNonBendingSlope = pX / pZ;
338   
339 //   pT = TMath::Sqrt(pX * pX + pY * pY);      
340 //   theta = TMath::ATan2(pT, pZ); 
341 //   pTotal =
342 //     TotalMomentumEnergyLoss(rLimit, pTotal, theta, xEndAbsorber, yEndAbsorber);
343
344 //   fInverseBendingMomentum = (sign / pTotal) *
345 //     TMath::Sqrt(1.0 +
346 //              fBendingSlope * fBendingSlope +
347 //              fNonBendingSlope * fNonBendingSlope) /
348 //     TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope);
349
350 //   // vertex position at (0,0,0)
351 //   // should be taken from vertex measurement ???
352 //   fBendingCoor = 0.0;
353 //   fNonBendingCoor = 0;
354 //   fZ= 0;
355 // }
356
357 void AliMUONTrackParam::BransonCorrection()
358 {
359   // Branson correction of track parameters
360   // the entry parameters have to be calculated at the end of the absorber
361   // simplified version: the z positions of Branson's planes are no longer calculated
362   // but are given as inputs. One can use the macros MUONTestAbso.C and DrawTestAbso.C
363   // to test this correction. 
364   // Would it be possible to calculate all that from Geant configuration ????
365   // and to get the Branson parameters from a function in ABSO module ????
366   // with an eventual contribution from other detectors like START ????
367   Double_t  zBP, xBP, yBP;
368   Double_t  pYZ, pX, pY, pZ, pTotal, xEndAbsorber, yEndAbsorber, radiusEndAbsorber2, pT, theta;
369   Int_t sign;
370   static Bool_t first = kTRUE;
371   static Double_t zBP1, zBP2, rLimit, thetaLimit, zEndAbsorber;
372   // zBP1 for outer part and zBP2 for inner part (only at the first call)
373   if (first) {
374     first = kFALSE;
375   
376     zEndAbsorber = -503;  // spectro (z<0)
377     thetaLimit = 3.0 * (TMath::Pi()) / 180.;
378     rLimit = TMath::Abs(zEndAbsorber) * TMath::Tan(thetaLimit);
379     zBP1 = -450; // values close to those calculated with EvalAbso.C
380     zBP2 = -480;
381   }
382
383   pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
384   sign = 1;      
385   if (fInverseBendingMomentum < 0) sign = -1;     
386   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); // spectro (z<0)
387   pX = pZ * fNonBendingSlope; 
388   pY = pZ * fBendingSlope; 
389   pTotal = TMath::Sqrt(pYZ *pYZ + pX * pX);
390   xEndAbsorber = fNonBendingCoor; 
391   yEndAbsorber = fBendingCoor; 
392   radiusEndAbsorber2 = xEndAbsorber * xEndAbsorber + yEndAbsorber * yEndAbsorber;
393
394   if (radiusEndAbsorber2 > rLimit*rLimit) {
395     zBP = zBP1;
396   } else {
397     zBP = zBP2;
398   }
399
400   xBP = xEndAbsorber - (pX / pZ) * (zEndAbsorber - zBP);
401   yBP = yEndAbsorber - (pY / pZ) * (zEndAbsorber - zBP);
402
403   // new parameters after Branson and energy loss corrections
404 //   Float_t zSmear = zBP - gRandom->Gaus(0.,2.);  // !!! possible smearing of Z vertex position
405   Float_t zSmear = zBP;
406   
407   pZ = pTotal * zSmear / TMath::Sqrt(xBP * xBP + yBP * yBP + zSmear * zSmear);
408   pX = pZ * xBP / zSmear;
409   pY = pZ * yBP / zSmear;
410   fBendingSlope = pY / pZ;
411   fNonBendingSlope = pX / pZ;
412
413   
414   pT = TMath::Sqrt(pX * pX + pY * pY);      
415   theta = TMath::ATan2(pT, TMath::Abs(pZ)); 
416   pTotal = TotalMomentumEnergyLoss(thetaLimit, pTotal, theta);
417
418   fInverseBendingMomentum = (sign / pTotal) *
419     TMath::Sqrt(1.0 +
420                 fBendingSlope * fBendingSlope +
421                 fNonBendingSlope * fNonBendingSlope) /
422     TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope);
423
424   // vertex position at (0,0,0)
425   // should be taken from vertex measurement ???
426   fBendingCoor = 0.0;
427   fNonBendingCoor = 0;
428   fZ= 0;
429 }
430
431   //__________________________________________________________________________
432 Double_t AliMUONTrackParam::TotalMomentumEnergyLoss(Double_t thetaLimit, Double_t pTotal, Double_t theta)
433 {
434   // Returns the total momentum corrected from energy loss in the front absorber
435   // One can use the macros MUONTestAbso.C and DrawTestAbso.C
436   // to test this correction. 
437   // Momentum energy loss behaviour evaluated with the simulation of single muons (april 2002)
438   Double_t deltaP, pTotalCorrected;
439
440    // Parametrization to be redone according to change of absorber material ????
441   // See remark in function BransonCorrection !!!!
442   // The name is not so good, and there are many arguments !!!!
443   if (theta  < thetaLimit ) {
444     if (pTotal < 20) {
445       deltaP = 2.5938 + 0.0570 * pTotal - 0.001151 * pTotal * pTotal;
446     } else {
447       deltaP = 3.0714 + 0.011767 *pTotal;
448     }
449   } else {
450     if (pTotal < 20) {
451       deltaP  = 2.1207 + 0.05478 * pTotal - 0.00145079 * pTotal * pTotal;
452     } else { 
453       deltaP = 2.6069 + 0.0051705 * pTotal;
454     }
455   }
456   pTotalCorrected = pTotal + deltaP / TMath::Cos(theta);
457   return pTotalCorrected;
458 }
459
460   //__________________________________________________________________________
461 void AliMUONTrackParam::FieldCorrection(Double_t Z)
462 {
463   // 
464   // Correction of the effect of the magnetic field in the absorber
465   // Assume a constant field along Z axis.
466
467   Float_t b[3],x[3]; 
468   Double_t bZ;
469   Double_t pYZ,pX,pY,pZ,pT;
470   Double_t pXNew,pYNew;
471   Double_t c;
472
473   pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
474   c = TMath::Sign(1.0,fInverseBendingMomentum); // particle charge 
475  
476   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
477   pX = pZ * fNonBendingSlope; 
478   pY = pZ * fBendingSlope;
479   pT = TMath::Sqrt(pX*pX+pY*pY);
480
481   if (TMath::Abs(pZ) <= 0) return;
482   x[2] = Z/2;
483   x[0] = x[2]*fNonBendingSlope;  
484   x[1] = x[2]*fBendingSlope;
485
486   // Take magn. field value at position x.
487   gAlice->Field()->Field(x, b);
488   bZ =  b[2];
489  
490   // Transverse momentum rotation
491   // Parameterized with the study of DeltaPhi = phiReco - phiGen as a function of pZ.
492   Double_t phiShift = c*0.436*0.0003*bZ*Z/pZ; 
493  // Rotate momentum around Z axis.
494   pXNew = pX*TMath::Cos(phiShift) - pY*TMath::Sin(phiShift);
495   pYNew = pX*TMath::Sin(phiShift) + pY*TMath::Cos(phiShift);
496  
497   fBendingSlope = pYNew / pZ;
498   fNonBendingSlope = pXNew / pZ;
499   
500   fInverseBendingMomentum = c / TMath::Sqrt(pYNew*pYNew+pZ*pZ);
501  
502 }