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.50 2001/12/06 14:16:19 kowal2
21 Revision 1.49 2001/11/30 11:55:37 hristov
22 Noise table created in Hits2SDigits (M.Ivanov)
24 Revision 1.48 2001/11/24 16:10:21 kowal2
27 Revision 1.47 2001/11/19 10:25:34 kowal2
28 Nearest integer instead of integer when converting to ADC counts
30 Revision 1.46 2001/11/07 06:47:12 kowal2
33 Revision 1.45 2001/11/03 13:33:48 kowal2
34 Updated algorithms in Hits2SDigits, SDigits2Digits,
38 Revision 1.44 2001/08/30 09:28:48 hristov
39 TTree names are explicitly set via SetName(name) and then Write() is called
41 Revision 1.43 2001/07/28 12:02:54 hristov
42 Branch split level set to 99
44 Revision 1.42 2001/07/28 11:38:52 hristov
45 Loop variable declared once
47 Revision 1.41 2001/07/28 10:53:50 hristov
48 Digitisation done according to the general scheme (M.Ivanov)
50 Revision 1.40 2001/07/27 13:03:14 hristov
51 Default Branch split level set to 99
53 Revision 1.39 2001/07/26 09:09:34 kowal2
54 Hits2Reco method added
56 Revision 1.38 2001/07/20 14:32:43 kowal2
57 Processing of many events possible now
59 Revision 1.37 2001/06/12 07:17:18 kowal2
60 Hits2SDigits method implemented (summable digits)
62 Revision 1.36 2001/05/16 14:57:25 alibrary
63 New files for folders and Stack
65 Revision 1.35 2001/05/08 16:02:22 kowal2
66 Updated material specifications
68 Revision 1.34 2001/05/08 15:00:15 hristov
69 Corrections for tracking in arbitrary magnenetic field. Changes towards a concept of global Alice track. Back propagation of reconstructed tracks (Yu.Belikov)
71 Revision 1.33 2001/04/03 12:40:43 kowal2
74 Revision 1.32 2001/03/12 17:47:36 hristov
75 Changes needed on Sun with CC 5.0
77 Revision 1.31 2001/03/12 08:21:50 kowal2
78 Corrected C++ bug in the material definitions
80 Revision 1.30 2001/03/01 17:34:47 kowal2
81 Correction due to the accuracy problem
83 Revision 1.29 2001/02/28 16:34:40 kowal2
84 Protection against nonphysical values of the avalanche size,
87 Revision 1.28 2001/01/26 19:57:19 hristov
88 Major upgrade of AliRoot code
90 Revision 1.27 2001/01/13 17:29:33 kowal2
91 Sun compiler correction
93 Revision 1.26 2001/01/10 07:59:43 kowal2
94 Corrections to load points from the noncompressed hits.
96 Revision 1.25 2000/11/02 07:25:31 kowal2
97 Changes due to the new hit structure.
100 Revision 1.24 2000/10/05 16:06:09 kowal2
101 Forward declarations. Changes due to a new class AliComplexCluster.
103 Revision 1.23 2000/10/02 21:28:18 fca
104 Removal of useless dependecies via forward declarations
106 Revision 1.22 2000/07/10 20:57:39 hristov
107 Update of TPC code and macros by M.Kowalski
109 Revision 1.19.2.4 2000/06/26 07:39:42 kowal2
110 Changes to obey the coding rules
112 Revision 1.19.2.3 2000/06/25 08:38:41 kowal2
113 Splitted from AliTPCtracking
115 Revision 1.19.2.2 2000/06/16 12:59:28 kowal2
116 Changed parameter settings
118 Revision 1.19.2.1 2000/06/09 07:15:07 kowal2
120 Defaults loaded automatically (hard-wired)
121 Optional parameters can be set via macro called in the constructor
123 Revision 1.19 2000/04/18 19:00:59 fca
124 Small bug fixes to TPC files
126 Revision 1.18 2000/04/17 09:37:33 kowal2
127 removed obsolete AliTPCDigitsDisplay.C
129 Revision 1.17.2.2 2000/04/10 08:15:12 kowal2
131 New, experimental data structure from M. Ivanov
132 New tracking algorithm
133 Different pad geometry for different sectors
134 Digitization rewritten
136 Revision 1.17.2.1 2000/04/10 07:56:53 kowal2
137 Not used anymore - removed
139 Revision 1.17 2000/01/19 17:17:30 fca
140 Introducing a list of lists of hits -- more hits allowed for detector now
142 Revision 1.16 1999/11/05 09:29:23 fca
143 Accept only signals > 0
145 Revision 1.15 1999/10/08 06:26:53 fca
146 Removed ClustersIndex - not used anymore
148 Revision 1.14 1999/09/29 09:24:33 fca
149 Introduction of the Copyright and cvs Log
153 ///////////////////////////////////////////////////////////////////////////////
155 // Time Projection Chamber //
156 // This class contains the basic functions for the Time Projection Chamber //
157 // detector. Functions specific to one particular geometry are //
158 // contained in the derived classes //
162 <img src="picts/AliTPCClass.gif">
167 ///////////////////////////////////////////////////////////////////////////////
175 #include <TGeometry.h>
178 #include <TObjectTable.h>
179 #include "TParticle.h"
185 #include <iostream.h>
192 #include "AliTPCParamSR.h"
193 #include "AliTPCPRF2D.h"
194 #include "AliTPCRF1D.h"
195 #include "AliDigits.h"
196 #include "AliSimDigits.h"
197 #include "AliTPCTrackHits.h"
198 #include "AliTPCTrackHitsV2.h"
199 #include "AliPoints.h"
200 #include "AliArrayBranch.h"
203 #include "AliTPCDigitsArray.h"
204 #include "AliComplexCluster.h"
205 #include "AliClusters.h"
206 #include "AliTPCClustersRow.h"
207 #include "AliTPCClustersArray.h"
209 #include "AliTPCcluster.h"
210 #include "AliTPCclusterer.h"
211 #include "AliTPCtracker.h"
213 #include <TInterpreter.h>
220 //_____________________________________________________________________________
224 // Default constructor
235 fHitType = 4; //default CONTAINERS - based on ROOT structure
242 //_____________________________________________________________________________
243 AliTPC::AliTPC(const char *name, const char *title)
244 : AliDetector(name,title)
247 // Standard constructor
251 // Initialise arrays of hits and digits
252 fHits = new TClonesArray("AliTPChit", 176);
253 gAlice->AddHitList(fHits);
258 fTrackHits = new AliTPCTrackHitsV2;
259 fTrackHits->SetHitPrecision(0.002);
260 fTrackHits->SetStepPrecision(0.003);
261 fTrackHits->SetMaxDistance(100);
263 fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
264 fTrackHitsOld->SetHitPrecision(0.002);
265 fTrackHitsOld->SetStepPrecision(0.003);
266 fTrackHitsOld->SetMaxDistance(100);
273 // Initialise counters
279 // Initialise color attributes
280 SetMarkerColor(kYellow);
283 // Set TPC parameters
287 if (!strcmp(title,"Default")) {
288 fTPCParam = new AliTPCParamSR;
290 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
296 //_____________________________________________________________________________
307 delete fTrackHits; //MI 15.09.2000
308 delete fTrackHitsOld; //MI 10.12.2001
309 if (fNoiseTable) delete [] fNoiseTable;
313 //_____________________________________________________________________________
314 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
317 // Add a hit to the list
319 // TClonesArray &lhits = *fHits;
320 // new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
322 TClonesArray &lhits = *fHits;
323 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
326 AddHit2(track,vol,hits);
329 //_____________________________________________________________________________
330 void AliTPC::BuildGeometry()
334 // Build TPC ROOT TNode geometry for the event display
339 const int kColorTPC=19;
340 char name[5], title[25];
341 const Double_t kDegrad=TMath::Pi()/180;
342 const Double_t kRaddeg=180./TMath::Pi();
345 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
346 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
348 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
349 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
351 Int_t nLo = fTPCParam->GetNInnerSector()/2;
352 Int_t nHi = fTPCParam->GetNOuterSector()/2;
354 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
355 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
356 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
357 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
360 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
361 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
367 // Get ALICE top node
370 nTop=gAlice->GetGeometry()->GetNode("alice");
374 rl = fTPCParam->GetInnerRadiusLow();
375 ru = fTPCParam->GetInnerRadiusUp();
379 sprintf(name,"LS%2.2d",i);
381 sprintf(title,"TPC low sector %3d",i);
384 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
385 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
386 tubs->SetNumberOfDivisions(1);
388 nNode = new TNode(name,title,name,0,0,0,"");
389 nNode->SetLineColor(kColorTPC);
395 rl = fTPCParam->GetOuterRadiusLow();
396 ru = fTPCParam->GetOuterRadiusUp();
399 sprintf(name,"US%2.2d",i);
401 sprintf(title,"TPC upper sector %d",i);
403 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
404 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
405 tubs->SetNumberOfDivisions(1);
407 nNode = new TNode(name,title,name,0,0,0,"");
408 nNode->SetLineColor(kColorTPC);
414 //_____________________________________________________________________________
415 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
418 // Calculate distance from TPC to mouse on the display
424 void AliTPC::Clusters2Tracks(TFile *of) {
425 //-----------------------------------------------------------------
426 // This is a track finder.
427 //-----------------------------------------------------------------
428 AliTPCtracker tracker(fTPCParam);
429 tracker.Clusters2Tracks(gFile,of);
432 //_____________________________________________________________________________
433 void AliTPC::CreateMaterials()
435 //-----------------------------------------------
436 // Create Materials for for TPC simulations
437 //-----------------------------------------------
439 //-----------------------------------------------------------------
440 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
441 //-----------------------------------------------------------------
443 Int_t iSXFLD=gAlice->Field()->Integ();
444 Float_t sXMGMX=gAlice->Field()->Max();
446 Float_t amat[5]; // atomic numbers
447 Float_t zmat[5]; // z
448 Float_t wmat[5]; // proportions
454 //***************** Gases *************************
456 //-------------------------------------------------
458 //-------------------------------------------------
469 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
479 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
482 //--------------------------------------------------------------
484 //--------------------------------------------------------------
501 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
503 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
518 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
520 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
536 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
538 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
540 //----------------------------------------------------------------
541 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
542 //----------------------------------------------------------------
548 Float_t rho,absl,X0,buf[1];
552 for(nc = 0;nc<fNoComp;nc++)
555 // retrive material constants
557 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,X0,absl,buf,nbuf);
562 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
564 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
565 density += fMixtProp[nc]*rho; // density of the mixture
569 // mixture proportions by weight!
571 for(nc = 0;nc<fNoComp;nc++)
574 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
576 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
577 apure[nnc] : amol[nnc])/am;
581 // Drift gases 1 - nonsensitive, 2 - sensitive
583 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
584 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
593 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
596 //----------------------------------------------------------------------
598 //----------------------------------------------------------------------
620 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
642 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
660 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
678 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
680 // SiO2 - used later for the glass fiber
692 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
701 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
710 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
719 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
737 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
756 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
758 // Epoxy - C14 H20 O3
775 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
783 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
787 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,X0,absl,buf,nbuf);
791 wmat[0]=0.644; // by weight!
794 density=0.5*(1.25+2.265);
796 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
800 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,X0,absl,buf,nbuf);
802 wmat[0]=0.725; // by weight!
807 AliMixture(39,"G10",amat,zmat,density,2,wmat);
812 //----------------------------------------------------------
813 // tracking media for gases
814 //----------------------------------------------------------
816 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
817 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
818 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
819 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
821 //-----------------------------------------------------------
822 // tracking media for solids
823 //-----------------------------------------------------------
825 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
826 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
827 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
828 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
829 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
830 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
831 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
832 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
833 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
834 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
835 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
836 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
840 void AliTPC::GenerNoise(Int_t tablesize)
843 //Generate table with noise
850 if (fNoiseTable) delete[] fNoiseTable;
851 fNoiseTable = new Float_t[tablesize];
852 fNoiseDepth = tablesize;
853 fCurrentNoise =0; //!index of the noise in the noise table
855 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
856 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
859 Float_t AliTPC::GetNoise()
861 // get noise from table
862 // if ((fCurrentNoise%10)==0)
863 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
864 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
865 return fNoiseTable[fCurrentNoise++];
866 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
870 Bool_t AliTPC::IsSectorActive(Int_t sec)
873 // check if the sector is active
874 if (!fActiveSectors) return kTRUE;
875 else return fActiveSectors[sec];
878 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
880 // activate interesting sectors
881 if (fActiveSectors) delete [] fActiveSectors;
882 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
883 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
884 for (Int_t i=0;i<n;i++)
885 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
889 void AliTPC::SetActiveSectors()
892 // activate sectors which were hitted by tracks
894 if (fHitType==0) return; // if Clones hit - not short volume ID information
895 if (fActiveSectors) delete [] fActiveSectors;
896 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
897 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
899 if (fHitType>1) branch = gAlice->TreeH()->GetBranch("TPC2");
900 else branch = gAlice->TreeH()->GetBranch("TPC");
901 Stat_t ntracks = gAlice->TreeH()->GetEntries();
902 // loop over all hits
903 for(Int_t track=0;track<ntracks;track++){
906 if (fTrackHits && fHitType&4) {
907 TBranch * br1 = gAlice->TreeH()->GetBranch("fVolumes");
908 TBranch * br2 = gAlice->TreeH()->GetBranch("fNVolumes");
909 br1->GetEvent(track);
910 br2->GetEvent(track);
911 Int_t *volumes = fTrackHits->GetVolumes();
912 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
913 fActiveSectors[volumes[j]]=kTRUE;
917 if (fTrackHitsOld && fHitType&2) {
918 TBranch * br = gAlice->TreeH()->GetBranch("fTrackHitsInfo");
920 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
921 for (UInt_t j=0;j<ar->GetSize();j++){
922 fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
932 void AliTPC::Digits2Clusters(TFile *of, Int_t eventnumber)
934 //-----------------------------------------------------------------
935 // This is a simple cluster finder.
936 //-----------------------------------------------------------------
937 AliTPCclusterer::Digits2Clusters(fTPCParam,of,eventnumber);
940 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
941 extern Double_t SigmaZ2(Double_t, Double_t);
942 //_____________________________________________________________________________
943 void AliTPC::Hits2Clusters(TFile *of, Int_t eventn)
945 //--------------------------------------------------------
946 // TPC simple cluster generator from hits
947 // obtained from the TPC Fast Simulator
948 // The point errors are taken from the parametrization
949 //--------------------------------------------------------
951 //-----------------------------------------------------------------
952 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
953 //-----------------------------------------------------------------
954 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
955 // Jouri.Belikov@cern.ch
956 //----------------------------------------------------------------
958 /////////////////////////////////////////////////////////////////////////////
960 //---------------------------------------------------------------------
961 // ALICE TPC Cluster Parameters
962 //--------------------------------------------------------------------
966 // Cluster width in rphi
967 const Float_t kACrphi=0.18322;
968 const Float_t kBCrphi=0.59551e-3;
969 const Float_t kCCrphi=0.60952e-1;
970 // Cluster width in z
971 const Float_t kACz=0.19081;
972 const Float_t kBCz=0.55938e-3;
973 const Float_t kCCz=0.30428;
975 TDirectory *savedir=gDirectory;
978 cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
982 //if(fDefaults == 0) SetDefaults();
984 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
986 TParticle *particle; // pointer to a given particle
987 AliTPChit *tpcHit; // pointer to a sigle TPC hit
991 Float_t pl,pt,tanth,rpad,ratio;
994 //---------------------------------------------------------------
995 // Get the access to the tracks
996 //---------------------------------------------------------------
998 TTree *tH = gAlice->TreeH();
999 Stat_t ntracks = tH->GetEntries();
1001 //Switch to the output file
1006 sprintf(cname,"TreeC_TPC_%d",eventn);
1008 fTPCParam->Write(fTPCParam->GetTitle());
1009 AliTPCClustersArray carray;
1010 carray.Setup(fTPCParam);
1011 carray.SetClusterType("AliTPCcluster");
1014 Int_t nclusters=0; //cluster counter
1016 //------------------------------------------------------------
1017 // Loop over all sectors (72 sectors for 20 deg
1018 // segmentation for both lower and upper sectors)
1019 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
1020 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
1022 // First cluster for sector 0 starts at "0"
1023 //------------------------------------------------------------
1025 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
1027 fTPCParam->AdjustCosSin(isec,cph,sph);
1029 //------------------------------------------------------------
1031 //------------------------------------------------------------
1033 for(Int_t track=0;track<ntracks;track++){
1035 tH->GetEvent(track);
1037 // Get number of the TPC hits
1039 tpcHit = (AliTPChit*)FirstHit(-1);
1045 if (tpcHit->fQ == 0.) {
1046 tpcHit = (AliTPChit*) NextHit();
1047 continue; //information about track (I.Belikov)
1049 sector=tpcHit->fSector; // sector number
1052 tpcHit = (AliTPChit*) NextHit();
1055 ipart=tpcHit->Track();
1056 particle=gAlice->Particle(ipart);
1059 if(pt < 1.e-9) pt=1.e-9;
1061 tanth = TMath::Abs(tanth);
1062 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
1063 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
1065 // space-point resolutions
1067 sigmaRphi=SigmaY2(rpad,tanth,pt);
1068 sigmaZ =SigmaZ2(rpad,tanth );
1072 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
1073 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
1075 // temporary protection
1077 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
1078 if(sigmaZ < 0.) sigmaZ=0.4e-3;
1079 if(clRphi < 0.) clRphi=2.5e-3;
1080 if(clZ < 0.) clZ=2.5e-5;
1085 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
1086 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
1088 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
1089 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
1090 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
1091 Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
1092 fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
1093 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
1094 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
1095 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
1096 if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->Z();
1097 xyz[2]=sigmaRphi; // fSigmaY2
1098 xyz[3]=sigmaZ; // fSigmaZ2
1099 xyz[4]=tpcHit->fQ; // q
1101 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
1102 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
1104 Int_t tracks[3]={tpcHit->Track(), -1, -1};
1105 AliTPCcluster cluster(tracks,xyz);
1107 clrow->InsertCluster(&cluster); nclusters++;
1109 tpcHit = (AliTPChit*)NextHit();
1112 } // end of loop over hits
1114 } // end of loop over tracks
1116 Int_t nrows=fTPCParam->GetNRow(isec);
1117 for (Int_t irow=0; irow<nrows; irow++) {
1118 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
1119 if (!clrow) continue;
1120 carray.StoreRow(isec,irow);
1121 carray.ClearRow(isec,irow);
1124 } // end of loop over sectors
1126 cerr<<"Number of made clusters : "<<nclusters<<" \n";
1127 carray.GetTree()->SetName(cname);
1128 carray.GetTree()->Write();
1130 savedir->cd(); //switch back to the input file
1132 } // end of function
1134 //_________________________________________________________________
1135 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1137 //--------------------------------------------------------
1138 //calculate exact cross point of track and given pad row
1139 //resulting values are expressed in "digit" coordinata
1140 //--------------------------------------------------------
1142 //-----------------------------------------------------------------
1143 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1144 //-----------------------------------------------------------------
1146 if (fClustersArray==0){
1150 TParticle *particle; // pointer to a given particle
1151 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1152 // Int_t sector,nhits;
1154 const Int_t kcmaxhits=30000;
1155 TVector * xxxx = new TVector(kcmaxhits*4);
1156 TVector & xxx = *xxxx;
1157 Int_t maxhits = kcmaxhits;
1158 //construct array for each padrow
1159 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
1160 fClustersArray->CreateRow(isec,i);
1162 //---------------------------------------------------------------
1163 // Get the access to the tracks
1164 //---------------------------------------------------------------
1166 TTree *tH = gAlice->TreeH();
1167 Stat_t ntracks = tH->GetEntries();
1168 Int_t npart = gAlice->GetNtrack();
1171 if (fHitType>1) branch = tH->GetBranch("TPC2");
1172 else branch = tH->GetBranch("TPC");
1174 //------------------------------------------------------------
1176 //------------------------------------------------------------
1178 for(Int_t track=0;track<ntracks;track++){
1179 Bool_t isInSector=kTRUE;
1181 isInSector = TrackInVolume(isec,track);
1182 if (!isInSector) continue;
1184 branch->GetEntry(track); // get next track
1186 // Get number of the TPC hits and a pointer
1190 Int_t currentIndex=0;
1191 Int_t lastrow=-1; //last writen row
1195 tpcHit = (AliTPChit*)FirstHit(-1);
1198 Int_t sector=tpcHit->fSector; // sector number
1200 tpcHit = (AliTPChit*) NextHit();
1204 ipart=tpcHit->Track();
1205 if (ipart<npart) particle=gAlice->Particle(ipart);
1209 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
1210 Int_t index[3]={1,isec,0};
1211 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
1212 if (currentrow<0) {tpcHit = (AliTPChit*)NextHit(); continue;}
1213 if (lastrow<0) lastrow=currentrow;
1214 if (currentrow==lastrow){
1215 if ( currentIndex>=maxhits){
1217 xxx.ResizeTo(4*maxhits);
1219 xxx(currentIndex*4)=x[0];
1220 xxx(currentIndex*4+1)=x[1];
1221 xxx(currentIndex*4+2)=x[2];
1222 xxx(currentIndex*4+3)=tpcHit->fQ;
1226 if (currentIndex>2){
1238 for (Int_t index=0;index<currentIndex;index++){
1240 x=x2=x3=x4=xxx(index*4);
1248 sumy+=xxx(index*4+1);
1249 sumxy+=xxx(index*4+1)*x;
1250 sumx2y+=xxx(index*4+1)*x2;
1251 sumz+=xxx(index*4+2);
1252 sumxz+=xxx(index*4+2)*x;
1253 sumx2z+=xxx(index*4+2)*x2;
1254 sumq+=xxx(index*4+3);
1256 Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1257 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1258 sumx2*(sumx*sumx3-sumx2*sumx2);
1260 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1261 sumx2*(sumxy*sumx3-sumx2y*sumx2);
1262 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1263 sumx2*(sumxz*sumx3-sumx2z*sumx2);
1265 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1266 sumx2*(sumx*sumx2y-sumx2*sumxy);
1267 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1268 sumx2*(sumx*sumx2z-sumx2*sumxz);
1270 Float_t y=detay/det+centralPad;
1271 Float_t z=detaz/det;
1272 Float_t by=detby/det; //y angle
1273 Float_t bz=detbz/det; //z angle
1274 sumy/=Float_t(currentIndex);
1275 sumz/=Float_t(currentIndex);
1277 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1279 AliComplexCluster* cl = new((AliComplexCluster*)row->Append()) AliComplexCluster ;
1280 // AliComplexCluster cl;
1286 cl->fTracks[0]=ipart;
1290 } //end of calculating cluster for given row
1293 tpcHit = (AliTPChit*)NextHit();
1294 } // end of loop over hits
1295 } // end of loop over tracks
1296 //write padrows to tree
1297 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1298 fClustersArray->StoreRow(isec,ii);
1299 fClustersArray->ClearRow(isec,ii);
1308 void AliTPC::SDigits2Digits2(Int_t eventnumber)
1310 //create digits from summable digits
1311 GenerNoise(500000); //create teble with noise
1314 sprintf(sname,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1315 sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1317 //conect tree with sSDigits
1318 TTree *t = (TTree *)gDirectory->Get(sname);
1319 AliSimDigits digarr, *dummy=&digarr;
1320 t->GetBranch("Segment")->SetAddress(&dummy);
1321 Stat_t nentries = t->GetEntries();
1323 // set zero suppression
1325 fTPCParam->SetZeroSup(2);
1327 // get zero suppression
1329 Int_t zerosup = fTPCParam->GetZeroSup();
1331 //make tree with digits
1333 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1334 arr->SetClass("AliSimDigits");
1335 arr->Setup(fTPCParam);
1336 arr->MakeTree(fDigitsFile);
1338 AliTPCParam * par =fTPCParam;
1340 //Loop over segments of the TPC
1342 for (Int_t n=0; n<nentries; n++) {
1345 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1346 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
1349 if (!IsSectorActive(sec)) continue;
1350 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1351 Int_t nrows = digrow->GetNRows();
1352 Int_t ncols = digrow->GetNCols();
1354 digrow->ExpandBuffer();
1355 digarr.ExpandBuffer();
1356 digrow->ExpandTrackBuffer();
1357 digarr.ExpandTrackBuffer();
1360 Short_t * pamp0 = digarr.GetDigits();
1361 Int_t * ptracks0 = digarr.GetTracks();
1362 Short_t * pamp1 = digrow->GetDigits();
1363 Int_t * ptracks1 = digrow->GetTracks();
1364 Int_t nelems =nrows*ncols;
1365 Int_t saturation = fTPCParam->GetADCSat();
1366 //use internal structure of the AliDigits - for speed reason
1367 //if you cahnge implementation
1368 //of the Alidigits - it must be rewriten -
1369 for (Int_t i= 0; i<nelems; i++){
1370 // Float_t q = *pamp0;
1371 //q/=16.; //conversion faktor
1372 //Float_t noise= GetNoise();
1374 //q= TMath::Nint(q);
1375 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1377 if (q>saturation) q=saturation;
1379 //if (ptracks0[0]==0)
1382 ptracks1[0]=ptracks0[0];
1383 ptracks1[nelems]=ptracks0[nelems];
1384 ptracks1[2*nelems]=ptracks0[2*nelems];
1392 arr->StoreRow(sec,row);
1393 arr->ClearRow(sec,row);
1394 // cerr<<sec<<"\t"<<row<<"\n";
1401 arr->GetTree()->SetName(dname);
1402 arr->GetTree()->Write();
1405 //_________________________________________
1406 void AliTPC::Merge(TTree * intree, Int_t *mask, Int_t nin, Int_t outid)
1409 //intree - pointer to array of trees with s digits
1410 //mask - mask for each
1411 //nin - number of inputs
1412 //outid - event number of the output event
1414 //create digits from summable digits
1415 //conect tree with sSDigits
1418 AliSimDigits ** digarr = new AliSimDigits*[nin];
1419 for (Int_t i1=0;i1<nin; i1++){
1421 intree[i1].GetBranch("Segment")->SetAddress(&digarr[i1]);
1423 Stat_t nentries = intree[0].GetEntries();
1425 //make tree with digits
1427 sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),outid);
1428 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1429 arr->SetClass("AliSimDigits");
1430 arr->Setup(fTPCParam);
1431 arr->MakeTree(fDigitsFile);
1433 // set zero suppression
1435 fTPCParam->SetZeroSup(2);
1437 // get zero suppression
1439 Int_t zerosup = fTPCParam->GetZeroSup();
1442 AliTPCParam * par =fTPCParam;
1444 //Loop over segments of the TPC
1445 for (Int_t n=0; n<nentries; n++) {
1447 for (Int_t i=0;i<nin; i++){
1448 //connect proper digits
1449 intree[i].GetEvent(n);
1450 digarr[i]->ExpandBuffer();
1451 digarr[i]->ExpandTrackBuffer();
1454 if (!par->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
1455 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
1459 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1460 Int_t nrows = digrow->GetNRows();
1461 Int_t ncols = digrow->GetNCols();
1463 digrow->ExpandBuffer();
1464 digrow->ExpandTrackBuffer();
1466 for (Int_t rows=0;rows<nrows; rows++){
1467 for (Int_t col=0;col<ncols; col++){
1469 Int_t label[1000]; // i hope no more than 300 events merged
1471 // looop over digits
1472 for (Int_t i=0;i<nin; i++){
1473 q += digarr[i]->GetDigitFast(rows,col);
1474 for (Int_t tr=0;tr<3;tr++) {
1475 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
1477 label[labptr]=lab+mask[i]-2;
1483 q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac()*16);
1485 q/=16; //conversion faktor
1490 if(q > fTPCParam->GetADCSat()) q = (Short_t)(fTPCParam->GetADCSat());
1491 digrow->SetDigitFast(q,rows,col);
1492 for (Int_t tr=0;tr<3;tr++){
1494 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
1496 ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
1501 arr->StoreRow(sec,row);
1503 arr->ClearRow(sec,row);
1508 arr->GetTree()->SetName(dname);
1509 arr->GetTree()->Write();
1515 /*_________________________________________
1516 void AliTPC::SDigits2Digits(Int_t eventnumber)
1520 cerr<<"Digitizing TPC...\n";
1522 Hits2Digits(eventnumber);
1527 // char treeName[100];
1529 // sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1531 // GetDigitsArray()->GetTree()->Write(treeName);
1534 //__________________________________________________________________
1535 void AliTPC::SetDefaults(){
1538 cerr<<"Setting default parameters...\n";
1540 // Set response functions
1542 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1543 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1544 AliTPCPRF2D * prfouter = new AliTPCPRF2D;
1545 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1546 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1547 rf->SetOffset(3*param->GetZSigma());
1550 TDirectory *savedir=gDirectory;
1551 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1553 cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1556 prfinner->Read("prf_07504_Gati_056068_d02");
1557 prfouter->Read("prf_10006_Gati_047051_d03");
1561 param->SetInnerPRF(prfinner);
1562 param->SetOuterPRF(prfouter);
1563 param->SetTimeRF(rf);
1573 //__________________________________________________________________
1574 void AliTPC::Hits2Digits(Int_t eventnumber)
1576 //----------------------------------------------------
1577 // Loop over all sectors for a single event
1578 //----------------------------------------------------
1581 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1582 GenerNoise(500000); //create teble with noise
1584 //setup TPCDigitsArray
1586 if(GetDigitsArray()) delete GetDigitsArray();
1588 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1589 arr->SetClass("AliSimDigits");
1590 arr->Setup(fTPCParam);
1591 arr->MakeTree(fDigitsFile);
1592 SetDigitsArray(arr);
1594 fDigitsSwitch=0; // standard digits
1596 cerr<<"Digitizing TPC -- normal digits...\n";
1598 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1604 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1606 GetDigitsArray()->GetTree()->SetName(treeName);
1607 GetDigitsArray()->GetTree()->Write();
1614 //__________________________________________________________________
1615 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1618 //-----------------------------------------------------------
1619 // summable digits - 16 bit "ADC", no noise, no saturation
1620 //-----------------------------------------------------------
1622 //----------------------------------------------------
1623 // Loop over all sectors for a single event
1624 //----------------------------------------------------
1627 if(fDefaults == 0) SetDefaults();
1628 GenerNoise(500000); //create table with noise
1629 //setup TPCDigitsArray
1631 if(GetDigitsArray()) delete GetDigitsArray();
1633 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1634 arr->SetClass("AliSimDigits");
1635 arr->Setup(fTPCParam);
1636 arr->MakeTree(fDigitsFile);
1637 SetDigitsArray(arr);
1639 cerr<<"Digitizing TPC -- summable digits...\n";
1641 fDigitsSwitch=1; // summable digits
1643 // set zero suppression to "0"
1645 fTPCParam->SetZeroSup(0);
1647 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1654 sprintf(treeName,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1656 GetDigitsArray()->GetTree()->SetName(treeName);
1657 GetDigitsArray()->GetTree()->Write();
1663 //__________________________________________________________________
1664 void AliTPC::Hits2SDigits()
1667 //-----------------------------------------------------------
1668 // summable digits - 16 bit "ADC", no noise, no saturation
1669 //-----------------------------------------------------------
1671 //----------------------------------------------------
1672 // Loop over all sectors for a single event
1673 //----------------------------------------------------
1674 //MI change - for pp run
1675 Int_t eventnumber = gAlice->GetEvNumber();
1677 if(fDefaults == 0) SetDefaults();
1678 GenerNoise(500000); //create table with noise
1680 //setup TPCDigitsArray
1682 if(GetDigitsArray()) delete GetDigitsArray();
1684 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1685 arr->SetClass("AliSimDigits");
1686 arr->Setup(fTPCParam);
1687 arr->MakeTree(fDigitsFile);
1688 SetDigitsArray(arr);
1690 cerr<<"Digitizing TPC -- summable digits...\n";
1692 // fDigitsSwitch=1; // summable digits -for the moment direct
1694 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1700 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1702 GetDigitsArray()->GetTree()->SetName(treeName);
1703 GetDigitsArray()->GetTree()->Write();
1708 //_____________________________________________________________________________
1709 void AliTPC::Hits2DigitsSector(Int_t isec)
1711 //-------------------------------------------------------------------
1712 // TPC conversion from hits to digits.
1713 //-------------------------------------------------------------------
1715 //-----------------------------------------------------------------
1716 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1717 //-----------------------------------------------------------------
1719 //-------------------------------------------------------
1720 // Get the access to the track hits
1721 //-------------------------------------------------------
1723 // check if the parameters are set - important if one calls this method
1724 // directly, not from the Hits2Digits
1726 if(fDefaults == 0) SetDefaults();
1728 TTree *tH = gAlice->TreeH(); // pointer to the hits tree
1729 Stat_t ntracks = tH->GetEntries();
1733 //-------------------------------------------
1734 // Only if there are any tracks...
1735 //-------------------------------------------
1739 //printf("*** Processing sector number %d ***\n",isec);
1741 Int_t nrows =fTPCParam->GetNRow(isec);
1743 row= new TObjArray* [nrows];
1745 MakeSector(isec,nrows,tH,ntracks,row);
1747 //--------------------------------------------------------
1748 // Digitize this sector, row by row
1749 // row[i] is the pointer to the TObjArray of TVectors,
1750 // each one containing electrons accepted on this
1751 // row, assigned into tracks
1752 //--------------------------------------------------------
1756 if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree(fDigitsFile);
1758 for (i=0;i<nrows;i++){
1760 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1762 DigitizeRow(i,isec,row);
1764 fDigitsArray->StoreRow(isec,i);
1766 Int_t ndig = dig->GetDigitSize();
1767 if (gDebug > 10) printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1769 fDigitsArray->ClearRow(isec,i);
1772 } // end of the sector digitization
1774 for(i=0;i<nrows;i++){
1779 delete [] row; // delete the array of pointers to TObjArray-s
1783 } // end of Hits2DigitsSector
1786 //_____________________________________________________________________________
1787 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1789 //-----------------------------------------------------------
1790 // Single row digitization, coupling from the neighbouring
1791 // rows taken into account
1792 //-----------------------------------------------------------
1794 //-----------------------------------------------------------------
1795 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1796 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1797 //-----------------------------------------------------------------
1800 Float_t zerosup = fTPCParam->GetZeroSup();
1801 Int_t nrows =fTPCParam->GetNRow(isec);
1802 fCurrentIndex[1]= isec;
1805 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1806 Int_t nofTbins = fTPCParam->GetMaxTBin();
1807 Int_t indexRange[4];
1809 // Integrated signal for this row
1810 // and a single track signal
1812 TMatrix *m1 = new TMatrix(0,nofPads,0,nofTbins); // integrated
1813 TMatrix *m2 = new TMatrix(0,nofPads,0,nofTbins); // single
1815 TMatrix &total = *m1;
1817 // Array of pointers to the label-signal list
1819 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1820 Float_t **pList = new Float_t* [nofDigits];
1824 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1828 Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1829 Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1830 for (Int_t row= row1;row<=row2;row++){
1831 Int_t nTracks= rows[row]->GetEntries();
1832 for (i1=0;i1<nTracks;i1++){
1833 fCurrentIndex[2]= row;
1834 fCurrentIndex[3]=irow;
1836 m2->Zero(); // clear single track signal matrix
1837 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1838 GetList(trackLabel,nofPads,m2,indexRange,pList);
1840 else GetSignal(rows[row],i1,0,m1,indexRange);
1846 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1847 for(Int_t ip=0;ip<nofPads;ip++){
1848 for(Int_t it=0;it<nofTbins;it++){
1850 Float_t q = total(ip,it);
1852 Int_t gi =it*nofPads+ip; // global index
1854 if(fDigitsSwitch == 0){
1856 // q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
1860 if(q <=zerosup) continue; // do not fill zeros
1861 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1866 if(q <= 0.) continue; // do not fill zeros
1867 if(q>2000.) q=2000.;
1873 // "real" signal or electronic noise (list = -1)?
1876 for(Int_t j1=0;j1<3;j1++){
1877 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1882 <A NAME="AliDigits"></A>
1883 using of AliDigits object
1886 dig->SetDigitFast((Short_t)q,it,ip);
1887 if (fDigitsArray->IsSimulated())
1889 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1890 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1891 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1895 } // end of loop over time buckets
1896 } // end of lop over pads
1899 // This row has been digitized, delete nonused stuff
1902 for(lp=0;lp<nofDigits;lp++){
1903 if(pList[lp]) delete [] pList[lp];
1912 } // end of DigitizeRow
1914 //_____________________________________________________________________________
1916 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr, TMatrix *m1, TMatrix *m2,
1920 //---------------------------------------------------------------
1921 // Calculates 2-D signal (pad,time) for a single track,
1922 // returns a pointer to the signal matrix and the track label
1923 // No digitization is performed at this level!!!
1924 //---------------------------------------------------------------
1926 //-----------------------------------------------------------------
1927 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1928 // Modified: Marian Ivanov
1929 //-----------------------------------------------------------------
1933 tv = (TVector*)p1->At(ntr); // pointer to a track
1936 Float_t label = v(0);
1937 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
1939 Int_t nElectrons = (tv->GetNrows()-1)/4;
1940 indexRange[0]=9999; // min pad
1941 indexRange[1]=-1; // max pad
1942 indexRange[2]=9999; //min time
1943 indexRange[3]=-1; // max time
1945 // Float_t IneffFactor = 0.5; // inefficiency in the gain close to the edge, as above
1947 TMatrix &signal = *m1;
1948 TMatrix &total = *m2;
1950 // Loop over all electrons
1952 for(Int_t nel=0; nel<nElectrons; nel++){
1954 Float_t aval = v(idx+4);
1955 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1956 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1957 Int_t n = fTPCParam->CalcResponse(xyz,fCurrentIndex,fCurrentIndex[3]);
1959 if (n>0) for (Int_t i =0; i<n; i++){
1960 Int_t *index = fTPCParam->GetResBin(i);
1961 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1962 if ( ( pad<(fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]))) && (pad>=0)) {
1963 Int_t time=index[2];
1964 Float_t weight = fTPCParam->GetResWeight(i); //we normalise response to ADC channel
1965 weight *= eltoadcfac;
1967 if (m1!=0) signal(pad,time)+=weight;
1968 total(pad,time)+=weight;
1969 indexRange[0]=TMath::Min(indexRange[0],pad);
1970 indexRange[1]=TMath::Max(indexRange[1],pad);
1971 indexRange[2]=TMath::Min(indexRange[2],time);
1972 indexRange[3]=TMath::Max(indexRange[3],time);
1975 } // end of loop over electrons
1977 return label; // returns track label when finished
1980 //_____________________________________________________________________________
1981 void AliTPC::GetList(Float_t label,Int_t np,TMatrix *m,Int_t *indexRange,
1984 //----------------------------------------------------------------------
1985 // Updates the list of tracks contributing to digits for a given row
1986 //----------------------------------------------------------------------
1988 //-----------------------------------------------------------------
1989 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1990 //-----------------------------------------------------------------
1992 TMatrix &signal = *m;
1994 // lop over nonzero digits
1996 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1997 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
2000 // accept only the contribution larger than 500 electrons (1/2 s_noise)
2002 if(signal(ip,it)<0.5) continue;
2005 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
2007 if(!pList[globalIndex]){
2010 // Create new list (6 elements - 3 signals and 3 labels),
2013 pList[globalIndex] = new Float_t [6];
2017 *pList[globalIndex] = -1.;
2018 *(pList[globalIndex]+1) = -1.;
2019 *(pList[globalIndex]+2) = -1.;
2020 *(pList[globalIndex]+3) = -1.;
2021 *(pList[globalIndex]+4) = -1.;
2022 *(pList[globalIndex]+5) = -1.;
2025 *pList[globalIndex] = label;
2026 *(pList[globalIndex]+3) = signal(ip,it);
2030 // check the signal magnitude
2032 Float_t highest = *(pList[globalIndex]+3);
2033 Float_t middle = *(pList[globalIndex]+4);
2034 Float_t lowest = *(pList[globalIndex]+5);
2037 // compare the new signal with already existing list
2040 if(signal(ip,it)<lowest) continue; // neglect this track
2044 if (signal(ip,it)>highest){
2045 *(pList[globalIndex]+5) = middle;
2046 *(pList[globalIndex]+4) = highest;
2047 *(pList[globalIndex]+3) = signal(ip,it);
2049 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
2050 *(pList[globalIndex]+1) = *pList[globalIndex];
2051 *pList[globalIndex] = label;
2053 else if (signal(ip,it)>middle){
2054 *(pList[globalIndex]+5) = middle;
2055 *(pList[globalIndex]+4) = signal(ip,it);
2057 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
2058 *(pList[globalIndex]+1) = label;
2061 *(pList[globalIndex]+5) = signal(ip,it);
2062 *(pList[globalIndex]+2) = label;
2066 } // end of loop over pads
2067 } // end of loop over time bins
2072 //___________________________________________________________________
2073 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
2074 Stat_t ntracks,TObjArray **row)
2077 //-----------------------------------------------------------------
2078 // Prepares the sector digitization, creates the vectors of
2079 // tracks for each row of this sector. The track vector
2080 // contains the track label and the position of electrons.
2081 //-----------------------------------------------------------------
2083 //-----------------------------------------------------------------
2084 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2085 //-----------------------------------------------------------------
2087 Float_t gasgain = fTPCParam->GetGasGain();
2091 AliTPChit *tpcHit; // pointer to a sigle TPC hit
2094 if (fHitType>1) branch = TH->GetBranch("TPC2");
2095 else branch = TH->GetBranch("TPC");
2098 //----------------------------------------------
2099 // Create TObjArray-s, one for each row,
2100 // each TObjArray will store the TVectors
2101 // of electrons, one TVector per each track.
2102 //----------------------------------------------
2104 Int_t *nofElectrons = new Int_t [nrows]; // electron counter for each row
2105 TVector **tracks = new TVector* [nrows]; //pointers to the track vectors
2106 for(i=0; i<nrows; i++){
2107 row[i] = new TObjArray;
2114 //--------------------------------------------------------------------
2115 // Loop over tracks, the "track" contains the full history
2116 //--------------------------------------------------------------------
2118 Int_t previousTrack,currentTrack;
2119 previousTrack = -1; // nothing to store so far!
2121 for(Int_t track=0;track<ntracks;track++){
2122 Bool_t isInSector=kTRUE;
2124 isInSector = TrackInVolume(isec,track);
2125 if (!isInSector) continue;
2127 branch->GetEntry(track); // get next track
2131 tpcHit = (AliTPChit*)FirstHit(-1);
2133 //--------------------------------------------------------------
2135 //--------------------------------------------------------------
2140 Int_t sector=tpcHit->fSector; // sector number
2142 tpcHit = (AliTPChit*) NextHit();
2146 currentTrack = tpcHit->Track(); // track number
2149 if(currentTrack != previousTrack){
2151 // store already filled fTrack
2153 for(i=0;i<nrows;i++){
2154 if(previousTrack != -1){
2155 if(nofElectrons[i]>0){
2156 TVector &v = *tracks[i];
2157 v(0) = previousTrack;
2158 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2159 row[i]->Add(tracks[i]);
2162 delete tracks[i]; // delete empty TVector
2168 tracks[i] = new TVector(481); // TVectors for the next fTrack
2170 } // end of loop over rows
2172 previousTrack=currentTrack; // update track label
2175 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2177 //---------------------------------------------------
2178 // Calculate the electron attachment probability
2179 //---------------------------------------------------
2182 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
2183 /fTPCParam->GetDriftV();
2185 Float_t attProb = fTPCParam->GetAttCoef()*
2186 fTPCParam->GetOxyCont()*time; // fraction!
2188 //-----------------------------------------------
2189 // Loop over electrons
2190 //-----------------------------------------------
2193 for(Int_t nel=0;nel<qI;nel++){
2194 // skip if electron lost due to the attachment
2195 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2200 // protection for the nonphysical avalanche size (10**6 maximum)
2202 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2203 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2206 TransportElectron(xyz,index); //MI change -august
2208 fTPCParam->GetPadRow(xyz,index); //MI change august
2209 rowNumber = index[2];
2210 //transform position to local digit coordinates
2211 //relative to nearest pad row
2212 if ((rowNumber<0)||rowNumber>=fTPCParam->GetNRow(isec)) continue;
2213 nofElectrons[rowNumber]++;
2214 //----------------------------------
2215 // Expand vector if necessary
2216 //----------------------------------
2217 if(nofElectrons[rowNumber]>120){
2218 Int_t range = tracks[rowNumber]->GetNrows();
2219 if((nofElectrons[rowNumber])>(range-1)/4){
2221 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
2225 TVector &v = *tracks[rowNumber];
2226 Int_t idx = 4*nofElectrons[rowNumber]-3;
2228 v(idx)= xyz[0]; // X - pad row coordinate
2229 v(idx+1)=xyz[1]; // Y - pad coordinate (along the pad-row)
2230 v(idx+2)=xyz[2]; // Z - time bin coordinate
2231 v(idx+3)=xyz[3]; // avalanche size
2232 } // end of loop over electrons
2234 tpcHit = (AliTPChit*)NextHit();
2236 } // end of loop over hits
2237 } // end of loop over tracks
2240 // store remaining track (the last one) if not empty
2243 for(i=0;i<nrows;i++){
2244 if(nofElectrons[i]>0){
2245 TVector &v = *tracks[i];
2246 v(0) = previousTrack;
2247 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2248 row[i]->Add(tracks[i]);
2257 delete [] nofElectrons;
2260 } // end of MakeSector
2263 //_____________________________________________________________________________
2267 // Initialise TPC detector after definition of geometry
2272 printf("\n%s: ",ClassName());
2273 for(i=0;i<35;i++) printf("*");
2274 printf(" TPC_INIT ");
2275 for(i=0;i<35;i++) printf("*");
2276 printf("\n%s: ",ClassName());
2278 for(i=0;i<80;i++) printf("*");
2283 //_____________________________________________________________________________
2284 void AliTPC::MakeBranch(Option_t* option, const char *file)
2287 // Create Tree branches for the TPC.
2289 Int_t buffersize = 4000;
2290 char branchname[10];
2291 sprintf(branchname,"%s",GetName());
2293 AliDetector::MakeBranch(option,file);
2295 const char *d = strstr(option,"D");
2297 if (fDigits && gAlice->TreeD() && d) {
2298 MakeBranchInTree(gAlice->TreeD(),
2299 branchname, &fDigits, buffersize, file);
2302 if (fHitType>1) MakeBranch2(option,file); // MI change 14.09.2000
2305 //_____________________________________________________________________________
2306 void AliTPC::ResetDigits()
2309 // Reset number of digits and the digits array for this detector
2312 if (fDigits) fDigits->Clear();
2315 //_____________________________________________________________________________
2316 void AliTPC::SetSecAL(Int_t sec)
2318 //---------------------------------------------------
2319 // Activate/deactivate selection for lower sectors
2320 //---------------------------------------------------
2322 //-----------------------------------------------------------------
2323 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2324 //-----------------------------------------------------------------
2329 //_____________________________________________________________________________
2330 void AliTPC::SetSecAU(Int_t sec)
2332 //----------------------------------------------------
2333 // Activate/deactivate selection for upper sectors
2334 //---------------------------------------------------
2336 //-----------------------------------------------------------------
2337 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2338 //-----------------------------------------------------------------
2343 //_____________________________________________________________________________
2344 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
2346 //----------------------------------------
2347 // Select active lower sectors
2348 //----------------------------------------
2350 //-----------------------------------------------------------------
2351 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2352 //-----------------------------------------------------------------
2362 //_____________________________________________________________________________
2363 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
2364 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
2365 Int_t s11 , Int_t s12)
2367 //--------------------------------
2368 // Select active upper sectors
2369 //--------------------------------
2371 //-----------------------------------------------------------------
2372 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2373 //-----------------------------------------------------------------
2389 //_____________________________________________________________________________
2390 void AliTPC::SetSens(Int_t sens)
2393 //-------------------------------------------------------------
2394 // Activates/deactivates the sensitive strips at the center of
2395 // the pad row -- this is for the space-point resolution calculations
2396 //-------------------------------------------------------------
2398 //-----------------------------------------------------------------
2399 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2400 //-----------------------------------------------------------------
2406 void AliTPC::SetSide(Float_t side=0.)
2408 // choice of the TPC side
2413 //____________________________________________________________________________
2414 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2415 Float_t p2,Float_t p3)
2418 // gax mixture definition
2432 //_____________________________________________________________________________
2434 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2437 // electron transport taking into account:
2439 // 2.ExB at the wires
2440 // 3. nonisochronity
2442 // xyz and index must be already transformed to system 1
2445 fTPCParam->Transform1to2(xyz,index);
2448 Float_t driftl=xyz[2];
2449 if(driftl<0.01) driftl=0.01;
2450 driftl=TMath::Sqrt(driftl);
2451 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2452 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2453 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2454 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2455 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2459 if (fTPCParam->GetMWPCReadout()==kTRUE){
2461 fTPCParam->Transform2to2NearestWire(xyz,index);
2462 Float_t dx=xyz[0]-x1;
2463 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2465 //add nonisochronity (not implemented yet)
2469 ClassImp(AliTPCdigit)
2471 //_____________________________________________________________________________
2472 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2476 // Creates a TPC digit object
2478 fSector = digits[0];
2479 fPadRow = digits[1];
2482 fSignal = digits[4];
2488 //_____________________________________________________________________________
2489 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2493 // Creates a TPC hit object
2504 //________________________________________________________________________
2505 // Additional code because of the AliTPCTrackHitsV2
2507 void AliTPC::MakeBranch2(Option_t *option,const char *file)
2510 // Create a new branch in the current Root Tree
2511 // The branch of fHits is automatically split
2512 // MI change 14.09.2000
2513 if (fHitType<2) return;
2514 char branchname[10];
2515 sprintf(branchname,"%s2",GetName());
2517 // Get the pointer to the header
2518 const char *cH = strstr(option,"H");
2520 if (fTrackHits && gAlice->TreeH() && cH && fHitType&4) {
2521 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2522 // gAlice->TreeH(),fBufferSize,99);
2523 //TBranch * branch =
2524 gAlice->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2527 // gAlice->TreeH()->GetListOfBranches()->Add(branch);
2529 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2530 const char folder [] = "RunMC/Event/Data";
2532 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2533 Publish(folder,&fTrackHits,branchname);
2535 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2536 TDirectory *wd = gDirectory;
2538 TIter next( b->GetListOfBranches());
2539 while ((b=(TBranch*)next())) {
2544 cout << "Diverting branch " << branchname << " to file " << file << endl;
2548 if (fTrackHitsOld && gAlice->TreeH() && cH && fHitType&2) {
2549 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2550 gAlice->TreeH(),fBufferSize,99);
2551 //TBranch * branch = gAlice->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2554 gAlice->TreeH()->GetListOfBranches()->Add(branch);
2556 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2557 const char folder [] = "RunMC/Event/Data";
2559 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2560 Publish(folder,&fTrackHitsOld,branchname);
2562 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2563 TDirectory *wd = gDirectory;
2565 TIter next( b->GetListOfBranches());
2566 while ((b=(TBranch*)next())) {
2571 cout << "Diverting branch " << branchname << " to file " << file << endl;
2576 void AliTPC::SetTreeAddress()
2578 if (fHitType<=1) AliDetector::SetTreeAddress();
2579 if (fHitType>1) SetTreeAddress2();
2582 void AliTPC::SetTreeAddress2()
2585 // Set branch address for the TrackHits Tree
2588 char branchname[20];
2589 sprintf(branchname,"%s2",GetName());
2591 // Branch address for hit tree
2592 TTree *treeH = gAlice->TreeH();
2593 if ((treeH)&&(fHitType&4)) {
2594 branch = treeH->GetBranch(branchname);
2595 if (branch) branch->SetAddress(&fTrackHits);
2597 if ((treeH)&&(fHitType&2)) {
2598 branch = treeH->GetBranch(branchname);
2599 if (branch) branch->SetAddress(&fTrackHitsOld);
2604 void AliTPC::FinishPrimary()
2606 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2607 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2611 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2614 // add hit to the list
2617 int primary = gAlice->GetPrimary(track);
2618 gAlice->Particle(primary)->SetBit(kKeepBit);
2622 gAlice->FlagTrack(track);
2624 //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2625 //if (hit->fTrack!=rtrack)
2626 // cout<<"bad track number\n";
2627 if (fTrackHits && fHitType&4)
2628 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2629 hits[1],hits[2],(Int_t)hits[3]);
2630 if (fTrackHitsOld &&fHitType&2 )
2631 fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2632 hits[1],hits[2],(Int_t)hits[3]);
2636 void AliTPC::ResetHits()
2638 if (fHitType&1) AliDetector::ResetHits();
2639 if (fHitType>1) ResetHits2();
2642 void AliTPC::ResetHits2()
2646 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2647 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2651 AliHit* AliTPC::FirstHit(Int_t track)
2653 if (fHitType>1) return FirstHit2(track);
2654 return AliDetector::FirstHit(track);
2656 AliHit* AliTPC::NextHit()
2658 if (fHitType>1) return NextHit2();
2660 return AliDetector::NextHit();
2663 AliHit* AliTPC::FirstHit2(Int_t track)
2666 // Initialise the hit iterator
2667 // Return the address of the first hit for track
2668 // If track>=0 the track is read from disk
2669 // while if track<0 the first hit of the current
2670 // track is returned
2673 gAlice->ResetHits();
2674 gAlice->TreeH()->GetEvent(track);
2677 if (fTrackHits && fHitType&4) {
2678 fTrackHits->First();
2679 return fTrackHits->GetHit();
2681 if (fTrackHitsOld && fHitType&2) {
2682 fTrackHitsOld->First();
2683 return fTrackHitsOld->GetHit();
2689 AliHit* AliTPC::NextHit2()
2692 //Return the next hit for the current track
2695 if (fTrackHitsOld && fHitType&2) {
2696 fTrackHitsOld->Next();
2697 return fTrackHitsOld->GetHit();
2701 return fTrackHits->GetHit();
2707 void AliTPC::LoadPoints(Int_t)
2711 /* if(fHitType==1) return AliDetector::LoadPoints(a);
2714 if(fHitType==1) AliDetector::LoadPoints(a);
2715 else LoadPoints2(a);
2722 void AliTPC::RemapTrackHitIDs(Int_t *map)
2724 if (!fTrackHits) return;
2726 if (fTrackHitsOld && fHitType&2){
2727 AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2728 for (UInt_t i=0;i<arr->GetSize();i++){
2729 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2730 info->fTrackID = map[info->fTrackID];
2733 if (fTrackHitsOld && fHitType&4){
2734 TClonesArray * arr = fTrackHits->GetArray();;
2735 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2736 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2737 info->fTrackID = map[info->fTrackID];
2742 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2744 //return bool information - is track in given volume
2745 //load only part of the track information
2746 //return true if current track is in volume
2749 if (fTrackHitsOld && fHitType&2) {
2750 TBranch * br = gAlice->TreeH()->GetBranch("fTrackHitsInfo");
2751 br->GetEvent(track);
2752 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2753 for (UInt_t j=0;j<ar->GetSize();j++){
2754 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2758 if (fTrackHits && fHitType&4) {
2759 TBranch * br1 = gAlice->TreeH()->GetBranch("fVolumes");
2760 TBranch * br2 = gAlice->TreeH()->GetBranch("fNVolumes");
2761 br2->GetEvent(track);
2762 br1->GetEvent(track);
2763 Int_t *volumes = fTrackHits->GetVolumes();
2764 Int_t nvolumes = fTrackHits->GetNVolumes();
2765 if (!volumes && nvolumes>0) {
2766 printf("Problematic track\t%d\t%d",track,nvolumes);
2769 for (Int_t j=0;j<nvolumes; j++)
2770 if (volumes[j]==id) return kTRUE;
2774 TBranch * br = gAlice->TreeH()->GetBranch("fSector");
2775 br->GetEvent(track);
2776 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2777 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2784 //_____________________________________________________________________________
2785 void AliTPC::LoadPoints2(Int_t)
2788 // Store x, y, z of all hits in memory
2790 if (fTrackHits == 0 && fTrackHitsOld==0) return;
2793 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2794 if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2796 if (nhits == 0) return;
2797 Int_t tracks = gAlice->GetNtrack();
2798 if (fPoints == 0) fPoints = new TObjArray(tracks);
2801 Int_t *ntrk=new Int_t[tracks];
2802 Int_t *limi=new Int_t[tracks];
2803 Float_t **coor=new Float_t*[tracks];
2804 for(Int_t i=0;i<tracks;i++) {
2810 AliPoints *points = 0;
2813 Int_t chunk=nhits/4+1;
2815 // Loop over all the hits and store their position
2817 ahit = FirstHit2(-1);
2819 trk=ahit->GetTrack();
2820 if(ntrk[trk]==limi[trk]) {
2822 // Initialise a new track
2823 fp=new Float_t[3*(limi[trk]+chunk)];
2825 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2826 delete [] coor[trk];
2833 fp[3*ntrk[trk] ] = ahit->X();
2834 fp[3*ntrk[trk]+1] = ahit->Y();
2835 fp[3*ntrk[trk]+2] = ahit->Z();
2843 for(trk=0; trk<tracks; ++trk) {
2845 points = new AliPoints();
2846 points->SetMarkerColor(GetMarkerColor());
2847 points->SetMarkerSize(GetMarkerSize());
2848 points->SetDetector(this);
2849 points->SetParticle(trk);
2850 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2851 fPoints->AddAt(points,trk);
2852 delete [] coor[trk];
2862 //_____________________________________________________________________________
2863 void AliTPC::LoadPoints3(Int_t)
2866 // Store x, y, z of all hits in memory
2867 // - only intersection point with pad row
2868 if (fTrackHits == 0) return;
2870 Int_t nhits = fTrackHits->GetEntriesFast();
2871 if (nhits == 0) return;
2872 Int_t tracks = gAlice->GetNtrack();
2873 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2874 fPoints->Expand(2*tracks);
2877 Int_t *ntrk=new Int_t[tracks];
2878 Int_t *limi=new Int_t[tracks];
2879 Float_t **coor=new Float_t*[tracks];
2880 for(Int_t i=0;i<tracks;i++) {
2886 AliPoints *points = 0;
2889 Int_t chunk=nhits/4+1;
2891 // Loop over all the hits and store their position
2893 ahit = FirstHit2(-1);
2894 //for (Int_t hit=0;hit<nhits;hit++) {
2898 // ahit = (AliHit*)fHits->UncheckedAt(hit);
2899 trk=ahit->GetTrack();
2900 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2901 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2902 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2903 if (currentrow!=lastrow){
2904 lastrow = currentrow;
2905 //later calculate intersection point
2906 if(ntrk[trk]==limi[trk]) {
2908 // Initialise a new track
2909 fp=new Float_t[3*(limi[trk]+chunk)];
2911 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2912 delete [] coor[trk];
2919 fp[3*ntrk[trk] ] = ahit->X();
2920 fp[3*ntrk[trk]+1] = ahit->Y();
2921 fp[3*ntrk[trk]+2] = ahit->Z();
2928 for(trk=0; trk<tracks; ++trk) {
2930 points = new AliPoints();
2931 points->SetMarkerColor(GetMarkerColor()+1);
2932 points->SetMarkerStyle(5);
2933 points->SetMarkerSize(0.2);
2934 points->SetDetector(this);
2935 points->SetParticle(trk);
2936 // points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
2937 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2938 fPoints->AddAt(points,tracks+trk);
2939 delete [] coor[trk];
2950 void AliTPC::FindTrackHitsIntersection(TClonesArray * arr)
2954 //fill clones array with intersection of current point with the
2959 const Int_t kcmaxhits=30000;
2960 TVector * xxxx = new TVector(kcmaxhits*4);
2961 TVector & xxx = *xxxx;
2962 Int_t maxhits = kcmaxhits;
2965 AliTPChit * tpcHit=0;
2966 tpcHit = (AliTPChit*)FirstHit2(-1);
2967 Int_t currentIndex=0;
2968 Int_t lastrow=-1; //last writen row
2971 if (tpcHit==0) continue;
2972 sector=tpcHit->fSector; // sector number
2973 ipart=tpcHit->Track();
2977 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
2978 Int_t index[3]={1,sector,0};
2979 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2980 if (currentrow<0) continue;
2981 if (lastrow<0) lastrow=currentrow;
2982 if (currentrow==lastrow){
2983 if ( currentIndex>=maxhits){
2985 xxx.ResizeTo(4*maxhits);
2987 xxx(currentIndex*4)=x[0];
2988 xxx(currentIndex*4+1)=x[1];
2989 xxx(currentIndex*4+2)=x[2];
2990 xxx(currentIndex*4+3)=tpcHit->fQ;
2994 if (currentIndex>2){
3006 for (Int_t index=0;index<currentIndex;index++){
3008 x=x2=x3=x4=xxx(index*4);
3016 sumy+=xxx(index*4+1);
3017 sumxy+=xxx(index*4+1)*x;
3018 sumx2y+=xxx(index*4+1)*x2;
3019 sumz+=xxx(index*4+2);
3020 sumxz+=xxx(index*4+2)*x;
3021 sumx2z+=xxx(index*4+2)*x2;
3022 sumq+=xxx(index*4+3);
3024 Float_t centralPad = (fTPCParam->GetNPads(sector,lastrow)-1)/2;
3025 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
3026 sumx2*(sumx*sumx3-sumx2*sumx2);
3028 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
3029 sumx2*(sumxy*sumx3-sumx2y*sumx2);
3030 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
3031 sumx2*(sumxz*sumx3-sumx2z*sumx2);
3033 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
3034 sumx2*(sumx*sumx2y-sumx2*sumxy);
3035 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
3036 sumx2*(sumx*sumx2z-sumx2*sumxz);
3038 Float_t y=detay/det+centralPad;
3039 Float_t z=detaz/det;
3040 Float_t by=detby/det; //y angle
3041 Float_t bz=detbz/det; //z angle
3042 sumy/=Float_t(currentIndex);
3043 sumz/=Float_t(currentIndex);
3045 AliComplexCluster cl;
3051 cl.fTracks[0]=ipart;
3053 AliTPCClustersRow * row = (fClustersArray->GetRow(sector,lastrow));
3054 if (row!=0) row->InsertCluster(&cl);
3057 } //end of calculating cluster for given row
3059 } // end of loop over hits
3063 //_______________________________________________________________________________
3064 void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
3066 // produces rec points from digits and writes them on the root file
3067 // AliTPCclusters.root
3069 TDirectory *cwd = gDirectory;
3072 AliTPCParam *dig=(AliTPCParam *)gDirectory->Get("75x40_100x60");
3074 cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl;
3076 if(!gSystem->Getenv("CONFIG_FILE")){
3077 out=TFile::Open("AliTPCclusters.root","recreate");
3083 tmp1=gSystem->Getenv("CONFIG_FILE_PREFIX");
3084 tmp2=gSystem->Getenv("CONFIG_OUTDIR");
3085 sprintf(tmp3,"%s%s/AliTPCclusters.root",tmp1,tmp2);
3086 out=TFile::Open(tmp3,"recreate");
3090 cout<<"AliTPC::Digits2Reco - determination of rec points begins"<<endl;
3093 for(Int_t iev=firstevent;iev<lastevent+1;iev++){
3095 printf("Processing event %d\n",iev);
3096 Digits2Clusters(out,iev);
3098 cout<<"AliTPC::Digits2Reco - determination of rec points ended"<<endl;