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