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