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