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.55 2002/03/29 06:57:45 kowal2
19 Restored backward compatibility to use the hits from Dec. 2000 production.
21 Revision 1.54 2002/03/18 17:59:13 kowal2
22 Chnges in the pad geometry - 3 pad lengths introduced.
24 Revision 1.53 2002/02/25 11:02:56 kowal2
25 Changes towards speeding up the code. Thanks to Marian Ivanov.
27 Revision 1.52 2002/02/18 09:26:09 kowal2
28 Removed compiler warning
30 Revision 1.51 2002/01/21 17:13:21 kowal2
31 New track hits using root containers. Setting active sectors added.
33 Revision 1.50 2001/12/06 14:16:19 kowal2
36 Revision 1.49 2001/11/30 11:55:37 hristov
37 Noise table created in Hits2SDigits (M.Ivanov)
39 Revision 1.48 2001/11/24 16:10:21 kowal2
42 Revision 1.47 2001/11/19 10:25:34 kowal2
43 Nearest integer instead of integer when converting to ADC counts
45 Revision 1.46 2001/11/07 06:47:12 kowal2
48 Revision 1.45 2001/11/03 13:33:48 kowal2
49 Updated algorithms in Hits2SDigits, SDigits2Digits,
53 Revision 1.44 2001/08/30 09:28:48 hristov
54 TTree names are explicitly set via SetName(name) and then Write() is called
56 Revision 1.43 2001/07/28 12:02:54 hristov
57 Branch split level set to 99
59 Revision 1.42 2001/07/28 11:38:52 hristov
60 Loop variable declared once
62 Revision 1.41 2001/07/28 10:53:50 hristov
63 Digitisation done according to the general scheme (M.Ivanov)
65 Revision 1.40 2001/07/27 13:03:14 hristov
66 Default Branch split level set to 99
68 Revision 1.39 2001/07/26 09:09:34 kowal2
69 Hits2Reco method added
71 Revision 1.38 2001/07/20 14:32:43 kowal2
72 Processing of many events possible now
74 Revision 1.37 2001/06/12 07:17:18 kowal2
75 Hits2SDigits method implemented (summable digits)
77 Revision 1.36 2001/05/16 14:57:25 alibrary
78 New files for folders and Stack
80 Revision 1.35 2001/05/08 16:02:22 kowal2
81 Updated material specifications
83 Revision 1.34 2001/05/08 15:00:15 hristov
84 Corrections for tracking in arbitrary magnenetic field. Changes towards a concept of global Alice track. Back propagation of reconstructed tracks (Yu.Belikov)
86 Revision 1.33 2001/04/03 12:40:43 kowal2
89 Revision 1.32 2001/03/12 17:47:36 hristov
90 Changes needed on Sun with CC 5.0
92 Revision 1.31 2001/03/12 08:21:50 kowal2
93 Corrected C++ bug in the material definitions
95 Revision 1.30 2001/03/01 17:34:47 kowal2
96 Correction due to the accuracy problem
98 Revision 1.29 2001/02/28 16:34:40 kowal2
99 Protection against nonphysical values of the avalanche size,
102 Revision 1.28 2001/01/26 19:57:19 hristov
103 Major upgrade of AliRoot code
105 Revision 1.27 2001/01/13 17:29:33 kowal2
106 Sun compiler correction
108 Revision 1.26 2001/01/10 07:59:43 kowal2
109 Corrections to load points from the noncompressed hits.
111 Revision 1.25 2000/11/02 07:25:31 kowal2
112 Changes due to the new hit structure.
115 Revision 1.24 2000/10/05 16:06:09 kowal2
116 Forward declarations. Changes due to a new class AliComplexCluster.
118 Revision 1.23 2000/10/02 21:28:18 fca
119 Removal of useless dependecies via forward declarations
121 Revision 1.22 2000/07/10 20:57:39 hristov
122 Update of TPC code and macros by M.Kowalski
124 Revision 1.19.2.4 2000/06/26 07:39:42 kowal2
125 Changes to obey the coding rules
127 Revision 1.19.2.3 2000/06/25 08:38:41 kowal2
128 Splitted from AliTPCtracking
130 Revision 1.19.2.2 2000/06/16 12:59:28 kowal2
131 Changed parameter settings
133 Revision 1.19.2.1 2000/06/09 07:15:07 kowal2
135 Defaults loaded automatically (hard-wired)
136 Optional parameters can be set via macro called in the constructor
138 Revision 1.19 2000/04/18 19:00:59 fca
139 Small bug fixes to TPC files
141 Revision 1.18 2000/04/17 09:37:33 kowal2
142 removed obsolete AliTPCDigitsDisplay.C
144 Revision 1.17.2.2 2000/04/10 08:15:12 kowal2
146 New, experimental data structure from M. Ivanov
147 New tracking algorithm
148 Different pad geometry for different sectors
149 Digitization rewritten
151 Revision 1.17.2.1 2000/04/10 07:56:53 kowal2
152 Not used anymore - removed
154 Revision 1.17 2000/01/19 17:17:30 fca
155 Introducing a list of lists of hits -- more hits allowed for detector now
157 Revision 1.16 1999/11/05 09:29:23 fca
158 Accept only signals > 0
160 Revision 1.15 1999/10/08 06:26:53 fca
161 Removed ClustersIndex - not used anymore
163 Revision 1.14 1999/09/29 09:24:33 fca
164 Introduction of the Copyright and cvs Log
168 ///////////////////////////////////////////////////////////////////////////////
170 // Time Projection Chamber //
171 // This class contains the basic functions for the Time Projection Chamber //
172 // detector. Functions specific to one particular geometry are //
173 // contained in the derived classes //
177 <img src="picts/AliTPCClass.gif">
182 ///////////////////////////////////////////////////////////////////////////////
190 #include <TGeometry.h>
193 #include <TObjectTable.h>
194 #include "TParticle.h"
200 #include <iostream.h>
207 #include "AliTPCParamSR.h"
208 #include "AliTPCPRF2D.h"
209 #include "AliTPCRF1D.h"
210 #include "AliDigits.h"
211 #include "AliSimDigits.h"
212 #include "AliTPCTrackHits.h"
213 #include "AliTPCTrackHitsV2.h"
214 #include "AliPoints.h"
215 #include "AliArrayBranch.h"
218 #include "AliTPCDigitsArray.h"
219 #include "AliComplexCluster.h"
220 #include "AliClusters.h"
221 #include "AliTPCClustersRow.h"
222 #include "AliTPCClustersArray.h"
224 #include "AliTPCcluster.h"
225 #include "AliTPCclusterer.h"
226 #include "AliTPCtracker.h"
228 #include <TInterpreter.h>
235 //_____________________________________________________________________________
236 // helper class for fast matrix and vector manipulation - no range checking
237 // origin - Marian Ivanov
239 class AliTPCFastMatrix : public TMatrix {
241 AliTPCFastMatrix(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb);
242 inline Float_t & UncheckedAt(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
243 inline Float_t UncheckedAtFast(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
246 AliTPCFastMatrix::AliTPCFastMatrix(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb):
247 TMatrix(row_lwb, row_upb,col_lwb,col_upb)
250 //_____________________________________________________________________________
251 class AliTPCFastVector : public TVector {
253 AliTPCFastVector(Int_t size);
254 inline Float_t & UncheckedAt(Int_t index) const {return fElements[index];} //fast acces
257 AliTPCFastVector::AliTPCFastVector(Int_t size):TVector(size){
260 //_____________________________________________________________________________
264 // Default constructor
275 fHitType = 4; //default CONTAINERS - based on ROOT structure
282 //_____________________________________________________________________________
283 AliTPC::AliTPC(const char *name, const char *title)
284 : AliDetector(name,title)
287 // Standard constructor
291 // Initialise arrays of hits and digits
292 fHits = new TClonesArray("AliTPChit", 176);
293 gAlice->AddHitList(fHits);
298 fTrackHits = new AliTPCTrackHitsV2;
299 fTrackHits->SetHitPrecision(0.002);
300 fTrackHits->SetStepPrecision(0.003);
301 fTrackHits->SetMaxDistance(100);
303 fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
304 fTrackHitsOld->SetHitPrecision(0.002);
305 fTrackHitsOld->SetStepPrecision(0.003);
306 fTrackHitsOld->SetMaxDistance(100);
313 // Initialise counters
319 // Initialise color attributes
320 SetMarkerColor(kYellow);
323 // Set TPC parameters
327 if (!strcmp(title,"Default")) {
328 fTPCParam = new AliTPCParamSR;
330 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
336 //_____________________________________________________________________________
347 delete fTrackHits; //MI 15.09.2000
348 delete fTrackHitsOld; //MI 10.12.2001
349 if (fNoiseTable) delete [] fNoiseTable;
353 //_____________________________________________________________________________
354 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
357 // Add a hit to the list
359 // TClonesArray &lhits = *fHits;
360 // new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
362 TClonesArray &lhits = *fHits;
363 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
366 AddHit2(track,vol,hits);
369 //_____________________________________________________________________________
370 void AliTPC::BuildGeometry()
374 // Build TPC ROOT TNode geometry for the event display
379 const int kColorTPC=19;
380 char name[5], title[25];
381 const Double_t kDegrad=TMath::Pi()/180;
382 const Double_t kRaddeg=180./TMath::Pi();
385 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
386 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
388 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
389 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
391 Int_t nLo = fTPCParam->GetNInnerSector()/2;
392 Int_t nHi = fTPCParam->GetNOuterSector()/2;
394 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
395 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
396 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
397 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
400 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
401 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
407 // Get ALICE top node
410 nTop=gAlice->GetGeometry()->GetNode("alice");
414 rl = fTPCParam->GetInnerRadiusLow();
415 ru = fTPCParam->GetInnerRadiusUp();
419 sprintf(name,"LS%2.2d",i);
421 sprintf(title,"TPC low sector %3d",i);
424 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
425 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
426 tubs->SetNumberOfDivisions(1);
428 nNode = new TNode(name,title,name,0,0,0,"");
429 nNode->SetLineColor(kColorTPC);
435 rl = fTPCParam->GetOuterRadiusLow();
436 ru = fTPCParam->GetOuterRadiusUp();
439 sprintf(name,"US%2.2d",i);
441 sprintf(title,"TPC upper sector %d",i);
443 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
444 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
445 tubs->SetNumberOfDivisions(1);
447 nNode = new TNode(name,title,name,0,0,0,"");
448 nNode->SetLineColor(kColorTPC);
454 //_____________________________________________________________________________
455 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
458 // Calculate distance from TPC to mouse on the display
464 void AliTPC::Clusters2Tracks(TFile *of) {
465 //-----------------------------------------------------------------
466 // This is a track finder.
467 //-----------------------------------------------------------------
468 AliTPCtracker tracker(fTPCParam);
469 tracker.Clusters2Tracks(gFile,of);
472 //_____________________________________________________________________________
473 void AliTPC::CreateMaterials()
475 //-----------------------------------------------
476 // Create Materials for for TPC simulations
477 //-----------------------------------------------
479 //-----------------------------------------------------------------
480 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
481 //-----------------------------------------------------------------
483 Int_t iSXFLD=gAlice->Field()->Integ();
484 Float_t sXMGMX=gAlice->Field()->Max();
486 Float_t amat[5]; // atomic numbers
487 Float_t zmat[5]; // z
488 Float_t wmat[5]; // proportions
494 //***************** Gases *************************
496 //-------------------------------------------------
498 //-------------------------------------------------
509 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
519 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
522 //--------------------------------------------------------------
524 //--------------------------------------------------------------
541 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
543 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
558 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
560 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
576 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
578 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
580 //----------------------------------------------------------------
581 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
582 //----------------------------------------------------------------
588 Float_t rho,absl,X0,buf[1];
592 for(nc = 0;nc<fNoComp;nc++)
595 // retrive material constants
597 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,X0,absl,buf,nbuf);
602 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
604 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
605 density += fMixtProp[nc]*rho; // density of the mixture
609 // mixture proportions by weight!
611 for(nc = 0;nc<fNoComp;nc++)
614 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
616 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
617 apure[nnc] : amol[nnc])/am;
621 // Drift gases 1 - nonsensitive, 2 - sensitive
623 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
624 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
633 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
636 //----------------------------------------------------------------------
638 //----------------------------------------------------------------------
660 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
682 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
700 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
718 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
720 // SiO2 - used later for the glass fiber
732 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
741 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
750 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
759 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
777 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
796 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
798 // Epoxy - C14 H20 O3
815 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
823 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
827 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,X0,absl,buf,nbuf);
831 wmat[0]=0.644; // by weight!
834 density=0.5*(1.25+2.265);
836 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
840 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,X0,absl,buf,nbuf);
842 wmat[0]=0.725; // by weight!
847 AliMixture(39,"G10",amat,zmat,density,2,wmat);
852 //----------------------------------------------------------
853 // tracking media for gases
854 //----------------------------------------------------------
856 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
857 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
858 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
859 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
861 //-----------------------------------------------------------
862 // tracking media for solids
863 //-----------------------------------------------------------
865 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
866 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
867 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
868 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
869 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
870 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
871 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
872 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
873 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
874 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
875 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
876 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
880 void AliTPC::GenerNoise(Int_t tablesize)
883 //Generate table with noise
890 if (fNoiseTable) delete[] fNoiseTable;
891 fNoiseTable = new Float_t[tablesize];
892 fNoiseDepth = tablesize;
893 fCurrentNoise =0; //!index of the noise in the noise table
895 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
896 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
899 Float_t AliTPC::GetNoise()
901 // get noise from table
902 // if ((fCurrentNoise%10)==0)
903 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
904 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
905 return fNoiseTable[fCurrentNoise++];
906 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
910 Bool_t AliTPC::IsSectorActive(Int_t sec)
913 // check if the sector is active
914 if (!fActiveSectors) return kTRUE;
915 else return fActiveSectors[sec];
918 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
920 // activate interesting sectors
921 if (fActiveSectors) delete [] fActiveSectors;
922 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
923 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
924 for (Int_t i=0;i<n;i++)
925 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
929 void AliTPC::SetActiveSectors(Int_t flag)
932 // activate sectors which were hitted by tracks
934 if (fHitType==0) return; // if Clones hit - not short volume ID information
935 if (fActiveSectors) delete [] fActiveSectors;
936 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
938 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
941 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
943 if (fHitType>1) branch = gAlice->TreeH()->GetBranch("TPC2");
944 else branch = gAlice->TreeH()->GetBranch("TPC");
945 Stat_t ntracks = gAlice->TreeH()->GetEntries();
946 // loop over all hits
947 for(Int_t track=0;track<ntracks;track++){
950 if (fTrackHits && fHitType&4) {
951 TBranch * br1 = gAlice->TreeH()->GetBranch("fVolumes");
952 TBranch * br2 = gAlice->TreeH()->GetBranch("fNVolumes");
953 br1->GetEvent(track);
954 br2->GetEvent(track);
955 Int_t *volumes = fTrackHits->GetVolumes();
956 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
957 fActiveSectors[volumes[j]]=kTRUE;
961 if (fTrackHitsOld && fHitType&2) {
962 TBranch * br = gAlice->TreeH()->GetBranch("fTrackHitsInfo");
964 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
965 for (UInt_t j=0;j<ar->GetSize();j++){
966 fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
976 void AliTPC::Digits2Clusters(TFile *of, Int_t eventnumber)
978 //-----------------------------------------------------------------
979 // This is a simple cluster finder.
980 //-----------------------------------------------------------------
981 AliTPCclusterer::Digits2Clusters(fTPCParam,of,eventnumber);
984 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
985 extern Double_t SigmaZ2(Double_t, Double_t);
986 //_____________________________________________________________________________
987 void AliTPC::Hits2Clusters(TFile *of, Int_t eventn)
989 //--------------------------------------------------------
990 // TPC simple cluster generator from hits
991 // obtained from the TPC Fast Simulator
992 // The point errors are taken from the parametrization
993 //--------------------------------------------------------
995 //-----------------------------------------------------------------
996 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
997 //-----------------------------------------------------------------
998 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
999 // Jouri.Belikov@cern.ch
1000 //----------------------------------------------------------------
1002 /////////////////////////////////////////////////////////////////////////////
1004 //---------------------------------------------------------------------
1005 // ALICE TPC Cluster Parameters
1006 //--------------------------------------------------------------------
1010 // Cluster width in rphi
1011 const Float_t kACrphi=0.18322;
1012 const Float_t kBCrphi=0.59551e-3;
1013 const Float_t kCCrphi=0.60952e-1;
1014 // Cluster width in z
1015 const Float_t kACz=0.19081;
1016 const Float_t kBCz=0.55938e-3;
1017 const Float_t kCCz=0.30428;
1019 TDirectory *savedir=gDirectory;
1021 if (!of->IsOpen()) {
1022 cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
1026 //if(fDefaults == 0) SetDefaults();
1028 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
1030 TParticle *particle; // pointer to a given particle
1031 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1035 Float_t pl,pt,tanth,rpad,ratio;
1038 //---------------------------------------------------------------
1039 // Get the access to the tracks
1040 //---------------------------------------------------------------
1042 TTree *tH = gAlice->TreeH();
1043 Stat_t ntracks = tH->GetEntries();
1045 //Switch to the output file
1050 sprintf(cname,"TreeC_TPC_%d",eventn);
1052 fTPCParam->Write(fTPCParam->GetTitle());
1053 AliTPCClustersArray carray;
1054 carray.Setup(fTPCParam);
1055 carray.SetClusterType("AliTPCcluster");
1058 Int_t nclusters=0; //cluster counter
1060 //------------------------------------------------------------
1061 // Loop over all sectors (72 sectors for 20 deg
1062 // segmentation for both lower and upper sectors)
1063 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
1064 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
1066 // First cluster for sector 0 starts at "0"
1067 //------------------------------------------------------------
1069 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
1071 fTPCParam->AdjustCosSin(isec,cph,sph);
1073 //------------------------------------------------------------
1075 //------------------------------------------------------------
1077 for(Int_t track=0;track<ntracks;track++){
1079 tH->GetEvent(track);
1081 // Get number of the TPC hits
1083 tpcHit = (AliTPChit*)FirstHit(-1);
1089 if (tpcHit->fQ == 0.) {
1090 tpcHit = (AliTPChit*) NextHit();
1091 continue; //information about track (I.Belikov)
1093 sector=tpcHit->fSector; // sector number
1096 tpcHit = (AliTPChit*) NextHit();
1099 ipart=tpcHit->Track();
1100 particle=gAlice->Particle(ipart);
1103 if(pt < 1.e-9) pt=1.e-9;
1105 tanth = TMath::Abs(tanth);
1106 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
1107 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
1109 // space-point resolutions
1111 sigmaRphi=SigmaY2(rpad,tanth,pt);
1112 sigmaZ =SigmaZ2(rpad,tanth );
1116 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
1117 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
1119 // temporary protection
1121 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
1122 if(sigmaZ < 0.) sigmaZ=0.4e-3;
1123 if(clRphi < 0.) clRphi=2.5e-3;
1124 if(clZ < 0.) clZ=2.5e-5;
1129 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
1130 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
1132 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
1133 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
1134 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
1135 Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
1136 fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
1137 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
1138 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
1139 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
1140 if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->Z();
1141 xyz[2]=sigmaRphi; // fSigmaY2
1142 xyz[3]=sigmaZ; // fSigmaZ2
1143 xyz[4]=tpcHit->fQ; // q
1145 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
1146 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
1148 Int_t tracks[3]={tpcHit->Track(), -1, -1};
1149 AliTPCcluster cluster(tracks,xyz);
1151 clrow->InsertCluster(&cluster); nclusters++;
1153 tpcHit = (AliTPChit*)NextHit();
1156 } // end of loop over hits
1158 } // end of loop over tracks
1160 Int_t nrows=fTPCParam->GetNRow(isec);
1161 for (Int_t irow=0; irow<nrows; irow++) {
1162 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
1163 if (!clrow) continue;
1164 carray.StoreRow(isec,irow);
1165 carray.ClearRow(isec,irow);
1168 } // end of loop over sectors
1170 cerr<<"Number of made clusters : "<<nclusters<<" \n";
1171 carray.GetTree()->SetName(cname);
1172 carray.GetTree()->Write();
1174 savedir->cd(); //switch back to the input file
1176 } // end of function
1178 //_________________________________________________________________
1179 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1181 //--------------------------------------------------------
1182 //calculate exact cross point of track and given pad row
1183 //resulting values are expressed in "digit" coordinata
1184 //--------------------------------------------------------
1186 //-----------------------------------------------------------------
1187 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1188 //-----------------------------------------------------------------
1190 if (fClustersArray==0){
1194 TParticle *particle; // pointer to a given particle
1195 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1196 // Int_t sector,nhits;
1198 const Int_t kcmaxhits=30000;
1199 AliTPCFastVector * xxxx = new AliTPCFastVector(kcmaxhits*4);
1200 AliTPCFastVector & xxx = *xxxx;
1201 Int_t maxhits = kcmaxhits;
1202 //construct array for each padrow
1203 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
1204 fClustersArray->CreateRow(isec,i);
1206 //---------------------------------------------------------------
1207 // Get the access to the tracks
1208 //---------------------------------------------------------------
1210 TTree *tH = gAlice->TreeH();
1211 Stat_t ntracks = tH->GetEntries();
1212 Int_t npart = gAlice->GetNtrack();
1215 if (fHitType>1) branch = tH->GetBranch("TPC2");
1216 else branch = tH->GetBranch("TPC");
1218 //------------------------------------------------------------
1220 //------------------------------------------------------------
1222 for(Int_t track=0;track<ntracks;track++){
1223 Bool_t isInSector=kTRUE;
1225 isInSector = TrackInVolume(isec,track);
1226 if (!isInSector) continue;
1228 branch->GetEntry(track); // get next track
1230 // Get number of the TPC hits and a pointer
1234 Int_t currentIndex=0;
1235 Int_t lastrow=-1; //last writen row
1239 tpcHit = (AliTPChit*)FirstHit(-1);
1242 Int_t sector=tpcHit->fSector; // sector number
1244 tpcHit = (AliTPChit*) NextHit();
1248 ipart=tpcHit->Track();
1249 if (ipart<npart) particle=gAlice->Particle(ipart);
1253 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
1254 Int_t index[3]={1,isec,0};
1255 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
1256 if (currentrow<0) {tpcHit = (AliTPChit*)NextHit(); continue;}
1257 if (lastrow<0) lastrow=currentrow;
1258 if (currentrow==lastrow){
1259 if ( currentIndex>=maxhits){
1261 xxx.ResizeTo(4*maxhits);
1263 xxx(currentIndex*4)=x[0];
1264 xxx(currentIndex*4+1)=x[1];
1265 xxx(currentIndex*4+2)=x[2];
1266 xxx(currentIndex*4+3)=tpcHit->fQ;
1270 if (currentIndex>2){
1282 for (Int_t index=0;index<currentIndex;index++){
1284 x=x2=x3=x4=xxx(index*4);
1292 sumy+=xxx(index*4+1);
1293 sumxy+=xxx(index*4+1)*x;
1294 sumx2y+=xxx(index*4+1)*x2;
1295 sumz+=xxx(index*4+2);
1296 sumxz+=xxx(index*4+2)*x;
1297 sumx2z+=xxx(index*4+2)*x2;
1298 sumq+=xxx(index*4+3);
1300 Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1301 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1302 sumx2*(sumx*sumx3-sumx2*sumx2);
1304 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1305 sumx2*(sumxy*sumx3-sumx2y*sumx2);
1306 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1307 sumx2*(sumxz*sumx3-sumx2z*sumx2);
1309 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1310 sumx2*(sumx*sumx2y-sumx2*sumxy);
1311 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1312 sumx2*(sumx*sumx2z-sumx2*sumxz);
1314 Float_t y=detay/det+centralPad;
1315 Float_t z=detaz/det;
1316 Float_t by=detby/det; //y angle
1317 Float_t bz=detbz/det; //z angle
1318 sumy/=Float_t(currentIndex);
1319 sumz/=Float_t(currentIndex);
1321 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1323 AliComplexCluster* cl = new((AliComplexCluster*)row->Append()) AliComplexCluster ;
1324 // AliComplexCluster cl;
1330 cl->fTracks[0]=ipart;
1334 } //end of calculating cluster for given row
1337 tpcHit = (AliTPChit*)NextHit();
1338 } // end of loop over hits
1339 } // end of loop over tracks
1340 //write padrows to tree
1341 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1342 fClustersArray->StoreRow(isec,ii);
1343 fClustersArray->ClearRow(isec,ii);
1352 void AliTPC::SDigits2Digits2(Int_t eventnumber)
1354 //create digits from summable digits
1355 GenerNoise(500000); //create teble with noise
1358 sprintf(sname,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1359 sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1361 //conect tree with sSDigits
1363 if (gAlice->GetTreeDFile()) {
1364 t = (TTree *)gAlice->GetTreeDFile()->Get(sname);
1366 t = (TTree *)gDirectory->Get(sname);
1369 cerr<<"TPC tree with sdigits not found"<<endl;
1372 AliSimDigits digarr, *dummy=&digarr;
1373 t->GetBranch("Segment")->SetAddress(&dummy);
1374 Stat_t nentries = t->GetEntries();
1376 // set zero suppression
1378 fTPCParam->SetZeroSup(2);
1380 // get zero suppression
1382 Int_t zerosup = fTPCParam->GetZeroSup();
1384 //make tree with digits
1386 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1387 arr->SetClass("AliSimDigits");
1388 arr->Setup(fTPCParam);
1389 // Note that methods arr->MakeTree have different signatures
1390 if (gAlice->GetTreeDFile()) {
1391 arr->MakeTree(gAlice->GetTreeDFile());
1393 arr->MakeTree(fDigitsFile);
1396 AliTPCParam * par =fTPCParam;
1398 //Loop over segments of the TPC
1400 for (Int_t n=0; n<nentries; n++) {
1403 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1404 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
1407 if (!IsSectorActive(sec)) continue;
1408 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1409 Int_t nrows = digrow->GetNRows();
1410 Int_t ncols = digrow->GetNCols();
1412 digrow->ExpandBuffer();
1413 digarr.ExpandBuffer();
1414 digrow->ExpandTrackBuffer();
1415 digarr.ExpandTrackBuffer();
1418 Short_t * pamp0 = digarr.GetDigits();
1419 Int_t * ptracks0 = digarr.GetTracks();
1420 Short_t * pamp1 = digrow->GetDigits();
1421 Int_t * ptracks1 = digrow->GetTracks();
1422 Int_t nelems =nrows*ncols;
1423 Int_t saturation = fTPCParam->GetADCSat();
1424 //use internal structure of the AliDigits - for speed reason
1425 //if you cahnge implementation
1426 //of the Alidigits - it must be rewriten -
1427 for (Int_t i= 0; i<nelems; i++){
1428 // Float_t q = *pamp0;
1429 //q/=16.; //conversion faktor
1430 //Float_t noise= GetNoise();
1432 //q= TMath::Nint(q);
1433 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1435 if (q>saturation) q=saturation;
1437 //if (ptracks0[0]==0)
1440 ptracks1[0]=ptracks0[0];
1441 ptracks1[nelems]=ptracks0[nelems];
1442 ptracks1[2*nelems]=ptracks0[2*nelems];
1450 arr->StoreRow(sec,row);
1451 arr->ClearRow(sec,row);
1452 // cerr<<sec<<"\t"<<row<<"\n";
1459 arr->GetTree()->SetName(dname);
1460 arr->GetTree()->AutoSave();
1463 //_________________________________________
1464 void AliTPC::Merge(TTree * intree, Int_t *mask, Int_t nin, Int_t outid)
1467 //intree - pointer to array of trees with s digits
1468 //mask - mask for each
1469 //nin - number of inputs
1470 //outid - event number of the output event
1472 //create digits from summable digits
1473 //conect tree with sSDigits
1476 AliSimDigits ** digarr = new AliSimDigits*[nin];
1477 for (Int_t i1=0;i1<nin; i1++){
1479 intree[i1].GetBranch("Segment")->SetAddress(&digarr[i1]);
1481 Stat_t nentries = intree[0].GetEntries();
1483 //make tree with digits
1485 sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),outid);
1486 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1487 arr->SetClass("AliSimDigits");
1488 arr->Setup(fTPCParam);
1489 arr->MakeTree(fDigitsFile);
1491 // set zero suppression
1493 fTPCParam->SetZeroSup(2);
1495 // get zero suppression
1497 Int_t zerosup = fTPCParam->GetZeroSup();
1500 AliTPCParam * par =fTPCParam;
1502 //Loop over segments of the TPC
1503 for (Int_t n=0; n<nentries; n++) {
1505 for (Int_t i=0;i<nin; i++){
1506 //connect proper digits
1507 intree[i].GetEvent(n);
1508 digarr[i]->ExpandBuffer();
1509 digarr[i]->ExpandTrackBuffer();
1512 if (!par->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
1513 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
1517 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1518 Int_t nrows = digrow->GetNRows();
1519 Int_t ncols = digrow->GetNCols();
1521 digrow->ExpandBuffer();
1522 digrow->ExpandTrackBuffer();
1524 for (Int_t rows=0;rows<nrows; rows++){
1525 for (Int_t col=0;col<ncols; col++){
1527 Int_t label[1000]; // i hope no more than 300 events merged
1529 // looop over digits
1530 for (Int_t i=0;i<nin; i++){
1531 q += digarr[i]->GetDigitFast(rows,col);
1532 for (Int_t tr=0;tr<3;tr++) {
1533 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
1535 label[labptr]=lab+mask[i]-2;
1541 q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac()*16);
1543 q/=16; //conversion faktor
1548 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat();
1549 digrow->SetDigitFast((Short_t)q,rows,col);
1550 for (Int_t tr=0;tr<3;tr++){
1552 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
1554 ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
1559 arr->StoreRow(sec,row);
1561 arr->ClearRow(sec,row);
1566 arr->GetTree()->SetName(dname);
1567 arr->GetTree()->Write();
1573 /*_________________________________________
1574 void AliTPC::SDigits2Digits(Int_t eventnumber)
1578 cerr<<"Digitizing TPC...\n";
1580 Hits2Digits(eventnumber);
1585 // char treeName[100];
1587 // sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1589 // GetDigitsArray()->GetTree()->Write(treeName);
1592 //__________________________________________________________________
1593 void AliTPC::SetDefaults(){
1596 cerr<<"Setting default parameters...\n";
1598 // Set response functions
1600 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1602 printf("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...\n");
1604 param = new AliTPCParamSR();
1607 param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1610 printf("No TPC parameters found\n");
1615 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1616 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1617 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1618 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1619 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1620 rf->SetOffset(3*param->GetZSigma());
1623 TDirectory *savedir=gDirectory;
1624 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1626 cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1629 prfinner->Read("prf_07504_Gati_056068_d02");
1630 prfouter1->Read("prf_10006_Gati_047051_d03");
1631 prfouter2->Read("prf_15006_Gati_047051_d03");
1635 param->SetInnerPRF(prfinner);
1636 param->SetOuter1PRF(prfouter1);
1637 param->SetOuter2PRF(prfouter2);
1638 param->SetTimeRF(rf);
1648 //__________________________________________________________________
1649 void AliTPC::Hits2Digits(Int_t eventnumber)
1651 //----------------------------------------------------
1652 // Loop over all sectors for a single event
1653 //----------------------------------------------------
1656 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1657 GenerNoise(500000); //create teble with noise
1659 //setup TPCDigitsArray
1661 if(GetDigitsArray()) delete GetDigitsArray();
1663 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1664 arr->SetClass("AliSimDigits");
1665 arr->Setup(fTPCParam);
1666 // Note that methods arr->MakeTree have different signatures
1667 if (gAlice->GetTreeDFile()) {
1668 arr->MakeTree(gAlice->GetTreeDFile());
1670 arr->MakeTree(fDigitsFile);
1672 SetDigitsArray(arr);
1674 fDigitsSwitch=0; // standard digits
1676 cerr<<"Digitizing TPC -- normal digits...\n";
1678 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1684 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1686 GetDigitsArray()->GetTree()->SetName(treeName);
1687 GetDigitsArray()->GetTree()->AutoSave();
1694 //__________________________________________________________________
1695 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1698 //-----------------------------------------------------------
1699 // summable digits - 16 bit "ADC", no noise, no saturation
1700 //-----------------------------------------------------------
1702 //----------------------------------------------------
1703 // Loop over all sectors for a single event
1704 //----------------------------------------------------
1707 if(fDefaults == 0) SetDefaults();
1708 GenerNoise(500000); //create table with noise
1709 //setup TPCDigitsArray
1711 if(GetDigitsArray()) delete GetDigitsArray();
1713 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1714 arr->SetClass("AliSimDigits");
1715 arr->Setup(fTPCParam);
1716 // Note that methods arr->MakeTree have different signatures
1717 if (gAlice->GetTreeSFile()) {
1718 arr->MakeTree(gAlice->GetTreeSFile());
1720 arr->MakeTree(fDigitsFile);
1722 SetDigitsArray(arr);
1724 cerr<<"Digitizing TPC -- summable digits...\n";
1726 fDigitsSwitch=1; // summable digits
1728 // set zero suppression to "0"
1730 fTPCParam->SetZeroSup(0);
1732 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1739 sprintf(treeName,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1741 GetDigitsArray()->GetTree()->SetName(treeName);
1742 GetDigitsArray()->GetTree()->AutoSave();
1748 //__________________________________________________________________
1749 void AliTPC::Hits2SDigits()
1752 //-----------------------------------------------------------
1753 // summable digits - 16 bit "ADC", no noise, no saturation
1754 //-----------------------------------------------------------
1756 //----------------------------------------------------
1757 // Loop over all sectors for a single event
1758 //----------------------------------------------------
1759 //MI change - for pp run
1760 Int_t eventnumber = gAlice->GetEvNumber();
1762 if(fDefaults == 0) SetDefaults();
1763 GenerNoise(500000); //create table with noise
1765 //setup TPCDigitsArray
1767 if(GetDigitsArray()) delete GetDigitsArray();
1769 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1770 arr->SetClass("AliSimDigits");
1771 arr->Setup(fTPCParam);
1772 // Note that methods arr->MakeTree have different signatures
1773 if (gAlice->GetTreeSFile()) {
1774 arr->MakeTree(gAlice->GetTreeSFile());
1776 arr->MakeTree(fDigitsFile);
1778 SetDigitsArray(arr);
1780 cerr<<"Digitizing TPC -- summable digits...\n";
1782 // fDigitsSwitch=1; // summable digits -for the moment direct
1784 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1790 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1792 GetDigitsArray()->GetTree()->SetName(treeName);
1793 GetDigitsArray()->GetTree()->AutoSave();
1798 //_____________________________________________________________________________
1799 void AliTPC::Hits2DigitsSector(Int_t isec)
1801 //-------------------------------------------------------------------
1802 // TPC conversion from hits to digits.
1803 //-------------------------------------------------------------------
1805 //-----------------------------------------------------------------
1806 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1807 //-----------------------------------------------------------------
1809 //-------------------------------------------------------
1810 // Get the access to the track hits
1811 //-------------------------------------------------------
1813 // check if the parameters are set - important if one calls this method
1814 // directly, not from the Hits2Digits
1816 if(fDefaults == 0) SetDefaults();
1818 TTree *tH = gAlice->TreeH(); // pointer to the hits tree
1819 Stat_t ntracks = tH->GetEntries();
1823 //-------------------------------------------
1824 // Only if there are any tracks...
1825 //-------------------------------------------
1829 //printf("*** Processing sector number %d ***\n",isec);
1831 Int_t nrows =fTPCParam->GetNRow(isec);
1833 row= new TObjArray* [nrows];
1835 MakeSector(isec,nrows,tH,ntracks,row);
1837 //--------------------------------------------------------
1838 // Digitize this sector, row by row
1839 // row[i] is the pointer to the TObjArray of AliTPCFastVectors,
1840 // each one containing electrons accepted on this
1841 // row, assigned into tracks
1842 //--------------------------------------------------------
1846 if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree(fDigitsFile);
1848 for (i=0;i<nrows;i++){
1850 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1852 DigitizeRow(i,isec,row);
1854 fDigitsArray->StoreRow(isec,i);
1856 Int_t ndig = dig->GetDigitSize();
1857 if (gDebug > 10) printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1859 fDigitsArray->ClearRow(isec,i);
1862 } // end of the sector digitization
1864 for(i=0;i<nrows;i++){
1869 delete [] row; // delete the array of pointers to TObjArray-s
1873 } // end of Hits2DigitsSector
1876 //_____________________________________________________________________________
1877 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1879 //-----------------------------------------------------------
1880 // Single row digitization, coupling from the neighbouring
1881 // rows taken into account
1882 //-----------------------------------------------------------
1884 //-----------------------------------------------------------------
1885 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1886 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1887 //-----------------------------------------------------------------
1890 Float_t zerosup = fTPCParam->GetZeroSup();
1891 Int_t nrows =fTPCParam->GetNRow(isec);
1892 fCurrentIndex[1]= isec;
1895 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1896 Int_t nofTbins = fTPCParam->GetMaxTBin();
1897 Int_t indexRange[4];
1899 // Integrated signal for this row
1900 // and a single track signal
1903 AliTPCFastMatrix *m1 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // integrated
1904 AliTPCFastMatrix *m2 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // single
1906 AliTPCFastMatrix &total = *m1;
1908 // Array of pointers to the label-signal list
1910 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1911 Float_t **pList = new Float_t* [nofDigits];
1915 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1919 Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1920 Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1921 for (Int_t row= row1;row<=row2;row++){
1922 Int_t nTracks= rows[row]->GetEntries();
1923 for (i1=0;i1<nTracks;i1++){
1924 fCurrentIndex[2]= row;
1925 fCurrentIndex[3]=irow;
1927 m2->Zero(); // clear single track signal matrix
1928 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1929 GetList(trackLabel,nofPads,m2,indexRange,pList);
1931 else GetSignal(rows[row],i1,0,m1,indexRange);
1937 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1939 Float_t fzerosup = zerosup+0.5;
1940 for(Int_t it=0;it<nofTbins;it++){
1941 Float_t *pq = &(total.UncheckedAt(0,it));
1942 for(Int_t ip=0;ip<nofPads;ip++){
1946 if(fDigitsSwitch == 0){
1948 if(q <=fzerosup) continue; // do not fill zeros
1950 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1955 if(q <= 0.) continue; // do not fill zeros
1956 if(q>2000.) q=2000.;
1962 // "real" signal or electronic noise (list = -1)?
1965 for(Int_t j1=0;j1<3;j1++){
1966 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1971 <A NAME="AliDigits"></A>
1972 using of AliDigits object
1975 dig->SetDigitFast((Short_t)q,it,ip);
1976 if (fDigitsArray->IsSimulated())
1978 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1979 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1980 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1984 } // end of loop over time buckets
1985 } // end of lop over pads
1988 // This row has been digitized, delete nonused stuff
1991 for(lp=0;lp<nofDigits;lp++){
1992 if(pList[lp]) delete [] pList[lp];
2001 } // end of DigitizeRow
2003 //_____________________________________________________________________________
2005 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
2006 AliTPCFastMatrix *m1, AliTPCFastMatrix *m2,Int_t *indexRange)
2009 //---------------------------------------------------------------
2010 // Calculates 2-D signal (pad,time) for a single track,
2011 // returns a pointer to the signal matrix and the track label
2012 // No digitization is performed at this level!!!
2013 //---------------------------------------------------------------
2015 //-----------------------------------------------------------------
2016 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2017 // Modified: Marian Ivanov
2018 //-----------------------------------------------------------------
2020 AliTPCFastVector *tv;
2022 tv = (AliTPCFastVector*)p1->At(ntr); // pointer to a track
2023 AliTPCFastVector &v = *tv;
2025 Float_t label = v(0);
2026 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
2028 Int_t nElectrons = (tv->GetNrows()-1)/4;
2029 indexRange[0]=9999; // min pad
2030 indexRange[1]=-1; // max pad
2031 indexRange[2]=9999; //min time
2032 indexRange[3]=-1; // max time
2034 AliTPCFastMatrix &signal = *m1;
2035 AliTPCFastMatrix &total = *m2;
2037 // Loop over all electrons
2039 for(Int_t nel=0; nel<nElectrons; nel++){
2041 Float_t aval = v(idx+4);
2042 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
2043 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
2044 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
2046 Int_t *index = fTPCParam->GetResBin(0);
2047 Float_t *weight = & (fTPCParam->GetResWeight(0));
2049 if (n>0) for (Int_t i =0; i<n; i++){
2050 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
2053 Int_t time=index[2];
2054 Float_t qweight = *(weight)*eltoadcfac;
2056 if (m1!=0) signal.UncheckedAt(pad,time)+=qweight;
2057 total.UncheckedAt(pad,time)+=qweight;
2058 if (indexRange[0]>pad) indexRange[0]=pad;
2059 if (indexRange[1]<pad) indexRange[1]=pad;
2060 if (indexRange[2]>time) indexRange[2]=time;
2061 if (indexRange[3]<time) indexRange[3]=time;
2068 } // end of loop over electrons
2070 return label; // returns track label when finished
2073 //_____________________________________________________________________________
2074 void AliTPC::GetList(Float_t label,Int_t np,AliTPCFastMatrix *m,
2075 Int_t *indexRange, Float_t **pList)
2077 //----------------------------------------------------------------------
2078 // Updates the list of tracks contributing to digits for a given row
2079 //----------------------------------------------------------------------
2081 //-----------------------------------------------------------------
2082 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2083 //-----------------------------------------------------------------
2085 AliTPCFastMatrix &signal = *m;
2087 // lop over nonzero digits
2089 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
2090 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
2093 // accept only the contribution larger than 500 electrons (1/2 s_noise)
2095 if(signal(ip,it)<0.5) continue;
2098 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
2100 if(!pList[globalIndex]){
2103 // Create new list (6 elements - 3 signals and 3 labels),
2106 pList[globalIndex] = new Float_t [6];
2110 *pList[globalIndex] = -1.;
2111 *(pList[globalIndex]+1) = -1.;
2112 *(pList[globalIndex]+2) = -1.;
2113 *(pList[globalIndex]+3) = -1.;
2114 *(pList[globalIndex]+4) = -1.;
2115 *(pList[globalIndex]+5) = -1.;
2118 *pList[globalIndex] = label;
2119 *(pList[globalIndex]+3) = signal(ip,it);
2123 // check the signal magnitude
2125 Float_t highest = *(pList[globalIndex]+3);
2126 Float_t middle = *(pList[globalIndex]+4);
2127 Float_t lowest = *(pList[globalIndex]+5);
2130 // compare the new signal with already existing list
2133 if(signal(ip,it)<lowest) continue; // neglect this track
2137 if (signal(ip,it)>highest){
2138 *(pList[globalIndex]+5) = middle;
2139 *(pList[globalIndex]+4) = highest;
2140 *(pList[globalIndex]+3) = signal(ip,it);
2142 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
2143 *(pList[globalIndex]+1) = *pList[globalIndex];
2144 *pList[globalIndex] = label;
2146 else if (signal(ip,it)>middle){
2147 *(pList[globalIndex]+5) = middle;
2148 *(pList[globalIndex]+4) = signal(ip,it);
2150 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
2151 *(pList[globalIndex]+1) = label;
2154 *(pList[globalIndex]+5) = signal(ip,it);
2155 *(pList[globalIndex]+2) = label;
2159 } // end of loop over pads
2160 } // end of loop over time bins
2165 //___________________________________________________________________
2166 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
2167 Stat_t ntracks,TObjArray **row)
2170 //-----------------------------------------------------------------
2171 // Prepares the sector digitization, creates the vectors of
2172 // tracks for each row of this sector. The track vector
2173 // contains the track label and the position of electrons.
2174 //-----------------------------------------------------------------
2176 //-----------------------------------------------------------------
2177 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2178 //-----------------------------------------------------------------
2180 Float_t gasgain = fTPCParam->GetGasGain();
2184 AliTPChit *tpcHit; // pointer to a sigle TPC hit
2187 if (fHitType>1) branch = TH->GetBranch("TPC2");
2188 else branch = TH->GetBranch("TPC");
2191 //----------------------------------------------
2192 // Create TObjArray-s, one for each row,
2193 // each TObjArray will store the AliTPCFastVectors
2194 // of electrons, one AliTPCFastVectors per each track.
2195 //----------------------------------------------
2197 Int_t *nofElectrons = new Int_t [nrows]; // electron counter for each row
2198 AliTPCFastVector **tracks = new AliTPCFastVector* [nrows]; //pointers to the track vectors
2200 for(i=0; i<nrows; i++){
2201 row[i] = new TObjArray;
2208 //--------------------------------------------------------------------
2209 // Loop over tracks, the "track" contains the full history
2210 //--------------------------------------------------------------------
2212 Int_t previousTrack,currentTrack;
2213 previousTrack = -1; // nothing to store so far!
2215 for(Int_t track=0;track<ntracks;track++){
2216 Bool_t isInSector=kTRUE;
2218 isInSector = TrackInVolume(isec,track);
2219 if (!isInSector) continue;
2221 branch->GetEntry(track); // get next track
2225 tpcHit = (AliTPChit*)FirstHit(-1);
2227 //--------------------------------------------------------------
2229 //--------------------------------------------------------------
2234 Int_t sector=tpcHit->fSector; // sector number
2236 tpcHit = (AliTPChit*) NextHit();
2240 currentTrack = tpcHit->Track(); // track number
2243 if(currentTrack != previousTrack){
2245 // store already filled fTrack
2247 for(i=0;i<nrows;i++){
2248 if(previousTrack != -1){
2249 if(nofElectrons[i]>0){
2250 AliTPCFastVector &v = *tracks[i];
2251 v(0) = previousTrack;
2252 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2253 row[i]->Add(tracks[i]);
2256 delete tracks[i]; // delete empty AliTPCFastVector
2262 tracks[i] = new AliTPCFastVector(481); // AliTPCFastVectors for the next fTrack
2264 } // end of loop over rows
2266 previousTrack=currentTrack; // update track label
2269 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2271 //---------------------------------------------------
2272 // Calculate the electron attachment probability
2273 //---------------------------------------------------
2276 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
2277 /fTPCParam->GetDriftV();
2279 Float_t attProb = fTPCParam->GetAttCoef()*
2280 fTPCParam->GetOxyCont()*time; // fraction!
2282 //-----------------------------------------------
2283 // Loop over electrons
2284 //-----------------------------------------------
2287 for(Int_t nel=0;nel<qI;nel++){
2288 // skip if electron lost due to the attachment
2289 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2294 // protection for the nonphysical avalanche size (10**6 maximum)
2296 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2297 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2300 TransportElectron(xyz,index); //MI change -august
2302 fTPCParam->GetPadRow(xyz,index); //MI change august
2303 rowNumber = index[2];
2304 //transform position to local digit coordinates
2305 //relative to nearest pad row
2306 if ((rowNumber<0)||rowNumber>=fTPCParam->GetNRow(isec)) continue;
2308 if (isec <fTPCParam->GetNInnerSector()) {
2309 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2310 y1 = fTPCParam->GetYInner(rowNumber);
2313 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2314 y1 = fTPCParam->GetYOuter(rowNumber);
2324 nofElectrons[rowNumber]++;
2325 //----------------------------------
2326 // Expand vector if necessary
2327 //----------------------------------
2328 if(nofElectrons[rowNumber]>120){
2329 Int_t range = tracks[rowNumber]->GetNrows();
2330 if((nofElectrons[rowNumber])>(range-1)/4){
2332 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
2336 AliTPCFastVector &v = *tracks[rowNumber];
2337 Int_t idx = 4*nofElectrons[rowNumber]-3;
2338 Real_t * position = &(((AliTPCFastVector&)v).UncheckedAt(idx)); //make code faster
2339 memcpy(position,xyz,4*sizeof(Float_t));
2341 } // end of loop over electrons
2343 tpcHit = (AliTPChit*)NextHit();
2345 } // end of loop over hits
2346 } // end of loop over tracks
2349 // store remaining track (the last one) if not empty
2352 for(i=0;i<nrows;i++){
2353 if(nofElectrons[i]>0){
2354 AliTPCFastVector &v = *tracks[i];
2355 v(0) = previousTrack;
2356 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2357 row[i]->Add(tracks[i]);
2366 delete [] nofElectrons;
2369 } // end of MakeSector
2372 //_____________________________________________________________________________
2376 // Initialise TPC detector after definition of geometry
2381 printf("\n%s: ",ClassName());
2382 for(i=0;i<35;i++) printf("*");
2383 printf(" TPC_INIT ");
2384 for(i=0;i<35;i++) printf("*");
2385 printf("\n%s: ",ClassName());
2387 for(i=0;i<80;i++) printf("*");
2392 //_____________________________________________________________________________
2393 void AliTPC::MakeBranch(Option_t* option, const char *file)
2396 // Create Tree branches for the TPC.
2398 Int_t buffersize = 4000;
2399 char branchname[10];
2400 sprintf(branchname,"%s",GetName());
2402 AliDetector::MakeBranch(option,file);
2404 const char *d = strstr(option,"D");
2406 if (fDigits && gAlice->TreeD() && d) {
2407 MakeBranchInTree(gAlice->TreeD(),
2408 branchname, &fDigits, buffersize, file);
2411 if (fHitType>1) MakeBranch2(option,file); // MI change 14.09.2000
2414 //_____________________________________________________________________________
2415 void AliTPC::ResetDigits()
2418 // Reset number of digits and the digits array for this detector
2421 if (fDigits) fDigits->Clear();
2424 //_____________________________________________________________________________
2425 void AliTPC::SetSecAL(Int_t sec)
2427 //---------------------------------------------------
2428 // Activate/deactivate selection for lower sectors
2429 //---------------------------------------------------
2431 //-----------------------------------------------------------------
2432 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2433 //-----------------------------------------------------------------
2438 //_____________________________________________________________________________
2439 void AliTPC::SetSecAU(Int_t sec)
2441 //----------------------------------------------------
2442 // Activate/deactivate selection for upper sectors
2443 //---------------------------------------------------
2445 //-----------------------------------------------------------------
2446 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2447 //-----------------------------------------------------------------
2452 //_____________________________________________________________________________
2453 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
2455 //----------------------------------------
2456 // Select active lower sectors
2457 //----------------------------------------
2459 //-----------------------------------------------------------------
2460 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2461 //-----------------------------------------------------------------
2471 //_____________________________________________________________________________
2472 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
2473 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
2474 Int_t s11 , Int_t s12)
2476 //--------------------------------
2477 // Select active upper sectors
2478 //--------------------------------
2480 //-----------------------------------------------------------------
2481 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2482 //-----------------------------------------------------------------
2498 //_____________________________________________________________________________
2499 void AliTPC::SetSens(Int_t sens)
2502 //-------------------------------------------------------------
2503 // Activates/deactivates the sensitive strips at the center of
2504 // the pad row -- this is for the space-point resolution calculations
2505 //-------------------------------------------------------------
2507 //-----------------------------------------------------------------
2508 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2509 //-----------------------------------------------------------------
2515 void AliTPC::SetSide(Float_t side=0.)
2517 // choice of the TPC side
2522 //____________________________________________________________________________
2523 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2524 Float_t p2,Float_t p3)
2527 // gax mixture definition
2541 //_____________________________________________________________________________
2543 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2546 // electron transport taking into account:
2548 // 2.ExB at the wires
2549 // 3. nonisochronity
2551 // xyz and index must be already transformed to system 1
2554 fTPCParam->Transform1to2(xyz,index);
2557 Float_t driftl=xyz[2];
2558 if(driftl<0.01) driftl=0.01;
2559 driftl=TMath::Sqrt(driftl);
2560 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2561 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2562 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2563 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2564 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2568 if (fTPCParam->GetMWPCReadout()==kTRUE){
2570 fTPCParam->Transform2to2NearestWire(xyz,index);
2571 Float_t dx=xyz[0]-x1;
2572 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2574 //add nonisochronity (not implemented yet)
2578 ClassImp(AliTPCdigit)
2580 //_____________________________________________________________________________
2581 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2585 // Creates a TPC digit object
2587 fSector = digits[0];
2588 fPadRow = digits[1];
2591 fSignal = digits[4];
2597 //_____________________________________________________________________________
2598 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2602 // Creates a TPC hit object
2613 //________________________________________________________________________
2614 // Additional code because of the AliTPCTrackHitsV2
2616 void AliTPC::MakeBranch2(Option_t *option,const char *file)
2619 // Create a new branch in the current Root Tree
2620 // The branch of fHits is automatically split
2621 // MI change 14.09.2000
2622 if (fHitType<2) return;
2623 char branchname[10];
2624 sprintf(branchname,"%s2",GetName());
2626 // Get the pointer to the header
2627 const char *cH = strstr(option,"H");
2629 if (fTrackHits && gAlice->TreeH() && cH && fHitType&4) {
2630 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2631 // gAlice->TreeH(),fBufferSize,99);
2632 //TBranch * branch =
2633 gAlice->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2636 // gAlice->TreeH()->GetListOfBranches()->Add(branch);
2638 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2639 const char folder [] = "RunMC/Event/Data";
2641 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2642 Publish(folder,&fTrackHits,branchname);
2644 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2645 TDirectory *wd = gDirectory;
2647 TIter next( b->GetListOfBranches());
2648 while ((b=(TBranch*)next())) {
2653 cout << "Diverting branch " << branchname << " to file " << file << endl;
2657 if (fTrackHitsOld && gAlice->TreeH() && cH && fHitType&2) {
2658 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2659 gAlice->TreeH(),fBufferSize,99);
2660 //TBranch * branch = gAlice->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2663 gAlice->TreeH()->GetListOfBranches()->Add(branch);
2665 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2666 const char folder [] = "RunMC/Event/Data";
2668 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2669 Publish(folder,&fTrackHitsOld,branchname);
2671 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2672 TDirectory *wd = gDirectory;
2674 TIter next( b->GetListOfBranches());
2675 while ((b=(TBranch*)next())) {
2680 cout << "Diverting branch " << branchname << " to file " << file << endl;
2685 void AliTPC::SetTreeAddress()
2687 if (fHitType<=1) AliDetector::SetTreeAddress();
2688 if (fHitType>1) SetTreeAddress2();
2691 void AliTPC::SetTreeAddress2()
2694 // Set branch address for the TrackHits Tree
2697 char branchname[20];
2698 sprintf(branchname,"%s2",GetName());
2700 // Branch address for hit tree
2701 TTree *treeH = gAlice->TreeH();
2702 if ((treeH)&&(fHitType&4)) {
2703 branch = treeH->GetBranch(branchname);
2704 if (branch) branch->SetAddress(&fTrackHits);
2706 if ((treeH)&&(fHitType&2)) {
2707 branch = treeH->GetBranch(branchname);
2708 if (branch) branch->SetAddress(&fTrackHitsOld);
2713 void AliTPC::FinishPrimary()
2715 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2716 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2720 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2723 // add hit to the list
2726 int primary = gAlice->GetPrimary(track);
2727 gAlice->Particle(primary)->SetBit(kKeepBit);
2731 gAlice->FlagTrack(track);
2733 //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2734 //if (hit->fTrack!=rtrack)
2735 // cout<<"bad track number\n";
2736 if (fTrackHits && fHitType&4)
2737 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2738 hits[1],hits[2],(Int_t)hits[3]);
2739 if (fTrackHitsOld &&fHitType&2 )
2740 fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2741 hits[1],hits[2],(Int_t)hits[3]);
2745 void AliTPC::ResetHits()
2747 if (fHitType&1) AliDetector::ResetHits();
2748 if (fHitType>1) ResetHits2();
2751 void AliTPC::ResetHits2()
2755 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2756 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2760 AliHit* AliTPC::FirstHit(Int_t track)
2762 if (fHitType>1) return FirstHit2(track);
2763 return AliDetector::FirstHit(track);
2765 AliHit* AliTPC::NextHit()
2767 if (fHitType>1) return NextHit2();
2769 return AliDetector::NextHit();
2772 AliHit* AliTPC::FirstHit2(Int_t track)
2775 // Initialise the hit iterator
2776 // Return the address of the first hit for track
2777 // If track>=0 the track is read from disk
2778 // while if track<0 the first hit of the current
2779 // track is returned
2782 gAlice->ResetHits();
2783 gAlice->TreeH()->GetEvent(track);
2786 if (fTrackHits && fHitType&4) {
2787 fTrackHits->First();
2788 return fTrackHits->GetHit();
2790 if (fTrackHitsOld && fHitType&2) {
2791 fTrackHitsOld->First();
2792 return fTrackHitsOld->GetHit();
2798 AliHit* AliTPC::NextHit2()
2801 //Return the next hit for the current track
2804 if (fTrackHitsOld && fHitType&2) {
2805 fTrackHitsOld->Next();
2806 return fTrackHitsOld->GetHit();
2810 return fTrackHits->GetHit();
2816 void AliTPC::LoadPoints(Int_t)
2820 /* if(fHitType==1) return AliDetector::LoadPoints(a);
2823 if(fHitType==1) AliDetector::LoadPoints(a);
2824 else LoadPoints2(a);
2831 void AliTPC::RemapTrackHitIDs(Int_t *map)
2833 if (!fTrackHits) return;
2835 if (fTrackHitsOld && fHitType&2){
2836 AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2837 for (UInt_t i=0;i<arr->GetSize();i++){
2838 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2839 info->fTrackID = map[info->fTrackID];
2842 if (fTrackHitsOld && fHitType&4){
2843 TClonesArray * arr = fTrackHits->GetArray();;
2844 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2845 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2846 info->fTrackID = map[info->fTrackID];
2851 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2853 //return bool information - is track in given volume
2854 //load only part of the track information
2855 //return true if current track is in volume
2858 if (fTrackHitsOld && fHitType&2) {
2859 TBranch * br = gAlice->TreeH()->GetBranch("fTrackHitsInfo");
2860 br->GetEvent(track);
2861 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2862 for (UInt_t j=0;j<ar->GetSize();j++){
2863 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2867 if (fTrackHits && fHitType&4) {
2868 TBranch * br1 = gAlice->TreeH()->GetBranch("fVolumes");
2869 TBranch * br2 = gAlice->TreeH()->GetBranch("fNVolumes");
2870 br2->GetEvent(track);
2871 br1->GetEvent(track);
2872 Int_t *volumes = fTrackHits->GetVolumes();
2873 Int_t nvolumes = fTrackHits->GetNVolumes();
2874 if (!volumes && nvolumes>0) {
2875 printf("Problematic track\t%d\t%d",track,nvolumes);
2878 for (Int_t j=0;j<nvolumes; j++)
2879 if (volumes[j]==id) return kTRUE;
2883 TBranch * br = gAlice->TreeH()->GetBranch("fSector");
2884 br->GetEvent(track);
2885 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2886 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2893 //_____________________________________________________________________________
2894 void AliTPC::LoadPoints2(Int_t)
2897 // Store x, y, z of all hits in memory
2899 if (fTrackHits == 0 && fTrackHitsOld==0) return;
2902 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2903 if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2905 if (nhits == 0) return;
2906 Int_t tracks = gAlice->GetNtrack();
2907 if (fPoints == 0) fPoints = new TObjArray(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);
2928 trk=ahit->GetTrack();
2929 if(ntrk[trk]==limi[trk]) {
2931 // Initialise a new track
2932 fp=new Float_t[3*(limi[trk]+chunk)];
2934 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2935 delete [] coor[trk];
2942 fp[3*ntrk[trk] ] = ahit->X();
2943 fp[3*ntrk[trk]+1] = ahit->Y();
2944 fp[3*ntrk[trk]+2] = ahit->Z();
2952 for(trk=0; trk<tracks; ++trk) {
2954 points = new AliPoints();
2955 points->SetMarkerColor(GetMarkerColor());
2956 points->SetMarkerSize(GetMarkerSize());
2957 points->SetDetector(this);
2958 points->SetParticle(trk);
2959 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2960 fPoints->AddAt(points,trk);
2961 delete [] coor[trk];
2971 //_____________________________________________________________________________
2972 void AliTPC::LoadPoints3(Int_t)
2975 // Store x, y, z of all hits in memory
2976 // - only intersection point with pad row
2977 if (fTrackHits == 0) return;
2979 Int_t nhits = fTrackHits->GetEntriesFast();
2980 if (nhits == 0) return;
2981 Int_t tracks = gAlice->GetNtrack();
2982 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2983 fPoints->Expand(2*tracks);
2986 Int_t *ntrk=new Int_t[tracks];
2987 Int_t *limi=new Int_t[tracks];
2988 Float_t **coor=new Float_t*[tracks];
2989 for(Int_t i=0;i<tracks;i++) {
2995 AliPoints *points = 0;
2998 Int_t chunk=nhits/4+1;
3000 // Loop over all the hits and store their position
3002 ahit = FirstHit2(-1);
3003 //for (Int_t hit=0;hit<nhits;hit++) {
3007 // ahit = (AliHit*)fHits->UncheckedAt(hit);
3008 trk=ahit->GetTrack();
3009 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
3010 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
3011 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
3012 if (currentrow!=lastrow){
3013 lastrow = currentrow;
3014 //later calculate intersection point
3015 if(ntrk[trk]==limi[trk]) {
3017 // Initialise a new track
3018 fp=new Float_t[3*(limi[trk]+chunk)];
3020 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
3021 delete [] coor[trk];
3028 fp[3*ntrk[trk] ] = ahit->X();
3029 fp[3*ntrk[trk]+1] = ahit->Y();
3030 fp[3*ntrk[trk]+2] = ahit->Z();
3037 for(trk=0; trk<tracks; ++trk) {
3039 points = new AliPoints();
3040 points->SetMarkerColor(GetMarkerColor()+1);
3041 points->SetMarkerStyle(5);
3042 points->SetMarkerSize(0.2);
3043 points->SetDetector(this);
3044 points->SetParticle(trk);
3045 // points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
3046 points->SetPolyMarker(ntrk[trk],coor[trk],30);
3047 fPoints->AddAt(points,tracks+trk);
3048 delete [] coor[trk];
3059 void AliTPC::FindTrackHitsIntersection(TClonesArray * arr)
3063 //fill clones array with intersection of current point with the
3068 const Int_t kcmaxhits=30000;
3069 AliTPCFastVector * xxxx = new AliTPCFastVector(kcmaxhits*4);
3070 AliTPCFastVector & xxx = *xxxx;
3071 Int_t maxhits = kcmaxhits;
3074 AliTPChit * tpcHit=0;
3075 tpcHit = (AliTPChit*)FirstHit2(-1);
3076 Int_t currentIndex=0;
3077 Int_t lastrow=-1; //last writen row
3080 if (tpcHit==0) continue;
3081 sector=tpcHit->fSector; // sector number
3082 ipart=tpcHit->Track();
3086 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
3087 Int_t index[3]={1,sector,0};
3088 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
3089 if (currentrow<0) continue;
3090 if (lastrow<0) lastrow=currentrow;
3091 if (currentrow==lastrow){
3092 if ( currentIndex>=maxhits){
3094 xxx.ResizeTo(4*maxhits);
3096 xxx(currentIndex*4)=x[0];
3097 xxx(currentIndex*4+1)=x[1];
3098 xxx(currentIndex*4+2)=x[2];
3099 xxx(currentIndex*4+3)=tpcHit->fQ;
3103 if (currentIndex>2){
3115 for (Int_t index=0;index<currentIndex;index++){
3117 x=x2=x3=x4=xxx(index*4);
3125 sumy+=xxx(index*4+1);
3126 sumxy+=xxx(index*4+1)*x;
3127 sumx2y+=xxx(index*4+1)*x2;
3128 sumz+=xxx(index*4+2);
3129 sumxz+=xxx(index*4+2)*x;
3130 sumx2z+=xxx(index*4+2)*x2;
3131 sumq+=xxx(index*4+3);
3133 Float_t centralPad = (fTPCParam->GetNPads(sector,lastrow)-1)/2;
3134 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
3135 sumx2*(sumx*sumx3-sumx2*sumx2);
3137 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
3138 sumx2*(sumxy*sumx3-sumx2y*sumx2);
3139 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
3140 sumx2*(sumxz*sumx3-sumx2z*sumx2);
3142 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
3143 sumx2*(sumx*sumx2y-sumx2*sumxy);
3144 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
3145 sumx2*(sumx*sumx2z-sumx2*sumxz);
3147 Float_t y=detay/det+centralPad;
3148 Float_t z=detaz/det;
3149 Float_t by=detby/det; //y angle
3150 Float_t bz=detbz/det; //z angle
3151 sumy/=Float_t(currentIndex);
3152 sumz/=Float_t(currentIndex);
3154 AliComplexCluster cl;
3160 cl.fTracks[0]=ipart;
3162 AliTPCClustersRow * row = (fClustersArray->GetRow(sector,lastrow));
3163 if (row!=0) row->InsertCluster(&cl);
3166 } //end of calculating cluster for given row
3168 } // end of loop over hits
3172 //_______________________________________________________________________________
3173 void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
3175 // produces rec points from digits and writes them on the root file
3176 // AliTPCclusters.root
3178 TDirectory *cwd = gDirectory;
3181 AliTPCParamSR *dig=(AliTPCParamSR *)gDirectory->Get("75x40_100x60");
3183 printf("You are running 2 pad-length geom hits with 3 pad-length geom digits\n");
3185 dig = new AliTPCParamSR();
3189 dig=(AliTPCParamSR *)gDirectory->Get("75x40_100x60_150x60");
3192 printf("No TPC parameters found\n");
3197 cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl;
3199 if(!gSystem->Getenv("CONFIG_FILE")){
3200 out=TFile::Open("AliTPCclusters.root","recreate");
3206 tmp1=gSystem->Getenv("CONFIG_FILE_PREFIX");
3207 tmp2=gSystem->Getenv("CONFIG_OUTDIR");
3208 sprintf(tmp3,"%s%s/AliTPCclusters.root",tmp1,tmp2);
3209 out=TFile::Open(tmp3,"recreate");
3213 cout<<"AliTPC::Digits2Reco - determination of rec points begins"<<endl;
3216 for(Int_t iev=firstevent;iev<lastevent+1;iev++){
3218 printf("Processing event %d\n",iev);
3219 Digits2Clusters(out,iev);
3221 cout<<"AliTPC::Digits2Reco - determination of rec points ended"<<endl;