1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Time Projection Chamber //
21 // This class contains the basic functions for the Time Projection Chamber //
22 // detector. Functions specific to one particular geometry are //
23 // contained in the derived classes //
27 <img src="picts/AliTPCClass.gif">
32 ///////////////////////////////////////////////////////////////////////////////
36 #include <Riostream.h>
40 #include <TGeometry.h>
41 #include <TInterpreter.h>
45 #include <TObjectTable.h>
46 #include <TParticle.h>
53 #include <TVirtualMC.h>
57 #include "AliArrayBranch.h"
58 #include "AliClusters.h"
59 #include "AliComplexCluster.h"
60 #include "AliDigits.h"
62 #include "AliPoints.h"
64 #include "AliRunLoader.h"
65 #include "AliSimDigits.h"
68 #include "AliTPCClustersArray.h"
69 #include "AliTPCClustersRow.h"
70 #include "AliTPCDigitsArray.h"
71 #include "AliTPCLoader.h"
72 #include "AliTPCPRF2D.h"
73 #include "AliTPCParamSR.h"
74 #include "AliTPCRF1D.h"
75 #include "AliTPCTrackHits.h"
76 #include "AliTPCTrackHitsV2.h"
77 #include "AliTPCcluster.h"
78 #include "AliTrackReference.h"
80 #include "AliTPCDigitizer.h"
81 #include "AliTPCclustererMI.h"
82 #include "AliTPCtrackerMI.h"
83 #include "AliTPCpidESD.h"
88 //_____________________________________________________________________________
89 // helper class for fast matrix and vector manipulation - no range checking
90 // origin - Marian Ivanov
92 class AliTPCFastMatrix : public TMatrix {
94 AliTPCFastMatrix(Int_t rowlwb, Int_t rowupb, Int_t collwb, Int_t colupb);
95 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
96 Float_t & UncheckedAt(Int_t rown, Int_t coln) const {return fElements[(rown-fRowLwb)*fNcols+(coln-fColLwb)];} //fast acces
97 Float_t UncheckedAtFast(Int_t rown, Int_t coln) const {return fElements[(rown-fRowLwb)*fNcols+(coln-fColLwb)];} //fast acces
99 Float_t & UncheckedAt(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
100 Float_t UncheckedAtFast(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
104 AliTPCFastMatrix::AliTPCFastMatrix(Int_t rowlwb, Int_t rowupb, Int_t collwb, Int_t colupb):
105 TMatrix(rowlwb, rowupb,collwb,colupb)
108 //_____________________________________________________________________________
109 class AliTPCFastVector : public TVector {
111 AliTPCFastVector(Int_t size);
112 virtual ~AliTPCFastVector(){;}
113 Float_t & UncheckedAt(Int_t index) const {return fElements[index];} //fast acces
117 AliTPCFastVector::AliTPCFastVector(Int_t size):TVector(size){
120 //_____________________________________________________________________________
124 // Default constructor
135 fHitType = 2; //default CONTAINERS - based on ROOT structure
142 //_____________________________________________________________________________
143 AliTPC::AliTPC(const char *name, const char *title)
144 : AliDetector(name,title)
147 // Standard constructor
151 // Initialise arrays of hits and digits
152 fHits = new TClonesArray("AliTPChit", 176);
153 gAlice->GetMCApp()->AddHitList(fHits);
158 fTrackHits = new AliTPCTrackHitsV2;
159 fTrackHits->SetHitPrecision(0.002);
160 fTrackHits->SetStepPrecision(0.003);
161 fTrackHits->SetMaxDistance(100);
163 fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
164 fTrackHitsOld->SetHitPrecision(0.002);
165 fTrackHitsOld->SetStepPrecision(0.003);
166 fTrackHitsOld->SetMaxDistance(100);
173 // Initialise counters
179 // Initialise color attributes
180 SetMarkerColor(kYellow);
183 // Set TPC parameters
187 if (!strcmp(title,"Default")) {
188 fTPCParam = new AliTPCParamSR;
190 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
196 //_____________________________________________________________________________
197 AliTPC::AliTPC(const AliTPC& t):AliDetector(t){
199 // dummy copy constructor
212 delete fTrackHits; //MI 15.09.2000
213 delete fTrackHitsOld; //MI 10.12.2001
214 if (fNoiseTable) delete [] fNoiseTable;
218 //_____________________________________________________________________________
219 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
222 // Add a hit to the list
224 // TClonesArray &lhits = *fHits;
225 // new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
227 TClonesArray &lhits = *fHits;
228 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
231 AddHit2(track,vol,hits);
234 //_____________________________________________________________________________
235 void AliTPC::BuildGeometry()
239 // Build TPC ROOT TNode geometry for the event display
244 const int kColorTPC=19;
245 char name[5], title[25];
246 const Double_t kDegrad=TMath::Pi()/180;
247 const Double_t kRaddeg=180./TMath::Pi();
250 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
251 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
253 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
254 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
256 Int_t nLo = fTPCParam->GetNInnerSector()/2;
257 Int_t nHi = fTPCParam->GetNOuterSector()/2;
259 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
260 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
261 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
262 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
265 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
266 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
272 // Get ALICE top node
275 nTop=gAlice->GetGeometry()->GetNode("alice");
279 rl = fTPCParam->GetInnerRadiusLow();
280 ru = fTPCParam->GetInnerRadiusUp();
284 sprintf(name,"LS%2.2d",i);
286 sprintf(title,"TPC low sector %3d",i);
289 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
290 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
291 tubs->SetNumberOfDivisions(1);
293 nNode = new TNode(name,title,name,0,0,0,"");
294 nNode->SetLineColor(kColorTPC);
300 rl = fTPCParam->GetOuterRadiusLow();
301 ru = fTPCParam->GetOuterRadiusUp();
304 sprintf(name,"US%2.2d",i);
306 sprintf(title,"TPC upper sector %d",i);
308 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
309 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
310 tubs->SetNumberOfDivisions(1);
312 nNode = new TNode(name,title,name,0,0,0,"");
313 nNode->SetLineColor(kColorTPC);
319 //_____________________________________________________________________________
320 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t ) const
323 // Calculate distance from TPC to mouse on the display
329 void AliTPC::Clusters2Tracks() const
331 //-----------------------------------------------------------------
332 // This is a track finder.
333 //-----------------------------------------------------------------
334 Error("Clusters2Tracks",
335 "Dummy function ! Call AliTPCtracker::Clusters2Tracks(...) instead !");
339 //_____________________________________________________________________________
340 void AliTPC::CreateMaterials()
342 //-----------------------------------------------
343 // Create Materials for for TPC simulations
344 //-----------------------------------------------
346 //-----------------------------------------------------------------
347 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
348 //-----------------------------------------------------------------
350 Int_t iSXFLD=gAlice->Field()->Integ();
351 Float_t sXMGMX=gAlice->Field()->Max();
353 Float_t amat[5]; // atomic numbers
354 Float_t zmat[5]; // z
355 Float_t wmat[5]; // proportions
361 //***************** Gases *************************
363 //-------------------------------------------------
365 //-------------------------------------------------
376 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
386 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
389 //--------------------------------------------------------------
391 //--------------------------------------------------------------
408 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
410 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
425 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
427 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
443 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
445 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
447 //----------------------------------------------------------------
448 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
449 //----------------------------------------------------------------
455 Float_t rho,absl,x0,buf[1];
459 for(nc = 0;nc<fNoComp;nc++)
462 // retrive material constants
464 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,x0,absl,buf,nbuf);
469 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
471 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
472 density += fMixtProp[nc]*rho; // density of the mixture
476 // mixture proportions by weight!
478 for(nc = 0;nc<fNoComp;nc++)
481 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
483 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
484 apure[nnc] : amol[nnc])/am;
488 // Drift gases 1 - nonsensitive, 2 - sensitive
490 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
491 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
500 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
503 //----------------------------------------------------------------------
505 //----------------------------------------------------------------------
527 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
549 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
567 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
585 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
587 // SiO2 - used later for the glass fiber
599 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
608 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
617 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
626 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
644 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
663 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
665 // Epoxy - C14 H20 O3
682 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
690 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
694 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,x0,absl,buf,nbuf);
698 wmat[0]=0.644; // by weight!
701 density=0.5*(1.25+2.265);
703 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
707 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,x0,absl,buf,nbuf);
709 wmat[0]=0.725; // by weight!
714 AliMixture(39,"G10",amat,zmat,density,2,wmat);
719 //----------------------------------------------------------
720 // tracking media for gases
721 //----------------------------------------------------------
723 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
724 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
725 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
726 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
728 //-----------------------------------------------------------
729 // tracking media for solids
730 //-----------------------------------------------------------
732 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
733 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
734 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
735 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
736 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
737 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
738 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
739 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
740 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
741 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
742 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
743 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
747 void AliTPC::GenerNoise(Int_t tablesize)
750 //Generate table with noise
757 if (fNoiseTable) delete[] fNoiseTable;
758 fNoiseTable = new Float_t[tablesize];
759 fNoiseDepth = tablesize;
760 fCurrentNoise =0; //!index of the noise in the noise table
762 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
763 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
766 Float_t AliTPC::GetNoise()
768 // get noise from table
769 // if ((fCurrentNoise%10)==0)
770 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
771 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
772 return fNoiseTable[fCurrentNoise++];
773 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
777 Bool_t AliTPC::IsSectorActive(Int_t sec) const
780 // check if the sector is active
781 if (!fActiveSectors) return kTRUE;
782 else return fActiveSectors[sec];
785 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
787 // activate interesting sectors
788 SetTreeAddress();//just for security
789 if (fActiveSectors) delete [] fActiveSectors;
790 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
791 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
792 for (Int_t i=0;i<n;i++)
793 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
797 void AliTPC::SetActiveSectors(Int_t flag)
800 // activate sectors which were hitted by tracks
802 SetTreeAddress();//just for security
803 if (fHitType==0) return; // if Clones hit - not short volume ID information
804 if (fActiveSectors) delete [] fActiveSectors;
805 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
807 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
810 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
814 Fatal("SetActiveSectors","Can not find TreeH in folder");
817 if (fHitType>1) branch = TreeH()->GetBranch("TPC2");
818 else branch = TreeH()->GetBranch("TPC");
819 Stat_t ntracks = TreeH()->GetEntries();
820 // loop over all hits
821 if (GetDebug()) cout<<"\nAliTPC::SetActiveSectors(): Got "<<ntracks<<" tracks\n";
823 for(Int_t track=0;track<ntracks;track++)
827 if (fTrackHits && fHitType&4) {
828 TBranch * br1 = TreeH()->GetBranch("fVolumes");
829 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
830 br1->GetEvent(track);
831 br2->GetEvent(track);
832 Int_t *volumes = fTrackHits->GetVolumes();
833 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
834 fActiveSectors[volumes[j]]=kTRUE;
838 if (fTrackHitsOld && fHitType&2) {
839 TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
841 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
842 for (UInt_t j=0;j<ar->GetSize();j++){
843 fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
852 void AliTPC::Digits2Clusters(Int_t /*eventnumber*/) const
854 //-----------------------------------------------------------------
855 // This is a simple cluster finder.
856 //-----------------------------------------------------------------
857 Error("Digits2Clusters",
858 "Dummy function ! Call AliTPCclusterer::Digits2Clusters(...) instead !");
861 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
862 extern Double_t SigmaZ2(Double_t, Double_t);
863 //_____________________________________________________________________________
864 void AliTPC::Hits2Clusters(Int_t /*eventn*/)
866 //--------------------------------------------------------
867 // TPC simple cluster generator from hits
868 // obtained from the TPC Fast Simulator
869 // The point errors are taken from the parametrization
870 //--------------------------------------------------------
872 //-----------------------------------------------------------------
873 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
874 //-----------------------------------------------------------------
875 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
876 // Jouri.Belikov@cern.ch
877 //----------------------------------------------------------------
879 /////////////////////////////////////////////////////////////////////////////
881 //---------------------------------------------------------------------
882 // ALICE TPC Cluster Parameters
883 //--------------------------------------------------------------------
887 // Cluster width in rphi
888 const Float_t kACrphi=0.18322;
889 const Float_t kBCrphi=0.59551e-3;
890 const Float_t kCCrphi=0.60952e-1;
891 // Cluster width in z
892 const Float_t kACz=0.19081;
893 const Float_t kBCz=0.55938e-3;
894 const Float_t kCCz=0.30428;
898 cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
902 //if(fDefaults == 0) SetDefaults();
904 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
906 TParticle *particle; // pointer to a given particle
907 AliTPChit *tpcHit; // pointer to a sigle TPC hit
911 Float_t pl,pt,tanth,rpad,ratio;
914 //---------------------------------------------------------------
915 // Get the access to the tracks
916 //---------------------------------------------------------------
921 Fatal("Hits2Clusters","Can not find TreeH in folder");
926 Stat_t ntracks = tH->GetEntries();
928 //Switch to the output file
930 if (fLoader->TreeR() == 0x0) fLoader->MakeTree("R");
932 cout<<"fTPCParam->GetTitle() = "<<fTPCParam->GetTitle()<<endl;
934 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::fgkRunLoaderName);
936 //fTPCParam->Write(fTPCParam->GetTitle());
938 AliTPCClustersArray carray;
939 carray.Setup(fTPCParam);
940 carray.SetClusterType("AliTPCcluster");
941 carray.MakeTree(fLoader->TreeR());
943 Int_t nclusters=0; //cluster counter
945 //------------------------------------------------------------
946 // Loop over all sectors (72 sectors for 20 deg
947 // segmentation for both lower and upper sectors)
948 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
949 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
951 // First cluster for sector 0 starts at "0"
952 //------------------------------------------------------------
954 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
956 fTPCParam->AdjustCosSin(isec,cph,sph);
958 //------------------------------------------------------------
960 //------------------------------------------------------------
962 for(Int_t track=0;track<ntracks;track++){
966 // Get number of the TPC hits
968 tpcHit = (AliTPChit*)FirstHit(-1);
974 if (tpcHit->fQ == 0.) {
975 tpcHit = (AliTPChit*) NextHit();
976 continue; //information about track (I.Belikov)
978 sector=tpcHit->fSector; // sector number
981 tpcHit = (AliTPChit*) NextHit();
984 ipart=tpcHit->Track();
985 particle=gAlice->GetMCApp()->Particle(ipart);
988 if(pt < 1.e-9) pt=1.e-9;
990 tanth = TMath::Abs(tanth);
991 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
992 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
994 // space-point resolutions
996 sigmaRphi=SigmaY2(rpad,tanth,pt);
997 sigmaZ =SigmaZ2(rpad,tanth );
1001 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
1002 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
1004 // temporary protection
1006 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
1007 if(sigmaZ < 0.) sigmaZ=0.4e-3;
1008 if(clRphi < 0.) clRphi=2.5e-3;
1009 if(clZ < 0.) clZ=2.5e-5;
1014 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
1015 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
1017 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
1018 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
1019 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
1020 Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
1021 fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
1022 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
1023 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
1024 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
1025 if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->Z();
1026 xyz[2]=sigmaRphi; // fSigmaY2
1027 xyz[3]=sigmaZ; // fSigmaZ2
1028 xyz[4]=tpcHit->fQ; // q
1030 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
1031 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
1033 Int_t tracks[3]={tpcHit->Track(), -1, -1};
1034 AliTPCcluster cluster(tracks,xyz);
1036 clrow->InsertCluster(&cluster); nclusters++;
1038 tpcHit = (AliTPChit*)NextHit();
1041 } // end of loop over hits
1043 } // end of loop over tracks
1045 Int_t nrows=fTPCParam->GetNRow(isec);
1046 for (Int_t irow=0; irow<nrows; irow++) {
1047 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
1048 if (!clrow) continue;
1049 carray.StoreRow(isec,irow);
1050 carray.ClearRow(isec,irow);
1053 } // end of loop over sectors
1055 // cerr<<"Number of made clusters : "<<nclusters<<" \n";
1056 fLoader->WriteRecPoints("OVERWRITE");
1059 } // end of function
1061 //_________________________________________________________________
1062 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1064 //--------------------------------------------------------
1065 //calculate exact cross point of track and given pad row
1066 //resulting values are expressed in "digit" coordinata
1067 //--------------------------------------------------------
1069 //-----------------------------------------------------------------
1070 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1071 //-----------------------------------------------------------------
1073 if (fClustersArray==0){
1077 TParticle *particle; // pointer to a given particle
1078 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1079 // Int_t sector,nhits;
1081 const Int_t kcmaxhits=30000;
1082 AliTPCFastVector * xxxx = new AliTPCFastVector(kcmaxhits*4);
1083 AliTPCFastVector & xxx = *xxxx;
1084 Int_t maxhits = kcmaxhits;
1085 //construct array for each padrow
1086 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
1087 fClustersArray->CreateRow(isec,i);
1089 //---------------------------------------------------------------
1090 // Get the access to the tracks
1091 //---------------------------------------------------------------
1093 TTree *tH = TreeH();
1096 Fatal("Hits2Clusters","Can not find TreeH in folder");
1101 Stat_t ntracks = tH->GetEntries();
1102 Int_t npart = gAlice->GetMCApp()->GetNtrack();
1105 if (fHitType>1) branch = tH->GetBranch("TPC2");
1106 else branch = tH->GetBranch("TPC");
1108 //------------------------------------------------------------
1110 //------------------------------------------------------------
1112 for(Int_t track=0;track<ntracks;track++){
1113 Bool_t isInSector=kTRUE;
1115 isInSector = TrackInVolume(isec,track);
1116 if (!isInSector) continue;
1118 branch->GetEntry(track); // get next track
1120 // Get number of the TPC hits and a pointer
1124 Int_t currentIndex=0;
1125 Int_t lastrow=-1; //last writen row
1129 tpcHit = (AliTPChit*)FirstHit(-1);
1132 Int_t sector=tpcHit->fSector; // sector number
1134 tpcHit = (AliTPChit*) NextHit();
1138 ipart=tpcHit->Track();
1139 if (ipart<npart) particle=gAlice->GetMCApp()->Particle(ipart);
1143 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
1144 Int_t index[3]={1,isec,0};
1145 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
1146 if (currentrow<0) {tpcHit = (AliTPChit*)NextHit(); continue;}
1147 if (lastrow<0) lastrow=currentrow;
1148 if (currentrow==lastrow){
1149 if ( currentIndex>=maxhits){
1151 xxx.ResizeTo(4*maxhits);
1153 xxx(currentIndex*4)=x[0];
1154 xxx(currentIndex*4+1)=x[1];
1155 xxx(currentIndex*4+2)=x[2];
1156 xxx(currentIndex*4+3)=tpcHit->fQ;
1160 if (currentIndex>2){
1172 for (Int_t index=0;index<currentIndex;index++){
1174 x=x2=x3=x4=xxx(index*4);
1182 sumy+=xxx(index*4+1);
1183 sumxy+=xxx(index*4+1)*x;
1184 sumx2y+=xxx(index*4+1)*x2;
1185 sumz+=xxx(index*4+2);
1186 sumxz+=xxx(index*4+2)*x;
1187 sumx2z+=xxx(index*4+2)*x2;
1188 sumq+=xxx(index*4+3);
1190 Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1191 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1192 sumx2*(sumx*sumx3-sumx2*sumx2);
1194 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1195 sumx2*(sumxy*sumx3-sumx2y*sumx2);
1196 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1197 sumx2*(sumxz*sumx3-sumx2z*sumx2);
1199 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1200 sumx2*(sumx*sumx2y-sumx2*sumxy);
1201 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1202 sumx2*(sumx*sumx2z-sumx2*sumxz);
1204 if (TMath::Abs(det)<0.00001){
1205 tpcHit = (AliTPChit*)NextHit();
1209 Float_t y=detay/det+centralPad;
1210 Float_t z=detaz/det;
1211 Float_t by=detby/det; //y angle
1212 Float_t bz=detbz/det; //z angle
1213 sumy/=Float_t(currentIndex);
1214 sumz/=Float_t(currentIndex);
1216 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1218 AliComplexCluster* cl = new((AliComplexCluster*)row->Append()) AliComplexCluster ;
1219 // AliComplexCluster cl;
1225 cl->fTracks[0]=ipart;
1229 } //end of calculating cluster for given row
1232 tpcHit = (AliTPChit*)NextHit();
1233 } // end of loop over hits
1234 } // end of loop over tracks
1235 //write padrows to tree
1236 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1237 fClustersArray->StoreRow(isec,ii);
1238 fClustersArray->ClearRow(isec,ii);
1246 //______________________________________________________________________
1247 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
1249 return new AliTPCDigitizer(manager);
1252 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
1254 //create digits from summable digits
1255 GenerNoise(500000); //create teble with noise
1257 //conect tree with sSDigits
1258 TTree *t = fLoader->TreeS();
1262 fLoader->LoadSDigits("READ");
1263 t = fLoader->TreeS();
1266 Error("SDigits2Digits2","Can not get input TreeS");
1271 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1273 AliSimDigits digarr, *dummy=&digarr;
1274 TBranch* sdb = t->GetBranch("Segment");
1277 Error("SDigits2Digits2","Can not find branch with segments in TreeS.");
1281 sdb->SetAddress(&dummy);
1283 Stat_t nentries = t->GetEntries();
1285 // set zero suppression
1287 fTPCParam->SetZeroSup(2);
1289 // get zero suppression
1291 Int_t zerosup = fTPCParam->GetZeroSup();
1293 //make tree with digits
1295 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1296 arr->SetClass("AliSimDigits");
1297 arr->Setup(fTPCParam);
1298 arr->MakeTree(fLoader->TreeD());
1300 AliTPCParam * par = fTPCParam;
1302 //Loop over segments of the TPC
1304 for (Int_t n=0; n<nentries; n++) {
1307 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1308 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
1311 if (!IsSectorActive(sec))
1313 // cout<<n<<" NOT Active \n";
1318 // cout<<n<<" Active \n";
1320 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1321 Int_t nrows = digrow->GetNRows();
1322 Int_t ncols = digrow->GetNCols();
1324 digrow->ExpandBuffer();
1325 digarr.ExpandBuffer();
1326 digrow->ExpandTrackBuffer();
1327 digarr.ExpandTrackBuffer();
1330 Short_t * pamp0 = digarr.GetDigits();
1331 Int_t * ptracks0 = digarr.GetTracks();
1332 Short_t * pamp1 = digrow->GetDigits();
1333 Int_t * ptracks1 = digrow->GetTracks();
1334 Int_t nelems =nrows*ncols;
1335 Int_t saturation = fTPCParam->GetADCSat();
1336 //use internal structure of the AliDigits - for speed reason
1337 //if you cahnge implementation
1338 //of the Alidigits - it must be rewriten -
1339 for (Int_t i= 0; i<nelems; i++){
1340 // Float_t q = *pamp0;
1341 //q/=16.; //conversion faktor
1342 //Float_t noise= GetNoise();
1344 //q= TMath::Nint(q);
1345 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1347 if (q>saturation) q=saturation;
1349 //if (ptracks0[0]==0)
1352 ptracks1[0]=ptracks0[0];
1353 ptracks1[nelems]=ptracks0[nelems];
1354 ptracks1[2*nelems]=ptracks0[2*nelems];
1362 arr->StoreRow(sec,row);
1363 arr->ClearRow(sec,row);
1364 // cerr<<sec<<"\t"<<row<<"\n";
1369 fLoader->WriteDigits("OVERWRITE");
1373 //__________________________________________________________________
1374 void AliTPC::SetDefaults(){
1376 // setting the defaults
1379 // cerr<<"Setting default parameters...\n";
1381 // Set response functions
1384 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::fgkRunLoaderName);
1386 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1388 printf("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...\n");
1390 param = new AliTPCParamSR();
1393 param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1396 printf("No TPC parameters found\n");
1401 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1402 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1403 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1404 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1405 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1406 rf->SetOffset(3*param->GetZSigma());
1409 TDirectory *savedir=gDirectory;
1410 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1412 cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1417 prfinner->Read("prf_07504_Gati_056068_d02");
1418 //PH Set different names
1419 s=prfinner->GetGRF()->GetName();
1421 prfinner->GetGRF()->SetName(s.Data());
1423 prfouter1->Read("prf_10006_Gati_047051_d03");
1424 s=prfouter1->GetGRF()->GetName();
1426 prfouter1->GetGRF()->SetName(s.Data());
1428 prfouter2->Read("prf_15006_Gati_047051_d03");
1429 s=prfouter2->GetGRF()->GetName();
1431 prfouter2->GetGRF()->SetName(s.Data());
1436 param->SetInnerPRF(prfinner);
1437 param->SetOuter1PRF(prfouter1);
1438 param->SetOuter2PRF(prfouter2);
1439 param->SetTimeRF(rf);
1449 //__________________________________________________________________
1450 void AliTPC::Hits2Digits()
1453 // creates digits from hits
1456 fLoader->LoadHits("read");
1457 fLoader->LoadDigits("recreate");
1458 AliRunLoader* runLoader = fLoader->GetRunLoader();
1460 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1461 runLoader->GetEvent(iEvent);
1463 Hits2Digits(iEvent);
1466 fLoader->UnloadHits();
1467 fLoader->UnloadDigits();
1469 //__________________________________________________________________
1470 void AliTPC::Hits2Digits(Int_t eventnumber)
1472 //----------------------------------------------------
1473 // Loop over all sectors for a single event
1474 //----------------------------------------------------
1475 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::fgkRunLoaderName);
1476 rl->GetEvent(eventnumber);
1477 if (fLoader->TreeH() == 0x0)
1479 if(fLoader->LoadHits())
1481 Error("Hits2Digits","Can not load hits.");
1486 if (fLoader->TreeD() == 0x0 )
1488 fLoader->MakeTree("D");
1489 if (fLoader->TreeD() == 0x0 )
1491 Error("Hits2Digits","Can not get TreeD");
1496 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1497 GenerNoise(500000); //create teble with noise
1499 //setup TPCDigitsArray
1501 if(GetDigitsArray()) delete GetDigitsArray();
1503 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1504 arr->SetClass("AliSimDigits");
1505 arr->Setup(fTPCParam);
1507 arr->MakeTree(fLoader->TreeD());
1508 SetDigitsArray(arr);
1510 fDigitsSwitch=0; // standard digits
1512 // cerr<<"Digitizing TPC -- normal digits...\n";
1514 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1515 if (IsSectorActive(isec))
1517 if (fDebug) Info("Hits2Digits","Sector %d is active.",isec);
1518 Hits2DigitsSector(isec);
1522 if (fDebug) Info("Hits2Digits","Sector %d is NOT active.",isec);
1525 fLoader->WriteDigits("OVERWRITE");
1527 //this line prevents the crash in the similar one
1528 //on the beginning of this method
1529 //destructor attempts to reset the tree, which is deleted by the loader
1530 //need to be redesign
1531 if(GetDigitsArray()) delete GetDigitsArray();
1532 SetDigitsArray(0x0);
1536 //__________________________________________________________________
1537 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1540 //-----------------------------------------------------------
1541 // summable digits - 16 bit "ADC", no noise, no saturation
1542 //-----------------------------------------------------------
1544 //----------------------------------------------------
1545 // Loop over all sectors for a single event
1546 //----------------------------------------------------
1547 // AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::fgkRunLoaderName);
1549 AliRunLoader* rl = fLoader->GetRunLoader();
1551 rl->GetEvent(eventnumber);
1552 if (fLoader->TreeH() == 0x0)
1554 if(fLoader->LoadHits())
1556 Error("Hits2Digits","Can not load hits.");
1563 if (fLoader->TreeS() == 0x0 )
1565 fLoader->MakeTree("S");
1568 if(fDefaults == 0) SetDefaults();
1570 GenerNoise(500000); //create table with noise
1571 //setup TPCDigitsArray
1573 if(GetDigitsArray()) delete GetDigitsArray();
1576 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1577 arr->SetClass("AliSimDigits");
1578 arr->Setup(fTPCParam);
1579 arr->MakeTree(fLoader->TreeS());
1581 SetDigitsArray(arr);
1583 // cerr<<"Digitizing TPC -- summable digits...\n";
1585 fDigitsSwitch=1; // summable digits
1587 // set zero suppression to "0"
1589 fTPCParam->SetZeroSup(0);
1591 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1592 if (IsSectorActive(isec))
1594 // cout<<"Sector "<<isec<<" is active\n";
1595 Hits2DigitsSector(isec);
1598 fLoader->WriteSDigits("OVERWRITE");
1600 //this line prevents the crash in the similar one
1601 //on the beginning of this method
1602 //destructor attempts to reset the tree, which is deleted by the loader
1603 //need to be redesign
1604 if(GetDigitsArray()) delete GetDigitsArray();
1605 SetDigitsArray(0x0);
1607 //__________________________________________________________________
1609 void AliTPC::Hits2SDigits()
1612 //-----------------------------------------------------------
1613 // summable digits - 16 bit "ADC", no noise, no saturation
1614 //-----------------------------------------------------------
1616 fLoader->LoadHits("read");
1617 fLoader->LoadSDigits("recreate");
1618 AliRunLoader* runLoader = fLoader->GetRunLoader();
1620 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1621 runLoader->GetEvent(iEvent);
1624 Hits2SDigits2(iEvent);
1627 fLoader->UnloadHits();
1628 fLoader->UnloadSDigits();
1630 //_____________________________________________________________________________
1632 void AliTPC::Hits2DigitsSector(Int_t isec)
1634 //-------------------------------------------------------------------
1635 // TPC conversion from hits to digits.
1636 //-------------------------------------------------------------------
1638 //-----------------------------------------------------------------
1639 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1640 //-----------------------------------------------------------------
1642 //-------------------------------------------------------
1643 // Get the access to the track hits
1644 //-------------------------------------------------------
1646 // check if the parameters are set - important if one calls this method
1647 // directly, not from the Hits2Digits
1649 if(fDefaults == 0) SetDefaults();
1651 TTree *tH = TreeH(); // pointer to the hits tree
1654 Fatal("Hits2DigitsSector","Can not find TreeH in folder");
1658 Stat_t ntracks = tH->GetEntries();
1662 //-------------------------------------------
1663 // Only if there are any tracks...
1664 //-------------------------------------------
1668 //printf("*** Processing sector number %d ***\n",isec);
1670 Int_t nrows =fTPCParam->GetNRow(isec);
1672 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1674 MakeSector(isec,nrows,tH,ntracks,row);
1676 //--------------------------------------------------------
1677 // Digitize this sector, row by row
1678 // row[i] is the pointer to the TObjArray of AliTPCFastVectors,
1679 // each one containing electrons accepted on this
1680 // row, assigned into tracks
1681 //--------------------------------------------------------
1685 if (fDigitsArray->GetTree()==0)
1687 Fatal("Hits2DigitsSector","Tree not set in fDigitsArray");
1690 for (i=0;i<nrows;i++){
1692 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1694 DigitizeRow(i,isec,row);
1696 fDigitsArray->StoreRow(isec,i);
1698 Int_t ndig = dig->GetDigitSize();
1701 printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1703 fDigitsArray->ClearRow(isec,i);
1706 } // end of the sector digitization
1708 for(i=0;i<nrows+2;i++){
1713 delete [] row; // delete the array of pointers to TObjArray-s
1717 } // end of Hits2DigitsSector
1720 //_____________________________________________________________________________
1721 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1723 //-----------------------------------------------------------
1724 // Single row digitization, coupling from the neighbouring
1725 // rows taken into account
1726 //-----------------------------------------------------------
1728 //-----------------------------------------------------------------
1729 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1730 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1731 //-----------------------------------------------------------------
1734 Float_t zerosup = fTPCParam->GetZeroSup();
1735 // Int_t nrows =fTPCParam->GetNRow(isec);
1736 fCurrentIndex[1]= isec;
1739 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1740 Int_t nofTbins = fTPCParam->GetMaxTBin();
1741 Int_t indexRange[4];
1743 // Integrated signal for this row
1744 // and a single track signal
1747 AliTPCFastMatrix *m1 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // integrated
1748 AliTPCFastMatrix *m2 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // single
1750 AliTPCFastMatrix &total = *m1;
1752 // Array of pointers to the label-signal list
1754 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1755 Float_t **pList = new Float_t* [nofDigits];
1759 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1763 //Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1764 //Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1767 for (Int_t row= row1;row<=row2;row++){
1768 Int_t nTracks= rows[row]->GetEntries();
1769 for (i1=0;i1<nTracks;i1++){
1770 fCurrentIndex[2]= row;
1771 fCurrentIndex[3]=irow+1;
1773 m2->Zero(); // clear single track signal matrix
1774 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1775 GetList(trackLabel,nofPads,m2,indexRange,pList);
1777 else GetSignal(rows[row],i1,0,m1,indexRange);
1783 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1785 Float_t fzerosup = zerosup+0.5;
1786 for(Int_t it=0;it<nofTbins;it++){
1787 Float_t *pq = &(total.UncheckedAt(0,it));
1788 for(Int_t ip=0;ip<nofPads;ip++){
1792 if(fDigitsSwitch == 0){
1794 if(q <=fzerosup) continue; // do not fill zeros
1796 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1801 if(q <= 0.) continue; // do not fill zeros
1802 if(q>2000.) q=2000.;
1808 // "real" signal or electronic noise (list = -1)?
1811 for(Int_t j1=0;j1<3;j1++){
1812 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1817 <A NAME="AliDigits"></A>
1818 using of AliDigits object
1821 dig->SetDigitFast((Short_t)q,it,ip);
1822 if (fDigitsArray->IsSimulated())
1824 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1825 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1826 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1830 } // end of loop over time buckets
1831 } // end of lop over pads
1834 // This row has been digitized, delete nonused stuff
1837 for(lp=0;lp<nofDigits;lp++){
1838 if(pList[lp]) delete [] pList[lp];
1847 } // end of DigitizeRow
1849 //_____________________________________________________________________________
1851 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1852 AliTPCFastMatrix *m1, AliTPCFastMatrix *m2,Int_t *indexRange)
1855 //---------------------------------------------------------------
1856 // Calculates 2-D signal (pad,time) for a single track,
1857 // returns a pointer to the signal matrix and the track label
1858 // No digitization is performed at this level!!!
1859 //---------------------------------------------------------------
1861 //-----------------------------------------------------------------
1862 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1863 // Modified: Marian Ivanov
1864 //-----------------------------------------------------------------
1866 AliTPCFastVector *tv;
1868 tv = (AliTPCFastVector*)p1->At(ntr); // pointer to a track
1869 AliTPCFastVector &v = *tv;
1871 Float_t label = v(0);
1872 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1)-1)/2;
1874 Int_t nElectrons = (tv->GetNrows()-1)/4;
1875 indexRange[0]=9999; // min pad
1876 indexRange[1]=-1; // max pad
1877 indexRange[2]=9999; //min time
1878 indexRange[3]=-1; // max time
1880 AliTPCFastMatrix &signal = *m1;
1881 AliTPCFastMatrix &total = *m2;
1883 // Loop over all electrons
1885 for(Int_t nel=0; nel<nElectrons; nel++){
1887 Float_t aval = v(idx+4);
1888 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1889 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1890 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1892 Int_t *index = fTPCParam->GetResBin(0);
1893 Float_t *weight = & (fTPCParam->GetResWeight(0));
1895 if (n>0) for (Int_t i =0; i<n; i++){
1896 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1899 Int_t time=index[2];
1900 Float_t qweight = *(weight)*eltoadcfac;
1902 if (m1!=0) signal.UncheckedAt(pad,time)+=qweight;
1903 total.UncheckedAt(pad,time)+=qweight;
1904 if (indexRange[0]>pad) indexRange[0]=pad;
1905 if (indexRange[1]<pad) indexRange[1]=pad;
1906 if (indexRange[2]>time) indexRange[2]=time;
1907 if (indexRange[3]<time) indexRange[3]=time;
1914 } // end of loop over electrons
1916 return label; // returns track label when finished
1919 //_____________________________________________________________________________
1920 void AliTPC::GetList(Float_t label,Int_t np,AliTPCFastMatrix *m,
1921 Int_t *indexRange, Float_t **pList)
1923 //----------------------------------------------------------------------
1924 // Updates the list of tracks contributing to digits for a given row
1925 //----------------------------------------------------------------------
1927 //-----------------------------------------------------------------
1928 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1929 //-----------------------------------------------------------------
1931 AliTPCFastMatrix &signal = *m;
1933 // lop over nonzero digits
1935 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1936 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1939 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1941 if(signal(ip,it)<0.5) continue;
1944 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1946 if(!pList[globalIndex]){
1949 // Create new list (6 elements - 3 signals and 3 labels),
1952 pList[globalIndex] = new Float_t [6];
1956 *pList[globalIndex] = -1.;
1957 *(pList[globalIndex]+1) = -1.;
1958 *(pList[globalIndex]+2) = -1.;
1959 *(pList[globalIndex]+3) = -1.;
1960 *(pList[globalIndex]+4) = -1.;
1961 *(pList[globalIndex]+5) = -1.;
1964 *pList[globalIndex] = label;
1965 *(pList[globalIndex]+3) = signal(ip,it);
1969 // check the signal magnitude
1971 Float_t highest = *(pList[globalIndex]+3);
1972 Float_t middle = *(pList[globalIndex]+4);
1973 Float_t lowest = *(pList[globalIndex]+5);
1976 // compare the new signal with already existing list
1979 if(signal(ip,it)<lowest) continue; // neglect this track
1983 if (signal(ip,it)>highest){
1984 *(pList[globalIndex]+5) = middle;
1985 *(pList[globalIndex]+4) = highest;
1986 *(pList[globalIndex]+3) = signal(ip,it);
1988 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1989 *(pList[globalIndex]+1) = *pList[globalIndex];
1990 *pList[globalIndex] = label;
1992 else if (signal(ip,it)>middle){
1993 *(pList[globalIndex]+5) = middle;
1994 *(pList[globalIndex]+4) = signal(ip,it);
1996 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1997 *(pList[globalIndex]+1) = label;
2000 *(pList[globalIndex]+5) = signal(ip,it);
2001 *(pList[globalIndex]+2) = label;
2005 } // end of loop over pads
2006 } // end of loop over time bins
2011 //___________________________________________________________________
2012 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
2013 Stat_t ntracks,TObjArray **row)
2016 //-----------------------------------------------------------------
2017 // Prepares the sector digitization, creates the vectors of
2018 // tracks for each row of this sector. The track vector
2019 // contains the track label and the position of electrons.
2020 //-----------------------------------------------------------------
2022 //-----------------------------------------------------------------
2023 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2024 //-----------------------------------------------------------------
2026 Float_t gasgain = fTPCParam->GetGasGain();
2030 AliTPChit *tpcHit; // pointer to a sigle TPC hit
2033 if (fHitType>1) branch = TH->GetBranch("TPC2");
2034 else branch = TH->GetBranch("TPC");
2037 //----------------------------------------------
2038 // Create TObjArray-s, one for each row,
2039 // each TObjArray will store the AliTPCFastVectors
2040 // of electrons, one AliTPCFastVectors per each track.
2041 //----------------------------------------------
2043 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
2044 AliTPCFastVector **tracks = new AliTPCFastVector* [nrows+2]; //pointers to the track vectors
2046 for(i=0; i<nrows+2; i++){
2047 row[i] = new TObjArray;
2054 //--------------------------------------------------------------------
2055 // Loop over tracks, the "track" contains the full history
2056 //--------------------------------------------------------------------
2058 Int_t previousTrack,currentTrack;
2059 previousTrack = -1; // nothing to store so far!
2061 for(Int_t track=0;track<ntracks;track++){
2062 Bool_t isInSector=kTRUE;
2064 isInSector = TrackInVolume(isec,track);
2065 if (!isInSector) continue;
2067 branch->GetEntry(track); // get next track
2071 tpcHit = (AliTPChit*)FirstHit(-1);
2073 //--------------------------------------------------------------
2075 //--------------------------------------------------------------
2080 Int_t sector=tpcHit->fSector; // sector number
2082 tpcHit = (AliTPChit*) NextHit();
2086 currentTrack = tpcHit->Track(); // track number
2089 if(currentTrack != previousTrack){
2091 // store already filled fTrack
2093 for(i=0;i<nrows+2;i++){
2094 if(previousTrack != -1){
2095 if(nofElectrons[i]>0){
2096 AliTPCFastVector &v = *tracks[i];
2097 v(0) = previousTrack;
2098 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2099 row[i]->Add(tracks[i]);
2102 delete tracks[i]; // delete empty AliTPCFastVector
2108 tracks[i] = new AliTPCFastVector(481); // AliTPCFastVectors for the next fTrack
2110 } // end of loop over rows
2112 previousTrack=currentTrack; // update track label
2115 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2117 //---------------------------------------------------
2118 // Calculate the electron attachment probability
2119 //---------------------------------------------------
2122 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
2123 /fTPCParam->GetDriftV();
2125 Float_t attProb = fTPCParam->GetAttCoef()*
2126 fTPCParam->GetOxyCont()*time; // fraction!
2128 //-----------------------------------------------
2129 // Loop over electrons
2130 //-----------------------------------------------
2133 for(Int_t nel=0;nel<qI;nel++){
2134 // skip if electron lost due to the attachment
2135 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2140 // protection for the nonphysical avalanche size (10**6 maximum)
2142 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2143 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2146 TransportElectron(xyz,index);
2148 fTPCParam->GetPadRow(xyz,index);
2149 // row 0 - cross talk from the innermost row
2150 // row fNRow+1 cross talk from the outermost row
2151 rowNumber = index[2]+1;
2152 //transform position to local digit coordinates
2153 //relative to nearest pad row
2154 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
2156 if (isec <fTPCParam->GetNInnerSector()) {
2157 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2158 y1 = fTPCParam->GetYInner(rowNumber);
2161 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2162 y1 = fTPCParam->GetYOuter(rowNumber);
2164 // gain inefficiency at the wires edges - linear
2167 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.));
2169 nofElectrons[rowNumber]++;
2170 //----------------------------------
2171 // Expand vector if necessary
2172 //----------------------------------
2173 if(nofElectrons[rowNumber]>120){
2174 Int_t range = tracks[rowNumber]->GetNrows();
2175 if((nofElectrons[rowNumber])>(range-1)/4){
2177 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
2181 AliTPCFastVector &v = *tracks[rowNumber];
2182 Int_t idx = 4*nofElectrons[rowNumber]-3;
2183 Real_t * position = &(((AliTPCFastVector&)v).UncheckedAt(idx)); //make code faster
2184 memcpy(position,xyz,4*sizeof(Float_t));
2186 } // end of loop over electrons
2188 tpcHit = (AliTPChit*)NextHit();
2190 } // end of loop over hits
2191 } // end of loop over tracks
2194 // store remaining track (the last one) if not empty
2197 for(i=0;i<nrows+2;i++){
2198 if(nofElectrons[i]>0){
2199 AliTPCFastVector &v = *tracks[i];
2200 v(0) = previousTrack;
2201 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2202 row[i]->Add(tracks[i]);
2211 delete [] nofElectrons;
2214 } // end of MakeSector
2217 //_____________________________________________________________________________
2221 // Initialise TPC detector after definition of geometry
2226 printf("\n%s: ",ClassName());
2227 for(i=0;i<35;i++) printf("*");
2228 printf(" TPC_INIT ");
2229 for(i=0;i<35;i++) printf("*");
2230 printf("\n%s: ",ClassName());
2232 for(i=0;i<80;i++) printf("*");
2237 //_____________________________________________________________________________
2238 void AliTPC::MakeBranch(Option_t* option)
2241 // Create Tree branches for the TPC.
2243 if(GetDebug()) Info("MakeBranch","");
2244 Int_t buffersize = 4000;
2245 char branchname[10];
2246 sprintf(branchname,"%s",GetName());
2248 const char *h = strstr(option,"H");
2250 if ( h && (fHitType<=1) && (fHits == 0x0)) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2252 AliDetector::MakeBranch(option);
2254 const char *d = strstr(option,"D");
2256 if (fDigits && fLoader->TreeD() && d)
2258 MakeBranchInTree(gAlice->TreeD(), branchname, &fDigits, buffersize, 0);
2261 if (fHitType>1) MakeBranch2(option,0); // MI change 14.09.2000
2264 //_____________________________________________________________________________
2265 void AliTPC::ResetDigits()
2268 // Reset number of digits and the digits array for this detector
2271 if (fDigits) fDigits->Clear();
2274 //_____________________________________________________________________________
2275 void AliTPC::SetSecAL(Int_t sec)
2277 //---------------------------------------------------
2278 // Activate/deactivate selection for lower sectors
2279 //---------------------------------------------------
2281 //-----------------------------------------------------------------
2282 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2283 //-----------------------------------------------------------------
2287 //_____________________________________________________________________________
2288 void AliTPC::SetSecAU(Int_t sec)
2290 //----------------------------------------------------
2291 // Activate/deactivate selection for upper sectors
2292 //---------------------------------------------------
2294 //-----------------------------------------------------------------
2295 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2296 //-----------------------------------------------------------------
2300 //_____________________________________________________________________________
2301 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
2303 //----------------------------------------
2304 // Select active lower sectors
2305 //----------------------------------------
2307 //-----------------------------------------------------------------
2308 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2309 //-----------------------------------------------------------------
2319 //_____________________________________________________________________________
2320 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
2321 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
2322 Int_t s11 , Int_t s12)
2324 //--------------------------------
2325 // Select active upper sectors
2326 //--------------------------------
2328 //-----------------------------------------------------------------
2329 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2330 //-----------------------------------------------------------------
2346 //_____________________________________________________________________________
2347 void AliTPC::SetSens(Int_t sens)
2350 //-------------------------------------------------------------
2351 // Activates/deactivates the sensitive strips at the center of
2352 // the pad row -- this is for the space-point resolution calculations
2353 //-------------------------------------------------------------
2355 //-----------------------------------------------------------------
2356 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2357 //-----------------------------------------------------------------
2363 void AliTPC::SetSide(Float_t side=0.)
2365 // choice of the TPC side
2370 //____________________________________________________________________________
2371 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2372 Float_t p2,Float_t p3)
2375 // gax mixture definition
2389 //_____________________________________________________________________________
2391 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2394 // electron transport taking into account:
2396 // 2.ExB at the wires
2397 // 3. nonisochronity
2399 // xyz and index must be already transformed to system 1
2402 fTPCParam->Transform1to2(xyz,index);
2405 Float_t driftl=xyz[2];
2406 if(driftl<0.01) driftl=0.01;
2407 driftl=TMath::Sqrt(driftl);
2408 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2409 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2410 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2411 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2412 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2416 if (fTPCParam->GetMWPCReadout()==kTRUE){
2417 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2418 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2420 //add nonisochronity (not implemented yet)
2423 ClassImp(AliTPCdigit)
2425 //_____________________________________________________________________________
2426 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2430 // Creates a TPC digit object
2432 fSector = digits[0];
2433 fPadRow = digits[1];
2436 fSignal = digits[4];
2442 //_____________________________________________________________________________
2443 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2447 // Creates a TPC hit object
2457 //________________________________________________________________________
2458 // Additional code because of the AliTPCTrackHitsV2
2460 void AliTPC::MakeBranch2(Option_t *option,const char */*file*/)
2463 // Create a new branch in the current Root Tree
2464 // The branch of fHits is automatically split
2465 // MI change 14.09.2000
2466 if(GetDebug()) Info("MakeBranch2","");
2467 if (fHitType<2) return;
2468 char branchname[10];
2469 sprintf(branchname,"%s2",GetName());
2471 // Get the pointer to the header
2472 const char *cH = strstr(option,"H");
2474 if (fTrackHits && TreeH() && cH && fHitType&4)
2476 if(GetDebug()) Info("MakeBranch2","Making branch for Type 4 Hits");
2477 TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2480 if (fTrackHitsOld && TreeH() && cH && fHitType&2)
2482 if(GetDebug()) Info("MakeBranch2","Making branch for Type 2 Hits");
2483 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2484 TreeH(),fBufferSize,99);
2485 TreeH()->GetListOfBranches()->Add(branch);
2489 void AliTPC::SetTreeAddress()
2491 //Sets tree address for hits
2494 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2495 AliDetector::SetTreeAddress();
2497 if (fHitType>1) SetTreeAddress2();
2500 void AliTPC::SetTreeAddress2()
2503 // Set branch address for the TrackHits Tree
2505 if(GetDebug()) Info("SetTreeAddress2","");
2508 char branchname[20];
2509 sprintf(branchname,"%s2",GetName());
2511 // Branch address for hit tree
2512 TTree *treeH = TreeH();
2513 if ((treeH)&&(fHitType&4)) {
2514 branch = treeH->GetBranch(branchname);
2517 branch->SetAddress(&fTrackHits);
2518 if (GetDebug()) Info("SetTreeAddress2","fHitType&4 Setting");
2521 if (GetDebug()) Info("SetTreeAddress2","fHitType&4 Failed (can not find branch)");
2524 if ((treeH)&&(fHitType&2)) {
2525 branch = treeH->GetBranch(branchname);
2528 branch->SetAddress(&fTrackHitsOld);
2529 if (GetDebug()) Info("SetTreeAddress2","fHitType&2 Setting");
2531 else if (GetDebug())
2532 Info("SetTreeAddress2","fHitType&2 Failed (can not find branch)");
2534 //set address to TREETR
2536 TTree *treeTR = TreeTR();
2537 if (treeTR && fTrackReferences) {
2538 branch = treeTR->GetBranch(GetName());
2539 if (branch) branch->SetAddress(&fTrackReferences);
2544 void AliTPC::FinishPrimary()
2546 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2547 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2551 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2554 // add hit to the list
2557 int primary = gAlice->GetMCApp()->GetPrimary(track);
2558 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2562 gAlice->GetMCApp()->FlagTrack(track);
2564 //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2565 //if (hit->fTrack!=rtrack)
2566 // cout<<"bad track number\n";
2567 if (fTrackHits && fHitType&4)
2568 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2569 hits[1],hits[2],(Int_t)hits[3]);
2570 if (fTrackHitsOld &&fHitType&2 )
2571 fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2572 hits[1],hits[2],(Int_t)hits[3]);
2576 void AliTPC::ResetHits()
2578 if (fHitType&1) AliDetector::ResetHits();
2579 if (fHitType>1) ResetHits2();
2582 void AliTPC::ResetHits2()
2586 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2587 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2591 AliHit* AliTPC::FirstHit(Int_t track)
2593 if (fHitType>1) return FirstHit2(track);
2594 return AliDetector::FirstHit(track);
2596 AliHit* AliTPC::NextHit()
2601 if (fHitType>1) return NextHit2();
2603 return AliDetector::NextHit();
2606 AliHit* AliTPC::FirstHit2(Int_t track)
2609 // Initialise the hit iterator
2610 // Return the address of the first hit for track
2611 // If track>=0 the track is read from disk
2612 // while if track<0 the first hit of the current
2613 // track is returned
2616 gAlice->ResetHits();
2617 TreeH()->GetEvent(track);
2620 if (fTrackHits && fHitType&4) {
2621 fTrackHits->First();
2622 return fTrackHits->GetHit();
2624 if (fTrackHitsOld && fHitType&2) {
2625 fTrackHitsOld->First();
2626 return fTrackHitsOld->GetHit();
2632 AliHit* AliTPC::NextHit2()
2635 //Return the next hit for the current track
2638 if (fTrackHitsOld && fHitType&2) {
2639 fTrackHitsOld->Next();
2640 return fTrackHitsOld->GetHit();
2644 return fTrackHits->GetHit();
2650 void AliTPC::LoadPoints(Int_t)
2654 /* if(fHitType==1) return AliDetector::LoadPoints(a);
2657 if(fHitType==1) AliDetector::LoadPoints(a);
2658 else LoadPoints2(a);
2665 void AliTPC::RemapTrackHitIDs(Int_t *map)
2670 if (!fTrackHits) return;
2672 if (fTrackHitsOld && fHitType&2){
2673 AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2674 for (UInt_t i=0;i<arr->GetSize();i++){
2675 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2676 info->fTrackID = map[info->fTrackID];
2679 if (fTrackHitsOld && fHitType&4){
2680 TClonesArray * arr = fTrackHits->GetArray();;
2681 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2682 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2683 info->fTrackID = map[info->fTrackID];
2688 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2690 //return bool information - is track in given volume
2691 //load only part of the track information
2692 //return true if current track is in volume
2695 if (fTrackHitsOld && fHitType&2) {
2696 TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
2697 br->GetEvent(track);
2698 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2699 for (UInt_t j=0;j<ar->GetSize();j++){
2700 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2704 if (fTrackHits && fHitType&4) {
2705 TBranch * br1 = TreeH()->GetBranch("fVolumes");
2706 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
2707 br2->GetEvent(track);
2708 br1->GetEvent(track);
2709 Int_t *volumes = fTrackHits->GetVolumes();
2710 Int_t nvolumes = fTrackHits->GetNVolumes();
2711 if (!volumes && nvolumes>0) {
2712 printf("Problematic track\t%d\t%d",track,nvolumes);
2715 for (Int_t j=0;j<nvolumes; j++)
2716 if (volumes[j]==id) return kTRUE;
2720 TBranch * br = TreeH()->GetBranch("fSector");
2721 br->GetEvent(track);
2722 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2723 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2730 //_____________________________________________________________________________
2731 void AliTPC::LoadPoints2(Int_t)
2734 // Store x, y, z of all hits in memory
2736 if (fTrackHits == 0 && fTrackHitsOld==0) return;
2739 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2740 if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2742 if (nhits == 0) return;
2743 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2744 if (fPoints == 0) fPoints = new TObjArray(tracks);
2747 Int_t *ntrk=new Int_t[tracks];
2748 Int_t *limi=new Int_t[tracks];
2749 Float_t **coor=new Float_t*[tracks];
2750 for(Int_t i=0;i<tracks;i++) {
2756 AliPoints *points = 0;
2759 Int_t chunk=nhits/4+1;
2761 // Loop over all the hits and store their position
2763 ahit = FirstHit2(-1);
2765 trk=ahit->GetTrack();
2766 if(ntrk[trk]==limi[trk]) {
2768 // Initialise a new track
2769 fp=new Float_t[3*(limi[trk]+chunk)];
2771 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2772 delete [] coor[trk];
2779 fp[3*ntrk[trk] ] = ahit->X();
2780 fp[3*ntrk[trk]+1] = ahit->Y();
2781 fp[3*ntrk[trk]+2] = ahit->Z();
2789 for(trk=0; trk<tracks; ++trk) {
2791 points = new AliPoints();
2792 points->SetMarkerColor(GetMarkerColor());
2793 points->SetMarkerSize(GetMarkerSize());
2794 points->SetDetector(this);
2795 points->SetParticle(trk);
2796 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2797 fPoints->AddAt(points,trk);
2798 delete [] coor[trk];
2808 //_____________________________________________________________________________
2809 void AliTPC::LoadPoints3(Int_t)
2812 // Store x, y, z of all hits in memory
2813 // - only intersection point with pad row
2814 if (fTrackHits == 0) return;
2816 Int_t nhits = fTrackHits->GetEntriesFast();
2817 if (nhits == 0) return;
2818 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2819 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2820 fPoints->Expand(2*tracks);
2823 Int_t *ntrk=new Int_t[tracks];
2824 Int_t *limi=new Int_t[tracks];
2825 Float_t **coor=new Float_t*[tracks];
2826 for(Int_t i=0;i<tracks;i++) {
2832 AliPoints *points = 0;
2835 Int_t chunk=nhits/4+1;
2837 // Loop over all the hits and store their position
2839 ahit = FirstHit2(-1);
2840 //for (Int_t hit=0;hit<nhits;hit++) {
2844 // ahit = (AliHit*)fHits->UncheckedAt(hit);
2845 trk=ahit->GetTrack();
2846 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2847 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2848 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2849 if (currentrow!=lastrow){
2850 lastrow = currentrow;
2851 //later calculate intersection point
2852 if(ntrk[trk]==limi[trk]) {
2854 // Initialise a new track
2855 fp=new Float_t[3*(limi[trk]+chunk)];
2857 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2858 delete [] coor[trk];
2865 fp[3*ntrk[trk] ] = ahit->X();
2866 fp[3*ntrk[trk]+1] = ahit->Y();
2867 fp[3*ntrk[trk]+2] = ahit->Z();
2874 for(trk=0; trk<tracks; ++trk) {
2876 points = new AliPoints();
2877 points->SetMarkerColor(GetMarkerColor()+1);
2878 points->SetMarkerStyle(5);
2879 points->SetMarkerSize(0.2);
2880 points->SetDetector(this);
2881 points->SetParticle(trk);
2882 // points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
2883 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2884 fPoints->AddAt(points,tracks+trk);
2885 delete [] coor[trk];
2896 void AliTPC::FindTrackHitsIntersection(TClonesArray * /*arr*/)
2900 //fill clones array with intersection of current point with the
2905 const Int_t kcmaxhits=30000;
2906 AliTPCFastVector * xxxx = new AliTPCFastVector(kcmaxhits*4);
2907 AliTPCFastVector & xxx = *xxxx;
2908 Int_t maxhits = kcmaxhits;
2911 AliTPChit * tpcHit=0;
2912 tpcHit = (AliTPChit*)FirstHit2(-1);
2913 Int_t currentIndex=0;
2914 Int_t lastrow=-1; //last writen row
2917 if (tpcHit==0) continue;
2918 sector=tpcHit->fSector; // sector number
2919 ipart=tpcHit->Track();
2923 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
2924 Int_t index[3]={1,sector,0};
2925 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2926 if (currentrow<0) continue;
2927 if (lastrow<0) lastrow=currentrow;
2928 if (currentrow==lastrow){
2929 if ( currentIndex>=maxhits){
2931 xxx.ResizeTo(4*maxhits);
2933 xxx(currentIndex*4)=x[0];
2934 xxx(currentIndex*4+1)=x[1];
2935 xxx(currentIndex*4+2)=x[2];
2936 xxx(currentIndex*4+3)=tpcHit->fQ;
2940 if (currentIndex>2){
2952 for (Int_t index=0;index<currentIndex;index++){
2954 x=x2=x3=x4=xxx(index*4);
2962 sumy+=xxx(index*4+1);
2963 sumxy+=xxx(index*4+1)*x;
2964 sumx2y+=xxx(index*4+1)*x2;
2965 sumz+=xxx(index*4+2);
2966 sumxz+=xxx(index*4+2)*x;
2967 sumx2z+=xxx(index*4+2)*x2;
2968 sumq+=xxx(index*4+3);
2970 Float_t centralPad = (fTPCParam->GetNPads(sector,lastrow)-1)/2;
2971 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
2972 sumx2*(sumx*sumx3-sumx2*sumx2);
2974 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
2975 sumx2*(sumxy*sumx3-sumx2y*sumx2);
2976 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
2977 sumx2*(sumxz*sumx3-sumx2z*sumx2);
2979 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
2980 sumx2*(sumx*sumx2y-sumx2*sumxy);
2981 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
2982 sumx2*(sumx*sumx2z-sumx2*sumxz);
2984 Float_t y=detay/det+centralPad;
2985 Float_t z=detaz/det;
2986 Float_t by=detby/det; //y angle
2987 Float_t bz=detbz/det; //z angle
2988 sumy/=Float_t(currentIndex);
2989 sumz/=Float_t(currentIndex);
2991 AliComplexCluster cl;
2997 cl.fTracks[0]=ipart;
2999 AliTPCClustersRow * row = (fClustersArray->GetRow(sector,lastrow));
3000 if (row!=0) row->InsertCluster(&cl);
3003 } //end of calculating cluster for given row
3005 } // end of loop over hits
3009 //_______________________________________________________________________________
3010 void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
3012 // produces rec points from digits and writes them on the root file
3013 // AliTPCclusters.root
3015 TDirectory *cwd = gDirectory;
3018 AliTPCParamSR *dig=(AliTPCParamSR *)gDirectory->Get("75x40_100x60");
3020 printf("You are running 2 pad-length geom hits with 3 pad-length geom digits\n");
3022 dig = new AliTPCParamSR();
3026 dig=(AliTPCParamSR *)gDirectory->Get("75x40_100x60_150x60");
3029 printf("No TPC parameters found\n");
3034 cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl;
3036 if(!gSystem->Getenv("CONFIG_FILE")){
3037 out=TFile::Open("AliTPCclusters.root","recreate");
3043 tmp1=gSystem->Getenv("CONFIG_FILE_PREFIX");
3044 tmp2=gSystem->Getenv("CONFIG_OUTDIR");
3045 sprintf(tmp3,"%s%s/AliTPCclusters.root",tmp1,tmp2);
3046 out=TFile::Open(tmp3,"recreate");
3050 cout<<"AliTPC::Digits2Reco - determination of rec points begins"<<endl;
3053 for(Int_t iev=firstevent;iev<lastevent+1;iev++){
3055 printf("Processing event %d\n",iev);
3056 Digits2Clusters(iev);
3058 cout<<"AliTPC::Digits2Reco - determination of rec points ended"<<endl;
3067 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
3070 fLoader = new AliTPCLoader(GetName(),topfoldername);
3074 ////////////////////////////////////////////////////////////////////////
3075 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
3077 // load TPC paarmeters from a given file or create new if the object
3078 // is not found there
3079 // 12/05/2003 This method should be moved to the AliTPCLoader
3080 // and one has to decide where to store the TPC parameters
3083 sprintf(paramName,"75x40_100x60_150x60");
3084 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
3086 cout<<"TPC parameters "<<paramName<<" found."<<endl;
3088 cerr<<"TPC parameters not found. Create new (they may be incorrect)."
3090 paramTPC = new AliTPCParamSR;
3094 // the older version of parameters can be accessed with this code.
3095 // In some cases, we have old parameters saved in the file but
3096 // digits were created with new parameters, it can be distinguish
3097 // by the name of TPC TreeD. The code here is just for the case
3098 // we would need to compare with old data, uncomment it if needed.
3100 // char paramName[50];
3101 // sprintf(paramName,"75x40_100x60");
3102 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
3104 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
3106 // sprintf(paramName,"75x40_100x60_150x60");
3107 // paramTPC=(AliTPCParam*)in->Get(paramName);
3109 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
3111 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
3113 // paramTPC = new AliTPCParamSR;
3121 //____________________________________________________________________________
3122 Double_t SigmaY2(Double_t r, Double_t tgl, Double_t pt)
3125 // Parametrised error of the cluster reconstruction (pad direction)
3128 const Float_t kArphi=0.41818e-2;
3129 const Float_t kBrphi=0.17460e-4;
3130 const Float_t kCrphi=0.30993e-2;
3131 const Float_t kDrphi=0.41061e-3;
3133 pt=TMath::Abs(pt)*1000.;
3135 tgl=TMath::Abs(tgl);
3136 Double_t s=kArphi - kBrphi*r*tgl + kCrphi*x*x + kDrphi*x;
3137 if (s<0.4e-3) s=0.4e-3;
3138 s*=1.3; //Iouri Belikov
3144 //____________________________________________________________________________
3145 Double_t SigmaZ2(Double_t r, Double_t tgl)
3148 // Parametrised error of the cluster reconstruction (drift direction)
3151 const Float_t kAz=0.39614e-2;
3152 const Float_t kBz=0.22443e-4;
3153 const Float_t kCz=0.51504e-1;
3156 tgl=TMath::Abs(tgl);
3157 Double_t s=kAz - kBz*r*tgl + kCz*tgl*tgl;
3158 if (s<0.4e-3) s=0.4e-3;
3159 s*=1.3; //Iouri Belikov