]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackParam.cxx
AliMUONEventReconstructor package
[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 /*
17 $Log$
18 Revision 1.5  2000/07/18 16:04:06  gosset
19 AliMUONEventReconstructor package:
20 * a few minor modifications and more comments
21 * a few corrections
22   * right sign for Z of raw clusters
23   * right loop over chambers inside station
24   * symmetrized covariance matrix for measurements (TrackChi2MCS)
25   * right sign of charge in extrapolation (ExtrapToZ)
26   * right zEndAbsorber for Branson correction below 3 degrees
27 * use of TVirtualFitter instead of TMinuit for AliMUONTrack::Fit
28 * no parameter for AliMUONTrack::Fit() but more fit parameters in Track object
29
30 Revision 1.4  2000/07/03 07:53:31  morsch
31 Double declaration problem on HP solved.
32
33 Revision 1.3  2000/06/30 10:15:48  gosset
34 Changes to EventReconstructor...:
35 precision fit with multiple Coulomb scattering;
36 extrapolation to vertex with Branson correction in absorber (JPC)
37
38 Revision 1.2  2000/06/15 07:58:49  morsch
39 Code from MUON-dev joined
40
41 Revision 1.1.2.3  2000/06/09 21:03:09  morsch
42 Make includes consistent with new file structure.
43
44 Revision 1.1.2.2  2000/06/09 12:58:05  gosset
45 Removed comment beginnings in Log sections of .cxx files
46 Suppressed most violations of coding rules
47
48 Revision 1.1.2.1  2000/06/07 14:44:53  gosset
49 Addition of files for track reconstruction in C++
50 */
51
52 //__________________________________________________________________________
53 //
54 // Track parameters in ALICE dimuon spectrometer
55 //__________________________________________________________________________
56
57 #include <iostream.h>
58
59 #include "AliCallf77.h" 
60 #include "AliMUON.h" 
61 #include "AliMUONHitForRec.h" 
62 #include "AliMUONSegment.h" 
63 #include "AliMUONTrackParam.h" 
64 #include "AliMUONChamber.h" 
65 #include "AliRun.h" 
66
67 ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
68
69   // A few calls in Fortran or from Fortran (extrap.F).
70   // Needed, instead of calls to Geant subroutines,
71   // because double precision is necessary for track fit converging with Minuit.
72   // The "extrap" functions should be translated into C++ ????
73 #ifndef WIN32 
74 # define extrap_onestep_helix extrap_onestep_helix_
75 # define extrap_onestep_helix3 extrap_onestep_helix3_
76 # define extrap_onestep_rungekutta extrap_onestep_rungekutta_
77 # define gufld_double gufld_double_
78 #else 
79 # define extrap_onestep_helix EXTRAP_ONESTEP_HELIX
80 # define extrap_onestep_helix3 EXTRAP_ONESTEP_HELIX3
81 # define extrap_onestep_rungekutta EXTRAP_ONESTEP_RUNGEKUTTA
82 # define gufld_double GUFLD_DOUBLE
83 #endif 
84
85 extern "C" {
86   void type_of_call extrap_onestep_helix
87   (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
88
89   void type_of_call extrap_onestep_helix3
90   (Double_t &Field, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
91
92   void type_of_call extrap_onestep_rungekutta
93   (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
94
95   void type_of_call gufld_double(Double_t *Position, Double_t *Field) {
96     // interface to "gAlice->Field()->Field" for arguments in double precision
97     Float_t x[3], b[3];
98     x[0] = Position[0]; x[1] = Position[1]; x[2] = Position[2];
99     gAlice->Field()->Field(x, b);
100     Field[0] = b[0]; Field[1] = b[1]; Field[2] = b[2];
101   }
102 }
103
104 // Inline functions for Get and Set: inline removed because it does not work !!!!
105 Double_t AliMUONTrackParam::GetInverseBendingMomentum(void) {
106   // Get fInverseBendingMomentum
107   return fInverseBendingMomentum;}
108 void AliMUONTrackParam::SetInverseBendingMomentum(Double_t InverseBendingMomentum) {
109   // Set fInverseBendingMomentum
110   fInverseBendingMomentum = InverseBendingMomentum;}
111 Double_t AliMUONTrackParam::GetBendingSlope(void) {
112   // Get fBendingSlope
113   return fBendingSlope;}
114 void AliMUONTrackParam::SetBendingSlope(Double_t BendingSlope) {
115   // Set fBendingSlope
116   fBendingSlope = BendingSlope;}
117 Double_t AliMUONTrackParam::GetNonBendingSlope(void) {
118   // Get fNonBendingSlope
119   return fNonBendingSlope;}
120 void AliMUONTrackParam::SetNonBendingSlope(Double_t NonBendingSlope) {
121   // Set fNonBendingSlope
122   fNonBendingSlope = NonBendingSlope;}
123 Double_t AliMUONTrackParam::GetZ(void) {
124   // Get fZ
125   return fZ;}
126 void AliMUONTrackParam::SetZ(Double_t Z) {
127   // Set fZ
128   fZ = Z;}
129 Double_t AliMUONTrackParam::GetBendingCoor(void) {
130   // Get fBendingCoor
131   return fBendingCoor;}
132 void AliMUONTrackParam::SetBendingCoor(Double_t BendingCoor) {
133   // Set fBendingCoor
134   fBendingCoor = BendingCoor;}
135 Double_t AliMUONTrackParam::GetNonBendingCoor(void) {
136   // Get fNonBendingCoor
137   return fNonBendingCoor;}
138 void AliMUONTrackParam::SetNonBendingCoor(Double_t NonBendingCoor) {
139   // Set fNonBendingCoor
140   fNonBendingCoor = NonBendingCoor;}
141
142   //__________________________________________________________________________
143 void AliMUONTrackParam::ExtrapToZ(Double_t Z)
144 {
145   // Track parameter extrapolation to the plane at "Z".
146   // On return, the track parameters resulting from the extrapolation
147   // replace the current track parameters.
148   if (this->fZ == Z) return; // nothing to be done if same Z
149   Double_t forwardBackward; // +1 if forward, -1 if backward
150   if (Z > this->fZ) forwardBackward = 1.0;
151   else forwardBackward = -1.0;
152   Double_t vGeant3[7], vGeant3New[7]; // 7 in parameter ????
153   Int_t iGeant3, stepNumber;
154   Int_t maxStepNumber = 5000; // in parameter ????
155   // For safety: return kTRUE or kFALSE ????
156   // Parameter vector for calling EXTRAP_ONESTEP
157   SetGeant3Parameters(vGeant3, forwardBackward);
158   // sign of charge (sign of fInverseBendingMomentum if forward motion)
159   // must be changed if backward extrapolation
160   Double_t chargeExtrap = forwardBackward *
161     TMath::Sign(Double_t(1.0), this->fInverseBendingMomentum);
162   Double_t stepLength = 6.0; // in parameter ????
163   // Extrapolation loop
164   stepNumber = 0;
165   while (((forwardBackward * (vGeant3[2] - Z)) <= 0.0) &&
166          (stepNumber < maxStepNumber)) {
167     stepNumber++;
168     // Option for switching between helix and Runge-Kutta ???? 
169     // extrap_onestep_rungekutta(chargeExtrap, stepLength, vGeant3, vGeant3New);
170     extrap_onestep_helix(chargeExtrap, stepLength, vGeant3, vGeant3New);
171     if ((forwardBackward * (vGeant3New[2] - Z)) > 0.0) break; // one is beyond Z
172     // better use TArray ????
173     for (iGeant3 = 0; iGeant3 < 7; iGeant3++)
174       {vGeant3[iGeant3] = vGeant3New[iGeant3];}
175   }
176   // check maxStepNumber ????
177   // Interpolation back to exact Z (2nd order)
178   // should be in function ???? using TArray ????
179   Double_t dZ12 = vGeant3New[2] - vGeant3[2]; // 1->2
180   Double_t dZ1i = Z - vGeant3[2]; // 1-i
181   Double_t dZi2 = vGeant3New[2] - Z; // i->2
182   Double_t xPrime = (vGeant3New[0] - vGeant3[0]) / dZ12;
183   Double_t xSecond =
184     ((vGeant3New[3] / vGeant3New[5]) - (vGeant3[3] / vGeant3[5])) / dZ12;
185   Double_t yPrime = (vGeant3New[1] - vGeant3[1]) / dZ12;
186   Double_t ySecond =
187     ((vGeant3New[4] / vGeant3New[5]) - (vGeant3[4] / vGeant3[5])) / dZ12;
188   vGeant3[0] = vGeant3[0] + xPrime * dZ1i - 0.5 * xSecond * dZ1i * dZi2; // X
189   vGeant3[1] = vGeant3[1] + yPrime * dZ1i - 0.5 * ySecond * dZ1i * dZi2; // Y
190   vGeant3[2] = Z; // Z
191   Double_t xPrimeI = xPrime - 0.5 * xSecond * (dZi2 - dZ1i);
192   Double_t yPrimeI = yPrime - 0.5 * ySecond * (dZi2 - dZ1i);
193   // (PX, PY, PZ)/PTOT assuming forward motion
194   vGeant3[5] =
195     1.0 / TMath::Sqrt(1.0 + xPrimeI * xPrimeI + yPrimeI * yPrimeI); // PZ/PTOT
196   vGeant3[3] = xPrimeI * vGeant3[5]; // PX/PTOT
197   vGeant3[4] = yPrimeI * vGeant3[5]; // PY/PTOT
198   // Track parameters from Geant3 parameters,
199   // with charge back for forward motion
200   GetFromGeant3Parameters(vGeant3, chargeExtrap * forwardBackward);
201 }
202
203   //__________________________________________________________________________
204 void AliMUONTrackParam::SetGeant3Parameters(Double_t *VGeant3, Double_t ForwardBackward)
205 {
206   // Set vector of Geant3 parameters pointed to by "VGeant3"
207   // from track parameters in current AliMUONTrackParam.
208   // Since AliMUONTrackParam is only geometry, one uses "ForwardBackward"
209   // to know whether the particle is going forward (+1) or backward (-1).
210   VGeant3[0] = this->fNonBendingCoor; // X
211   VGeant3[1] = this->fBendingCoor; // Y
212   VGeant3[2] = this->fZ; // Z
213   Double_t pYZ = TMath::Abs(1.0 / this->fInverseBendingMomentum);
214   Double_t pZ =
215     pYZ / TMath::Sqrt(1.0 + this->fBendingSlope * this->fBendingSlope);
216   VGeant3[6] =
217     TMath::Sqrt(pYZ * pYZ +
218                 pZ * pZ * this->fNonBendingSlope * this->fNonBendingSlope); // PTOT
219   VGeant3[5] = ForwardBackward * pZ / VGeant3[6]; // PZ/PTOT
220   VGeant3[3] = this->fNonBendingSlope * VGeant3[5]; // PX/PTOT
221   VGeant3[4] = this->fBendingSlope * VGeant3[5]; // PY/PTOT
222 }
223
224   //__________________________________________________________________________
225 void AliMUONTrackParam::GetFromGeant3Parameters(Double_t *VGeant3, Double_t Charge)
226 {
227   // Get track parameters in current AliMUONTrackParam
228   // from Geant3 parameters pointed to by "VGeant3",
229   // assumed to be calculated for forward motion in Z.
230   // "InverseBendingMomentum" is signed with "Charge".
231   this->fNonBendingCoor = VGeant3[0]; // X
232   this->fBendingCoor = VGeant3[1]; // Y
233   this->fZ = VGeant3[2]; // Z
234   Double_t pYZ = VGeant3[6] * TMath::Sqrt(1.0 - VGeant3[3] * VGeant3[3]);
235   this->fInverseBendingMomentum = Charge / pYZ;
236   this->fBendingSlope = VGeant3[4] / VGeant3[5];
237   this->fNonBendingSlope = VGeant3[3] / VGeant3[5];
238 }
239
240   //__________________________________________________________________________
241 void AliMUONTrackParam::ExtrapToStation(Int_t Station, AliMUONTrackParam *TrackParam)
242 {
243   // Track parameters extrapolated from current track parameters ("this")
244   // to both chambers of the station(0..) "Station"
245   // are returned in the array (dimension 2) of track parameters
246   // pointed to by "TrackParam" (index 0 and 1 for first and second chambers).
247   Double_t extZ[2], z1, z2;
248   Int_t i1, i2;
249   AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
250   // range of Station to be checked ????
251   z1 = (&(pMUON->Chamber(2 * Station)))->Z(); // Z of first chamber
252   z2 = (&(pMUON->Chamber(2 * Station + 1)))->Z(); // Z of second chamber
253   // First and second Z to extrapolate at
254   if ((z1 > this->fZ) && (z2 > this->fZ)) {i1 = 0; i2 = 1;}
255   else if ((z1 < this->fZ) && (z2 < this->fZ)) {i1 = 1; i2 = 0;}
256   else {
257     cout << "ERROR in AliMUONTrackParam::CreateExtrapSegmentInStation" << endl;
258     cout << "Starting Z (" << this->fZ << ") in between z1 (" << z1 <<
259       ") and z2 (" << z2 << ") of station(0..) " << Station << endl;
260   }
261   extZ[i1] = z1;
262   extZ[i2] = z2;
263   // copy of track parameters
264   TrackParam[i1] = *this;
265   // first extrapolation
266   (&(TrackParam[i1]))->ExtrapToZ(extZ[0]);
267   TrackParam[i2] = TrackParam[i1];
268   // second extrapolation
269   (&(TrackParam[i2]))->ExtrapToZ(extZ[1]);
270   return;
271 }
272
273   //__________________________________________________________________________
274 void AliMUONTrackParam::ExtrapToVertex()
275 {
276   // Extrapolation to the vertex.
277   // Returns the track parameters resulting from the extrapolation,
278   // in the current TrackParam.
279   // Changes parameters according to Branson correction through the absorber 
280   
281   Double_t zAbsorber = 503.0; // to be coherent with the Geant absorber geometry !!!!
282   // Extrapolates track parameters upstream to the "Z" end of the front absorber
283   ExtrapToZ(zAbsorber);
284     // Makes Branson correction (multiple scattering + energy loss)
285   BransonCorrection();
286 }
287
288   //__________________________________________________________________________
289 void AliMUONTrackParam::BransonCorrection()
290 {
291   // Branson correction of track parameters
292   // the entry parameters have to be calculated at the end of the absorber
293   Double_t zEndAbsorber, zBP, xBP, yBP;
294   Double_t  pYZ, pX, pY, pZ, pTotal, xEndAbsorber, yEndAbsorber, radiusEndAbsorber2, pT, theta;
295   Int_t sign;
296   // Would it be possible to calculate all that from Geant configuration ????
297   // and to get the Branson parameters from a function in ABSO module ????
298   // with an eventual contribution from other detectors like START ????
299   // Radiation lengths outer part theta > 3 degres
300   static Double_t x01[9] = { 18.8,    // C (cm)
301                              10.397,   // Concrete (cm)
302                              0.56,    // Plomb (cm)
303                              47.26,   // Polyethylene (cm)
304                              0.56,   // Plomb (cm)
305                              47.26,   // Polyethylene (cm)
306                              0.56,   // Plomb (cm)
307                              47.26,   // Polyethylene (cm)
308                              0.56 };   // Plomb (cm)
309   // inner part theta < 3 degres
310   static Double_t x02[3] = { 18.8,    // C (cm)
311                              10.397,   // Concrete (cm)
312                              0.35 };    // W (cm) 
313   // z positions of the materials inside the absober outer part theta > 3 degres
314   static Double_t z1[10] = { 90, 315, 467, 472, 477, 482, 487, 492, 497, 502 };
315   // inner part theta < 3 degres
316   static Double_t z2[4] = { 90, 315, 467, 503 };
317   static Bool_t first = kTRUE;
318   static Double_t zBP1, zBP2, rLimit;
319   // Calculates z positions of the Branson's planes: zBP1 for outer part and zBP2 for inner part (only at the first call)
320   if (first) {
321     first = kFALSE;
322     Double_t aNBP = 0.0;
323     Double_t aDBP = 0.0;
324     Int_t iBound;
325     
326     for (iBound = 0; iBound < 9; iBound++) {
327       aNBP = aNBP +
328         (z1[iBound+1] * z1[iBound+1] * z1[iBound+1] -
329          z1[iBound]   * z1[iBound]   * z1[iBound]    ) / x01[iBound];
330       aDBP = aDBP +
331         (z1[iBound+1] * z1[iBound+1] - z1[iBound]   * z1[iBound]    ) / x01[iBound];
332     }
333     zBP1 = (2.0 * aNBP) / (3.0 * aDBP);
334     aNBP = 0.0;
335     aDBP = 0.0;
336     for (iBound = 0; iBound < 3; iBound++) {
337       aNBP = aNBP +
338         (z2[iBound+1] * z2[iBound+1] * z2[iBound+1] -
339          z2[iBound]   * z2[iBound ]  * z2[iBound]    ) / x02[iBound];
340       aDBP = aDBP +
341         (z2[iBound+1] * z2[iBound+1] - z2[iBound] * z2[iBound]) / x02[iBound];
342     }
343     zBP2 = (2.0 * aNBP) / (3.0 * aDBP);
344     rLimit = z2[3] * TMath::Tan(3.0 * (TMath::Pi()) / 180.);
345   }
346
347   pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
348   sign = 1;      
349   if (fInverseBendingMomentum < 0) sign = -1;     
350   pZ = pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); 
351   pX = pZ * fNonBendingSlope; 
352   pY = pZ * fBendingSlope; 
353   pTotal = TMath::Sqrt(pYZ *pYZ + pX * pX);
354   xEndAbsorber = fNonBendingCoor; 
355   yEndAbsorber = fBendingCoor; 
356   radiusEndAbsorber2 = xEndAbsorber * xEndAbsorber + yEndAbsorber * yEndAbsorber;
357
358   if (radiusEndAbsorber2 > rLimit*rLimit) {
359     zEndAbsorber = z1[9];
360     zBP = zBP1;
361   } else {
362     zEndAbsorber = z2[3];
363     zBP = zBP2;
364   }
365
366   xBP = xEndAbsorber - (pX / pZ) * (zEndAbsorber - zBP);
367   yBP = yEndAbsorber - (pY / pZ) * (zEndAbsorber - zBP);
368
369   // new parameters after Branson and energy loss corrections
370   pZ = pTotal * zBP / TMath::Sqrt(xBP * xBP + yBP * yBP + zBP * zBP);
371   pX = pZ * xBP / zBP;
372   pY = pZ * yBP / zBP;
373   fBendingSlope = pY / pZ;
374   fNonBendingSlope = pX / pZ;
375   
376   pT = TMath::Sqrt(pX * pX + pY * pY);      
377   theta = TMath::ATan2(pT, pZ); 
378   pTotal =
379     TotalMomentumEnergyLoss(rLimit, pTotal, theta, xEndAbsorber, yEndAbsorber);
380
381   fInverseBendingMomentum = (sign / pTotal) *
382     TMath::Sqrt(1.0 +
383                 fBendingSlope * fBendingSlope +
384                 fNonBendingSlope * fNonBendingSlope) /
385     TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope);
386
387   // vertex position at (0,0,0)
388   // should be taken from vertex measurement ???
389   fBendingCoor = 0.0;
390   fNonBendingCoor = 0;
391   fZ= 0;
392 }
393
394   //__________________________________________________________________________
395 Double_t AliMUONTrackParam::TotalMomentumEnergyLoss(Double_t rLimit, Double_t pTotal, Double_t theta, Double_t xEndAbsorber, Double_t yEndAbsorber)
396 {
397   // Returns the total momentum corrected from energy loss in the front absorber
398   Double_t deltaP, pTotalCorrected;
399
400   Double_t radiusEndAbsorber2 =
401     xEndAbsorber *xEndAbsorber + yEndAbsorber * yEndAbsorber;
402   // Parametrization to be redone according to change of absorber material ????
403   // See remark in function BransonCorrection !!!!
404   // The name is not so good, and there are many arguments !!!!
405   if (radiusEndAbsorber2 < rLimit * rLimit) {
406     if (pTotal < 15) {
407       deltaP = 2.737 + 0.0494 * pTotal - 0.001123 * pTotal * pTotal;
408     } else {
409       deltaP = 3.0643 + 0.01346 *pTotal;
410     }
411   } else {
412     if (pTotal < 15) {
413       deltaP  = 2.1380 + 0.0351 * pTotal - 0.000853 * pTotal * pTotal;
414     } else { 
415       deltaP = 2.407 + 0.00702 * pTotal;
416     }
417   }
418   pTotalCorrected = pTotal + deltaP / TMath::Cos(theta);
419   return pTotalCorrected;
420 }
421