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