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