]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDgtuTrack.cxx
Introduce an enumerator for PID methods
[u/mrichter/AliRoot.git] / TRD / AliTRDgtuTrack.cxx
CommitLineData
e3b2b5e5 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
3010c308 16/* $Id$ */
17
e3b2b5e5 18///////////////////////////////////////////////////////////////////////////////
19// //
20// //
21// TRD module global track (GTU) //
22// //
23// //
24///////////////////////////////////////////////////////////////////////////////
25
3010c308 26#include <TMath.h>
e3b2b5e5 27#include <TMatrixD.h>
28#include <TObjArray.h>
29
6d50f529 30#include "AliLog.h"
31
4ba1d6ae 32#include "AliTRDReconstructor.h"
e3b2b5e5 33#include "AliTRDgeometry.h"
34#include "AliTRDcalibDB.h"
e3b2b5e5 35#include "AliTRDltuTracklet.h"
e3b2b5e5 36#include "AliTRDgtuTrack.h"
720a0a16 37#include "Cal/AliTRDCalPID.h"
e3b2b5e5 38
39ClassImp(AliTRDgtuTrack)
40
41//_____________________________________________________________________________
42AliTRDgtuTrack::AliTRDgtuTrack()
6d50f529 43 :TObject()
44 ,fTracklets(new TObjArray(400))
45 ,fYproj(0)
46 ,fZproj(0)
47 ,fSlope(0)
48 ,fDetector(-1)
49 ,fNtracklets(0)
50 ,fNplanes(0)
51 ,fNclusters(0)
52 ,fPt(0)
53 ,fPhi(0)
54 ,fEta(0)
55 ,fLabel(-1)
56 ,fPID(0)
57 ,fIsElectron(kFALSE)
e3b2b5e5 58{
59 //
60 // Default constructor
61 //
62
e3b2b5e5 63}
64
65//_____________________________________________________________________________
5b0e57fd 66AliTRDgtuTrack::AliTRDgtuTrack(const AliTRDgtuTrack &t)
6d50f529 67 :TObject(t)
68 ,fTracklets(NULL)
69 ,fYproj(t.fYproj)
70 ,fZproj(t.fZproj)
71 ,fSlope(t.fSlope)
72 ,fDetector(t.fDetector)
73 ,fNtracklets(t.fNtracklets)
74 ,fNplanes(t.fNplanes)
75 ,fNclusters(t.fNclusters)
76 ,fPt(t.fPt)
77 ,fPhi(t.fPhi)
78 ,fEta(t.fEta)
79 ,fLabel(t.fLabel)
80 ,fPID(t.fPID)
81 ,fIsElectron(t.fIsElectron)
e3b2b5e5 82{
83 //
6d50f529 84 // Copy contructor
e3b2b5e5 85 //
86
87}
88
89//_____________________________________________________________________________
90AliTRDgtuTrack &AliTRDgtuTrack::operator=(const AliTRDgtuTrack &t)
91{
92 //
6d50f529 93 // Assignment operator
e3b2b5e5 94 //
95
96 if (this != &t) ((AliTRDgtuTrack &) t).Copy(*this);
5b0e57fd 97
e3b2b5e5 98 return *this;
99
6d50f529 100}
e3b2b5e5 101
102//_____________________________________________________________________________
103void AliTRDgtuTrack::Copy(TObject &t) const
104{
105 //
6d50f529 106 // Copy function
e3b2b5e5 107 //
108
109 ((AliTRDgtuTrack &) t).fTracklets = NULL;
110 ((AliTRDgtuTrack &) t).fYproj = fYproj;
111 ((AliTRDgtuTrack &) t).fZproj = fZproj;
112 ((AliTRDgtuTrack &) t).fSlope = fSlope;
113 ((AliTRDgtuTrack &) t).fDetector = fDetector;
114 ((AliTRDgtuTrack &) t).fNtracklets = fNtracklets;
115 ((AliTRDgtuTrack &) t).fNplanes = fNplanes;
116 ((AliTRDgtuTrack &) t).fNclusters = fNclusters;
117 ((AliTRDgtuTrack &) t).fPt = fPt;
118 ((AliTRDgtuTrack &) t).fPhi = fPhi;
119 ((AliTRDgtuTrack &) t).fEta = fEta;
120 ((AliTRDgtuTrack &) t).fLabel = fLabel;
121 ((AliTRDgtuTrack &) t).fPID = fPID;
122 ((AliTRDgtuTrack &) t).fIsElectron = fIsElectron;
123
124}
125
126//_____________________________________________________________________________
127AliTRDgtuTrack::~AliTRDgtuTrack()
128{
129 //
6d50f529 130 // Destructor
e3b2b5e5 131 //
132
6d50f529 133 if (fTracklets) {
5b0e57fd 134 //fTracklets->Delete();
135 fTracklets->Clear();
6d50f529 136 delete fTracklets;
6bf84b68 137 fTracklets = 0;
6d50f529 138 }
139
e3b2b5e5 140}
141
142//_____________________________________________________________________________
143void AliTRDgtuTrack::AddTracklet(AliTRDltuTracklet *trk)
144{
145 //
146 // Add a LTU tracklet to this track
147 //
148
149 Tracklets()->Add(trk);
150
151}
152
153//_____________________________________________________________________________
5b0e57fd 154AliTRDltuTracklet *AliTRDgtuTrack::GetTracklet(Int_t pos) const
e3b2b5e5 155{
156 //
157 // Return LTU tracklet at position "pos"
158 //
159
6d50f529 160 if (fTracklets == 0) {
161 return 0;
162 }
163 void *trk = fTracklets->UncheckedAt(pos);
164 if (trk == 0) {
165 return 0;
166 }
e3b2b5e5 167
6d50f529 168 return (AliTRDltuTracklet *) trk;
e3b2b5e5 169
170}
171
172//_____________________________________________________________________________
5b0e57fd 173Int_t AliTRDgtuTrack::Compare(const TObject *o) const
e3b2b5e5 174{
175 //
176 // Compare function for sorting the tracks
177 //
178
6bf84b68 179 AliTRDgtuTrack *gtutrack = (AliTRDgtuTrack *) o;
e3b2b5e5 180
6bf84b68 181 if (fYproj < gtutrack->GetYproj()) {
182 return -1;
183 }
184 if (fYproj == gtutrack->GetYproj()) {
185 return 0;
186 }
e3b2b5e5 187
188 return +1;
189
190}
191
192//_____________________________________________________________________________
193void AliTRDgtuTrack::Reset()
194{
195 //
196 // Reset the track information
197 //
198
6d50f529 199 fYproj = 0.0;
200 fZproj = 0.0;
201 fSlope = 0.0;
202 fDetector = -1;
e3b2b5e5 203 fNtracklets = 0;
6d50f529 204 fNplanes = 0;
205 fNclusters = 0;
206 fPt = 0.0;
207 fPhi = 0.0;
208 fEta = 0.0;
209 fLabel = -1;
210 fPID = 0.0;
e3b2b5e5 211 fIsElectron = kFALSE;
212
213}
214
215//_____________________________________________________________________________
216void AliTRDgtuTrack::Track(Float_t xpl, Float_t field)
217{
218 //
219 // Calculate the kinematics of the found track
220 //
221
6d50f529 222 Int_t i = 0;
223 Int_t iDet = 0;
224 Int_t nDet = 0;
225 Bool_t newDetector;
226
e3b2b5e5 227 AliTRDltuTracklet *trk;
228 Int_t nTracklets = GetNtracklets();
229 Float_t fC[kNmaxTrk][3]; // X, Y, Z coordinates of segments
230
6d50f529 231 fYproj = 0.0;
232 fZproj = 0.0;
233 fSlope = 0.0;
234 fNclusters = 0;
235 fNplanes = 0;
e3b2b5e5 236 fNtracklets = GetNtracklets();
053767a4 237 Int_t inDetector[kNlayer];
238 for (i = 0; i < kNlayer; i++) {
6d50f529 239 inDetector[i] = -1;
240 }
241
242 for (i = 0; i < nTracklets; i++) {
e3b2b5e5 243
5b0e57fd 244 trk = GetTracklet(i);
245 fYproj += trk->GetYproj(xpl);
246 fZproj += trk->GetZproj(xpl);
247 fSlope += trk->GetSlope();
e3b2b5e5 248 fNclusters += trk->GetNclusters();
5b0e57fd 249 iDet = trk->GetDetector();
e3b2b5e5 250
251 newDetector = kTRUE;
252 for (Int_t id = 0; id < nDet; id++) {
253 if (iDet == inDetector[id]) {
254 newDetector = kFALSE;
255 break;
256 }
257 }
258 if (newDetector) {
259 inDetector[nDet++] = iDet;
260 fNplanes++;
261 }
262
263 fC[i][0] = trk->GetTime0();
264 fC[i][1] = trk->GetOffset();
265 fC[i][2] = trk->GetRowz();
266
267 }
5b0e57fd 268 fYproj /= (Float_t) nTracklets;
269 fZproj /= (Float_t) nTracklets;
270 fSlope /= (Float_t) nTracklets;
271
272 Float_t x[kNmaxTrk+1];
273 Float_t y[kNmaxTrk+1];
274 Float_t z[kNmaxTrk+1];
275 Bool_t count[kNmaxTrk];
6c27b212 276 for (i = 0; i < kNmaxTrk; i++) {
5b0e57fd 277 count[i] = kFALSE;
278 }
e3b2b5e5 279
280 Int_t iXmin = -1;
5b0e57fd 281 Int_t j = 0;
e3b2b5e5 282 x[0] = y[0] = z[0] = 0.0;
283 while (j < nTracklets) {
284 iXmin = -1;
6c27b212 285 for (i = 0; i < nTracklets; i++) {
e3b2b5e5 286 if (count[i]) continue;
287 if (iXmin == -1) {
288 iXmin = i;
289 continue;
290 }
5b0e57fd 291 if (fC[i][0] < fC[iXmin][0]) {
292 iXmin = i;
293 }
e3b2b5e5 294 }
295 x[j+1] = fC[iXmin][0];
296 y[j+1] = fC[iXmin][1];
297 z[j+1] = fC[iXmin][2];
298 j++;
299 count[iXmin] = kTRUE;
300 }
301
302 TMatrixD smatrix(2,2);
303 TMatrixD sums(2,1);
304 TMatrixD res(2,1);
305 Double_t xv, yv;
306 Float_t a, b;
307
308 smatrix.Zero();
309 sums.Zero();
6d50f529 310 for (i = 0; i < nTracklets; i++) {
5b0e57fd 311 xv = (Double_t) x[i+1];
312 yv = (Double_t) y[i+1];
e3b2b5e5 313 smatrix(0,0) += 1.0;
314 smatrix(1,1) += xv*xv;
315 smatrix(0,1) += xv;
316 smatrix(1,0) += xv;
317 sums(0,0) += yv;
318 sums(1,0) += xv*yv;
319 }
320 res = smatrix.Invert() * sums;
5b0e57fd 321 a = res(0,0);
322 b = res(1,0);
e3b2b5e5 323
6d50f529 324 Float_t dist = AliTRDgeometry::GetTime0(1) - AliTRDgeometry::GetTime0(0);
5b0e57fd 325 Float_t fx1 = x[1] + dist * (Float_t) (nTracklets-1) / 6.0;
6d50f529 326 Float_t fy1 = a + b * fx1;
5b0e57fd 327 Float_t fx2 = x[nTracklets] - dist * (Float_t) (nTracklets-1) / 6.0;
6d50f529 328 Float_t fy2 = a + b * fx2;
329 Float_t d12 = TMath::Sqrt((fx2-fx1)*(fx2-fx1)+(fy2-fy1)*(fy2-fy1));
e3b2b5e5 330 Float_t alpha = TMath::ATan(fy2/fx2) - TMath::ATan(fy1/fx1);
5b0e57fd 331 Float_t r = (d12 / 2.0) / TMath::Sin(alpha);
e3b2b5e5 332
333 fPt = 0.3 * field * 0.01 * r;
334
5b0e57fd 335 Float_t d1 = fx1*fx1 + fy1*fy1;
336 Float_t d2 = fx2*fx2 + fy2*fy2;
337 Float_t d = fx1*fy2 - fx2*fy1;
e3b2b5e5 338
5b0e57fd 339 Float_t xc = (d1*fy2 - d2*fy1) / (2.0*d);
340 Float_t yc = (d2*fx1 - d1*fx2) / (2.0*d);
e3b2b5e5 341
342 if (yc != 0.0) {
343 fPhi = TMath::ATan(xc/yc);
6d50f529 344 }
345 else {
e3b2b5e5 346 fPhi = TMath::PiOver2();
347 }
348
349 fPhi *= 180.0/TMath::Pi();
350
351 smatrix.Zero();
352 sums.Zero();
6d50f529 353 for (i = 0; i < nTracklets+1; i++) {
5b0e57fd 354 xv = (Double_t) z[i];
355 yv = (Double_t) x[i];
e3b2b5e5 356 smatrix(0,0) += 1.0;
357 smatrix(1,1) += xv*xv;
358 smatrix(0,1) += xv;
359 smatrix(1,0) += xv;
360 sums(0,0) += yv;
361 sums(1,0) += xv*yv;
362 }
363 res = smatrix.Invert() * sums;
5b0e57fd 364 a = res(0,0);
365 b = res(1,0);
e3b2b5e5 366 Float_t theta = TMath::ATan(b);
367
6d50f529 368 if (theta < 0.0) {
369 theta = TMath::Pi() + theta;
370 }
e3b2b5e5 371 if (theta == 0.0) {
372 fEta = 0.0;
6d50f529 373 }
374 else {
e3b2b5e5 375 fEta = -TMath::Log(TMath::Tan(theta/2.0));
376 }
377
378}
379
380//_____________________________________________________________________________
381void AliTRDgtuTrack::MakePID()
382{
383 //
384 // Electron likelihood signal
385 //
386
6d50f529 387 Int_t i = 0;
388
6bf84b68 389 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
390 if (!calibration) {
6d50f529 391 AliError("No instance of AliTRDcalibDB.");
e3b2b5e5 392 return;
393 }
4ba1d6ae 394
395 AliTRDrecoParam *rec = AliTRDReconstructor::RecoParam();
396 if (!rec) {
397 AliError("No TRD reco param.");
398 return;
399 }
400
401 const AliTRDCalPID *pd = calibration->GetPIDObject(rec->GetPIDMethod());
e3b2b5e5 402
403 AliTRDltuTracklet *trk;
6bf84b68 404 Int_t nTracklets = GetNtracklets();
405 Int_t det;
406 Int_t pla;
407 Float_t sl;
408 Float_t th;
409 Float_t q;
410 Float_t probPio = 1.0;
411 Float_t probEle = 1.0;
412
6d50f529 413 for (i = 0; i < nTracklets; i++) {
e3b2b5e5 414
415 trk = GetTracklet(i);
416
5b0e57fd 417 sl = TMath::Abs(trk->GetSlope()); // Tracklet inclination in X-y plane
418 th = trk->GetRowz()/trk->GetTime0(); // Tracklet inclination in X-z plane
419 th = TMath::ATan(TMath::Abs(th));
e3b2b5e5 420
5b0e57fd 421 q = trk->GetQ()
422 * TMath::Cos(sl/180.0*TMath::Pi())
423 * TMath::Cos(th/180.0*TMath::Pi());
e3b2b5e5 424
425 det = trk->GetDetector();
426 pla = trk->GetPlane(det);
427
5b0e57fd 428 // Unclear yet factor to match the PS distributions = 5.8
e3b2b5e5 429 // not explained only by the tail filter ...
e3b2b5e5 430 // AliRoot v4-03-07 , v4-03-Release
431 //q = q * 5.8;
432
4c8471bd 433 // HEAD28Mar06
e3b2b5e5 434 // Temporary (B. Vulpescu):
435 // The charge distributions do not match the new changes in simulation (A. Bercuci),
436 // which are nevertheless now in agreement with the beam tests.
437 // Some tricks will be used to still have reasonable results
438 // To match the existing charge distributions, the charge per layer has to be modified
439 // as folows:
440 /*
441 if (k == 0) {
442 // electrons
443 q = 4.3 * q + 95.0;
444 } else {
445 // others
446 q = 4.2 * q + 70.0;
447 }
448 */
449 // Since at tracking time we have no information on the particle type, we will modify
450 // instead the charge distributions accordingly. This will slow down the sampling.
451 // The modified distributions are in TRDdEdxHistogramsV1_BV.root and the CDB has
452 // been regenerated with AliTRDCreateDummyCDB.C
453 // The new PIDLQ data base has the version :
454 // I-AliCDBLocal::Get: CDB object retrieved: path "TRD/Calib/PIDLQ"; run range [0,0];
455 // version v0_s1
456
4c8471bd 457 // HEAD28Mar06 new distributions: factor = 6.0
458
dab811d0 459 // A.Bercuci on 2nd May 2007
460 // Temporary modification to deal with more energy slices. The values
461 // attached to charge slices and track length are dummy
c6011b06 462 Float_t dedx[3];
463 dedx[0] = dedx[1] = q*3.; dedx[2] = 0.;
464 Float_t length = 3.7;
465
44dbae42 466 probEle *= pd->GetProbability(0, TMath::Abs(fPt), dedx, length, 0);
467 probPio *= pd->GetProbability(2, TMath::Abs(fPt), dedx, length, 0);
e3b2b5e5 468
469 }
470
5b0e57fd 471 if ((probEle + probPio) > 0.0) {
472 fPID = probEle/(probEle + probPio);
6d50f529 473 }
474 else {
e3b2b5e5 475 fPID = 0.0;
476 }
477
478 // Thresholds for LQ cut at 90% electron efficiency (from AliRoot v4-03-07)
479 // P [GeV/c] fPIDcut (between 0 and 1)
480 // 2 0.925
481 // 3 0.915
482 // 4 0.875
483 // 5 0.855
484 // 6 0.845
485 // 8 0.785
486 // 10 0.735
487 //
488 // PIDcut = 0.978 - 0.024 * P[GeV/c]
489 //Float_t PIDcut = 0.978 - 0.024 * TMath::Abs(fPt);
490
491 // HEAD28Mar06 with modified distributions (A. Bercuci changes, P. Shukla distributions)
4c8471bd 492 //Float_t fPIDcut = 0.829 - 0.032 * TMath::Abs(fPt);
493
494 // HEAD28Mar06 with new generated distributions (pol2 fit)
5b0e57fd 495 Float_t absPt = TMath::Abs(fPt);
4c8471bd 496 //Float_t fPIDcut = 0.9575 - 0.0832 * absPt + 0.0037 * absPt*absPt; // 800 bins in dEdx
497 Float_t fPIDcut = 0.9482 - 0.0795 * absPt + 0.0035 * absPt*absPt; // 200 bins in dEdx
e3b2b5e5 498
499 fIsElectron = kFALSE;
500 if (fPID >= fPIDcut) {
501 fIsElectron = kTRUE;
502 }
503
504}
505
506//_____________________________________________________________________________
507void AliTRDgtuTrack::CookLabel()
508{
509 //
510 // Cook the track label from tracklets labels
511 //
512
513 AliTRDltuTracklet *trk;
514
515 const Int_t kMaxTracks = 10;
516 Int_t trackLabel[kMaxTracks];
517 Int_t trackCount[kMaxTracks];
518 for (Int_t it = 0; it < kMaxTracks; it++) {
519 trackLabel[it] = -1;
5b0e57fd 520 trackCount[it] = 0;
e3b2b5e5 521 }
522
523 Bool_t counted;
6bf84b68 524 Int_t label;
525 Int_t nTracks = 0;
e3b2b5e5 526 for (Int_t itrk = 0; itrk < fNtracklets; itrk++) {
527
528 trk = GetTracklet(itrk);
529
6bf84b68 530 if (trk->GetLabel() == -1) {
531 continue;
532 }
e3b2b5e5 533
534 label = trk->GetLabel();
535
536 counted = kFALSE;
537 for (Int_t it = 0; it < nTracks; it++) {
538 if (label == trackLabel[it]) {
539 trackCount[it]++;
540 counted = kTRUE;
541 break;
542 }
543 }
544 if (!counted) {
545 trackLabel[nTracks] = label;
546 trackCount[nTracks]++;
547 nTracks++;
548 if (nTracks == kMaxTracks) {
549 Warning("CookLabel","Too many tracks for this tracklet.");
550 nTracks--;
551 break;
552 }
553 }
554
555 }
556
6bf84b68 557 Float_t frac = 4.0 / 5.0;
e3b2b5e5 558 for (Int_t it = 0; it < kMaxTracks; it++) {
6bf84b68 559 if (trackCount[it] >= (Int_t) (frac*fNtracklets)) {
e3b2b5e5 560 fLabel = trackLabel[it];
561 break;
562 }
563 }
564
565}
566
6d50f529 567//_____________________________________________________________________________
568void AliTRDgtuTrack::ResetTracklets()
569{
570 //
571 // Resets the list of tracklets
572 //
573
574 if (fTracklets) {
5b0e57fd 575 //fTracklets->Delete();
576 fTracklets->Clear();
6d50f529 577 }
578
579}
580
581//_____________________________________________________________________________
6bf84b68 582TObjArray *AliTRDgtuTrack::Tracklets()
6d50f529 583{
584 //
585 // Returns the list of tracklets
586 //
587
588 if (!fTracklets) {
589 fTracklets = new TObjArray(400);
590 }
591
592 return fTracklets;
593
594}
595
596//_____________________________________________________________________________
597Int_t AliTRDgtuTrack::GetNtracklets() const
598{
599 //
600 // Returns the number of tracklets
601 //
602
603 if (fTracklets) {
604 return fTracklets->GetEntriesFast();
605 }
606
607 return 0;
608
609}