1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////
20 // class AliTrackPoints //
22 // used by Anti-Merging cut //
23 // contains set of poits the lay on track trajectory //
24 // according to reconstructed track parameters - //
25 // NOT CLUSTERS POSITIONS!!! //
26 // Anti-Merging cut is applied only on tracks coming from //
27 // different events (that are use to fill deniminators) //
29 ////////////////////////////////////////////////////////////
31 #include "AliTrackPoints.h"
34 #include <TClonesArray.h>
38 #include "AliESDtrack.h"
39 #include "AliTPCtrack.h"
40 #include "AliTrackReference.h"
41 #include "AliITStrackV2.h"
45 #include "AliTracker.h"
47 #include "AliRunLoader.h"
48 #include "AliTPCtrack.h"
53 ClassImp(AliTrackPoints)
55 Int_t AliTrackPoints::fgDebug = 0;
57 AliTrackPoints::AliTrackPoints():
66 /***************************************************************/
68 AliTrackPoints::AliTrackPoints(AliTrackPoints::ETypes type, AliESDtrack* track, Float_t mf):
75 //tupe - what kind of track points should be calculated
76 //mf - magnetic field in [kG] = [T]*10.0
87 case kITSInnerFromVertexOuterFromTPC:
92 MakeITSPointsInnerFromVertexOuterFromTPC(track,mf);
96 Info("AliTrackPoints","Not recognized type");
101 /***************************************************************/
103 AliTrackPoints::AliTrackPoints(Int_t n, AliESDtrack* track, Float_t mf, Float_t dr, Float_t r0):
110 //mf - magnetic field in kG - needed to calculate curvature out of Pt
111 //r0 - starting radius
112 //dr - calculate points every dr cm, default every 30cm
115 Error("AliTrackPoints","ESD track is null");
124 if ( ((track->GetStatus() & AliESDtrack::kTPCrefit) == kFALSE)&&
125 ((track->GetStatus() & AliESDtrack::kTPCin) == kFALSE) )
127 //could happend: its stand alone tracking
128 AliDebug(3,"This ESD track does not contain TPC information");
141 track->GetInnerExternalParameters(alpha,x,par);//get properties of the track
144 Error("AliTrackPoints","This ESD track seem not to contain TPC information (curv is 0)");
150 Error("AliTrackPoints","Zero Magnetic field passed as parameter.");
154 //Double_t alpha = track->GetInnerAlpha();
155 Double_t cc = 1000./0.299792458/mf;//conversion constant
156 Double_t c=par[4]/cc;
158 MakePoints(dr,r0,x,par,c,alpha);
162 /***************************************************************/
164 AliTrackPoints::AliTrackPoints(Int_t n, AliTPCtrack* track, Float_t dr, Float_t r0):
172 //dr - calculate points every dr cm, default every 30cm
175 Error("AliTrackPoints","TPC track is null");
183 track->PropagateTo(r0);
185 //* This formation is now fixed in the following way: *
186 //* external param0: local Y-coordinate of a track (cm) *
187 //* external param1: local Z-coordinate of a track (cm) *
188 //* external param2: local sine of the track momentum azimuth angle *
189 //* external param3: tangent of the track momentum dip angle *
190 //* external param4: 1/pt (1/(GeV/c)) *
194 track->GetExternalParameters(x,par); //get properties of the track
196 Double_t alpha = track->GetAlpha();
197 Double_t c=track->GetC();
198 MakePoints(dr,r0,x,par,c,alpha);
201 /***************************************************************/
203 AliTrackPoints::~AliTrackPoints()
211 /***************************************************************/
213 void AliTrackPoints::MakePoints( Float_t dr, Float_t r0, Double_t x, Double_t* par, Double_t c, Double_t alpha)
215 //Calculates points starting at radius r0
216 //spacing every dr (in radial direction)
217 // according to track parameters
218 // x - position in sector local reference frame. x i parallel to R and sector is symmetric with respect to x
219 // par - track external parameters; array with 5 elements; look at AliTPCtrack.h or AliESDtrack.h for their meaning
220 // c - track curvature
221 // alpha - sector's rotation angle (phi) == angle needed for local to global transformation
224 Double_t z0 = par[1];
226 Double_t phi0local = TMath::ATan2(y,x);
227 Double_t phi0global = phi0local + alpha;
229 if (phi0local<0) phi0local+=2*TMath::Pi();
230 if (phi0local>=2.*TMath::Pi()) phi0local-=2*TMath::Pi();
232 if (phi0global<0) phi0global+=2*TMath::Pi();
233 if (phi0global>=2.*TMath::Pi()) phi0global-=2*TMath::Pi();
235 Double_t r = TMath::Hypot(x,y);
238 AliDebug(9,Form("Radius0 %f, Real Radius %f",r0,r));
240 AliDebug(5,Form("Phi Global at first padraw %f, Phi locat %f",phi0global,phi0local));
242 Double_t eta = x*c - par[2] ;//par[2] = fX*C - eta; eta==fP2 ; C==fP4
244 //this calculattions are assuming new (current) model
245 Double_t tmp = par[2];
247 tmp = c*y + TMath::Sqrt(tmp);
248 Double_t dca=(TMath::Hypot(eta,tmp) - 1. )/TMath::Abs(c);
250 //Here is old model Cold=Cnew/2.
251 Double_t dcasq = dca*dca;
253 Double_t cst1 = (1.+c2*dca)*dca;//first constant
254 Double_t cst2 = 1. + 2.*c2*dca;//second constant
256 Double_t factorPhi0 = TMath::ASin((c2*r + cst1/r)/cst2);
257 Double_t factorZ0 = TMath::ASin(c2*TMath::Sqrt((r*r-dcasq)/cst2))*par[3]/c2;
259 for(Int_t i = 0; i<fN; i++)
261 Double_t rc = r0 + i*dr;
262 Double_t ftmp = (c2*rc + cst1/rc)/cst2;
265 AliDebug(1,Form("ASin argument > 1 %f:",ftmp));
268 else if (ftmp < -1.0)
270 AliDebug(1,Form("ASin argument < -1 %f:",ftmp));
274 Double_t factorPhi = TMath::ASin( ftmp );//factor phi od rc
275 Double_t phi = phi0global + factorPhi - factorPhi0;
277 ftmp = (rc*rc-dcasq)/cst2;
280 AliDebug(1,Form("Sqrt argument < 0: %f",ftmp));
284 ftmp = c2*TMath::Sqrt(ftmp);
287 AliDebug(1,Form("ASin argument > 1: %f",ftmp));
290 else if (ftmp < -1.0)
292 AliDebug(2,Form("ASin argument < -1: %f",ftmp));
295 Double_t factorZ = TMath::ASin(ftmp)*par[3]/c2;
296 fZ[i] = z0 + factorZ - factorZ0;
297 fX[i] = rc*TMath::Cos(phi);
298 fY[i] = rc*TMath::Sin(phi);
300 AliDebug(3,Form("AliTrackPoints","X %f Y %f Z %f R asked %f R obtained %f",
301 fX[i],fY[i],fZ[i],rc,TMath::Hypot(fX[i],fY[i])));
305 /***************************************************************/
307 void AliTrackPoints::MakeITSPoints(AliESDtrack* track)
309 //Calculates points in ITS
311 AliITStrackV2 itstrack(*track,kTRUE);
313 static const Double_t kR[6] = {4.0, 7.0, 14.9, 23.8, 39.1, 43.6};
314 for (Int_t i = 0; i < 6; i++)
316 itstrack.GetGlobalXYZat(kR[i],x,y,z);
320 // Info("MakeITSPoints","X %f Y %f Z %f R asked %f R obtained %f",
321 // fX[i],fY[i],fZ[i],r[i],TMath::Hypot(fX[i],fY[i]));
326 /***************************************************************/
328 void AliTrackPoints::MakeITSPointsInnerFromVertexOuterFromTPC(AliESDtrack* track, Float_t mf)
330 //makes trackpoints for ITS
331 //for 3 inner layers calculates out of the vector at vertex
332 //for 3 outer ---------------//------------------ at inner TPC
334 static const Double_t kR[6] = {4.0, 7.0, 14.9, 23.8, 39.1, 43.6};
335 AliITStrackV2 itstrack(*track,kTRUE);
337 for (Int_t i = 0; i < 3; i++)
339 itstrack.GetGlobalXYZat(kR[i],x,y,z);
343 AliDebug(3,Form("X %f Y %f Z %f R asked %f R obtained %f",
344 fX[i],fY[i],fZ[i],kR[i],TMath::Hypot(fX[i],fY[i])));
347 for (Int_t i = 3; i < 6; i++)
350 AliTrackPoints tmptp(1,track,mf,0,kR[i]);
351 tmptp.PositionAt(0,ax,ay,az);
355 AliDebug(3,Form("X %f Y %f Z %f R asked %f R obtained %f",
356 fX[i],fY[i],fZ[i],kR[i],TMath::Hypot(fX[i],fY[i])));
361 /***************************************************************/
363 void AliTrackPoints::PositionAt(Int_t n, Float_t &x,Float_t &y,Float_t &z)
365 //returns position at point n
366 if ((n<0) || (n>=fN))
368 Error("PositionAt","Point %d out of range",n);
375 AliDebug(2,Form("n %d; X %f; Y %f; Z %f",n,x,y,z));
379 /***************************************************************/
381 void AliTrackPoints::Move(Float_t x, Float_t y, Float_t z)
383 //Moves all points about vector
384 for (Int_t i = 0; i<fN; i++)
392 /***************************************************************/
394 Double_t AliTrackPoints::AvarageDistance(const AliTrackPoints& tr)
396 //returns the aritmethic avarage distance between two tracks
397 // Info("AvarageDistance","Entered");
398 if ( (fN <= 0) || (tr.fN <=0) )
400 AliDebug(1,"One of tracks is empty");
406 Warning("AvarageDistance","Number of points is not equal");
411 for (Int_t i = 0; i<fN; i++)
413 AliDebug(10,Form("radii: %f %f",TMath::Hypot(fX[i],fY[i]),TMath::Hypot(tr.fX[i],tr.fY[i])));
414 // Float_t r1sq = fX[i]*fX[i]+fY[i]*fY[i];
415 // Float_t r2sq = tr.fX[i]*tr.fX[i]+tr.fY[i]*tr.fY[i];
418 Double_t dx = fX[i]-tr.fX[i];
419 Double_t dy = fY[i]-tr.fY[i];
420 Double_t dz = fZ[i]-tr.fZ[i];
421 sum+=TMath::Sqrt(dx*dx + dy*dy + dz*dz);
423 AliDebug(2,Form("Diff: x ,y z: %f , %f, %f",dx,dy,dz));
424 AliDebug(2,Form("xxyyzz %f %f %f %f %f %f",
425 fX[i],tr.fX[i],fY[i],tr.fY[i],fZ[i],tr.fZ[i]));
428 Double_t retval = sum/((Double_t)fN);
429 AliDebug(1,Form("Avarage distance is %f.",retval));
434 /***************************************************************/
436 void AliTrackPoints::Print(Option_t* /*option*/) const
438 // Prints the coordinates of the track points
439 Info("Print","There is %d points",fN);
440 for(Int_t i = 0; i < fN; i++)
442 Info("Print","%d: %f %f %f",i,fX[i],fY[i],fZ[i]);
447 /***************************************************************/
449 void AliTrackPoints::Testesd(Int_t entr,const char* fname )
451 // This is a former macro converted to member function.
452 // It is used to test the functionality of the class using ESD tracks
455 AliRunLoader* rl = AliRunLoader::Open();
458 Float_t mf = rl->GetAliRun()->Field()->SolenoidField();
461 TFile* fFile = TFile::Open(fname);
465 printf("testesd: There is no suche a ESD file\n");
468 AliESD* esd = dynamic_cast<AliESD*>(fFile->Get("0"));
469 AliESDtrack *t = esd->GetTrack(entr);
472 ::Error("testesd","Can not get track %d",entr);
477 Int_t nTrackPoints = 170;
478 AliTrackPoints* tp = new AliTrackPoints(nTrackPoints,t,mf,1.);
489 TH2D* hxy = new TH2D("hxy","hxy",1000,xmin,xmax,1000,ymin,ymax);
490 TH2D* hxyt = new TH2D("hxyt","hxyt",1000,xmin,xmax,1000,ymin,ymax);
491 TH2D* hxyTR = new TH2D("hxyTR","hxyTR",1000,xmin,xmax,1000,ymin,ymax);
493 TH2D* hxz = new TH2D("hxz","hxz",1000,xmin,xmax,1000,zmin,zmax);
494 TH2D* hxzt = new TH2D("hxzt","hxzt",1000,xmin,xmax,1000,zmin,zmax);
495 TH2D* hxzTR = new TH2D("hxzTR","hxzTR",1000,xmin,xmax,1000,zmin,zmax);
497 hxyt->SetDirectory(0x0);
498 hxy->SetDirectory(0x0);
499 hxyTR->SetDirectory(0x0);
501 hxzt->SetDirectory(0x0);
502 hxz->SetDirectory(0x0);
503 hxzTR->SetDirectory(0x0);
507 for (Int_t i = 0;i<nTrackPoints;i++)
510 tp->PositionAt(i,x,y,z);
513 printf("Rdemanded %f\n",r);
514 printf("tpx %f tpy %f tpz %f Rt =%f\n", x,y,z,TMath::Hypot(x,y));
519 TTree* treeTR = rl->TreeTR();
520 TBranch* b = treeTR->GetBranch("TPC");
522 TClonesArray* trackrefs = new TClonesArray("AliTrackReference", 100);
523 AliTrackReference* tref;
524 b->SetAddress(&trackrefs);
526 Int_t tlab = TMath::Abs(t->GetLabel());
528 Int_t netr = (Int_t)treeTR->GetEntries();
529 printf("Found %d entries in TR tree\n",netr);
531 for (Int_t e = 0; e < netr; e++)
534 tref = (AliTrackReference*)trackrefs->At(0);
535 if (tref == 0x0) continue;
536 if (tref->GetTrack() != tlab) continue;
538 printf("Found %d entries in TR array\n",trackrefs->GetEntries());
540 for (Int_t i = 0; i < trackrefs->GetEntries(); i++)
542 tref = (AliTrackReference*)trackrefs->At(i);
543 if (tref->GetTrack() != tlab) continue;
547 printf("Track Ref: x %f y %f z %f\n",tref->X(),tref->Y(),tref->Z());
551 for (Int_t j = 1; j < 10; j++)
553 hxyTR->Fill(x, y+j*0.1);
554 hxyTR->Fill(x, y-j*0.1);
555 hxyTR->Fill(x+j*0.1,y);
556 hxyTR->Fill(x-j*0.1,y);
558 hxzTR->Fill(x,z-j*0.1);
559 hxzTR->Fill(x,z+j*0.1);
560 hxzTR->Fill(x-j*0.1,z);
561 hxzTR->Fill(x+j*0.1,z);
567 // hxzt->Draw("same");
573 /***************************************************************/
575 void AliTrackPoints::Testtpc(Int_t entr)
577 // This is a former macro converted to member function.
578 // It is used to test the functionality of the class using TPC tracks
581 AliRunLoader* rl = AliRunLoader::Open();
582 AliLoader* l = rl->GetLoader("TPCLoader");
584 AliTracker::SetFieldMap(rl->GetAliRun()->Field(),kTRUE);
586 AliTPCtrack* t = new AliTPCtrack();
587 TBranch* b=l->TreeT()->GetBranch("tracks");
589 l->TreeT()->GetEntry(entr);
590 Int_t nTrackPoints = 160;
591 AliTrackPoints* tp = new AliTrackPoints(nTrackPoints,t,1.);
602 TH2D* hxy = new TH2D("hxy","hxy",1000,xmin,xmax,1000,ymin,ymax);
603 TH2D* hxyt = new TH2D("hxyt","hxyt",1000,xmin,xmax,1000,ymin,ymax);
604 TH2D* hxyTR = new TH2D("hxyTR","hxyTR",1000,xmin,xmax,1000,ymin,ymax);
606 TH2D* hxz = new TH2D("hxz","hxz",1000,xmin,xmax,1000,zmin,zmax);
607 TH2D* hxzt = new TH2D("hxzt","hxzt",1000,xmin,xmax,1000,zmin,zmax);
608 TH2D* hxzTR = new TH2D("hxzTR","hxzTR",1000,xmin,xmax,1000,zmin,zmax);
610 hxyt->SetDirectory(0x0);
611 hxy->SetDirectory(0x0);
612 hxyTR->SetDirectory(0x0);
614 hxzt->SetDirectory(0x0);
615 hxz->SetDirectory(0x0);
616 hxzTR->SetDirectory(0x0);
620 for (Int_t i = 0;i<nTrackPoints;i++)
623 tp->PositionAt(i,x,y,z);
626 printf("Rdemanded %f\n",r);
627 printf("tpx %f tpy %f tpz %f Rt =%f\n", x,y,z,TMath::Hypot(x,y));
629 //BUT they are local!!!!
631 // Double_t phi = t->Phi();
632 Double_t rl = TMath::Hypot(t->GetX(),t->GetY());//real radius
634 Double_t alpha = t->GetAlpha();
635 Double_t salpha = TMath::Sin(alpha);
636 Double_t calpha = TMath::Cos(alpha);
637 x = t->GetX()*calpha - t->GetY()*salpha;
638 y = t->GetX()*salpha + t->GetY()*calpha;
641 printf("tx %f ty %f tz %f Rt = %f R from XY %f\n",x,y,z,TMath::Hypot(x,y),rl);
643 printf("tpz - tz %f\n",z-t->GetZ());
651 TTree* treeTR = rl->TreeTR();
652 b = treeTR->GetBranch("TPC");
654 TClonesArray* trackrefs = new TClonesArray("AliTrackReference", 100);
655 AliTrackReference* tref;
656 b->SetAddress(&trackrefs);
658 Int_t tlab = TMath::Abs(t->GetLabel());
660 Int_t netr = (Int_t)treeTR->GetEntries();
661 printf("Found %d entries in TR tree\n",netr);
663 for (Int_t e = 0; e < netr; e++)
666 tref = (AliTrackReference*)trackrefs->At(0);
667 if (tref == 0x0) continue;
668 if (tref->GetTrack() != tlab) continue;
670 printf("Found %d entries in TR array\n",trackrefs->GetEntries());
672 for (Int_t i = 0; i < trackrefs->GetEntries(); i++)
674 tref = (AliTrackReference*)trackrefs->At(i);
675 if (tref->GetTrack() != tlab) continue;
679 printf("Track Ref: x %f y %f z %f\n",tref->X(),tref->Y(),tref->Z());
683 for (Int_t j = 1; j < 10; j++)
685 hxyTR->Fill(x, y+j*0.1);
686 hxyTR->Fill(x, y-j*0.1);
687 hxyTR->Fill(x+j*0.1,y);
688 hxyTR->Fill(x-j*0.1,y);
690 hxzTR->Fill(x,z-j*0.1);
691 hxzTR->Fill(x,z+j*0.1);
692 hxzTR->Fill(x-j*0.1,z);
693 hxzTR->Fill(x+j*0.1,z);
699 // hxzt->Draw("same");