b690f3ddbdcb8e537819d5478ac302281931ac46
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerTrack.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 AliMUONTriggerTrack
20 //---------------------------
21 // Reconstructed Trigger track in ALICE dimuon spectrometer
22 // Note: equivalent to AliMUONTriggerTrack for tracking,
23 // No need for a AliMUONTriggerTrackParam
24 // Author: Philippe Crochet
25 //-----------------------------------------------------------------------------
26
27 #include "AliMUONTriggerTrack.h"
28 #include "AliMUONTrackReconstructor.h" 
29 #include "TString.h"
30 #include <Riostream.h>
31 #include "AliLog.h"
32
33 /// \cond CLASSIMP
34 ClassImp(AliMUONTriggerTrack)
35 /// \endcond
36
37 //__________________________________________________________________________
38 AliMUONTriggerTrack::AliMUONTriggerTrack()
39   : TObject(),
40     fx11(0),
41     fy11(0),
42     fz11(0.),
43     fz21(0.),
44     fSlopeX(0),
45     fSlopeY(0),
46     floTrgNum(0),
47     fGTPattern(0),
48     fHitsPatternInTrigCh(0),
49     fCovariances(0x0)
50 {
51   /// default ctr
52       AliDebug(5,Form("this=%p",this));
53 }
54 //__________________________________________________________________________
55 AliMUONTriggerTrack::AliMUONTriggerTrack(Float_t x11, Float_t y11, Float_t z11, Float_t z21, Float_t slopeX, Float_t slopeY, Int_t loTrgNum, Long_t theGTPattern, UShort_t hitsPatternInTrigCh)
56     : TObject(),
57       fx11(x11),
58       fy11(y11),
59       fz11(z11),
60       fz21(z21),
61       fSlopeX(slopeX),
62       fSlopeY(slopeY),
63       floTrgNum(loTrgNum),
64       fGTPattern(theGTPattern),
65       fHitsPatternInTrigCh(hitsPatternInTrigCh),
66       fCovariances(0x0)
67 {
68 /// ctor from local trigger output
69         AliDebug(5,Form("this=%p x11=%f y11=%f z11=%f z21=%f slopeX=%f slopeY=%f loTrgNum=%d GTPattern=%ld HitsPatternInTrigCh %i",
70                         this,x11,y11,z11,z21,slopeX,slopeY,loTrgNum,theGTPattern,fHitsPatternInTrigCh));
71
72 }
73
74 //__________________________________________________________________________
75 AliMUONTriggerTrack::~AliMUONTriggerTrack()
76 {
77   /// Destructor
78   AliDebug(5,Form("this=%p",this));
79   if (fCovariances) {
80     delete fCovariances;
81     fCovariances = 0x0;
82   }
83 }
84
85 //__________________________________________________________________________
86 AliMUONTriggerTrack::AliMUONTriggerTrack (const AliMUONTriggerTrack& theMUONTriggerTrack)
87     : TObject(theMUONTriggerTrack),
88       fx11(theMUONTriggerTrack.fx11),
89       fy11(theMUONTriggerTrack.fy11),
90       fz11(theMUONTriggerTrack.fz11),
91       fz21(theMUONTriggerTrack.fz21),
92       fSlopeX(theMUONTriggerTrack.fSlopeX),
93       fSlopeY(theMUONTriggerTrack.fSlopeY),
94       floTrgNum(theMUONTriggerTrack.floTrgNum),
95       fGTPattern(theMUONTriggerTrack.fGTPattern),
96       fHitsPatternInTrigCh(theMUONTriggerTrack.fHitsPatternInTrigCh),
97       fCovariances(0x0)
98 {
99 ///
100 /// copy ctor
101 ///
102   if (theMUONTriggerTrack.fCovariances) fCovariances = new TMatrixD(*(theMUONTriggerTrack.fCovariances));
103   AliDebug(5,Form("this=%p copy ctor",this));
104
105 }
106       
107 //__________________________________________________________________________
108 AliMUONTriggerTrack & AliMUONTriggerTrack::operator=(const AliMUONTriggerTrack&
109 theMUONTriggerTrack)
110 {
111 /// Assignment operator
112
113     // check assignement to self
114     if (this == &theMUONTriggerTrack)
115         return *this;
116     
117     /// base class assignement
118     TObject::operator=(theMUONTriggerTrack);
119
120     fx11 = theMUONTriggerTrack.fx11;
121     fy11 = theMUONTriggerTrack.fy11;
122     fz11 = theMUONTriggerTrack.fz11;
123     fz21 = theMUONTriggerTrack.fz21;
124     fSlopeX = theMUONTriggerTrack.fSlopeX;
125     fSlopeY = theMUONTriggerTrack.fSlopeY;
126     floTrgNum = theMUONTriggerTrack.floTrgNum;
127     fGTPattern = theMUONTriggerTrack.fGTPattern;
128     fHitsPatternInTrigCh = theMUONTriggerTrack.fHitsPatternInTrigCh;
129
130     if (theMUONTriggerTrack.fCovariances) {
131       if (fCovariances) *fCovariances = *(theMUONTriggerTrack.fCovariances);
132       else fCovariances = new TMatrixD(*(theMUONTriggerTrack.fCovariances));
133     } else {
134       delete fCovariances;
135       fCovariances = 0x0;
136     }
137
138     return *this;
139 }
140
141 //__________________________________________________________________________
142 void
143 AliMUONTriggerTrack::Print(Option_t* opt) const
144 {
145 /// Printing
146   TString optString(opt);
147   optString.ToUpper();
148   if ( optString.Contains("FULL") ) optString = "PARAM COV";
149
150   if ( optString.Contains("PARAM"))
151     cout << Form("(X,Y,Z)11=(%7.2f,%7.2f,%7.2f) Z21=%7.2f Slope(X,Y)=(%7.2f,%7.2f) LocalBoard #%3d GlobalTriggerPattern %x HitsPatternInTrigCh %x",
152                  fx11,fy11,fz11,fz21,fSlopeX,fSlopeY,floTrgNum,fGTPattern,fHitsPatternInTrigCh) << endl;
153
154   if ( optString.Contains("COV") ){
155     if ( ! fCovariances ) cout << "Covariances not initialized " << endl;
156     else fCovariances->Print();
157   }
158 }
159
160 //__________________________________________________________________________
161 void AliMUONTriggerTrack::SetCovariances(const TMatrixD& covariances)
162 {
163   /// Set the covariance matrix
164   if (fCovariances) *fCovariances = covariances;
165   else fCovariances = new TMatrixD(covariances);
166 }
167
168 //__________________________________________________________________________
169 void AliMUONTriggerTrack::SetCovariances(const Double_t matrix[3][3])
170 {
171   /// Set the covariance matrix
172   if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
173   else fCovariances = new TMatrixD(3,3,&(matrix[0][0]));
174 }
175
176 //__________________________________________________________________________
177 const TMatrixD& AliMUONTriggerTrack::GetCovariances() const
178 {
179   /// Return the covariance matrix (create it before if needed)
180   if (!fCovariances) {
181     fCovariances = new TMatrixD(3,3);
182     fCovariances->Zero();
183   }
184   return *fCovariances;
185 }
186
187 //__________________________________________________________________________
188 Bool_t AliMUONTriggerTrack::Match(AliMUONTriggerTrack &track,
189                                   Double_t sigmaCut) const
190 {
191   /// Try to match this track with the given track. Matching conditions:
192   /// - x, y position and y slope within sigmaCut
193   
194   // Find the track with the covariances correctly set
195   // Extrapolate to the z of the other track
196   Bool_t hasCov1 = ( GetCovariances().NonZeros() != 0 );
197   Bool_t hasCov2 = ( track.GetCovariances().NonZeros() != 0 );
198
199   const AliMUONTriggerTrack* trackToExtrap = ( hasCov2 ) ? &track : this;
200   const AliMUONTriggerTrack* fixedTrack = ( hasCov2 ) ? this : &track;
201
202   TMatrixD paramDiff(3,1);
203   Double_t deltaZ = fixedTrack->GetZ11() - trackToExtrap->GetZ11();
204   paramDiff(0,0) = fixedTrack->GetX11() - trackToExtrap->GetX11();
205   paramDiff(1,0) = fixedTrack->GetY11() - ( trackToExtrap->GetY11() + trackToExtrap->GetSlopeY() * deltaZ );
206   paramDiff(2,0) = fixedTrack->GetSlopeY() - trackToExtrap->GetSlopeY();
207   Double_t chi2 = 0.;
208
209   TMatrixD cov1(fixedTrack->GetCovariances());
210   TMatrixD cov2(trackToExtrap->GetCovariances());
211
212   // Extrapolate covariances to z
213   if ( deltaZ != 0 ) {
214     if ( hasCov1 || hasCov2 ){
215       TMatrixD jacob(3,3);
216       jacob.UnitMatrix();
217       jacob(1,2) = deltaZ;
218       TMatrixD tmp(trackToExtrap->GetCovariances(),TMatrixD::kMultTranspose,jacob);
219       TMatrixD tmp2(jacob,TMatrixD::kMult,tmp);
220       cov2 = tmp2;
221     }
222   }
223
224   AliDebug(3, Form("track1 Y11 %f  track2 Y11: %f (Z11 %f)  -> %f (Z11 %f)", fixedTrack->GetY11(), trackToExtrap->GetY11(), trackToExtrap->GetZ11(), trackToExtrap->GetY11() + trackToExtrap->GetSlopeY() * deltaZ, fixedTrack->GetZ11()));
225
226   TMatrixD sumCov(cov1,TMatrixD::kPlus,cov2);
227   if (sumCov.Determinant() != 0) {
228     sumCov.Invert();      
229     TMatrixD tmp(sumCov,TMatrixD::kMult,paramDiff);
230     TMatrixD chi2M(paramDiff,TMatrixD::kTransposeMult,tmp);
231     chi2 = chi2M(0,0);
232   } else {
233     AliWarning(" Determinant = 0");
234     Double_t sigma2 = 0.;
235     for (Int_t iVar = 0; iVar < 3; iVar++) {
236       sigma2 = cov1(iVar,iVar) + cov2(iVar,iVar);
237       chi2 += paramDiff(iVar,0) * paramDiff(iVar,0) / sigma2;
238     }
239   }
240
241   if ( chi2/3 > sigmaCut * sigmaCut )
242     return kFALSE;
243   
244   return kTRUE;
245 }