New class AliESDEvent, backward compatibility with the old AliESD (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackParam.cxx
CommitLineData
a9e2aefa 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
88cb7938 16/* $Id$ */
a9e2aefa 17
3831f268 18///////////////////////////////////////////////////
19//
20// Track parameters
21// in
22// ALICE
23// dimuon
24// spectrometer
a9e2aefa 25//
3831f268 26///////////////////////////////////////////////////
a9e2aefa 27
37827b29 28#include "AliMUONTrackParam.h"
22ccc301 29#include "AliMUONHitForRec.h"
30
211c52eb 31#include "AliESDMuonTrack.h"
37827b29 32#include "AliLog.h"
22ccc301 33
22ccc301 34#include <TMath.h>
ea94c18b 35
36#include <Riostream.h>
a9e2aefa 37
7945aae7 38/// \cond CLASSIMP
a9e2aefa 39ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
7945aae7 40/// \endcond
a9e2aefa 41
61adb9bd 42 //_________________________________________________________________________
30178c30 43AliMUONTrackParam::AliMUONTrackParam()
54d7ba50 44 : TObject(),
208f139e 45 fZ(0.),
ea94c18b 46 fParameters(5,1),
208f139e 47 fCovariances(0x0),
ea94c18b 48 fPropagator(0x0),
49 fExtrapParameters(0x0),
50 fExtrapCovariances(0x0),
51 fSmoothParameters(0x0),
52 fSmoothCovariances(0x0),
53 fHitForRecPtr(0x0),
54 fRemovable(kFALSE),
55 fTrackChi2(0.),
56 fLocalChi2(0.)
30178c30 57{
37827b29 58 /// Constructor
30178c30 59}
61adb9bd 60
30178c30 61 //_________________________________________________________________________
de2cd600 62AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
63 : TObject(theMUONTrackParam),
208f139e 64 fZ(theMUONTrackParam.fZ),
ea94c18b 65 fParameters(theMUONTrackParam.fParameters),
208f139e 66 fCovariances(0x0),
ea94c18b 67 fPropagator(0x0),
68 fExtrapParameters(0x0),
69 fExtrapCovariances(0x0),
70 fSmoothParameters(0x0),
71 fSmoothCovariances(0x0),
72 fHitForRecPtr(theMUONTrackParam.fHitForRecPtr),
73 fRemovable(theMUONTrackParam.fRemovable),
74 fTrackChi2(theMUONTrackParam.fTrackChi2),
75 fLocalChi2(theMUONTrackParam.fLocalChi2)
de2cd600 76{
2457f726 77 /// Copy constructor
208f139e 78 if (theMUONTrackParam.fCovariances) fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
ea94c18b 79 if (theMUONTrackParam.fPropagator) fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
80 if (theMUONTrackParam.fExtrapParameters) fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
81 if (theMUONTrackParam.fExtrapCovariances) fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
82 if (theMUONTrackParam.fSmoothParameters) fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
83 if (theMUONTrackParam.fSmoothCovariances) fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
de2cd600 84}
85
86 //_________________________________________________________________________
87AliMUONTrackParam& AliMUONTrackParam::operator=(const AliMUONTrackParam& theMUONTrackParam)
61adb9bd 88{
2457f726 89 /// Asignment operator
30178c30 90 if (this == &theMUONTrackParam)
61adb9bd 91 return *this;
92
30178c30 93 // base class assignement
94 TObject::operator=(theMUONTrackParam);
95
ea94c18b 96 fZ = theMUONTrackParam.fZ;
97
98 fParameters = theMUONTrackParam.fParameters;
208f139e 99
100 if (theMUONTrackParam.fCovariances) {
101 if (fCovariances) *fCovariances = *(theMUONTrackParam.fCovariances);
102 else fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
019df241 103 } else {
208f139e 104 delete fCovariances;
105 fCovariances = 0x0;
106 }
107
ea94c18b 108 if (theMUONTrackParam.fPropagator) {
109 if (fPropagator) *fPropagator = *(theMUONTrackParam.fPropagator);
110 else fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
019df241 111 } else {
ea94c18b 112 delete fPropagator;
113 fPropagator = 0x0;
114 }
115
116 if (theMUONTrackParam.fExtrapParameters) {
117 if (fExtrapParameters) *fExtrapParameters = *(theMUONTrackParam.fExtrapParameters);
118 else fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
019df241 119 } else {
ea94c18b 120 delete fExtrapParameters;
121 fExtrapParameters = 0x0;
122 }
123
124 if (theMUONTrackParam.fExtrapCovariances) {
125 if (fExtrapCovariances) *fExtrapCovariances = *(theMUONTrackParam.fExtrapCovariances);
126 else fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
019df241 127 } else {
ea94c18b 128 delete fExtrapCovariances;
129 fExtrapCovariances = 0x0;
130 }
131
132 if (theMUONTrackParam.fSmoothParameters) {
133 if (fSmoothParameters) *fSmoothParameters = *(theMUONTrackParam.fSmoothParameters);
134 else fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
019df241 135 } else {
ea94c18b 136 delete fSmoothParameters;
137 fSmoothParameters = 0x0;
138 }
139
140 if (theMUONTrackParam.fSmoothCovariances) {
141 if (fSmoothCovariances) *fSmoothCovariances = *(theMUONTrackParam.fSmoothCovariances);
142 else fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
019df241 143 } else {
ea94c18b 144 delete fSmoothCovariances;
145 fSmoothCovariances = 0x0;
146 }
147
148 fHitForRecPtr = theMUONTrackParam.fHitForRecPtr;
149
150 fRemovable = theMUONTrackParam.fRemovable;
151
152 fTrackChi2 = theMUONTrackParam.fTrackChi2;
153 fLocalChi2 = theMUONTrackParam.fLocalChi2;
154
61adb9bd 155 return *this;
156}
de2cd600 157
158 //__________________________________________________________________________
159AliMUONTrackParam::~AliMUONTrackParam()
61adb9bd 160{
de2cd600 161/// Destructor
208f139e 162 DeleteCovariances();
ea94c18b 163 delete fPropagator;
164 delete fExtrapParameters;
165 delete fExtrapCovariances;
166 delete fSmoothParameters;
167 delete fSmoothCovariances;
de2cd600 168}
169
170 //__________________________________________________________________________
ea94c18b 171void
172AliMUONTrackParam::Clear(Option_t* /*opt*/)
173{
174 /// Delete the covariance matrix
175 DeleteCovariances();
176 delete fPropagator; fPropagator = 0x0;
177 delete fExtrapParameters; fExtrapParameters = 0x0;
178 delete fExtrapCovariances; fExtrapCovariances = 0x0;
179 delete fSmoothParameters; fSmoothParameters = 0x0;
180 delete fSmoothCovariances; fSmoothCovariances = 0x0;
de2cd600 181}
54d7ba50 182
de2cd600 183 //__________________________________________________________________________
184AliMUONHitForRec* AliMUONTrackParam::GetHitForRecPtr(void) const
185{
186/// return pointer to HitForRec attached to the current TrackParam
187/// this method should not be called when fHitForRecPtr == NULL
208f139e 188 if (!fHitForRecPtr) AliWarning("fHitForRecPtr == NULL");
de2cd600 189 return fHitForRecPtr;
190}
191
211c52eb 192 //_________________________________________________________________________
193void AliMUONTrackParam::GetParamFrom(const AliESDMuonTrack& esdMuonTrack)
194{
2457f726 195 /// assigned value form ESD track.
ea94c18b 196 fZ = esdMuonTrack.GetZ();
197 fParameters(0,0) = esdMuonTrack.GetNonBendingCoor();
198 fParameters(1,0) = TMath::Tan(esdMuonTrack.GetThetaX());
199 fParameters(2,0) = esdMuonTrack.GetBendingCoor();
200 fParameters(3,0) = TMath::Tan(esdMuonTrack.GetThetaY());
201 fParameters(4,0) = esdMuonTrack.GetInverseBendingMomentum();
211c52eb 202}
203
204 //_________________________________________________________________________
ea94c18b 205void AliMUONTrackParam::SetParamFor(AliESDMuonTrack& esdMuonTrack) const
211c52eb 206{
2457f726 207 /// assigned value form ESD track.
ea94c18b 208 esdMuonTrack.SetZ(fZ);
209 esdMuonTrack.SetNonBendingCoor(fParameters(0,0));
210 esdMuonTrack.SetThetaX(TMath::ATan(fParameters(1,0)));
211 esdMuonTrack.SetBendingCoor(fParameters(2,0));
212 esdMuonTrack.SetThetaY(TMath::ATan(fParameters(3,0)));
213 esdMuonTrack.SetInverseBendingMomentum(fParameters(4,0));
211c52eb 214}
215
22ccc301 216 //_________________________________________________________________________
217void AliMUONTrackParam::GetParamFromUncorrected(const AliESDMuonTrack& esdMuonTrack)
218{
219 /// assigned value form ESD track.
ea94c18b 220 fZ = esdMuonTrack.GetZUncorrected();
221 fParameters(0,0) = esdMuonTrack.GetNonBendingCoorUncorrected();
222 fParameters(1,0) = TMath::Tan(esdMuonTrack.GetThetaXUncorrected());
223 fParameters(2,0) = esdMuonTrack.GetBendingCoorUncorrected();
224 fParameters(3,0) = TMath::Tan(esdMuonTrack.GetThetaYUncorrected());
225 fParameters(4,0) = esdMuonTrack.GetInverseBendingMomentumUncorrected();
22ccc301 226}
227
228 //_________________________________________________________________________
ea94c18b 229void AliMUONTrackParam::SetParamForUncorrected(AliESDMuonTrack& esdMuonTrack) const
22ccc301 230{
231 /// assigned value form ESD track.
ea94c18b 232 esdMuonTrack.SetZUncorrected(fZ);
233 esdMuonTrack.SetNonBendingCoorUncorrected(fParameters(0,0));
234 esdMuonTrack.SetThetaXUncorrected(TMath::ATan(fParameters(1,0)));
235 esdMuonTrack.SetBendingCoorUncorrected(fParameters(2,0));
236 esdMuonTrack.SetThetaYUncorrected(TMath::ATan(fParameters(3,0)));
237 esdMuonTrack.SetInverseBendingMomentumUncorrected(fParameters(4,0));
22ccc301 238}
239
a9e2aefa 240 //__________________________________________________________________________
6464217e 241Double_t AliMUONTrackParam::Px() const
b8dc484b 242{
22ccc301 243 /// return p_x from track parameters
b8dc484b 244 Double_t pYZ, pZ, pX;
245 pYZ = 0;
ea94c18b 246 if ( TMath::Abs(fParameters(4,0)) > 0 )
247 pYZ = TMath::Abs(1.0 / fParameters(4,0));
248 pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0))); // spectro. (z<0)
249 pX = pZ * fParameters(1,0);
b8dc484b 250 return pX;
251}
37827b29 252
b8dc484b 253 //__________________________________________________________________________
6464217e 254Double_t AliMUONTrackParam::Py() const
b8dc484b 255{
22ccc301 256 /// return p_y from track parameters
b8dc484b 257 Double_t pYZ, pZ, pY;
258 pYZ = 0;
ea94c18b 259 if ( TMath::Abs(fParameters(4,0)) > 0 )
260 pYZ = TMath::Abs(1.0 / fParameters(4,0));
261 pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0))); // spectro. (z<0)
262 pY = pZ * fParameters(3,0);
b8dc484b 263 return pY;
264}
37827b29 265
b8dc484b 266 //__________________________________________________________________________
6464217e 267Double_t AliMUONTrackParam::Pz() const
b8dc484b 268{
22ccc301 269 /// return p_z from track parameters
b8dc484b 270 Double_t pYZ, pZ;
271 pYZ = 0;
ea94c18b 272 if ( TMath::Abs(fParameters(4,0)) > 0 )
273 pYZ = TMath::Abs(1.0 / fParameters(4,0));
274 pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0))); // spectro. (z<0)
b8dc484b 275 return pZ;
276}
37827b29 277
b8dc484b 278 //__________________________________________________________________________
6464217e 279Double_t AliMUONTrackParam::P() const
b8dc484b 280{
22ccc301 281 /// return p from track parameters
b8dc484b 282 Double_t pYZ, pZ, p;
283 pYZ = 0;
ea94c18b 284 if ( TMath::Abs(fParameters(4,0)) > 0 )
285 pYZ = TMath::Abs(1.0 / fParameters(4,0));
286 pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0))); // spectro. (z<0)
b8dc484b 287 p = TMath::Abs(pZ) *
ea94c18b 288 TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
b8dc484b 289 return p;
290
291}
4d03a78e 292
208f139e 293 //__________________________________________________________________________
ea94c18b 294const TMatrixD& AliMUONTrackParam::GetCovariances() const
208f139e 295{
296 /// Return the covariance matrix (create it before if needed)
297 if (!fCovariances) {
298 fCovariances = new TMatrixD(5,5);
ea94c18b 299 fCovariances->Zero();
208f139e 300 }
ea94c18b 301 return *fCovariances;
302}
208f139e 303
304 //__________________________________________________________________________
ea94c18b 305void AliMUONTrackParam::SetCovariances(const TMatrixD& covariances)
208f139e 306{
307 /// Set the covariance matrix
ea94c18b 308 if (fCovariances) *fCovariances = covariances;
309 else fCovariances = new TMatrixD(covariances);
208f139e 310}
311
312 //__________________________________________________________________________
ea94c18b 313void AliMUONTrackParam::SetCovariances(const Double_t matrix[5][5])
208f139e 314{
315 /// Set the covariance matrix
316 if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
317 else fCovariances = new TMatrixD(5,5,&(matrix[0][0]));
318}
319
320 //__________________________________________________________________________
ea94c18b 321void AliMUONTrackParam::SetVariances(const Double_t matrix[5][5])
208f139e 322{
323 /// Set the diagonal terms of the covariance matrix (variances)
324 if (!fCovariances) fCovariances = new TMatrixD(5,5);
ea94c18b 325 fCovariances->Zero();
208f139e 326 for (Int_t i=0; i<5; i++) (*fCovariances)(i,i) = matrix[i][i];
327}
328
329 //__________________________________________________________________________
330void AliMUONTrackParam::DeleteCovariances()
331{
332 /// Delete the covariance matrix
686772dc 333 delete fCovariances;
208f139e 334 fCovariances = 0x0;
335}
336
337 //__________________________________________________________________________
ea94c18b 338const TMatrixD& AliMUONTrackParam::GetPropagator() const
208f139e 339{
ea94c18b 340 /// Return the propagator (create it before if needed)
341 if (!fPropagator) {
342 fPropagator = new TMatrixD(5,5);
019df241 343 fPropagator->UnitMatrix();
208f139e 344 }
ea94c18b 345 return *fPropagator;
346 }
347
348 //__________________________________________________________________________
349void AliMUONTrackParam::ResetPropagator()
350{
351 /// Reset the propagator
019df241 352 if (fPropagator) fPropagator->UnitMatrix();
ea94c18b 353}
354
355 //__________________________________________________________________________
356void AliMUONTrackParam::UpdatePropagator(const TMatrixD& propagator)
357{
358 /// Update the propagator
ea94c18b 359 if (fPropagator) *fPropagator = TMatrixD(propagator,TMatrixD::kMult,*fPropagator);
360 else fPropagator = new TMatrixD(propagator);
361}
362
363 //__________________________________________________________________________
364const TMatrixD& AliMUONTrackParam::GetExtrapParameters() const
365{
366 /// Return extrapolated parameters (create it before if needed)
367 if (!fExtrapParameters) {
368 fExtrapParameters = new TMatrixD(5,1);
369 fExtrapParameters->Zero();
370 }
371 return *fExtrapParameters;
372 }
373
374 //__________________________________________________________________________
375void AliMUONTrackParam::SetExtrapParameters(const TMatrixD& extrapParameters)
376{
377 /// Set extrapolated parameters
ea94c18b 378 if (fExtrapParameters) *fExtrapParameters = extrapParameters;
379 else fExtrapParameters = new TMatrixD(extrapParameters);
380}
381
382 //__________________________________________________________________________
383const TMatrixD& AliMUONTrackParam::GetExtrapCovariances() const
384{
385 /// Return the extrapolated covariance matrix (create it before if needed)
386 if (!fExtrapCovariances) {
387 fExtrapCovariances = new TMatrixD(5,5);
388 fExtrapCovariances->Zero();
389 }
390 return *fExtrapCovariances;
391 }
392
393 //__________________________________________________________________________
394void AliMUONTrackParam::SetExtrapCovariances(const TMatrixD& extrapCovariances)
395{
396 /// Set the extrapolated covariance matrix
ea94c18b 397 if (fExtrapCovariances) *fExtrapCovariances = extrapCovariances;
398 else fExtrapCovariances = new TMatrixD(extrapCovariances);
399}
400
401 //__________________________________________________________________________
402const TMatrixD& AliMUONTrackParam::GetSmoothParameters() const
403{
404 /// Return the smoothed parameters (create it before if needed)
405 if (!fSmoothParameters) {
406 fSmoothParameters = new TMatrixD(5,1);
407 fSmoothParameters->Zero();
408 }
409 return *fSmoothParameters;
410 }
411
412 //__________________________________________________________________________
413void AliMUONTrackParam::SetSmoothParameters(const TMatrixD& smoothParameters)
414{
415 /// Set the smoothed parameters
ea94c18b 416 if (fSmoothParameters) *fSmoothParameters = smoothParameters;
417 else fSmoothParameters = new TMatrixD(smoothParameters);
418}
419
420 //__________________________________________________________________________
421const TMatrixD& AliMUONTrackParam::GetSmoothCovariances() const
422{
423 /// Return the smoothed covariance matrix (create it before if needed)
424 if (!fSmoothCovariances) {
425 fSmoothCovariances = new TMatrixD(5,5);
426 fSmoothCovariances->Zero();
427 }
428 return *fSmoothCovariances;
429 }
430
431 //__________________________________________________________________________
432void AliMUONTrackParam::SetSmoothCovariances(const TMatrixD& smoothCovariances)
433{
434 /// Set the smoothed covariance matrix
ea94c18b 435 if (fSmoothCovariances) *fSmoothCovariances = smoothCovariances;
436 else fSmoothCovariances = new TMatrixD(smoothCovariances);
208f139e 437}
438
439 //__________________________________________________________________________
440Int_t AliMUONTrackParam::Compare(const TObject* trackParam) const
441{
442 /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
443 /// Returns 1 (0, -1) if Z of current TrackHit
444 /// is smaller than (equal to, larger than) Z of TrackHit
847cbaef 445 if (fHitForRecPtr) {
446 if (fHitForRecPtr->GetZ() != fZ)
447 AliWarning("track parameters are given at a different z position than the one of the corresponding hit");
448 }
449 if (fZ < ((AliMUONTrackParam*)trackParam)->GetZ()) return(1);
450 else if (fZ == ((AliMUONTrackParam*)trackParam)->GetZ()) return(0);
208f139e 451 else return(-1);
452}
453
6464217e 454//_____________________________________________-
455void AliMUONTrackParam::Print(Option_t* opt) const
456{
2457f726 457 /// Printing TrackParam information
458 /// "full" option for printing all the information about the TrackParam
6464217e 459 TString sopt(opt);
460 sopt.ToUpper();
461
462 if ( sopt.Contains("FULL") ) {
ea94c18b 463 cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3) << 1./fParameters(4,0) <<
464 ", NonBendSlope=" << setw(5) << setprecision(3) << fParameters(1,0)*180./TMath::Pi() <<
465 ", BendSlope=" << setw(5) << setprecision(3) << fParameters(3,0)*180./TMath::Pi() <<
466 ", (x,y,z)_IP=(" << setw(5) << setprecision(3) << fParameters(0,0) <<
467 "," << setw(5) << setprecision(3) << fParameters(2,0) <<
468 "," << setw(5) << setprecision(3) << fZ <<
6464217e 469 ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
470 "," << setw(5) << setprecision(3) << Py() <<
471 "," << setw(5) << setprecision(3) << Pz() << ") GeV/c" << endl;
472 }
473 else {
474 cout << "<AliMUONTrackParam>" << endl;
475 }
476
477}