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 Revision 1.17.2.2 2000/04/10 08:15:12 kowal2
20 New, experimental data structure from M. Ivanov
21 New tracking algorithm
22 Different pad geometry for different sectors
23 Digitization rewritten
25 Revision 1.17.2.1 2000/04/10 07:56:53 kowal2
26 Not used anymore - removed
28 Revision 1.17 2000/01/19 17:17:30 fca
29 Introducing a list of lists of hits -- more hits allowed for detector now
31 Revision 1.16 1999/11/05 09:29:23 fca
32 Accept only signals > 0
34 Revision 1.15 1999/10/08 06:26:53 fca
35 Removed ClustersIndex - not used anymore
37 Revision 1.14 1999/09/29 09:24:33 fca
38 Introduction of the Copyright and cvs Log
42 ///////////////////////////////////////////////////////////////////////////////
44 // Time Projection Chamber //
45 // This class contains the basic functions for the Time Projection Chamber //
46 // detector. Functions specific to one particular geometry are //
47 // contained in the derived classes //
51 <img src="picts/AliTPCClass.gif">
56 ///////////////////////////////////////////////////////////////////////////////
62 #include <TGeometry.h>
65 #include <TObjectTable.h>
66 #include "TParticle.h"
74 #include "AliTPCParam.h"
75 #include "AliTPCPRF2D.h"
76 #include "AliTPCRF1D.h"
77 #include "AliDigits.h"
78 #include "AliSimDigits.h"
80 #include "AliTPCDigitsArray.h"
81 #include "AliCluster.h"
82 #include "AliClusters.h"
83 #include "AliTPCClustersRow.h"
84 #include "AliTPCClustersArray.h"
90 //_____________________________________________________________________________
94 // Default constructor
110 //_____________________________________________________________________________
111 AliTPC::AliTPC(const char *name, const char *title)
112 : AliDetector(name,title)
115 // Standard constructor
119 // Initialise arrays of hits and digits
120 fHits = new TClonesArray("AliTPChit", 176);
126 // Initialise counters
136 // Initialise color attributes
137 SetMarkerColor(kYellow);
140 //_____________________________________________________________________________
151 if (fDigitsArray!=0) delete fDigitsArray;
152 if (fClustersArray!=0) delete fClustersArray;
154 if (fTPCParam) delete fTPCParam;
157 //_____________________________________________________________________________
158 void AliTPC::AddCluster(Float_t *hits, Int_t *tracks)
161 // Add a simulated cluster to the list
163 if(!fClusters) fClusters=new TClonesArray("AliTPCcluster",10000);
164 TClonesArray &lclusters = *fClusters;
165 new(lclusters[fNclusters++]) AliTPCcluster(hits,tracks);
168 //_____________________________________________________________________________
169 void AliTPC::AddCluster(const AliTPCcluster &c)
172 // Add a simulated cluster copy to the list
174 if(!fClusters) fClusters=new TClonesArray("AliTPCcluster",900000);
175 TClonesArray &lclusters = *fClusters;
176 new(lclusters[fNclusters++]) AliTPCcluster(c);
179 //_____________________________________________________________________________
180 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
183 // Add a hit to the list
185 TClonesArray &lhits = *fHits;
186 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
189 //_____________________________________________________________________________
190 void AliTPC::AddTrack(Float_t *hits)
193 // Add a track to the list of tracks
195 TClonesArray <racks = *fTracks;
196 new(ltracks[fNtracks++]) AliTPCtrack(hits);
199 //_____________________________________________________________________________
200 void AliTPC::AddTrack(const AliTPCtrack& t)
203 // Add a track copy to the list of tracks
205 if(!fTracks) fTracks=new TClonesArray("AliTPCtrack",10000);
206 TClonesArray <racks = *fTracks;
207 new(ltracks[fNtracks++]) AliTPCtrack(t);
210 //_____________________________________________________________________________
211 void AliTPC::BuildGeometry()
215 // Build TPC ROOT TNode geometry for the event display
220 const int kColorTPC=19;
221 char name[5], title[25];
222 const Double_t kDegrad=TMath::Pi()/180;
223 const Double_t kRaddeg=180./TMath::Pi();
226 Float_t InnerOpenAngle = fTPCParam->GetInnerAngle();
227 Float_t OuterOpenAngle = fTPCParam->GetOuterAngle();
229 Float_t InnerAngleShift = fTPCParam->GetInnerAngleShift();
230 Float_t OuterAngleShift = fTPCParam->GetOuterAngleShift();
232 Int_t nLo = fTPCParam->GetNInnerSector()/2;
233 Int_t nHi = fTPCParam->GetNOuterSector()/2;
235 const Double_t loAng = (Double_t)TMath::Nint(InnerOpenAngle*kRaddeg);
236 const Double_t hiAng = (Double_t)TMath::Nint(OuterOpenAngle*kRaddeg);
237 const Double_t loAngSh = (Double_t)TMath::Nint(InnerAngleShift*kRaddeg);
238 const Double_t hiAngSh = (Double_t)TMath::Nint(OuterAngleShift*kRaddeg);
241 const Double_t loCorr = 1/TMath::Cos(0.5*loAng*kDegrad);
242 const Double_t hiCorr = 1/TMath::Cos(0.5*hiAng*kDegrad);
248 // Get ALICE top node
251 Top=gAlice->GetGeometry()->GetNode("alice");
255 rl = fTPCParam->GetInnerRadiusLow();
256 ru = fTPCParam->GetInnerRadiusUp();
260 sprintf(name,"LS%2.2d",i);
262 sprintf(title,"TPC low sector %3d",i);
265 tubs = new TTUBS(name,title,"void",rl*loCorr,ru*loCorr,250.,
266 loAng*(i-0.5)+loAngSh,loAng*(i+0.5)+loAngSh);
267 tubs->SetNumberOfDivisions(1);
269 Node = new TNode(name,title,name,0,0,0,"");
270 Node->SetLineColor(kColorTPC);
276 rl = fTPCParam->GetOuterRadiusLow();
277 ru = fTPCParam->GetOuterRadiusUp();
280 sprintf(name,"US%2.2d",i);
282 sprintf(title,"TPC upper sector %d",i);
284 tubs = new TTUBS(name,title,"void",rl*hiCorr,ru*hiCorr,250,
285 hiAng*(i-0.5)+hiAngSh,hiAng*(i+0.5)+hiAngSh);
286 tubs->SetNumberOfDivisions(1);
288 Node = new TNode(name,title,name,0,0,0,"");
289 Node->SetLineColor(kColorTPC);
298 //_____________________________________________________________________________
299 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
302 // Calculate distance from TPC to mouse on the display
308 //_____________________________________________________________________________
309 static Double_t SigmaY2(Double_t r, Double_t tgl, Double_t pt)
312 // Parametrised error of the cluster reconstruction (pad direction)
314 pt=TMath::Abs(pt)*1000.;
317 Double_t s=a_rphi - b_rphi*r*tgl + c_rphi*x*x + d_rphi*x;
318 if (s<0.4e-3) s=0.4e-3;
319 s*=1.3; //Iouri Belikov
323 //_____________________________________________________________________________
324 static Double_t SigmaZ2(Double_t r, Double_t tgl)
327 // Parametrised error of the cluster reconstruction (drift direction)
330 Double_t s=a_z - b_z*r*tgl + c_z*tgl*tgl;
331 if (s<0.4e-3) s=0.4e-3;
332 s*=1.3; //Iouri Belikov
336 //_____________________________________________________________________________
337 inline Double_t f1(Double_t x1,Double_t y1,
338 Double_t x2,Double_t y2,
339 Double_t x3,Double_t y3)
341 //-----------------------------------------------------------------
342 // Initial approximation of the track curvature
344 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
345 //-----------------------------------------------------------------
346 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
347 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
348 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
349 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
350 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
352 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
354 return -xr*yr/sqrt(xr*xr+yr*yr);
358 //_____________________________________________________________________________
359 inline Double_t f2(Double_t x1,Double_t y1,
360 Double_t x2,Double_t y2,
361 Double_t x3,Double_t y3)
363 //-----------------------------------------------------------------
364 // Initial approximation of the track curvature times center of curvature
366 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
367 //-----------------------------------------------------------------
368 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
369 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
370 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
371 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
372 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
374 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
376 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
379 //_____________________________________________________________________________
380 inline Double_t f3(Double_t x1,Double_t y1,
381 Double_t x2,Double_t y2,
382 Double_t z1,Double_t z2)
384 //-----------------------------------------------------------------
385 // Initial approximation of the tangent of the track dip angle
387 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
388 //-----------------------------------------------------------------
389 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
392 //_____________________________________________________________________________
393 static Int_t FindProlongation(AliTPCtrack& t, const AliTPCSector *sec,
396 //-----------------------------------------------------------------
397 // This function tries to find a track prolongation.
399 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
400 //-----------------------------------------------------------------
401 const Int_t ROWS_TO_SKIP=(t<10) ? 10 : Int_t(0.5*sec->GetNRows());
402 const Float_t MAX_CHI2=12.;
403 Int_t try_again=ROWS_TO_SKIP;
404 Double_t alpha=sec->GetAlpha();
405 Int_t ns=Int_t(2*TMath::Pi()/alpha+0.5);
407 for (Int_t nr=sec->GetRowNumber(t.GetX())-1; nr>=rf; nr--) {
408 Double_t x=sec->GetX(nr), ymax=sec->GetMaxY(nr);
409 if (!t.PropagateTo(x)) return 0;
412 Double_t max_chi2=MAX_CHI2;
413 const AliTPCRow& row=sec[s][nr];
414 Double_t sy2=SigmaY2(t.GetX(),t.GetTgl(),t.GetPt());
415 Double_t sz2=SigmaZ2(t.GetX(),t.GetTgl());
416 Double_t road=5.*sqrt(t.GetSigmaY2() + sy2), y=t.GetY(), z=t.GetZ();
419 if (t>4) cerr<<t<<" FindProlongation warning: Too broad road !\n";
424 for (Int_t i=row.Find(y-road); i<row; i++) {
425 AliTPCcluster* c=(AliTPCcluster*)(row[i]);
426 if (c->fY > y+road) break;
427 if (c->IsUsed()) continue;
428 if ((c->fZ - z)*(c->fZ - z) > 25.*(t.GetSigmaZ2() + sz2)) continue;
429 Double_t chi2=t.GetPredictedChi2(c);
430 if (chi2 > max_chi2) continue;
436 t.Update(cl,max_chi2);
437 cl->fdEdX=sec->GetPadPitchWidth()*TMath::Sqrt((1+t.GetTgl()*t.GetTgl())/
438 (1-(t.GetC()*x-t.GetEta())*(t.GetC()*x-t.GetEta())));
439 try_again=ROWS_TO_SKIP;
441 if (try_again==0) break;
444 if (!t.Rotate(alpha)) return 0;
445 } else if (y <-ymax) {
447 if (!t.Rotate(-alpha)) return 0;
458 //_____________________________________________________________________________
459 static void MakeSeeds(TObjArray& seeds,const AliTPCSector *sec, Int_t max_sec,
462 //-----------------------------------------------------------------
463 // This function creates track seeds.
465 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
466 //-----------------------------------------------------------------
467 TMatrix C(5,5); TVector x(5);
468 Double_t alpha=sec->GetAlpha(), shift=sec->GetAlphaShift();
469 Double_t cs=cos(alpha), sn=sin(alpha);
470 for (Int_t ns=0; ns<max_sec; ns++) {
471 Int_t nl=sec[(ns-1+max_sec)%max_sec][i2];
472 Int_t nm=sec[ns][i2];
473 Int_t nu=sec[(ns+1)%max_sec][i2];
474 const AliTPCRow& r1=sec[ns][i1];
475 for (Int_t is=0; is < r1; is++) {
476 Double_t x1=sec->GetX(i1), y1=r1[is]->fY, z1=r1[is]->fZ;
477 for (Int_t js=0; js < nl+nm+nu; js++) {
478 const AliTPCcluster *cl;
480 Double_t x2=sec->GetX(i2), y2, z2, tmp;
483 ks=(ns-1+max_sec)%max_sec;
484 const AliTPCRow& r2=sec[(ns-1+max_sec)%max_sec][i2];
486 y2=cl->fY; z2=cl->fZ;
488 y2 =-x2*sn+y2*cs; x2=tmp;
492 const AliTPCRow& r2=sec[ns][i2];
494 y2=cl->fY; z2=cl->fZ;
497 const AliTPCRow& r2=sec[(ns+1)%max_sec][i2];
499 y2=cl->fY; z2=cl->fZ;
501 y2 =x2*sn+y2*cs; x2=tmp;
504 Double_t zz=z1 - z1/x1*(x1-x2);
505 if (TMath::Abs(zz-z2)>5) continue;
507 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
508 if (d==0.) {cerr<<"MakeSeeds warning: Straight seed !\n"; continue;}
510 Double_t x3=0., y3=0.;//gRandom->Gaus(0.,TMath::Sqrt(cl->fSigmaY2));
514 x(2)=f1(x1,y1,x2,y2,x3,y3);
515 x(3)=f2(x1,y1,x2,y2,x3,y3);
516 x(4)=f3(x1,y1,x2,y2,z1,z2);
518 if (TMath::Abs(x(2)*x1-x(3)) >= 0.999) continue;
520 if (TMath::Abs(x(4)) > 1.2) continue;
522 Double_t a=asin(x(3));
523 Double_t zv=z1 - x(4)/x(2)*(a+asin(x(2)*x1-x(3)));
524 if (TMath::Abs(zv)>10.) continue;
526 TMatrix X(6,6); X=0.;
527 X(0,0)=r1[is]->fSigmaY2; X(1,1)=r1[is]->fSigmaZ2;
528 X(2,2)=cl->fSigmaY2; X(3,3)=cl->fSigmaZ2;
529 X(4,4)=cl->fSigmaY2; X(5,5)=cl->fSigmaZ2;
530 //X(4,4)=3./12.; X(5,5)=3./12.;
531 TMatrix F(5,6); F.UnitMatrix();
532 Double_t sy=sqrt(X(0,0)), sz=sqrt(X(1,1));
533 F(2,0)=(f1(x1,y1+sy,x2,y2,x3,y3)-x(2))/sy;
534 F(2,2)=(f1(x1,y1,x2,y2+sy,x3,y3)-x(2))/sy;
535 F(2,4)=(f1(x1,y1,x2,y2,x3,y3+sy)-x(2))/sy;
536 F(3,0)=(f2(x1,y1+sy,x2,y2,x3,y3)-x(3))/sy;
537 F(3,2)=(f2(x1,y1,x2,y2+sy,x3,y3)-x(3))/sy;
538 F(3,4)=(f2(x1,y1,x2,y2,x3,y3+sy)-x(3))/sy;
539 F(4,0)=(f3(x1,y1+sy,x2,y2,z1,z2)-x(4))/sy;
540 F(4,1)=(f3(x1,y1,x2,y2,z1+sz,z2)-x(4))/sz;
541 F(4,2)=(f3(x1,y1,x2,y2+sy,z1,z2)-x(4))/sy;
542 F(4,3)=(f3(x1,y1,x2,y2,z1,z2+sz)-x(4))/sz;
546 TMatrix t(F,TMatrix::kMult,X);
547 C.Mult(t,TMatrix(TMatrix::kTransposed,F));
549 AliTPCtrack *track=new AliTPCtrack(r1[is], x, C, x1, ns*alpha+shift);
550 Int_t rc=FindProlongation(*track,sec,ns,i2);
551 if (rc<0 || *track<(i1-i2)/2) delete track;
552 else seeds.AddLast(track);
558 //_____________________________________________________________________________
559 AliTPCParam *AliTPCSector::param;
560 void AliTPC::Clusters2Tracks()
562 //-----------------------------------------------------------------
563 // This is a track finder.
565 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
566 //-----------------------------------------------------------------
567 if (!fClusters) return;
569 AliTPCParam *p=fTPCParam;
570 AliTPCSector::SetParam(p);
572 const Int_t nis=p->GetNInnerSector()/2;
573 AliTPCSSector *ssec=new AliTPCSSector[nis];
574 Int_t nrow_low=ssec->GetNRows();
576 const Int_t nos=p->GetNOuterSector()/2;
577 AliTPCLSector *lsec=new AliTPCLSector[nos];
578 Int_t nrow_up=lsec->GetNRows();
580 Int_t ncl=fClusters->GetEntriesFast();
582 AliTPCcluster *c=(AliTPCcluster*)fClusters->UncheckedAt(ncl);
583 Int_t sec=c->fSector, row=c->fPadRow;
586 ssec[sec%nis][row].InsertCluster(c);
589 lsec[sec%nos][row].InsertCluster(c);
593 TObjArray seeds(20000);
595 Int_t nrows=nrow_low+nrow_up;
596 Int_t gap=Int_t(0.125*nrows), shift=Int_t(0.5*gap);
597 MakeSeeds(seeds, lsec, nos, nrow_up-1, nrow_up-1-gap);
598 MakeSeeds(seeds, lsec, nos, nrow_up-1-shift, nrow_up-1-shift-gap);
603 Int_t nseed=seeds.GetEntriesFast();
605 for (Int_t s=0; s<nseed; s++) {
606 AliTPCtrack *pt=(AliTPCtrack*)seeds.UncheckedAt(s), &t=*pt;
607 Double_t alpha=t.GetAlpha();
608 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
609 if (alpha < 0. ) alpha += 2.*TMath::Pi();
610 Int_t ns=Int_t(alpha/lsec->GetAlpha())%nos;
612 if (!FindProlongation(t,lsec,ns)) continue;
614 alpha=t.GetAlpha() + 0.5*ssec->GetAlpha() - ssec->GetAlphaShift();
615 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
616 if (alpha < 0. ) alpha += 2.*TMath::Pi();
617 ns=Int_t(alpha/ssec->GetAlpha())%nis; //index of the inner sector needed
619 alpha=ns*ssec->GetAlpha() - t.GetAlpha();
620 if (!t.Rotate(alpha)) continue;
622 if (!FindProlongation(t,ssec,ns)) continue;
624 if (t >= Int_t(0.4*nrows)) {
637 //_____________________________________________________________________________
638 void AliTPC::CreateMaterials()
640 //-----------------------------------------------
641 // Create Materials for for TPC
642 //-----------------------------------------------
644 //-----------------------------------------------------------------
645 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
646 //-----------------------------------------------------------------
648 Int_t ISXFLD=gAlice->Field()->Integ();
649 Float_t SXMGMX=gAlice->Field()->Max();
651 Float_t amat[5]; // atomic numbers
652 Float_t zmat[5]; // z
653 Float_t wmat[5]; // proportions
657 // ********************* Gases *******************
659 //--------------------------------------------------------------
661 //--------------------------------------------------------------
666 Float_t a_ne = 20.18;
671 AliMaterial(20,"Ne",a_ne,z_ne,density,999.,999.);
675 Float_t a_ar = 39.948;
680 AliMaterial(21,"Ar",a_ar,z_ar,density,999.,999.);
688 //--------------------------------------------------------------
690 //--------------------------------------------------------------
707 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
709 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
724 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
726 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
741 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
743 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
745 //----------------------------------------------------------------
746 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
747 //----------------------------------------------------------------
755 Float_t a,z,rho,absl,X0,buf[1];
758 for(nc = 0;nc<fNoComp;nc++)
761 // retrive material constants
763 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,X0,absl,buf,nbuf);
768 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
770 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? a_pure[nnc] : amol[nnc]);
771 density += fMixtProp[nc]*rho; // density of the mixture
775 // mixture proportions by weight!
777 for(nc = 0;nc<fNoComp;nc++)
780 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
782 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ? a_pure[nnc] : amol[nnc])/am;
786 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
787 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
788 AliMixture(33,"Drift gas 3",amat,zmat,density,fNoComp,wmat);
790 AliMedium(2, "Drift gas 1", 31, 0, ISXFLD, SXMGMX, 10., 999.,.1, .001, .001);
791 AliMedium(3, "Drift gas 2", 32, 0, ISXFLD, SXMGMX, 10., 999.,.1, .001, .001);
792 AliMedium(4, "Drift gas 3", 33, 1, ISXFLD, SXMGMX, 10., 999.,.1, .001, .001);
796 AliMaterial(24, "Air", 14.61, 7.3, .001205, 30420., 67500.);
798 AliMedium(24, "Air", 24, 0, ISXFLD, SXMGMX, 10., .1, .1, .1, .1);
800 //----------------------------------------------------------------------
802 //----------------------------------------------------------------------
806 AliMaterial(30, "Al", 26.98, 13., 2.7, 8.9, 37.2);
808 AliMedium(0, "Al",30, 0, ISXFLD, SXMGMX, 10., .1, .1, .1, .1);
812 AliMaterial(31, "Si", 28.086, 14.,2.33, 9.36, 999.);
814 AliMedium(7, "Al",31, 0, ISXFLD, SXMGMX, 10., .1, .1, .1, .1);
833 AliMixture(32, "Mylar",amat,zmat,density,-3,wmat);
835 AliMedium(5, "Mylar",32, 0, ISXFLD, SXMGMX, 10., .1, .1, .001, .01);
842 AliMaterial(33,"C normal",12.011,6.,2.265,18.8,999.);
844 AliMedium(6,"C normal",33,0, ISXFLD, SXMGMX, 10., .1, .1, .001, .01);
846 // G10 for inner and outr field cage
847 // G10 is 60% SiO2 + 40% epoxy, right now I use A and Z for SiO2
863 AliMixture(34,"G10 aux.",amat,zmat,density,-2,wmat);
866 gMC->Gfmate((*fIdmate)[34],namate,a,z,rho,X0,absl,buf,nbuf);
868 Float_t thickX0 = 0.0052; // field cage in X0 units
870 Float_t thick = 2.; // in cm
874 rhoFactor = X0*thickX0/thick;
875 density = rho*rhoFactor;
877 AliMaterial(35,"G10-fc",a,z,density,999.,999.);
879 AliMedium(8,"G10-fc",35,0, ISXFLD, SXMGMX, 10., .1, .1, .001, .01);
881 thickX0 = 0.0027; // inner vessel (eta <0.9)
883 rhoFactor = X0*thickX0/thick;
884 density = rho*rhoFactor;
886 AliMaterial(36,"G10-iv",a,z,density,999.,999.);
888 AliMedium(9,"G10-iv",36,0, ISXFLD, SXMGMX, 10., .1, .1, .001, .01);
892 gMC->Gfmate((*fIdmate)[33],namate,a,z,rho,X0,absl,buf,nbuf);
894 thickX0 = 0.0133; // outer vessel
896 rhoFactor = X0*thickX0/thick;
897 density = rho*rhoFactor;
900 AliMaterial(37,"C-ov",a,z,density,999.,999.);
902 AliMedium(10,"C-ov",37,0, ISXFLD, SXMGMX, 10., .1, .1, .001, .01);
904 thickX0=0.015; // inner vessel (cone, eta > 0.9)
906 rhoFactor = X0*thickX0/thick;
907 density = rho*rhoFactor;
909 AliMaterial(38,"C-ivc",a,z,density,999.,999.);
911 AliMedium(11,"C-ivc",38,0, ISXFLD, SXMGMX, 10., .1, .1, .001, .01);
915 AliMedium(12,"CO2",10,0, ISXFLD, SXMGMX, 10., 999.,.1, .001, .001);
919 //_____________________________________________________________________________
925 Bin::Bin() {q=0; mask=0xFFFFFFFE;}
931 inline Bool_t IsMaximum(Int_t k, Int_t max, const Bin *bins) {
932 UShort_t q=bins[k].q;
933 if (q==1023) return kFALSE;
934 if (bins[k-max].q > q) return kFALSE;
935 if (bins[k-1 ].q > q) return kFALSE;
936 if (bins[k+max].q > q) return kFALSE;
937 if (bins[k+1 ].q > q) return kFALSE;
938 if (bins[k-max-1].q > q) return kFALSE;
939 if (bins[k+max-1].q > q) return kFALSE;
940 if (bins[k+max+1].q > q) return kFALSE;
941 if (bins[k-max+1].q > q) return kFALSE;
944 static void FindPeaks(Int_t k, Int_t max, Bin *bins, Peak *peaks, Int_t& n) {
947 if (IsMaximum(k,max,bins)) {
948 peaks[n].k=k; peaks[n].mask=(2<<n);
952 if (bins[k-max].mask&1) FindPeaks(k-max,max,bins,peaks,n);
953 if (bins[k-1 ].mask&1) FindPeaks(k-1 ,max,bins,peaks,n);
954 if (bins[k+max].mask&1) FindPeaks(k+max,max,bins,peaks,n);
955 if (bins[k+1 ].mask&1) FindPeaks(k+1 ,max,bins,peaks,n);
958 static void MarkPeak(Int_t k, Int_t max, Bin *bins, UInt_t m) {
959 UShort_t q=bins[k].q;
963 if (bins[k-max].q <= q)
964 if ((bins[k-max].mask&m) == 0) MarkPeak(k-max,max,bins,m);
965 if (bins[k-1 ].q <= q)
966 if ((bins[k-1 ].mask&m) == 0) MarkPeak(k-1 ,max,bins,m);
967 if (bins[k+max].q <= q)
968 if ((bins[k+max].mask&m) == 0) MarkPeak(k+max,max,bins,m);
969 if (bins[k+1 ].q <= q)
970 if ((bins[k+1 ].mask&m) == 0) MarkPeak(k+1 ,max,bins,m);
973 static void MakeCluster(Int_t k,Int_t max,Bin *bins,UInt_t m,AliTPCcluster &c){
974 Float_t q=(Float_t)bins[k].q;
975 Int_t i=k/max, j=k-i*max;
982 bins[k].mask = 0xFFFFFFFE;
984 if (bins[k-max].mask == m) MakeCluster(k-max,max,bins,m,c);
985 if (bins[k-1 ].mask == m) MakeCluster(k-1 ,max,bins,m,c);
986 if (bins[k+max].mask == m) MakeCluster(k+max,max,bins,m,c);
987 if (bins[k+1 ].mask == m) MakeCluster(k+1 ,max,bins,m,c);
990 //_____________________________________________________________________________
991 void AliTPC::Digits2Clusters()
993 //-----------------------------------------------------------------
994 // This is a simple cluster finder.
996 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
997 //-----------------------------------------------------------------
998 AliTPCParam *par = fTPCParam;
999 const Int_t MAXZ=par->GetMaxTBin()+2;
1001 TTree *t = (TTree *)gDirectory->Get("TreeD_75x40_100x60");
1002 AliSimDigits digarr, *dummy=&digarr;
1003 t->GetBranch("Segment")->SetAddress(&dummy);
1004 Stat_t sectors_by_rows = t->GetEntries();
1005 for (Int_t n=0; n<sectors_by_rows; n++) {
1008 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1009 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
1013 Float_t rx=par->GetPadRowRadii(sec,row);
1017 Int_t nis=par->GetNInnerSector(), nos=par->GetNOuterSector();
1019 npads = par->GetNPadsLow(row);
1020 sign = (sec < nis/2) ? 1 : -1;
1022 npads = par->GetNPadsUp(row);
1023 sign = ((sec-nis) < nos/2) ? 1 : -1;
1027 const Int_t MAXBIN=MAXZ*(npads+2);
1028 Bin *bins=new Bin[MAXBIN];
1032 Short_t dig=digarr.CurrentDigit();
1033 if (dig<=par->GetZeroSup()) continue;
1034 Int_t j=digarr.CurrentRow()+1, i=digarr.CurrentColumn()+1;
1035 bins[i*MAXZ+j].q=dig;
1036 bins[i*MAXZ+j].mask=1;
1037 } while (digarr.Next());
1040 for (Int_t i=0; i<MAXBIN; i++) {
1041 if ((bins[i].mask&1) == 0) continue;
1042 Peak peaks[32]; Int_t npeaks=0;
1043 FindPeaks(i, MAXZ, bins, peaks, npeaks);
1045 if (npeaks>30) continue;
1048 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
1049 if (peaks[k].k < 0) continue; //this peak is already removed
1050 for (l=k+1; l<npeaks; l++) {
1051 if (peaks[l].k < 0) continue; //this peak is already removed
1052 Int_t ki=peaks[k].k/MAXZ, kj=peaks[k].k - ki*MAXZ;
1053 Int_t li=peaks[l].k/MAXZ, lj=peaks[l].k - li*MAXZ;
1054 Int_t di=TMath::Abs(ki - li);
1055 Int_t dj=TMath::Abs(kj - lj);
1056 if (di>1 || dj>1) continue;
1057 if (bins[peaks[k].k].q > bins[peaks[l].k].q) {
1058 peaks[l].mask=peaks[k].mask;
1061 peaks[k].mask=peaks[l].mask;
1068 for (k=0; k<npeaks; k++) {
1069 MarkPeak(TMath::Abs(peaks[k].k), MAXZ, bins, peaks[k].mask);
1072 for (k=0; k<npeaks; k++) {
1073 if (peaks[k].k < 0) continue; //removed peak
1075 MakeCluster(peaks[k].k, MAXZ, bins, peaks[k].mask, c);
1076 if (c.fQ < 5) continue; //noise cluster
1080 Double_t s2 = c.fSigmaY2/c.fQ - c.fY*c.fY;
1081 c.fSigmaY2 = s2 + 1./12.;
1082 c.fSigmaY2 *= par->GetPadPitchWidth(sec)*par->GetPadPitchWidth(sec);
1084 c.fSigmaY2 *= 0.064*1.3*1.3;
1085 if (sec<par->GetNInnerSector()) c.fSigmaY2 *= 1.44*1.44;
1088 s2 = c.fSigmaZ2/c.fQ - c.fZ*c.fZ;
1089 c.fSigmaZ2 = s2 + 1./12.;
1090 c.fSigmaZ2 *= par->GetZWidth()*par->GetZWidth();
1092 c.fSigmaZ2 *= 0.10*1.3*1.3;
1093 if (sec<par->GetNInnerSector()) c.fSigmaZ2 *= 1.33*1.33;
1096 c.fY = (c.fY - 0.5 - 0.5*npads)*par->GetPadPitchWidth(sec);
1097 c.fZ = par->GetZWidth()*(c.fZ-1);
1098 c.fZ -= 3.*par->GetZSigma(); // PASA delay
1099 c.fZ = sign*(z_end - c.fZ);
1101 if (rx<230./250.*TMath::Abs(c.fZ)) continue;
1105 Int_t ki=peaks[k].k/MAXZ, kj=peaks[k].k - ki*MAXZ;
1106 c.fTracks[0]=digarr.GetTrackID(kj-1,ki-1,0);
1107 c.fTracks[1]=digarr.GetTrackID(kj-1,ki-1,1);
1108 c.fTracks[2]=digarr.GetTrackID(kj-1,ki-1,2);
1110 c.fQ=bins[peaks[k].k].q;
1112 if (ki==1 || ki==npads || kj==1 || kj==MAXZ-2) {
1117 AddCluster(c); ncl++;
1121 cerr<<"sector, row, compressed digits, clusters: "
1122 <<sec<<' '<<row<<' '<<digarr.GetSize()<<' '<<ncl<<" \r";
1128 //_____________________________________________________________________________
1129 void AliTPC::Hits2Clusters()
1131 //--------------------------------------------------------
1132 // TPC simple cluster generator from hits
1133 // obtained from the TPC Fast Simulator
1134 // The point errors are taken from the parametrization
1135 //--------------------------------------------------------
1137 //-----------------------------------------------------------------
1138 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1139 //-----------------------------------------------------------------
1142 printf("AliTPCParam MUST be created firstly\n");
1146 Float_t sigma_rphi,sigma_z,cl_rphi,cl_z;
1148 TParticle *particle; // pointer to a given particle
1149 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1150 TClonesArray *Particles; //pointer to the particle list
1154 Float_t pl,pt,tanth,rpad,ratio;
1157 //---------------------------------------------------------------
1158 // Get the access to the tracks
1159 //---------------------------------------------------------------
1161 TTree *TH = gAlice->TreeH();
1162 Stat_t ntracks = TH->GetEntries();
1164 //------------------------------------------------------------
1165 // Loop over all sectors (72 sectors for 20 deg
1166 // segmentation for both lower and upper sectors)
1167 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
1168 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
1170 // First cluster for sector 0 starts at "0"
1171 //------------------------------------------------------------
1173 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
1175 fTPCParam->AdjustCosSin(isec,cph,sph);
1177 //------------------------------------------------------------
1179 //------------------------------------------------------------
1181 for(Int_t track=0;track<ntracks;track++){
1183 TH->GetEvent(track);
1185 // Get number of the TPC hits and a pointer
1188 nhits=fHits->GetEntriesFast();
1189 Particles=gAlice->Particles();
1193 for(Int_t hit=0;hit<nhits;hit++){
1194 tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
1195 if (tpcHit->fQ == 0.) continue; //information about track (I.Belikov)
1196 sector=tpcHit->fSector; // sector number
1197 if(sector != isec) continue; //terminate iteration
1198 ipart=tpcHit->fTrack;
1199 particle=(TParticle*)Particles->UncheckedAt(ipart);
1202 if(pt < 1.e-9) pt=1.e-9;
1204 tanth = TMath::Abs(tanth);
1205 rpad=TMath::Sqrt(tpcHit->fX*tpcHit->fX + tpcHit->fY*tpcHit->fY);
1206 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
1208 // space-point resolutions
1210 sigma_rphi=SigmaY2(rpad,tanth,pt);
1211 sigma_z =SigmaZ2(rpad,tanth );
1215 cl_rphi=ac_rphi-bc_rphi*rpad*tanth+cc_rphi*ratio*ratio;
1216 cl_z=ac_z-bc_z*rpad*tanth+cc_z*tanth*tanth;
1218 // temporary protection
1220 if(sigma_rphi < 0.) sigma_rphi=0.4e-3;
1221 if(sigma_z < 0.) sigma_z=0.4e-3;
1222 if(cl_rphi < 0.) cl_rphi=2.5e-3;
1223 if(cl_z < 0.) cl_z=2.5e-5;
1228 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
1229 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
1231 //Float_t xprim= tpcHit->fX*cph + tpcHit->fY*sph;
1232 Float_t yprim=-tpcHit->fX*sph + tpcHit->fY*cph;
1233 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigma_rphi)); // y
1234 xyz[1]=gRandom->Gaus(tpcHit->fZ,TMath::Sqrt(sigma_z)); // z
1235 xyz[2]=tpcHit->fQ; // q
1236 xyz[3]=sigma_rphi; // fSigmaY2
1237 xyz[4]=sigma_z; // fSigmaZ2
1239 Int_t tracks[5]={tpcHit->fTrack, -1, -1, sector, tpcHit->fPadRow};
1240 AddCluster(xyz,tracks);
1242 } // end of loop over hits
1243 } // end of loop over tracks
1245 } // end of loop over sectors
1247 } // end of function
1249 //_________________________________________________________________
1250 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1252 //--------------------------------------------------------
1253 //calculate exact cross point of track and given pad row
1254 //resulting values are expressed in "digit" coordinata
1255 //--------------------------------------------------------
1257 //-----------------------------------------------------------------
1258 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1259 //-----------------------------------------------------------------
1261 if (fClustersArray==0){
1265 TParticle *particle; // pointer to a given particle
1266 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1267 TClonesArray *Particles; //pointer to the particle list
1270 const Int_t cmaxhits=30000;
1271 TVector * xxxx = new TVector(cmaxhits*4);
1272 TVector & xxx = *xxxx;
1273 Int_t maxhits = cmaxhits;
1274 //construct array for each padrow
1275 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
1276 fClustersArray->CreateRow(isec,i);
1278 //---------------------------------------------------------------
1279 // Get the access to the tracks
1280 //---------------------------------------------------------------
1282 TTree *TH = gAlice->TreeH();
1283 Stat_t ntracks = TH->GetEntries();
1284 Particles=gAlice->Particles();
1285 Int_t npart = Particles->GetEntriesFast();
1287 //------------------------------------------------------------
1289 //------------------------------------------------------------
1291 for(Int_t track=0;track<ntracks;track++){
1293 TH->GetEvent(track);
1295 // Get number of the TPC hits and a pointer
1298 nhits=fHits->GetEntriesFast();
1302 Int_t currentIndex=0;
1303 Int_t lastrow=-1; //last writen row
1304 for(Int_t hit=0;hit<nhits;hit++){
1305 tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
1306 if (tpcHit==0) continue;
1307 sector=tpcHit->fSector; // sector number
1308 if(sector != isec) continue;
1309 ipart=tpcHit->fTrack;
1310 if (ipart<npart) particle=(TParticle*)Particles->UncheckedAt(ipart);
1314 Float_t x[3]={tpcHit->fX,tpcHit->fY,tpcHit->fZ};
1315 Int_t index[3]={1,isec,0};
1316 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
1317 if (currentrow<0) continue;
1318 if (lastrow<0) lastrow=currentrow;
1319 if (currentrow==lastrow){
1320 if ( currentIndex>=maxhits){
1322 xxx.ResizeTo(4*maxhits);
1324 xxx(currentIndex*4)=x[0];
1325 xxx(currentIndex*4+1)=x[1];
1326 xxx(currentIndex*4+2)=x[2];
1327 xxx(currentIndex*4+3)=tpcHit->fQ;
1331 if (currentIndex>2){
1343 for (Int_t index=0;index<currentIndex;index++){
1345 x=x2=x3=x4=xxx(index*4);
1353 sumy+=xxx(index*4+1);
1354 sumxy+=xxx(index*4+1)*x;
1355 sumx2y+=xxx(index*4+1)*x2;
1356 sumz+=xxx(index*4+2);
1357 sumxz+=xxx(index*4+2)*x;
1358 sumx2z+=xxx(index*4+2)*x2;
1359 sumq+=xxx(index*4+3);
1361 Float_t CentralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1362 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1363 sumx2*(sumx*sumx3-sumx2*sumx2);
1365 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1366 sumx2*(sumxy*sumx3-sumx2y*sumx2);
1367 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1368 sumx2*(sumxz*sumx3-sumx2z*sumx2);
1370 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1371 sumx2*(sumx*sumx2y-sumx2*sumxy);
1372 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1373 sumx2*(sumx*sumx2z-sumx2*sumxz);
1375 Float_t y=detay/det+CentralPad;
1376 Float_t z=detaz/det;
1377 Float_t by=detby/det; //y angle
1378 Float_t bz=detbz/det; //z angle
1379 sumy/=Float_t(currentIndex);
1380 sumz/=Float_t(currentIndex);
1387 cl.fTracks[0]=ipart;
1389 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1390 if (row!=0) row->InsertCluster(&cl);
1393 } //end of calculating cluster for given row
1397 } // end of loop over hits
1398 } // end of loop over tracks
1399 //write padrows to tree
1400 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1401 fClustersArray->StoreRow(isec,ii);
1402 fClustersArray->ClearRow(isec,ii);
1408 //__________________________________________________________________
1409 void AliTPC::Hits2Digits()
1411 //----------------------------------------------------
1412 // Loop over all sectors
1413 //----------------------------------------------------
1416 printf("AliTPCParam MUST be created firstly\n");
1420 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
1425 //_____________________________________________________________________________
1426 void AliTPC::Hits2DigitsSector(Int_t isec)
1428 //-------------------------------------------------------------------
1429 // TPC conversion from hits to digits.
1430 //-------------------------------------------------------------------
1432 //-----------------------------------------------------------------
1433 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1434 //-----------------------------------------------------------------
1436 //-------------------------------------------------------
1437 // Get the access to the track hits
1438 //-------------------------------------------------------
1441 TTree *TH = gAlice->TreeH(); // pointer to the hits tree
1442 Stat_t ntracks = TH->GetEntries();
1446 //-------------------------------------------
1447 // Only if there are any tracks...
1448 //-------------------------------------------
1452 printf("*** Processing sector number %d ***\n",isec);
1454 Int_t nrows =fTPCParam->GetNRow(isec);
1456 row= new TObjArray* [nrows];
1458 MakeSector(isec,nrows,TH,ntracks,row);
1460 //--------------------------------------------------------
1461 // Digitize this sector, row by row
1462 // row[i] is the pointer to the TObjArray of TVectors,
1463 // each one containing electrons accepted on this
1464 // row, assigned into tracks
1465 //--------------------------------------------------------
1469 if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree();
1471 for (i=0;i<nrows;i++){
1473 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1475 DigitizeRow(i,isec,row);
1477 fDigitsArray->StoreRow(isec,i);
1479 Int_t ndig = dig->GetSize();
1481 printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1483 fDigitsArray->ClearRow(isec,i);
1486 } // end of the sector digitization
1488 for(i=0;i<nrows;i++){
1492 delete [] row; // delete the array of pointers to TObjArray-s
1496 } // end of Hits2DigitsSector
1499 //_____________________________________________________________________________
1500 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1502 //-----------------------------------------------------------
1503 // Single row digitization, coupling from the neighbouring
1504 // rows taken into account
1505 //-----------------------------------------------------------
1507 //-----------------------------------------------------------------
1508 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1509 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1510 //-----------------------------------------------------------------
1513 Float_t zerosup = fTPCParam->GetZeroSup();
1514 Int_t nrows =fTPCParam->GetNRow(isec);
1515 fCurrentIndex[1]= isec;
1518 Int_t n_of_pads = fTPCParam->GetNPads(isec,irow);
1519 Int_t n_of_tbins = fTPCParam->GetMaxTBin();
1520 Int_t IndexRange[4];
1522 // Integrated signal for this row
1523 // and a single track signal
1525 TMatrix *m1 = new TMatrix(0,n_of_pads,0,n_of_tbins); // integrated
1526 TMatrix *m2 = new TMatrix(0,n_of_pads,0,n_of_tbins); // single
1528 TMatrix &Total = *m1;
1530 // Array of pointers to the label-signal list
1532 Int_t NofDigits = n_of_pads*n_of_tbins; // number of digits for this row
1533 Float_t **pList = new Float_t* [NofDigits];
1537 for(lp=0;lp<NofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1541 Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1542 Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1543 for (Int_t row= row1;row<=row2;row++){
1544 Int_t nTracks= rows[row]->GetEntries();
1545 for (i1=0;i1<nTracks;i1++){
1546 fCurrentIndex[2]= row;
1547 fCurrentIndex[3]=irow;
1549 m2->Zero(); // clear single track signal matrix
1550 Float_t TrackLabel = GetSignal(rows[row],i1,m2,m1,IndexRange);
1551 GetList(TrackLabel,n_of_pads,m2,IndexRange,pList);
1553 else GetSignal(rows[row],i1,0,m1,IndexRange);
1559 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1560 for(Int_t ip=0;ip<n_of_pads;ip++){
1561 for(Int_t it=0;it<n_of_tbins;it++){
1563 Float_t q = Total(ip,it);
1565 Int_t gi =it*n_of_pads+ip; // global index
1567 q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
1571 if(q <=zerosup) continue; // do not fill zeros
1572 if(q > adc_sat) q = adc_sat; // saturation
1575 // "real" signal or electronic noise (list = -1)?
1578 for(Int_t j1=0;j1<3;j1++){
1579 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -1;
1584 <A NAME="AliDigits"></A>
1585 using of AliDigits object
1588 dig->SetDigitFast((Short_t)q,it,ip);
1589 if (fDigitsArray->IsSimulated())
1591 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1592 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1593 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1597 } // end of loop over time buckets
1598 } // end of lop over pads
1601 // This row has been digitized, delete nonused stuff
1604 for(lp=0;lp<NofDigits;lp++){
1605 if(pList[lp]) delete [] pList[lp];
1614 } // end of DigitizeRow
1616 //_____________________________________________________________________________
1618 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr, TMatrix *m1, TMatrix *m2,
1622 //---------------------------------------------------------------
1623 // Calculates 2-D signal (pad,time) for a single track,
1624 // returns a pointer to the signal matrix and the track label
1625 // No digitization is performed at this level!!!
1626 //---------------------------------------------------------------
1628 //-----------------------------------------------------------------
1629 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1630 // Modified: Marian Ivanov
1631 //-----------------------------------------------------------------
1635 tv = (TVector*)p1->At(ntr); // pointer to a track
1638 Float_t label = v(0);
1639 Int_t CentralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
1641 Int_t nElectrons = (tv->GetNrows()-1)/4;
1642 IndexRange[0]=9999; // min pad
1643 IndexRange[1]=-1; // max pad
1644 IndexRange[2]=9999; //min time
1645 IndexRange[3]=-1; // max time
1647 // Float_t IneffFactor = 0.5; // inefficiency in the gain close to the edge, as above
1649 TMatrix &signal = *m1;
1650 TMatrix &total = *m2;
1652 // Loop over all electrons
1654 for(Int_t nel=0; nel<nElectrons; nel++){
1656 Float_t aval = v(idx+4);
1657 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1658 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1659 Int_t n = fTPCParam->CalcResponse(xyz,fCurrentIndex,fCurrentIndex[3]);
1661 if (n>0) for (Int_t i =0; i<n; i++){
1662 Int_t *index = fTPCParam->GetResBin(i);
1663 Int_t pad=index[1]+CentralPad; //in digit coordinates central pad has coordinate 0
1664 if ( ( pad<(fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]))) && (pad>0)) {
1665 Int_t time=index[2];
1666 Float_t weight = fTPCParam->GetResWeight(i); //we normalise response to ADC channel
1667 weight *= eltoadcfac;
1669 if (m1!=0) signal(pad,time)+=weight;
1670 total(pad,time)+=weight;
1671 IndexRange[0]=TMath::Min(IndexRange[0],pad);
1672 IndexRange[1]=TMath::Max(IndexRange[1],pad);
1673 IndexRange[2]=TMath::Min(IndexRange[2],time);
1674 IndexRange[3]=TMath::Max(IndexRange[3],time);
1677 } // end of loop over electrons
1679 return label; // returns track label when finished
1682 //_____________________________________________________________________________
1683 void AliTPC::GetList(Float_t label,Int_t np,TMatrix *m,Int_t *IndexRange,
1686 //----------------------------------------------------------------------
1687 // Updates the list of tracks contributing to digits for a given row
1688 //----------------------------------------------------------------------
1690 //-----------------------------------------------------------------
1691 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1692 //-----------------------------------------------------------------
1694 TMatrix &signal = *m;
1696 // lop over nonzero digits
1698 for(Int_t it=IndexRange[2];it<IndexRange[3]+1;it++){
1699 for(Int_t ip=IndexRange[0];ip<IndexRange[1]+1;ip++){
1702 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1704 if(signal(ip,it)<0.5) continue;
1707 Int_t GlobalIndex = it*np+ip; // GlobalIndex starts from 0!
1709 if(!pList[GlobalIndex]){
1712 // Create new list (6 elements - 3 signals and 3 labels),
1715 pList[GlobalIndex] = new Float_t [6];
1719 *pList[GlobalIndex] = -1.;
1720 *(pList[GlobalIndex]+1) = -1.;
1721 *(pList[GlobalIndex]+2) = -1.;
1722 *(pList[GlobalIndex]+3) = -1.;
1723 *(pList[GlobalIndex]+4) = -1.;
1724 *(pList[GlobalIndex]+5) = -1.;
1727 *pList[GlobalIndex] = label;
1728 *(pList[GlobalIndex]+3) = signal(ip,it);
1732 // check the signal magnitude
1734 Float_t highest = *(pList[GlobalIndex]+3);
1735 Float_t middle = *(pList[GlobalIndex]+4);
1736 Float_t lowest = *(pList[GlobalIndex]+5);
1739 // compare the new signal with already existing list
1742 if(signal(ip,it)<lowest) continue; // neglect this track
1746 if (signal(ip,it)>highest){
1747 *(pList[GlobalIndex]+5) = middle;
1748 *(pList[GlobalIndex]+4) = highest;
1749 *(pList[GlobalIndex]+3) = signal(ip,it);
1751 *(pList[GlobalIndex]+2) = *(pList[GlobalIndex]+1);
1752 *(pList[GlobalIndex]+1) = *pList[GlobalIndex];
1753 *pList[GlobalIndex] = label;
1755 else if (signal(ip,it)>middle){
1756 *(pList[GlobalIndex]+5) = middle;
1757 *(pList[GlobalIndex]+4) = signal(ip,it);
1759 *(pList[GlobalIndex]+2) = *(pList[GlobalIndex]+1);
1760 *(pList[GlobalIndex]+1) = label;
1763 *(pList[GlobalIndex]+5) = signal(ip,it);
1764 *(pList[GlobalIndex]+2) = label;
1768 } // end of loop over pads
1769 } // end of loop over time bins
1774 //___________________________________________________________________
1775 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1776 Stat_t ntracks,TObjArray **row)
1779 //-----------------------------------------------------------------
1780 // Prepares the sector digitization, creates the vectors of
1781 // tracks for each row of this sector. The track vector
1782 // contains the track label and the position of electrons.
1783 //-----------------------------------------------------------------
1785 //-----------------------------------------------------------------
1786 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1787 //-----------------------------------------------------------------
1789 Float_t gasgain = fTPCParam->GetGasGain();
1793 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1795 //----------------------------------------------
1796 // Create TObjArray-s, one for each row,
1797 // each TObjArray will store the TVectors
1798 // of electrons, one TVector per each track.
1799 //----------------------------------------------
1801 for(i=0; i<nrows; i++){
1802 row[i] = new TObjArray;
1804 Int_t *n_of_electrons = new Int_t [nrows]; // electron counter for each row
1805 TVector **tracks = new TVector* [nrows]; //pointers to the track vectors
1807 //--------------------------------------------------------------------
1808 // Loop over tracks, the "track" contains the full history
1809 //--------------------------------------------------------------------
1811 Int_t previousTrack,currentTrack;
1812 previousTrack = -1; // nothing to store so far!
1814 for(Int_t track=0;track<ntracks;track++){
1818 TH->GetEvent(track); // get next track
1819 Int_t nhits = fHits->GetEntriesFast(); // get number of hits for this track
1821 if(nhits == 0) continue; // no hits in the TPC for this track
1823 //--------------------------------------------------------------
1825 //--------------------------------------------------------------
1827 for(Int_t hit=0;hit<nhits;hit++){
1829 tpcHit = (AliTPChit*)fHits->UncheckedAt(hit); // get a pointer to a hit
1831 Int_t sector=tpcHit->fSector; // sector number
1832 if(sector != isec) continue;
1834 currentTrack = tpcHit->fTrack; // track number
1835 if(currentTrack != previousTrack){
1837 // store already filled fTrack
1839 for(i=0;i<nrows;i++){
1840 if(previousTrack != -1){
1841 if(n_of_electrons[i]>0){
1842 TVector &v = *tracks[i];
1843 v(0) = previousTrack;
1844 tracks[i]->ResizeTo(4*n_of_electrons[i]+1); // shrink if necessary
1845 row[i]->Add(tracks[i]);
1848 delete tracks[i]; // delete empty TVector
1853 n_of_electrons[i]=0;
1854 tracks[i] = new TVector(481); // TVectors for the next fTrack
1856 } // end of loop over rows
1858 previousTrack=currentTrack; // update track label
1861 Int_t QI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1863 //---------------------------------------------------
1864 // Calculate the electron attachment probability
1865 //---------------------------------------------------
1868 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->fZ))
1869 /fTPCParam->GetDriftV();
1871 Float_t AttProb = fTPCParam->GetAttCoef()*
1872 fTPCParam->GetOxyCont()*time; // fraction!
1874 //-----------------------------------------------
1875 // Loop over electrons
1876 //-----------------------------------------------
1879 for(Int_t nel=0;nel<QI;nel++){
1880 // skip if electron lost due to the attachment
1881 if((gRandom->Rndm(0)) < AttProb) continue; // electron lost!
1885 xyz[3]= (Float_t) (-gasgain*TMath::Log(gRandom->Rndm()));
1888 TransportElectron(xyz,index); //MI change -august
1890 fTPCParam->GetPadRow(xyz,index); //MI change august
1891 row_number = index[2];
1892 //transform position to local digit coordinates
1893 //relative to nearest pad row
1894 if ((row_number<0)||row_number>=fTPCParam->GetNRow(isec)) continue;
1895 n_of_electrons[row_number]++;
1896 //----------------------------------
1897 // Expand vector if necessary
1898 //----------------------------------
1899 if(n_of_electrons[row_number]>120){
1900 Int_t range = tracks[row_number]->GetNrows();
1901 if((n_of_electrons[row_number])>(range-1)/4){
1903 tracks[row_number]->ResizeTo(range+400); // Add 100 electrons
1907 TVector &v = *tracks[row_number];
1908 Int_t idx = 4*n_of_electrons[row_number]-3;
1910 v(idx)= xyz[0]; // X - pad row coordinate
1911 v(idx+1)=xyz[1]; // Y - pad coordinate (along the pad-row)
1912 v(idx+2)=xyz[2]; // Z - time bin coordinate
1913 v(idx+3)=xyz[3]; // avalanche size
1914 } // end of loop over electrons
1916 } // end of loop over hits
1917 } // end of loop over tracks
1920 // store remaining track (the last one) if not empty
1923 for(i=0;i<nrows;i++){
1924 if(n_of_electrons[i]>0){
1925 TVector &v = *tracks[i];
1926 v(0) = previousTrack;
1927 tracks[i]->ResizeTo(4*n_of_electrons[i]+1); // shrink if necessary
1928 row[i]->Add(tracks[i]);
1937 delete [] n_of_electrons;
1940 } // end of MakeSector
1943 //_____________________________________________________________________________
1947 // Initialise TPC detector after definition of geometry
1952 for(i=0;i<35;i++) printf("*");
1953 printf(" TPC_INIT ");
1954 for(i=0;i<35;i++) printf("*");
1957 for(i=0;i<80;i++) printf("*");
1961 //_____________________________________________________________________________
1962 void AliTPC::MakeBranch(Option_t* option)
1965 // Create Tree branches for the TPC.
1967 Int_t buffersize = 4000;
1968 char branchname[10];
1969 sprintf(branchname,"%s",GetName());
1971 AliDetector::MakeBranch(option);
1973 char *D = strstr(option,"D");
1975 if (fDigits && gAlice->TreeD() && D) {
1976 gAlice->TreeD()->Branch(branchname,&fDigits, buffersize);
1977 printf("Making Branch %s for digits\n",branchname);
1980 char *R = strstr(option,"R");
1982 if (fClusters && gAlice->TreeR() && R) {
1983 gAlice->TreeR()->Branch(branchname,&fClusters, buffersize);
1984 printf("Making Branch %s for Clusters\n",branchname);
1988 //_____________________________________________________________________________
1989 void AliTPC::ResetDigits()
1992 // Reset number of digits and the digits array for this detector
1996 if (fDigits) fDigits->Clear();
1998 if (fClusters) fClusters->Clear();
2001 //_____________________________________________________________________________
2002 void AliTPC::SetSecAL(Int_t sec)
2004 //---------------------------------------------------
2005 // Activate/deactivate selection for lower sectors
2006 //---------------------------------------------------
2008 //-----------------------------------------------------------------
2009 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2010 //-----------------------------------------------------------------
2015 //_____________________________________________________________________________
2016 void AliTPC::SetSecAU(Int_t sec)
2018 //----------------------------------------------------
2019 // Activate/deactivate selection for upper sectors
2020 //---------------------------------------------------
2022 //-----------------------------------------------------------------
2023 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2024 //-----------------------------------------------------------------
2029 //_____________________________________________________________________________
2030 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
2032 //----------------------------------------
2033 // Select active lower sectors
2034 //----------------------------------------
2036 //-----------------------------------------------------------------
2037 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2038 //-----------------------------------------------------------------
2048 //_____________________________________________________________________________
2049 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
2050 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
2051 Int_t s11 , Int_t s12)
2053 //--------------------------------
2054 // Select active upper sectors
2055 //--------------------------------
2057 //-----------------------------------------------------------------
2058 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2059 //-----------------------------------------------------------------
2075 //_____________________________________________________________________________
2076 void AliTPC::SetSens(Int_t sens)
2079 //-------------------------------------------------------------
2080 // Activates/deactivates the sensitive strips at the center of
2081 // the pad row -- this is for the space-point resolution calculations
2082 //-------------------------------------------------------------
2084 //-----------------------------------------------------------------
2085 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2086 //-----------------------------------------------------------------
2091 void AliTPC::SetSide(Float_t side)
2096 //____________________________________________________________________________
2097 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2098 Float_t p2,Float_t p3)
2113 //_____________________________________________________________________________
2115 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2118 // electron transport taking into account:
2120 // 2.ExB at the wires
2121 // 3. nonisochronity
2123 // xyz and index must be already transformed to system 1
2126 fTPCParam->Transform1to2(xyz,index);
2129 Float_t driftl=xyz[2];
2130 if(driftl<0.01) driftl=0.01;
2131 driftl=TMath::Sqrt(driftl);
2132 Float_t sig_t = driftl*(fTPCParam->GetDiffT());
2133 Float_t sig_l = driftl*(fTPCParam->GetDiffL());
2134 xyz[0]=gRandom->Gaus(xyz[0],sig_t);
2135 xyz[1]=gRandom->Gaus(xyz[1],sig_t);
2136 xyz[2]=gRandom->Gaus(xyz[2],sig_l);
2140 if (fTPCParam->GetMWPCReadout()==kTRUE){
2142 fTPCParam->Transform2to2NearestWire(xyz,index);
2143 Float_t dx=xyz[0]-x1;
2144 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2146 //add nonisochronity (not implemented yet)
2149 //_____________________________________________________________________________
2150 void AliTPC::Streamer(TBuffer &R__b)
2153 // Stream an object of class AliTPC.
2155 if (R__b.IsReading()) {
2156 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
2157 AliDetector::Streamer(R__b);
2158 if (R__v < 2) return;
2164 R__b.WriteVersion(AliTPC::IsA());
2165 AliDetector::Streamer(R__b);
2172 ClassImp(AliTPCcluster)
2174 //_____________________________________________________________________________
2175 AliTPCcluster::AliTPCcluster(Float_t *hits, Int_t *lab)
2178 // Creates a simulated cluster for the TPC
2180 fTracks[0] = lab[0];
2181 fTracks[1] = lab[1];
2182 fTracks[2] = lab[2];
2192 //_____________________________________________________________________________
2193 void AliTPCcluster::GetXYZ(Float_t *x, const AliTPCParam *par) const
2196 // Transformation from local to global coordinate system
2198 x[0]=par->GetPadRowRadii(fSector,fPadRow);
2201 Float_t cs, sn, tmp;
2202 par->AdjustCosSin(fSector,cs,sn);
2203 tmp = x[0]*cs-x[1]*sn;
2204 x[1]= x[0]*sn+x[1]*cs; x[0]=tmp;
2207 //_____________________________________________________________________________
2208 Int_t AliTPCcluster::Compare(TObject * o)
2211 // compare two clusters according y coordinata
2213 AliTPCcluster *cl= (AliTPCcluster *)o;
2214 if (fY<cl->fY) return -1;
2215 if (fY==cl->fY) return 0;
2219 Bool_t AliTPCcluster::IsSortable() const
2222 //make AliTPCcluster sortabale
2229 ClassImp(AliTPCdigit)
2231 //_____________________________________________________________________________
2232 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2236 // Creates a TPC digit object
2238 fSector = digits[0];
2239 fPadRow = digits[1];
2242 fSignal = digits[4];
2248 //_____________________________________________________________________________
2249 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2253 // Creates a TPC hit object
2264 ClassImp(AliTPCtrack)
2266 //_____________________________________________________________________________
2267 AliTPCtrack::AliTPCtrack(Float_t *hits)
2270 // Default creator for a TPC reconstructed track object
2272 fX=hits[0]; // This is dummy code !
2274 //_________________________________________________________________________
2276 AliTPCtrack::AliTPCtrack(const AliTPCcluster *c,const TVector& xx,
2277 const TMatrix& CC, Double_t xref, Double_t alpha):
2278 x(xx),C(CC),fClusters(200)
2280 //-----------------------------------------------------------------
2281 // This is the main track constructor.
2283 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2284 //-----------------------------------------------------------------
2288 fClusters.AddLast((AliTPCcluster*)(c));
2291 //_____________________________________________________________________________
2292 AliTPCtrack::AliTPCtrack(const AliTPCtrack& t) : x(t.x), C(t.C),
2293 fClusters(t.fClusters.GetEntriesFast())
2295 //-----------------------------------------------------------------
2296 // This is a track copy constructor.
2298 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2299 //-----------------------------------------------------------------
2303 Int_t n=t.fClusters.GetEntriesFast();
2304 for (Int_t i=0; i<n; i++) fClusters.AddLast(t.fClusters.UncheckedAt(i));
2307 //_____________________________________________________________________________
2308 Int_t AliTPCtrack::Compare(TObject *o) {
2309 //-----------------------------------------------------------------
2310 // This function compares tracks according to the uncertainty of their
2312 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2313 //-----------------------------------------------------------------
2314 AliTPCtrack *t=(AliTPCtrack*)o;
2315 Double_t co=t->GetSigmaY2();
2316 Double_t c =GetSigmaY2();
2318 else if (c<co) return -1;
2322 //_____________________________________________________________________________
2323 Int_t AliTPCtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho,Double_t pm)
2325 //-----------------------------------------------------------------
2326 // This function propagates a track to a reference plane x=xk.
2328 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2329 //-----------------------------------------------------------------
2330 if (TMath::Abs(x(2)*xk - x(3)) >= 0.999) {
2331 if (*this>4) cerr<<*this<<" AliTPCtrack warning: Propagation failed !\n";
2335 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=x(0), z1=x(1);
2336 Double_t c1=x(2)*x1 - x(3), r1=sqrt(1.- c1*c1);
2337 Double_t c2=x(2)*x2 - x(3), r2=sqrt(1.- c2*c2);
2339 x(0) += dx*(c1+c2)/(r1+r2);
2340 x(1) += dx*(c1+c2)/(c1*r2 + c2*r1)*x(4);
2342 TMatrix F(5,5); F.UnitMatrix();
2343 Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
2344 F(0,2)= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
2345 F(0,3)=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
2346 Double_t cr=c1*r2+c2*r1;
2347 F(1,2)= dx*x(4)*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
2348 F(1,3)=-dx*x(4)*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
2350 TMatrix tmp(F,TMatrix::kMult,C);
2351 C.Mult(tmp,TMatrix(TMatrix::kTransposed,F));
2355 //Multiple scattering******************
2356 Double_t ey=x(2)*fX - x(3);
2357 Double_t ex=sqrt(1-ey*ey);
2359 TMatrix Q(5,5); Q=0.;
2360 Q(2,2)=ez*ez+ey*ey; Q(2,3)=-ex*ey; Q(2,4)=-ex*ez;
2361 Q(3,2)=Q(2,3); Q(3,3)= ez*ez+ex*ex; Q(3,4)=-ey*ez;
2362 Q(4,2)=Q(2,4); Q(4,3)= Q(3,4); Q(4,4)=1.;
2365 F(2,2)=-x(2)*ex; F(2,3)=-x(2)*ey;
2366 F(3,2)=-ex*(x(2)*fX-ey); F(3,3)=-(1.+ x(2)*fX*ey - ey*ey);
2367 F(4,2)=-ez*ex; F(4,3)=-ez*ey; F(4,4)=1.;
2370 Q.Mult(tmp,TMatrix(TMatrix::kTransposed,F));
2372 Double_t p2=GetPt()*GetPt()*(1.+x(4)*x(4));
2373 Double_t beta2=p2/(p2 + pm*pm);
2374 Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-x(0))*(y1-x(0))+(z1-x(1))*(z1-x(1)));
2375 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
2379 //Energy losses************************
2380 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d*rho;
2381 if (x1 < x2) dE=-dE;
2382 x(2)*=(1.- sqrt(p2+pm*pm)/p2*dE);
2383 //x(3)*=(1.- sqrt(p2+pm*pm)/p2*dE);
2388 //_____________________________________________________________________________
2389 void AliTPCtrack::PropagateToVertex(Double_t x0,Double_t rho,Double_t pm)
2391 //-----------------------------------------------------------------
2392 // This function propagates tracks to the "vertex".
2394 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2395 //-----------------------------------------------------------------
2396 Double_t c=x(2)*fX - x(3);
2397 Double_t tgf=-x(3)/(x(2)*x(0) + sqrt(1-c*c));
2398 Double_t snf=tgf/sqrt(1.+ tgf*tgf);
2399 Double_t xv=(x(3)+snf)/x(2);
2400 PropagateTo(xv,x0,rho,pm);
2403 //_____________________________________________________________________________
2404 void AliTPCtrack::Update(const AliTPCcluster *c, Double_t chisq)
2406 //-----------------------------------------------------------------
2407 // This function associates a clusters with this track.
2409 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2410 //-----------------------------------------------------------------
2411 TMatrix H(2,5); H.UnitMatrix();
2412 TMatrix Ht(TMatrix::kTransposed,H);
2413 TVector m(2); m(0)=c->fY; m(1)=c->fZ;
2414 TMatrix V(2,2); V(0,0)=c->fSigmaY2; V(0,1)=0.; V(1,0)=0.; V(1,1)=c->fSigmaZ2;
2416 TMatrix tmp(H,TMatrix::kMult,C);
2417 TMatrix R(tmp,TMatrix::kMult,Ht); R+=V;
2419 Double_t det=(Double_t)R(0,0)*R(1,1) - (Double_t)R(0,1)*R(1,0);
2420 R(0,1)=R(0,0); R(0,0)=R(1,1); R(1,1)=R(0,1);
2421 R(1,0)*=-1; R(0,1)=R(1,0);
2426 TMatrix K(C,TMatrix::kMult,Ht); K*=R;
2431 x*=-1; x*=K; x+=savex;
2432 if (TMath::Abs(x(2)*fX-x(3)) >= 0.999) {
2433 if (*this>4) cerr<<*this<<" AliTPCtrack warning: Filtering failed !\n";
2439 C.Mult(K,tmp); C-=saveC; C*=-1;
2441 fClusters.AddLast((AliTPCcluster*)c);
2445 //_____________________________________________________________________________
2446 Int_t AliTPCtrack::Rotate(Double_t alpha)
2448 //-----------------------------------------------------------------
2449 // This function rotates this track.
2451 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2452 //-----------------------------------------------------------------
2455 Double_t x1=fX, y1=x(0);
2456 Double_t ca=cos(alpha), sa=sin(alpha);
2457 Double_t r1=x(2)*fX - x(3);
2460 x(0)=-x1*sa + y1*ca;
2461 x(3)=x(3)*ca + (x(2)*y1 + sqrt(1.- r1*r1))*sa;
2463 Double_t r2=x(2)*fX - x(3);
2464 if (TMath::Abs(r2) >= 0.999) {
2465 if (*this>4) cerr<<*this<<" AliTPCtrack warning: Rotation failed !\n";
2469 Double_t y0=x(0) + sqrt(1.- r2*r2)/x(2);
2470 if ((x(0)-y0)*x(2) >= 0.) {
2471 if (*this>4) cerr<<*this<<" AliTPCtrack warning: Rotation failed !!!\n";
2475 TMatrix F(5,5); F.UnitMatrix();
2478 F(3,2)=(y1 - r1*x1/sqrt(1.- r1*r1))*sa;
2479 F(3,3)= ca + sa*r1/sqrt(1.- r1*r1);
2480 TMatrix tmp(F,TMatrix::kMult,C);
2481 // Double_t dy2=C(0,0);
2482 C.Mult(tmp,TMatrix(TMatrix::kTransposed,F));
2483 // C(0,0)+=dy2*sa*sa*r1*r1/(1.- r1*r1);
2484 // C(1,1)+=dy2*sa*sa*x(4)*x(4)/(1.- r1*r1);
2489 //_____________________________________________________________________________
2490 void AliTPCtrack::UseClusters() const
2492 //-----------------------------------------------------------------
2493 // This function marks clusters associated with this track.
2495 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2496 //-----------------------------------------------------------------
2497 Int_t num_of_clusters=fClusters.GetEntriesFast();
2498 for (Int_t i=0; i<num_of_clusters; i++) {
2499 //if (i<=14) continue;
2500 AliTPCcluster *c=(AliTPCcluster*)fClusters.UncheckedAt(i);
2505 //_____________________________________________________________________________
2506 Double_t AliTPCtrack::GetPredictedChi2(const AliTPCcluster *c) const
2508 //-----------------------------------------------------------------
2509 // This function calculates a predicted chi2 increment.
2511 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2512 //-----------------------------------------------------------------
2513 TMatrix H(2,5); H.UnitMatrix();
2514 TVector m(2); m(0)=c->fY; m(1)=c->fZ;
2515 TMatrix V(2,2); V(0,0)=c->fSigmaY2; V(0,1)=0.; V(1,0)=0.; V(1,1)=c->fSigmaZ2;
2516 TVector res=x; res*=H; res-=m; //res*=-1;
2517 TMatrix tmp(H,TMatrix::kMult,C);
2518 TMatrix R(tmp,TMatrix::kMult,TMatrix(TMatrix::kTransposed,H)); R+=V;
2520 Double_t det=(Double_t)R(0,0)*R(1,1) - (Double_t)R(0,1)*R(1,0);
2521 if (TMath::Abs(det) < 1.e-10) {
2522 if (*this>4) cerr<<*this<<" AliTPCtrack warning: Singular matrix !\n";
2525 R(0,1)=R(0,0); R(0,0)=R(1,1); R(1,1)=R(0,1);
2526 R(1,0)*=-1; R(0,1)=R(1,0);
2536 //_____________________________________________________________________________
2537 struct S { Int_t lab; Int_t max; };
2538 Int_t AliTPCtrack::GetLabel(Int_t nrows) const
2540 //-----------------------------------------------------------------
2541 // This function returns the track label. If label<0, this track is fake.
2543 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2544 //-----------------------------------------------------------------
2545 Int_t num_of_clusters=fClusters.GetEntriesFast();
2546 S *s=new S[num_of_clusters];
2548 for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
2550 Int_t lab=123456789;
2551 for (i=0; i<num_of_clusters; i++) {
2552 AliTPCcluster *c=(AliTPCcluster*)fClusters.UncheckedAt(i);
2553 lab=TMath::Abs(c->fTracks[0]);
2555 for (j=0; j<num_of_clusters; j++)
2556 if (s[j].lab==lab || s[j].max==0) break;
2562 for (i=0; i<num_of_clusters; i++)
2563 if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
2567 for (i=0; i<num_of_clusters; i++) {
2568 AliTPCcluster *c=(AliTPCcluster*)fClusters.UncheckedAt(i);
2569 if (TMath::Abs(c->fTracks[1]) == lab ||
2570 TMath::Abs(c->fTracks[2]) == lab ) max++;
2573 if (1.-Float_t(max)/num_of_clusters > 0.10) return -lab;
2575 Int_t tail=Int_t(0.08*nrows);
2576 if (num_of_clusters < tail) return lab;
2579 for (i=1; i<=tail; i++) {
2580 AliTPCcluster *c=(AliTPCcluster*)fClusters.UncheckedAt(num_of_clusters-i);
2581 if (lab == TMath::Abs(c->fTracks[0]) ||
2582 lab == TMath::Abs(c->fTracks[1]) ||
2583 lab == TMath::Abs(c->fTracks[2])) max++;
2585 if (max < Int_t(0.5*tail)) return -lab;
2590 //_____________________________________________________________________________
2591 void AliTPCtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
2593 //-----------------------------------------------------------------
2594 // This function returns reconstructed track momentum in the global system.
2596 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2597 //-----------------------------------------------------------------
2598 Double_t pt=TMath::Abs(GetPt()); // GeV/c
2599 Double_t r=x(2)*fX-x(3);
2600 Double_t y0=x(0) + sqrt(1.- r*r)/x(2);
2601 px=-pt*(x(0)-y0)*x(2); //cos(phi);
2602 py=-pt*(x(3)-fX*x(2)); //sin(phi);
2604 Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
2605 py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
2609 //_____________________________________________________________________________
2610 Double_t AliTPCtrack::GetdEdX(Double_t low, Double_t up) const {
2611 //-----------------------------------------------------------------
2612 // This funtion calculates dE/dX within the "low" and "up" cuts.
2614 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2615 //-----------------------------------------------------------------
2616 Int_t ncl=fClusters.GetEntriesFast();
2618 Double_t *q=new Double_t[ncl];
2620 for (i=1; i<ncl; i++) { //Shall I think of this "i=1" ? (I.Belikov)
2621 AliTPCcluster *cl=(AliTPCcluster*)(fClusters.UncheckedAt(i));
2622 q[n++]=TMath::Abs(cl->fQ)/cl->fdEdX;
2623 if (cl->fSector<36) q[n-1]*=1.1;
2630 for (i=0; i<n-1; i++) {
2631 if (q[i]<=q[i+1]) continue;
2632 Double_t tmp=q[i]; q[i]=q[i+1]; q[i+1]=tmp;
2637 Int_t nl=Int_t(low*n), nu=Int_t(up *n);
2639 for (i=nl; i<=nu; i++) dedx += q[i];
2644 //_________________________________________________________________________
2646 // Classes for internal tracking use
2647 //_________________________________________________________________________
2648 void AliTPCRow::InsertCluster(const AliTPCcluster* c) {
2649 //-----------------------------------------------------------------------
2650 // Insert a cluster into this pad row in accordence with its y-coordinate
2652 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2653 //-----------------------------------------------------------------------
2654 if (num_of_clusters==MAX_CLUSTER_PER_ROW) {
2655 cerr<<"AliTPCRow::InsertCluster(): Too many clusters !\n"; return;
2657 if (num_of_clusters==0) {clusters[num_of_clusters++]=c; return;}
2658 Int_t i=Find(c->fY);
2659 memmove(clusters+i+1 ,clusters+i,(num_of_clusters-i)*sizeof(AliTPCcluster*));
2660 clusters[i]=c; num_of_clusters++;
2662 //___________________________________________________________________
2664 Int_t AliTPCRow::Find(Double_t y) const {
2665 //-----------------------------------------------------------------------
2666 // Return the index of the nearest cluster
2668 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
2669 //-----------------------------------------------------------------------
2670 if (y <= clusters[0]->fY) return 0;
2671 if (y > clusters[num_of_clusters-1]->fY) return num_of_clusters;
2672 Int_t b=0, e=num_of_clusters-1, m=(b+e)/2;
2673 for (; b<e; m=(b+e)/2) {
2674 if (y > clusters[m]->fY) b=m+1;
2679 //________________________________________________________________________