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 "AliCTPTimeParams.h"
82 #include "AliRawReader.h"
83 #include "AliTPCRawStreamV3.h"
84 #include "TTreeStream.h"
87 //_____________________________________________________________________________
88 AliTPC::AliTPC():AliDetector(),
98 fPrimaryIonisation(0),
110 // Default constructor
113 for(Int_t i=0;i<4;i++) fCurrentIndex[i]=0;
115 // fTrackHitsOld = 0;
116 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
117 fHitType = 4; // ROOT containers
119 fHitType = 2; //default CONTAINERS - based on ROOT structure
123 //_____________________________________________________________________________
124 AliTPC::AliTPC(const char *name, const char *title)
125 : AliDetector(name,title),
135 fPrimaryIonisation(0),
147 // Standard constructor
151 // Initialise arrays of hits and digits
152 fHits = new TClonesArray("AliTPChit", 176);
153 gAlice->GetMCApp()->AddHitList(fHits);
155 fTrackHits = new AliTPCTrackHitsV2;
156 fTrackHits->SetHitPrecision(0.002);
157 fTrackHits->SetStepPrecision(0.003);
158 fTrackHits->SetMaxDistance(100);
160 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
161 //fTrackHitsOld->SetHitPrecision(0.002);
162 //fTrackHitsOld->SetStepPrecision(0.003);
163 //fTrackHitsOld->SetMaxDistance(100);
166 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
167 fHitType = 4; // ROOT containers
172 for(Int_t i=0;i<4;i++) fCurrentIndex[i]=0;
177 // Initialise color attributes
178 //PH SetMarkerColor(kYellow);
181 // Set TPC parameters
185 if (!strcmp(title,"Ne-CO2") || !strcmp(title,"Ne-CO2-N") || !strcmp(title,"Default") ) {
186 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
189 AliWarning("In Config.C you must set non-default parameters.");
194 void AliTPC::CreateDebugStremer(){
196 // Create Debug streamer to check simulation
198 fDebugStreamer = new TTreeSRedirector("TPCSimdebug.root");
200 //_____________________________________________________________________________
211 delete fTrackHits; //MI 15.09.2000
212 // delete fTrackHitsOld; //MI 10.12.2001
215 delete [] fNoiseTable;
216 delete [] fActiveSectors;
217 if (fDebugStreamer) delete fDebugStreamer;
220 //_____________________________________________________________________________
221 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
224 // Add a hit to the list
227 TClonesArray &lhits = *fHits;
228 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
231 AddHit2(track,vol,hits);
234 //_____________________________________________________________________________
235 void AliTPC::CreateMaterials()
237 //-----------------------------------------------
238 // Create Materials for for TPC simulations
239 //-----------------------------------------------
241 //-----------------------------------------------------------------
242 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
243 //-----------------------------------------------------------------
245 Int_t iSXFLD=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
246 Float_t sXMGMX=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
248 Float_t amat[5]; // atomic numbers
249 Float_t zmat[5]; // z
250 Float_t wmat[5]; // proportions
256 //***************** Gases *************************
259 //--------------------------------------------------------------
260 // gases - air and CO2
261 //--------------------------------------------------------------
277 AliMixture(10,"CO2",amat,zmat,density,2,wmat);
292 AliMixture(11,"Air",amat,zmat,density,2,wmat);
294 //----------------------------------------------------------------
296 //----------------------------------------------------------------
299 // Drift gases 1 - nonsensitive, 2 - sensitive, 3 - for Kr
300 // Composition by % of volume, values at 20deg and 1 atm.
302 // get the geometry title - defined in Config.C
305 TString title(GetTitle());
317 if(title == TString("Ne-CO2") || title == TString("Default")){
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);
327 else if (title == TString("Ne-CO2-N")){
336 AliMixture(12,"Ne-CO2-N-1",amat,zmat,density,4,wmat);
337 AliMixture(13,"Ne-CO2-N-2",amat,zmat,density,4,wmat);
338 AliMixture(30,"Ne-CO2-N-3",amat,zmat,density,4,wmat);
344 //----------------------------------------------------------------------
346 //----------------------------------------------------------------------
368 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
389 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
407 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
425 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
443 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
444 // material for "prepregs"
445 // Epoxy - C14 H20 O3
448 // prepreg1 60% C-fiber, 40% epoxy (vol)
463 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
465 //prepreg2 60% glass-fiber, 40% epoxy
484 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
486 //prepreg3 50% glass-fiber, 50% epoxy
505 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
507 // G10 60% SiO2 40% epoxy
526 AliMixture(22, "G10",amat,zmat,density,4,wmat);
535 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
537 // Si (for electronics
544 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
553 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
571 AliMixture(33,"Brass",amat,zmat,density,2,wmat);
573 // Epoxy - C14 H20 O3
589 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
592 AliMixture(35,"Epoxy1",amat,zmat,density,-3,wmat);
594 // epoxy film - 90% epoxy, 10% glass fiber
614 AliMixture(34, "Epoxy-film",amat,zmat,density,4,wmat);
632 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
640 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
642 // Fe (steel for the inner heat screen)
650 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
652 // Peek - (C6H4-O-OC6H4-O-C6H4-CO)n
667 AliMixture(30,"Peek",amat,zmat,density,-3,wmat);
682 AliMixture(31,"Alumina",amat,zmat,density,-2,wmat);
701 AliMixture(32,"Water",amat,zmat,density,-2,wmat);
704 //----------------------------------------------------------
705 // tracking media for gases
706 //----------------------------------------------------------
708 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
709 AliMedium(1, "DriftGas1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
710 AliMedium(2, "DriftGas2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
711 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
712 AliMedium(20, "DriftGas3", 35, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
713 //-----------------------------------------------------------
714 // tracking media for solids
715 //-----------------------------------------------------------
717 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
718 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
719 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
720 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
721 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
722 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
724 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
725 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
726 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
727 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
729 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
730 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
731 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
732 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
733 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
734 AliMedium(19,"Peek",30,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
735 AliMedium(21,"Alumina",31,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
736 AliMedium(22,"Water",32,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
737 AliMedium(23,"Brass",33,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
738 AliMedium(24,"Epoxyfm",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
739 AliMedium(25,"Epoxy1",35,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
742 void AliTPC::GenerNoise(Int_t tablesize)
745 //Generate table with noise
752 if (fNoiseTable) delete[] fNoiseTable;
753 fNoiseTable = new Float_t[tablesize];
754 fNoiseDepth = tablesize;
755 fCurrentNoise =0; //!index of the noise in the noise table
757 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
758 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
761 Float_t AliTPC::GetNoise()
763 // get noise from table
764 // if ((fCurrentNoise%10)==0)
765 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
766 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
767 return fNoiseTable[fCurrentNoise++];
768 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
772 Bool_t AliTPC::IsSectorActive(Int_t sec) const
775 // check if the sector is active
776 if (!fActiveSectors) return kTRUE;
777 else return fActiveSectors[sec];
780 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
782 // activate interesting sectors
783 SetTreeAddress();//just for security
784 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
785 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
786 for (Int_t i=0;i<n;i++)
787 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
791 void AliTPC::SetActiveSectors(Int_t flag)
794 // activate sectors which were hitted by tracks
796 SetTreeAddress();//just for security
797 if (fHitType==0) return; // if Clones hit - not short volume ID information
798 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
800 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
803 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
804 //TBranch * branch=0;
805 if (fLoader->TreeH() == 0x0)
807 AliFatal("Can not find TreeH in folder");
810 //if (fHitType>1) branch = fLoader->TreeH()->GetBranch("TPC2");
811 if (fHitType>1) fLoader->TreeH()->GetBranch("TPC2");
812 //else branch = fLoader->TreeH()->GetBranch("TPC");
813 else fLoader->TreeH()->GetBranch("TPC");
814 Stat_t ntracks = fLoader->TreeH()->GetEntries();
815 // loop over all hits
816 AliDebug(1,Form("Got %d tracks", (Int_t) ntracks));
818 for(Int_t track=0;track<ntracks;track++) {
821 if (fTrackHits && fHitType&4) {
822 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
823 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
824 br1->GetEvent(track);
825 br2->GetEvent(track);
826 Int_t *volumes = fTrackHits->GetVolumes();
827 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++) {
828 if (volumes[j]>-1 && volumes[j]<fTPCParam->GetNSector()) {
829 fActiveSectors[volumes[j]]=kTRUE;
832 AliError(Form("Volume %d -> sector number %d is outside (0..%d)",
835 fTPCParam->GetNSector()));
841 // if (fTrackHitsOld && fHitType&2) {
842 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
843 // br->GetEvent(track);
844 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
845 // for (UInt_t j=0;j<ar->GetSize();j++){
846 // fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
855 //_____________________________________________________________________________
856 void AliTPC::Digits2Raw()
858 // convert digits of the current event to raw data
860 static const Int_t kThreshold = 0;
862 fLoader->LoadDigits();
863 TTree* digits = fLoader->TreeD();
865 AliError("No digits tree");
871 AliSimDigits* digrow = &digarr;
872 digits->GetBranch("Segment")->SetAddress(&digrow);
874 const char* fileName = "AliTPCDDL.dat";
875 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
879 // 2: txt files with digits
880 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
881 //it is highly suggested to use this mode only for debugging digits files
882 //reasonably small, because otherwise the size of the txt files can reach
883 //quickly several MB wasting time and disk space.
884 buffer->SetVerbose(0);
886 Int_t nEntries = Int_t(digits->GetEntries());
887 Int_t previousSector = -1;
889 for (Int_t i = 0; i < nEntries; i++) {
892 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
893 if(previousSector != sector) {
895 previousSector = sector;
898 if (sector < 36) { //inner sector [0;35]
900 //the whole row is written into the output file
901 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
902 sector, subSector, row);
904 //only the pads in the range [37;48] are written into the output file
905 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
906 sector, subSector, row);
908 //only the pads outside the range [37;48] are written into the output file
909 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
910 sector, subSector, row);
913 } else { //outer sector [36;71]
914 if (row == 54) subSector = 2;
915 if ((row != 27) && (row != 76)) {
916 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
917 sector, subSector, row);
918 } else if (row == 27) {
919 //only the pads outside the range [43;46] are written into the output file
920 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
921 sector, subSector, row);
923 //only the pads in the range [43;46] are written into the output file
924 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
925 sector, subSector, row);
926 } else if (row == 76) {
927 //only the pads outside the range [33;88] are written into the output file
928 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
929 sector, subSector, row);
931 //only the pads in the range [33;88] are written into the output file
932 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
933 sector, subSector, row);
939 fLoader->UnloadDigits();
941 AliTPCDDLRawData rawWriter;
942 rawWriter.SetVerbose(0);
944 rawWriter.RawData(fileName);
945 gSystem->Unlink(fileName);
950 //_____________________________________________________________________________
951 Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
952 // Converts the TPC raw data into summable digits
953 // The method is used for merging simulated and
955 if (fLoader->TreeS() == 0x0 ) {
956 fLoader->MakeTree("S");
959 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
961 //setup TPCDigitsArray
962 if(GetDigitsArray()) delete GetDigitsArray();
964 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
965 arr->SetClass("AliSimDigits");
966 arr->Setup(fTPCParam);
967 arr->MakeTree(fLoader->TreeS());
971 // set zero suppression to "0"
972 fTPCParam->SetZeroSup(0);
975 const Int_t kmaxTime = fTPCParam->GetMaxTBin();
976 const Int_t kNIS = fTPCParam->GetNInnerSector();
977 const Int_t kNOS = fTPCParam->GetNOuterSector();
978 const Int_t kNS = kNIS + kNOS;
981 AliTPCROC * roc = AliTPCROC::Instance();
982 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
983 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
984 Short_t** allBins = new Short_t*[nRowsMax];
985 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
986 Int_t maxBin = kmaxTime*nPadsMax;
987 allBins[iRow] = new Short_t[maxBin];
988 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
991 for(Int_t iSector = 0; iSector < kNS; iSector++) {
993 Int_t nRows = fTPCParam->GetNRow(iSector);
994 Int_t nDDLs = 0, indexDDL = 0;
995 if (iSector < kNIS) {
997 indexDDL = iSector * 2;
1001 indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
1004 // Load the raw data for corresponding DDLs
1007 AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
1008 AliTPCRawStreamV3 input(rawReader,(AliAltroMapping**)mapping);
1009 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
1012 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
1013 Int_t maxBin = kmaxTime*nPadsMax;
1014 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
1017 // Begin loop over altro data
1018 while (input.NextDDL()) {
1020 if (input.GetSector() != iSector)
1021 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
1024 while ( input.NextChannel() ) {
1026 Int_t iRow = input.GetRow();
1027 if (iRow < 0 || iRow >= nRows)
1028 AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
1029 iRow, 0, nRows -1));
1030 Int_t iPad = input.GetPad();
1032 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1034 if (iPad < 0 || iPad >= maxPad)
1035 AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
1036 iPad, 0, maxPad -1));
1039 while ( input.NextBunch() ){
1040 Int_t startTbin = (Int_t)input.GetStartTimeBin();
1041 Int_t bunchlength = (Int_t)input.GetBunchLength();
1042 const UShort_t *sig = input.GetSignals();
1043 for (Int_t iTime = 0; iTime<bunchlength; iTime++){
1044 Int_t iTimeBin=startTbin-iTime;
1045 if ( iTimeBin < 0 || iTimeBin >= kmaxTime) {
1047 //AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
1048 // iTimeBin, 0, kmaxTime -1));
1051 Int_t maxBin = kmaxTime*maxPad;
1052 if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
1053 ((iPad*kmaxTime+iTimeBin) < 0))
1054 AliFatal(Form("Index outside the allowed range"
1055 " Sector=%d Row=%d Pad=%d Timebin=%d"
1056 " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
1057 allBins[iRow][iPad*kmaxTime+iTimeBin] = sig[iTime];
1060 } // End loop over altro data
1063 // Now fill the digits array
1064 if (fDigitsArray->GetTree()==0) {
1065 AliFatal("Tree not set in fDigitsArray");
1068 for (Int_t iRow = 0; iRow < nRows; iRow++) {
1069 AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
1070 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1071 for(Int_t iPad = 0; iPad < maxPad; iPad++) {
1072 for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
1073 Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
1074 if (q <= 0) continue;
1076 dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
1077 ((AliSimDigits*)dig)->SetTrackIDFast( 3141593, iTimeBin,iPad,0);
1080 fDigitsArray->StoreRow(iSector,iRow);
1081 Int_t ndig = dig->GetDigitSize();
1084 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1085 iSector,iRow,ndig));
1087 fDigitsArray->ClearRow(iSector,iRow);
1089 } // end of the sector digitization
1091 // get LHC clock phase from the digits tree
1093 TParameter<float> *ph;
1095 TTree *digtree = fLoader->TreeD();
1097 if(digtree){ // if TreeD exists
1098 ph = (TParameter<float>*)digtree->GetUserInfo()->FindObject("lhcphase0");
1099 phase = ph->GetVal();
1101 else{ //TreeD does not exist
1105 // store lhc clock phase in S-digits tree
1107 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",phase));
1109 fLoader->WriteSDigits("OVERWRITE");
1111 if(GetDigitsArray()) delete GetDigitsArray();
1112 SetDigitsArray(0x0);
1115 for (Int_t iRow = 0; iRow < nRowsMax; iRow++)
1116 delete [] allBins[iRow];
1122 //______________________________________________________________________
1123 AliDigitizer* AliTPC::CreateDigitizer(AliDigitizationInput* digInput) const
1125 return new AliTPCDigitizer(digInput);
1128 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
1130 //create digits from summable digits
1131 GenerNoise(500000); //create teble with noise
1133 //conect tree with sSDigits
1134 TTree *t = fLoader->TreeS();
1137 fLoader->LoadSDigits("READ");
1138 t = fLoader->TreeS();
1140 AliError("Can not get input TreeS");
1145 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1147 AliSimDigits digarr, *dummy=&digarr;
1148 TBranch* sdb = t->GetBranch("Segment");
1150 AliError("Can not find branch with segments in TreeS.");
1154 sdb->SetAddress(&dummy);
1156 Stat_t nentries = t->GetEntries();
1158 // set zero suppression
1160 fTPCParam->SetZeroSup(2);
1162 // get zero suppression
1164 Int_t zerosup = fTPCParam->GetZeroSup();
1166 //make tree with digits
1168 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1169 arr->SetClass("AliSimDigits");
1170 arr->Setup(fTPCParam);
1171 arr->MakeTree(fLoader->TreeD());
1173 AliTPCParam * par = fTPCParam;
1175 //Loop over segments of the TPC
1177 for (Int_t n=0; n<nentries; n++) {
1180 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1181 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
1184 if (!IsSectorActive(sec)) continue;
1186 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1187 Int_t nrows = digrow->GetNRows();
1188 Int_t ncols = digrow->GetNCols();
1190 digrow->ExpandBuffer();
1191 digarr.ExpandBuffer();
1192 digrow->ExpandTrackBuffer();
1193 digarr.ExpandTrackBuffer();
1196 Short_t * pamp0 = digarr.GetDigits();
1197 Int_t * ptracks0 = digarr.GetTracks();
1198 Short_t * pamp1 = digrow->GetDigits();
1199 Int_t * ptracks1 = digrow->GetTracks();
1200 Int_t nelems =nrows*ncols;
1201 Int_t saturation = fTPCParam->GetADCSat() - 1;
1202 //use internal structure of the AliDigits - for speed reason
1203 //if you cahnge implementation
1204 //of the Alidigits - it must be rewriten -
1205 for (Int_t i= 0; i<nelems; i++){
1206 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1208 if (q>saturation) q=saturation;
1211 ptracks1[0]=ptracks0[0];
1212 ptracks1[nelems]=ptracks0[nelems];
1213 ptracks1[2*nelems]=ptracks0[2*nelems];
1221 arr->StoreRow(sec,row);
1222 arr->ClearRow(sec,row);
1227 fLoader->WriteDigits("OVERWRITE");
1231 //__________________________________________________________________
1232 void AliTPC::SetDefaults(){
1234 // setting the defaults
1237 // Set response functions
1240 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1242 //AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1243 //gDirectory->Get("75x40_100x60");
1244 AliTPCParamSR *param = (AliTPCParamSR*)AliTPCcalibDB::Instance()->GetParameters();
1246 AliFatal("No TPC parameters found");
1249 if (!param->IsGeoRead()){
1251 // read transformation matrices for gGeoManager
1253 param->ReadGeoMatrices();
1258 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1259 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1260 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1263 //AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1264 //rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1265 //rf->SetOffset(3*param->GetZSigma());
1270 char strgamma4[1000];
1271 //sprintf(strgamma4,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
1273 snprintf(strgamma4,1000,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
1274 TF1 * fgamma4 = new TF1("fgamma4",strgamma4, -1,1);
1275 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE,1000);
1276 rf->SetParam(fgamma4,param->GetZWidth(), 1,0.2);
1277 rf->SetOffset(3*param->GetZSigma());
1279 TDirectory *savedir=gDirectory;
1282 printf ("TPC MWPC readout\n");
1283 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1285 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1288 prfinner->Read("prf_07504_Gati_056068_d02");
1289 //PH Set different names
1290 s=prfinner->GetGRF()->GetName();
1292 prfinner->GetGRF()->SetName(s.Data());
1294 prfouter1->Read("prf_10006_Gati_047051_d03");
1295 s=prfouter1->GetGRF()->GetName();
1297 prfouter1->GetGRF()->SetName(s.Data());
1299 prfouter2->Read("prf_15006_Gati_047051_d03");
1300 s=prfouter2->GetGRF()->GetName();
1302 prfouter2->GetGRF()->SetName(s.Data());
1307 printf ("TPC GEM readout\n");
1308 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2dGEM.root");
1310 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2dGEM.root !");
1313 prfinner->Read("prf0");
1314 //PH Set different names
1315 s=prfinner->GetGRF()->GetName();
1317 prfinner->GetGRF()->SetName(s.Data());
1319 prfouter1->Read("prf1");
1320 s=prfouter1->GetGRF()->GetName();
1322 prfouter1->GetGRF()->SetName(s.Data());
1324 prfouter2->Read("prf2");
1325 s=prfouter2->GetGRF()->GetName();
1327 prfouter2->GetGRF()->SetName(s.Data());
1332 param->SetInnerPRF(prfinner);
1333 param->SetOuter1PRF(prfouter1);
1334 param->SetOuter2PRF(prfouter2);
1335 param->SetTimeRF(rf);
1345 //__________________________________________________________________
1346 void AliTPC::Hits2Digits()
1349 // creates digits from hits
1351 if (!fTPCParam->IsGeoRead()){
1353 // read transformation matrices for gGeoManager
1355 fTPCParam->ReadGeoMatrices();
1358 fLoader->LoadHits("read");
1359 fLoader->LoadDigits("recreate");
1360 AliRunLoader* runLoader = fLoader->GetRunLoader();
1362 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1363 //PH runLoader->GetEvent(iEvent);
1364 Hits2Digits(iEvent);
1367 fLoader->UnloadHits();
1368 fLoader->UnloadDigits();
1370 //__________________________________________________________________
1371 void AliTPC::Hits2Digits(Int_t eventnumber)
1373 //----------------------------------------------------
1374 // Loop over all sectors for a single event
1375 //----------------------------------------------------
1376 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1377 rl->GetEvent(eventnumber);
1379 if (fLoader->TreeH() == 0x0) {
1380 if(fLoader->LoadHits()) {
1381 AliError("Can not load hits.");
1386 if (fLoader->TreeD() == 0x0 ) {
1387 fLoader->MakeTree("D");
1388 if (fLoader->TreeD() == 0x0 ) {
1389 AliError("Can not get TreeD");
1394 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1395 GenerNoise(500000); //create teble with noise
1397 //setup TPCDigitsArray
1399 if(GetDigitsArray()) delete GetDigitsArray();
1401 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1402 arr->SetClass("AliSimDigits");
1403 arr->Setup(fTPCParam);
1405 arr->MakeTree(fLoader->TreeD());
1406 SetDigitsArray(arr);
1408 fDigitsSwitch=0; // standard digits
1409 // here LHC clock phase
1411 switch (fLHCclockPhaseSw){
1418 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1422 // not implemented yet
1425 // adding phase to the TreeD user info
1426 fLoader->TreeD()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1428 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1429 if (IsSectorActive(isec)) {
1430 AliDebug(1,Form("Hits2Digits: Sector %d is active.",isec));
1431 Hits2DigitsSector(isec);
1434 AliDebug(1,Form("Hits2Digits: Sector %d is NOT active.",isec));
1437 fLoader->WriteDigits("OVERWRITE");
1439 //this line prevents the crash in the similar one
1440 //on the beginning of this method
1441 //destructor attempts to reset the tree, which is deleted by the loader
1442 //need to be redesign
1443 if(GetDigitsArray()) delete GetDigitsArray();
1444 SetDigitsArray(0x0);
1448 //__________________________________________________________________
1449 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1452 //-----------------------------------------------------------
1453 // summable digits - 16 bit "ADC", no noise, no saturation
1454 //-----------------------------------------------------------
1456 //----------------------------------------------------
1457 // Loop over all sectors for a single event
1458 //----------------------------------------------------
1460 AliRunLoader* rl = fLoader->GetRunLoader();
1462 rl->GetEvent(eventnumber);
1463 if (fLoader->TreeH() == 0x0) {
1464 if(fLoader->LoadHits()) {
1465 AliError("Can not load hits.");
1472 if (fLoader->TreeS() == 0x0 ) {
1473 fLoader->MakeTree("S");
1476 if(fDefaults == 0) SetDefaults();
1478 GenerNoise(500000); //create table with noise
1479 //setup TPCDigitsArray
1481 if(GetDigitsArray()) delete GetDigitsArray();
1484 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1485 arr->SetClass("AliSimDigits");
1486 arr->Setup(fTPCParam);
1487 arr->MakeTree(fLoader->TreeS());
1489 SetDigitsArray(arr);
1491 fDigitsSwitch=1; // summable digits
1493 // set zero suppression to "0"
1494 // here LHC clock phase
1496 switch (fLHCclockPhaseSw){
1503 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1507 // not implemented yet
1510 // adding phase to the TreeS user info
1512 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1514 fTPCParam->SetZeroSup(0);
1516 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1517 if (IsSectorActive(isec)) {
1518 Hits2DigitsSector(isec);
1521 fLoader->WriteSDigits("OVERWRITE");
1523 //this line prevents the crash in the similar one
1524 //on the beginning of this method
1525 //destructor attempts to reset the tree, which is deleted by the loader
1526 //need to be redesign
1527 if(GetDigitsArray()) delete GetDigitsArray();
1528 SetDigitsArray(0x0);
1530 //__________________________________________________________________
1532 void AliTPC::Hits2SDigits()
1535 //-----------------------------------------------------------
1536 // summable digits - 16 bit "ADC", no noise, no saturation
1537 //-----------------------------------------------------------
1539 if (!fTPCParam->IsGeoRead()){
1541 // read transformation matrices for gGeoManager
1543 fTPCParam->ReadGeoMatrices();
1546 fLoader->LoadHits("read");
1547 fLoader->LoadSDigits("recreate");
1548 AliRunLoader* runLoader = fLoader->GetRunLoader();
1550 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1551 runLoader->GetEvent(iEvent);
1554 Hits2SDigits2(iEvent);
1557 fLoader->UnloadHits();
1558 fLoader->UnloadSDigits();
1559 if (fDebugStreamer) {
1560 delete fDebugStreamer;
1564 //_____________________________________________________________________________
1566 void AliTPC::Hits2DigitsSector(Int_t isec)
1568 //-------------------------------------------------------------------
1569 // TPC conversion from hits to digits.
1570 //-------------------------------------------------------------------
1572 //-----------------------------------------------------------------
1573 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1574 //-----------------------------------------------------------------
1576 //-------------------------------------------------------
1577 // Get the access to the track hits
1578 //-------------------------------------------------------
1580 // check if the parameters are set - important if one calls this method
1581 // directly, not from the Hits2Digits
1583 if(fDefaults == 0) SetDefaults();
1585 TTree *tH = fLoader->TreeH(); // pointer to the hits tree
1587 AliFatal("Can not find TreeH in folder");
1591 Stat_t ntracks = tH->GetEntries();
1593 Int_t nrows =fTPCParam->GetNRow(isec);
1595 TObjArray **row=new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1596 for(Int_t j=0;j<nrows+2;j++) row[j]=0;
1598 MakeSector(isec,nrows,tH,ntracks,row);
1600 //--------------------------------------------------------
1601 // Digitize this sector, row by row
1602 // row[i] is the pointer to the TObjArray of TVectors,
1603 // each one containing electrons accepted on this
1604 // row, assigned into tracks
1605 //--------------------------------------------------------
1609 if (fDigitsArray->GetTree()==0) {
1610 AliFatal("Tree not set in fDigitsArray");
1613 for (i=0;i<nrows;i++){
1615 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1617 DigitizeRow(i,isec,row);
1619 fDigitsArray->StoreRow(isec,i);
1621 Int_t ndig = dig->GetDigitSize();
1624 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1627 fDigitsArray->ClearRow(isec,i);
1630 } // end of the sector digitization
1632 for(i=0;i<nrows+2;i++){
1637 delete [] row; // delete the array of pointers to TObjArray-s
1640 } // end of Hits2DigitsSector
1643 //_____________________________________________________________________________
1644 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1646 //-----------------------------------------------------------
1647 // Single row digitization, coupling from the neighbouring
1648 // rows taken into account
1649 //-----------------------------------------------------------
1651 //-----------------------------------------------------------------
1652 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1653 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1654 //-----------------------------------------------------------------
1656 Float_t zerosup = fTPCParam->GetZeroSup();
1657 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
1658 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
1659 AliTPCCalROC * gainROC = gainTPC->GetCalROC(isec); // pad gains per given sector
1660 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(isec); // noise per given sector
1663 fCurrentIndex[1]= isec;
1666 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1667 Int_t nofTbins = fTPCParam->GetMaxTBin();
1668 Int_t indexRange[4];
1670 // Integrated signal for this row
1671 // and a single track signal
1674 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1675 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
1677 TMatrixF &total = *m1;
1679 // Array of pointers to the label-signal list
1681 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1682 Float_t **pList = new Float_t* [nofDigits];
1686 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1692 for (Int_t row= row1;row<=row2;row++){
1693 Int_t nTracks= rows[row]->GetEntries();
1694 for (i1=0;i1<nTracks;i1++){
1695 fCurrentIndex[2]= row;
1696 fCurrentIndex[3]=irow+1;
1698 m2->Zero(); // clear single track signal matrix
1699 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1700 GetList(trackLabel,nofPads,m2,indexRange,pList);
1702 else GetSignal(rows[row],i1,0,m1,indexRange);
1708 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1710 Float_t fzerosup = zerosup+0.5;
1711 for(Int_t it=0;it<nofTbins;it++){
1712 for(Int_t ip=0;ip<nofPads;ip++){
1714 Float_t q=total(ip,it);
1715 if(fDigitsSwitch == 0){
1716 Float_t gain = gainROC->GetValue(irow,ip); // get gain for given - pad-row pad
1717 Float_t noisePad = noiseROC->GetValue(irow,ip);
1720 q+=GetNoise()*noisePad;
1721 if(q <=fzerosup) continue; // do not fill zeros
1723 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
1728 if(q <= 0.) continue; // do not fill zeros
1729 if(q>2000.) q=2000.;
1735 // "real" signal or electronic noise (list = -1)?
1738 for(Int_t j1=0;j1<3;j1++){
1739 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1744 <A NAME="AliDigits"></A>
1745 using of AliDigits object
1748 dig->SetDigitFast((Short_t)q,it,ip);
1749 if (fDigitsArray->IsSimulated()) {
1750 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1751 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1752 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1755 } // end of loop over time buckets
1756 } // end of lop over pads
1762 // glitch filters if normal simulated digits
1764 if(!fDigitsSwitch) ((AliSimDigits*)dig)->GlitchFilter();
1766 // This row has been digitized, delete nonused stuff
1769 for(lp=0;lp<nofDigits;lp++){
1770 if(pList[lp]) delete [] pList[lp];
1778 } // end of DigitizeRow
1780 //_____________________________________________________________________________
1782 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1783 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
1786 //---------------------------------------------------------------
1787 // Calculates 2-D signal (pad,time) for a single track,
1788 // returns a pointer to the signal matrix and the track label
1789 // No digitization is performed at this level!!!
1790 //---------------------------------------------------------------
1792 //-----------------------------------------------------------------
1793 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1794 // Modified: Marian Ivanov
1795 //-----------------------------------------------------------------
1799 tv = (TVector*)p1->At(ntr); // pointer to a track
1802 Float_t label = v(0);
1803 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
1805 Int_t nElectrons = (tv->GetNrows()-1)/5;
1806 indexRange[0]=9999; // min pad
1807 indexRange[1]=-1; // max pad
1808 indexRange[2]=9999; //min time
1809 indexRange[3]=-1; // max time
1811 TMatrixF &signal = *m1;
1812 TMatrixF &total = *m2;
1814 // Get LHC clock phase
1816 TParameter<float> *ph;
1817 if(fDigitsSwitch){// s-digits
1818 ph = (TParameter<float>*)fLoader->TreeS()->GetUserInfo()->FindObject("lhcphase0");
1820 else{ // normal digits
1821 ph = (TParameter<float>*)fLoader->TreeD()->GetUserInfo()->FindObject("lhcphase0");
1823 // Loop over all electrons
1825 for(Int_t nel=0; nel<nElectrons; nel++){
1827 Float_t aval = v(idx+4);
1828 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1829 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
1830 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,
1831 fCurrentIndex[3],ph->GetVal());
1833 Int_t *index = fTPCParam->GetResBin(0);
1834 Float_t *weight = & (fTPCParam->GetResWeight(0));
1836 if (n>0) for (Int_t i =0; i<n; i++){
1837 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1840 Int_t time=index[2];
1841 Float_t qweight = *(weight)*eltoadcfac;
1843 if (m1!=0) signal(pad,time)+=qweight;
1844 total(pad,time)+=qweight;
1845 if (indexRange[0]>pad) indexRange[0]=pad;
1846 if (indexRange[1]<pad) indexRange[1]=pad;
1847 if (indexRange[2]>time) indexRange[2]=time;
1848 if (indexRange[3]<time) indexRange[3]=time;
1855 } // end of loop over electrons
1857 return label; // returns track label when finished
1860 //_____________________________________________________________________________
1861 void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
1862 Int_t *indexRange, Float_t **pList)
1864 //----------------------------------------------------------------------
1865 // Updates the list of tracks contributing to digits for a given row
1866 //----------------------------------------------------------------------
1868 //-----------------------------------------------------------------
1869 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1870 //-----------------------------------------------------------------
1872 TMatrixF &signal = *m;
1874 // lop over nonzero digits
1876 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1877 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1880 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1882 if(signal(ip,it)<0.5) continue;
1884 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1886 if(!pList[globalIndex]){
1889 // Create new list (6 elements - 3 signals and 3 labels),
1892 pList[globalIndex] = new Float_t [6];
1896 *pList[globalIndex] = -1.;
1897 *(pList[globalIndex]+1) = -1.;
1898 *(pList[globalIndex]+2) = -1.;
1899 *(pList[globalIndex]+3) = -1.;
1900 *(pList[globalIndex]+4) = -1.;
1901 *(pList[globalIndex]+5) = -1.;
1903 *pList[globalIndex] = label;
1904 *(pList[globalIndex]+3) = signal(ip,it);
1908 // check the signal magnitude
1910 Float_t highest = *(pList[globalIndex]+3);
1911 Float_t middle = *(pList[globalIndex]+4);
1912 Float_t lowest = *(pList[globalIndex]+5);
1915 // compare the new signal with already existing list
1918 if(signal(ip,it)<lowest) continue; // neglect this track
1922 if (signal(ip,it)>highest){
1923 *(pList[globalIndex]+5) = middle;
1924 *(pList[globalIndex]+4) = highest;
1925 *(pList[globalIndex]+3) = signal(ip,it);
1927 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1928 *(pList[globalIndex]+1) = *pList[globalIndex];
1929 *pList[globalIndex] = label;
1931 else if (signal(ip,it)>middle){
1932 *(pList[globalIndex]+5) = middle;
1933 *(pList[globalIndex]+4) = signal(ip,it);
1935 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1936 *(pList[globalIndex]+1) = label;
1939 *(pList[globalIndex]+5) = signal(ip,it);
1940 *(pList[globalIndex]+2) = label;
1944 } // end of loop over pads
1945 } // end of loop over time bins
1948 //___________________________________________________________________
1949 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1950 Stat_t ntracks,TObjArray **row)
1953 //-----------------------------------------------------------------
1954 // Prepares the sector digitization, creates the vectors of
1955 // tracks for each row of this sector. The track vector
1956 // contains the track label and the position of electrons.
1957 //-----------------------------------------------------------------
1960 // The trasport of the electrons through TPC drift volume
1961 // Drift (drift velocity + velocity map(not yet implemented)))
1962 // Application of the random processes (diffusion, gas gain)
1963 // Systematic effects (ExB effect in drift volume + ROCs)
1966 // Loop over primary electrons:
1967 // Creation of the secondary electrons
1968 // Loop over electrons (primary+ secondaries)
1969 // Global coordinate frame:
1970 // 1. Skip electrons if attached
1971 // 2. ExB effect in drift volume
1972 // a.) Simulation calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1973 // b.) Reconstruction - calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1974 // 3. Generation of gas gain (Random - Exponential distribution)
1975 // 4. TransportElectron function (diffusion)
1977 // 5. Conversion to the local coordinate frame pad-row, pad, timebin
1978 // 6. Apply Time0 shift - AliTPCCalPad class
1979 // a.) Plus sign in simulation
1980 // b.) Minus sign in reconstruction
1983 //-----------------------------------------------------------------
1984 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1985 // Origin: Marian Ivanov, marian.ivanov@cern.ch
1986 //-----------------------------------------------------------------
1987 AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
1988 if (gAlice){ // Set correctly the magnetic field in the ExB calculation
1989 if (!calib->GetExB()){
1990 AliMagF * field = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField());
1992 calib->SetExBField(field);
1997 Float_t gasgain = fTPCParam->GetGasGain();
1998 gasgain = gasgain/fGainFactor;
2002 AliTPChit *tpcHit; // pointer to a sigle TPC hit
2005 if (fHitType>1) branch = TH->GetBranch("TPC2");
2006 else branch = TH->GetBranch("TPC");
2009 //----------------------------------------------
2010 // Create TObjArray-s, one for each row,
2011 // each TObjArray will store the TVectors
2012 // of electrons, one TVectors per each track.
2013 //----------------------------------------------
2015 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
2016 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
2018 for(i=0; i<nrows+2; i++){
2019 row[i] = new TObjArray;
2026 //--------------------------------------------------------------------
2027 // Loop over tracks, the "track" contains the full history
2028 //--------------------------------------------------------------------
2030 Int_t previousTrack,currentTrack;
2031 previousTrack = -1; // nothing to store so far!
2033 for(Int_t track=0;track<ntracks;track++){
2034 Bool_t isInSector=kTRUE;
2036 isInSector = TrackInVolume(isec,track);
2037 if (!isInSector) continue;
2039 branch->GetEntry(track); // get next track
2043 tpcHit = (AliTPChit*)FirstHit(-1);
2045 //--------------------------------------------------------------
2047 //--------------------------------------------------------------
2052 Int_t sector=tpcHit->fSector; // sector number
2054 tpcHit = (AliTPChit*) NextHit();
2058 // Remove hits which arrive before the TPC opening gate signal
2059 if(((fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
2060 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
2061 tpcHit = (AliTPChit*) NextHit();
2065 currentTrack = tpcHit->Track(); // track number
2067 if(currentTrack != previousTrack){
2069 // store already filled fTrack
2071 for(i=0;i<nrows+2;i++){
2072 if(previousTrack != -1){
2073 if(nofElectrons[i]>0){
2074 TVector &v = *tracks[i];
2075 v(0) = previousTrack;
2076 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2077 row[i]->Add(tracks[i]);
2080 delete tracks[i]; // delete empty TVector
2086 tracks[i] = new TVector(601); // TVectors for the next fTrack
2088 } // end of loop over rows
2090 previousTrack=currentTrack; // update track label
2093 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
2095 //---------------------------------------------------
2096 // Calculate the electron attachment probability
2097 //---------------------------------------------------
2100 Float_t time = 1.e6*(fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
2101 /fTPCParam->GetDriftV();
2103 Float_t attProb = fTPCParam->GetAttCoef()*
2104 fTPCParam->GetOxyCont()*time; // fraction!
2106 //-----------------------------------------------
2107 // Loop over electrons
2108 //-----------------------------------------------
2111 for(Int_t nel=0;nel<qI;nel++){
2112 // skip if electron lost due to the attachment
2113 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
2118 Double_t dxyz0[3],dxyz1[3];
2119 dxyz0[0]=tpcHit->X();
2120 dxyz0[1]=tpcHit->Y();
2121 dxyz0[2]=tpcHit->Z();
2122 if (calib->GetExB()){
2123 calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
2125 AliError("Not valid ExB calibration");
2126 dxyz1[0]=tpcHit->X();
2127 dxyz1[1]=tpcHit->Y();
2128 dxyz1[2]=tpcHit->Z();
2136 // protection for the nonphysical avalanche size (10**6 maximum)
2138 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2139 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2142 TransportElectron(xyz,index);
2144 Int_t padrow = fTPCParam->GetPadRow(xyz,index);
2146 // Add Time0 correction due unisochronity
2147 // xyz[0] - pad row coordinate
2148 // xyz[1] - pad coordinate
2149 // xyz[2] - is in now time bin coordinate system
2150 Float_t correction =0;
2151 if (calib->GetPadTime0()){
2152 if (!calib->GetPadTime0()->GetCalROC(isec)) continue;
2153 Int_t npads = fTPCParam->GetNPads(isec,padrow);
2154 // Int_t pad = TMath::Nint(xyz[1]+fTPCParam->GetNPads(isec,TMath::Nint(xyz[0]))*0.5);
2155 // pad numbering from -npads/2 .. npads/2-1
2156 Int_t pad = TMath::Nint(xyz[1]+npads/2);
2158 if (pad>=npads) pad=npads-1;
2159 correction = calib->GetPadTime0()->GetCalROC(isec)->GetValue(padrow,pad);
2160 // printf("%d\t%d\t%d\t%f\n",isec,padrow,pad,correction);
2161 if (fDebugStreamer){
2162 (*fDebugStreamer)<<"Time0"<<
2170 "cor="<<correction<<
2174 if (AliTPCcalibDB::Instance()->IsTrgL0()){
2175 // Modification 14.03
2176 // distinguish between the L0 and L1 trigger as it is done in the reconstruction
2177 // by defualt we assume L1 trigger is used - make a correction in case of L0
2178 AliCTPTimeParams* ctp = AliTPCcalibDB::Instance()->GetCTPTimeParams();
2180 //for TPC standalone runs no ctp info
2181 Double_t delay = ctp->GetDelayL1L0()*0.000000025;
2182 xyz[2]+=delay/fTPCParam->GetTSample(); // adding the delay (in the AliTPCTramsform opposite sign)
2186 xyz[2]+=fTPCParam->GetNTBinsL1(); // adding Level 1 time bin offset
2188 // Electron track time (for pileup simulation)
2189 xyz[2]+=tpcHit->Time()/fTPCParam->GetTSample(); // adding time of flight
2193 // row 0 - cross talk from the innermost row
2194 // row fNRow+1 cross talk from the outermost row
2195 rowNumber = index[2]+1;
2196 //transform position to local digit coordinates
2197 //relative to nearest pad row
2198 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
2200 if (isec <fTPCParam->GetNInnerSector()) {
2201 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2202 y1 = fTPCParam->GetYInner(rowNumber);
2205 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2206 y1 = fTPCParam->GetYOuter(rowNumber);
2208 // gain inefficiency at the wires edges - linear
2211 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.)); */
2213 nofElectrons[rowNumber]++;
2214 //----------------------------------
2215 // Expand vector if necessary
2216 //----------------------------------
2217 if(nofElectrons[rowNumber]>120){
2218 Int_t range = tracks[rowNumber]->GetNrows();
2219 if((nofElectrons[rowNumber])>(range-1)/5){
2221 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
2225 TVector &v = *tracks[rowNumber];
2226 Int_t idx = 5*nofElectrons[rowNumber]-4;
2227 Real_t * position = &(((TVector&)v)(idx)); //make code faster
2228 memcpy(position,xyz,5*sizeof(Float_t));
2230 } // end of loop over electrons
2232 tpcHit = (AliTPChit*)NextHit();
2234 } // end of loop over hits
2235 } // end of loop over tracks
2238 // store remaining track (the last one) if not empty
2241 for(i=0;i<nrows+2;i++){
2242 if(nofElectrons[i]>0){
2243 TVector &v = *tracks[i];
2244 v(0) = previousTrack;
2245 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2246 row[i]->Add(tracks[i]);
2255 delete [] nofElectrons;
2257 } // end of MakeSector
2260 //_____________________________________________________________________________
2264 // Initialise TPC detector after definition of geometry
2266 AliDebug(1,"*********************************************");
2269 //_____________________________________________________________________________
2270 void AliTPC::ResetDigits()
2273 // Reset number of digits and the digits array for this detector
2276 if (fDigits) fDigits->Clear();
2281 //_____________________________________________________________________________
2282 void AliTPC::SetSens(Int_t sens)
2285 //-------------------------------------------------------------
2286 // Activates/deactivates the sensitive strips at the center of
2287 // the pad row -- this is for the space-point resolution calculations
2288 //-------------------------------------------------------------
2290 //-----------------------------------------------------------------
2291 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2292 //-----------------------------------------------------------------
2298 void AliTPC::SetSide(Float_t side=0.)
2300 // choice of the TPC side
2305 //_____________________________________________________________________________
2307 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2310 // electron transport taking into account:
2312 // 2.ExB at the wires
2313 // 3. nonisochronity
2315 // xyz and index must be already transformed to system 1
2318 fTPCParam->Transform1to2(xyz,index); // mis-alignment applied in this step
2321 Float_t driftl=xyz[2];
2322 if(driftl<0.01) driftl=0.01;
2323 driftl=TMath::Sqrt(driftl);
2324 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2325 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2326 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2327 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2328 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2332 if (fTPCParam->GetMWPCReadout()==kTRUE){
2333 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2334 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2336 //add nonisochronity (not implemented yet)
2342 //______________________________________________________________________
2343 AliTPChit::AliTPChit()
2355 //_____________________________________________________________________________
2356 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits)
2357 :AliHit(shunt,track),
2364 // Creates a TPC hit object
2375 //________________________________________________________________________
2376 // Additional code because of the AliTPCTrackHitsV2
2378 void AliTPC::MakeBranch(Option_t *option)
2381 // Create a new branch in the current Root Tree
2382 // The branch of fHits is automatically split
2383 // MI change 14.09.2000
2385 if (fHitType<2) return;
2386 char branchname[10];
2387 //sprintf(branchname,"%s2",GetName());
2388 snprintf(branchname,10,"%s2",GetName());
2390 // Get the pointer to the header
2391 const char *cH = strstr(option,"H");
2393 if (fTrackHits && fLoader->TreeH() && cH && fHitType&4) {
2394 AliDebug(1,"Making branch for Type 4 Hits");
2395 fLoader->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2398 // if (fTrackHitsOld && fLoader->TreeH() && cH && fHitType&2) {
2399 // AliDebug(1,"Making branch for Type 2 Hits");
2400 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2401 // fLoader->TreeH(),fBufferSize,99);
2402 // fLoader->TreeH()->GetListOfBranches()->Add(branch);
2406 void AliTPC::SetTreeAddress()
2408 //Sets tree address for hits
2410 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2411 AliDetector::SetTreeAddress();
2413 if (fHitType>1) SetTreeAddress2();
2416 void AliTPC::SetTreeAddress2()
2419 // Set branch address for the TrackHits Tree
2424 char branchname[20];
2425 //sprintf(branchname,"%s2",GetName());
2426 snprintf(branchname,20,"%s2",GetName());
2428 // Branch address for hit tree
2429 TTree *treeH = fLoader->TreeH();
2430 if ((treeH)&&(fHitType&4)) {
2431 branch = treeH->GetBranch(branchname);
2433 branch->SetAddress(&fTrackHits);
2434 AliDebug(1,"fHitType&4 Setting");
2437 AliDebug(1,"fHitType&4 Failed (can not find branch)");
2440 // if ((treeH)&&(fHitType&2)) {
2441 // branch = treeH->GetBranch(branchname);
2443 // branch->SetAddress(&fTrackHitsOld);
2444 // AliDebug(1,"fHitType&2 Setting");
2447 // AliDebug(1,"fHitType&2 Failed (can not find branch)");
2451 void AliTPC::FinishPrimary()
2453 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2454 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2458 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2461 // add hit to the list
2465 int primary = gAlice->GetMCApp()->GetPrimary(track);
2466 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2470 gAlice->GetMCApp()->FlagTrack(track);
2472 if (fTrackHits && fHitType&4)
2473 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2474 hits[1],hits[2],(Int_t)hits[3],hits[4]);
2475 // if (fTrackHitsOld &&fHitType&2 )
2476 // fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2477 // hits[1],hits[2],(Int_t)hits[3]);
2481 void AliTPC::ResetHits()
2483 if (fHitType&1) AliDetector::ResetHits();
2484 if (fHitType>1) ResetHits2();
2487 void AliTPC::ResetHits2()
2491 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2492 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2496 AliHit* AliTPC::FirstHit(Int_t track)
2498 if (fHitType>1) return FirstHit2(track);
2499 return AliDetector::FirstHit(track);
2501 AliHit* AliTPC::NextHit()
2506 if (fHitType>1) return NextHit2();
2508 return AliDetector::NextHit();
2511 AliHit* AliTPC::FirstHit2(Int_t track)
2514 // Initialise the hit iterator
2515 // Return the address of the first hit for track
2516 // If track>=0 the track is read from disk
2517 // while if track<0 the first hit of the current
2518 // track is returned
2521 gAlice->GetMCApp()->ResetHits();
2522 fLoader->TreeH()->GetEvent(track);
2525 if (fTrackHits && fHitType&4) {
2526 fTrackHits->First();
2527 return fTrackHits->GetHit();
2529 // if (fTrackHitsOld && fHitType&2) {
2530 // fTrackHitsOld->First();
2531 // return fTrackHitsOld->GetHit();
2537 AliHit* AliTPC::NextHit2()
2540 //Return the next hit for the current track
2543 // if (fTrackHitsOld && fHitType&2) {
2544 // fTrackHitsOld->Next();
2545 // return fTrackHitsOld->GetHit();
2549 return fTrackHits->GetHit();
2555 void AliTPC::RemapTrackHitIDs(Int_t *map)
2560 if (!fTrackHits) return;
2562 // if (fTrackHitsOld && fHitType&2){
2563 // AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2564 // for (UInt_t i=0;i<arr->GetSize();i++){
2565 // AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2566 // info->fTrackID = map[info->fTrackID];
2569 // if (fTrackHitsOld && fHitType&4){
2570 if (fTrackHits && fHitType&4){
2571 TClonesArray * arr = fTrackHits->GetArray();;
2572 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2573 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2574 info->SetTrackID(map[info->GetTrackID()]);
2579 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2581 //return bool information - is track in given volume
2582 //load only part of the track information
2583 //return true if current track is in volume
2586 // if (fTrackHitsOld && fHitType&2) {
2587 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
2588 // br->GetEvent(track);
2589 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2590 // for (UInt_t j=0;j<ar->GetSize();j++){
2591 // if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2595 if (fTrackHits && fHitType&4) {
2596 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
2597 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
2598 br2->GetEvent(track);
2599 br1->GetEvent(track);
2600 Int_t *volumes = fTrackHits->GetVolumes();
2601 Int_t nvolumes = fTrackHits->GetNVolumes();
2602 if (!volumes && nvolumes>0) {
2603 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2606 for (Int_t j=0;j<nvolumes; j++)
2607 if (volumes[j]==id) return kTRUE;
2611 TBranch * br = fLoader->TreeH()->GetBranch("fSector");
2612 br->GetEvent(track);
2613 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2614 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2622 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2625 fLoader = new AliTPCLoader(GetName(),topfoldername);
2629 ////////////////////////////////////////////////////////////////////////
2630 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2632 // load TPC paarmeters from a given file or create new if the object
2633 // is not found there
2634 // 12/05/2003 This method should be moved to the AliTPCLoader
2635 // and one has to decide where to store the TPC parameters
2638 //sprintf(paramName,"75x40_100x60_150x60");
2639 snprintf(paramName,50,"75x40_100x60_150x60");
2640 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2642 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2644 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2645 //paramTPC = new AliTPCParamSR;
2646 paramTPC = AliTPCcalibDB::Instance()->GetParameters();
2647 if (!paramTPC->IsGeoRead()){
2649 // read transformation matrices for gGeoManager
2651 paramTPC->ReadGeoMatrices();
2657 // the older version of parameters can be accessed with this code.
2658 // In some cases, we have old parameters saved in the file but
2659 // digits were created with new parameters, it can be distinguish
2660 // by the name of TPC TreeD. The code here is just for the case
2661 // we would need to compare with old data, uncomment it if needed.
2663 // char paramName[50];
2664 // sprintf(paramName,"75x40_100x60");
2665 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2667 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2669 // sprintf(paramName,"75x40_100x60_150x60");
2670 // paramTPC=(AliTPCParam*)in->Get(paramName);
2672 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2674 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2676 // paramTPC = new AliTPCParamSR;