]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackParam.cxx
ReadRaw(): TGraphs are created once per event (B.Polichtchouk)
[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 #include "AliMUON.h"
30 #include "AliMUONTrackParam.h" 
31 #include "AliMUONConstants.h"
32 #include "AliESDMuonTrack.h"
33 #include "AliRun.h" 
34 #include "AliMagF.h" 
35 #include "AliLog.h" 
36
37 ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
38
39   //_________________________________________________________________________
40 AliMUONTrackParam::AliMUONTrackParam()
41   : TObject()
42 {
43 // Constructor
44
45   fInverseBendingMomentum = 0;
46   fBendingSlope = 0;
47   fNonBendingSlope = 0;
48   fZ = 0;
49   fBendingCoor = 0;
50   fNonBendingCoor = 0;
51 }
52
53   //_________________________________________________________________________
54 AliMUONTrackParam& 
55 AliMUONTrackParam::operator=(const AliMUONTrackParam& theMUONTrackParam)
56 {
57   // Asignment operator
58   if (this == &theMUONTrackParam)
59     return *this;
60
61   // base class assignement
62   TObject::operator=(theMUONTrackParam);
63
64   fInverseBendingMomentum =  theMUONTrackParam.fInverseBendingMomentum; 
65   fBendingSlope           =  theMUONTrackParam.fBendingSlope; 
66   fNonBendingSlope        =  theMUONTrackParam.fNonBendingSlope; 
67   fZ                      =  theMUONTrackParam.fZ; 
68   fBendingCoor            =  theMUONTrackParam.fBendingCoor; 
69   fNonBendingCoor         =  theMUONTrackParam.fNonBendingCoor;
70
71   return *this;
72 }
73   //_________________________________________________________________________
74 AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
75   : TObject(theMUONTrackParam)
76 {
77   // Copy constructor
78   fInverseBendingMomentum =  theMUONTrackParam.fInverseBendingMomentum; 
79   fBendingSlope           =  theMUONTrackParam.fBendingSlope; 
80   fNonBendingSlope        =  theMUONTrackParam.fNonBendingSlope; 
81   fZ                      =  theMUONTrackParam.fZ; 
82   fBendingCoor            =  theMUONTrackParam.fBendingCoor; 
83   fNonBendingCoor         =  theMUONTrackParam.fNonBendingCoor;
84 }
85
86   //_________________________________________________________________________
87 void AliMUONTrackParam::GetParamFrom(const AliESDMuonTrack& esdMuonTrack)
88 {
89   // assigned value form ESD track.
90   fInverseBendingMomentum =  esdMuonTrack.GetInverseBendingMomentum();
91   fBendingSlope           =  TMath::Tan(esdMuonTrack.GetThetaY());
92   fNonBendingSlope        =  TMath::Tan(esdMuonTrack.GetThetaX());
93   fZ                      =  esdMuonTrack.GetZ(); 
94   fBendingCoor            =  esdMuonTrack.GetBendingCoor(); 
95   fNonBendingCoor         =  esdMuonTrack.GetNonBendingCoor();
96 }
97
98   //_________________________________________________________________________
99 void AliMUONTrackParam::SetParamFor(AliESDMuonTrack& esdMuonTrack)
100 {
101   // assigned value form ESD track.
102   esdMuonTrack.SetInverseBendingMomentum(fInverseBendingMomentum);
103   esdMuonTrack.SetThetaX(TMath::ATan(fNonBendingSlope));
104   esdMuonTrack.SetThetaY(TMath::ATan(fBendingSlope));
105   esdMuonTrack.SetZ(fZ); 
106   esdMuonTrack.SetBendingCoor(fBendingCoor); 
107   esdMuonTrack.SetNonBendingCoor(fNonBendingCoor);
108 }
109
110   //__________________________________________________________________________
111 void AliMUONTrackParam::ExtrapToZ(Double_t Z)
112 {
113   // Track parameter extrapolation to the plane at "Z".
114   // On return, the track parameters resulting from the extrapolation
115   // replace the current track parameters.
116   if (this->fZ == Z) return; // nothing to be done if same Z
117   Double_t forwardBackward; // +1 if forward, -1 if backward
118   if (Z < this->fZ) forwardBackward = 1.0; // spectro. z<0 
119   else forwardBackward = -1.0;
120   Double_t vGeant3[7], vGeant3New[7]; // 7 in parameter ????
121   Int_t iGeant3, stepNumber;
122   Int_t maxStepNumber = 5000; // in parameter ????
123   // For safety: return kTRUE or kFALSE ????
124   // Parameter vector for calling EXTRAP_ONESTEP
125   SetGeant3Parameters(vGeant3, forwardBackward);
126   // sign of charge (sign of fInverseBendingMomentum if forward motion)
127   // must be changed if backward extrapolation
128   Double_t chargeExtrap = forwardBackward *
129     TMath::Sign(Double_t(1.0), this->fInverseBendingMomentum);
130   Double_t stepLength = 6.0; // in parameter ????
131   // Extrapolation loop
132   stepNumber = 0;
133   while (((-forwardBackward * (vGeant3[2] - Z)) <= 0.0) &&  // spectro. z<0
134          (stepNumber < maxStepNumber)) {
135     stepNumber++;
136     // Option for switching between helix and Runge-Kutta ???? 
137     //ExtrapOneStepRungekutta(chargeExtrap, stepLength, vGeant3, vGeant3New);
138     ExtrapOneStepHelix(chargeExtrap, stepLength, vGeant3, vGeant3New);
139     if ((-forwardBackward * (vGeant3New[2] - Z)) > 0.0) break; // one is beyond Z spectro. z<0
140     // better use TArray ????
141     for (iGeant3 = 0; iGeant3 < 7; iGeant3++)
142       {vGeant3[iGeant3] = vGeant3New[iGeant3];}
143   }
144   // check maxStepNumber ????
145   // Interpolation back to exact Z (2nd order)
146   // should be in function ???? using TArray ????
147   Double_t dZ12 = vGeant3New[2] - vGeant3[2]; // 1->2
148   if (TMath::Abs(dZ12) > 0) {
149     Double_t dZ1i = Z - vGeant3[2]; // 1-i
150     Double_t dZi2 = vGeant3New[2] - Z; // i->2
151     Double_t xPrime = (vGeant3New[0] - vGeant3[0]) / dZ12;
152     Double_t xSecond =
153       ((vGeant3New[3] / vGeant3New[5]) - (vGeant3[3] / vGeant3[5])) / dZ12;
154     Double_t yPrime = (vGeant3New[1] - vGeant3[1]) / dZ12;
155     Double_t ySecond =
156       ((vGeant3New[4] / vGeant3New[5]) - (vGeant3[4] / vGeant3[5])) / dZ12;
157     vGeant3[0] = vGeant3[0] + xPrime * dZ1i - 0.5 * xSecond * dZ1i * dZi2; // X
158     vGeant3[1] = vGeant3[1] + yPrime * dZ1i - 0.5 * ySecond * dZ1i * dZi2; // Y
159     vGeant3[2] = Z; // Z
160     Double_t xPrimeI = xPrime - 0.5 * xSecond * (dZi2 - dZ1i);
161     Double_t yPrimeI = yPrime - 0.5 * ySecond * (dZi2 - dZ1i);
162     // (PX, PY, PZ)/PTOT assuming forward motion
163     vGeant3[5] =
164       1.0 / TMath::Sqrt(1.0 + xPrimeI * xPrimeI + yPrimeI * yPrimeI); // PZ/PTOT
165     vGeant3[3] = xPrimeI * vGeant3[5]; // PX/PTOT
166     vGeant3[4] = yPrimeI * vGeant3[5]; // PY/PTOT
167   } else {
168     AliWarning(Form("Extrap. to Z not reached, Z = %f",Z));    
169   }
170   // Track parameters from Geant3 parameters,
171   // with charge back for forward motion
172   GetFromGeant3Parameters(vGeant3, chargeExtrap * forwardBackward);
173 }
174
175   //__________________________________________________________________________
176 void AliMUONTrackParam::SetGeant3Parameters(Double_t *VGeant3, Double_t ForwardBackward)
177 {
178   // Set vector of Geant3 parameters pointed to by "VGeant3"
179   // from track parameters in current AliMUONTrackParam.
180   // Since AliMUONTrackParam is only geometry, one uses "ForwardBackward"
181   // to know whether the particle is going forward (+1) or backward (-1).
182   VGeant3[0] = this->fNonBendingCoor; // X
183   VGeant3[1] = this->fBendingCoor; // Y
184   VGeant3[2] = this->fZ; // Z
185   Double_t pYZ = TMath::Abs(1.0 / this->fInverseBendingMomentum);
186   Double_t pZ =
187     pYZ / TMath::Sqrt(1.0 + this->fBendingSlope * this->fBendingSlope);
188   VGeant3[6] =
189     TMath::Sqrt(pYZ * pYZ +
190                 pZ * pZ * this->fNonBendingSlope * this->fNonBendingSlope); // PTOT
191   VGeant3[5] = -ForwardBackward * pZ / VGeant3[6]; // PZ/PTOT spectro. z<0
192   VGeant3[3] = this->fNonBendingSlope * VGeant3[5]; // PX/PTOT
193   VGeant3[4] = this->fBendingSlope * VGeant3[5]; // PY/PTOT
194 }
195
196   //__________________________________________________________________________
197 void AliMUONTrackParam::GetFromGeant3Parameters(Double_t *VGeant3, Double_t Charge)
198 {
199   // Get track parameters in current AliMUONTrackParam
200   // from Geant3 parameters pointed to by "VGeant3",
201   // assumed to be calculated for forward motion in Z.
202   // "InverseBendingMomentum" is signed with "Charge".
203   this->fNonBendingCoor = VGeant3[0]; // X
204   this->fBendingCoor = VGeant3[1]; // Y
205   this->fZ = VGeant3[2]; // Z
206   Double_t pYZ = VGeant3[6] * TMath::Sqrt(1.0 - VGeant3[3] * VGeant3[3]);
207   this->fInverseBendingMomentum = Charge / pYZ;
208   this->fBendingSlope = VGeant3[4] / VGeant3[5];
209   this->fNonBendingSlope = VGeant3[3] / VGeant3[5];
210 }
211
212   //__________________________________________________________________________
213 void AliMUONTrackParam::ExtrapToStation(Int_t Station, AliMUONTrackParam *TrackParam)
214 {
215   // Track parameters extrapolated from current track parameters ("this")
216   // to both chambers of the station(0..) "Station"
217   // are returned in the array (dimension 2) of track parameters
218   // pointed to by "TrackParam" (index 0 and 1 for first and second chambers).
219   Double_t extZ[2], z1, z2;
220   Int_t i1 = -1, i2 = -1; // = -1 to avoid compilation warnings
221   // range of Station to be checked ????
222   z1 = AliMUONConstants::DefaultChamberZ(2 * Station);
223   z2 = AliMUONConstants::DefaultChamberZ(2 * Station + 1);
224   // First and second Z to extrapolate at
225   if ((z1 > this->fZ) && (z2 > this->fZ)) {i1 = 0; i2 = 1;}
226   else if ((z1 < this->fZ) && (z2 < this->fZ)) {i1 = 1; i2 = 0;}
227   else {
228         AliError(Form("Starting Z (%f) in between z1 (%f) and z2 (%f) of station(0..)%d",this->fZ,z1,z2,Station));
229 //     cout << "ERROR in AliMUONTrackParam::CreateExtrapSegmentInStation" << endl;
230 //     cout << "Starting Z (" << this->fZ << ") in between z1 (" << z1 <<
231 //       ") and z2 (" << z2 << ") of station(0..) " << Station << endl;
232   }
233   extZ[i1] = z1;
234   extZ[i2] = z2;
235   // copy of track parameters
236   TrackParam[i1] = *this;
237   // first extrapolation
238   (&(TrackParam[i1]))->ExtrapToZ(extZ[0]);
239   TrackParam[i2] = TrackParam[i1];
240   // second extrapolation
241   (&(TrackParam[i2]))->ExtrapToZ(extZ[1]);
242   return;
243 }
244
245   //__________________________________________________________________________
246 void AliMUONTrackParam::ExtrapToVertex(Double_t xVtx, Double_t yVtx, Double_t zVtx)
247 {
248   // Extrapolation to the vertex.
249   // Returns the track parameters resulting from the extrapolation,
250   // in the current TrackParam.
251   // Changes parameters according to Branson correction through the absorber 
252   
253   Double_t zAbsorber = -503.0; // to be coherent with the Geant absorber geometry !!!!
254                                // spectro. (z<0) 
255   // Extrapolates track parameters upstream to the "Z" end of the front absorber
256   ExtrapToZ(zAbsorber); // !!!
257   // Makes Branson correction (multiple scattering + energy loss)
258   BransonCorrection(xVtx,yVtx,zVtx);
259   // Makes a simple magnetic field correction through the absorber
260   FieldCorrection(zAbsorber);
261 }
262
263
264 //  Keep this version for future developments
265   //__________________________________________________________________________
266 // void AliMUONTrackParam::BransonCorrection()
267 // {
268 //   // Branson correction of track parameters
269 //   // the entry parameters have to be calculated at the end of the absorber
270 //   Double_t zEndAbsorber, zBP, xBP, yBP;
271 //   Double_t  pYZ, pX, pY, pZ, pTotal, xEndAbsorber, yEndAbsorber, radiusEndAbsorber2, pT, theta;
272 //   Int_t sign;
273 //   // Would it be possible to calculate all that from Geant configuration ????
274 //   // and to get the Branson parameters from a function in ABSO module ????
275 //   // with an eventual contribution from other detectors like START ????
276 //   // Radiation lengths outer part theta > 3 degres
277 //   static Double_t x01[9] = { 18.8,    // C (cm)
278 //                           10.397,   // Concrete (cm)
279 //                           0.56,    // Plomb (cm)
280 //                           47.26,   // Polyethylene (cm)
281 //                           0.56,   // Plomb (cm)
282 //                           47.26,   // Polyethylene (cm)
283 //                           0.56,   // Plomb (cm)
284 //                           47.26,   // Polyethylene (cm)
285 //                           0.56 };   // Plomb (cm)
286 //   // inner part theta < 3 degres
287 //   static Double_t x02[3] = { 18.8,    // C (cm)
288 //                           10.397,   // Concrete (cm)
289 //                           0.35 };    // W (cm) 
290 //   // z positions of the materials inside the absober outer part theta > 3 degres
291 //   static Double_t z1[10] = { 90, 315, 467, 472, 477, 482, 487, 492, 497, 502 };
292 //   // inner part theta < 3 degres
293 //   static Double_t z2[4] = { 90, 315, 467, 503 };
294 //   static Bool_t first = kTRUE;
295 //   static Double_t zBP1, zBP2, rLimit;
296 //   // Calculates z positions of the Branson's planes: zBP1 for outer part and zBP2 for inner part (only at the first call)
297 //   if (first) {
298 //     first = kFALSE;
299 //     Double_t aNBP = 0.0;
300 //     Double_t aDBP = 0.0;
301 //     Int_t iBound;
302     
303 //     for (iBound = 0; iBound < 9; iBound++) {
304 //       aNBP = aNBP +
305 //      (z1[iBound+1] * z1[iBound+1] * z1[iBound+1] -
306 //       z1[iBound]   * z1[iBound]   * z1[iBound]    ) / x01[iBound];
307 //       aDBP = aDBP +
308 //      (z1[iBound+1] * z1[iBound+1] - z1[iBound]   * z1[iBound]    ) / x01[iBound];
309 //     }
310 //     zBP1 = (2.0 * aNBP) / (3.0 * aDBP);
311 //     aNBP = 0.0;
312 //     aDBP = 0.0;
313 //     for (iBound = 0; iBound < 3; iBound++) {
314 //       aNBP = aNBP +
315 //      (z2[iBound+1] * z2[iBound+1] * z2[iBound+1] -
316 //       z2[iBound]   * z2[iBound ]  * z2[iBound]    ) / x02[iBound];
317 //       aDBP = aDBP +
318 //      (z2[iBound+1] * z2[iBound+1] - z2[iBound] * z2[iBound]) / x02[iBound];
319 //     }
320 //     zBP2 = (2.0 * aNBP) / (3.0 * aDBP);
321 //     rLimit = z2[3] * TMath::Tan(3.0 * (TMath::Pi()) / 180.);
322 //   }
323
324 //   pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
325 //   sign = 1;      
326 //   if (fInverseBendingMomentum < 0) sign = -1;     
327 //   pZ = pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); 
328 //   pX = pZ * fNonBendingSlope; 
329 //   pY = pZ * fBendingSlope; 
330 //   pTotal = TMath::Sqrt(pYZ *pYZ + pX * pX);
331 //   xEndAbsorber = fNonBendingCoor; 
332 //   yEndAbsorber = fBendingCoor; 
333 //   radiusEndAbsorber2 = xEndAbsorber * xEndAbsorber + yEndAbsorber * yEndAbsorber;
334
335 //   if (radiusEndAbsorber2 > rLimit*rLimit) {
336 //     zEndAbsorber = z1[9];
337 //     zBP = zBP1;
338 //   } else {
339 //     zEndAbsorber = z2[3];
340 //     zBP = zBP2;
341 //   }
342
343 //   xBP = xEndAbsorber - (pX / pZ) * (zEndAbsorber - zBP);
344 //   yBP = yEndAbsorber - (pY / pZ) * (zEndAbsorber - zBP);
345
346 //   // new parameters after Branson and energy loss corrections
347 //   pZ = pTotal * zBP / TMath::Sqrt(xBP * xBP + yBP * yBP + zBP * zBP);
348 //   pX = pZ * xBP / zBP;
349 //   pY = pZ * yBP / zBP;
350 //   fBendingSlope = pY / pZ;
351 //   fNonBendingSlope = pX / pZ;
352   
353 //   pT = TMath::Sqrt(pX * pX + pY * pY);      
354 //   theta = TMath::ATan2(pT, pZ); 
355 //   pTotal =
356 //     TotalMomentumEnergyLoss(rLimit, pTotal, theta, xEndAbsorber, yEndAbsorber);
357
358 //   fInverseBendingMomentum = (sign / pTotal) *
359 //     TMath::Sqrt(1.0 +
360 //              fBendingSlope * fBendingSlope +
361 //              fNonBendingSlope * fNonBendingSlope) /
362 //     TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope);
363
364 //   // vertex position at (0,0,0)
365 //   // should be taken from vertex measurement ???
366 //   fBendingCoor = 0.0;
367 //   fNonBendingCoor = 0;
368 //   fZ= 0;
369 // }
370
371 void AliMUONTrackParam::BransonCorrection(Double_t xVtx,Double_t yVtx,Double_t zVtx)
372 {
373   // Branson correction of track parameters
374   // the entry parameters have to be calculated at the end of the absorber
375   // simplified version: the z positions of Branson's planes are no longer calculated
376   // but are given as inputs. One can use the macros MUONTestAbso.C and DrawTestAbso.C
377   // to test this correction. 
378   // Would it be possible to calculate all that from Geant configuration ????
379   // and to get the Branson parameters from a function in ABSO module ????
380   // with an eventual contribution from other detectors like START ????
381   //change to take into account the vertex postition (real, reconstruct,....)
382
383   Double_t  zBP, xBP, yBP;
384   Double_t  pYZ, pX, pY, pZ, pTotal, xEndAbsorber, yEndAbsorber, radiusEndAbsorber2, pT, theta;
385   Int_t sign;
386   static Bool_t first = kTRUE;
387   static Double_t zBP1, zBP2, rLimit, thetaLimit, zEndAbsorber;
388   // zBP1 for outer part and zBP2 for inner part (only at the first call)
389   if (first) {
390     first = kFALSE;
391   
392     zEndAbsorber = -503;  // spectro (z<0)
393     thetaLimit = 3.0 * (TMath::Pi()) / 180.;
394     rLimit = TMath::Abs(zEndAbsorber) * TMath::Tan(thetaLimit);
395     zBP1 = -450; // values close to those calculated with EvalAbso.C
396     zBP2 = -480;
397   }
398
399   pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
400   sign = 1;      
401   if (fInverseBendingMomentum < 0) sign = -1;  
402   pZ = Pz();
403   pX = Px(); 
404   pY = Py(); 
405   pTotal = TMath::Sqrt(pYZ *pYZ + pX * pX);
406   xEndAbsorber = fNonBendingCoor; 
407   yEndAbsorber = fBendingCoor; 
408   radiusEndAbsorber2 = xEndAbsorber * xEndAbsorber + yEndAbsorber * yEndAbsorber;
409
410   if (radiusEndAbsorber2 > rLimit*rLimit) {
411     zBP = zBP1;
412   } else {
413     zBP = zBP2;
414   }
415
416   xBP = xEndAbsorber - (pX / pZ) * (zEndAbsorber - zBP);
417   yBP = yEndAbsorber - (pY / pZ) * (zEndAbsorber - zBP);
418
419   // new parameters after Branson and energy loss corrections
420 //   Float_t zSmear = zBP - gRandom->Gaus(0.,2.);  // !!! possible smearing of Z vertex position
421
422   Float_t zSmear = zBP ;
423   
424    pZ = pTotal * (zSmear-zVtx) / TMath::Sqrt((xBP-xVtx) * (xBP-xVtx) + (yBP-yVtx) * (yBP-yVtx) +( zSmear-zVtx) * (zSmear-zVtx) );
425    pX = pZ * (xBP - xVtx)/ (zSmear-zVtx);
426    pY = pZ * (yBP - yVtx) / (zSmear-zVtx);
427   fBendingSlope = pY / pZ;
428   fNonBendingSlope = pX / pZ;
429
430   
431   pT = TMath::Sqrt(pX * pX + pY * pY);      
432   theta = TMath::ATan2(pT, TMath::Abs(pZ)); 
433   pTotal = TotalMomentumEnergyLoss(thetaLimit, pTotal, theta);
434
435   fInverseBendingMomentum = (sign / pTotal) *
436     TMath::Sqrt(1.0 +
437                 fBendingSlope * fBendingSlope +
438                 fNonBendingSlope * fNonBendingSlope) /
439     TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope);
440
441   // vertex position at (0,0,0)
442   // should be taken from vertex measurement ???
443
444   fBendingCoor = xVtx;
445   fNonBendingCoor = yVtx;
446   fZ= zVtx;
447
448 }
449
450   //__________________________________________________________________________
451 Double_t AliMUONTrackParam::TotalMomentumEnergyLoss(Double_t thetaLimit, Double_t pTotal, Double_t theta)
452 {
453   // Returns the total momentum corrected from energy loss in the front absorber
454   // One can use the macros MUONTestAbso.C and DrawTestAbso.C
455   // to test this correction. 
456   // Momentum energy loss behaviour evaluated with the simulation of single muons (april 2002)
457   Double_t deltaP, pTotalCorrected;
458
459    // Parametrization to be redone according to change of absorber material ????
460   // See remark in function BransonCorrection !!!!
461   // The name is not so good, and there are many arguments !!!!
462   if (theta  < thetaLimit ) {
463     if (pTotal < 20) {
464       deltaP = 2.5938 + 0.0570 * pTotal - 0.001151 * pTotal * pTotal;
465     } else {
466       deltaP = 3.0714 + 0.011767 *pTotal;
467     }
468     deltaP *= 0.75; // AZ
469   } else {
470     if (pTotal < 20) {
471       deltaP  = 2.1207 + 0.05478 * pTotal - 0.00145079 * pTotal * pTotal;
472     } else { 
473       deltaP = 2.6069 + 0.0051705 * pTotal;
474     }
475     deltaP *= 0.9; // AZ
476   }
477   pTotalCorrected = pTotal + deltaP / TMath::Cos(theta);
478   return pTotalCorrected;
479 }
480
481   //__________________________________________________________________________
482 void AliMUONTrackParam::FieldCorrection(Double_t Z)
483 {
484   // 
485   // Correction of the effect of the magnetic field in the absorber
486   // Assume a constant field along Z axis.
487
488   Float_t b[3],x[3]; 
489   Double_t bZ;
490   Double_t pYZ,pX,pY,pZ,pT;
491   Double_t pXNew,pYNew;
492   Double_t c;
493
494   pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
495   c = TMath::Sign(1.0,fInverseBendingMomentum); // particle charge 
496  
497   pZ = Pz();
498   pX = Px(); 
499   pY = Py();
500   pT = TMath::Sqrt(pX*pX+pY*pY);
501
502   if (TMath::Abs(pZ) <= 0) return;
503   x[2] = Z/2;
504   x[0] = x[2]*fNonBendingSlope;  
505   x[1] = x[2]*fBendingSlope;
506
507   // Take magn. field value at position x.
508   gAlice->Field()->Field(x, b);
509   bZ =  b[2];
510  
511   // Transverse momentum rotation
512   // Parameterized with the study of DeltaPhi = phiReco - phiGen as a function of pZ.
513   Double_t phiShift = c*0.436*0.0003*bZ*Z/pZ; 
514  // Rotate momentum around Z axis.
515   pXNew = pX*TMath::Cos(phiShift) - pY*TMath::Sin(phiShift);
516   pYNew = pX*TMath::Sin(phiShift) + pY*TMath::Cos(phiShift);
517  
518   fBendingSlope = pYNew / pZ;
519   fNonBendingSlope = pXNew / pZ;
520   
521   fInverseBendingMomentum = c / TMath::Sqrt(pYNew*pYNew+pZ*pZ);
522  
523 }
524   //__________________________________________________________________________
525 Double_t AliMUONTrackParam::Px() const
526 {
527   // return px from track paramaters
528   Double_t pYZ, pZ, pX;
529   pYZ = 0;
530   if (  TMath::Abs(fInverseBendingMomentum) > 0 )
531     pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
532   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
533   pX = pZ * fNonBendingSlope; 
534   return pX;
535 }
536   //__________________________________________________________________________
537 Double_t AliMUONTrackParam::Py() const
538 {
539   // return px from track paramaters
540   Double_t pYZ, pZ, pY;
541   pYZ = 0;
542   if (  TMath::Abs(fInverseBendingMomentum) > 0 )
543     pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
544   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
545   pY = pZ * fBendingSlope; 
546   return pY;
547 }
548   //__________________________________________________________________________
549 Double_t AliMUONTrackParam::Pz() const
550 {
551   // return px from track paramaters
552   Double_t pYZ, pZ;
553   pYZ = 0;
554   if (  TMath::Abs(fInverseBendingMomentum) > 0 )
555     pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
556   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
557   return pZ;
558 }
559   //__________________________________________________________________________
560 Double_t AliMUONTrackParam::P() const
561 {
562   // return p from track paramaters
563   Double_t  pYZ, pZ, p;
564   pYZ = 0;
565   if (  TMath::Abs(fInverseBendingMomentum) > 0 )
566     pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
567   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
568   p = TMath::Abs(pZ) * 
569     TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope + fNonBendingSlope * fNonBendingSlope);
570   return p;
571   
572 }
573  //__________________________________________________________________________
574 void AliMUONTrackParam::ExtrapOneStepHelix(Double_t charge, Double_t step, 
575                                          Double_t *vect, Double_t *vout) const
576 {
577 //    ******************************************************************
578 //    *                                                                *
579 //    *  Performs the tracking of one step in a magnetic field         *
580 //    *  The trajectory is assumed to be a helix in a constant field   *
581 //    *  taken at the mid point of the step.                           *
582 //    *  Parameters:                                                   *
583 //    *   input                                                        *
584 //    *     STEP =arc length of the step asked                         *
585 //    *     VECT =input vector (position,direction cos and momentum)   *
586 //    *     CHARGE=  electric charge of the particle                   *
587 //    *   output                                                       *
588 //    *     VOUT = same as VECT after completion of the step           *
589 //    *                                                                *
590 //    *    ==>Called by : <USER>, GUSWIM                               *
591 //    *       Author    m.hansroul  *********                          *
592 //    *       modified  s.egli, s.v.levonian                           *
593 //    *       modified  v.perevoztchikov
594 //    *                                                                *
595 //    ******************************************************************
596 //
597
598 // modif: everything in double precision
599
600     Double_t xyz[3], h[4], hxp[3];
601     Double_t h2xy, hp, rho, tet;
602     Double_t sint, sintt, tsint, cos1t;
603     Double_t f1, f2, f3, f4, f5, f6;
604
605     const Int_t kix  = 0;
606     const Int_t kiy  = 1;
607     const Int_t kiz  = 2;
608     const Int_t kipx = 3;
609     const Int_t kipy = 4;
610     const Int_t kipz = 5;
611     const Int_t kipp = 6;
612
613     const Double_t kec = 2.9979251e-4;
614     //
615     //    ------------------------------------------------------------------
616     //
617     //       units are kgauss,centimeters,gev/c
618     //
619     vout[kipp] = vect[kipp];
620     if (TMath::Abs(charge) < 0.00001) {
621       for (Int_t i = 0; i < 3; i++) {
622         vout[i] = vect[i] + step * vect[i+3];
623         vout[i+3] = vect[i+3];
624       }
625       return;
626     }
627     xyz[0]    = vect[kix] + 0.5 * step * vect[kipx];
628     xyz[1]    = vect[kiy] + 0.5 * step * vect[kipy];
629     xyz[2]    = vect[kiz] + 0.5 * step * vect[kipz];
630
631     //cmodif: call gufld (xyz, h) changed into:
632     GetField (xyz, h);
633  
634     h2xy = h[0]*h[0] + h[1]*h[1];
635     h[3] = h[2]*h[2]+ h2xy;
636     if (h[3] < 1.e-12) {
637       for (Int_t i = 0; i < 3; i++) {
638         vout[i] = vect[i] + step * vect[i+3];
639         vout[i+3] = vect[i+3];
640       }
641       return;
642     }
643     if (h2xy < 1.e-12*h[3]) {
644       ExtrapOneStepHelix3(charge*h[2], step, vect, vout);
645       return;
646     }
647     h[3] = TMath::Sqrt(h[3]);
648     h[0] /= h[3];
649     h[1] /= h[3];
650     h[2] /= h[3];
651     h[3] *= kec;
652
653     hxp[0] = h[1]*vect[kipz] - h[2]*vect[kipy];
654     hxp[1] = h[2]*vect[kipx] - h[0]*vect[kipz];
655     hxp[2] = h[0]*vect[kipy] - h[1]*vect[kipx];
656  
657     hp = h[0]*vect[kipx] + h[1]*vect[kipy] + h[2]*vect[kipz];
658
659     rho = -charge*h[3]/vect[kipp];
660     tet = rho * step;
661
662     if (TMath::Abs(tet) > 0.15) {
663       sint = TMath::Sin(tet);
664       sintt = (sint/tet);
665       tsint = (tet-sint)/tet;
666       cos1t = 2.*(TMath::Sin(0.5*tet))*(TMath::Sin(0.5*tet))/tet;
667     } else {
668       tsint = tet*tet/36.;
669       sintt = (1. - tsint);
670       sint = tet*sintt;
671       cos1t = 0.5*tet;
672     }
673
674     f1 = step * sintt;
675     f2 = step * cos1t;
676     f3 = step * tsint * hp;
677     f4 = -tet*cos1t;
678     f5 = sint;
679     f6 = tet * cos1t * hp;
680  
681     vout[kix] = vect[kix] + f1*vect[kipx] + f2*hxp[0] + f3*h[0];
682     vout[kiy] = vect[kiy] + f1*vect[kipy] + f2*hxp[1] + f3*h[1];
683     vout[kiz] = vect[kiz] + f1*vect[kipz] + f2*hxp[2] + f3*h[2];
684  
685     vout[kipx] = vect[kipx] + f4*vect[kipx] + f5*hxp[0] + f6*h[0];
686     vout[kipy] = vect[kipy] + f4*vect[kipy] + f5*hxp[1] + f6*h[1];
687     vout[kipz] = vect[kipz] + f4*vect[kipz] + f5*hxp[2] + f6*h[2];
688  
689     return;
690 }
691
692  //__________________________________________________________________________
693 void AliMUONTrackParam::ExtrapOneStepHelix3(Double_t field, Double_t step, 
694                                                Double_t *vect, Double_t *vout) const
695 {
696 // 
697 //     ******************************************************************
698 //     *                                                                *
699 //     *       Tracking routine in a constant field oriented            *
700 //     *       along axis 3                                             *
701 //     *       Tracking is performed with a conventional                *
702 //     *       helix step method                                        *
703 //     *                                                                *
704 //     *    ==>Called by : <USER>, GUSWIM                               *
705 //     *       Authors    R.Brun, M.Hansroul  *********                 *
706 //     *       Rewritten  V.Perevoztchikov
707 //     *                                                                *
708 //     ******************************************************************
709 // 
710
711     Double_t hxp[3];
712     Double_t h4, hp, rho, tet;
713     Double_t sint, sintt, tsint, cos1t;
714     Double_t f1, f2, f3, f4, f5, f6;
715
716     const Int_t kix  = 0;
717     const Int_t kiy  = 1;
718     const Int_t kiz  = 2;
719     const Int_t kipx = 3;
720     const Int_t kipy = 4;
721     const Int_t kipz = 5;
722     const Int_t kipp = 6;
723
724     const Double_t kec = 2.9979251e-4;
725
726 // 
727 //     ------------------------------------------------------------------
728 // 
729 //       units are kgauss,centimeters,gev/c
730 // 
731     vout[kipp] = vect[kipp];
732     h4 = field * kec;
733
734     hxp[0] = - vect[kipy];
735     hxp[1] = + vect[kipx];
736  
737     hp = vect[kipz];
738
739     rho = -h4/vect[kipp];
740     tet = rho * step;
741     if (TMath::Abs(tet) > 0.15) {
742       sint = TMath::Sin(tet);
743       sintt = (sint/tet);
744       tsint = (tet-sint)/tet;
745       cos1t = 2.* TMath::Sin(0.5*tet) * TMath::Sin(0.5*tet)/tet;
746     } else {
747       tsint = tet*tet/36.;
748       sintt = (1. - tsint);
749       sint = tet*sintt;
750       cos1t = 0.5*tet;
751     }
752
753     f1 = step * sintt;
754     f2 = step * cos1t;
755     f3 = step * tsint * hp;
756     f4 = -tet*cos1t;
757     f5 = sint;
758     f6 = tet * cos1t * hp;
759  
760     vout[kix] = vect[kix] + f1*vect[kipx] + f2*hxp[0];
761     vout[kiy] = vect[kiy] + f1*vect[kipy] + f2*hxp[1];
762     vout[kiz] = vect[kiz] + f1*vect[kipz] + f3;
763  
764     vout[kipx] = vect[kipx] + f4*vect[kipx] + f5*hxp[0];
765     vout[kipy] = vect[kipy] + f4*vect[kipy] + f5*hxp[1];
766     vout[kipz] = vect[kipz] + f4*vect[kipz] + f6;
767
768     return;
769 }
770  //__________________________________________________________________________
771 void AliMUONTrackParam::ExtrapOneStepRungekutta(Double_t charge, Double_t step, 
772                                                      Double_t* vect, Double_t* vout) const
773 {
774 // 
775 //     ******************************************************************
776 //     *                                                                *
777 //     *  Runge-Kutta method for tracking a particle through a magnetic *
778 //     *  field. Uses Nystroem algorithm (See Handbook Nat. Bur. of     *
779 //     *  Standards, procedure 25.5.20)                                 *
780 //     *                                                                *
781 //     *  Input parameters                                              *
782 //     *       CHARGE    Particle charge                                *
783 //     *       STEP      Step size                                      *
784 //     *       VECT      Initial co-ords,direction cosines,momentum     *
785 //     *  Output parameters                                             *
786 //     *       VOUT      Output co-ords,direction cosines,momentum      *
787 //     *  User routine called                                           *
788 //     *       CALL GUFLD(X,F)                                          *
789 //     *                                                                *
790 //     *    ==>Called by : <USER>, GUSWIM                               *
791 //     *       Authors    R.Brun, M.Hansroul  *********                 *
792 //     *                  V.Perevoztchikov (CUT STEP implementation)    *
793 //     *                                                                *
794 //     *                                                                *
795 //     ******************************************************************
796 // 
797
798     Double_t h2, h4, f[4];
799     Double_t xyzt[3], a, b, c, ph,ph2;
800     Double_t secxs[4],secys[4],seczs[4],hxp[3];
801     Double_t g1, g2, g3, g4, g5, g6, ang2, dxt, dyt, dzt;
802     Double_t est, at, bt, ct, cba;
803     Double_t f1, f2, f3, f4, rho, tet, hnorm, hp, rho1, sint, cost;
804     
805     Double_t x;
806     Double_t y;
807     Double_t z;
808     
809     Double_t xt;
810     Double_t yt;
811     Double_t zt;
812
813     Double_t maxit = 1992;
814     Double_t maxcut = 11;
815
816     const Double_t kdlt   = 1e-4;
817     const Double_t kdlt32 = kdlt/32.;
818     const Double_t kthird = 1./3.;
819     const Double_t khalf  = 0.5;
820     const Double_t kec = 2.9979251e-4;
821
822     const Double_t kpisqua = 9.86960440109;
823     const Int_t kix  = 0;
824     const Int_t kiy  = 1;
825     const Int_t kiz  = 2;
826     const Int_t kipx = 3;
827     const Int_t kipy = 4;
828     const Int_t kipz = 5;
829   
830     // *.
831     // *.    ------------------------------------------------------------------
832     // *.
833     // *             this constant is for units cm,gev/c and kgauss
834     // *
835     Int_t iter = 0;
836     Int_t ncut = 0;
837     for(Int_t j = 0; j < 7; j++)
838       vout[j] = vect[j];
839
840     Double_t  pinv   = kec * charge / vect[6];
841     Double_t tl = 0.;
842     Double_t h = step;
843     Double_t rest;
844
845  
846     do {
847       rest  = step - tl;
848       if (TMath::Abs(h) > TMath::Abs(rest)) h = rest;
849       //cmodif: call gufld(vout,f) changed into:
850
851       GetField(vout,f);
852
853       // *
854       // *             start of integration
855       // *
856       x      = vout[0];
857       y      = vout[1];
858       z      = vout[2];
859       a      = vout[3];
860       b      = vout[4];
861       c      = vout[5];
862
863       h2     = khalf * h;
864       h4     = khalf * h2;
865       ph     = pinv * h;
866       ph2    = khalf * ph;
867       secxs[0] = (b * f[2] - c * f[1]) * ph2;
868       secys[0] = (c * f[0] - a * f[2]) * ph2;
869       seczs[0] = (a * f[1] - b * f[0]) * ph2;
870       ang2 = (secxs[0]*secxs[0] + secys[0]*secys[0] + seczs[0]*seczs[0]);
871       if (ang2 > kpisqua) break;
872
873       dxt    = h2 * a + h4 * secxs[0];
874       dyt    = h2 * b + h4 * secys[0];
875       dzt    = h2 * c + h4 * seczs[0];
876       xt     = x + dxt;
877       yt     = y + dyt;
878       zt     = z + dzt;
879       // *
880       // *              second intermediate point
881       // *
882
883       est = TMath::Abs(dxt) + TMath::Abs(dyt) + TMath::Abs(dzt);
884       if (est > h) {
885         if (ncut++ > maxcut) break;
886         h *= khalf;
887         continue;
888       }
889  
890       xyzt[0] = xt;
891       xyzt[1] = yt;
892       xyzt[2] = zt;
893
894       //cmodif: call gufld(xyzt,f) changed into:
895       GetField(xyzt,f);
896
897       at     = a + secxs[0];
898       bt     = b + secys[0];
899       ct     = c + seczs[0];
900
901       secxs[1] = (bt * f[2] - ct * f[1]) * ph2;
902       secys[1] = (ct * f[0] - at * f[2]) * ph2;
903       seczs[1] = (at * f[1] - bt * f[0]) * ph2;
904       at     = a + secxs[1];
905       bt     = b + secys[1];
906       ct     = c + seczs[1];
907       secxs[2] = (bt * f[2] - ct * f[1]) * ph2;
908       secys[2] = (ct * f[0] - at * f[2]) * ph2;
909       seczs[2] = (at * f[1] - bt * f[0]) * ph2;
910       dxt    = h * (a + secxs[2]);
911       dyt    = h * (b + secys[2]);
912       dzt    = h * (c + seczs[2]);
913       xt     = x + dxt;
914       yt     = y + dyt;
915       zt     = z + dzt;
916       at     = a + 2.*secxs[2];
917       bt     = b + 2.*secys[2];
918       ct     = c + 2.*seczs[2];
919
920       est = TMath::Abs(dxt)+TMath::Abs(dyt)+TMath::Abs(dzt);
921       if (est > 2.*TMath::Abs(h)) {
922         if (ncut++ > maxcut) break;
923         h *= khalf;
924         continue;
925       }
926  
927       xyzt[0] = xt;
928       xyzt[1] = yt;
929       xyzt[2] = zt;
930
931       //cmodif: call gufld(xyzt,f) changed into:
932       GetField(xyzt,f);
933
934       z      = z + (c + (seczs[0] + seczs[1] + seczs[2]) * kthird) * h;
935       y      = y + (b + (secys[0] + secys[1] + secys[2]) * kthird) * h;
936       x      = x + (a + (secxs[0] + secxs[1] + secxs[2]) * kthird) * h;
937
938       secxs[3] = (bt*f[2] - ct*f[1])* ph2;
939       secys[3] = (ct*f[0] - at*f[2])* ph2;
940       seczs[3] = (at*f[1] - bt*f[0])* ph2;
941       a      = a+(secxs[0]+secxs[3]+2. * (secxs[1]+secxs[2])) * kthird;
942       b      = b+(secys[0]+secys[3]+2. * (secys[1]+secys[2])) * kthird;
943       c      = c+(seczs[0]+seczs[3]+2. * (seczs[1]+seczs[2])) * kthird;
944
945       est    = TMath::Abs(secxs[0]+secxs[3] - (secxs[1]+secxs[2]))
946         + TMath::Abs(secys[0]+secys[3] - (secys[1]+secys[2]))
947         + TMath::Abs(seczs[0]+seczs[3] - (seczs[1]+seczs[2]));
948
949       if (est > kdlt && TMath::Abs(h) > 1.e-4) {
950         if (ncut++ > maxcut) break;
951         h *= khalf;
952         continue;
953       }
954
955       ncut = 0;
956       // *               if too many iterations, go to helix
957       if (iter++ > maxit) break;
958
959       tl += h;
960       if (est < kdlt32) 
961         h *= 2.;
962       cba    = 1./ TMath::Sqrt(a*a + b*b + c*c);
963       vout[0] = x;
964       vout[1] = y;
965       vout[2] = z;
966       vout[3] = cba*a;
967       vout[4] = cba*b;
968       vout[5] = cba*c;
969       rest = step - tl;
970       if (step < 0.) rest = -rest;
971       if (rest < 1.e-5*TMath::Abs(step)) return;
972
973     } while(1);
974
975     // angle too big, use helix
976
977     f1  = f[0];
978     f2  = f[1];
979     f3  = f[2];
980     f4  = TMath::Sqrt(f1*f1+f2*f2+f3*f3);
981     rho = -f4*pinv;
982     tet = rho * step;
983  
984     hnorm = 1./f4;
985     f1 = f1*hnorm;
986     f2 = f2*hnorm;
987     f3 = f3*hnorm;
988
989     hxp[0] = f2*vect[kipz] - f3*vect[kipy];
990     hxp[1] = f3*vect[kipx] - f1*vect[kipz];
991     hxp[2] = f1*vect[kipy] - f2*vect[kipx];
992  
993     hp = f1*vect[kipx] + f2*vect[kipy] + f3*vect[kipz];
994
995     rho1 = 1./rho;
996     sint = TMath::Sin(tet);
997     cost = 2.*TMath::Sin(khalf*tet)*TMath::Sin(khalf*tet);
998
999     g1 = sint*rho1;
1000     g2 = cost*rho1;
1001     g3 = (tet-sint) * hp*rho1;
1002     g4 = -cost;
1003     g5 = sint;
1004     g6 = cost * hp;
1005  
1006     vout[kix] = vect[kix] + g1*vect[kipx] + g2*hxp[0] + g3*f1;
1007     vout[kiy] = vect[kiy] + g1*vect[kipy] + g2*hxp[1] + g3*f2;
1008     vout[kiz] = vect[kiz] + g1*vect[kipz] + g2*hxp[2] + g3*f3;
1009  
1010     vout[kipx] = vect[kipx] + g4*vect[kipx] + g5*hxp[0] + g6*f1;
1011     vout[kipy] = vect[kipy] + g4*vect[kipy] + g5*hxp[1] + g6*f2;
1012     vout[kipz] = vect[kipz] + g4*vect[kipz] + g5*hxp[2] + g6*f3;
1013
1014     return;
1015 }
1016 //___________________________________________________________
1017  void  AliMUONTrackParam::GetField(Double_t *Position, Double_t *Field) const
1018 {
1019     // interface to "gAlice->Field()->Field" for arguments in double precision
1020
1021     Float_t x[3], b[3];
1022
1023     x[0] = Position[0]; x[1] = Position[1]; x[2] = Position[2];
1024
1025     gAlice->Field()->Field(x, b);
1026     Field[0] = b[0]; Field[1] = b[1]; Field[2] = b[2];
1027
1028     return;
1029   }
1030 //_____________________________________________-
1031 void AliMUONTrackParam::Print(Option_t* opt) const
1032 {
1033 //
1034   // Printing TrackParam information 
1035   // "full" option for printing all the information about the TrackParam
1036   //
1037   TString sopt(opt);
1038   sopt.ToUpper();
1039  
1040   if ( sopt.Contains("FULL") ) { 
1041     cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3)  << 1./GetInverseBendingMomentum() << 
1042       ", NonBendSlope=" << setw(5) << setprecision(3)  << GetNonBendingSlope()*180./TMath::Pi() <<
1043       ", BendSlope=" << setw(5) << setprecision(3)     << GetBendingSlope()*180./TMath::Pi()  << 
1044       ", (x,y,z)_IP=(" <<  setw(5) << setprecision(3) << GetNonBendingCoor() <<
1045       "," <<  setw(5) << setprecision(3) << GetBendingCoor() <<
1046       "," <<  setw(5) << setprecision(3) << GetZ() <<
1047       ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
1048       "," << setw(5) << setprecision(3) << Py() <<
1049       "," << setw(5) << setprecision(3) << Pz() << ") GeV/c" << endl;
1050   }
1051   else {
1052     cout << "<AliMUONTrackParam>"  << endl;
1053   }
1054     
1055 }