Adding missing include
[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
34#include <Riostream.h>
35#include <TMath.h>
36#include <TMatrixD.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 fNonBendingCoor(0.),
54d7ba50 46 fNonBendingSlope(0.),
54d7ba50 47 fBendingCoor(0.),
208f139e 48 fBendingSlope(0.),
49 fInverseBendingMomentum(0.),
50 fZ(0.),
51 fCovariances(0x0),
de2cd600 52 fHitForRecPtr(0x0)
30178c30 53{
37827b29 54 /// Constructor
30178c30 55}
61adb9bd 56
30178c30 57 //_________________________________________________________________________
de2cd600 58AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
59 : TObject(theMUONTrackParam),
208f139e 60 fNonBendingCoor(theMUONTrackParam.fNonBendingCoor),
de2cd600 61 fNonBendingSlope(theMUONTrackParam.fNonBendingSlope),
de2cd600 62 fBendingCoor(theMUONTrackParam.fBendingCoor),
208f139e 63 fBendingSlope(theMUONTrackParam.fBendingSlope),
64 fInverseBendingMomentum(theMUONTrackParam.fInverseBendingMomentum),
65 fZ(theMUONTrackParam.fZ),
66 fCovariances(0x0),
de2cd600 67 fHitForRecPtr(theMUONTrackParam.fHitForRecPtr)
68{
2457f726 69 /// Copy constructor
208f139e 70 if (theMUONTrackParam.fCovariances) fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
de2cd600 71}
72
73 //_________________________________________________________________________
74AliMUONTrackParam& AliMUONTrackParam::operator=(const AliMUONTrackParam& theMUONTrackParam)
61adb9bd 75{
2457f726 76 /// Asignment operator
30178c30 77 if (this == &theMUONTrackParam)
61adb9bd 78 return *this;
79
30178c30 80 // base class assignement
81 TObject::operator=(theMUONTrackParam);
82
208f139e 83 fNonBendingCoor = theMUONTrackParam.fNonBendingCoor;
84 fNonBendingSlope = theMUONTrackParam.fNonBendingSlope;
85 fBendingCoor = theMUONTrackParam.fBendingCoor;
86 fBendingSlope = theMUONTrackParam.fBendingSlope;
87 fInverseBendingMomentum = theMUONTrackParam.fInverseBendingMomentum;
88 fZ = theMUONTrackParam.fZ;
89
90 if (theMUONTrackParam.fCovariances) {
91 if (fCovariances) *fCovariances = *(theMUONTrackParam.fCovariances);
92 else fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
93 } else if (fCovariances) {
94 delete fCovariances;
95 fCovariances = 0x0;
96 }
97
61adb9bd 98 return *this;
99}
de2cd600 100
101 //__________________________________________________________________________
102AliMUONTrackParam::~AliMUONTrackParam()
61adb9bd 103{
de2cd600 104/// Destructor
208f139e 105 DeleteCovariances();
de2cd600 106}
107
108 //__________________________________________________________________________
109void AliMUONTrackParam::SetTrackParam(AliMUONTrackParam& theMUONTrackParam)
110{
208f139e 111 /// Set track parameters from "TrackParam" leaving pointer to fHitForRecPtr and parameter covariances unchanged
112 fNonBendingCoor = theMUONTrackParam.fNonBendingCoor;
113 fNonBendingSlope = theMUONTrackParam.fNonBendingSlope;
114 fBendingCoor = theMUONTrackParam.fBendingCoor;
115 fBendingSlope = theMUONTrackParam.fBendingSlope;
116 fInverseBendingMomentum = theMUONTrackParam.fInverseBendingMomentum;
117 fZ = theMUONTrackParam.fZ;
de2cd600 118}
54d7ba50 119
de2cd600 120 //__________________________________________________________________________
121AliMUONHitForRec* AliMUONTrackParam::GetHitForRecPtr(void) const
122{
123/// return pointer to HitForRec attached to the current TrackParam
124/// this method should not be called when fHitForRecPtr == NULL
208f139e 125 if (!fHitForRecPtr) AliWarning("fHitForRecPtr == NULL");
de2cd600 126 return fHitForRecPtr;
127}
128
211c52eb 129 //_________________________________________________________________________
130void AliMUONTrackParam::GetParamFrom(const AliESDMuonTrack& esdMuonTrack)
131{
2457f726 132 /// assigned value form ESD track.
208f139e 133 fInverseBendingMomentum = esdMuonTrack.GetInverseBendingMomentum();
134 fBendingSlope = TMath::Tan(esdMuonTrack.GetThetaY());
135 fNonBendingSlope = TMath::Tan(esdMuonTrack.GetThetaX());
136 fZ = esdMuonTrack.GetZ();
137 fBendingCoor = esdMuonTrack.GetBendingCoor();
138 fNonBendingCoor = esdMuonTrack.GetNonBendingCoor();
211c52eb 139}
140
141 //_________________________________________________________________________
142void AliMUONTrackParam::SetParamFor(AliESDMuonTrack& esdMuonTrack)
143{
2457f726 144 /// assigned value form ESD track.
211c52eb 145 esdMuonTrack.SetInverseBendingMomentum(fInverseBendingMomentum);
146 esdMuonTrack.SetThetaX(TMath::ATan(fNonBendingSlope));
147 esdMuonTrack.SetThetaY(TMath::ATan(fBendingSlope));
148 esdMuonTrack.SetZ(fZ);
149 esdMuonTrack.SetBendingCoor(fBendingCoor);
150 esdMuonTrack.SetNonBendingCoor(fNonBendingCoor);
151}
152
22ccc301 153 //_________________________________________________________________________
154void AliMUONTrackParam::GetParamFromUncorrected(const AliESDMuonTrack& esdMuonTrack)
155{
156 /// assigned value form ESD track.
157 fInverseBendingMomentum = esdMuonTrack.GetInverseBendingMomentumUncorrected();
158 fBendingSlope = TMath::Tan(esdMuonTrack.GetThetaYUncorrected());
159 fNonBendingSlope = TMath::Tan(esdMuonTrack.GetThetaXUncorrected());
160 fZ = esdMuonTrack.GetZUncorrected();
161 fBendingCoor = esdMuonTrack.GetBendingCoorUncorrected();
162 fNonBendingCoor = esdMuonTrack.GetNonBendingCoorUncorrected();
163}
164
165 //_________________________________________________________________________
166void AliMUONTrackParam::SetParamForUncorrected(AliESDMuonTrack& esdMuonTrack)
167{
168 /// assigned value form ESD track.
169 esdMuonTrack.SetInverseBendingMomentumUncorrected(fInverseBendingMomentum);
170 esdMuonTrack.SetThetaXUncorrected(TMath::ATan(fNonBendingSlope));
171 esdMuonTrack.SetThetaYUncorrected(TMath::ATan(fBendingSlope));
172 esdMuonTrack.SetZUncorrected(fZ);
173 esdMuonTrack.SetBendingCoorUncorrected(fBendingCoor);
174 esdMuonTrack.SetNonBendingCoorUncorrected(fNonBendingCoor);
175}
176
a9e2aefa 177 //__________________________________________________________________________
6464217e 178Double_t AliMUONTrackParam::Px() const
b8dc484b 179{
22ccc301 180 /// return p_x from track parameters
b8dc484b 181 Double_t pYZ, pZ, pX;
182 pYZ = 0;
183 if ( TMath::Abs(fInverseBendingMomentum) > 0 )
184 pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
185 pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); // spectro. (z<0)
186 pX = pZ * fNonBendingSlope;
187 return pX;
188}
37827b29 189
b8dc484b 190 //__________________________________________________________________________
6464217e 191Double_t AliMUONTrackParam::Py() const
b8dc484b 192{
22ccc301 193 /// return p_y from track parameters
b8dc484b 194 Double_t pYZ, pZ, pY;
195 pYZ = 0;
196 if ( TMath::Abs(fInverseBendingMomentum) > 0 )
197 pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
198 pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); // spectro. (z<0)
199 pY = pZ * fBendingSlope;
200 return pY;
201}
37827b29 202
b8dc484b 203 //__________________________________________________________________________
6464217e 204Double_t AliMUONTrackParam::Pz() const
b8dc484b 205{
22ccc301 206 /// return p_z from track parameters
b8dc484b 207 Double_t pYZ, pZ;
208 pYZ = 0;
209 if ( TMath::Abs(fInverseBendingMomentum) > 0 )
210 pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
211 pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); // spectro. (z<0)
212 return pZ;
213}
37827b29 214
b8dc484b 215 //__________________________________________________________________________
6464217e 216Double_t AliMUONTrackParam::P() const
b8dc484b 217{
22ccc301 218 /// return p from track parameters
b8dc484b 219 Double_t pYZ, pZ, p;
220 pYZ = 0;
221 if ( TMath::Abs(fInverseBendingMomentum) > 0 )
222 pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
223 pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope)); // spectro. (z<0)
224 p = TMath::Abs(pZ) *
225 TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope + fNonBendingSlope * fNonBendingSlope);
226 return p;
227
228}
4d03a78e 229
208f139e 230 //__________________________________________________________________________
686772dc 231TMatrixD* AliMUONTrackParam::GetCovariances() const
208f139e 232{
233 /// Return the covariance matrix (create it before if needed)
234 if (!fCovariances) {
235 fCovariances = new TMatrixD(5,5);
236 (*fCovariances) = 0;
237 }
238 return fCovariances;
239 }
240
241 //__________________________________________________________________________
242void AliMUONTrackParam::SetCovariances(TMatrixD* covariances)
243{
244 /// Set the covariance matrix
245 if (covariances == fCovariances) return; // nothing to be done
246 if (fCovariances) *fCovariances = *covariances;
247 else fCovariances = new TMatrixD(*covariances);
248}
249
250 //__________________________________________________________________________
251void AliMUONTrackParam::SetCovariances(Double_t matrix[5][5])
252{
253 /// Set the covariance matrix
254 if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
255 else fCovariances = new TMatrixD(5,5,&(matrix[0][0]));
256}
257
258 //__________________________________________________________________________
259void AliMUONTrackParam::SetVariances(Double_t matrix[5][5])
260{
261 /// Set the diagonal terms of the covariance matrix (variances)
262 if (!fCovariances) fCovariances = new TMatrixD(5,5);
263 (*fCovariances) = 0;
264 for (Int_t i=0; i<5; i++) (*fCovariances)(i,i) = matrix[i][i];
265}
266
686772dc 267//__________________________________________________________________________
268void
269AliMUONTrackParam::Clear(Option_t* /*opt*/)
270{
271 /// Delete the covariance matrix
272 DeleteCovariances();
273}
274
208f139e 275 //__________________________________________________________________________
276void AliMUONTrackParam::DeleteCovariances()
277{
278 /// Delete the covariance matrix
686772dc 279 delete fCovariances;
208f139e 280 fCovariances = 0x0;
281}
282
283 //__________________________________________________________________________
284void AliMUONTrackParam::EvalCovariances(AliMUONHitForRec* hit2)
285{
286 /// Evaluate covariances assuming the track is only a straight line
287 /// between the HitForRec attached to the current TrackParam and hit2.
288 /// Nothing can be done on fInverseBendingMomentum (-> 50% err).
289
290 // Allocate memory if needed
291 if (!fCovariances) fCovariances = new TMatrixD(5,5);
292
293 // Reset the covariance matrix
294 (*fCovariances) = 0;
295
296 if (!fHitForRecPtr) {
297 AliWarning("fHitForRecPtr == NULL: cannot calculate TrackParam covariances");
298 return;
299 }
300
301 Double_t dz = fHitForRecPtr->GetZ() - hit2->GetZ();
302
303 // Non bending plane
304 (*fCovariances)(0,0) = fHitForRecPtr->GetNonBendingReso2();
305 (*fCovariances)(0,1) = fHitForRecPtr->GetNonBendingReso2() / dz;
306 (*fCovariances)(1,0) = (*fCovariances)(0,1);
307 (*fCovariances)(1,1) = ( fHitForRecPtr->GetNonBendingReso2() + hit2->GetNonBendingReso2() ) / dz / dz;
308 // Bending plane
309 (*fCovariances)(2,2) = fHitForRecPtr->GetBendingReso2();
310 (*fCovariances)(2,3) = fHitForRecPtr->GetBendingReso2() / dz;
311 (*fCovariances)(3,2) = (*fCovariances)(2,3);
312 (*fCovariances)(3,3) = ( fHitForRecPtr->GetBendingReso2() + hit2->GetBendingReso2() ) / dz / dz;
313 // Inverse bending momentum
314 (*fCovariances)(4,4) = 0.5*fInverseBendingMomentum * 0.5*fInverseBendingMomentum; // error 50%
315
316}
317
318 //__________________________________________________________________________
319Int_t AliMUONTrackParam::Compare(const TObject* trackParam) const
320{
321 /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
322 /// Returns 1 (0, -1) if Z of current TrackHit
323 /// is smaller than (equal to, larger than) Z of TrackHit
847cbaef 324 if (fHitForRecPtr) {
325 if (fHitForRecPtr->GetZ() != fZ)
326 AliWarning("track parameters are given at a different z position than the one of the corresponding hit");
327 }
328 if (fZ < ((AliMUONTrackParam*)trackParam)->GetZ()) return(1);
329 else if (fZ == ((AliMUONTrackParam*)trackParam)->GetZ()) return(0);
208f139e 330 else return(-1);
331}
332
6464217e 333//_____________________________________________-
334void AliMUONTrackParam::Print(Option_t* opt) const
335{
2457f726 336 /// Printing TrackParam information
337 /// "full" option for printing all the information about the TrackParam
6464217e 338 TString sopt(opt);
339 sopt.ToUpper();
340
341 if ( sopt.Contains("FULL") ) {
342 cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3) << 1./GetInverseBendingMomentum() <<
343 ", NonBendSlope=" << setw(5) << setprecision(3) << GetNonBendingSlope()*180./TMath::Pi() <<
344 ", BendSlope=" << setw(5) << setprecision(3) << GetBendingSlope()*180./TMath::Pi() <<
345 ", (x,y,z)_IP=(" << setw(5) << setprecision(3) << GetNonBendingCoor() <<
346 "," << setw(5) << setprecision(3) << GetBendingCoor() <<
347 "," << setw(5) << setprecision(3) << GetZ() <<
348 ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
349 "," << setw(5) << setprecision(3) << Py() <<
350 "," << setw(5) << setprecision(3) << Pz() << ") GeV/c" << endl;
351 }
352 else {
353 cout << "<AliMUONTrackParam>" << endl;
354 }
355
356}