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.52 2002/02/18 09:26:09 kowal2
19 Removed compiler warning
21 Revision 1.51 2002/01/21 17:13:21 kowal2
22 New track hits using root containers. Setting active sectors added.
24 Revision 1.50 2001/12/06 14:16:19 kowal2
27 Revision 1.49 2001/11/30 11:55:37 hristov
28 Noise table created in Hits2SDigits (M.Ivanov)
30 Revision 1.48 2001/11/24 16:10:21 kowal2
33 Revision 1.47 2001/11/19 10:25:34 kowal2
34 Nearest integer instead of integer when converting to ADC counts
36 Revision 1.46 2001/11/07 06:47:12 kowal2
39 Revision 1.45 2001/11/03 13:33:48 kowal2
40 Updated algorithms in Hits2SDigits, SDigits2Digits,
44 Revision 1.44 2001/08/30 09:28:48 hristov
45 TTree names are explicitly set via SetName(name) and then Write() is called
47 Revision 1.43 2001/07/28 12:02:54 hristov
48 Branch split level set to 99
50 Revision 1.42 2001/07/28 11:38:52 hristov
51 Loop variable declared once
53 Revision 1.41 2001/07/28 10:53:50 hristov
54 Digitisation done according to the general scheme (M.Ivanov)
56 Revision 1.40 2001/07/27 13:03:14 hristov
57 Default Branch split level set to 99
59 Revision 1.39 2001/07/26 09:09:34 kowal2
60 Hits2Reco method added
62 Revision 1.38 2001/07/20 14:32:43 kowal2
63 Processing of many events possible now
65 Revision 1.37 2001/06/12 07:17:18 kowal2
66 Hits2SDigits method implemented (summable digits)
68 Revision 1.36 2001/05/16 14:57:25 alibrary
69 New files for folders and Stack
71 Revision 1.35 2001/05/08 16:02:22 kowal2
72 Updated material specifications
74 Revision 1.34 2001/05/08 15:00:15 hristov
75 Corrections for tracking in arbitrary magnenetic field. Changes towards a concept of global Alice track. Back propagation of reconstructed tracks (Yu.Belikov)
77 Revision 1.33 2001/04/03 12:40:43 kowal2
80 Revision 1.32 2001/03/12 17:47:36 hristov
81 Changes needed on Sun with CC 5.0
83 Revision 1.31 2001/03/12 08:21:50 kowal2
84 Corrected C++ bug in the material definitions
86 Revision 1.30 2001/03/01 17:34:47 kowal2
87 Correction due to the accuracy problem
89 Revision 1.29 2001/02/28 16:34:40 kowal2
90 Protection against nonphysical values of the avalanche size,
93 Revision 1.28 2001/01/26 19:57:19 hristov
94 Major upgrade of AliRoot code
96 Revision 1.27 2001/01/13 17:29:33 kowal2
97 Sun compiler correction
99 Revision 1.26 2001/01/10 07:59:43 kowal2
100 Corrections to load points from the noncompressed hits.
102 Revision 1.25 2000/11/02 07:25:31 kowal2
103 Changes due to the new hit structure.
106 Revision 1.24 2000/10/05 16:06:09 kowal2
107 Forward declarations. Changes due to a new class AliComplexCluster.
109 Revision 1.23 2000/10/02 21:28:18 fca
110 Removal of useless dependecies via forward declarations
112 Revision 1.22 2000/07/10 20:57:39 hristov
113 Update of TPC code and macros by M.Kowalski
115 Revision 1.19.2.4 2000/06/26 07:39:42 kowal2
116 Changes to obey the coding rules
118 Revision 1.19.2.3 2000/06/25 08:38:41 kowal2
119 Splitted from AliTPCtracking
121 Revision 1.19.2.2 2000/06/16 12:59:28 kowal2
122 Changed parameter settings
124 Revision 1.19.2.1 2000/06/09 07:15:07 kowal2
126 Defaults loaded automatically (hard-wired)
127 Optional parameters can be set via macro called in the constructor
129 Revision 1.19 2000/04/18 19:00:59 fca
130 Small bug fixes to TPC files
132 Revision 1.18 2000/04/17 09:37:33 kowal2
133 removed obsolete AliTPCDigitsDisplay.C
135 Revision 1.17.2.2 2000/04/10 08:15:12 kowal2
137 New, experimental data structure from M. Ivanov
138 New tracking algorithm
139 Different pad geometry for different sectors
140 Digitization rewritten
142 Revision 1.17.2.1 2000/04/10 07:56:53 kowal2
143 Not used anymore - removed
145 Revision 1.17 2000/01/19 17:17:30 fca
146 Introducing a list of lists of hits -- more hits allowed for detector now
148 Revision 1.16 1999/11/05 09:29:23 fca
149 Accept only signals > 0
151 Revision 1.15 1999/10/08 06:26:53 fca
152 Removed ClustersIndex - not used anymore
154 Revision 1.14 1999/09/29 09:24:33 fca
155 Introduction of the Copyright and cvs Log
159 ///////////////////////////////////////////////////////////////////////////////
161 // Time Projection Chamber //
162 // This class contains the basic functions for the Time Projection Chamber //
163 // detector. Functions specific to one particular geometry are //
164 // contained in the derived classes //
168 <img src="picts/AliTPCClass.gif">
173 ///////////////////////////////////////////////////////////////////////////////
181 #include <TGeometry.h>
184 #include <TObjectTable.h>
185 #include "TParticle.h"
191 #include <iostream.h>
198 #include "AliTPCParamSR.h"
199 #include "AliTPCPRF2D.h"
200 #include "AliTPCRF1D.h"
201 #include "AliDigits.h"
202 #include "AliSimDigits.h"
203 #include "AliTPCTrackHits.h"
204 #include "AliTPCTrackHitsV2.h"
205 #include "AliPoints.h"
206 #include "AliArrayBranch.h"
209 #include "AliTPCDigitsArray.h"
210 #include "AliComplexCluster.h"
211 #include "AliClusters.h"
212 #include "AliTPCClustersRow.h"
213 #include "AliTPCClustersArray.h"
215 #include "AliTPCcluster.h"
216 #include "AliTPCclusterer.h"
217 #include "AliTPCtracker.h"
219 #include <TInterpreter.h>
226 //_____________________________________________________________________________
227 // helper class for fast matrix and vector manipulation - no range checking
228 // origin - Marian Ivanov
230 class AliTPCFastMatrix : public TMatrix {
232 AliTPCFastMatrix(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb);
233 inline Float_t & UncheckedAt(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
234 inline Float_t UncheckedAtFast(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
237 AliTPCFastMatrix::AliTPCFastMatrix(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb):
238 TMatrix(row_lwb, row_upb,col_lwb,col_upb)
241 //_____________________________________________________________________________
242 class AliTPCFastVector : public TVector {
244 AliTPCFastVector(Int_t size);
245 inline Float_t & UncheckedAt(Int_t index) const {return fElements[index];} //fast acces
248 AliTPCFastVector::AliTPCFastVector(Int_t size):TVector(size){
251 //_____________________________________________________________________________
255 // Default constructor
266 fHitType = 4; //default CONTAINERS - based on ROOT structure
273 //_____________________________________________________________________________
274 AliTPC::AliTPC(const char *name, const char *title)
275 : AliDetector(name,title)
278 // Standard constructor
282 // Initialise arrays of hits and digits
283 fHits = new TClonesArray("AliTPChit", 176);
284 gAlice->AddHitList(fHits);
289 fTrackHits = new AliTPCTrackHitsV2;
290 fTrackHits->SetHitPrecision(0.002);
291 fTrackHits->SetStepPrecision(0.003);
292 fTrackHits->SetMaxDistance(100);
294 fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
295 fTrackHitsOld->SetHitPrecision(0.002);
296 fTrackHitsOld->SetStepPrecision(0.003);
297 fTrackHitsOld->SetMaxDistance(100);
304 // Initialise counters
310 // Initialise color attributes
311 SetMarkerColor(kYellow);
314 // Set TPC parameters
318 if (!strcmp(title,"Default")) {
319 fTPCParam = new AliTPCParamSR;
321 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
327 //_____________________________________________________________________________
338 delete fTrackHits; //MI 15.09.2000
339 delete fTrackHitsOld; //MI 10.12.2001
340 if (fNoiseTable) delete [] fNoiseTable;
344 //_____________________________________________________________________________
345 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
348 // Add a hit to the list
350 // TClonesArray &lhits = *fHits;
351 // new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
353 TClonesArray &lhits = *fHits;
354 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
357 AddHit2(track,vol,hits);
360 //_____________________________________________________________________________
361 void AliTPC::BuildGeometry()
365 // Build TPC ROOT TNode geometry for the event display
370 const int kColorTPC=19;
371 char name[5], title[25];
372 const Double_t kDegrad=TMath::Pi()/180;
373 const Double_t kRaddeg=180./TMath::Pi();
376 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
377 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
379 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
380 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
382 Int_t nLo = fTPCParam->GetNInnerSector()/2;
383 Int_t nHi = fTPCParam->GetNOuterSector()/2;
385 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
386 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
387 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
388 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
391 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
392 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
398 // Get ALICE top node
401 nTop=gAlice->GetGeometry()->GetNode("alice");
405 rl = fTPCParam->GetInnerRadiusLow();
406 ru = fTPCParam->GetInnerRadiusUp();
410 sprintf(name,"LS%2.2d",i);
412 sprintf(title,"TPC low sector %3d",i);
415 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
416 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
417 tubs->SetNumberOfDivisions(1);
419 nNode = new TNode(name,title,name,0,0,0,"");
420 nNode->SetLineColor(kColorTPC);
426 rl = fTPCParam->GetOuterRadiusLow();
427 ru = fTPCParam->GetOuterRadiusUp();
430 sprintf(name,"US%2.2d",i);
432 sprintf(title,"TPC upper sector %d",i);
434 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
435 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
436 tubs->SetNumberOfDivisions(1);
438 nNode = new TNode(name,title,name,0,0,0,"");
439 nNode->SetLineColor(kColorTPC);
445 //_____________________________________________________________________________
446 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
449 // Calculate distance from TPC to mouse on the display
455 void AliTPC::Clusters2Tracks(TFile *of) {
456 //-----------------------------------------------------------------
457 // This is a track finder.
458 //-----------------------------------------------------------------
459 AliTPCtracker tracker(fTPCParam);
460 tracker.Clusters2Tracks(gFile,of);
463 //_____________________________________________________________________________
464 void AliTPC::CreateMaterials()
466 //-----------------------------------------------
467 // Create Materials for for TPC simulations
468 //-----------------------------------------------
470 //-----------------------------------------------------------------
471 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
472 //-----------------------------------------------------------------
474 Int_t iSXFLD=gAlice->Field()->Integ();
475 Float_t sXMGMX=gAlice->Field()->Max();
477 Float_t amat[5]; // atomic numbers
478 Float_t zmat[5]; // z
479 Float_t wmat[5]; // proportions
485 //***************** Gases *************************
487 //-------------------------------------------------
489 //-------------------------------------------------
500 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
510 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
513 //--------------------------------------------------------------
515 //--------------------------------------------------------------
532 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
534 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
549 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
551 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
567 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
569 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
571 //----------------------------------------------------------------
572 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
573 //----------------------------------------------------------------
579 Float_t rho,absl,X0,buf[1];
583 for(nc = 0;nc<fNoComp;nc++)
586 // retrive material constants
588 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,X0,absl,buf,nbuf);
593 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
595 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
596 density += fMixtProp[nc]*rho; // density of the mixture
600 // mixture proportions by weight!
602 for(nc = 0;nc<fNoComp;nc++)
605 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
607 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
608 apure[nnc] : amol[nnc])/am;
612 // Drift gases 1 - nonsensitive, 2 - sensitive
614 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
615 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
624 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
627 //----------------------------------------------------------------------
629 //----------------------------------------------------------------------
651 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
673 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
691 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
709 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
711 // SiO2 - used later for the glass fiber
723 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
732 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
741 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
750 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
768 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
787 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
789 // Epoxy - C14 H20 O3
806 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
814 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
818 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,X0,absl,buf,nbuf);
822 wmat[0]=0.644; // by weight!
825 density=0.5*(1.25+2.265);
827 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
831 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,X0,absl,buf,nbuf);
833 wmat[0]=0.725; // by weight!
838 AliMixture(39,"G10",amat,zmat,density,2,wmat);
843 //----------------------------------------------------------
844 // tracking media for gases
845 //----------------------------------------------------------
847 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
848 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
849 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
850 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
852 //-----------------------------------------------------------
853 // tracking media for solids
854 //-----------------------------------------------------------
856 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
857 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
858 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
859 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
860 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
861 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
862 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
863 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
864 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
865 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
866 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
867 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
871 void AliTPC::GenerNoise(Int_t tablesize)
874 //Generate table with noise
881 if (fNoiseTable) delete[] fNoiseTable;
882 fNoiseTable = new Float_t[tablesize];
883 fNoiseDepth = tablesize;
884 fCurrentNoise =0; //!index of the noise in the noise table
886 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
887 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
890 Float_t AliTPC::GetNoise()
892 // get noise from table
893 // if ((fCurrentNoise%10)==0)
894 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
895 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
896 return fNoiseTable[fCurrentNoise++];
897 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
901 Bool_t AliTPC::IsSectorActive(Int_t sec)
904 // check if the sector is active
905 if (!fActiveSectors) return kTRUE;
906 else return fActiveSectors[sec];
909 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
911 // activate interesting sectors
912 if (fActiveSectors) delete [] fActiveSectors;
913 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
914 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
915 for (Int_t i=0;i<n;i++)
916 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
920 void AliTPC::SetActiveSectors()
923 // activate sectors which were hitted by tracks
925 if (fHitType==0) return; // if Clones hit - not short volume ID information
926 if (fActiveSectors) delete [] fActiveSectors;
927 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
928 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
930 if (fHitType>1) branch = gAlice->TreeH()->GetBranch("TPC2");
931 else branch = gAlice->TreeH()->GetBranch("TPC");
932 Stat_t ntracks = gAlice->TreeH()->GetEntries();
933 // loop over all hits
934 for(Int_t track=0;track<ntracks;track++){
937 if (fTrackHits && fHitType&4) {
938 TBranch * br1 = gAlice->TreeH()->GetBranch("fVolumes");
939 TBranch * br2 = gAlice->TreeH()->GetBranch("fNVolumes");
940 br1->GetEvent(track);
941 br2->GetEvent(track);
942 Int_t *volumes = fTrackHits->GetVolumes();
943 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
944 fActiveSectors[volumes[j]]=kTRUE;
948 if (fTrackHitsOld && fHitType&2) {
949 TBranch * br = gAlice->TreeH()->GetBranch("fTrackHitsInfo");
951 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
952 for (UInt_t j=0;j<ar->GetSize();j++){
953 fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
963 void AliTPC::Digits2Clusters(TFile *of, Int_t eventnumber)
965 //-----------------------------------------------------------------
966 // This is a simple cluster finder.
967 //-----------------------------------------------------------------
968 AliTPCclusterer::Digits2Clusters(fTPCParam,of,eventnumber);
971 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
972 extern Double_t SigmaZ2(Double_t, Double_t);
973 //_____________________________________________________________________________
974 void AliTPC::Hits2Clusters(TFile *of, Int_t eventn)
976 //--------------------------------------------------------
977 // TPC simple cluster generator from hits
978 // obtained from the TPC Fast Simulator
979 // The point errors are taken from the parametrization
980 //--------------------------------------------------------
982 //-----------------------------------------------------------------
983 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
984 //-----------------------------------------------------------------
985 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
986 // Jouri.Belikov@cern.ch
987 //----------------------------------------------------------------
989 /////////////////////////////////////////////////////////////////////////////
991 //---------------------------------------------------------------------
992 // ALICE TPC Cluster Parameters
993 //--------------------------------------------------------------------
997 // Cluster width in rphi
998 const Float_t kACrphi=0.18322;
999 const Float_t kBCrphi=0.59551e-3;
1000 const Float_t kCCrphi=0.60952e-1;
1001 // Cluster width in z
1002 const Float_t kACz=0.19081;
1003 const Float_t kBCz=0.55938e-3;
1004 const Float_t kCCz=0.30428;
1006 TDirectory *savedir=gDirectory;
1008 if (!of->IsOpen()) {
1009 cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
1013 //if(fDefaults == 0) SetDefaults();
1015 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
1017 TParticle *particle; // pointer to a given particle
1018 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1022 Float_t pl,pt,tanth,rpad,ratio;
1025 //---------------------------------------------------------------
1026 // Get the access to the tracks
1027 //---------------------------------------------------------------
1029 TTree *tH = gAlice->TreeH();
1030 Stat_t ntracks = tH->GetEntries();
1032 //Switch to the output file
1037 sprintf(cname,"TreeC_TPC_%d",eventn);
1039 fTPCParam->Write(fTPCParam->GetTitle());
1040 AliTPCClustersArray carray;
1041 carray.Setup(fTPCParam);
1042 carray.SetClusterType("AliTPCcluster");
1045 Int_t nclusters=0; //cluster counter
1047 //------------------------------------------------------------
1048 // Loop over all sectors (72 sectors for 20 deg
1049 // segmentation for both lower and upper sectors)
1050 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
1051 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
1053 // First cluster for sector 0 starts at "0"
1054 //------------------------------------------------------------
1056 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
1058 fTPCParam->AdjustCosSin(isec,cph,sph);
1060 //------------------------------------------------------------
1062 //------------------------------------------------------------
1064 for(Int_t track=0;track<ntracks;track++){
1066 tH->GetEvent(track);
1068 // Get number of the TPC hits
1070 tpcHit = (AliTPChit*)FirstHit(-1);
1076 if (tpcHit->fQ == 0.) {
1077 tpcHit = (AliTPChit*) NextHit();
1078 continue; //information about track (I.Belikov)
1080 sector=tpcHit->fSector; // sector number
1083 tpcHit = (AliTPChit*) NextHit();
1086 ipart=tpcHit->Track();
1087 particle=gAlice->Particle(ipart);
1090 if(pt < 1.e-9) pt=1.e-9;
1092 tanth = TMath::Abs(tanth);
1093 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
1094 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
1096 // space-point resolutions
1098 sigmaRphi=SigmaY2(rpad,tanth,pt);
1099 sigmaZ =SigmaZ2(rpad,tanth );
1103 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
1104 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
1106 // temporary protection
1108 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
1109 if(sigmaZ < 0.) sigmaZ=0.4e-3;
1110 if(clRphi < 0.) clRphi=2.5e-3;
1111 if(clZ < 0.) clZ=2.5e-5;
1116 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
1117 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
1119 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
1120 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
1121 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
1122 Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
1123 fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
1124 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
1125 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
1126 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
1127 if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->Z();
1128 xyz[2]=sigmaRphi; // fSigmaY2
1129 xyz[3]=sigmaZ; // fSigmaZ2
1130 xyz[4]=tpcHit->fQ; // q
1132 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
1133 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
1135 Int_t tracks[3]={tpcHit->Track(), -1, -1};
1136 AliTPCcluster cluster(tracks,xyz);
1138 clrow->InsertCluster(&cluster); nclusters++;
1140 tpcHit = (AliTPChit*)NextHit();
1143 } // end of loop over hits
1145 } // end of loop over tracks
1147 Int_t nrows=fTPCParam->GetNRow(isec);
1148 for (Int_t irow=0; irow<nrows; irow++) {
1149 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
1150 if (!clrow) continue;
1151 carray.StoreRow(isec,irow);
1152 carray.ClearRow(isec,irow);
1155 } // end of loop over sectors
1157 cerr<<"Number of made clusters : "<<nclusters<<" \n";
1158 carray.GetTree()->SetName(cname);
1159 carray.GetTree()->Write();
1161 savedir->cd(); //switch back to the input file
1163 } // end of function
1165 //_________________________________________________________________
1166 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1168 //--------------------------------------------------------
1169 //calculate exact cross point of track and given pad row
1170 //resulting values are expressed in "digit" coordinata
1171 //--------------------------------------------------------
1173 //-----------------------------------------------------------------
1174 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1175 //-----------------------------------------------------------------
1177 if (fClustersArray==0){
1181 TParticle *particle; // pointer to a given particle
1182 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1183 // Int_t sector,nhits;
1185 const Int_t kcmaxhits=30000;
1186 AliTPCFastVector * xxxx = new AliTPCFastVector(kcmaxhits*4);
1187 AliTPCFastVector & xxx = *xxxx;
1188 Int_t maxhits = kcmaxhits;
1189 //construct array for each padrow
1190 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
1191 fClustersArray->CreateRow(isec,i);
1193 //---------------------------------------------------------------
1194 // Get the access to the tracks
1195 //---------------------------------------------------------------
1197 TTree *tH = gAlice->TreeH();
1198 Stat_t ntracks = tH->GetEntries();
1199 Int_t npart = gAlice->GetNtrack();
1202 if (fHitType>1) branch = tH->GetBranch("TPC2");
1203 else branch = tH->GetBranch("TPC");
1205 //------------------------------------------------------------
1207 //------------------------------------------------------------
1209 for(Int_t track=0;track<ntracks;track++){
1210 Bool_t isInSector=kTRUE;
1212 isInSector = TrackInVolume(isec,track);
1213 if (!isInSector) continue;
1215 branch->GetEntry(track); // get next track
1217 // Get number of the TPC hits and a pointer
1221 Int_t currentIndex=0;
1222 Int_t lastrow=-1; //last writen row
1226 tpcHit = (AliTPChit*)FirstHit(-1);
1229 Int_t sector=tpcHit->fSector; // sector number
1231 tpcHit = (AliTPChit*) NextHit();
1235 ipart=tpcHit->Track();
1236 if (ipart<npart) particle=gAlice->Particle(ipart);
1240 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
1241 Int_t index[3]={1,isec,0};
1242 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
1243 if (currentrow<0) {tpcHit = (AliTPChit*)NextHit(); continue;}
1244 if (lastrow<0) lastrow=currentrow;
1245 if (currentrow==lastrow){
1246 if ( currentIndex>=maxhits){
1248 xxx.ResizeTo(4*maxhits);
1250 xxx(currentIndex*4)=x[0];
1251 xxx(currentIndex*4+1)=x[1];
1252 xxx(currentIndex*4+2)=x[2];
1253 xxx(currentIndex*4+3)=tpcHit->fQ;
1257 if (currentIndex>2){
1269 for (Int_t index=0;index<currentIndex;index++){
1271 x=x2=x3=x4=xxx(index*4);
1279 sumy+=xxx(index*4+1);
1280 sumxy+=xxx(index*4+1)*x;
1281 sumx2y+=xxx(index*4+1)*x2;
1282 sumz+=xxx(index*4+2);
1283 sumxz+=xxx(index*4+2)*x;
1284 sumx2z+=xxx(index*4+2)*x2;
1285 sumq+=xxx(index*4+3);
1287 Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1288 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1289 sumx2*(sumx*sumx3-sumx2*sumx2);
1291 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1292 sumx2*(sumxy*sumx3-sumx2y*sumx2);
1293 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1294 sumx2*(sumxz*sumx3-sumx2z*sumx2);
1296 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1297 sumx2*(sumx*sumx2y-sumx2*sumxy);
1298 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1299 sumx2*(sumx*sumx2z-sumx2*sumxz);
1301 Float_t y=detay/det+centralPad;
1302 Float_t z=detaz/det;
1303 Float_t by=detby/det; //y angle
1304 Float_t bz=detbz/det; //z angle
1305 sumy/=Float_t(currentIndex);
1306 sumz/=Float_t(currentIndex);
1308 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1310 AliComplexCluster* cl = new((AliComplexCluster*)row->Append()) AliComplexCluster ;
1311 // AliComplexCluster cl;
1317 cl->fTracks[0]=ipart;
1321 } //end of calculating cluster for given row
1324 tpcHit = (AliTPChit*)NextHit();
1325 } // end of loop over hits
1326 } // end of loop over tracks
1327 //write padrows to tree
1328 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1329 fClustersArray->StoreRow(isec,ii);
1330 fClustersArray->ClearRow(isec,ii);
1339 void AliTPC::SDigits2Digits2(Int_t eventnumber)
1341 //create digits from summable digits
1342 GenerNoise(500000); //create teble with noise
1345 sprintf(sname,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1346 sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1348 //conect tree with sSDigits
1349 TTree *t = (TTree *)gDirectory->Get(sname);
1350 AliSimDigits digarr, *dummy=&digarr;
1351 t->GetBranch("Segment")->SetAddress(&dummy);
1352 Stat_t nentries = t->GetEntries();
1354 // set zero suppression
1356 fTPCParam->SetZeroSup(2);
1358 // get zero suppression
1360 Int_t zerosup = fTPCParam->GetZeroSup();
1362 //make tree with digits
1364 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1365 arr->SetClass("AliSimDigits");
1366 arr->Setup(fTPCParam);
1367 arr->MakeTree(fDigitsFile);
1369 AliTPCParam * par =fTPCParam;
1371 //Loop over segments of the TPC
1373 for (Int_t n=0; n<nentries; n++) {
1376 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1377 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
1380 if (!IsSectorActive(sec)) continue;
1381 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1382 Int_t nrows = digrow->GetNRows();
1383 Int_t ncols = digrow->GetNCols();
1385 digrow->ExpandBuffer();
1386 digarr.ExpandBuffer();
1387 digrow->ExpandTrackBuffer();
1388 digarr.ExpandTrackBuffer();
1391 Short_t * pamp0 = digarr.GetDigits();
1392 Int_t * ptracks0 = digarr.GetTracks();
1393 Short_t * pamp1 = digrow->GetDigits();
1394 Int_t * ptracks1 = digrow->GetTracks();
1395 Int_t nelems =nrows*ncols;
1396 Int_t saturation = fTPCParam->GetADCSat();
1397 //use internal structure of the AliDigits - for speed reason
1398 //if you cahnge implementation
1399 //of the Alidigits - it must be rewriten -
1400 for (Int_t i= 0; i<nelems; i++){
1401 // Float_t q = *pamp0;
1402 //q/=16.; //conversion faktor
1403 //Float_t noise= GetNoise();
1405 //q= TMath::Nint(q);
1406 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1408 if (q>saturation) q=saturation;
1410 //if (ptracks0[0]==0)
1413 ptracks1[0]=ptracks0[0];
1414 ptracks1[nelems]=ptracks0[nelems];
1415 ptracks1[2*nelems]=ptracks0[2*nelems];
1423 arr->StoreRow(sec,row);
1424 arr->ClearRow(sec,row);
1425 // cerr<<sec<<"\t"<<row<<"\n";
1432 arr->GetTree()->SetName(dname);
1433 arr->GetTree()->Write();
1436 //_________________________________________
1437 void AliTPC::Merge(TTree * intree, Int_t *mask, Int_t nin, Int_t outid)
1440 //intree - pointer to array of trees with s digits
1441 //mask - mask for each
1442 //nin - number of inputs
1443 //outid - event number of the output event
1445 //create digits from summable digits
1446 //conect tree with sSDigits
1449 AliSimDigits ** digarr = new AliSimDigits*[nin];
1450 for (Int_t i1=0;i1<nin; i1++){
1452 intree[i1].GetBranch("Segment")->SetAddress(&digarr[i1]);
1454 Stat_t nentries = intree[0].GetEntries();
1456 //make tree with digits
1458 sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),outid);
1459 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1460 arr->SetClass("AliSimDigits");
1461 arr->Setup(fTPCParam);
1462 arr->MakeTree(fDigitsFile);
1464 // set zero suppression
1466 fTPCParam->SetZeroSup(2);
1468 // get zero suppression
1470 Int_t zerosup = fTPCParam->GetZeroSup();
1473 AliTPCParam * par =fTPCParam;
1475 //Loop over segments of the TPC
1476 for (Int_t n=0; n<nentries; n++) {
1478 for (Int_t i=0;i<nin; i++){
1479 //connect proper digits
1480 intree[i].GetEvent(n);
1481 digarr[i]->ExpandBuffer();
1482 digarr[i]->ExpandTrackBuffer();
1485 if (!par->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
1486 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
1490 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1491 Int_t nrows = digrow->GetNRows();
1492 Int_t ncols = digrow->GetNCols();
1494 digrow->ExpandBuffer();
1495 digrow->ExpandTrackBuffer();
1497 for (Int_t rows=0;rows<nrows; rows++){
1498 for (Int_t col=0;col<ncols; col++){
1500 Int_t label[1000]; // i hope no more than 300 events merged
1502 // looop over digits
1503 for (Int_t i=0;i<nin; i++){
1504 q += digarr[i]->GetDigitFast(rows,col);
1505 for (Int_t tr=0;tr<3;tr++) {
1506 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
1508 label[labptr]=lab+mask[i]-2;
1514 q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac()*16);
1516 q/=16; //conversion faktor
1521 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat();
1522 digrow->SetDigitFast((Short_t)q,rows,col);
1523 for (Int_t tr=0;tr<3;tr++){
1525 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
1527 ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
1532 arr->StoreRow(sec,row);
1534 arr->ClearRow(sec,row);
1539 arr->GetTree()->SetName(dname);
1540 arr->GetTree()->Write();
1546 /*_________________________________________
1547 void AliTPC::SDigits2Digits(Int_t eventnumber)
1551 cerr<<"Digitizing TPC...\n";
1553 Hits2Digits(eventnumber);
1558 // char treeName[100];
1560 // sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1562 // GetDigitsArray()->GetTree()->Write(treeName);
1565 //__________________________________________________________________
1566 void AliTPC::SetDefaults(){
1569 cerr<<"Setting default parameters...\n";
1571 // Set response functions
1573 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1574 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1575 AliTPCPRF2D * prfouter = new AliTPCPRF2D;
1576 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1577 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1578 rf->SetOffset(3*param->GetZSigma());
1581 TDirectory *savedir=gDirectory;
1582 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1584 cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1587 prfinner->Read("prf_07504_Gati_056068_d02");
1588 prfouter->Read("prf_10006_Gati_047051_d03");
1592 param->SetInnerPRF(prfinner);
1593 param->SetOuterPRF(prfouter);
1594 param->SetTimeRF(rf);
1604 //__________________________________________________________________
1605 void AliTPC::Hits2Digits(Int_t eventnumber)
1607 //----------------------------------------------------
1608 // Loop over all sectors for a single event
1609 //----------------------------------------------------
1612 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1613 GenerNoise(500000); //create teble with noise
1615 //setup TPCDigitsArray
1617 if(GetDigitsArray()) delete GetDigitsArray();
1619 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1620 arr->SetClass("AliSimDigits");
1621 arr->Setup(fTPCParam);
1622 arr->MakeTree(fDigitsFile);
1623 SetDigitsArray(arr);
1625 fDigitsSwitch=0; // standard digits
1627 cerr<<"Digitizing TPC -- normal digits...\n";
1629 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1635 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1637 GetDigitsArray()->GetTree()->SetName(treeName);
1638 GetDigitsArray()->GetTree()->Write();
1645 //__________________________________________________________________
1646 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1649 //-----------------------------------------------------------
1650 // summable digits - 16 bit "ADC", no noise, no saturation
1651 //-----------------------------------------------------------
1653 //----------------------------------------------------
1654 // Loop over all sectors for a single event
1655 //----------------------------------------------------
1658 if(fDefaults == 0) SetDefaults();
1659 GenerNoise(500000); //create table with noise
1660 //setup TPCDigitsArray
1662 if(GetDigitsArray()) delete GetDigitsArray();
1664 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1665 arr->SetClass("AliSimDigits");
1666 arr->Setup(fTPCParam);
1667 arr->MakeTree(fDigitsFile);
1668 SetDigitsArray(arr);
1670 cerr<<"Digitizing TPC -- summable digits...\n";
1672 fDigitsSwitch=1; // summable digits
1674 // set zero suppression to "0"
1676 fTPCParam->SetZeroSup(0);
1678 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1685 sprintf(treeName,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1687 GetDigitsArray()->GetTree()->SetName(treeName);
1688 GetDigitsArray()->GetTree()->Write();
1694 //__________________________________________________________________
1695 void AliTPC::Hits2SDigits()
1698 //-----------------------------------------------------------
1699 // summable digits - 16 bit "ADC", no noise, no saturation
1700 //-----------------------------------------------------------
1702 //----------------------------------------------------
1703 // Loop over all sectors for a single event
1704 //----------------------------------------------------
1705 //MI change - for pp run
1706 Int_t eventnumber = gAlice->GetEvNumber();
1708 if(fDefaults == 0) SetDefaults();
1709 GenerNoise(500000); //create table with noise
1711 //setup TPCDigitsArray
1713 if(GetDigitsArray()) delete GetDigitsArray();
1715 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1716 arr->SetClass("AliSimDigits");
1717 arr->Setup(fTPCParam);
1718 arr->MakeTree(fDigitsFile);
1719 SetDigitsArray(arr);
1721 cerr<<"Digitizing TPC -- summable digits...\n";
1723 // fDigitsSwitch=1; // summable digits -for the moment direct
1725 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1731 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1733 GetDigitsArray()->GetTree()->SetName(treeName);
1734 GetDigitsArray()->GetTree()->Write();
1739 //_____________________________________________________________________________
1740 void AliTPC::Hits2DigitsSector(Int_t isec)
1742 //-------------------------------------------------------------------
1743 // TPC conversion from hits to digits.
1744 //-------------------------------------------------------------------
1746 //-----------------------------------------------------------------
1747 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1748 //-----------------------------------------------------------------
1750 //-------------------------------------------------------
1751 // Get the access to the track hits
1752 //-------------------------------------------------------
1754 // check if the parameters are set - important if one calls this method
1755 // directly, not from the Hits2Digits
1757 if(fDefaults == 0) SetDefaults();
1759 TTree *tH = gAlice->TreeH(); // pointer to the hits tree
1760 Stat_t ntracks = tH->GetEntries();
1764 //-------------------------------------------
1765 // Only if there are any tracks...
1766 //-------------------------------------------
1770 //printf("*** Processing sector number %d ***\n",isec);
1772 Int_t nrows =fTPCParam->GetNRow(isec);
1774 row= new TObjArray* [nrows];
1776 MakeSector(isec,nrows,tH,ntracks,row);
1778 //--------------------------------------------------------
1779 // Digitize this sector, row by row
1780 // row[i] is the pointer to the TObjArray of AliTPCFastVectors,
1781 // each one containing electrons accepted on this
1782 // row, assigned into tracks
1783 //--------------------------------------------------------
1787 if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree(fDigitsFile);
1789 for (i=0;i<nrows;i++){
1791 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1793 DigitizeRow(i,isec,row);
1795 fDigitsArray->StoreRow(isec,i);
1797 Int_t ndig = dig->GetDigitSize();
1798 if (gDebug > 10) printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1800 fDigitsArray->ClearRow(isec,i);
1803 } // end of the sector digitization
1805 for(i=0;i<nrows;i++){
1810 delete [] row; // delete the array of pointers to TObjArray-s
1814 } // end of Hits2DigitsSector
1817 //_____________________________________________________________________________
1818 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1820 //-----------------------------------------------------------
1821 // Single row digitization, coupling from the neighbouring
1822 // rows taken into account
1823 //-----------------------------------------------------------
1825 //-----------------------------------------------------------------
1826 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1827 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1828 //-----------------------------------------------------------------
1831 Float_t zerosup = fTPCParam->GetZeroSup();
1832 Int_t nrows =fTPCParam->GetNRow(isec);
1833 fCurrentIndex[1]= isec;
1836 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1837 Int_t nofTbins = fTPCParam->GetMaxTBin();
1838 Int_t indexRange[4];
1840 // Integrated signal for this row
1841 // and a single track signal
1844 AliTPCFastMatrix *m1 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // integrated
1845 AliTPCFastMatrix *m2 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // single
1847 AliTPCFastMatrix &total = *m1;
1849 // Array of pointers to the label-signal list
1851 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1852 Float_t **pList = new Float_t* [nofDigits];
1856 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1860 Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1861 Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1862 for (Int_t row= row1;row<=row2;row++){
1863 Int_t nTracks= rows[row]->GetEntries();
1864 for (i1=0;i1<nTracks;i1++){
1865 fCurrentIndex[2]= row;
1866 fCurrentIndex[3]=irow;
1868 m2->Zero(); // clear single track signal matrix
1869 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1870 GetList(trackLabel,nofPads,m2,indexRange,pList);
1872 else GetSignal(rows[row],i1,0,m1,indexRange);
1878 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1880 Float_t fzerosup = zerosup+0.5;
1881 for(Int_t it=0;it<nofTbins;it++){
1882 Float_t *pq = &(total.UncheckedAt(0,it));
1883 for(Int_t ip=0;ip<nofPads;ip++){
1887 if(fDigitsSwitch == 0){
1889 if(q <=fzerosup) continue; // do not fill zeros
1891 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1896 if(q <= 0.) continue; // do not fill zeros
1897 if(q>2000.) q=2000.;
1903 // "real" signal or electronic noise (list = -1)?
1906 for(Int_t j1=0;j1<3;j1++){
1907 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1912 <A NAME="AliDigits"></A>
1913 using of AliDigits object
1916 dig->SetDigitFast((Short_t)q,it,ip);
1917 if (fDigitsArray->IsSimulated())
1919 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1920 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1921 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1925 } // end of loop over time buckets
1926 } // end of lop over pads
1929 // This row has been digitized, delete nonused stuff
1932 for(lp=0;lp<nofDigits;lp++){
1933 if(pList[lp]) delete [] pList[lp];
1942 } // end of DigitizeRow
1944 //_____________________________________________________________________________
1946 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1947 AliTPCFastMatrix *m1, AliTPCFastMatrix *m2,Int_t *indexRange)
1950 //---------------------------------------------------------------
1951 // Calculates 2-D signal (pad,time) for a single track,
1952 // returns a pointer to the signal matrix and the track label
1953 // No digitization is performed at this level!!!
1954 //---------------------------------------------------------------
1956 //-----------------------------------------------------------------
1957 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1958 // Modified: Marian Ivanov
1959 //-----------------------------------------------------------------
1961 AliTPCFastVector *tv;
1963 tv = (AliTPCFastVector*)p1->At(ntr); // pointer to a track
1964 AliTPCFastVector &v = *tv;
1966 Float_t label = v(0);
1967 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
1969 Int_t nElectrons = (tv->GetNrows()-1)/4;
1970 indexRange[0]=9999; // min pad
1971 indexRange[1]=-1; // max pad
1972 indexRange[2]=9999; //min time
1973 indexRange[3]=-1; // max time
1975 AliTPCFastMatrix &signal = *m1;
1976 AliTPCFastMatrix &total = *m2;
1978 // Loop over all electrons
1980 for(Int_t nel=0; nel<nElectrons; nel++){
1982 Float_t aval = v(idx+4);
1983 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1984 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1985 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1987 Int_t *index = fTPCParam->GetResBin(0);
1988 Float_t *weight = & (fTPCParam->GetResWeight(0));
1990 if (n>0) for (Int_t i =0; i<n; i++){
1991 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1994 Int_t time=index[2];
1995 Float_t qweight = *(weight)*eltoadcfac;
1997 if (m1!=0) signal.UncheckedAt(pad,time)+=qweight;
1998 total.UncheckedAt(pad,time)+=qweight;
1999 if (indexRange[0]>pad) indexRange[0]=pad;
2000 if (indexRange[1]<pad) indexRange[1]=pad;
2001 if (indexRange[2]>time) indexRange[2]=time;
2002 if (indexRange[3]<time) indexRange[3]=time;
2009 } // end of loop over electrons
2011 return label; // returns track label when finished
2014 //_____________________________________________________________________________
2015 void AliTPC::GetList(Float_t label,Int_t np,AliTPCFastMatrix *m,
2016 Int_t *indexRange, Float_t **pList)
2018 //----------------------------------------------------------------------
2019 // Updates the list of tracks contributing to digits for a given row
2020 //----------------------------------------------------------------------
2022 //-----------------------------------------------------------------
2023 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2024 //-----------------------------------------------------------------
2026 AliTPCFastMatrix &signal = *m;
2028 // lop over nonzero digits
2030 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
2031 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
2034 // accept only the contribution larger than 500 electrons (1/2 s_noise)
2036 if(signal(ip,it)<0.5) continue;
2039 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
2041 if(!pList[globalIndex]){
2044 // Create new list (6 elements - 3 signals and 3 labels),
2047 pList[globalIndex] = new Float_t [6];
2051 *pList[globalIndex] = -1.;
2052 *(pList[globalIndex]+1) = -1.;
2053 *(pList[globalIndex]+2) = -1.;
2054 *(pList[globalIndex]+3) = -1.;
2055 *(pList[globalIndex]+4) = -1.;
2056 *(pList[globalIndex]+5) = -1.;
2059 *pList[globalIndex] = label;
2060 *(pList[globalIndex]+3) = signal(ip,it);
2064 // check the signal magnitude
2066 Float_t highest = *(pList[globalIndex]+3);
2067 Float_t middle = *(pList[globalIndex]+4);
2068 Float_t lowest = *(pList[globalIndex]+5);
2071 // compare the new signal with already existing list
2074 if(signal(ip,it)<lowest) continue; // neglect this track
2078 if (signal(ip,it)>highest){
2079 *(pList[globalIndex]+5) = middle;
2080 *(pList[globalIndex]+4) = highest;
2081 *(pList[globalIndex]+3) = signal(ip,it);
2083 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
2084 *(pList[globalIndex]+1) = *pList[globalIndex];
2085 *pList[globalIndex] = label;
2087 else if (signal(ip,it)>middle){
2088 *(pList[globalIndex]+5) = middle;
2089 *(pList[globalIndex]+4) = signal(ip,it);
2091 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
2092 *(pList[globalIndex]+1) = label;
2095 *(pList[globalIndex]+5) = signal(ip,it);
2096 *(pList[globalIndex]+2) = label;
2100 } // end of loop over pads
2101 } // end of loop over time bins
2106 //___________________________________________________________________
2107 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
2108 Stat_t ntracks,TObjArray **row)
2111 //-----------------------------------------------------------------
2112 // Prepares the sector digitization, creates the vectors of
2113 // tracks for each row of this sector. The track vector
2114 // contains the track label and the position of electrons.
2115 //-----------------------------------------------------------------
2117 //-----------------------------------------------------------------
2118 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2119 //-----------------------------------------------------------------
2121 Float_t gasgain = fTPCParam->GetGasGain();
2125 AliTPChit *tpcHit; // pointer to a sigle TPC hit
2128 if (fHitType>1) branch = TH->GetBranch("TPC2");
2129 else branch = TH->GetBranch("TPC");
2132 //----------------------------------------------
2133 // Create TObjArray-s, one for each row,
2134 // each TObjArray will store the AliTPCFastVectors
2135 // of electrons, one AliTPCFastVectors per each track.
2136 //----------------------------------------------
2138 Int_t *nofElectrons = new Int_t [nrows]; // electron counter for each row
2139 AliTPCFastVector **tracks = new AliTPCFastVector* [nrows]; //pointers to the track vectors
2141 for(i=0; i<nrows; i++){
2142 row[i] = new TObjArray;
2149 //--------------------------------------------------------------------
2150 // Loop over tracks, the "track" contains the full history
2151 //--------------------------------------------------------------------
2153 Int_t previousTrack,currentTrack;
2154 previousTrack = -1; // nothing to store so far!
2156 for(Int_t track=0;track<ntracks;track++){
2157 Bool_t isInSector=kTRUE;
2159 isInSector = TrackInVolume(isec,track);
2160 if (!isInSector) continue;
2162 branch->GetEntry(track); // get next track
2166 tpcHit = (AliTPChit*)FirstHit(-1);
2168 //--------------------------------------------------------------
2170 //--------------------------------------------------------------
2175 Int_t sector=tpcHit->fSector; // sector number
2177 tpcHit = (AliTPChit*) NextHit();
2181 currentTrack = tpcHit->Track(); // track number
2184 if(currentTrack != previousTrack){
2186 // store already filled fTrack
2188 for(i=0;i<nrows;i++){
2189 if(previousTrack != -1){
2190 if(nofElectrons[i]>0){
2191 AliTPCFastVector &v = *tracks[i];
2192 v(0) = previousTrack;
2193 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2194 row[i]->Add(tracks[i]);
2197 delete tracks[i]; // delete empty AliTPCFastVector
2203 tracks[i] = new AliTPCFastVector(481); // AliTPCFastVectors for the next fTrack
2205 } // end of loop over rows
2207 previousTrack=currentTrack; // update track label
2210 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2212 //---------------------------------------------------
2213 // Calculate the electron attachment probability
2214 //---------------------------------------------------
2217 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
2218 /fTPCParam->GetDriftV();
2220 Float_t attProb = fTPCParam->GetAttCoef()*
2221 fTPCParam->GetOxyCont()*time; // fraction!
2223 //-----------------------------------------------
2224 // Loop over electrons
2225 //-----------------------------------------------
2228 for(Int_t nel=0;nel<qI;nel++){
2229 // skip if electron lost due to the attachment
2230 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2235 // protection for the nonphysical avalanche size (10**6 maximum)
2237 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2238 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2241 TransportElectron(xyz,index); //MI change -august
2243 fTPCParam->GetPadRow(xyz,index); //MI change august
2244 rowNumber = index[2];
2245 //transform position to local digit coordinates
2246 //relative to nearest pad row
2247 if ((rowNumber<0)||rowNumber>=fTPCParam->GetNRow(isec)) continue;
2248 nofElectrons[rowNumber]++;
2249 //----------------------------------
2250 // Expand vector if necessary
2251 //----------------------------------
2252 if(nofElectrons[rowNumber]>120){
2253 Int_t range = tracks[rowNumber]->GetNrows();
2254 if((nofElectrons[rowNumber])>(range-1)/4){
2256 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
2260 AliTPCFastVector &v = *tracks[rowNumber];
2261 Int_t idx = 4*nofElectrons[rowNumber]-3;
2262 Real_t * position = &(((AliTPCFastVector&)v).UncheckedAt(idx)); //make code faster
2263 memcpy(position,xyz,4*sizeof(Float_t));
2265 } // end of loop over electrons
2267 tpcHit = (AliTPChit*)NextHit();
2269 } // end of loop over hits
2270 } // end of loop over tracks
2273 // store remaining track (the last one) if not empty
2276 for(i=0;i<nrows;i++){
2277 if(nofElectrons[i]>0){
2278 AliTPCFastVector &v = *tracks[i];
2279 v(0) = previousTrack;
2280 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2281 row[i]->Add(tracks[i]);
2290 delete [] nofElectrons;
2293 } // end of MakeSector
2296 //_____________________________________________________________________________
2300 // Initialise TPC detector after definition of geometry
2305 printf("\n%s: ",ClassName());
2306 for(i=0;i<35;i++) printf("*");
2307 printf(" TPC_INIT ");
2308 for(i=0;i<35;i++) printf("*");
2309 printf("\n%s: ",ClassName());
2311 for(i=0;i<80;i++) printf("*");
2316 //_____________________________________________________________________________
2317 void AliTPC::MakeBranch(Option_t* option, const char *file)
2320 // Create Tree branches for the TPC.
2322 Int_t buffersize = 4000;
2323 char branchname[10];
2324 sprintf(branchname,"%s",GetName());
2326 AliDetector::MakeBranch(option,file);
2328 const char *d = strstr(option,"D");
2330 if (fDigits && gAlice->TreeD() && d) {
2331 MakeBranchInTree(gAlice->TreeD(),
2332 branchname, &fDigits, buffersize, file);
2335 if (fHitType>1) MakeBranch2(option,file); // MI change 14.09.2000
2338 //_____________________________________________________________________________
2339 void AliTPC::ResetDigits()
2342 // Reset number of digits and the digits array for this detector
2345 if (fDigits) fDigits->Clear();
2348 //_____________________________________________________________________________
2349 void AliTPC::SetSecAL(Int_t sec)
2351 //---------------------------------------------------
2352 // Activate/deactivate selection for lower sectors
2353 //---------------------------------------------------
2355 //-----------------------------------------------------------------
2356 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2357 //-----------------------------------------------------------------
2362 //_____________________________________________________________________________
2363 void AliTPC::SetSecAU(Int_t sec)
2365 //----------------------------------------------------
2366 // Activate/deactivate selection for upper sectors
2367 //---------------------------------------------------
2369 //-----------------------------------------------------------------
2370 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2371 //-----------------------------------------------------------------
2376 //_____________________________________________________________________________
2377 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
2379 //----------------------------------------
2380 // Select active lower sectors
2381 //----------------------------------------
2383 //-----------------------------------------------------------------
2384 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2385 //-----------------------------------------------------------------
2395 //_____________________________________________________________________________
2396 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
2397 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
2398 Int_t s11 , Int_t s12)
2400 //--------------------------------
2401 // Select active upper sectors
2402 //--------------------------------
2404 //-----------------------------------------------------------------
2405 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2406 //-----------------------------------------------------------------
2422 //_____________________________________________________________________________
2423 void AliTPC::SetSens(Int_t sens)
2426 //-------------------------------------------------------------
2427 // Activates/deactivates the sensitive strips at the center of
2428 // the pad row -- this is for the space-point resolution calculations
2429 //-------------------------------------------------------------
2431 //-----------------------------------------------------------------
2432 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2433 //-----------------------------------------------------------------
2439 void AliTPC::SetSide(Float_t side=0.)
2441 // choice of the TPC side
2446 //____________________________________________________________________________
2447 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2448 Float_t p2,Float_t p3)
2451 // gax mixture definition
2465 //_____________________________________________________________________________
2467 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2470 // electron transport taking into account:
2472 // 2.ExB at the wires
2473 // 3. nonisochronity
2475 // xyz and index must be already transformed to system 1
2478 fTPCParam->Transform1to2(xyz,index);
2481 Float_t driftl=xyz[2];
2482 if(driftl<0.01) driftl=0.01;
2483 driftl=TMath::Sqrt(driftl);
2484 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2485 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2486 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2487 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2488 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2492 if (fTPCParam->GetMWPCReadout()==kTRUE){
2494 fTPCParam->Transform2to2NearestWire(xyz,index);
2495 Float_t dx=xyz[0]-x1;
2496 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2498 //add nonisochronity (not implemented yet)
2502 ClassImp(AliTPCdigit)
2504 //_____________________________________________________________________________
2505 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2509 // Creates a TPC digit object
2511 fSector = digits[0];
2512 fPadRow = digits[1];
2515 fSignal = digits[4];
2521 //_____________________________________________________________________________
2522 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2526 // Creates a TPC hit object
2537 //________________________________________________________________________
2538 // Additional code because of the AliTPCTrackHitsV2
2540 void AliTPC::MakeBranch2(Option_t *option,const char *file)
2543 // Create a new branch in the current Root Tree
2544 // The branch of fHits is automatically split
2545 // MI change 14.09.2000
2546 if (fHitType<2) return;
2547 char branchname[10];
2548 sprintf(branchname,"%s2",GetName());
2550 // Get the pointer to the header
2551 const char *cH = strstr(option,"H");
2553 if (fTrackHits && gAlice->TreeH() && cH && fHitType&4) {
2554 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2555 // gAlice->TreeH(),fBufferSize,99);
2556 //TBranch * branch =
2557 gAlice->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2560 // gAlice->TreeH()->GetListOfBranches()->Add(branch);
2562 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2563 const char folder [] = "RunMC/Event/Data";
2565 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2566 Publish(folder,&fTrackHits,branchname);
2568 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2569 TDirectory *wd = gDirectory;
2571 TIter next( b->GetListOfBranches());
2572 while ((b=(TBranch*)next())) {
2577 cout << "Diverting branch " << branchname << " to file " << file << endl;
2581 if (fTrackHitsOld && gAlice->TreeH() && cH && fHitType&2) {
2582 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2583 gAlice->TreeH(),fBufferSize,99);
2584 //TBranch * branch = gAlice->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2587 gAlice->TreeH()->GetListOfBranches()->Add(branch);
2589 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2590 const char folder [] = "RunMC/Event/Data";
2592 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2593 Publish(folder,&fTrackHitsOld,branchname);
2595 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2596 TDirectory *wd = gDirectory;
2598 TIter next( b->GetListOfBranches());
2599 while ((b=(TBranch*)next())) {
2604 cout << "Diverting branch " << branchname << " to file " << file << endl;
2609 void AliTPC::SetTreeAddress()
2611 if (fHitType<=1) AliDetector::SetTreeAddress();
2612 if (fHitType>1) SetTreeAddress2();
2615 void AliTPC::SetTreeAddress2()
2618 // Set branch address for the TrackHits Tree
2621 char branchname[20];
2622 sprintf(branchname,"%s2",GetName());
2624 // Branch address for hit tree
2625 TTree *treeH = gAlice->TreeH();
2626 if ((treeH)&&(fHitType&4)) {
2627 branch = treeH->GetBranch(branchname);
2628 if (branch) branch->SetAddress(&fTrackHits);
2630 if ((treeH)&&(fHitType&2)) {
2631 branch = treeH->GetBranch(branchname);
2632 if (branch) branch->SetAddress(&fTrackHitsOld);
2637 void AliTPC::FinishPrimary()
2639 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2640 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2644 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2647 // add hit to the list
2650 int primary = gAlice->GetPrimary(track);
2651 gAlice->Particle(primary)->SetBit(kKeepBit);
2655 gAlice->FlagTrack(track);
2657 //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2658 //if (hit->fTrack!=rtrack)
2659 // cout<<"bad track number\n";
2660 if (fTrackHits && fHitType&4)
2661 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2662 hits[1],hits[2],(Int_t)hits[3]);
2663 if (fTrackHitsOld &&fHitType&2 )
2664 fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2665 hits[1],hits[2],(Int_t)hits[3]);
2669 void AliTPC::ResetHits()
2671 if (fHitType&1) AliDetector::ResetHits();
2672 if (fHitType>1) ResetHits2();
2675 void AliTPC::ResetHits2()
2679 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2680 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2684 AliHit* AliTPC::FirstHit(Int_t track)
2686 if (fHitType>1) return FirstHit2(track);
2687 return AliDetector::FirstHit(track);
2689 AliHit* AliTPC::NextHit()
2691 if (fHitType>1) return NextHit2();
2693 return AliDetector::NextHit();
2696 AliHit* AliTPC::FirstHit2(Int_t track)
2699 // Initialise the hit iterator
2700 // Return the address of the first hit for track
2701 // If track>=0 the track is read from disk
2702 // while if track<0 the first hit of the current
2703 // track is returned
2706 gAlice->ResetHits();
2707 gAlice->TreeH()->GetEvent(track);
2710 if (fTrackHits && fHitType&4) {
2711 fTrackHits->First();
2712 return fTrackHits->GetHit();
2714 if (fTrackHitsOld && fHitType&2) {
2715 fTrackHitsOld->First();
2716 return fTrackHitsOld->GetHit();
2722 AliHit* AliTPC::NextHit2()
2725 //Return the next hit for the current track
2728 if (fTrackHitsOld && fHitType&2) {
2729 fTrackHitsOld->Next();
2730 return fTrackHitsOld->GetHit();
2734 return fTrackHits->GetHit();
2740 void AliTPC::LoadPoints(Int_t)
2744 /* if(fHitType==1) return AliDetector::LoadPoints(a);
2747 if(fHitType==1) AliDetector::LoadPoints(a);
2748 else LoadPoints2(a);
2755 void AliTPC::RemapTrackHitIDs(Int_t *map)
2757 if (!fTrackHits) return;
2759 if (fTrackHitsOld && fHitType&2){
2760 AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2761 for (UInt_t i=0;i<arr->GetSize();i++){
2762 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2763 info->fTrackID = map[info->fTrackID];
2766 if (fTrackHitsOld && fHitType&4){
2767 TClonesArray * arr = fTrackHits->GetArray();;
2768 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2769 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2770 info->fTrackID = map[info->fTrackID];
2775 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2777 //return bool information - is track in given volume
2778 //load only part of the track information
2779 //return true if current track is in volume
2782 if (fTrackHitsOld && fHitType&2) {
2783 TBranch * br = gAlice->TreeH()->GetBranch("fTrackHitsInfo");
2784 br->GetEvent(track);
2785 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2786 for (UInt_t j=0;j<ar->GetSize();j++){
2787 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2791 if (fTrackHits && fHitType&4) {
2792 TBranch * br1 = gAlice->TreeH()->GetBranch("fVolumes");
2793 TBranch * br2 = gAlice->TreeH()->GetBranch("fNVolumes");
2794 br2->GetEvent(track);
2795 br1->GetEvent(track);
2796 Int_t *volumes = fTrackHits->GetVolumes();
2797 Int_t nvolumes = fTrackHits->GetNVolumes();
2798 if (!volumes && nvolumes>0) {
2799 printf("Problematic track\t%d\t%d",track,nvolumes);
2802 for (Int_t j=0;j<nvolumes; j++)
2803 if (volumes[j]==id) return kTRUE;
2807 TBranch * br = gAlice->TreeH()->GetBranch("fSector");
2808 br->GetEvent(track);
2809 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2810 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2817 //_____________________________________________________________________________
2818 void AliTPC::LoadPoints2(Int_t)
2821 // Store x, y, z of all hits in memory
2823 if (fTrackHits == 0 && fTrackHitsOld==0) return;
2826 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2827 if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2829 if (nhits == 0) return;
2830 Int_t tracks = gAlice->GetNtrack();
2831 if (fPoints == 0) fPoints = new TObjArray(tracks);
2834 Int_t *ntrk=new Int_t[tracks];
2835 Int_t *limi=new Int_t[tracks];
2836 Float_t **coor=new Float_t*[tracks];
2837 for(Int_t i=0;i<tracks;i++) {
2843 AliPoints *points = 0;
2846 Int_t chunk=nhits/4+1;
2848 // Loop over all the hits and store their position
2850 ahit = FirstHit2(-1);
2852 trk=ahit->GetTrack();
2853 if(ntrk[trk]==limi[trk]) {
2855 // Initialise a new track
2856 fp=new Float_t[3*(limi[trk]+chunk)];
2858 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2859 delete [] coor[trk];
2866 fp[3*ntrk[trk] ] = ahit->X();
2867 fp[3*ntrk[trk]+1] = ahit->Y();
2868 fp[3*ntrk[trk]+2] = ahit->Z();
2876 for(trk=0; trk<tracks; ++trk) {
2878 points = new AliPoints();
2879 points->SetMarkerColor(GetMarkerColor());
2880 points->SetMarkerSize(GetMarkerSize());
2881 points->SetDetector(this);
2882 points->SetParticle(trk);
2883 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2884 fPoints->AddAt(points,trk);
2885 delete [] coor[trk];
2895 //_____________________________________________________________________________
2896 void AliTPC::LoadPoints3(Int_t)
2899 // Store x, y, z of all hits in memory
2900 // - only intersection point with pad row
2901 if (fTrackHits == 0) return;
2903 Int_t nhits = fTrackHits->GetEntriesFast();
2904 if (nhits == 0) return;
2905 Int_t tracks = gAlice->GetNtrack();
2906 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2907 fPoints->Expand(2*tracks);
2910 Int_t *ntrk=new Int_t[tracks];
2911 Int_t *limi=new Int_t[tracks];
2912 Float_t **coor=new Float_t*[tracks];
2913 for(Int_t i=0;i<tracks;i++) {
2919 AliPoints *points = 0;
2922 Int_t chunk=nhits/4+1;
2924 // Loop over all the hits and store their position
2926 ahit = FirstHit2(-1);
2927 //for (Int_t hit=0;hit<nhits;hit++) {
2931 // ahit = (AliHit*)fHits->UncheckedAt(hit);
2932 trk=ahit->GetTrack();
2933 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2934 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2935 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2936 if (currentrow!=lastrow){
2937 lastrow = currentrow;
2938 //later calculate intersection point
2939 if(ntrk[trk]==limi[trk]) {
2941 // Initialise a new track
2942 fp=new Float_t[3*(limi[trk]+chunk)];
2944 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2945 delete [] coor[trk];
2952 fp[3*ntrk[trk] ] = ahit->X();
2953 fp[3*ntrk[trk]+1] = ahit->Y();
2954 fp[3*ntrk[trk]+2] = ahit->Z();
2961 for(trk=0; trk<tracks; ++trk) {
2963 points = new AliPoints();
2964 points->SetMarkerColor(GetMarkerColor()+1);
2965 points->SetMarkerStyle(5);
2966 points->SetMarkerSize(0.2);
2967 points->SetDetector(this);
2968 points->SetParticle(trk);
2969 // points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
2970 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2971 fPoints->AddAt(points,tracks+trk);
2972 delete [] coor[trk];
2983 void AliTPC::FindTrackHitsIntersection(TClonesArray * arr)
2987 //fill clones array with intersection of current point with the
2992 const Int_t kcmaxhits=30000;
2993 AliTPCFastVector * xxxx = new AliTPCFastVector(kcmaxhits*4);
2994 AliTPCFastVector & xxx = *xxxx;
2995 Int_t maxhits = kcmaxhits;
2998 AliTPChit * tpcHit=0;
2999 tpcHit = (AliTPChit*)FirstHit2(-1);
3000 Int_t currentIndex=0;
3001 Int_t lastrow=-1; //last writen row
3004 if (tpcHit==0) continue;
3005 sector=tpcHit->fSector; // sector number
3006 ipart=tpcHit->Track();
3010 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
3011 Int_t index[3]={1,sector,0};
3012 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
3013 if (currentrow<0) continue;
3014 if (lastrow<0) lastrow=currentrow;
3015 if (currentrow==lastrow){
3016 if ( currentIndex>=maxhits){
3018 xxx.ResizeTo(4*maxhits);
3020 xxx(currentIndex*4)=x[0];
3021 xxx(currentIndex*4+1)=x[1];
3022 xxx(currentIndex*4+2)=x[2];
3023 xxx(currentIndex*4+3)=tpcHit->fQ;
3027 if (currentIndex>2){
3039 for (Int_t index=0;index<currentIndex;index++){
3041 x=x2=x3=x4=xxx(index*4);
3049 sumy+=xxx(index*4+1);
3050 sumxy+=xxx(index*4+1)*x;
3051 sumx2y+=xxx(index*4+1)*x2;
3052 sumz+=xxx(index*4+2);
3053 sumxz+=xxx(index*4+2)*x;
3054 sumx2z+=xxx(index*4+2)*x2;
3055 sumq+=xxx(index*4+3);
3057 Float_t centralPad = (fTPCParam->GetNPads(sector,lastrow)-1)/2;
3058 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
3059 sumx2*(sumx*sumx3-sumx2*sumx2);
3061 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
3062 sumx2*(sumxy*sumx3-sumx2y*sumx2);
3063 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
3064 sumx2*(sumxz*sumx3-sumx2z*sumx2);
3066 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
3067 sumx2*(sumx*sumx2y-sumx2*sumxy);
3068 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
3069 sumx2*(sumx*sumx2z-sumx2*sumxz);
3071 Float_t y=detay/det+centralPad;
3072 Float_t z=detaz/det;
3073 Float_t by=detby/det; //y angle
3074 Float_t bz=detbz/det; //z angle
3075 sumy/=Float_t(currentIndex);
3076 sumz/=Float_t(currentIndex);
3078 AliComplexCluster cl;
3084 cl.fTracks[0]=ipart;
3086 AliTPCClustersRow * row = (fClustersArray->GetRow(sector,lastrow));
3087 if (row!=0) row->InsertCluster(&cl);
3090 } //end of calculating cluster for given row
3092 } // end of loop over hits
3096 //_______________________________________________________________________________
3097 void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
3099 // produces rec points from digits and writes them on the root file
3100 // AliTPCclusters.root
3102 TDirectory *cwd = gDirectory;
3105 AliTPCParam *dig=(AliTPCParam *)gDirectory->Get("75x40_100x60");
3107 cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl;
3109 if(!gSystem->Getenv("CONFIG_FILE")){
3110 out=TFile::Open("AliTPCclusters.root","recreate");
3116 tmp1=gSystem->Getenv("CONFIG_FILE_PREFIX");
3117 tmp2=gSystem->Getenv("CONFIG_OUTDIR");
3118 sprintf(tmp3,"%s%s/AliTPCclusters.root",tmp1,tmp2);
3119 out=TFile::Open(tmp3,"recreate");
3123 cout<<"AliTPC::Digits2Reco - determination of rec points begins"<<endl;
3126 for(Int_t iev=firstevent;iev<lastevent+1;iev++){
3128 printf("Processing event %d\n",iev);
3129 Digits2Clusters(out,iev);
3131 cout<<"AliTPC::Digits2Reco - determination of rec points ended"<<endl;