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>
56 #include "AliDigits.h"
59 #include "AliRunLoader.h"
60 #include "AliSimDigits.h"
63 #include "AliTPCDigitsArray.h"
64 #include "AliTPCLoader.h"
65 #include "AliTPCPRF2D.h"
66 #include "AliTPCParamSR.h"
67 #include "AliTPCRF1D.h"
68 //#include "AliTPCTrackHits.h"
69 #include "AliTPCTrackHitsV2.h"
70 #include "AliTrackReference.h"
73 #include "AliTPCDigitizer.h"
74 #include "AliTPCBuffer.h"
75 #include "AliTPCDDLRawData.h"
77 #include "AliTPCcalibDB.h"
78 #include "AliTPCCalPad.h"
79 #include "AliTPCCalROC.h"
80 #include "AliTPCExB.h"
81 #include "AliRawReader.h"
82 #include "AliTPCRawStream.h"
83 #include "TTreeStream.h"
86 //_____________________________________________________________________________
87 AliTPC::AliTPC():AliDetector(),
97 fPrimaryIonisation(0),
107 // Default constructor
111 // fTrackHitsOld = 0;
112 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
113 fHitType = 4; // ROOT containers
115 fHitType = 2; //default CONTAINERS - based on ROOT structure
119 //_____________________________________________________________________________
120 AliTPC::AliTPC(const char *name, const char *title)
121 : AliDetector(name,title),
131 fPrimaryIonisation(0),
141 // Standard constructor
145 // Initialise arrays of hits and digits
146 fHits = new TClonesArray("AliTPChit", 176);
147 gAlice->GetMCApp()->AddHitList(fHits);
149 fTrackHits = new AliTPCTrackHitsV2;
150 fTrackHits->SetHitPrecision(0.002);
151 fTrackHits->SetStepPrecision(0.003);
152 fTrackHits->SetMaxDistance(100);
154 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
155 //fTrackHitsOld->SetHitPrecision(0.002);
156 //fTrackHitsOld->SetStepPrecision(0.003);
157 //fTrackHitsOld->SetMaxDistance(100);
160 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
161 fHitType = 4; // ROOT containers
171 // Initialise color attributes
172 //PH SetMarkerColor(kYellow);
175 // Set TPC parameters
179 if (!strcmp(title,"Default")) {
180 //fTPCParam = new AliTPCParamSR;
181 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
183 AliWarning("In Config.C you must set non-default parameters.");
189 //_____________________________________________________________________________
200 delete fTrackHits; //MI 15.09.2000
201 // delete fTrackHitsOld; //MI 10.12.2001
204 delete [] fNoiseTable;
205 delete [] fActiveSectors;
206 if (fDebugStreamer) delete fDebugStreamer;
209 //_____________________________________________________________________________
210 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
213 // Add a hit to the list
216 TClonesArray &lhits = *fHits;
217 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
220 AddHit2(track,vol,hits);
223 //_____________________________________________________________________________
224 void AliTPC::CreateMaterials()
226 //-----------------------------------------------
227 // Create Materials for for TPC simulations
228 //-----------------------------------------------
230 //-----------------------------------------------------------------
231 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
232 //-----------------------------------------------------------------
234 Int_t iSXFLD=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
235 Float_t sXMGMX=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
237 Float_t amat[5]; // atomic numbers
238 Float_t zmat[5]; // z
239 Float_t wmat[5]; // proportions
245 //***************** Gases *************************
248 //--------------------------------------------------------------
249 // gases - air and CO2
250 //--------------------------------------------------------------
266 AliMixture(10,"CO2",amat,zmat,density,2,wmat);
281 AliMixture(11,"Air",amat,zmat,density,2,wmat);
283 //----------------------------------------------------------------
285 //----------------------------------------------------------------
288 // Drift gases 1 - nonsensitive, 2 - sensitive
289 // Ne-CO2-N (85-10-5)
308 AliMixture(12,"Ne-CO2-N-1",amat,zmat,density,4,wmat);
309 AliMixture(13,"Ne-CO2-N-2",amat,zmat,density,4,wmat);
310 AliMixture(30,"Ne-CO2-N-3",amat,zmat,density,4,wmat);
311 //----------------------------------------------------------------------
313 //----------------------------------------------------------------------
335 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
356 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
374 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
392 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
410 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
411 // material for "prepregs"
412 // Epoxy - C14 H20 O3
415 // prepreg1 60% C-fiber, 40% epoxy (vol)
430 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
432 //prepreg2 60% glass-fiber, 40% epoxy
451 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
453 //prepreg3 50% glass-fiber, 50% epoxy
472 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
474 // G10 60% SiO2 40% epoxy
493 AliMixture(22, "G10",amat,zmat,density,4,wmat);
502 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
504 // Si (for electronics
511 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
520 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
522 // Epoxy - C14 H20 O3
538 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
556 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
564 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
566 // Fe (steel for the inner heat screen)
574 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
576 // Peek - (C6H4-O-OC6H4-O-C6H4-CO)n
591 AliMixture(30,"Peek",amat,zmat,density,-3,wmat);
606 AliMixture(31,"Alumina",amat,zmat,density,-2,wmat);
625 AliMixture(32,"Water",amat,zmat,density,-2,wmat);
627 //----------------------------------------------------------
628 // tracking media for gases
629 //----------------------------------------------------------
631 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
632 AliMedium(1, "Ne-CO2-N-1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
633 AliMedium(2, "Ne-CO2-N-2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
634 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
635 AliMedium(20, "Ne-CO2-N-3", 30, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
636 //-----------------------------------------------------------
637 // tracking media for solids
638 //-----------------------------------------------------------
640 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
641 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
642 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
643 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
644 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
645 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
647 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
648 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
649 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
650 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
652 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
653 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
654 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
655 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
656 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
657 AliMedium(19,"Peek",30,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
658 AliMedium(21,"Alumina",31,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
659 AliMedium(22,"Water",32,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
662 void AliTPC::GenerNoise(Int_t tablesize)
665 //Generate table with noise
672 if (fNoiseTable) delete[] fNoiseTable;
673 fNoiseTable = new Float_t[tablesize];
674 fNoiseDepth = tablesize;
675 fCurrentNoise =0; //!index of the noise in the noise table
677 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
678 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
681 Float_t AliTPC::GetNoise()
683 // get noise from table
684 // if ((fCurrentNoise%10)==0)
685 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
686 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
687 return fNoiseTable[fCurrentNoise++];
688 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
692 Bool_t AliTPC::IsSectorActive(Int_t sec) const
695 // check if the sector is active
696 if (!fActiveSectors) return kTRUE;
697 else return fActiveSectors[sec];
700 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
702 // activate interesting sectors
703 SetTreeAddress();//just for security
704 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
705 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
706 for (Int_t i=0;i<n;i++)
707 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
711 void AliTPC::SetActiveSectors(Int_t flag)
714 // activate sectors which were hitted by tracks
716 SetTreeAddress();//just for security
717 if (fHitType==0) return; // if Clones hit - not short volume ID information
718 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
720 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
723 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
725 if (fLoader->TreeH() == 0x0)
727 AliFatal("Can not find TreeH in folder");
730 if (fHitType>1) branch = fLoader->TreeH()->GetBranch("TPC2");
731 else branch = fLoader->TreeH()->GetBranch("TPC");
732 Stat_t ntracks = fLoader->TreeH()->GetEntries();
733 // loop over all hits
734 AliDebug(1,Form("Got %d tracks",ntracks));
736 for(Int_t track=0;track<ntracks;track++) {
739 if (fTrackHits && fHitType&4) {
740 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
741 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
742 br1->GetEvent(track);
743 br2->GetEvent(track);
744 Int_t *volumes = fTrackHits->GetVolumes();
745 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++) {
746 if (volumes[j]>-1 && volumes[j]<fTPCParam->GetNSector()) {
747 fActiveSectors[volumes[j]]=kTRUE;
750 AliError(Form("Volume %d -> sector number %d is outside (0..%d)",
753 fTPCParam->GetNSector()));
759 // if (fTrackHitsOld && fHitType&2) {
760 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
761 // br->GetEvent(track);
762 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
763 // for (UInt_t j=0;j<ar->GetSize();j++){
764 // fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
773 //_____________________________________________________________________________
774 void AliTPC::Digits2Raw()
776 // convert digits of the current event to raw data
778 static const Int_t kThreshold = 0;
780 fLoader->LoadDigits();
781 TTree* digits = fLoader->TreeD();
783 AliError("No digits tree");
788 AliSimDigits* digrow = &digarr;
789 digits->GetBranch("Segment")->SetAddress(&digrow);
791 const char* fileName = "AliTPCDDL.dat";
792 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
796 // 2: txt files with digits
797 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
798 //it is highly suggested to use this mode only for debugging digits files
799 //reasonably small, because otherwise the size of the txt files can reach
800 //quickly several MB wasting time and disk space.
801 buffer->SetVerbose(0);
803 Int_t nEntries = Int_t(digits->GetEntries());
804 Int_t previousSector = -1;
806 for (Int_t i = 0; i < nEntries; i++) {
809 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
810 if(previousSector != sector) {
812 previousSector = sector;
815 if (sector < 36) { //inner sector [0;35]
817 //the whole row is written into the output file
818 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
819 sector, subSector, row);
821 //only the pads in the range [37;48] are written into the output file
822 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
823 sector, subSector, row);
825 //only the pads outside the range [37;48] are written into the output file
826 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
827 sector, subSector, row);
830 } else { //outer sector [36;71]
831 if (row == 54) subSector = 2;
832 if ((row != 27) && (row != 76)) {
833 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
834 sector, subSector, row);
835 } else if (row == 27) {
836 //only the pads outside the range [43;46] are written into the output file
837 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
838 sector, subSector, row);
840 //only the pads in the range [43;46] are written into the output file
841 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
842 sector, subSector, row);
843 } else if (row == 76) {
844 //only the pads outside the range [33;88] are written into the output file
845 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
846 sector, subSector, row);
848 //only the pads in the range [33;88] are written into the output file
849 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
850 sector, subSector, row);
856 fLoader->UnloadDigits();
858 AliTPCDDLRawData rawWriter;
859 rawWriter.SetVerbose(0);
861 rawWriter.RawData(fileName);
862 gSystem->Unlink(fileName);
867 //_____________________________________________________________________________
868 Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
869 // Converts the TPC raw data into summable digits
870 // The method is used for merging simulated and
872 if (fLoader->TreeS() == 0x0 ) {
873 fLoader->MakeTree("S");
876 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
878 //setup TPCDigitsArray
879 if(GetDigitsArray()) delete GetDigitsArray();
881 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
882 arr->SetClass("AliSimDigits");
883 arr->Setup(fTPCParam);
884 arr->MakeTree(fLoader->TreeS());
888 // set zero suppression to "0"
889 fTPCParam->SetZeroSup(0);
892 const Int_t kmaxTime = fTPCParam->GetMaxTBin();
893 const Int_t kNIS = fTPCParam->GetNInnerSector();
894 const Int_t kNOS = fTPCParam->GetNOuterSector();
895 const Int_t kNS = kNIS + kNOS;
897 Short_t** allBins = NULL; //array which contains the data for one sector
899 for(Int_t iSector = 0; iSector < kNS; iSector++) {
901 Int_t nRows = fTPCParam->GetNRow(iSector);
902 Int_t nDDLs = 0, indexDDL = 0;
903 if (iSector < kNIS) {
905 indexDDL = iSector * 2;
909 indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
912 // Loas the raw data for corresponding DDLs
914 AliTPCRawStream input(rawReader);
915 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
917 // Alocate and init the array with the sector data
918 allBins = new Short_t*[nRows];
919 for (Int_t iRow = 0; iRow < nRows; iRow++) {
920 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
921 Int_t maxBin = kmaxTime*maxPad;
922 allBins[iRow] = new Short_t[maxBin];
923 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
926 // Begin loop over altro data
927 while (input.Next()) {
929 if (input.GetSector() != iSector)
930 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
932 Int_t iRow = input.GetRow();
933 if (iRow < 0 || iRow >= nRows)
934 AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
936 Int_t iPad = input.GetPad();
938 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
940 if (iPad < 0 || iPad >= maxPad)
941 AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
942 iPad, 0, maxPad -1));
944 Int_t iTimeBin = input.GetTime();
945 if ( iTimeBin < 0 || iTimeBin >= kmaxTime)
946 AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
947 iTimeBin, 0, kmaxTime -1));
949 Int_t maxBin = kmaxTime*maxPad;
951 if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
952 ((iPad*kmaxTime+iTimeBin) < 0))
953 AliFatal(Form("Index outside the allowed range"
954 " Sector=%d Row=%d Pad=%d Timebin=%d"
955 " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
957 allBins[iRow][iPad*kmaxTime+iTimeBin] = input.GetSignal();
959 } // End loop over altro data
961 // Now fill the digits array
962 if (fDigitsArray->GetTree()==0) {
963 AliFatal("Tree not set in fDigitsArray");
966 for (Int_t iRow = 0; iRow < nRows; iRow++) {
967 AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
969 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
970 for(Int_t iPad = 0; iPad < maxPad; iPad++) {
971 for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
972 Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
973 if (q <= 0) continue;
975 dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
978 fDigitsArray->StoreRow(iSector,iRow);
979 Int_t ndig = dig->GetDigitSize();
982 Form("*** Sector, row, compressed digits %d %d %d ***\n",
985 fDigitsArray->ClearRow(iSector,iRow);
987 } // end of the sector digitization
989 for (Int_t iRow = 0; iRow < nRows; iRow++)
990 delete [] allBins[iRow];
996 fLoader->WriteSDigits("OVERWRITE");
998 if(GetDigitsArray()) delete GetDigitsArray();
1004 //______________________________________________________________________
1005 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
1007 return new AliTPCDigitizer(manager);
1010 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
1012 //create digits from summable digits
1013 GenerNoise(500000); //create teble with noise
1015 //conect tree with sSDigits
1016 TTree *t = fLoader->TreeS();
1019 fLoader->LoadSDigits("READ");
1020 t = fLoader->TreeS();
1022 AliError("Can not get input TreeS");
1027 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1029 AliSimDigits digarr, *dummy=&digarr;
1030 TBranch* sdb = t->GetBranch("Segment");
1032 AliError("Can not find branch with segments in TreeS.");
1036 sdb->SetAddress(&dummy);
1038 Stat_t nentries = t->GetEntries();
1040 // set zero suppression
1042 fTPCParam->SetZeroSup(2);
1044 // get zero suppression
1046 Int_t zerosup = fTPCParam->GetZeroSup();
1048 //make tree with digits
1050 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1051 arr->SetClass("AliSimDigits");
1052 arr->Setup(fTPCParam);
1053 arr->MakeTree(fLoader->TreeD());
1055 AliTPCParam * par = fTPCParam;
1057 //Loop over segments of the TPC
1059 for (Int_t n=0; n<nentries; n++) {
1062 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
1063 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
1066 if (!IsSectorActive(sec)) continue;
1068 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1069 Int_t nrows = digrow->GetNRows();
1070 Int_t ncols = digrow->GetNCols();
1072 digrow->ExpandBuffer();
1073 digarr.ExpandBuffer();
1074 digrow->ExpandTrackBuffer();
1075 digarr.ExpandTrackBuffer();
1078 Short_t * pamp0 = digarr.GetDigits();
1079 Int_t * ptracks0 = digarr.GetTracks();
1080 Short_t * pamp1 = digrow->GetDigits();
1081 Int_t * ptracks1 = digrow->GetTracks();
1082 Int_t nelems =nrows*ncols;
1083 Int_t saturation = fTPCParam->GetADCSat() - 1;
1084 //use internal structure of the AliDigits - for speed reason
1085 //if you cahnge implementation
1086 //of the Alidigits - it must be rewriten -
1087 for (Int_t i= 0; i<nelems; i++){
1088 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1090 if (q>saturation) q=saturation;
1093 ptracks1[0]=ptracks0[0];
1094 ptracks1[nelems]=ptracks0[nelems];
1095 ptracks1[2*nelems]=ptracks0[2*nelems];
1103 arr->StoreRow(sec,row);
1104 arr->ClearRow(sec,row);
1109 fLoader->WriteDigits("OVERWRITE");
1113 //__________________________________________________________________
1114 void AliTPC::SetDefaults(){
1116 // setting the defaults
1119 // Set response functions
1122 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1124 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1126 // AliInfo("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...");
1128 // param = new AliTPCParamSR();
1131 // param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1133 param = (AliTPCParamSR*)AliTPCcalibDB::Instance()->GetParameters();
1134 if (!param->IsGeoRead()){
1136 // read transformation matrices for gGeoManager
1138 param->ReadGeoMatrices();
1141 AliFatal("No TPC parameters found");
1145 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1146 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1147 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1150 //AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1151 //rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1152 //rf->SetOffset(3*param->GetZSigma());
1157 char strgamma4[1000];
1158 sprintf(strgamma4,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
1160 TF1 * fgamma4 = new TF1("fgamma4",strgamma4, -1,1);
1161 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE,1000);
1162 rf->SetParam(fgamma4,param->GetZWidth(), 1,0.2);
1163 rf->SetOffset(3*param->GetZSigma());
1166 TDirectory *savedir=gDirectory;
1167 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1169 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1172 prfinner->Read("prf_07504_Gati_056068_d02");
1173 //PH Set different names
1174 s=prfinner->GetGRF()->GetName();
1176 prfinner->GetGRF()->SetName(s.Data());
1178 prfouter1->Read("prf_10006_Gati_047051_d03");
1179 s=prfouter1->GetGRF()->GetName();
1181 prfouter1->GetGRF()->SetName(s.Data());
1183 prfouter2->Read("prf_15006_Gati_047051_d03");
1184 s=prfouter2->GetGRF()->GetName();
1186 prfouter2->GetGRF()->SetName(s.Data());
1191 param->SetInnerPRF(prfinner);
1192 param->SetOuter1PRF(prfouter1);
1193 param->SetOuter2PRF(prfouter2);
1194 param->SetTimeRF(rf);
1204 //__________________________________________________________________
1205 void AliTPC::Hits2Digits()
1208 // creates digits from hits
1210 if (!fTPCParam->IsGeoRead()){
1212 // read transformation matrices for gGeoManager
1214 fTPCParam->ReadGeoMatrices();
1217 fLoader->LoadHits("read");
1218 fLoader->LoadDigits("recreate");
1219 AliRunLoader* runLoader = fLoader->GetRunLoader();
1221 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1222 //PH runLoader->GetEvent(iEvent);
1223 Hits2Digits(iEvent);
1226 fLoader->UnloadHits();
1227 fLoader->UnloadDigits();
1229 //__________________________________________________________________
1230 void AliTPC::Hits2Digits(Int_t eventnumber)
1232 //----------------------------------------------------
1233 // Loop over all sectors for a single event
1234 //----------------------------------------------------
1235 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1236 rl->GetEvent(eventnumber);
1238 if (fLoader->TreeH() == 0x0) {
1239 if(fLoader->LoadHits()) {
1240 AliError("Can not load hits.");
1245 if (fLoader->TreeD() == 0x0 ) {
1246 fLoader->MakeTree("D");
1247 if (fLoader->TreeD() == 0x0 ) {
1248 AliError("Can not get TreeD");
1253 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1254 GenerNoise(500000); //create teble with noise
1256 //setup TPCDigitsArray
1258 if(GetDigitsArray()) delete GetDigitsArray();
1260 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1261 arr->SetClass("AliSimDigits");
1262 arr->Setup(fTPCParam);
1264 arr->MakeTree(fLoader->TreeD());
1265 SetDigitsArray(arr);
1267 fDigitsSwitch=0; // standard digits
1269 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1270 if (IsSectorActive(isec)) {
1271 AliDebug(1,Form("Hits2Digits","Sector %d is active.",isec));
1272 Hits2DigitsSector(isec);
1275 AliDebug(1,Form("Hits2Digits","Sector %d is NOT active.",isec));
1278 fLoader->WriteDigits("OVERWRITE");
1280 //this line prevents the crash in the similar one
1281 //on the beginning of this method
1282 //destructor attempts to reset the tree, which is deleted by the loader
1283 //need to be redesign
1284 if(GetDigitsArray()) delete GetDigitsArray();
1285 SetDigitsArray(0x0);
1289 //__________________________________________________________________
1290 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1293 //-----------------------------------------------------------
1294 // summable digits - 16 bit "ADC", no noise, no saturation
1295 //-----------------------------------------------------------
1297 //----------------------------------------------------
1298 // Loop over all sectors for a single event
1299 //----------------------------------------------------
1301 AliRunLoader* rl = fLoader->GetRunLoader();
1303 rl->GetEvent(eventnumber);
1304 if (fLoader->TreeH() == 0x0) {
1305 if(fLoader->LoadHits()) {
1306 AliError("Can not load hits.");
1313 if (fLoader->TreeS() == 0x0 ) {
1314 fLoader->MakeTree("S");
1317 if(fDefaults == 0) SetDefaults();
1319 GenerNoise(500000); //create table with noise
1320 //setup TPCDigitsArray
1322 if(GetDigitsArray()) delete GetDigitsArray();
1325 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1326 arr->SetClass("AliSimDigits");
1327 arr->Setup(fTPCParam);
1328 arr->MakeTree(fLoader->TreeS());
1330 SetDigitsArray(arr);
1332 fDigitsSwitch=1; // summable digits
1334 // set zero suppression to "0"
1336 fTPCParam->SetZeroSup(0);
1338 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1339 if (IsSectorActive(isec)) {
1340 Hits2DigitsSector(isec);
1343 fLoader->WriteSDigits("OVERWRITE");
1345 //this line prevents the crash in the similar one
1346 //on the beginning of this method
1347 //destructor attempts to reset the tree, which is deleted by the loader
1348 //need to be redesign
1349 if(GetDigitsArray()) delete GetDigitsArray();
1350 SetDigitsArray(0x0);
1352 //__________________________________________________________________
1354 void AliTPC::Hits2SDigits()
1357 //-----------------------------------------------------------
1358 // summable digits - 16 bit "ADC", no noise, no saturation
1359 //-----------------------------------------------------------
1360 if (0) fDebugStreamer = new TTreeSRedirector("TPCSimdebug.root");
1362 if (!fTPCParam->IsGeoRead()){
1364 // read transformation matrices for gGeoManager
1366 fTPCParam->ReadGeoMatrices();
1369 fLoader->LoadHits("read");
1370 fLoader->LoadSDigits("recreate");
1371 AliRunLoader* runLoader = fLoader->GetRunLoader();
1373 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1374 runLoader->GetEvent(iEvent);
1377 Hits2SDigits2(iEvent);
1380 fLoader->UnloadHits();
1381 fLoader->UnloadSDigits();
1382 if (fDebugStreamer) {
1383 delete fDebugStreamer;
1387 //_____________________________________________________________________________
1389 void AliTPC::Hits2DigitsSector(Int_t isec)
1391 //-------------------------------------------------------------------
1392 // TPC conversion from hits to digits.
1393 //-------------------------------------------------------------------
1395 //-----------------------------------------------------------------
1396 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1397 //-----------------------------------------------------------------
1399 //-------------------------------------------------------
1400 // Get the access to the track hits
1401 //-------------------------------------------------------
1403 // check if the parameters are set - important if one calls this method
1404 // directly, not from the Hits2Digits
1406 if(fDefaults == 0) SetDefaults();
1408 TTree *tH = fLoader->TreeH(); // pointer to the hits tree
1410 AliFatal("Can not find TreeH in folder");
1414 Stat_t ntracks = tH->GetEntries();
1418 //-------------------------------------------
1419 // Only if there are any tracks...
1420 //-------------------------------------------
1424 Int_t nrows =fTPCParam->GetNRow(isec);
1426 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1428 MakeSector(isec,nrows,tH,ntracks,row);
1430 //--------------------------------------------------------
1431 // Digitize this sector, row by row
1432 // row[i] is the pointer to the TObjArray of TVectors,
1433 // each one containing electrons accepted on this
1434 // row, assigned into tracks
1435 //--------------------------------------------------------
1439 if (fDigitsArray->GetTree()==0) {
1440 AliFatal("Tree not set in fDigitsArray");
1443 for (i=0;i<nrows;i++){
1445 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1447 DigitizeRow(i,isec,row);
1449 fDigitsArray->StoreRow(isec,i);
1451 Int_t ndig = dig->GetDigitSize();
1454 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1457 fDigitsArray->ClearRow(isec,i);
1460 } // end of the sector digitization
1462 for(i=0;i<nrows+2;i++){
1467 delete [] row; // delete the array of pointers to TObjArray-s
1471 } // end of Hits2DigitsSector
1474 //_____________________________________________________________________________
1475 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1477 //-----------------------------------------------------------
1478 // Single row digitization, coupling from the neighbouring
1479 // rows taken into account
1480 //-----------------------------------------------------------
1482 //-----------------------------------------------------------------
1483 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1484 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1485 //-----------------------------------------------------------------
1487 Float_t zerosup = fTPCParam->GetZeroSup();
1489 fCurrentIndex[1]= isec;
1492 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1493 Int_t nofTbins = fTPCParam->GetMaxTBin();
1494 Int_t indexRange[4];
1496 // Integrated signal for this row
1497 // and a single track signal
1500 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1501 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
1503 TMatrixF &total = *m1;
1505 // Array of pointers to the label-signal list
1507 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1508 Float_t **pList = new Float_t* [nofDigits];
1512 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1518 for (Int_t row= row1;row<=row2;row++){
1519 Int_t nTracks= rows[row]->GetEntries();
1520 for (i1=0;i1<nTracks;i1++){
1521 fCurrentIndex[2]= row;
1522 fCurrentIndex[3]=irow+1;
1524 m2->Zero(); // clear single track signal matrix
1525 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1526 GetList(trackLabel,nofPads,m2,indexRange,pList);
1528 else GetSignal(rows[row],i1,0,m1,indexRange);
1534 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1536 Float_t fzerosup = zerosup+0.5;
1537 for(Int_t it=0;it<nofTbins;it++){
1538 for(Int_t ip=0;ip<nofPads;ip++){
1540 Float_t q=total(ip,it);
1541 if(fDigitsSwitch == 0){
1543 if(q <=fzerosup) continue; // do not fill zeros
1545 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
1550 if(q <= 0.) continue; // do not fill zeros
1551 if(q>2000.) q=2000.;
1557 // "real" signal or electronic noise (list = -1)?
1560 for(Int_t j1=0;j1<3;j1++){
1561 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1566 <A NAME="AliDigits"></A>
1567 using of AliDigits object
1570 dig->SetDigitFast((Short_t)q,it,ip);
1571 if (fDigitsArray->IsSimulated()) {
1572 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1573 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1574 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1577 } // end of loop over time buckets
1578 } // end of lop over pads
1581 // This row has been digitized, delete nonused stuff
1584 for(lp=0;lp<nofDigits;lp++){
1585 if(pList[lp]) delete [] pList[lp];
1593 } // end of DigitizeRow
1595 //_____________________________________________________________________________
1597 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1598 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
1601 //---------------------------------------------------------------
1602 // Calculates 2-D signal (pad,time) for a single track,
1603 // returns a pointer to the signal matrix and the track label
1604 // No digitization is performed at this level!!!
1605 //---------------------------------------------------------------
1607 //-----------------------------------------------------------------
1608 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1609 // Modified: Marian Ivanov
1610 //-----------------------------------------------------------------
1614 tv = (TVector*)p1->At(ntr); // pointer to a track
1617 Float_t label = v(0);
1618 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
1620 Int_t nElectrons = (tv->GetNrows()-1)/5;
1621 indexRange[0]=9999; // min pad
1622 indexRange[1]=-1; // max pad
1623 indexRange[2]=9999; //min time
1624 indexRange[3]=-1; // max time
1626 TMatrixF &signal = *m1;
1627 TMatrixF &total = *m2;
1629 // Loop over all electrons
1631 for(Int_t nel=0; nel<nElectrons; nel++){
1633 Float_t aval = v(idx+4);
1634 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1635 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
1636 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1638 Int_t *index = fTPCParam->GetResBin(0);
1639 Float_t *weight = & (fTPCParam->GetResWeight(0));
1641 if (n>0) for (Int_t i =0; i<n; i++){
1642 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1645 Int_t time=index[2];
1646 Float_t qweight = *(weight)*eltoadcfac;
1648 if (m1!=0) signal(pad,time)+=qweight;
1649 total(pad,time)+=qweight;
1650 if (indexRange[0]>pad) indexRange[0]=pad;
1651 if (indexRange[1]<pad) indexRange[1]=pad;
1652 if (indexRange[2]>time) indexRange[2]=time;
1653 if (indexRange[3]<time) indexRange[3]=time;
1660 } // end of loop over electrons
1662 return label; // returns track label when finished
1665 //_____________________________________________________________________________
1666 void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
1667 Int_t *indexRange, Float_t **pList)
1669 //----------------------------------------------------------------------
1670 // Updates the list of tracks contributing to digits for a given row
1671 //----------------------------------------------------------------------
1673 //-----------------------------------------------------------------
1674 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1675 //-----------------------------------------------------------------
1677 TMatrixF &signal = *m;
1679 // lop over nonzero digits
1681 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1682 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1685 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1687 if(signal(ip,it)<0.5) continue;
1689 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1691 if(!pList[globalIndex]){
1694 // Create new list (6 elements - 3 signals and 3 labels),
1697 pList[globalIndex] = new Float_t [6];
1701 *pList[globalIndex] = -1.;
1702 *(pList[globalIndex]+1) = -1.;
1703 *(pList[globalIndex]+2) = -1.;
1704 *(pList[globalIndex]+3) = -1.;
1705 *(pList[globalIndex]+4) = -1.;
1706 *(pList[globalIndex]+5) = -1.;
1708 *pList[globalIndex] = label;
1709 *(pList[globalIndex]+3) = signal(ip,it);
1713 // check the signal magnitude
1715 Float_t highest = *(pList[globalIndex]+3);
1716 Float_t middle = *(pList[globalIndex]+4);
1717 Float_t lowest = *(pList[globalIndex]+5);
1720 // compare the new signal with already existing list
1723 if(signal(ip,it)<lowest) continue; // neglect this track
1727 if (signal(ip,it)>highest){
1728 *(pList[globalIndex]+5) = middle;
1729 *(pList[globalIndex]+4) = highest;
1730 *(pList[globalIndex]+3) = signal(ip,it);
1732 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1733 *(pList[globalIndex]+1) = *pList[globalIndex];
1734 *pList[globalIndex] = label;
1736 else if (signal(ip,it)>middle){
1737 *(pList[globalIndex]+5) = middle;
1738 *(pList[globalIndex]+4) = signal(ip,it);
1740 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1741 *(pList[globalIndex]+1) = label;
1744 *(pList[globalIndex]+5) = signal(ip,it);
1745 *(pList[globalIndex]+2) = label;
1749 } // end of loop over pads
1750 } // end of loop over time bins
1753 //___________________________________________________________________
1754 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1755 Stat_t ntracks,TObjArray **row)
1758 //-----------------------------------------------------------------
1759 // Prepares the sector digitization, creates the vectors of
1760 // tracks for each row of this sector. The track vector
1761 // contains the track label and the position of electrons.
1762 //-----------------------------------------------------------------
1765 // The trasport of the electrons through TPC drift volume
1766 // Drift (drift velocity + velocity map(not yet implemented)))
1767 // Application of the random processes (diffusion, gas gain)
1768 // Systematic effects (ExB effect in drift volume + ROCs)
1771 // Loop over primary electrons:
1772 // Creation of the secondary electrons
1773 // Loop over electrons (primary+ secondaries)
1774 // Global coordinate frame:
1775 // 1. Skip electrons if attached
1776 // 2. ExB effect in drift volume
1777 // a.) Simulation calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1778 // b.) Reconstruction - calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1779 // 3. Generation of gas gain (Random - Exponential distribution)
1780 // 4. TransportElectron function (diffusion)
1782 // 5. Conversion to the local coordinate frame pad-row, pad, timebin
1783 // 6. Apply Time0 shift - AliTPCCalPad class
1784 // a.) Plus sign in simulation
1785 // b.) Minus sign in reconstruction
1788 //-----------------------------------------------------------------
1789 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1790 // Origin: Marian Ivanov, marian.ivanov@cern.ch
1791 //-----------------------------------------------------------------
1792 AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
1793 if (gAlice){ // Set correctly the magnetic field in the ExB calculation
1794 AliMagF * field = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField());
1796 calib->SetExBField(field->SolenoidField());
1800 Float_t gasgain = fTPCParam->GetGasGain();
1801 gasgain = gasgain/fGainFactor;
1805 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1808 if (fHitType>1) branch = TH->GetBranch("TPC2");
1809 else branch = TH->GetBranch("TPC");
1812 //----------------------------------------------
1813 // Create TObjArray-s, one for each row,
1814 // each TObjArray will store the TVectors
1815 // of electrons, one TVectors per each track.
1816 //----------------------------------------------
1818 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
1819 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
1821 for(i=0; i<nrows+2; i++){
1822 row[i] = new TObjArray;
1829 //--------------------------------------------------------------------
1830 // Loop over tracks, the "track" contains the full history
1831 //--------------------------------------------------------------------
1833 Int_t previousTrack,currentTrack;
1834 previousTrack = -1; // nothing to store so far!
1836 for(Int_t track=0;track<ntracks;track++){
1837 Bool_t isInSector=kTRUE;
1839 isInSector = TrackInVolume(isec,track);
1840 if (!isInSector) continue;
1842 branch->GetEntry(track); // get next track
1846 tpcHit = (AliTPChit*)FirstHit(-1);
1848 //--------------------------------------------------------------
1850 //--------------------------------------------------------------
1855 Int_t sector=tpcHit->fSector; // sector number
1857 tpcHit = (AliTPChit*) NextHit();
1861 // Remove hits which arrive before the TPC opening gate signal
1862 if(((fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
1863 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
1864 tpcHit = (AliTPChit*) NextHit();
1868 currentTrack = tpcHit->Track(); // track number
1870 if(currentTrack != previousTrack){
1872 // store already filled fTrack
1874 for(i=0;i<nrows+2;i++){
1875 if(previousTrack != -1){
1876 if(nofElectrons[i]>0){
1877 TVector &v = *tracks[i];
1878 v(0) = previousTrack;
1879 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
1880 row[i]->Add(tracks[i]);
1883 delete tracks[i]; // delete empty TVector
1889 tracks[i] = new TVector(601); // TVectors for the next fTrack
1891 } // end of loop over rows
1893 previousTrack=currentTrack; // update track label
1896 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1898 //---------------------------------------------------
1899 // Calculate the electron attachment probability
1900 //---------------------------------------------------
1903 Float_t time = 1.e6*(fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
1904 /fTPCParam->GetDriftV();
1906 Float_t attProb = fTPCParam->GetAttCoef()*
1907 fTPCParam->GetOxyCont()*time; // fraction!
1909 //-----------------------------------------------
1910 // Loop over electrons
1911 //-----------------------------------------------
1914 for(Int_t nel=0;nel<qI;nel++){
1915 // skip if electron lost due to the attachment
1916 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1921 Double_t dxyz0[3],dxyz1[3];
1922 dxyz0[0]=tpcHit->X();
1923 dxyz0[1]=tpcHit->Y();
1924 dxyz0[2]=tpcHit->Z();
1925 if (calib->GetExB()){
1926 calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1928 AliError("Not valid ExB calibration");
1929 dxyz1[0]=tpcHit->X();
1930 dxyz1[1]=tpcHit->Y();
1931 dxyz1[2]=tpcHit->Z();
1939 // protection for the nonphysical avalanche size (10**6 maximum)
1941 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1942 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
1945 TransportElectron(xyz,index);
1947 Int_t padrow = fTPCParam->GetPadRow(xyz,index);
1949 // Add Time0 correction due unisochronity
1950 // xyz[0] - pad row coordinate
1951 // xyz[1] - pad coordinate
1952 // xyz[2] - is in now time bin coordinate system
1953 Float_t correction =0;
1954 if (calib->GetPadTime0()){
1955 if (!calib->GetPadTime0()->GetCalROC(isec)) continue;
1956 Int_t npads = fTPCParam->GetNPads(isec,padrow);
1957 // Int_t pad = TMath::Nint(xyz[1]+fTPCParam->GetNPads(isec,TMath::Nint(xyz[0]))*0.5);
1958 // pad numbering from -npads/2 .. npads/2-1
1959 Int_t pad = TMath::Nint(xyz[1]+npads/2);
1961 if (pad>=npads) pad=npads-1;
1962 correction = calib->GetPadTime0()->GetCalROC(isec)->GetValue(padrow,pad);
1963 // printf("%d\t%d\t%d\t%f\n",isec,padrow,pad,correction);
1964 if (fDebugStreamer){
1965 (*fDebugStreamer)<<"Time0"<<
1973 "cor="<<correction<<
1978 xyz[2]+=fTPCParam->GetNTBinsL1(); // adding Level 1 time bin offset
1980 // Electron track time (for pileup simulation)
1981 xyz[2]+=tpcHit->Time()/fTPCParam->GetTSample(); // adding time of flight
1985 // row 0 - cross talk from the innermost row
1986 // row fNRow+1 cross talk from the outermost row
1987 rowNumber = index[2]+1;
1988 //transform position to local digit coordinates
1989 //relative to nearest pad row
1990 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
1992 if (isec <fTPCParam->GetNInnerSector()) {
1993 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
1994 y1 = fTPCParam->GetYInner(rowNumber);
1997 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
1998 y1 = fTPCParam->GetYOuter(rowNumber);
2000 // gain inefficiency at the wires edges - linear
2003 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.)); */
2005 nofElectrons[rowNumber]++;
2006 //----------------------------------
2007 // Expand vector if necessary
2008 //----------------------------------
2009 if(nofElectrons[rowNumber]>120){
2010 Int_t range = tracks[rowNumber]->GetNrows();
2011 if((nofElectrons[rowNumber])>(range-1)/5){
2013 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
2017 TVector &v = *tracks[rowNumber];
2018 Int_t idx = 5*nofElectrons[rowNumber]-4;
2019 Real_t * position = &(((TVector&)v)(idx)); //make code faster
2020 memcpy(position,xyz,5*sizeof(Float_t));
2022 } // end of loop over electrons
2024 tpcHit = (AliTPChit*)NextHit();
2026 } // end of loop over hits
2027 } // end of loop over tracks
2030 // store remaining track (the last one) if not empty
2033 for(i=0;i<nrows+2;i++){
2034 if(nofElectrons[i]>0){
2035 TVector &v = *tracks[i];
2036 v(0) = previousTrack;
2037 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
2038 row[i]->Add(tracks[i]);
2047 delete [] nofElectrons;
2049 } // end of MakeSector
2052 //_____________________________________________________________________________
2056 // Initialise TPC detector after definition of geometry
2058 AliDebug(1,"*********************************************");
2061 //_____________________________________________________________________________
2062 void AliTPC::ResetDigits()
2065 // Reset number of digits and the digits array for this detector
2068 if (fDigits) fDigits->Clear();
2073 //_____________________________________________________________________________
2074 void AliTPC::SetSens(Int_t sens)
2077 //-------------------------------------------------------------
2078 // Activates/deactivates the sensitive strips at the center of
2079 // the pad row -- this is for the space-point resolution calculations
2080 //-------------------------------------------------------------
2082 //-----------------------------------------------------------------
2083 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2084 //-----------------------------------------------------------------
2090 void AliTPC::SetSide(Float_t side=0.)
2092 // choice of the TPC side
2097 //_____________________________________________________________________________
2099 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2102 // electron transport taking into account:
2104 // 2.ExB at the wires
2105 // 3. nonisochronity
2107 // xyz and index must be already transformed to system 1
2110 fTPCParam->Transform1to2(xyz,index); // mis-alignment applied in this step
2113 Float_t driftl=xyz[2];
2114 if(driftl<0.01) driftl=0.01;
2115 driftl=TMath::Sqrt(driftl);
2116 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2117 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2118 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2119 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2120 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2124 if (fTPCParam->GetMWPCReadout()==kTRUE){
2125 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2126 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2128 //add nonisochronity (not implemented yet)
2134 //______________________________________________________________________
2135 AliTPChit::AliTPChit()
2147 //_____________________________________________________________________________
2148 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits)
2149 :AliHit(shunt,track),
2156 // Creates a TPC hit object
2167 //________________________________________________________________________
2168 // Additional code because of the AliTPCTrackHitsV2
2170 void AliTPC::MakeBranch(Option_t *option)
2173 // Create a new branch in the current Root Tree
2174 // The branch of fHits is automatically split
2175 // MI change 14.09.2000
2177 if (fHitType<2) return;
2178 char branchname[10];
2179 sprintf(branchname,"%s2",GetName());
2181 // Get the pointer to the header
2182 const char *cH = strstr(option,"H");
2184 if (fTrackHits && fLoader->TreeH() && cH && fHitType&4) {
2185 AliDebug(1,"Making branch for Type 4 Hits");
2186 fLoader->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2189 // if (fTrackHitsOld && fLoader->TreeH() && cH && fHitType&2) {
2190 // AliDebug(1,"Making branch for Type 2 Hits");
2191 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2192 // fLoader->TreeH(),fBufferSize,99);
2193 // fLoader->TreeH()->GetListOfBranches()->Add(branch);
2197 void AliTPC::SetTreeAddress()
2199 //Sets tree address for hits
2201 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2202 AliDetector::SetTreeAddress();
2204 if (fHitType>1) SetTreeAddress2();
2207 void AliTPC::SetTreeAddress2()
2210 // Set branch address for the TrackHits Tree
2215 char branchname[20];
2216 sprintf(branchname,"%s2",GetName());
2218 // Branch address for hit tree
2219 TTree *treeH = fLoader->TreeH();
2220 if ((treeH)&&(fHitType&4)) {
2221 branch = treeH->GetBranch(branchname);
2223 branch->SetAddress(&fTrackHits);
2224 AliDebug(1,"fHitType&4 Setting");
2227 AliDebug(1,"fHitType&4 Failed (can not find branch)");
2230 // if ((treeH)&&(fHitType&2)) {
2231 // branch = treeH->GetBranch(branchname);
2233 // branch->SetAddress(&fTrackHitsOld);
2234 // AliDebug(1,"fHitType&2 Setting");
2237 // AliDebug(1,"fHitType&2 Failed (can not find branch)");
2241 void AliTPC::FinishPrimary()
2243 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2244 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2248 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2251 // add hit to the list
2255 int primary = gAlice->GetMCApp()->GetPrimary(track);
2256 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2260 gAlice->GetMCApp()->FlagTrack(track);
2262 if (fTrackHits && fHitType&4)
2263 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2264 hits[1],hits[2],(Int_t)hits[3],hits[4]);
2265 // if (fTrackHitsOld &&fHitType&2 )
2266 // fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2267 // hits[1],hits[2],(Int_t)hits[3]);
2271 void AliTPC::ResetHits()
2273 if (fHitType&1) AliDetector::ResetHits();
2274 if (fHitType>1) ResetHits2();
2277 void AliTPC::ResetHits2()
2281 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2282 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2286 AliHit* AliTPC::FirstHit(Int_t track)
2288 if (fHitType>1) return FirstHit2(track);
2289 return AliDetector::FirstHit(track);
2291 AliHit* AliTPC::NextHit()
2296 if (fHitType>1) return NextHit2();
2298 return AliDetector::NextHit();
2301 AliHit* AliTPC::FirstHit2(Int_t track)
2304 // Initialise the hit iterator
2305 // Return the address of the first hit for track
2306 // If track>=0 the track is read from disk
2307 // while if track<0 the first hit of the current
2308 // track is returned
2311 gAlice->GetMCApp()->ResetHits();
2312 fLoader->TreeH()->GetEvent(track);
2315 if (fTrackHits && fHitType&4) {
2316 fTrackHits->First();
2317 return fTrackHits->GetHit();
2319 // if (fTrackHitsOld && fHitType&2) {
2320 // fTrackHitsOld->First();
2321 // return fTrackHitsOld->GetHit();
2327 AliHit* AliTPC::NextHit2()
2330 //Return the next hit for the current track
2333 // if (fTrackHitsOld && fHitType&2) {
2334 // fTrackHitsOld->Next();
2335 // return fTrackHitsOld->GetHit();
2339 return fTrackHits->GetHit();
2345 void AliTPC::RemapTrackHitIDs(Int_t *map)
2350 if (!fTrackHits) return;
2352 // if (fTrackHitsOld && fHitType&2){
2353 // AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2354 // for (UInt_t i=0;i<arr->GetSize();i++){
2355 // AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2356 // info->fTrackID = map[info->fTrackID];
2359 // if (fTrackHitsOld && fHitType&4){
2360 if (fTrackHits && fHitType&4){
2361 TClonesArray * arr = fTrackHits->GetArray();;
2362 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2363 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2364 info->SetTrackID(map[info->GetTrackID()]);
2369 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2371 //return bool information - is track in given volume
2372 //load only part of the track information
2373 //return true if current track is in volume
2376 // if (fTrackHitsOld && fHitType&2) {
2377 // TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
2378 // br->GetEvent(track);
2379 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2380 // for (UInt_t j=0;j<ar->GetSize();j++){
2381 // if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2385 if (fTrackHits && fHitType&4) {
2386 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
2387 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
2388 br2->GetEvent(track);
2389 br1->GetEvent(track);
2390 Int_t *volumes = fTrackHits->GetVolumes();
2391 Int_t nvolumes = fTrackHits->GetNVolumes();
2392 if (!volumes && nvolumes>0) {
2393 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2396 for (Int_t j=0;j<nvolumes; j++)
2397 if (volumes[j]==id) return kTRUE;
2401 TBranch * br = fLoader->TreeH()->GetBranch("fSector");
2402 br->GetEvent(track);
2403 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2404 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2412 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2415 fLoader = new AliTPCLoader(GetName(),topfoldername);
2419 ////////////////////////////////////////////////////////////////////////
2420 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2422 // load TPC paarmeters from a given file or create new if the object
2423 // is not found there
2424 // 12/05/2003 This method should be moved to the AliTPCLoader
2425 // and one has to decide where to store the TPC parameters
2428 sprintf(paramName,"75x40_100x60_150x60");
2429 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2431 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2433 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2434 //paramTPC = new AliTPCParamSR;
2435 paramTPC = AliTPCcalibDB::Instance()->GetParameters();
2436 if (!paramTPC->IsGeoRead()){
2438 // read transformation matrices for gGeoManager
2440 paramTPC->ReadGeoMatrices();
2446 // the older version of parameters can be accessed with this code.
2447 // In some cases, we have old parameters saved in the file but
2448 // digits were created with new parameters, it can be distinguish
2449 // by the name of TPC TreeD. The code here is just for the case
2450 // we would need to compare with old data, uncomment it if needed.
2452 // char paramName[50];
2453 // sprintf(paramName,"75x40_100x60");
2454 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2456 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2458 // sprintf(paramName,"75x40_100x60_150x60");
2459 // paramTPC=(AliTPCParam*)in->Get(paramName);
2461 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2463 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2465 // paramTPC = new AliTPCParamSR;