Coding rule violations corrected.
[u/mrichter/AliRoot.git] / ANALYSIS / AliTrackPoints.cxx
CommitLineData
a5556ea5 1//_________________________________
2////////////////////////////////////////////////////////////
3// //
4// class AliTrackPoints //
5// //
6// used by Anti-Merging cut //
7// contains set of poits the lay on track trajectory //
8// according to reconstructed track parameters - //
9// NOT CLUSTERS POSITIONS!!! //
10// Anti-Merging cut is applied only on tracks coming from //
11// different events (that are use to fill deniminators) //
12// //
13////////////////////////////////////////////////////////////
14
15#include <TClonesArray.h>
16#include <TFile.h>
17#include <TMath.h>
18
19#include "AliESDtrack.h"
20#include "AliTrackPoints.h"
21#include "AliTPCtrack.h"
22#include "AliTrackReference.h"
23
24ClassImp(AliTrackPoints)
25
26Int_t AliTrackPoints::fgDebug = 0;
27AliTrackPoints::AliTrackPoints():
28 fN(0),
29 fX(0x0),
30 fY(0x0),
31 fZ(0x0)
32{
33 //constructor
34}
35/***************************************************************/
36
37AliTrackPoints::AliTrackPoints(Int_t n, AliESDtrack* track, Float_t mf, Float_t dr, Float_t r0):
38 fN(n),
39 fX(new Float_t[fN]),
40 fY(new Float_t[fN]),
41 fZ(new Float_t[fN])
42{
43 //constructor
44 //mf - magnetic field in kG - needed to calculated curvature out of Pt
45 //r0 - starting radius
46 //dr - calculate points every dr cm, default every 30cm
47 if (track == 0x0)
48 {
49 Error("AliTrackPoints","ESD track is null");
50 fN = 0;
51 delete [] fX;
52 delete [] fY;
53 delete [] fZ;
54 fX = fY = fZ = 0x0;
55 return;
56 }
57
58 if ( ((track->GetStatus() & AliESDtrack::kTPCrefit) == kFALSE)&&
59 ((track->GetStatus() & AliESDtrack::kTPCin) == kFALSE) )
60 {
61 //could happend: its stand alone tracking
62 if (GetDebug() > 3)
63 Warning("AliTrackPoints","This ESD track does not contain TPC information");
64
65 fN = 0;
66 delete [] fX;
67 delete [] fY;
68 delete [] fZ;
69 fX = fY = fZ = 0x0;
70
71 return;
72 }
73
74 Double_t x;
75 Double_t par[5];
76 track->GetInnerExternalParameters(x,par); //get properties of the track
77 if (par[4] == 0)
78 {
79 Error("AliTrackPoints","This ESD track seem not to contain TPC information (curv is 0)");
80 return;
81 }
82
83 if (mf == 0.0)
84 {
85 Error("AliTrackPoints","Zero Magnetic field passed as parameter.");
86 return;
87 }
88
89 Double_t alpha = track->GetInnerAlpha();
90 Double_t cc = 1000./0.299792458/mf;//conversion constant
91 Double_t c=par[4]/cc;
92
93 MakePoints(dr,r0,x,par,c,alpha);
94
95}
96/***************************************************************/
97
98AliTrackPoints::AliTrackPoints(Int_t n, AliTPCtrack* track, Float_t dr, Float_t r0):
99 fN(n),
100 fX(new Float_t[fN]),
101 fY(new Float_t[fN]),
102 fZ(new Float_t[fN])
103{
104 //constructor
105 //r0 starting radius
106 //dr - calculate points every dr cm, default every 30cm
107 if (track == 0x0)
108 {
109 Error("AliTrackPoints","TPC track is null");
110 fN = 0;
111 delete [] fX;
112 delete [] fY;
113 delete [] fZ;
114 fX = fY = fZ = 0x0;
115 return;
116 }
117 track->PropagateTo(r0);
118
119 //* This formation is now fixed in the following way: *
120 //* external param0: local Y-coordinate of a track (cm) *
121 //* external param1: local Z-coordinate of a track (cm) *
122 //* external param2: local sine of the track momentum azimuth angle *
123 //* external param3: tangent of the track momentum dip angle *
124 //* external param4: 1/pt (1/(GeV/c)) *
125
126 Double_t x = 0;
127 Double_t par[5];
128 track->GetExternalParameters(x,par); //get properties of the track
129
130 Double_t alpha = track->GetAlpha();
131 Double_t c=track->GetC();
132 MakePoints(dr,r0,x,par,c,alpha);
133}
134
135void AliTrackPoints::MakePoints( Float_t dr, Float_t r0, Double_t x, Double_t* par, Double_t c, Double_t alpha)
136{
137 //Calculates points starting at radius r0
138 //spacing every dr (in radial direction)
139 // according to track parameters
140 // x - position in sector local reference frame. x i parallel to R and sector is symmetric with respect to x
141 // par - track external parameters; array with 5 elements; look at AliTPCtrack.h or AliESDtrack.h for their meaning
142 // c - track curvature
143 // alpha - sector's rotation angle (phi) == angle needed for local to global transformation
144
145 Double_t y = par[0];
146 Double_t z0 = par[1];
147
148 Double_t phi0local = TMath::ATan2(y,x);
149 Double_t phi0global = phi0local + alpha;
150
151 if (phi0local<0) phi0local+=2*TMath::Pi();
152 if (phi0local>=2.*TMath::Pi()) phi0local-=2*TMath::Pi();
153
154 if (phi0global<0) phi0global+=2*TMath::Pi();
155 if (phi0global>=2.*TMath::Pi()) phi0global-=2*TMath::Pi();
156
157 Double_t r = TMath::Hypot(x,y);
158
159
160 if (GetDebug() > 9)
161 Info("AliTrackPoints","Radius0 %f, Real Radius %f",r0,r);
162
163 if (GetDebug() > 5)
164 Info("AliTrackPoints","Phi Global at first padraw %f, Phi locat %f",phi0global,phi0local);
165
166 Double_t eta = x*c - par[2] ;//par[2] = fX*C - eta; eta==fP2 ; C==fP4
167
168 //this calculattions are assuming new (current) model
169 Double_t tmp = par[2];
170 tmp = 1. - tmp*tmp;
171 tmp = c*y + TMath::Sqrt(tmp);
172 Double_t dca=(TMath::Hypot(eta,tmp) - 1. )/TMath::Abs(c);
173
174 //Here is old model Cold=Cnew/2.
175 Double_t dcasq = dca*dca;
176 Double_t c2 = c/2.;
177 Double_t cst1 = (1.+c2*dca)*dca;//first constant
178 Double_t cst2 = 1. + 2.*c2*dca;//second constant
179
180 Double_t factorPhi0 = TMath::ASin((c2*r + cst1/r)/cst2);
181 Double_t factorZ0 = TMath::ASin(c2*TMath::Sqrt((r*r-dcasq)/cst2))*par[3]/c2;
182
183 for(Int_t i = 0; i<fN; i++)
184 {
185 Double_t rc = r0 + i*dr;
186 Double_t ftmp = (c2*rc + cst1/rc)/cst2;
187 if (ftmp > 1.0)
188 {
189 if (GetDebug() > 1)
190 Warning("AliTrackPoints","ASin argument > 1 %f:",ftmp);
191 ftmp=1.0;
192 }
193 else if (ftmp < -1.0)
194 {
195 if (GetDebug() > 1)
196 Warning("AliTrackPoints","ASin argument < -1 %f:",ftmp);
197 ftmp=-1.0;
198 }
199
200 Double_t factorPhi = TMath::ASin( ftmp );//factor phi od rc
201 Double_t phi = phi0global + factorPhi - factorPhi0;
202
203 ftmp = (rc*rc-dcasq)/cst2;
204 if (ftmp < 0.0)
205 {
206 if (GetDebug() > 1)
207 Warning("AliTrackPoints","Sqrt argument < 0: %f",ftmp);
208 ftmp=0.0;
209 }
210
211 ftmp = c2*TMath::Sqrt(ftmp);
212 if (ftmp > 1.0)
213 {
214 if (GetDebug() > 1)
215 Warning("AliTrackPoints","ASin argument > 1: %f",ftmp);
216 ftmp=1.0;
217 }
218 else if (ftmp < -1.0)
219 {
220 if (GetDebug() > 1)
221 Warning("AliTrackPoints","ASin argument < -1: %f",ftmp);
222 ftmp=-1.0;
223 }
224 Double_t factorZ = TMath::ASin(ftmp)*par[3]/c2;
225 fZ[i] = z0 + factorZ - factorZ0;
226 fX[i] = rc*TMath::Cos(phi);
227 fY[i] = rc*TMath::Sin(phi);
228
229 if ( GetDebug() > 2 )
230 {
231 Info("AliTrackPoints","X %f Y %f Z %f R asked %f R obtained %f",
232 fX[i],fY[i],fZ[i],rc,TMath::Hypot(fX[i],fY[i]));
233 }
234 }
235}
236/***************************************************************/
237
238AliTrackPoints::~AliTrackPoints()
239{
240 //destructor
241 delete [] fX;
242 delete [] fY;
243 delete [] fZ;
244}
245/***************************************************************/
246
247void AliTrackPoints::PositionAt(Int_t n, Float_t &x,Float_t &y,Float_t &z)
248{
249 //returns position at point n
250 if ((n<0) || (n>fN))
251 {
252 Error("PositionAt","Point %d out of range",n);
253 return;
254 }
255
256 x = fX[n];
257 y = fY[n];
258 z = fZ[n];
259 if ( GetDebug() > 1 )
260 {
261 Info("AliTrackPoints","n %d; X %f; Y %f; Z %f",n,x,y,z);
262 }
263}
264/***************************************************************/
265
266Double_t AliTrackPoints::AvarageDistance(const AliTrackPoints& tr)
267{
268 //returns the aritmethic avarage distance between two tracks
269// Info("AvarageDistance","Entered");
270 if ( (fN <= 0) || (tr.fN <=0) )
271 {
272 if (GetDebug()) Warning("AvarageDistance","One of tracks is empty");
273 return -1;
274 }
275
276 if (fN != tr.fN)
277 {
278 Warning("AvarageDistance","Number of points is not equal");
279 return -1;
280 }
281
282 Double_t sum = 0;
283 for (Int_t i = 0; i<fN; i++)
284 {
285 if (GetDebug()>9)
286 {
287// Float_t r1sq = fX[i]*fX[i]+fY[i]*fY[i];
288// Float_t r2sq = tr.fX[i]*tr.fX[i]+tr.fY[i]*tr.fY[i];
289 Float_t r1sq = TMath::Hypot(fX[i],fY[i]);
290 Float_t r2sq = TMath::Hypot(tr.fX[i],tr.fY[i]);
291 Info("AvarageDistance","radii: %f %f",r1sq,r2sq);
292 }
293
294
295 Double_t dx = fX[i]-tr.fX[i];
296 Double_t dy = fY[i]-tr.fY[i];
297 Double_t dz = fZ[i]-tr.fZ[i];
298 sum+=TMath::Sqrt(dx*dx + dy*dy + dz*dz);
299
300 if (GetDebug()>1)
301 {
302 Info("AvarageDistance","Diff: x ,y z: %f , %f, %f",dx,dy,dz);
303 Info("AvarageDistance","xxyyzz %f %f %f %f %f %f",
304 fX[i],tr.fX[i],fY[i],tr.fY[i],fZ[i],tr.fZ[i]);
305 }
306 }
307
308 Double_t retval = sum/((Double_t)fN);
309 if ( GetDebug() )
310 {
311 Info("AvarageDistance","Avarage distance is %f.",retval);
312 }
313 return retval;
314}
315/***************************************************************/
316/***************************************************************/
317/***************************************************************/
318/***************************************************************/
319/***************************************************************/
320/***************************************************************/
321
322#include "AliRun.h"
323#include "AliESD.h"
324#include "AliRunLoader.h"
325#include "AliTPCtrack.h"
326#include "TTree.h"
327#include "TBranch.h"
328#include "TH2D.h"
329#include "TCanvas.h"
330#include "AliMagF.h"
331
332
333
334
335void AliTrackPoints::TestESD(Int_t entr,const char* fname )
336{
337//Tests creation of track points for ESD tracks
338 delete gAlice;
339 gAlice = 0x0;
340 AliRunLoader* rl = AliRunLoader::Open();
341 rl->LoadgAlice();
342
343 Float_t mf = rl->GetAliRun()->Field()->SolenoidField();
344
345
346 TFile* fFile = TFile::Open(fname);
347
348 if (fFile == 0x0)
349 {
350 printf("testesd: There is no suche a ESD file\n");
351 return;
352 }
353 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get("0"));
354 AliESDtrack *t = esd->GetTrack(entr);
355 if (t == 0x0)
356 {
357 ::Error("testesd","Can not get track %d",entr);
358 return;
359 }
360
361
362 Int_t N = 170;
363 AliTrackPoints* tp = new AliTrackPoints(N,t,mf,1.);
364
365 Float_t xmin = -250;
366 Float_t xmax = 250;
367
368 Float_t ymin = -250;
369 Float_t ymax = 250;
370
371 Float_t zmin = -250;
372 Float_t zmax = 250;
373
374 TH2D* hxy = new TH2D("hxy","hxy",1000,xmin,xmax,1000,ymin,ymax);
375 TH2D* hxyt = new TH2D("hxyt","hxyt",1000,xmin,xmax,1000,ymin,ymax);
376 TH2D* hxyTR = new TH2D("hxyTR","hxyTR",1000,xmin,xmax,1000,ymin,ymax);
377
378 TH2D* hxz = new TH2D("hxz","hxz",1000,xmin,xmax,1000,zmin,zmax);
379 TH2D* hxzt = new TH2D("hxzt","hxzt",1000,xmin,xmax,1000,zmin,zmax);
380 TH2D* hxzTR = new TH2D("hxzTR","hxzTR",1000,xmin,xmax,1000,zmin,zmax);
381
382 hxyt->SetDirectory(0x0);
383 hxy->SetDirectory(0x0);
384 hxyTR->SetDirectory(0x0);
385
386 hxzt->SetDirectory(0x0);
387 hxz->SetDirectory(0x0);
388 hxzTR->SetDirectory(0x0);
389
390 Float_t x,y,z;
391
392 for (Int_t i = 0;i<N;i++)
393 {
394 Double_t r = 84.1+i;
395 tp->PositionAt(i,x,y,z);
396 hxy->Fill(x,y);
397 hxz->Fill(x,z);
398 printf("Rdemanded %f\n",r);
399 printf("tpx %f tpy %f tpz %f Rt =%f\n", x,y,z,TMath::Hypot(x,y));
400
401 }
402
403 rl->LoadTrackRefs();
404 TTree* treeTR = rl->TreeTR();
405 TBranch* b = treeTR->GetBranch("TPC");
406
407 TClonesArray* trackrefs = new TClonesArray("AliTrackReference", 100);
408 AliTrackReference* tref;
409 b->SetAddress(&trackrefs);
410
411 Int_t tlab = TMath::Abs(t->GetLabel());
412
413 Int_t netr = (Int_t)treeTR->GetEntries();
414 printf("Found %d entries in TR tree\n",netr);
415
416 for (Int_t e = 0; e < netr; e++)
417 {
418 treeTR->GetEntry(e);
419 tref = (AliTrackReference*)trackrefs->At(0);
420 if (tref == 0x0) continue;
421 if (tref->GetTrack() != tlab) continue;
422
423 printf("Found %d entries in TR array\n",trackrefs->GetEntries());
424
425 for (Int_t i = 0; i < trackrefs->GetEntries(); i++)
426 {
427 tref = (AliTrackReference*)trackrefs->At(i);
428 if (tref->GetTrack() != tlab) continue;
429 x = tref->X();
430 y = tref->Y();
431 z = tref->Z();
432 printf("Track Ref: x %f y %f z %f\n",tref->X(),tref->Y(),tref->Z());
433
434 hxzTR->Fill(x,z);
435 hxyTR->Fill(x,y);
436 for (Int_t j = 1; j < 10; j++)
437 {
438 hxyTR->Fill(x, y+j*0.1);
439 hxyTR->Fill(x, y-j*0.1);
440 hxyTR->Fill(x+j*0.1,y);
441 hxyTR->Fill(x-j*0.1,y);
442
443 hxzTR->Fill(x,z-j*0.1);
444 hxzTR->Fill(x,z+j*0.1);
445 hxzTR->Fill(x-j*0.1,z);
446 hxzTR->Fill(x+j*0.1,z);
447 }
448 }
449 break;
450 }
451 hxy->Draw("");
452// hxzt->Draw("same");
453 hxyTR->Draw("same");
454
455 delete rl;
456}
457
458/***************************************************************/
459/***************************************************************/
460/***************************************************************/
461
462void AliTrackPoints::TestTPC(Int_t entr)
463{
464//Tests creation of track points for TPC tracks
465 delete gAlice;
466 gAlice = 0x0;
467 AliRunLoader* rl = AliRunLoader::Open();
468 AliLoader* l = rl->GetLoader("TPCLoader");
469 rl->LoadgAlice();
470 AliKalmanTrack::SetConvConst(100/0.299792458/0.2/rl->GetAliRun()->Field()->Factor());
471 l->LoadTracks();
472 AliTPCtrack* t = new AliTPCtrack();
473 TBranch* b=l->TreeT()->GetBranch("tracks");
474 b->SetAddress(&t);
475 l->TreeT()->GetEntry(entr);
476 Int_t N = 160;
477 AliTrackPoints* tp = new AliTrackPoints(N,t,1.);
478
479 Float_t xmin = -250;
480 Float_t xmax = 250;
481
482 Float_t ymin = -250;
483 Float_t ymax = 250;
484
485 Float_t zmin = -250;
486 Float_t zmax = 250;
487
488 TH2D* hxy = new TH2D("hxy","hxy",1000,xmin,xmax,1000,ymin,ymax);
489 TH2D* hxyt = new TH2D("hxyt","hxyt",1000,xmin,xmax,1000,ymin,ymax);
490 TH2D* hxyTR = new TH2D("hxyTR","hxyTR",1000,xmin,xmax,1000,ymin,ymax);
491
492 TH2D* hxz = new TH2D("hxz","hxz",1000,xmin,xmax,1000,zmin,zmax);
493 TH2D* hxzt = new TH2D("hxzt","hxzt",1000,xmin,xmax,1000,zmin,zmax);
494 TH2D* hxzTR = new TH2D("hxzTR","hxzTR",1000,xmin,xmax,1000,zmin,zmax);
495
496 hxyt->SetDirectory(0x0);
497 hxy->SetDirectory(0x0);
498 hxyTR->SetDirectory(0x0);
499
500 hxzt->SetDirectory(0x0);
501 hxz->SetDirectory(0x0);
502 hxzTR->SetDirectory(0x0);
503
504 Float_t x,y,z;
505
506 for (Int_t i = 0;i<N;i++)
507 {
508 Double_t r = 84.1+i;
509 tp->PositionAt(i,x,y,z);
510 hxy->Fill(x,y);
511 hxz->Fill(x,z);
512 printf("Rdemanded %f\n",r);
513 printf("tpx %f tpy %f tpz %f Rt =%f\n", x,y,z,TMath::Hypot(x,y));
514
515 //BUT they are local!!!!
516 t->PropagateTo(r);
517// Double_t phi = t->Phi();
518 Double_t rl = TMath::Hypot(t->GetX(),t->GetY());//real radius
519
520 Double_t alpha = t->GetAlpha();
521 Double_t salpha = TMath::Sin(alpha);
522 Double_t calpha = TMath::Cos(alpha);
523 x = t->GetX()*calpha - t->GetY()*salpha;
524 y = t->GetX()*salpha + t->GetY()*calpha;
525 z = t->GetZ();
526
527 printf("tx %f ty %f tz %f Rt = %f R from XY %f\n",x,y,z,TMath::Hypot(x,y),rl);
528
529 printf("tpz - tz %f\n",z-t->GetZ());
530 printf("\n");
531 hxyt->Fill(x,y);
532 hxzt->Fill(x,z);
533
534 }
535
536 rl->LoadTrackRefs();
537 TTree* treeTR = rl->TreeTR();
538 b = treeTR->GetBranch("TPC");
539
540 TClonesArray* trackrefs = new TClonesArray("AliTrackReference", 100);
541 AliTrackReference* tref;
542 b->SetAddress(&trackrefs);
543
544 Int_t tlab = TMath::Abs(t->GetLabel());
545
546 Int_t netr = (Int_t)treeTR->GetEntries();
547 printf("Found %d entries in TR tree\n",netr);
548
549 for (Int_t e = 0; e < netr; e++)
550 {
551 treeTR->GetEntry(e);
552 tref = (AliTrackReference*)trackrefs->At(0);
553 if (tref == 0x0) continue;
554 if (tref->GetTrack() != tlab) continue;
555
556 printf("Found %d entries in TR array\n",trackrefs->GetEntries());
557
558 for (Int_t i = 0; i < trackrefs->GetEntries(); i++)
559 {
560 tref = (AliTrackReference*)trackrefs->At(i);
561 if (tref->GetTrack() != tlab) continue;
562 x = tref->X();
563 y = tref->Y();
564 z = tref->Z();
565 printf("Track Ref: x %f y %f z %f\n",tref->X(),tref->Y(),tref->Z());
566
567 hxzTR->Fill(x,z);
568 hxyTR->Fill(x,y);
569 for (Int_t j = 1; j < 10; j++)
570 {
571 hxyTR->Fill(x, y+j*0.1);
572 hxyTR->Fill(x, y-j*0.1);
573 hxyTR->Fill(x+j*0.1,y);
574 hxyTR->Fill(x-j*0.1,y);
575
576 hxzTR->Fill(x,z-j*0.1);
577 hxzTR->Fill(x,z+j*0.1);
578 hxzTR->Fill(x-j*0.1,z);
579 hxzTR->Fill(x+j*0.1,z);
580 }
581 }
582 break;
583 }
584 hxz->Draw("");
585// hxzt->Draw("same");
586 hxzTR->Draw("same");
587
588 delete rl;
589}