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>
46 #include <TObjectTable.h>
47 #include <TParticle.h>
53 #include <TVirtualMC.h>
56 #include <TStopwatch.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"
76 #include "AliTPCDigitizer.h"
77 #include "AliTPCBuffer.h"
78 #include "AliTPCDDLRawData.h"
80 #include "AliRawReader.h"
81 #include "AliTPCRawStream.h"
84 //_____________________________________________________________________________
85 AliTPC::AliTPC():AliDetector(),
102 // Default constructor
106 // fTrackHitsOld = 0;
107 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
108 fHitType = 4; // ROOT containers
110 fHitType = 2; //default CONTAINERS - based on ROOT structure
114 //_____________________________________________________________________________
115 AliTPC::AliTPC(const char *name, const char *title)
116 : AliDetector(name,title),
132 // Standard constructor
136 // Initialise arrays of hits and digits
137 fHits = new TClonesArray("AliTPChit", 176);
138 gAlice->GetMCApp()->AddHitList(fHits);
140 fTrackHits = new AliTPCTrackHitsV2;
141 fTrackHits->SetHitPrecision(0.002);
142 fTrackHits->SetStepPrecision(0.003);
143 fTrackHits->SetMaxDistance(100);
145 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
146 //fTrackHitsOld->SetHitPrecision(0.002);
147 //fTrackHitsOld->SetStepPrecision(0.003);
148 //fTrackHitsOld->SetMaxDistance(100);
151 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
152 fHitType = 4; // ROOT containers
162 // Initialise color attributes
163 //PH SetMarkerColor(kYellow);
166 // Set TPC parameters
170 if (!strcmp(title,"Default")) {
171 fTPCParam = new AliTPCParamSR;
173 AliWarning("In Config.C you must set non-default parameters.");
178 //_____________________________________________________________________________
189 delete fTrackHits; //MI 15.09.2000
190 // delete fTrackHitsOld; //MI 10.12.2001
193 delete [] fNoiseTable;
194 delete [] fActiveSectors;
198 //_____________________________________________________________________________
199 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
202 // Add a hit to the list
205 TClonesArray &lhits = *fHits;
206 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
209 AddHit2(track,vol,hits);
212 //_____________________________________________________________________________
213 void AliTPC::BuildGeometry()
217 // Build TPC ROOT TNode geometry for the event display
222 const int kColorTPC=19;
223 char name[5], title[25];
224 const Double_t kDegrad=TMath::Pi()/180;
225 const Double_t kRaddeg=180./TMath::Pi();
228 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
229 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
231 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
232 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
234 Int_t nLo = fTPCParam->GetNInnerSector()/2;
235 Int_t nHi = fTPCParam->GetNOuterSector()/2;
237 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
238 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
239 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
240 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
243 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
244 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
250 // Get ALICE top node
253 nTop=gAlice->GetGeometry()->GetNode("alice");
257 rl = fTPCParam->GetInnerRadiusLow();
258 ru = fTPCParam->GetInnerRadiusUp();
262 sprintf(name,"LS%2.2d",i);
264 sprintf(title,"TPC low sector %3d",i);
267 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
268 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
269 tubs->SetNumberOfDivisions(1);
271 nNode = new TNode(name,title,name,0,0,0,"");
272 nNode->SetLineColor(kColorTPC);
278 rl = fTPCParam->GetOuterRadiusLow();
279 ru = fTPCParam->GetOuterRadiusUp();
282 sprintf(name,"US%2.2d",i);
284 sprintf(title,"TPC upper sector %d",i);
286 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
287 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
288 tubs->SetNumberOfDivisions(1);
290 nNode = new TNode(name,title,name,0,0,0,"");
291 nNode->SetLineColor(kColorTPC);
297 //_____________________________________________________________________________
298 void AliTPC::CreateMaterials()
300 //-----------------------------------------------
301 // Create Materials for for TPC simulations
302 //-----------------------------------------------
304 //-----------------------------------------------------------------
305 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
306 //-----------------------------------------------------------------
308 Int_t iSXFLD=gAlice->Field()->Integ();
309 Float_t sXMGMX=gAlice->Field()->Max();
311 Float_t amat[5]; // atomic numbers
312 Float_t zmat[5]; // z
313 Float_t wmat[5]; // proportions
319 //***************** Gases *************************
322 //--------------------------------------------------------------
323 // gases - air and CO2
324 //--------------------------------------------------------------
340 AliMixture(10,"CO2",amat,zmat,density,2,wmat);
355 AliMixture(11,"Air",amat,zmat,density,2,wmat);
357 //----------------------------------------------------------------
359 //----------------------------------------------------------------
362 // Drift gases 1 - nonsensitive, 2 - sensitive
363 // Ne-CO2-N (85-10-5)
382 AliMixture(12,"Ne-CO2-N-1",amat,zmat,density,4,wmat);
383 AliMixture(13,"Ne-CO2-N-2",amat,zmat,density,4,wmat);
385 //----------------------------------------------------------------------
387 //----------------------------------------------------------------------
409 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
430 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
448 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
466 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
484 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
485 // material for "prepregs"
486 // Epoxy - C14 H20 O3
489 // prepreg1 60% C-fiber, 40% epoxy (vol)
504 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
506 //prepreg2 60% glass-fiber, 40% epoxy
525 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
527 //prepreg3 50% glass-fiber, 50% epoxy
546 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
548 // G10 60% SiO2 40% epoxy
567 AliMixture(22, "G10",amat,zmat,density,4,wmat);
576 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
578 // Si (for electronics
585 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
594 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
596 // Epoxy - C14 H20 O3
612 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
630 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
638 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
640 // Fe (steel for the inner heat screen)
648 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
650 //----------------------------------------------------------
651 // tracking media for gases
652 //----------------------------------------------------------
654 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
655 AliMedium(1, "Ne-CO2-N-1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
656 AliMedium(2, "Ne-CO2-N-2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
657 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
658 AliMedium(20, "Ne-CO2-N-3", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
659 //-----------------------------------------------------------
660 // tracking media for solids
661 //-----------------------------------------------------------
663 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
664 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
665 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
666 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
667 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
668 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
670 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
671 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
672 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
673 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
675 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
676 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
677 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
678 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
679 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
683 void AliTPC::GenerNoise(Int_t tablesize)
686 //Generate table with noise
693 if (fNoiseTable) delete[] fNoiseTable;
694 fNoiseTable = new Float_t[tablesize];
695 fNoiseDepth = tablesize;
696 fCurrentNoise =0; //!index of the noise in the noise table
698 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
699 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
702 Float_t AliTPC::GetNoise()
704 // get noise from table
705 // if ((fCurrentNoise%10)==0)
706 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
707 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
708 return fNoiseTable[fCurrentNoise++];
709 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
713 Bool_t AliTPC::IsSectorActive(Int_t sec) const
716 // check if the sector is active
717 if (!fActiveSectors) return kTRUE;
718 else return fActiveSectors[sec];
721 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
723 // activate interesting sectors
724 SetTreeAddress();//just for security
725 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
726 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
727 for (Int_t i=0;i<n;i++)
728 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
732 void AliTPC::SetActiveSectors(Int_t flag)
735 // activate sectors which were hitted by tracks
737 SetTreeAddress();//just for security
738 if (fHitType==0) return; // if Clones hit - not short volume ID information
739 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
741 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
744 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
748 AliFatal("Can not find TreeH in folder");
751 if (fHitType>1) branch = TreeH()->GetBranch("TPC2");
752 else branch = TreeH()->GetBranch("TPC");
753 Stat_t ntracks = TreeH()->GetEntries();
754 // loop over all hits
755 AliDebug(1,Form("Got %d tracks",ntracks));
757 for(Int_t track=0;track<ntracks;track++) {
760 if (fTrackHits && fHitType&4) {
761 TBranch * br1 = TreeH()->GetBranch("fVolumes");
762 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
763 br1->GetEvent(track);
764 br2->GetEvent(track);
765 Int_t *volumes = fTrackHits->GetVolumes();
766 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++) {
767 if (volumes[j]<fTPCParam->GetNSector()) {
768 fActiveSectors[volumes[j]]=kTRUE;
771 AliError(Form("Volume %d -> sector number %d is outside (0..%d)",
774 fTPCParam->GetNSector()));
780 // if (fTrackHitsOld && fHitType&2) {
781 // TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
782 // br->GetEvent(track);
783 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
784 // for (UInt_t j=0;j<ar->GetSize();j++){
785 // fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
794 //_____________________________________________________________________________
795 void AliTPC::Digits2Raw()
797 // convert digits of the current event to raw data
799 static const Int_t kThreshold = 0;
801 fLoader->LoadDigits();
802 TTree* digits = fLoader->TreeD();
804 AliError("No digits tree");
809 AliSimDigits* digrow = &digarr;
810 digits->GetBranch("Segment")->SetAddress(&digrow);
812 const char* fileName = "AliTPCDDL.dat";
813 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
817 // 2: txt files with digits
818 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
819 //it is highly suggested to use this mode only for debugging digits files
820 //reasonably small, because otherwise the size of the txt files can reach
821 //quickly several MB wasting time and disk space.
822 buffer->SetVerbose(0);
824 Int_t nEntries = Int_t(digits->GetEntries());
825 Int_t previousSector = -1;
827 for (Int_t i = 0; i < nEntries; i++) {
830 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
831 if(previousSector != sector) {
833 previousSector = sector;
836 if (sector < 36) { //inner sector [0;35]
838 //the whole row is written into the output file
839 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
840 sector, subSector, row);
842 //only the pads in the range [37;48] are written into the output file
843 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
844 sector, subSector, row);
846 //only the pads outside the range [37;48] are written into the output file
847 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
848 sector, subSector, row);
851 } else { //outer sector [36;71]
852 if (row == 54) subSector = 2;
853 if ((row != 27) && (row != 76)) {
854 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
855 sector, subSector, row);
856 } else if (row == 27) {
857 //only the pads outside the range [43;46] are written into the output file
858 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
859 sector, subSector, row);
861 //only the pads in the range [43;46] are written into the output file
862 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
863 sector, subSector, row);
864 } else if (row == 76) {
865 //only the pads outside the range [33;88] are written into the output file
866 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
867 sector, subSector, row);
869 //only the pads in the range [33;88] are written into the output file
870 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
871 sector, subSector, row);
877 fLoader->UnloadDigits();
879 AliTPCDDLRawData rawWriter;
880 rawWriter.SetVerbose(0);
882 rawWriter.RawData(fileName);
883 gSystem->Unlink(fileName);
888 //_____________________________________________________________________________
889 Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
890 // Converts the TPC raw data into summable digits
891 // The method is used for merging simulated and
893 if (fLoader->TreeS() == 0x0 ) {
894 fLoader->MakeTree("S");
897 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
899 //setup TPCDigitsArray
900 if(GetDigitsArray()) delete GetDigitsArray();
902 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
903 arr->SetClass("AliSimDigits");
904 arr->Setup(fTPCParam);
905 arr->MakeTree(fLoader->TreeS());
909 // set zero suppression to "0"
910 fTPCParam->SetZeroSup(0);
913 const Int_t kmaxTime = fTPCParam->GetMaxTBin();
914 const Int_t kNIS = fTPCParam->GetNInnerSector();
915 const Int_t kNOS = fTPCParam->GetNOuterSector();
916 const Int_t kNS = kNIS + kNOS;
918 Short_t** allBins = NULL; //array which contains the data for one sector
920 for(Int_t iSector = 0; iSector < kNS; iSector++) {
922 Int_t nRows = fTPCParam->GetNRow(iSector);
923 Int_t nDDLs = 0, indexDDL = 0;
924 if (iSector < kNIS) {
926 indexDDL = iSector * 2;
930 indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
933 // Loas the raw data for corresponding DDLs
935 AliTPCRawStream input(rawReader);
936 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
938 // Alocate and init the array with the sector data
939 allBins = new Short_t*[nRows];
940 for (Int_t iRow = 0; iRow < nRows; iRow++) {
941 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
942 Int_t maxBin = kmaxTime*maxPad;
943 allBins[iRow] = new Short_t[maxBin];
944 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
947 // Begin loop over altro data
948 while (input.Next()) {
950 if (input.GetSector() != iSector)
951 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
953 Int_t iRow = input.GetRow();
954 if (iRow < 0 || iRow >= nRows)
955 AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
957 Int_t iPad = input.GetPad();
959 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
961 if (iPad < 0 || iPad >= maxPad)
962 AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
963 iPad, 0, maxPad -1));
965 Int_t iTimeBin = input.GetTime();
966 if ( iTimeBin < 0 || iTimeBin >= kmaxTime)
967 AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
968 iTimeBin, 0, kmaxTime -1));
970 Int_t maxBin = kmaxTime*maxPad;
972 if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
973 ((iPad*kmaxTime+iTimeBin) < 0))
974 AliFatal(Form("Index outside the allowed range"
975 " Sector=%d Row=%d Pad=%d Timebin=%d"
976 " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
978 allBins[iRow][iPad*kmaxTime+iTimeBin] = input.GetSignal();
980 } // End loop over altro data
982 // Now fill the digits array
983 if (fDigitsArray->GetTree()==0) {
984 AliFatal("Tree not set in fDigitsArray");
987 for (Int_t iRow = 0; iRow < nRows; iRow++) {
988 AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
990 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
991 for(Int_t iPad = 0; iPad < maxPad; iPad++) {
992 for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
993 Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
994 if (q <= 0) continue;
996 dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
999 fDigitsArray->StoreRow(iSector,iRow);
1000 Int_t ndig = dig->GetDigitSize();
1003 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1004 iSector,iRow,ndig));
1006 fDigitsArray->ClearRow(iSector,iRow);
1008 } // end of the sector digitization
1010 for (Int_t iRow = 0; iRow < nRows; iRow++)
1011 delete [] allBins[iRow];
1017 fLoader->WriteSDigits("OVERWRITE");
1019 if(GetDigitsArray()) delete GetDigitsArray();
1020 SetDigitsArray(0x0);
1025 //______________________________________________________________________
1026 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
1028 return new AliTPCDigitizer(manager);
1031 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
1033 //create digits from summable digits
1034 GenerNoise(500000); //create teble with noise
1036 //conect tree with sSDigits
1037 TTree *t = fLoader->TreeS();
1040 fLoader->LoadSDigits("READ");
1041 t = fLoader->TreeS();
1043 AliError("Can not get input TreeS");
1048 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1050 AliSimDigits digarr, *dummy=&digarr;
1051 TBranch* sdb = t->GetBranch("Segment");
1053 AliError("Can not find branch with segments in TreeS.");
1057 sdb->SetAddress(&dummy);
1059 Stat_t nentries = t->GetEntries();
1061 // set zero suppression
1063 fTPCParam->SetZeroSup(2);
1065 // get zero suppression
1067 Int_t zerosup = fTPCParam->GetZeroSup();
1069 //make tree with digits
1071 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1072 arr->SetClass("AliSimDigits");
1073 arr->Setup(fTPCParam);
1074 arr->MakeTree(fLoader->TreeD());
1076 AliTPCParam * par = fTPCParam;
1078 //Loop over segments of the TPC
1080 for (Int_t n=0; n<nentries; n++) {
1083 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1084 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
1087 if (!IsSectorActive(sec)) continue;
1089 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1090 Int_t nrows = digrow->GetNRows();
1091 Int_t ncols = digrow->GetNCols();
1093 digrow->ExpandBuffer();
1094 digarr.ExpandBuffer();
1095 digrow->ExpandTrackBuffer();
1096 digarr.ExpandTrackBuffer();
1099 Short_t * pamp0 = digarr.GetDigits();
1100 Int_t * ptracks0 = digarr.GetTracks();
1101 Short_t * pamp1 = digrow->GetDigits();
1102 Int_t * ptracks1 = digrow->GetTracks();
1103 Int_t nelems =nrows*ncols;
1104 Int_t saturation = fTPCParam->GetADCSat() - 1;
1105 //use internal structure of the AliDigits - for speed reason
1106 //if you cahnge implementation
1107 //of the Alidigits - it must be rewriten -
1108 for (Int_t i= 0; i<nelems; i++){
1109 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1111 if (q>saturation) q=saturation;
1114 ptracks1[0]=ptracks0[0];
1115 ptracks1[nelems]=ptracks0[nelems];
1116 ptracks1[2*nelems]=ptracks0[2*nelems];
1124 arr->StoreRow(sec,row);
1125 arr->ClearRow(sec,row);
1130 fLoader->WriteDigits("OVERWRITE");
1134 //__________________________________________________________________
1135 void AliTPC::SetDefaults(){
1137 // setting the defaults
1140 // Set response functions
1143 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1145 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1147 AliInfo("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...");
1149 param = new AliTPCParamSR();
1152 param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1155 AliFatal("No TPC parameters found");
1159 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1160 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1161 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1162 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1163 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1164 rf->SetOffset(3*param->GetZSigma());
1167 TDirectory *savedir=gDirectory;
1168 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1170 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1173 prfinner->Read("prf_07504_Gati_056068_d02");
1174 //PH Set different names
1175 s=prfinner->GetGRF()->GetName();
1177 prfinner->GetGRF()->SetName(s.Data());
1179 prfouter1->Read("prf_10006_Gati_047051_d03");
1180 s=prfouter1->GetGRF()->GetName();
1182 prfouter1->GetGRF()->SetName(s.Data());
1184 prfouter2->Read("prf_15006_Gati_047051_d03");
1185 s=prfouter2->GetGRF()->GetName();
1187 prfouter2->GetGRF()->SetName(s.Data());
1192 param->SetInnerPRF(prfinner);
1193 param->SetOuter1PRF(prfouter1);
1194 param->SetOuter2PRF(prfouter2);
1195 param->SetTimeRF(rf);
1205 //__________________________________________________________________
1206 void AliTPC::Hits2Digits()
1209 // creates digits from hits
1211 if (!fTPCParam->IsGeoRead()){
1213 // read transformation matrices for gGeoManager
1215 fTPCParam->ReadGeoMatrices();
1218 fLoader->LoadHits("read");
1219 fLoader->LoadDigits("recreate");
1220 AliRunLoader* runLoader = fLoader->GetRunLoader();
1222 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1223 //PH runLoader->GetEvent(iEvent);
1225 Hits2Digits(iEvent);
1228 fLoader->UnloadHits();
1229 fLoader->UnloadDigits();
1231 //__________________________________________________________________
1232 void AliTPC::Hits2Digits(Int_t eventnumber)
1234 //----------------------------------------------------
1235 // Loop over all sectors for a single event
1236 //----------------------------------------------------
1237 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1238 rl->GetEvent(eventnumber);
1239 if (fLoader->TreeH() == 0x0) {
1240 if(fLoader->LoadHits()) {
1241 AliError("Can not load hits.");
1246 if (fLoader->TreeD() == 0x0 ) {
1247 fLoader->MakeTree("D");
1248 if (fLoader->TreeD() == 0x0 ) {
1249 AliError("Can not get TreeD");
1254 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1255 GenerNoise(500000); //create teble with noise
1257 //setup TPCDigitsArray
1259 if(GetDigitsArray()) delete GetDigitsArray();
1261 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1262 arr->SetClass("AliSimDigits");
1263 arr->Setup(fTPCParam);
1265 arr->MakeTree(fLoader->TreeD());
1266 SetDigitsArray(arr);
1268 fDigitsSwitch=0; // standard digits
1270 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1271 if (IsSectorActive(isec)) {
1272 AliDebug(1,Form("Hits2Digits","Sector %d is active.",isec));
1273 Hits2DigitsSector(isec);
1276 AliDebug(1,Form("Hits2Digits","Sector %d is NOT active.",isec));
1279 fLoader->WriteDigits("OVERWRITE");
1281 //this line prevents the crash in the similar one
1282 //on the beginning of this method
1283 //destructor attempts to reset the tree, which is deleted by the loader
1284 //need to be redesign
1285 if(GetDigitsArray()) delete GetDigitsArray();
1286 SetDigitsArray(0x0);
1290 //__________________________________________________________________
1291 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1294 //-----------------------------------------------------------
1295 // summable digits - 16 bit "ADC", no noise, no saturation
1296 //-----------------------------------------------------------
1298 //----------------------------------------------------
1299 // Loop over all sectors for a single event
1300 //----------------------------------------------------
1302 AliRunLoader* rl = fLoader->GetRunLoader();
1304 rl->GetEvent(eventnumber);
1305 if (fLoader->TreeH() == 0x0) {
1306 if(fLoader->LoadHits()) {
1307 AliError("Can not load hits.");
1314 if (fLoader->TreeS() == 0x0 ) {
1315 fLoader->MakeTree("S");
1318 if(fDefaults == 0) SetDefaults();
1320 GenerNoise(500000); //create table with noise
1321 //setup TPCDigitsArray
1323 if(GetDigitsArray()) delete GetDigitsArray();
1326 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1327 arr->SetClass("AliSimDigits");
1328 arr->Setup(fTPCParam);
1329 arr->MakeTree(fLoader->TreeS());
1331 SetDigitsArray(arr);
1333 fDigitsSwitch=1; // summable digits
1335 // set zero suppression to "0"
1337 fTPCParam->SetZeroSup(0);
1339 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1340 if (IsSectorActive(isec)) {
1341 Hits2DigitsSector(isec);
1344 fLoader->WriteSDigits("OVERWRITE");
1346 //this line prevents the crash in the similar one
1347 //on the beginning of this method
1348 //destructor attempts to reset the tree, which is deleted by the loader
1349 //need to be redesign
1350 if(GetDigitsArray()) delete GetDigitsArray();
1351 SetDigitsArray(0x0);
1353 //__________________________________________________________________
1355 void AliTPC::Hits2SDigits()
1358 //-----------------------------------------------------------
1359 // summable digits - 16 bit "ADC", no noise, no saturation
1360 //-----------------------------------------------------------
1362 if (!fTPCParam->IsGeoRead()){
1364 // read transformation matrices for gGeoManager
1366 fTPCParam->ReadGeoMatrices();
1369 fLoader->LoadHits("read");
1370 fLoader->LoadSDigits("recreate");
1371 AliRunLoader* runLoader = fLoader->GetRunLoader();
1373 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1374 runLoader->GetEvent(iEvent);
1377 Hits2SDigits2(iEvent);
1380 fLoader->UnloadHits();
1381 fLoader->UnloadSDigits();
1383 //_____________________________________________________________________________
1385 void AliTPC::Hits2DigitsSector(Int_t isec)
1387 //-------------------------------------------------------------------
1388 // TPC conversion from hits to digits.
1389 //-------------------------------------------------------------------
1391 //-----------------------------------------------------------------
1392 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1393 //-----------------------------------------------------------------
1395 //-------------------------------------------------------
1396 // Get the access to the track hits
1397 //-------------------------------------------------------
1399 // check if the parameters are set - important if one calls this method
1400 // directly, not from the Hits2Digits
1402 if(fDefaults == 0) SetDefaults();
1404 TTree *tH = TreeH(); // pointer to the hits tree
1406 AliFatal("Can not find TreeH in folder");
1410 Stat_t ntracks = tH->GetEntries();
1414 //-------------------------------------------
1415 // Only if there are any tracks...
1416 //-------------------------------------------
1420 Int_t nrows =fTPCParam->GetNRow(isec);
1422 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1424 MakeSector(isec,nrows,tH,ntracks,row);
1426 //--------------------------------------------------------
1427 // Digitize this sector, row by row
1428 // row[i] is the pointer to the TObjArray of TVectors,
1429 // each one containing electrons accepted on this
1430 // row, assigned into tracks
1431 //--------------------------------------------------------
1435 if (fDigitsArray->GetTree()==0) {
1436 AliFatal("Tree not set in fDigitsArray");
1439 for (i=0;i<nrows;i++){
1441 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1443 DigitizeRow(i,isec,row);
1445 fDigitsArray->StoreRow(isec,i);
1447 Int_t ndig = dig->GetDigitSize();
1450 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1453 fDigitsArray->ClearRow(isec,i);
1456 } // end of the sector digitization
1458 for(i=0;i<nrows+2;i++){
1463 delete [] row; // delete the array of pointers to TObjArray-s
1467 } // end of Hits2DigitsSector
1470 //_____________________________________________________________________________
1471 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1473 //-----------------------------------------------------------
1474 // Single row digitization, coupling from the neighbouring
1475 // rows taken into account
1476 //-----------------------------------------------------------
1478 //-----------------------------------------------------------------
1479 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1480 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1481 //-----------------------------------------------------------------
1483 Float_t zerosup = fTPCParam->GetZeroSup();
1485 fCurrentIndex[1]= isec;
1488 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1489 Int_t nofTbins = fTPCParam->GetMaxTBin();
1490 Int_t indexRange[4];
1492 // Integrated signal for this row
1493 // and a single track signal
1496 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1497 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
1499 TMatrixF &total = *m1;
1501 // Array of pointers to the label-signal list
1503 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1504 Float_t **pList = new Float_t* [nofDigits];
1508 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1514 for (Int_t row= row1;row<=row2;row++){
1515 Int_t nTracks= rows[row]->GetEntries();
1516 for (i1=0;i1<nTracks;i1++){
1517 fCurrentIndex[2]= row;
1518 fCurrentIndex[3]=irow+1;
1520 m2->Zero(); // clear single track signal matrix
1521 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1522 GetList(trackLabel,nofPads,m2,indexRange,pList);
1524 else GetSignal(rows[row],i1,0,m1,indexRange);
1530 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1532 Float_t fzerosup = zerosup+0.5;
1533 for(Int_t it=0;it<nofTbins;it++){
1534 for(Int_t ip=0;ip<nofPads;ip++){
1536 Float_t q=total(ip,it);
1537 if(fDigitsSwitch == 0){
1539 if(q <=fzerosup) continue; // do not fill zeros
1541 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
1546 if(q <= 0.) continue; // do not fill zeros
1547 if(q>2000.) q=2000.;
1553 // "real" signal or electronic noise (list = -1)?
1556 for(Int_t j1=0;j1<3;j1++){
1557 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1562 <A NAME="AliDigits"></A>
1563 using of AliDigits object
1566 dig->SetDigitFast((Short_t)q,it,ip);
1567 if (fDigitsArray->IsSimulated()) {
1568 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1569 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1570 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1573 } // end of loop over time buckets
1574 } // end of lop over pads
1577 // This row has been digitized, delete nonused stuff
1580 for(lp=0;lp<nofDigits;lp++){
1581 if(pList[lp]) delete [] pList[lp];
1589 } // end of DigitizeRow
1591 //_____________________________________________________________________________
1593 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1594 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
1597 //---------------------------------------------------------------
1598 // Calculates 2-D signal (pad,time) for a single track,
1599 // returns a pointer to the signal matrix and the track label
1600 // No digitization is performed at this level!!!
1601 //---------------------------------------------------------------
1603 //-----------------------------------------------------------------
1604 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1605 // Modified: Marian Ivanov
1606 //-----------------------------------------------------------------
1610 tv = (TVector*)p1->At(ntr); // pointer to a track
1613 Float_t label = v(0);
1614 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
1616 Int_t nElectrons = (tv->GetNrows()-1)/5;
1617 indexRange[0]=9999; // min pad
1618 indexRange[1]=-1; // max pad
1619 indexRange[2]=9999; //min time
1620 indexRange[3]=-1; // max time
1622 TMatrixF &signal = *m1;
1623 TMatrixF &total = *m2;
1625 // Loop over all electrons
1627 for(Int_t nel=0; nel<nElectrons; nel++){
1629 Float_t aval = v(idx+4);
1630 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1631 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
1632 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1634 Int_t *index = fTPCParam->GetResBin(0);
1635 Float_t *weight = & (fTPCParam->GetResWeight(0));
1637 if (n>0) for (Int_t i =0; i<n; i++){
1638 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1641 Int_t time=index[2];
1642 Float_t qweight = *(weight)*eltoadcfac;
1644 if (m1!=0) signal(pad,time)+=qweight;
1645 total(pad,time)+=qweight;
1646 if (indexRange[0]>pad) indexRange[0]=pad;
1647 if (indexRange[1]<pad) indexRange[1]=pad;
1648 if (indexRange[2]>time) indexRange[2]=time;
1649 if (indexRange[3]<time) indexRange[3]=time;
1656 } // end of loop over electrons
1658 return label; // returns track label when finished
1661 //_____________________________________________________________________________
1662 void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
1663 Int_t *indexRange, Float_t **pList)
1665 //----------------------------------------------------------------------
1666 // Updates the list of tracks contributing to digits for a given row
1667 //----------------------------------------------------------------------
1669 //-----------------------------------------------------------------
1670 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1671 //-----------------------------------------------------------------
1673 TMatrixF &signal = *m;
1675 // lop over nonzero digits
1677 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1678 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1681 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1683 if(signal(ip,it)<0.5) continue;
1685 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1687 if(!pList[globalIndex]){
1690 // Create new list (6 elements - 3 signals and 3 labels),
1693 pList[globalIndex] = new Float_t [6];
1697 *pList[globalIndex] = -1.;
1698 *(pList[globalIndex]+1) = -1.;
1699 *(pList[globalIndex]+2) = -1.;
1700 *(pList[globalIndex]+3) = -1.;
1701 *(pList[globalIndex]+4) = -1.;
1702 *(pList[globalIndex]+5) = -1.;
1704 *pList[globalIndex] = label;
1705 *(pList[globalIndex]+3) = signal(ip,it);
1709 // check the signal magnitude
1711 Float_t highest = *(pList[globalIndex]+3);
1712 Float_t middle = *(pList[globalIndex]+4);
1713 Float_t lowest = *(pList[globalIndex]+5);
1716 // compare the new signal with already existing list
1719 if(signal(ip,it)<lowest) continue; // neglect this track
1723 if (signal(ip,it)>highest){
1724 *(pList[globalIndex]+5) = middle;
1725 *(pList[globalIndex]+4) = highest;
1726 *(pList[globalIndex]+3) = signal(ip,it);
1728 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1729 *(pList[globalIndex]+1) = *pList[globalIndex];
1730 *pList[globalIndex] = label;
1732 else if (signal(ip,it)>middle){
1733 *(pList[globalIndex]+5) = middle;
1734 *(pList[globalIndex]+4) = signal(ip,it);
1736 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1737 *(pList[globalIndex]+1) = label;
1740 *(pList[globalIndex]+5) = signal(ip,it);
1741 *(pList[globalIndex]+2) = label;
1745 } // end of loop over pads
1746 } // end of loop over time bins
1749 //___________________________________________________________________
1750 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1751 Stat_t ntracks,TObjArray **row)
1754 //-----------------------------------------------------------------
1755 // Prepares the sector digitization, creates the vectors of
1756 // tracks for each row of this sector. The track vector
1757 // contains the track label and the position of electrons.
1758 //-----------------------------------------------------------------
1760 //-----------------------------------------------------------------
1761 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1762 //-----------------------------------------------------------------
1764 Float_t gasgain = fTPCParam->GetGasGain();
1768 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1771 if (fHitType>1) branch = TH->GetBranch("TPC2");
1772 else branch = TH->GetBranch("TPC");
1775 //----------------------------------------------
1776 // Create TObjArray-s, one for each row,
1777 // each TObjArray will store the TVectors
1778 // of electrons, one TVectors per each track.
1779 //----------------------------------------------
1781 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
1782 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
1784 for(i=0; i<nrows+2; i++){
1785 row[i] = new TObjArray;
1792 //--------------------------------------------------------------------
1793 // Loop over tracks, the "track" contains the full history
1794 //--------------------------------------------------------------------
1796 Int_t previousTrack,currentTrack;
1797 previousTrack = -1; // nothing to store so far!
1799 for(Int_t track=0;track<ntracks;track++){
1800 Bool_t isInSector=kTRUE;
1802 isInSector = TrackInVolume(isec,track);
1803 if (!isInSector) continue;
1805 branch->GetEntry(track); // get next track
1809 tpcHit = (AliTPChit*)FirstHit(-1);
1811 //--------------------------------------------------------------
1813 //--------------------------------------------------------------
1818 Int_t sector=tpcHit->fSector; // sector number
1820 tpcHit = (AliTPChit*) NextHit();
1824 // Remove hits which arrive before the TPC opening gate signal
1825 if(((fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
1826 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
1827 tpcHit = (AliTPChit*) NextHit();
1831 currentTrack = tpcHit->Track(); // track number
1833 if(currentTrack != previousTrack){
1835 // store already filled fTrack
1837 for(i=0;i<nrows+2;i++){
1838 if(previousTrack != -1){
1839 if(nofElectrons[i]>0){
1840 TVector &v = *tracks[i];
1841 v(0) = previousTrack;
1842 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
1843 row[i]->Add(tracks[i]);
1846 delete tracks[i]; // delete empty TVector
1852 tracks[i] = new TVector(601); // TVectors for the next fTrack
1854 } // end of loop over rows
1856 previousTrack=currentTrack; // update track label
1859 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1861 //---------------------------------------------------
1862 // Calculate the electron attachment probability
1863 //---------------------------------------------------
1866 Float_t time = 1.e6*(fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
1867 /fTPCParam->GetDriftV();
1869 Float_t attProb = fTPCParam->GetAttCoef()*
1870 fTPCParam->GetOxyCont()*time; // fraction!
1872 //-----------------------------------------------
1873 // Loop over electrons
1874 //-----------------------------------------------
1877 for(Int_t nel=0;nel<qI;nel++){
1878 // skip if electron lost due to the attachment
1879 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1884 // protection for the nonphysical avalanche size (10**6 maximum)
1886 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1887 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
1890 TransportElectron(xyz,index);
1892 fTPCParam->GetPadRow(xyz,index);
1893 // Electron track time (for pileup simulation)
1894 xyz[4] = tpcHit->Time()/fTPCParam->GetTSample();
1895 // row 0 - cross talk from the innermost row
1896 // row fNRow+1 cross talk from the outermost row
1897 rowNumber = index[2]+1;
1898 //transform position to local digit coordinates
1899 //relative to nearest pad row
1900 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
1902 if (isec <fTPCParam->GetNInnerSector()) {
1903 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
1904 y1 = fTPCParam->GetYInner(rowNumber);
1907 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
1908 y1 = fTPCParam->GetYOuter(rowNumber);
1910 // gain inefficiency at the wires edges - linear
1913 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.));
1915 nofElectrons[rowNumber]++;
1916 //----------------------------------
1917 // Expand vector if necessary
1918 //----------------------------------
1919 if(nofElectrons[rowNumber]>120){
1920 Int_t range = tracks[rowNumber]->GetNrows();
1921 if((nofElectrons[rowNumber])>(range-1)/5){
1923 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
1927 TVector &v = *tracks[rowNumber];
1928 Int_t idx = 5*nofElectrons[rowNumber]-4;
1929 Real_t * position = &(((TVector&)v)(idx)); //make code faster
1930 memcpy(position,xyz,5*sizeof(Float_t));
1932 } // end of loop over electrons
1934 tpcHit = (AliTPChit*)NextHit();
1936 } // end of loop over hits
1937 } // end of loop over tracks
1940 // store remaining track (the last one) if not empty
1943 for(i=0;i<nrows+2;i++){
1944 if(nofElectrons[i]>0){
1945 TVector &v = *tracks[i];
1946 v(0) = previousTrack;
1947 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
1948 row[i]->Add(tracks[i]);
1957 delete [] nofElectrons;
1959 } // end of MakeSector
1962 //_____________________________________________________________________________
1966 // Initialise TPC detector after definition of geometry
1968 AliDebug(1,"*********************************************");
1971 //_____________________________________________________________________________
1972 void AliTPC::MakeBranch(Option_t* option)
1975 // Create Tree branches for the TPC.
1978 Int_t buffersize = 4000;
1979 char branchname[10];
1980 sprintf(branchname,"%s",GetName());
1982 const char *h = strstr(option,"H");
1984 if ( h && (fHitType<=1) && (fHits == 0x0)) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
1986 AliDetector::MakeBranch(option);
1988 const char *d = strstr(option,"D");
1990 if (fDigits && fLoader->TreeD() && d) {
1991 MakeBranchInTree(gAlice->TreeD(), branchname, &fDigits, buffersize, 0);
1994 if (fHitType>1) MakeBranch2(option,0); // MI change 14.09.2000
1997 //_____________________________________________________________________________
1998 void AliTPC::ResetDigits()
2001 // Reset number of digits and the digits array for this detector
2004 if (fDigits) fDigits->Clear();
2009 //_____________________________________________________________________________
2010 void AliTPC::SetSens(Int_t sens)
2013 //-------------------------------------------------------------
2014 // Activates/deactivates the sensitive strips at the center of
2015 // the pad row -- this is for the space-point resolution calculations
2016 //-------------------------------------------------------------
2018 //-----------------------------------------------------------------
2019 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2020 //-----------------------------------------------------------------
2026 void AliTPC::SetSide(Float_t side=0.)
2028 // choice of the TPC side
2033 //_____________________________________________________________________________
2035 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2038 // electron transport taking into account:
2040 // 2.ExB at the wires
2041 // 3. nonisochronity
2043 // xyz and index must be already transformed to system 1
2046 fTPCParam->Transform1to2(xyz,index);
2049 Float_t driftl=xyz[2];
2050 if(driftl<0.01) driftl=0.01;
2051 driftl=TMath::Sqrt(driftl);
2052 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2053 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2054 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2055 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2056 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2060 if (fTPCParam->GetMWPCReadout()==kTRUE){
2061 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2062 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2064 //add nonisochronity (not implemented yet)
2068 //______________________________________________________________________
2069 AliTPChit::AliTPChit()
2081 //_____________________________________________________________________________
2082 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits)
2083 :AliHit(shunt,track),
2090 // Creates a TPC hit object
2101 //________________________________________________________________________
2102 // Additional code because of the AliTPCTrackHitsV2
2104 void AliTPC::MakeBranch2(Option_t *option,const char */*file*/)
2107 // Create a new branch in the current Root Tree
2108 // The branch of fHits is automatically split
2109 // MI change 14.09.2000
2111 if (fHitType<2) return;
2112 char branchname[10];
2113 sprintf(branchname,"%s2",GetName());
2115 // Get the pointer to the header
2116 const char *cH = strstr(option,"H");
2118 if (fTrackHits && TreeH() && cH && fHitType&4) {
2119 AliDebug(1,"Making branch for Type 4 Hits");
2120 TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2123 // if (fTrackHitsOld && TreeH() && cH && fHitType&2) {
2124 // AliDebug(1,"Making branch for Type 2 Hits");
2125 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2126 // TreeH(),fBufferSize,99);
2127 // TreeH()->GetListOfBranches()->Add(branch);
2131 void AliTPC::SetTreeAddress()
2133 //Sets tree address for hits
2135 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2136 AliDetector::SetTreeAddress();
2138 if (fHitType>1) SetTreeAddress2();
2141 void AliTPC::SetTreeAddress2()
2144 // Set branch address for the TrackHits Tree
2149 char branchname[20];
2150 sprintf(branchname,"%s2",GetName());
2152 // Branch address for hit tree
2153 TTree *treeH = TreeH();
2154 if ((treeH)&&(fHitType&4)) {
2155 branch = treeH->GetBranch(branchname);
2157 branch->SetAddress(&fTrackHits);
2158 AliDebug(1,"fHitType&4 Setting");
2161 AliDebug(1,"fHitType&4 Failed (can not find branch)");
2164 // if ((treeH)&&(fHitType&2)) {
2165 // branch = treeH->GetBranch(branchname);
2167 // branch->SetAddress(&fTrackHitsOld);
2168 // AliDebug(1,"fHitType&2 Setting");
2171 // AliDebug(1,"fHitType&2 Failed (can not find branch)");
2173 //set address to TREETR
2175 TTree *treeTR = TreeTR();
2176 if (treeTR && fTrackReferences) {
2177 branch = treeTR->GetBranch(GetName());
2178 if (branch) branch->SetAddress(&fTrackReferences);
2183 void AliTPC::FinishPrimary()
2185 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2186 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2190 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2193 // add hit to the list
2196 int primary = gAlice->GetMCApp()->GetPrimary(track);
2197 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2201 gAlice->GetMCApp()->FlagTrack(track);
2203 if (fTrackHits && fHitType&4)
2204 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2205 hits[1],hits[2],(Int_t)hits[3],hits[4]);
2206 // if (fTrackHitsOld &&fHitType&2 )
2207 // fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2208 // hits[1],hits[2],(Int_t)hits[3]);
2212 void AliTPC::ResetHits()
2214 if (fHitType&1) AliDetector::ResetHits();
2215 if (fHitType>1) ResetHits2();
2218 void AliTPC::ResetHits2()
2222 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2223 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2227 AliHit* AliTPC::FirstHit(Int_t track)
2229 if (fHitType>1) return FirstHit2(track);
2230 return AliDetector::FirstHit(track);
2232 AliHit* AliTPC::NextHit()
2237 if (fHitType>1) return NextHit2();
2239 return AliDetector::NextHit();
2242 AliHit* AliTPC::FirstHit2(Int_t track)
2245 // Initialise the hit iterator
2246 // Return the address of the first hit for track
2247 // If track>=0 the track is read from disk
2248 // while if track<0 the first hit of the current
2249 // track is returned
2252 gAlice->ResetHits();
2253 TreeH()->GetEvent(track);
2256 if (fTrackHits && fHitType&4) {
2257 fTrackHits->First();
2258 return fTrackHits->GetHit();
2260 // if (fTrackHitsOld && fHitType&2) {
2261 // fTrackHitsOld->First();
2262 // return fTrackHitsOld->GetHit();
2268 AliHit* AliTPC::NextHit2()
2271 //Return the next hit for the current track
2274 // if (fTrackHitsOld && fHitType&2) {
2275 // fTrackHitsOld->Next();
2276 // return fTrackHitsOld->GetHit();
2280 return fTrackHits->GetHit();
2286 void AliTPC::LoadPoints(Int_t)
2291 if(fHitType==1) AliDetector::LoadPoints(a);
2292 else LoadPoints2(a);
2296 void AliTPC::RemapTrackHitIDs(Int_t *map)
2301 if (!fTrackHits) return;
2303 // if (fTrackHitsOld && fHitType&2){
2304 // AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2305 // for (UInt_t i=0;i<arr->GetSize();i++){
2306 // AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2307 // info->fTrackID = map[info->fTrackID];
2310 // if (fTrackHitsOld && fHitType&4){
2311 if (fTrackHits && fHitType&4){
2312 TClonesArray * arr = fTrackHits->GetArray();;
2313 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2314 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2315 info->SetTrackID(map[info->GetTrackID()]);
2320 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2322 //return bool information - is track in given volume
2323 //load only part of the track information
2324 //return true if current track is in volume
2327 // if (fTrackHitsOld && fHitType&2) {
2328 // TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
2329 // br->GetEvent(track);
2330 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2331 // for (UInt_t j=0;j<ar->GetSize();j++){
2332 // if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2336 if (fTrackHits && fHitType&4) {
2337 TBranch * br1 = TreeH()->GetBranch("fVolumes");
2338 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
2339 br2->GetEvent(track);
2340 br1->GetEvent(track);
2341 Int_t *volumes = fTrackHits->GetVolumes();
2342 Int_t nvolumes = fTrackHits->GetNVolumes();
2343 if (!volumes && nvolumes>0) {
2344 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2347 for (Int_t j=0;j<nvolumes; j++)
2348 if (volumes[j]==id) return kTRUE;
2352 TBranch * br = TreeH()->GetBranch("fSector");
2353 br->GetEvent(track);
2354 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2355 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2362 //_____________________________________________________________________________
2363 void AliTPC::LoadPoints2(Int_t)
2366 // Store x, y, z of all hits in memory
2368 // if (fTrackHits == 0 && fTrackHitsOld==0) return;
2369 if (fTrackHits == 0 ) return;
2372 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2373 // if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2375 if (nhits == 0) return;
2376 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2377 if (fPoints == 0) fPoints = new TObjArray(tracks);
2380 Int_t *ntrk=new Int_t[tracks];
2381 Int_t *limi=new Int_t[tracks];
2382 Float_t **coor=new Float_t*[tracks];
2383 for(Int_t i=0;i<tracks;i++) {
2389 AliPoints *points = 0;
2392 Int_t chunk=nhits/4+1;
2394 // Loop over all the hits and store their position
2396 ahit = FirstHit2(-1);
2398 trk=ahit->GetTrack();
2399 if(ntrk[trk]==limi[trk]) {
2401 // Initialise a new track
2402 fp=new Float_t[3*(limi[trk]+chunk)];
2404 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2405 delete [] coor[trk];
2412 fp[3*ntrk[trk] ] = ahit->X();
2413 fp[3*ntrk[trk]+1] = ahit->Y();
2414 fp[3*ntrk[trk]+2] = ahit->Z();
2422 for(trk=0; trk<tracks; ++trk) {
2424 points = new AliPoints();
2425 points->SetMarkerColor(kYellow); //PH kYellow it the default in TPC
2426 points->SetMarkerSize(1);//PH Default size=1
2427 points->SetDetector(this);
2428 points->SetParticle(trk);
2429 points->SetPolyMarker(ntrk[trk],coor[trk],1); // Default style=1
2430 fPoints->AddAt(points,trk);
2431 delete [] coor[trk];
2441 //_____________________________________________________________________________
2442 void AliTPC::LoadPoints3(Int_t)
2445 // Store x, y, z of all hits in memory
2446 // - only intersection point with pad row
2447 if (fTrackHits == 0) return;
2449 Int_t nhits = fTrackHits->GetEntriesFast();
2450 if (nhits == 0) return;
2451 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2452 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2453 fPoints->Expand(2*tracks);
2456 Int_t *ntrk=new Int_t[tracks];
2457 Int_t *limi=new Int_t[tracks];
2458 Float_t **coor=new Float_t*[tracks];
2459 for(Int_t i=0;i<tracks;i++) {
2465 AliPoints *points = 0;
2468 Int_t chunk=nhits/4+1;
2470 // Loop over all the hits and store their position
2472 ahit = FirstHit2(-1);
2476 trk=ahit->GetTrack();
2477 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2478 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2479 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2480 if (currentrow!=lastrow){
2481 lastrow = currentrow;
2482 //later calculate intersection point
2483 if(ntrk[trk]==limi[trk]) {
2485 // Initialise a new track
2486 fp=new Float_t[3*(limi[trk]+chunk)];
2488 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2489 delete [] coor[trk];
2496 fp[3*ntrk[trk] ] = ahit->X();
2497 fp[3*ntrk[trk]+1] = ahit->Y();
2498 fp[3*ntrk[trk]+2] = ahit->Z();
2505 for(trk=0; trk<tracks; ++trk) {
2507 points = new AliPoints();
2508 points->SetMarkerColor(kMagenta); //PH kYellow + 1 is kMagenta
2509 points->SetMarkerStyle(5);
2510 points->SetMarkerSize(0.2);
2511 points->SetDetector(this);
2512 points->SetParticle(trk);
2513 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2514 fPoints->AddAt(points,tracks+trk);
2515 delete [] coor[trk];
2526 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2529 fLoader = new AliTPCLoader(GetName(),topfoldername);
2533 ////////////////////////////////////////////////////////////////////////
2534 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2536 // load TPC paarmeters from a given file or create new if the object
2537 // is not found there
2538 // 12/05/2003 This method should be moved to the AliTPCLoader
2539 // and one has to decide where to store the TPC parameters
2542 sprintf(paramName,"75x40_100x60_150x60");
2543 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2545 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2547 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2548 paramTPC = new AliTPCParamSR;
2552 // the older version of parameters can be accessed with this code.
2553 // In some cases, we have old parameters saved in the file but
2554 // digits were created with new parameters, it can be distinguish
2555 // by the name of TPC TreeD. The code here is just for the case
2556 // we would need to compare with old data, uncomment it if needed.
2558 // char paramName[50];
2559 // sprintf(paramName,"75x40_100x60");
2560 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2562 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2564 // sprintf(paramName,"75x40_100x60_150x60");
2565 // paramTPC=(AliTPCParam*)in->Get(paramName);
2567 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2569 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2571 // paramTPC = new AliTPCParamSR;