]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDtrackV1.cxx
added protection
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackV1.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 #include "AliTRDtrackV1.h"
19 #include "AliTRDcluster.h"
20 #include "AliTRDcalibDB.h"
21 #include "AliTRDrecoParam.h"
22
23 #include "AliESDtrack.h"
24
25 ClassImp(AliTRDtrackV1)
26
27 ///////////////////////////////////////////////////////////////////////////////
28 //                                                                           //
29 //  Represents a reconstructed TRD track                                     //
30 //  Local TRD Kalman track                                                   //
31 //                                                                           //
32 //  Authors:                                                                 //
33 //    Alex Bercuci <A.Bercuci@gsi.de>                                        //
34 //    Markus Fasel <M.Fasel@gsi.de>                                          //
35 //                                                                           //
36 ///////////////////////////////////////////////////////////////////////////////
37
38 //_______________________________________________________________
39 AliTRDtrackV1::AliTRDtrackV1() 
40   :AliTRDtrack()
41   ,fRecoParam(0x0)
42 {
43   //
44   // Default constructor
45   //
46         
47         for(int ip=0; ip<6; ip++){
48                 fTrackletIndex[ip] = -1;
49                 fTracklet[ip].Reset();
50         }
51 }
52
53 //_______________________________________________________________
54 AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) 
55   :AliTRDtrack(t)
56   ,fRecoParam(0x0)
57 {
58   //
59   // Constructor from AliESDtrack
60   //
61
62         //AliInfo(Form("alpha %f", GetAlpha()));
63         t.GetTRDtracklets(&fTrackletIndex[0]);
64         for(int ip=0; ip<6; ip++) fTracklet[ip].Reset();
65 }
66
67 //_______________________________________________________________
68 AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) 
69   :AliTRDtrack(ref)
70   ,fRecoParam(ref.fRecoParam)
71 {
72   //
73   // Copy constructor
74   //
75
76         for(int ip=0; ip<6; ip++){ 
77                 fTrackletIndex[ip] = ref.fTrackletIndex[ip];
78                 fTracklet[ip]      = ref.fTracklet[ip];
79         }
80 }
81
82 //_______________________________________________________________
83 // AliTRDtrackV1::~AliTRDtrackV1()
84 // {
85 //      
86 // }
87         
88 //_______________________________________________________________
89 AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 *trklts, const Double_t p[5]
90                            , const Double_t cov[15]
91                            , Double_t x, Double_t alpha)
92   :AliTRDtrack()
93   ,fRecoParam(0x0)
94 {
95   //
96   // The stand alone tracking constructor
97   // TEMPORARY !!!!!!!!!!!
98   // to check :
99   // 1. covariance matrix
100   // 2. dQdl calculation
101   //
102
103   Double_t cnv   = 1.0 / (GetBz() * kB2C);
104
105   Double_t pp[5] = { p[0]    
106                    , p[1]
107                    , x*p[4] - p[2]
108                    , p[3]
109                    , p[4]*cnv      };
110
111   Double_t c22 = x*x*cov[14] - 2*x*cov[12] + cov[ 5];
112   Double_t c32 =   x*cov[13] -     cov[ 8];
113   Double_t c20 =   x*cov[10] -     cov[ 3];
114   Double_t c21 =   x*cov[11] -     cov[ 4];
115   Double_t c42 =   x*cov[14] -     cov[12];
116
117   Double_t cc[15] = { cov[ 0]
118                     , cov[ 1],     cov[ 2]
119                     , c20,         c21,         c22
120                     , cov[ 6],     cov[ 7],     c32,     cov[ 9]
121                     , cov[10]*cnv, cov[11]*cnv, c42*cnv, cov[13]*cnv, cov[14]*cnv*cnv };
122   
123         Set(x,alpha,pp,cc);
124   Double_t s = GetSnp();
125   Double_t t = GetTgl();
126
127         Int_t ncl = 0, nclPlane; AliTRDcluster *c = 0x0;
128         for(int iplane=0; iplane<6; iplane++){
129                 fTrackletIndex[iplane] = -1;
130                 fTracklet[iplane] = trklts[iplane];
131                 nclPlane = 0;
132                 for(int ic = 0; ic<AliTRDseed::knTimebins; ic++){
133                         if(!fTracklet[iplane].IsUsable(ic)) continue;
134                         if(!(c = fTracklet[iplane].GetClusters(ic))) continue;
135                         
136                         fIndex[ncl]      = fTracklet[iplane].GetIndexes(ic);
137                         Double_t q = TMath::Abs(c->GetQ());
138                         fClusters[ncl]   = c;
139                         // temporary !!!
140                         // This is not correctly. Has to be updated in the AliTRDtrackerV1::FollowBackProlonagation()
141                         fdQdl[ncl]       = q * (s*s < 1.) ? TMath::Sqrt((1-s*s)/(1+t*t)) : 1.;
142                         ncl++;
143                         nclPlane++;
144                 }
145                 //printf("%d N clusters plane %d [%d %d].\n", iplane, nclPlane, fTracklet[iplane].GetN2(), trklts[iplane].GetN());
146         }
147         //printf("N clusters in AliTRDtrackV1 %d.\n", ncl);
148         SetNumberOfClusters(ncl);
149 }
150
151 //_______________________________________________________________
152 Bool_t AliTRDtrackV1::CookPID()
153 {
154   //
155   // Cook the PID information
156   //
157
158 // CookdEdx();  // truncated mean ... do we still need it ?
159
160 // CookdEdxTimBin(seed->GetID());
161         
162   // Sets the a priori probabilities
163   for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) {
164     fPID[ispec] = 1.0 / AliPID::kSPECIES;       
165   }
166         
167         // steer PID calculation @ tracklet level
168         Double_t *prob = 0x0;
169         fPIDquality = 0;
170         for(int itrklt=0; itrklt<AliESDtrack::kNPlane; itrklt++){
171     //for (Int_t iSlice = 0; iSlice < AliESDtrack::kNSlice; iSlice++) fdEdxPlane[itrklt][iSlice] = -1.;
172
173                 if(fTrackletIndex[itrklt]<0) continue;
174                 if(!fTracklet[itrklt].IsOK()) continue;
175                 if(!(prob = fTracklet[itrklt].GetProbability())) return kFALSE;
176                 
177                 Int_t nspec = 0; // quality check of tracklet dEdx
178                 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
179                         if(prob[ispec] < 0.) continue;
180                         fPID[ispec] *= prob[ispec];
181                         nspec++;
182                 }
183                 if(!nspec) continue;
184                 
185                 fPIDquality++;
186         }
187   
188   // no tracklet found for PID calculations
189   if(!fPIDquality) return kTRUE;
190
191         // slot for PID calculation @ track level
192         
193
194   // normalize probabilities
195   Double_t probTotal = 0.0;
196   for (Int_t is = 0; is < AliPID::kSPECIES; is++) probTotal += fPID[is];
197
198
199   if (probTotal <= 0.0) {
200     AliWarning("The total probability over all species <= 0. This may be caused by some error in the reference data.");
201     return kFALSE;
202   }
203
204   for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) fPID[iSpecies] /= probTotal;
205
206   return kTRUE;
207 }
208
209 //_______________________________________________________________
210 Float_t AliTRDtrackV1::GetMomentum(Int_t plane) const
211 {
212   //
213   // Get the momentum at a given plane
214   //
215
216         return plane >=0 && plane < 6 && fTrackletIndex[plane] >= 0 ? fTracklet[plane].GetMomentum() : -1.;
217 }
218
219 //_______________________________________________________________
220 Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt) const
221 {
222   //
223   // Get the predicted chi2
224   //
225
226   Double_t x      = trklt->GetX0();
227   Double_t p[2]   = { trklt->GetYat(x)
228                     , trklt->GetZat(x) };
229   Double_t cov[3];
230         trklt->GetCovAt(x, cov);
231
232   return AliExternalTrackParam::GetPredictedChi2(p, cov);
233
234 }
235
236 //_______________________________________________________________
237 Bool_t AliTRDtrackV1::IsOwner() const
238 {
239   //
240   // Check whether track owns the tracklets
241   //
242
243         for (Int_t ip = 0; ip < AliESDtrack::kNPlane; ip++) {
244                 if(fTrackletIndex[ip] < 0) continue;
245                 if(!fTracklet[ip].IsOwner()) return kFALSE;
246         }
247         return kTRUE;
248 }
249         
250 //_______________________________________________________________
251 void AliTRDtrackV1::SetOwner(Bool_t own)
252 {
253   //
254   // Toggle ownership of tracklets
255   //
256
257         for (Int_t ip = 0; ip < AliESDtrack::kNPlane; ip++) {
258                 if(fTrackletIndex[ip] < 0) continue;
259                 //AliInfo(Form("p[%d] index[%d]", ip, fTrackletIndex[ip]));
260                 fTracklet[ip].SetOwner(own);
261         }
262 }
263
264 //_______________________________________________________________
265 void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *trklt, Int_t plane, Int_t index)
266 {
267   //
268   // Set the tracklets
269   //
270
271         if(plane < 0 || plane >=6) return;
272         fTracklet[plane]      = (*trklt);
273         fTrackletIndex[plane] = index;
274 }
275
276 //_______________________________________________________________
277 Bool_t  AliTRDtrackV1::Update(AliTRDseedV1 *trklt, Double_t chisq)
278 {
279   //
280   // Update track parameters
281   //
282
283   Double_t x      = trklt->GetX0();
284   Double_t p[2]   = { trklt->GetYat(x)
285                     , trklt->GetZat(x) };
286   Double_t cov[3];
287         trklt->GetCovAt(x, cov);
288         
289 //      Print();
290 //      AliInfo(Form("cov[%f %f %f]", cov[0], cov[1], cov[2]));
291
292   if(!AliExternalTrackParam::Update(p, cov)) return kFALSE;
293         //Print();
294
295   // Register info to track
296 //   Int_t n      = GetNumberOfClusters();
297 //   fIndex[n]    = index;
298 //   fClusters[n] = c;
299   SetNumberOfClusters(GetNumberOfClusters()+trklt->GetN());
300   SetChi2(GetChi2() + chisq);
301         
302         // update tracklet
303         trklt->SetMomentum(GetP());
304   Double_t s = GetSnp(), t = GetTgl();
305         trklt->SetdQdl(TMath::Sqrt((1.0 - s*s) / (1.0 + t*t)));
306         return kTRUE;
307 }
308
309 //_______________________________________________________________
310 void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
311 {
312   //
313   // Update the ESD track
314   //
315         
316         // copy dEdx to ESD
317         Float_t *dedx = 0x0;
318         for (Int_t ip = 0; ip < AliESDtrack::kNPlane; ip++) {
319                 if(fTrackletIndex[ip] < 0) continue;
320                 fTracklet[ip].CookdEdx(AliESDtrack::kNSlice);
321                 dedx = fTracklet[ip].GetdEdx();
322                 for (Int_t js = 0; js < AliESDtrack::kNSlice; js++) track->SetTRDsignals(dedx[js], ip, js);
323                 //track->SetTRDTimBin(fTimBinPlane[i], i);
324         }
325
326         // copy PID to ESD
327         track->SetTRDpid(fPID);
328         track->SetTRDpidQuality(fPIDquality);
329 }