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.38 2001/07/20 14:32:43 kowal2
19 Processing of many events possible now
21 Revision 1.37 2001/06/12 07:17:18 kowal2
22 Hits2SDigits method implemented (summable digits)
24 Revision 1.36 2001/05/16 14:57:25 alibrary
25 New files for folders and Stack
27 Revision 1.35 2001/05/08 16:02:22 kowal2
28 Updated material specifications
30 Revision 1.34 2001/05/08 15:00:15 hristov
31 Corrections for tracking in arbitrary magnenetic field. Changes towards a concept of global Alice track. Back propagation of reconstructed tracks (Yu.Belikov)
33 Revision 1.33 2001/04/03 12:40:43 kowal2
36 Revision 1.32 2001/03/12 17:47:36 hristov
37 Changes needed on Sun with CC 5.0
39 Revision 1.31 2001/03/12 08:21:50 kowal2
40 Corrected C++ bug in the material definitions
42 Revision 1.30 2001/03/01 17:34:47 kowal2
43 Correction due to the accuracy problem
45 Revision 1.29 2001/02/28 16:34:40 kowal2
46 Protection against nonphysical values of the avalanche size,
49 Revision 1.28 2001/01/26 19:57:19 hristov
50 Major upgrade of AliRoot code
52 Revision 1.27 2001/01/13 17:29:33 kowal2
53 Sun compiler correction
55 Revision 1.26 2001/01/10 07:59:43 kowal2
56 Corrections to load points from the noncompressed hits.
58 Revision 1.25 2000/11/02 07:25:31 kowal2
59 Changes due to the new hit structure.
62 Revision 1.24 2000/10/05 16:06:09 kowal2
63 Forward declarations. Changes due to a new class AliComplexCluster.
65 Revision 1.23 2000/10/02 21:28:18 fca
66 Removal of useless dependecies via forward declarations
68 Revision 1.22 2000/07/10 20:57:39 hristov
69 Update of TPC code and macros by M.Kowalski
71 Revision 1.19.2.4 2000/06/26 07:39:42 kowal2
72 Changes to obey the coding rules
74 Revision 1.19.2.3 2000/06/25 08:38:41 kowal2
75 Splitted from AliTPCtracking
77 Revision 1.19.2.2 2000/06/16 12:59:28 kowal2
78 Changed parameter settings
80 Revision 1.19.2.1 2000/06/09 07:15:07 kowal2
82 Defaults loaded automatically (hard-wired)
83 Optional parameters can be set via macro called in the constructor
85 Revision 1.19 2000/04/18 19:00:59 fca
86 Small bug fixes to TPC files
88 Revision 1.18 2000/04/17 09:37:33 kowal2
89 removed obsolete AliTPCDigitsDisplay.C
91 Revision 1.17.2.2 2000/04/10 08:15:12 kowal2
93 New, experimental data structure from M. Ivanov
94 New tracking algorithm
95 Different pad geometry for different sectors
96 Digitization rewritten
98 Revision 1.17.2.1 2000/04/10 07:56:53 kowal2
99 Not used anymore - removed
101 Revision 1.17 2000/01/19 17:17:30 fca
102 Introducing a list of lists of hits -- more hits allowed for detector now
104 Revision 1.16 1999/11/05 09:29:23 fca
105 Accept only signals > 0
107 Revision 1.15 1999/10/08 06:26:53 fca
108 Removed ClustersIndex - not used anymore
110 Revision 1.14 1999/09/29 09:24:33 fca
111 Introduction of the Copyright and cvs Log
115 ///////////////////////////////////////////////////////////////////////////////
117 // Time Projection Chamber //
118 // This class contains the basic functions for the Time Projection Chamber //
119 // detector. Functions specific to one particular geometry are //
120 // contained in the derived classes //
124 <img src="picts/AliTPCClass.gif">
129 ///////////////////////////////////////////////////////////////////////////////
137 #include <TGeometry.h>
140 #include <TObjectTable.h>
141 #include "TParticle.h"
147 #include <iostream.h>
154 #include "AliTPCParamSR.h"
155 #include "AliTPCPRF2D.h"
156 #include "AliTPCRF1D.h"
157 #include "AliDigits.h"
158 #include "AliSimDigits.h"
159 #include "AliTPCTrackHits.h"
160 #include "AliPoints.h"
161 #include "AliArrayBranch.h"
164 #include "AliTPCDigitsArray.h"
165 #include "AliComplexCluster.h"
166 #include "AliClusters.h"
167 #include "AliTPCClustersRow.h"
168 #include "AliTPCClustersArray.h"
170 #include "AliTPCcluster.h"
171 #include "AliTPCclusterer.h"
172 #include "AliTPCtracker.h"
174 #include <TInterpreter.h>
181 //_____________________________________________________________________________
185 // Default constructor
200 //_____________________________________________________________________________
201 AliTPC::AliTPC(const char *name, const char *title)
202 : AliDetector(name,title)
205 // Standard constructor
209 // Initialise arrays of hits and digits
210 fHits = new TClonesArray("AliTPChit", 176);
211 gAlice->AddHitList(fHits);
217 fTrackHits = new AliTPCTrackHits; //MI - 13.09.2000
218 fTrackHits->SetHitPrecision(0.002);
219 fTrackHits->SetStepPrecision(0.003);
220 fTrackHits->SetMaxDistance(100);
224 // Initialise counters
230 // Initialise color attributes
231 SetMarkerColor(kYellow);
234 // Set TPC parameters
238 if (!strcmp(title,"Default")) {
239 fTPCParam = new AliTPCParamSR;
241 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
247 //_____________________________________________________________________________
258 delete fTrackHits; //MI 15.09.2000
261 //_____________________________________________________________________________
262 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
265 // Add a hit to the list
267 // TClonesArray &lhits = *fHits;
268 // new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
270 TClonesArray &lhits = *fHits;
271 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
274 AddHit2(track,vol,hits);
277 //_____________________________________________________________________________
278 void AliTPC::BuildGeometry()
282 // Build TPC ROOT TNode geometry for the event display
287 const int kColorTPC=19;
288 char name[5], title[25];
289 const Double_t kDegrad=TMath::Pi()/180;
290 const Double_t kRaddeg=180./TMath::Pi();
293 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
294 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
296 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
297 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
299 Int_t nLo = fTPCParam->GetNInnerSector()/2;
300 Int_t nHi = fTPCParam->GetNOuterSector()/2;
302 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
303 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
304 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
305 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
308 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
309 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
315 // Get ALICE top node
318 nTop=gAlice->GetGeometry()->GetNode("alice");
322 rl = fTPCParam->GetInnerRadiusLow();
323 ru = fTPCParam->GetInnerRadiusUp();
327 sprintf(name,"LS%2.2d",i);
329 sprintf(title,"TPC low sector %3d",i);
332 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
333 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
334 tubs->SetNumberOfDivisions(1);
336 nNode = new TNode(name,title,name,0,0,0,"");
337 nNode->SetLineColor(kColorTPC);
343 rl = fTPCParam->GetOuterRadiusLow();
344 ru = fTPCParam->GetOuterRadiusUp();
347 sprintf(name,"US%2.2d",i);
349 sprintf(title,"TPC upper sector %d",i);
351 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
352 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
353 tubs->SetNumberOfDivisions(1);
355 nNode = new TNode(name,title,name,0,0,0,"");
356 nNode->SetLineColor(kColorTPC);
362 //_____________________________________________________________________________
363 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
366 // Calculate distance from TPC to mouse on the display
372 void AliTPC::Clusters2Tracks(TFile *of) {
373 //-----------------------------------------------------------------
374 // This is a track finder.
375 //-----------------------------------------------------------------
376 AliTPCtracker tracker(fTPCParam);
377 tracker.Clusters2Tracks(gFile,of);
380 //_____________________________________________________________________________
381 void AliTPC::CreateMaterials()
383 //-----------------------------------------------
384 // Create Materials for for TPC simulations
385 //-----------------------------------------------
387 //-----------------------------------------------------------------
388 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
389 //-----------------------------------------------------------------
391 Int_t iSXFLD=gAlice->Field()->Integ();
392 Float_t sXMGMX=gAlice->Field()->Max();
394 Float_t amat[5]; // atomic numbers
395 Float_t zmat[5]; // z
396 Float_t wmat[5]; // proportions
402 //***************** Gases *************************
404 //-------------------------------------------------
406 //-------------------------------------------------
417 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
427 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
430 //--------------------------------------------------------------
432 //--------------------------------------------------------------
449 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
451 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
466 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
468 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
484 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
486 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
488 //----------------------------------------------------------------
489 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
490 //----------------------------------------------------------------
496 Float_t rho,absl,X0,buf[1];
500 for(nc = 0;nc<fNoComp;nc++)
503 // retrive material constants
505 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,X0,absl,buf,nbuf);
510 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
512 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
513 density += fMixtProp[nc]*rho; // density of the mixture
517 // mixture proportions by weight!
519 for(nc = 0;nc<fNoComp;nc++)
522 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
524 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
525 apure[nnc] : amol[nnc])/am;
529 // Drift gases 1 - nonsensitive, 2 - sensitive
531 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
532 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
541 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
544 //----------------------------------------------------------------------
546 //----------------------------------------------------------------------
568 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
590 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
608 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
626 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
628 // SiO2 - used later for the glass fiber
640 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
649 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
658 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
667 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
685 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
704 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
706 // Epoxy - C14 H20 O3
723 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
731 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
735 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,X0,absl,buf,nbuf);
739 wmat[0]=0.644; // by weight!
742 density=0.5*(1.25+2.265);
744 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
748 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,X0,absl,buf,nbuf);
750 wmat[0]=0.725; // by weight!
755 AliMixture(39,"G10",amat,zmat,density,2,wmat);
760 //----------------------------------------------------------
761 // tracking media for gases
762 //----------------------------------------------------------
764 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
765 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
766 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
767 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
769 //-----------------------------------------------------------
770 // tracking media for solids
771 //-----------------------------------------------------------
773 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
774 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
775 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
776 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
777 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
778 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
779 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
780 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
781 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
782 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
783 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
784 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
789 void AliTPC::Digits2Clusters(TFile *of, Int_t eventnumber)
791 //-----------------------------------------------------------------
792 // This is a simple cluster finder.
793 //-----------------------------------------------------------------
794 AliTPCclusterer::Digits2Clusters(fTPCParam,of,eventnumber);
797 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
798 extern Double_t SigmaZ2(Double_t, Double_t);
799 //_____________________________________________________________________________
800 void AliTPC::Hits2Clusters(TFile *of, Int_t eventn)
802 //--------------------------------------------------------
803 // TPC simple cluster generator from hits
804 // obtained from the TPC Fast Simulator
805 // The point errors are taken from the parametrization
806 //--------------------------------------------------------
808 //-----------------------------------------------------------------
809 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
810 //-----------------------------------------------------------------
811 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
812 // Jouri.Belikov@cern.ch
813 //----------------------------------------------------------------
815 /////////////////////////////////////////////////////////////////////////////
817 //---------------------------------------------------------------------
818 // ALICE TPC Cluster Parameters
819 //--------------------------------------------------------------------
823 // Cluster width in rphi
824 const Float_t kACrphi=0.18322;
825 const Float_t kBCrphi=0.59551e-3;
826 const Float_t kCCrphi=0.60952e-1;
827 // Cluster width in z
828 const Float_t kACz=0.19081;
829 const Float_t kBCz=0.55938e-3;
830 const Float_t kCCz=0.30428;
832 TDirectory *savedir=gDirectory;
835 cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
839 //if(fDefaults == 0) SetDefaults();
841 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
843 TParticle *particle; // pointer to a given particle
844 AliTPChit *tpcHit; // pointer to a sigle TPC hit
848 Float_t pl,pt,tanth,rpad,ratio;
851 //---------------------------------------------------------------
852 // Get the access to the tracks
853 //---------------------------------------------------------------
855 TTree *tH = gAlice->TreeH();
856 Stat_t ntracks = tH->GetEntries();
858 //Switch to the output file
863 sprintf(cname,"TreeC_TPC_%d",eventn);
865 fTPCParam->Write(fTPCParam->GetTitle());
866 AliTPCClustersArray carray;
867 carray.Setup(fTPCParam);
868 carray.SetClusterType("AliTPCcluster");
871 Int_t nclusters=0; //cluster counter
873 //------------------------------------------------------------
874 // Loop over all sectors (72 sectors for 20 deg
875 // segmentation for both lower and upper sectors)
876 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
877 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
879 // First cluster for sector 0 starts at "0"
880 //------------------------------------------------------------
882 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
884 fTPCParam->AdjustCosSin(isec,cph,sph);
886 //------------------------------------------------------------
888 //------------------------------------------------------------
890 for(Int_t track=0;track<ntracks;track++){
894 // Get number of the TPC hits
896 // nhits=fHits->GetEntriesFast();
899 tpcHit = (AliTPChit*)FirstHit(-1);
903 // for(Int_t hit=0;hit<nhits;hit++){
904 //tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
908 if (tpcHit->fQ == 0.) {
909 tpcHit = (AliTPChit*) NextHit();
910 continue; //information about track (I.Belikov)
912 sector=tpcHit->fSector; // sector number
915 // if(sector != isec) continue; //terminate iteration
918 tpcHit = (AliTPChit*) NextHit();
921 ipart=tpcHit->Track();
922 particle=gAlice->Particle(ipart);
925 if(pt < 1.e-9) pt=1.e-9;
927 tanth = TMath::Abs(tanth);
928 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
929 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
931 // space-point resolutions
933 sigmaRphi=SigmaY2(rpad,tanth,pt);
934 sigmaZ =SigmaZ2(rpad,tanth );
938 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
939 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
941 // temporary protection
943 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
944 if(sigmaZ < 0.) sigmaZ=0.4e-3;
945 if(clRphi < 0.) clRphi=2.5e-3;
946 if(clZ < 0.) clZ=2.5e-5;
951 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
952 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
954 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
955 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
956 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
957 Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
958 fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
959 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
960 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
961 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
962 if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->Z();
963 xyz[2]=sigmaRphi; // fSigmaY2
964 xyz[3]=sigmaZ; // fSigmaZ2
965 xyz[4]=tpcHit->fQ; // q
967 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
968 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
970 Int_t tracks[3]={tpcHit->Track(), -1, -1};
971 AliTPCcluster cluster(tracks,xyz);
973 clrow->InsertCluster(&cluster); nclusters++;
975 tpcHit = (AliTPChit*)NextHit();
978 } // end of loop over hits
980 } // end of loop over tracks
982 Int_t nrows=fTPCParam->GetNRow(isec);
983 for (Int_t irow=0; irow<nrows; irow++) {
984 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
985 if (!clrow) continue;
986 carray.StoreRow(isec,irow);
987 carray.ClearRow(isec,irow);
990 } // end of loop over sectors
992 cerr<<"Number of made clusters : "<<nclusters<<" \n";
994 carray.GetTree()->Write(cname);
996 savedir->cd(); //switch back to the input file
1000 //_________________________________________________________________
1001 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1003 //--------------------------------------------------------
1004 //calculate exact cross point of track and given pad row
1005 //resulting values are expressed in "digit" coordinata
1006 //--------------------------------------------------------
1008 //-----------------------------------------------------------------
1009 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1010 //-----------------------------------------------------------------
1012 if (fClustersArray==0){
1016 TParticle *particle; // pointer to a given particle
1017 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1020 const Int_t kcmaxhits=30000;
1021 TVector * xxxx = new TVector(kcmaxhits*4);
1022 TVector & xxx = *xxxx;
1023 Int_t maxhits = kcmaxhits;
1024 //construct array for each padrow
1025 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
1026 fClustersArray->CreateRow(isec,i);
1028 //---------------------------------------------------------------
1029 // Get the access to the tracks
1030 //---------------------------------------------------------------
1032 TTree *tH = gAlice->TreeH();
1033 Stat_t ntracks = tH->GetEntries();
1034 Int_t npart = gAlice->GetNtrack();
1036 //------------------------------------------------------------
1038 //------------------------------------------------------------
1040 for(Int_t track=0;track<ntracks;track++){
1042 tH->GetEvent(track);
1044 // Get number of the TPC hits and a pointer
1047 nhits=fHits->GetEntriesFast();
1051 Int_t currentIndex=0;
1052 Int_t lastrow=-1; //last writen row
1053 for(Int_t hit=0;hit<nhits;hit++){
1054 tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
1055 if (tpcHit==0) continue;
1056 sector=tpcHit->fSector; // sector number
1057 if(sector != isec) continue;
1058 ipart=tpcHit->Track();
1059 if (ipart<npart) particle=gAlice->Particle(ipart);
1063 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
1064 Int_t index[3]={1,isec,0};
1065 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
1066 if (currentrow<0) continue;
1067 if (lastrow<0) lastrow=currentrow;
1068 if (currentrow==lastrow){
1069 if ( currentIndex>=maxhits){
1071 xxx.ResizeTo(4*maxhits);
1073 xxx(currentIndex*4)=x[0];
1074 xxx(currentIndex*4+1)=x[1];
1075 xxx(currentIndex*4+2)=x[2];
1076 xxx(currentIndex*4+3)=tpcHit->fQ;
1080 if (currentIndex>2){
1092 for (Int_t index=0;index<currentIndex;index++){
1094 x=x2=x3=x4=xxx(index*4);
1102 sumy+=xxx(index*4+1);
1103 sumxy+=xxx(index*4+1)*x;
1104 sumx2y+=xxx(index*4+1)*x2;
1105 sumz+=xxx(index*4+2);
1106 sumxz+=xxx(index*4+2)*x;
1107 sumx2z+=xxx(index*4+2)*x2;
1108 sumq+=xxx(index*4+3);
1110 Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1111 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1112 sumx2*(sumx*sumx3-sumx2*sumx2);
1114 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1115 sumx2*(sumxy*sumx3-sumx2y*sumx2);
1116 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1117 sumx2*(sumxz*sumx3-sumx2z*sumx2);
1119 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1120 sumx2*(sumx*sumx2y-sumx2*sumxy);
1121 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1122 sumx2*(sumx*sumx2z-sumx2*sumxz);
1124 Float_t y=detay/det+centralPad;
1125 Float_t z=detaz/det;
1126 Float_t by=detby/det; //y angle
1127 Float_t bz=detbz/det; //z angle
1128 sumy/=Float_t(currentIndex);
1129 sumz/=Float_t(currentIndex);
1130 AliComplexCluster cl;
1136 cl.fTracks[0]=ipart;
1138 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1139 if (row!=0) row->InsertCluster(&cl);
1142 } //end of calculating cluster for given row
1146 } // end of loop over hits
1147 } // end of loop over tracks
1148 //write padrows to tree
1149 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1150 fClustersArray->StoreRow(isec,ii);
1151 fClustersArray->ClearRow(isec,ii);
1156 //___________________________________________
1157 void AliTPC::SDigits2Digits(Int_t eventnumber)
1161 cerr<<"Digitizing TPC...\n";
1163 Hits2Digits(eventnumber);
1168 // char treeName[100];
1170 // sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1172 // GetDigitsArray()->GetTree()->Write(treeName);
1174 //__________________________________________________________________
1175 void AliTPC::SetDefaults(){
1178 cerr<<"Setting default parameters...\n";
1180 // Set response functions
1182 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1183 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1184 AliTPCPRF2D * prfouter = new AliTPCPRF2D;
1185 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1186 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1187 rf->SetOffset(3*param->GetZSigma());
1190 TDirectory *savedir=gDirectory;
1191 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1193 cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1196 prfinner->Read("prf_07504_Gati_056068_d02");
1197 prfouter->Read("prf_10006_Gati_047051_d03");
1201 param->SetInnerPRF(prfinner);
1202 param->SetOuterPRF(prfouter);
1203 param->SetTimeRF(rf);
1213 //__________________________________________________________________
1214 void AliTPC::Hits2Digits(Int_t eventnumber)
1216 //----------------------------------------------------
1217 // Loop over all sectors for a single event
1218 //----------------------------------------------------
1221 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1223 //setup TPCDigitsArray
1225 if(GetDigitsArray()) delete GetDigitsArray();
1227 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1228 arr->SetClass("AliSimDigits");
1229 arr->Setup(fTPCParam);
1230 arr->MakeTree(fDigitsFile);
1231 SetDigitsArray(arr);
1233 fDigitsSwitch=0; // standard digits
1235 cerr<<"Digitizing TPC...\n";
1237 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
1243 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1245 GetDigitsArray()->GetTree()->Write(treeName);
1252 //__________________________________________________________________
1253 void AliTPC::Hits2SDigits(Int_t eventnumber)
1256 //-----------------------------------------------------------
1257 // summable digits - 16 bit "ADC", no noise, no saturation
1258 //-----------------------------------------------------------
1260 //----------------------------------------------------
1261 // Loop over all sectors for a single event
1262 //----------------------------------------------------
1265 if(fDefaults == 0) SetDefaults();
1267 //setup TPCDigitsArray
1269 if(GetDigitsArray()) delete GetDigitsArray();
1271 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1272 arr->SetClass("AliSimDigits");
1273 arr->Setup(fTPCParam);
1274 arr->MakeTree(fDigitsFile);
1275 SetDigitsArray(arr);
1277 cerr<<"Digitizing TPC...\n";
1279 fDigitsSwitch=1; // summable digits
1281 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
1288 sprintf(treeName,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1290 GetDigitsArray()->GetTree()->Write(treeName);
1296 //_____________________________________________________________________________
1297 void AliTPC::Hits2DigitsSector(Int_t isec)
1299 //-------------------------------------------------------------------
1300 // TPC conversion from hits to digits.
1301 //-------------------------------------------------------------------
1303 //-----------------------------------------------------------------
1304 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1305 //-----------------------------------------------------------------
1307 //-------------------------------------------------------
1308 // Get the access to the track hits
1309 //-------------------------------------------------------
1311 // check if the parameters are set - important if one calls this method
1312 // directly, not from the Hits2Digits
1314 if(fDefaults == 0) SetDefaults();
1316 TTree *tH = gAlice->TreeH(); // pointer to the hits tree
1317 Stat_t ntracks = tH->GetEntries();
1321 //-------------------------------------------
1322 // Only if there are any tracks...
1323 //-------------------------------------------
1327 //printf("*** Processing sector number %d ***\n",isec);
1329 Int_t nrows =fTPCParam->GetNRow(isec);
1331 row= new TObjArray* [nrows];
1333 MakeSector(isec,nrows,tH,ntracks,row);
1335 //--------------------------------------------------------
1336 // Digitize this sector, row by row
1337 // row[i] is the pointer to the TObjArray of TVectors,
1338 // each one containing electrons accepted on this
1339 // row, assigned into tracks
1340 //--------------------------------------------------------
1344 if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree(fDigitsFile);
1346 for (i=0;i<nrows;i++){
1348 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1350 DigitizeRow(i,isec,row);
1352 fDigitsArray->StoreRow(isec,i);
1354 Int_t ndig = dig->GetDigitSize();
1357 //printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1359 fDigitsArray->ClearRow(isec,i);
1362 } // end of the sector digitization
1364 for(i=0;i<nrows;i++){
1369 delete [] row; // delete the array of pointers to TObjArray-s
1373 } // end of Hits2DigitsSector
1376 //_____________________________________________________________________________
1377 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1379 //-----------------------------------------------------------
1380 // Single row digitization, coupling from the neighbouring
1381 // rows taken into account
1382 //-----------------------------------------------------------
1384 //-----------------------------------------------------------------
1385 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1386 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1387 //-----------------------------------------------------------------
1390 Float_t zerosup = fTPCParam->GetZeroSup();
1391 Int_t nrows =fTPCParam->GetNRow(isec);
1392 fCurrentIndex[1]= isec;
1395 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1396 Int_t nofTbins = fTPCParam->GetMaxTBin();
1397 Int_t indexRange[4];
1399 // Integrated signal for this row
1400 // and a single track signal
1402 TMatrix *m1 = new TMatrix(0,nofPads,0,nofTbins); // integrated
1403 TMatrix *m2 = new TMatrix(0,nofPads,0,nofTbins); // single
1405 TMatrix &total = *m1;
1407 // Array of pointers to the label-signal list
1409 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1410 Float_t **pList = new Float_t* [nofDigits];
1414 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1418 Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1419 Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1420 for (Int_t row= row1;row<=row2;row++){
1421 Int_t nTracks= rows[row]->GetEntries();
1422 for (i1=0;i1<nTracks;i1++){
1423 fCurrentIndex[2]= row;
1424 fCurrentIndex[3]=irow;
1426 m2->Zero(); // clear single track signal matrix
1427 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1428 GetList(trackLabel,nofPads,m2,indexRange,pList);
1430 else GetSignal(rows[row],i1,0,m1,indexRange);
1436 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1437 for(Int_t ip=0;ip<nofPads;ip++){
1438 for(Int_t it=0;it<nofTbins;it++){
1440 Float_t q = total(ip,it);
1442 Int_t gi =it*nofPads+ip; // global index
1444 if(fDigitsSwitch == 0){
1446 q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
1450 if(q <=zerosup) continue; // do not fill zeros
1451 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1461 // "real" signal or electronic noise (list = -1)?
1464 for(Int_t j1=0;j1<3;j1++){
1465 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -1;
1470 <A NAME="AliDigits"></A>
1471 using of AliDigits object
1474 dig->SetDigitFast((Short_t)q,it,ip);
1475 if (fDigitsArray->IsSimulated())
1477 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1478 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1479 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1483 } // end of loop over time buckets
1484 } // end of lop over pads
1487 // This row has been digitized, delete nonused stuff
1490 for(lp=0;lp<nofDigits;lp++){
1491 if(pList[lp]) delete [] pList[lp];
1500 } // end of DigitizeRow
1502 //_____________________________________________________________________________
1504 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr, TMatrix *m1, TMatrix *m2,
1508 //---------------------------------------------------------------
1509 // Calculates 2-D signal (pad,time) for a single track,
1510 // returns a pointer to the signal matrix and the track label
1511 // No digitization is performed at this level!!!
1512 //---------------------------------------------------------------
1514 //-----------------------------------------------------------------
1515 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1516 // Modified: Marian Ivanov
1517 //-----------------------------------------------------------------
1521 tv = (TVector*)p1->At(ntr); // pointer to a track
1524 Float_t label = v(0);
1525 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
1527 Int_t nElectrons = (tv->GetNrows()-1)/4;
1528 indexRange[0]=9999; // min pad
1529 indexRange[1]=-1; // max pad
1530 indexRange[2]=9999; //min time
1531 indexRange[3]=-1; // max time
1533 // Float_t IneffFactor = 0.5; // inefficiency in the gain close to the edge, as above
1535 TMatrix &signal = *m1;
1536 TMatrix &total = *m2;
1538 // Loop over all electrons
1540 for(Int_t nel=0; nel<nElectrons; nel++){
1542 Float_t aval = v(idx+4);
1543 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1544 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1545 Int_t n = fTPCParam->CalcResponse(xyz,fCurrentIndex,fCurrentIndex[3]);
1547 if (n>0) for (Int_t i =0; i<n; i++){
1548 Int_t *index = fTPCParam->GetResBin(i);
1549 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1550 if ( ( pad<(fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]))) && (pad>0)) {
1551 Int_t time=index[2];
1552 Float_t weight = fTPCParam->GetResWeight(i); //we normalise response to ADC channel
1553 weight *= eltoadcfac;
1555 if (m1!=0) signal(pad,time)+=weight;
1556 total(pad,time)+=weight;
1557 indexRange[0]=TMath::Min(indexRange[0],pad);
1558 indexRange[1]=TMath::Max(indexRange[1],pad);
1559 indexRange[2]=TMath::Min(indexRange[2],time);
1560 indexRange[3]=TMath::Max(indexRange[3],time);
1563 } // end of loop over electrons
1565 return label; // returns track label when finished
1568 //_____________________________________________________________________________
1569 void AliTPC::GetList(Float_t label,Int_t np,TMatrix *m,Int_t *indexRange,
1572 //----------------------------------------------------------------------
1573 // Updates the list of tracks contributing to digits for a given row
1574 //----------------------------------------------------------------------
1576 //-----------------------------------------------------------------
1577 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1578 //-----------------------------------------------------------------
1580 TMatrix &signal = *m;
1582 // lop over nonzero digits
1584 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1585 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1588 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1590 if(signal(ip,it)<0.5) continue;
1593 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1595 if(!pList[globalIndex]){
1598 // Create new list (6 elements - 3 signals and 3 labels),
1601 pList[globalIndex] = new Float_t [6];
1605 *pList[globalIndex] = -1.;
1606 *(pList[globalIndex]+1) = -1.;
1607 *(pList[globalIndex]+2) = -1.;
1608 *(pList[globalIndex]+3) = -1.;
1609 *(pList[globalIndex]+4) = -1.;
1610 *(pList[globalIndex]+5) = -1.;
1613 *pList[globalIndex] = label;
1614 *(pList[globalIndex]+3) = signal(ip,it);
1618 // check the signal magnitude
1620 Float_t highest = *(pList[globalIndex]+3);
1621 Float_t middle = *(pList[globalIndex]+4);
1622 Float_t lowest = *(pList[globalIndex]+5);
1625 // compare the new signal with already existing list
1628 if(signal(ip,it)<lowest) continue; // neglect this track
1632 if (signal(ip,it)>highest){
1633 *(pList[globalIndex]+5) = middle;
1634 *(pList[globalIndex]+4) = highest;
1635 *(pList[globalIndex]+3) = signal(ip,it);
1637 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1638 *(pList[globalIndex]+1) = *pList[globalIndex];
1639 *pList[globalIndex] = label;
1641 else if (signal(ip,it)>middle){
1642 *(pList[globalIndex]+5) = middle;
1643 *(pList[globalIndex]+4) = signal(ip,it);
1645 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1646 *(pList[globalIndex]+1) = label;
1649 *(pList[globalIndex]+5) = signal(ip,it);
1650 *(pList[globalIndex]+2) = label;
1654 } // end of loop over pads
1655 } // end of loop over time bins
1660 //___________________________________________________________________
1661 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1662 Stat_t ntracks,TObjArray **row)
1665 //-----------------------------------------------------------------
1666 // Prepares the sector digitization, creates the vectors of
1667 // tracks for each row of this sector. The track vector
1668 // contains the track label and the position of electrons.
1669 //-----------------------------------------------------------------
1671 //-----------------------------------------------------------------
1672 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1673 //-----------------------------------------------------------------
1675 Float_t gasgain = fTPCParam->GetGasGain();
1679 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1682 if (fHitType&2) branch = TH->GetBranch("TPC2");
1683 else branch = TH->GetBranch("TPC");
1686 //----------------------------------------------
1687 // Create TObjArray-s, one for each row,
1688 // each TObjArray will store the TVectors
1689 // of electrons, one TVector per each track.
1690 //----------------------------------------------
1692 Int_t *nofElectrons = new Int_t [nrows]; // electron counter for each row
1693 TVector **tracks = new TVector* [nrows]; //pointers to the track vectors
1694 for(i=0; i<nrows; i++){
1695 row[i] = new TObjArray;
1702 //--------------------------------------------------------------------
1703 // Loop over tracks, the "track" contains the full history
1704 //--------------------------------------------------------------------
1706 Int_t previousTrack,currentTrack;
1707 previousTrack = -1; // nothing to store so far!
1709 for(Int_t track=0;track<ntracks;track++){
1710 Bool_t isInSector=kTRUE;
1715 TBranch * br = TH->GetBranch("fTrackHitsInfo");
1716 br->GetEvent(track);
1717 AliObjectArray * ar = fTrackHits->fTrackHitsInfo;
1718 for (UInt_t j=0;j<ar->GetSize();j++){
1719 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==isec) isInSector=kTRUE;
1722 if (!isInSector) continue;
1724 branch->GetEntry(track); // get next track
1728 tpcHit = (AliTPChit*)FirstHit(-1);
1730 //--------------------------------------------------------------
1732 //--------------------------------------------------------------
1737 Int_t sector=tpcHit->fSector; // sector number
1738 // if(sector != isec) continue;
1740 tpcHit = (AliTPChit*) NextHit();
1744 currentTrack = tpcHit->Track(); // track number
1747 if(currentTrack != previousTrack){
1749 // store already filled fTrack
1751 for(i=0;i<nrows;i++){
1752 if(previousTrack != -1){
1753 if(nofElectrons[i]>0){
1754 TVector &v = *tracks[i];
1755 v(0) = previousTrack;
1756 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1757 row[i]->Add(tracks[i]);
1760 delete tracks[i]; // delete empty TVector
1766 tracks[i] = new TVector(481); // TVectors for the next fTrack
1768 } // end of loop over rows
1770 previousTrack=currentTrack; // update track label
1773 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1775 //---------------------------------------------------
1776 // Calculate the electron attachment probability
1777 //---------------------------------------------------
1780 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
1781 /fTPCParam->GetDriftV();
1783 Float_t attProb = fTPCParam->GetAttCoef()*
1784 fTPCParam->GetOxyCont()*time; // fraction!
1786 //-----------------------------------------------
1787 // Loop over electrons
1788 //-----------------------------------------------
1791 for(Int_t nel=0;nel<qI;nel++){
1792 // skip if electron lost due to the attachment
1793 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1798 // protection for the nonphysical avalanche size (10**6 maximum)
1800 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1801 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
1804 TransportElectron(xyz,index); //MI change -august
1806 fTPCParam->GetPadRow(xyz,index); //MI change august
1807 rowNumber = index[2];
1808 //transform position to local digit coordinates
1809 //relative to nearest pad row
1810 if ((rowNumber<0)||rowNumber>=fTPCParam->GetNRow(isec)) continue;
1811 nofElectrons[rowNumber]++;
1812 //----------------------------------
1813 // Expand vector if necessary
1814 //----------------------------------
1815 if(nofElectrons[rowNumber]>120){
1816 Int_t range = tracks[rowNumber]->GetNrows();
1817 if((nofElectrons[rowNumber])>(range-1)/4){
1819 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
1823 TVector &v = *tracks[rowNumber];
1824 Int_t idx = 4*nofElectrons[rowNumber]-3;
1826 v(idx)= xyz[0]; // X - pad row coordinate
1827 v(idx+1)=xyz[1]; // Y - pad coordinate (along the pad-row)
1828 v(idx+2)=xyz[2]; // Z - time bin coordinate
1829 v(idx+3)=xyz[3]; // avalanche size
1830 } // end of loop over electrons
1832 tpcHit = (AliTPChit*)NextHit();
1834 } // end of loop over hits
1835 } // end of loop over tracks
1838 // store remaining track (the last one) if not empty
1841 for(i=0;i<nrows;i++){
1842 if(nofElectrons[i]>0){
1843 TVector &v = *tracks[i];
1844 v(0) = previousTrack;
1845 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1846 row[i]->Add(tracks[i]);
1855 delete [] nofElectrons;
1858 } // end of MakeSector
1861 //_____________________________________________________________________________
1865 // Initialise TPC detector after definition of geometry
1870 printf("\n%s: ",ClassName());
1871 for(i=0;i<35;i++) printf("*");
1872 printf(" TPC_INIT ");
1873 for(i=0;i<35;i++) printf("*");
1874 printf("\n%s: ",ClassName());
1876 for(i=0;i<80;i++) printf("*");
1881 //_____________________________________________________________________________
1882 void AliTPC::MakeBranch(Option_t* option, const char *file)
1885 // Create Tree branches for the TPC.
1887 Int_t buffersize = 4000;
1888 char branchname[10];
1889 sprintf(branchname,"%s",GetName());
1891 AliDetector::MakeBranch(option,file);
1893 const char *d = strstr(option,"D");
1895 if (fDigits && gAlice->TreeD() && d) {
1896 MakeBranchInTree(gAlice->TreeD(),
1897 branchname, &fDigits, buffersize, file);
1900 if (fHitType&2) MakeBranch2(option,file); // MI change 14.09.2000
1903 //_____________________________________________________________________________
1904 void AliTPC::ResetDigits()
1907 // Reset number of digits and the digits array for this detector
1910 if (fDigits) fDigits->Clear();
1913 //_____________________________________________________________________________
1914 void AliTPC::SetSecAL(Int_t sec)
1916 //---------------------------------------------------
1917 // Activate/deactivate selection for lower sectors
1918 //---------------------------------------------------
1920 //-----------------------------------------------------------------
1921 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1922 //-----------------------------------------------------------------
1927 //_____________________________________________________________________________
1928 void AliTPC::SetSecAU(Int_t sec)
1930 //----------------------------------------------------
1931 // Activate/deactivate selection for upper sectors
1932 //---------------------------------------------------
1934 //-----------------------------------------------------------------
1935 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1936 //-----------------------------------------------------------------
1941 //_____________________________________________________________________________
1942 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
1944 //----------------------------------------
1945 // Select active lower sectors
1946 //----------------------------------------
1948 //-----------------------------------------------------------------
1949 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1950 //-----------------------------------------------------------------
1960 //_____________________________________________________________________________
1961 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
1962 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
1963 Int_t s11 , Int_t s12)
1965 //--------------------------------
1966 // Select active upper sectors
1967 //--------------------------------
1969 //-----------------------------------------------------------------
1970 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1971 //-----------------------------------------------------------------
1987 //_____________________________________________________________________________
1988 void AliTPC::SetSens(Int_t sens)
1991 //-------------------------------------------------------------
1992 // Activates/deactivates the sensitive strips at the center of
1993 // the pad row -- this is for the space-point resolution calculations
1994 //-------------------------------------------------------------
1996 //-----------------------------------------------------------------
1997 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1998 //-----------------------------------------------------------------
2004 void AliTPC::SetSide(Float_t side=0.)
2006 // choice of the TPC side
2011 //____________________________________________________________________________
2012 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2013 Float_t p2,Float_t p3)
2016 // gax mixture definition
2030 //_____________________________________________________________________________
2032 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2035 // electron transport taking into account:
2037 // 2.ExB at the wires
2038 // 3. nonisochronity
2040 // xyz and index must be already transformed to system 1
2043 fTPCParam->Transform1to2(xyz,index);
2046 Float_t driftl=xyz[2];
2047 if(driftl<0.01) driftl=0.01;
2048 driftl=TMath::Sqrt(driftl);
2049 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2050 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2051 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2052 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2053 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2057 if (fTPCParam->GetMWPCReadout()==kTRUE){
2059 fTPCParam->Transform2to2NearestWire(xyz,index);
2060 Float_t dx=xyz[0]-x1;
2061 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2063 //add nonisochronity (not implemented yet)
2067 ClassImp(AliTPCdigit)
2069 //_____________________________________________________________________________
2070 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2074 // Creates a TPC digit object
2076 fSector = digits[0];
2077 fPadRow = digits[1];
2080 fSignal = digits[4];
2086 //_____________________________________________________________________________
2087 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2091 // Creates a TPC hit object
2102 //________________________________________________________________________
2103 // Additional code because of the AliTPCTrackHits
2105 void AliTPC::MakeBranch2(Option_t *option,const char *file)
2108 // Create a new branch in the current Root Tree
2109 // The branch of fHits is automatically split
2110 // MI change 14.09.2000
2111 if (fHitType&2==0) return;
2112 char branchname[10];
2113 sprintf(branchname,"%s2",GetName());
2115 // Get the pointer to the header
2116 const char *cH = strstr(option,"H");
2118 if (fTrackHits && gAlice->TreeH() && cH) {
2119 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHits,
2120 gAlice->TreeH(),fBufferSize,1);
2121 gAlice->TreeH()->GetListOfBranches()->Add(branch);
2123 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2124 const char folder [] = "RunMC/Event/Data";
2126 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2127 Publish(folder,&fTrackHits,branchname);
2129 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2130 TDirectory *wd = gDirectory;
2132 TIter next( b->GetListOfBranches());
2133 while ((b=(TBranch*)next())) {
2138 cout << "Diverting branch " << branchname << " to file " << file << endl;
2143 void AliTPC::SetTreeAddress()
2145 if (fHitType&1) AliDetector::SetTreeAddress();
2146 if (fHitType&2) SetTreeAddress2();
2149 void AliTPC::SetTreeAddress2()
2152 // Set branch address for the TrackHits Tree
2155 char branchname[20];
2156 sprintf(branchname,"%s2",GetName());
2158 // Branch address for hit tree
2159 TTree *treeH = gAlice->TreeH();
2161 branch = treeH->GetBranch(branchname);
2162 if (branch) branch->SetAddress(&fTrackHits);
2166 void AliTPC::FinishPrimary()
2168 if (fTrackHits) fTrackHits->FlushHitStack();
2172 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2175 // add hit to the list
2178 int primary = gAlice->GetPrimary(track);
2179 gAlice->Particle(primary)->SetBit(kKeepBit);
2183 gAlice->FlagTrack(track);
2185 //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2186 //if (hit->fTrack!=rtrack)
2187 // cout<<"bad track number\n";
2189 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2190 hits[1],hits[2],(Int_t)hits[3]);
2193 void AliTPC::ResetHits()
2195 if (fHitType&1) AliDetector::ResetHits();
2196 if (fHitType&2) ResetHits2();
2199 void AliTPC::ResetHits2()
2203 if (fTrackHits) fTrackHits->Clear();
2206 AliHit* AliTPC::FirstHit(Int_t track)
2208 if (fHitType&2) return FirstHit2(track);
2209 return AliDetector::FirstHit(track);
2211 AliHit* AliTPC::NextHit()
2213 if (fHitType&2) return NextHit2();
2214 return AliDetector::NextHit();
2217 AliHit* AliTPC::FirstHit2(Int_t track)
2220 // Initialise the hit iterator
2221 // Return the address of the first hit for track
2222 // If track>=0 the track is read from disk
2223 // while if track<0 the first hit of the current
2224 // track is returned
2227 gAlice->ResetHits();
2228 gAlice->TreeH()->GetEvent(track);
2232 fTrackHits->First();
2233 return fTrackHits->GetHit();
2238 AliHit* AliTPC::NextHit2()
2241 //Return the next hit for the current track
2245 return fTrackHits->GetHit();
2251 void AliTPC::LoadPoints(Int_t)
2255 /* if(fHitType==1) return AliDetector::LoadPoints(a);
2258 if(fHitType==1) AliDetector::LoadPoints(a);
2259 else LoadPoints2(a);
2266 void AliTPC::RemapTrackHitIDs(Int_t *map)
2268 if (!fTrackHits) return;
2269 AliObjectArray * arr = fTrackHits->fTrackHitsInfo;
2270 for (UInt_t i=0;i<arr->GetSize();i++){
2271 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2272 info->fTrackID = map[info->fTrackID];
2278 //_____________________________________________________________________________
2279 void AliTPC::LoadPoints2(Int_t)
2282 // Store x, y, z of all hits in memory
2284 if (fTrackHits == 0) return;
2286 Int_t nhits = fTrackHits->GetEntriesFast();
2287 if (nhits == 0) return;
2288 Int_t tracks = gAlice->GetNtrack();
2289 if (fPoints == 0) fPoints = new TObjArray(tracks);
2292 Int_t *ntrk=new Int_t[tracks];
2293 Int_t *limi=new Int_t[tracks];
2294 Float_t **coor=new Float_t*[tracks];
2295 for(Int_t i=0;i<tracks;i++) {
2301 AliPoints *points = 0;
2304 Int_t chunk=nhits/4+1;
2306 // Loop over all the hits and store their position
2308 ahit = FirstHit2(-1);
2309 //for (Int_t hit=0;hit<nhits;hit++) {
2311 // ahit = (AliHit*)fHits->UncheckedAt(hit);
2312 trk=ahit->GetTrack();
2313 if(ntrk[trk]==limi[trk]) {
2315 // Initialise a new track
2316 fp=new Float_t[3*(limi[trk]+chunk)];
2318 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2319 delete [] coor[trk];
2326 fp[3*ntrk[trk] ] = ahit->X();
2327 fp[3*ntrk[trk]+1] = ahit->Y();
2328 fp[3*ntrk[trk]+2] = ahit->Z();
2333 for(trk=0; trk<tracks; ++trk) {
2335 points = new AliPoints();
2336 points->SetMarkerColor(GetMarkerColor());
2337 points->SetMarkerSize(GetMarkerSize());
2338 points->SetDetector(this);
2339 points->SetParticle(trk);
2340 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2341 fPoints->AddAt(points,trk);
2342 delete [] coor[trk];
2352 //_____________________________________________________________________________
2353 void AliTPC::LoadPoints3(Int_t)
2356 // Store x, y, z of all hits in memory
2357 // - only intersection point with pad row
2358 if (fTrackHits == 0) return;
2360 Int_t nhits = fTrackHits->GetEntriesFast();
2361 if (nhits == 0) return;
2362 Int_t tracks = gAlice->GetNtrack();
2363 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2364 fPoints->Expand(2*tracks);
2367 Int_t *ntrk=new Int_t[tracks];
2368 Int_t *limi=new Int_t[tracks];
2369 Float_t **coor=new Float_t*[tracks];
2370 for(Int_t i=0;i<tracks;i++) {
2376 AliPoints *points = 0;
2379 Int_t chunk=nhits/4+1;
2381 // Loop over all the hits and store their position
2383 ahit = FirstHit2(-1);
2384 //for (Int_t hit=0;hit<nhits;hit++) {
2388 // ahit = (AliHit*)fHits->UncheckedAt(hit);
2389 trk=ahit->GetTrack();
2390 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2391 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2392 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2393 if (currentrow!=lastrow){
2394 lastrow = currentrow;
2395 //later calculate intersection point
2396 if(ntrk[trk]==limi[trk]) {
2398 // Initialise a new track
2399 fp=new Float_t[3*(limi[trk]+chunk)];
2401 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2402 delete [] coor[trk];
2409 fp[3*ntrk[trk] ] = ahit->X();
2410 fp[3*ntrk[trk]+1] = ahit->Y();
2411 fp[3*ntrk[trk]+2] = ahit->Z();
2418 for(trk=0; trk<tracks; ++trk) {
2420 points = new AliPoints();
2421 points->SetMarkerColor(GetMarkerColor()+1);
2422 points->SetMarkerStyle(5);
2423 points->SetMarkerSize(0.2);
2424 points->SetDetector(this);
2425 points->SetParticle(trk);
2426 // points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
2427 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2428 fPoints->AddAt(points,tracks+trk);
2429 delete [] coor[trk];
2440 void AliTPC::FindTrackHitsIntersection(TClonesArray * arr)
2444 //fill clones array with intersection of current point with the
2449 const Int_t kcmaxhits=30000;
2450 TVector * xxxx = new TVector(kcmaxhits*4);
2451 TVector & xxx = *xxxx;
2452 Int_t maxhits = kcmaxhits;
2455 AliTPChit * tpcHit=0;
2456 tpcHit = (AliTPChit*)FirstHit2(-1);
2457 Int_t currentIndex=0;
2458 Int_t lastrow=-1; //last writen row
2461 if (tpcHit==0) continue;
2462 sector=tpcHit->fSector; // sector number
2463 ipart=tpcHit->Track();
2467 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
2468 Int_t index[3]={1,sector,0};
2469 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2470 if (currentrow<0) continue;
2471 if (lastrow<0) lastrow=currentrow;
2472 if (currentrow==lastrow){
2473 if ( currentIndex>=maxhits){
2475 xxx.ResizeTo(4*maxhits);
2477 xxx(currentIndex*4)=x[0];
2478 xxx(currentIndex*4+1)=x[1];
2479 xxx(currentIndex*4+2)=x[2];
2480 xxx(currentIndex*4+3)=tpcHit->fQ;
2484 if (currentIndex>2){
2496 for (Int_t index=0;index<currentIndex;index++){
2498 x=x2=x3=x4=xxx(index*4);
2506 sumy+=xxx(index*4+1);
2507 sumxy+=xxx(index*4+1)*x;
2508 sumx2y+=xxx(index*4+1)*x2;
2509 sumz+=xxx(index*4+2);
2510 sumxz+=xxx(index*4+2)*x;
2511 sumx2z+=xxx(index*4+2)*x2;
2512 sumq+=xxx(index*4+3);
2514 Float_t centralPad = (fTPCParam->GetNPads(sector,lastrow)-1)/2;
2515 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
2516 sumx2*(sumx*sumx3-sumx2*sumx2);
2518 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
2519 sumx2*(sumxy*sumx3-sumx2y*sumx2);
2520 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
2521 sumx2*(sumxz*sumx3-sumx2z*sumx2);
2523 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
2524 sumx2*(sumx*sumx2y-sumx2*sumxy);
2525 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
2526 sumx2*(sumx*sumx2z-sumx2*sumxz);
2528 Float_t y=detay/det+centralPad;
2529 Float_t z=detaz/det;
2530 Float_t by=detby/det; //y angle
2531 Float_t bz=detbz/det; //z angle
2532 sumy/=Float_t(currentIndex);
2533 sumz/=Float_t(currentIndex);
2535 AliComplexCluster cl;
2541 cl.fTracks[0]=ipart;
2543 AliTPCClustersRow * row = (fClustersArray->GetRow(sector,lastrow));
2544 if (row!=0) row->InsertCluster(&cl);
2547 } //end of calculating cluster for given row
2549 } // end of loop over hits
2553 //_______________________________________________________________________________
2554 void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
2556 // produces rec points from digits and writes them on the root file
2557 // AliTPCclusters.root
2559 TDirectory *cwd = gDirectory;
2562 AliTPCParam *dig=(AliTPCParam *)gDirectory->Get("75x40_100x60");
2564 cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl;
2566 if(!gSystem->Getenv("CONFIG_FILE")){
2567 out=TFile::Open("AliTPCclusters.root","recreate");
2573 tmp1=gSystem->Getenv("CONFIG_FILE_PREFIX");
2574 tmp2=gSystem->Getenv("CONFIG_OUTDIR");
2575 sprintf(tmp3,"%s%s/AliTPCclusters.root",tmp1,tmp2);
2576 out=TFile::Open(tmp3,"recreate");
2580 cout<<"AliTPC::Digits2Reco - determination of rec points begins"<<endl;
2583 for(Int_t iev=firstevent;iev<lastevent+1;iev++){
2585 printf("Processing event %d\n",iev);
2586 Digits2Clusters(out,iev);
2588 cout<<"AliTPC::Digits2Reco - determination of rec points ended"<<endl;