1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //====================================================================================================================================================
18 // Description of an ALICE muon forward track, combining the information of the Muon Spectrometer and the Muon Forward Tracker
20 // Contact author: antonio.uras@cern.ch
22 //====================================================================================================================================================
25 #include "AliMUONTrack.h"
26 #include "AliMFTCluster.h"
27 #include "AliMUONVCluster.h"
28 #include "AliMUONTrackParam.h"
29 #include "AliMUONTrackExtrap.h"
30 #include "TClonesArray.h"
32 #include "TParticle.h"
33 #include "AliMuonForwardTrack.h"
34 #include "AliMFTConstants.h"
36 ClassImp(AliMuonForwardTrack)
38 //====================================================================================================================================================
40 AliMuonForwardTrack::AliMuonForwardTrack():
45 fNWrongClustersMC(-1),
49 // default constructor
51 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) fPlaneExists[iPlane] = kFALSE;
52 for (Int_t iParent=0; iParent<fgkNParentsMax; iParent++) {
53 fParentMCLabel[iParent] = -1;
54 fParentPDGCode[iParent] = 0;
56 fMFTClusters = new TClonesArray("AliMFTCluster");
60 //====================================================================================================================================================
62 AliMuonForwardTrack::AliMuonForwardTrack(AliMUONTrack *MUONTrack):
67 fNWrongClustersMC(-1),
71 SetMUONTrack(MUONTrack);
72 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) fPlaneExists[iPlane] = kFALSE;
73 for (Int_t iParent=0; iParent<fgkNParentsMax; iParent++) {
74 fParentMCLabel[iParent] = -1;
75 fParentPDGCode[iParent] = 0;
77 fMFTClusters = new TClonesArray("AliMFTCluster");
81 //====================================================================================================================================================
83 AliMuonForwardTrack::AliMuonForwardTrack(const AliMuonForwardTrack& track):
88 fNWrongClustersMC(track.fNWrongClustersMC),
89 fTrackMCId(track.fTrackMCId)
93 fMUONTrack = new AliMUONTrack(*(track.fMUONTrack));
94 if (track.fMCTrackRef) fMCTrackRef = new TParticle(*(track.fMCTrackRef));
95 fMFTClusters = new TClonesArray(*(track.fMFTClusters));
96 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) fPlaneExists[iPlane] = (track.fPlaneExists)[iPlane];
97 for (Int_t iParent=0; iParent<fgkNParentsMax; iParent++) {
98 fParentMCLabel[iParent] = (track.fParentMCLabel)[iParent];
99 fParentPDGCode[iParent] = (track.fParentPDGCode)[iParent];
104 //====================================================================================================================================================
106 AliMuonForwardTrack& AliMuonForwardTrack::operator=(const AliMuonForwardTrack& track) {
108 // Asignment operator
110 // check assignement to self
111 if (this == &track) return *this;
113 // base class assignement
114 AliMUONTrack::operator=(track);
119 fMUONTrack = new AliMUONTrack(*(track.fMUONTrack));
120 if (track.fMCTrackRef) fMCTrackRef = new TParticle(*(track.fMCTrackRef));
121 fMFTClusters = new TClonesArray(*(track.fMFTClusters));
122 fNWrongClustersMC = track.fNWrongClustersMC;
123 fTrackMCId = track.fTrackMCId;
125 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) fPlaneExists[iPlane] = (track.fPlaneExists)[iPlane];
126 for (Int_t iParent=0; iParent<fgkNParentsMax; iParent++) {
127 fParentMCLabel[iParent] = (track.fParentMCLabel)[iParent];
128 fParentPDGCode[iParent] = (track.fParentPDGCode)[iParent];
135 //====================================================================================================================================================
137 AliMuonForwardTrack::~AliMuonForwardTrack() {
145 //====================================================================================================================================================
147 void AliMuonForwardTrack::SetMUONTrack(AliMUONTrack *MUONTrack) {
150 AliInfo("fMUONTrack already exists, nothing will be done");
154 fMUONTrack = MUONTrack;
155 SetGlobalChi2(fMUONTrack->GetGlobalChi2());
159 //====================================================================================================================================================
161 void AliMuonForwardTrack::SetMCTrackRef(TParticle *MCTrackRef) {
164 AliInfo("fMCTrackRef already exists, nothing will be done");
168 fMCTrackRef = MCTrackRef;
172 //====================================================================================================================================================
174 void AliMuonForwardTrack::AddTrackParamAtMFTCluster(AliMUONTrackParam &trackParam, AliMFTCluster &mftCluster) {
176 AliDebug(1, Form("Before adding: this->fMFTClusters=%p has %d entries", this->fMFTClusters, this->fMFTClusters->GetEntries()));
177 Int_t iMFTCluster = this->fMFTClusters->GetEntries();
178 AliDebug(1, Form("mftCluster->GetX() = %f mftCluster->GetY() = %f mftCluster->GetErrX() = %f cmftCluster->GetErrY() = %f",
179 mftCluster.GetX(), mftCluster.GetY(), mftCluster.GetErrX(), mftCluster.GetErrY()));
180 AliMUONVCluster *muonCluster = (AliMUONVCluster*) mftCluster.CreateMUONCluster();
181 AliDebug(1, Form("Created MUON cluster %p", muonCluster));
182 trackParam.SetUniqueID(iMFTCluster); // we profit of this slot to store the reference to the corresponding MFTCluster
183 AliDebug(1, Form("Now adding muonCluster %p and trackParam %p",muonCluster, &trackParam));
184 AddTrackParamAtCluster(trackParam, *muonCluster, kTRUE);
185 // we pass the parameters this->GetTrackParamAtCluster()->First() to the Kalman Filter algorithm: they will be updated!!
186 Double_t chi2Kalman = RunKalmanFilter(*(AliMUONTrackParam*)(GetTrackParamAtCluster()->First()));
187 AliDebug(1, Form("Adding Kalman chi2 = %f to global chi2 = %f", chi2Kalman, GetGlobalChi2()));
188 Double_t newGlobalChi2 = GetGlobalChi2() + chi2Kalman;
189 mftCluster.SetLocalChi2(chi2Kalman);
190 mftCluster.SetTrackChi2(newGlobalChi2);
191 new ((*(this->fMFTClusters))[iMFTCluster]) AliMFTCluster(mftCluster);
192 AliDebug(1, Form("GetTrackParamAtCluster() = %p has %d entries while this->fMFTClusters=%p has %d entries",
193 GetTrackParamAtCluster(), GetTrackParamAtCluster()->GetEntries(), this->fMFTClusters, this->fMFTClusters->GetEntries()));
194 AliDebug(1, Form("muonCluster->GetZ() = %f, trackParam->GetZ() = %f",muonCluster->GetZ(), trackParam.GetZ()));
195 SetGlobalChi2(newGlobalChi2);
196 AliDebug(1, Form("New global chi2 = %f", GetGlobalChi2()));
197 ((AliMUONTrackParam*) GetTrackParamAtCluster()->First())->SetTrackChi2(newGlobalChi2);
198 for (Int_t iPar=0; iPar<GetTrackParamAtCluster()->GetEntries(); iPar++) {
199 AliDebug(1, Form("GetTrackParamAtCluster()->At(%d)->GetClusterPtr() = %p",
200 iPar, ((AliMUONTrackParam*)(GetTrackParamAtCluster()->At(iPar)))->GetClusterPtr()));
205 //====================================================================================================================================================
207 AliMUONTrackParam* AliMuonForwardTrack::GetTrackParamAtMUONCluster(Int_t iMUONCluster) {
209 if (iMUONCluster<0 || iMUONCluster>=GetNMUONClusters()) {
210 AliError("Invalid MUON cluster index. NULL pointer will be returned");
214 AliMUONTrackParam *trackParam = (AliMUONTrackParam*) fMUONTrack->GetTrackParamAtCluster()->At(iMUONCluster);
220 //====================================================================================================================================================
222 AliMUONTrackParam* AliMuonForwardTrack::GetTrackParamAtMFTCluster(Int_t iMFTCluster) {
224 if (iMFTCluster<0 || iMFTCluster>=GetNMFTClusters()) {
225 AliError("Invalid MFT cluster index. NULL pointer will be returned");
229 AliMUONTrackParam *trackParam = (AliMUONTrackParam*) GetTrackParamAtCluster()->At(iMFTCluster);
235 //====================================================================================================================================================
237 AliMUONVCluster* AliMuonForwardTrack::GetMUONCluster(Int_t iMUONCluster) {
239 if (iMUONCluster<0 || iMUONCluster>=GetNMUONClusters()) {
240 AliError("Invalid MUON cluster index. NULL pointer will be returned");
244 AliMUONTrackParam *trackParam = GetTrackParamAtMUONCluster(iMUONCluster);
245 AliMUONVCluster *muonCluster = trackParam->GetClusterPtr();
251 //====================================================================================================================================================
253 AliMFTCluster* AliMuonForwardTrack::GetMFTCluster(Int_t iMFTCluster) {
255 if (iMFTCluster<0 || iMFTCluster>=GetNMFTClusters()) {
256 AliError(Form("Invalid MFT cluster index (%d). GetNMFTClusters()=%d. NULL pointer will be returned", iMFTCluster, GetNMFTClusters()));
260 AliMUONTrackParam *trackParam = GetTrackParamAtMFTCluster(iMFTCluster);
261 AliMFTCluster *mftCluster = (AliMFTCluster*) this->fMFTClusters->At(trackParam->GetUniqueID());
267 //====================================================================================================================================================
269 Double_t AliMuonForwardTrack::RunKalmanFilter(AliMUONTrackParam &trackParamAtCluster) {
271 AliDebug(1, Form("Running Kalman filter for parameters %p (z = %f) and cluster %p (z = %f)",
272 &trackParamAtCluster, trackParamAtCluster.GetZ(), trackParamAtCluster.GetClusterPtr(), trackParamAtCluster.GetClusterPtr()->GetZ()));
274 // Compute new track parameters and their covariances including new cluster using kalman filter
275 // return the *additional* track chi2
277 // Get actual track parameters (p)
278 TMatrixD param(trackParamAtCluster.GetParameters());
280 // Get new cluster parameters (m)
281 AliMUONVCluster *cluster = trackParamAtCluster.GetClusterPtr();
282 AliDebug(1, Form("cluster->GetX() = %f cluster->GetY() = %f cluster->GetErrX() = %f cluster->GetErrY() = %f",
283 cluster->GetX(), cluster->GetY(), cluster->GetErrX(), cluster->GetErrY()));
284 TMatrixD clusterParam(5,1);
286 clusterParam(0,0) = cluster->GetX();
287 clusterParam(2,0) = cluster->GetY();
289 // Compute the current parameter weight (W)
290 TMatrixD paramWeight(trackParamAtCluster.GetCovariances());
291 if (paramWeight.Determinant() != 0) {
292 paramWeight.Invert();
294 Warning("RunKalmanFilter"," Determinant = 0");
298 // Compute the new cluster weight (U)
299 TMatrixD clusterWeight(5,5);
300 clusterWeight.Zero();
301 clusterWeight(0,0) = 1. / cluster->GetErrX2();
302 clusterWeight(2,2) = 1. / cluster->GetErrY2();
304 // Compute the new parameters covariance matrix ( (W+U)^-1 )
305 TMatrixD newParamCov(paramWeight,TMatrixD::kPlus,clusterWeight);
306 if (newParamCov.Determinant() != 0) {
307 newParamCov.Invert();
310 Warning("RunKalmanFilter"," Determinant = 0");
314 // Save the new parameters covariance matrix
315 trackParamAtCluster.SetCovariances(newParamCov);
317 // Compute the new parameters (p' = ((W+U)^-1)U(m-p) + p)
318 TMatrixD tmp(clusterParam,TMatrixD::kMinus,param);
319 TMatrixD tmp2(clusterWeight,TMatrixD::kMult,tmp); // U(m-p)
320 TMatrixD newParam(newParamCov,TMatrixD::kMult,tmp2); // ((W+U)^-1)U(m-p)
321 newParam += param; // ((W+U)^-1)U(m-p) + p
323 // Save the new parameters
324 trackParamAtCluster.SetParameters(newParam);
326 // Compute the additional chi2 (= ((p'-p)^-1)W(p'-p) + ((p'-m)^-1)U(p'-m))
327 tmp = newParam; // p'
328 tmp -= param; // (p'-p)
329 TMatrixD tmp3(paramWeight,TMatrixD::kMult,tmp); // W(p'-p)
330 TMatrixD addChi2Track(tmp,TMatrixD::kTransposeMult,tmp3); // ((p'-p)^-1)W(p'-p)
331 tmp = newParam; // p'
332 tmp -= clusterParam; // (p'-m)
333 TMatrixD tmp4(clusterWeight,TMatrixD::kMult,tmp); // U(p'-m)
334 addChi2Track += TMatrixD(tmp,TMatrixD::kTransposeMult,tmp4); // ((p'-p)^-1)W(p'-p) + ((p'-m)^-1)U(p'-m)
336 AliDebug(1,Form("Adding Kalman chi2 = %f",addChi2Track(0,0)));
338 return addChi2Track(0,0);
342 //====================================================================================================================================================
344 Double_t AliMuonForwardTrack::GetWeightedOffset(Double_t x, Double_t y, Double_t z) {
346 AliMUONTrackParam *param = GetTrackParamAtMFTCluster(0);
347 AliMUONTrackExtrap::ExtrapToZCov(param, z);
350 cov = param->GetCovariances();
352 TMatrixD covCoordinates(2,2);
353 covCoordinates(0,0) = cov(0,0);
354 covCoordinates(0,1) = cov(0,2);
355 covCoordinates(1,0) = cov(2,0);
356 covCoordinates(1,1) = cov(2,2);
358 TMatrixD covCoordinatesInverse = covCoordinates.Invert();
360 Double_t dX = param->GetNonBendingCoor() - x;
361 Double_t dY = param->GetBendingCoor() - y;
363 Double_t weightedOffset = TMath::Sqrt(0.5*(dX*dX*covCoordinatesInverse(0,0) +
364 dY*dY*covCoordinatesInverse(1,1) +
365 2.*dX*dY*covCoordinatesInverse(0,1)));
367 return weightedOffset;
371 //====================================================================================================================================================
373 Double_t AliMuonForwardTrack::GetOffsetX(Double_t x, Double_t z) {
375 AliMUONTrackParam *param = GetTrackParamAtMFTCluster(0);
376 AliMUONTrackExtrap::ExtrapToZCov(param, z);
377 Double_t dX = param->GetNonBendingCoor() - x;
382 //====================================================================================================================================================
384 Double_t AliMuonForwardTrack::GetOffsetY(Double_t y, Double_t z) {
386 AliMUONTrackParam *param = GetTrackParamAtMFTCluster(0);
387 AliMUONTrackExtrap::ExtrapToZCov(param, z);
388 Double_t dY = param->GetBendingCoor() - y;
393 //====================================================================================================================================================
395 Double_t AliMuonForwardTrack::GetOffset(Double_t x, Double_t y, Double_t z) {
397 AliMUONTrackParam *param = GetTrackParamAtMFTCluster(0);
398 AliMUONTrackExtrap::ExtrapToZCov(param, z);
399 Double_t dX = param->GetNonBendingCoor() - x;
400 Double_t dY = param->GetBendingCoor() - y;
401 return TMath::Sqrt(dX*dX + dY*dY);
405 //====================================================================================================================================================