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>
40 #include <TGeometry.h>
41 #include <TInterpreter.h>
46 #include <TObjectTable.h>
47 #include <TParticle.h>
53 #include <TVirtualMC.h>
56 #include <TStopwatch.h>
58 #include "AliDigits.h"
60 #include "AliPoints.h"
62 #include "AliRunLoader.h"
63 #include "AliSimDigits.h"
66 #include "AliTPCDigitsArray.h"
67 #include "AliTPCLoader.h"
68 #include "AliTPCPRF2D.h"
69 #include "AliTPCParamSR.h"
70 #include "AliTPCRF1D.h"
71 //#include "AliTPCTrackHits.h"
72 #include "AliTPCTrackHitsV2.h"
73 #include "AliTrackReference.h"
75 #include "AliTPCDigitizer.h"
76 #include "AliTPCBuffer.h"
77 #include "AliTPCDDLRawData.h"
82 //_____________________________________________________________________________
86 // Default constructor
96 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
97 fHitType = 4; // ROOT containers
99 fHitType = 2; //default CONTAINERS - based on ROOT structure
108 //_____________________________________________________________________________
109 AliTPC::AliTPC(const char *name, const char *title)
110 : AliDetector(name,title)
113 // Standard constructor
117 // Initialise arrays of hits and digits
118 fHits = new TClonesArray("AliTPChit", 176);
119 gAlice->GetMCApp()->AddHitList(fHits);
123 fTrackHits = new AliTPCTrackHitsV2;
124 fTrackHits->SetHitPrecision(0.002);
125 fTrackHits->SetStepPrecision(0.003);
126 fTrackHits->SetMaxDistance(100);
128 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
129 //fTrackHitsOld->SetHitPrecision(0.002);
130 //fTrackHitsOld->SetStepPrecision(0.003);
131 //fTrackHitsOld->SetMaxDistance(100);
135 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
136 fHitType = 4; // ROOT containers
142 // Initialise counters
148 // Initialise color attributes
149 SetMarkerColor(kYellow);
152 // Set TPC parameters
156 if (!strcmp(title,"Default")) {
157 fTPCParam = new AliTPCParamSR;
159 AliWarning("In Config.C you must set non-default parameters.");
166 //_____________________________________________________________________________
167 AliTPC::AliTPC(const AliTPC& t):AliDetector(t){
169 // dummy copy constructor
182 delete fTrackHits; //MI 15.09.2000
183 // delete fTrackHitsOld; //MI 10.12.2001
186 delete [] fNoiseTable;
187 delete [] fActiveSectors;
191 //_____________________________________________________________________________
192 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
195 // Add a hit to the list
198 TClonesArray &lhits = *fHits;
199 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
202 AddHit2(track,vol,hits);
205 //_____________________________________________________________________________
206 void AliTPC::BuildGeometry()
210 // Build TPC ROOT TNode geometry for the event display
215 const int kColorTPC=19;
216 char name[5], title[25];
217 const Double_t kDegrad=TMath::Pi()/180;
218 const Double_t kRaddeg=180./TMath::Pi();
221 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
222 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
224 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
225 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
227 Int_t nLo = fTPCParam->GetNInnerSector()/2;
228 Int_t nHi = fTPCParam->GetNOuterSector()/2;
230 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
231 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
232 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
233 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
236 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
237 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
243 // Get ALICE top node
246 nTop=gAlice->GetGeometry()->GetNode("alice");
250 rl = fTPCParam->GetInnerRadiusLow();
251 ru = fTPCParam->GetInnerRadiusUp();
255 sprintf(name,"LS%2.2d",i);
257 sprintf(title,"TPC low sector %3d",i);
260 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
261 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
262 tubs->SetNumberOfDivisions(1);
264 nNode = new TNode(name,title,name,0,0,0,"");
265 nNode->SetLineColor(kColorTPC);
271 rl = fTPCParam->GetOuterRadiusLow();
272 ru = fTPCParam->GetOuterRadiusUp();
275 sprintf(name,"US%2.2d",i);
277 sprintf(title,"TPC upper sector %d",i);
279 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
280 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
281 tubs->SetNumberOfDivisions(1);
283 nNode = new TNode(name,title,name,0,0,0,"");
284 nNode->SetLineColor(kColorTPC);
290 //_____________________________________________________________________________
291 void AliTPC::CreateMaterials()
293 //-----------------------------------------------
294 // Create Materials for for TPC simulations
295 //-----------------------------------------------
297 //-----------------------------------------------------------------
298 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
299 //-----------------------------------------------------------------
301 Int_t iSXFLD=gAlice->Field()->Integ();
302 Float_t sXMGMX=gAlice->Field()->Max();
304 Float_t amat[5]; // atomic numbers
305 Float_t zmat[5]; // z
306 Float_t wmat[5]; // proportions
312 //***************** Gases *************************
315 //--------------------------------------------------------------
316 // gases - air and CO2
317 //--------------------------------------------------------------
333 AliMixture(10,"CO2",amat,zmat,density,2,wmat);
348 AliMixture(11,"Air",amat,zmat,density,2,wmat);
350 //----------------------------------------------------------------
352 //----------------------------------------------------------------
355 // Drift gases 1 - nonsensitive, 2 - sensitive
356 // Ne-CO2-N (85-10-5)
375 AliMixture(12,"Ne-CO2-N-1",amat,zmat,density,4,wmat);
376 AliMixture(13,"Ne-CO2-N-2",amat,zmat,density,4,wmat);
378 //----------------------------------------------------------------------
380 //----------------------------------------------------------------------
402 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
423 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
441 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
459 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
477 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
478 // material for "prepregs"
479 // Epoxy - C14 H20 O3
482 // prepreg1 60% C-fiber, 40% epoxy (vol)
497 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
499 //prepreg2 60% glass-fiber, 40% epoxy
518 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
520 //prepreg3 50% glass-fiber, 50% epoxy
539 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
541 // G10 60% SiO2 40% epoxy
560 AliMixture(22, "G10",amat,zmat,density,4,wmat);
569 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
571 // Si (for electronics
578 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
587 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
589 // Epoxy - C14 H20 O3
605 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
623 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
631 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
633 // Fe (steel for the inner heat screen)
641 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
643 //----------------------------------------------------------
644 // tracking media for gases
645 //----------------------------------------------------------
647 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
648 AliMedium(1, "Ne-CO2-N-1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
649 AliMedium(2, "Ne-CO2-N-2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
650 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
652 //-----------------------------------------------------------
653 // tracking media for solids
654 //-----------------------------------------------------------
656 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
657 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
658 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
659 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
660 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
661 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
663 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
664 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
665 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
666 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
668 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
669 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
670 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
671 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
672 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
676 void AliTPC::GenerNoise(Int_t tablesize)
679 //Generate table with noise
686 if (fNoiseTable) delete[] fNoiseTable;
687 fNoiseTable = new Float_t[tablesize];
688 fNoiseDepth = tablesize;
689 fCurrentNoise =0; //!index of the noise in the noise table
691 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
692 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
695 Float_t AliTPC::GetNoise()
697 // get noise from table
698 // if ((fCurrentNoise%10)==0)
699 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
700 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
701 return fNoiseTable[fCurrentNoise++];
702 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
706 Bool_t AliTPC::IsSectorActive(Int_t sec) const
709 // check if the sector is active
710 if (!fActiveSectors) return kTRUE;
711 else return fActiveSectors[sec];
714 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
716 // activate interesting sectors
717 SetTreeAddress();//just for security
718 if (fActiveSectors) delete [] fActiveSectors;
719 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
720 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
721 for (Int_t i=0;i<n;i++)
722 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
726 void AliTPC::SetActiveSectors(Int_t flag)
729 // activate sectors which were hitted by tracks
731 SetTreeAddress();//just for security
732 if (fHitType==0) return; // if Clones hit - not short volume ID information
733 if (fActiveSectors) delete [] fActiveSectors;
734 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
736 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
739 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
743 AliFatal("Can not find TreeH in folder");
746 if (fHitType>1) branch = TreeH()->GetBranch("TPC2");
747 else branch = TreeH()->GetBranch("TPC");
748 Stat_t ntracks = TreeH()->GetEntries();
749 // loop over all hits
750 AliDebug(1,Form("Got %d tracks",ntracks));
752 for(Int_t track=0;track<ntracks;track++) {
755 if (fTrackHits && fHitType&4) {
756 TBranch * br1 = TreeH()->GetBranch("fVolumes");
757 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
758 br1->GetEvent(track);
759 br2->GetEvent(track);
760 Int_t *volumes = fTrackHits->GetVolumes();
761 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
762 fActiveSectors[volumes[j]]=kTRUE;
766 // if (fTrackHitsOld && fHitType&2) {
767 // TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
768 // br->GetEvent(track);
769 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
770 // for (UInt_t j=0;j<ar->GetSize();j++){
771 // fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
780 //_____________________________________________________________________________
781 void AliTPC::Digits2Raw()
783 // convert digits of the current event to raw data
785 static const Int_t kThreshold = 0;
787 fLoader->LoadDigits();
788 TTree* digits = fLoader->TreeD();
790 AliError("No digits tree");
795 AliSimDigits* digrow = &digarr;
796 digits->GetBranch("Segment")->SetAddress(&digrow);
798 const char* fileName = "AliTPCDDL.dat";
799 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
803 // 2: txt files with digits
804 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
805 //it is highly suggested to use this mode only for debugging digits files
806 //reasonably small, because otherwise the size of the txt files can reach
807 //quickly several MB wasting time and disk space.
808 buffer->SetVerbose(0);
810 Int_t nEntries = Int_t(digits->GetEntries());
811 Int_t previousSector = -1;
813 for (Int_t i = 0; i < nEntries; i++) {
816 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
817 if(previousSector != sector) {
819 previousSector = sector;
822 if (sector < 36) { //inner sector [0;35]
824 //the whole row is written into the output file
825 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
826 sector, subSector, row);
828 //only the pads in the range [37;48] are written into the output file
829 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
830 sector, subSector, row);
832 //only the pads outside the range [37;48] are written into the output file
833 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
834 sector, subSector, row);
837 } else { //outer sector [36;71]
838 if (row == 54) subSector = 2;
839 if ((row != 27) && (row != 76)) {
840 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
841 sector, subSector, row);
842 } else if (row == 27) {
843 //only the pads outside the range [43;46] are written into the output file
844 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
845 sector, subSector, row);
847 //only the pads in the range [43;46] are written into the output file
848 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
849 sector, subSector, row);
850 } else if (row == 76) {
851 //only the pads outside the range [33;88] are written into the output file
852 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
853 sector, subSector, row);
855 //only the pads in the range [33;88] are written into the output file
856 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
857 sector, subSector, row);
863 fLoader->UnloadDigits();
865 AliTPCDDLRawData rawWriter;
866 rawWriter.SetVerbose(0);
868 rawWriter.RawData(fileName);
869 gSystem->Unlink(fileName);
875 //______________________________________________________________________
876 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
878 return new AliTPCDigitizer(manager);
881 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
883 //create digits from summable digits
884 GenerNoise(500000); //create teble with noise
886 //conect tree with sSDigits
887 TTree *t = fLoader->TreeS();
890 fLoader->LoadSDigits("READ");
891 t = fLoader->TreeS();
893 AliError("Can not get input TreeS");
898 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
900 AliSimDigits digarr, *dummy=&digarr;
901 TBranch* sdb = t->GetBranch("Segment");
903 AliError("Can not find branch with segments in TreeS.");
907 sdb->SetAddress(&dummy);
909 Stat_t nentries = t->GetEntries();
911 // set zero suppression
913 fTPCParam->SetZeroSup(2);
915 // get zero suppression
917 Int_t zerosup = fTPCParam->GetZeroSup();
919 //make tree with digits
921 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
922 arr->SetClass("AliSimDigits");
923 arr->Setup(fTPCParam);
924 arr->MakeTree(fLoader->TreeD());
926 AliTPCParam * par = fTPCParam;
928 //Loop over segments of the TPC
930 for (Int_t n=0; n<nentries; n++) {
933 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
934 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
937 if (!IsSectorActive(sec)) continue;
939 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
940 Int_t nrows = digrow->GetNRows();
941 Int_t ncols = digrow->GetNCols();
943 digrow->ExpandBuffer();
944 digarr.ExpandBuffer();
945 digrow->ExpandTrackBuffer();
946 digarr.ExpandTrackBuffer();
949 Short_t * pamp0 = digarr.GetDigits();
950 Int_t * ptracks0 = digarr.GetTracks();
951 Short_t * pamp1 = digrow->GetDigits();
952 Int_t * ptracks1 = digrow->GetTracks();
953 Int_t nelems =nrows*ncols;
954 Int_t saturation = fTPCParam->GetADCSat() - 1;
955 //use internal structure of the AliDigits - for speed reason
956 //if you cahnge implementation
957 //of the Alidigits - it must be rewriten -
958 for (Int_t i= 0; i<nelems; i++){
959 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
961 if (q>saturation) q=saturation;
964 ptracks1[0]=ptracks0[0];
965 ptracks1[nelems]=ptracks0[nelems];
966 ptracks1[2*nelems]=ptracks0[2*nelems];
974 arr->StoreRow(sec,row);
975 arr->ClearRow(sec,row);
980 fLoader->WriteDigits("OVERWRITE");
984 //__________________________________________________________________
985 void AliTPC::SetDefaults(){
987 // setting the defaults
990 // Set response functions
993 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
995 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
997 AliInfo("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...");
999 param = new AliTPCParamSR();
1002 param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1005 AliFatal("No TPC parameters found");
1009 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1010 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1011 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1012 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1013 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1014 rf->SetOffset(3*param->GetZSigma());
1017 TDirectory *savedir=gDirectory;
1018 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1020 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1023 prfinner->Read("prf_07504_Gati_056068_d02");
1024 //PH Set different names
1025 s=prfinner->GetGRF()->GetName();
1027 prfinner->GetGRF()->SetName(s.Data());
1029 prfouter1->Read("prf_10006_Gati_047051_d03");
1030 s=prfouter1->GetGRF()->GetName();
1032 prfouter1->GetGRF()->SetName(s.Data());
1034 prfouter2->Read("prf_15006_Gati_047051_d03");
1035 s=prfouter2->GetGRF()->GetName();
1037 prfouter2->GetGRF()->SetName(s.Data());
1042 param->SetInnerPRF(prfinner);
1043 param->SetOuter1PRF(prfouter1);
1044 param->SetOuter2PRF(prfouter2);
1045 param->SetTimeRF(rf);
1055 //__________________________________________________________________
1056 void AliTPC::Hits2Digits()
1059 // creates digits from hits
1061 if (!fTPCParam->IsGeoRead()){
1063 // read transformation matrices for gGeoManager
1065 fTPCParam->ReadGeoMatrices();
1068 fLoader->LoadHits("read");
1069 fLoader->LoadDigits("recreate");
1070 AliRunLoader* runLoader = fLoader->GetRunLoader();
1072 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1073 runLoader->GetEvent(iEvent);
1075 Hits2Digits(iEvent);
1078 fLoader->UnloadHits();
1079 fLoader->UnloadDigits();
1081 //__________________________________________________________________
1082 void AliTPC::Hits2Digits(Int_t eventnumber)
1084 //----------------------------------------------------
1085 // Loop over all sectors for a single event
1086 //----------------------------------------------------
1087 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1088 rl->GetEvent(eventnumber);
1089 if (fLoader->TreeH() == 0x0) {
1090 if(fLoader->LoadHits()) {
1091 AliError("Can not load hits.");
1096 if (fLoader->TreeD() == 0x0 ) {
1097 fLoader->MakeTree("D");
1098 if (fLoader->TreeD() == 0x0 ) {
1099 AliError("Can not get TreeD");
1104 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1105 GenerNoise(500000); //create teble with noise
1107 //setup TPCDigitsArray
1109 if(GetDigitsArray()) delete GetDigitsArray();
1111 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1112 arr->SetClass("AliSimDigits");
1113 arr->Setup(fTPCParam);
1115 arr->MakeTree(fLoader->TreeD());
1116 SetDigitsArray(arr);
1118 fDigitsSwitch=0; // standard digits
1120 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1121 if (IsSectorActive(isec)) {
1122 AliDebug(1,Form("Hits2Digits","Sector %d is active.",isec));
1123 Hits2DigitsSector(isec);
1126 AliDebug(1,Form("Hits2Digits","Sector %d is NOT active.",isec));
1129 fLoader->WriteDigits("OVERWRITE");
1131 //this line prevents the crash in the similar one
1132 //on the beginning of this method
1133 //destructor attempts to reset the tree, which is deleted by the loader
1134 //need to be redesign
1135 if(GetDigitsArray()) delete GetDigitsArray();
1136 SetDigitsArray(0x0);
1140 //__________________________________________________________________
1141 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1144 //-----------------------------------------------------------
1145 // summable digits - 16 bit "ADC", no noise, no saturation
1146 //-----------------------------------------------------------
1148 //----------------------------------------------------
1149 // Loop over all sectors for a single event
1150 //----------------------------------------------------
1152 AliRunLoader* rl = fLoader->GetRunLoader();
1154 rl->GetEvent(eventnumber);
1155 if (fLoader->TreeH() == 0x0) {
1156 if(fLoader->LoadHits()) {
1157 AliError("Can not load hits.");
1164 if (fLoader->TreeS() == 0x0 ) {
1165 fLoader->MakeTree("S");
1168 if(fDefaults == 0) SetDefaults();
1170 GenerNoise(500000); //create table with noise
1171 //setup TPCDigitsArray
1173 if(GetDigitsArray()) delete GetDigitsArray();
1176 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1177 arr->SetClass("AliSimDigits");
1178 arr->Setup(fTPCParam);
1179 arr->MakeTree(fLoader->TreeS());
1181 SetDigitsArray(arr);
1183 fDigitsSwitch=1; // summable digits
1185 // set zero suppression to "0"
1187 fTPCParam->SetZeroSup(0);
1189 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1190 if (IsSectorActive(isec)) {
1191 Hits2DigitsSector(isec);
1194 fLoader->WriteSDigits("OVERWRITE");
1196 //this line prevents the crash in the similar one
1197 //on the beginning of this method
1198 //destructor attempts to reset the tree, which is deleted by the loader
1199 //need to be redesign
1200 if(GetDigitsArray()) delete GetDigitsArray();
1201 SetDigitsArray(0x0);
1203 //__________________________________________________________________
1205 void AliTPC::Hits2SDigits()
1208 //-----------------------------------------------------------
1209 // summable digits - 16 bit "ADC", no noise, no saturation
1210 //-----------------------------------------------------------
1212 if (!fTPCParam->IsGeoRead()){
1214 // read transformation matrices for gGeoManager
1216 fTPCParam->ReadGeoMatrices();
1219 fLoader->LoadHits("read");
1220 fLoader->LoadSDigits("recreate");
1221 AliRunLoader* runLoader = fLoader->GetRunLoader();
1223 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1224 runLoader->GetEvent(iEvent);
1227 Hits2SDigits2(iEvent);
1230 fLoader->UnloadHits();
1231 fLoader->UnloadSDigits();
1233 //_____________________________________________________________________________
1235 void AliTPC::Hits2DigitsSector(Int_t isec)
1237 //-------------------------------------------------------------------
1238 // TPC conversion from hits to digits.
1239 //-------------------------------------------------------------------
1241 //-----------------------------------------------------------------
1242 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1243 //-----------------------------------------------------------------
1245 //-------------------------------------------------------
1246 // Get the access to the track hits
1247 //-------------------------------------------------------
1249 // check if the parameters are set - important if one calls this method
1250 // directly, not from the Hits2Digits
1252 if(fDefaults == 0) SetDefaults();
1254 TTree *tH = TreeH(); // pointer to the hits tree
1256 AliFatal("Can not find TreeH in folder");
1260 Stat_t ntracks = tH->GetEntries();
1264 //-------------------------------------------
1265 // Only if there are any tracks...
1266 //-------------------------------------------
1270 Int_t nrows =fTPCParam->GetNRow(isec);
1272 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1274 MakeSector(isec,nrows,tH,ntracks,row);
1276 //--------------------------------------------------------
1277 // Digitize this sector, row by row
1278 // row[i] is the pointer to the TObjArray of TVectors,
1279 // each one containing electrons accepted on this
1280 // row, assigned into tracks
1281 //--------------------------------------------------------
1285 if (fDigitsArray->GetTree()==0) {
1286 AliFatal("Tree not set in fDigitsArray");
1289 for (i=0;i<nrows;i++){
1291 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1293 DigitizeRow(i,isec,row);
1295 fDigitsArray->StoreRow(isec,i);
1297 Int_t ndig = dig->GetDigitSize();
1300 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1303 fDigitsArray->ClearRow(isec,i);
1306 } // end of the sector digitization
1308 for(i=0;i<nrows+2;i++){
1313 delete [] row; // delete the array of pointers to TObjArray-s
1317 } // end of Hits2DigitsSector
1320 //_____________________________________________________________________________
1321 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1323 //-----------------------------------------------------------
1324 // Single row digitization, coupling from the neighbouring
1325 // rows taken into account
1326 //-----------------------------------------------------------
1328 //-----------------------------------------------------------------
1329 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1330 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1331 //-----------------------------------------------------------------
1333 Float_t zerosup = fTPCParam->GetZeroSup();
1335 fCurrentIndex[1]= isec;
1338 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1339 Int_t nofTbins = fTPCParam->GetMaxTBin();
1340 Int_t indexRange[4];
1342 // Integrated signal for this row
1343 // and a single track signal
1346 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1347 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
1349 TMatrixF &total = *m1;
1351 // Array of pointers to the label-signal list
1353 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1354 Float_t **pList = new Float_t* [nofDigits];
1358 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1364 for (Int_t row= row1;row<=row2;row++){
1365 Int_t nTracks= rows[row]->GetEntries();
1366 for (i1=0;i1<nTracks;i1++){
1367 fCurrentIndex[2]= row;
1368 fCurrentIndex[3]=irow+1;
1370 m2->Zero(); // clear single track signal matrix
1371 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1372 GetList(trackLabel,nofPads,m2,indexRange,pList);
1374 else GetSignal(rows[row],i1,0,m1,indexRange);
1380 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1382 Float_t fzerosup = zerosup+0.5;
1383 for(Int_t it=0;it<nofTbins;it++){
1384 for(Int_t ip=0;ip<nofPads;ip++){
1386 Float_t q=total(ip,it);
1387 if(fDigitsSwitch == 0){
1389 if(q <=fzerosup) continue; // do not fill zeros
1391 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
1396 if(q <= 0.) continue; // do not fill zeros
1397 if(q>2000.) q=2000.;
1403 // "real" signal or electronic noise (list = -1)?
1406 for(Int_t j1=0;j1<3;j1++){
1407 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1412 <A NAME="AliDigits"></A>
1413 using of AliDigits object
1416 dig->SetDigitFast((Short_t)q,it,ip);
1417 if (fDigitsArray->IsSimulated()) {
1418 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1419 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1420 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1423 } // end of loop over time buckets
1424 } // end of lop over pads
1427 // This row has been digitized, delete nonused stuff
1430 for(lp=0;lp<nofDigits;lp++){
1431 if(pList[lp]) delete [] pList[lp];
1439 } // end of DigitizeRow
1441 //_____________________________________________________________________________
1443 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1444 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
1447 //---------------------------------------------------------------
1448 // Calculates 2-D signal (pad,time) for a single track,
1449 // returns a pointer to the signal matrix and the track label
1450 // No digitization is performed at this level!!!
1451 //---------------------------------------------------------------
1453 //-----------------------------------------------------------------
1454 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1455 // Modified: Marian Ivanov
1456 //-----------------------------------------------------------------
1460 tv = (TVector*)p1->At(ntr); // pointer to a track
1463 Float_t label = v(0);
1464 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
1466 Int_t nElectrons = (tv->GetNrows()-1)/5;
1467 indexRange[0]=9999; // min pad
1468 indexRange[1]=-1; // max pad
1469 indexRange[2]=9999; //min time
1470 indexRange[3]=-1; // max time
1472 TMatrixF &signal = *m1;
1473 TMatrixF &total = *m2;
1475 // Loop over all electrons
1477 for(Int_t nel=0; nel<nElectrons; nel++){
1479 Float_t aval = v(idx+4);
1480 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1481 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
1482 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1484 Int_t *index = fTPCParam->GetResBin(0);
1485 Float_t *weight = & (fTPCParam->GetResWeight(0));
1487 if (n>0) for (Int_t i =0; i<n; i++){
1488 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1491 Int_t time=index[2];
1492 Float_t qweight = *(weight)*eltoadcfac;
1494 if (m1!=0) signal(pad,time)+=qweight;
1495 total(pad,time)+=qweight;
1496 if (indexRange[0]>pad) indexRange[0]=pad;
1497 if (indexRange[1]<pad) indexRange[1]=pad;
1498 if (indexRange[2]>time) indexRange[2]=time;
1499 if (indexRange[3]<time) indexRange[3]=time;
1506 } // end of loop over electrons
1508 return label; // returns track label when finished
1511 //_____________________________________________________________________________
1512 void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
1513 Int_t *indexRange, Float_t **pList)
1515 //----------------------------------------------------------------------
1516 // Updates the list of tracks contributing to digits for a given row
1517 //----------------------------------------------------------------------
1519 //-----------------------------------------------------------------
1520 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1521 //-----------------------------------------------------------------
1523 TMatrixF &signal = *m;
1525 // lop over nonzero digits
1527 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1528 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1531 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1533 if(signal(ip,it)<0.5) continue;
1535 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1537 if(!pList[globalIndex]){
1540 // Create new list (6 elements - 3 signals and 3 labels),
1543 pList[globalIndex] = new Float_t [6];
1547 *pList[globalIndex] = -1.;
1548 *(pList[globalIndex]+1) = -1.;
1549 *(pList[globalIndex]+2) = -1.;
1550 *(pList[globalIndex]+3) = -1.;
1551 *(pList[globalIndex]+4) = -1.;
1552 *(pList[globalIndex]+5) = -1.;
1554 *pList[globalIndex] = label;
1555 *(pList[globalIndex]+3) = signal(ip,it);
1559 // check the signal magnitude
1561 Float_t highest = *(pList[globalIndex]+3);
1562 Float_t middle = *(pList[globalIndex]+4);
1563 Float_t lowest = *(pList[globalIndex]+5);
1566 // compare the new signal with already existing list
1569 if(signal(ip,it)<lowest) continue; // neglect this track
1573 if (signal(ip,it)>highest){
1574 *(pList[globalIndex]+5) = middle;
1575 *(pList[globalIndex]+4) = highest;
1576 *(pList[globalIndex]+3) = signal(ip,it);
1578 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1579 *(pList[globalIndex]+1) = *pList[globalIndex];
1580 *pList[globalIndex] = label;
1582 else if (signal(ip,it)>middle){
1583 *(pList[globalIndex]+5) = middle;
1584 *(pList[globalIndex]+4) = signal(ip,it);
1586 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1587 *(pList[globalIndex]+1) = label;
1590 *(pList[globalIndex]+5) = signal(ip,it);
1591 *(pList[globalIndex]+2) = label;
1595 } // end of loop over pads
1596 } // end of loop over time bins
1599 //___________________________________________________________________
1600 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1601 Stat_t ntracks,TObjArray **row)
1604 //-----------------------------------------------------------------
1605 // Prepares the sector digitization, creates the vectors of
1606 // tracks for each row of this sector. The track vector
1607 // contains the track label and the position of electrons.
1608 //-----------------------------------------------------------------
1610 //-----------------------------------------------------------------
1611 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1612 //-----------------------------------------------------------------
1614 Float_t gasgain = fTPCParam->GetGasGain();
1618 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1621 if (fHitType>1) branch = TH->GetBranch("TPC2");
1622 else branch = TH->GetBranch("TPC");
1625 //----------------------------------------------
1626 // Create TObjArray-s, one for each row,
1627 // each TObjArray will store the TVectors
1628 // of electrons, one TVectors per each track.
1629 //----------------------------------------------
1631 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
1632 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
1634 for(i=0; i<nrows+2; i++){
1635 row[i] = new TObjArray;
1642 //--------------------------------------------------------------------
1643 // Loop over tracks, the "track" contains the full history
1644 //--------------------------------------------------------------------
1646 Int_t previousTrack,currentTrack;
1647 previousTrack = -1; // nothing to store so far!
1649 for(Int_t track=0;track<ntracks;track++){
1650 Bool_t isInSector=kTRUE;
1652 isInSector = TrackInVolume(isec,track);
1653 if (!isInSector) continue;
1655 branch->GetEntry(track); // get next track
1659 tpcHit = (AliTPChit*)FirstHit(-1);
1661 //--------------------------------------------------------------
1663 //--------------------------------------------------------------
1668 Int_t sector=tpcHit->fSector; // sector number
1670 tpcHit = (AliTPChit*) NextHit();
1674 // Remove hits which arrive before the TPC opening gate signal
1675 if(((fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
1676 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
1677 tpcHit = (AliTPChit*) NextHit();
1681 currentTrack = tpcHit->Track(); // track number
1683 if(currentTrack != previousTrack){
1685 // store already filled fTrack
1687 for(i=0;i<nrows+2;i++){
1688 if(previousTrack != -1){
1689 if(nofElectrons[i]>0){
1690 TVector &v = *tracks[i];
1691 v(0) = previousTrack;
1692 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
1693 row[i]->Add(tracks[i]);
1696 delete tracks[i]; // delete empty TVector
1702 tracks[i] = new TVector(601); // TVectors for the next fTrack
1704 } // end of loop over rows
1706 previousTrack=currentTrack; // update track label
1709 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1711 //---------------------------------------------------
1712 // Calculate the electron attachment probability
1713 //---------------------------------------------------
1716 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
1717 /fTPCParam->GetDriftV();
1719 Float_t attProb = fTPCParam->GetAttCoef()*
1720 fTPCParam->GetOxyCont()*time; // fraction!
1722 //-----------------------------------------------
1723 // Loop over electrons
1724 //-----------------------------------------------
1727 for(Int_t nel=0;nel<qI;nel++){
1728 // skip if electron lost due to the attachment
1729 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1734 // protection for the nonphysical avalanche size (10**6 maximum)
1736 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1737 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
1740 TransportElectron(xyz,index);
1742 fTPCParam->GetPadRow(xyz,index);
1743 // Electron track time (for pileup simulation)
1744 xyz[4] = tpcHit->Time()/fTPCParam->GetTSample();
1745 // row 0 - cross talk from the innermost row
1746 // row fNRow+1 cross talk from the outermost row
1747 rowNumber = index[2]+1;
1748 //transform position to local digit coordinates
1749 //relative to nearest pad row
1750 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
1752 if (isec <fTPCParam->GetNInnerSector()) {
1753 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
1754 y1 = fTPCParam->GetYInner(rowNumber);
1757 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
1758 y1 = fTPCParam->GetYOuter(rowNumber);
1760 // gain inefficiency at the wires edges - linear
1763 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.));
1765 nofElectrons[rowNumber]++;
1766 //----------------------------------
1767 // Expand vector if necessary
1768 //----------------------------------
1769 if(nofElectrons[rowNumber]>120){
1770 Int_t range = tracks[rowNumber]->GetNrows();
1771 if((nofElectrons[rowNumber])>(range-1)/5){
1773 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
1777 TVector &v = *tracks[rowNumber];
1778 Int_t idx = 5*nofElectrons[rowNumber]-4;
1779 Real_t * position = &(((TVector&)v)(idx)); //make code faster
1780 memcpy(position,xyz,5*sizeof(Float_t));
1782 } // end of loop over electrons
1784 tpcHit = (AliTPChit*)NextHit();
1786 } // end of loop over hits
1787 } // end of loop over tracks
1790 // store remaining track (the last one) if not empty
1793 for(i=0;i<nrows+2;i++){
1794 if(nofElectrons[i]>0){
1795 TVector &v = *tracks[i];
1796 v(0) = previousTrack;
1797 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
1798 row[i]->Add(tracks[i]);
1807 delete [] nofElectrons;
1809 } // end of MakeSector
1812 //_____________________________________________________________________________
1816 // Initialise TPC detector after definition of geometry
1818 AliDebug(1,"*********************************************");
1821 //_____________________________________________________________________________
1822 void AliTPC::MakeBranch(Option_t* option)
1825 // Create Tree branches for the TPC.
1828 Int_t buffersize = 4000;
1829 char branchname[10];
1830 sprintf(branchname,"%s",GetName());
1832 const char *h = strstr(option,"H");
1834 if ( h && (fHitType<=1) && (fHits == 0x0)) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
1836 AliDetector::MakeBranch(option);
1838 const char *d = strstr(option,"D");
1840 if (fDigits && fLoader->TreeD() && d) {
1841 MakeBranchInTree(gAlice->TreeD(), branchname, &fDigits, buffersize, 0);
1844 if (fHitType>1) MakeBranch2(option,0); // MI change 14.09.2000
1847 //_____________________________________________________________________________
1848 void AliTPC::ResetDigits()
1851 // Reset number of digits and the digits array for this detector
1854 if (fDigits) fDigits->Clear();
1859 //_____________________________________________________________________________
1860 void AliTPC::SetSens(Int_t sens)
1863 //-------------------------------------------------------------
1864 // Activates/deactivates the sensitive strips at the center of
1865 // the pad row -- this is for the space-point resolution calculations
1866 //-------------------------------------------------------------
1868 //-----------------------------------------------------------------
1869 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1870 //-----------------------------------------------------------------
1876 void AliTPC::SetSide(Float_t side=0.)
1878 // choice of the TPC side
1883 //_____________________________________________________________________________
1885 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
1888 // electron transport taking into account:
1890 // 2.ExB at the wires
1891 // 3. nonisochronity
1893 // xyz and index must be already transformed to system 1
1896 fTPCParam->Transform1to2(xyz,index);
1899 Float_t driftl=xyz[2];
1900 if(driftl<0.01) driftl=0.01;
1901 driftl=TMath::Sqrt(driftl);
1902 Float_t sigT = driftl*(fTPCParam->GetDiffT());
1903 Float_t sigL = driftl*(fTPCParam->GetDiffL());
1904 xyz[0]=gRandom->Gaus(xyz[0],sigT);
1905 xyz[1]=gRandom->Gaus(xyz[1],sigT);
1906 xyz[2]=gRandom->Gaus(xyz[2],sigL);
1910 if (fTPCParam->GetMWPCReadout()==kTRUE){
1911 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
1912 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
1914 //add nonisochronity (not implemented yet)
1919 //_____________________________________________________________________________
1920 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
1924 // Creates a TPC hit object
1935 //________________________________________________________________________
1936 // Additional code because of the AliTPCTrackHitsV2
1938 void AliTPC::MakeBranch2(Option_t *option,const char */*file*/)
1941 // Create a new branch in the current Root Tree
1942 // The branch of fHits is automatically split
1943 // MI change 14.09.2000
1945 if (fHitType<2) return;
1946 char branchname[10];
1947 sprintf(branchname,"%s2",GetName());
1949 // Get the pointer to the header
1950 const char *cH = strstr(option,"H");
1952 if (fTrackHits && TreeH() && cH && fHitType&4) {
1953 AliDebug(1,"Making branch for Type 4 Hits");
1954 TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
1957 // if (fTrackHitsOld && TreeH() && cH && fHitType&2) {
1958 // AliDebug(1,"Making branch for Type 2 Hits");
1959 // AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
1960 // TreeH(),fBufferSize,99);
1961 // TreeH()->GetListOfBranches()->Add(branch);
1965 void AliTPC::SetTreeAddress()
1967 //Sets tree address for hits
1969 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
1970 AliDetector::SetTreeAddress();
1972 if (fHitType>1) SetTreeAddress2();
1975 void AliTPC::SetTreeAddress2()
1978 // Set branch address for the TrackHits Tree
1983 char branchname[20];
1984 sprintf(branchname,"%s2",GetName());
1986 // Branch address for hit tree
1987 TTree *treeH = TreeH();
1988 if ((treeH)&&(fHitType&4)) {
1989 branch = treeH->GetBranch(branchname);
1991 branch->SetAddress(&fTrackHits);
1992 AliDebug(1,"fHitType&4 Setting");
1995 AliDebug(1,"fHitType&4 Failed (can not find branch)");
1998 // if ((treeH)&&(fHitType&2)) {
1999 // branch = treeH->GetBranch(branchname);
2001 // branch->SetAddress(&fTrackHitsOld);
2002 // AliDebug(1,"fHitType&2 Setting");
2005 // AliDebug(1,"fHitType&2 Failed (can not find branch)");
2007 //set address to TREETR
2009 TTree *treeTR = TreeTR();
2010 if (treeTR && fTrackReferences) {
2011 branch = treeTR->GetBranch(GetName());
2012 if (branch) branch->SetAddress(&fTrackReferences);
2017 void AliTPC::FinishPrimary()
2019 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2020 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2024 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2027 // add hit to the list
2030 int primary = gAlice->GetMCApp()->GetPrimary(track);
2031 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2035 gAlice->GetMCApp()->FlagTrack(track);
2037 if (fTrackHits && fHitType&4)
2038 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2039 hits[1],hits[2],(Int_t)hits[3],hits[4]);
2040 // if (fTrackHitsOld &&fHitType&2 )
2041 // fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2042 // hits[1],hits[2],(Int_t)hits[3]);
2046 void AliTPC::ResetHits()
2048 if (fHitType&1) AliDetector::ResetHits();
2049 if (fHitType>1) ResetHits2();
2052 void AliTPC::ResetHits2()
2056 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2057 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2061 AliHit* AliTPC::FirstHit(Int_t track)
2063 if (fHitType>1) return FirstHit2(track);
2064 return AliDetector::FirstHit(track);
2066 AliHit* AliTPC::NextHit()
2071 if (fHitType>1) return NextHit2();
2073 return AliDetector::NextHit();
2076 AliHit* AliTPC::FirstHit2(Int_t track)
2079 // Initialise the hit iterator
2080 // Return the address of the first hit for track
2081 // If track>=0 the track is read from disk
2082 // while if track<0 the first hit of the current
2083 // track is returned
2086 gAlice->ResetHits();
2087 TreeH()->GetEvent(track);
2090 if (fTrackHits && fHitType&4) {
2091 fTrackHits->First();
2092 return fTrackHits->GetHit();
2094 // if (fTrackHitsOld && fHitType&2) {
2095 // fTrackHitsOld->First();
2096 // return fTrackHitsOld->GetHit();
2102 AliHit* AliTPC::NextHit2()
2105 //Return the next hit for the current track
2108 // if (fTrackHitsOld && fHitType&2) {
2109 // fTrackHitsOld->Next();
2110 // return fTrackHitsOld->GetHit();
2114 return fTrackHits->GetHit();
2120 void AliTPC::LoadPoints(Int_t)
2125 if(fHitType==1) AliDetector::LoadPoints(a);
2126 else LoadPoints2(a);
2130 void AliTPC::RemapTrackHitIDs(Int_t *map)
2135 if (!fTrackHits) return;
2137 // if (fTrackHitsOld && fHitType&2){
2138 // AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2139 // for (UInt_t i=0;i<arr->GetSize();i++){
2140 // AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2141 // info->fTrackID = map[info->fTrackID];
2144 // if (fTrackHitsOld && fHitType&4){
2145 if (fTrackHits && fHitType&4){
2146 TClonesArray * arr = fTrackHits->GetArray();;
2147 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2148 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2149 info->fTrackID = map[info->fTrackID];
2154 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2156 //return bool information - is track in given volume
2157 //load only part of the track information
2158 //return true if current track is in volume
2161 // if (fTrackHitsOld && fHitType&2) {
2162 // TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
2163 // br->GetEvent(track);
2164 // AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2165 // for (UInt_t j=0;j<ar->GetSize();j++){
2166 // if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2170 if (fTrackHits && fHitType&4) {
2171 TBranch * br1 = TreeH()->GetBranch("fVolumes");
2172 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
2173 br2->GetEvent(track);
2174 br1->GetEvent(track);
2175 Int_t *volumes = fTrackHits->GetVolumes();
2176 Int_t nvolumes = fTrackHits->GetNVolumes();
2177 if (!volumes && nvolumes>0) {
2178 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2181 for (Int_t j=0;j<nvolumes; j++)
2182 if (volumes[j]==id) return kTRUE;
2186 TBranch * br = TreeH()->GetBranch("fSector");
2187 br->GetEvent(track);
2188 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2189 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2196 //_____________________________________________________________________________
2197 void AliTPC::LoadPoints2(Int_t)
2200 // Store x, y, z of all hits in memory
2202 // if (fTrackHits == 0 && fTrackHitsOld==0) return;
2203 if (fTrackHits == 0 ) return;
2206 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2207 // if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2209 if (nhits == 0) return;
2210 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2211 if (fPoints == 0) fPoints = new TObjArray(tracks);
2214 Int_t *ntrk=new Int_t[tracks];
2215 Int_t *limi=new Int_t[tracks];
2216 Float_t **coor=new Float_t*[tracks];
2217 for(Int_t i=0;i<tracks;i++) {
2223 AliPoints *points = 0;
2226 Int_t chunk=nhits/4+1;
2228 // Loop over all the hits and store their position
2230 ahit = FirstHit2(-1);
2232 trk=ahit->GetTrack();
2233 if(ntrk[trk]==limi[trk]) {
2235 // Initialise a new track
2236 fp=new Float_t[3*(limi[trk]+chunk)];
2238 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2239 delete [] coor[trk];
2246 fp[3*ntrk[trk] ] = ahit->X();
2247 fp[3*ntrk[trk]+1] = ahit->Y();
2248 fp[3*ntrk[trk]+2] = ahit->Z();
2256 for(trk=0; trk<tracks; ++trk) {
2258 points = new AliPoints();
2259 points->SetMarkerColor(GetMarkerColor());
2260 points->SetMarkerSize(GetMarkerSize());
2261 points->SetDetector(this);
2262 points->SetParticle(trk);
2263 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2264 fPoints->AddAt(points,trk);
2265 delete [] coor[trk];
2275 //_____________________________________________________________________________
2276 void AliTPC::LoadPoints3(Int_t)
2279 // Store x, y, z of all hits in memory
2280 // - only intersection point with pad row
2281 if (fTrackHits == 0) return;
2283 Int_t nhits = fTrackHits->GetEntriesFast();
2284 if (nhits == 0) return;
2285 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2286 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2287 fPoints->Expand(2*tracks);
2290 Int_t *ntrk=new Int_t[tracks];
2291 Int_t *limi=new Int_t[tracks];
2292 Float_t **coor=new Float_t*[tracks];
2293 for(Int_t i=0;i<tracks;i++) {
2299 AliPoints *points = 0;
2302 Int_t chunk=nhits/4+1;
2304 // Loop over all the hits and store their position
2306 ahit = FirstHit2(-1);
2310 trk=ahit->GetTrack();
2311 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2312 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2313 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2314 if (currentrow!=lastrow){
2315 lastrow = currentrow;
2316 //later calculate intersection point
2317 if(ntrk[trk]==limi[trk]) {
2319 // Initialise a new track
2320 fp=new Float_t[3*(limi[trk]+chunk)];
2322 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2323 delete [] coor[trk];
2330 fp[3*ntrk[trk] ] = ahit->X();
2331 fp[3*ntrk[trk]+1] = ahit->Y();
2332 fp[3*ntrk[trk]+2] = ahit->Z();
2339 for(trk=0; trk<tracks; ++trk) {
2341 points = new AliPoints();
2342 points->SetMarkerColor(GetMarkerColor()+1);
2343 points->SetMarkerStyle(5);
2344 points->SetMarkerSize(0.2);
2345 points->SetDetector(this);
2346 points->SetParticle(trk);
2347 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2348 fPoints->AddAt(points,tracks+trk);
2349 delete [] coor[trk];
2360 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2363 fLoader = new AliTPCLoader(GetName(),topfoldername);
2367 ////////////////////////////////////////////////////////////////////////
2368 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2370 // load TPC paarmeters from a given file or create new if the object
2371 // is not found there
2372 // 12/05/2003 This method should be moved to the AliTPCLoader
2373 // and one has to decide where to store the TPC parameters
2376 sprintf(paramName,"75x40_100x60_150x60");
2377 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2379 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2381 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2382 paramTPC = new AliTPCParamSR;
2386 // the older version of parameters can be accessed with this code.
2387 // In some cases, we have old parameters saved in the file but
2388 // digits were created with new parameters, it can be distinguish
2389 // by the name of TPC TreeD. The code here is just for the case
2390 // we would need to compare with old data, uncomment it if needed.
2392 // char paramName[50];
2393 // sprintf(paramName,"75x40_100x60");
2394 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2396 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2398 // sprintf(paramName,"75x40_100x60_150x60");
2399 // paramTPC=(AliTPCParam*)in->Get(paramName);
2401 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2403 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2405 // paramTPC = new AliTPCParamSR;