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>
45 #include <TObjectTable.h>
46 #include <TParticle.h>
52 #include <TVirtualMC.h>
55 #include <TStopwatch.h>
57 #include "AliArrayBranch.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
107 //_____________________________________________________________________________
108 AliTPC::AliTPC(const char *name, const char *title)
109 : AliDetector(name,title)
112 // Standard constructor
116 // Initialise arrays of hits and digits
117 fHits = new TClonesArray("AliTPChit", 176);
118 gAlice->GetMCApp()->AddHitList(fHits);
122 fTrackHits = new AliTPCTrackHitsV2;
123 fTrackHits->SetHitPrecision(0.002);
124 fTrackHits->SetStepPrecision(0.003);
125 fTrackHits->SetMaxDistance(100);
127 fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
128 fTrackHitsOld->SetHitPrecision(0.002);
129 fTrackHitsOld->SetStepPrecision(0.003);
130 fTrackHitsOld->SetMaxDistance(100);
134 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
135 fHitType = 4; // ROOT containers
141 // Initialise counters
147 // Initialise color attributes
148 SetMarkerColor(kYellow);
151 // Set TPC parameters
155 if (!strcmp(title,"Default")) {
156 fTPCParam = new AliTPCParamSR;
158 AliWarning("In Config.C you must set non-default parameters.");
164 //_____________________________________________________________________________
165 AliTPC::AliTPC(const AliTPC& t):AliDetector(t){
167 // dummy copy constructor
180 delete fTrackHits; //MI 15.09.2000
181 delete fTrackHitsOld; //MI 10.12.2001
182 if (fNoiseTable) delete [] fNoiseTable;
186 //_____________________________________________________________________________
187 void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
190 // Add a hit to the list
193 TClonesArray &lhits = *fHits;
194 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
197 AddHit2(track,vol,hits);
200 //_____________________________________________________________________________
201 void AliTPC::BuildGeometry()
205 // Build TPC ROOT TNode geometry for the event display
210 const int kColorTPC=19;
211 char name[5], title[25];
212 const Double_t kDegrad=TMath::Pi()/180;
213 const Double_t kRaddeg=180./TMath::Pi();
216 Float_t innerOpenAngle = fTPCParam->GetInnerAngle();
217 Float_t outerOpenAngle = fTPCParam->GetOuterAngle();
219 Float_t innerAngleShift = fTPCParam->GetInnerAngleShift();
220 Float_t outerAngleShift = fTPCParam->GetOuterAngleShift();
222 Int_t nLo = fTPCParam->GetNInnerSector()/2;
223 Int_t nHi = fTPCParam->GetNOuterSector()/2;
225 const Double_t kloAng = (Double_t)TMath::Nint(innerOpenAngle*kRaddeg);
226 const Double_t khiAng = (Double_t)TMath::Nint(outerOpenAngle*kRaddeg);
227 const Double_t kloAngSh = (Double_t)TMath::Nint(innerAngleShift*kRaddeg);
228 const Double_t khiAngSh = (Double_t)TMath::Nint(outerAngleShift*kRaddeg);
231 const Double_t kloCorr = 1/TMath::Cos(0.5*kloAng*kDegrad);
232 const Double_t khiCorr = 1/TMath::Cos(0.5*khiAng*kDegrad);
238 // Get ALICE top node
241 nTop=gAlice->GetGeometry()->GetNode("alice");
245 rl = fTPCParam->GetInnerRadiusLow();
246 ru = fTPCParam->GetInnerRadiusUp();
250 sprintf(name,"LS%2.2d",i);
252 sprintf(title,"TPC low sector %3d",i);
255 tubs = new TTUBS(name,title,"void",rl*kloCorr,ru*kloCorr,250.,
256 kloAng*(i-0.5)+kloAngSh,kloAng*(i+0.5)+kloAngSh);
257 tubs->SetNumberOfDivisions(1);
259 nNode = new TNode(name,title,name,0,0,0,"");
260 nNode->SetLineColor(kColorTPC);
266 rl = fTPCParam->GetOuterRadiusLow();
267 ru = fTPCParam->GetOuterRadiusUp();
270 sprintf(name,"US%2.2d",i);
272 sprintf(title,"TPC upper sector %d",i);
274 tubs = new TTUBS(name,title,"void",rl*khiCorr,ru*khiCorr,250,
275 khiAng*(i-0.5)+khiAngSh,khiAng*(i+0.5)+khiAngSh);
276 tubs->SetNumberOfDivisions(1);
278 nNode = new TNode(name,title,name,0,0,0,"");
279 nNode->SetLineColor(kColorTPC);
285 //_____________________________________________________________________________
286 Int_t AliTPC::DistancetoPrimitive(Int_t , Int_t ) const
289 // Calculate distance from TPC to mouse on the display
296 //_____________________________________________________________________________
297 void AliTPC::CreateMaterials()
299 //-----------------------------------------------
300 // Create Materials for for TPC simulations
301 //-----------------------------------------------
303 //-----------------------------------------------------------------
304 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
305 //-----------------------------------------------------------------
307 Int_t iSXFLD=gAlice->Field()->Integ();
308 Float_t sXMGMX=gAlice->Field()->Max();
310 Float_t amat[5]; // atomic numbers
311 Float_t zmat[5]; // z
312 Float_t wmat[5]; // proportions
318 //***************** Gases *************************
320 //-------------------------------------------------
322 //-------------------------------------------------
333 AliMaterial(20,"Ne",amat[0],zmat[0],density,999.,999.);
343 AliMaterial(21,"Ar",amat[0],zmat[0],density,999.,999.);
346 //--------------------------------------------------------------
348 //--------------------------------------------------------------
365 amol[0] = amat[0]*wmat[0]+amat[1]*wmat[1];
367 AliMixture(10,"CO2",amat,zmat,density,-2,wmat);
382 amol[1] = amat[0]*wmat[0]+amat[1]*wmat[1];
384 AliMixture(11,"CF4",amat,zmat,density,-2,wmat);
400 amol[2] = amat[0]*wmat[0]+amat[1]*wmat[1];
402 AliMixture(12,"CH4",amat,zmat,density,-2,wmat);
404 //----------------------------------------------------------------
405 // gases - mixtures, ID >= 20 pure gases, <= 10 ID < 20 -compounds
406 //----------------------------------------------------------------
412 Float_t rho,absl,x0,buf[1];
416 for(nc = 0;nc<fNoComp;nc++) {
418 // retrive material constants
420 gMC->Gfmate((*fIdmate)[fMixtComp[nc]],namate,a,z,rho,x0,absl,buf,nbuf);
425 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
427 am += fMixtProp[nc]*((fMixtComp[nc]>=20) ? apure[nnc] : amol[nnc]);
428 density += fMixtProp[nc]*rho; // density of the mixture
432 // mixture proportions by weight!
434 for(nc = 0;nc<fNoComp;nc++) {
436 Int_t nnc = (fMixtComp[nc]>=20) ? fMixtComp[nc]%20 : fMixtComp[nc]%10;
438 wmat[nc] = fMixtProp[nc]*((fMixtComp[nc]>=20) ?
439 apure[nnc] : amol[nnc])/am;
443 // Drift gases 1 - nonsensitive, 2 - sensitive
445 AliMixture(31,"Drift gas 1",amat,zmat,density,fNoComp,wmat);
446 AliMixture(32,"Drift gas 2",amat,zmat,density,fNoComp,wmat);
455 AliMaterial(24,"Air",amat[0],zmat[0],density,999.,999.);
458 //----------------------------------------------------------------------
460 //----------------------------------------------------------------------
482 AliMixture(34,"Kevlar",amat,zmat,density,-4,wmat);
504 AliMixture(35,"NOMEX",amat,zmat,density,-4,wmat);
522 AliMixture(36,"Makrolon",amat,zmat,density,-3,wmat);
540 AliMixture(37, "Mylar",amat,zmat,density,-3,wmat);
542 // SiO2 - used later for the glass fiber
554 AliMixture(38,"SiO2",amat,zmat,2.2,-2,wmat); //SiO2 - quartz (rho=2.2)
563 AliMaterial(40,"Al",amat[0],zmat[0],density,999.,999.);
572 AliMaterial(41,"Si",amat[0],zmat[0],density,999.,999.);
581 AliMaterial(42,"Cu",amat[0],zmat[0],density,999.,999.);
599 AliMixture(43, "Tedlar",amat,zmat,density,-3,wmat);
618 AliMixture(44,"Plexiglas",amat,zmat,density,-3,wmat);
620 // Epoxy - C14 H20 O3
637 AliMixture(45,"Epoxy",amat,zmat,density,-3,wmat);
645 AliMaterial(46,"C",amat[0],zmat[0],density,999.,999.);
649 gMC->Gfmate((*fIdmate)[45],namate,amat[1],zmat[1],rho,x0,absl,buf,nbuf);
653 wmat[0]=0.644; // by weight!
656 density=0.5*(1.25+2.265);
658 AliMixture(47,"Cfiber",amat,zmat,density,2,wmat);
662 gMC->Gfmate((*fIdmate)[38],namate,amat[0],zmat[0],rho,x0,absl,buf,nbuf);
664 wmat[0]=0.725; // by weight!
669 AliMixture(39,"G10",amat,zmat,density,2,wmat);
674 //----------------------------------------------------------
675 // tracking media for gases
676 //----------------------------------------------------------
678 AliMedium(0, "Air", 24, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
679 AliMedium(1, "Drift gas 1", 31, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
680 AliMedium(2, "Drift gas 2", 32, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
681 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
683 //-----------------------------------------------------------
684 // tracking media for solids
685 //-----------------------------------------------------------
687 AliMedium(4,"Al",40,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
688 AliMedium(5,"Kevlar",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
689 AliMedium(6,"Nomex",35,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
690 AliMedium(7,"Makrolon",36,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
691 AliMedium(8,"Mylar",37,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
692 AliMedium(9,"Tedlar",43,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
693 AliMedium(10,"Cu",42,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
694 AliMedium(11,"Si",41,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
695 AliMedium(12,"G10",39,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
696 AliMedium(13,"Plexiglas",44,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
697 AliMedium(14,"Epoxy",45,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
698 AliMedium(15,"Cfiber",47,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
702 void AliTPC::GenerNoise(Int_t tablesize)
705 //Generate table with noise
712 if (fNoiseTable) delete[] fNoiseTable;
713 fNoiseTable = new Float_t[tablesize];
714 fNoiseDepth = tablesize;
715 fCurrentNoise =0; //!index of the noise in the noise table
717 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
718 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
721 Float_t AliTPC::GetNoise()
723 // get noise from table
724 // if ((fCurrentNoise%10)==0)
725 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
726 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
727 return fNoiseTable[fCurrentNoise++];
728 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
732 Bool_t AliTPC::IsSectorActive(Int_t sec) const
735 // check if the sector is active
736 if (!fActiveSectors) return kTRUE;
737 else return fActiveSectors[sec];
740 void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
742 // activate interesting sectors
743 SetTreeAddress();//just for security
744 if (fActiveSectors) delete [] fActiveSectors;
745 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
746 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
747 for (Int_t i=0;i<n;i++)
748 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
752 void AliTPC::SetActiveSectors(Int_t flag)
755 // activate sectors which were hitted by tracks
757 SetTreeAddress();//just for security
758 if (fHitType==0) return; // if Clones hit - not short volume ID information
759 if (fActiveSectors) delete [] fActiveSectors;
760 fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
762 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
765 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
769 AliFatal("Can not find TreeH in folder");
772 if (fHitType>1) branch = TreeH()->GetBranch("TPC2");
773 else branch = TreeH()->GetBranch("TPC");
774 Stat_t ntracks = TreeH()->GetEntries();
775 // loop over all hits
776 AliDebug(1,Form("Got %d tracks",ntracks));
778 for(Int_t track=0;track<ntracks;track++) {
781 if (fTrackHits && fHitType&4) {
782 TBranch * br1 = TreeH()->GetBranch("fVolumes");
783 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
784 br1->GetEvent(track);
785 br2->GetEvent(track);
786 Int_t *volumes = fTrackHits->GetVolumes();
787 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++)
788 fActiveSectors[volumes[j]]=kTRUE;
792 if (fTrackHitsOld && fHitType&2) {
793 TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
795 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
796 for (UInt_t j=0;j<ar->GetSize();j++){
797 fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
806 //_____________________________________________________________________________
807 void AliTPC::Digits2Raw()
809 // convert digits of the current event to raw data
811 static const Int_t kThreshold = 0;
812 static const Bool_t kCompress = kTRUE;
814 fLoader->LoadDigits();
815 TTree* digits = fLoader->TreeD();
817 AliError("No digits tree");
822 AliSimDigits* digrow = &digarr;
823 digits->GetBranch("Segment")->SetAddress(&digrow);
825 const char* fileName = "AliTPCDDL.dat";
826 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
830 // 2: txt files with digits
831 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
832 //it is highly suggested to use this mode only for debugging digits files
833 //reasonably small, because otherwise the size of the txt files can reach
834 //quickly several MB wasting time and disk space.
835 buffer->SetVerbose(0);
837 Int_t nEntries = Int_t(digits->GetEntries());
838 Int_t previousSector = -1;
840 for (Int_t i = 0; i < nEntries; i++) {
843 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
844 if(previousSector != sector) {
846 previousSector = sector;
849 if (sector < 36) { //inner sector [0;35]
851 //the whole row is written into the output file
852 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
853 sector, subSector, row);
855 //only the pads in the range [37;48] are written into the output file
856 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
857 sector, subSector, row);
859 //only the pads outside the range [37;48] are written into the output file
860 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
861 sector, subSector, row);
864 } else { //outer sector [36;71]
865 if (row == 54) subSector = 2;
866 if ((row != 27) && (row != 76)) {
867 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
868 sector, subSector, row);
869 } else if (row == 27) {
870 //only the pads outside the range [43;46] are written into the output file
871 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
872 sector, subSector, row);
874 //only the pads in the range [43;46] are written into the output file
875 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
876 sector, subSector, row);
877 } else if (row == 76) {
878 //only the pads outside the range [33;88] are written into the output file
879 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
880 sector, subSector, row);
882 //only the pads in the range [33;88] are written into the output file
883 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
884 sector, subSector, row);
890 fLoader->UnloadDigits();
892 AliTPCDDLRawData rawWriter;
893 rawWriter.SetVerbose(0);
895 rawWriter.RawData(fileName);
896 gSystem->Unlink(fileName);
899 AliInfo("Compressing raw data");
900 rawWriter.RawDataCompDecompress(kTRUE);
901 gSystem->Unlink("Statistics");
907 //______________________________________________________________________
908 AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
910 return new AliTPCDigitizer(manager);
913 void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
915 //create digits from summable digits
916 GenerNoise(500000); //create teble with noise
918 //conect tree with sSDigits
919 TTree *t = fLoader->TreeS();
922 fLoader->LoadSDigits("READ");
923 t = fLoader->TreeS();
925 AliError("Can not get input TreeS");
930 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
932 AliSimDigits digarr, *dummy=&digarr;
933 TBranch* sdb = t->GetBranch("Segment");
935 AliError("Can not find branch with segments in TreeS.");
939 sdb->SetAddress(&dummy);
941 Stat_t nentries = t->GetEntries();
943 // set zero suppression
945 fTPCParam->SetZeroSup(2);
947 // get zero suppression
949 Int_t zerosup = fTPCParam->GetZeroSup();
951 //make tree with digits
953 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
954 arr->SetClass("AliSimDigits");
955 arr->Setup(fTPCParam);
956 arr->MakeTree(fLoader->TreeD());
958 AliTPCParam * par = fTPCParam;
960 //Loop over segments of the TPC
962 for (Int_t n=0; n<nentries; n++) {
965 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
966 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
969 if (!IsSectorActive(sec)) continue;
971 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
972 Int_t nrows = digrow->GetNRows();
973 Int_t ncols = digrow->GetNCols();
975 digrow->ExpandBuffer();
976 digarr.ExpandBuffer();
977 digrow->ExpandTrackBuffer();
978 digarr.ExpandTrackBuffer();
981 Short_t * pamp0 = digarr.GetDigits();
982 Int_t * ptracks0 = digarr.GetTracks();
983 Short_t * pamp1 = digrow->GetDigits();
984 Int_t * ptracks1 = digrow->GetTracks();
985 Int_t nelems =nrows*ncols;
986 Int_t saturation = fTPCParam->GetADCSat();
987 //use internal structure of the AliDigits - for speed reason
988 //if you cahnge implementation
989 //of the Alidigits - it must be rewriten -
990 for (Int_t i= 0; i<nelems; i++){
991 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
993 if (q>saturation) q=saturation;
996 ptracks1[0]=ptracks0[0];
997 ptracks1[nelems]=ptracks0[nelems];
998 ptracks1[2*nelems]=ptracks0[2*nelems];
1006 arr->StoreRow(sec,row);
1007 arr->ClearRow(sec,row);
1012 fLoader->WriteDigits("OVERWRITE");
1016 //__________________________________________________________________
1017 void AliTPC::SetDefaults(){
1019 // setting the defaults
1022 // Set response functions
1025 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1027 AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
1029 AliInfo("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...");
1031 param = new AliTPCParamSR();
1034 param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
1037 AliFatal("No TPC parameters found");
1041 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
1042 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1043 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
1044 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1045 rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1046 rf->SetOffset(3*param->GetZSigma());
1049 TDirectory *savedir=gDirectory;
1050 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
1052 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
1055 prfinner->Read("prf_07504_Gati_056068_d02");
1056 //PH Set different names
1057 s=prfinner->GetGRF()->GetName();
1059 prfinner->GetGRF()->SetName(s.Data());
1061 prfouter1->Read("prf_10006_Gati_047051_d03");
1062 s=prfouter1->GetGRF()->GetName();
1064 prfouter1->GetGRF()->SetName(s.Data());
1066 prfouter2->Read("prf_15006_Gati_047051_d03");
1067 s=prfouter2->GetGRF()->GetName();
1069 prfouter2->GetGRF()->SetName(s.Data());
1074 param->SetInnerPRF(prfinner);
1075 param->SetOuter1PRF(prfouter1);
1076 param->SetOuter2PRF(prfouter2);
1077 param->SetTimeRF(rf);
1087 //__________________________________________________________________
1088 void AliTPC::Hits2Digits()
1091 // creates digits from hits
1094 fLoader->LoadHits("read");
1095 fLoader->LoadDigits("recreate");
1096 AliRunLoader* runLoader = fLoader->GetRunLoader();
1098 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1099 runLoader->GetEvent(iEvent);
1101 Hits2Digits(iEvent);
1104 fLoader->UnloadHits();
1105 fLoader->UnloadDigits();
1107 //__________________________________________________________________
1108 void AliTPC::Hits2Digits(Int_t eventnumber)
1110 //----------------------------------------------------
1111 // Loop over all sectors for a single event
1112 //----------------------------------------------------
1113 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
1114 rl->GetEvent(eventnumber);
1115 if (fLoader->TreeH() == 0x0) {
1116 if(fLoader->LoadHits()) {
1117 AliError("Can not load hits.");
1122 if (fLoader->TreeD() == 0x0 ) {
1123 fLoader->MakeTree("D");
1124 if (fLoader->TreeD() == 0x0 ) {
1125 AliError("Can not get TreeD");
1130 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
1131 GenerNoise(500000); //create teble with noise
1133 //setup TPCDigitsArray
1135 if(GetDigitsArray()) delete GetDigitsArray();
1137 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1138 arr->SetClass("AliSimDigits");
1139 arr->Setup(fTPCParam);
1141 arr->MakeTree(fLoader->TreeD());
1142 SetDigitsArray(arr);
1144 fDigitsSwitch=0; // standard digits
1146 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1147 if (IsSectorActive(isec)) {
1148 AliDebug(1,Form("Hits2Digits","Sector %d is active.",isec));
1149 Hits2DigitsSector(isec);
1152 AliDebug(1,Form("Hits2Digits","Sector %d is NOT active.",isec));
1155 fLoader->WriteDigits("OVERWRITE");
1157 //this line prevents the crash in the similar one
1158 //on the beginning of this method
1159 //destructor attempts to reset the tree, which is deleted by the loader
1160 //need to be redesign
1161 if(GetDigitsArray()) delete GetDigitsArray();
1162 SetDigitsArray(0x0);
1166 //__________________________________________________________________
1167 void AliTPC::Hits2SDigits2(Int_t eventnumber)
1170 //-----------------------------------------------------------
1171 // summable digits - 16 bit "ADC", no noise, no saturation
1172 //-----------------------------------------------------------
1174 //----------------------------------------------------
1175 // Loop over all sectors for a single event
1176 //----------------------------------------------------
1178 AliRunLoader* rl = fLoader->GetRunLoader();
1180 rl->GetEvent(eventnumber);
1181 if (fLoader->TreeH() == 0x0) {
1182 if(fLoader->LoadHits()) {
1183 AliError("Can not load hits.");
1190 if (fLoader->TreeS() == 0x0 ) {
1191 fLoader->MakeTree("S");
1194 if(fDefaults == 0) SetDefaults();
1196 GenerNoise(500000); //create table with noise
1197 //setup TPCDigitsArray
1199 if(GetDigitsArray()) delete GetDigitsArray();
1202 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1203 arr->SetClass("AliSimDigits");
1204 arr->Setup(fTPCParam);
1205 arr->MakeTree(fLoader->TreeS());
1207 SetDigitsArray(arr);
1209 fDigitsSwitch=1; // summable digits
1211 // set zero suppression to "0"
1213 fTPCParam->SetZeroSup(0);
1215 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1216 if (IsSectorActive(isec)) {
1217 Hits2DigitsSector(isec);
1220 fLoader->WriteSDigits("OVERWRITE");
1222 //this line prevents the crash in the similar one
1223 //on the beginning of this method
1224 //destructor attempts to reset the tree, which is deleted by the loader
1225 //need to be redesign
1226 if(GetDigitsArray()) delete GetDigitsArray();
1227 SetDigitsArray(0x0);
1229 //__________________________________________________________________
1231 void AliTPC::Hits2SDigits()
1234 //-----------------------------------------------------------
1235 // summable digits - 16 bit "ADC", no noise, no saturation
1236 //-----------------------------------------------------------
1238 fLoader->LoadHits("read");
1239 fLoader->LoadSDigits("recreate");
1240 AliRunLoader* runLoader = fLoader->GetRunLoader();
1242 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1243 runLoader->GetEvent(iEvent);
1246 Hits2SDigits2(iEvent);
1249 fLoader->UnloadHits();
1250 fLoader->UnloadSDigits();
1252 //_____________________________________________________________________________
1254 void AliTPC::Hits2DigitsSector(Int_t isec)
1256 //-------------------------------------------------------------------
1257 // TPC conversion from hits to digits.
1258 //-------------------------------------------------------------------
1260 //-----------------------------------------------------------------
1261 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1262 //-----------------------------------------------------------------
1264 //-------------------------------------------------------
1265 // Get the access to the track hits
1266 //-------------------------------------------------------
1268 // check if the parameters are set - important if one calls this method
1269 // directly, not from the Hits2Digits
1271 if(fDefaults == 0) SetDefaults();
1273 TTree *tH = TreeH(); // pointer to the hits tree
1275 AliFatal("Can not find TreeH in folder");
1279 Stat_t ntracks = tH->GetEntries();
1283 //-------------------------------------------
1284 // Only if there are any tracks...
1285 //-------------------------------------------
1289 Int_t nrows =fTPCParam->GetNRow(isec);
1291 row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1293 MakeSector(isec,nrows,tH,ntracks,row);
1295 //--------------------------------------------------------
1296 // Digitize this sector, row by row
1297 // row[i] is the pointer to the TObjArray of TVectors,
1298 // each one containing electrons accepted on this
1299 // row, assigned into tracks
1300 //--------------------------------------------------------
1304 if (fDigitsArray->GetTree()==0) {
1305 AliFatal("Tree not set in fDigitsArray");
1308 for (i=0;i<nrows;i++){
1310 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
1312 DigitizeRow(i,isec,row);
1314 fDigitsArray->StoreRow(isec,i);
1316 Int_t ndig = dig->GetDigitSize();
1319 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1322 fDigitsArray->ClearRow(isec,i);
1325 } // end of the sector digitization
1327 for(i=0;i<nrows+2;i++){
1332 delete [] row; // delete the array of pointers to TObjArray-s
1336 } // end of Hits2DigitsSector
1339 //_____________________________________________________________________________
1340 void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
1342 //-----------------------------------------------------------
1343 // Single row digitization, coupling from the neighbouring
1344 // rows taken into account
1345 //-----------------------------------------------------------
1347 //-----------------------------------------------------------------
1348 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1349 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
1350 //-----------------------------------------------------------------
1352 Float_t zerosup = fTPCParam->GetZeroSup();
1354 fCurrentIndex[1]= isec;
1357 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1358 Int_t nofTbins = fTPCParam->GetMaxTBin();
1359 Int_t indexRange[4];
1361 // Integrated signal for this row
1362 // and a single track signal
1365 TMatrix *m1 = new TMatrix(0,nofPads,0,nofTbins); // integrated
1366 TMatrix *m2 = new TMatrix(0,nofPads,0,nofTbins); // single
1368 TMatrix &total = *m1;
1370 // Array of pointers to the label-signal list
1372 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1373 Float_t **pList = new Float_t* [nofDigits];
1377 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
1383 for (Int_t row= row1;row<=row2;row++){
1384 Int_t nTracks= rows[row]->GetEntries();
1385 for (i1=0;i1<nTracks;i1++){
1386 fCurrentIndex[2]= row;
1387 fCurrentIndex[3]=irow+1;
1389 m2->Zero(); // clear single track signal matrix
1390 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1391 GetList(trackLabel,nofPads,m2,indexRange,pList);
1393 else GetSignal(rows[row],i1,0,m1,indexRange);
1399 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
1401 Float_t fzerosup = zerosup+0.5;
1402 for(Int_t it=0;it<nofTbins;it++){
1403 for(Int_t ip=0;ip<nofPads;ip++){
1405 Float_t q=total(ip,it);
1406 if(fDigitsSwitch == 0){
1408 if(q <=fzerosup) continue; // do not fill zeros
1410 if(q > fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat(); // saturation
1415 if(q <= 0.) continue; // do not fill zeros
1416 if(q>2000.) q=2000.;
1422 // "real" signal or electronic noise (list = -1)?
1425 for(Int_t j1=0;j1<3;j1++){
1426 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
1431 <A NAME="AliDigits"></A>
1432 using of AliDigits object
1435 dig->SetDigitFast((Short_t)q,it,ip);
1436 if (fDigitsArray->IsSimulated()) {
1437 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1438 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1439 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1442 } // end of loop over time buckets
1443 } // end of lop over pads
1446 // This row has been digitized, delete nonused stuff
1449 for(lp=0;lp<nofDigits;lp++){
1450 if(pList[lp]) delete [] pList[lp];
1458 } // end of DigitizeRow
1460 //_____________________________________________________________________________
1462 Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
1463 TMatrix *m1, TMatrix *m2,Int_t *indexRange)
1466 //---------------------------------------------------------------
1467 // Calculates 2-D signal (pad,time) for a single track,
1468 // returns a pointer to the signal matrix and the track label
1469 // No digitization is performed at this level!!!
1470 //---------------------------------------------------------------
1472 //-----------------------------------------------------------------
1473 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1474 // Modified: Marian Ivanov
1475 //-----------------------------------------------------------------
1479 tv = (TVector*)p1->At(ntr); // pointer to a track
1482 Float_t label = v(0);
1483 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1)-1)/2;
1485 Int_t nElectrons = (tv->GetNrows()-1)/4;
1486 indexRange[0]=9999; // min pad
1487 indexRange[1]=-1; // max pad
1488 indexRange[2]=9999; //min time
1489 indexRange[3]=-1; // max time
1491 TMatrix &signal = *m1;
1492 TMatrix &total = *m2;
1494 // Loop over all electrons
1496 for(Int_t nel=0; nel<nElectrons; nel++){
1498 Float_t aval = v(idx+4);
1499 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
1500 Float_t xyz[3]={v(idx+1),v(idx+2),v(idx+3)};
1501 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,fCurrentIndex[3]);
1503 Int_t *index = fTPCParam->GetResBin(0);
1504 Float_t *weight = & (fTPCParam->GetResWeight(0));
1506 if (n>0) for (Int_t i =0; i<n; i++){
1507 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
1510 Int_t time=index[2];
1511 Float_t qweight = *(weight)*eltoadcfac;
1513 if (m1!=0) signal(pad,time)+=qweight;
1514 total(pad,time)+=qweight;
1515 if (indexRange[0]>pad) indexRange[0]=pad;
1516 if (indexRange[1]<pad) indexRange[1]=pad;
1517 if (indexRange[2]>time) indexRange[2]=time;
1518 if (indexRange[3]<time) indexRange[3]=time;
1525 } // end of loop over electrons
1527 return label; // returns track label when finished
1530 //_____________________________________________________________________________
1531 void AliTPC::GetList(Float_t label,Int_t np,TMatrix *m,
1532 Int_t *indexRange, Float_t **pList)
1534 //----------------------------------------------------------------------
1535 // Updates the list of tracks contributing to digits for a given row
1536 //----------------------------------------------------------------------
1538 //-----------------------------------------------------------------
1539 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1540 //-----------------------------------------------------------------
1542 TMatrix &signal = *m;
1544 // lop over nonzero digits
1546 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1547 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
1550 // accept only the contribution larger than 500 electrons (1/2 s_noise)
1552 if(signal(ip,it)<0.5) continue;
1554 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
1556 if(!pList[globalIndex]){
1559 // Create new list (6 elements - 3 signals and 3 labels),
1562 pList[globalIndex] = new Float_t [6];
1566 *pList[globalIndex] = -1.;
1567 *(pList[globalIndex]+1) = -1.;
1568 *(pList[globalIndex]+2) = -1.;
1569 *(pList[globalIndex]+3) = -1.;
1570 *(pList[globalIndex]+4) = -1.;
1571 *(pList[globalIndex]+5) = -1.;
1573 *pList[globalIndex] = label;
1574 *(pList[globalIndex]+3) = signal(ip,it);
1578 // check the signal magnitude
1580 Float_t highest = *(pList[globalIndex]+3);
1581 Float_t middle = *(pList[globalIndex]+4);
1582 Float_t lowest = *(pList[globalIndex]+5);
1585 // compare the new signal with already existing list
1588 if(signal(ip,it)<lowest) continue; // neglect this track
1592 if (signal(ip,it)>highest){
1593 *(pList[globalIndex]+5) = middle;
1594 *(pList[globalIndex]+4) = highest;
1595 *(pList[globalIndex]+3) = signal(ip,it);
1597 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1598 *(pList[globalIndex]+1) = *pList[globalIndex];
1599 *pList[globalIndex] = label;
1601 else if (signal(ip,it)>middle){
1602 *(pList[globalIndex]+5) = middle;
1603 *(pList[globalIndex]+4) = signal(ip,it);
1605 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1606 *(pList[globalIndex]+1) = label;
1609 *(pList[globalIndex]+5) = signal(ip,it);
1610 *(pList[globalIndex]+2) = label;
1614 } // end of loop over pads
1615 } // end of loop over time bins
1618 //___________________________________________________________________
1619 void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1620 Stat_t ntracks,TObjArray **row)
1623 //-----------------------------------------------------------------
1624 // Prepares the sector digitization, creates the vectors of
1625 // tracks for each row of this sector. The track vector
1626 // contains the track label and the position of electrons.
1627 //-----------------------------------------------------------------
1629 //-----------------------------------------------------------------
1630 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1631 //-----------------------------------------------------------------
1633 Float_t gasgain = fTPCParam->GetGasGain();
1637 AliTPChit *tpcHit; // pointer to a sigle TPC hit
1640 if (fHitType>1) branch = TH->GetBranch("TPC2");
1641 else branch = TH->GetBranch("TPC");
1644 //----------------------------------------------
1645 // Create TObjArray-s, one for each row,
1646 // each TObjArray will store the TVectors
1647 // of electrons, one TVectors per each track.
1648 //----------------------------------------------
1650 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
1651 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
1653 for(i=0; i<nrows+2; i++){
1654 row[i] = new TObjArray;
1661 //--------------------------------------------------------------------
1662 // Loop over tracks, the "track" contains the full history
1663 //--------------------------------------------------------------------
1665 Int_t previousTrack,currentTrack;
1666 previousTrack = -1; // nothing to store so far!
1668 for(Int_t track=0;track<ntracks;track++){
1669 Bool_t isInSector=kTRUE;
1671 isInSector = TrackInVolume(isec,track);
1672 if (!isInSector) continue;
1674 branch->GetEntry(track); // get next track
1678 tpcHit = (AliTPChit*)FirstHit(-1);
1680 //--------------------------------------------------------------
1682 //--------------------------------------------------------------
1687 Int_t sector=tpcHit->fSector; // sector number
1689 tpcHit = (AliTPChit*) NextHit();
1693 currentTrack = tpcHit->Track(); // track number
1695 if(currentTrack != previousTrack){
1697 // store already filled fTrack
1699 for(i=0;i<nrows+2;i++){
1700 if(previousTrack != -1){
1701 if(nofElectrons[i]>0){
1702 TVector &v = *tracks[i];
1703 v(0) = previousTrack;
1704 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1705 row[i]->Add(tracks[i]);
1708 delete tracks[i]; // delete empty TVector
1714 tracks[i] = new TVector(481); // TVectors for the next fTrack
1716 } // end of loop over rows
1718 previousTrack=currentTrack; // update track label
1721 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
1723 //---------------------------------------------------
1724 // Calculate the electron attachment probability
1725 //---------------------------------------------------
1728 Float_t time = 1.e6*(fTPCParam->GetZLength()-TMath::Abs(tpcHit->Z()))
1729 /fTPCParam->GetDriftV();
1731 Float_t attProb = fTPCParam->GetAttCoef()*
1732 fTPCParam->GetOxyCont()*time; // fraction!
1734 //-----------------------------------------------
1735 // Loop over electrons
1736 //-----------------------------------------------
1739 for(Int_t nel=0;nel<qI;nel++){
1740 // skip if electron lost due to the attachment
1741 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
1746 // protection for the nonphysical avalanche size (10**6 maximum)
1748 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
1749 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
1752 TransportElectron(xyz,index);
1754 fTPCParam->GetPadRow(xyz,index);
1755 // row 0 - cross talk from the innermost row
1756 // row fNRow+1 cross talk from the outermost row
1757 rowNumber = index[2]+1;
1758 //transform position to local digit coordinates
1759 //relative to nearest pad row
1760 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
1762 if (isec <fTPCParam->GetNInnerSector()) {
1763 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
1764 y1 = fTPCParam->GetYInner(rowNumber);
1767 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
1768 y1 = fTPCParam->GetYOuter(rowNumber);
1770 // gain inefficiency at the wires edges - linear
1773 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.));
1775 nofElectrons[rowNumber]++;
1776 //----------------------------------
1777 // Expand vector if necessary
1778 //----------------------------------
1779 if(nofElectrons[rowNumber]>120){
1780 Int_t range = tracks[rowNumber]->GetNrows();
1781 if((nofElectrons[rowNumber])>(range-1)/4){
1783 tracks[rowNumber]->ResizeTo(range+400); // Add 100 electrons
1787 TVector &v = *tracks[rowNumber];
1788 Int_t idx = 4*nofElectrons[rowNumber]-3;
1789 Real_t * position = &(((TVector&)v)(idx)); //make code faster
1790 memcpy(position,xyz,4*sizeof(Float_t));
1792 } // end of loop over electrons
1794 tpcHit = (AliTPChit*)NextHit();
1796 } // end of loop over hits
1797 } // end of loop over tracks
1800 // store remaining track (the last one) if not empty
1803 for(i=0;i<nrows+2;i++){
1804 if(nofElectrons[i]>0){
1805 TVector &v = *tracks[i];
1806 v(0) = previousTrack;
1807 tracks[i]->ResizeTo(4*nofElectrons[i]+1); // shrink if necessary
1808 row[i]->Add(tracks[i]);
1817 delete [] nofElectrons;
1819 } // end of MakeSector
1822 //_____________________________________________________________________________
1826 // Initialise TPC detector after definition of geometry
1828 AliDebug(1,"*********************************************");
1831 //_____________________________________________________________________________
1832 void AliTPC::MakeBranch(Option_t* option)
1835 // Create Tree branches for the TPC.
1838 Int_t buffersize = 4000;
1839 char branchname[10];
1840 sprintf(branchname,"%s",GetName());
1842 const char *h = strstr(option,"H");
1844 if ( h && (fHitType<=1) && (fHits == 0x0)) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
1846 AliDetector::MakeBranch(option);
1848 const char *d = strstr(option,"D");
1850 if (fDigits && fLoader->TreeD() && d) {
1851 MakeBranchInTree(gAlice->TreeD(), branchname, &fDigits, buffersize, 0);
1854 if (fHitType>1) MakeBranch2(option,0); // MI change 14.09.2000
1857 //_____________________________________________________________________________
1858 void AliTPC::ResetDigits()
1861 // Reset number of digits and the digits array for this detector
1864 if (fDigits) fDigits->Clear();
1867 //_____________________________________________________________________________
1868 void AliTPC::SetSecAL(Int_t sec)
1870 //---------------------------------------------------
1871 // Activate/deactivate selection for lower sectors
1872 //---------------------------------------------------
1874 //-----------------------------------------------------------------
1875 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1876 //-----------------------------------------------------------------
1880 //_____________________________________________________________________________
1881 void AliTPC::SetSecAU(Int_t sec)
1883 //----------------------------------------------------
1884 // Activate/deactivate selection for upper sectors
1885 //---------------------------------------------------
1887 //-----------------------------------------------------------------
1888 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1889 //-----------------------------------------------------------------
1893 //_____________________________________________________________________________
1894 void AliTPC::SetSecLows(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6)
1896 //----------------------------------------
1897 // Select active lower sectors
1898 //----------------------------------------
1900 //-----------------------------------------------------------------
1901 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1902 //-----------------------------------------------------------------
1912 //_____________________________________________________________________________
1913 void AliTPC::SetSecUps(Int_t s1,Int_t s2,Int_t s3,Int_t s4,Int_t s5, Int_t s6,
1914 Int_t s7, Int_t s8 ,Int_t s9 ,Int_t s10,
1915 Int_t s11 , Int_t s12)
1917 //--------------------------------
1918 // Select active upper sectors
1919 //--------------------------------
1921 //-----------------------------------------------------------------
1922 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1923 //-----------------------------------------------------------------
1939 //_____________________________________________________________________________
1940 void AliTPC::SetSens(Int_t sens)
1943 //-------------------------------------------------------------
1944 // Activates/deactivates the sensitive strips at the center of
1945 // the pad row -- this is for the space-point resolution calculations
1946 //-------------------------------------------------------------
1948 //-----------------------------------------------------------------
1949 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1950 //-----------------------------------------------------------------
1956 void AliTPC::SetSide(Float_t side=0.)
1958 // choice of the TPC side
1963 //____________________________________________________________________________
1964 void AliTPC::SetGasMixt(Int_t nc,Int_t c1,Int_t c2,Int_t c3,Float_t p1,
1965 Float_t p2,Float_t p3)
1968 // gax mixture definition
1980 //_____________________________________________________________________________
1982 void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
1985 // electron transport taking into account:
1987 // 2.ExB at the wires
1988 // 3. nonisochronity
1990 // xyz and index must be already transformed to system 1
1993 fTPCParam->Transform1to2(xyz,index);
1996 Float_t driftl=xyz[2];
1997 if(driftl<0.01) driftl=0.01;
1998 driftl=TMath::Sqrt(driftl);
1999 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2000 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2001 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2002 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2003 xyz[2]=gRandom->Gaus(xyz[2],sigL);
2007 if (fTPCParam->GetMWPCReadout()==kTRUE){
2008 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
2009 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2011 //add nonisochronity (not implemented yet)
2016 //_____________________________________________________________________________
2017 AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
2021 // Creates a TPC hit object
2031 //________________________________________________________________________
2032 // Additional code because of the AliTPCTrackHitsV2
2034 void AliTPC::MakeBranch2(Option_t *option,const char */*file*/)
2037 // Create a new branch in the current Root Tree
2038 // The branch of fHits is automatically split
2039 // MI change 14.09.2000
2041 if (fHitType<2) return;
2042 char branchname[10];
2043 sprintf(branchname,"%s2",GetName());
2045 // Get the pointer to the header
2046 const char *cH = strstr(option,"H");
2048 if (fTrackHits && TreeH() && cH && fHitType&4) {
2049 AliDebug(1,"Making branch for Type 4 Hits");
2050 TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
2053 if (fTrackHitsOld && TreeH() && cH && fHitType&2) {
2054 AliDebug(1,"Making branch for Type 2 Hits");
2055 AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
2056 TreeH(),fBufferSize,99);
2057 TreeH()->GetListOfBranches()->Add(branch);
2061 void AliTPC::SetTreeAddress()
2063 //Sets tree address for hits
2065 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2066 AliDetector::SetTreeAddress();
2068 if (fHitType>1) SetTreeAddress2();
2071 void AliTPC::SetTreeAddress2()
2074 // Set branch address for the TrackHits Tree
2079 char branchname[20];
2080 sprintf(branchname,"%s2",GetName());
2082 // Branch address for hit tree
2083 TTree *treeH = TreeH();
2084 if ((treeH)&&(fHitType&4)) {
2085 branch = treeH->GetBranch(branchname);
2087 branch->SetAddress(&fTrackHits);
2088 AliDebug(1,"fHitType&4 Setting");
2091 AliDebug(1,"fHitType&4 Failed (can not find branch)");
2094 if ((treeH)&&(fHitType&2)) {
2095 branch = treeH->GetBranch(branchname);
2097 branch->SetAddress(&fTrackHitsOld);
2098 AliDebug(1,"fHitType&2 Setting");
2101 AliDebug(1,"fHitType&2 Failed (can not find branch)");
2103 //set address to TREETR
2105 TTree *treeTR = TreeTR();
2106 if (treeTR && fTrackReferences) {
2107 branch = treeTR->GetBranch(GetName());
2108 if (branch) branch->SetAddress(&fTrackReferences);
2113 void AliTPC::FinishPrimary()
2115 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
2116 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
2120 void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2123 // add hit to the list
2126 int primary = gAlice->GetMCApp()->GetPrimary(track);
2127 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
2131 gAlice->GetMCApp()->FlagTrack(track);
2133 if (fTrackHits && fHitType&4)
2134 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
2135 hits[1],hits[2],(Int_t)hits[3]);
2136 if (fTrackHitsOld &&fHitType&2 )
2137 fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2138 hits[1],hits[2],(Int_t)hits[3]);
2142 void AliTPC::ResetHits()
2144 if (fHitType&1) AliDetector::ResetHits();
2145 if (fHitType>1) ResetHits2();
2148 void AliTPC::ResetHits2()
2152 if (fTrackHits && fHitType&4) fTrackHits->Clear();
2153 if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
2157 AliHit* AliTPC::FirstHit(Int_t track)
2159 if (fHitType>1) return FirstHit2(track);
2160 return AliDetector::FirstHit(track);
2162 AliHit* AliTPC::NextHit()
2167 if (fHitType>1) return NextHit2();
2169 return AliDetector::NextHit();
2172 AliHit* AliTPC::FirstHit2(Int_t track)
2175 // Initialise the hit iterator
2176 // Return the address of the first hit for track
2177 // If track>=0 the track is read from disk
2178 // while if track<0 the first hit of the current
2179 // track is returned
2182 gAlice->ResetHits();
2183 TreeH()->GetEvent(track);
2186 if (fTrackHits && fHitType&4) {
2187 fTrackHits->First();
2188 return fTrackHits->GetHit();
2190 if (fTrackHitsOld && fHitType&2) {
2191 fTrackHitsOld->First();
2192 return fTrackHitsOld->GetHit();
2198 AliHit* AliTPC::NextHit2()
2201 //Return the next hit for the current track
2204 if (fTrackHitsOld && fHitType&2) {
2205 fTrackHitsOld->Next();
2206 return fTrackHitsOld->GetHit();
2210 return fTrackHits->GetHit();
2216 void AliTPC::LoadPoints(Int_t)
2221 if(fHitType==1) AliDetector::LoadPoints(a);
2222 else LoadPoints2(a);
2226 void AliTPC::RemapTrackHitIDs(Int_t *map)
2231 if (!fTrackHits) return;
2233 if (fTrackHitsOld && fHitType&2){
2234 AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2235 for (UInt_t i=0;i<arr->GetSize();i++){
2236 AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2237 info->fTrackID = map[info->fTrackID];
2240 if (fTrackHitsOld && fHitType&4){
2241 TClonesArray * arr = fTrackHits->GetArray();;
2242 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2243 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
2244 info->fTrackID = map[info->fTrackID];
2249 Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2251 //return bool information - is track in given volume
2252 //load only part of the track information
2253 //return true if current track is in volume
2256 if (fTrackHitsOld && fHitType&2) {
2257 TBranch * br = TreeH()->GetBranch("fTrackHitsInfo");
2258 br->GetEvent(track);
2259 AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2260 for (UInt_t j=0;j<ar->GetSize();j++){
2261 if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2265 if (fTrackHits && fHitType&4) {
2266 TBranch * br1 = TreeH()->GetBranch("fVolumes");
2267 TBranch * br2 = TreeH()->GetBranch("fNVolumes");
2268 br2->GetEvent(track);
2269 br1->GetEvent(track);
2270 Int_t *volumes = fTrackHits->GetVolumes();
2271 Int_t nvolumes = fTrackHits->GetNVolumes();
2272 if (!volumes && nvolumes>0) {
2273 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
2276 for (Int_t j=0;j<nvolumes; j++)
2277 if (volumes[j]==id) return kTRUE;
2281 TBranch * br = TreeH()->GetBranch("fSector");
2282 br->GetEvent(track);
2283 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2284 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2291 //_____________________________________________________________________________
2292 void AliTPC::LoadPoints2(Int_t)
2295 // Store x, y, z of all hits in memory
2297 if (fTrackHits == 0 && fTrackHitsOld==0) return;
2300 if (fHitType&4) nhits = fTrackHits->GetEntriesFast();
2301 if (fHitType&2) nhits = fTrackHitsOld->GetEntriesFast();
2303 if (nhits == 0) return;
2304 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2305 if (fPoints == 0) fPoints = new TObjArray(tracks);
2308 Int_t *ntrk=new Int_t[tracks];
2309 Int_t *limi=new Int_t[tracks];
2310 Float_t **coor=new Float_t*[tracks];
2311 for(Int_t i=0;i<tracks;i++) {
2317 AliPoints *points = 0;
2320 Int_t chunk=nhits/4+1;
2322 // Loop over all the hits and store their position
2324 ahit = FirstHit2(-1);
2326 trk=ahit->GetTrack();
2327 if(ntrk[trk]==limi[trk]) {
2329 // Initialise a new track
2330 fp=new Float_t[3*(limi[trk]+chunk)];
2332 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2333 delete [] coor[trk];
2340 fp[3*ntrk[trk] ] = ahit->X();
2341 fp[3*ntrk[trk]+1] = ahit->Y();
2342 fp[3*ntrk[trk]+2] = ahit->Z();
2350 for(trk=0; trk<tracks; ++trk) {
2352 points = new AliPoints();
2353 points->SetMarkerColor(GetMarkerColor());
2354 points->SetMarkerSize(GetMarkerSize());
2355 points->SetDetector(this);
2356 points->SetParticle(trk);
2357 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
2358 fPoints->AddAt(points,trk);
2359 delete [] coor[trk];
2369 //_____________________________________________________________________________
2370 void AliTPC::LoadPoints3(Int_t)
2373 // Store x, y, z of all hits in memory
2374 // - only intersection point with pad row
2375 if (fTrackHits == 0) return;
2377 Int_t nhits = fTrackHits->GetEntriesFast();
2378 if (nhits == 0) return;
2379 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
2380 if (fPoints == 0) fPoints = new TObjArray(2*tracks);
2381 fPoints->Expand(2*tracks);
2384 Int_t *ntrk=new Int_t[tracks];
2385 Int_t *limi=new Int_t[tracks];
2386 Float_t **coor=new Float_t*[tracks];
2387 for(Int_t i=0;i<tracks;i++) {
2393 AliPoints *points = 0;
2396 Int_t chunk=nhits/4+1;
2398 // Loop over all the hits and store their position
2400 ahit = FirstHit2(-1);
2404 trk=ahit->GetTrack();
2405 Float_t x[3]={ahit->X(),ahit->Y(),ahit->Z()};
2406 Int_t index[3]={1,((AliTPChit*)ahit)->fSector,0};
2407 Int_t currentrow = fTPCParam->GetPadRow(x,index) ;
2408 if (currentrow!=lastrow){
2409 lastrow = currentrow;
2410 //later calculate intersection point
2411 if(ntrk[trk]==limi[trk]) {
2413 // Initialise a new track
2414 fp=new Float_t[3*(limi[trk]+chunk)];
2416 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
2417 delete [] coor[trk];
2424 fp[3*ntrk[trk] ] = ahit->X();
2425 fp[3*ntrk[trk]+1] = ahit->Y();
2426 fp[3*ntrk[trk]+2] = ahit->Z();
2433 for(trk=0; trk<tracks; ++trk) {
2435 points = new AliPoints();
2436 points->SetMarkerColor(GetMarkerColor()+1);
2437 points->SetMarkerStyle(5);
2438 points->SetMarkerSize(0.2);
2439 points->SetDetector(this);
2440 points->SetParticle(trk);
2441 points->SetPolyMarker(ntrk[trk],coor[trk],30);
2442 fPoints->AddAt(points,tracks+trk);
2443 delete [] coor[trk];
2454 AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2457 fLoader = new AliTPCLoader(GetName(),topfoldername);
2461 ////////////////////////////////////////////////////////////////////////
2462 AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2464 // load TPC paarmeters from a given file or create new if the object
2465 // is not found there
2466 // 12/05/2003 This method should be moved to the AliTPCLoader
2467 // and one has to decide where to store the TPC parameters
2470 sprintf(paramName,"75x40_100x60_150x60");
2471 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2473 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
2475 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
2476 paramTPC = new AliTPCParamSR;
2480 // the older version of parameters can be accessed with this code.
2481 // In some cases, we have old parameters saved in the file but
2482 // digits were created with new parameters, it can be distinguish
2483 // by the name of TPC TreeD. The code here is just for the case
2484 // we would need to compare with old data, uncomment it if needed.
2486 // char paramName[50];
2487 // sprintf(paramName,"75x40_100x60");
2488 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2490 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2492 // sprintf(paramName,"75x40_100x60_150x60");
2493 // paramTPC=(AliTPCParam*)in->Get(paramName);
2495 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
2497 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2499 // paramTPC = new AliTPCParamSR;