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