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 "AliTPCcalibDB.h"
81 #include "AliTPCCalPad.h"
82 #include "AliTPCCalROC.h"
83 #include "AliTPCExB.h"
84 #include "AliRawReader.h"
85 #include "AliTPCRawStream.h"
88 //_____________________________________________________________________________
89 AliTPC::AliTPC():AliDetector(),
99 fPrimaryIonisation(0),
109 // Default constructor
113 // fTrackHitsOld = 0;
114 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
115 fHitType = 4; // ROOT containers
117 fHitType = 2; //default CONTAINERS - based on ROOT structure
121 //_____________________________________________________________________________
122 AliTPC::AliTPC(const char *name, const char *title)
123 : AliDetector(name,title),
133 fPrimaryIonisation(0),
142 // Standard constructor
146 // Initialise arrays of hits and digits
147 fHits = new TClonesArray("AliTPChit", 176);
148 gAlice->GetMCApp()->AddHitList(fHits);
150 fTrackHits = new AliTPCTrackHitsV2;
151 fTrackHits->SetHitPrecision(0.002);
152 fTrackHits->SetStepPrecision(0.003);
153 fTrackHits->SetMaxDistance(100);
155 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
156 //fTrackHitsOld->SetHitPrecision(0.002);
157 //fTrackHitsOld->SetStepPrecision(0.003);
158 //fTrackHitsOld->SetMaxDistance(100);
161 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
162 fHitType = 4; // ROOT containers
172 // Initialise color attributes
173 //PH SetMarkerColor(kYellow);
176 // Set TPC parameters
180 if (!strcmp(title,"Default")) {
181 //fTPCParam = new AliTPCParamSR;
182 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
184 AliWarning("In Config.C you must set non-default parameters.");
189 //_____________________________________________________________________________
200 delete fTrackHits; //MI 15.09.2000
201 // delete fTrackHitsOld; //MI 10.12.2001
204 delete [] fNoiseTable;
205 delete [] fActiveSectors;
209 //_____________________________________________________________________________
210 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
213 // Add a hit to the list
216 TClonesArray &lhits = *fHits;
217 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
220 AddHit2(track,vol,hits);
223 //_____________________________________________________________________________
224 void AliTPC::BuildGeometry()
228 // Build TPC ROOT TNode geometry for the event display
233 const int kColorTPC=19;
234 char name[5], title[25];
235 const Double_t kDegrad=TMath::Pi()/180;
236 const Double_t kRaddeg=180./TMath::Pi();
239 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
240 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
242 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
243 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
245 Int_t nLo = fTPCParam->GetNInnerSector()/2;
246 Int_t nHi = fTPCParam->GetNOuterSector()/2;
248 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
249 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
250 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
251 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
254 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
255 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
261 // Get ALICE top node
264 nTop=gAlice->GetGeometry()->GetNode("alice");
268 rl = fTPCParam->GetInnerRadiusLow();
269 ru = fTPCParam->GetInnerRadiusUp();
273 sprintf(name,"LS%2.2d",i);
275 sprintf(title,"TPC low sector %3d",i);
278 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
279 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
280 tubs->SetNumberOfDivisions(1);
282 nNode = new TNode(name,title,name,0,0,0,"");
283 nNode->SetLineColor(kColorTPC);
289 rl = fTPCParam->GetOuterRadiusLow();
290 ru = fTPCParam->GetOuterRadiusUp();
293 sprintf(name,"US%2.2d",i);
295 sprintf(title,"TPC upper sector %d",i);
297 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
298 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
299 tubs->SetNumberOfDivisions(1);
301 nNode = new TNode(name,title,name,0,0,0,"");
302 nNode->SetLineColor(kColorTPC);
308 //_____________________________________________________________________________
309 void AliTPC::CreateMaterials()
311 //-----------------------------------------------
312 // Create Materials for for TPC simulations
313 //-----------------------------------------------
315 //-----------------------------------------------------------------
316 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
317 //-----------------------------------------------------------------
319 Int_t iSXFLD=gAlice->Field()->Integ();
320 Float_t sXMGMX=gAlice->Field()->Max();
322 Float_t amat[5]; // atomic numbers
323 Float_t zmat[5]; // z
324 Float_t wmat[5]; // proportions
330 //***************** Gases *************************
333 //--------------------------------------------------------------
334 // gases - air and CO2
335 //--------------------------------------------------------------
351 AliMixture(10,"CO2",amat,zmat,density,2,wmat);
366 AliMixture(11,"Air",amat,zmat,density,2,wmat);
368 //----------------------------------------------------------------
370 //----------------------------------------------------------------
373 // Drift gases 1 - nonsensitive, 2 - sensitive
374 // Ne-CO2-N (85-10-5)
393 AliMixture(12,"Ne-CO2-N-1",amat,zmat,density,4,wmat);
394 AliMixture(13,"Ne-CO2-N-2",amat,zmat,density,4,wmat);
395 AliMixture(30,"Ne-CO2-N-3",amat,zmat,density,4,wmat);
396 //----------------------------------------------------------------------
398 //----------------------------------------------------------------------
420 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
441 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
459 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
477 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
495 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
496 // material for "prepregs"
497 // Epoxy - C14 H20 O3
500 // prepreg1 60% C-fiber, 40% epoxy (vol)
515 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
517 //prepreg2 60% glass-fiber, 40% epoxy
536 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
538 //prepreg3 50% glass-fiber, 50% epoxy
557 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
559 // G10 60% SiO2 40% epoxy
578 AliMixture(22, "G10",amat,zmat,density,4,wmat);
587 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
589 // Si (for electronics
596 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
605 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
607 // Epoxy - C14 H20 O3
623 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
641 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
649 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
651 // Fe (steel for the inner heat screen)
659 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
661 // Peek - (C6H4-O-OC6H4-O-C6H4-CO)n
676 AliMixture(30,"Peek",amat,zmat,density,-3,wmat);
691 AliMixture(31,"Alumina",amat,zmat,density,-2,wmat);
710 AliMixture(32,"Water",amat,zmat,density,-2,wmat);
712 //----------------------------------------------------------
713 // tracking media for gases
714 //----------------------------------------------------------
716 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
717 AliMedium(1, "Ne-CO2-N-1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
718 AliMedium(2, "Ne-CO2-N-2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
719 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
720 AliMedium(20, "Ne-CO2-N-3", 30, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
721 //-----------------------------------------------------------
722 // tracking media for solids
723 //-----------------------------------------------------------
725 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
726 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
727 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
728 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
729 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
730 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
732 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
733 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
734 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
735 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
737 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
738 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
739 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
740 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
741 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
742 AliMedium(19,"Peek",30,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
743 AliMedium(21,"Alumina",31,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
744 AliMedium(22,"Water",32,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
747 void AliTPC::GenerNoise(Int_t tablesize)
750 //Generate table with noise
757 if (fNoiseTable) delete[] fNoiseTable;
758 fNoiseTable = new Float_t[tablesize];
759 fNoiseDepth = tablesize;
760 fCurrentNoise =0; //!index of the noise in the noise table
762 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
763 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
766 Float_t AliTPC::GetNoise()
768 // get noise from table
769 // if ((fCurrentNoise%10)==0)
770 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
771 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
772 return fNoiseTable[fCurrentNoise++];
773 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
777 Bool_t AliTPC::IsSectorActive(Int_t sec) const
780 // check if the sector is active
781 if (!fActiveSectors) return kTRUE;
782 else return fActiveSectors[sec];
785 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
787 // activate interesting sectors
788 SetTreeAddress();//just for security
789 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
790 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
791 for (Int_t i=0;i<n;i++)
792 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
796 void AliTPC::SetActiveSectors(Int_t flag)
799 // activate sectors which were hitted by tracks
801 SetTreeAddress();//just for security
802 if (fHitType==0) return; // if Clones hit - not short volume ID information
803 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
805 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
808 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
812 AliFatal("Can not find TreeH in folder");
815 if (fHitType>1) branch = TreeH()->GetBranch("TPC2");
816 else branch = TreeH()->GetBranch("TPC");
817 Stat_t ntracks = TreeH()->GetEntries();
818 // loop over all hits
819 AliDebug(1,Form("Got %d tracks",ntracks));
821 for(Int_t track=0;track<ntracks;track++) {
824 if (fTrackHits && fHitType&4) {
825 TBranch * br1 = TreeH()->GetBranch("fVolumes");
826 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
827 br1->GetEvent(track);
828 br2->GetEvent(track);
829 Int_t *volumes = fTrackHits->GetVolumes();
830 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++) {
831 if (volumes[j]>-1 && volumes[j]<fTPCParam->GetNSector()) {
832 fActiveSectors[volumes[j]]=kTRUE;
835 AliError(Form("Volume %d -> sector number %d is outside (0..%d)",
838 fTPCParam->GetNSector()));
844 // if (fTrackHitsOld && fHitType&2) {
845 // TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
846 // br->GetEvent(track);
847 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
848 // for (UInt_t j=0;j<ar->GetSize();j++){
849 // fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
858 //_____________________________________________________________________________
859 void AliTPC::Digits2Raw()
861 // convert digits of the current event to raw data
863 static const Int_t kThreshold = 0;
865 fLoader->LoadDigits();
866 TTree* digits = fLoader->TreeD();
868 AliError("No digits tree");
873 AliSimDigits* digrow = &digarr;
874 digits->GetBranch("Segment")->SetAddress(&digrow);
876 const char* fileName = "AliTPCDDL.dat";
877 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
881 // 2: txt files with digits
882 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
883 //it is highly suggested to use this mode only for debugging digits files
884 //reasonably small, because otherwise the size of the txt files can reach
885 //quickly several MB wasting time and disk space.
886 buffer->SetVerbose(0);
888 Int_t nEntries = Int_t(digits->GetEntries());
889 Int_t previousSector = -1;
891 for (Int_t i = 0; i < nEntries; i++) {
894 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
895 if(previousSector != sector) {
897 previousSector = sector;
900 if (sector < 36) { //inner sector [0;35]
902 //the whole row is written into the output file
903 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
904 sector, subSector, row);
906 //only the pads in the range [37;48] are written into the output file
907 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
908 sector, subSector, row);
910 //only the pads outside the range [37;48] are written into the output file
911 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
912 sector, subSector, row);
915 } else { //outer sector [36;71]
916 if (row == 54) subSector = 2;
917 if ((row != 27) && (row != 76)) {
918 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
919 sector, subSector, row);
920 } else if (row == 27) {
921 //only the pads outside the range [43;46] are written into the output file
922 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
923 sector, subSector, row);
925 //only the pads in the range [43;46] are written into the output file
926 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
927 sector, subSector, row);
928 } else if (row == 76) {
929 //only the pads outside the range [33;88] are written into the output file
930 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
931 sector, subSector, row);
933 //only the pads in the range [33;88] are written into the output file
934 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
935 sector, subSector, row);
941 fLoader->UnloadDigits();
943 AliTPCDDLRawData rawWriter;
944 rawWriter.SetVerbose(0);
946 rawWriter.RawData(fileName);
947 gSystem->Unlink(fileName);
952 //_____________________________________________________________________________
953 Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
954 // Converts the TPC raw data into summable digits
955 // The method is used for merging simulated and
957 if (fLoader->TreeS() == 0x0 ) {
958 fLoader->MakeTree("S");
961 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
963 //setup TPCDigitsArray
964 if(GetDigitsArray()) delete GetDigitsArray();
966 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
967 arr->SetClass("AliSimDigits");
968 arr->Setup(fTPCParam);
969 arr->MakeTree(fLoader->TreeS());
973 // set zero suppression to "0"
974 fTPCParam->SetZeroSup(0);
977 const Int_t kmaxTime = fTPCParam->GetMaxTBin();
978 const Int_t kNIS = fTPCParam->GetNInnerSector();
979 const Int_t kNOS = fTPCParam->GetNOuterSector();
980 const Int_t kNS = kNIS + kNOS;
982 Short_t** allBins = NULL; //array which contains the data for one sector
984 for(Int_t iSector = 0; iSector < kNS; iSector++) {
986 Int_t nRows = fTPCParam->GetNRow(iSector);
987 Int_t nDDLs = 0, indexDDL = 0;
988 if (iSector < kNIS) {
990 indexDDL = iSector * 2;
994 indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
997 // Loas the raw data for corresponding DDLs
999 AliTPCRawStream input(rawReader);
1000 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
1002 // Alocate and init the array with the sector data
1003 allBins = new Short_t*[nRows];
1004 for (Int_t iRow = 0; iRow < nRows; iRow++) {
1005 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1006 Int_t maxBin = kmaxTime*maxPad;
1007 allBins[iRow] = new Short_t[maxBin];
1008 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
1011 // Begin loop over altro data
1012 while (input.Next()) {
1014 if (input.GetSector() != iSector)
1015 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
1017 Int_t iRow = input.GetRow();
1018 if (iRow < 0 || iRow >= nRows)
1019 AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
1020 iRow, 0, nRows -1));
1021 Int_t iPad = input.GetPad();
1023 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1025 if (iPad < 0 || iPad >= maxPad)
1026 AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
1027 iPad, 0, maxPad -1));
1029 Int_t iTimeBin = input.GetTime();
1030 if ( iTimeBin < 0 || iTimeBin >= kmaxTime)
1031 AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
1032 iTimeBin, 0, kmaxTime -1));
1034 Int_t maxBin = kmaxTime*maxPad;
1036 if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
1037 ((iPad*kmaxTime+iTimeBin) < 0))
1038 AliFatal(Form("Index outside the allowed range"
1039 " Sector=%d Row=%d Pad=%d Timebin=%d"
1040 " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
1042 allBins[iRow][iPad*kmaxTime+iTimeBin] = input.GetSignal();
1044 } // End loop over altro data
1046 // Now fill the digits array
1047 if (fDigitsArray->GetTree()==0) {
1048 AliFatal("Tree not set in fDigitsArray");
1051 for (Int_t iRow = 0; iRow < nRows; iRow++) {
1052 AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
1054 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1055 for(Int_t iPad = 0; iPad < maxPad; iPad++) {
1056 for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
1057 Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
1058 if (q <= 0) continue;
1060 dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
1063 fDigitsArray->StoreRow(iSector,iRow);
1064 Int_t ndig = dig->GetDigitSize();
1067 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1068 iSector,iRow,ndig));
1070 fDigitsArray->ClearRow(iSector,iRow);
1072 } // end of the sector digitization
1074 for (Int_t iRow = 0; iRow < nRows; iRow++)
1075 delete [] allBins[iRow];
1081 fLoader->WriteSDigits("OVERWRITE");
1083 if(GetDigitsArray()) delete GetDigitsArray();
1084 SetDigitsArray(0x0);
1089 //______________________________________________________________________
1090 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
1092 return new AliTPCDigitizer(manager);
1095 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
1097 //create digits from summable digits
1098 GenerNoise(500000); //create teble with noise
1100 //conect tree with sSDigits
1101 TTree *t = fLoader->TreeS();
1104 fLoader->LoadSDigits("READ");
1105 t = fLoader->TreeS();
1107 AliError("Can not get input TreeS");
1112 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1114 AliSimDigits digarr, *dummy=&digarr;
1115 TBranch* sdb = t->GetBranch("Segment");
1117 AliError("Can not find branch with segments in TreeS.");
1121 sdb->SetAddress(&dummy);
1123 Stat_t nentries = t->GetEntries();
1125 // set zero suppression
1127 fTPCParam->SetZeroSup(2);
1129 // get zero suppression
1131 Int_t zerosup = fTPCParam->GetZeroSup();
1133 //make tree with digits
1135 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1136 arr->SetClass("AliSimDigits");
1137 arr->Setup(fTPCParam);
1138 arr->MakeTree(fLoader->TreeD());
1140 AliTPCParam * par = fTPCParam;
1142 //Loop over segments of the TPC
1144 for (Int_t n=0; n<nentries; n++) {
1147 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1148 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
1151 if (!IsSectorActive(sec)) continue;
1153 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1154 Int_t nrows = digrow->GetNRows();
1155 Int_t ncols = digrow->GetNCols();
1157 digrow->ExpandBuffer();
1158 digarr.ExpandBuffer();
1159 digrow->ExpandTrackBuffer();
1160 digarr.ExpandTrackBuffer();
1163 Short_t * pamp0 = digarr.GetDigits();
1164 Int_t * ptracks0 = digarr.GetTracks();
1165 Short_t * pamp1 = digrow->GetDigits();
1166 Int_t * ptracks1 = digrow->GetTracks();
1167 Int_t nelems =nrows*ncols;
1168 Int_t saturation = fTPCParam->GetADCSat() - 1;
1169 //use internal structure of the AliDigits - for speed reason
1170 //if you cahnge implementation
1171 //of the Alidigits - it must be rewriten -
1172 for (Int_t i= 0; i<nelems; i++){
1173 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1175 if (q>saturation) q=saturation;
1178 ptracks1[0]=ptracks0[0];
1179 ptracks1[nelems]=ptracks0[nelems];
1180 ptracks1[2*nelems]=ptracks0[2*nelems];
1188 arr->StoreRow(sec,row);
1189 arr->ClearRow(sec,row);
1194 fLoader->WriteDigits("OVERWRITE");
1198 //__________________________________________________________________
1199 void AliTPC::SetDefaults(){
1201 // setting the defaults
1204 // Set response functions
1207 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1209 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1211 // AliInfo("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...");
1213 // param = new AliTPCParamSR();
1216 // param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1218 param = (AliTPCParamSR*)AliTPCcalibDB::Instance()->GetParameters();
1219 if (!param->IsGeoRead()){
1221 // read transformation matrices for gGeoManager
1223 param->ReadGeoMatrices();
1226 AliFatal("No TPC parameters found");
1230 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1231 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1232 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1233 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1234 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1235 rf->SetOffset(3*param->GetZSigma());
1238 TDirectory *savedir=gDirectory;
1239 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1241 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1244 prfinner->Read("prf_07504_Gati_056068_d02");
1245 //PH Set different names
1246 s=prfinner->GetGRF()->GetName();
1248 prfinner->GetGRF()->SetName(s.Data());
1250 prfouter1->Read("prf_10006_Gati_047051_d03");
1251 s=prfouter1->GetGRF()->GetName();
1253 prfouter1->GetGRF()->SetName(s.Data());
1255 prfouter2->Read("prf_15006_Gati_047051_d03");
1256 s=prfouter2->GetGRF()->GetName();
1258 prfouter2->GetGRF()->SetName(s.Data());
1263 param->SetInnerPRF(prfinner);
1264 param->SetOuter1PRF(prfouter1);
1265 param->SetOuter2PRF(prfouter2);
1266 param->SetTimeRF(rf);
1276 //__________________________________________________________________
1277 void AliTPC::Hits2Digits()
1280 // creates digits from hits
1282 if (!fTPCParam->IsGeoRead()){
1284 // read transformation matrices for gGeoManager
1286 fTPCParam->ReadGeoMatrices();
1289 fLoader->LoadHits("read");
1290 fLoader->LoadDigits("recreate");
1291 AliRunLoader* runLoader = fLoader->GetRunLoader();
1293 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1294 //PH runLoader->GetEvent(iEvent);
1295 Hits2Digits(iEvent);
1298 fLoader->UnloadHits();
1299 fLoader->UnloadDigits();
1301 //__________________________________________________________________
1302 void AliTPC::Hits2Digits(Int_t eventnumber)
1304 //----------------------------------------------------
1305 // Loop over all sectors for a single event
1306 //----------------------------------------------------
1307 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1308 rl->GetEvent(eventnumber);
1310 if (fLoader->TreeH() == 0x0) {
1311 if(fLoader->LoadHits()) {
1312 AliError("Can not load hits.");
1317 if (fLoader->TreeD() == 0x0 ) {
1318 fLoader->MakeTree("D");
1319 if (fLoader->TreeD() == 0x0 ) {
1320 AliError("Can not get TreeD");
1325 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1326 GenerNoise(500000); //create teble with noise
1328 //setup TPCDigitsArray
1330 if(GetDigitsArray()) delete GetDigitsArray();
1332 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1333 arr->SetClass("AliSimDigits");
1334 arr->Setup(fTPCParam);
1336 arr->MakeTree(fLoader->TreeD());
1337 SetDigitsArray(arr);
1339 fDigitsSwitch=0; // standard digits
1341 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1342 if (IsSectorActive(isec)) {
1343 AliDebug(1,Form("Hits2Digits","Sector %d is active.",isec));
1344 Hits2DigitsSector(isec);
1347 AliDebug(1,Form("Hits2Digits","Sector %d is NOT active.",isec));
1350 fLoader->WriteDigits("OVERWRITE");
1352 //this line prevents the crash in the similar one
1353 //on the beginning of this method
1354 //destructor attempts to reset the tree, which is deleted by the loader
1355 //need to be redesign
1356 if(GetDigitsArray()) delete GetDigitsArray();
1357 SetDigitsArray(0x0);
1361 //__________________________________________________________________
1362 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1365 //-----------------------------------------------------------
1366 // summable digits - 16 bit "ADC", no noise, no saturation
1367 //-----------------------------------------------------------
1369 //----------------------------------------------------
1370 // Loop over all sectors for a single event
1371 //----------------------------------------------------
1373 AliRunLoader* rl = fLoader->GetRunLoader();
1375 rl->GetEvent(eventnumber);
1376 if (fLoader->TreeH() == 0x0) {
1377 if(fLoader->LoadHits()) {
1378 AliError("Can not load hits.");
1385 if (fLoader->TreeS() == 0x0 ) {
1386 fLoader->MakeTree("S");
1389 if(fDefaults == 0) SetDefaults();
1391 GenerNoise(500000); //create table with noise
1392 //setup TPCDigitsArray
1394 if(GetDigitsArray()) delete GetDigitsArray();
1397 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1398 arr->SetClass("AliSimDigits");
1399 arr->Setup(fTPCParam);
1400 arr->MakeTree(fLoader->TreeS());
1402 SetDigitsArray(arr);
1404 fDigitsSwitch=1; // summable digits
1406 // set zero suppression to "0"
1408 fTPCParam->SetZeroSup(0);
1410 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1411 if (IsSectorActive(isec)) {
1412 Hits2DigitsSector(isec);
1415 fLoader->WriteSDigits("OVERWRITE");
1417 //this line prevents the crash in the similar one
1418 //on the beginning of this method
1419 //destructor attempts to reset the tree, which is deleted by the loader
1420 //need to be redesign
1421 if(GetDigitsArray()) delete GetDigitsArray();
1422 SetDigitsArray(0x0);
1424 //__________________________________________________________________
1426 void AliTPC::Hits2SDigits()
1429 //-----------------------------------------------------------
1430 // summable digits - 16 bit "ADC", no noise, no saturation
1431 //-----------------------------------------------------------
1433 if (!fTPCParam->IsGeoRead()){
1435 // read transformation matrices for gGeoManager
1437 fTPCParam->ReadGeoMatrices();
1440 fLoader->LoadHits("read");
1441 fLoader->LoadSDigits("recreate");
1442 AliRunLoader* runLoader = fLoader->GetRunLoader();
1444 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1445 runLoader->GetEvent(iEvent);
1448 Hits2SDigits2(iEvent);
1451 fLoader->UnloadHits();
1452 fLoader->UnloadSDigits();
1454 //_____________________________________________________________________________
1456 void AliTPC::Hits2DigitsSector(Int_t isec)
1458 //-------------------------------------------------------------------
1459 // TPC conversion from hits to digits.
1460 //-------------------------------------------------------------------
1462 //-----------------------------------------------------------------
1463 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1464 //-----------------------------------------------------------------
1466 //-------------------------------------------------------
1467 // Get the access to the track hits
1468 //-------------------------------------------------------
1470 // check if the parameters are set - important if one calls this method
1471 // directly, not from the Hits2Digits
1473 if(fDefaults == 0) SetDefaults();
1475 TTree *tH = TreeH(); // pointer to the hits tree
1477 AliFatal("Can not find TreeH in folder");
1481 Stat_t ntracks = tH->GetEntries();
1485 //-------------------------------------------
1486 // Only if there are any tracks...
1487 //-------------------------------------------
1491 Int_t nrows =fTPCParam->GetNRow(isec);
1493 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1495 MakeSector(isec,nrows,tH,ntracks,row);
1497 //--------------------------------------------------------
1498 // Digitize this sector, row by row
1499 // row[i] is the pointer to the TObjArray of TVectors,
1500 // each one containing electrons accepted on this
1501 // row, assigned into tracks
1502 //--------------------------------------------------------
1506 if (fDigitsArray->GetTree()==0) {
1507 AliFatal("Tree not set in fDigitsArray");
1510 for (i=0;i<nrows;i++){
1512 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1514 DigitizeRow(i,isec,row);
1516 fDigitsArray->StoreRow(isec,i);
1518 Int_t ndig = dig->GetDigitSize();
1521 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1524 fDigitsArray->ClearRow(isec,i);
1527 } // end of the sector digitization
1529 for(i=0;i<nrows+2;i++){
1534 delete [] row; // delete the array of pointers to TObjArray-s
1538 } // end of Hits2DigitsSector
1541 //_____________________________________________________________________________
1542 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1544 //-----------------------------------------------------------
1545 // Single row digitization, coupling from the neighbouring
1546 // rows taken into account
1547 //-----------------------------------------------------------
1549 //-----------------------------------------------------------------
1550 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1551 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1552 //-----------------------------------------------------------------
1554 Float_t zerosup = fTPCParam->GetZeroSup();
1556 fCurrentIndex[1]= isec;
1559 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1560 Int_t nofTbins = fTPCParam->GetMaxTBin();
1561 Int_t indexRange[4];
1563 // Integrated signal for this row
1564 // and a single track signal
1567 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1568 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
1570 TMatrixF &total = *m1;
1572 // Array of pointers to the label-signal list
1574 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1575 Float_t **pList = new Float_t* [nofDigits];
1579 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1585 for (Int_t row= row1;row<=row2;row++){
1586 Int_t nTracks= rows[row]->GetEntries();
1587 for (i1=0;i1<nTracks;i1++){
1588 fCurrentIndex[2]= row;
1589 fCurrentIndex[3]=irow+1;
1591 m2->Zero(); // clear single track signal matrix
1592 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1593 GetList(trackLabel,nofPads,m2,indexRange,pList);
1595 else GetSignal(rows[row],i1,0,m1,indexRange);
1601 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1603 Float_t fzerosup = zerosup+0.5;
1604 for(Int_t it=0;it<nofTbins;it++){
1605 for(Int_t ip=0;ip<nofPads;ip++){
1607 Float_t q=total(ip,it);
1608 if(fDigitsSwitch == 0){
1610 if(q <=fzerosup) continue; // do not fill zeros
1612 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
1617 if(q <= 0.) continue; // do not fill zeros
1618 if(q>2000.) q=2000.;
1624 // "real" signal or electronic noise (list = -1)?
1627 for(Int_t j1=0;j1<3;j1++){
1628 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1633 <A NAME="AliDigits"></A>
1634 using of AliDigits object
1637 dig->SetDigitFast((Short_t)q,it,ip);
1638 if (fDigitsArray->IsSimulated()) {
1639 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1640 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1641 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1644 } // end of loop over time buckets
1645 } // end of lop over pads
1648 // This row has been digitized, delete nonused stuff
1651 for(lp=0;lp<nofDigits;lp++){
1652 if(pList[lp]) delete [] pList[lp];
1660 } // end of DigitizeRow
1662 //_____________________________________________________________________________
1664 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1665 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
1668 //---------------------------------------------------------------
1669 // Calculates 2-D signal (pad,time) for a single track,
1670 // returns a pointer to the signal matrix and the track label
1671 // No digitization is performed at this level!!!
1672 //---------------------------------------------------------------
1674 //-----------------------------------------------------------------
1675 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1676 // Modified: Marian Ivanov
1677 //-----------------------------------------------------------------
1681 tv = (TVector*)p1->At(ntr); // pointer to a track
1684 Float_t label = v(0);
1685 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
1687 Int_t nElectrons = (tv->GetNrows()-1)/5;
1688 indexRange[0]=9999; // min pad
1689 indexRange[1]=-1; // max pad
1690 indexRange[2]=9999; //min time
1691 indexRange[3]=-1; // max time
1693 TMatrixF &signal = *m1;
1694 TMatrixF &total = *m2;
1696 // Loop over all electrons
1698 for(Int_t nel=0; nel<nElectrons; nel++){
1700 Float_t aval = v(idx+4);
1701 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1702 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
1703 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1705 Int_t *index = fTPCParam->GetResBin(0);
1706 Float_t *weight = & (fTPCParam->GetResWeight(0));
1708 if (n>0) for (Int_t i =0; i<n; i++){
1709 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1712 Int_t time=index[2];
1713 Float_t qweight = *(weight)*eltoadcfac;
1715 if (m1!=0) signal(pad,time)+=qweight;
1716 total(pad,time)+=qweight;
1717 if (indexRange[0]>pad) indexRange[0]=pad;
1718 if (indexRange[1]<pad) indexRange[1]=pad;
1719 if (indexRange[2]>time) indexRange[2]=time;
1720 if (indexRange[3]<time) indexRange[3]=time;
1727 } // end of loop over electrons
1729 return label; // returns track label when finished
1732 //_____________________________________________________________________________
1733 void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
1734 Int_t *indexRange, Float_t **pList)
1736 //----------------------------------------------------------------------
1737 // Updates the list of tracks contributing to digits for a given row
1738 //----------------------------------------------------------------------
1740 //-----------------------------------------------------------------
1741 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1742 //-----------------------------------------------------------------
1744 TMatrixF &signal = *m;
1746 // lop over nonzero digits
1748 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1749 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1752 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1754 if(signal(ip,it)<0.5) continue;
1756 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1758 if(!pList[globalIndex]){
1761 // Create new list (6 elements - 3 signals and 3 labels),
1764 pList[globalIndex] = new Float_t [6];
1768 *pList[globalIndex] = -1.;
1769 *(pList[globalIndex]+1) = -1.;
1770 *(pList[globalIndex]+2) = -1.;
1771 *(pList[globalIndex]+3) = -1.;
1772 *(pList[globalIndex]+4) = -1.;
1773 *(pList[globalIndex]+5) = -1.;
1775 *pList[globalIndex] = label;
1776 *(pList[globalIndex]+3) = signal(ip,it);
1780 // check the signal magnitude
1782 Float_t highest = *(pList[globalIndex]+3);
1783 Float_t middle = *(pList[globalIndex]+4);
1784 Float_t lowest = *(pList[globalIndex]+5);
1787 // compare the new signal with already existing list
1790 if(signal(ip,it)<lowest) continue; // neglect this track
1794 if (signal(ip,it)>highest){
1795 *(pList[globalIndex]+5) = middle;
1796 *(pList[globalIndex]+4) = highest;
1797 *(pList[globalIndex]+3) = signal(ip,it);
1799 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1800 *(pList[globalIndex]+1) = *pList[globalIndex];
1801 *pList[globalIndex] = label;
1803 else if (signal(ip,it)>middle){
1804 *(pList[globalIndex]+5) = middle;
1805 *(pList[globalIndex]+4) = signal(ip,it);
1807 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1808 *(pList[globalIndex]+1) = label;
1811 *(pList[globalIndex]+5) = signal(ip,it);
1812 *(pList[globalIndex]+2) = label;
1816 } // end of loop over pads
1817 } // end of loop over time bins
1820 //___________________________________________________________________
1821 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1822 Stat_t ntracks,TObjArray **row)
1825 //-----------------------------------------------------------------
1826 // Prepares the sector digitization, creates the vectors of
1827 // tracks for each row of this sector. The track vector
1828 // contains the track label and the position of electrons.
1829 //-----------------------------------------------------------------
1832 // The trasport of the electrons through TPC drift volume
1833 // Drift (drift velocity + velocity map(not yet implemented)))
1834 // Application of the random processes (diffusion, gas gain)
1835 // Systematic effects (ExB effect in drift volume + ROCs)
1838 // Loop over primary electrons:
1839 // Creation of the secondary electrons
1840 // Loop over electrons (primary+ secondaries)
1841 // Global coordinate frame:
1842 // 1. Skip electrons if attached
1843 // 2. ExB effect in drift volume
1844 // a.) Simulation calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1845 // b.) Reconstruction - calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1846 // 3. Generation of gas gain (Random - Exponential distribution)
1847 // 4. TransportElectron function (diffusion)
1849 // 5. Conversion to the local coordinate frame pad-row, pad, timebin
1850 // 6. Apply Time0 shift - AliTPCCalPad class
1851 // a.) Plus sign in simulation
1852 // b.) Minus sign in reconstruction
1855 //-----------------------------------------------------------------
1856 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1857 // Origin: Marian Ivanov, marian.ivanov@cern.ch
1858 //-----------------------------------------------------------------
1859 AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
1860 if (gAlice){ // Set correctly the magnetic field in the ExB calculation
1861 AliMagF * field = gAlice->Field();
1863 calib->SetExBField(field->SolenoidField());
1867 Float_t gasgain = fTPCParam->GetGasGain();
1868 gasgain = gasgain/fGainFactor;
1872 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1875 if (fHitType>1) branch = TH->GetBranch("TPC2");
1876 else branch = TH->GetBranch("TPC");
1879 //----------------------------------------------
1880 // Create TObjArray-s, one for each row,
1881 // each TObjArray will store the TVectors
1882 // of electrons, one TVectors per each track.
1883 //----------------------------------------------
1885 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
1886 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
1888 for(i=0; i<nrows+2; i++){
1889 row[i] = new TObjArray;
1896 //--------------------------------------------------------------------
1897 // Loop over tracks, the "track" contains the full history
1898 //--------------------------------------------------------------------
1900 Int_t previousTrack,currentTrack;
1901 previousTrack = -1; // nothing to store so far!
1903 for(Int_t track=0;track<ntracks;track++){
1904 Bool_t isInSector=kTRUE;
1906 isInSector = TrackInVolume(isec,track);
1907 if (!isInSector) continue;
1909 branch->GetEntry(track); // get next track
1913 tpcHit = (AliTPChit*)FirstHit(-1);
1915 //--------------------------------------------------------------
1917 //--------------------------------------------------------------
1922 Int_t sector=tpcHit->fSector; // sector number
1924 tpcHit = (AliTPChit*) NextHit();
1928 // Remove hits which arrive before the TPC opening gate signal
1929 if(((fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
1930 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
1931 tpcHit = (AliTPChit*) NextHit();
1935 currentTrack = tpcHit->Track(); // track number
1937 if(currentTrack != previousTrack){
1939 // store already filled fTrack
1941 for(i=0;i<nrows+2;i++){
1942 if(previousTrack != -1){
1943 if(nofElectrons[i]>0){
1944 TVector &v = *tracks[i];
1945 v(0) = previousTrack;
1946 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
1947 row[i]->Add(tracks[i]);
1950 delete tracks[i]; // delete empty TVector
1956 tracks[i] = new TVector(601); // TVectors for the next fTrack
1958 } // end of loop over rows
1960 previousTrack=currentTrack; // update track label
1963 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1965 //---------------------------------------------------
1966 // Calculate the electron attachment probability
1967 //---------------------------------------------------
1970 Float_t time = 1.e6*(fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
1971 /fTPCParam->GetDriftV();
1973 Float_t attProb = fTPCParam->GetAttCoef()*
1974 fTPCParam->GetOxyCont()*time; // fraction!
1976 //-----------------------------------------------
1977 // Loop over electrons
1978 //-----------------------------------------------
1981 for(Int_t nel=0;nel<qI;nel++){
1982 // skip if electron lost due to the attachment
1983 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1988 Double_t dxyz0[3],dxyz1[3];
1989 dxyz0[0]=tpcHit->X();
1990 dxyz0[1]=tpcHit->Y();
1991 dxyz0[2]=tpcHit->Z();
1992 if (calib->GetExB()){
1993 calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1995 AliError("Not valid ExB calibration");
1996 dxyz1[0]=tpcHit->X();
1997 dxyz1[1]=tpcHit->Y();
1998 dxyz1[2]=tpcHit->Z();
2006 // protection for the nonphysical avalanche size (10**6 maximum)
2008 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2009 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2012 TransportElectron(xyz,index);
2014 fTPCParam->GetPadRow(xyz,index);
2016 // Add Time0 correction due unisochronity
2017 // xyz[0] - pad row coordinate
2018 // xyz[1] - pad coordinate
2019 // xyz[2] - is in now time bin coordinate system
2020 Float_t correction =0;
2021 if (calib->GetPadTime0()){
2022 if (!calib->GetPadTime0()->GetCalROC(isec)) continue;
2023 Int_t npads = fTPCParam->GetNPads(isec,TMath::Nint(xyz[0]));
2024 // Int_t pad = TMath::Nint(xyz[1]+fTPCParam->GetNPads(isec,TMath::Nint(xyz[0]))*0.5);
2025 Int_t pad = TMath::Nint(xyz[1]);
2027 if (pad>=npads) pad=npads-1;
2028 correction = calib->GetPadTime0()->GetCalROC(isec)->GetValue(TMath::Nint(xyz[0]),pad);
2032 xyz[2]+=fTPCParam->GetNTBinsL1(); // adding Level 1 time bin offset
2034 // Electron track time (for pileup simulation)
2035 xyz[2]+=tpcHit->Time()/fTPCParam->GetTSample(); // adding time of flight
2039 // row 0 - cross talk from the innermost row
2040 // row fNRow+1 cross talk from the outermost row
2041 rowNumber = index[2]+1;
2042 //transform position to local digit coordinates
2043 //relative to nearest pad row
2044 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
2046 if (isec <fTPCParam->GetNInnerSector()) {
2047 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2048 y1 = fTPCParam->GetYInner(rowNumber);
2051 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2052 y1 = fTPCParam->GetYOuter(rowNumber);
2054 // gain inefficiency at the wires edges - linear
2057 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.)); */
2059 nofElectrons[rowNumber]++;
2060 //----------------------------------
2061 // Expand vector if necessary
2062 //----------------------------------
2063 if(nofElectrons[rowNumber]>120){
2064 Int_t range = tracks[rowNumber]->GetNrows();
2065 if((nofElectrons[rowNumber])>(range-1)/5){
2067 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
2071 TVector &v = *tracks[rowNumber];
2072 Int_t idx = 5*nofElectrons[rowNumber]-4;
2073 Real_t * position = &(((TVector&)v)(idx)); //make code faster
2074 memcpy(position,xyz,5*sizeof(Float_t));
2076 } // end of loop over electrons
2078 tpcHit = (AliTPChit*)NextHit();
2080 } // end of loop over hits
2081 } // end of loop over tracks
2084 // store remaining track (the last one) if not empty
2087 for(i=0;i<nrows+2;i++){
2088 if(nofElectrons[i]>0){
2089 TVector &v = *tracks[i];
2090 v(0) = previousTrack;
2091 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2092 row[i]->Add(tracks[i]);
2101 delete [] nofElectrons;
2103 } // end of MakeSector
2106 //_____________________________________________________________________________
2110 // Initialise TPC detector after definition of geometry
2112 AliDebug(1,"*********************************************");
2115 //_____________________________________________________________________________
2116 void AliTPC::MakeBranch(Option_t* option)
2119 // Create Tree branches for the TPC.
2122 Int_t buffersize = 4000;
2123 char branchname[10];
2124 sprintf(branchname,"%s",GetName());
2126 const char *h = strstr(option,"H");
2128 if ( h && (fHitType<=1) && (fHits == 0x0)) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2130 AliDetector::MakeBranch(option);
2132 const char *d = strstr(option,"D");
2134 if (fDigits && fLoader->TreeD() && d) {
2135 MakeBranchInTree(gAlice->TreeD(), branchname, &fDigits, buffersize, 0);
2138 if (fHitType>1) MakeBranch2(option,0); // MI change 14.09.2000
2141 //_____________________________________________________________________________
2142 void AliTPC::ResetDigits()
2145 // Reset number of digits and the digits array for this detector
2148 if (fDigits) fDigits->Clear();
2153 //_____________________________________________________________________________
2154 void AliTPC::SetSens(Int_t sens)
2157 //-------------------------------------------------------------
2158 // Activates/deactivates the sensitive strips at the center of
2159 // the pad row -- this is for the space-point resolution calculations
2160 //-------------------------------------------------------------
2162 //-----------------------------------------------------------------
2163 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2164 //-----------------------------------------------------------------
2170 void AliTPC::SetSide(Float_t side=0.)
2172 // choice of the TPC side
2177 //_____________________________________________________________________________
2179 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2182 // electron transport taking into account:
2184 // 2.ExB at the wires
2185 // 3. nonisochronity
2187 // xyz and index must be already transformed to system 1
2190 fTPCParam->Transform1to2(xyz,index);
2193 Float_t driftl=xyz[2];
2194 if(driftl<0.01) driftl=0.01;
2195 driftl=TMath::Sqrt(driftl);
2196 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2197 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2198 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2199 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2200 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2204 if (fTPCParam->GetMWPCReadout()==kTRUE){
2205 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2206 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2208 //add nonisochronity (not implemented yet)
2214 //______________________________________________________________________
2215 AliTPChit::AliTPChit()
2227 //_____________________________________________________________________________
2228 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits)
2229 :AliHit(shunt,track),
2236 // Creates a TPC hit object
2247 //________________________________________________________________________
2248 // Additional code because of the AliTPCTrackHitsV2
2250 void AliTPC::MakeBranch2(Option_t *option,const char */*file*/)
2253 // Create a new branch in the current Root Tree
2254 // The branch of fHits is automatically split
2255 // MI change 14.09.2000
2257 if (fHitType<2) return;
2258 char branchname[10];
2259 sprintf(branchname,"%s2",GetName());
2261 // Get the pointer to the header
2262 const char *cH = strstr(option,"H");
2264 if (fTrackHits && TreeH() && cH && fHitType&4) {
2265 AliDebug(1,"Making branch for Type 4 Hits");
2266 TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2269 // if (fTrackHitsOld && TreeH() && cH && fHitType&2) {
2270 // AliDebug(1,"Making branch for Type 2 Hits");
2271 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2272 // TreeH(),fBufferSize,99);
2273 // TreeH()->GetListOfBranches()->Add(branch);
2277 void AliTPC::SetTreeAddress()
2279 //Sets tree address for hits
2281 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2282 AliDetector::SetTreeAddress();
2284 if (fHitType>1) SetTreeAddress2();
2287 void AliTPC::SetTreeAddress2()
2290 // Set branch address for the TrackHits Tree
2295 char branchname[20];
2296 sprintf(branchname,"%s2",GetName());
2298 // Branch address for hit tree
2299 TTree *treeH = TreeH();
2300 if ((treeH)&&(fHitType&4)) {
2301 branch = treeH->GetBranch(branchname);
2303 branch->SetAddress(&fTrackHits);
2304 AliDebug(1,"fHitType&4 Setting");
2307 AliDebug(1,"fHitType&4 Failed (can not find branch)");
2310 // if ((treeH)&&(fHitType&2)) {
2311 // branch = treeH->GetBranch(branchname);
2313 // branch->SetAddress(&fTrackHitsOld);
2314 // AliDebug(1,"fHitType&2 Setting");
2317 // AliDebug(1,"fHitType&2 Failed (can not find branch)");
2321 void AliTPC::FinishPrimary()
2323 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2324 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2328 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2331 // add hit to the list
2334 int primary = gAlice->GetMCApp()->GetPrimary(track);
2335 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2339 gAlice->GetMCApp()->FlagTrack(track);
2341 if (fTrackHits && fHitType&4)
2342 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2343 hits[1],hits[2],(Int_t)hits[3],hits[4]);
2344 // if (fTrackHitsOld &&fHitType&2 )
2345 // fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2346 // hits[1],hits[2],(Int_t)hits[3]);
2350 void AliTPC::ResetHits()
2352 if (fHitType&1) AliDetector::ResetHits();
2353 if (fHitType>1) ResetHits2();
2356 void AliTPC::ResetHits2()
2360 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2361 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2365 AliHit* AliTPC::FirstHit(Int_t track)
2367 if (fHitType>1) return FirstHit2(track);
2368 return AliDetector::FirstHit(track);
2370 AliHit* AliTPC::NextHit()
2375 if (fHitType>1) return NextHit2();
2377 return AliDetector::NextHit();
2380 AliHit* AliTPC::FirstHit2(Int_t track)
2383 // Initialise the hit iterator
2384 // Return the address of the first hit for track
2385 // If track>=0 the track is read from disk
2386 // while if track<0 the first hit of the current
2387 // track is returned
2390 gAlice->ResetHits();
2391 TreeH()->GetEvent(track);
2394 if (fTrackHits && fHitType&4) {
2395 fTrackHits->First();
2396 return fTrackHits->GetHit();
2398 // if (fTrackHitsOld && fHitType&2) {
2399 // fTrackHitsOld->First();
2400 // return fTrackHitsOld->GetHit();
2406 AliHit* AliTPC::NextHit2()
2409 //Return the next hit for the current track
2412 // if (fTrackHitsOld && fHitType&2) {
2413 // fTrackHitsOld->Next();
2414 // return fTrackHitsOld->GetHit();
2418 return fTrackHits->GetHit();
2424 void AliTPC::LoadPoints(Int_t)
2429 if(fHitType==1) AliDetector::LoadPoints(a);
2430 else LoadPoints2(a);
2434 void AliTPC::RemapTrackHitIDs(Int_t *map)
2439 if (!fTrackHits) return;
2441 // if (fTrackHitsOld && fHitType&2){
2442 // AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2443 // for (UInt_t i=0;i<arr->GetSize();i++){
2444 // AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2445 // info->fTrackID = map[info->fTrackID];
2448 // if (fTrackHitsOld && fHitType&4){
2449 if (fTrackHits && fHitType&4){
2450 TClonesArray * arr = fTrackHits->GetArray();;
2451 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2452 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2453 info->SetTrackID(map[info->GetTrackID()]);
2458 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2460 //return bool information - is track in given volume
2461 //load only part of the track information
2462 //return true if current track is in volume
2465 // if (fTrackHitsOld && fHitType&2) {
2466 // TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
2467 // br->GetEvent(track);
2468 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2469 // for (UInt_t j=0;j<ar->GetSize();j++){
2470 // if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2474 if (fTrackHits && fHitType&4) {
2475 TBranch * br1 = TreeH()->GetBranch("fVolumes");
2476 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
2477 br2->GetEvent(track);
2478 br1->GetEvent(track);
2479 Int_t *volumes = fTrackHits->GetVolumes();
2480 Int_t nvolumes = fTrackHits->GetNVolumes();
2481 if (!volumes && nvolumes>0) {
2482 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2485 for (Int_t j=0;j<nvolumes; j++)
2486 if (volumes[j]==id) return kTRUE;
2490 TBranch * br = TreeH()->GetBranch("fSector");
2491 br->GetEvent(track);
2492 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2493 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2500 //_____________________________________________________________________________
2501 void AliTPC::LoadPoints2(Int_t)
2504 // Store x, y, z of all hits in memory
2506 // if (fTrackHits == 0 && fTrackHitsOld==0) return;
2507 if (fTrackHits == 0 ) return;
2510 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2511 // if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2513 if (nhits == 0) return;
2514 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2515 if (fPoints == 0) fPoints = new TObjArray(tracks);
2518 Int_t *ntrk=new Int_t[tracks];
2519 Int_t *limi=new Int_t[tracks];
2520 Float_t **coor=new Float_t*[tracks];
2521 for(Int_t i=0;i<tracks;i++) {
2527 AliPoints *points = 0;
2530 Int_t chunk=nhits/4+1;
2532 // Loop over all the hits and store their position
2534 ahit = FirstHit2(-1);
2536 trk=ahit->GetTrack();
2537 if(ntrk[trk]==limi[trk]) {
2539 // Initialise a new track
2540 fp=new Float_t[3*(limi[trk]+chunk)];
2542 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2543 delete [] coor[trk];
2550 fp[3*ntrk[trk] ] = ahit->X();
2551 fp[3*ntrk[trk]+1] = ahit->Y();
2552 fp[3*ntrk[trk]+2] = ahit->Z();
2560 for(trk=0; trk<tracks; ++trk) {
2562 points = new AliPoints();
2563 points->SetMarkerColor(kYellow); //PH kYellow it the default in TPC
2564 points->SetMarkerSize(1);//PH Default size=1
2565 points->SetDetector(this);
2566 points->SetParticle(trk);
2567 points->SetPolyMarker(ntrk[trk],coor[trk],1); // Default style=1
2568 fPoints->AddAt(points,trk);
2569 delete [] coor[trk];
2579 //_____________________________________________________________________________
2580 void AliTPC::LoadPoints3(Int_t)
2583 // Store x, y, z of all hits in memory
2584 // - only intersection point with pad row
2585 if (fTrackHits == 0) return;
2587 Int_t nhits = fTrackHits->GetEntriesFast();
2588 if (nhits == 0) return;
2589 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2590 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2591 fPoints->Expand(2*tracks);
2594 Int_t *ntrk=new Int_t[tracks];
2595 Int_t *limi=new Int_t[tracks];
2596 Float_t **coor=new Float_t*[tracks];
2597 for(Int_t i=0;i<tracks;i++) {
2603 AliPoints *points = 0;
2606 Int_t chunk=nhits/4+1;
2608 // Loop over all the hits and store their position
2610 ahit = FirstHit2(-1);
2614 trk=ahit->GetTrack();
2615 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2616 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2617 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2618 if (currentrow!=lastrow){
2619 lastrow = currentrow;
2620 //later calculate intersection point
2621 if(ntrk[trk]==limi[trk]) {
2623 // Initialise a new track
2624 fp=new Float_t[3*(limi[trk]+chunk)];
2626 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2627 delete [] coor[trk];
2634 fp[3*ntrk[trk] ] = ahit->X();
2635 fp[3*ntrk[trk]+1] = ahit->Y();
2636 fp[3*ntrk[trk]+2] = ahit->Z();
2643 for(trk=0; trk<tracks; ++trk) {
2645 points = new AliPoints();
2646 points->SetMarkerColor(kMagenta); //PH kYellow + 1 is kMagenta
2647 points->SetMarkerStyle(5);
2648 points->SetMarkerSize(0.2);
2649 points->SetDetector(this);
2650 points->SetParticle(trk);
2651 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2652 fPoints->AddAt(points,tracks+trk);
2653 delete [] coor[trk];
2664 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2667 fLoader = new AliTPCLoader(GetName(),topfoldername);
2671 ////////////////////////////////////////////////////////////////////////
2672 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2674 // load TPC paarmeters from a given file or create new if the object
2675 // is not found there
2676 // 12/05/2003 This method should be moved to the AliTPCLoader
2677 // and one has to decide where to store the TPC parameters
2680 sprintf(paramName,"75x40_100x60_150x60");
2681 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2683 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2685 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2686 //paramTPC = new AliTPCParamSR;
2687 paramTPC = AliTPCcalibDB::Instance()->GetParameters();
2688 if (!paramTPC->IsGeoRead()){
2690 // read transformation matrices for gGeoManager
2692 paramTPC->ReadGeoMatrices();
2698 // the older version of parameters can be accessed with this code.
2699 // In some cases, we have old parameters saved in the file but
2700 // digits were created with new parameters, it can be distinguish
2701 // by the name of TPC TreeD. The code here is just for the case
2702 // we would need to compare with old data, uncomment it if needed.
2704 // char paramName[50];
2705 // sprintf(paramName,"75x40_100x60");
2706 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2708 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2710 // sprintf(paramName,"75x40_100x60_150x60");
2711 // paramTPC=(AliTPCParam*)in->Get(paramName);
2713 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2715 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2717 // paramTPC = new AliTPCParamSR;