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,"Default")) {
185 //fTPCParam = new AliTPCParamSR;
186 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
299 // Ne-CO2 (90-10) (volume) values at 20deg and 1 atm.
300 // rho(Ne) = 0.839 g/cm^3, rho(CO2) = 1.842 g/cm^3
313 //wmat[0]=0.756992632;
315 //wmat[1]=0.056235789;
317 //wmat[2]=0.128469474;
319 // wmat[3]=0.058395789;
323 AliMixture(12,"Ne-CO2-1",amat,zmat,density,3,wmat);
324 AliMixture(13,"Ne-CO2-2",amat,zmat,density,3,wmat);
325 AliMixture(35,"Ne-CO2-3",amat,zmat,density,3,wmat);
326 //----------------------------------------------------------------------
328 //----------------------------------------------------------------------
350 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
371 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
389 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
407 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
425 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
426 // material for "prepregs"
427 // Epoxy - C14 H20 O3
430 // prepreg1 60% C-fiber, 40% epoxy (vol)
445 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
447 //prepreg2 60% glass-fiber, 40% epoxy
466 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
468 //prepreg3 50% glass-fiber, 50% epoxy
487 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
489 // G10 60% SiO2 40% epoxy
508 AliMixture(22, "G10",amat,zmat,density,4,wmat);
517 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
519 // Si (for electronics
526 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
535 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
553 AliMixture(33,"Brass",amat,zmat,density,2,wmat);
555 // Epoxy - C14 H20 O3
571 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
573 // epoxy film - 90% epoxy, 10% glass fiber
593 AliMixture(34, "Epoxy-film",amat,zmat,density,4,wmat);
611 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
619 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
621 // Fe (steel for the inner heat screen)
629 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
631 // Peek - (C6H4-O-OC6H4-O-C6H4-CO)n
646 AliMixture(30,"Peek",amat,zmat,density,-3,wmat);
661 AliMixture(31,"Alumina",amat,zmat,density,-2,wmat);
680 AliMixture(32,"Water",amat,zmat,density,-2,wmat);
683 //----------------------------------------------------------
684 // tracking media for gases
685 //----------------------------------------------------------
687 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
688 AliMedium(1, "Ne-CO2-1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
689 AliMedium(2, "Ne-CO2-2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
690 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
691 AliMedium(20, "Ne-CO2-3", 35, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
692 //-----------------------------------------------------------
693 // tracking media for solids
694 //-----------------------------------------------------------
696 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
697 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
698 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
699 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
700 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
701 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
703 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
704 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
705 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
706 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
708 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
709 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
710 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
711 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
712 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
713 AliMedium(19,"Peek",30,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
714 AliMedium(21,"Alumina",31,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
715 AliMedium(22,"Water",32,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
716 AliMedium(23,"Brass",33,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
717 AliMedium(24,"Epoxyfm",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
720 void AliTPC::GenerNoise(Int_t tablesize)
723 //Generate table with noise
730 if (fNoiseTable) delete[] fNoiseTable;
731 fNoiseTable = new Float_t[tablesize];
732 fNoiseDepth = tablesize;
733 fCurrentNoise =0; //!index of the noise in the noise table
735 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
736 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
739 Float_t AliTPC::GetNoise()
741 // get noise from table
742 // if ((fCurrentNoise%10)==0)
743 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
744 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
745 return fNoiseTable[fCurrentNoise++];
746 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
750 Bool_t AliTPC::IsSectorActive(Int_t sec) const
753 // check if the sector is active
754 if (!fActiveSectors) return kTRUE;
755 else return fActiveSectors[sec];
758 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
760 // activate interesting sectors
761 SetTreeAddress();//just for security
762 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
763 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
764 for (Int_t i=0;i<n;i++)
765 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
769 void AliTPC::SetActiveSectors(Int_t flag)
772 // activate sectors which were hitted by tracks
774 SetTreeAddress();//just for security
775 if (fHitType==0) return; // if Clones hit - not short volume ID information
776 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
778 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
781 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
782 //TBranch * branch=0;
783 if (fLoader->TreeH() == 0x0)
785 AliFatal("Can not find TreeH in folder");
788 //if (fHitType>1) branch = fLoader->TreeH()->GetBranch("TPC2");
789 if (fHitType>1) fLoader->TreeH()->GetBranch("TPC2");
790 //else branch = fLoader->TreeH()->GetBranch("TPC");
791 else fLoader->TreeH()->GetBranch("TPC");
792 Stat_t ntracks = fLoader->TreeH()->GetEntries();
793 // loop over all hits
794 AliDebug(1,Form("Got %d tracks", (Int_t) ntracks));
796 for(Int_t track=0;track<ntracks;track++) {
799 if (fTrackHits && fHitType&4) {
800 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
801 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
802 br1->GetEvent(track);
803 br2->GetEvent(track);
804 Int_t *volumes = fTrackHits->GetVolumes();
805 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++) {
806 if (volumes[j]>-1 && volumes[j]<fTPCParam->GetNSector()) {
807 fActiveSectors[volumes[j]]=kTRUE;
810 AliError(Form("Volume %d -> sector number %d is outside (0..%d)",
813 fTPCParam->GetNSector()));
819 // if (fTrackHitsOld && fHitType&2) {
820 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
821 // br->GetEvent(track);
822 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
823 // for (UInt_t j=0;j<ar->GetSize();j++){
824 // fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
833 //_____________________________________________________________________________
834 void AliTPC::Digits2Raw()
836 // convert digits of the current event to raw data
838 static const Int_t kThreshold = 0;
840 fLoader->LoadDigits();
841 TTree* digits = fLoader->TreeD();
843 AliError("No digits tree");
849 AliSimDigits* digrow = &digarr;
850 digits->GetBranch("Segment")->SetAddress(&digrow);
852 const char* fileName = "AliTPCDDL.dat";
853 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
857 // 2: txt files with digits
858 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
859 //it is highly suggested to use this mode only for debugging digits files
860 //reasonably small, because otherwise the size of the txt files can reach
861 //quickly several MB wasting time and disk space.
862 buffer->SetVerbose(0);
864 Int_t nEntries = Int_t(digits->GetEntries());
865 Int_t previousSector = -1;
867 for (Int_t i = 0; i < nEntries; i++) {
870 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
871 if(previousSector != sector) {
873 previousSector = sector;
876 if (sector < 36) { //inner sector [0;35]
878 //the whole row is written into the output file
879 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
880 sector, subSector, row);
882 //only the pads in the range [37;48] are written into the output file
883 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
884 sector, subSector, row);
886 //only the pads outside the range [37;48] are written into the output file
887 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
888 sector, subSector, row);
891 } else { //outer sector [36;71]
892 if (row == 54) subSector = 2;
893 if ((row != 27) && (row != 76)) {
894 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
895 sector, subSector, row);
896 } else if (row == 27) {
897 //only the pads outside the range [43;46] are written into the output file
898 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
899 sector, subSector, row);
901 //only the pads in the range [43;46] are written into the output file
902 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
903 sector, subSector, row);
904 } else if (row == 76) {
905 //only the pads outside the range [33;88] are written into the output file
906 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
907 sector, subSector, row);
909 //only the pads in the range [33;88] are written into the output file
910 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
911 sector, subSector, row);
917 fLoader->UnloadDigits();
919 AliTPCDDLRawData rawWriter;
920 rawWriter.SetVerbose(0);
922 rawWriter.RawData(fileName);
923 gSystem->Unlink(fileName);
928 //_____________________________________________________________________________
929 Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
930 // Converts the TPC raw data into summable digits
931 // The method is used for merging simulated and
933 if (fLoader->TreeS() == 0x0 ) {
934 fLoader->MakeTree("S");
937 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
939 //setup TPCDigitsArray
940 if(GetDigitsArray()) delete GetDigitsArray();
942 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
943 arr->SetClass("AliSimDigits");
944 arr->Setup(fTPCParam);
945 arr->MakeTree(fLoader->TreeS());
949 // set zero suppression to "0"
950 fTPCParam->SetZeroSup(0);
953 const Int_t kmaxTime = fTPCParam->GetMaxTBin();
954 const Int_t kNIS = fTPCParam->GetNInnerSector();
955 const Int_t kNOS = fTPCParam->GetNOuterSector();
956 const Int_t kNS = kNIS + kNOS;
959 AliTPCROC * roc = AliTPCROC::Instance();
960 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
961 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
962 Short_t** allBins = new Short_t*[nRowsMax];
963 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
964 Int_t maxBin = kmaxTime*nPadsMax;
965 allBins[iRow] = new Short_t[maxBin];
966 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
969 for(Int_t iSector = 0; iSector < kNS; iSector++) {
971 Int_t nRows = fTPCParam->GetNRow(iSector);
972 Int_t nDDLs = 0, indexDDL = 0;
973 if (iSector < kNIS) {
975 indexDDL = iSector * 2;
979 indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
982 // Load the raw data for corresponding DDLs
985 AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
986 AliTPCRawStreamV3 input(rawReader,(AliAltroMapping**)mapping);
987 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
990 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
991 Int_t maxBin = kmaxTime*nPadsMax;
992 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
995 // Begin loop over altro data
996 while (input.NextDDL()) {
998 if (input.GetSector() != iSector)
999 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
1002 while ( input.NextChannel() ) {
1004 Int_t iRow = input.GetRow();
1005 if (iRow < 0 || iRow >= nRows)
1006 AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
1007 iRow, 0, nRows -1));
1008 Int_t iPad = input.GetPad();
1010 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1012 if (iPad < 0 || iPad >= maxPad)
1013 AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
1014 iPad, 0, maxPad -1));
1017 while ( input.NextBunch() ){
1018 Int_t startTbin = (Int_t)input.GetStartTimeBin();
1019 Int_t bunchlength = (Int_t)input.GetBunchLength();
1020 const UShort_t *sig = input.GetSignals();
1021 for (Int_t iTime = 0; iTime<bunchlength; iTime++){
1022 Int_t iTimeBin=startTbin-iTime;
1023 if ( iTimeBin < 0 || iTimeBin >= kmaxTime) {
1025 //AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
1026 // iTimeBin, 0, kmaxTime -1));
1029 Int_t maxBin = kmaxTime*maxPad;
1030 if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
1031 ((iPad*kmaxTime+iTimeBin) < 0))
1032 AliFatal(Form("Index outside the allowed range"
1033 " Sector=%d Row=%d Pad=%d Timebin=%d"
1034 " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
1035 allBins[iRow][iPad*kmaxTime+iTimeBin] = sig[iTime];
1038 } // End loop over altro data
1041 // Now fill the digits array
1042 if (fDigitsArray->GetTree()==0) {
1043 AliFatal("Tree not set in fDigitsArray");
1046 for (Int_t iRow = 0; iRow < nRows; iRow++) {
1047 AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
1048 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1049 for(Int_t iPad = 0; iPad < maxPad; iPad++) {
1050 for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
1051 Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
1052 if (q <= 0) continue;
1054 dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
1055 ((AliSimDigits*)dig)->SetTrackIDFast( 3141593, iTimeBin,iPad,0);
1058 fDigitsArray->StoreRow(iSector,iRow);
1059 Int_t ndig = dig->GetDigitSize();
1062 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1063 iSector,iRow,ndig));
1065 fDigitsArray->ClearRow(iSector,iRow);
1067 } // end of the sector digitization
1069 // get LHC clock phase from the digits tree
1071 TParameter<float> *ph;
1073 TTree *digtree = fLoader->TreeD();
1075 if(digtree){ // if TreeD exists
1076 ph = (TParameter<float>*)digtree->GetUserInfo()->FindObject("lhcphase0");
1077 phase = ph->GetVal();
1079 else{ //TreeD does not exist
1083 // store lhc clock phase in S-digits tree
1085 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",phase));
1087 fLoader->WriteSDigits("OVERWRITE");
1089 if(GetDigitsArray()) delete GetDigitsArray();
1090 SetDigitsArray(0x0);
1093 for (Int_t iRow = 0; iRow < nRowsMax; iRow++)
1094 delete [] allBins[iRow];
1100 //______________________________________________________________________
1101 AliDigitizer* AliTPC::CreateDigitizer(AliDigitizationInput* digInput) const
1103 return new AliTPCDigitizer(digInput);
1106 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
1108 //create digits from summable digits
1109 GenerNoise(500000); //create teble with noise
1111 //conect tree with sSDigits
1112 TTree *t = fLoader->TreeS();
1115 fLoader->LoadSDigits("READ");
1116 t = fLoader->TreeS();
1118 AliError("Can not get input TreeS");
1123 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1125 AliSimDigits digarr, *dummy=&digarr;
1126 TBranch* sdb = t->GetBranch("Segment");
1128 AliError("Can not find branch with segments in TreeS.");
1132 sdb->SetAddress(&dummy);
1134 Stat_t nentries = t->GetEntries();
1136 // set zero suppression
1138 fTPCParam->SetZeroSup(2);
1140 // get zero suppression
1142 Int_t zerosup = fTPCParam->GetZeroSup();
1144 //make tree with digits
1146 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1147 arr->SetClass("AliSimDigits");
1148 arr->Setup(fTPCParam);
1149 arr->MakeTree(fLoader->TreeD());
1151 AliTPCParam * par = fTPCParam;
1153 //Loop over segments of the TPC
1155 for (Int_t n=0; n<nentries; n++) {
1158 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1159 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
1162 if (!IsSectorActive(sec)) continue;
1164 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1165 Int_t nrows = digrow->GetNRows();
1166 Int_t ncols = digrow->GetNCols();
1168 digrow->ExpandBuffer();
1169 digarr.ExpandBuffer();
1170 digrow->ExpandTrackBuffer();
1171 digarr.ExpandTrackBuffer();
1174 Short_t * pamp0 = digarr.GetDigits();
1175 Int_t * ptracks0 = digarr.GetTracks();
1176 Short_t * pamp1 = digrow->GetDigits();
1177 Int_t * ptracks1 = digrow->GetTracks();
1178 Int_t nelems =nrows*ncols;
1179 Int_t saturation = fTPCParam->GetADCSat() - 1;
1180 //use internal structure of the AliDigits - for speed reason
1181 //if you cahnge implementation
1182 //of the Alidigits - it must be rewriten -
1183 for (Int_t i= 0; i<nelems; i++){
1184 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1186 if (q>saturation) q=saturation;
1189 ptracks1[0]=ptracks0[0];
1190 ptracks1[nelems]=ptracks0[nelems];
1191 ptracks1[2*nelems]=ptracks0[2*nelems];
1199 arr->StoreRow(sec,row);
1200 arr->ClearRow(sec,row);
1205 fLoader->WriteDigits("OVERWRITE");
1209 //__________________________________________________________________
1210 void AliTPC::SetDefaults(){
1212 // setting the defaults
1215 // Set response functions
1218 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1220 //AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1221 //gDirectory->Get("75x40_100x60");
1222 AliTPCParamSR *param = (AliTPCParamSR*)AliTPCcalibDB::Instance()->GetParameters();
1224 AliFatal("No TPC parameters found");
1227 if (!param->IsGeoRead()){
1229 // read transformation matrices for gGeoManager
1231 param->ReadGeoMatrices();
1236 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1237 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1238 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1241 //AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1242 //rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1243 //rf->SetOffset(3*param->GetZSigma());
1248 char strgamma4[1000];
1249 //sprintf(strgamma4,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
1251 snprintf(strgamma4,1000,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
1252 TF1 * fgamma4 = new TF1("fgamma4",strgamma4, -1,1);
1253 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE,1000);
1254 rf->SetParam(fgamma4,param->GetZWidth(), 1,0.2);
1255 rf->SetOffset(3*param->GetZSigma());
1257 TDirectory *savedir=gDirectory;
1260 printf ("TPC MWPC readout\n");
1261 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1263 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1266 prfinner->Read("prf_07504_Gati_056068_d02");
1267 //PH Set different names
1268 s=prfinner->GetGRF()->GetName();
1270 prfinner->GetGRF()->SetName(s.Data());
1272 prfouter1->Read("prf_10006_Gati_047051_d03");
1273 s=prfouter1->GetGRF()->GetName();
1275 prfouter1->GetGRF()->SetName(s.Data());
1277 prfouter2->Read("prf_15006_Gati_047051_d03");
1278 s=prfouter2->GetGRF()->GetName();
1280 prfouter2->GetGRF()->SetName(s.Data());
1285 printf ("TPC GEM readout\n");
1286 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2dGEM.root");
1288 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2dGEM.root !");
1291 prfinner->Read("prf0");
1292 //PH Set different names
1293 s=prfinner->GetGRF()->GetName();
1295 prfinner->GetGRF()->SetName(s.Data());
1297 prfouter1->Read("prf1");
1298 s=prfouter1->GetGRF()->GetName();
1300 prfouter1->GetGRF()->SetName(s.Data());
1302 prfouter2->Read("prf2");
1303 s=prfouter2->GetGRF()->GetName();
1305 prfouter2->GetGRF()->SetName(s.Data());
1310 param->SetInnerPRF(prfinner);
1311 param->SetOuter1PRF(prfouter1);
1312 param->SetOuter2PRF(prfouter2);
1313 param->SetTimeRF(rf);
1323 //__________________________________________________________________
1324 void AliTPC::Hits2Digits()
1327 // creates digits from hits
1329 if (!fTPCParam->IsGeoRead()){
1331 // read transformation matrices for gGeoManager
1333 fTPCParam->ReadGeoMatrices();
1336 fLoader->LoadHits("read");
1337 fLoader->LoadDigits("recreate");
1338 AliRunLoader* runLoader = fLoader->GetRunLoader();
1340 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1341 //PH runLoader->GetEvent(iEvent);
1342 Hits2Digits(iEvent);
1345 fLoader->UnloadHits();
1346 fLoader->UnloadDigits();
1348 //__________________________________________________________________
1349 void AliTPC::Hits2Digits(Int_t eventnumber)
1351 //----------------------------------------------------
1352 // Loop over all sectors for a single event
1353 //----------------------------------------------------
1354 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1355 rl->GetEvent(eventnumber);
1357 if (fLoader->TreeH() == 0x0) {
1358 if(fLoader->LoadHits()) {
1359 AliError("Can not load hits.");
1364 if (fLoader->TreeD() == 0x0 ) {
1365 fLoader->MakeTree("D");
1366 if (fLoader->TreeD() == 0x0 ) {
1367 AliError("Can not get TreeD");
1372 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1373 GenerNoise(500000); //create teble with noise
1375 //setup TPCDigitsArray
1377 if(GetDigitsArray()) delete GetDigitsArray();
1379 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1380 arr->SetClass("AliSimDigits");
1381 arr->Setup(fTPCParam);
1383 arr->MakeTree(fLoader->TreeD());
1384 SetDigitsArray(arr);
1386 fDigitsSwitch=0; // standard digits
1387 // here LHC clock phase
1389 switch (fLHCclockPhaseSw){
1396 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1400 // not implemented yet
1403 // adding phase to the TreeD user info
1404 fLoader->TreeD()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1406 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1407 if (IsSectorActive(isec)) {
1408 AliDebug(1,Form("Hits2Digits: Sector %d is active.",isec));
1409 Hits2DigitsSector(isec);
1412 AliDebug(1,Form("Hits2Digits: Sector %d is NOT active.",isec));
1415 fLoader->WriteDigits("OVERWRITE");
1417 //this line prevents the crash in the similar one
1418 //on the beginning of this method
1419 //destructor attempts to reset the tree, which is deleted by the loader
1420 //need to be redesign
1421 if(GetDigitsArray()) delete GetDigitsArray();
1422 SetDigitsArray(0x0);
1426 //__________________________________________________________________
1427 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1430 //-----------------------------------------------------------
1431 // summable digits - 16 bit "ADC", no noise, no saturation
1432 //-----------------------------------------------------------
1434 //----------------------------------------------------
1435 // Loop over all sectors for a single event
1436 //----------------------------------------------------
1438 AliRunLoader* rl = fLoader->GetRunLoader();
1440 rl->GetEvent(eventnumber);
1441 if (fLoader->TreeH() == 0x0) {
1442 if(fLoader->LoadHits()) {
1443 AliError("Can not load hits.");
1450 if (fLoader->TreeS() == 0x0 ) {
1451 fLoader->MakeTree("S");
1454 if(fDefaults == 0) SetDefaults();
1456 GenerNoise(500000); //create table with noise
1457 //setup TPCDigitsArray
1459 if(GetDigitsArray()) delete GetDigitsArray();
1462 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1463 arr->SetClass("AliSimDigits");
1464 arr->Setup(fTPCParam);
1465 arr->MakeTree(fLoader->TreeS());
1467 SetDigitsArray(arr);
1469 fDigitsSwitch=1; // summable digits
1471 // set zero suppression to "0"
1472 // here LHC clock phase
1474 switch (fLHCclockPhaseSw){
1481 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1485 // not implemented yet
1488 // adding phase to the TreeS user info
1490 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1492 fTPCParam->SetZeroSup(0);
1494 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1495 if (IsSectorActive(isec)) {
1496 Hits2DigitsSector(isec);
1499 fLoader->WriteSDigits("OVERWRITE");
1501 //this line prevents the crash in the similar one
1502 //on the beginning of this method
1503 //destructor attempts to reset the tree, which is deleted by the loader
1504 //need to be redesign
1505 if(GetDigitsArray()) delete GetDigitsArray();
1506 SetDigitsArray(0x0);
1508 //__________________________________________________________________
1510 void AliTPC::Hits2SDigits()
1513 //-----------------------------------------------------------
1514 // summable digits - 16 bit "ADC", no noise, no saturation
1515 //-----------------------------------------------------------
1517 if (!fTPCParam->IsGeoRead()){
1519 // read transformation matrices for gGeoManager
1521 fTPCParam->ReadGeoMatrices();
1524 fLoader->LoadHits("read");
1525 fLoader->LoadSDigits("recreate");
1526 AliRunLoader* runLoader = fLoader->GetRunLoader();
1528 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1529 runLoader->GetEvent(iEvent);
1532 Hits2SDigits2(iEvent);
1535 fLoader->UnloadHits();
1536 fLoader->UnloadSDigits();
1537 if (fDebugStreamer) {
1538 delete fDebugStreamer;
1542 //_____________________________________________________________________________
1544 void AliTPC::Hits2DigitsSector(Int_t isec)
1546 //-------------------------------------------------------------------
1547 // TPC conversion from hits to digits.
1548 //-------------------------------------------------------------------
1550 //-----------------------------------------------------------------
1551 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1552 //-----------------------------------------------------------------
1554 //-------------------------------------------------------
1555 // Get the access to the track hits
1556 //-------------------------------------------------------
1558 // check if the parameters are set - important if one calls this method
1559 // directly, not from the Hits2Digits
1561 if(fDefaults == 0) SetDefaults();
1563 TTree *tH = fLoader->TreeH(); // pointer to the hits tree
1565 AliFatal("Can not find TreeH in folder");
1569 Stat_t ntracks = tH->GetEntries();
1571 Int_t nrows =fTPCParam->GetNRow(isec);
1573 TObjArray **row=new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1574 for(Int_t j=0;j<nrows+2;j++) row[j]=0;
1576 MakeSector(isec,nrows,tH,ntracks,row);
1578 //--------------------------------------------------------
1579 // Digitize this sector, row by row
1580 // row[i] is the pointer to the TObjArray of TVectors,
1581 // each one containing electrons accepted on this
1582 // row, assigned into tracks
1583 //--------------------------------------------------------
1587 if (fDigitsArray->GetTree()==0) {
1588 AliFatal("Tree not set in fDigitsArray");
1591 for (i=0;i<nrows;i++){
1593 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1595 DigitizeRow(i,isec,row);
1597 fDigitsArray->StoreRow(isec,i);
1599 Int_t ndig = dig->GetDigitSize();
1602 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1605 fDigitsArray->ClearRow(isec,i);
1608 } // end of the sector digitization
1610 for(i=0;i<nrows+2;i++){
1615 delete [] row; // delete the array of pointers to TObjArray-s
1618 } // end of Hits2DigitsSector
1621 //_____________________________________________________________________________
1622 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1624 //-----------------------------------------------------------
1625 // Single row digitization, coupling from the neighbouring
1626 // rows taken into account
1627 //-----------------------------------------------------------
1629 //-----------------------------------------------------------------
1630 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1631 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1632 //-----------------------------------------------------------------
1634 Float_t zerosup = fTPCParam->GetZeroSup();
1635 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
1636 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
1637 AliTPCCalROC * gainROC = gainTPC->GetCalROC(isec); // pad gains per given sector
1638 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(isec); // noise per given sector
1641 fCurrentIndex[1]= isec;
1644 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1645 Int_t nofTbins = fTPCParam->GetMaxTBin();
1646 Int_t indexRange[4];
1648 // Integrated signal for this row
1649 // and a single track signal
1652 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1653 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
1655 TMatrixF &total = *m1;
1657 // Array of pointers to the label-signal list
1659 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1660 Float_t **pList = new Float_t* [nofDigits];
1664 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1670 for (Int_t row= row1;row<=row2;row++){
1671 Int_t nTracks= rows[row]->GetEntries();
1672 for (i1=0;i1<nTracks;i1++){
1673 fCurrentIndex[2]= row;
1674 fCurrentIndex[3]=irow+1;
1676 m2->Zero(); // clear single track signal matrix
1677 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1678 GetList(trackLabel,nofPads,m2,indexRange,pList);
1680 else GetSignal(rows[row],i1,0,m1,indexRange);
1686 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1688 Float_t fzerosup = zerosup+0.5;
1689 for(Int_t it=0;it<nofTbins;it++){
1690 for(Int_t ip=0;ip<nofPads;ip++){
1692 Float_t q=total(ip,it);
1693 if(fDigitsSwitch == 0){
1694 Float_t gain = gainROC->GetValue(irow,ip); // get gain for given - pad-row pad
1695 Float_t noisePad = noiseROC->GetValue(irow,ip);
1698 q+=GetNoise()*noisePad;
1699 if(q <=fzerosup) continue; // do not fill zeros
1701 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
1706 if(q <= 0.) continue; // do not fill zeros
1707 if(q>2000.) q=2000.;
1713 // "real" signal or electronic noise (list = -1)?
1716 for(Int_t j1=0;j1<3;j1++){
1717 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1722 <A NAME="AliDigits"></A>
1723 using of AliDigits object
1726 dig->SetDigitFast((Short_t)q,it,ip);
1727 if (fDigitsArray->IsSimulated()) {
1728 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1729 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1730 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1733 } // end of loop over time buckets
1734 } // end of lop over pads
1740 // glitch filters if normal simulated digits
1742 if(!fDigitsSwitch) ((AliSimDigits*)dig)->GlitchFilter();
1744 // This row has been digitized, delete nonused stuff
1747 for(lp=0;lp<nofDigits;lp++){
1748 if(pList[lp]) delete [] pList[lp];
1756 } // end of DigitizeRow
1758 //_____________________________________________________________________________
1760 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1761 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
1764 //---------------------------------------------------------------
1765 // Calculates 2-D signal (pad,time) for a single track,
1766 // returns a pointer to the signal matrix and the track label
1767 // No digitization is performed at this level!!!
1768 //---------------------------------------------------------------
1770 //-----------------------------------------------------------------
1771 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1772 // Modified: Marian Ivanov
1773 //-----------------------------------------------------------------
1777 tv = (TVector*)p1->At(ntr); // pointer to a track
1780 Float_t label = v(0);
1781 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
1783 Int_t nElectrons = (tv->GetNrows()-1)/5;
1784 indexRange[0]=9999; // min pad
1785 indexRange[1]=-1; // max pad
1786 indexRange[2]=9999; //min time
1787 indexRange[3]=-1; // max time
1789 TMatrixF &signal = *m1;
1790 TMatrixF &total = *m2;
1792 // Get LHC clock phase
1794 TParameter<float> *ph;
1795 if(fDigitsSwitch){// s-digits
1796 ph = (TParameter<float>*)fLoader->TreeS()->GetUserInfo()->FindObject("lhcphase0");
1798 else{ // normal digits
1799 ph = (TParameter<float>*)fLoader->TreeD()->GetUserInfo()->FindObject("lhcphase0");
1801 // Loop over all electrons
1803 for(Int_t nel=0; nel<nElectrons; nel++){
1805 Float_t aval = v(idx+4);
1806 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1807 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
1808 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,
1809 fCurrentIndex[3],ph->GetVal());
1811 Int_t *index = fTPCParam->GetResBin(0);
1812 Float_t *weight = & (fTPCParam->GetResWeight(0));
1814 if (n>0) for (Int_t i =0; i<n; i++){
1815 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1818 Int_t time=index[2];
1819 Float_t qweight = *(weight)*eltoadcfac;
1821 if (m1!=0) signal(pad,time)+=qweight;
1822 total(pad,time)+=qweight;
1823 if (indexRange[0]>pad) indexRange[0]=pad;
1824 if (indexRange[1]<pad) indexRange[1]=pad;
1825 if (indexRange[2]>time) indexRange[2]=time;
1826 if (indexRange[3]<time) indexRange[3]=time;
1833 } // end of loop over electrons
1835 return label; // returns track label when finished
1838 //_____________________________________________________________________________
1839 void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
1840 Int_t *indexRange, Float_t **pList)
1842 //----------------------------------------------------------------------
1843 // Updates the list of tracks contributing to digits for a given row
1844 //----------------------------------------------------------------------
1846 //-----------------------------------------------------------------
1847 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1848 //-----------------------------------------------------------------
1850 TMatrixF &signal = *m;
1852 // lop over nonzero digits
1854 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1855 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1858 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1860 if(signal(ip,it)<0.5) continue;
1862 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1864 if(!pList[globalIndex]){
1867 // Create new list (6 elements - 3 signals and 3 labels),
1870 pList[globalIndex] = new Float_t [6];
1874 *pList[globalIndex] = -1.;
1875 *(pList[globalIndex]+1) = -1.;
1876 *(pList[globalIndex]+2) = -1.;
1877 *(pList[globalIndex]+3) = -1.;
1878 *(pList[globalIndex]+4) = -1.;
1879 *(pList[globalIndex]+5) = -1.;
1881 *pList[globalIndex] = label;
1882 *(pList[globalIndex]+3) = signal(ip,it);
1886 // check the signal magnitude
1888 Float_t highest = *(pList[globalIndex]+3);
1889 Float_t middle = *(pList[globalIndex]+4);
1890 Float_t lowest = *(pList[globalIndex]+5);
1893 // compare the new signal with already existing list
1896 if(signal(ip,it)<lowest) continue; // neglect this track
1900 if (signal(ip,it)>highest){
1901 *(pList[globalIndex]+5) = middle;
1902 *(pList[globalIndex]+4) = highest;
1903 *(pList[globalIndex]+3) = signal(ip,it);
1905 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1906 *(pList[globalIndex]+1) = *pList[globalIndex];
1907 *pList[globalIndex] = label;
1909 else if (signal(ip,it)>middle){
1910 *(pList[globalIndex]+5) = middle;
1911 *(pList[globalIndex]+4) = signal(ip,it);
1913 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1914 *(pList[globalIndex]+1) = label;
1917 *(pList[globalIndex]+5) = signal(ip,it);
1918 *(pList[globalIndex]+2) = label;
1922 } // end of loop over pads
1923 } // end of loop over time bins
1926 //___________________________________________________________________
1927 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1928 Stat_t ntracks,TObjArray **row)
1931 //-----------------------------------------------------------------
1932 // Prepares the sector digitization, creates the vectors of
1933 // tracks for each row of this sector. The track vector
1934 // contains the track label and the position of electrons.
1935 //-----------------------------------------------------------------
1938 // The trasport of the electrons through TPC drift volume
1939 // Drift (drift velocity + velocity map(not yet implemented)))
1940 // Application of the random processes (diffusion, gas gain)
1941 // Systematic effects (ExB effect in drift volume + ROCs)
1944 // Loop over primary electrons:
1945 // Creation of the secondary electrons
1946 // Loop over electrons (primary+ secondaries)
1947 // Global coordinate frame:
1948 // 1. Skip electrons if attached
1949 // 2. ExB effect in drift volume
1950 // a.) Simulation calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1951 // b.) Reconstruction - calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1952 // 3. Generation of gas gain (Random - Exponential distribution)
1953 // 4. TransportElectron function (diffusion)
1955 // 5. Conversion to the local coordinate frame pad-row, pad, timebin
1956 // 6. Apply Time0 shift - AliTPCCalPad class
1957 // a.) Plus sign in simulation
1958 // b.) Minus sign in reconstruction
1961 //-----------------------------------------------------------------
1962 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1963 // Origin: Marian Ivanov, marian.ivanov@cern.ch
1964 //-----------------------------------------------------------------
1965 AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
1966 if (gAlice){ // Set correctly the magnetic field in the ExB calculation
1967 if (!calib->GetExB()){
1968 AliMagF * field = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField());
1970 calib->SetExBField(field);
1975 Float_t gasgain = fTPCParam->GetGasGain();
1976 gasgain = gasgain/fGainFactor;
1980 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1983 if (fHitType>1) branch = TH->GetBranch("TPC2");
1984 else branch = TH->GetBranch("TPC");
1987 //----------------------------------------------
1988 // Create TObjArray-s, one for each row,
1989 // each TObjArray will store the TVectors
1990 // of electrons, one TVectors per each track.
1991 //----------------------------------------------
1993 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
1994 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
1996 for(i=0; i<nrows+2; i++){
1997 row[i] = new TObjArray;
2004 //--------------------------------------------------------------------
2005 // Loop over tracks, the "track" contains the full history
2006 //--------------------------------------------------------------------
2008 Int_t previousTrack,currentTrack;
2009 previousTrack = -1; // nothing to store so far!
2011 for(Int_t track=0;track<ntracks;track++){
2012 Bool_t isInSector=kTRUE;
2014 isInSector = TrackInVolume(isec,track);
2015 if (!isInSector) continue;
2017 branch->GetEntry(track); // get next track
2021 tpcHit = (AliTPChit*)FirstHit(-1);
2023 //--------------------------------------------------------------
2025 //--------------------------------------------------------------
2030 Int_t sector=tpcHit->fSector; // sector number
2032 tpcHit = (AliTPChit*) NextHit();
2036 // Remove hits which arrive before the TPC opening gate signal
2037 if(((fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
2038 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
2039 tpcHit = (AliTPChit*) NextHit();
2043 currentTrack = tpcHit->Track(); // track number
2045 if(currentTrack != previousTrack){
2047 // store already filled fTrack
2049 for(i=0;i<nrows+2;i++){
2050 if(previousTrack != -1){
2051 if(nofElectrons[i]>0){
2052 TVector &v = *tracks[i];
2053 v(0) = previousTrack;
2054 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2055 row[i]->Add(tracks[i]);
2058 delete tracks[i]; // delete empty TVector
2064 tracks[i] = new TVector(601); // TVectors for the next fTrack
2066 } // end of loop over rows
2068 previousTrack=currentTrack; // update track label
2071 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2073 //---------------------------------------------------
2074 // Calculate the electron attachment probability
2075 //---------------------------------------------------
2078 Float_t time = 1.e6*(fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
2079 /fTPCParam->GetDriftV();
2081 Float_t attProb = fTPCParam->GetAttCoef()*
2082 fTPCParam->GetOxyCont()*time; // fraction!
2084 //-----------------------------------------------
2085 // Loop over electrons
2086 //-----------------------------------------------
2089 for(Int_t nel=0;nel<qI;nel++){
2090 // skip if electron lost due to the attachment
2091 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2096 Double_t dxyz0[3],dxyz1[3];
2097 dxyz0[0]=tpcHit->X();
2098 dxyz0[1]=tpcHit->Y();
2099 dxyz0[2]=tpcHit->Z();
2100 if (calib->GetExB()){
2101 calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
2103 AliError("Not valid ExB calibration");
2104 dxyz1[0]=tpcHit->X();
2105 dxyz1[1]=tpcHit->Y();
2106 dxyz1[2]=tpcHit->Z();
2114 // protection for the nonphysical avalanche size (10**6 maximum)
2116 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2117 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2120 TransportElectron(xyz,index);
2122 Int_t padrow = fTPCParam->GetPadRow(xyz,index);
2124 // Add Time0 correction due unisochronity
2125 // xyz[0] - pad row coordinate
2126 // xyz[1] - pad coordinate
2127 // xyz[2] - is in now time bin coordinate system
2128 Float_t correction =0;
2129 if (calib->GetPadTime0()){
2130 if (!calib->GetPadTime0()->GetCalROC(isec)) continue;
2131 Int_t npads = fTPCParam->GetNPads(isec,padrow);
2132 // Int_t pad = TMath::Nint(xyz[1]+fTPCParam->GetNPads(isec,TMath::Nint(xyz[0]))*0.5);
2133 // pad numbering from -npads/2 .. npads/2-1
2134 Int_t pad = TMath::Nint(xyz[1]+npads/2);
2136 if (pad>=npads) pad=npads-1;
2137 correction = calib->GetPadTime0()->GetCalROC(isec)->GetValue(padrow,pad);
2138 // printf("%d\t%d\t%d\t%f\n",isec,padrow,pad,correction);
2139 if (fDebugStreamer){
2140 (*fDebugStreamer)<<"Time0"<<
2148 "cor="<<correction<<
2153 xyz[2]+=fTPCParam->GetNTBinsL1(); // adding Level 1 time bin offset
2155 // Electron track time (for pileup simulation)
2156 xyz[2]+=tpcHit->Time()/fTPCParam->GetTSample(); // adding time of flight
2160 // row 0 - cross talk from the innermost row
2161 // row fNRow+1 cross talk from the outermost row
2162 rowNumber = index[2]+1;
2163 //transform position to local digit coordinates
2164 //relative to nearest pad row
2165 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
2167 if (isec <fTPCParam->GetNInnerSector()) {
2168 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2169 y1 = fTPCParam->GetYInner(rowNumber);
2172 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2173 y1 = fTPCParam->GetYOuter(rowNumber);
2175 // gain inefficiency at the wires edges - linear
2178 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.)); */
2180 nofElectrons[rowNumber]++;
2181 //----------------------------------
2182 // Expand vector if necessary
2183 //----------------------------------
2184 if(nofElectrons[rowNumber]>120){
2185 Int_t range = tracks[rowNumber]->GetNrows();
2186 if((nofElectrons[rowNumber])>(range-1)/5){
2188 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
2192 TVector &v = *tracks[rowNumber];
2193 Int_t idx = 5*nofElectrons[rowNumber]-4;
2194 Real_t * position = &(((TVector&)v)(idx)); //make code faster
2195 memcpy(position,xyz,5*sizeof(Float_t));
2197 } // end of loop over electrons
2199 tpcHit = (AliTPChit*)NextHit();
2201 } // end of loop over hits
2202 } // end of loop over tracks
2205 // store remaining track (the last one) if not empty
2208 for(i=0;i<nrows+2;i++){
2209 if(nofElectrons[i]>0){
2210 TVector &v = *tracks[i];
2211 v(0) = previousTrack;
2212 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2213 row[i]->Add(tracks[i]);
2222 delete [] nofElectrons;
2224 } // end of MakeSector
2227 //_____________________________________________________________________________
2231 // Initialise TPC detector after definition of geometry
2233 AliDebug(1,"*********************************************");
2236 //_____________________________________________________________________________
2237 void AliTPC::ResetDigits()
2240 // Reset number of digits and the digits array for this detector
2243 if (fDigits) fDigits->Clear();
2248 //_____________________________________________________________________________
2249 void AliTPC::SetSens(Int_t sens)
2252 //-------------------------------------------------------------
2253 // Activates/deactivates the sensitive strips at the center of
2254 // the pad row -- this is for the space-point resolution calculations
2255 //-------------------------------------------------------------
2257 //-----------------------------------------------------------------
2258 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2259 //-----------------------------------------------------------------
2265 void AliTPC::SetSide(Float_t side=0.)
2267 // choice of the TPC side
2272 //_____________________________________________________________________________
2274 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2277 // electron transport taking into account:
2279 // 2.ExB at the wires
2280 // 3. nonisochronity
2282 // xyz and index must be already transformed to system 1
2285 fTPCParam->Transform1to2(xyz,index); // mis-alignment applied in this step
2288 Float_t driftl=xyz[2];
2289 if(driftl<0.01) driftl=0.01;
2290 driftl=TMath::Sqrt(driftl);
2291 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2292 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2293 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2294 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2295 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2299 if (fTPCParam->GetMWPCReadout()==kTRUE){
2300 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2301 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2303 //add nonisochronity (not implemented yet)
2309 //______________________________________________________________________
2310 AliTPChit::AliTPChit()
2322 //_____________________________________________________________________________
2323 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits)
2324 :AliHit(shunt,track),
2331 // Creates a TPC hit object
2342 //________________________________________________________________________
2343 // Additional code because of the AliTPCTrackHitsV2
2345 void AliTPC::MakeBranch(Option_t *option)
2348 // Create a new branch in the current Root Tree
2349 // The branch of fHits is automatically split
2350 // MI change 14.09.2000
2352 if (fHitType<2) return;
2353 char branchname[10];
2354 //sprintf(branchname,"%s2",GetName());
2355 snprintf(branchname,10,"%s2",GetName());
2357 // Get the pointer to the header
2358 const char *cH = strstr(option,"H");
2360 if (fTrackHits && fLoader->TreeH() && cH && fHitType&4) {
2361 AliDebug(1,"Making branch for Type 4 Hits");
2362 fLoader->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2365 // if (fTrackHitsOld && fLoader->TreeH() && cH && fHitType&2) {
2366 // AliDebug(1,"Making branch for Type 2 Hits");
2367 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2368 // fLoader->TreeH(),fBufferSize,99);
2369 // fLoader->TreeH()->GetListOfBranches()->Add(branch);
2373 void AliTPC::SetTreeAddress()
2375 //Sets tree address for hits
2377 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2378 AliDetector::SetTreeAddress();
2380 if (fHitType>1) SetTreeAddress2();
2383 void AliTPC::SetTreeAddress2()
2386 // Set branch address for the TrackHits Tree
2391 char branchname[20];
2392 //sprintf(branchname,"%s2",GetName());
2393 snprintf(branchname,20,"%s2",GetName());
2395 // Branch address for hit tree
2396 TTree *treeH = fLoader->TreeH();
2397 if ((treeH)&&(fHitType&4)) {
2398 branch = treeH->GetBranch(branchname);
2400 branch->SetAddress(&fTrackHits);
2401 AliDebug(1,"fHitType&4 Setting");
2404 AliDebug(1,"fHitType&4 Failed (can not find branch)");
2407 // if ((treeH)&&(fHitType&2)) {
2408 // branch = treeH->GetBranch(branchname);
2410 // branch->SetAddress(&fTrackHitsOld);
2411 // AliDebug(1,"fHitType&2 Setting");
2414 // AliDebug(1,"fHitType&2 Failed (can not find branch)");
2418 void AliTPC::FinishPrimary()
2420 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2421 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2425 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2428 // add hit to the list
2432 int primary = gAlice->GetMCApp()->GetPrimary(track);
2433 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2437 gAlice->GetMCApp()->FlagTrack(track);
2439 if (fTrackHits && fHitType&4)
2440 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2441 hits[1],hits[2],(Int_t)hits[3],hits[4]);
2442 // if (fTrackHitsOld &&fHitType&2 )
2443 // fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2444 // hits[1],hits[2],(Int_t)hits[3]);
2448 void AliTPC::ResetHits()
2450 if (fHitType&1) AliDetector::ResetHits();
2451 if (fHitType>1) ResetHits2();
2454 void AliTPC::ResetHits2()
2458 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2459 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2463 AliHit* AliTPC::FirstHit(Int_t track)
2465 if (fHitType>1) return FirstHit2(track);
2466 return AliDetector::FirstHit(track);
2468 AliHit* AliTPC::NextHit()
2473 if (fHitType>1) return NextHit2();
2475 return AliDetector::NextHit();
2478 AliHit* AliTPC::FirstHit2(Int_t track)
2481 // Initialise the hit iterator
2482 // Return the address of the first hit for track
2483 // If track>=0 the track is read from disk
2484 // while if track<0 the first hit of the current
2485 // track is returned
2488 gAlice->GetMCApp()->ResetHits();
2489 fLoader->TreeH()->GetEvent(track);
2492 if (fTrackHits && fHitType&4) {
2493 fTrackHits->First();
2494 return fTrackHits->GetHit();
2496 // if (fTrackHitsOld && fHitType&2) {
2497 // fTrackHitsOld->First();
2498 // return fTrackHitsOld->GetHit();
2504 AliHit* AliTPC::NextHit2()
2507 //Return the next hit for the current track
2510 // if (fTrackHitsOld && fHitType&2) {
2511 // fTrackHitsOld->Next();
2512 // return fTrackHitsOld->GetHit();
2516 return fTrackHits->GetHit();
2522 void AliTPC::RemapTrackHitIDs(Int_t *map)
2527 if (!fTrackHits) return;
2529 // if (fTrackHitsOld && fHitType&2){
2530 // AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2531 // for (UInt_t i=0;i<arr->GetSize();i++){
2532 // AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2533 // info->fTrackID = map[info->fTrackID];
2536 // if (fTrackHitsOld && fHitType&4){
2537 if (fTrackHits && fHitType&4){
2538 TClonesArray * arr = fTrackHits->GetArray();;
2539 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2540 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2541 info->SetTrackID(map[info->GetTrackID()]);
2546 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2548 //return bool information - is track in given volume
2549 //load only part of the track information
2550 //return true if current track is in volume
2553 // if (fTrackHitsOld && fHitType&2) {
2554 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
2555 // br->GetEvent(track);
2556 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2557 // for (UInt_t j=0;j<ar->GetSize();j++){
2558 // if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2562 if (fTrackHits && fHitType&4) {
2563 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
2564 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
2565 br2->GetEvent(track);
2566 br1->GetEvent(track);
2567 Int_t *volumes = fTrackHits->GetVolumes();
2568 Int_t nvolumes = fTrackHits->GetNVolumes();
2569 if (!volumes && nvolumes>0) {
2570 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2573 for (Int_t j=0;j<nvolumes; j++)
2574 if (volumes[j]==id) return kTRUE;
2578 TBranch * br = fLoader->TreeH()->GetBranch("fSector");
2579 br->GetEvent(track);
2580 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2581 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2589 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2592 fLoader = new AliTPCLoader(GetName(),topfoldername);
2596 ////////////////////////////////////////////////////////////////////////
2597 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2599 // load TPC paarmeters from a given file or create new if the object
2600 // is not found there
2601 // 12/05/2003 This method should be moved to the AliTPCLoader
2602 // and one has to decide where to store the TPC parameters
2605 //sprintf(paramName,"75x40_100x60_150x60");
2606 snprintf(paramName,50,"75x40_100x60_150x60");
2607 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2609 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2611 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2612 //paramTPC = new AliTPCParamSR;
2613 paramTPC = AliTPCcalibDB::Instance()->GetParameters();
2614 if (!paramTPC->IsGeoRead()){
2616 // read transformation matrices for gGeoManager
2618 paramTPC->ReadGeoMatrices();
2624 // the older version of parameters can be accessed with this code.
2625 // In some cases, we have old parameters saved in the file but
2626 // digits were created with new parameters, it can be distinguish
2627 // by the name of TPC TreeD. The code here is just for the case
2628 // we would need to compare with old data, uncomment it if needed.
2630 // char paramName[50];
2631 // sprintf(paramName,"75x40_100x60");
2632 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2634 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2636 // sprintf(paramName,"75x40_100x60_150x60");
2637 // paramTPC=(AliTPCParam*)in->Get(paramName);
2639 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2641 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2643 // paramTPC = new AliTPCParamSR;