]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG1/TRD/info/AliTRDtrackInfo.cxx
Added PID selection level
[u/mrichter/AliRoot.git] / PWG1 / TRD / info / AliTRDtrackInfo.cxx
CommitLineData
1ee39b3a 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: AliTRDtrackInfo.cxx 27496 2008-07-22 08:35:45Z cblume $ */
17
18////////////////////////////////////////////////////////////////////////////
19// //
20// Reconstruction QA //
21// //
22// Authors: //
23// Alex Bercuci <A.Bercuci@gsi.de> //
24// Markus Fasel <M.Fasel@gsi.de> //
25// //
26////////////////////////////////////////////////////////////////////////////
27
28#include "TDatabasePDG.h"
b9ddd472 29#include "TPDGCode.h"
4226db3e 30#include "TVectorT.h"
1ee39b3a 31
32#include "AliTrackReference.h"
33#include "AliExternalTrackParam.h"
34
35#include "AliTRDseedV1.h"
36#include "AliTRDtrackV1.h"
37#include "AliTRDgeometry.h"
38#include "AliTRDtrackerV1.h"
39
40#include "AliTRDtrackInfo.h"
41
42ClassImp(AliTRDtrackInfo)
43ClassImp(AliTRDtrackInfo::AliMCinfo)
44ClassImp(AliTRDtrackInfo::AliESDinfo)
5066aa9a 45Double_t AliTRDtrackInfo::AliMCinfo::fgKalmanStep = 2.;
1ee39b3a 46
47//___________________________________________________
48AliTRDtrackInfo::AliTRDtrackInfo():
49 TObject()
50 ,fNClusters(0)
f232df0d 51 ,fTRDtrack(NULL)
52 ,fMC(NULL)
1ee39b3a 53 ,fESD()
54{
55 //
56 // Default constructor
57 //
58}
59
60
61//___________________________________________________
62AliTRDtrackInfo::AliTRDtrackInfo(const AliTRDtrackInfo &trdInfo):
63 TObject((const TObject&)trdInfo)
64 ,fNClusters(trdInfo.fNClusters)
f232df0d 65 ,fTRDtrack(NULL)
a340fe39 66 ,fMC(NULL)
1ee39b3a 67 ,fESD(trdInfo.fESD)
68{
69 //
70 // copy Entries
71 //
72
73 if(trdInfo.fMC) fMC = new AliMCinfo(*trdInfo.fMC);
74
75 if(trdInfo.fTRDtrack){
76 fTRDtrack = new AliTRDtrackV1(*trdInfo.fTRDtrack);
77 if(trdInfo.fTRDtrack->IsOwner()) fTRDtrack->SetOwner();
78 }
79}
80
81//___________________________________________________
82AliTRDtrackInfo::AliMCinfo::AliMCinfo()
83 :fLabel(0)
84 ,fPDG(0)
85 ,fNTrackRefs(0)
86{
87 // Set 0-Pointers
88 memset(fTrackRefs, 0, sizeof(AliTrackReference *) * 12);
89}
90
91//___________________________________________________
92AliTRDtrackInfo::AliMCinfo::AliMCinfo(const AliMCinfo &mc)
93 :fLabel(mc.fLabel)
94 ,fPDG(mc.fPDG)
95 ,fNTrackRefs(mc.fNTrackRefs)
96{
97 //
98 // Constructor
99 //
100
101 memset(fTrackRefs, 0, sizeof(AliTrackReference *) * 12);
102 for(Int_t ien = 0; ien < 12; ien++){
103 if(mc.fTrackRefs[ien])
104 fTrackRefs[ien] = new AliTrackReference(*(mc.fTrackRefs[ien]));
105 }
106}
107
b9ddd472 108//________________________________________________________
109Int_t AliTRDtrackInfo::AliMCinfo::GetPID() const
110{
111 switch(fPDG){
112 case kElectron:
113 case kPositron: return AliPID::kElectron;
114 case kMuonPlus:
115 case kMuonMinus: return AliPID::kMuon;
116 case kPiPlus:
117 case kPiMinus: return AliPID::kPion;
118 case kKPlus:
119 case kKMinus: return AliPID::kKaon;
120 case kProton:
121 case kProtonBar: return AliPID::kProton;
122 }
123 return -1;
124}
125
1ee39b3a 126//___________________________________________________
127AliTRDtrackInfo::AliESDinfo::AliESDinfo()
b9ddd472 128 :fHasV0(0)
129 ,fId(-1)
1ee39b3a 130 ,fStatus(0)
131 ,fKinkIndex(0)
132 ,fTPCncls(0)
133 ,fTRDpidQuality(0)
134 ,fTRDnSlices(0)
f232df0d 135 ,fTRDslices(NULL)
136 ,fOP(NULL)
1ee39b3a 137{
138 //
139 // Constructor
140 //
141
142 memset(fTRDr, 0, AliPID::kSPECIES*sizeof(Double32_t));
143}
144
145//___________________________________________________
146AliTRDtrackInfo::AliESDinfo::AliESDinfo(const AliESDinfo &esd)
b9ddd472 147 :fHasV0(esd.fHasV0)
148 ,fId(esd.fId)
1ee39b3a 149 ,fStatus(esd.fStatus)
150 ,fKinkIndex(esd.fKinkIndex)
151 ,fTPCncls(esd.fTPCncls)
152 ,fTRDpidQuality(esd.fTRDpidQuality)
153 ,fTRDnSlices(esd.fTRDnSlices)
f232df0d 154 ,fTRDslices(NULL)
155 ,fOP(NULL)
1ee39b3a 156{
157 //
158 // Constructor
159 //
160
161 memcpy(fTRDr, esd.fTRDr, AliPID::kSPECIES*sizeof(Double32_t));
162
163 if(fTRDnSlices){
164 fTRDslices = new Double32_t[fTRDnSlices];
165 memcpy(fTRDslices, esd.fTRDslices, fTRDnSlices*sizeof(Double32_t));
166 }
167 if(esd.fOP) fOP = new AliExternalTrackParam(*esd.fOP);
168}
169
170
171//___________________________________________________
172AliTRDtrackInfo::~AliTRDtrackInfo()
173{
174 //
175 // Destructor
176 //
177
178 if(fMC) delete fMC;
179 if(fTRDtrack) delete fTRDtrack;
180}
181
182//___________________________________________________
183AliTRDtrackInfo::AliMCinfo::~AliMCinfo()
184{
185 //
186 // Destructor
187 //
188
189 fNTrackRefs = 0;
190 for(Int_t ien = 0; ien < 12; ien++){
191 if(fTrackRefs[ien]) delete fTrackRefs[ien];
f232df0d 192 fTrackRefs[ien] = NULL;
1ee39b3a 193 }
194}
195
196//___________________________________________________
197AliTRDtrackInfo::AliESDinfo::~AliESDinfo()
198{
199 //
200 // Destructor
201 //
202
203 if(fTRDnSlices){
204 delete [] fTRDslices;
f232df0d 205 fTRDslices = NULL;
1ee39b3a 206 fTRDnSlices = 0;
207 }
f232df0d 208 if(fOP) delete fOP; fOP = NULL;
1ee39b3a 209}
210
211
212//___________________________________________________
213AliTRDtrackInfo& AliTRDtrackInfo::operator=(const AliTRDtrackInfo &trdInfo)
214{
215 //
216 // = Operator
217 //
218
219 fNClusters = trdInfo.fNClusters;
220 fESD = trdInfo.fESD;
221
222 if(trdInfo.fMC){
223 if(!fMC)
224 fMC = new AliMCinfo(*trdInfo.fMC);
225 else
226 new(fMC) AliMCinfo(*trdInfo.fMC);
227 }
228
229 if(trdInfo.fTRDtrack){
230 if(!fTRDtrack)
231 fTRDtrack = new AliTRDtrackV1(*trdInfo.fTRDtrack);
232 else
233 new(fTRDtrack) AliTRDtrackV1(*trdInfo.fTRDtrack);
234 if(trdInfo.fTRDtrack->IsOwner()) fTRDtrack->SetOwner();
235 }
236
237 return *this;
238}
239
240//___________________________________________________
241AliTRDtrackInfo::AliMCinfo& AliTRDtrackInfo::AliMCinfo::operator=(const AliMCinfo &mc)
242{
243 //
244 // Assignment operator
245 //
246
247 fLabel = mc.fLabel;
248 fPDG = mc.fPDG;
249 fNTrackRefs = mc.fNTrackRefs;
250
251 AliTrackReference **itr = &fTrackRefs[0];
252 AliTrackReference* const *jtr = &mc.fTrackRefs[0];
253 for(Int_t ien = 0; ien < 12; ien++, itr++, jtr++){
254 if((*jtr)){
255 if(!(*itr)) (*itr) = new AliTrackReference(*(*jtr));
256 else new(&(*itr)) AliTrackReference(*(*jtr));
f232df0d 257 } else (*itr) = NULL;
1ee39b3a 258 }
259 return *this;
260}
261
262//___________________________________________________
263AliTRDtrackInfo::AliESDinfo& AliTRDtrackInfo::AliESDinfo::operator=(const AliESDinfo &esd)
264{
265 //
266 // Assignment operator
267 //
268
269 fId = esd.fId;
270 fStatus = esd.fStatus;
271 fTRDpidQuality = esd.fTRDpidQuality;
272 fTRDnSlices = esd.fTRDnSlices;
f232df0d 273 fTRDslices = NULL;
1ee39b3a 274
275 memcpy(fTRDr, esd.fTRDr, AliPID::kSPECIES*sizeof(Double32_t));
276
277 if(fTRDnSlices){
278 fTRDslices = new Double32_t[fTRDnSlices];
279 memcpy(fTRDslices, esd.fTRDslices, fTRDnSlices*sizeof(Double32_t));
280 }
281 if(esd.fOP){
282 if(fOP) new(fOP) AliExternalTrackParam(esd.fOP);
283 else fOP = new AliExternalTrackParam(esd.fOP);
f232df0d 284 } else fOP = NULL;
1ee39b3a 285
286 return *this;
287}
288
289//___________________________________________________
290void AliTRDtrackInfo::Delete(const Option_t *)
291{
292 //
293 // Delete
294 //
295
296 fNClusters = 0;
f232df0d 297 if(fMC) delete fMC; fMC = NULL;
298 if(fTRDtrack) delete fTRDtrack; fTRDtrack = NULL;
1ee39b3a 299}
300
301//___________________________________________________
302void AliTRDtrackInfo::SetTrack(const AliTRDtrackV1 *track)
303{
304 //
305 // Set the TRD track
306 //
307
308 if(!fTRDtrack)
309 fTRDtrack = new AliTRDtrackV1(*track);
310 else
311 new(fTRDtrack)AliTRDtrackV1(*track);
312 fTRDtrack->SetOwner();
313 // Make a copy for the object in order to avoid ownership problems
314}
315
316//___________________________________________________
317void AliTRDtrackInfo::AddTrackRef(const AliTrackReference *tref)
318{
319 //
320 // Add track reference
321 //
322
1ee39b3a 323 if(fMC->fNTrackRefs >= 12){
324 SetCurved();
325 return;
326 }
327 // Make a copy for the object in order to avoid ownership problems
328 fMC->fTrackRefs[fMC->fNTrackRefs++] = new AliTrackReference(*tref);
329}
330
331//___________________________________________________
332AliTrackReference* AliTRDtrackInfo::GetTrackRef(Int_t idx) const
333{
334//
335// Returns a track reference
336//
f232df0d 337 if(!fMC) return NULL;
338 return (idx>=0 && idx < 12) ? fMC->fTrackRefs[idx] : NULL;
1ee39b3a 339}
340
341//___________________________________________________
342AliTrackReference* AliTRDtrackInfo::GetTrackRef(AliTRDseedV1* const tracklet) const
343{
344//
345// Returns a track reference
346//
f232df0d 347 if(!fMC) return NULL;
1ee39b3a 348 Double_t cw = AliTRDgeometry::CamHght() + AliTRDgeometry::CdrHght();
349 AliTrackReference * const* jtr = &(fMC->fTrackRefs[0]);
350 for(Int_t itr = 0; itr < fMC->fNTrackRefs; itr++, ++jtr){
351 if(!(*jtr)) break;
352 if(TMath::Abs(tracklet->GetX0() - (*jtr)->LocalX()) < cw) return (*jtr);
353 }
f232df0d 354 return NULL;
1ee39b3a 355}
356
357//___________________________________________________
358Int_t AliTRDtrackInfo::GetNumberOfClusters() const
359{
360 //
361 // Returns the number of clusters
362 //
363
364 Int_t n = 0;
365 if(!fTRDtrack) return 0;
366 if(fTRDtrack->GetNumberOfTracklets() == 0) return n;
f232df0d 367 AliTRDseedV1 *tracklet = NULL;
1ee39b3a 368 for(Int_t ip=0; ip<6; ip++){
369 if(!(tracklet = const_cast<AliTRDseedV1 *>(fTRDtrack->GetTracklet(ip)))) continue;
370 n+=tracklet->GetN();
371 }
372 return n;
373}
374
375
376//___________________________________________________
377void AliTRDtrackInfo::SetOuterParam(const AliExternalTrackParam *op)
378{
379 //
380 // Set outer track parameters
381 //
382
383 if(!op) return;
384 if(fESD.fOP) new(fESD.fOP) AliExternalTrackParam(*op);
385 else fESD.fOP = new AliExternalTrackParam(*op);
386}
387
388//___________________________________________________
389Int_t AliTRDtrackInfo::GetNTracklets() const
390{
391 //
392 // Return the number of tracklets
393 //
394
e2927481 395 if(!fTRDtrack) return 0;
1ee39b3a 396 return fTRDtrack->GetNumberOfTracklets();
397}
398
399//___________________________________________________
400void AliTRDtrackInfo::SetSlices(Int_t n, Double32_t *s)
401{
402 //
403 // Set the slices
404 //
1ee39b3a 405 if(fESD.fTRDnSlices != n){
406 fESD.fTRDnSlices = 0;
407 delete [] fESD.fTRDslices;
f232df0d 408 fESD.fTRDslices = NULL;
1ee39b3a 409 }
410
411 if(!fESD.fTRDnSlices){
412 fESD.fTRDnSlices = n;
f232df0d 413 fESD.fTRDslices = new Double32_t[fESD.fTRDnSlices];
1ee39b3a 414 }
415
416 memcpy(fESD.fTRDslices, s, n*sizeof(Double32_t));
417}
418
419//___________________________________________________
420Bool_t AliTRDtrackInfo::AliMCinfo::GetDirections(Float_t &x0, Float_t &y0, Float_t &z0, Float_t &dydx, Float_t &dzdx, Float_t &pt, UChar_t &status) const
421{
422// Check for 2 track ref for the tracklet defined bythe radial position x0
423// The "status" is a bit map and gives a more informative output in case of failure:
424// - 0 : everything is OK
425// - BIT(0) : 0 track refs found
426// - BIT(1) : 1 track reference found
427// - BIT(2) : dx <= 0 between track references
428// - BIT(3) : dx > 0 && dx < 3.7 - tangent tracks
429
430 status = 0;
431 Double_t cw = AliTRDgeometry::CamHght() + AliTRDgeometry::CdrHght();
432 Int_t nFound = 0;
f232df0d 433 AliTrackReference *tr[2] = {NULL, NULL};
1ee39b3a 434 AliTrackReference * const* jtr = &fTrackRefs[0];
435 for(Int_t itr = 0; itr < fNTrackRefs; itr++, ++jtr){
436 if(!(*jtr)) break;
437/*
438 if(fDebugLevel>=5) printf("\t\tref[%2d] x[%6.3f]\n", itr, (*jtr)->LocalX());*/
439 if(TMath::Abs(x0 - (*jtr)->LocalX()) > cw) continue;
440 tr[nFound++] = (*jtr);
441 if(nFound == 2) break;
442 }
443 if(nFound < 2){
f232df0d 444 AliWarningGeneral("AliTRDtrackInfo::AliMCinfo::GetDirections()", Form("Missing track ref x0[%6.3f] nref[%d]", x0, nFound));
1ee39b3a 445 if(!nFound) SETBIT(status, 0);
446 else SETBIT(status, 1);
447 return kFALSE;
448 }
449 if((pt=tr[1]->Pt()) < 1.e-3) return kFALSE;
450
451 Double_t dx = tr[1]->LocalX() - tr[0]->LocalX();
452 if(dx <= 0.){
453 AliWarningGeneral("AliTRDtrackInfo::AliMCinfo::GetDirections()", Form("Track ref with wrong radial distances refX0[%6.3f] refX1[%6.3f]", tr[0]->LocalX(), tr[1]->LocalX()));
454 SETBIT(status, 2);
455 return kFALSE;
456 }
457 if(TMath::Abs(dx-AliTRDgeometry::CamHght()-AliTRDgeometry::CdrHght())>1.E-3) SETBIT(status, 3);
458
459 dydx = (tr[1]->LocalY() - tr[0]->LocalY()) / dx;
460 dzdx = (tr[1]->Z() - tr[0]->Z()) / dx;
461 //Float_t dx0 = tr[1]->LocalX() - x0;
462 y0 = tr[1]->LocalY()/* - dydx*dx0*/;
463 z0 = tr[1]->Z()/* - dzdx*dx0*/;
464 x0 = tr[1]->LocalX();
465 return kTRUE;
466}
467
468//___________________________________________________
5066aa9a 469void AliTRDtrackInfo::AliMCinfo::PropagateKalman(TVectorD *dx, TVectorD *dy, TVectorD *dz, TVectorD *pt, TVectorD *dpt, TVectorD *c) const
1ee39b3a 470{
471// Propagate Kalman from the first TRD track reference to
472// last one and save residuals in the y, z and pt.
473//
474// This is to calibrate the dEdx and MS corrections
475
4226db3e 476 if(!fNTrackRefs) return;
1ee39b3a 477 for(Int_t itr=kNTrackRefs; itr--;){
4226db3e 478 (*dx)[itr] = -1.; (*dy)[itr] = 100.; (*dz)[itr] = 100.; (*dpt)[itr] = 100.;
1ee39b3a 479 }
1ee39b3a 480
481 // Initialize TRD track to the first track reference
4226db3e 482 AliTrackReference *tr(NULL);
483 Int_t itr(0); while(!(tr = fTrackRefs[itr])) itr++;
1ee39b3a 484 if(tr->Pt()<1.e-3) return;
485
486 AliTRDtrackV1 tt;
487 Double_t xyz[3]={tr->X(),tr->Y(),tr->Z()};
488 Double_t pxyz[3]={tr->Px(),tr->Py(),tr->Pz()};
489 Double_t var[6] = {1.e-4, 1.e-4, 1.e-4, 1.e-4, 1.e-4, 1.e-4};
490 Double_t cov[21]={
491 var[0], 0., 0., 0., 0., 0.,
492 var[1], 0., 0., 0., 0.,
493 var[2], 0., 0., 0.,
494 var[3], 0., 0.,
495 var[4], 0.,
496 var[5]
497 };
498 TDatabasePDG db;
499 const TParticlePDG *pdg=db.GetParticle(fPDG);
500 if(!pdg){
501 AliWarningGeneral("AliTRDtrackInfo::AliMCinfo::PropagateKalman()", Form("PDG entry missing for code %d. References for track %d", fPDG, fNTrackRefs));
502 return;
503 }
504 tt.Set(xyz, pxyz, cov, Short_t(pdg->Charge()));
505 tt.SetMass(pdg->Mass());
506
4226db3e 507 Double_t x0(tr->LocalX());
508 const Double_t *cc(NULL);
509 for(Int_t ip=0; itr<fNTrackRefs; itr++){
510 if(!(tr = fTrackRefs[itr])) continue;
5066aa9a 511 if(!AliTRDtrackerV1::PropagateToX(tt, tr->LocalX(), fgKalmanStep)) continue;
1ee39b3a 512
513 //if(update) ...
4226db3e 514 (*dx)[ip] = tt.GetX() - x0;
515 (*dy)[ip] = tt.GetY() - tr->LocalY();
516 (*dz)[ip] = tt.GetZ() - tr->Z();
5066aa9a 517 (*pt)[ip] = tr->Pt();
4226db3e 518 (*dpt)[ip] = tt.Pt()- tr->Pt();
1ee39b3a 519 cc = tt.GetCovariance();
4226db3e 520 c->Use(ip*15, (ip+1)*15, cc);
1ee39b3a 521 ip++;
522 }
523}