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 "AliTPCRawStreamV3.h"
83 #include "TTreeStream.h"
86 //_____________________________________________________________________________
87 AliTPC::AliTPC():AliDetector(),
97 fPrimaryIonisation(0),
109 // Default constructor
112 for(Int_t i=0;i<4;i++) fCurrentIndex[i]=0;
114 // fTrackHitsOld = 0;
115 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
116 fHitType = 4; // ROOT containers
118 fHitType = 2; //default CONTAINERS - based on ROOT structure
122 //_____________________________________________________________________________
123 AliTPC::AliTPC(const char *name, const char *title)
124 : AliDetector(name,title),
134 fPrimaryIonisation(0),
146 // Standard constructor
150 // Initialise arrays of hits and digits
151 fHits = new TClonesArray("AliTPChit", 176);
152 gAlice->GetMCApp()->AddHitList(fHits);
154 fTrackHits = new AliTPCTrackHitsV2;
155 fTrackHits->SetHitPrecision(0.002);
156 fTrackHits->SetStepPrecision(0.003);
157 fTrackHits->SetMaxDistance(100);
159 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
160 //fTrackHitsOld->SetHitPrecision(0.002);
161 //fTrackHitsOld->SetStepPrecision(0.003);
162 //fTrackHitsOld->SetMaxDistance(100);
165 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
166 fHitType = 4; // ROOT containers
171 for(Int_t i=0;i<4;i++) fCurrentIndex[i]=0;
176 // Initialise color attributes
177 //PH SetMarkerColor(kYellow);
180 // Set TPC parameters
184 if (!strcmp(title,"Ne-CO2") || !strcmp(title,"Ne-CO2-N") || !strcmp(title,"Default") ) {
185 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
188 AliWarning("In Config.C you must set non-default parameters.");
193 void AliTPC::CreateDebugStremer(){
195 // Create Debug streamer to check simulation
197 fDebugStreamer = new TTreeSRedirector("TPCSimdebug.root");
199 //_____________________________________________________________________________
210 delete fTrackHits; //MI 15.09.2000
211 // delete fTrackHitsOld; //MI 10.12.2001
214 delete [] fNoiseTable;
215 delete [] fActiveSectors;
216 if (fDebugStreamer) delete fDebugStreamer;
219 //_____________________________________________________________________________
220 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
223 // Add a hit to the list
226 TClonesArray &lhits = *fHits;
227 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
230 AddHit2(track,vol,hits);
233 //_____________________________________________________________________________
234 void AliTPC::CreateMaterials()
236 //-----------------------------------------------
237 // Create Materials for for TPC simulations
238 //-----------------------------------------------
240 //-----------------------------------------------------------------
241 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
242 //-----------------------------------------------------------------
244 Int_t iSXFLD=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
245 Float_t sXMGMX=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
247 Float_t amat[5]; // atomic numbers
248 Float_t zmat[5]; // z
249 Float_t wmat[5]; // proportions
255 //***************** Gases *************************
258 //--------------------------------------------------------------
259 // gases - air and CO2
260 //--------------------------------------------------------------
276 AliMixture(10,"CO2",amat,zmat,density,2,wmat);
291 AliMixture(11,"Air",amat,zmat,density,2,wmat);
293 //----------------------------------------------------------------
295 //----------------------------------------------------------------
298 // Drift gases 1 - nonsensitive, 2 - sensitive, 3 - for Kr
299 // Composition by % of volume, values at 20deg and 1 atm.
301 // get the geometry title - defined in Config.C
304 TString title(GetTitle());
316 if(title == TString("Ne-CO2") || title == TString("Default")){
322 AliMixture(12,"Ne-CO2-1",amat,zmat,density,3,wmat);
323 AliMixture(13,"Ne-CO2-2",amat,zmat,density,3,wmat);
324 AliMixture(35,"Ne-CO2-3",amat,zmat,density,3,wmat);
326 else if (title == TString("Ne-CO2-N")){
335 AliMixture(12,"Ne-CO2-N-1",amat,zmat,density,4,wmat);
336 AliMixture(13,"Ne-CO2-N-2",amat,zmat,density,4,wmat);
337 AliMixture(30,"Ne-CO2-N-3",amat,zmat,density,4,wmat);
343 //----------------------------------------------------------------------
345 //----------------------------------------------------------------------
367 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
388 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
406 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
424 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
442 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
443 // material for "prepregs"
444 // Epoxy - C14 H20 O3
447 // prepreg1 60% C-fiber, 40% epoxy (vol)
462 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
464 //prepreg2 60% glass-fiber, 40% epoxy
483 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
485 //prepreg3 50% glass-fiber, 50% epoxy
504 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
506 // G10 60% SiO2 40% epoxy
525 AliMixture(22, "G10",amat,zmat,density,4,wmat);
534 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
536 // Si (for electronics
543 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
552 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
570 AliMixture(33,"Brass",amat,zmat,density,2,wmat);
572 // Epoxy - C14 H20 O3
588 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
591 AliMixture(35,"Epoxy1",amat,zmat,density,-3,wmat);
593 // epoxy film - 90% epoxy, 10% glass fiber
613 AliMixture(34, "Epoxy-film",amat,zmat,density,4,wmat);
631 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
639 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
641 // Fe (steel for the inner heat screen)
649 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
651 // Peek - (C6H4-O-OC6H4-O-C6H4-CO)n
666 AliMixture(30,"Peek",amat,zmat,density,-3,wmat);
681 AliMixture(31,"Alumina",amat,zmat,density,-2,wmat);
700 AliMixture(32,"Water",amat,zmat,density,-2,wmat);
703 //----------------------------------------------------------
704 // tracking media for gases
705 //----------------------------------------------------------
707 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
708 AliMedium(1, "DriftGas1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
709 AliMedium(2, "DriftGas2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
710 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
711 AliMedium(20, "DriftGas3", 35, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
712 //-----------------------------------------------------------
713 // tracking media for solids
714 //-----------------------------------------------------------
716 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
717 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
718 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
719 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
720 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
721 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
723 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
724 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
725 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
726 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
728 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
729 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
730 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
731 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
732 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
733 AliMedium(19,"Peek",30,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
734 AliMedium(21,"Alumina",31,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
735 AliMedium(22,"Water",32,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
736 AliMedium(23,"Brass",33,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
737 AliMedium(24,"Epoxyfm",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
738 AliMedium(25,"Epoxy1",35,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
741 void AliTPC::GenerNoise(Int_t tablesize)
744 //Generate table with noise
751 if (fNoiseTable) delete[] fNoiseTable;
752 fNoiseTable = new Float_t[tablesize];
753 fNoiseDepth = tablesize;
754 fCurrentNoise =0; //!index of the noise in the noise table
756 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
757 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
760 Float_t AliTPC::GetNoise()
762 // get noise from table
763 // if ((fCurrentNoise%10)==0)
764 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
765 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
766 return fNoiseTable[fCurrentNoise++];
767 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
771 Bool_t AliTPC::IsSectorActive(Int_t sec) const
774 // check if the sector is active
775 if (!fActiveSectors) return kTRUE;
776 else return fActiveSectors[sec];
779 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
781 // activate interesting sectors
782 SetTreeAddress();//just for security
783 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
784 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
785 for (Int_t i=0;i<n;i++)
786 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
790 void AliTPC::SetActiveSectors(Int_t flag)
793 // activate sectors which were hitted by tracks
795 SetTreeAddress();//just for security
796 if (fHitType==0) return; // if Clones hit - not short volume ID information
797 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
799 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
802 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
803 //TBranch * branch=0;
804 if (fLoader->TreeH() == 0x0)
806 AliFatal("Can not find TreeH in folder");
809 //if (fHitType>1) branch = fLoader->TreeH()->GetBranch("TPC2");
810 if (fHitType>1) fLoader->TreeH()->GetBranch("TPC2");
811 //else branch = fLoader->TreeH()->GetBranch("TPC");
812 else fLoader->TreeH()->GetBranch("TPC");
813 Stat_t ntracks = fLoader->TreeH()->GetEntries();
814 // loop over all hits
815 AliDebug(1,Form("Got %d tracks", (Int_t) ntracks));
817 for(Int_t track=0;track<ntracks;track++) {
820 if (fTrackHits && fHitType&4) {
821 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
822 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
823 br1->GetEvent(track);
824 br2->GetEvent(track);
825 Int_t *volumes = fTrackHits->GetVolumes();
826 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++) {
827 if (volumes[j]>-1 && volumes[j]<fTPCParam->GetNSector()) {
828 fActiveSectors[volumes[j]]=kTRUE;
831 AliError(Form("Volume %d -> sector number %d is outside (0..%d)",
834 fTPCParam->GetNSector()));
840 // if (fTrackHitsOld && fHitType&2) {
841 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
842 // br->GetEvent(track);
843 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
844 // for (UInt_t j=0;j<ar->GetSize();j++){
845 // fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
854 //_____________________________________________________________________________
855 void AliTPC::Digits2Raw()
857 // convert digits of the current event to raw data
859 static const Int_t kThreshold = 0;
861 fLoader->LoadDigits();
862 TTree* digits = fLoader->TreeD();
864 AliError("No digits tree");
870 AliSimDigits* digrow = &digarr;
871 digits->GetBranch("Segment")->SetAddress(&digrow);
873 const char* fileName = "AliTPCDDL.dat";
874 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
878 // 2: txt files with digits
879 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
880 //it is highly suggested to use this mode only for debugging digits files
881 //reasonably small, because otherwise the size of the txt files can reach
882 //quickly several MB wasting time and disk space.
883 buffer->SetVerbose(0);
885 Int_t nEntries = Int_t(digits->GetEntries());
886 Int_t previousSector = -1;
888 for (Int_t i = 0; i < nEntries; i++) {
891 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
892 if(previousSector != sector) {
894 previousSector = sector;
897 if (sector < 36) { //inner sector [0;35]
899 //the whole row is written into the output file
900 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
901 sector, subSector, row);
903 //only the pads in the range [37;48] are written into the output file
904 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
905 sector, subSector, row);
907 //only the pads outside the range [37;48] are written into the output file
908 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
909 sector, subSector, row);
912 } else { //outer sector [36;71]
913 if (row == 54) subSector = 2;
914 if ((row != 27) && (row != 76)) {
915 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
916 sector, subSector, row);
917 } else if (row == 27) {
918 //only the pads outside the range [43;46] are written into the output file
919 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
920 sector, subSector, row);
922 //only the pads in the range [43;46] are written into the output file
923 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
924 sector, subSector, row);
925 } else if (row == 76) {
926 //only the pads outside the range [33;88] are written into the output file
927 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
928 sector, subSector, row);
930 //only the pads in the range [33;88] are written into the output file
931 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
932 sector, subSector, row);
938 fLoader->UnloadDigits();
940 AliTPCDDLRawData rawWriter;
941 rawWriter.SetVerbose(0);
943 rawWriter.RawData(fileName);
944 gSystem->Unlink(fileName);
949 //_____________________________________________________________________________
950 Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
951 // Converts the TPC raw data into summable digits
952 // The method is used for merging simulated and
954 if (fLoader->TreeS() == 0x0 ) {
955 fLoader->MakeTree("S");
958 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
960 //setup TPCDigitsArray
961 if(GetDigitsArray()) delete GetDigitsArray();
963 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
964 arr->SetClass("AliSimDigits");
965 arr->Setup(fTPCParam);
966 arr->MakeTree(fLoader->TreeS());
970 // set zero suppression to "0"
971 fTPCParam->SetZeroSup(0);
974 const Int_t kmaxTime = fTPCParam->GetMaxTBin();
975 const Int_t kNIS = fTPCParam->GetNInnerSector();
976 const Int_t kNOS = fTPCParam->GetNOuterSector();
977 const Int_t kNS = kNIS + kNOS;
980 AliTPCROC * roc = AliTPCROC::Instance();
981 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
982 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
983 Short_t** allBins = new Short_t*[nRowsMax];
984 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
985 Int_t maxBin = kmaxTime*nPadsMax;
986 allBins[iRow] = new Short_t[maxBin];
987 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
990 for(Int_t iSector = 0; iSector < kNS; iSector++) {
992 Int_t nRows = fTPCParam->GetNRow(iSector);
993 Int_t nDDLs = 0, indexDDL = 0;
994 if (iSector < kNIS) {
996 indexDDL = iSector * 2;
1000 indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
1003 // Load the raw data for corresponding DDLs
1006 AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
1007 AliTPCRawStreamV3 input(rawReader,(AliAltroMapping**)mapping);
1008 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
1011 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
1012 Int_t maxBin = kmaxTime*nPadsMax;
1013 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
1016 // Begin loop over altro data
1017 while (input.NextDDL()) {
1019 if (input.GetSector() != iSector)
1020 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
1023 while ( input.NextChannel() ) {
1025 Int_t iRow = input.GetRow();
1026 if (iRow < 0 || iRow >= nRows)
1027 AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
1028 iRow, 0, nRows -1));
1029 Int_t iPad = input.GetPad();
1031 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1033 if (iPad < 0 || iPad >= maxPad)
1034 AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
1035 iPad, 0, maxPad -1));
1038 while ( input.NextBunch() ){
1039 Int_t startTbin = (Int_t)input.GetStartTimeBin();
1040 Int_t bunchlength = (Int_t)input.GetBunchLength();
1041 const UShort_t *sig = input.GetSignals();
1042 for (Int_t iTime = 0; iTime<bunchlength; iTime++){
1043 Int_t iTimeBin=startTbin-iTime;
1044 if ( iTimeBin < 0 || iTimeBin >= kmaxTime) {
1046 //AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
1047 // iTimeBin, 0, kmaxTime -1));
1050 Int_t maxBin = kmaxTime*maxPad;
1051 if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
1052 ((iPad*kmaxTime+iTimeBin) < 0))
1053 AliFatal(Form("Index outside the allowed range"
1054 " Sector=%d Row=%d Pad=%d Timebin=%d"
1055 " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
1056 allBins[iRow][iPad*kmaxTime+iTimeBin] = sig[iTime];
1059 } // End loop over altro data
1062 // Now fill the digits array
1063 if (fDigitsArray->GetTree()==0) {
1064 AliFatal("Tree not set in fDigitsArray");
1067 for (Int_t iRow = 0; iRow < nRows; iRow++) {
1068 AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
1069 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1070 for(Int_t iPad = 0; iPad < maxPad; iPad++) {
1071 for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
1072 Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
1073 if (q <= 0) continue;
1075 dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
1076 ((AliSimDigits*)dig)->SetTrackIDFast( 3141593, iTimeBin,iPad,0);
1079 fDigitsArray->StoreRow(iSector,iRow);
1080 Int_t ndig = dig->GetDigitSize();
1083 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1084 iSector,iRow,ndig));
1086 fDigitsArray->ClearRow(iSector,iRow);
1088 } // end of the sector digitization
1090 // get LHC clock phase from the digits tree
1092 TParameter<float> *ph;
1094 TTree *digtree = fLoader->TreeD();
1096 if(digtree){ // if TreeD exists
1097 ph = (TParameter<float>*)digtree->GetUserInfo()->FindObject("lhcphase0");
1098 phase = ph->GetVal();
1100 else{ //TreeD does not exist
1104 // store lhc clock phase in S-digits tree
1106 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",phase));
1108 fLoader->WriteSDigits("OVERWRITE");
1110 if(GetDigitsArray()) delete GetDigitsArray();
1111 SetDigitsArray(0x0);
1114 for (Int_t iRow = 0; iRow < nRowsMax; iRow++)
1115 delete [] allBins[iRow];
1121 //______________________________________________________________________
1122 AliDigitizer* AliTPC::CreateDigitizer(AliDigitizationInput* digInput) const
1124 return new AliTPCDigitizer(digInput);
1127 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
1129 //create digits from summable digits
1130 GenerNoise(500000); //create teble with noise
1132 //conect tree with sSDigits
1133 TTree *t = fLoader->TreeS();
1136 fLoader->LoadSDigits("READ");
1137 t = fLoader->TreeS();
1139 AliError("Can not get input TreeS");
1144 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1146 AliSimDigits digarr, *dummy=&digarr;
1147 TBranch* sdb = t->GetBranch("Segment");
1149 AliError("Can not find branch with segments in TreeS.");
1153 sdb->SetAddress(&dummy);
1155 Stat_t nentries = t->GetEntries();
1157 // set zero suppression
1159 fTPCParam->SetZeroSup(2);
1161 // get zero suppression
1163 Int_t zerosup = fTPCParam->GetZeroSup();
1165 //make tree with digits
1167 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1168 arr->SetClass("AliSimDigits");
1169 arr->Setup(fTPCParam);
1170 arr->MakeTree(fLoader->TreeD());
1172 AliTPCParam * par = fTPCParam;
1174 //Loop over segments of the TPC
1176 for (Int_t n=0; n<nentries; n++) {
1179 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1180 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
1183 if (!IsSectorActive(sec)) continue;
1185 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1186 Int_t nrows = digrow->GetNRows();
1187 Int_t ncols = digrow->GetNCols();
1189 digrow->ExpandBuffer();
1190 digarr.ExpandBuffer();
1191 digrow->ExpandTrackBuffer();
1192 digarr.ExpandTrackBuffer();
1195 Short_t * pamp0 = digarr.GetDigits();
1196 Int_t * ptracks0 = digarr.GetTracks();
1197 Short_t * pamp1 = digrow->GetDigits();
1198 Int_t * ptracks1 = digrow->GetTracks();
1199 Int_t nelems =nrows*ncols;
1200 Int_t saturation = fTPCParam->GetADCSat() - 1;
1201 //use internal structure of the AliDigits - for speed reason
1202 //if you cahnge implementation
1203 //of the Alidigits - it must be rewriten -
1204 for (Int_t i= 0; i<nelems; i++){
1205 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1207 if (q>saturation) q=saturation;
1210 ptracks1[0]=ptracks0[0];
1211 ptracks1[nelems]=ptracks0[nelems];
1212 ptracks1[2*nelems]=ptracks0[2*nelems];
1220 arr->StoreRow(sec,row);
1221 arr->ClearRow(sec,row);
1226 fLoader->WriteDigits("OVERWRITE");
1230 //__________________________________________________________________
1231 void AliTPC::SetDefaults(){
1233 // setting the defaults
1236 // Set response functions
1239 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1241 //AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1242 //gDirectory->Get("75x40_100x60");
1243 AliTPCParamSR *param = (AliTPCParamSR*)AliTPCcalibDB::Instance()->GetParameters();
1245 AliFatal("No TPC parameters found");
1248 if (!param->IsGeoRead()){
1250 // read transformation matrices for gGeoManager
1252 param->ReadGeoMatrices();
1257 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1258 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1259 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1262 //AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1263 //rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1264 //rf->SetOffset(3*param->GetZSigma());
1269 char strgamma4[1000];
1270 //sprintf(strgamma4,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
1272 snprintf(strgamma4,1000,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
1273 TF1 * fgamma4 = new TF1("fgamma4",strgamma4, -1,1);
1274 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE,1000);
1275 rf->SetParam(fgamma4,param->GetZWidth(), 1,0.2);
1276 rf->SetOffset(3*param->GetZSigma());
1278 TDirectory *savedir=gDirectory;
1281 printf ("TPC MWPC readout\n");
1282 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1284 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1287 prfinner->Read("prf_07504_Gati_056068_d02");
1288 //PH Set different names
1289 s=prfinner->GetGRF()->GetName();
1291 prfinner->GetGRF()->SetName(s.Data());
1293 prfouter1->Read("prf_10006_Gati_047051_d03");
1294 s=prfouter1->GetGRF()->GetName();
1296 prfouter1->GetGRF()->SetName(s.Data());
1298 prfouter2->Read("prf_15006_Gati_047051_d03");
1299 s=prfouter2->GetGRF()->GetName();
1301 prfouter2->GetGRF()->SetName(s.Data());
1306 printf ("TPC GEM readout\n");
1307 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2dGEM.root");
1309 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2dGEM.root !");
1312 prfinner->Read("prf0");
1313 //PH Set different names
1314 s=prfinner->GetGRF()->GetName();
1316 prfinner->GetGRF()->SetName(s.Data());
1318 prfouter1->Read("prf1");
1319 s=prfouter1->GetGRF()->GetName();
1321 prfouter1->GetGRF()->SetName(s.Data());
1323 prfouter2->Read("prf2");
1324 s=prfouter2->GetGRF()->GetName();
1326 prfouter2->GetGRF()->SetName(s.Data());
1331 param->SetInnerPRF(prfinner);
1332 param->SetOuter1PRF(prfouter1);
1333 param->SetOuter2PRF(prfouter2);
1334 param->SetTimeRF(rf);
1344 //__________________________________________________________________
1345 void AliTPC::Hits2Digits()
1348 // creates digits from hits
1350 if (!fTPCParam->IsGeoRead()){
1352 // read transformation matrices for gGeoManager
1354 fTPCParam->ReadGeoMatrices();
1357 fLoader->LoadHits("read");
1358 fLoader->LoadDigits("recreate");
1359 AliRunLoader* runLoader = fLoader->GetRunLoader();
1361 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1362 //PH runLoader->GetEvent(iEvent);
1363 Hits2Digits(iEvent);
1366 fLoader->UnloadHits();
1367 fLoader->UnloadDigits();
1369 //__________________________________________________________________
1370 void AliTPC::Hits2Digits(Int_t eventnumber)
1372 //----------------------------------------------------
1373 // Loop over all sectors for a single event
1374 //----------------------------------------------------
1375 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1376 rl->GetEvent(eventnumber);
1378 if (fLoader->TreeH() == 0x0) {
1379 if(fLoader->LoadHits()) {
1380 AliError("Can not load hits.");
1385 if (fLoader->TreeD() == 0x0 ) {
1386 fLoader->MakeTree("D");
1387 if (fLoader->TreeD() == 0x0 ) {
1388 AliError("Can not get TreeD");
1393 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1394 GenerNoise(500000); //create teble with noise
1396 //setup TPCDigitsArray
1398 if(GetDigitsArray()) delete GetDigitsArray();
1400 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1401 arr->SetClass("AliSimDigits");
1402 arr->Setup(fTPCParam);
1404 arr->MakeTree(fLoader->TreeD());
1405 SetDigitsArray(arr);
1407 fDigitsSwitch=0; // standard digits
1408 // here LHC clock phase
1410 switch (fLHCclockPhaseSw){
1417 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1421 // not implemented yet
1424 // adding phase to the TreeD user info
1425 fLoader->TreeD()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1427 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1428 if (IsSectorActive(isec)) {
1429 AliDebug(1,Form("Hits2Digits: Sector %d is active.",isec));
1430 Hits2DigitsSector(isec);
1433 AliDebug(1,Form("Hits2Digits: Sector %d is NOT active.",isec));
1436 fLoader->WriteDigits("OVERWRITE");
1438 //this line prevents the crash in the similar one
1439 //on the beginning of this method
1440 //destructor attempts to reset the tree, which is deleted by the loader
1441 //need to be redesign
1442 if(GetDigitsArray()) delete GetDigitsArray();
1443 SetDigitsArray(0x0);
1447 //__________________________________________________________________
1448 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1451 //-----------------------------------------------------------
1452 // summable digits - 16 bit "ADC", no noise, no saturation
1453 //-----------------------------------------------------------
1455 //----------------------------------------------------
1456 // Loop over all sectors for a single event
1457 //----------------------------------------------------
1459 AliRunLoader* rl = fLoader->GetRunLoader();
1461 rl->GetEvent(eventnumber);
1462 if (fLoader->TreeH() == 0x0) {
1463 if(fLoader->LoadHits()) {
1464 AliError("Can not load hits.");
1471 if (fLoader->TreeS() == 0x0 ) {
1472 fLoader->MakeTree("S");
1475 if(fDefaults == 0) SetDefaults();
1477 GenerNoise(500000); //create table with noise
1478 //setup TPCDigitsArray
1480 if(GetDigitsArray()) delete GetDigitsArray();
1483 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1484 arr->SetClass("AliSimDigits");
1485 arr->Setup(fTPCParam);
1486 arr->MakeTree(fLoader->TreeS());
1488 SetDigitsArray(arr);
1490 fDigitsSwitch=1; // summable digits
1492 // set zero suppression to "0"
1493 // here LHC clock phase
1495 switch (fLHCclockPhaseSw){
1502 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1506 // not implemented yet
1509 // adding phase to the TreeS user info
1511 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1513 fTPCParam->SetZeroSup(0);
1515 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1516 if (IsSectorActive(isec)) {
1517 Hits2DigitsSector(isec);
1520 fLoader->WriteSDigits("OVERWRITE");
1522 //this line prevents the crash in the similar one
1523 //on the beginning of this method
1524 //destructor attempts to reset the tree, which is deleted by the loader
1525 //need to be redesign
1526 if(GetDigitsArray()) delete GetDigitsArray();
1527 SetDigitsArray(0x0);
1529 //__________________________________________________________________
1531 void AliTPC::Hits2SDigits()
1534 //-----------------------------------------------------------
1535 // summable digits - 16 bit "ADC", no noise, no saturation
1536 //-----------------------------------------------------------
1538 if (!fTPCParam->IsGeoRead()){
1540 // read transformation matrices for gGeoManager
1542 fTPCParam->ReadGeoMatrices();
1545 fLoader->LoadHits("read");
1546 fLoader->LoadSDigits("recreate");
1547 AliRunLoader* runLoader = fLoader->GetRunLoader();
1549 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1550 runLoader->GetEvent(iEvent);
1553 Hits2SDigits2(iEvent);
1556 fLoader->UnloadHits();
1557 fLoader->UnloadSDigits();
1558 if (fDebugStreamer) {
1559 delete fDebugStreamer;
1563 //_____________________________________________________________________________
1565 void AliTPC::Hits2DigitsSector(Int_t isec)
1567 //-------------------------------------------------------------------
1568 // TPC conversion from hits to digits.
1569 //-------------------------------------------------------------------
1571 //-----------------------------------------------------------------
1572 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1573 //-----------------------------------------------------------------
1575 //-------------------------------------------------------
1576 // Get the access to the track hits
1577 //-------------------------------------------------------
1579 // check if the parameters are set - important if one calls this method
1580 // directly, not from the Hits2Digits
1582 if(fDefaults == 0) SetDefaults();
1584 TTree *tH = fLoader->TreeH(); // pointer to the hits tree
1586 AliFatal("Can not find TreeH in folder");
1590 Stat_t ntracks = tH->GetEntries();
1592 Int_t nrows =fTPCParam->GetNRow(isec);
1594 TObjArray **row=new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1595 for(Int_t j=0;j<nrows+2;j++) row[j]=0;
1597 MakeSector(isec,nrows,tH,ntracks,row);
1599 //--------------------------------------------------------
1600 // Digitize this sector, row by row
1601 // row[i] is the pointer to the TObjArray of TVectors,
1602 // each one containing electrons accepted on this
1603 // row, assigned into tracks
1604 //--------------------------------------------------------
1608 if (fDigitsArray->GetTree()==0) {
1609 AliFatal("Tree not set in fDigitsArray");
1612 for (i=0;i<nrows;i++){
1614 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1616 DigitizeRow(i,isec,row);
1618 fDigitsArray->StoreRow(isec,i);
1620 Int_t ndig = dig->GetDigitSize();
1623 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1626 fDigitsArray->ClearRow(isec,i);
1629 } // end of the sector digitization
1631 for(i=0;i<nrows+2;i++){
1636 delete [] row; // delete the array of pointers to TObjArray-s
1639 } // end of Hits2DigitsSector
1642 //_____________________________________________________________________________
1643 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1645 //-----------------------------------------------------------
1646 // Single row digitization, coupling from the neighbouring
1647 // rows taken into account
1648 //-----------------------------------------------------------
1650 //-----------------------------------------------------------------
1651 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1652 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1653 //-----------------------------------------------------------------
1655 Float_t zerosup = fTPCParam->GetZeroSup();
1656 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
1657 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
1658 AliTPCCalROC * gainROC = gainTPC->GetCalROC(isec); // pad gains per given sector
1659 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(isec); // noise per given sector
1662 fCurrentIndex[1]= isec;
1665 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1666 Int_t nofTbins = fTPCParam->GetMaxTBin();
1667 Int_t indexRange[4];
1669 // Integrated signal for this row
1670 // and a single track signal
1673 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1674 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
1676 TMatrixF &total = *m1;
1678 // Array of pointers to the label-signal list
1680 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1681 Float_t **pList = new Float_t* [nofDigits];
1685 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1691 for (Int_t row= row1;row<=row2;row++){
1692 Int_t nTracks= rows[row]->GetEntries();
1693 for (i1=0;i1<nTracks;i1++){
1694 fCurrentIndex[2]= row;
1695 fCurrentIndex[3]=irow+1;
1697 m2->Zero(); // clear single track signal matrix
1698 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1699 GetList(trackLabel,nofPads,m2,indexRange,pList);
1701 else GetSignal(rows[row],i1,0,m1,indexRange);
1707 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1709 Float_t fzerosup = zerosup+0.5;
1710 for(Int_t it=0;it<nofTbins;it++){
1711 for(Int_t ip=0;ip<nofPads;ip++){
1713 Float_t q=total(ip,it);
1714 if(fDigitsSwitch == 0){
1715 Float_t gain = gainROC->GetValue(irow,ip); // get gain for given - pad-row pad
1716 Float_t noisePad = noiseROC->GetValue(irow,ip);
1719 q+=GetNoise()*noisePad;
1720 if(q <=fzerosup) continue; // do not fill zeros
1722 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
1727 if(q <= 0.) continue; // do not fill zeros
1728 if(q>2000.) q=2000.;
1734 // "real" signal or electronic noise (list = -1)?
1737 for(Int_t j1=0;j1<3;j1++){
1738 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1743 <A NAME="AliDigits"></A>
1744 using of AliDigits object
1747 dig->SetDigitFast((Short_t)q,it,ip);
1748 if (fDigitsArray->IsSimulated()) {
1749 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1750 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1751 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1754 } // end of loop over time buckets
1755 } // end of lop over pads
1761 // glitch filters if normal simulated digits
1763 if(!fDigitsSwitch) ((AliSimDigits*)dig)->GlitchFilter();
1765 // This row has been digitized, delete nonused stuff
1768 for(lp=0;lp<nofDigits;lp++){
1769 if(pList[lp]) delete [] pList[lp];
1777 } // end of DigitizeRow
1779 //_____________________________________________________________________________
1781 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1782 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
1785 //---------------------------------------------------------------
1786 // Calculates 2-D signal (pad,time) for a single track,
1787 // returns a pointer to the signal matrix and the track label
1788 // No digitization is performed at this level!!!
1789 //---------------------------------------------------------------
1791 //-----------------------------------------------------------------
1792 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1793 // Modified: Marian Ivanov
1794 //-----------------------------------------------------------------
1798 tv = (TVector*)p1->At(ntr); // pointer to a track
1801 Float_t label = v(0);
1802 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
1804 Int_t nElectrons = (tv->GetNrows()-1)/5;
1805 indexRange[0]=9999; // min pad
1806 indexRange[1]=-1; // max pad
1807 indexRange[2]=9999; //min time
1808 indexRange[3]=-1; // max time
1810 TMatrixF &signal = *m1;
1811 TMatrixF &total = *m2;
1813 // Get LHC clock phase
1815 TParameter<float> *ph;
1816 if(fDigitsSwitch){// s-digits
1817 ph = (TParameter<float>*)fLoader->TreeS()->GetUserInfo()->FindObject("lhcphase0");
1819 else{ // normal digits
1820 ph = (TParameter<float>*)fLoader->TreeD()->GetUserInfo()->FindObject("lhcphase0");
1822 // Loop over all electrons
1824 for(Int_t nel=0; nel<nElectrons; nel++){
1826 Float_t aval = v(idx+4);
1827 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1828 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
1829 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,
1830 fCurrentIndex[3],ph->GetVal());
1832 Int_t *index = fTPCParam->GetResBin(0);
1833 Float_t *weight = & (fTPCParam->GetResWeight(0));
1835 if (n>0) for (Int_t i =0; i<n; i++){
1836 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1839 Int_t time=index[2];
1840 Float_t qweight = *(weight)*eltoadcfac;
1842 if (m1!=0) signal(pad,time)+=qweight;
1843 total(pad,time)+=qweight;
1844 if (indexRange[0]>pad) indexRange[0]=pad;
1845 if (indexRange[1]<pad) indexRange[1]=pad;
1846 if (indexRange[2]>time) indexRange[2]=time;
1847 if (indexRange[3]<time) indexRange[3]=time;
1854 } // end of loop over electrons
1856 return label; // returns track label when finished
1859 //_____________________________________________________________________________
1860 void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
1861 Int_t *indexRange, Float_t **pList)
1863 //----------------------------------------------------------------------
1864 // Updates the list of tracks contributing to digits for a given row
1865 //----------------------------------------------------------------------
1867 //-----------------------------------------------------------------
1868 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1869 //-----------------------------------------------------------------
1871 TMatrixF &signal = *m;
1873 // lop over nonzero digits
1875 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1876 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1879 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1881 if(signal(ip,it)<0.5) continue;
1883 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1885 if(!pList[globalIndex]){
1888 // Create new list (6 elements - 3 signals and 3 labels),
1891 pList[globalIndex] = new Float_t [6];
1895 *pList[globalIndex] = -1.;
1896 *(pList[globalIndex]+1) = -1.;
1897 *(pList[globalIndex]+2) = -1.;
1898 *(pList[globalIndex]+3) = -1.;
1899 *(pList[globalIndex]+4) = -1.;
1900 *(pList[globalIndex]+5) = -1.;
1902 *pList[globalIndex] = label;
1903 *(pList[globalIndex]+3) = signal(ip,it);
1907 // check the signal magnitude
1909 Float_t highest = *(pList[globalIndex]+3);
1910 Float_t middle = *(pList[globalIndex]+4);
1911 Float_t lowest = *(pList[globalIndex]+5);
1914 // compare the new signal with already existing list
1917 if(signal(ip,it)<lowest) continue; // neglect this track
1921 if (signal(ip,it)>highest){
1922 *(pList[globalIndex]+5) = middle;
1923 *(pList[globalIndex]+4) = highest;
1924 *(pList[globalIndex]+3) = signal(ip,it);
1926 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1927 *(pList[globalIndex]+1) = *pList[globalIndex];
1928 *pList[globalIndex] = label;
1930 else if (signal(ip,it)>middle){
1931 *(pList[globalIndex]+5) = middle;
1932 *(pList[globalIndex]+4) = signal(ip,it);
1934 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1935 *(pList[globalIndex]+1) = label;
1938 *(pList[globalIndex]+5) = signal(ip,it);
1939 *(pList[globalIndex]+2) = label;
1943 } // end of loop over pads
1944 } // end of loop over time bins
1947 //___________________________________________________________________
1948 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1949 Stat_t ntracks,TObjArray **row)
1952 //-----------------------------------------------------------------
1953 // Prepares the sector digitization, creates the vectors of
1954 // tracks for each row of this sector. The track vector
1955 // contains the track label and the position of electrons.
1956 //-----------------------------------------------------------------
1959 // The trasport of the electrons through TPC drift volume
1960 // Drift (drift velocity + velocity map(not yet implemented)))
1961 // Application of the random processes (diffusion, gas gain)
1962 // Systematic effects (ExB effect in drift volume + ROCs)
1965 // Loop over primary electrons:
1966 // Creation of the secondary electrons
1967 // Loop over electrons (primary+ secondaries)
1968 // Global coordinate frame:
1969 // 1. Skip electrons if attached
1970 // 2. ExB effect in drift volume
1971 // a.) Simulation calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1972 // b.) Reconstruction - calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1973 // 3. Generation of gas gain (Random - Exponential distribution)
1974 // 4. TransportElectron function (diffusion)
1976 // 5. Conversion to the local coordinate frame pad-row, pad, timebin
1977 // 6. Apply Time0 shift - AliTPCCalPad class
1978 // a.) Plus sign in simulation
1979 // b.) Minus sign in reconstruction
1982 //-----------------------------------------------------------------
1983 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1984 // Origin: Marian Ivanov, marian.ivanov@cern.ch
1985 //-----------------------------------------------------------------
1986 AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
1987 if (gAlice){ // Set correctly the magnetic field in the ExB calculation
1988 if (!calib->GetExB()){
1989 AliMagF * field = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField());
1991 calib->SetExBField(field);
1996 Float_t gasgain = fTPCParam->GetGasGain();
1997 gasgain = gasgain/fGainFactor;
2001 AliTPChit *tpcHit; // pointer to a sigle TPC hit
2004 if (fHitType>1) branch = TH->GetBranch("TPC2");
2005 else branch = TH->GetBranch("TPC");
2008 //----------------------------------------------
2009 // Create TObjArray-s, one for each row,
2010 // each TObjArray will store the TVectors
2011 // of electrons, one TVectors per each track.
2012 //----------------------------------------------
2014 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
2015 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
2017 for(i=0; i<nrows+2; i++){
2018 row[i] = new TObjArray;
2025 //--------------------------------------------------------------------
2026 // Loop over tracks, the "track" contains the full history
2027 //--------------------------------------------------------------------
2029 Int_t previousTrack,currentTrack;
2030 previousTrack = -1; // nothing to store so far!
2032 for(Int_t track=0;track<ntracks;track++){
2033 Bool_t isInSector=kTRUE;
2035 isInSector = TrackInVolume(isec,track);
2036 if (!isInSector) continue;
2038 branch->GetEntry(track); // get next track
2042 tpcHit = (AliTPChit*)FirstHit(-1);
2044 //--------------------------------------------------------------
2046 //--------------------------------------------------------------
2051 Int_t sector=tpcHit->fSector; // sector number
2053 tpcHit = (AliTPChit*) NextHit();
2057 // Remove hits which arrive before the TPC opening gate signal
2058 if(((fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
2059 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
2060 tpcHit = (AliTPChit*) NextHit();
2064 currentTrack = tpcHit->Track(); // track number
2066 if(currentTrack != previousTrack){
2068 // store already filled fTrack
2070 for(i=0;i<nrows+2;i++){
2071 if(previousTrack != -1){
2072 if(nofElectrons[i]>0){
2073 TVector &v = *tracks[i];
2074 v(0) = previousTrack;
2075 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2076 row[i]->Add(tracks[i]);
2079 delete tracks[i]; // delete empty TVector
2085 tracks[i] = new TVector(601); // TVectors for the next fTrack
2087 } // end of loop over rows
2089 previousTrack=currentTrack; // update track label
2092 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2094 //---------------------------------------------------
2095 // Calculate the electron attachment probability
2096 //---------------------------------------------------
2099 Float_t time = 1.e6*(fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
2100 /fTPCParam->GetDriftV();
2102 Float_t attProb = fTPCParam->GetAttCoef()*
2103 fTPCParam->GetOxyCont()*time; // fraction!
2105 //-----------------------------------------------
2106 // Loop over electrons
2107 //-----------------------------------------------
2110 for(Int_t nel=0;nel<qI;nel++){
2111 // skip if electron lost due to the attachment
2112 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2117 Double_t dxyz0[3],dxyz1[3];
2118 dxyz0[0]=tpcHit->X();
2119 dxyz0[1]=tpcHit->Y();
2120 dxyz0[2]=tpcHit->Z();
2121 if (calib->GetExB()){
2122 calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
2124 AliError("Not valid ExB calibration");
2125 dxyz1[0]=tpcHit->X();
2126 dxyz1[1]=tpcHit->Y();
2127 dxyz1[2]=tpcHit->Z();
2135 // protection for the nonphysical avalanche size (10**6 maximum)
2137 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2138 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2141 TransportElectron(xyz,index);
2143 Int_t padrow = fTPCParam->GetPadRow(xyz,index);
2145 // Add Time0 correction due unisochronity
2146 // xyz[0] - pad row coordinate
2147 // xyz[1] - pad coordinate
2148 // xyz[2] - is in now time bin coordinate system
2149 Float_t correction =0;
2150 if (calib->GetPadTime0()){
2151 if (!calib->GetPadTime0()->GetCalROC(isec)) continue;
2152 Int_t npads = fTPCParam->GetNPads(isec,padrow);
2153 // Int_t pad = TMath::Nint(xyz[1]+fTPCParam->GetNPads(isec,TMath::Nint(xyz[0]))*0.5);
2154 // pad numbering from -npads/2 .. npads/2-1
2155 Int_t pad = TMath::Nint(xyz[1]+npads/2);
2157 if (pad>=npads) pad=npads-1;
2158 correction = calib->GetPadTime0()->GetCalROC(isec)->GetValue(padrow,pad);
2159 // printf("%d\t%d\t%d\t%f\n",isec,padrow,pad,correction);
2160 if (fDebugStreamer){
2161 (*fDebugStreamer)<<"Time0"<<
2169 "cor="<<correction<<
2174 xyz[2]+=fTPCParam->GetNTBinsL1(); // adding Level 1 time bin offset
2176 // Electron track time (for pileup simulation)
2177 xyz[2]+=tpcHit->Time()/fTPCParam->GetTSample(); // adding time of flight
2181 // row 0 - cross talk from the innermost row
2182 // row fNRow+1 cross talk from the outermost row
2183 rowNumber = index[2]+1;
2184 //transform position to local digit coordinates
2185 //relative to nearest pad row
2186 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
2188 if (isec <fTPCParam->GetNInnerSector()) {
2189 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2190 y1 = fTPCParam->GetYInner(rowNumber);
2193 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2194 y1 = fTPCParam->GetYOuter(rowNumber);
2196 // gain inefficiency at the wires edges - linear
2199 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.)); */
2201 nofElectrons[rowNumber]++;
2202 //----------------------------------
2203 // Expand vector if necessary
2204 //----------------------------------
2205 if(nofElectrons[rowNumber]>120){
2206 Int_t range = tracks[rowNumber]->GetNrows();
2207 if((nofElectrons[rowNumber])>(range-1)/5){
2209 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
2213 TVector &v = *tracks[rowNumber];
2214 Int_t idx = 5*nofElectrons[rowNumber]-4;
2215 Real_t * position = &(((TVector&)v)(idx)); //make code faster
2216 memcpy(position,xyz,5*sizeof(Float_t));
2218 } // end of loop over electrons
2220 tpcHit = (AliTPChit*)NextHit();
2222 } // end of loop over hits
2223 } // end of loop over tracks
2226 // store remaining track (the last one) if not empty
2229 for(i=0;i<nrows+2;i++){
2230 if(nofElectrons[i]>0){
2231 TVector &v = *tracks[i];
2232 v(0) = previousTrack;
2233 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2234 row[i]->Add(tracks[i]);
2243 delete [] nofElectrons;
2245 } // end of MakeSector
2248 //_____________________________________________________________________________
2252 // Initialise TPC detector after definition of geometry
2254 AliDebug(1,"*********************************************");
2257 //_____________________________________________________________________________
2258 void AliTPC::ResetDigits()
2261 // Reset number of digits and the digits array for this detector
2264 if (fDigits) fDigits->Clear();
2269 //_____________________________________________________________________________
2270 void AliTPC::SetSens(Int_t sens)
2273 //-------------------------------------------------------------
2274 // Activates/deactivates the sensitive strips at the center of
2275 // the pad row -- this is for the space-point resolution calculations
2276 //-------------------------------------------------------------
2278 //-----------------------------------------------------------------
2279 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2280 //-----------------------------------------------------------------
2286 void AliTPC::SetSide(Float_t side=0.)
2288 // choice of the TPC side
2293 //_____________________________________________________________________________
2295 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2298 // electron transport taking into account:
2300 // 2.ExB at the wires
2301 // 3. nonisochronity
2303 // xyz and index must be already transformed to system 1
2306 fTPCParam->Transform1to2(xyz,index); // mis-alignment applied in this step
2309 Float_t driftl=xyz[2];
2310 if(driftl<0.01) driftl=0.01;
2311 driftl=TMath::Sqrt(driftl);
2312 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2313 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2314 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2315 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2316 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2320 if (fTPCParam->GetMWPCReadout()==kTRUE){
2321 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2322 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2324 //add nonisochronity (not implemented yet)
2330 //______________________________________________________________________
2331 AliTPChit::AliTPChit()
2343 //_____________________________________________________________________________
2344 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits)
2345 :AliHit(shunt,track),
2352 // Creates a TPC hit object
2363 //________________________________________________________________________
2364 // Additional code because of the AliTPCTrackHitsV2
2366 void AliTPC::MakeBranch(Option_t *option)
2369 // Create a new branch in the current Root Tree
2370 // The branch of fHits is automatically split
2371 // MI change 14.09.2000
2373 if (fHitType<2) return;
2374 char branchname[10];
2375 //sprintf(branchname,"%s2",GetName());
2376 snprintf(branchname,10,"%s2",GetName());
2378 // Get the pointer to the header
2379 const char *cH = strstr(option,"H");
2381 if (fTrackHits && fLoader->TreeH() && cH && fHitType&4) {
2382 AliDebug(1,"Making branch for Type 4 Hits");
2383 fLoader->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2386 // if (fTrackHitsOld && fLoader->TreeH() && cH && fHitType&2) {
2387 // AliDebug(1,"Making branch for Type 2 Hits");
2388 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2389 // fLoader->TreeH(),fBufferSize,99);
2390 // fLoader->TreeH()->GetListOfBranches()->Add(branch);
2394 void AliTPC::SetTreeAddress()
2396 //Sets tree address for hits
2398 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2399 AliDetector::SetTreeAddress();
2401 if (fHitType>1) SetTreeAddress2();
2404 void AliTPC::SetTreeAddress2()
2407 // Set branch address for the TrackHits Tree
2412 char branchname[20];
2413 //sprintf(branchname,"%s2",GetName());
2414 snprintf(branchname,20,"%s2",GetName());
2416 // Branch address for hit tree
2417 TTree *treeH = fLoader->TreeH();
2418 if ((treeH)&&(fHitType&4)) {
2419 branch = treeH->GetBranch(branchname);
2421 branch->SetAddress(&fTrackHits);
2422 AliDebug(1,"fHitType&4 Setting");
2425 AliDebug(1,"fHitType&4 Failed (can not find branch)");
2428 // if ((treeH)&&(fHitType&2)) {
2429 // branch = treeH->GetBranch(branchname);
2431 // branch->SetAddress(&fTrackHitsOld);
2432 // AliDebug(1,"fHitType&2 Setting");
2435 // AliDebug(1,"fHitType&2 Failed (can not find branch)");
2439 void AliTPC::FinishPrimary()
2441 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2442 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2446 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2449 // add hit to the list
2453 int primary = gAlice->GetMCApp()->GetPrimary(track);
2454 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2458 gAlice->GetMCApp()->FlagTrack(track);
2460 if (fTrackHits && fHitType&4)
2461 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2462 hits[1],hits[2],(Int_t)hits[3],hits[4]);
2463 // if (fTrackHitsOld &&fHitType&2 )
2464 // fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2465 // hits[1],hits[2],(Int_t)hits[3]);
2469 void AliTPC::ResetHits()
2471 if (fHitType&1) AliDetector::ResetHits();
2472 if (fHitType>1) ResetHits2();
2475 void AliTPC::ResetHits2()
2479 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2480 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2484 AliHit* AliTPC::FirstHit(Int_t track)
2486 if (fHitType>1) return FirstHit2(track);
2487 return AliDetector::FirstHit(track);
2489 AliHit* AliTPC::NextHit()
2494 if (fHitType>1) return NextHit2();
2496 return AliDetector::NextHit();
2499 AliHit* AliTPC::FirstHit2(Int_t track)
2502 // Initialise the hit iterator
2503 // Return the address of the first hit for track
2504 // If track>=0 the track is read from disk
2505 // while if track<0 the first hit of the current
2506 // track is returned
2509 gAlice->GetMCApp()->ResetHits();
2510 fLoader->TreeH()->GetEvent(track);
2513 if (fTrackHits && fHitType&4) {
2514 fTrackHits->First();
2515 return fTrackHits->GetHit();
2517 // if (fTrackHitsOld && fHitType&2) {
2518 // fTrackHitsOld->First();
2519 // return fTrackHitsOld->GetHit();
2525 AliHit* AliTPC::NextHit2()
2528 //Return the next hit for the current track
2531 // if (fTrackHitsOld && fHitType&2) {
2532 // fTrackHitsOld->Next();
2533 // return fTrackHitsOld->GetHit();
2537 return fTrackHits->GetHit();
2543 void AliTPC::RemapTrackHitIDs(Int_t *map)
2548 if (!fTrackHits) return;
2550 // if (fTrackHitsOld && fHitType&2){
2551 // AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2552 // for (UInt_t i=0;i<arr->GetSize();i++){
2553 // AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2554 // info->fTrackID = map[info->fTrackID];
2557 // if (fTrackHitsOld && fHitType&4){
2558 if (fTrackHits && fHitType&4){
2559 TClonesArray * arr = fTrackHits->GetArray();;
2560 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2561 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2562 info->SetTrackID(map[info->GetTrackID()]);
2567 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2569 //return bool information - is track in given volume
2570 //load only part of the track information
2571 //return true if current track is in volume
2574 // if (fTrackHitsOld && fHitType&2) {
2575 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
2576 // br->GetEvent(track);
2577 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2578 // for (UInt_t j=0;j<ar->GetSize();j++){
2579 // if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2583 if (fTrackHits && fHitType&4) {
2584 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
2585 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
2586 br2->GetEvent(track);
2587 br1->GetEvent(track);
2588 Int_t *volumes = fTrackHits->GetVolumes();
2589 Int_t nvolumes = fTrackHits->GetNVolumes();
2590 if (!volumes && nvolumes>0) {
2591 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2594 for (Int_t j=0;j<nvolumes; j++)
2595 if (volumes[j]==id) return kTRUE;
2599 TBranch * br = fLoader->TreeH()->GetBranch("fSector");
2600 br->GetEvent(track);
2601 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2602 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2610 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2613 fLoader = new AliTPCLoader(GetName(),topfoldername);
2617 ////////////////////////////////////////////////////////////////////////
2618 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2620 // load TPC paarmeters from a given file or create new if the object
2621 // is not found there
2622 // 12/05/2003 This method should be moved to the AliTPCLoader
2623 // and one has to decide where to store the TPC parameters
2626 //sprintf(paramName,"75x40_100x60_150x60");
2627 snprintf(paramName,50,"75x40_100x60_150x60");
2628 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2630 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2632 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2633 //paramTPC = new AliTPCParamSR;
2634 paramTPC = AliTPCcalibDB::Instance()->GetParameters();
2635 if (!paramTPC->IsGeoRead()){
2637 // read transformation matrices for gGeoManager
2639 paramTPC->ReadGeoMatrices();
2645 // the older version of parameters can be accessed with this code.
2646 // In some cases, we have old parameters saved in the file but
2647 // digits were created with new parameters, it can be distinguish
2648 // by the name of TPC TreeD. The code here is just for the case
2649 // we would need to compare with old data, uncomment it if needed.
2651 // char paramName[50];
2652 // sprintf(paramName,"75x40_100x60");
2653 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2655 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2657 // sprintf(paramName,"75x40_100x60_150x60");
2658 // paramTPC=(AliTPCParam*)in->Get(paramName);
2660 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2662 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2664 // paramTPC = new AliTPCParamSR;