Line data Source code
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 : // Class AliMUONTrackExtrap
20 : // ------------------------
21 : // Tools for track extrapolation in ALICE dimuon spectrometer
22 : // Author: Philippe Pillot
23 : //-----------------------------------------------------------------------------
24 :
25 : #include "AliMUONTrackExtrap.h"
26 : #include "AliMUONTrackParam.h"
27 : #include "AliMUONConstants.h"
28 : #include "AliMUONReconstructor.h"
29 :
30 : #include "AliMagF.h"
31 : #include "AliExternalTrackParam.h"
32 :
33 : #include <TGeoGlobalMagField.h>
34 : #include <TGeoManager.h>
35 : #include <TMath.h>
36 : #include <TDatabasePDG.h>
37 :
38 : #include <Riostream.h>
39 :
40 : using std::endl;
41 : using std::cout;
42 : /// \cond CLASSIMP
43 18 : ClassImp(AliMUONTrackExtrap) // Class implementation in ROOT context
44 : /// \endcond
45 :
46 18 : const Double_t AliMUONTrackExtrap::fgkSimpleBPosition = 0.5 * (AliMUONConstants::CoilZ() + AliMUONConstants::YokeZ());
47 18 : const Double_t AliMUONTrackExtrap::fgkSimpleBLength = 0.5 * (AliMUONConstants::CoilL() + AliMUONConstants::YokeL());
48 : Double_t AliMUONTrackExtrap::fgSimpleBValue = 0.;
49 : Bool_t AliMUONTrackExtrap::fgFieldON = kFALSE;
50 : const Bool_t AliMUONTrackExtrap::fgkUseHelix = kFALSE;
51 : const Int_t AliMUONTrackExtrap::fgkMaxStepNumber = 5000;
52 : const Double_t AliMUONTrackExtrap::fgkHelixStepLength = 6.;
53 : const Double_t AliMUONTrackExtrap::fgkRungeKuttaMaxResidue = 0.002;
54 :
55 : //__________________________________________________________________________
56 : void AliMUONTrackExtrap::SetField()
57 : {
58 : /// set field on/off flag;
59 : /// set field at the centre of the dipole
60 8 : const Double_t x[3] = {50.,50.,fgkSimpleBPosition};
61 4 : Double_t b[3] = {0.,0.,0.};
62 4 : TGeoGlobalMagField::Instance()->Field(x,b);
63 4 : fgSimpleBValue = b[0];
64 4 : fgFieldON = (TMath::Abs(fgSimpleBValue) > 1.e-10) ? kTRUE : kFALSE;
65 :
66 4 : }
67 :
68 : //__________________________________________________________________________
69 : Double_t AliMUONTrackExtrap::GetImpactParamFromBendingMomentum(Double_t bendingMomentum)
70 : {
71 : /// Returns impact parameter at vertex in bending plane (cm),
72 : /// from the signed bending momentum "BendingMomentum" in bending plane (GeV/c),
73 : /// using simple values for dipole magnetic field.
74 : /// The sign of "BendingMomentum" is the sign of the charge.
75 :
76 0 : if (bendingMomentum == 0.) return 1.e10;
77 :
78 : const Double_t kCorrectionFactor = 1.1; // impact parameter is 10% underestimated
79 :
80 0 : return kCorrectionFactor * (-0.0003 * fgSimpleBValue * fgkSimpleBLength * fgkSimpleBPosition / bendingMomentum);
81 0 : }
82 :
83 : //__________________________________________________________________________
84 : Double_t
85 : AliMUONTrackExtrap::GetBendingMomentumFromImpactParam(Double_t impactParam)
86 : {
87 : /// Returns signed bending momentum in bending plane (GeV/c),
88 : /// the sign being the sign of the charge for particles moving forward in Z,
89 : /// from the impact parameter "ImpactParam" at vertex in bending plane (cm),
90 : /// using simple values for dipole magnetic field.
91 :
92 180 : if (impactParam == 0.) return 1.e10;
93 :
94 : const Double_t kCorrectionFactor = 1.1; // bending momentum is 10% underestimated
95 :
96 90 : if (fgFieldON)
97 : {
98 90 : return kCorrectionFactor * (-0.0003 * fgSimpleBValue * fgkSimpleBLength * fgkSimpleBPosition / impactParam);
99 : }
100 : else
101 : {
102 0 : return AliMUONConstants::GetMostProbBendingMomentum();
103 : }
104 90 : }
105 :
106 : //__________________________________________________________________________
107 : void AliMUONTrackExtrap::LinearExtrapToZ(AliMUONTrackParam* trackParam, Double_t zEnd)
108 : {
109 : /// Track parameters linearly extrapolated to the plane at "zEnd".
110 : /// On return, results from the extrapolation are updated in trackParam.
111 :
112 928 : if (trackParam->GetZ() == zEnd) return; // nothing to be done if same z
113 :
114 : // Compute track parameters
115 434 : Double_t dZ = zEnd - trackParam->GetZ();
116 434 : trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + trackParam->GetNonBendingSlope() * dZ);
117 434 : trackParam->SetBendingCoor(trackParam->GetBendingCoor() + trackParam->GetBendingSlope() * dZ);
118 434 : trackParam->SetZ(zEnd);
119 898 : }
120 :
121 : //__________________________________________________________________________
122 : void AliMUONTrackExtrap::LinearExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zEnd, Bool_t updatePropagator)
123 : {
124 : /// Track parameters and their covariances linearly extrapolated to the plane at "zEnd".
125 : /// On return, results from the extrapolation are updated in trackParam.
126 :
127 418 : if (trackParam->GetZ() == zEnd) return; // nothing to be done if same z
128 :
129 : // No need to propagate the covariance matrix if it does not exist
130 384 : if (!trackParam->CovariancesExist()) {
131 0 : cout<<"W-AliMUONTrackExtrap::LinearExtrapToZCov: Covariance matrix does not exist"<<endl;
132 : // Extrapolate linearly track parameters to "zEnd"
133 0 : LinearExtrapToZ(trackParam,zEnd);
134 0 : return;
135 : }
136 :
137 : // Compute track parameters
138 384 : Double_t dZ = zEnd - trackParam->GetZ();
139 384 : trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + trackParam->GetNonBendingSlope() * dZ);
140 384 : trackParam->SetBendingCoor(trackParam->GetBendingCoor() + trackParam->GetBendingSlope() * dZ);
141 384 : trackParam->SetZ(zEnd);
142 :
143 : // Calculate the jacobian related to the track parameters linear extrapolation to "zEnd"
144 384 : TMatrixD jacob(5,5);
145 384 : jacob.UnitMatrix();
146 768 : jacob(0,1) = dZ;
147 768 : jacob(2,3) = dZ;
148 :
149 : // Extrapolate track parameter covariances to "zEnd"
150 768 : TMatrixD tmp(trackParam->GetCovariances(),TMatrixD::kMultTranspose,jacob);
151 384 : TMatrixD tmp2(jacob,TMatrixD::kMult,tmp);
152 384 : trackParam->SetCovariances(tmp2);
153 :
154 : // Update the propagator if required
155 384 : if (updatePropagator) trackParam->UpdatePropagator(jacob);
156 802 : }
157 :
158 : //__________________________________________________________________________
159 : Bool_t AliMUONTrackExtrap::ExtrapToZ(AliMUONTrackParam* trackParam, Double_t zEnd)
160 : {
161 : /// Interface to track parameter extrapolation to the plane at "Z" using Helix or Rungekutta algorithm.
162 : /// On return, the track parameters resulting from the extrapolation are updated in trackParam.
163 8460 : if (!fgFieldON) {
164 0 : AliMUONTrackExtrap::LinearExtrapToZ(trackParam,zEnd);
165 0 : return kTRUE;
166 : }
167 : else if (fgkUseHelix) return AliMUONTrackExtrap::ExtrapToZHelix(trackParam,zEnd);
168 4230 : else return AliMUONTrackExtrap::ExtrapToZRungekutta(trackParam,zEnd);
169 4230 : }
170 :
171 : //__________________________________________________________________________
172 : Bool_t AliMUONTrackExtrap::ExtrapToZHelix(AliMUONTrackParam* trackParam, Double_t zEnd)
173 : {
174 : /// Track parameter extrapolation to the plane at "Z" using Helix algorithm.
175 : /// On return, the track parameters resulting from the extrapolation are updated in trackParam.
176 0 : if (trackParam->GetZ() == zEnd) return kTRUE; // nothing to be done if same Z
177 : Double_t forwardBackward; // +1 if forward, -1 if backward
178 0 : if (zEnd < trackParam->GetZ()) forwardBackward = 1.0; // spectro. z<0
179 : else forwardBackward = -1.0;
180 0 : Double_t v3[7], v3New[7]; // 7 in parameter ????
181 : Int_t i3, stepNumber;
182 : // For safety: return kTRUE or kFALSE ????
183 : // Parameter vector for calling EXTRAP_ONESTEP
184 0 : ConvertTrackParamForExtrap(trackParam, forwardBackward, v3);
185 : // sign of charge (sign of fInverseBendingMomentum if forward motion)
186 : // must be changed if backward extrapolation
187 0 : Double_t chargeExtrap = forwardBackward * TMath::Sign(Double_t(1.0), trackParam->GetInverseBendingMomentum());
188 : // Extrapolation loop
189 : stepNumber = 0;
190 0 : while (((-forwardBackward * (v3[2] - zEnd)) <= 0.0) && (stepNumber < fgkMaxStepNumber)) { // spectro. z<0
191 0 : stepNumber++;
192 0 : ExtrapOneStepHelix(chargeExtrap, fgkHelixStepLength, v3, v3New);
193 0 : if ((-forwardBackward * (v3New[2] - zEnd)) > 0.0) break; // one is beyond Z spectro. z<0
194 : // better use TArray ????
195 0 : for (i3 = 0; i3 < 7; i3++) {v3[i3] = v3New[i3];}
196 : }
197 : // check fgkMaxStepNumber ????
198 : // Interpolation back to exact Z (2nd order)
199 : // should be in function ???? using TArray ????
200 0 : Double_t dZ12 = v3New[2] - v3[2]; // 1->2
201 0 : if (TMath::Abs(dZ12) > 0) {
202 0 : Double_t dZ1i = zEnd - v3[2]; // 1-i
203 0 : Double_t dZi2 = v3New[2] - zEnd; // i->2
204 0 : Double_t xPrime = (v3New[0] - v3[0]) / dZ12;
205 0 : Double_t xSecond = ((v3New[3] / v3New[5]) - (v3[3] / v3[5])) / dZ12;
206 0 : Double_t yPrime = (v3New[1] - v3[1]) / dZ12;
207 0 : Double_t ySecond = ((v3New[4] / v3New[5]) - (v3[4] / v3[5])) / dZ12;
208 0 : v3[0] = v3[0] + xPrime * dZ1i - 0.5 * xSecond * dZ1i * dZi2; // X
209 0 : v3[1] = v3[1] + yPrime * dZ1i - 0.5 * ySecond * dZ1i * dZi2; // Y
210 0 : v3[2] = zEnd; // Z
211 0 : Double_t xPrimeI = xPrime - 0.5 * xSecond * (dZi2 - dZ1i);
212 0 : Double_t yPrimeI = yPrime - 0.5 * ySecond * (dZi2 - dZ1i);
213 : // (PX, PY, PZ)/PTOT assuming forward motion
214 0 : v3[5] = 1.0 / TMath::Sqrt(1.0 + xPrimeI * xPrimeI + yPrimeI * yPrimeI); // PZ/PTOT
215 0 : v3[3] = xPrimeI * v3[5]; // PX/PTOT
216 0 : v3[4] = yPrimeI * v3[5]; // PY/PTOT
217 0 : } else {
218 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToZHelix: Extrap. to Z not reached, Z = "<<zEnd<<endl;
219 : }
220 : // Recover track parameters (charge back for forward motion)
221 0 : RecoverTrackParam(v3, chargeExtrap * forwardBackward, trackParam);
222 : return kTRUE;
223 0 : }
224 :
225 : //__________________________________________________________________________
226 : Bool_t AliMUONTrackExtrap::ExtrapToZRungekutta(AliMUONTrackParam* trackParam, Double_t zEnd)
227 : {
228 : /// Track parameter extrapolation to the plane at "Z" using Rungekutta algorithm.
229 : /// On return, the track parameters resulting from the extrapolation are updated in trackParam.
230 8460 : if (trackParam->GetZ() == zEnd) return kTRUE; // nothing to be done if same Z
231 : Double_t forwardBackward; // +1 if forward, -1 if backward
232 5350 : if (zEnd < trackParam->GetZ()) forwardBackward = 1.0; // spectro. z<0
233 : else forwardBackward = -1.0;
234 : // sign of charge (sign of fInverseBendingMomentum if forward motion)
235 : // must be changed if backward extrapolation
236 4230 : Double_t chargeExtrap = forwardBackward * TMath::Sign(Double_t(1.0), trackParam->GetInverseBendingMomentum());
237 4230 : Double_t v3[7], v3New[7];
238 : Double_t dZ, step;
239 : Int_t stepNumber = 0;
240 :
241 : // Extrapolation loop (until within tolerance or the track turn around)
242 4230 : Double_t residue = zEnd - trackParam->GetZ();
243 : Bool_t uturn = kFALSE;
244 : Bool_t trackingFailed = kFALSE;
245 : Bool_t tooManyStep = kFALSE;
246 17644 : while (TMath::Abs(residue) > fgkRungeKuttaMaxResidue && stepNumber <= fgkMaxStepNumber) {
247 :
248 4592 : dZ = zEnd - trackParam->GetZ();
249 : // step lenght assuming linear trajectory
250 9184 : step = dZ * TMath::Sqrt(1.0 + trackParam->GetBendingSlope()*trackParam->GetBendingSlope() +
251 4592 : trackParam->GetNonBendingSlope()*trackParam->GetNonBendingSlope());
252 4592 : ConvertTrackParamForExtrap(trackParam, forwardBackward, v3);
253 :
254 4592 : do { // reduce step lenght while zEnd oversteped
255 5018 : if (stepNumber > fgkMaxStepNumber) {
256 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToZRungekutta: Too many trials: "<<stepNumber<<endl;
257 : tooManyStep = kTRUE;
258 0 : break;
259 : }
260 5018 : stepNumber ++;
261 5018 : step = TMath::Abs(step);
262 5018 : if (!AliMUONTrackExtrap::ExtrapOneStepRungekutta(chargeExtrap,step,v3,v3New)) {
263 : trackingFailed = kTRUE;
264 0 : break;
265 : }
266 5018 : residue = zEnd - v3New[2];
267 5018 : step *= dZ/(v3New[2]-trackParam->GetZ());
268 6946 : } while (residue*dZ < 0 && TMath::Abs(residue) > fgkRungeKuttaMaxResidue);
269 :
270 4592 : if (trackingFailed) break;
271 4592 : else if (v3New[5]*v3[5] < 0) { // the track turned around
272 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToZRungekutta: The track turned around"<<endl;
273 : uturn = kTRUE;
274 0 : break;
275 4592 : } else RecoverTrackParam(v3New, chargeExtrap * forwardBackward, trackParam);
276 :
277 : }
278 :
279 : // terminate the extropolation with a straight line up to the exact "zEnd" value
280 8460 : if (trackingFailed || uturn) {
281 :
282 : // track ends +-100 meters away in the bending direction
283 0 : dZ = zEnd - v3[2];
284 0 : Double_t bendingSlope = TMath::Sign(1.e4,-fgSimpleBValue*trackParam->GetInverseBendingMomentum()) / dZ;
285 0 : Double_t pZ = TMath::Abs(1. / trackParam->GetInverseBendingMomentum()) / TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
286 0 : Double_t nonBendingSlope = TMath::Sign(TMath::Abs(v3[3]) * v3[6] / pZ, trackParam->GetNonBendingSlope());
287 0 : trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + dZ * nonBendingSlope);
288 0 : trackParam->SetNonBendingSlope(nonBendingSlope);
289 0 : trackParam->SetBendingCoor(trackParam->GetBendingCoor() + dZ * bendingSlope);
290 0 : trackParam->SetBendingSlope(bendingSlope);
291 0 : trackParam->SetZ(zEnd);
292 :
293 : return kFALSE;
294 :
295 : } else {
296 :
297 : // track extrapolated normally
298 4230 : trackParam->SetNonBendingCoor(trackParam->GetNonBendingCoor() + residue * trackParam->GetNonBendingSlope());
299 4230 : trackParam->SetBendingCoor(trackParam->GetBendingCoor() + residue * trackParam->GetBendingSlope());
300 4230 : trackParam->SetZ(zEnd);
301 :
302 4230 : return !tooManyStep;
303 :
304 : }
305 :
306 8460 : }
307 :
308 : //__________________________________________________________________________
309 : void AliMUONTrackExtrap::ConvertTrackParamForExtrap(AliMUONTrackParam* trackParam, Double_t forwardBackward, Double_t *v3)
310 : {
311 : /// Set vector of Geant3 parameters pointed to by "v3" from track parameters in trackParam.
312 : /// Since AliMUONTrackParam is only geometry, one uses "forwardBackward"
313 : /// to know whether the particle is going forward (+1) or backward (-1).
314 9184 : v3[0] = trackParam->GetNonBendingCoor(); // X
315 4592 : v3[1] = trackParam->GetBendingCoor(); // Y
316 4592 : v3[2] = trackParam->GetZ(); // Z
317 4592 : Double_t pYZ = TMath::Abs(1.0 / trackParam->GetInverseBendingMomentum());
318 4592 : Double_t pZ = pYZ / TMath::Sqrt(1.0 + trackParam->GetBendingSlope() * trackParam->GetBendingSlope());
319 4592 : v3[6] = TMath::Sqrt(pYZ * pYZ + pZ * pZ * trackParam->GetNonBendingSlope() * trackParam->GetNonBendingSlope()); // PTOT
320 4592 : v3[5] = -forwardBackward * pZ / v3[6]; // PZ/PTOT spectro. z<0
321 4592 : v3[3] = trackParam->GetNonBendingSlope() * v3[5]; // PX/PTOT
322 4592 : v3[4] = trackParam->GetBendingSlope() * v3[5]; // PY/PTOT
323 4592 : }
324 :
325 : //__________________________________________________________________________
326 : void AliMUONTrackExtrap::RecoverTrackParam(Double_t *v3, Double_t charge, AliMUONTrackParam* trackParam)
327 : {
328 : /// Set track parameters in trackParam from Geant3 parameters pointed to by "v3",
329 : /// assumed to be calculated for forward motion in Z.
330 : /// "InverseBendingMomentum" is signed with "charge".
331 9184 : trackParam->SetNonBendingCoor(v3[0]); // X
332 4592 : trackParam->SetBendingCoor(v3[1]); // Y
333 4592 : trackParam->SetZ(v3[2]); // Z
334 4592 : Double_t pYZ = v3[6] * TMath::Sqrt((1.-v3[3])*(1.+v3[3]));
335 4592 : trackParam->SetInverseBendingMomentum(charge/pYZ);
336 4592 : trackParam->SetBendingSlope(v3[4]/v3[5]);
337 4592 : trackParam->SetNonBendingSlope(v3[3]/v3[5]);
338 4592 : }
339 :
340 : //__________________________________________________________________________
341 : Bool_t AliMUONTrackExtrap::ExtrapToZCov(AliMUONTrackParam* trackParam, Double_t zEnd, Bool_t updatePropagator)
342 : {
343 : /// Track parameters and their covariances extrapolated to the plane at "zEnd".
344 : /// On return, results from the extrapolation are updated in trackParam.
345 :
346 684 : if (trackParam->GetZ() == zEnd) return kTRUE; // nothing to be done if same z
347 :
348 684 : if (!fgFieldON) { // linear extrapolation if no magnetic field
349 0 : AliMUONTrackExtrap::LinearExtrapToZCov(trackParam,zEnd,updatePropagator);
350 0 : return kTRUE;
351 : }
352 :
353 : // No need to propagate the covariance matrix if it does not exist
354 684 : if (!trackParam->CovariancesExist()) {
355 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToZCov: Covariance matrix does not exist"<<endl;
356 : // Extrapolate track parameters to "zEnd"
357 0 : return ExtrapToZ(trackParam,zEnd);
358 : }
359 :
360 : // Save the actual track parameters
361 684 : AliMUONTrackParam trackParamSave(*trackParam);
362 684 : TMatrixD paramSave(trackParamSave.GetParameters());
363 684 : Double_t zBegin = trackParamSave.GetZ();
364 :
365 : // Get reference to the parameter covariance matrix
366 684 : const TMatrixD& kParamCov = trackParam->GetCovariances();
367 :
368 : // Extrapolate track parameters to "zEnd"
369 : // Do not update the covariance matrix if the extrapolation failed
370 1368 : if (!ExtrapToZ(trackParam,zEnd)) return kFALSE;
371 :
372 : // Get reference to the extrapolated parameters
373 684 : const TMatrixD& extrapParam = trackParam->GetParameters();
374 :
375 : // Calculate the jacobian related to the track parameters extrapolation to "zEnd"
376 : Bool_t extrapStatus = kTRUE;
377 684 : TMatrixD jacob(5,5);
378 684 : jacob.Zero();
379 684 : TMatrixD dParam(5,1);
380 684 : Double_t direction[5] = {-1.,-1.,1.,1.,-1.};
381 8208 : for (Int_t i=0; i<5; i++) {
382 : // Skip jacobian calculation for parameters with no associated error
383 6840 : if (kParamCov(i,i) <= 0.) continue;
384 :
385 : // Small variation of parameter i only
386 41040 : for (Int_t j=0; j<5; j++) {
387 17100 : if (j==i) {
388 10260 : dParam(j,0) = TMath::Sqrt(kParamCov(i,i));
389 10260 : dParam(j,0) *= TMath::Sign(1.,direction[j]*paramSave(j,0)); // variation always in the same direction
390 30780 : } else dParam(j,0) = 0.;
391 : }
392 :
393 : // Set new parameters
394 3420 : trackParamSave.SetParameters(paramSave);
395 3420 : trackParamSave.AddParameters(dParam);
396 3420 : trackParamSave.SetZ(zBegin);
397 :
398 : // Extrapolate new track parameters to "zEnd"
399 6840 : if (!ExtrapToZ(&trackParamSave,zEnd)) {
400 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToZCov: Bad covariance matrix"<<endl;
401 : extrapStatus = kFALSE;
402 0 : }
403 :
404 : // Calculate the jacobian
405 3420 : TMatrixD jacobji(trackParamSave.GetParameters(),TMatrixD::kMinus,extrapParam);
406 6840 : jacobji *= 1. / dParam(i,0);
407 3420 : jacob.SetSub(0,i,jacobji);
408 3420 : }
409 :
410 : // Extrapolate track parameter covariances to "zEnd"
411 684 : TMatrixD tmp(kParamCov,TMatrixD::kMultTranspose,jacob);
412 684 : TMatrixD tmp2(jacob,TMatrixD::kMult,tmp);
413 684 : trackParam->SetCovariances(tmp2);
414 :
415 : // Update the propagator if required
416 1248 : if (updatePropagator) trackParam->UpdatePropagator(jacob);
417 :
418 684 : return extrapStatus;
419 2052 : }
420 :
421 : //__________________________________________________________________________
422 : void AliMUONTrackExtrap::AddMCSEffectInAbsorber(AliMUONTrackParam* param, Double_t signedPathLength, Double_t f0, Double_t f1, Double_t f2)
423 : {
424 : /// Add to the track parameter covariances the effects of multiple Coulomb scattering
425 : /// signedPathLength must have the sign of (zOut - zIn) where all other parameters are assumed to be given at zOut.
426 :
427 : // absorber related covariance parameters
428 64 : Double_t bendingSlope = param->GetBendingSlope();
429 32 : Double_t nonBendingSlope = param->GetNonBendingSlope();
430 32 : Double_t inverseBendingMomentum = param->GetInverseBendingMomentum();
431 64 : Double_t alpha2 = 0.0136 * 0.0136 * inverseBendingMomentum * inverseBendingMomentum * (1.0 + bendingSlope * bendingSlope) /
432 32 : (1.0 + bendingSlope *bendingSlope + nonBendingSlope * nonBendingSlope); // velocity = 1
433 32 : Double_t pathLength = TMath::Abs(signedPathLength);
434 32 : Double_t varCoor = alpha2 * (pathLength * pathLength * f0 - 2. * pathLength * f1 + f2);
435 32 : Double_t covCorrSlope = TMath::Sign(1.,signedPathLength) * alpha2 * (pathLength * f0 - f1);
436 32 : Double_t varSlop = alpha2 * f0;
437 :
438 : // Set MCS covariance matrix
439 32 : TMatrixD newParamCov(param->GetCovariances());
440 : // Non bending plane
441 96 : newParamCov(0,0) += varCoor; newParamCov(0,1) += covCorrSlope;
442 96 : newParamCov(1,0) += covCorrSlope; newParamCov(1,1) += varSlop;
443 : // Bending plane
444 96 : newParamCov(2,2) += varCoor; newParamCov(2,3) += covCorrSlope;
445 96 : newParamCov(3,2) += covCorrSlope; newParamCov(3,3) += varSlop;
446 :
447 : // Set momentum related covariances if B!=0
448 32 : if (fgFieldON) {
449 : // compute derivative d(q/Pxy) / dSlopeX and d(q/Pxy) / dSlopeY
450 32 : Double_t dqPxydSlopeX = inverseBendingMomentum * nonBendingSlope / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
451 32 : Double_t dqPxydSlopeY = - inverseBendingMomentum * nonBendingSlope*nonBendingSlope * bendingSlope /
452 32 : (1. + bendingSlope*bendingSlope) / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
453 : // Inverse bending momentum (due to dependences with bending and non bending slopes)
454 96 : newParamCov(4,0) += dqPxydSlopeX * covCorrSlope; newParamCov(0,4) += dqPxydSlopeX * covCorrSlope;
455 96 : newParamCov(4,1) += dqPxydSlopeX * varSlop; newParamCov(1,4) += dqPxydSlopeX * varSlop;
456 96 : newParamCov(4,2) += dqPxydSlopeY * covCorrSlope; newParamCov(2,4) += dqPxydSlopeY * covCorrSlope;
457 96 : newParamCov(4,3) += dqPxydSlopeY * varSlop; newParamCov(3,4) += dqPxydSlopeY * varSlop;
458 64 : newParamCov(4,4) += (dqPxydSlopeX*dqPxydSlopeX + dqPxydSlopeY*dqPxydSlopeY) * varSlop;
459 32 : }
460 :
461 : // Set new covariances
462 32 : param->SetCovariances(newParamCov);
463 32 : }
464 :
465 : //__________________________________________________________________________
466 : void AliMUONTrackExtrap::CorrectMCSEffectInAbsorber(AliMUONTrackParam* param,
467 : Double_t xVtx, Double_t yVtx, Double_t zVtx,
468 : Double_t errXVtx, Double_t errYVtx,
469 : Double_t absZBeg, Double_t pathLength, Double_t f0, Double_t f1, Double_t f2)
470 : {
471 : /// Correct parameters and corresponding covariances using Branson correction
472 : /// - input param are parameters and covariances at the end of absorber
473 : /// - output param are parameters and covariances at vertex
474 : /// Absorber correction parameters are supposed to be calculated at the current track z-position
475 :
476 : // Position of the Branson plane (spectro. (z<0))
477 64 : Double_t zB = (f1>0.) ? absZBeg - f2/f1 : 0.;
478 :
479 : // Add MCS effects to current parameter covariances (spectro. (z<0))
480 16 : AddMCSEffectInAbsorber(param, -pathLength, f0, f1, f2);
481 :
482 : // Get track parameters and covariances in the Branson plane corrected for magnetic field effect
483 16 : ExtrapToZCov(param,zVtx);
484 16 : LinearExtrapToZCov(param,zB);
485 :
486 : // compute track parameters at vertex
487 16 : TMatrixD newParam(5,1);
488 32 : newParam(0,0) = xVtx;
489 48 : newParam(1,0) = (param->GetNonBendingCoor() - xVtx) / (zB - zVtx);
490 32 : newParam(2,0) = yVtx;
491 48 : newParam(3,0) = (param->GetBendingCoor() - yVtx) / (zB - zVtx);
492 96 : newParam(4,0) = param->GetCharge() / param->P() *
493 96 : TMath::Sqrt(1.0 + newParam(1,0)*newParam(1,0) + newParam(3,0)*newParam(3,0)) /
494 48 : TMath::Sqrt(1.0 + newParam(3,0)*newParam(3,0));
495 :
496 : // Get covariances in (X, SlopeX, Y, SlopeY, q*PTot) coordinate system
497 32 : TMatrixD paramCovP(param->GetCovariances());
498 16 : Cov2CovP(param->GetParameters(),paramCovP);
499 :
500 : // Get the covariance matrix in the (XVtx, X, YVtx, Y, q*PTot) coordinate system
501 16 : TMatrixD paramCovVtx(5,5);
502 16 : paramCovVtx.Zero();
503 32 : paramCovVtx(0,0) = errXVtx * errXVtx;
504 48 : paramCovVtx(1,1) = paramCovP(0,0);
505 32 : paramCovVtx(2,2) = errYVtx * errYVtx;
506 48 : paramCovVtx(3,3) = paramCovP(2,2);
507 48 : paramCovVtx(4,4) = paramCovP(4,4);
508 48 : paramCovVtx(1,3) = paramCovP(0,2);
509 48 : paramCovVtx(3,1) = paramCovP(2,0);
510 48 : paramCovVtx(1,4) = paramCovP(0,4);
511 48 : paramCovVtx(4,1) = paramCovP(4,0);
512 48 : paramCovVtx(3,4) = paramCovP(2,4);
513 48 : paramCovVtx(4,3) = paramCovP(4,2);
514 :
515 : // Jacobian of the transformation (XVtx, X, YVtx, Y, q*PTot) -> (XVtx, SlopeXVtx, YVtx, SlopeYVtx, q*PTotVtx)
516 16 : TMatrixD jacob(5,5);
517 16 : jacob.UnitMatrix();
518 32 : jacob(1,0) = - 1. / (zB - zVtx);
519 32 : jacob(1,1) = 1. / (zB - zVtx);
520 32 : jacob(3,2) = - 1. / (zB - zVtx);
521 32 : jacob(3,3) = 1. / (zB - zVtx);
522 :
523 : // Compute covariances at vertex in the (XVtx, SlopeXVtx, YVtx, SlopeYVtx, q*PTotVtx) coordinate system
524 16 : TMatrixD tmp(paramCovVtx,TMatrixD::kMultTranspose,jacob);
525 16 : TMatrixD newParamCov(jacob,TMatrixD::kMult,tmp);
526 :
527 : // Compute covariances at vertex in the (XVtx, SlopeXVtx, YVtx, SlopeYVtx, q/PyzVtx) coordinate system
528 16 : CovP2Cov(newParam,newParamCov);
529 :
530 : // Set parameters and covariances at vertex
531 16 : param->SetParameters(newParam);
532 16 : param->SetZ(zVtx);
533 16 : param->SetCovariances(newParamCov);
534 16 : }
535 :
536 : //__________________________________________________________________________
537 : void AliMUONTrackExtrap::CorrectELossEffectInAbsorber(AliMUONTrackParam* param, Double_t eLoss, Double_t sigmaELoss2)
538 : {
539 : /// Correct parameters for energy loss and add energy loss fluctuation effect to covariances
540 :
541 : // Get parameter covariances in (X, SlopeX, Y, SlopeY, q*PTot) coordinate system
542 128 : TMatrixD newParamCov(param->GetCovariances());
543 64 : Cov2CovP(param->GetParameters(),newParamCov);
544 :
545 : // Compute new parameters corrected for energy loss
546 192 : Double_t muMass = TDatabasePDG::Instance()->GetParticle("mu-")->Mass(); // GeV
547 64 : Double_t p = param->P();
548 64 : Double_t e = TMath::Sqrt(p*p + muMass*muMass);
549 64 : Double_t eCorr = e + eLoss;
550 64 : Double_t pCorr = TMath::Sqrt(eCorr*eCorr - muMass*muMass);
551 64 : Double_t nonBendingSlope = param->GetNonBendingSlope();
552 64 : Double_t bendingSlope = param->GetBendingSlope();
553 256 : param->SetInverseBendingMomentum(param->GetCharge() / pCorr *
554 128 : TMath::Sqrt(1.0 + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope) /
555 64 : TMath::Sqrt(1.0 + bendingSlope*bendingSlope));
556 :
557 : // Add effects of energy loss fluctuation to covariances
558 128 : newParamCov(4,4) += eCorr * eCorr / pCorr / pCorr * sigmaELoss2;
559 :
560 : // Get new parameter covariances in (X, SlopeX, Y, SlopeY, q/Pyz) coordinate system
561 64 : CovP2Cov(param->GetParameters(),newParamCov);
562 :
563 : // Set new parameter covariances
564 64 : param->SetCovariances(newParamCov);
565 64 : }
566 :
567 : //__________________________________________________________________________
568 : Bool_t AliMUONTrackExtrap::GetAbsorberCorrectionParam(Double_t trackXYZIn[3], Double_t trackXYZOut[3], Double_t pTotal,
569 : Double_t &pathLength, Double_t &f0, Double_t &f1, Double_t &f2,
570 : Double_t &meanRho, Double_t &totalELoss, Double_t &sigmaELoss2)
571 : {
572 : /// Parameters used to correct for Multiple Coulomb Scattering and energy loss in absorber
573 : /// Calculated assuming a linear propagation from trackXYZIn to trackXYZOut (order is important)
574 : // pathLength: path length between trackXYZIn and trackXYZOut (cm)
575 : // f0: 0th moment of z calculated with the inverse radiation-length distribution
576 : // f1: 1st moment of z calculated with the inverse radiation-length distribution
577 : // f2: 2nd moment of z calculated with the inverse radiation-length distribution
578 : // meanRho: average density of crossed material (g/cm3)
579 : // totalELoss: total energy loss in absorber
580 :
581 : // Reset absorber's parameters
582 64 : pathLength = 0.;
583 32 : f0 = 0.;
584 32 : f1 = 0.;
585 32 : f2 = 0.;
586 32 : meanRho = 0.;
587 32 : totalELoss = 0.;
588 32 : sigmaELoss2 = 0.;
589 :
590 : // Check whether the geometry is available
591 32 : if (!gGeoManager) {
592 0 : cout<<"E-AliMUONTrackExtrap::GetAbsorberCorrectionParam: no TGeo"<<endl;
593 0 : return kFALSE;
594 : }
595 :
596 : // Initialize starting point and direction
597 96 : pathLength = TMath::Sqrt((trackXYZOut[0] - trackXYZIn[0])*(trackXYZOut[0] - trackXYZIn[0])+
598 64 : (trackXYZOut[1] - trackXYZIn[1])*(trackXYZOut[1] - trackXYZIn[1])+
599 32 : (trackXYZOut[2] - trackXYZIn[2])*(trackXYZOut[2] - trackXYZIn[2]));
600 32 : if (pathLength < TGeoShape::Tolerance()) return kFALSE;
601 32 : Double_t b[3];
602 32 : b[0] = (trackXYZOut[0] - trackXYZIn[0]) / pathLength;
603 32 : b[1] = (trackXYZOut[1] - trackXYZIn[1]) / pathLength;
604 32 : b[2] = (trackXYZOut[2] - trackXYZIn[2]) / pathLength;
605 32 : TGeoNode *currentnode = gGeoManager->InitTrack(trackXYZIn, b);
606 32 : if (!currentnode) {
607 0 : cout<<"E-AliMUONTrackExtrap::GetAbsorberCorrectionParam: start point out of geometry"<<endl;
608 0 : return kFALSE;
609 : }
610 :
611 : // loop over absorber slices and calculate absorber's parameters
612 : Double_t rho = 0.; // material density (g/cm3)
613 : Double_t x0 = 0.; // radiation-length (cm-1)
614 : Double_t atomicA = 0.; // A of material
615 : Double_t atomicZ = 0.; // Z of material
616 : Double_t atomicZoverA = 0.; // Z/A of material
617 : Double_t localPathLength = 0;
618 32 : Double_t remainingPathLength = pathLength;
619 : Double_t sigmaELoss = 0.;
620 32 : Double_t zB = trackXYZIn[2];
621 : Double_t zE, dzB, dzE;
622 32 : do {
623 : // Get material properties
624 284 : TGeoMaterial *material = currentnode->GetVolume()->GetMedium()->GetMaterial();
625 284 : rho = material->GetDensity();
626 284 : x0 = material->GetRadLen();
627 284 : atomicA = material->GetA();
628 284 : atomicZ = material->GetZ();
629 284 : if(material->IsMixture()){
630 186 : TGeoMixture * mixture = (TGeoMixture*)material;
631 : atomicZoverA = 0.;
632 : Double_t sum = 0.;
633 2244 : for (Int_t iel=0;iel<mixture->GetNelements();iel++){
634 936 : sum += mixture->GetWmixt()[iel];
635 936 : atomicZoverA += mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
636 : }
637 186 : atomicZoverA/=sum;
638 186 : }
639 98 : else atomicZoverA = atomicZ/atomicA;
640 :
641 : // Get path length within this material
642 284 : gGeoManager->FindNextBoundary(remainingPathLength);
643 284 : localPathLength = gGeoManager->GetStep() + 1.e-6;
644 : // Check if boundary within remaining path length. If so, make sure to cross the boundary to prepare the next step
645 316 : if (localPathLength >= remainingPathLength) localPathLength = remainingPathLength;
646 : else {
647 252 : currentnode = gGeoManager->Step();
648 252 : if (!currentnode) {
649 0 : cout<<"E-AliMUONTrackExtrap::GetAbsorberCorrectionParam: navigation failed"<<endl;
650 0 : f0 = f1 = f2 = meanRho = totalELoss = sigmaELoss2 = 0.;
651 0 : return kFALSE;
652 : }
653 252 : if (!gGeoManager->IsEntering()) {
654 : // make another small step to try to enter in new absorber slice
655 0 : gGeoManager->SetStep(0.001);
656 0 : currentnode = gGeoManager->Step();
657 0 : if (!gGeoManager->IsEntering() || !currentnode) {
658 0 : cout<<"E-AliMUONTrackExtrap::GetAbsorberCorrectionParam: navigation failed"<<endl;
659 0 : f0 = f1 = f2 = meanRho = totalELoss = sigmaELoss2 = 0.;
660 0 : return kFALSE;
661 : }
662 0 : localPathLength += 0.001;
663 0 : }
664 : }
665 :
666 : // calculate absorber's parameters
667 284 : zE = b[2] * localPathLength + zB;
668 284 : dzB = zB - trackXYZIn[2];
669 284 : dzE = zE - trackXYZIn[2];
670 284 : f0 += localPathLength / x0;
671 284 : f1 += (dzE*dzE - dzB*dzB) / b[2] / b[2] / x0 / 2.;
672 284 : f2 += (dzE*dzE*dzE - dzB*dzB*dzB) / b[2] / b[2] / b[2] / x0 / 3.;
673 284 : meanRho += localPathLength * rho;
674 284 : totalELoss += BetheBloch(pTotal, localPathLength, rho, atomicZ, atomicZoverA);
675 284 : sigmaELoss += EnergyLossFluctuation(pTotal, localPathLength, rho, atomicZoverA);
676 :
677 : // prepare next step
678 : zB = zE;
679 284 : remainingPathLength -= localPathLength;
680 568 : } while (remainingPathLength > TGeoShape::Tolerance());
681 :
682 32 : meanRho /= pathLength;
683 32 : sigmaELoss2 = sigmaELoss*sigmaELoss;
684 :
685 32 : return kTRUE;
686 64 : }
687 :
688 : //__________________________________________________________________________
689 : Double_t AliMUONTrackExtrap::GetMCSAngle2(const AliMUONTrackParam& param, Double_t dZ, Double_t x0)
690 : {
691 : /// Return the angular dispersion square due to multiple Coulomb scattering
692 : /// through a material of thickness "dZ" and of radiation length "x0"
693 : /// assuming linear propagation and using the small angle approximation.
694 :
695 860 : Double_t bendingSlope = param.GetBendingSlope();
696 430 : Double_t nonBendingSlope = param.GetNonBendingSlope();
697 860 : Double_t inverseTotalMomentum2 = param.GetInverseBendingMomentum() * param.GetInverseBendingMomentum() *
698 860 : (1.0 + bendingSlope * bendingSlope) /
699 430 : (1.0 + bendingSlope *bendingSlope + nonBendingSlope * nonBendingSlope);
700 : // Path length in the material
701 430 : Double_t pathLength = TMath::Abs(dZ) * TMath::Sqrt(1.0 + bendingSlope*bendingSlope + nonBendingSlope*nonBendingSlope);
702 : // relativistic velocity
703 : Double_t velo = 1.;
704 : // Angular dispersion square of the track (variance) in a plane perpendicular to the trajectory
705 430 : Double_t theta02 = 0.0136 / velo * (1 + 0.038 * TMath::Log(pathLength/x0));
706 :
707 430 : return theta02 * theta02 * inverseTotalMomentum2 * pathLength / x0;
708 : }
709 :
710 : //__________________________________________________________________________
711 : void AliMUONTrackExtrap::AddMCSEffect(AliMUONTrackParam *param, Double_t dZ, Double_t x0)
712 : {
713 : /// Add to the track parameter covariances the effects of multiple Coulomb scattering
714 : /// through a material of thickness "Abs(dZ)" and of radiation length "x0"
715 : /// assuming linear propagation and using the small angle approximation.
716 : /// dZ = zOut - zIn (sign is important) and "param" is assumed to be given zOut.
717 : /// If x0 <= 0., assume dZ = pathLength/x0 and consider the material thickness as negligible.
718 :
719 780 : Double_t bendingSlope = param->GetBendingSlope();
720 390 : Double_t nonBendingSlope = param->GetNonBendingSlope();
721 390 : Double_t inverseBendingMomentum = param->GetInverseBendingMomentum();
722 780 : Double_t inverseTotalMomentum2 = inverseBendingMomentum * inverseBendingMomentum *
723 780 : (1.0 + bendingSlope * bendingSlope) /
724 390 : (1.0 + bendingSlope *bendingSlope + nonBendingSlope * nonBendingSlope);
725 : // Path length in the material
726 390 : Double_t signedPathLength = dZ * TMath::Sqrt(1.0 + bendingSlope*bendingSlope + nonBendingSlope*nonBendingSlope);
727 796 : Double_t pathLengthOverX0 = (x0 > 0.) ? TMath::Abs(signedPathLength) / x0 : TMath::Abs(signedPathLength);
728 : // relativistic velocity
729 : Double_t velo = 1.;
730 : // Angular dispersion square of the track (variance) in a plane perpendicular to the trajectory
731 390 : Double_t theta02 = 0.0136 / velo * (1 + 0.038 * TMath::Log(pathLengthOverX0));
732 390 : theta02 *= theta02 * inverseTotalMomentum2 * pathLengthOverX0;
733 :
734 796 : Double_t varCoor = (x0 > 0.) ? signedPathLength * signedPathLength * theta02 / 3. : 0.;
735 : Double_t varSlop = theta02;
736 796 : Double_t covCorrSlope = (x0 > 0.) ? signedPathLength * theta02 / 2. : 0.;
737 :
738 : // Set MCS covariance matrix
739 390 : TMatrixD newParamCov(param->GetCovariances());
740 : // Non bending plane
741 1170 : newParamCov(0,0) += varCoor; newParamCov(0,1) += covCorrSlope;
742 1170 : newParamCov(1,0) += covCorrSlope; newParamCov(1,1) += varSlop;
743 : // Bending plane
744 1170 : newParamCov(2,2) += varCoor; newParamCov(2,3) += covCorrSlope;
745 1170 : newParamCov(3,2) += covCorrSlope; newParamCov(3,3) += varSlop;
746 :
747 : // Set momentum related covariances if B!=0
748 390 : if (fgFieldON) {
749 : // compute derivative d(q/Pxy) / dSlopeX and d(q/Pxy) / dSlopeY
750 390 : Double_t dqPxydSlopeX = inverseBendingMomentum * nonBendingSlope / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
751 390 : Double_t dqPxydSlopeY = - inverseBendingMomentum * nonBendingSlope*nonBendingSlope * bendingSlope /
752 390 : (1. + bendingSlope*bendingSlope) / (1. + nonBendingSlope*nonBendingSlope + bendingSlope*bendingSlope);
753 : // Inverse bending momentum (due to dependences with bending and non bending slopes)
754 1170 : newParamCov(4,0) += dqPxydSlopeX * covCorrSlope; newParamCov(0,4) += dqPxydSlopeX * covCorrSlope;
755 1170 : newParamCov(4,1) += dqPxydSlopeX * varSlop; newParamCov(1,4) += dqPxydSlopeX * varSlop;
756 1170 : newParamCov(4,2) += dqPxydSlopeY * covCorrSlope; newParamCov(2,4) += dqPxydSlopeY * covCorrSlope;
757 1170 : newParamCov(4,3) += dqPxydSlopeY * varSlop; newParamCov(3,4) += dqPxydSlopeY * varSlop;
758 780 : newParamCov(4,4) += (dqPxydSlopeX*dqPxydSlopeX + dqPxydSlopeY*dqPxydSlopeY) * varSlop;
759 390 : }
760 :
761 : // Set new covariances
762 390 : param->SetCovariances(newParamCov);
763 390 : }
764 :
765 : //__________________________________________________________________________
766 : void AliMUONTrackExtrap::ExtrapToVertex(AliMUONTrackParam* trackParam,
767 : Double_t xVtx, Double_t yVtx, Double_t zVtx,
768 : Double_t errXVtx, Double_t errYVtx,
769 : Bool_t correctForMCS, Bool_t correctForEnergyLoss)
770 : {
771 : /// Main method for extrapolation to the vertex:
772 : /// Returns the track parameters and covariances resulting from the extrapolation of the current trackParam
773 : /// Changes parameters and covariances according to multiple scattering and energy loss corrections:
774 : /// if correctForMCS=kTRUE: compute parameters using Branson correction and add correction resolution to covariances
775 : /// if correctForMCS=kFALSE: add parameter dispersion due to MCS in parameter covariances
776 : /// if correctForEnergyLoss=kTRUE: correct parameters for energy loss and add energy loss fluctuation to covariances
777 : /// if correctForEnergyLoss=kFALSE: do nothing about energy loss
778 :
779 32 : if (trackParam->GetZ() == zVtx) return; // nothing to be done if already at vertex
780 :
781 32 : if (trackParam->GetZ() > zVtx) { // spectro. (z<0)
782 0 : cout<<"E-AliMUONTrackExtrap::ExtrapToVertex: Starting Z ("<<trackParam->GetZ()
783 0 : <<") upstream the vertex (zVtx = "<<zVtx<<")"<<endl;
784 0 : return;
785 : }
786 :
787 : // Check the vertex position relatively to the absorber
788 32 : if (zVtx < AliMUONConstants::AbsZBeg() && zVtx > AliMUONConstants::AbsZEnd()) { // spectro. (z<0)
789 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToVertex: Ending Z ("<<zVtx
790 0 : <<") inside the front absorber ("<<AliMUONConstants::AbsZBeg()<<","<<AliMUONConstants::AbsZEnd()<<")"<<endl;
791 32 : } else if (zVtx < AliMUONConstants::AbsZEnd() ) { // spectro. (z<0)
792 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToVertex: Ending Z ("<<zVtx
793 0 : <<") downstream the front absorber (zAbsorberEnd = "<<AliMUONConstants::AbsZEnd()<<")"<<endl;
794 0 : if (trackParam->CovariancesExist()) ExtrapToZCov(trackParam,zVtx);
795 0 : else ExtrapToZ(trackParam,zVtx);
796 : return;
797 : }
798 :
799 : // Check the track position relatively to the absorber and extrapolate track parameters to the end of the absorber if needed
800 32 : if (trackParam->GetZ() > AliMUONConstants::AbsZBeg()) { // spectro. (z<0)
801 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToVertex: Starting Z ("<<trackParam->GetZ()
802 0 : <<") upstream the front absorber (zAbsorberBegin = "<<AliMUONConstants::AbsZBeg()<<")"<<endl;
803 0 : if (trackParam->CovariancesExist()) ExtrapToZCov(trackParam,zVtx);
804 0 : else ExtrapToZ(trackParam,zVtx);
805 : return;
806 32 : } else if (trackParam->GetZ() > AliMUONConstants::AbsZEnd()) { // spectro. (z<0)
807 0 : cout<<"W-AliMUONTrackExtrap::ExtrapToVertex: Starting Z ("<<trackParam->GetZ()
808 0 : <<") inside the front absorber ("<<AliMUONConstants::AbsZBeg()<<","<<AliMUONConstants::AbsZEnd()<<")"<<endl;
809 0 : } else {
810 64 : if (trackParam->CovariancesExist()) ExtrapToZCov(trackParam,AliMUONConstants::AbsZEnd());
811 0 : else ExtrapToZ(trackParam,AliMUONConstants::AbsZEnd());
812 : }
813 :
814 : // Get absorber correction parameters assuming linear propagation in absorber
815 32 : Double_t trackXYZOut[3];
816 32 : trackXYZOut[0] = trackParam->GetNonBendingCoor();
817 32 : trackXYZOut[1] = trackParam->GetBendingCoor();
818 32 : trackXYZOut[2] = trackParam->GetZ();
819 32 : Double_t trackXYZIn[3];
820 32 : if (correctForMCS) { // assume linear propagation until the vertex
821 16 : trackXYZIn[2] = TMath::Min(zVtx, AliMUONConstants::AbsZBeg()); // spectro. (z<0)
822 16 : trackXYZIn[0] = trackXYZOut[0] + (xVtx - trackXYZOut[0]) / (zVtx - trackXYZOut[2]) * (trackXYZIn[2] - trackXYZOut[2]);
823 16 : trackXYZIn[1] = trackXYZOut[1] + (yVtx - trackXYZOut[1]) / (zVtx - trackXYZOut[2]) * (trackXYZIn[2] - trackXYZOut[2]);
824 16 : } else {
825 16 : AliMUONTrackParam trackParamIn(*trackParam);
826 16 : ExtrapToZ(&trackParamIn, TMath::Min(zVtx, AliMUONConstants::AbsZBeg()));
827 32 : trackXYZIn[0] = trackParamIn.GetNonBendingCoor();
828 32 : trackXYZIn[1] = trackParamIn.GetBendingCoor();
829 16 : trackXYZIn[2] = trackParamIn.GetZ();
830 16 : }
831 32 : Double_t pTot = trackParam->P();
832 32 : Double_t pathLength, f0, f1, f2, meanRho, totalELoss, sigmaELoss2;
833 32 : if (!GetAbsorberCorrectionParam(trackXYZIn,trackXYZOut,pTot,pathLength,f0,f1,f2,meanRho,totalELoss,sigmaELoss2)) {
834 0 : cout<<"E-AliMUONTrackExtrap::ExtrapToVertex: Unable to take into account the absorber effects"<<endl;
835 0 : if (trackParam->CovariancesExist()) ExtrapToZCov(trackParam,zVtx);
836 0 : else ExtrapToZ(trackParam,zVtx);
837 0 : return;
838 : }
839 :
840 : // Compute track parameters and covariances at vertex according to correctForMCS and correctForEnergyLoss flags
841 32 : if (correctForMCS) {
842 :
843 48 : if (correctForEnergyLoss) {
844 :
845 : // Correct for multiple scattering and energy loss
846 16 : CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
847 16 : CorrectMCSEffectInAbsorber(trackParam, xVtx, yVtx, zVtx, errXVtx, errYVtx,
848 16 : trackXYZIn[2], pathLength, f0, f1, f2);
849 16 : CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
850 :
851 16 : } else {
852 :
853 : // Correct for multiple scattering
854 0 : CorrectMCSEffectInAbsorber(trackParam, xVtx, yVtx, zVtx, errXVtx, errYVtx,
855 0 : trackXYZIn[2], pathLength, f0, f1, f2);
856 : }
857 :
858 : } else {
859 :
860 16 : if (correctForEnergyLoss) {
861 :
862 : // Correct for energy loss add multiple scattering dispersion in covariance matrix
863 16 : CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
864 16 : AddMCSEffectInAbsorber(trackParam, -pathLength, f0, f1, f2); // (spectro. (z<0))
865 16 : ExtrapToZCov(trackParam, trackXYZIn[2]);
866 16 : CorrectELossEffectInAbsorber(trackParam, 0.5*totalELoss, 0.5*sigmaELoss2);
867 16 : ExtrapToZCov(trackParam, zVtx);
868 :
869 16 : } else {
870 :
871 : // add multiple scattering dispersion in covariance matrix
872 0 : AddMCSEffectInAbsorber(trackParam, -pathLength, f0, f1, f2); // (spectro. (z<0))
873 0 : ExtrapToZCov(trackParam, zVtx);
874 :
875 : }
876 :
877 : }
878 :
879 96 : }
880 :
881 : //__________________________________________________________________________
882 : void AliMUONTrackExtrap::ExtrapToVertex(AliMUONTrackParam* trackParam,
883 : Double_t xVtx, Double_t yVtx, Double_t zVtx,
884 : Double_t errXVtx, Double_t errYVtx)
885 : {
886 : /// Extrapolate track parameters to vertex, corrected for multiple scattering and energy loss effects
887 : /// Add branson correction resolution and energy loss fluctuation to parameter covariances
888 32 : ExtrapToVertex(trackParam, xVtx, yVtx, zVtx, errXVtx, errYVtx, kTRUE, kTRUE);
889 16 : }
890 :
891 : //__________________________________________________________________________
892 : void AliMUONTrackExtrap::ExtrapToVertexWithoutELoss(AliMUONTrackParam* trackParam,
893 : Double_t xVtx, Double_t yVtx, Double_t zVtx,
894 : Double_t errXVtx, Double_t errYVtx)
895 : {
896 : /// Extrapolate track parameters to vertex, corrected for multiple scattering effects only
897 : /// Add branson correction resolution to parameter covariances
898 0 : ExtrapToVertex(trackParam, xVtx, yVtx, zVtx, errXVtx, errYVtx, kTRUE, kFALSE);
899 0 : }
900 :
901 : //__________________________________________________________________________
902 : void AliMUONTrackExtrap::ExtrapToVertexWithoutBranson(AliMUONTrackParam* trackParam, Double_t zVtx)
903 : {
904 : /// Extrapolate track parameters to vertex, corrected for energy loss effects only
905 : /// Add dispersion due to multiple scattering and energy loss fluctuation to parameter covariances
906 32 : ExtrapToVertex(trackParam, 0., 0., zVtx, 0., 0., kFALSE, kTRUE);
907 16 : }
908 :
909 : //__________________________________________________________________________
910 : void AliMUONTrackExtrap::ExtrapToVertexUncorrected(AliMUONTrackParam* trackParam, Double_t zVtx)
911 : {
912 : /// Extrapolate track parameters to vertex without multiple scattering and energy loss corrections
913 : /// Add dispersion due to multiple scattering to parameter covariances
914 0 : ExtrapToVertex(trackParam, 0., 0., zVtx, 0., 0., kFALSE, kFALSE);
915 0 : }
916 :
917 : //__________________________________________________________________________
918 : Double_t AliMUONTrackExtrap::TotalMomentumEnergyLoss(AliMUONTrackParam* trackParam, Double_t xVtx, Double_t yVtx, Double_t zVtx)
919 : {
920 : /// Calculate the total momentum energy loss in-between the track position and the vertex assuming a linear propagation
921 :
922 0 : if (trackParam->GetZ() == zVtx) return 0.; // nothing to be done if already at vertex
923 :
924 : // Check whether the geometry is available
925 0 : if (!gGeoManager) {
926 0 : cout<<"E-AliMUONTrackExtrap::TotalMomentumEnergyLoss: no TGeo"<<endl;
927 0 : return 0.;
928 : }
929 :
930 : // Get encountered material correction parameters assuming linear propagation from vertex to the track position
931 0 : Double_t trackXYZOut[3];
932 0 : trackXYZOut[0] = trackParam->GetNonBendingCoor();
933 0 : trackXYZOut[1] = trackParam->GetBendingCoor();
934 0 : trackXYZOut[2] = trackParam->GetZ();
935 0 : Double_t trackXYZIn[3];
936 0 : trackXYZIn[0] = xVtx;
937 0 : trackXYZIn[1] = yVtx;
938 0 : trackXYZIn[2] = zVtx;
939 0 : Double_t pTot = trackParam->P();
940 0 : Double_t pathLength, f0, f1, f2, meanRho, totalELoss, sigmaELoss2;
941 0 : GetAbsorberCorrectionParam(trackXYZIn,trackXYZOut,pTot,pathLength,f0,f1,f2,meanRho,totalELoss,sigmaELoss2);
942 :
943 : // total momentum corrected for energy loss
944 0 : Double_t muMass = TDatabasePDG::Instance()->GetParticle("mu-")->Mass(); // GeV
945 0 : Double_t e = TMath::Sqrt(pTot*pTot + muMass*muMass);
946 0 : Double_t eCorr = e + totalELoss;
947 0 : Double_t pTotCorr = TMath::Sqrt(eCorr*eCorr - muMass*muMass);
948 :
949 0 : return pTotCorr - pTot;
950 0 : }
951 :
952 : //__________________________________________________________________________
953 : Double_t AliMUONTrackExtrap::BetheBloch(Double_t pTotal, Double_t pathLength, Double_t rho, Double_t atomicZ, Double_t atomicZoverA)
954 : {
955 : /// Returns the mean total momentum energy loss of muon with total momentum='pTotal'
956 : /// in the absorber layer of lenght='pathLength', density='rho', A='atomicA' and Z='atomicZ'
957 568 : Double_t muMass = TDatabasePDG::Instance()->GetParticle("mu-")->Mass(); // GeV
958 :
959 : // mean exitation energy (GeV)
960 : Double_t i;
961 438 : if (atomicZ < 13) i = (12. * atomicZ + 7.) * 1.e-9;
962 130 : else i = (9.76 * atomicZ + 58.8 * TMath::Power(atomicZ,-0.19)) * 1.e-9;
963 :
964 284 : return pathLength * rho * AliExternalTrackParam::BetheBlochGeant(pTotal/muMass, rho, 0.20, 3.00, i, atomicZoverA);
965 : }
966 :
967 : //__________________________________________________________________________
968 : Double_t AliMUONTrackExtrap::EnergyLossFluctuation(Double_t pTotal, Double_t pathLength, Double_t rho, Double_t atomicZoverA)
969 : {
970 : /// Returns the total momentum energy loss fluctuation of muon with total momentum='pTotal'
971 : /// in the absorber layer of lenght='pathLength', density='rho', A='atomicA' and Z='atomicZ'
972 568 : Double_t muMass = TDatabasePDG::Instance()->GetParticle("mu-")->Mass(); // GeV
973 : //Double_t eMass = 0.510998918e-3; // GeV
974 : Double_t k = 0.307075e-3; // GeV.g^-1.cm^2
975 284 : Double_t p2=pTotal*pTotal;
976 284 : Double_t beta2=p2/(p2 + muMass*muMass);
977 :
978 284 : Double_t fwhm = 2. * k * rho * pathLength * atomicZoverA / beta2; // FWHM of the energy loss Landau distribution
979 284 : Double_t sigma = fwhm / TMath::Sqrt(8.*log(2.)); // gaussian: fwmh = 2 * srqt(2*ln(2)) * sigma (i.e. fwmh = 2.35 * sigma)
980 :
981 : //sigma2 = k * rho * pathLength * atomicZ / atomicA * eMass; // sigma2 of the energy loss gaussian distribution
982 :
983 284 : return sigma;
984 : }
985 :
986 : //__________________________________________________________________________
987 : void AliMUONTrackExtrap::Cov2CovP(const TMatrixD ¶m, TMatrixD &cov)
988 : {
989 : /// change coordinate system: (X, SlopeX, Y, SlopeY, q/Pyz) -> (X, SlopeX, Y, SlopeY, q*PTot)
990 : /// parameters (param) are given in the (X, SlopeX, Y, SlopeY, q/Pyz) coordinate system
991 :
992 : // charge * total momentum
993 240 : Double_t qPTot = TMath::Sqrt(1. + param(1,0)*param(1,0) + param(3,0)*param(3,0)) /
994 160 : TMath::Sqrt(1. + param(3,0)*param(3,0)) / param(4,0);
995 :
996 : // Jacobian of the opposite transformation
997 80 : TMatrixD jacob(5,5);
998 80 : jacob.UnitMatrix();
999 560 : jacob(4,1) = qPTot * param(1,0) / (1. + param(1,0)*param(1,0) + param(3,0)*param(3,0));
1000 560 : jacob(4,3) = - qPTot * param(1,0) * param(1,0) * param(3,0) /
1001 640 : (1. + param(3,0)*param(3,0)) / (1. + param(1,0)*param(1,0) + param(3,0)*param(3,0));
1002 240 : jacob(4,4) = - qPTot / param(4,0);
1003 :
1004 : // compute covariances in new coordinate system
1005 80 : TMatrixD tmp(cov,TMatrixD::kMultTranspose,jacob);
1006 80 : cov.Mult(jacob,tmp);
1007 80 : }
1008 :
1009 : //__________________________________________________________________________
1010 : void AliMUONTrackExtrap::CovP2Cov(const TMatrixD ¶m, TMatrixD &covP)
1011 : {
1012 : /// change coordinate system: (X, SlopeX, Y, SlopeY, q*PTot) -> (X, SlopeX, Y, SlopeY, q/Pyz)
1013 : /// parameters (param) are given in the (X, SlopeX, Y, SlopeY, q/Pyz) coordinate system
1014 :
1015 : // charge * total momentum
1016 240 : Double_t qPTot = TMath::Sqrt(1. + param(1,0)*param(1,0) + param(3,0)*param(3,0)) /
1017 160 : TMath::Sqrt(1. + param(3,0)*param(3,0)) / param(4,0);
1018 :
1019 : // Jacobian of the transformation
1020 80 : TMatrixD jacob(5,5);
1021 80 : jacob.UnitMatrix();
1022 640 : jacob(4,1) = param(4,0) * param(1,0) / (1. + param(1,0)*param(1,0) + param(3,0)*param(3,0));
1023 640 : jacob(4,3) = - param(4,0) * param(1,0) * param(1,0) * param(3,0) /
1024 640 : (1. + param(3,0)*param(3,0)) / (1. + param(1,0)*param(1,0) + param(3,0)*param(3,0));
1025 240 : jacob(4,4) = - param(4,0) / qPTot;
1026 :
1027 : // compute covariances in new coordinate system
1028 80 : TMatrixD tmp(covP,TMatrixD::kMultTranspose,jacob);
1029 80 : covP.Mult(jacob,tmp);
1030 80 : }
1031 :
1032 : //__________________________________________________________________________
1033 : void AliMUONTrackExtrap::ExtrapOneStepHelix(Double_t charge, Double_t step, const Double_t *vect, Double_t *vout)
1034 : {
1035 : /// <pre>
1036 : /// ******************************************************************
1037 : /// * *
1038 : /// * Performs the tracking of one step in a magnetic field *
1039 : /// * The trajectory is assumed to be a helix in a constant field *
1040 : /// * taken at the mid point of the step. *
1041 : /// * Parameters: *
1042 : /// * input *
1043 : /// * STEP =arc length of the step asked *
1044 : /// * VECT =input vector (position,direction cos and momentum) *
1045 : /// * CHARGE= electric charge of the particle *
1046 : /// * output *
1047 : /// * VOUT = same as VECT after completion of the step *
1048 : /// * *
1049 : /// * ==>Called by : USER, GUSWIM *
1050 : /// * Author m.hansroul ********* *
1051 : /// * modified s.egli, s.v.levonian *
1052 : /// * modified v.perevoztchikov
1053 : /// * *
1054 : /// ******************************************************************
1055 : /// </pre>
1056 :
1057 : // modif: everything in double precision
1058 :
1059 0 : Double_t xyz[3], h[4], hxp[3];
1060 : Double_t h2xy, hp, rho, tet;
1061 : Double_t sint, sintt, tsint, cos1t;
1062 : Double_t f1, f2, f3, f4, f5, f6;
1063 :
1064 : const Int_t kix = 0;
1065 : const Int_t kiy = 1;
1066 : const Int_t kiz = 2;
1067 : const Int_t kipx = 3;
1068 : const Int_t kipy = 4;
1069 : const Int_t kipz = 5;
1070 : const Int_t kipp = 6;
1071 :
1072 : const Double_t kec = 2.9979251e-4;
1073 : //
1074 : // ------------------------------------------------------------------
1075 : //
1076 : // units are kgauss,centimeters,gev/c
1077 : //
1078 0 : vout[kipp] = vect[kipp];
1079 0 : if (TMath::Abs(charge) < 0.00001) {
1080 0 : for (Int_t i = 0; i < 3; i++) {
1081 0 : vout[i] = vect[i] + step * vect[i+3];
1082 0 : vout[i+3] = vect[i+3];
1083 : }
1084 0 : return;
1085 : }
1086 0 : xyz[0] = vect[kix] + 0.5 * step * vect[kipx];
1087 0 : xyz[1] = vect[kiy] + 0.5 * step * vect[kipy];
1088 0 : xyz[2] = vect[kiz] + 0.5 * step * vect[kipz];
1089 :
1090 : //cmodif: call gufld (xyz, h) changed into:
1091 0 : TGeoGlobalMagField::Instance()->Field(xyz,h);
1092 :
1093 0 : h2xy = h[0]*h[0] + h[1]*h[1];
1094 0 : h[3] = h[2]*h[2]+ h2xy;
1095 0 : if (h[3] < 1.e-12) {
1096 0 : for (Int_t i = 0; i < 3; i++) {
1097 0 : vout[i] = vect[i] + step * vect[i+3];
1098 0 : vout[i+3] = vect[i+3];
1099 : }
1100 0 : return;
1101 : }
1102 0 : if (h2xy < 1.e-12*h[3]) {
1103 0 : ExtrapOneStepHelix3(charge*h[2], step, vect, vout);
1104 0 : return;
1105 : }
1106 0 : h[3] = TMath::Sqrt(h[3]);
1107 0 : h[0] /= h[3];
1108 0 : h[1] /= h[3];
1109 0 : h[2] /= h[3];
1110 0 : h[3] *= kec;
1111 :
1112 0 : hxp[0] = h[1]*vect[kipz] - h[2]*vect[kipy];
1113 0 : hxp[1] = h[2]*vect[kipx] - h[0]*vect[kipz];
1114 0 : hxp[2] = h[0]*vect[kipy] - h[1]*vect[kipx];
1115 :
1116 0 : hp = h[0]*vect[kipx] + h[1]*vect[kipy] + h[2]*vect[kipz];
1117 :
1118 0 : rho = -charge*h[3]/vect[kipp];
1119 0 : tet = rho * step;
1120 :
1121 0 : if (TMath::Abs(tet) > 0.15) {
1122 0 : sint = TMath::Sin(tet);
1123 0 : sintt = (sint/tet);
1124 0 : tsint = (tet-sint)/tet;
1125 0 : cos1t = 2.*(TMath::Sin(0.5*tet))*(TMath::Sin(0.5*tet))/tet;
1126 0 : } else {
1127 0 : tsint = tet*tet/36.;
1128 0 : sintt = (1. - tsint);
1129 0 : sint = tet*sintt;
1130 0 : cos1t = 0.5*tet;
1131 : }
1132 :
1133 0 : f1 = step * sintt;
1134 0 : f2 = step * cos1t;
1135 0 : f3 = step * tsint * hp;
1136 0 : f4 = -tet*cos1t;
1137 : f5 = sint;
1138 0 : f6 = tet * cos1t * hp;
1139 :
1140 0 : vout[kix] = vect[kix] + f1*vect[kipx] + f2*hxp[0] + f3*h[0];
1141 0 : vout[kiy] = vect[kiy] + f1*vect[kipy] + f2*hxp[1] + f3*h[1];
1142 0 : vout[kiz] = vect[kiz] + f1*vect[kipz] + f2*hxp[2] + f3*h[2];
1143 :
1144 0 : vout[kipx] = vect[kipx] + f4*vect[kipx] + f5*hxp[0] + f6*h[0];
1145 0 : vout[kipy] = vect[kipy] + f4*vect[kipy] + f5*hxp[1] + f6*h[1];
1146 0 : vout[kipz] = vect[kipz] + f4*vect[kipz] + f5*hxp[2] + f6*h[2];
1147 :
1148 0 : return;
1149 0 : }
1150 :
1151 : //__________________________________________________________________________
1152 : void AliMUONTrackExtrap::ExtrapOneStepHelix3(Double_t field, Double_t step, const Double_t *vect, Double_t *vout)
1153 : {
1154 : /// <pre>
1155 : /// ******************************************************************
1156 : /// * *
1157 : /// * Tracking routine in a constant field oriented *
1158 : /// * along axis 3 *
1159 : /// * Tracking is performed with a conventional *
1160 : /// * helix step method *
1161 : /// * *
1162 : /// * ==>Called by : USER, GUSWIM *
1163 : /// * Authors R.Brun, M.Hansroul ********* *
1164 : /// * Rewritten V.Perevoztchikov
1165 : /// * *
1166 : /// ******************************************************************
1167 : /// </pre>
1168 :
1169 : Double_t hxp[3];
1170 : Double_t h4, hp, rho, tet;
1171 : Double_t sint, sintt, tsint, cos1t;
1172 : Double_t f1, f2, f3, f4, f5, f6;
1173 :
1174 : const Int_t kix = 0;
1175 : const Int_t kiy = 1;
1176 : const Int_t kiz = 2;
1177 : const Int_t kipx = 3;
1178 : const Int_t kipy = 4;
1179 : const Int_t kipz = 5;
1180 : const Int_t kipp = 6;
1181 :
1182 : const Double_t kec = 2.9979251e-4;
1183 :
1184 : //
1185 : // ------------------------------------------------------------------
1186 : //
1187 : // units are kgauss,centimeters,gev/c
1188 : //
1189 0 : vout[kipp] = vect[kipp];
1190 0 : h4 = field * kec;
1191 :
1192 0 : hxp[0] = - vect[kipy];
1193 0 : hxp[1] = + vect[kipx];
1194 :
1195 0 : hp = vect[kipz];
1196 :
1197 0 : rho = -h4/vect[kipp];
1198 0 : tet = rho * step;
1199 0 : if (TMath::Abs(tet) > 0.15) {
1200 0 : sint = TMath::Sin(tet);
1201 0 : sintt = (sint/tet);
1202 0 : tsint = (tet-sint)/tet;
1203 0 : cos1t = 2.* TMath::Sin(0.5*tet) * TMath::Sin(0.5*tet)/tet;
1204 0 : } else {
1205 0 : tsint = tet*tet/36.;
1206 0 : sintt = (1. - tsint);
1207 0 : sint = tet*sintt;
1208 0 : cos1t = 0.5*tet;
1209 : }
1210 :
1211 0 : f1 = step * sintt;
1212 0 : f2 = step * cos1t;
1213 0 : f3 = step * tsint * hp;
1214 0 : f4 = -tet*cos1t;
1215 : f5 = sint;
1216 0 : f6 = tet * cos1t * hp;
1217 :
1218 0 : vout[kix] = vect[kix] + f1*vect[kipx] + f2*hxp[0];
1219 0 : vout[kiy] = vect[kiy] + f1*vect[kipy] + f2*hxp[1];
1220 0 : vout[kiz] = vect[kiz] + f1*vect[kipz] + f3;
1221 :
1222 0 : vout[kipx] = vect[kipx] + f4*vect[kipx] + f5*hxp[0];
1223 0 : vout[kipy] = vect[kipy] + f4*vect[kipy] + f5*hxp[1];
1224 0 : vout[kipz] = vect[kipz] + f4*vect[kipz] + f6;
1225 :
1226 : return;
1227 0 : }
1228 :
1229 : //__________________________________________________________________________
1230 : Bool_t AliMUONTrackExtrap::ExtrapOneStepRungekutta(Double_t charge, Double_t step, const Double_t* vect, Double_t* vout)
1231 : {
1232 : /// <pre>
1233 : /// ******************************************************************
1234 : /// * *
1235 : /// * Runge-Kutta method for tracking a particle through a magnetic *
1236 : /// * field. Uses Nystroem algorithm (See Handbook Nat. Bur. of *
1237 : /// * Standards, procedure 25.5.20) *
1238 : /// * *
1239 : /// * Input parameters *
1240 : /// * CHARGE Particle charge *
1241 : /// * STEP Step size *
1242 : /// * VECT Initial co-ords,direction cosines,momentum *
1243 : /// * Output parameters *
1244 : /// * VOUT Output co-ords,direction cosines,momentum *
1245 : /// * User routine called *
1246 : /// * CALL GUFLD(X,F) *
1247 : /// * *
1248 : /// * ==>Called by : USER, GUSWIM *
1249 : /// * Authors R.Brun, M.Hansroul ********* *
1250 : /// * V.Perevoztchikov (CUT STEP implementation) *
1251 : /// * *
1252 : /// * *
1253 : /// ******************************************************************
1254 : /// </pre>
1255 :
1256 10036 : Double_t h2, h4, f[4];
1257 5018 : Double_t xyzt[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
1258 : Double_t a, b, c, ph,ph2;
1259 : Double_t secxs[4],secys[4],seczs[4],hxp[3];
1260 : Double_t g1, g2, g3, g4, g5, g6, ang2, dxt, dyt, dzt;
1261 : Double_t est, at, bt, ct, cba;
1262 : Double_t f1, f2, f3, f4, rho, tet, hnorm, hp, rho1, sint, cost;
1263 :
1264 : Double_t x;
1265 : Double_t y;
1266 : Double_t z;
1267 :
1268 : Double_t xt;
1269 : Double_t yt;
1270 : Double_t zt;
1271 :
1272 : Double_t maxit = 1992;
1273 : Double_t maxcut = 11;
1274 :
1275 : const Double_t kdlt = 1e-4;
1276 : const Double_t kdlt32 = kdlt/32.;
1277 : const Double_t kthird = 1./3.;
1278 : const Double_t khalf = 0.5;
1279 : const Double_t kec = 2.9979251e-4;
1280 :
1281 : const Double_t kpisqua = 9.86960440109;
1282 : const Int_t kix = 0;
1283 : const Int_t kiy = 1;
1284 : const Int_t kiz = 2;
1285 : const Int_t kipx = 3;
1286 : const Int_t kipy = 4;
1287 : const Int_t kipz = 5;
1288 :
1289 : // *.
1290 : // *. ------------------------------------------------------------------
1291 : // *.
1292 : // * this constant is for units cm,gev/c and kgauss
1293 : // *
1294 : Int_t iter = 0;
1295 : Int_t ncut = 0;
1296 80288 : for(Int_t j = 0; j < 7; j++)
1297 35126 : vout[j] = vect[j];
1298 :
1299 5018 : Double_t pinv = kec * charge / vect[6];
1300 : Double_t tl = 0.;
1301 : Double_t h = step;
1302 : Double_t rest;
1303 :
1304 :
1305 5018 : do {
1306 14316 : rest = step - tl;
1307 14996 : if (TMath::Abs(h) > TMath::Abs(rest)) h = rest;
1308 : //cmodif: call gufld(vout,f) changed into:
1309 14316 : TGeoGlobalMagField::Instance()->Field(vout,f);
1310 :
1311 : // *
1312 : // * start of integration
1313 : // *
1314 14316 : x = vout[0];
1315 14316 : y = vout[1];
1316 14316 : z = vout[2];
1317 14316 : a = vout[3];
1318 14316 : b = vout[4];
1319 14316 : c = vout[5];
1320 :
1321 14316 : h2 = khalf * h;
1322 14316 : h4 = khalf * h2;
1323 14316 : ph = pinv * h;
1324 14316 : ph2 = khalf * ph;
1325 14316 : secxs[0] = (b * f[2] - c * f[1]) * ph2;
1326 14316 : secys[0] = (c * f[0] - a * f[2]) * ph2;
1327 14316 : seczs[0] = (a * f[1] - b * f[0]) * ph2;
1328 14316 : ang2 = (secxs[0]*secxs[0] + secys[0]*secys[0] + seczs[0]*seczs[0]);
1329 14316 : if (ang2 > kpisqua) break;
1330 :
1331 14316 : dxt = h2 * a + h4 * secxs[0];
1332 14316 : dyt = h2 * b + h4 * secys[0];
1333 14316 : dzt = h2 * c + h4 * seczs[0];
1334 14316 : xt = x + dxt;
1335 14316 : yt = y + dyt;
1336 14316 : zt = z + dzt;
1337 : // *
1338 : // * second intermediate point
1339 : // *
1340 :
1341 14316 : est = TMath::Abs(dxt) + TMath::Abs(dyt) + TMath::Abs(dzt);
1342 14316 : if (est > h) {
1343 0 : if (ncut++ > maxcut) break;
1344 : h *= khalf;
1345 0 : continue;
1346 : }
1347 :
1348 14316 : xyzt[0] = xt;
1349 14316 : xyzt[1] = yt;
1350 14316 : xyzt[2] = zt;
1351 :
1352 : //cmodif: call gufld(xyzt,f) changed into:
1353 14316 : TGeoGlobalMagField::Instance()->Field(xyzt,f);
1354 :
1355 14316 : at = a + secxs[0];
1356 14316 : bt = b + secys[0];
1357 14316 : ct = c + seczs[0];
1358 :
1359 14316 : secxs[1] = (bt * f[2] - ct * f[1]) * ph2;
1360 14316 : secys[1] = (ct * f[0] - at * f[2]) * ph2;
1361 14316 : seczs[1] = (at * f[1] - bt * f[0]) * ph2;
1362 14316 : at = a + secxs[1];
1363 14316 : bt = b + secys[1];
1364 14316 : ct = c + seczs[1];
1365 14316 : secxs[2] = (bt * f[2] - ct * f[1]) * ph2;
1366 14316 : secys[2] = (ct * f[0] - at * f[2]) * ph2;
1367 14316 : seczs[2] = (at * f[1] - bt * f[0]) * ph2;
1368 14316 : dxt = h * (a + secxs[2]);
1369 14316 : dyt = h * (b + secys[2]);
1370 14316 : dzt = h * (c + seczs[2]);
1371 14316 : xt = x + dxt;
1372 14316 : yt = y + dyt;
1373 14316 : zt = z + dzt;
1374 14316 : at = a + 2.*secxs[2];
1375 14316 : bt = b + 2.*secys[2];
1376 14316 : ct = c + 2.*seczs[2];
1377 :
1378 14316 : est = TMath::Abs(dxt)+TMath::Abs(dyt)+TMath::Abs(dzt);
1379 14316 : if (est > 2.*TMath::Abs(h)) {
1380 0 : if (ncut++ > maxcut) break;
1381 : h *= khalf;
1382 0 : continue;
1383 : }
1384 :
1385 14316 : xyzt[0] = xt;
1386 14316 : xyzt[1] = yt;
1387 14316 : xyzt[2] = zt;
1388 :
1389 : //cmodif: call gufld(xyzt,f) changed into:
1390 14316 : TGeoGlobalMagField::Instance()->Field(xyzt,f);
1391 :
1392 14316 : z = z + (c + (seczs[0] + seczs[1] + seczs[2]) * kthird) * h;
1393 14316 : y = y + (b + (secys[0] + secys[1] + secys[2]) * kthird) * h;
1394 14316 : x = x + (a + (secxs[0] + secxs[1] + secxs[2]) * kthird) * h;
1395 :
1396 14316 : secxs[3] = (bt*f[2] - ct*f[1])* ph2;
1397 14316 : secys[3] = (ct*f[0] - at*f[2])* ph2;
1398 14316 : seczs[3] = (at*f[1] - bt*f[0])* ph2;
1399 14316 : a = a+(secxs[0]+secxs[3]+2. * (secxs[1]+secxs[2])) * kthird;
1400 14316 : b = b+(secys[0]+secys[3]+2. * (secys[1]+secys[2])) * kthird;
1401 14316 : c = c+(seczs[0]+seczs[3]+2. * (seczs[1]+seczs[2])) * kthird;
1402 :
1403 14316 : est = TMath::Abs(secxs[0]+secxs[3] - (secxs[1]+secxs[2]))
1404 14316 : + TMath::Abs(secys[0]+secys[3] - (secys[1]+secys[2]))
1405 14316 : + TMath::Abs(seczs[0]+seczs[3] - (seczs[1]+seczs[2]));
1406 :
1407 17908 : if (est > kdlt && TMath::Abs(h) > 1.e-4) {
1408 3592 : if (ncut++ > maxcut) break;
1409 : h *= khalf;
1410 3592 : continue;
1411 : }
1412 :
1413 : ncut = 0;
1414 : // * if too many iterations, go to helix
1415 10724 : if (iter++ > maxit) break;
1416 :
1417 10724 : tl += h;
1418 10724 : if (est < kdlt32)
1419 4150 : h *= 2.;
1420 10724 : cba = 1./ TMath::Sqrt(a*a + b*b + c*c);
1421 10724 : vout[0] = x;
1422 10724 : vout[1] = y;
1423 10724 : vout[2] = z;
1424 10724 : vout[3] = cba*a;
1425 10724 : vout[4] = cba*b;
1426 10724 : vout[5] = cba*c;
1427 10724 : rest = step - tl;
1428 10724 : if (step < 0.) rest = -rest;
1429 15742 : if (rest < 1.e-5*TMath::Abs(step)) return kTRUE;
1430 :
1431 : } while(1);
1432 :
1433 : // angle too big, use helix
1434 0 : cout<<"W-AliMUONTrackExtrap::ExtrapOneStepRungekutta: Ruge-Kutta failed: switch to helix"<<endl;
1435 :
1436 0 : f1 = f[0];
1437 0 : f2 = f[1];
1438 0 : f3 = f[2];
1439 0 : f4 = TMath::Sqrt(f1*f1+f2*f2+f3*f3);
1440 0 : if (f4 < 1.e-10) {
1441 0 : cout<<"E-AliMUONTrackExtrap::ExtrapOneStepRungekutta: magnetic field at (";
1442 0 : cout<<xyzt[0]<<", "<<xyzt[1]<<", "<<xyzt[2]<<") = "<<f4<<": giving up"<<endl;
1443 0 : return kFALSE;
1444 : }
1445 0 : rho = -f4*pinv;
1446 0 : tet = rho * step;
1447 :
1448 0 : hnorm = 1./f4;
1449 0 : f1 = f1*hnorm;
1450 0 : f2 = f2*hnorm;
1451 0 : f3 = f3*hnorm;
1452 :
1453 0 : hxp[0] = f2*vect[kipz] - f3*vect[kipy];
1454 0 : hxp[1] = f3*vect[kipx] - f1*vect[kipz];
1455 0 : hxp[2] = f1*vect[kipy] - f2*vect[kipx];
1456 :
1457 0 : hp = f1*vect[kipx] + f2*vect[kipy] + f3*vect[kipz];
1458 :
1459 0 : rho1 = 1./rho;
1460 0 : sint = TMath::Sin(tet);
1461 0 : cost = 2.*TMath::Sin(khalf*tet)*TMath::Sin(khalf*tet);
1462 :
1463 0 : g1 = sint*rho1;
1464 0 : g2 = cost*rho1;
1465 0 : g3 = (tet-sint) * hp*rho1;
1466 0 : g4 = -cost;
1467 : g5 = sint;
1468 0 : g6 = cost * hp;
1469 :
1470 0 : vout[kix] = vect[kix] + g1*vect[kipx] + g2*hxp[0] + g3*f1;
1471 0 : vout[kiy] = vect[kiy] + g1*vect[kipy] + g2*hxp[1] + g3*f2;
1472 0 : vout[kiz] = vect[kiz] + g1*vect[kipz] + g2*hxp[2] + g3*f3;
1473 :
1474 0 : vout[kipx] = vect[kipx] + g4*vect[kipx] + g5*hxp[0] + g6*f1;
1475 0 : vout[kipy] = vect[kipy] + g4*vect[kipy] + g5*hxp[1] + g6*f2;
1476 0 : vout[kipz] = vect[kipz] + g4*vect[kipz] + g5*hxp[2] + g6*f3;
1477 :
1478 0 : return kTRUE;
1479 5018 : }
1480 :
|