1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Time Projection Chamber //
21 // This class contains the basic functions for the Time Projection Chamber //
22 // detector. Functions specific to one particular geometry are //
23 // contained in the derived classes //
27 <img src="picts/AliTPCClass.gif">
32 ///////////////////////////////////////////////////////////////////////////////
36 #include <Riostream.h>
40 #include <TGeometry.h>
41 #include <TInterpreter.h>
45 #include <TObjectTable.h>
46 #include <TParticle.h>
52 #include <TVirtualMC.h>
55 #include <TStopwatch.h>
57 #include "AliArrayBranch.h"
58 #include "AliDigits.h"
60 #include "AliPoints.h"
62 #include "AliRunLoader.h"
63 #include "AliSimDigits.h"
66 #include "AliTPCDigitsArray.h"
67 #include "AliTPCLoader.h"
68 #include "AliTPCPRF2D.h"
69 #include "AliTPCParamSR.h"
70 #include "AliTPCRF1D.h"
71 #include "AliTPCTrackHits.h"
72 #include "AliTPCTrackHitsV2.h"
73 #include "AliTrackReference.h"
75 #include "AliTPCDigitizer.h"
76 #include "AliTPCBuffer.h"
77 #include "AliTPCDDLRawData.h"
82 //_____________________________________________________________________________
83 // helper class for fast matrix and vector manipulation - no range checking
84 // origin - Marian Ivanov
86 class AliTPCFastMatrix : public TMatrix {
88 AliTPCFastMatrix(Int_t rowlwb, Int_t rowupb, Int_t collwb, Int_t colupb);
89 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
90 Float_t & UncheckedAt(Int_t rown, Int_t coln) const {return fElements[(rown-fRowLwb)*fNcols+(coln-fColLwb)];} //fast acces
91 Float_t UncheckedAtFast(Int_t rown, Int_t coln) const {return fElements[(rown-fRowLwb)*fNcols+(coln-fColLwb)];} //fast acces
93 Float_t & UncheckedAt(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
94 Float_t UncheckedAtFast(Int_t rown, Int_t coln) const {return (fIndex[coln])[rown];} //fast acces
98 AliTPCFastMatrix::AliTPCFastMatrix(Int_t rowlwb, Int_t rowupb, Int_t collwb, Int_t colupb):
99 TMatrix(rowlwb, rowupb,collwb,colupb)
102 //_____________________________________________________________________________
106 // Default constructor
116 fHitType = 2; //default CONTAINERS - based on ROOT structure
123 //_____________________________________________________________________________
124 AliTPC::AliTPC(const char *name, const char *title)
125 : AliDetector(name,title)
128 // Standard constructor
132 // Initialise arrays of hits and digits
133 fHits = new TClonesArray("AliTPChit", 176);
134 gAlice->GetMCApp()->AddHitList(fHits);
138 fTrackHits = new AliTPCTrackHitsV2;
139 fTrackHits->SetHitPrecision(0.002);
140 fTrackHits->SetStepPrecision(0.003);
141 fTrackHits->SetMaxDistance(100);
143 fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
144 fTrackHitsOld->SetHitPrecision(0.002);
145 fTrackHitsOld->SetStepPrecision(0.003);
146 fTrackHitsOld->SetMaxDistance(100);
153 // Initialise counters
159 // Initialise color attributes
160 SetMarkerColor(kYellow);
163 // Set TPC parameters
167 if (!strcmp(title,"Default")) {
168 fTPCParam = new AliTPCParamSR;
170 cerr<<"AliTPC warning: in Config.C you must set non-default parameters\n";
176 //_____________________________________________________________________________
177 AliTPC::AliTPC(const AliTPC& t):AliDetector(t){
179 // dummy copy constructor
192 delete fTrackHits; //MI 15.09.2000
193 delete fTrackHitsOld; //MI 10.12.2001
194 if (fNoiseTable) delete [] fNoiseTable;
198 //_____________________________________________________________________________
199 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
202 // Add a hit to the list
204 // TClonesArray &lhits = *fHits;
205 // new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
207 TClonesArray &lhits = *fHits;
208 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
211 AddHit2(track,vol,hits);
214 //_____________________________________________________________________________
215 void AliTPC::BuildGeometry()
219 // Build TPC ROOT TNode geometry for the event display
224 const int kColorTPC=19;
225 char name[5], title[25];
226 const Double_t kDegrad=TMath::Pi()/180;
227 const Double_t kRaddeg=180./TMath::Pi();
230 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
231 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
233 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
234 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
236 Int_t nLo = fTPCParam->GetNInnerSector()/2;
237 Int_t nHi = fTPCParam->GetNOuterSector()/2;
239 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
240 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
241 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
242 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
245 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
246 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
252 // Get ALICE top node
255 nTop=gAlice->GetGeometry()->GetNode("alice");
259 rl = fTPCParam->GetInnerRadiusLow();
260 ru = fTPCParam->GetInnerRadiusUp();
264 sprintf(name,"LS%2.2d",i);
266 sprintf(title,"TPC low sector %3d",i);
269 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
270 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
271 tubs->SetNumberOfDivisions(1);
273 nNode = new TNode(name,title,name,0,0,0,"");
274 nNode->SetLineColor(kColorTPC);
280 rl = fTPCParam->GetOuterRadiusLow();
281 ru = fTPCParam->GetOuterRadiusUp();
284 sprintf(name,"US%2.2d",i);
286 sprintf(title,"TPC upper sector %d",i);
288 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
289 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
290 tubs->SetNumberOfDivisions(1);
292 nNode = new TNode(name,title,name,0,0,0,"");
293 nNode->SetLineColor(kColorTPC);
299 //_____________________________________________________________________________
300 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t ) const
303 // Calculate distance from TPC to mouse on the display
310 //_____________________________________________________________________________
311 void AliTPC::CreateMaterials()
313 //-----------------------------------------------
314 // Create Materials for for TPC simulations
315 //-----------------------------------------------
317 //-----------------------------------------------------------------
318 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
319 //-----------------------------------------------------------------
321 Int_t iSXFLD=gAlice->Field()->Integ();
322 Float_t sXMGMX=gAlice->Field()->Max();
324 Float_t amat[5]; // atomic numbers
325 Float_t zmat[5]; // z
326 Float_t wmat[5]; // proportions
332 //***************** Gases *************************
334 //-------------------------------------------------
336 //-------------------------------------------------
347 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
357 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
360 //--------------------------------------------------------------
362 //--------------------------------------------------------------
379 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
381 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
396 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
398 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
414 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
416 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
418 //----------------------------------------------------------------
419 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
420 //----------------------------------------------------------------
426 Float_t rho,absl,x0,buf[1];
430 for(nc = 0;nc<fNoComp;nc++)
433 // retrive material constants
435 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,x0,absl,buf,nbuf);
440 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
442 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
443 density += fMixtProp[nc]*rho; // density of the mixture
447 // mixture proportions by weight!
449 for(nc = 0;nc<fNoComp;nc++)
452 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
454 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
455 apure[nnc] : amol[nnc])/am;
459 // Drift gases 1 - nonsensitive, 2 - sensitive
461 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
462 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
471 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
474 //----------------------------------------------------------------------
476 //----------------------------------------------------------------------
498 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
520 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
538 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
556 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
558 // SiO2 - used later for the glass fiber
570 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
579 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
588 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
597 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
615 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
634 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
636 // Epoxy - C14 H20 O3
653 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
661 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
665 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,x0,absl,buf,nbuf);
669 wmat[0]=0.644; // by weight!
672 density=0.5*(1.25+2.265);
674 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
678 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,x0,absl,buf,nbuf);
680 wmat[0]=0.725; // by weight!
685 AliMixture(39,"G10",amat,zmat,density,2,wmat);
690 //----------------------------------------------------------
691 // tracking media for gases
692 //----------------------------------------------------------
694 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
695 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
696 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
697 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
699 //-----------------------------------------------------------
700 // tracking media for solids
701 //-----------------------------------------------------------
703 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
704 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
705 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
706 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
707 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
708 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
709 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
710 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
711 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
712 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
713 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
714 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
718 void AliTPC::GenerNoise(Int_t tablesize)
721 //Generate table with noise
728 if (fNoiseTable) delete[] fNoiseTable;
729 fNoiseTable = new Float_t[tablesize];
730 fNoiseDepth = tablesize;
731 fCurrentNoise =0; //!index of the noise in the noise table
733 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
734 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
737 Float_t AliTPC::GetNoise()
739 // get noise from table
740 // if ((fCurrentNoise%10)==0)
741 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
742 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
743 return fNoiseTable[fCurrentNoise++];
744 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
748 Bool_t AliTPC::IsSectorActive(Int_t sec) const
751 // check if the sector is active
752 if (!fActiveSectors) return kTRUE;
753 else return fActiveSectors[sec];
756 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
758 // activate interesting sectors
759 SetTreeAddress();//just for security
760 if (fActiveSectors) delete [] fActiveSectors;
761 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
762 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
763 for (Int_t i=0;i<n;i++)
764 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
768 void AliTPC::SetActiveSectors(Int_t flag)
771 // activate sectors which were hitted by tracks
773 SetTreeAddress();//just for security
774 if (fHitType==0) return; // if Clones hit - not short volume ID information
775 if (fActiveSectors) delete [] fActiveSectors;
776 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
778 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
781 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
785 Fatal("SetActiveSectors","Can not find TreeH in folder");
788 if (fHitType>1) branch = TreeH()->GetBranch("TPC2");
789 else branch = TreeH()->GetBranch("TPC");
790 Stat_t ntracks = TreeH()->GetEntries();
791 // loop over all hits
792 if (GetDebug()) cout<<"\nAliTPC::SetActiveSectors(): Got "<<ntracks<<" tracks\n";
794 for(Int_t track=0;track<ntracks;track++)
798 if (fTrackHits && fHitType&4) {
799 TBranch * br1 = TreeH()->GetBranch("fVolumes");
800 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
801 br1->GetEvent(track);
802 br2->GetEvent(track);
803 Int_t *volumes = fTrackHits->GetVolumes();
804 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
805 fActiveSectors[volumes[j]]=kTRUE;
809 if (fTrackHitsOld && fHitType&2) {
810 TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
812 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
813 for (UInt_t j=0;j<ar->GetSize();j++){
814 fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
823 //_____________________________________________________________________________
824 void AliTPC::Digits2Raw()
826 // convert digits of the current event to raw data
828 static const Int_t kThreshold = 0;
829 static const Bool_t kCompress = kTRUE;
831 fLoader->LoadDigits();
832 TTree* digits = fLoader->TreeD();
834 Error("Digits2Raw", "no digits tree");
839 AliSimDigits* digrow = &digarr;
840 digits->GetBranch("Segment")->SetAddress(&digrow);
842 const char* fileName = "AliTPCDDL.dat";
843 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
847 // 2: txt files with digits
848 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
849 //it is highly suggested to use this mode only for debugging digits files
850 //reasonably small, because otherwise the size of the txt files can reach
851 //quickly several MB wasting time and disk space.
852 buffer->SetVerbose(0);
854 Int_t nEntries = Int_t(digits->GetEntries());
855 Int_t previousSector = -1;
857 for (Int_t i = 0; i < nEntries; i++) {
860 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
861 if(previousSector != sector) {
863 previousSector = sector;
866 if (sector < 36) { //inner sector [0;35]
868 //the whole row is written into the output file
869 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
870 sector, subSector, row);
872 //only the pads in the range [37;48] are written into the output file
873 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
874 sector, subSector, row);
876 //only the pads outside the range [37;48] are written into the output file
877 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
878 sector, subSector, row);
881 } else { //outer sector [36;71]
882 if (row == 54) subSector = 2;
883 if ((row != 27) && (row != 76)) {
884 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
885 sector, subSector, row);
886 } else if (row == 27) {
887 //only the pads outside the range [43;46] are written into the output file
888 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
889 sector, subSector, row);
891 //only the pads in the range [43;46] are written into the output file
892 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
893 sector, subSector, row);
894 } else if (row == 76) {
895 //only the pads outside the range [33;88] are written into the output file
896 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
897 sector, subSector, row);
899 //only the pads in the range [33;88] are written into the output file
900 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
901 sector, subSector, row);
907 fLoader->UnloadDigits();
909 AliTPCDDLRawData rawWriter;
910 rawWriter.SetVerbose(0);
912 rawWriter.RawData(fileName);
913 gSystem->Unlink(fileName);
916 Info("Digits2Raw", "compressing raw data");
917 rawWriter.RawDataCompDecompress(kTRUE);
918 gSystem->Unlink("Statistics");
924 //______________________________________________________________________
925 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
927 return new AliTPCDigitizer(manager);
930 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
932 //create digits from summable digits
933 GenerNoise(500000); //create teble with noise
935 //conect tree with sSDigits
936 TTree *t = fLoader->TreeS();
940 fLoader->LoadSDigits("READ");
941 t = fLoader->TreeS();
944 Error("SDigits2Digits2","Can not get input TreeS");
949 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
951 AliSimDigits digarr, *dummy=&digarr;
952 TBranch* sdb = t->GetBranch("Segment");
955 Error("SDigits2Digits2","Can not find branch with segments in TreeS.");
959 sdb->SetAddress(&dummy);
961 Stat_t nentries = t->GetEntries();
963 // set zero suppression
965 fTPCParam->SetZeroSup(2);
967 // get zero suppression
969 Int_t zerosup = fTPCParam->GetZeroSup();
971 //make tree with digits
973 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
974 arr->SetClass("AliSimDigits");
975 arr->Setup(fTPCParam);
976 arr->MakeTree(fLoader->TreeD());
978 AliTPCParam * par = fTPCParam;
980 //Loop over segments of the TPC
982 for (Int_t n=0; n<nentries; n++) {
985 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
986 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
989 if (!IsSectorActive(sec))
991 // cout<<n<<" NOT Active \n";
996 // cout<<n<<" Active \n";
998 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
999 Int_t nrows = digrow->GetNRows();
1000 Int_t ncols = digrow->GetNCols();
1002 digrow->ExpandBuffer();
1003 digarr.ExpandBuffer();
1004 digrow->ExpandTrackBuffer();
1005 digarr.ExpandTrackBuffer();
1008 Short_t * pamp0 = digarr.GetDigits();
1009 Int_t * ptracks0 = digarr.GetTracks();
1010 Short_t * pamp1 = digrow->GetDigits();
1011 Int_t * ptracks1 = digrow->GetTracks();
1012 Int_t nelems =nrows*ncols;
1013 Int_t saturation = fTPCParam->GetADCSat();
1014 //use internal structure of the AliDigits - for speed reason
1015 //if you cahnge implementation
1016 //of the Alidigits - it must be rewriten -
1017 for (Int_t i= 0; i<nelems; i++){
1018 // Float_t q = *pamp0;
1019 //q/=16.; //conversion faktor
1020 //Float_t noise= GetNoise();
1022 //q= TMath::Nint(q);
1023 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1025 if (q>saturation) q=saturation;
1027 //if (ptracks0[0]==0)
1030 ptracks1[0]=ptracks0[0];
1031 ptracks1[nelems]=ptracks0[nelems];
1032 ptracks1[2*nelems]=ptracks0[2*nelems];
1040 arr->StoreRow(sec,row);
1041 arr->ClearRow(sec,row);
1042 // cerr<<sec<<"\t"<<row<<"\n";
1047 fLoader->WriteDigits("OVERWRITE");
1051 //__________________________________________________________________
1052 void AliTPC::SetDefaults(){
1054 // setting the defaults
1057 // cerr<<"Setting default parameters...\n";
1059 // Set response functions
1062 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1064 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1066 printf("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...\n");
1068 param = new AliTPCParamSR();
1071 param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1074 printf("No TPC parameters found\n");
1079 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1080 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1081 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1082 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1083 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1084 rf->SetOffset(3*param->GetZSigma());
1087 TDirectory *savedir=gDirectory;
1088 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1090 cerr<<"Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !\n" ;
1095 prfinner->Read("prf_07504_Gati_056068_d02");
1096 //PH Set different names
1097 s=prfinner->GetGRF()->GetName();
1099 prfinner->GetGRF()->SetName(s.Data());
1101 prfouter1->Read("prf_10006_Gati_047051_d03");
1102 s=prfouter1->GetGRF()->GetName();
1104 prfouter1->GetGRF()->SetName(s.Data());
1106 prfouter2->Read("prf_15006_Gati_047051_d03");
1107 s=prfouter2->GetGRF()->GetName();
1109 prfouter2->GetGRF()->SetName(s.Data());
1114 param->SetInnerPRF(prfinner);
1115 param->SetOuter1PRF(prfouter1);
1116 param->SetOuter2PRF(prfouter2);
1117 param->SetTimeRF(rf);
1127 //__________________________________________________________________
1128 void AliTPC::Hits2Digits()
1131 // creates digits from hits
1134 fLoader->LoadHits("read");
1135 fLoader->LoadDigits("recreate");
1136 AliRunLoader* runLoader = fLoader->GetRunLoader();
1138 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1139 runLoader->GetEvent(iEvent);
1141 Hits2Digits(iEvent);
1144 fLoader->UnloadHits();
1145 fLoader->UnloadDigits();
1147 //__________________________________________________________________
1148 void AliTPC::Hits2Digits(Int_t eventnumber)
1150 //----------------------------------------------------
1151 // Loop over all sectors for a single event
1152 //----------------------------------------------------
1153 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1154 rl->GetEvent(eventnumber);
1155 if (fLoader->TreeH() == 0x0)
1157 if(fLoader->LoadHits())
1159 Error("Hits2Digits","Can not load hits.");
1164 if (fLoader->TreeD() == 0x0 )
1166 fLoader->MakeTree("D");
1167 if (fLoader->TreeD() == 0x0 )
1169 Error("Hits2Digits","Can not get TreeD");
1174 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1175 GenerNoise(500000); //create teble with noise
1177 //setup TPCDigitsArray
1179 if(GetDigitsArray()) delete GetDigitsArray();
1181 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1182 arr->SetClass("AliSimDigits");
1183 arr->Setup(fTPCParam);
1185 arr->MakeTree(fLoader->TreeD());
1186 SetDigitsArray(arr);
1188 fDigitsSwitch=0; // standard digits
1190 // cerr<<"Digitizing TPC -- normal digits...\n";
1192 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1193 if (IsSectorActive(isec))
1195 if (fDebug) Info("Hits2Digits","Sector %d is active.",isec);
1196 Hits2DigitsSector(isec);
1200 if (fDebug) Info("Hits2Digits","Sector %d is NOT active.",isec);
1203 fLoader->WriteDigits("OVERWRITE");
1205 //this line prevents the crash in the similar one
1206 //on the beginning of this method
1207 //destructor attempts to reset the tree, which is deleted by the loader
1208 //need to be redesign
1209 if(GetDigitsArray()) delete GetDigitsArray();
1210 SetDigitsArray(0x0);
1214 //__________________________________________________________________
1215 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1218 //-----------------------------------------------------------
1219 // summable digits - 16 bit "ADC", no noise, no saturation
1220 //-----------------------------------------------------------
1222 //----------------------------------------------------
1223 // Loop over all sectors for a single event
1224 //----------------------------------------------------
1225 // AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::fgkRunLoaderName);
1227 AliRunLoader* rl = fLoader->GetRunLoader();
1229 rl->GetEvent(eventnumber);
1230 if (fLoader->TreeH() == 0x0)
1232 if(fLoader->LoadHits())
1234 Error("Hits2Digits","Can not load hits.");
1241 if (fLoader->TreeS() == 0x0 )
1243 fLoader->MakeTree("S");
1246 if(fDefaults == 0) SetDefaults();
1248 GenerNoise(500000); //create table with noise
1249 //setup TPCDigitsArray
1251 if(GetDigitsArray()) delete GetDigitsArray();
1254 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1255 arr->SetClass("AliSimDigits");
1256 arr->Setup(fTPCParam);
1257 arr->MakeTree(fLoader->TreeS());
1259 SetDigitsArray(arr);
1261 // cerr<<"Digitizing TPC -- summable digits...\n";
1263 fDigitsSwitch=1; // summable digits
1265 // set zero suppression to "0"
1267 fTPCParam->SetZeroSup(0);
1269 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1270 if (IsSectorActive(isec))
1272 // cout<<"Sector "<<isec<<" is active\n";
1273 Hits2DigitsSector(isec);
1276 fLoader->WriteSDigits("OVERWRITE");
1278 //this line prevents the crash in the similar one
1279 //on the beginning of this method
1280 //destructor attempts to reset the tree, which is deleted by the loader
1281 //need to be redesign
1282 if(GetDigitsArray()) delete GetDigitsArray();
1283 SetDigitsArray(0x0);
1285 //__________________________________________________________________
1287 void AliTPC::Hits2SDigits()
1290 //-----------------------------------------------------------
1291 // summable digits - 16 bit "ADC", no noise, no saturation
1292 //-----------------------------------------------------------
1294 fLoader->LoadHits("read");
1295 fLoader->LoadSDigits("recreate");
1296 AliRunLoader* runLoader = fLoader->GetRunLoader();
1298 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1299 runLoader->GetEvent(iEvent);
1302 Hits2SDigits2(iEvent);
1305 fLoader->UnloadHits();
1306 fLoader->UnloadSDigits();
1308 //_____________________________________________________________________________
1310 void AliTPC::Hits2DigitsSector(Int_t isec)
1312 //-------------------------------------------------------------------
1313 // TPC conversion from hits to digits.
1314 //-------------------------------------------------------------------
1316 //-----------------------------------------------------------------
1317 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1318 //-----------------------------------------------------------------
1320 //-------------------------------------------------------
1321 // Get the access to the track hits
1322 //-------------------------------------------------------
1324 // check if the parameters are set - important if one calls this method
1325 // directly, not from the Hits2Digits
1327 if(fDefaults == 0) SetDefaults();
1329 TTree *tH = TreeH(); // pointer to the hits tree
1332 Fatal("Hits2DigitsSector","Can not find TreeH in folder");
1336 Stat_t ntracks = tH->GetEntries();
1340 //-------------------------------------------
1341 // Only if there are any tracks...
1342 //-------------------------------------------
1346 //printf("*** Processing sector number %d ***\n",isec);
1348 Int_t nrows =fTPCParam->GetNRow(isec);
1350 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1352 MakeSector(isec,nrows,tH,ntracks,row);
1354 //--------------------------------------------------------
1355 // Digitize this sector, row by row
1356 // row[i] is the pointer to the TObjArray of AliTPCFastVectors,
1357 // each one containing electrons accepted on this
1358 // row, assigned into tracks
1359 //--------------------------------------------------------
1363 if (fDigitsArray->GetTree()==0)
1365 Fatal("Hits2DigitsSector","Tree not set in fDigitsArray");
1368 for (i=0;i<nrows;i++){
1370 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1372 DigitizeRow(i,isec,row);
1374 fDigitsArray->StoreRow(isec,i);
1376 Int_t ndig = dig->GetDigitSize();
1379 printf("*** Sector, row, compressed digits %d %d %d ***\n",isec,i,ndig);
1381 fDigitsArray->ClearRow(isec,i);
1384 } // end of the sector digitization
1386 for(i=0;i<nrows+2;i++){
1391 delete [] row; // delete the array of pointers to TObjArray-s
1395 } // end of Hits2DigitsSector
1398 //_____________________________________________________________________________
1399 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1401 //-----------------------------------------------------------
1402 // Single row digitization, coupling from the neighbouring
1403 // rows taken into account
1404 //-----------------------------------------------------------
1406 //-----------------------------------------------------------------
1407 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1408 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1409 //-----------------------------------------------------------------
1412 Float_t zerosup = fTPCParam->GetZeroSup();
1413 // Int_t nrows =fTPCParam->GetNRow(isec);
1414 fCurrentIndex[1]= isec;
1417 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1418 Int_t nofTbins = fTPCParam->GetMaxTBin();
1419 Int_t indexRange[4];
1421 // Integrated signal for this row
1422 // and a single track signal
1425 AliTPCFastMatrix *m1 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // integrated
1426 AliTPCFastMatrix *m2 = new AliTPCFastMatrix(0,nofPads,0,nofTbins); // single
1428 AliTPCFastMatrix &total = *m1;
1430 // Array of pointers to the label-signal list
1432 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1433 Float_t **pList = new Float_t* [nofDigits];
1437 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1441 //Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
1442 //Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
1445 for (Int_t row= row1;row<=row2;row++){
1446 Int_t nTracks= rows[row]->GetEntries();
1447 for (i1=0;i1<nTracks;i1++){
1448 fCurrentIndex[2]= row;
1449 fCurrentIndex[3]=irow+1;
1451 m2->Zero(); // clear single track signal matrix
1452 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1453 GetList(trackLabel,nofPads,m2,indexRange,pList);
1455 else GetSignal(rows[row],i1,0,m1,indexRange);
1461 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1463 Float_t fzerosup = zerosup+0.5;
1464 for(Int_t it=0;it<nofTbins;it++){
1465 Float_t *pq = &(total.UncheckedAt(0,it));
1466 for(Int_t ip=0;ip<nofPads;ip++){
1470 if(fDigitsSwitch == 0){
1472 if(q <=fzerosup) continue; // do not fill zeros
1474 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1479 if(q <= 0.) continue; // do not fill zeros
1480 if(q>2000.) q=2000.;
1486 // "real" signal or electronic noise (list = -1)?
1489 for(Int_t j1=0;j1<3;j1++){
1490 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1495 <A NAME="AliDigits"></A>
1496 using of AliDigits object
1499 dig->SetDigitFast((Short_t)q,it,ip);
1500 if (fDigitsArray->IsSimulated())
1502 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1503 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1504 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1508 } // end of loop over time buckets
1509 } // end of lop over pads
1512 // This row has been digitized, delete nonused stuff
1515 for(lp=0;lp<nofDigits;lp++){
1516 if(pList[lp]) delete [] pList[lp];
1525 } // end of DigitizeRow
1527 //_____________________________________________________________________________
1529 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1530 AliTPCFastMatrix *m1, AliTPCFastMatrix *m2,Int_t *indexRange)
1533 //---------------------------------------------------------------
1534 // Calculates 2-D signal (pad,time) for a single track,
1535 // returns a pointer to the signal matrix and the track label
1536 // No digitization is performed at this level!!!
1537 //---------------------------------------------------------------
1539 //-----------------------------------------------------------------
1540 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1541 // Modified: Marian Ivanov
1542 //-----------------------------------------------------------------
1544 AliTPCFastVector *tv;
1546 tv = (AliTPCFastVector*)p1->At(ntr); // pointer to a track
1547 AliTPCFastVector &v = *tv;
1549 Float_t label = v(0);
1550 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1)-1)/2;
1552 Int_t nElectrons = (tv->GetNrows()-1)/4;
1553 indexRange[0]=9999; // min pad
1554 indexRange[1]=-1; // max pad
1555 indexRange[2]=9999; //min time
1556 indexRange[3]=-1; // max time
1558 AliTPCFastMatrix &signal = *m1;
1559 AliTPCFastMatrix &total = *m2;
1561 // Loop over all electrons
1563 for(Int_t nel=0; nel<nElectrons; nel++){
1565 Float_t aval = v(idx+4);
1566 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1567 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1568 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1570 Int_t *index = fTPCParam->GetResBin(0);
1571 Float_t *weight = & (fTPCParam->GetResWeight(0));
1573 if (n>0) for (Int_t i =0; i<n; i++){
1574 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1577 Int_t time=index[2];
1578 Float_t qweight = *(weight)*eltoadcfac;
1580 if (m1!=0) signal.UncheckedAt(pad,time)+=qweight;
1581 total.UncheckedAt(pad,time)+=qweight;
1582 if (indexRange[0]>pad) indexRange[0]=pad;
1583 if (indexRange[1]<pad) indexRange[1]=pad;
1584 if (indexRange[2]>time) indexRange[2]=time;
1585 if (indexRange[3]<time) indexRange[3]=time;
1592 } // end of loop over electrons
1594 return label; // returns track label when finished
1597 //_____________________________________________________________________________
1598 void AliTPC::GetList(Float_t label,Int_t np,AliTPCFastMatrix *m,
1599 Int_t *indexRange, Float_t **pList)
1601 //----------------------------------------------------------------------
1602 // Updates the list of tracks contributing to digits for a given row
1603 //----------------------------------------------------------------------
1605 //-----------------------------------------------------------------
1606 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1607 //-----------------------------------------------------------------
1609 AliTPCFastMatrix &signal = *m;
1611 // lop over nonzero digits
1613 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1614 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1617 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1619 if(signal(ip,it)<0.5) continue;
1622 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1624 if(!pList[globalIndex]){
1627 // Create new list (6 elements - 3 signals and 3 labels),
1630 pList[globalIndex] = new Float_t [6];
1634 *pList[globalIndex] = -1.;
1635 *(pList[globalIndex]+1) = -1.;
1636 *(pList[globalIndex]+2) = -1.;
1637 *(pList[globalIndex]+3) = -1.;
1638 *(pList[globalIndex]+4) = -1.;
1639 *(pList[globalIndex]+5) = -1.;
1642 *pList[globalIndex] = label;
1643 *(pList[globalIndex]+3) = signal(ip,it);
1647 // check the signal magnitude
1649 Float_t highest = *(pList[globalIndex]+3);
1650 Float_t middle = *(pList[globalIndex]+4);
1651 Float_t lowest = *(pList[globalIndex]+5);
1654 // compare the new signal with already existing list
1657 if(signal(ip,it)<lowest) continue; // neglect this track
1661 if (signal(ip,it)>highest){
1662 *(pList[globalIndex]+5) = middle;
1663 *(pList[globalIndex]+4) = highest;
1664 *(pList[globalIndex]+3) = signal(ip,it);
1666 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1667 *(pList[globalIndex]+1) = *pList[globalIndex];
1668 *pList[globalIndex] = label;
1670 else if (signal(ip,it)>middle){
1671 *(pList[globalIndex]+5) = middle;
1672 *(pList[globalIndex]+4) = signal(ip,it);
1674 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1675 *(pList[globalIndex]+1) = label;
1678 *(pList[globalIndex]+5) = signal(ip,it);
1679 *(pList[globalIndex]+2) = label;
1683 } // end of loop over pads
1684 } // end of loop over time bins
1689 //___________________________________________________________________
1690 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1691 Stat_t ntracks,TObjArray **row)
1694 //-----------------------------------------------------------------
1695 // Prepares the sector digitization, creates the vectors of
1696 // tracks for each row of this sector. The track vector
1697 // contains the track label and the position of electrons.
1698 //-----------------------------------------------------------------
1700 //-----------------------------------------------------------------
1701 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1702 //-----------------------------------------------------------------
1704 Float_t gasgain = fTPCParam->GetGasGain();
1708 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1711 if (fHitType>1) branch = TH->GetBranch("TPC2");
1712 else branch = TH->GetBranch("TPC");
1715 //----------------------------------------------
1716 // Create TObjArray-s, one for each row,
1717 // each TObjArray will store the AliTPCFastVectors
1718 // of electrons, one AliTPCFastVectors per each track.
1719 //----------------------------------------------
1721 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
1722 AliTPCFastVector **tracks = new AliTPCFastVector* [nrows+2]; //pointers to the track vectors
1724 for(i=0; i<nrows+2; i++){
1725 row[i] = new TObjArray;
1732 //--------------------------------------------------------------------
1733 // Loop over tracks, the "track" contains the full history
1734 //--------------------------------------------------------------------
1736 Int_t previousTrack,currentTrack;
1737 previousTrack = -1; // nothing to store so far!
1739 for(Int_t track=0;track<ntracks;track++){
1740 Bool_t isInSector=kTRUE;
1742 isInSector = TrackInVolume(isec,track);
1743 if (!isInSector) continue;
1745 branch->GetEntry(track); // get next track
1749 tpcHit = (AliTPChit*)FirstHit(-1);
1751 //--------------------------------------------------------------
1753 //--------------------------------------------------------------
1758 Int_t sector=tpcHit->fSector; // sector number
1760 tpcHit = (AliTPChit*) NextHit();
1764 currentTrack = tpcHit->Track(); // track number
1767 if(currentTrack != previousTrack){
1769 // store already filled fTrack
1771 for(i=0;i<nrows+2;i++){
1772 if(previousTrack != -1){
1773 if(nofElectrons[i]>0){
1774 AliTPCFastVector &v = *tracks[i];
1775 v(0) = previousTrack;
1776 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1777 row[i]->Add(tracks[i]);
1780 delete tracks[i]; // delete empty AliTPCFastVector
1786 tracks[i] = new AliTPCFastVector(481); // AliTPCFastVectors for the next fTrack
1788 } // end of loop over rows
1790 previousTrack=currentTrack; // update track label
1793 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1795 //---------------------------------------------------
1796 // Calculate the electron attachment probability
1797 //---------------------------------------------------
1800 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
1801 /fTPCParam->GetDriftV();
1803 Float_t attProb = fTPCParam->GetAttCoef()*
1804 fTPCParam->GetOxyCont()*time; // fraction!
1806 //-----------------------------------------------
1807 // Loop over electrons
1808 //-----------------------------------------------
1811 for(Int_t nel=0;nel<qI;nel++){
1812 // skip if electron lost due to the attachment
1813 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1818 // protection for the nonphysical avalanche size (10**6 maximum)
1820 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1821 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
1824 TransportElectron(xyz,index);
1826 fTPCParam->GetPadRow(xyz,index);
1827 // row 0 - cross talk from the innermost row
1828 // row fNRow+1 cross talk from the outermost row
1829 rowNumber = index[2]+1;
1830 //transform position to local digit coordinates
1831 //relative to nearest pad row
1832 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
1834 if (isec <fTPCParam->GetNInnerSector()) {
1835 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
1836 y1 = fTPCParam->GetYInner(rowNumber);
1839 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
1840 y1 = fTPCParam->GetYOuter(rowNumber);
1842 // gain inefficiency at the wires edges - linear
1845 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.));
1847 nofElectrons[rowNumber]++;
1848 //----------------------------------
1849 // Expand vector if necessary
1850 //----------------------------------
1851 if(nofElectrons[rowNumber]>120){
1852 Int_t range = tracks[rowNumber]->GetNrows();
1853 if((nofElectrons[rowNumber])>(range-1)/4){
1855 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
1859 AliTPCFastVector &v = *tracks[rowNumber];
1860 Int_t idx = 4*nofElectrons[rowNumber]-3;
1861 Real_t * position = &(((AliTPCFastVector&)v).UncheckedAt(idx)); //make code faster
1862 memcpy(position,xyz,4*sizeof(Float_t));
1864 } // end of loop over electrons
1866 tpcHit = (AliTPChit*)NextHit();
1868 } // end of loop over hits
1869 } // end of loop over tracks
1872 // store remaining track (the last one) if not empty
1875 for(i=0;i<nrows+2;i++){
1876 if(nofElectrons[i]>0){
1877 AliTPCFastVector &v = *tracks[i];
1878 v(0) = previousTrack;
1879 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1880 row[i]->Add(tracks[i]);
1889 delete [] nofElectrons;
1892 } // end of MakeSector
1895 //_____________________________________________________________________________
1899 // Initialise TPC detector after definition of geometry
1904 printf("\n%s: ",ClassName());
1905 for(i=0;i<35;i++) printf("*");
1906 printf(" TPC_INIT ");
1907 for(i=0;i<35;i++) printf("*");
1908 printf("\n%s: ",ClassName());
1910 for(i=0;i<80;i++) printf("*");
1915 //_____________________________________________________________________________
1916 void AliTPC::MakeBranch(Option_t* option)
1919 // Create Tree branches for the TPC.
1921 if(GetDebug()) Info("MakeBranch","");
1922 Int_t buffersize = 4000;
1923 char branchname[10];
1924 sprintf(branchname,"%s",GetName());
1926 const char *h = strstr(option,"H");
1928 if ( h && (fHitType<=1) && (fHits == 0x0)) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
1930 AliDetector::MakeBranch(option);
1932 const char *d = strstr(option,"D");
1934 if (fDigits && fLoader->TreeD() && d)
1936 MakeBranchInTree(gAlice->TreeD(), branchname, &fDigits, buffersize, 0);
1939 if (fHitType>1) MakeBranch2(option,0); // MI change 14.09.2000
1942 //_____________________________________________________________________________
1943 void AliTPC::ResetDigits()
1946 // Reset number of digits and the digits array for this detector
1949 if (fDigits) fDigits->Clear();
1952 //_____________________________________________________________________________
1953 void AliTPC::SetSecAL(Int_t sec)
1955 //---------------------------------------------------
1956 // Activate/deactivate selection for lower sectors
1957 //---------------------------------------------------
1959 //-----------------------------------------------------------------
1960 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1961 //-----------------------------------------------------------------
1965 //_____________________________________________________________________________
1966 void AliTPC::SetSecAU(Int_t sec)
1968 //----------------------------------------------------
1969 // Activate/deactivate selection for upper sectors
1970 //---------------------------------------------------
1972 //-----------------------------------------------------------------
1973 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1974 //-----------------------------------------------------------------
1978 //_____________________________________________________________________________
1979 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
1981 //----------------------------------------
1982 // Select active lower sectors
1983 //----------------------------------------
1985 //-----------------------------------------------------------------
1986 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1987 //-----------------------------------------------------------------
1997 //_____________________________________________________________________________
1998 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
1999 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
2000 Int_t s11 , Int_t s12)
2002 //--------------------------------
2003 // Select active upper sectors
2004 //--------------------------------
2006 //-----------------------------------------------------------------
2007 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2008 //-----------------------------------------------------------------
2024 //_____________________________________________________________________________
2025 void AliTPC::SetSens(Int_t sens)
2028 //-------------------------------------------------------------
2029 // Activates/deactivates the sensitive strips at the center of
2030 // the pad row -- this is for the space-point resolution calculations
2031 //-------------------------------------------------------------
2033 //-----------------------------------------------------------------
2034 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2035 //-----------------------------------------------------------------
2041 void AliTPC::SetSide(Float_t side=0.)
2043 // choice of the TPC side
2048 //____________________________________________________________________________
2049 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
2050 Float_t p2,Float_t p3)
2053 // gax mixture definition
2067 //_____________________________________________________________________________
2069 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2072 // electron transport taking into account:
2074 // 2.ExB at the wires
2075 // 3. nonisochronity
2077 // xyz and index must be already transformed to system 1
2080 fTPCParam->Transform1to2(xyz,index);
2083 Float_t driftl=xyz[2];
2084 if(driftl<0.01) driftl=0.01;
2085 driftl=TMath::Sqrt(driftl);
2086 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2087 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2088 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2089 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2090 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2094 if (fTPCParam->GetMWPCReadout()==kTRUE){
2095 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2096 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2098 //add nonisochronity (not implemented yet)
2103 //_____________________________________________________________________________
2104 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2108 // Creates a TPC hit object
2118 //________________________________________________________________________
2119 // Additional code because of the AliTPCTrackHitsV2
2121 void AliTPC::MakeBranch2(Option_t *option,const char */*file*/)
2124 // Create a new branch in the current Root Tree
2125 // The branch of fHits is automatically split
2126 // MI change 14.09.2000
2127 if(GetDebug()) Info("MakeBranch2","");
2128 if (fHitType<2) return;
2129 char branchname[10];
2130 sprintf(branchname,"%s2",GetName());
2132 // Get the pointer to the header
2133 const char *cH = strstr(option,"H");
2135 if (fTrackHits && TreeH() && cH && fHitType&4)
2137 if(GetDebug()) Info("MakeBranch2","Making branch for Type 4 Hits");
2138 TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2141 if (fTrackHitsOld && TreeH() && cH && fHitType&2)
2143 if(GetDebug()) Info("MakeBranch2","Making branch for Type 2 Hits");
2144 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2145 TreeH(),fBufferSize,99);
2146 TreeH()->GetListOfBranches()->Add(branch);
2150 void AliTPC::SetTreeAddress()
2152 //Sets tree address for hits
2155 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2156 AliDetector::SetTreeAddress();
2158 if (fHitType>1) SetTreeAddress2();
2161 void AliTPC::SetTreeAddress2()
2164 // Set branch address for the TrackHits Tree
2166 if(GetDebug()) Info("SetTreeAddress2","");
2169 char branchname[20];
2170 sprintf(branchname,"%s2",GetName());
2172 // Branch address for hit tree
2173 TTree *treeH = TreeH();
2174 if ((treeH)&&(fHitType&4)) {
2175 branch = treeH->GetBranch(branchname);
2178 branch->SetAddress(&fTrackHits);
2179 if (GetDebug()) Info("SetTreeAddress2","fHitType&4 Setting");
2182 if (GetDebug()) Info("SetTreeAddress2","fHitType&4 Failed (can not find branch)");
2185 if ((treeH)&&(fHitType&2)) {
2186 branch = treeH->GetBranch(branchname);
2189 branch->SetAddress(&fTrackHitsOld);
2190 if (GetDebug()) Info("SetTreeAddress2","fHitType&2 Setting");
2192 else if (GetDebug())
2193 Info("SetTreeAddress2","fHitType&2 Failed (can not find branch)");
2195 //set address to TREETR
2197 TTree *treeTR = TreeTR();
2198 if (treeTR && fTrackReferences) {
2199 branch = treeTR->GetBranch(GetName());
2200 if (branch) branch->SetAddress(&fTrackReferences);
2205 void AliTPC::FinishPrimary()
2207 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2208 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2212 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2215 // add hit to the list
2218 int primary = gAlice->GetMCApp()->GetPrimary(track);
2219 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2223 gAlice->GetMCApp()->FlagTrack(track);
2225 //AliTPChit *hit = (AliTPChit*)fHits->UncheckedAt(fNhits-1);
2226 //if (hit->fTrack!=rtrack)
2227 // cout<<"bad track number\n";
2228 if (fTrackHits && fHitType&4)
2229 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2230 hits[1],hits[2],(Int_t)hits[3]);
2231 if (fTrackHitsOld &&fHitType&2 )
2232 fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2233 hits[1],hits[2],(Int_t)hits[3]);
2237 void AliTPC::ResetHits()
2239 if (fHitType&1) AliDetector::ResetHits();
2240 if (fHitType>1) ResetHits2();
2243 void AliTPC::ResetHits2()
2247 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2248 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2252 AliHit* AliTPC::FirstHit(Int_t track)
2254 if (fHitType>1) return FirstHit2(track);
2255 return AliDetector::FirstHit(track);
2257 AliHit* AliTPC::NextHit()
2262 if (fHitType>1) return NextHit2();
2264 return AliDetector::NextHit();
2267 AliHit* AliTPC::FirstHit2(Int_t track)
2270 // Initialise the hit iterator
2271 // Return the address of the first hit for track
2272 // If track>=0 the track is read from disk
2273 // while if track<0 the first hit of the current
2274 // track is returned
2277 gAlice->ResetHits();
2278 TreeH()->GetEvent(track);
2281 if (fTrackHits && fHitType&4) {
2282 fTrackHits->First();
2283 return fTrackHits->GetHit();
2285 if (fTrackHitsOld && fHitType&2) {
2286 fTrackHitsOld->First();
2287 return fTrackHitsOld->GetHit();
2293 AliHit* AliTPC::NextHit2()
2296 //Return the next hit for the current track
2299 if (fTrackHitsOld && fHitType&2) {
2300 fTrackHitsOld->Next();
2301 return fTrackHitsOld->GetHit();
2305 return fTrackHits->GetHit();
2311 void AliTPC::LoadPoints(Int_t)
2315 /* if(fHitType==1) return AliDetector::LoadPoints(a);
2318 if(fHitType==1) AliDetector::LoadPoints(a);
2319 else LoadPoints2(a);
2326 void AliTPC::RemapTrackHitIDs(Int_t *map)
2331 if (!fTrackHits) return;
2333 if (fTrackHitsOld && fHitType&2){
2334 AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2335 for (UInt_t i=0;i<arr->GetSize();i++){
2336 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2337 info->fTrackID = map[info->fTrackID];
2340 if (fTrackHitsOld && fHitType&4){
2341 TClonesArray * arr = fTrackHits->GetArray();;
2342 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2343 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2344 info->fTrackID = map[info->fTrackID];
2349 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2351 //return bool information - is track in given volume
2352 //load only part of the track information
2353 //return true if current track is in volume
2356 if (fTrackHitsOld && fHitType&2) {
2357 TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
2358 br->GetEvent(track);
2359 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2360 for (UInt_t j=0;j<ar->GetSize();j++){
2361 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2365 if (fTrackHits && fHitType&4) {
2366 TBranch * br1 = TreeH()->GetBranch("fVolumes");
2367 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
2368 br2->GetEvent(track);
2369 br1->GetEvent(track);
2370 Int_t *volumes = fTrackHits->GetVolumes();
2371 Int_t nvolumes = fTrackHits->GetNVolumes();
2372 if (!volumes && nvolumes>0) {
2373 printf("Problematic track\t%d\t%d",track,nvolumes);
2376 for (Int_t j=0;j<nvolumes; j++)
2377 if (volumes[j]==id) return kTRUE;
2381 TBranch * br = TreeH()->GetBranch("fSector");
2382 br->GetEvent(track);
2383 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2384 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2391 //_____________________________________________________________________________
2392 void AliTPC::LoadPoints2(Int_t)
2395 // Store x, y, z of all hits in memory
2397 if (fTrackHits == 0 && fTrackHitsOld==0) return;
2400 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2401 if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2403 if (nhits == 0) return;
2404 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2405 if (fPoints == 0) fPoints = new TObjArray(tracks);
2408 Int_t *ntrk=new Int_t[tracks];
2409 Int_t *limi=new Int_t[tracks];
2410 Float_t **coor=new Float_t*[tracks];
2411 for(Int_t i=0;i<tracks;i++) {
2417 AliPoints *points = 0;
2420 Int_t chunk=nhits/4+1;
2422 // Loop over all the hits and store their position
2424 ahit = FirstHit2(-1);
2426 trk=ahit->GetTrack();
2427 if(ntrk[trk]==limi[trk]) {
2429 // Initialise a new track
2430 fp=new Float_t[3*(limi[trk]+chunk)];
2432 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2433 delete [] coor[trk];
2440 fp[3*ntrk[trk] ] = ahit->X();
2441 fp[3*ntrk[trk]+1] = ahit->Y();
2442 fp[3*ntrk[trk]+2] = ahit->Z();
2450 for(trk=0; trk<tracks; ++trk) {
2452 points = new AliPoints();
2453 points->SetMarkerColor(GetMarkerColor());
2454 points->SetMarkerSize(GetMarkerSize());
2455 points->SetDetector(this);
2456 points->SetParticle(trk);
2457 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2458 fPoints->AddAt(points,trk);
2459 delete [] coor[trk];
2469 //_____________________________________________________________________________
2470 void AliTPC::LoadPoints3(Int_t)
2473 // Store x, y, z of all hits in memory
2474 // - only intersection point with pad row
2475 if (fTrackHits == 0) return;
2477 Int_t nhits = fTrackHits->GetEntriesFast();
2478 if (nhits == 0) return;
2479 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2480 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2481 fPoints->Expand(2*tracks);
2484 Int_t *ntrk=new Int_t[tracks];
2485 Int_t *limi=new Int_t[tracks];
2486 Float_t **coor=new Float_t*[tracks];
2487 for(Int_t i=0;i<tracks;i++) {
2493 AliPoints *points = 0;
2496 Int_t chunk=nhits/4+1;
2498 // Loop over all the hits and store their position
2500 ahit = FirstHit2(-1);
2501 //for (Int_t hit=0;hit<nhits;hit++) {
2505 // ahit = (AliHit*)fHits->UncheckedAt(hit);
2506 trk=ahit->GetTrack();
2507 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2508 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2509 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2510 if (currentrow!=lastrow){
2511 lastrow = currentrow;
2512 //later calculate intersection point
2513 if(ntrk[trk]==limi[trk]) {
2515 // Initialise a new track
2516 fp=new Float_t[3*(limi[trk]+chunk)];
2518 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2519 delete [] coor[trk];
2526 fp[3*ntrk[trk] ] = ahit->X();
2527 fp[3*ntrk[trk]+1] = ahit->Y();
2528 fp[3*ntrk[trk]+2] = ahit->Z();
2535 for(trk=0; trk<tracks; ++trk) {
2537 points = new AliPoints();
2538 points->SetMarkerColor(GetMarkerColor()+1);
2539 points->SetMarkerStyle(5);
2540 points->SetMarkerSize(0.2);
2541 points->SetDetector(this);
2542 points->SetParticle(trk);
2543 // points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()20);
2544 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2545 fPoints->AddAt(points,tracks+trk);
2546 delete [] coor[trk];
2557 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2560 fLoader = new AliTPCLoader(GetName(),topfoldername);
2564 ////////////////////////////////////////////////////////////////////////
2565 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2567 // load TPC paarmeters from a given file or create new if the object
2568 // is not found there
2569 // 12/05/2003 This method should be moved to the AliTPCLoader
2570 // and one has to decide where to store the TPC parameters
2573 sprintf(paramName,"75x40_100x60_150x60");
2574 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2576 cout<<"TPC parameters "<<paramName<<" found."<<endl;
2578 cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2580 paramTPC = new AliTPCParamSR;
2584 // the older version of parameters can be accessed with this code.
2585 // In some cases, we have old parameters saved in the file but
2586 // digits were created with new parameters, it can be distinguish
2587 // by the name of TPC TreeD. The code here is just for the case
2588 // we would need to compare with old data, uncomment it if needed.
2590 // char paramName[50];
2591 // sprintf(paramName,"75x40_100x60");
2592 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2594 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2596 // sprintf(paramName,"75x40_100x60_150x60");
2597 // paramTPC=(AliTPCParam*)in->Get(paramName);
2599 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2601 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2603 // paramTPC = new AliTPCParamSR;