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 // fast TPC cluster simulation //
22 ///////////////////////////////////////////////////////////////////////////////
24 #include <TParticle.h>
27 #include "AliRunLoader.h"
31 #include "AliTPCParam.h"
32 #include "AliTPCClustersArray.h"
33 #include "AliTPCClustersRow.h"
34 #include "AliTPCcluster.h"
35 #include "AliComplexCluster.h"
36 #include "AliTPCFast.h"
42 //_____________________________________________________________________________
43 void AliTPCFast::Hits2Clusters(AliRunLoader* runLoader) const
45 //--------------------------------------------------------
46 // TPC simple cluster generator from hits
47 // obtained from the TPC Fast Simulator
48 // The point errors are taken from the parametrization
49 //--------------------------------------------------------
51 //-----------------------------------------------------------------
52 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
53 //-----------------------------------------------------------------
54 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
55 // Jouri.Belikov@cern.ch
56 //----------------------------------------------------------------
58 /////////////////////////////////////////////////////////////////////////////
60 //---------------------------------------------------------------------
61 // ALICE TPC Cluster Parameters
62 //--------------------------------------------------------------------
66 // Cluster width in rphi
67 const Float_t kACrphi=0.18322;
68 const Float_t kBCrphi=0.59551e-3;
69 const Float_t kCCrphi=0.60952e-1;
71 const Float_t kACz=0.19081;
72 const Float_t kBCz=0.55938e-3;
73 const Float_t kCCz=0.30428;
76 AliLoader* loader = runLoader->GetLoader("TPCLoader");
78 AliError("No TPC loader found");
81 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
82 AliRun* aliRun = runLoader->GetAliRun();
84 AliError("Couldn't get AliRun object");
87 AliTPC* tpc = (AliTPC*) aliRun->GetDetector("TPC");
89 AliError("Couldn't get TPC detector");
92 AliTPCParam* param = tpc->GetParam();
94 AliError("No TPC parameters available");
98 //if(fDefaults == 0) SetDefaults();
100 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
102 TParticle *particle; // pointer to a given particle
103 AliTPChit *tpcHit; // pointer to a sigle TPC hit
107 Float_t pl,pt,tanth,rpad,ratio;
110 //---------------------------------------------------------------
111 // Get the access to the tracks
112 //---------------------------------------------------------------
114 TTree *tH = loader->TreeH();
116 AliFatal("Can not find TreeH in folder");
118 tpc->SetTreeAddress();
120 Stat_t ntracks = tH->GetEntries();
122 //Switch to the output file
124 if (loader->TreeR() == 0x0) loader->MakeTree("R");
126 AliDebug(1,Form("param->GetTitle() = %s",param->GetTitle()));
128 runLoader->CdGAFile();
129 //param->Write(param->GetTitle());
131 AliTPCClustersArray carray;
133 carray.SetClusterType("AliTPCcluster");
134 carray.MakeTree(loader->TreeR());
136 Int_t nclusters=0; //cluster counter
138 //------------------------------------------------------------
139 // Loop over all sectors (72 sectors for 20 deg
140 // segmentation for both lower and upper sectors)
141 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
142 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
144 // First cluster for sector 0 starts at "0"
145 //------------------------------------------------------------
147 for(Int_t isec=0;isec<param->GetNSector();isec++){
149 param->AdjustCosSin(isec,cph,sph);
151 //------------------------------------------------------------
153 //------------------------------------------------------------
155 for(Int_t track=0;track<ntracks;track++){
159 // Get number of the TPC hits
161 tpcHit = (AliTPChit*)tpc->FirstHit(-1);
167 if (tpcHit->fQ == 0.) {
168 tpcHit = (AliTPChit*) tpc->NextHit();
169 continue; //information about track (I.Belikov)
171 sector=tpcHit->fSector; // sector number
174 tpcHit = (AliTPChit*) tpc->NextHit();
177 ipart=tpcHit->Track();
178 particle=aliRun->GetMCApp()->Particle(ipart);
181 if(pt < 1.e-9) pt=1.e-9;
183 tanth = TMath::Abs(tanth);
184 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
185 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
187 // space-point resolutions
189 sigmaRphi=AliTPCcluster::SigmaY2(rpad,tanth,pt);
190 sigmaZ =AliTPCcluster::SigmaZ2(rpad,tanth );
194 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
195 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
197 // temporary protection
199 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
200 if(sigmaZ < 0.) sigmaZ=0.4e-3;
201 if(clRphi < 0.) clRphi=2.5e-3;
202 if(clZ < 0.) clZ=2.5e-5;
207 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
208 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
210 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
211 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
212 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
213 Float_t alpha=(isec < param->GetNInnerSector()) ?
214 param->GetInnerAngle() : param->GetOuterAngle();
215 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
216 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
217 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
218 if (TMath::Abs(xyz[1])>param->GetZLength()) xyz[1]=tpcHit->Z();
219 xyz[2]=sigmaRphi; // fSigmaY2
220 xyz[3]=sigmaZ; // fSigmaZ2
221 xyz[4]=tpcHit->fQ; // q
223 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
224 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
226 Int_t tracks[3]={tpcHit->Track(), -1, -1};
227 AliTPCcluster cluster(tracks,xyz);
229 clrow->InsertCluster(&cluster); nclusters++;
231 tpcHit = (AliTPChit*)tpc->NextHit();
234 } // end of loop over hits
236 } // end of loop over tracks
238 Int_t nrows=param->GetNRow(isec);
239 for (Int_t irow=0; irow<nrows; irow++) {
240 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
241 if (!clrow) continue;
242 carray.StoreRow(isec,irow);
243 carray.ClearRow(isec,irow);
246 } // end of loop over sectors
248 // cerr<<"Number of made clusters : "<<nclusters<<" \n";
249 loader->WriteRecPoints("OVERWRITE");
254 //_________________________________________________________________
255 void AliTPCFast::Hits2ExactClustersSector(AliRunLoader* runLoader,
256 AliTPCClustersArray* clustersArray,
259 //--------------------------------------------------------
260 //calculate exact cross point of track and given pad row
261 //resulting values are expressed in "digit" coordinata
262 //--------------------------------------------------------
264 //-----------------------------------------------------------------
265 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
266 //-----------------------------------------------------------------
268 if (clustersArray==0){
271 AliLoader* loader = runLoader->GetLoader("TPCLoader");
273 AliError("No TPC loader found");
276 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
277 AliRun* aliRun = runLoader->GetAliRun();
279 AliError("Couldn't get AliRun object");
282 AliTPC* tpc = (AliTPC*) aliRun->GetDetector("TPC");
284 AliError("Couldn't get TPC detector");
287 AliTPCParam* param = tpc->GetParam();
289 AliError("No TPC parameters available");
293 TParticle *particle; // pointer to a given particle
294 AliTPChit *tpcHit; // pointer to a sigle TPC hit
295 // Int_t sector,nhits;
297 const Int_t kcmaxhits=30000;
298 TVector * xxxx = new TVector(kcmaxhits*4);
299 TVector & xxx = *xxxx;
300 Int_t maxhits = kcmaxhits;
301 //construct array for each padrow
302 for (Int_t i=0; i<param->GetNRow(isec);i++)
303 clustersArray->CreateRow(isec,i);
305 //---------------------------------------------------------------
306 // Get the access to the tracks
307 //---------------------------------------------------------------
309 TTree *tH = loader->TreeH();
311 AliFatal("Can not find TreeH in folder");
313 tpc->SetTreeAddress();
315 Stat_t ntracks = tH->GetEntries();
316 Int_t npart = aliRun->GetMCApp()->GetNtrack();
319 if (tpc->GetHitType()>1) branch = tH->GetBranch("TPC2");
320 else branch = tH->GetBranch("TPC");
322 //------------------------------------------------------------
324 //------------------------------------------------------------
326 for(Int_t track=0;track<ntracks;track++){
327 Bool_t isInSector=kTRUE;
329 isInSector = tpc->TrackInVolume(isec,track);
330 if (!isInSector) continue;
332 branch->GetEntry(track); // get next track
334 // Get number of the TPC hits and a pointer
338 Int_t currentIndex=0;
339 Int_t lastrow=-1; //last writen row
343 tpcHit = (AliTPChit*)tpc->FirstHit(-1);
346 Int_t sector=tpcHit->fSector; // sector number
348 tpcHit = (AliTPChit*) tpc->NextHit();
352 ipart=tpcHit->Track();
353 if (ipart<npart) particle=aliRun->GetMCApp()->Particle(ipart);
357 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
358 Int_t index[3]={1,isec,0};
359 Int_t currentrow = param->GetPadRow(x,index) ;
360 if (currentrow<0) {tpcHit = (AliTPChit*)tpc->NextHit(); continue;}
361 if (lastrow<0) lastrow=currentrow;
362 if (currentrow==lastrow){
363 if ( currentIndex>=maxhits){
365 xxx.ResizeTo(4*maxhits);
367 xxx(currentIndex*4)=x[0];
368 xxx(currentIndex*4+1)=x[1];
369 xxx(currentIndex*4+2)=x[2];
370 xxx(currentIndex*4+3)=tpcHit->fQ;
386 for (Int_t index=0;index<currentIndex;index++){
388 x=x2=x3=x4=xxx(index*4);
396 sumy+=xxx(index*4+1);
397 sumxy+=xxx(index*4+1)*x;
398 sumx2y+=xxx(index*4+1)*x2;
399 sumz+=xxx(index*4+2);
400 sumxz+=xxx(index*4+2)*x;
401 sumx2z+=xxx(index*4+2)*x2;
402 sumq+=xxx(index*4+3);
404 Float_t centralPad = (param->GetNPads(isec,lastrow)-1)/2;
405 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
406 sumx2*(sumx*sumx3-sumx2*sumx2);
408 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
409 sumx2*(sumxy*sumx3-sumx2y*sumx2);
410 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
411 sumx2*(sumxz*sumx3-sumx2z*sumx2);
413 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
414 sumx2*(sumx*sumx2y-sumx2*sumxy);
415 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
416 sumx2*(sumx*sumx2z-sumx2*sumxz);
418 if (TMath::Abs(det)<0.00001){
419 tpcHit = (AliTPChit*)tpc->NextHit();
423 Float_t y=detay/det+centralPad;
425 Float_t by=detby/det; //y angle
426 Float_t bz=detbz/det; //z angle
427 sumy/=Float_t(currentIndex);
428 sumz/=Float_t(currentIndex);
430 AliTPCClustersRow * row = (clustersArray->GetRow(isec,lastrow));
432 AliComplexCluster* cl = new((AliComplexCluster*)row->Append()) AliComplexCluster ;
433 // AliComplexCluster cl;
439 cl->fTracks[0]=ipart;
443 } //end of calculating cluster for given row
446 tpcHit = (AliTPChit*)tpc->NextHit();
447 } // end of loop over hits
448 } // end of loop over tracks
449 //write padrows to tree
450 for (Int_t ii=0; ii<param->GetNRow(isec);ii++) {
451 clustersArray->StoreRow(isec,ii);
452 clustersArray->ClearRow(isec,ii);
459 void AliTPCFast::FindTrackHitsIntersection(AliRunLoader* runLoader,
460 AliTPCClustersArray* clustersArray) const
464 //fill clones array with intersection of current point with the
466 AliLoader* loader = runLoader->GetLoader("TPCLoader");
468 AliError("No TPC loader found");
471 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
472 AliRun* aliRun = runLoader->GetAliRun();
474 AliError("Couldn't get AliRun object");
477 AliTPC* tpc = (AliTPC*) aliRun->GetDetector("TPC");
479 AliError("Couldn't get TPC detector");
482 AliTPCParam* param = tpc->GetParam();
484 AliError("No TPC parameters available");
491 const Int_t kcmaxhits=30000;
492 TVector * xxxx = new TVector(kcmaxhits*4);
493 TVector & xxx = *xxxx;
494 Int_t maxhits = kcmaxhits;
497 AliTPChit * tpcHit=0;
498 tpcHit = (AliTPChit*)tpc->FirstHit2(-1);
499 Int_t currentIndex=0;
500 Int_t lastrow=-1; //last writen row
503 if (tpcHit==0) continue;
504 sector=tpcHit->fSector; // sector number
505 ipart=tpcHit->Track();
509 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
510 Int_t index[3]={1,sector,0};
511 Int_t currentrow = param->GetPadRow(x,index) ;
512 if (currentrow<0) continue;
513 if (lastrow<0) lastrow=currentrow;
514 if (currentrow==lastrow){
515 if ( currentIndex>=maxhits){
517 xxx.ResizeTo(4*maxhits);
519 xxx(currentIndex*4)=x[0];
520 xxx(currentIndex*4+1)=x[1];
521 xxx(currentIndex*4+2)=x[2];
522 xxx(currentIndex*4+3)=tpcHit->fQ;
538 for (Int_t index=0;index<currentIndex;index++){
540 x=x2=x3=x4=xxx(index*4);
548 sumy+=xxx(index*4+1);
549 sumxy+=xxx(index*4+1)*x;
550 sumx2y+=xxx(index*4+1)*x2;
551 sumz+=xxx(index*4+2);
552 sumxz+=xxx(index*4+2)*x;
553 sumx2z+=xxx(index*4+2)*x2;
554 sumq+=xxx(index*4+3);
556 Float_t centralPad = (param->GetNPads(sector,lastrow)-1)/2;
557 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
558 sumx2*(sumx*sumx3-sumx2*sumx2);
560 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
561 sumx2*(sumxy*sumx3-sumx2y*sumx2);
562 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
563 sumx2*(sumxz*sumx3-sumx2z*sumx2);
565 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
566 sumx2*(sumx*sumx2y-sumx2*sumxy);
567 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
568 sumx2*(sumx*sumx2z-sumx2*sumxz);
570 Float_t y=detay/det+centralPad;
572 Float_t by=detby/det; //y angle
573 Float_t bz=detbz/det; //z angle
574 sumy/=Float_t(currentIndex);
575 sumz/=Float_t(currentIndex);
577 AliComplexCluster cl;
585 AliTPCClustersRow * row = (clustersArray->GetRow(sector,lastrow));
586 if (row!=0) row->InsertCluster(&cl);
589 } //end of calculating cluster for given row
591 } // end of loop over hits