]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackParam.cxx
Updated serial number for station 345
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackParam.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-----------------------------------------------------------------------------
19 // Class AliMUONTrackParam
20 //-------------------------
21 // Track parameters in ALICE dimuon spectrometer
22 //-----------------------------------------------------------------------------
23
24 #include "AliMUONTrackParam.h"
25 #include "AliMUONVCluster.h"
26
27 #include "AliLog.h"
28
29 #include <TMath.h>
30
31 #include <Riostream.h>
32
33 /// \cond CLASSIMP
34 ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
35 /// \endcond
36
37   //_________________________________________________________________________
38 AliMUONTrackParam::AliMUONTrackParam()
39   : TObject(),
40     fZ(0.),
41     fParameters(5,1),
42     fCovariances(0x0),
43     fPropagator(0x0),
44     fExtrapParameters(0x0),
45     fExtrapCovariances(0x0),
46     fSmoothParameters(0x0),
47     fSmoothCovariances(0x0),
48     fClusterPtr(0x0),
49     fOwnCluster(kFALSE),
50     fRemovable(kFALSE),
51     fTrackChi2(0.),
52     fLocalChi2(0.)
53 {
54   /// Constructor
55 }
56
57   //_________________________________________________________________________
58 AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
59   : TObject(theMUONTrackParam),
60     fZ(theMUONTrackParam.fZ),
61     fParameters(theMUONTrackParam.fParameters),
62     fCovariances(0x0),
63     fPropagator(0x0),
64     fExtrapParameters(0x0),
65     fExtrapCovariances(0x0),
66     fSmoothParameters(0x0),
67     fSmoothCovariances(0x0),
68     fClusterPtr(0x0),
69     fOwnCluster(theMUONTrackParam.fOwnCluster),
70     fRemovable(theMUONTrackParam.fRemovable),
71     fTrackChi2(theMUONTrackParam.fTrackChi2),
72     fLocalChi2(theMUONTrackParam.fLocalChi2)
73 {
74   /// Copy constructor
75   if (theMUONTrackParam.fCovariances) fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
76   if (theMUONTrackParam.fPropagator) fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
77   if (theMUONTrackParam.fExtrapParameters) fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
78   if (theMUONTrackParam.fExtrapCovariances) fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
79   if (theMUONTrackParam.fSmoothParameters) fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
80   if (theMUONTrackParam.fSmoothCovariances) fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
81   
82   if(fOwnCluster) fClusterPtr = static_cast<AliMUONVCluster*>(theMUONTrackParam.fClusterPtr->Clone());
83   else fClusterPtr = theMUONTrackParam.fClusterPtr;
84 }
85
86   //_________________________________________________________________________
87 AliMUONTrackParam& AliMUONTrackParam::operator=(const AliMUONTrackParam& theMUONTrackParam)
88 {
89   /// Asignment operator
90   if (this == &theMUONTrackParam)
91     return *this;
92
93   // base class assignement
94   TObject::operator=(theMUONTrackParam);
95
96   fZ = theMUONTrackParam.fZ; 
97   
98   fParameters = theMUONTrackParam.fParameters;
99   
100   if (theMUONTrackParam.fCovariances) {
101     if (fCovariances) *fCovariances = *(theMUONTrackParam.fCovariances);
102     else fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
103   } else {
104     delete fCovariances;
105     fCovariances = 0x0;
106   }
107   
108   if (theMUONTrackParam.fPropagator) {
109     if (fPropagator) *fPropagator = *(theMUONTrackParam.fPropagator);
110     else fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
111   } else {
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));
119   } else {
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));
127   } else {
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));
135   } else {
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));
143   } else {
144     delete fSmoothCovariances;
145     fSmoothCovariances = 0x0;
146   }
147   
148   if (fOwnCluster) delete fClusterPtr;
149   fOwnCluster = theMUONTrackParam.fOwnCluster;
150   if(fOwnCluster) fClusterPtr = static_cast<AliMUONVCluster*>(theMUONTrackParam.fClusterPtr->Clone());
151   else fClusterPtr = theMUONTrackParam.fClusterPtr;
152   
153   fRemovable = theMUONTrackParam.fRemovable;
154   
155   fTrackChi2 = theMUONTrackParam.fTrackChi2;
156   fLocalChi2 = theMUONTrackParam.fLocalChi2;
157   
158   return *this;
159 }
160
161   //__________________________________________________________________________
162 AliMUONTrackParam::~AliMUONTrackParam()
163 {
164 /// Destructor
165   DeleteCovariances();
166   delete fPropagator;
167   delete fExtrapParameters;
168   delete fExtrapCovariances;
169   delete fSmoothParameters;
170   delete fSmoothCovariances;
171   if(fOwnCluster) delete fClusterPtr;
172 }
173
174   //__________________________________________________________________________
175 void
176 AliMUONTrackParam::Clear(Option_t* /*opt*/)
177 {
178   /// clear memory
179   DeleteCovariances();
180   delete fPropagator; fPropagator = 0x0;
181   delete fExtrapParameters; fExtrapParameters = 0x0;
182   delete fExtrapCovariances; fExtrapCovariances = 0x0;
183   delete fSmoothParameters; fSmoothParameters = 0x0;
184   delete fSmoothCovariances; fSmoothCovariances = 0x0;
185   if(fOwnCluster) {
186     delete fClusterPtr; fClusterPtr = 0x0;
187   }
188 }
189
190   //__________________________________________________________________________
191 Double_t AliMUONTrackParam::Px() const
192 {
193   /// return p_x from track parameters
194   Double_t pZ;
195   if (TMath::Abs(fParameters(4,0)) > 0) {
196     Double_t pYZ = (TMath::Abs(fParameters(4,0)) > 0) ? TMath::Abs(1.0 / fParameters(4,0)) : FLT_MAX;
197     pZ = - pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
198   } else {
199     pZ = - FLT_MAX / TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
200   }
201   return pZ * fParameters(1,0); 
202 }
203
204   //__________________________________________________________________________
205 Double_t AliMUONTrackParam::Py() const
206 {
207   /// return p_y from track parameters
208   Double_t pZ;
209   if (TMath::Abs(fParameters(4,0)) > 0) {
210     Double_t pYZ = (TMath::Abs(fParameters(4,0)) > 0) ? TMath::Abs(1.0 / fParameters(4,0)) : FLT_MAX;
211     pZ = - pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
212   } else {
213     pZ = - FLT_MAX / TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
214   }
215   return pZ * fParameters(3,0); 
216 }
217
218   //__________________________________________________________________________
219 Double_t AliMUONTrackParam::Pz() const
220 {
221   /// return p_z from track parameters
222   if (TMath::Abs(fParameters(4,0)) > 0) {
223     Double_t pYZ = TMath::Abs(1.0 / fParameters(4,0));
224     return - pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
225   } else return - FLT_MAX / TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
226 }
227
228   //__________________________________________________________________________
229 Double_t AliMUONTrackParam::P() const
230 {
231   /// return p from track parameters
232   if (TMath::Abs(fParameters(4,0)) > 0) {
233     Double_t pYZ = TMath::Abs(1.0 / fParameters(4,0));
234     Double_t pZ = - pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
235     return - pZ * TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
236   } else return FLT_MAX;
237 }
238
239   //__________________________________________________________________________
240 const TMatrixD& AliMUONTrackParam::GetCovariances() const
241 {
242   /// Return the covariance matrix (create it before if needed)
243   if (!fCovariances) {
244     fCovariances = new TMatrixD(5,5);
245     fCovariances->Zero();
246   }
247   return *fCovariances;
248 }
249
250   //__________________________________________________________________________
251 void AliMUONTrackParam::SetCovariances(const TMatrixD& covariances)
252 {
253   /// Set the covariance matrix
254   if (fCovariances) *fCovariances = covariances;
255   else fCovariances = new TMatrixD(covariances);
256 }
257
258   //__________________________________________________________________________
259 void AliMUONTrackParam::SetCovariances(const Double_t matrix[5][5])
260 {
261   /// Set the covariance matrix
262   if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
263   else fCovariances = new TMatrixD(5,5,&(matrix[0][0]));
264 }
265
266   //__________________________________________________________________________
267 void AliMUONTrackParam::SetVariances(const Double_t matrix[5][5])
268 {
269   /// Set the diagonal terms of the covariance matrix (variances)
270   if (!fCovariances) fCovariances = new TMatrixD(5,5);
271   fCovariances->Zero();
272   for (Int_t i=0; i<5; i++) (*fCovariances)(i,i) = matrix[i][i];
273 }
274
275   //__________________________________________________________________________
276 void AliMUONTrackParam::DeleteCovariances()
277 {
278   /// Delete the covariance matrix
279   delete fCovariances;
280   fCovariances = 0x0;
281 }
282
283   //__________________________________________________________________________
284 const TMatrixD& AliMUONTrackParam::GetPropagator() const
285 {
286   /// Return the propagator (create it before if needed)
287   if (!fPropagator) {
288     fPropagator = new TMatrixD(5,5);
289     fPropagator->UnitMatrix();
290   }
291   return *fPropagator;
292 }
293
294   //__________________________________________________________________________
295 void AliMUONTrackParam::ResetPropagator()
296 {
297   /// Reset the propagator
298   if (fPropagator) fPropagator->UnitMatrix();
299 }
300
301   //__________________________________________________________________________
302 void AliMUONTrackParam::UpdatePropagator(const TMatrixD& propagator)
303 {
304   /// Update the propagator
305   if (fPropagator) *fPropagator = TMatrixD(propagator,TMatrixD::kMult,*fPropagator);
306   else fPropagator = new TMatrixD(propagator);
307 }
308
309   //__________________________________________________________________________
310 const TMatrixD& AliMUONTrackParam::GetExtrapParameters() const
311 {
312   /// Return extrapolated parameters (create it before if needed)
313   if (!fExtrapParameters) {
314     fExtrapParameters = new TMatrixD(5,1);
315     fExtrapParameters->Zero();
316   }
317   return *fExtrapParameters;
318   }
319
320   //__________________________________________________________________________
321 void AliMUONTrackParam::SetExtrapParameters(const TMatrixD& extrapParameters)
322 {
323   /// Set extrapolated parameters
324   if (fExtrapParameters) *fExtrapParameters = extrapParameters;
325   else fExtrapParameters = new TMatrixD(extrapParameters);
326 }
327
328   //__________________________________________________________________________
329 const TMatrixD& AliMUONTrackParam::GetExtrapCovariances() const
330 {
331   /// Return the extrapolated covariance matrix (create it before if needed)
332   if (!fExtrapCovariances) {
333     fExtrapCovariances = new TMatrixD(5,5);
334     fExtrapCovariances->Zero();
335   }
336   return *fExtrapCovariances;
337   }
338
339   //__________________________________________________________________________
340 void AliMUONTrackParam::SetExtrapCovariances(const TMatrixD& extrapCovariances)
341 {
342   /// Set the extrapolated covariance matrix
343   if (fExtrapCovariances) *fExtrapCovariances = extrapCovariances;
344   else fExtrapCovariances = new TMatrixD(extrapCovariances);
345 }
346
347   //__________________________________________________________________________
348 const TMatrixD& AliMUONTrackParam::GetSmoothParameters() const
349 {
350   /// Return the smoothed parameters (create it before if needed)
351   if (!fSmoothParameters) {
352     fSmoothParameters = new TMatrixD(5,1);
353     fSmoothParameters->Zero();
354   }
355   return *fSmoothParameters;
356   }
357
358   //__________________________________________________________________________
359 void AliMUONTrackParam::SetSmoothParameters(const TMatrixD& smoothParameters)
360 {
361   /// Set the smoothed parameters
362   if (fSmoothParameters) *fSmoothParameters = smoothParameters;
363   else fSmoothParameters = new TMatrixD(smoothParameters);
364 }
365
366   //__________________________________________________________________________
367 const TMatrixD& AliMUONTrackParam::GetSmoothCovariances() const
368 {
369   /// Return the smoothed covariance matrix (create it before if needed)
370   if (!fSmoothCovariances) {
371     fSmoothCovariances = new TMatrixD(5,5);
372     fSmoothCovariances->Zero();
373   }
374   return *fSmoothCovariances;
375   }
376
377   //__________________________________________________________________________
378 void AliMUONTrackParam::SetSmoothCovariances(const TMatrixD& smoothCovariances)
379 {
380   /// Set the smoothed covariance matrix
381   if (fSmoothCovariances) *fSmoothCovariances = smoothCovariances;
382   else fSmoothCovariances = new TMatrixD(smoothCovariances);
383 }
384
385 //__________________________________________________________________________
386 void AliMUONTrackParam::SetClusterPtr(AliMUONVCluster* cluster, Bool_t owner)
387 {
388   /// set pointeur to associated cluster
389   if (fOwnCluster) delete fClusterPtr;
390   fClusterPtr = cluster;
391   fOwnCluster = owner;
392 }
393
394   //__________________________________________________________________________
395 Int_t AliMUONTrackParam::Compare(const TObject* trackParam) const
396 {
397   /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
398   /// Returns 1 (0, -1) if the current Z
399   /// is smaller than (equal to, larger than) Z of trackParam
400   if (fZ < ((AliMUONTrackParam*)trackParam)->GetZ()) return(1);
401   else if (fZ == ((AliMUONTrackParam*)trackParam)->GetZ()) return(0);
402   else return(-1);
403 }
404
405   //__________________________________________________________________________
406 Bool_t AliMUONTrackParam::CompatibleTrackParam(const AliMUONTrackParam &trackParam, Double_t sigma2Cut, Double_t &chi2) const
407 {
408   /// Return kTRUE if the two set of track parameters are compatible within sigma2Cut
409   /// Set chi2 to the compatible chi2 value
410   /// Note that parameter covariances must exist for at least one set of parameters
411   /// Note also that if parameters are not given at the same Z, results will be meaningless
412   
413   // reset chi2 value
414   chi2 = 0.;
415   
416   // ckeck covariance matrices
417   if (!fCovariances && !trackParam.fCovariances) {
418     AliError("Covariance matrix must exist for at least one set of parameters");
419     return kFALSE;
420   }
421   
422   Double_t maxChi2 = 5. * sigma2Cut * sigma2Cut; // 5 degrees of freedom
423   
424   // check Z parameters
425   if (fZ != trackParam.fZ)
426     AliWarning(Form("Parameters are given at different Z position (%le : %le): results are meaningless", fZ, trackParam.fZ));
427   
428   // compute the parameter residuals
429   TMatrixD deltaParam(fParameters, TMatrixD::kMinus, trackParam.fParameters);
430   
431   // build the error matrix
432   TMatrixD weight(5,5);
433   if (fCovariances) weight += *fCovariances;
434   if (trackParam.fCovariances) weight += *(trackParam.fCovariances);
435   
436   // invert the error matrix to get the parameter weights if possible
437   if (weight.Determinant() == 0) {
438     AliError("Cannot compute the compatibility chi2");
439     return kFALSE;
440   }
441   weight.Invert();
442   
443   // compute the compatibility chi2
444   TMatrixD tmp(deltaParam, TMatrixD::kTransposeMult, weight);
445   TMatrixD mChi2(tmp, TMatrixD::kMult, deltaParam);
446   
447   // set chi2 value
448   chi2 = mChi2(0,0);
449   
450   // check compatibility
451   if (chi2 > maxChi2) return kFALSE;
452   
453   return kTRUE;
454 }
455
456   //__________________________________________________________________________
457 void AliMUONTrackParam::Print(Option_t* opt) const
458 {
459   /// Printing TrackParam information 
460   /// "full" option for printing all the information about the TrackParam
461   TString sopt(opt);
462   sopt.ToUpper();
463  
464   if ( sopt.Contains("FULL") ) { 
465     cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3)  << 1./fParameters(4,0) << 
466       ", NonBendSlope=" << setw(5) << setprecision(3)  << fParameters(1,0)*180./TMath::Pi() <<
467       ", BendSlope=" << setw(5) << setprecision(3)     << fParameters(3,0)*180./TMath::Pi()  << 
468       ", (x,y,z)_IP=(" <<  setw(5) << setprecision(3) << fParameters(0,0) <<
469       "," <<  setw(5) << setprecision(3) << fParameters(2,0) <<
470       "," <<  setw(5) << setprecision(3) << fZ <<
471       ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
472       "," << setw(5) << setprecision(3) << Py() <<
473       "," << setw(5) << setprecision(3) << Pz() << ") GeV/c" << endl;
474   }
475   else {
476     cout << "<AliMUONTrackParam>"  << endl;
477   }
478     
479 }