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.39 2001/07/26 09:09:34 kowal2
19 Hits2Reco method added
21 Revision 1.38 2001/07/20 14:32:43 kowal2
22 Processing of many events possible now
24 Revision 1.37 2001/06/12 07:17:18 kowal2
25 Hits2SDigits method implemented (summable digits)
27 Revision 1.36 2001/05/16 14:57:25 alibrary
28 New files for folders and Stack
30 Revision 1.35 2001/05/08 16:02:22 kowal2
31 Updated material specifications
33 Revision 1.34 2001/05/08 15:00:15 hristov
34 Corrections for tracking in arbitrary magnenetic field. Changes towards a concept of global Alice track. Back propagation of reconstructed tracks (Yu.Belikov)
36 Revision 1.33 2001/04/03 12:40:43 kowal2
39 Revision 1.32 2001/03/12 17:47:36 hristov
40 Changes needed on Sun with CC 5.0
42 Revision 1.31 2001/03/12 08:21:50 kowal2
43 Corrected C++ bug in the material definitions
45 Revision 1.30 2001/03/01 17:34:47 kowal2
46 Correction due to the accuracy problem
48 Revision 1.29 2001/02/28 16:34:40 kowal2
49 Protection against nonphysical values of the avalanche size,
52 Revision 1.28 2001/01/26 19:57:19 hristov
53 Major upgrade of AliRoot code
55 Revision 1.27 2001/01/13 17:29:33 kowal2
56 Sun compiler correction
58 Revision 1.26 2001/01/10 07:59:43 kowal2
59 Corrections to load points from the noncompressed hits.
61 Revision 1.25 2000/11/02 07:25:31 kowal2
62 Changes due to the new hit structure.
65 Revision 1.24 2000/10/05 16:06:09 kowal2
66 Forward declarations. Changes due to a new class AliComplexCluster.
68 Revision 1.23 2000/10/02 21:28:18 fca
69 Removal of useless dependecies via forward declarations
71 Revision 1.22 2000/07/10 20:57:39 hristov
72 Update of TPC code and macros by M.Kowalski
74 Revision 1.19.2.4 2000/06/26 07:39:42 kowal2
75 Changes to obey the coding rules
77 Revision 1.19.2.3 2000/06/25 08:38:41 kowal2
78 Splitted from AliTPCtracking
80 Revision 1.19.2.2 2000/06/16 12:59:28 kowal2
81 Changed parameter settings
83 Revision 1.19.2.1 2000/06/09 07:15:07 kowal2
85 Defaults loaded automatically (hard-wired)
86 Optional parameters can be set via macro called in the constructor
88 Revision 1.19 2000/04/18 19:00:59 fca
89 Small bug fixes to TPC files
91 Revision 1.18 2000/04/17 09:37:33 kowal2
92 removed obsolete AliTPCDigitsDisplay.C
94 Revision 1.17.2.2 2000/04/10 08:15:12 kowal2
96 New, experimental data structure from M. Ivanov
97 New tracking algorithm
98 Different pad geometry for different sectors
99 Digitization rewritten
101 Revision 1.17.2.1 2000/04/10 07:56:53 kowal2
102 Not used anymore - removed
104 Revision 1.17 2000/01/19 17:17:30 fca
105 Introducing a list of lists of hits -- more hits allowed for detector now
107 Revision 1.16 1999/11/05 09:29:23 fca
108 Accept only signals > 0
110 Revision 1.15 1999/10/08 06:26:53 fca
111 Removed ClustersIndex - not used anymore
113 Revision 1.14 1999/09/29 09:24:33 fca
114 Introduction of the Copyright and cvs Log
118 ///////////////////////////////////////////////////////////////////////////////
120 // Time Projection Chamber //
121 // This class contains the basic functions for the Time Projection Chamber //
122 // detector. Functions specific to one particular geometry are //
123 // contained in the derived classes //
127 <img src="picts/AliTPCClass.gif">
132 ///////////////////////////////////////////////////////////////////////////////
140 #include <TGeometry.h>
143 #include <TObjectTable.h>
144 #include "TParticle.h"
150 #include <iostream.h>
157 #include "AliTPCParamSR.h"
158 #include "AliTPCPRF2D.h"
159 #include "AliTPCRF1D.h"
160 #include "AliDigits.h"
161 #include "AliSimDigits.h"
162 #include "AliTPCTrackHits.h"
163 #include "AliPoints.h"
164 #include "AliArrayBranch.h"
167 #include "AliTPCDigitsArray.h"
168 #include "AliComplexCluster.h"
169 #include "AliClusters.h"
170 #include "AliTPCClustersRow.h"
171 #include "AliTPCClustersArray.h"
173 #include "AliTPCcluster.h"
174 #include "AliTPCclusterer.h"
175 #include "AliTPCtracker.h"
177 #include <TInterpreter.h>
184 //_____________________________________________________________________________
188 // Default constructor
203 //_____________________________________________________________________________
204 AliTPC::AliTPC(const char *name, const char *title)
205 : AliDetector(name,title)
208 // Standard constructor
212 // Initialise arrays of hits and digits
213 fHits = new TClonesArray("AliTPChit", 176);
214 gAlice->AddHitList(fHits);
220 fTrackHits = new AliTPCTrackHits; //MI - 13.09.2000
221 fTrackHits->SetHitPrecision(0.002);
222 fTrackHits->SetStepPrecision(0.003);
223 fTrackHits->SetMaxDistance(100);
227 // Initialise counters
233 // Initialise color attributes
234 SetMarkerColor(kYellow);
237 // Set TPC parameters
241 if (!strcmp(title,"Default")) {
242 fTPCParam = new AliTPCParamSR;
244 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
250 //_____________________________________________________________________________
261 delete fTrackHits; //MI 15.09.2000
264 //_____________________________________________________________________________
265 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
268 // Add a hit to the list
270 // TClonesArray &lhits = *fHits;
271 // new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
273 TClonesArray &lhits = *fHits;
274 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
277 AddHit2(track,vol,hits);
280 //_____________________________________________________________________________
281 void AliTPC::BuildGeometry()
285 // Build TPC ROOT TNode geometry for the event display
290 const int kColorTPC=19;
291 char name[5], title[25];
292 const Double_t kDegrad=TMath::Pi()/180;
293 const Double_t kRaddeg=180./TMath::Pi();
296 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
297 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
299 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
300 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
302 Int_t nLo = fTPCParam->GetNInnerSector()/2;
303 Int_t nHi = fTPCParam->GetNOuterSector()/2;
305 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
306 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
307 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
308 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
311 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
312 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
318 // Get ALICE top node
321 nTop=gAlice->GetGeometry()->GetNode("alice");
325 rl = fTPCParam->GetInnerRadiusLow();
326 ru = fTPCParam->GetInnerRadiusUp();
330 sprintf(name,"LS%2.2d",i);
332 sprintf(title,"TPC low sector %3d",i);
335 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
336 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
337 tubs->SetNumberOfDivisions(1);
339 nNode = new TNode(name,title,name,0,0,0,"");
340 nNode->SetLineColor(kColorTPC);
346 rl = fTPCParam->GetOuterRadiusLow();
347 ru = fTPCParam->GetOuterRadiusUp();
350 sprintf(name,"US%2.2d",i);
352 sprintf(title,"TPC upper sector %d",i);
354 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
355 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
356 tubs->SetNumberOfDivisions(1);
358 nNode = new TNode(name,title,name,0,0,0,"");
359 nNode->SetLineColor(kColorTPC);
365 //_____________________________________________________________________________
366 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
369 // Calculate distance from TPC to mouse on the display
375 void AliTPC::Clusters2Tracks(TFile *of) {
376 //-----------------------------------------------------------------
377 // This is a track finder.
378 //-----------------------------------------------------------------
379 AliTPCtracker tracker(fTPCParam);
380 tracker.Clusters2Tracks(gFile,of);
383 //_____________________________________________________________________________
384 void AliTPC::CreateMaterials()
386 //-----------------------------------------------
387 // Create Materials for for TPC simulations
388 //-----------------------------------------------
390 //-----------------------------------------------------------------
391 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
392 //-----------------------------------------------------------------
394 Int_t iSXFLD=gAlice->Field()->Integ();
395 Float_t sXMGMX=gAlice->Field()->Max();
397 Float_t amat[5]; // atomic numbers
398 Float_t zmat[5]; // z
399 Float_t wmat[5]; // proportions
405 //***************** Gases *************************
407 //-------------------------------------------------
409 //-------------------------------------------------
420 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
430 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
433 //--------------------------------------------------------------
435 //--------------------------------------------------------------
452 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
454 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
469 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
471 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
487 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
489 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
491 //----------------------------------------------------------------
492 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
493 //----------------------------------------------------------------
499 Float_t rho,absl,X0,buf[1];
503 for(nc = 0;nc<fNoComp;nc++)
506 // retrive material constants
508 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,X0,absl,buf,nbuf);
513 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
515 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
516 density += fMixtProp[nc]*rho; // density of the mixture
520 // mixture proportions by weight!
522 for(nc = 0;nc<fNoComp;nc++)
525 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
527 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
528 apure[nnc] : amol[nnc])/am;
532 // Drift gases 1 - nonsensitive, 2 - sensitive
534 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
535 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
544 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
547 //----------------------------------------------------------------------
549 //----------------------------------------------------------------------
571 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
593 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
611 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
629 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
631 // SiO2 - used later for the glass fiber
643 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
652 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
661 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
670 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
688 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
707 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
709 // Epoxy - C14 H20 O3
726 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
734 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
738 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,X0,absl,buf,nbuf);
742 wmat[0]=0.644; // by weight!
745 density=0.5*(1.25+2.265);
747 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
751 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,X0,absl,buf,nbuf);
753 wmat[0]=0.725; // by weight!
758 AliMixture(39,"G10",amat,zmat,density,2,wmat);
763 //----------------------------------------------------------
764 // tracking media for gases
765 //----------------------------------------------------------
767 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
768 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
769 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
770 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
772 //-----------------------------------------------------------
773 // tracking media for solids
774 //-----------------------------------------------------------
776 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
777 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
778 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
779 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
780 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
781 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
782 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
783 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
784 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
785 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
786 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
787 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
792 void AliTPC::Digits2Clusters(TFile *of, Int_t eventnumber)
794 //-----------------------------------------------------------------
795 // This is a simple cluster finder.
796 //-----------------------------------------------------------------
797 AliTPCclusterer::Digits2Clusters(fTPCParam,of,eventnumber);
800 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
801 extern Double_t SigmaZ2(Double_t, Double_t);
802 //_____________________________________________________________________________
803 void AliTPC::Hits2Clusters(TFile *of, Int_t eventn)
805 //--------------------------------------------------------
806 // TPC simple cluster generator from hits
807 // obtained from the TPC Fast Simulator
808 // The point errors are taken from the parametrization
809 //--------------------------------------------------------
811 //-----------------------------------------------------------------
812 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
813 //-----------------------------------------------------------------
814 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
815 // Jouri.Belikov@cern.ch
816 //----------------------------------------------------------------
818 /////////////////////////////////////////////////////////////////////////////
820 //---------------------------------------------------------------------
821 // ALICE TPC Cluster Parameters
822 //--------------------------------------------------------------------
826 // Cluster width in rphi
827 const Float_t kACrphi=0.18322;
828 const Float_t kBCrphi=0.59551e-3;
829 const Float_t kCCrphi=0.60952e-1;
830 // Cluster width in z
831 const Float_t kACz=0.19081;
832 const Float_t kBCz=0.55938e-3;
833 const Float_t kCCz=0.30428;
835 TDirectory *savedir=gDirectory;
838 cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
842 //if(fDefaults == 0) SetDefaults();
844 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
846 TParticle *particle; // pointer to a given particle
847 AliTPChit *tpcHit; // pointer to a sigle TPC hit
851 Float_t pl,pt,tanth,rpad,ratio;
854 //---------------------------------------------------------------
855 // Get the access to the tracks
856 //---------------------------------------------------------------
858 TTree *tH = gAlice->TreeH();
859 Stat_t ntracks = tH->GetEntries();
861 //Switch to the output file
866 sprintf(cname,"TreeC_TPC_%d",eventn);
868 fTPCParam->Write(fTPCParam->GetTitle());
869 AliTPCClustersArray carray;
870 carray.Setup(fTPCParam);
871 carray.SetClusterType("AliTPCcluster");
874 Int_t nclusters=0; //cluster counter
876 //------------------------------------------------------------
877 // Loop over all sectors (72 sectors for 20 deg
878 // segmentation for both lower and upper sectors)
879 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
880 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
882 // First cluster for sector 0 starts at "0"
883 //------------------------------------------------------------
885 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
887 fTPCParam->AdjustCosSin(isec,cph,sph);
889 //------------------------------------------------------------
891 //------------------------------------------------------------
893 for(Int_t track=0;track<ntracks;track++){
897 // Get number of the TPC hits
899 // nhits=fHits->GetEntriesFast();
902 tpcHit = (AliTPChit*)FirstHit(-1);
906 // for(Int_t hit=0;hit<nhits;hit++){
907 //tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
911 if (tpcHit->fQ == 0.) {
912 tpcHit = (AliTPChit*) NextHit();
913 continue; //information about track (I.Belikov)
915 sector=tpcHit->fSector; // sector number
918 // if(sector != isec) continue; //terminate iteration
921 tpcHit = (AliTPChit*) NextHit();
924 ipart=tpcHit->Track();
925 particle=gAlice->Particle(ipart);
928 if(pt < 1.e-9) pt=1.e-9;
930 tanth = TMath::Abs(tanth);
931 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
932 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
934 // space-point resolutions
936 sigmaRphi=SigmaY2(rpad,tanth,pt);
937 sigmaZ =SigmaZ2(rpad,tanth );
941 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
942 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
944 // temporary protection
946 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
947 if(sigmaZ < 0.) sigmaZ=0.4e-3;
948 if(clRphi < 0.) clRphi=2.5e-3;
949 if(clZ < 0.) clZ=2.5e-5;
954 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
955 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
957 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
958 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
959 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
960 Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
961 fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
962 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
963 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
964 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
965 if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->Z();
966 xyz[2]=sigmaRphi; // fSigmaY2
967 xyz[3]=sigmaZ; // fSigmaZ2
968 xyz[4]=tpcHit->fQ; // q
970 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
971 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
973 Int_t tracks[3]={tpcHit->Track(), -1, -1};
974 AliTPCcluster cluster(tracks,xyz);
976 clrow->InsertCluster(&cluster); nclusters++;
978 tpcHit = (AliTPChit*)NextHit();
981 } // end of loop over hits
983 } // end of loop over tracks
985 Int_t nrows=fTPCParam->GetNRow(isec);
986 for (Int_t irow=0; irow<nrows; irow++) {
987 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
988 if (!clrow) continue;
989 carray.StoreRow(isec,irow);
990 carray.ClearRow(isec,irow);
993 } // end of loop over sectors
995 cerr<<"Number of made clusters : "<<nclusters<<" \n";
997 carray.GetTree()->Write(cname);
999 savedir->cd(); //switch back to the input file
1001 } // end of function
1003 //_________________________________________________________________
1004 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1006 //--------------------------------------------------------
1007 //calculate exact cross point of track and given pad row
1008 //resulting values are expressed in "digit" coordinata
1009 //--------------------------------------------------------
1011 //-----------------------------------------------------------------
1012 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1013 //-----------------------------------------------------------------
1015 if (fClustersArray==0){
1019 TParticle *particle; // pointer to a given particle
1020 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1023 const Int_t kcmaxhits=30000;
1024 TVector * xxxx = new TVector(kcmaxhits*4);
1025 TVector & xxx = *xxxx;
1026 Int_t maxhits = kcmaxhits;
1027 //construct array for each padrow
1028 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
1029 fClustersArray->CreateRow(isec,i);
1031 //---------------------------------------------------------------
1032 // Get the access to the tracks
1033 //---------------------------------------------------------------
1035 TTree *tH = gAlice->TreeH();
1036 Stat_t ntracks = tH->GetEntries();
1037 Int_t npart = gAlice->GetNtrack();
1039 //------------------------------------------------------------
1041 //------------------------------------------------------------
1043 for(Int_t track=0;track<ntracks;track++){
1045 tH->GetEvent(track);
1047 // Get number of the TPC hits and a pointer
1050 nhits=fHits->GetEntriesFast();
1054 Int_t currentIndex=0;
1055 Int_t lastrow=-1; //last writen row
1056 for(Int_t hit=0;hit<nhits;hit++){
1057 tpcHit=(AliTPChit*)fHits->UncheckedAt(hit);
1058 if (tpcHit==0) continue;
1059 sector=tpcHit->fSector; // sector number
1060 if(sector != isec) continue;
1061 ipart=tpcHit->Track();
1062 if (ipart<npart) particle=gAlice->Particle(ipart);
1066 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
1067 Int_t index[3]={1,isec,0};
1068 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
1069 if (currentrow<0) continue;
1070 if (lastrow<0) lastrow=currentrow;
1071 if (currentrow==lastrow){
1072 if ( currentIndex>=maxhits){
1074 xxx.ResizeTo(4*maxhits);
1076 xxx(currentIndex*4)=x[0];
1077 xxx(currentIndex*4+1)=x[1];
1078 xxx(currentIndex*4+2)=x[2];
1079 xxx(currentIndex*4+3)=tpcHit->fQ;
1083 if (currentIndex>2){
1095 for (Int_t index=0;index<currentIndex;index++){
1097 x=x2=x3=x4=xxx(index*4);
1105 sumy+=xxx(index*4+1);
1106 sumxy+=xxx(index*4+1)*x;
1107 sumx2y+=xxx(index*4+1)*x2;
1108 sumz+=xxx(index*4+2);
1109 sumxz+=xxx(index*4+2)*x;
1110 sumx2z+=xxx(index*4+2)*x2;
1111 sumq+=xxx(index*4+3);
1113 Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1114 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1115 sumx2*(sumx*sumx3-sumx2*sumx2);
1117 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1118 sumx2*(sumxy*sumx3-sumx2y*sumx2);
1119 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1120 sumx2*(sumxz*sumx3-sumx2z*sumx2);
1122 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1123 sumx2*(sumx*sumx2y-sumx2*sumxy);
1124 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1125 sumx2*(sumx*sumx2z-sumx2*sumxz);
1127 Float_t y=detay/det+centralPad;
1128 Float_t z=detaz/det;
1129 Float_t by=detby/det; //y angle
1130 Float_t bz=detbz/det; //z angle
1131 sumy/=Float_t(currentIndex);
1132 sumz/=Float_t(currentIndex);
1133 AliComplexCluster cl;
1139 cl.fTracks[0]=ipart;
1141 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1142 if (row!=0) row->InsertCluster(&cl);
1145 } //end of calculating cluster for given row
1149 } // end of loop over hits
1150 } // end of loop over tracks
1151 //write padrows to tree
1152 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1153 fClustersArray->StoreRow(isec,ii);
1154 fClustersArray->ClearRow(isec,ii);
1159 //___________________________________________
1160 void AliTPC::SDigits2Digits(Int_t eventnumber)
1164 cerr<<"Digitizing TPC...\n";
1166 Hits2Digits(eventnumber);
1171 // char treeName[100];
1173 // sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1175 // GetDigitsArray()->GetTree()->Write(treeName);
1177 //__________________________________________________________________
1178 void AliTPC::SetDefaults(){
1181 cerr<<"Setting default parameters...\n";
1183 // Set response functions
1185 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1186 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1187 AliTPCPRF2D * prfouter = new AliTPCPRF2D;
1188 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1189 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1190 rf->SetOffset(3*param->GetZSigma());
1193 TDirectory *savedir=gDirectory;
1194 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1196 cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1199 prfinner->Read("prf_07504_Gati_056068_d02");
1200 prfouter->Read("prf_10006_Gati_047051_d03");
1204 param->SetInnerPRF(prfinner);
1205 param->SetOuterPRF(prfouter);
1206 param->SetTimeRF(rf);
1216 //__________________________________________________________________
1217 void AliTPC::Hits2Digits(Int_t eventnumber)
1219 //----------------------------------------------------
1220 // Loop over all sectors for a single event
1221 //----------------------------------------------------
1224 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1226 //setup TPCDigitsArray
1228 if(GetDigitsArray()) delete GetDigitsArray();
1230 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1231 arr->SetClass("AliSimDigits");
1232 arr->Setup(fTPCParam);
1233 arr->MakeTree(fDigitsFile);
1234 SetDigitsArray(arr);
1236 fDigitsSwitch=0; // standard digits
1238 cerr<<"Digitizing TPC...\n";
1240 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
1246 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1248 GetDigitsArray()->GetTree()->Write(treeName);
1255 //__________________________________________________________________
1256 void AliTPC::Hits2SDigits(Int_t eventnumber)
1259 //-----------------------------------------------------------
1260 // summable digits - 16 bit "ADC", no noise, no saturation
1261 //-----------------------------------------------------------
1263 //----------------------------------------------------
1264 // Loop over all sectors for a single event
1265 //----------------------------------------------------
1268 if(fDefaults == 0) SetDefaults();
1270 //setup TPCDigitsArray
1272 if(GetDigitsArray()) delete GetDigitsArray();
1274 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1275 arr->SetClass("AliSimDigits");
1276 arr->Setup(fTPCParam);
1277 arr->MakeTree(fDigitsFile);
1278 SetDigitsArray(arr);
1280 cerr<<"Digitizing TPC...\n";
1282 fDigitsSwitch=1; // summable digits
1284 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) Hits2DigitsSector(isec);
1291 sprintf(treeName,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1293 GetDigitsArray()->GetTree()->Write(treeName);
1299 //_____________________________________________________________________________
1300 void AliTPC::Hits2DigitsSector(Int_t isec)
1302 //-------------------------------------------------------------------
1303 // TPC conversion from hits to digits.
1304 //-------------------------------------------------------------------
1306 //-----------------------------------------------------------------
1307 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1308 //-----------------------------------------------------------------
1310 //-------------------------------------------------------
1311 // Get the access to the track hits
1312 //-------------------------------------------------------
1314 // check if the parameters are set - important if one calls this method
1315 // directly, not from the Hits2Digits
1317 if(fDefaults == 0) SetDefaults();
1319 TTree *tH = gAlice->TreeH(); // pointer to the hits tree
1320 Stat_t ntracks = tH->GetEntries();
1324 //-------------------------------------------
1325 // Only if there are any tracks...
1326 //-------------------------------------------
1330 //printf("*** Processing sector number %d ***\n",isec);
1332 Int_t nrows =fTPCParam->GetNRow(isec);
1334 row= new TObjArray* [nrows];
1336 MakeSector(isec,nrows,tH,ntracks,row);
1338 //--------------------------------------------------------
1339 // Digitize this sector, row by row
1340 // row[i] is the pointer to the TObjArray of TVectors,
1341 // each one containing electrons accepted on this
1342 // row, assigned into tracks
1343 //--------------------------------------------------------
1347 if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree(fDigitsFile);
1349 for (i=0;i<nrows;i++){
1351 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1353 DigitizeRow(i,isec,row);
1355 fDigitsArray->StoreRow(isec,i);
1357 Int_t ndig = dig->GetDigitSize();
1360 //printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1362 fDigitsArray->ClearRow(isec,i);
1365 } // end of the sector digitization
1367 for(i=0;i<nrows;i++){
1372 delete [] row; // delete the array of pointers to TObjArray-s
1376 } // end of Hits2DigitsSector
1379 //_____________________________________________________________________________
1380 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1382 //-----------------------------------------------------------
1383 // Single row digitization, coupling from the neighbouring
1384 // rows taken into account
1385 //-----------------------------------------------------------
1387 //-----------------------------------------------------------------
1388 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1389 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1390 //-----------------------------------------------------------------
1393 Float_t zerosup = fTPCParam->GetZeroSup();
1394 Int_t nrows =fTPCParam->GetNRow(isec);
1395 fCurrentIndex[1]= isec;
1398 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1399 Int_t nofTbins = fTPCParam->GetMaxTBin();
1400 Int_t indexRange[4];
1402 // Integrated signal for this row
1403 // and a single track signal
1405 TMatrix *m1 = new TMatrix(0,nofPads,0,nofTbins); // integrated
1406 TMatrix *m2 = new TMatrix(0,nofPads,0,nofTbins); // single
1408 TMatrix &total = *m1;
1410 // Array of pointers to the label-signal list
1412 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1413 Float_t **pList = new Float_t* [nofDigits];
1417 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1421 Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1422 Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1423 for (Int_t row= row1;row<=row2;row++){
1424 Int_t nTracks= rows[row]->GetEntries();
1425 for (i1=0;i1<nTracks;i1++){
1426 fCurrentIndex[2]= row;
1427 fCurrentIndex[3]=irow;
1429 m2->Zero(); // clear single track signal matrix
1430 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1431 GetList(trackLabel,nofPads,m2,indexRange,pList);
1433 else GetSignal(rows[row],i1,0,m1,indexRange);
1439 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1440 for(Int_t ip=0;ip<nofPads;ip++){
1441 for(Int_t it=0;it<nofTbins;it++){
1443 Float_t q = total(ip,it);
1445 Int_t gi =it*nofPads+ip; // global index
1447 if(fDigitsSwitch == 0){
1449 q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
1453 if(q <=zerosup) continue; // do not fill zeros
1454 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1464 // "real" signal or electronic noise (list = -1)?
1467 for(Int_t j1=0;j1<3;j1++){
1468 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -1;
1473 <A NAME="AliDigits"></A>
1474 using of AliDigits object
1477 dig->SetDigitFast((Short_t)q,it,ip);
1478 if (fDigitsArray->IsSimulated())
1480 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1481 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1482 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1486 } // end of loop over time buckets
1487 } // end of lop over pads
1490 // This row has been digitized, delete nonused stuff
1493 for(lp=0;lp<nofDigits;lp++){
1494 if(pList[lp]) delete [] pList[lp];
1503 } // end of DigitizeRow
1505 //_____________________________________________________________________________
1507 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr, TMatrix *m1, TMatrix *m2,
1511 //---------------------------------------------------------------
1512 // Calculates 2-D signal (pad,time) for a single track,
1513 // returns a pointer to the signal matrix and the track label
1514 // No digitization is performed at this level!!!
1515 //---------------------------------------------------------------
1517 //-----------------------------------------------------------------
1518 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1519 // Modified: Marian Ivanov
1520 //-----------------------------------------------------------------
1524 tv = (TVector*)p1->At(ntr); // pointer to a track
1527 Float_t label = v(0);
1528 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
1530 Int_t nElectrons = (tv->GetNrows()-1)/4;
1531 indexRange[0]=9999; // min pad
1532 indexRange[1]=-1; // max pad
1533 indexRange[2]=9999; //min time
1534 indexRange[3]=-1; // max time
1536 // Float_t IneffFactor = 0.5; // inefficiency in the gain close to the edge, as above
1538 TMatrix &signal = *m1;
1539 TMatrix &total = *m2;
1541 // Loop over all electrons
1543 for(Int_t nel=0; nel<nElectrons; nel++){
1545 Float_t aval = v(idx+4);
1546 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1547 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1548 Int_t n = fTPCParam->CalcResponse(xyz,fCurrentIndex,fCurrentIndex[3]);
1550 if (n>0) for (Int_t i =0; i<n; i++){
1551 Int_t *index = fTPCParam->GetResBin(i);
1552 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1553 if ( ( pad<(fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]))) && (pad>0)) {
1554 Int_t time=index[2];
1555 Float_t weight = fTPCParam->GetResWeight(i); //we normalise response to ADC channel
1556 weight *= eltoadcfac;
1558 if (m1!=0) signal(pad,time)+=weight;
1559 total(pad,time)+=weight;
1560 indexRange[0]=TMath::Min(indexRange[0],pad);
1561 indexRange[1]=TMath::Max(indexRange[1],pad);
1562 indexRange[2]=TMath::Min(indexRange[2],time);
1563 indexRange[3]=TMath::Max(indexRange[3],time);
1566 } // end of loop over electrons
1568 return label; // returns track label when finished
1571 //_____________________________________________________________________________
1572 void AliTPC::GetList(Float_t label,Int_t np,TMatrix *m,Int_t *indexRange,
1575 //----------------------------------------------------------------------
1576 // Updates the list of tracks contributing to digits for a given row
1577 //----------------------------------------------------------------------
1579 //-----------------------------------------------------------------
1580 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1581 //-----------------------------------------------------------------
1583 TMatrix &signal = *m;
1585 // lop over nonzero digits
1587 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1588 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1591 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1593 if(signal(ip,it)<0.5) continue;
1596 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1598 if(!pList[globalIndex]){
1601 // Create new list (6 elements - 3 signals and 3 labels),
1604 pList[globalIndex] = new Float_t [6];
1608 *pList[globalIndex] = -1.;
1609 *(pList[globalIndex]+1) = -1.;
1610 *(pList[globalIndex]+2) = -1.;
1611 *(pList[globalIndex]+3) = -1.;
1612 *(pList[globalIndex]+4) = -1.;
1613 *(pList[globalIndex]+5) = -1.;
1616 *pList[globalIndex] = label;
1617 *(pList[globalIndex]+3) = signal(ip,it);
1621 // check the signal magnitude
1623 Float_t highest = *(pList[globalIndex]+3);
1624 Float_t middle = *(pList[globalIndex]+4);
1625 Float_t lowest = *(pList[globalIndex]+5);
1628 // compare the new signal with already existing list
1631 if(signal(ip,it)<lowest) continue; // neglect this track
1635 if (signal(ip,it)>highest){
1636 *(pList[globalIndex]+5) = middle;
1637 *(pList[globalIndex]+4) = highest;
1638 *(pList[globalIndex]+3) = signal(ip,it);
1640 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1641 *(pList[globalIndex]+1) = *pList[globalIndex];
1642 *pList[globalIndex] = label;
1644 else if (signal(ip,it)>middle){
1645 *(pList[globalIndex]+5) = middle;
1646 *(pList[globalIndex]+4) = signal(ip,it);
1648 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1649 *(pList[globalIndex]+1) = label;
1652 *(pList[globalIndex]+5) = signal(ip,it);
1653 *(pList[globalIndex]+2) = label;
1657 } // end of loop over pads
1658 } // end of loop over time bins
1663 //___________________________________________________________________
1664 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1665 Stat_t ntracks,TObjArray **row)
1668 //-----------------------------------------------------------------
1669 // Prepares the sector digitization, creates the vectors of
1670 // tracks for each row of this sector. The track vector
1671 // contains the track label and the position of electrons.
1672 //-----------------------------------------------------------------
1674 //-----------------------------------------------------------------
1675 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1676 //-----------------------------------------------------------------
1678 Float_t gasgain = fTPCParam->GetGasGain();
1682 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1685 if (fHitType&2) branch = TH->GetBranch("TPC2");
1686 else branch = TH->GetBranch("TPC");
1689 //----------------------------------------------
1690 // Create TObjArray-s, one for each row,
1691 // each TObjArray will store the TVectors
1692 // of electrons, one TVector per each track.
1693 //----------------------------------------------
1695 Int_t *nofElectrons = new Int_t [nrows]; // electron counter for each row
1696 TVector **tracks = new TVector* [nrows]; //pointers to the track vectors
1697 for(i=0; i<nrows; i++){
1698 row[i] = new TObjArray;
1705 //--------------------------------------------------------------------
1706 // Loop over tracks, the "track" contains the full history
1707 //--------------------------------------------------------------------
1709 Int_t previousTrack,currentTrack;
1710 previousTrack = -1; // nothing to store so far!
1712 for(Int_t track=0;track<ntracks;track++){
1713 Bool_t isInSector=kTRUE;
1718 TBranch * br = TH->GetBranch("fTrackHitsInfo");
1719 br->GetEvent(track);
1720 AliObjectArray * ar = fTrackHits->fTrackHitsInfo;
1721 for (UInt_t j=0;j<ar->GetSize();j++){
1722 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==isec) isInSector=kTRUE;
1725 if (!isInSector) continue;
1727 branch->GetEntry(track); // get next track
1731 tpcHit = (AliTPChit*)FirstHit(-1);
1733 //--------------------------------------------------------------
1735 //--------------------------------------------------------------
1740 Int_t sector=tpcHit->fSector; // sector number
1741 // if(sector != isec) continue;
1743 tpcHit = (AliTPChit*) NextHit();
1747 currentTrack = tpcHit->Track(); // track number
1750 if(currentTrack != previousTrack){
1752 // store already filled fTrack
1754 for(i=0;i<nrows;i++){
1755 if(previousTrack != -1){
1756 if(nofElectrons[i]>0){
1757 TVector &v = *tracks[i];
1758 v(0) = previousTrack;
1759 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1760 row[i]->Add(tracks[i]);
1763 delete tracks[i]; // delete empty TVector
1769 tracks[i] = new TVector(481); // TVectors for the next fTrack
1771 } // end of loop over rows
1773 previousTrack=currentTrack; // update track label
1776 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1778 //---------------------------------------------------
1779 // Calculate the electron attachment probability
1780 //---------------------------------------------------
1783 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
1784 /fTPCParam->GetDriftV();
1786 Float_t attProb = fTPCParam->GetAttCoef()*
1787 fTPCParam->GetOxyCont()*time; // fraction!
1789 //-----------------------------------------------
1790 // Loop over electrons
1791 //-----------------------------------------------
1794 for(Int_t nel=0;nel<qI;nel++){
1795 // skip if electron lost due to the attachment
1796 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1801 // protection for the nonphysical avalanche size (10**6 maximum)
1803 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1804 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
1807 TransportElectron(xyz,index); //MI change -august
1809 fTPCParam->GetPadRow(xyz,index); //MI change august
1810 rowNumber = index[2];
1811 //transform position to local digit coordinates
1812 //relative to nearest pad row
1813 if ((rowNumber<0)||rowNumber>=fTPCParam->GetNRow(isec)) continue;
1814 nofElectrons[rowNumber]++;
1815 //----------------------------------
1816 // Expand vector if necessary
1817 //----------------------------------
1818 if(nofElectrons[rowNumber]>120){
1819 Int_t range = tracks[rowNumber]->GetNrows();
1820 if((nofElectrons[rowNumber])>(range-1)/4){
1822 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
1826 TVector &v = *tracks[rowNumber];
1827 Int_t idx = 4*nofElectrons[rowNumber]-3;
1829 v(idx)= xyz[0]; // X - pad row coordinate
1830 v(idx+1)=xyz[1]; // Y - pad coordinate (along the pad-row)
1831 v(idx+2)=xyz[2]; // Z - time bin coordinate
1832 v(idx+3)=xyz[3]; // avalanche size
1833 } // end of loop over electrons
1835 tpcHit = (AliTPChit*)NextHit();
1837 } // end of loop over hits
1838 } // end of loop over tracks
1841 // store remaining track (the last one) if not empty
1844 for(i=0;i<nrows;i++){
1845 if(nofElectrons[i]>0){
1846 TVector &v = *tracks[i];
1847 v(0) = previousTrack;
1848 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1849 row[i]->Add(tracks[i]);
1858 delete [] nofElectrons;
1861 } // end of MakeSector
1864 //_____________________________________________________________________________
1868 // Initialise TPC detector after definition of geometry
1873 printf("\n%s: ",ClassName());
1874 for(i=0;i<35;i++) printf("*");
1875 printf(" TPC_INIT ");
1876 for(i=0;i<35;i++) printf("*");
1877 printf("\n%s: ",ClassName());
1879 for(i=0;i<80;i++) printf("*");
1884 //_____________________________________________________________________________
1885 void AliTPC::MakeBranch(Option_t* option, const char *file)
1888 // Create Tree branches for the TPC.
1890 Int_t buffersize = 4000;
1891 char branchname[10];
1892 sprintf(branchname,"%s",GetName());
1894 AliDetector::MakeBranch(option,file);
1896 const char *d = strstr(option,"D");
1898 if (fDigits && gAlice->TreeD() && d) {
1899 MakeBranchInTree(gAlice->TreeD(),
1900 branchname, &fDigits, buffersize, file);
1903 if (fHitType&2) MakeBranch2(option,file); // MI change 14.09.2000
1906 //_____________________________________________________________________________
1907 void AliTPC::ResetDigits()
1910 // Reset number of digits and the digits array for this detector
1913 if (fDigits) fDigits->Clear();
1916 //_____________________________________________________________________________
1917 void AliTPC::SetSecAL(Int_t sec)
1919 //---------------------------------------------------
1920 // Activate/deactivate selection for lower sectors
1921 //---------------------------------------------------
1923 //-----------------------------------------------------------------
1924 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1925 //-----------------------------------------------------------------
1930 //_____________________________________________________________________________
1931 void AliTPC::SetSecAU(Int_t sec)
1933 //----------------------------------------------------
1934 // Activate/deactivate selection for upper sectors
1935 //---------------------------------------------------
1937 //-----------------------------------------------------------------
1938 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1939 //-----------------------------------------------------------------
1944 //_____________________________________________________________________________
1945 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
1947 //----------------------------------------
1948 // Select active lower sectors
1949 //----------------------------------------
1951 //-----------------------------------------------------------------
1952 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1953 //-----------------------------------------------------------------
1963 //_____________________________________________________________________________
1964 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
1965 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
1966 Int_t s11 , Int_t s12)
1968 //--------------------------------
1969 // Select active upper sectors
1970 //--------------------------------
1972 //-----------------------------------------------------------------
1973 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1974 //-----------------------------------------------------------------
1990 //_____________________________________________________________________________
1991 void AliTPC::SetSens(Int_t sens)
1994 //-------------------------------------------------------------
1995 // Activates/deactivates the sensitive strips at the center of
1996 // the pad row -- this is for the space-point resolution calculations
1997 //-------------------------------------------------------------
1999 //-----------------------------------------------------------------
2000 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2001 //-----------------------------------------------------------------
2007 void AliTPC::SetSide(Float_t side=0.)
2009 // choice of the TPC side
2014 //____________________________________________________________________________
2015 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2016 Float_t p2,Float_t p3)
2019 // gax mixture definition
2033 //_____________________________________________________________________________
2035 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2038 // electron transport taking into account:
2040 // 2.ExB at the wires
2041 // 3. nonisochronity
2043 // xyz and index must be already transformed to system 1
2046 fTPCParam->Transform1to2(xyz,index);
2049 Float_t driftl=xyz[2];
2050 if(driftl<0.01) driftl=0.01;
2051 driftl=TMath::Sqrt(driftl);
2052 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2053 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2054 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2055 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2056 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2060 if (fTPCParam->GetMWPCReadout()==kTRUE){
2062 fTPCParam->Transform2to2NearestWire(xyz,index);
2063 Float_t dx=xyz[0]-x1;
2064 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2066 //add nonisochronity (not implemented yet)
2070 ClassImp(AliTPCdigit)
2072 //_____________________________________________________________________________
2073 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2077 // Creates a TPC digit object
2079 fSector = digits[0];
2080 fPadRow = digits[1];
2083 fSignal = digits[4];
2089 //_____________________________________________________________________________
2090 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2094 // Creates a TPC hit object
2105 //________________________________________________________________________
2106 // Additional code because of the AliTPCTrackHits
2108 void AliTPC::MakeBranch2(Option_t *option,const char *file)
2111 // Create a new branch in the current Root Tree
2112 // The branch of fHits is automatically split
2113 // MI change 14.09.2000
2114 if (fHitType&2==0) return;
2115 char branchname[10];
2116 sprintf(branchname,"%s2",GetName());
2118 // Get the pointer to the header
2119 const char *cH = strstr(option,"H");
2121 if (fTrackHits && gAlice->TreeH() && cH) {
2122 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHits,
2123 gAlice->TreeH(),fBufferSize);
2124 gAlice->TreeH()->GetListOfBranches()->Add(branch);
2126 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2127 const char folder [] = "RunMC/Event/Data";
2129 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2130 Publish(folder,&fTrackHits,branchname);
2132 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2133 TDirectory *wd = gDirectory;
2135 TIter next( b->GetListOfBranches());
2136 while ((b=(TBranch*)next())) {
2141 cout << "Diverting branch " << branchname << " to file " << file << endl;
2146 void AliTPC::SetTreeAddress()
2148 if (fHitType&1) AliDetector::SetTreeAddress();
2149 if (fHitType&2) SetTreeAddress2();
2152 void AliTPC::SetTreeAddress2()
2155 // Set branch address for the TrackHits Tree
2158 char branchname[20];
2159 sprintf(branchname,"%s2",GetName());
2161 // Branch address for hit tree
2162 TTree *treeH = gAlice->TreeH();
2164 branch = treeH->GetBranch(branchname);
2165 if (branch) branch->SetAddress(&fTrackHits);
2169 void AliTPC::FinishPrimary()
2171 if (fTrackHits) fTrackHits->FlushHitStack();
2175 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2178 // add hit to the list
2181 int primary = gAlice->GetPrimary(track);
2182 gAlice->Particle(primary)->SetBit(kKeepBit);
2186 gAlice->FlagTrack(track);
2188 //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2189 //if (hit->fTrack!=rtrack)
2190 // cout<<"bad track number\n";
2192 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2193 hits[1],hits[2],(Int_t)hits[3]);
2196 void AliTPC::ResetHits()
2198 if (fHitType&1) AliDetector::ResetHits();
2199 if (fHitType&2) ResetHits2();
2202 void AliTPC::ResetHits2()
2206 if (fTrackHits) fTrackHits->Clear();
2209 AliHit* AliTPC::FirstHit(Int_t track)
2211 if (fHitType&2) return FirstHit2(track);
2212 return AliDetector::FirstHit(track);
2214 AliHit* AliTPC::NextHit()
2216 if (fHitType&2) return NextHit2();
2217 return AliDetector::NextHit();
2220 AliHit* AliTPC::FirstHit2(Int_t track)
2223 // Initialise the hit iterator
2224 // Return the address of the first hit for track
2225 // If track>=0 the track is read from disk
2226 // while if track<0 the first hit of the current
2227 // track is returned
2230 gAlice->ResetHits();
2231 gAlice->TreeH()->GetEvent(track);
2235 fTrackHits->First();
2236 return fTrackHits->GetHit();
2241 AliHit* AliTPC::NextHit2()
2244 //Return the next hit for the current track
2248 return fTrackHits->GetHit();
2254 void AliTPC::LoadPoints(Int_t)
2258 /* if(fHitType==1) return AliDetector::LoadPoints(a);
2261 if(fHitType==1) AliDetector::LoadPoints(a);
2262 else LoadPoints2(a);
2269 void AliTPC::RemapTrackHitIDs(Int_t *map)
2271 if (!fTrackHits) return;
2272 AliObjectArray * arr = fTrackHits->fTrackHitsInfo;
2273 for (UInt_t i=0;i<arr->GetSize();i++){
2274 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2275 info->fTrackID = map[info->fTrackID];
2281 //_____________________________________________________________________________
2282 void AliTPC::LoadPoints2(Int_t)
2285 // Store x, y, z of all hits in memory
2287 if (fTrackHits == 0) return;
2289 Int_t nhits = fTrackHits->GetEntriesFast();
2290 if (nhits == 0) return;
2291 Int_t tracks = gAlice->GetNtrack();
2292 if (fPoints == 0) fPoints = new TObjArray(tracks);
2295 Int_t *ntrk=new Int_t[tracks];
2296 Int_t *limi=new Int_t[tracks];
2297 Float_t **coor=new Float_t*[tracks];
2298 for(Int_t i=0;i<tracks;i++) {
2304 AliPoints *points = 0;
2307 Int_t chunk=nhits/4+1;
2309 // Loop over all the hits and store their position
2311 ahit = FirstHit2(-1);
2312 //for (Int_t hit=0;hit<nhits;hit++) {
2314 // ahit = (AliHit*)fHits->UncheckedAt(hit);
2315 trk=ahit->GetTrack();
2316 if(ntrk[trk]==limi[trk]) {
2318 // Initialise a new track
2319 fp=new Float_t[3*(limi[trk]+chunk)];
2321 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2322 delete [] coor[trk];
2329 fp[3*ntrk[trk] ] = ahit->X();
2330 fp[3*ntrk[trk]+1] = ahit->Y();
2331 fp[3*ntrk[trk]+2] = ahit->Z();
2336 for(trk=0; trk<tracks; ++trk) {
2338 points = new AliPoints();
2339 points->SetMarkerColor(GetMarkerColor());
2340 points->SetMarkerSize(GetMarkerSize());
2341 points->SetDetector(this);
2342 points->SetParticle(trk);
2343 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2344 fPoints->AddAt(points,trk);
2345 delete [] coor[trk];
2355 //_____________________________________________________________________________
2356 void AliTPC::LoadPoints3(Int_t)
2359 // Store x, y, z of all hits in memory
2360 // - only intersection point with pad row
2361 if (fTrackHits == 0) return;
2363 Int_t nhits = fTrackHits->GetEntriesFast();
2364 if (nhits == 0) return;
2365 Int_t tracks = gAlice->GetNtrack();
2366 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2367 fPoints->Expand(2*tracks);
2370 Int_t *ntrk=new Int_t[tracks];
2371 Int_t *limi=new Int_t[tracks];
2372 Float_t **coor=new Float_t*[tracks];
2373 for(Int_t i=0;i<tracks;i++) {
2379 AliPoints *points = 0;
2382 Int_t chunk=nhits/4+1;
2384 // Loop over all the hits and store their position
2386 ahit = FirstHit2(-1);
2387 //for (Int_t hit=0;hit<nhits;hit++) {
2391 // ahit = (AliHit*)fHits->UncheckedAt(hit);
2392 trk=ahit->GetTrack();
2393 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2394 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2395 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2396 if (currentrow!=lastrow){
2397 lastrow = currentrow;
2398 //later calculate intersection point
2399 if(ntrk[trk]==limi[trk]) {
2401 // Initialise a new track
2402 fp=new Float_t[3*(limi[trk]+chunk)];
2404 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2405 delete [] coor[trk];
2412 fp[3*ntrk[trk] ] = ahit->X();
2413 fp[3*ntrk[trk]+1] = ahit->Y();
2414 fp[3*ntrk[trk]+2] = ahit->Z();
2421 for(trk=0; trk<tracks; ++trk) {
2423 points = new AliPoints();
2424 points->SetMarkerColor(GetMarkerColor()+1);
2425 points->SetMarkerStyle(5);
2426 points->SetMarkerSize(0.2);
2427 points->SetDetector(this);
2428 points->SetParticle(trk);
2429 // points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
2430 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2431 fPoints->AddAt(points,tracks+trk);
2432 delete [] coor[trk];
2443 void AliTPC::FindTrackHitsIntersection(TClonesArray * arr)
2447 //fill clones array with intersection of current point with the
2452 const Int_t kcmaxhits=30000;
2453 TVector * xxxx = new TVector(kcmaxhits*4);
2454 TVector & xxx = *xxxx;
2455 Int_t maxhits = kcmaxhits;
2458 AliTPChit * tpcHit=0;
2459 tpcHit = (AliTPChit*)FirstHit2(-1);
2460 Int_t currentIndex=0;
2461 Int_t lastrow=-1; //last writen row
2464 if (tpcHit==0) continue;
2465 sector=tpcHit->fSector; // sector number
2466 ipart=tpcHit->Track();
2470 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
2471 Int_t index[3]={1,sector,0};
2472 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2473 if (currentrow<0) continue;
2474 if (lastrow<0) lastrow=currentrow;
2475 if (currentrow==lastrow){
2476 if ( currentIndex>=maxhits){
2478 xxx.ResizeTo(4*maxhits);
2480 xxx(currentIndex*4)=x[0];
2481 xxx(currentIndex*4+1)=x[1];
2482 xxx(currentIndex*4+2)=x[2];
2483 xxx(currentIndex*4+3)=tpcHit->fQ;
2487 if (currentIndex>2){
2499 for (Int_t index=0;index<currentIndex;index++){
2501 x=x2=x3=x4=xxx(index*4);
2509 sumy+=xxx(index*4+1);
2510 sumxy+=xxx(index*4+1)*x;
2511 sumx2y+=xxx(index*4+1)*x2;
2512 sumz+=xxx(index*4+2);
2513 sumxz+=xxx(index*4+2)*x;
2514 sumx2z+=xxx(index*4+2)*x2;
2515 sumq+=xxx(index*4+3);
2517 Float_t centralPad = (fTPCParam->GetNPads(sector,lastrow)-1)/2;
2518 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
2519 sumx2*(sumx*sumx3-sumx2*sumx2);
2521 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
2522 sumx2*(sumxy*sumx3-sumx2y*sumx2);
2523 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
2524 sumx2*(sumxz*sumx3-sumx2z*sumx2);
2526 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
2527 sumx2*(sumx*sumx2y-sumx2*sumxy);
2528 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
2529 sumx2*(sumx*sumx2z-sumx2*sumxz);
2531 Float_t y=detay/det+centralPad;
2532 Float_t z=detaz/det;
2533 Float_t by=detby/det; //y angle
2534 Float_t bz=detbz/det; //z angle
2535 sumy/=Float_t(currentIndex);
2536 sumz/=Float_t(currentIndex);
2538 AliComplexCluster cl;
2544 cl.fTracks[0]=ipart;
2546 AliTPCClustersRow * row = (fClustersArray->GetRow(sector,lastrow));
2547 if (row!=0) row->InsertCluster(&cl);
2550 } //end of calculating cluster for given row
2552 } // end of loop over hits
2556 //_______________________________________________________________________________
2557 void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
2559 // produces rec points from digits and writes them on the root file
2560 // AliTPCclusters.root
2562 TDirectory *cwd = gDirectory;
2565 AliTPCParam *dig=(AliTPCParam *)gDirectory->Get("75x40_100x60");
2567 cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl;
2569 if(!gSystem->Getenv("CONFIG_FILE")){
2570 out=TFile::Open("AliTPCclusters.root","recreate");
2576 tmp1=gSystem->Getenv("CONFIG_FILE_PREFIX");
2577 tmp2=gSystem->Getenv("CONFIG_OUTDIR");
2578 sprintf(tmp3,"%s%s/AliTPCclusters.root",tmp1,tmp2);
2579 out=TFile::Open(tmp3,"recreate");
2583 cout<<"AliTPC::Digits2Reco - determination of rec points begins"<<endl;
2586 for(Int_t iev=firstevent;iev<lastevent+1;iev++){
2588 printf("Processing event %d\n",iev);
2589 Digits2Clusters(out,iev);
2591 cout<<"AliTPC::Digits2Reco - determination of rec points ended"<<endl;