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.20 2000/06/30 12:07:49 kowal2
19 Updated from the TPC-PreRelease branch
21 Revision 1.19.2.4 2000/06/26 07:39:42 kowal2
22 Changes to obey the coding rules
24 Revision 1.19.2.3 2000/06/25 08:38:41 kowal2
25 Splitted from AliTPCtracking
27 Revision 1.19.2.2 2000/06/16 12:59:28 kowal2
28 Changed parameter settings
30 Revision 1.19.2.1 2000/06/09 07:15:07 kowal2
32 Defaults loaded automatically (hard-wired)
33 Optional parameters can be set via macro called in the constructor
35 Revision 1.19 2000/04/18 19:00:59 fca
36 Small bug fixes to TPC files
38 Revision 1.18 2000/04/17 09:37:33 kowal2
39 removed obsolete AliTPCDigitsDisplay.C
41 Revision 1.17.2.2 2000/04/10 08:15:12 kowal2
43 New, experimental data structure from M. Ivanov
44 New tracking algorithm
45 Different pad geometry for different sectors
46 Digitization rewritten
48 Revision 1.17.2.1 2000/04/10 07:56:53 kowal2
49 Not used anymore - removed
51 Revision 1.17 2000/01/19 17:17:30 fca
52 Introducing a list of lists of hits -- more hits allowed for detector now
54 Revision 1.16 1999/11/05 09:29:23 fca
55 Accept only signals > 0
57 Revision 1.15 1999/10/08 06:26:53 fca
58 Removed ClustersIndex - not used anymore
60 Revision 1.14 1999/09/29 09:24:33 fca
61 Introduction of the Copyright and cvs Log
65 ///////////////////////////////////////////////////////////////////////////////
67 // Time Projection Chamber //
68 // This class contains the basic functions for the Time Projection Chamber //
69 // detector. Functions specific to one particular geometry are //
70 // contained in the derived classes //
74 <img src="picts/AliTPCClass.gif">
79 ///////////////////////////////////////////////////////////////////////////////
87 #include <TGeometry.h>
90 #include <TObjectTable.h>
91 #include "TParticle.h"
100 #include "AliTPCParamSR.h"
101 #include "AliTPCPRF2D.h"
102 #include "AliTPCRF1D.h"
103 #include "AliDigits.h"
104 #include "AliSimDigits.h"
106 #include "AliTPCDigitsArray.h"
107 #include "AliCluster.h"
108 #include "AliClusters.h"
109 #include "AliTPCClustersRow.h"
110 #include "AliTPCClustersArray.h"
112 #include "AliTPCcluster.h"
113 #include "AliTPCclusterer.h"
114 #include "AliTPCtracker.h"
116 #include <TInterpreter.h>
120 //_____________________________________________________________________________
124 // Default constructor
136 //_____________________________________________________________________________
137 AliTPC::AliTPC(const char *name, const char *title)
138 : AliDetector(name,title)
141 // Standard constructor
145 // Initialise arrays of hits and digits
146 fHits = new TClonesArray("AliTPChit", 176);
147 gAlice->AddHitList(fHits);
152 // Initialise counters
158 // Initialise color attributes
159 SetMarkerColor(kYellow);
162 // Set TPC parameters
165 if (!strcmp(title,"Default")) {
166 fTPCParam = new AliTPCParamSR;
168 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
174 //_____________________________________________________________________________
187 //_____________________________________________________________________________
188 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
191 // Add a hit to the list
193 TClonesArray &lhits = *fHits;
194 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
197 //_____________________________________________________________________________
198 void AliTPC::BuildGeometry()
202 // Build TPC ROOT TNode geometry for the event display
207 const int kColorTPC=19;
208 char name[5], title[25];
209 const Double_t kDegrad=TMath::Pi()/180;
210 const Double_t kRaddeg=180./TMath::Pi();
213 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
214 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
216 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
217 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
219 Int_t nLo = fTPCParam->GetNInnerSector()/2;
220 Int_t nHi = fTPCParam->GetNOuterSector()/2;
222 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
223 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
224 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
225 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
228 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
229 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
235 // Get ALICE top node
238 nTop=gAlice->GetGeometry()->GetNode("alice");
242 rl = fTPCParam->GetInnerRadiusLow();
243 ru = fTPCParam->GetInnerRadiusUp();
247 sprintf(name,"LS%2.2d",i);
249 sprintf(title,"TPC low sector %3d",i);
252 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
253 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
254 tubs->SetNumberOfDivisions(1);
256 nNode = new TNode(name,title,name,0,0,0,"");
257 nNode->SetLineColor(kColorTPC);
263 rl = fTPCParam->GetOuterRadiusLow();
264 ru = fTPCParam->GetOuterRadiusUp();
267 sprintf(name,"US%2.2d",i);
269 sprintf(title,"TPC upper sector %d",i);
271 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
272 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
273 tubs->SetNumberOfDivisions(1);
275 nNode = new TNode(name,title,name,0,0,0,"");
276 nNode->SetLineColor(kColorTPC);
282 //_____________________________________________________________________________
283 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
286 // Calculate distance from TPC to mouse on the display
292 void AliTPC::Clusters2Tracks(TFile *of) {
293 //-----------------------------------------------------------------
294 // This is a track finder.
295 //-----------------------------------------------------------------
296 AliTPCtracker::Clusters2Tracks(fTPCParam,of);
299 //_____________________________________________________________________________
300 void AliTPC::CreateMaterials()
302 //-----------------------------------------------
303 // Create Materials for for TPC
304 //-----------------------------------------------
306 //-----------------------------------------------------------------
307 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
308 //-----------------------------------------------------------------
310 Int_t iSXFLD=gAlice->Field()->Integ();
311 Float_t sXMGMX=gAlice->Field()->Max();
313 Float_t amat[5]; // atomic numbers
314 Float_t zmat[5]; // z
315 Float_t wmat[5]; // proportions
319 // ********************* Gases *******************
321 //--------------------------------------------------------------
323 //--------------------------------------------------------------
333 AliMaterial(20,"Ne",aNe,zNe,density,999.,999.);
337 Float_t aAr = 39.948;
342 AliMaterial(21,"Ar",aAr,zAr,density,999.,999.);
350 //--------------------------------------------------------------
352 //--------------------------------------------------------------
369 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
371 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
386 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
388 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
403 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
405 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
407 //----------------------------------------------------------------
408 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
409 //----------------------------------------------------------------
417 Float_t a,z,rho,absl,x0,buf[1];
420 for(nc = 0;nc<fNoComp;nc++)
423 // retrive material constants
425 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,x0,absl,buf,nbuf);
430 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
432 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? aPure[nnc] : amol[nnc]);
433 density += fMixtProp[nc]*rho; // density of the mixture
437 // mixture proportions by weight!
439 for(nc = 0;nc<fNoComp;nc++)
442 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
444 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ? aPure[nnc] : amol[nnc])/am;
448 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
449 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
450 AliMixture(33,"Drift gas 3",amat,zmat,density,fNoComp,wmat);
452 AliMedium(2, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
453 AliMedium(3, "Drift gas 2", 32, 0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
454 AliMedium(4, "Drift gas 3", 33, 1, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
458 AliMaterial(24, "Air", 14.61, 7.3, .001205, 30420., 67500.);
460 AliMedium(24, "Air", 24, 0, iSXFLD, sXMGMX, 10., .1, .1, .1, .1);
462 //----------------------------------------------------------------------
464 //----------------------------------------------------------------------
468 AliMaterial(30, "Al", 26.98, 13., 2.7, 8.9, 37.2);
470 AliMedium(0, "Al",30, 0, iSXFLD, sXMGMX, 10., .1, .1, .1, .1);
474 AliMaterial(31, "Si", 28.086, 14.,2.33, 9.36, 999.);
476 AliMedium(7, "Al",31, 0, iSXFLD, sXMGMX, 10., .1, .1, .1, .1);
495 AliMixture(32, "Mylar",amat,zmat,density,-3,wmat);
497 AliMedium(5, "Mylar",32, 0, iSXFLD, sXMGMX, 10., .1, .1, .001, .01);
504 AliMaterial(33,"C normal",12.011,6.,2.265,18.8,999.);
506 AliMedium(6,"C normal",33,0, iSXFLD, sXMGMX, 10., .1, .1, .001, .01);
508 // G10 for inner and outr field cage
509 // G10 is 60% SiO2 + 40% epoxy, right now I use A and Z for SiO2
525 AliMixture(34,"G10 aux.",amat,zmat,density,-2,wmat);
528 gMC->Gfmate((*fIdmate)[34],namate,a,z,rho,x0,absl,buf,nbuf);
530 Float_t thickX0 = 0.0052; // field cage in X0 units
532 Float_t thick = 2.; // in cm
536 rhoFactor = x0*thickX0/thick;
537 density = rho*rhoFactor;
539 AliMaterial(35,"G10-fc",a,z,density,999.,999.);
541 AliMedium(8,"G10-fc",35,0, iSXFLD, sXMGMX, 10., .1, .1, .001, .01);
543 thickX0 = 0.0027; // inner vessel (eta <0.9)
545 rhoFactor = x0*thickX0/thick;
546 density = rho*rhoFactor;
548 AliMaterial(36,"G10-iv",a,z,density,999.,999.);
550 AliMedium(9,"G10-iv",36,0, iSXFLD, sXMGMX, 10., .1, .1, .001, .01);
554 gMC->Gfmate((*fIdmate)[33],namate,a,z,rho,x0,absl,buf,nbuf);
556 thickX0 = 0.0133; // outer vessel
558 rhoFactor = x0*thickX0/thick;
559 density = rho*rhoFactor;
562 AliMaterial(37,"C-ov",a,z,density,999.,999.);
564 AliMedium(10,"C-ov",37,0, iSXFLD, sXMGMX, 10., .1, .1, .001, .01);
566 thickX0=0.015; // inner vessel (cone, eta > 0.9)
568 rhoFactor = x0*thickX0/thick;
569 density = rho*rhoFactor;
571 AliMaterial(38,"C-ivc",a,z,density,999.,999.);
573 AliMedium(11,"C-ivc",38,0, iSXFLD, sXMGMX, 10., .1, .1, .001, .01);
577 AliMedium(12,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
582 void AliTPC::Digits2Clusters(TFile *of)
584 //-----------------------------------------------------------------
585 // This is a simple cluster finder.
586 //-----------------------------------------------------------------
587 AliTPCclusterer::Digits2Clusters(fTPCParam,of);
590 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
591 extern Double_t SigmaZ2(Double_t, Double_t);
592 //_____________________________________________________________________________
593 void AliTPC::Hits2Clusters(TFile *of)
595 //--------------------------------------------------------
596 // TPC simple cluster generator from hits
597 // obtained from the TPC Fast Simulator
598 // The point errors are taken from the parametrization
599 //--------------------------------------------------------
601 //-----------------------------------------------------------------
602 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
603 //-----------------------------------------------------------------
604 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
605 // Jouri.Belikov@cern.ch
606 //----------------------------------------------------------------
608 /////////////////////////////////////////////////////////////////////////////
610 //---------------------------------------------------------------------
611 // ALICE TPC Cluster Parameters
612 //--------------------------------------------------------------------
616 // Cluster width in rphi
617 const Float_t kACrphi=0.18322;
618 const Float_t kBCrphi=0.59551e-3;
619 const Float_t kCCrphi=0.60952e-1;
620 // Cluster width in z
621 const Float_t kACz=0.19081;
622 const Float_t kBCz=0.55938e-3;
623 const Float_t kCCz=0.30428;
625 TDirectory *savedir=gDirectory;
628 cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
633 printf("AliTPCParam MUST be created firstly\n");
637 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
639 TParticle *particle; // pointer to a given particle
640 AliTPChit *tpcHit; // pointer to a sigle TPC hit
641 TClonesArray *particles; //pointer to the particle list
645 Float_t pl,pt,tanth,rpad,ratio;
648 //---------------------------------------------------------------
649 // Get the access to the tracks
650 //---------------------------------------------------------------
652 TTree *tH = gAlice->TreeH();
653 Stat_t ntracks = tH->GetEntries();
654 particles=gAlice->Particles();
656 //Switch to the output file
659 fTPCParam->Write(fTPCParam->GetTitle());
660 AliTPCClustersArray carray;
661 carray.Setup(fTPCParam);
662 carray.SetClusterType("AliTPCcluster");
665 Int_t nclusters=0; //cluster counter
667 //------------------------------------------------------------
668 // Loop over all sectors (72 sectors for 20 deg
669 // segmentation for both lower and upper sectors)
670 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
671 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
673 // First cluster for sector 0 starts at "0"
674 //------------------------------------------------------------
676 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
678 fTPCParam->AdjustCosSin(isec,cph,sph);
680 //------------------------------------------------------------
682 //------------------------------------------------------------
684 for(Int_t track=0;track<ntracks;track++){
688 // Get number of the TPC hits
690 nhits=fHits->GetEntriesFast();
694 for(Int_t hit=0;hit<nhits;hit++){
695 tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
696 if (tpcHit->fQ == 0.) continue; //information about track (I.Belikov)
697 sector=tpcHit->fSector; // sector number
698 if(sector != isec) continue; //terminate iteration
699 ipart=tpcHit->fTrack;
700 particle=(TParticle*)particles->UncheckedAt(ipart);
703 if(pt < 1.e-9) pt=1.e-9;
705 tanth = TMath::Abs(tanth);
706 rpad=TMath::Sqrt(tpcHit->fX*tpcHit->fX + tpcHit->fY*tpcHit->fY);
707 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
709 // space-point resolutions
711 sigmaRphi=SigmaY2(rpad,tanth,pt);
712 sigmaZ =SigmaZ2(rpad,tanth );
716 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
717 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
719 // temporary protection
721 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
722 if(sigmaZ < 0.) sigmaZ=0.4e-3;
723 if(clRphi < 0.) clRphi=2.5e-3;
724 if(clZ < 0.) clZ=2.5e-5;
729 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
730 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
732 Float_t xprim= tpcHit->fX*cph + tpcHit->fY*sph;
733 Float_t yprim=-tpcHit->fX*sph + tpcHit->fY*cph;
734 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
735 Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
736 fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
737 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
738 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
739 xyz[1]=gRandom->Gaus(tpcHit->fZ,TMath::Sqrt(sigmaZ)); // z
740 if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->fZ;
741 xyz[2]=tpcHit->fQ; // q
742 xyz[3]=sigmaRphi; // fSigmaY2
743 xyz[4]=sigmaZ; // fSigmaZ2
745 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
746 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
748 Int_t tracks[3]={tpcHit->fTrack, -1, -1};
749 AliTPCcluster cluster(xyz,tracks);
751 clrow->InsertCluster(&cluster); nclusters++;
753 } // end of loop over hits
755 } // end of loop over tracks
757 Int_t nrows=fTPCParam->GetNRow(isec);
758 for (Int_t irow=0; irow<nrows; irow++) {
759 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
760 if (!clrow) continue;
761 carray.StoreRow(isec,irow);
762 carray.ClearRow(isec,irow);
765 } // end of loop over sectors
767 cerr<<"Number of made clusters : "<<nclusters<<" \n";
769 carray.GetTree()->Write();
771 savedir->cd(); //switch back to the input file
775 //_________________________________________________________________
776 void AliTPC::Hits2ExactClustersSector(Int_t isec)
778 //--------------------------------------------------------
779 //calculate exact cross point of track and given pad row
780 //resulting values are expressed in "digit" coordinata
781 //--------------------------------------------------------
783 //-----------------------------------------------------------------
784 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
785 //-----------------------------------------------------------------
787 if (fClustersArray==0){
791 TParticle *particle; // pointer to a given particle
792 AliTPChit *tpcHit; // pointer to a sigle TPC hit
793 TClonesArray *particles; //pointer to the particle list
796 const Int_t kcmaxhits=30000;
797 TVector * xxxx = new TVector(kcmaxhits*4);
798 TVector & xxx = *xxxx;
799 Int_t maxhits = kcmaxhits;
800 //construct array for each padrow
801 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
802 fClustersArray->CreateRow(isec,i);
804 //---------------------------------------------------------------
805 // Get the access to the tracks
806 //---------------------------------------------------------------
808 TTree *tH = gAlice->TreeH();
809 Stat_t ntracks = tH->GetEntries();
810 particles=gAlice->Particles();
811 Int_t npart = particles->GetEntriesFast();
813 //------------------------------------------------------------
815 //------------------------------------------------------------
817 for(Int_t track=0;track<ntracks;track++){
821 // Get number of the TPC hits and a pointer
824 nhits=fHits->GetEntriesFast();
828 Int_t currentIndex=0;
829 Int_t lastrow=-1; //last writen row
830 for(Int_t hit=0;hit<nhits;hit++){
831 tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
832 if (tpcHit==0) continue;
833 sector=tpcHit->fSector; // sector number
834 if(sector != isec) continue;
835 ipart=tpcHit->fTrack;
836 if (ipart<npart) particle=(TParticle*)particles->UncheckedAt(ipart);
840 Float_t x[3]={tpcHit->fX,tpcHit->fY,tpcHit->fZ};
841 Int_t index[3]={1,isec,0};
842 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
843 if (currentrow<0) continue;
844 if (lastrow<0) lastrow=currentrow;
845 if (currentrow==lastrow){
846 if ( currentIndex>=maxhits){
848 xxx.ResizeTo(4*maxhits);
850 xxx(currentIndex*4)=x[0];
851 xxx(currentIndex*4+1)=x[1];
852 xxx(currentIndex*4+2)=x[2];
853 xxx(currentIndex*4+3)=tpcHit->fQ;
869 for (Int_t index=0;index<currentIndex;index++){
871 x=x2=x3=x4=xxx(index*4);
879 sumy+=xxx(index*4+1);
880 sumxy+=xxx(index*4+1)*x;
881 sumx2y+=xxx(index*4+1)*x2;
882 sumz+=xxx(index*4+2);
883 sumxz+=xxx(index*4+2)*x;
884 sumx2z+=xxx(index*4+2)*x2;
885 sumq+=xxx(index*4+3);
887 Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
888 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
889 sumx2*(sumx*sumx3-sumx2*sumx2);
891 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
892 sumx2*(sumxy*sumx3-sumx2y*sumx2);
893 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
894 sumx2*(sumxz*sumx3-sumx2z*sumx2);
896 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
897 sumx2*(sumx*sumx2y-sumx2*sumxy);
898 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
899 sumx2*(sumx*sumx2z-sumx2*sumxz);
901 Float_t y=detay/det+centralPad;
903 Float_t by=detby/det; //y angle
904 Float_t bz=detbz/det; //z angle
905 sumy/=Float_t(currentIndex);
906 sumz/=Float_t(currentIndex);
915 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
916 if (row!=0) row->InsertCluster(&cl);
919 } //end of calculating cluster for given row
923 } // end of loop over hits
924 } // end of loop over tracks
925 //write padrows to tree
926 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
927 fClustersArray->StoreRow(isec,ii);
928 fClustersArray->ClearRow(isec,ii);
934 //__________________________________________________________________
935 void AliTPC::Hits2Digits()
937 //----------------------------------------------------
938 // Loop over all sectors
939 //----------------------------------------------------
942 printf("AliTPCParam MUST be created firstly\n");
946 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
951 //_____________________________________________________________________________
952 void AliTPC::Hits2DigitsSector(Int_t isec)
954 //-------------------------------------------------------------------
955 // TPC conversion from hits to digits.
956 //-------------------------------------------------------------------
958 //-----------------------------------------------------------------
959 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
960 //-----------------------------------------------------------------
962 //-------------------------------------------------------
963 // Get the access to the track hits
964 //-------------------------------------------------------
967 TTree *tH = gAlice->TreeH(); // pointer to the hits tree
968 Stat_t ntracks = tH->GetEntries();
972 //-------------------------------------------
973 // Only if there are any tracks...
974 //-------------------------------------------
978 printf("*** Processing sector number %d ***\n",isec);
980 Int_t nrows =fTPCParam->GetNRow(isec);
982 row= new TObjArray* [nrows];
984 MakeSector(isec,nrows,tH,ntracks,row);
986 //--------------------------------------------------------
987 // Digitize this sector, row by row
988 // row[i] is the pointer to the TObjArray of TVectors,
989 // each one containing electrons accepted on this
990 // row, assigned into tracks
991 //--------------------------------------------------------
995 if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree();
997 for (i=0;i<nrows;i++){
999 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1001 DigitizeRow(i,isec,row);
1003 fDigitsArray->StoreRow(isec,i);
1005 Int_t ndig = dig->GetDigitSize();
1007 printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1009 fDigitsArray->ClearRow(isec,i);
1012 } // end of the sector digitization
1014 for(i=0;i<nrows;i++){
1018 delete [] row; // delete the array of pointers to TObjArray-s
1022 } // end of Hits2DigitsSector
1025 //_____________________________________________________________________________
1026 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1028 //-----------------------------------------------------------
1029 // Single row digitization, coupling from the neighbouring
1030 // rows taken into account
1031 //-----------------------------------------------------------
1033 //-----------------------------------------------------------------
1034 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1035 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1036 //-----------------------------------------------------------------
1039 Float_t zerosup = fTPCParam->GetZeroSup();
1040 Int_t nrows =fTPCParam->GetNRow(isec);
1041 fCurrentIndex[1]= isec;
1044 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1045 Int_t nofTbins = fTPCParam->GetMaxTBin();
1046 Int_t indexRange[4];
1048 // Integrated signal for this row
1049 // and a single track signal
1051 TMatrix *m1 = new TMatrix(0,nofPads,0,nofTbins); // integrated
1052 TMatrix *m2 = new TMatrix(0,nofPads,0,nofTbins); // single
1054 TMatrix &total = *m1;
1056 // Array of pointers to the label-signal list
1058 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1059 Float_t **pList = new Float_t* [nofDigits];
1063 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1067 Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1068 Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1069 for (Int_t row= row1;row<=row2;row++){
1070 Int_t nTracks= rows[row]->GetEntries();
1071 for (i1=0;i1<nTracks;i1++){
1072 fCurrentIndex[2]= row;
1073 fCurrentIndex[3]=irow;
1075 m2->Zero(); // clear single track signal matrix
1076 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1077 GetList(trackLabel,nofPads,m2,indexRange,pList);
1079 else GetSignal(rows[row],i1,0,m1,indexRange);
1085 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1086 for(Int_t ip=0;ip<nofPads;ip++){
1087 for(Int_t it=0;it<nofTbins;it++){
1089 Float_t q = total(ip,it);
1091 Int_t gi =it*nofPads+ip; // global index
1093 q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
1097 if(q <=zerosup) continue; // do not fill zeros
1098 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1101 // "real" signal or electronic noise (list = -1)?
1104 for(Int_t j1=0;j1<3;j1++){
1105 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -1;
1110 <A NAME="AliDigits"></A>
1111 using of AliDigits object
1114 dig->SetDigitFast((Short_t)q,it,ip);
1115 if (fDigitsArray->IsSimulated())
1117 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1118 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1119 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1123 } // end of loop over time buckets
1124 } // end of lop over pads
1127 // This row has been digitized, delete nonused stuff
1130 for(lp=0;lp<nofDigits;lp++){
1131 if(pList[lp]) delete [] pList[lp];
1140 } // end of DigitizeRow
1142 //_____________________________________________________________________________
1144 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr, TMatrix *m1, TMatrix *m2,
1148 //---------------------------------------------------------------
1149 // Calculates 2-D signal (pad,time) for a single track,
1150 // returns a pointer to the signal matrix and the track label
1151 // No digitization is performed at this level!!!
1152 //---------------------------------------------------------------
1154 //-----------------------------------------------------------------
1155 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1156 // Modified: Marian Ivanov
1157 //-----------------------------------------------------------------
1161 tv = (TVector*)p1->At(ntr); // pointer to a track
1164 Float_t label = v(0);
1165 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
1167 Int_t nElectrons = (tv->GetNrows()-1)/4;
1168 indexRange[0]=9999; // min pad
1169 indexRange[1]=-1; // max pad
1170 indexRange[2]=9999; //min time
1171 indexRange[3]=-1; // max time
1173 // Float_t IneffFactor = 0.5; // inefficiency in the gain close to the edge, as above
1175 TMatrix &signal = *m1;
1176 TMatrix &total = *m2;
1178 // Loop over all electrons
1180 for(Int_t nel=0; nel<nElectrons; nel++){
1182 Float_t aval = v(idx+4);
1183 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1184 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1185 Int_t n = fTPCParam->CalcResponse(xyz,fCurrentIndex,fCurrentIndex[3]);
1187 if (n>0) for (Int_t i =0; i<n; i++){
1188 Int_t *index = fTPCParam->GetResBin(i);
1189 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1190 if ( ( pad<(fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]))) && (pad>0)) {
1191 Int_t time=index[2];
1192 Float_t weight = fTPCParam->GetResWeight(i); //we normalise response to ADC channel
1193 weight *= eltoadcfac;
1195 if (m1!=0) signal(pad,time)+=weight;
1196 total(pad,time)+=weight;
1197 indexRange[0]=TMath::Min(indexRange[0],pad);
1198 indexRange[1]=TMath::Max(indexRange[1],pad);
1199 indexRange[2]=TMath::Min(indexRange[2],time);
1200 indexRange[3]=TMath::Max(indexRange[3],time);
1203 } // end of loop over electrons
1205 return label; // returns track label when finished
1208 //_____________________________________________________________________________
1209 void AliTPC::GetList(Float_t label,Int_t np,TMatrix *m,Int_t *indexRange,
1212 //----------------------------------------------------------------------
1213 // Updates the list of tracks contributing to digits for a given row
1214 //----------------------------------------------------------------------
1216 //-----------------------------------------------------------------
1217 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1218 //-----------------------------------------------------------------
1220 TMatrix &signal = *m;
1222 // lop over nonzero digits
1224 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1225 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1228 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1230 if(signal(ip,it)<0.5) continue;
1233 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1235 if(!pList[globalIndex]){
1238 // Create new list (6 elements - 3 signals and 3 labels),
1241 pList[globalIndex] = new Float_t [6];
1245 *pList[globalIndex] = -1.;
1246 *(pList[globalIndex]+1) = -1.;
1247 *(pList[globalIndex]+2) = -1.;
1248 *(pList[globalIndex]+3) = -1.;
1249 *(pList[globalIndex]+4) = -1.;
1250 *(pList[globalIndex]+5) = -1.;
1253 *pList[globalIndex] = label;
1254 *(pList[globalIndex]+3) = signal(ip,it);
1258 // check the signal magnitude
1260 Float_t highest = *(pList[globalIndex]+3);
1261 Float_t middle = *(pList[globalIndex]+4);
1262 Float_t lowest = *(pList[globalIndex]+5);
1265 // compare the new signal with already existing list
1268 if(signal(ip,it)<lowest) continue; // neglect this track
1272 if (signal(ip,it)>highest){
1273 *(pList[globalIndex]+5) = middle;
1274 *(pList[globalIndex]+4) = highest;
1275 *(pList[globalIndex]+3) = signal(ip,it);
1277 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1278 *(pList[globalIndex]+1) = *pList[globalIndex];
1279 *pList[globalIndex] = label;
1281 else if (signal(ip,it)>middle){
1282 *(pList[globalIndex]+5) = middle;
1283 *(pList[globalIndex]+4) = signal(ip,it);
1285 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1286 *(pList[globalIndex]+1) = label;
1289 *(pList[globalIndex]+5) = signal(ip,it);
1290 *(pList[globalIndex]+2) = label;
1294 } // end of loop over pads
1295 } // end of loop over time bins
1300 //___________________________________________________________________
1301 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1302 Stat_t ntracks,TObjArray **row)
1305 //-----------------------------------------------------------------
1306 // Prepares the sector digitization, creates the vectors of
1307 // tracks for each row of this sector. The track vector
1308 // contains the track label and the position of electrons.
1309 //-----------------------------------------------------------------
1311 //-----------------------------------------------------------------
1312 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1313 //-----------------------------------------------------------------
1315 Float_t gasgain = fTPCParam->GetGasGain();
1319 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1321 //----------------------------------------------
1322 // Create TObjArray-s, one for each row,
1323 // each TObjArray will store the TVectors
1324 // of electrons, one TVector per each track.
1325 //----------------------------------------------
1327 Int_t *nofElectrons = new Int_t [nrows]; // electron counter for each row
1328 TVector **tracks = new TVector* [nrows]; //pointers to the track vectors
1329 for(i=0; i<nrows; i++){
1330 row[i] = new TObjArray;
1335 //--------------------------------------------------------------------
1336 // Loop over tracks, the "track" contains the full history
1337 //--------------------------------------------------------------------
1339 Int_t previousTrack,currentTrack;
1340 previousTrack = -1; // nothing to store so far!
1342 for(Int_t track=0;track<ntracks;track++){
1346 TH->GetEvent(track); // get next track
1347 Int_t nhits = fHits->GetEntriesFast(); // get number of hits for this track
1349 if(nhits == 0) continue; // no hits in the TPC for this track
1351 //--------------------------------------------------------------
1353 //--------------------------------------------------------------
1355 for(Int_t hit=0;hit<nhits;hit++){
1357 tpcHit = (AliTPChit*)fHits->UncheckedAt(hit); // get a pointer to a hit
1359 Int_t sector=tpcHit->fSector; // sector number
1360 if(sector != isec) continue;
1362 currentTrack = tpcHit->fTrack; // track number
1363 if(currentTrack != previousTrack){
1365 // store already filled fTrack
1367 for(i=0;i<nrows;i++){
1368 if(previousTrack != -1){
1369 if(nofElectrons[i]>0){
1370 TVector &v = *tracks[i];
1371 v(0) = previousTrack;
1372 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1373 row[i]->Add(tracks[i]);
1376 delete tracks[i]; // delete empty TVector
1382 tracks[i] = new TVector(481); // TVectors for the next fTrack
1384 } // end of loop over rows
1386 previousTrack=currentTrack; // update track label
1389 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1391 //---------------------------------------------------
1392 // Calculate the electron attachment probability
1393 //---------------------------------------------------
1396 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->fZ))
1397 /fTPCParam->GetDriftV();
1399 Float_t attProb = fTPCParam->GetAttCoef()*
1400 fTPCParam->GetOxyCont()*time; // fraction!
1402 //-----------------------------------------------
1403 // Loop over electrons
1404 //-----------------------------------------------
1407 for(Int_t nel=0;nel<qI;nel++){
1408 // skip if electron lost due to the attachment
1409 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1413 xyz[3]= (Float_t) (-gasgain*TMath::Log(gRandom->Rndm()));
1416 TransportElectron(xyz,index); //MI change -august
1418 fTPCParam->GetPadRow(xyz,index); //MI change august
1419 rowNumber = index[2];
1420 //transform position to local digit coordinates
1421 //relative to nearest pad row
1422 if ((rowNumber<0)||rowNumber>=fTPCParam->GetNRow(isec)) continue;
1423 nofElectrons[rowNumber]++;
1424 //----------------------------------
1425 // Expand vector if necessary
1426 //----------------------------------
1427 if(nofElectrons[rowNumber]>120){
1428 Int_t range = tracks[rowNumber]->GetNrows();
1429 if((nofElectrons[rowNumber])>(range-1)/4){
1431 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
1435 TVector &v = *tracks[rowNumber];
1436 Int_t idx = 4*nofElectrons[rowNumber]-3;
1438 v(idx)= xyz[0]; // X - pad row coordinate
1439 v(idx+1)=xyz[1]; // Y - pad coordinate (along the pad-row)
1440 v(idx+2)=xyz[2]; // Z - time bin coordinate
1441 v(idx+3)=xyz[3]; // avalanche size
1442 } // end of loop over electrons
1444 } // end of loop over hits
1445 } // end of loop over tracks
1448 // store remaining track (the last one) if not empty
1451 for(i=0;i<nrows;i++){
1452 if(nofElectrons[i]>0){
1453 TVector &v = *tracks[i];
1454 v(0) = previousTrack;
1455 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1456 row[i]->Add(tracks[i]);
1465 delete [] nofElectrons;
1468 } // end of MakeSector
1471 //_____________________________________________________________________________
1475 // Initialise TPC detector after definition of geometry
1480 for(i=0;i<35;i++) printf("*");
1481 printf(" TPC_INIT ");
1482 for(i=0;i<35;i++) printf("*");
1485 for(i=0;i<80;i++) printf("*");
1489 //_____________________________________________________________________________
1490 void AliTPC::MakeBranch(Option_t* option)
1493 // Create Tree branches for the TPC.
1495 Int_t buffersize = 4000;
1496 char branchname[10];
1497 sprintf(branchname,"%s",GetName());
1499 AliDetector::MakeBranch(option);
1501 char *d = strstr(option,"D");
1503 if (fDigits && gAlice->TreeD() && d) {
1504 gAlice->TreeD()->Branch(branchname,&fDigits, buffersize);
1505 printf("Making Branch %s for digits\n",branchname);
1509 //_____________________________________________________________________________
1510 void AliTPC::ResetDigits()
1513 // Reset number of digits and the digits array for this detector
1516 if (fDigits) fDigits->Clear();
1519 //_____________________________________________________________________________
1520 void AliTPC::SetSecAL(Int_t sec)
1522 //---------------------------------------------------
1523 // Activate/deactivate selection for lower sectors
1524 //---------------------------------------------------
1526 //-----------------------------------------------------------------
1527 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1528 //-----------------------------------------------------------------
1533 //_____________________________________________________________________________
1534 void AliTPC::SetSecAU(Int_t sec)
1536 //----------------------------------------------------
1537 // Activate/deactivate selection for upper sectors
1538 //---------------------------------------------------
1540 //-----------------------------------------------------------------
1541 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1542 //-----------------------------------------------------------------
1547 //_____________________________________________________________________________
1548 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
1550 //----------------------------------------
1551 // Select active lower sectors
1552 //----------------------------------------
1554 //-----------------------------------------------------------------
1555 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1556 //-----------------------------------------------------------------
1566 //_____________________________________________________________________________
1567 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
1568 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
1569 Int_t s11 , Int_t s12)
1571 //--------------------------------
1572 // Select active upper sectors
1573 //--------------------------------
1575 //-----------------------------------------------------------------
1576 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1577 //-----------------------------------------------------------------
1593 //_____________________________________________________________________________
1594 void AliTPC::SetSens(Int_t sens)
1597 //-------------------------------------------------------------
1598 // Activates/deactivates the sensitive strips at the center of
1599 // the pad row -- this is for the space-point resolution calculations
1600 //-------------------------------------------------------------
1602 //-----------------------------------------------------------------
1603 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1604 //-----------------------------------------------------------------
1609 void AliTPC::SetSide(Float_t side=0.)
1611 // choice of the TPC side
1616 //____________________________________________________________________________
1617 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
1618 Float_t p2,Float_t p3)
1621 // gax mixture definition
1635 //_____________________________________________________________________________
1637 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
1640 // electron transport taking into account:
1642 // 2.ExB at the wires
1643 // 3. nonisochronity
1645 // xyz and index must be already transformed to system 1
1648 fTPCParam->Transform1to2(xyz,index);
1651 Float_t driftl=xyz[2];
1652 if(driftl<0.01) driftl=0.01;
1653 driftl=TMath::Sqrt(driftl);
1654 Float_t sigT = driftl*(fTPCParam->GetDiffT());
1655 Float_t sigL = driftl*(fTPCParam->GetDiffL());
1656 xyz[0]=gRandom->Gaus(xyz[0],sigT);
1657 xyz[1]=gRandom->Gaus(xyz[1],sigT);
1658 xyz[2]=gRandom->Gaus(xyz[2],sigL);
1662 if (fTPCParam->GetMWPCReadout()==kTRUE){
1664 fTPCParam->Transform2to2NearestWire(xyz,index);
1665 Float_t dx=xyz[0]-x1;
1666 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
1668 //add nonisochronity (not implemented yet)
1671 //_____________________________________________________________________________
1672 void AliTPC::Streamer(TBuffer &R__b)
1675 // Stream an object of class AliTPC.
1677 if (R__b.IsReading()) {
1678 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1679 AliDetector::Streamer(R__b);
1680 if (R__v < 2) return;
1683 R__b.WriteVersion(AliTPC::IsA());
1684 AliDetector::Streamer(R__b);
1689 ClassImp(AliTPCdigit)
1691 //_____________________________________________________________________________
1692 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
1696 // Creates a TPC digit object
1698 fSector = digits[0];
1699 fPadRow = digits[1];
1702 fSignal = digits[4];
1708 //_____________________________________________________________________________
1709 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
1713 // Creates a TPC hit object