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.61 2002/09/10 07:06:42 kowal2
19 Corrected for the memory leak. Thanks to J. Chudoba and M. Ivanov
21 Revision 1.60 2002/06/12 14:56:56 kowal2
22 Added track length to the reference hits
24 Revision 1.59 2002/06/05 15:37:31 kowal2
25 Added cross-talk from the wires beyond the first and the last rows
27 Revision 1.58 2002/05/27 14:33:14 hristov
28 The new class AliTrackReference used (M.Ivanov)
30 Revision 1.57 2002/05/07 17:23:11 kowal2
31 Linear gain inefficiency instead of the step one at the wire edges.
33 Revision 1.56 2002/04/04 16:26:33 kowal2
34 Digits (Sdigits) go to separate files now.
36 Revision 1.55 2002/03/29 06:57:45 kowal2
37 Restored backward compatibility to use the hits from Dec. 2000 production.
39 Revision 1.54 2002/03/18 17:59:13 kowal2
40 Chnges in the pad geometry - 3 pad lengths introduced.
42 Revision 1.53 2002/02/25 11:02:56 kowal2
43 Changes towards speeding up the code. Thanks to Marian Ivanov.
45 Revision 1.52 2002/02/18 09:26:09 kowal2
46 Removed compiler warning
48 Revision 1.51 2002/01/21 17:13:21 kowal2
49 New track hits using root containers. Setting active sectors added.
51 Revision 1.50 2001/12/06 14:16:19 kowal2
54 Revision 1.49 2001/11/30 11:55:37 hristov
55 Noise table created in Hits2SDigits (M.Ivanov)
57 Revision 1.48 2001/11/24 16:10:21 kowal2
60 Revision 1.47 2001/11/19 10:25:34 kowal2
61 Nearest integer instead of integer when converting to ADC counts
63 Revision 1.46 2001/11/07 06:47:12 kowal2
66 Revision 1.45 2001/11/03 13:33:48 kowal2
67 Updated algorithms in Hits2SDigits, SDigits2Digits,
71 Revision 1.44 2001/08/30 09:28:48 hristov
72 TTree names are explicitly set via SetName(name) and then Write() is called
74 Revision 1.43 2001/07/28 12:02:54 hristov
75 Branch split level set to 99
77 Revision 1.42 2001/07/28 11:38:52 hristov
78 Loop variable declared once
80 Revision 1.41 2001/07/28 10:53:50 hristov
81 Digitisation done according to the general scheme (M.Ivanov)
83 Revision 1.40 2001/07/27 13:03:14 hristov
84 Default Branch split level set to 99
86 Revision 1.39 2001/07/26 09:09:34 kowal2
87 Hits2Reco method added
89 Revision 1.38 2001/07/20 14:32:43 kowal2
90 Processing of many events possible now
92 Revision 1.37 2001/06/12 07:17:18 kowal2
93 Hits2SDigits method implemented (summable digits)
95 Revision 1.36 2001/05/16 14:57:25 alibrary
96 New files for folders and Stack
98 Revision 1.35 2001/05/08 16:02:22 kowal2
99 Updated material specifications
101 Revision 1.34 2001/05/08 15:00:15 hristov
102 Corrections for tracking in arbitrary magnenetic field. Changes towards a concept of global Alice track. Back propagation of reconstructed tracks (Yu.Belikov)
104 Revision 1.33 2001/04/03 12:40:43 kowal2
107 Revision 1.32 2001/03/12 17:47:36 hristov
108 Changes needed on Sun with CC 5.0
110 Revision 1.31 2001/03/12 08:21:50 kowal2
111 Corrected C++ bug in the material definitions
113 Revision 1.30 2001/03/01 17:34:47 kowal2
114 Correction due to the accuracy problem
116 Revision 1.29 2001/02/28 16:34:40 kowal2
117 Protection against nonphysical values of the avalanche size,
120 Revision 1.28 2001/01/26 19:57:19 hristov
121 Major upgrade of AliRoot code
123 Revision 1.27 2001/01/13 17:29:33 kowal2
124 Sun compiler correction
126 Revision 1.26 2001/01/10 07:59:43 kowal2
127 Corrections to load points from the noncompressed hits.
129 Revision 1.25 2000/11/02 07:25:31 kowal2
130 Changes due to the new hit structure.
133 Revision 1.24 2000/10/05 16:06:09 kowal2
134 Forward declarations. Changes due to a new class AliComplexCluster.
136 Revision 1.23 2000/10/02 21:28:18 fca
137 Removal of useless dependecies via forward declarations
139 Revision 1.22 2000/07/10 20:57:39 hristov
140 Update of TPC code and macros by M.Kowalski
142 Revision 1.19.2.4 2000/06/26 07:39:42 kowal2
143 Changes to obey the coding rules
145 Revision 1.19.2.3 2000/06/25 08:38:41 kowal2
146 Splitted from AliTPCtracking
148 Revision 1.19.2.2 2000/06/16 12:59:28 kowal2
149 Changed parameter settings
151 Revision 1.19.2.1 2000/06/09 07:15:07 kowal2
153 Defaults loaded automatically (hard-wired)
154 Optional parameters can be set via macro called in the constructor
156 Revision 1.19 2000/04/18 19:00:59 fca
157 Small bug fixes to TPC files
159 Revision 1.18 2000/04/17 09:37:33 kowal2
160 removed obsolete AliTPCDigitsDisplay.C
162 Revision 1.17.2.2 2000/04/10 08:15:12 kowal2
164 New, experimental data structure from M. Ivanov
165 New tracking algorithm
166 Different pad geometry for different sectors
167 Digitization rewritten
169 Revision 1.17.2.1 2000/04/10 07:56:53 kowal2
170 Not used anymore - removed
172 Revision 1.17 2000/01/19 17:17:30 fca
173 Introducing a list of lists of hits -- more hits allowed for detector now
175 Revision 1.16 1999/11/05 09:29:23 fca
176 Accept only signals > 0
178 Revision 1.15 1999/10/08 06:26:53 fca
179 Removed ClustersIndex - not used anymore
181 Revision 1.14 1999/09/29 09:24:33 fca
182 Introduction of the Copyright and cvs Log
186 ///////////////////////////////////////////////////////////////////////////////
188 // Time Projection Chamber //
189 // This class contains the basic functions for the Time Projection Chamber //
190 // detector. Functions specific to one particular geometry are //
191 // contained in the derived classes //
195 <img src="picts/AliTPCClass.gif">
200 ///////////////////////////////////////////////////////////////////////////////
208 #include <TGeometry.h>
211 #include <TObjectTable.h>
212 #include "TParticle.h"
218 #include <iostream.h>
223 #include "AliTrackReference.h"
226 #include "AliTPCParamSR.h"
227 #include "AliTPCPRF2D.h"
228 #include "AliTPCRF1D.h"
229 #include "AliDigits.h"
230 #include "AliSimDigits.h"
231 #include "AliTPCTrackHits.h"
232 #include "AliTPCTrackHitsV2.h"
233 #include "AliPoints.h"
234 #include "AliArrayBranch.h"
237 #include "AliTPCDigitsArray.h"
238 #include "AliComplexCluster.h"
239 #include "AliClusters.h"
240 #include "AliTPCClustersRow.h"
241 #include "AliTPCClustersArray.h"
243 #include "AliTPCcluster.h"
244 #include "AliTPCclusterer.h"
245 #include "AliTPCtracker.h"
247 #include <TInterpreter.h>
254 //_____________________________________________________________________________
255 // helper class for fast matrix and vector manipulation - no range checking
256 // origin - Marian Ivanov
258 class AliTPCFastMatrix : public TMatrix {
260 AliTPCFastMatrix(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb);
261 inline Float_t & UncheckedAt(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
262 inline Float_t UncheckedAtFast(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
265 AliTPCFastMatrix::AliTPCFastMatrix(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb):
266 TMatrix(row_lwb, row_upb,col_lwb,col_upb)
269 //_____________________________________________________________________________
270 class AliTPCFastVector : public TVector {
272 AliTPCFastVector(Int_t size);
273 virtual ~AliTPCFastVector(){;}
274 inline Float_t & UncheckedAt(Int_t index) const {return fElements[index];} //fast acces
278 AliTPCFastVector::AliTPCFastVector(Int_t size):TVector(size){
281 //_____________________________________________________________________________
285 // Default constructor
296 fHitType = 2; //default CONTAINERS - based on ROOT structure
303 //_____________________________________________________________________________
304 AliTPC::AliTPC(const char *name, const char *title)
305 : AliDetector(name,title)
308 // Standard constructor
312 // Initialise arrays of hits and digits
313 fHits = new TClonesArray("AliTPChit", 176);
314 gAlice->AddHitList(fHits);
319 fTrackHits = new AliTPCTrackHitsV2;
320 fTrackHits->SetHitPrecision(0.002);
321 fTrackHits->SetStepPrecision(0.003);
322 fTrackHits->SetMaxDistance(100);
324 fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
325 fTrackHitsOld->SetHitPrecision(0.002);
326 fTrackHitsOld->SetStepPrecision(0.003);
327 fTrackHitsOld->SetMaxDistance(100);
334 // Initialise counters
340 // Initialise color attributes
341 SetMarkerColor(kYellow);
344 // Set TPC parameters
348 if (!strcmp(title,"Default")) {
349 fTPCParam = new AliTPCParamSR;
351 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
357 //_____________________________________________________________________________
368 delete fTrackHits; //MI 15.09.2000
369 delete fTrackHitsOld; //MI 10.12.2001
370 if (fNoiseTable) delete [] fNoiseTable;
374 //_____________________________________________________________________________
375 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
378 // Add a hit to the list
380 // TClonesArray &lhits = *fHits;
381 // new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
383 TClonesArray &lhits = *fHits;
384 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
387 AddHit2(track,vol,hits);
390 void AliTPC::AddTrackReference(Int_t lab, TLorentzVector p, TLorentzVector x, Float_t length){
392 // add a trackrefernce to the list
393 if (!fTrackReferences) {
394 cerr<<"Container trackrefernce not active\n";
397 Int_t nref = fTrackReferences->GetEntriesFast();
398 TClonesArray &lref = *fTrackReferences;
399 AliTrackReference * ref = new(lref[nref]) AliTrackReference;
400 ref->SetMomentum(p[0],p[1],p[2]);
401 ref->SetPosition(x[0],x[1],x[2]);
403 ref->SetLength(length);
406 //_____________________________________________________________________________
407 void AliTPC::BuildGeometry()
411 // Build TPC ROOT TNode geometry for the event display
416 const int kColorTPC=19;
417 char name[5], title[25];
418 const Double_t kDegrad=TMath::Pi()/180;
419 const Double_t kRaddeg=180./TMath::Pi();
422 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
423 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
425 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
426 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
428 Int_t nLo = fTPCParam->GetNInnerSector()/2;
429 Int_t nHi = fTPCParam->GetNOuterSector()/2;
431 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
432 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
433 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
434 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
437 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
438 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
444 // Get ALICE top node
447 nTop=gAlice->GetGeometry()->GetNode("alice");
451 rl = fTPCParam->GetInnerRadiusLow();
452 ru = fTPCParam->GetInnerRadiusUp();
456 sprintf(name,"LS%2.2d",i);
458 sprintf(title,"TPC low sector %3d",i);
461 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
462 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
463 tubs->SetNumberOfDivisions(1);
465 nNode = new TNode(name,title,name,0,0,0,"");
466 nNode->SetLineColor(kColorTPC);
472 rl = fTPCParam->GetOuterRadiusLow();
473 ru = fTPCParam->GetOuterRadiusUp();
476 sprintf(name,"US%2.2d",i);
478 sprintf(title,"TPC upper sector %d",i);
480 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
481 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
482 tubs->SetNumberOfDivisions(1);
484 nNode = new TNode(name,title,name,0,0,0,"");
485 nNode->SetLineColor(kColorTPC);
491 //_____________________________________________________________________________
492 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t )
495 // Calculate distance from TPC to mouse on the display
501 void AliTPC::Clusters2Tracks(TFile *of) {
502 //-----------------------------------------------------------------
503 // This is a track finder.
504 //-----------------------------------------------------------------
505 AliTPCtracker tracker(fTPCParam);
506 tracker.Clusters2Tracks(gFile,of);
509 //_____________________________________________________________________________
510 void AliTPC::CreateMaterials()
512 //-----------------------------------------------
513 // Create Materials for for TPC simulations
514 //-----------------------------------------------
516 //-----------------------------------------------------------------
517 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
518 //-----------------------------------------------------------------
520 Int_t iSXFLD=gAlice->Field()->Integ();
521 Float_t sXMGMX=gAlice->Field()->Max();
523 Float_t amat[5]; // atomic numbers
524 Float_t zmat[5]; // z
525 Float_t wmat[5]; // proportions
531 //***************** Gases *************************
533 //-------------------------------------------------
535 //-------------------------------------------------
546 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
556 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
559 //--------------------------------------------------------------
561 //--------------------------------------------------------------
578 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
580 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
595 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
597 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
613 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
615 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
617 //----------------------------------------------------------------
618 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
619 //----------------------------------------------------------------
625 Float_t rho,absl,X0,buf[1];
629 for(nc = 0;nc<fNoComp;nc++)
632 // retrive material constants
634 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,X0,absl,buf,nbuf);
639 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
641 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
642 density += fMixtProp[nc]*rho; // density of the mixture
646 // mixture proportions by weight!
648 for(nc = 0;nc<fNoComp;nc++)
651 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
653 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
654 apure[nnc] : amol[nnc])/am;
658 // Drift gases 1 - nonsensitive, 2 - sensitive
660 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
661 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
670 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
673 //----------------------------------------------------------------------
675 //----------------------------------------------------------------------
697 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
719 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
737 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
755 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
757 // SiO2 - used later for the glass fiber
769 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
778 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
787 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
796 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
814 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
833 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
835 // Epoxy - C14 H20 O3
852 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
860 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
864 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,X0,absl,buf,nbuf);
868 wmat[0]=0.644; // by weight!
871 density=0.5*(1.25+2.265);
873 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
877 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,X0,absl,buf,nbuf);
879 wmat[0]=0.725; // by weight!
884 AliMixture(39,"G10",amat,zmat,density,2,wmat);
889 //----------------------------------------------------------
890 // tracking media for gases
891 //----------------------------------------------------------
893 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
894 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
895 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
896 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
898 //-----------------------------------------------------------
899 // tracking media for solids
900 //-----------------------------------------------------------
902 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
903 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
904 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
905 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
906 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
907 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
908 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
909 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
910 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
911 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
912 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
913 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
917 void AliTPC::GenerNoise(Int_t tablesize)
920 //Generate table with noise
927 if (fNoiseTable) delete[] fNoiseTable;
928 fNoiseTable = new Float_t[tablesize];
929 fNoiseDepth = tablesize;
930 fCurrentNoise =0; //!index of the noise in the noise table
932 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
933 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
936 Float_t AliTPC::GetNoise()
938 // get noise from table
939 // if ((fCurrentNoise%10)==0)
940 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
941 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
942 return fNoiseTable[fCurrentNoise++];
943 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
947 Bool_t AliTPC::IsSectorActive(Int_t sec)
950 // check if the sector is active
951 if (!fActiveSectors) return kTRUE;
952 else return fActiveSectors[sec];
955 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
957 // activate interesting sectors
958 if (fActiveSectors) delete [] fActiveSectors;
959 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
960 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
961 for (Int_t i=0;i<n;i++)
962 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
966 void AliTPC::SetActiveSectors(Int_t flag)
969 // activate sectors which were hitted by tracks
971 if (fHitType==0) return; // if Clones hit - not short volume ID information
972 if (fActiveSectors) delete [] fActiveSectors;
973 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
975 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
978 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
980 if (fHitType>1) branch = gAlice->TreeH()->GetBranch("TPC2");
981 else branch = gAlice->TreeH()->GetBranch("TPC");
982 Stat_t ntracks = gAlice->TreeH()->GetEntries();
983 // loop over all hits
984 for(Int_t track=0;track<ntracks;track++){
987 if (fTrackHits && fHitType&4) {
988 TBranch * br1 = gAlice->TreeH()->GetBranch("fVolumes");
989 TBranch * br2 = gAlice->TreeH()->GetBranch("fNVolumes");
990 br1->GetEvent(track);
991 br2->GetEvent(track);
992 Int_t *volumes = fTrackHits->GetVolumes();
993 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
994 fActiveSectors[volumes[j]]=kTRUE;
998 if (fTrackHitsOld && fHitType&2) {
999 TBranch * br = gAlice->TreeH()->GetBranch("fTrackHitsInfo");
1000 br->GetEvent(track);
1001 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
1002 for (UInt_t j=0;j<ar->GetSize();j++){
1003 fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
1013 void AliTPC::Digits2Clusters(TFile *of, Int_t eventnumber)
1015 //-----------------------------------------------------------------
1016 // This is a simple cluster finder.
1017 //-----------------------------------------------------------------
1018 AliTPCclusterer::Digits2Clusters(fTPCParam,of,eventnumber);
1021 extern Double_t SigmaY2(Double_t, Double_t, Double_t);
1022 extern Double_t SigmaZ2(Double_t, Double_t);
1023 //_____________________________________________________________________________
1024 void AliTPC::Hits2Clusters(TFile *of, Int_t eventn)
1026 //--------------------------------------------------------
1027 // TPC simple cluster generator from hits
1028 // obtained from the TPC Fast Simulator
1029 // The point errors are taken from the parametrization
1030 //--------------------------------------------------------
1032 //-----------------------------------------------------------------
1033 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1034 //-----------------------------------------------------------------
1035 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
1036 // Jouri.Belikov@cern.ch
1037 //----------------------------------------------------------------
1039 /////////////////////////////////////////////////////////////////////////////
1041 //---------------------------------------------------------------------
1042 // ALICE TPC Cluster Parameters
1043 //--------------------------------------------------------------------
1047 // Cluster width in rphi
1048 const Float_t kACrphi=0.18322;
1049 const Float_t kBCrphi=0.59551e-3;
1050 const Float_t kCCrphi=0.60952e-1;
1051 // Cluster width in z
1052 const Float_t kACz=0.19081;
1053 const Float_t kBCz=0.55938e-3;
1054 const Float_t kCCz=0.30428;
1056 TDirectory *savedir=gDirectory;
1058 if (!of->IsOpen()) {
1059 cerr<<"AliTPC::Hits2Clusters(): output file not open !\n";
1063 //if(fDefaults == 0) SetDefaults();
1065 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
1067 TParticle *particle; // pointer to a given particle
1068 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1072 Float_t pl,pt,tanth,rpad,ratio;
1075 //---------------------------------------------------------------
1076 // Get the access to the tracks
1077 //---------------------------------------------------------------
1079 TTree *tH = gAlice->TreeH();
1080 Stat_t ntracks = tH->GetEntries();
1082 //Switch to the output file
1087 sprintf(cname,"TreeC_TPC_%d",eventn);
1089 fTPCParam->Write(fTPCParam->GetTitle());
1090 AliTPCClustersArray carray;
1091 carray.Setup(fTPCParam);
1092 carray.SetClusterType("AliTPCcluster");
1095 Int_t nclusters=0; //cluster counter
1097 //------------------------------------------------------------
1098 // Loop over all sectors (72 sectors for 20 deg
1099 // segmentation for both lower and upper sectors)
1100 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
1101 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
1103 // First cluster for sector 0 starts at "0"
1104 //------------------------------------------------------------
1106 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++){
1108 fTPCParam->AdjustCosSin(isec,cph,sph);
1110 //------------------------------------------------------------
1112 //------------------------------------------------------------
1114 for(Int_t track=0;track<ntracks;track++){
1116 tH->GetEvent(track);
1118 // Get number of the TPC hits
1120 tpcHit = (AliTPChit*)FirstHit(-1);
1126 if (tpcHit->fQ == 0.) {
1127 tpcHit = (AliTPChit*) NextHit();
1128 continue; //information about track (I.Belikov)
1130 sector=tpcHit->fSector; // sector number
1133 tpcHit = (AliTPChit*) NextHit();
1136 ipart=tpcHit->Track();
1137 particle=gAlice->Particle(ipart);
1140 if(pt < 1.e-9) pt=1.e-9;
1142 tanth = TMath::Abs(tanth);
1143 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
1144 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
1146 // space-point resolutions
1148 sigmaRphi=SigmaY2(rpad,tanth,pt);
1149 sigmaZ =SigmaZ2(rpad,tanth );
1153 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
1154 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
1156 // temporary protection
1158 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
1159 if(sigmaZ < 0.) sigmaZ=0.4e-3;
1160 if(clRphi < 0.) clRphi=2.5e-3;
1161 if(clZ < 0.) clZ=2.5e-5;
1166 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
1167 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
1169 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
1170 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
1171 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
1172 Float_t alpha=(isec < fTPCParam->GetNInnerSector()) ?
1173 fTPCParam->GetInnerAngle() : fTPCParam->GetOuterAngle();
1174 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
1175 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
1176 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
1177 if (TMath::Abs(xyz[1])>fTPCParam->GetZLength()) xyz[1]=tpcHit->Z();
1178 xyz[2]=sigmaRphi; // fSigmaY2
1179 xyz[3]=sigmaZ; // fSigmaZ2
1180 xyz[4]=tpcHit->fQ; // q
1182 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
1183 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
1185 Int_t tracks[3]={tpcHit->Track(), -1, -1};
1186 AliTPCcluster cluster(tracks,xyz);
1188 clrow->InsertCluster(&cluster); nclusters++;
1190 tpcHit = (AliTPChit*)NextHit();
1193 } // end of loop over hits
1195 } // end of loop over tracks
1197 Int_t nrows=fTPCParam->GetNRow(isec);
1198 for (Int_t irow=0; irow<nrows; irow++) {
1199 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
1200 if (!clrow) continue;
1201 carray.StoreRow(isec,irow);
1202 carray.ClearRow(isec,irow);
1205 } // end of loop over sectors
1207 cerr<<"Number of made clusters : "<<nclusters<<" \n";
1208 carray.GetTree()->SetName(cname);
1209 carray.GetTree()->Write();
1211 savedir->cd(); //switch back to the input file
1213 } // end of function
1215 //_________________________________________________________________
1216 void AliTPC::Hits2ExactClustersSector(Int_t isec)
1218 //--------------------------------------------------------
1219 //calculate exact cross point of track and given pad row
1220 //resulting values are expressed in "digit" coordinata
1221 //--------------------------------------------------------
1223 //-----------------------------------------------------------------
1224 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1225 //-----------------------------------------------------------------
1227 if (fClustersArray==0){
1231 TParticle *particle; // pointer to a given particle
1232 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1233 // Int_t sector,nhits;
1235 const Int_t kcmaxhits=30000;
1236 AliTPCFastVector * xxxx = new AliTPCFastVector(kcmaxhits*4);
1237 AliTPCFastVector & xxx = *xxxx;
1238 Int_t maxhits = kcmaxhits;
1239 //construct array for each padrow
1240 for (Int_t i=0; i<fTPCParam->GetNRow(isec);i++)
1241 fClustersArray->CreateRow(isec,i);
1243 //---------------------------------------------------------------
1244 // Get the access to the tracks
1245 //---------------------------------------------------------------
1247 TTree *tH = gAlice->TreeH();
1248 Stat_t ntracks = tH->GetEntries();
1249 Int_t npart = gAlice->GetNtrack();
1252 if (fHitType>1) branch = tH->GetBranch("TPC2");
1253 else branch = tH->GetBranch("TPC");
1255 //------------------------------------------------------------
1257 //------------------------------------------------------------
1259 for(Int_t track=0;track<ntracks;track++){
1260 Bool_t isInSector=kTRUE;
1262 isInSector = TrackInVolume(isec,track);
1263 if (!isInSector) continue;
1265 branch->GetEntry(track); // get next track
1267 // Get number of the TPC hits and a pointer
1271 Int_t currentIndex=0;
1272 Int_t lastrow=-1; //last writen row
1276 tpcHit = (AliTPChit*)FirstHit(-1);
1279 Int_t sector=tpcHit->fSector; // sector number
1281 tpcHit = (AliTPChit*) NextHit();
1285 ipart=tpcHit->Track();
1286 if (ipart<npart) particle=gAlice->Particle(ipart);
1290 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
1291 Int_t index[3]={1,isec,0};
1292 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
1293 if (currentrow<0) {tpcHit = (AliTPChit*)NextHit(); continue;}
1294 if (lastrow<0) lastrow=currentrow;
1295 if (currentrow==lastrow){
1296 if ( currentIndex>=maxhits){
1298 xxx.ResizeTo(4*maxhits);
1300 xxx(currentIndex*4)=x[0];
1301 xxx(currentIndex*4+1)=x[1];
1302 xxx(currentIndex*4+2)=x[2];
1303 xxx(currentIndex*4+3)=tpcHit->fQ;
1307 if (currentIndex>2){
1319 for (Int_t index=0;index<currentIndex;index++){
1321 x=x2=x3=x4=xxx(index*4);
1329 sumy+=xxx(index*4+1);
1330 sumxy+=xxx(index*4+1)*x;
1331 sumx2y+=xxx(index*4+1)*x2;
1332 sumz+=xxx(index*4+2);
1333 sumxz+=xxx(index*4+2)*x;
1334 sumx2z+=xxx(index*4+2)*x2;
1335 sumq+=xxx(index*4+3);
1337 Float_t centralPad = (fTPCParam->GetNPads(isec,lastrow)-1)/2;
1338 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
1339 sumx2*(sumx*sumx3-sumx2*sumx2);
1341 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
1342 sumx2*(sumxy*sumx3-sumx2y*sumx2);
1343 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
1344 sumx2*(sumxz*sumx3-sumx2z*sumx2);
1346 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
1347 sumx2*(sumx*sumx2y-sumx2*sumxy);
1348 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
1349 sumx2*(sumx*sumx2z-sumx2*sumxz);
1351 if (TMath::Abs(det)<0.00001){
1352 tpcHit = (AliTPChit*)NextHit();
1356 Float_t y=detay/det+centralPad;
1357 Float_t z=detaz/det;
1358 Float_t by=detby/det; //y angle
1359 Float_t bz=detbz/det; //z angle
1360 sumy/=Float_t(currentIndex);
1361 sumz/=Float_t(currentIndex);
1363 AliTPCClustersRow * row = (fClustersArray->GetRow(isec,lastrow));
1365 AliComplexCluster* cl = new((AliComplexCluster*)row->Append()) AliComplexCluster ;
1366 // AliComplexCluster cl;
1372 cl->fTracks[0]=ipart;
1376 } //end of calculating cluster for given row
1379 tpcHit = (AliTPChit*)NextHit();
1380 } // end of loop over hits
1381 } // end of loop over tracks
1382 //write padrows to tree
1383 for (Int_t ii=0; ii<fTPCParam->GetNRow(isec);ii++) {
1384 fClustersArray->StoreRow(isec,ii);
1385 fClustersArray->ClearRow(isec,ii);
1394 void AliTPC::SDigits2Digits2(Int_t eventnumber)
1396 //create digits from summable digits
1397 GenerNoise(500000); //create teble with noise
1400 sprintf(sname,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1401 sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1403 //conect tree with sSDigits
1405 if (gAlice->GetTreeDFile()) {
1406 t = (TTree *)gAlice->GetTreeDFile()->Get(sname);
1408 t = (TTree *)gDirectory->Get(sname);
1411 cerr<<"TPC tree with sdigits not found"<<endl;
1414 AliSimDigits digarr, *dummy=&digarr;
1415 t->GetBranch("Segment")->SetAddress(&dummy);
1416 Stat_t nentries = t->GetEntries();
1418 // set zero suppression
1420 fTPCParam->SetZeroSup(2);
1422 // get zero suppression
1424 Int_t zerosup = fTPCParam->GetZeroSup();
1426 //make tree with digits
1428 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1429 arr->SetClass("AliSimDigits");
1430 arr->Setup(fTPCParam);
1431 // Note that methods arr->MakeTree have different signatures
1432 if (gAlice->GetTreeDFile()) {
1433 arr->MakeTree(gAlice->GetTreeDFile());
1435 arr->MakeTree(fDigitsFile);
1438 AliTPCParam * par =fTPCParam;
1440 //Loop over segments of the TPC
1442 for (Int_t n=0; n<nentries; n++) {
1445 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1446 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
1449 if (!IsSectorActive(sec)) continue;
1450 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1451 Int_t nrows = digrow->GetNRows();
1452 Int_t ncols = digrow->GetNCols();
1454 digrow->ExpandBuffer();
1455 digarr.ExpandBuffer();
1456 digrow->ExpandTrackBuffer();
1457 digarr.ExpandTrackBuffer();
1460 Short_t * pamp0 = digarr.GetDigits();
1461 Int_t * ptracks0 = digarr.GetTracks();
1462 Short_t * pamp1 = digrow->GetDigits();
1463 Int_t * ptracks1 = digrow->GetTracks();
1464 Int_t nelems =nrows*ncols;
1465 Int_t saturation = fTPCParam->GetADCSat();
1466 //use internal structure of the AliDigits - for speed reason
1467 //if you cahnge implementation
1468 //of the Alidigits - it must be rewriten -
1469 for (Int_t i= 0; i<nelems; i++){
1470 // Float_t q = *pamp0;
1471 //q/=16.; //conversion faktor
1472 //Float_t noise= GetNoise();
1474 //q= TMath::Nint(q);
1475 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1477 if (q>saturation) q=saturation;
1479 //if (ptracks0[0]==0)
1482 ptracks1[0]=ptracks0[0];
1483 ptracks1[nelems]=ptracks0[nelems];
1484 ptracks1[2*nelems]=ptracks0[2*nelems];
1492 arr->StoreRow(sec,row);
1493 arr->ClearRow(sec,row);
1494 // cerr<<sec<<"\t"<<row<<"\n";
1501 arr->GetTree()->SetName(dname);
1502 arr->GetTree()->AutoSave();
1505 //_________________________________________
1506 void AliTPC::Merge(TTree * intree, Int_t *mask, Int_t nin, Int_t outid)
1509 //intree - pointer to array of trees with s digits
1510 //mask - mask for each
1511 //nin - number of inputs
1512 //outid - event number of the output event
1514 //create digits from summable digits
1515 //conect tree with sSDigits
1518 AliSimDigits ** digarr = new AliSimDigits*[nin];
1519 for (Int_t i1=0;i1<nin; i1++){
1521 intree[i1].GetBranch("Segment")->SetAddress(&digarr[i1]);
1523 Stat_t nentries = intree[0].GetEntries();
1525 //make tree with digits
1527 sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),outid);
1528 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1529 arr->SetClass("AliSimDigits");
1530 arr->Setup(fTPCParam);
1531 arr->MakeTree(fDigitsFile);
1533 // set zero suppression
1535 fTPCParam->SetZeroSup(2);
1537 // get zero suppression
1539 Int_t zerosup = fTPCParam->GetZeroSup();
1542 AliTPCParam * par =fTPCParam;
1544 //Loop over segments of the TPC
1545 for (Int_t n=0; n<nentries; n++) {
1547 for (Int_t i=0;i<nin; i++){
1548 //connect proper digits
1549 intree[i].GetEvent(n);
1550 digarr[i]->ExpandBuffer();
1551 digarr[i]->ExpandTrackBuffer();
1554 if (!par->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
1555 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
1559 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1560 Int_t nrows = digrow->GetNRows();
1561 Int_t ncols = digrow->GetNCols();
1563 digrow->ExpandBuffer();
1564 digrow->ExpandTrackBuffer();
1566 for (Int_t rows=0;rows<nrows; rows++){
1567 for (Int_t col=0;col<ncols; col++){
1569 Int_t label[1000]; // i hope no more than 300 events merged
1571 // looop over digits
1572 for (Int_t i=0;i<nin; i++){
1573 q += digarr[i]->GetDigitFast(rows,col);
1574 for (Int_t tr=0;tr<3;tr++) {
1575 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
1577 label[labptr]=lab+mask[i]-2;
1583 q = gRandom->Gaus(q,fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac()*16);
1585 q/=16; //conversion faktor
1590 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat();
1591 digrow->SetDigitFast((Short_t)q,rows,col);
1592 for (Int_t tr=0;tr<3;tr++){
1594 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
1596 ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
1601 arr->StoreRow(sec,row);
1603 arr->ClearRow(sec,row);
1608 arr->GetTree()->SetName(dname);
1609 arr->GetTree()->Write();
1615 /*_________________________________________
1616 void AliTPC::SDigits2Digits(Int_t eventnumber)
1620 cerr<<"Digitizing TPC...\n";
1622 Hits2Digits(eventnumber);
1627 // char treeName[100];
1629 // sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1631 // GetDigitsArray()->GetTree()->Write(treeName);
1634 //__________________________________________________________________
1635 void AliTPC::SetDefaults(){
1638 cerr<<"Setting default parameters...\n";
1640 // Set response functions
1642 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1644 printf("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...\n");
1646 param = new AliTPCParamSR();
1649 param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1652 printf("No TPC parameters found\n");
1657 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1658 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1659 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1660 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1661 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1662 rf->SetOffset(3*param->GetZSigma());
1665 TDirectory *savedir=gDirectory;
1666 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1668 cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1671 prfinner->Read("prf_07504_Gati_056068_d02");
1672 prfouter1->Read("prf_10006_Gati_047051_d03");
1673 prfouter2->Read("prf_15006_Gati_047051_d03");
1677 param->SetInnerPRF(prfinner);
1678 param->SetOuter1PRF(prfouter1);
1679 param->SetOuter2PRF(prfouter2);
1680 param->SetTimeRF(rf);
1690 //__________________________________________________________________
1691 void AliTPC::Hits2Digits(Int_t eventnumber)
1693 //----------------------------------------------------
1694 // Loop over all sectors for a single event
1695 //----------------------------------------------------
1698 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1699 GenerNoise(500000); //create teble with noise
1701 //setup TPCDigitsArray
1703 if(GetDigitsArray()) delete GetDigitsArray();
1705 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1706 arr->SetClass("AliSimDigits");
1707 arr->Setup(fTPCParam);
1708 // Note that methods arr->MakeTree have different signatures
1709 if (gAlice->GetTreeDFile()) {
1710 arr->MakeTree(gAlice->GetTreeDFile());
1712 arr->MakeTree(fDigitsFile);
1714 SetDigitsArray(arr);
1716 fDigitsSwitch=0; // standard digits
1718 cerr<<"Digitizing TPC -- normal digits...\n";
1720 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1726 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1728 GetDigitsArray()->GetTree()->SetName(treeName);
1729 GetDigitsArray()->GetTree()->AutoSave();
1736 //__________________________________________________________________
1737 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1740 //-----------------------------------------------------------
1741 // summable digits - 16 bit "ADC", no noise, no saturation
1742 //-----------------------------------------------------------
1744 //----------------------------------------------------
1745 // Loop over all sectors for a single event
1746 //----------------------------------------------------
1749 if(fDefaults == 0) SetDefaults();
1750 GenerNoise(500000); //create table with noise
1751 //setup TPCDigitsArray
1753 if(GetDigitsArray()) delete GetDigitsArray();
1755 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1756 arr->SetClass("AliSimDigits");
1757 arr->Setup(fTPCParam);
1758 // Note that methods arr->MakeTree have different signatures
1759 if (gAlice->GetTreeSFile()) {
1760 arr->MakeTree(gAlice->GetTreeSFile());
1762 arr->MakeTree(fDigitsFile);
1764 SetDigitsArray(arr);
1766 cerr<<"Digitizing TPC -- summable digits...\n";
1768 fDigitsSwitch=1; // summable digits
1770 // set zero suppression to "0"
1772 fTPCParam->SetZeroSup(0);
1774 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1781 sprintf(treeName,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
1783 GetDigitsArray()->GetTree()->SetName(treeName);
1784 GetDigitsArray()->GetTree()->AutoSave();
1790 //__________________________________________________________________
1791 void AliTPC::Hits2SDigits()
1794 //-----------------------------------------------------------
1795 // summable digits - 16 bit "ADC", no noise, no saturation
1796 //-----------------------------------------------------------
1798 //----------------------------------------------------
1799 // Loop over all sectors for a single event
1800 //----------------------------------------------------
1801 //MI change - for pp run
1802 Int_t eventnumber = gAlice->GetEvNumber();
1804 if(fDefaults == 0) SetDefaults();
1805 GenerNoise(500000); //create table with noise
1807 //setup TPCDigitsArray
1809 if(GetDigitsArray()) delete GetDigitsArray();
1811 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1812 arr->SetClass("AliSimDigits");
1813 arr->Setup(fTPCParam);
1814 // Note that methods arr->MakeTree have different signatures
1815 if (gAlice->GetTreeSFile()) {
1816 arr->MakeTree(gAlice->GetTreeSFile());
1818 arr->MakeTree(fDigitsFile);
1820 SetDigitsArray(arr);
1822 cerr<<"Digitizing TPC -- summable digits...\n";
1824 // fDigitsSwitch=1; // summable digits -for the moment direct
1826 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++) if (IsSectorActive(isec)) Hits2DigitsSector(isec);
1832 sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
1834 GetDigitsArray()->GetTree()->SetName(treeName);
1835 GetDigitsArray()->GetTree()->AutoSave();
1840 //_____________________________________________________________________________
1841 void AliTPC::Hits2DigitsSector(Int_t isec)
1843 //-------------------------------------------------------------------
1844 // TPC conversion from hits to digits.
1845 //-------------------------------------------------------------------
1847 //-----------------------------------------------------------------
1848 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1849 //-----------------------------------------------------------------
1851 //-------------------------------------------------------
1852 // Get the access to the track hits
1853 //-------------------------------------------------------
1855 // check if the parameters are set - important if one calls this method
1856 // directly, not from the Hits2Digits
1858 if(fDefaults == 0) SetDefaults();
1860 TTree *tH = gAlice->TreeH(); // pointer to the hits tree
1861 Stat_t ntracks = tH->GetEntries();
1865 //-------------------------------------------
1866 // Only if there are any tracks...
1867 //-------------------------------------------
1871 //printf("*** Processing sector number %d ***\n",isec);
1873 Int_t nrows =fTPCParam->GetNRow(isec);
1875 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1877 MakeSector(isec,nrows,tH,ntracks,row);
1879 //--------------------------------------------------------
1880 // Digitize this sector, row by row
1881 // row[i] is the pointer to the TObjArray of AliTPCFastVectors,
1882 // each one containing electrons accepted on this
1883 // row, assigned into tracks
1884 //--------------------------------------------------------
1888 if (fDigitsArray->GetTree()==0) fDigitsArray->MakeTree(fDigitsFile);
1890 for (i=0;i<nrows;i++){
1892 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1894 DigitizeRow(i,isec,row);
1896 fDigitsArray->StoreRow(isec,i);
1898 Int_t ndig = dig->GetDigitSize();
1899 if (gDebug > 10) printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1901 fDigitsArray->ClearRow(isec,i);
1904 } // end of the sector digitization
1906 for(i=0;i<nrows+2;i++){
1911 delete [] row; // delete the array of pointers to TObjArray-s
1915 } // end of Hits2DigitsSector
1918 //_____________________________________________________________________________
1919 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1921 //-----------------------------------------------------------
1922 // Single row digitization, coupling from the neighbouring
1923 // rows taken into account
1924 //-----------------------------------------------------------
1926 //-----------------------------------------------------------------
1927 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1928 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1929 //-----------------------------------------------------------------
1932 Float_t zerosup = fTPCParam->GetZeroSup();
1933 // Int_t nrows =fTPCParam->GetNRow(isec);
1934 fCurrentIndex[1]= isec;
1937 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1938 Int_t nofTbins = fTPCParam->GetMaxTBin();
1939 Int_t indexRange[4];
1941 // Integrated signal for this row
1942 // and a single track signal
1945 AliTPCFastMatrix *m1 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // integrated
1946 AliTPCFastMatrix *m2 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // single
1948 AliTPCFastMatrix &total = *m1;
1950 // Array of pointers to the label-signal list
1952 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1953 Float_t **pList = new Float_t* [nofDigits];
1957 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1961 //Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1962 //Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1965 for (Int_t row= row1;row<=row2;row++){
1966 Int_t nTracks= rows[row]->GetEntries();
1967 for (i1=0;i1<nTracks;i1++){
1968 fCurrentIndex[2]= row;
1969 fCurrentIndex[3]=irow+1;
1971 m2->Zero(); // clear single track signal matrix
1972 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1973 GetList(trackLabel,nofPads,m2,indexRange,pList);
1975 else GetSignal(rows[row],i1,0,m1,indexRange);
1981 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1983 Float_t fzerosup = zerosup+0.5;
1984 for(Int_t it=0;it<nofTbins;it++){
1985 Float_t *pq = &(total.UncheckedAt(0,it));
1986 for(Int_t ip=0;ip<nofPads;ip++){
1990 if(fDigitsSwitch == 0){
1992 if(q <=fzerosup) continue; // do not fill zeros
1994 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1999 if(q <= 0.) continue; // do not fill zeros
2000 if(q>2000.) q=2000.;
2006 // "real" signal or electronic noise (list = -1)?
2009 for(Int_t j1=0;j1<3;j1++){
2010 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
2015 <A NAME="AliDigits"></A>
2016 using of AliDigits object
2019 dig->SetDigitFast((Short_t)q,it,ip);
2020 if (fDigitsArray->IsSimulated())
2022 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
2023 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
2024 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
2028 } // end of loop over time buckets
2029 } // end of lop over pads
2032 // This row has been digitized, delete nonused stuff
2035 for(lp=0;lp<nofDigits;lp++){
2036 if(pList[lp]) delete [] pList[lp];
2045 } // end of DigitizeRow
2047 //_____________________________________________________________________________
2049 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
2050 AliTPCFastMatrix *m1, AliTPCFastMatrix *m2,Int_t *indexRange)
2053 //---------------------------------------------------------------
2054 // Calculates 2-D signal (pad,time) for a single track,
2055 // returns a pointer to the signal matrix and the track label
2056 // No digitization is performed at this level!!!
2057 //---------------------------------------------------------------
2059 //-----------------------------------------------------------------
2060 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2061 // Modified: Marian Ivanov
2062 //-----------------------------------------------------------------
2064 AliTPCFastVector *tv;
2066 tv = (AliTPCFastVector*)p1->At(ntr); // pointer to a track
2067 AliTPCFastVector &v = *tv;
2069 Float_t label = v(0);
2070 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1)-1)/2;
2072 Int_t nElectrons = (tv->GetNrows()-1)/4;
2073 indexRange[0]=9999; // min pad
2074 indexRange[1]=-1; // max pad
2075 indexRange[2]=9999; //min time
2076 indexRange[3]=-1; // max time
2078 AliTPCFastMatrix &signal = *m1;
2079 AliTPCFastMatrix &total = *m2;
2081 // Loop over all electrons
2083 for(Int_t nel=0; nel<nElectrons; nel++){
2085 Float_t aval = v(idx+4);
2086 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
2087 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
2088 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
2090 Int_t *index = fTPCParam->GetResBin(0);
2091 Float_t *weight = & (fTPCParam->GetResWeight(0));
2093 if (n>0) for (Int_t i =0; i<n; i++){
2094 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
2097 Int_t time=index[2];
2098 Float_t qweight = *(weight)*eltoadcfac;
2100 if (m1!=0) signal.UncheckedAt(pad,time)+=qweight;
2101 total.UncheckedAt(pad,time)+=qweight;
2102 if (indexRange[0]>pad) indexRange[0]=pad;
2103 if (indexRange[1]<pad) indexRange[1]=pad;
2104 if (indexRange[2]>time) indexRange[2]=time;
2105 if (indexRange[3]<time) indexRange[3]=time;
2112 } // end of loop over electrons
2114 return label; // returns track label when finished
2117 //_____________________________________________________________________________
2118 void AliTPC::GetList(Float_t label,Int_t np,AliTPCFastMatrix *m,
2119 Int_t *indexRange, Float_t **pList)
2121 //----------------------------------------------------------------------
2122 // Updates the list of tracks contributing to digits for a given row
2123 //----------------------------------------------------------------------
2125 //-----------------------------------------------------------------
2126 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2127 //-----------------------------------------------------------------
2129 AliTPCFastMatrix &signal = *m;
2131 // lop over nonzero digits
2133 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
2134 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
2137 // accept only the contribution larger than 500 electrons (1/2 s_noise)
2139 if(signal(ip,it)<0.5) continue;
2142 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
2144 if(!pList[globalIndex]){
2147 // Create new list (6 elements - 3 signals and 3 labels),
2150 pList[globalIndex] = new Float_t [6];
2154 *pList[globalIndex] = -1.;
2155 *(pList[globalIndex]+1) = -1.;
2156 *(pList[globalIndex]+2) = -1.;
2157 *(pList[globalIndex]+3) = -1.;
2158 *(pList[globalIndex]+4) = -1.;
2159 *(pList[globalIndex]+5) = -1.;
2162 *pList[globalIndex] = label;
2163 *(pList[globalIndex]+3) = signal(ip,it);
2167 // check the signal magnitude
2169 Float_t highest = *(pList[globalIndex]+3);
2170 Float_t middle = *(pList[globalIndex]+4);
2171 Float_t lowest = *(pList[globalIndex]+5);
2174 // compare the new signal with already existing list
2177 if(signal(ip,it)<lowest) continue; // neglect this track
2181 if (signal(ip,it)>highest){
2182 *(pList[globalIndex]+5) = middle;
2183 *(pList[globalIndex]+4) = highest;
2184 *(pList[globalIndex]+3) = signal(ip,it);
2186 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
2187 *(pList[globalIndex]+1) = *pList[globalIndex];
2188 *pList[globalIndex] = label;
2190 else if (signal(ip,it)>middle){
2191 *(pList[globalIndex]+5) = middle;
2192 *(pList[globalIndex]+4) = signal(ip,it);
2194 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
2195 *(pList[globalIndex]+1) = label;
2198 *(pList[globalIndex]+5) = signal(ip,it);
2199 *(pList[globalIndex]+2) = label;
2203 } // end of loop over pads
2204 } // end of loop over time bins
2209 //___________________________________________________________________
2210 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
2211 Stat_t ntracks,TObjArray **row)
2214 //-----------------------------------------------------------------
2215 // Prepares the sector digitization, creates the vectors of
2216 // tracks for each row of this sector. The track vector
2217 // contains the track label and the position of electrons.
2218 //-----------------------------------------------------------------
2220 //-----------------------------------------------------------------
2221 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2222 //-----------------------------------------------------------------
2224 Float_t gasgain = fTPCParam->GetGasGain();
2228 AliTPChit *tpcHit; // pointer to a sigle TPC hit
2231 if (fHitType>1) branch = TH->GetBranch("TPC2");
2232 else branch = TH->GetBranch("TPC");
2235 //----------------------------------------------
2236 // Create TObjArray-s, one for each row,
2237 // each TObjArray will store the AliTPCFastVectors
2238 // of electrons, one AliTPCFastVectors per each track.
2239 //----------------------------------------------
2241 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
2242 AliTPCFastVector **tracks = new AliTPCFastVector* [nrows+2]; //pointers to the track vectors
2244 for(i=0; i<nrows+2; i++){
2245 row[i] = new TObjArray;
2252 //--------------------------------------------------------------------
2253 // Loop over tracks, the "track" contains the full history
2254 //--------------------------------------------------------------------
2256 Int_t previousTrack,currentTrack;
2257 previousTrack = -1; // nothing to store so far!
2259 for(Int_t track=0;track<ntracks;track++){
2260 Bool_t isInSector=kTRUE;
2262 isInSector = TrackInVolume(isec,track);
2263 if (!isInSector) continue;
2265 branch->GetEntry(track); // get next track
2269 tpcHit = (AliTPChit*)FirstHit(-1);
2271 //--------------------------------------------------------------
2273 //--------------------------------------------------------------
2278 Int_t sector=tpcHit->fSector; // sector number
2280 tpcHit = (AliTPChit*) NextHit();
2284 currentTrack = tpcHit->Track(); // track number
2287 if(currentTrack != previousTrack){
2289 // store already filled fTrack
2291 for(i=0;i<nrows+2;i++){
2292 if(previousTrack != -1){
2293 if(nofElectrons[i]>0){
2294 AliTPCFastVector &v = *tracks[i];
2295 v(0) = previousTrack;
2296 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2297 row[i]->Add(tracks[i]);
2300 delete tracks[i]; // delete empty AliTPCFastVector
2306 tracks[i] = new AliTPCFastVector(481); // AliTPCFastVectors for the next fTrack
2308 } // end of loop over rows
2310 previousTrack=currentTrack; // update track label
2313 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2315 //---------------------------------------------------
2316 // Calculate the electron attachment probability
2317 //---------------------------------------------------
2320 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
2321 /fTPCParam->GetDriftV();
2323 Float_t attProb = fTPCParam->GetAttCoef()*
2324 fTPCParam->GetOxyCont()*time; // fraction!
2326 //-----------------------------------------------
2327 // Loop over electrons
2328 //-----------------------------------------------
2331 for(Int_t nel=0;nel<qI;nel++){
2332 // skip if electron lost due to the attachment
2333 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2338 // protection for the nonphysical avalanche size (10**6 maximum)
2340 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2341 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2344 TransportElectron(xyz,index);
2346 fTPCParam->GetPadRow(xyz,index);
2347 // row 0 - cross talk from the innermost row
2348 // row fNRow+1 cross talk from the outermost row
2349 rowNumber = index[2]+1;
2350 //transform position to local digit coordinates
2351 //relative to nearest pad row
2352 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
2354 if (isec <fTPCParam->GetNInnerSector()) {
2355 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2356 y1 = fTPCParam->GetYInner(rowNumber);
2359 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2360 y1 = fTPCParam->GetYOuter(rowNumber);
2362 // gain inefficiency at the wires edges - linear
2365 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.));
2367 nofElectrons[rowNumber]++;
2368 //----------------------------------
2369 // Expand vector if necessary
2370 //----------------------------------
2371 if(nofElectrons[rowNumber]>120){
2372 Int_t range = tracks[rowNumber]->GetNrows();
2373 if((nofElectrons[rowNumber])>(range-1)/4){
2375 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
2379 AliTPCFastVector &v = *tracks[rowNumber];
2380 Int_t idx = 4*nofElectrons[rowNumber]-3;
2381 Real_t * position = &(((AliTPCFastVector&)v).UncheckedAt(idx)); //make code faster
2382 memcpy(position,xyz,4*sizeof(Float_t));
2384 } // end of loop over electrons
2386 tpcHit = (AliTPChit*)NextHit();
2388 } // end of loop over hits
2389 } // end of loop over tracks
2392 // store remaining track (the last one) if not empty
2395 for(i=0;i<nrows+2;i++){
2396 if(nofElectrons[i]>0){
2397 AliTPCFastVector &v = *tracks[i];
2398 v(0) = previousTrack;
2399 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
2400 row[i]->Add(tracks[i]);
2409 delete [] nofElectrons;
2412 } // end of MakeSector
2415 //_____________________________________________________________________________
2419 // Initialise TPC detector after definition of geometry
2424 printf("\n%s: ",ClassName());
2425 for(i=0;i<35;i++) printf("*");
2426 printf(" TPC_INIT ");
2427 for(i=0;i<35;i++) printf("*");
2428 printf("\n%s: ",ClassName());
2430 for(i=0;i<80;i++) printf("*");
2435 //_____________________________________________________________________________
2436 void AliTPC::MakeBranch(Option_t* option, const char *file)
2439 // Create Tree branches for the TPC.
2441 Int_t buffersize = 4000;
2442 char branchname[10];
2443 sprintf(branchname,"%s",GetName());
2445 AliDetector::MakeBranch(option,file);
2447 const char *d = strstr(option,"D");
2449 if (fDigits && gAlice->TreeD() && d) {
2450 MakeBranchInTree(gAlice->TreeD(),
2451 branchname, &fDigits, buffersize, file);
2454 if (fHitType>1) MakeBranch2(option,file); // MI change 14.09.2000
2457 //_____________________________________________________________________________
2458 void AliTPC::ResetDigits()
2461 // Reset number of digits and the digits array for this detector
2464 if (fDigits) fDigits->Clear();
2467 //_____________________________________________________________________________
2468 void AliTPC::SetSecAL(Int_t sec)
2470 //---------------------------------------------------
2471 // Activate/deactivate selection for lower sectors
2472 //---------------------------------------------------
2474 //-----------------------------------------------------------------
2475 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2476 //-----------------------------------------------------------------
2481 //_____________________________________________________________________________
2482 void AliTPC::SetSecAU(Int_t sec)
2484 //----------------------------------------------------
2485 // Activate/deactivate selection for upper sectors
2486 //---------------------------------------------------
2488 //-----------------------------------------------------------------
2489 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2490 //-----------------------------------------------------------------
2495 //_____________________________________________________________________________
2496 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
2498 //----------------------------------------
2499 // Select active lower sectors
2500 //----------------------------------------
2502 //-----------------------------------------------------------------
2503 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2504 //-----------------------------------------------------------------
2514 //_____________________________________________________________________________
2515 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
2516 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
2517 Int_t s11 , Int_t s12)
2519 //--------------------------------
2520 // Select active upper sectors
2521 //--------------------------------
2523 //-----------------------------------------------------------------
2524 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2525 //-----------------------------------------------------------------
2541 //_____________________________________________________________________________
2542 void AliTPC::SetSens(Int_t sens)
2545 //-------------------------------------------------------------
2546 // Activates/deactivates the sensitive strips at the center of
2547 // the pad row -- this is for the space-point resolution calculations
2548 //-------------------------------------------------------------
2550 //-----------------------------------------------------------------
2551 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2552 //-----------------------------------------------------------------
2558 void AliTPC::SetSide(Float_t side=0.)
2560 // choice of the TPC side
2565 //____________________________________________________________________________
2566 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2567 Float_t p2,Float_t p3)
2570 // gax mixture definition
2584 //_____________________________________________________________________________
2586 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2589 // electron transport taking into account:
2591 // 2.ExB at the wires
2592 // 3. nonisochronity
2594 // xyz and index must be already transformed to system 1
2597 fTPCParam->Transform1to2(xyz,index);
2600 Float_t driftl=xyz[2];
2601 if(driftl<0.01) driftl=0.01;
2602 driftl=TMath::Sqrt(driftl);
2603 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2604 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2605 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2606 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2607 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2611 if (fTPCParam->GetMWPCReadout()==kTRUE){
2612 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2613 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2615 //add nonisochronity (not implemented yet)
2618 ClassImp(AliTPCdigit)
2620 //_____________________________________________________________________________
2621 AliTPCdigit::AliTPCdigit(Int_t *tracks, Int_t *digits):
2625 // Creates a TPC digit object
2627 fSector = digits[0];
2628 fPadRow = digits[1];
2631 fSignal = digits[4];
2637 //_____________________________________________________________________________
2638 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2642 // Creates a TPC hit object
2653 //________________________________________________________________________
2654 // Additional code because of the AliTPCTrackHitsV2
2656 void AliTPC::MakeBranch2(Option_t *option,const char *file)
2659 // Create a new branch in the current Root Tree
2660 // The branch of fHits is automatically split
2661 // MI change 14.09.2000
2662 if (fHitType<2) return;
2663 char branchname[10];
2664 sprintf(branchname,"%s2",GetName());
2666 // Get the pointer to the header
2667 const char *cH = strstr(option,"H");
2669 if (fTrackHits && gAlice->TreeH() && cH && fHitType&4) {
2670 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2671 // gAlice->TreeH(),fBufferSize,99);
2672 //TBranch * branch =
2673 gAlice->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2676 // gAlice->TreeH()->GetListOfBranches()->Add(branch);
2678 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2679 const char folder [] = "RunMC/Event/Data";
2681 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2682 Publish(folder,&fTrackHits,branchname);
2684 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2685 TDirectory *wd = gDirectory;
2687 TIter next( b->GetListOfBranches());
2688 while ((b=(TBranch*)next())) {
2693 cout << "Diverting branch " << branchname << " to file " << file << endl;
2697 if (fTrackHitsOld && gAlice->TreeH() && cH && fHitType&2) {
2698 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2699 gAlice->TreeH(),fBufferSize,99);
2700 //TBranch * branch = gAlice->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,
2703 gAlice->TreeH()->GetListOfBranches()->Add(branch);
2705 printf("* AliDetector::MakeBranch * Making Branch %s for trackhits\n",branchname);
2706 const char folder [] = "RunMC/Event/Data";
2708 printf("%15s: Publishing %s to %s\n",ClassName(),branchname,folder);
2709 Publish(folder,&fTrackHitsOld,branchname);
2711 TBranch *b = gAlice->TreeH()->GetBranch(branchname);
2712 TDirectory *wd = gDirectory;
2714 TIter next( b->GetListOfBranches());
2715 while ((b=(TBranch*)next())) {
2720 cout << "Diverting branch " << branchname << " to file " << file << endl;
2725 void AliTPC::SetTreeAddress()
2727 if (fHitType<=1) AliDetector::SetTreeAddress();
2728 if (fHitType>1) SetTreeAddress2();
2731 void AliTPC::SetTreeAddress2()
2734 // Set branch address for the TrackHits Tree
2737 char branchname[20];
2738 sprintf(branchname,"%s2",GetName());
2740 // Branch address for hit tree
2741 TTree *treeH = gAlice->TreeH();
2742 if ((treeH)&&(fHitType&4)) {
2743 branch = treeH->GetBranch(branchname);
2744 if (branch) branch->SetAddress(&fTrackHits);
2746 if ((treeH)&&(fHitType&2)) {
2747 branch = treeH->GetBranch(branchname);
2748 if (branch) branch->SetAddress(&fTrackHitsOld);
2750 //set address to TREETR
2751 TTree *treeTR = gAlice->TreeTR();
2752 if (treeTR && fTrackReferences) {
2753 branch = treeTR->GetBranch(GetName());
2754 if (branch) branch->SetAddress(&fTrackReferences);
2760 void AliTPC::FinishPrimary()
2762 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2763 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2767 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2770 // add hit to the list
2773 int primary = gAlice->GetPrimary(track);
2774 gAlice->Particle(primary)->SetBit(kKeepBit);
2778 gAlice->FlagTrack(track);
2780 //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2781 //if (hit->fTrack!=rtrack)
2782 // cout<<"bad track number\n";
2783 if (fTrackHits && fHitType&4)
2784 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2785 hits[1],hits[2],(Int_t)hits[3]);
2786 if (fTrackHitsOld &&fHitType&2 )
2787 fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2788 hits[1],hits[2],(Int_t)hits[3]);
2792 void AliTPC::ResetHits()
2794 if (fHitType&1) AliDetector::ResetHits();
2795 if (fHitType>1) ResetHits2();
2798 void AliTPC::ResetHits2()
2802 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2803 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2807 AliHit* AliTPC::FirstHit(Int_t track)
2809 if (fHitType>1) return FirstHit2(track);
2810 return AliDetector::FirstHit(track);
2812 AliHit* AliTPC::NextHit()
2814 if (fHitType>1) return NextHit2();
2816 return AliDetector::NextHit();
2819 AliHit* AliTPC::FirstHit2(Int_t track)
2822 // Initialise the hit iterator
2823 // Return the address of the first hit for track
2824 // If track>=0 the track is read from disk
2825 // while if track<0 the first hit of the current
2826 // track is returned
2829 gAlice->ResetHits();
2830 gAlice->TreeH()->GetEvent(track);
2833 if (fTrackHits && fHitType&4) {
2834 fTrackHits->First();
2835 return fTrackHits->GetHit();
2837 if (fTrackHitsOld && fHitType&2) {
2838 fTrackHitsOld->First();
2839 return fTrackHitsOld->GetHit();
2845 AliHit* AliTPC::NextHit2()
2848 //Return the next hit for the current track
2851 if (fTrackHitsOld && fHitType&2) {
2852 fTrackHitsOld->Next();
2853 return fTrackHitsOld->GetHit();
2857 return fTrackHits->GetHit();
2863 void AliTPC::LoadPoints(Int_t)
2867 /* if(fHitType==1) return AliDetector::LoadPoints(a);
2870 if(fHitType==1) AliDetector::LoadPoints(a);
2871 else LoadPoints2(a);
2878 void AliTPC::RemapTrackHitIDs(Int_t *map)
2880 if (!fTrackHits) return;
2882 if (fTrackHitsOld && fHitType&2){
2883 AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2884 for (UInt_t i=0;i<arr->GetSize();i++){
2885 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2886 info->fTrackID = map[info->fTrackID];
2889 if (fTrackHitsOld && fHitType&4){
2890 TClonesArray * arr = fTrackHits->GetArray();;
2891 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2892 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2893 info->fTrackID = map[info->fTrackID];
2898 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2900 //return bool information - is track in given volume
2901 //load only part of the track information
2902 //return true if current track is in volume
2905 if (fTrackHitsOld && fHitType&2) {
2906 TBranch * br = gAlice->TreeH()->GetBranch("fTrackHitsInfo");
2907 br->GetEvent(track);
2908 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2909 for (UInt_t j=0;j<ar->GetSize();j++){
2910 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2914 if (fTrackHits && fHitType&4) {
2915 TBranch * br1 = gAlice->TreeH()->GetBranch("fVolumes");
2916 TBranch * br2 = gAlice->TreeH()->GetBranch("fNVolumes");
2917 br2->GetEvent(track);
2918 br1->GetEvent(track);
2919 Int_t *volumes = fTrackHits->GetVolumes();
2920 Int_t nvolumes = fTrackHits->GetNVolumes();
2921 if (!volumes && nvolumes>0) {
2922 printf("Problematic track\t%d\t%d",track,nvolumes);
2925 for (Int_t j=0;j<nvolumes; j++)
2926 if (volumes[j]==id) return kTRUE;
2930 TBranch * br = gAlice->TreeH()->GetBranch("fSector");
2931 br->GetEvent(track);
2932 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2933 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2940 //_____________________________________________________________________________
2941 void AliTPC::LoadPoints2(Int_t)
2944 // Store x, y, z of all hits in memory
2946 if (fTrackHits == 0 && fTrackHitsOld==0) return;
2949 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2950 if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2952 if (nhits == 0) return;
2953 Int_t tracks = gAlice->GetNtrack();
2954 if (fPoints == 0) fPoints = new TObjArray(tracks);
2957 Int_t *ntrk=new Int_t[tracks];
2958 Int_t *limi=new Int_t[tracks];
2959 Float_t **coor=new Float_t*[tracks];
2960 for(Int_t i=0;i<tracks;i++) {
2966 AliPoints *points = 0;
2969 Int_t chunk=nhits/4+1;
2971 // Loop over all the hits and store their position
2973 ahit = FirstHit2(-1);
2975 trk=ahit->GetTrack();
2976 if(ntrk[trk]==limi[trk]) {
2978 // Initialise a new track
2979 fp=new Float_t[3*(limi[trk]+chunk)];
2981 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2982 delete [] coor[trk];
2989 fp[3*ntrk[trk] ] = ahit->X();
2990 fp[3*ntrk[trk]+1] = ahit->Y();
2991 fp[3*ntrk[trk]+2] = ahit->Z();
2999 for(trk=0; trk<tracks; ++trk) {
3001 points = new AliPoints();
3002 points->SetMarkerColor(GetMarkerColor());
3003 points->SetMarkerSize(GetMarkerSize());
3004 points->SetDetector(this);
3005 points->SetParticle(trk);
3006 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
3007 fPoints->AddAt(points,trk);
3008 delete [] coor[trk];
3018 //_____________________________________________________________________________
3019 void AliTPC::LoadPoints3(Int_t)
3022 // Store x, y, z of all hits in memory
3023 // - only intersection point with pad row
3024 if (fTrackHits == 0) return;
3026 Int_t nhits = fTrackHits->GetEntriesFast();
3027 if (nhits == 0) return;
3028 Int_t tracks = gAlice->GetNtrack();
3029 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
3030 fPoints->Expand(2*tracks);
3033 Int_t *ntrk=new Int_t[tracks];
3034 Int_t *limi=new Int_t[tracks];
3035 Float_t **coor=new Float_t*[tracks];
3036 for(Int_t i=0;i<tracks;i++) {
3042 AliPoints *points = 0;
3045 Int_t chunk=nhits/4+1;
3047 // Loop over all the hits and store their position
3049 ahit = FirstHit2(-1);
3050 //for (Int_t hit=0;hit<nhits;hit++) {
3054 // ahit = (AliHit*)fHits->UncheckedAt(hit);
3055 trk=ahit->GetTrack();
3056 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
3057 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
3058 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
3059 if (currentrow!=lastrow){
3060 lastrow = currentrow;
3061 //later calculate intersection point
3062 if(ntrk[trk]==limi[trk]) {
3064 // Initialise a new track
3065 fp=new Float_t[3*(limi[trk]+chunk)];
3067 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
3068 delete [] coor[trk];
3075 fp[3*ntrk[trk] ] = ahit->X();
3076 fp[3*ntrk[trk]+1] = ahit->Y();
3077 fp[3*ntrk[trk]+2] = ahit->Z();
3084 for(trk=0; trk<tracks; ++trk) {
3086 points = new AliPoints();
3087 points->SetMarkerColor(GetMarkerColor()+1);
3088 points->SetMarkerStyle(5);
3089 points->SetMarkerSize(0.2);
3090 points->SetDetector(this);
3091 points->SetParticle(trk);
3092 // points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
3093 points->SetPolyMarker(ntrk[trk],coor[trk],30);
3094 fPoints->AddAt(points,tracks+trk);
3095 delete [] coor[trk];
3106 void AliTPC::FindTrackHitsIntersection(TClonesArray * arr)
3110 //fill clones array with intersection of current point with the
3115 const Int_t kcmaxhits=30000;
3116 AliTPCFastVector * xxxx = new AliTPCFastVector(kcmaxhits*4);
3117 AliTPCFastVector & xxx = *xxxx;
3118 Int_t maxhits = kcmaxhits;
3121 AliTPChit * tpcHit=0;
3122 tpcHit = (AliTPChit*)FirstHit2(-1);
3123 Int_t currentIndex=0;
3124 Int_t lastrow=-1; //last writen row
3127 if (tpcHit==0) continue;
3128 sector=tpcHit->fSector; // sector number
3129 ipart=tpcHit->Track();
3133 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
3134 Int_t index[3]={1,sector,0};
3135 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
3136 if (currentrow<0) continue;
3137 if (lastrow<0) lastrow=currentrow;
3138 if (currentrow==lastrow){
3139 if ( currentIndex>=maxhits){
3141 xxx.ResizeTo(4*maxhits);
3143 xxx(currentIndex*4)=x[0];
3144 xxx(currentIndex*4+1)=x[1];
3145 xxx(currentIndex*4+2)=x[2];
3146 xxx(currentIndex*4+3)=tpcHit->fQ;
3150 if (currentIndex>2){
3162 for (Int_t index=0;index<currentIndex;index++){
3164 x=x2=x3=x4=xxx(index*4);
3172 sumy+=xxx(index*4+1);
3173 sumxy+=xxx(index*4+1)*x;
3174 sumx2y+=xxx(index*4+1)*x2;
3175 sumz+=xxx(index*4+2);
3176 sumxz+=xxx(index*4+2)*x;
3177 sumx2z+=xxx(index*4+2)*x2;
3178 sumq+=xxx(index*4+3);
3180 Float_t centralPad = (fTPCParam->GetNPads(sector,lastrow)-1)/2;
3181 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
3182 sumx2*(sumx*sumx3-sumx2*sumx2);
3184 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
3185 sumx2*(sumxy*sumx3-sumx2y*sumx2);
3186 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
3187 sumx2*(sumxz*sumx3-sumx2z*sumx2);
3189 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
3190 sumx2*(sumx*sumx2y-sumx2*sumxy);
3191 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
3192 sumx2*(sumx*sumx2z-sumx2*sumxz);
3194 Float_t y=detay/det+centralPad;
3195 Float_t z=detaz/det;
3196 Float_t by=detby/det; //y angle
3197 Float_t bz=detbz/det; //z angle
3198 sumy/=Float_t(currentIndex);
3199 sumz/=Float_t(currentIndex);
3201 AliComplexCluster cl;
3207 cl.fTracks[0]=ipart;
3209 AliTPCClustersRow * row = (fClustersArray->GetRow(sector,lastrow));
3210 if (row!=0) row->InsertCluster(&cl);
3213 } //end of calculating cluster for given row
3215 } // end of loop over hits
3219 //_______________________________________________________________________________
3220 void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
3222 // produces rec points from digits and writes them on the root file
3223 // AliTPCclusters.root
3225 TDirectory *cwd = gDirectory;
3228 AliTPCParamSR *dig=(AliTPCParamSR *)gDirectory->Get("75x40_100x60");
3230 printf("You are running 2 pad-length geom hits with 3 pad-length geom digits\n");
3232 dig = new AliTPCParamSR();
3236 dig=(AliTPCParamSR *)gDirectory->Get("75x40_100x60_150x60");
3239 printf("No TPC parameters found\n");
3244 cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl;
3246 if(!gSystem->Getenv("CONFIG_FILE")){
3247 out=TFile::Open("AliTPCclusters.root","recreate");
3253 tmp1=gSystem->Getenv("CONFIG_FILE_PREFIX");
3254 tmp2=gSystem->Getenv("CONFIG_OUTDIR");
3255 sprintf(tmp3,"%s%s/AliTPCclusters.root",tmp1,tmp2);
3256 out=TFile::Open(tmp3,"recreate");
3260 cout<<"AliTPC::Digits2Reco - determination of rec points begins"<<endl;
3263 for(Int_t iev=firstevent;iev<lastevent+1;iev++){
3265 printf("Processing event %d\n",iev);
3266 Digits2Clusters(out,iev);
3268 cout<<"AliTPC::Digits2Reco - determination of rec points ended"<<endl;