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