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>
41 #include <TGeoGlobalMagField.h>
42 #include <TInterpreter.h>
45 #include <TObjectTable.h>
46 #include <TParticle.h>
49 #include <TStopwatch.h>
54 #include <TVirtualMC.h>
55 #include <TParameter.h>
57 #include "AliDigits.h"
60 #include "AliRunLoader.h"
61 #include "AliSimDigits.h"
64 #include "AliTPCDigitsArray.h"
65 #include "AliTPCLoader.h"
66 #include "AliTPCPRF2D.h"
67 #include "AliTPCParamSR.h"
68 #include "AliTPCRF1D.h"
69 #include "AliTPCTrackHitsV2.h"
70 #include "AliTrackReference.h"
73 #include "AliTPCDigitizer.h"
74 #include "AliTPCBuffer.h"
75 #include "AliTPCDDLRawData.h"
77 #include "AliTPCcalibDB.h"
78 #include "AliTPCCalPad.h"
79 #include "AliTPCCalROC.h"
80 #include "AliTPCExB.h"
81 #include "AliRawReader.h"
82 #include "AliTPCRawStream.h"
83 #include "TTreeStream.h"
86 //_____________________________________________________________________________
87 AliTPC::AliTPC():AliDetector(),
97 fPrimaryIonisation(0),
108 // Default constructor
112 // fTrackHitsOld = 0;
113 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
114 fHitType = 4; // ROOT containers
116 fHitType = 2; //default CONTAINERS - based on ROOT structure
120 //_____________________________________________________________________________
121 AliTPC::AliTPC(const char *name, const char *title)
122 : AliDetector(name,title),
132 fPrimaryIonisation(0),
143 // Standard constructor
147 // Initialise arrays of hits and digits
148 fHits = new TClonesArray("AliTPChit", 176);
149 gAlice->GetMCApp()->AddHitList(fHits);
151 fTrackHits = new AliTPCTrackHitsV2;
152 fTrackHits->SetHitPrecision(0.002);
153 fTrackHits->SetStepPrecision(0.003);
154 fTrackHits->SetMaxDistance(100);
156 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
157 //fTrackHitsOld->SetHitPrecision(0.002);
158 //fTrackHitsOld->SetStepPrecision(0.003);
159 //fTrackHitsOld->SetMaxDistance(100);
162 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
163 fHitType = 4; // ROOT containers
173 // Initialise color attributes
174 //PH SetMarkerColor(kYellow);
177 // Set TPC parameters
181 if (!strcmp(title,"Default")) {
182 //fTPCParam = new AliTPCParamSR;
183 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
185 AliWarning("In Config.C you must set non-default parameters.");
190 void AliTPC::CreateDebugStremer(){
192 // Create Debug streamer to check simulation
194 fDebugStreamer = new TTreeSRedirector("TPCSimdebug.root");
196 //_____________________________________________________________________________
207 delete fTrackHits; //MI 15.09.2000
208 // delete fTrackHitsOld; //MI 10.12.2001
211 delete [] fNoiseTable;
212 delete [] fActiveSectors;
213 if (fDebugStreamer) delete fDebugStreamer;
216 //_____________________________________________________________________________
217 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
220 // Add a hit to the list
223 TClonesArray &lhits = *fHits;
224 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
227 AddHit2(track,vol,hits);
230 //_____________________________________________________________________________
231 void AliTPC::CreateMaterials()
233 //-----------------------------------------------
234 // Create Materials for for TPC simulations
235 //-----------------------------------------------
237 //-----------------------------------------------------------------
238 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
239 //-----------------------------------------------------------------
241 Int_t iSXFLD=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
242 Float_t sXMGMX=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
244 Float_t amat[5]; // atomic numbers
245 Float_t zmat[5]; // z
246 Float_t wmat[5]; // proportions
252 //***************** Gases *************************
255 //--------------------------------------------------------------
256 // gases - air and CO2
257 //--------------------------------------------------------------
273 AliMixture(10,"CO2",amat,zmat,density,2,wmat);
288 AliMixture(11,"Air",amat,zmat,density,2,wmat);
290 //----------------------------------------------------------------
292 //----------------------------------------------------------------
295 // Drift gases 1 - nonsensitive, 2 - sensitive
296 // Ne-CO2-N2 (90-10-5) (volume) values at 20deg and 1 atm.
297 // rho(Ne) = 0.839 g/cm^3, rho(CO2) = 1.842 g/cm^3, rho(N2) = 1.165 g/cm^3
298 // for the calculation - everything is normalized to 1
317 AliMixture(12,"Ne-CO2-N-1",amat,zmat,density,4,wmat);
318 AliMixture(13,"Ne-CO2-N-2",amat,zmat,density,4,wmat);
319 AliMixture(30,"Ne-CO2-N-3",amat,zmat,density,4,wmat);
320 //----------------------------------------------------------------------
322 //----------------------------------------------------------------------
344 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
365 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
383 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
401 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
419 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
420 // material for "prepregs"
421 // Epoxy - C14 H20 O3
424 // prepreg1 60% C-fiber, 40% epoxy (vol)
439 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
441 //prepreg2 60% glass-fiber, 40% epoxy
460 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
462 //prepreg3 50% glass-fiber, 50% epoxy
481 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
483 // G10 60% SiO2 40% epoxy
502 AliMixture(22, "G10",amat,zmat,density,4,wmat);
511 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
513 // Si (for electronics
520 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
529 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
547 AliMixture(33,"Brass",amat,zmat,density,2,wmat);
549 // Epoxy - C14 H20 O3
565 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
567 // epoxy film - 90% epoxy, 10% glass fiber
587 AliMixture(34, "Epoxy-film",amat,zmat,density,4,wmat);
605 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
613 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
615 // Fe (steel for the inner heat screen)
623 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
625 // Peek - (C6H4-O-OC6H4-O-C6H4-CO)n
640 AliMixture(30,"Peek",amat,zmat,density,-3,wmat);
655 AliMixture(31,"Alumina",amat,zmat,density,-2,wmat);
674 AliMixture(32,"Water",amat,zmat,density,-2,wmat);
677 //----------------------------------------------------------
678 // tracking media for gases
679 //----------------------------------------------------------
681 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
682 AliMedium(1, "Ne-CO2-N-1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
683 AliMedium(2, "Ne-CO2-N-2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
684 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
685 AliMedium(20, "Ne-CO2-N-3", 30, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
686 //-----------------------------------------------------------
687 // tracking media for solids
688 //-----------------------------------------------------------
690 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
691 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
692 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
693 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
694 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
695 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
697 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
698 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
699 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
700 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
702 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
703 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
704 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
705 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
706 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
707 AliMedium(19,"Peek",30,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
708 AliMedium(21,"Alumina",31,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
709 AliMedium(22,"Water",32,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
710 AliMedium(23,"Brass",33,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
711 AliMedium(24,"Epoxyfm",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
714 void AliTPC::GenerNoise(Int_t tablesize)
717 //Generate table with noise
724 if (fNoiseTable) delete[] fNoiseTable;
725 fNoiseTable = new Float_t[tablesize];
726 fNoiseDepth = tablesize;
727 fCurrentNoise =0; //!index of the noise in the noise table
729 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
730 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
733 Float_t AliTPC::GetNoise()
735 // get noise from table
736 // if ((fCurrentNoise%10)==0)
737 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
738 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
739 return fNoiseTable[fCurrentNoise++];
740 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
744 Bool_t AliTPC::IsSectorActive(Int_t sec) const
747 // check if the sector is active
748 if (!fActiveSectors) return kTRUE;
749 else return fActiveSectors[sec];
752 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
754 // activate interesting sectors
755 SetTreeAddress();//just for security
756 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
757 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
758 for (Int_t i=0;i<n;i++)
759 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
763 void AliTPC::SetActiveSectors(Int_t flag)
766 // activate sectors which were hitted by tracks
768 SetTreeAddress();//just for security
769 if (fHitType==0) return; // if Clones hit - not short volume ID information
770 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
772 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
775 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
777 if (fLoader->TreeH() == 0x0)
779 AliFatal("Can not find TreeH in folder");
782 if (fHitType>1) branch = fLoader->TreeH()->GetBranch("TPC2");
783 else branch = fLoader->TreeH()->GetBranch("TPC");
784 Stat_t ntracks = fLoader->TreeH()->GetEntries();
785 // loop over all hits
786 AliDebug(1,Form("Got %d tracks", (Int_t) ntracks));
788 for(Int_t track=0;track<ntracks;track++) {
791 if (fTrackHits && fHitType&4) {
792 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
793 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
794 br1->GetEvent(track);
795 br2->GetEvent(track);
796 Int_t *volumes = fTrackHits->GetVolumes();
797 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++) {
798 if (volumes[j]>-1 && volumes[j]<fTPCParam->GetNSector()) {
799 fActiveSectors[volumes[j]]=kTRUE;
802 AliError(Form("Volume %d -> sector number %d is outside (0..%d)",
805 fTPCParam->GetNSector()));
811 // if (fTrackHitsOld && fHitType&2) {
812 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
813 // br->GetEvent(track);
814 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
815 // for (UInt_t j=0;j<ar->GetSize();j++){
816 // fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
825 //_____________________________________________________________________________
826 void AliTPC::Digits2Raw()
828 // convert digits of the current event to raw data
830 static const Int_t kThreshold = 0;
832 fLoader->LoadDigits();
833 TTree* digits = fLoader->TreeD();
835 AliError("No digits tree");
840 AliSimDigits* digrow = &digarr;
841 digits->GetBranch("Segment")->SetAddress(&digrow);
843 const char* fileName = "AliTPCDDL.dat";
844 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
848 // 2: txt files with digits
849 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
850 //it is highly suggested to use this mode only for debugging digits files
851 //reasonably small, because otherwise the size of the txt files can reach
852 //quickly several MB wasting time and disk space.
853 buffer->SetVerbose(0);
855 Int_t nEntries = Int_t(digits->GetEntries());
856 Int_t previousSector = -1;
858 for (Int_t i = 0; i < nEntries; i++) {
861 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
862 if(previousSector != sector) {
864 previousSector = sector;
867 if (sector < 36) { //inner sector [0;35]
869 //the whole row is written into the output file
870 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
871 sector, subSector, row);
873 //only the pads in the range [37;48] are written into the output file
874 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
875 sector, subSector, row);
877 //only the pads outside the range [37;48] are written into the output file
878 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
879 sector, subSector, row);
882 } else { //outer sector [36;71]
883 if (row == 54) subSector = 2;
884 if ((row != 27) && (row != 76)) {
885 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
886 sector, subSector, row);
887 } else if (row == 27) {
888 //only the pads outside the range [43;46] are written into the output file
889 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
890 sector, subSector, row);
892 //only the pads in the range [43;46] are written into the output file
893 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
894 sector, subSector, row);
895 } else if (row == 76) {
896 //only the pads outside the range [33;88] are written into the output file
897 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
898 sector, subSector, row);
900 //only the pads in the range [33;88] are written into the output file
901 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
902 sector, subSector, row);
908 fLoader->UnloadDigits();
910 AliTPCDDLRawData rawWriter;
911 rawWriter.SetVerbose(0);
913 rawWriter.RawData(fileName);
914 gSystem->Unlink(fileName);
919 //_____________________________________________________________________________
920 Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
921 // Converts the TPC raw data into summable digits
922 // The method is used for merging simulated and
924 if (fLoader->TreeS() == 0x0 ) {
925 fLoader->MakeTree("S");
928 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
930 //setup TPCDigitsArray
931 if(GetDigitsArray()) delete GetDigitsArray();
933 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
934 arr->SetClass("AliSimDigits");
935 arr->Setup(fTPCParam);
936 arr->MakeTree(fLoader->TreeS());
940 // set zero suppression to "0"
941 fTPCParam->SetZeroSup(0);
944 const Int_t kmaxTime = fTPCParam->GetMaxTBin();
945 const Int_t kNIS = fTPCParam->GetNInnerSector();
946 const Int_t kNOS = fTPCParam->GetNOuterSector();
947 const Int_t kNS = kNIS + kNOS;
949 Short_t** allBins = NULL; //array which contains the data for one sector
951 for(Int_t iSector = 0; iSector < kNS; iSector++) {
953 Int_t nRows = fTPCParam->GetNRow(iSector);
954 Int_t nDDLs = 0, indexDDL = 0;
955 if (iSector < kNIS) {
957 indexDDL = iSector * 2;
961 indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
964 // Loas the raw data for corresponding DDLs
966 AliTPCRawStream input(rawReader);
967 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
969 // Alocate and init the array with the sector data
970 allBins = new Short_t*[nRows];
971 for (Int_t iRow = 0; iRow < nRows; iRow++) {
972 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
973 Int_t maxBin = kmaxTime*maxPad;
974 allBins[iRow] = new Short_t[maxBin];
975 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
978 // Begin loop over altro data
979 while (input.Next()) {
981 if (input.GetSector() != iSector)
982 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
984 Int_t iRow = input.GetRow();
985 if (iRow < 0 || iRow >= nRows)
986 AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
988 Int_t iPad = input.GetPad();
990 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
992 if (iPad < 0 || iPad >= maxPad)
993 AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
994 iPad, 0, maxPad -1));
996 Int_t iTimeBin = input.GetTime();
997 if ( iTimeBin < 0 || iTimeBin >= kmaxTime)
998 AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
999 iTimeBin, 0, kmaxTime -1));
1001 Int_t maxBin = kmaxTime*maxPad;
1003 if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
1004 ((iPad*kmaxTime+iTimeBin) < 0))
1005 AliFatal(Form("Index outside the allowed range"
1006 " Sector=%d Row=%d Pad=%d Timebin=%d"
1007 " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
1009 allBins[iRow][iPad*kmaxTime+iTimeBin] = input.GetSignal();
1011 } // End loop over altro data
1013 // Now fill the digits array
1014 if (fDigitsArray->GetTree()==0) {
1015 AliFatal("Tree not set in fDigitsArray");
1018 for (Int_t iRow = 0; iRow < nRows; iRow++) {
1019 AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
1021 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1022 for(Int_t iPad = 0; iPad < maxPad; iPad++) {
1023 for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
1024 Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
1025 if (q <= 0) continue;
1027 dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
1030 fDigitsArray->StoreRow(iSector,iRow);
1031 Int_t ndig = dig->GetDigitSize();
1034 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1035 iSector,iRow,ndig));
1037 fDigitsArray->ClearRow(iSector,iRow);
1039 } // end of the sector digitization
1041 for (Int_t iRow = 0; iRow < nRows; iRow++)
1042 delete [] allBins[iRow];
1048 fLoader->WriteSDigits("OVERWRITE");
1050 if(GetDigitsArray()) delete GetDigitsArray();
1051 SetDigitsArray(0x0);
1056 //______________________________________________________________________
1057 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
1059 return new AliTPCDigitizer(manager);
1062 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
1064 //create digits from summable digits
1065 GenerNoise(500000); //create teble with noise
1067 //conect tree with sSDigits
1068 TTree *t = fLoader->TreeS();
1071 fLoader->LoadSDigits("READ");
1072 t = fLoader->TreeS();
1074 AliError("Can not get input TreeS");
1079 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1081 AliSimDigits digarr, *dummy=&digarr;
1082 TBranch* sdb = t->GetBranch("Segment");
1084 AliError("Can not find branch with segments in TreeS.");
1088 sdb->SetAddress(&dummy);
1090 Stat_t nentries = t->GetEntries();
1092 // set zero suppression
1094 fTPCParam->SetZeroSup(2);
1096 // get zero suppression
1098 Int_t zerosup = fTPCParam->GetZeroSup();
1100 //make tree with digits
1102 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1103 arr->SetClass("AliSimDigits");
1104 arr->Setup(fTPCParam);
1105 arr->MakeTree(fLoader->TreeD());
1107 AliTPCParam * par = fTPCParam;
1109 //Loop over segments of the TPC
1111 for (Int_t n=0; n<nentries; n++) {
1114 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1115 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
1118 if (!IsSectorActive(sec)) continue;
1120 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1121 Int_t nrows = digrow->GetNRows();
1122 Int_t ncols = digrow->GetNCols();
1124 digrow->ExpandBuffer();
1125 digarr.ExpandBuffer();
1126 digrow->ExpandTrackBuffer();
1127 digarr.ExpandTrackBuffer();
1130 Short_t * pamp0 = digarr.GetDigits();
1131 Int_t * ptracks0 = digarr.GetTracks();
1132 Short_t * pamp1 = digrow->GetDigits();
1133 Int_t * ptracks1 = digrow->GetTracks();
1134 Int_t nelems =nrows*ncols;
1135 Int_t saturation = fTPCParam->GetADCSat() - 1;
1136 //use internal structure of the AliDigits - for speed reason
1137 //if you cahnge implementation
1138 //of the Alidigits - it must be rewriten -
1139 for (Int_t i= 0; i<nelems; i++){
1140 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1142 if (q>saturation) q=saturation;
1145 ptracks1[0]=ptracks0[0];
1146 ptracks1[nelems]=ptracks0[nelems];
1147 ptracks1[2*nelems]=ptracks0[2*nelems];
1155 arr->StoreRow(sec,row);
1156 arr->ClearRow(sec,row);
1161 fLoader->WriteDigits("OVERWRITE");
1165 //__________________________________________________________________
1166 void AliTPC::SetDefaults(){
1168 // setting the defaults
1171 // Set response functions
1174 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1176 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1178 // AliInfo("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...");
1180 // param = new AliTPCParamSR();
1183 // param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1185 param = (AliTPCParamSR*)AliTPCcalibDB::Instance()->GetParameters();
1186 if (!param->IsGeoRead()){
1188 // read transformation matrices for gGeoManager
1190 param->ReadGeoMatrices();
1193 AliFatal("No TPC parameters found");
1197 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1198 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1199 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1202 //AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1203 //rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1204 //rf->SetOffset(3*param->GetZSigma());
1209 char strgamma4[1000];
1210 sprintf(strgamma4,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
1212 TF1 * fgamma4 = new TF1("fgamma4",strgamma4, -1,1);
1213 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE,1000);
1214 rf->SetParam(fgamma4,param->GetZWidth(), 1,0.2);
1215 rf->SetOffset(3*param->GetZSigma());
1218 TDirectory *savedir=gDirectory;
1219 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1221 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1224 prfinner->Read("prf_07504_Gati_056068_d02");
1225 //PH Set different names
1226 s=prfinner->GetGRF()->GetName();
1228 prfinner->GetGRF()->SetName(s.Data());
1230 prfouter1->Read("prf_10006_Gati_047051_d03");
1231 s=prfouter1->GetGRF()->GetName();
1233 prfouter1->GetGRF()->SetName(s.Data());
1235 prfouter2->Read("prf_15006_Gati_047051_d03");
1236 s=prfouter2->GetGRF()->GetName();
1238 prfouter2->GetGRF()->SetName(s.Data());
1243 param->SetInnerPRF(prfinner);
1244 param->SetOuter1PRF(prfouter1);
1245 param->SetOuter2PRF(prfouter2);
1246 param->SetTimeRF(rf);
1256 //__________________________________________________________________
1257 void AliTPC::Hits2Digits()
1260 // creates digits from hits
1262 if (!fTPCParam->IsGeoRead()){
1264 // read transformation matrices for gGeoManager
1266 fTPCParam->ReadGeoMatrices();
1269 fLoader->LoadHits("read");
1270 fLoader->LoadDigits("recreate");
1271 AliRunLoader* runLoader = fLoader->GetRunLoader();
1273 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1274 //PH runLoader->GetEvent(iEvent);
1275 Hits2Digits(iEvent);
1278 fLoader->UnloadHits();
1279 fLoader->UnloadDigits();
1281 //__________________________________________________________________
1282 void AliTPC::Hits2Digits(Int_t eventnumber)
1284 //----------------------------------------------------
1285 // Loop over all sectors for a single event
1286 //----------------------------------------------------
1287 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1288 rl->GetEvent(eventnumber);
1290 if (fLoader->TreeH() == 0x0) {
1291 if(fLoader->LoadHits()) {
1292 AliError("Can not load hits.");
1297 if (fLoader->TreeD() == 0x0 ) {
1298 fLoader->MakeTree("D");
1299 if (fLoader->TreeD() == 0x0 ) {
1300 AliError("Can not get TreeD");
1305 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1306 GenerNoise(500000); //create teble with noise
1308 //setup TPCDigitsArray
1310 if(GetDigitsArray()) delete GetDigitsArray();
1312 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1313 arr->SetClass("AliSimDigits");
1314 arr->Setup(fTPCParam);
1316 arr->MakeTree(fLoader->TreeD());
1317 SetDigitsArray(arr);
1319 fDigitsSwitch=0; // standard digits
1320 // here LHC clock phase
1322 switch (fLHCclockPhaseSw){
1329 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1333 // not implemented yet
1336 // adding phase to the TreeD user info
1337 fLoader->TreeD()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1339 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1340 if (IsSectorActive(isec)) {
1341 AliDebug(1,Form("Hits2Digits: Sector %d is active.",isec));
1342 Hits2DigitsSector(isec);
1345 AliDebug(1,Form("Hits2Digits: Sector %d is NOT active.",isec));
1348 fLoader->WriteDigits("OVERWRITE");
1350 //this line prevents the crash in the similar one
1351 //on the beginning of this method
1352 //destructor attempts to reset the tree, which is deleted by the loader
1353 //need to be redesign
1354 if(GetDigitsArray()) delete GetDigitsArray();
1355 SetDigitsArray(0x0);
1359 //__________________________________________________________________
1360 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1363 //-----------------------------------------------------------
1364 // summable digits - 16 bit "ADC", no noise, no saturation
1365 //-----------------------------------------------------------
1367 //----------------------------------------------------
1368 // Loop over all sectors for a single event
1369 //----------------------------------------------------
1371 AliRunLoader* rl = fLoader->GetRunLoader();
1373 rl->GetEvent(eventnumber);
1374 if (fLoader->TreeH() == 0x0) {
1375 if(fLoader->LoadHits()) {
1376 AliError("Can not load hits.");
1383 if (fLoader->TreeS() == 0x0 ) {
1384 fLoader->MakeTree("S");
1387 if(fDefaults == 0) SetDefaults();
1389 GenerNoise(500000); //create table with noise
1390 //setup TPCDigitsArray
1392 if(GetDigitsArray()) delete GetDigitsArray();
1395 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1396 arr->SetClass("AliSimDigits");
1397 arr->Setup(fTPCParam);
1398 arr->MakeTree(fLoader->TreeS());
1400 SetDigitsArray(arr);
1402 fDigitsSwitch=1; // summable digits
1404 // set zero suppression to "0"
1405 // here LHC clock phase
1407 switch (fLHCclockPhaseSw){
1414 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1418 // not implemented yet
1421 // adding phase to the TreeS user info
1423 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1425 fTPCParam->SetZeroSup(0);
1427 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1428 if (IsSectorActive(isec)) {
1429 Hits2DigitsSector(isec);
1432 fLoader->WriteSDigits("OVERWRITE");
1434 //this line prevents the crash in the similar one
1435 //on the beginning of this method
1436 //destructor attempts to reset the tree, which is deleted by the loader
1437 //need to be redesign
1438 if(GetDigitsArray()) delete GetDigitsArray();
1439 SetDigitsArray(0x0);
1441 //__________________________________________________________________
1443 void AliTPC::Hits2SDigits()
1446 //-----------------------------------------------------------
1447 // summable digits - 16 bit "ADC", no noise, no saturation
1448 //-----------------------------------------------------------
1450 if (!fTPCParam->IsGeoRead()){
1452 // read transformation matrices for gGeoManager
1454 fTPCParam->ReadGeoMatrices();
1457 fLoader->LoadHits("read");
1458 fLoader->LoadSDigits("recreate");
1459 AliRunLoader* runLoader = fLoader->GetRunLoader();
1461 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1462 runLoader->GetEvent(iEvent);
1465 Hits2SDigits2(iEvent);
1468 fLoader->UnloadHits();
1469 fLoader->UnloadSDigits();
1470 if (fDebugStreamer) {
1471 delete fDebugStreamer;
1475 //_____________________________________________________________________________
1477 void AliTPC::Hits2DigitsSector(Int_t isec)
1479 //-------------------------------------------------------------------
1480 // TPC conversion from hits to digits.
1481 //-------------------------------------------------------------------
1483 //-----------------------------------------------------------------
1484 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1485 //-----------------------------------------------------------------
1487 //-------------------------------------------------------
1488 // Get the access to the track hits
1489 //-------------------------------------------------------
1491 // check if the parameters are set - important if one calls this method
1492 // directly, not from the Hits2Digits
1494 if(fDefaults == 0) SetDefaults();
1496 TTree *tH = fLoader->TreeH(); // pointer to the hits tree
1498 AliFatal("Can not find TreeH in folder");
1502 Stat_t ntracks = tH->GetEntries();
1508 Int_t nrows =fTPCParam->GetNRow(isec);
1510 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1512 MakeSector(isec,nrows,tH,ntracks,row);
1514 //--------------------------------------------------------
1515 // Digitize this sector, row by row
1516 // row[i] is the pointer to the TObjArray of TVectors,
1517 // each one containing electrons accepted on this
1518 // row, assigned into tracks
1519 //--------------------------------------------------------
1523 if (fDigitsArray->GetTree()==0) {
1524 AliFatal("Tree not set in fDigitsArray");
1527 for (i=0;i<nrows;i++){
1529 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1531 DigitizeRow(i,isec,row);
1533 fDigitsArray->StoreRow(isec,i);
1535 Int_t ndig = dig->GetDigitSize();
1538 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1541 fDigitsArray->ClearRow(isec,i);
1544 } // end of the sector digitization
1546 for(i=0;i<nrows+2;i++){
1551 delete [] row; // delete the array of pointers to TObjArray-s
1554 } // end of Hits2DigitsSector
1557 //_____________________________________________________________________________
1558 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1560 //-----------------------------------------------------------
1561 // Single row digitization, coupling from the neighbouring
1562 // rows taken into account
1563 //-----------------------------------------------------------
1565 //-----------------------------------------------------------------
1566 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1567 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1568 //-----------------------------------------------------------------
1570 Float_t zerosup = fTPCParam->GetZeroSup();
1571 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
1572 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
1573 AliTPCCalROC * gainROC = gainTPC->GetCalROC(isec); // pad gains per given sector
1574 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(isec); // noise per given sector
1577 fCurrentIndex[1]= isec;
1580 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1581 Int_t nofTbins = fTPCParam->GetMaxTBin();
1582 Int_t indexRange[4];
1584 // Integrated signal for this row
1585 // and a single track signal
1588 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1589 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
1591 TMatrixF &total = *m1;
1593 // Array of pointers to the label-signal list
1595 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1596 Float_t **pList = new Float_t* [nofDigits];
1600 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1606 for (Int_t row= row1;row<=row2;row++){
1607 Int_t nTracks= rows[row]->GetEntries();
1608 for (i1=0;i1<nTracks;i1++){
1609 fCurrentIndex[2]= row;
1610 fCurrentIndex[3]=irow+1;
1612 m2->Zero(); // clear single track signal matrix
1613 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1614 GetList(trackLabel,nofPads,m2,indexRange,pList);
1616 else GetSignal(rows[row],i1,0,m1,indexRange);
1622 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1624 Float_t fzerosup = zerosup+0.5;
1625 for(Int_t it=0;it<nofTbins;it++){
1626 for(Int_t ip=0;ip<nofPads;ip++){
1628 Float_t q=total(ip,it);
1629 if(fDigitsSwitch == 0){
1630 Float_t gain = gainROC->GetValue(irow,ip); // get gain for given - pad-row pad
1631 Float_t noisePad = noiseROC->GetValue(irow,ip);
1634 q+=GetNoise()*noisePad;
1635 if(q <=fzerosup) continue; // do not fill zeros
1637 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
1642 if(q <= 0.) continue; // do not fill zeros
1643 if(q>2000.) q=2000.;
1649 // "real" signal or electronic noise (list = -1)?
1652 for(Int_t j1=0;j1<3;j1++){
1653 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1658 <A NAME="AliDigits"></A>
1659 using of AliDigits object
1662 dig->SetDigitFast((Short_t)q,it,ip);
1663 if (fDigitsArray->IsSimulated()) {
1664 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1665 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1666 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1669 } // end of loop over time buckets
1670 } // end of lop over pads
1676 // glitch filters if normal simulated digits
1678 if(!fDigitsSwitch) ((AliSimDigits*)dig)->GlitchFilter();
1680 // This row has been digitized, delete nonused stuff
1683 for(lp=0;lp<nofDigits;lp++){
1684 if(pList[lp]) delete [] pList[lp];
1692 } // end of DigitizeRow
1694 //_____________________________________________________________________________
1696 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1697 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
1700 //---------------------------------------------------------------
1701 // Calculates 2-D signal (pad,time) for a single track,
1702 // returns a pointer to the signal matrix and the track label
1703 // No digitization is performed at this level!!!
1704 //---------------------------------------------------------------
1706 //-----------------------------------------------------------------
1707 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1708 // Modified: Marian Ivanov
1709 //-----------------------------------------------------------------
1713 tv = (TVector*)p1->At(ntr); // pointer to a track
1716 Float_t label = v(0);
1717 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
1719 Int_t nElectrons = (tv->GetNrows()-1)/5;
1720 indexRange[0]=9999; // min pad
1721 indexRange[1]=-1; // max pad
1722 indexRange[2]=9999; //min time
1723 indexRange[3]=-1; // max time
1725 TMatrixF &signal = *m1;
1726 TMatrixF &total = *m2;
1728 // Get LHC clock phase
1730 TParameter<float> *ph;
1731 if(fDigitsSwitch){// s-digits
1732 ph = (TParameter<float>*)fLoader->TreeS()->GetUserInfo()->FindObject("lhcphase0");
1734 else{ // normal digits
1735 ph = (TParameter<float>*)fLoader->TreeD()->GetUserInfo()->FindObject("lhcphase0");
1737 // Loop over all electrons
1739 for(Int_t nel=0; nel<nElectrons; nel++){
1741 Float_t aval = v(idx+4);
1742 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1743 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
1744 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,
1745 fCurrentIndex[3],ph->GetVal());
1747 Int_t *index = fTPCParam->GetResBin(0);
1748 Float_t *weight = & (fTPCParam->GetResWeight(0));
1750 if (n>0) for (Int_t i =0; i<n; i++){
1751 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1754 Int_t time=index[2];
1755 Float_t qweight = *(weight)*eltoadcfac;
1757 if (m1!=0) signal(pad,time)+=qweight;
1758 total(pad,time)+=qweight;
1759 if (indexRange[0]>pad) indexRange[0]=pad;
1760 if (indexRange[1]<pad) indexRange[1]=pad;
1761 if (indexRange[2]>time) indexRange[2]=time;
1762 if (indexRange[3]<time) indexRange[3]=time;
1769 } // end of loop over electrons
1771 return label; // returns track label when finished
1774 //_____________________________________________________________________________
1775 void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
1776 Int_t *indexRange, Float_t **pList)
1778 //----------------------------------------------------------------------
1779 // Updates the list of tracks contributing to digits for a given row
1780 //----------------------------------------------------------------------
1782 //-----------------------------------------------------------------
1783 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1784 //-----------------------------------------------------------------
1786 TMatrixF &signal = *m;
1788 // lop over nonzero digits
1790 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1791 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1794 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1796 if(signal(ip,it)<0.5) continue;
1798 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1800 if(!pList[globalIndex]){
1803 // Create new list (6 elements - 3 signals and 3 labels),
1806 pList[globalIndex] = new Float_t [6];
1810 *pList[globalIndex] = -1.;
1811 *(pList[globalIndex]+1) = -1.;
1812 *(pList[globalIndex]+2) = -1.;
1813 *(pList[globalIndex]+3) = -1.;
1814 *(pList[globalIndex]+4) = -1.;
1815 *(pList[globalIndex]+5) = -1.;
1817 *pList[globalIndex] = label;
1818 *(pList[globalIndex]+3) = signal(ip,it);
1822 // check the signal magnitude
1824 Float_t highest = *(pList[globalIndex]+3);
1825 Float_t middle = *(pList[globalIndex]+4);
1826 Float_t lowest = *(pList[globalIndex]+5);
1829 // compare the new signal with already existing list
1832 if(signal(ip,it)<lowest) continue; // neglect this track
1836 if (signal(ip,it)>highest){
1837 *(pList[globalIndex]+5) = middle;
1838 *(pList[globalIndex]+4) = highest;
1839 *(pList[globalIndex]+3) = signal(ip,it);
1841 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1842 *(pList[globalIndex]+1) = *pList[globalIndex];
1843 *pList[globalIndex] = label;
1845 else if (signal(ip,it)>middle){
1846 *(pList[globalIndex]+5) = middle;
1847 *(pList[globalIndex]+4) = signal(ip,it);
1849 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1850 *(pList[globalIndex]+1) = label;
1853 *(pList[globalIndex]+5) = signal(ip,it);
1854 *(pList[globalIndex]+2) = label;
1858 } // end of loop over pads
1859 } // end of loop over time bins
1862 //___________________________________________________________________
1863 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1864 Stat_t ntracks,TObjArray **row)
1867 //-----------------------------------------------------------------
1868 // Prepares the sector digitization, creates the vectors of
1869 // tracks for each row of this sector. The track vector
1870 // contains the track label and the position of electrons.
1871 //-----------------------------------------------------------------
1874 // The trasport of the electrons through TPC drift volume
1875 // Drift (drift velocity + velocity map(not yet implemented)))
1876 // Application of the random processes (diffusion, gas gain)
1877 // Systematic effects (ExB effect in drift volume + ROCs)
1880 // Loop over primary electrons:
1881 // Creation of the secondary electrons
1882 // Loop over electrons (primary+ secondaries)
1883 // Global coordinate frame:
1884 // 1. Skip electrons if attached
1885 // 2. ExB effect in drift volume
1886 // a.) Simulation calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1887 // b.) Reconstruction - calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1888 // 3. Generation of gas gain (Random - Exponential distribution)
1889 // 4. TransportElectron function (diffusion)
1891 // 5. Conversion to the local coordinate frame pad-row, pad, timebin
1892 // 6. Apply Time0 shift - AliTPCCalPad class
1893 // a.) Plus sign in simulation
1894 // b.) Minus sign in reconstruction
1897 //-----------------------------------------------------------------
1898 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1899 // Origin: Marian Ivanov, marian.ivanov@cern.ch
1900 //-----------------------------------------------------------------
1901 AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
1902 if (gAlice){ // Set correctly the magnetic field in the ExB calculation
1903 if (!calib->GetExB()){
1904 AliMagF * field = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField());
1906 calib->SetExBField(field);
1911 Float_t gasgain = fTPCParam->GetGasGain();
1912 gasgain = gasgain/fGainFactor;
1916 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1919 if (fHitType>1) branch = TH->GetBranch("TPC2");
1920 else branch = TH->GetBranch("TPC");
1923 //----------------------------------------------
1924 // Create TObjArray-s, one for each row,
1925 // each TObjArray will store the TVectors
1926 // of electrons, one TVectors per each track.
1927 //----------------------------------------------
1929 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
1930 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
1932 for(i=0; i<nrows+2; i++){
1933 row[i] = new TObjArray;
1940 //--------------------------------------------------------------------
1941 // Loop over tracks, the "track" contains the full history
1942 //--------------------------------------------------------------------
1944 Int_t previousTrack,currentTrack;
1945 previousTrack = -1; // nothing to store so far!
1947 for(Int_t track=0;track<ntracks;track++){
1948 Bool_t isInSector=kTRUE;
1950 isInSector = TrackInVolume(isec,track);
1951 if (!isInSector) continue;
1953 branch->GetEntry(track); // get next track
1957 tpcHit = (AliTPChit*)FirstHit(-1);
1959 //--------------------------------------------------------------
1961 //--------------------------------------------------------------
1966 Int_t sector=tpcHit->fSector; // sector number
1968 tpcHit = (AliTPChit*) NextHit();
1972 // Remove hits which arrive before the TPC opening gate signal
1973 if(((fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
1974 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
1975 tpcHit = (AliTPChit*) NextHit();
1979 currentTrack = tpcHit->Track(); // track number
1981 if(currentTrack != previousTrack){
1983 // store already filled fTrack
1985 for(i=0;i<nrows+2;i++){
1986 if(previousTrack != -1){
1987 if(nofElectrons[i]>0){
1988 TVector &v = *tracks[i];
1989 v(0) = previousTrack;
1990 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
1991 row[i]->Add(tracks[i]);
1994 delete tracks[i]; // delete empty TVector
2000 tracks[i] = new TVector(601); // TVectors for the next fTrack
2002 } // end of loop over rows
2004 previousTrack=currentTrack; // update track label
2007 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2009 //---------------------------------------------------
2010 // Calculate the electron attachment probability
2011 //---------------------------------------------------
2014 Float_t time = 1.e6*(fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
2015 /fTPCParam->GetDriftV();
2017 Float_t attProb = fTPCParam->GetAttCoef()*
2018 fTPCParam->GetOxyCont()*time; // fraction!
2020 //-----------------------------------------------
2021 // Loop over electrons
2022 //-----------------------------------------------
2025 for(Int_t nel=0;nel<qI;nel++){
2026 // skip if electron lost due to the attachment
2027 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2032 Double_t dxyz0[3],dxyz1[3];
2033 dxyz0[0]=tpcHit->X();
2034 dxyz0[1]=tpcHit->Y();
2035 dxyz0[2]=tpcHit->Z();
2036 if (calib->GetExB()){
2037 calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
2039 AliError("Not valid ExB calibration");
2040 dxyz1[0]=tpcHit->X();
2041 dxyz1[1]=tpcHit->Y();
2042 dxyz1[2]=tpcHit->Z();
2050 // protection for the nonphysical avalanche size (10**6 maximum)
2052 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2053 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2056 TransportElectron(xyz,index);
2058 Int_t padrow = fTPCParam->GetPadRow(xyz,index);
2060 // Add Time0 correction due unisochronity
2061 // xyz[0] - pad row coordinate
2062 // xyz[1] - pad coordinate
2063 // xyz[2] - is in now time bin coordinate system
2064 Float_t correction =0;
2065 if (calib->GetPadTime0()){
2066 if (!calib->GetPadTime0()->GetCalROC(isec)) continue;
2067 Int_t npads = fTPCParam->GetNPads(isec,padrow);
2068 // Int_t pad = TMath::Nint(xyz[1]+fTPCParam->GetNPads(isec,TMath::Nint(xyz[0]))*0.5);
2069 // pad numbering from -npads/2 .. npads/2-1
2070 Int_t pad = TMath::Nint(xyz[1]+npads/2);
2072 if (pad>=npads) pad=npads-1;
2073 correction = calib->GetPadTime0()->GetCalROC(isec)->GetValue(padrow,pad);
2074 // printf("%d\t%d\t%d\t%f\n",isec,padrow,pad,correction);
2075 if (fDebugStreamer){
2076 (*fDebugStreamer)<<"Time0"<<
2084 "cor="<<correction<<
2089 xyz[2]+=fTPCParam->GetNTBinsL1(); // adding Level 1 time bin offset
2091 // Electron track time (for pileup simulation)
2092 xyz[2]+=tpcHit->Time()/fTPCParam->GetTSample(); // adding time of flight
2096 // row 0 - cross talk from the innermost row
2097 // row fNRow+1 cross talk from the outermost row
2098 rowNumber = index[2]+1;
2099 //transform position to local digit coordinates
2100 //relative to nearest pad row
2101 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
2103 if (isec <fTPCParam->GetNInnerSector()) {
2104 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2105 y1 = fTPCParam->GetYInner(rowNumber);
2108 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2109 y1 = fTPCParam->GetYOuter(rowNumber);
2111 // gain inefficiency at the wires edges - linear
2114 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.)); */
2116 nofElectrons[rowNumber]++;
2117 //----------------------------------
2118 // Expand vector if necessary
2119 //----------------------------------
2120 if(nofElectrons[rowNumber]>120){
2121 Int_t range = tracks[rowNumber]->GetNrows();
2122 if((nofElectrons[rowNumber])>(range-1)/5){
2124 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
2128 TVector &v = *tracks[rowNumber];
2129 Int_t idx = 5*nofElectrons[rowNumber]-4;
2130 Real_t * position = &(((TVector&)v)(idx)); //make code faster
2131 memcpy(position,xyz,5*sizeof(Float_t));
2133 } // end of loop over electrons
2135 tpcHit = (AliTPChit*)NextHit();
2137 } // end of loop over hits
2138 } // end of loop over tracks
2141 // store remaining track (the last one) if not empty
2144 for(i=0;i<nrows+2;i++){
2145 if(nofElectrons[i]>0){
2146 TVector &v = *tracks[i];
2147 v(0) = previousTrack;
2148 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2149 row[i]->Add(tracks[i]);
2158 delete [] nofElectrons;
2160 } // end of MakeSector
2163 //_____________________________________________________________________________
2167 // Initialise TPC detector after definition of geometry
2169 AliDebug(1,"*********************************************");
2172 //_____________________________________________________________________________
2173 void AliTPC::ResetDigits()
2176 // Reset number of digits and the digits array for this detector
2179 if (fDigits) fDigits->Clear();
2184 //_____________________________________________________________________________
2185 void AliTPC::SetSens(Int_t sens)
2188 //-------------------------------------------------------------
2189 // Activates/deactivates the sensitive strips at the center of
2190 // the pad row -- this is for the space-point resolution calculations
2191 //-------------------------------------------------------------
2193 //-----------------------------------------------------------------
2194 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2195 //-----------------------------------------------------------------
2201 void AliTPC::SetSide(Float_t side=0.)
2203 // choice of the TPC side
2208 //_____________________________________________________________________________
2210 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2213 // electron transport taking into account:
2215 // 2.ExB at the wires
2216 // 3. nonisochronity
2218 // xyz and index must be already transformed to system 1
2221 fTPCParam->Transform1to2(xyz,index); // mis-alignment applied in this step
2224 Float_t driftl=xyz[2];
2225 if(driftl<0.01) driftl=0.01;
2226 driftl=TMath::Sqrt(driftl);
2227 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2228 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2229 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2230 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2231 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2235 if (fTPCParam->GetMWPCReadout()==kTRUE){
2236 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2237 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2239 //add nonisochronity (not implemented yet)
2245 //______________________________________________________________________
2246 AliTPChit::AliTPChit()
2258 //_____________________________________________________________________________
2259 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits)
2260 :AliHit(shunt,track),
2267 // Creates a TPC hit object
2278 //________________________________________________________________________
2279 // Additional code because of the AliTPCTrackHitsV2
2281 void AliTPC::MakeBranch(Option_t *option)
2284 // Create a new branch in the current Root Tree
2285 // The branch of fHits is automatically split
2286 // MI change 14.09.2000
2288 if (fHitType<2) return;
2289 char branchname[10];
2290 sprintf(branchname,"%s2",GetName());
2292 // Get the pointer to the header
2293 const char *cH = strstr(option,"H");
2295 if (fTrackHits && fLoader->TreeH() && cH && fHitType&4) {
2296 AliDebug(1,"Making branch for Type 4 Hits");
2297 fLoader->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2300 // if (fTrackHitsOld && fLoader->TreeH() && cH && fHitType&2) {
2301 // AliDebug(1,"Making branch for Type 2 Hits");
2302 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2303 // fLoader->TreeH(),fBufferSize,99);
2304 // fLoader->TreeH()->GetListOfBranches()->Add(branch);
2308 void AliTPC::SetTreeAddress()
2310 //Sets tree address for hits
2312 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2313 AliDetector::SetTreeAddress();
2315 if (fHitType>1) SetTreeAddress2();
2318 void AliTPC::SetTreeAddress2()
2321 // Set branch address for the TrackHits Tree
2326 char branchname[20];
2327 sprintf(branchname,"%s2",GetName());
2329 // Branch address for hit tree
2330 TTree *treeH = fLoader->TreeH();
2331 if ((treeH)&&(fHitType&4)) {
2332 branch = treeH->GetBranch(branchname);
2334 branch->SetAddress(&fTrackHits);
2335 AliDebug(1,"fHitType&4 Setting");
2338 AliDebug(1,"fHitType&4 Failed (can not find branch)");
2341 // if ((treeH)&&(fHitType&2)) {
2342 // branch = treeH->GetBranch(branchname);
2344 // branch->SetAddress(&fTrackHitsOld);
2345 // AliDebug(1,"fHitType&2 Setting");
2348 // AliDebug(1,"fHitType&2 Failed (can not find branch)");
2352 void AliTPC::FinishPrimary()
2354 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2355 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2359 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2362 // add hit to the list
2366 int primary = gAlice->GetMCApp()->GetPrimary(track);
2367 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2371 gAlice->GetMCApp()->FlagTrack(track);
2373 if (fTrackHits && fHitType&4)
2374 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2375 hits[1],hits[2],(Int_t)hits[3],hits[4]);
2376 // if (fTrackHitsOld &&fHitType&2 )
2377 // fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2378 // hits[1],hits[2],(Int_t)hits[3]);
2382 void AliTPC::ResetHits()
2384 if (fHitType&1) AliDetector::ResetHits();
2385 if (fHitType>1) ResetHits2();
2388 void AliTPC::ResetHits2()
2392 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2393 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2397 AliHit* AliTPC::FirstHit(Int_t track)
2399 if (fHitType>1) return FirstHit2(track);
2400 return AliDetector::FirstHit(track);
2402 AliHit* AliTPC::NextHit()
2407 if (fHitType>1) return NextHit2();
2409 return AliDetector::NextHit();
2412 AliHit* AliTPC::FirstHit2(Int_t track)
2415 // Initialise the hit iterator
2416 // Return the address of the first hit for track
2417 // If track>=0 the track is read from disk
2418 // while if track<0 the first hit of the current
2419 // track is returned
2422 gAlice->GetMCApp()->ResetHits();
2423 fLoader->TreeH()->GetEvent(track);
2426 if (fTrackHits && fHitType&4) {
2427 fTrackHits->First();
2428 return fTrackHits->GetHit();
2430 // if (fTrackHitsOld && fHitType&2) {
2431 // fTrackHitsOld->First();
2432 // return fTrackHitsOld->GetHit();
2438 AliHit* AliTPC::NextHit2()
2441 //Return the next hit for the current track
2444 // if (fTrackHitsOld && fHitType&2) {
2445 // fTrackHitsOld->Next();
2446 // return fTrackHitsOld->GetHit();
2450 return fTrackHits->GetHit();
2456 void AliTPC::RemapTrackHitIDs(Int_t *map)
2461 if (!fTrackHits) return;
2463 // if (fTrackHitsOld && fHitType&2){
2464 // AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2465 // for (UInt_t i=0;i<arr->GetSize();i++){
2466 // AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2467 // info->fTrackID = map[info->fTrackID];
2470 // if (fTrackHitsOld && fHitType&4){
2471 if (fTrackHits && fHitType&4){
2472 TClonesArray * arr = fTrackHits->GetArray();;
2473 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2474 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2475 info->SetTrackID(map[info->GetTrackID()]);
2480 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2482 //return bool information - is track in given volume
2483 //load only part of the track information
2484 //return true if current track is in volume
2487 // if (fTrackHitsOld && fHitType&2) {
2488 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
2489 // br->GetEvent(track);
2490 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2491 // for (UInt_t j=0;j<ar->GetSize();j++){
2492 // if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2496 if (fTrackHits && fHitType&4) {
2497 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
2498 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
2499 br2->GetEvent(track);
2500 br1->GetEvent(track);
2501 Int_t *volumes = fTrackHits->GetVolumes();
2502 Int_t nvolumes = fTrackHits->GetNVolumes();
2503 if (!volumes && nvolumes>0) {
2504 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2507 for (Int_t j=0;j<nvolumes; j++)
2508 if (volumes[j]==id) return kTRUE;
2512 TBranch * br = fLoader->TreeH()->GetBranch("fSector");
2513 br->GetEvent(track);
2514 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2515 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2523 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2526 fLoader = new AliTPCLoader(GetName(),topfoldername);
2530 ////////////////////////////////////////////////////////////////////////
2531 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2533 // load TPC paarmeters from a given file or create new if the object
2534 // is not found there
2535 // 12/05/2003 This method should be moved to the AliTPCLoader
2536 // and one has to decide where to store the TPC parameters
2539 sprintf(paramName,"75x40_100x60_150x60");
2540 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2542 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2544 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2545 //paramTPC = new AliTPCParamSR;
2546 paramTPC = AliTPCcalibDB::Instance()->GetParameters();
2547 if (!paramTPC->IsGeoRead()){
2549 // read transformation matrices for gGeoManager
2551 paramTPC->ReadGeoMatrices();
2557 // the older version of parameters can be accessed with this code.
2558 // In some cases, we have old parameters saved in the file but
2559 // digits were created with new parameters, it can be distinguish
2560 // by the name of TPC TreeD. The code here is just for the case
2561 // we would need to compare with old data, uncomment it if needed.
2563 // char paramName[50];
2564 // sprintf(paramName,"75x40_100x60");
2565 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2567 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2569 // sprintf(paramName,"75x40_100x60_150x60");
2570 // paramTPC=(AliTPCParam*)in->Get(paramName);
2572 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2574 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2576 // paramTPC = new AliTPCParamSR;