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>
29 #include "AliRunLoader.h"
30 #include "AliLoader.h"
34 #include "AliTPCParam.h"
35 #include "AliTPCClustersArray.h"
36 #include "AliTPCClustersRow.h"
37 #include "AliTPCcluster.h"
38 #include "AliComplexCluster.h"
39 #include "AliTPCFast.h"
43 //____________________________________________________________________
44 AliTPCFast::AliTPCFast(const AliTPCFast ¶m)
45 :TObject(param),fParam(0)
49 // copy constructor - dummy
51 fParam = param.fParam;
53 AliTPCFast & AliTPCFast::operator =(const AliTPCFast & param)
56 // assignment operator - dummy
62 //_____________________________________________________________________________
63 void AliTPCFast::Hits2Clusters(AliRunLoader* runLoader) const
65 //--------------------------------------------------------
66 // TPC simple cluster generator from hits
67 // obtained from the TPC Fast Simulator
68 // The point errors are taken from the parametrization
69 //--------------------------------------------------------
71 //-----------------------------------------------------------------
72 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
73 //-----------------------------------------------------------------
74 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
75 // Jouri.Belikov@cern.ch
76 //----------------------------------------------------------------
78 /////////////////////////////////////////////////////////////////////////////
80 //---------------------------------------------------------------------
81 // ALICE TPC Cluster Parameters
82 //--------------------------------------------------------------------
86 // Cluster width in rphi
87 const Float_t kACrphi=0.18322;
88 const Float_t kBCrphi=0.59551e-3;
89 const Float_t kCCrphi=0.60952e-1;
91 const Float_t kACz=0.19081;
92 const Float_t kBCz=0.55938e-3;
93 const Float_t kCCz=0.30428;
96 AliLoader* loader = runLoader->GetLoader("TPCLoader");
98 AliError("No TPC loader found");
101 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
102 AliRun* aliRun = runLoader->GetAliRun();
104 AliError("Couldn't get AliRun object");
107 AliTPC* tpc = (AliTPC*) aliRun->GetDetector("TPC");
109 AliError("Couldn't get TPC detector");
112 AliTPCParam* param = tpc->GetParam();
114 AliError("No TPC parameters available");
118 //if(fDefaults == 0) SetDefaults();
120 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
122 TParticle *particle; // pointer to a given particle
123 AliTPChit *tpcHit; // pointer to a sigle TPC hit
127 Float_t pl,pt,tanth,rpad,ratio;
130 //---------------------------------------------------------------
131 // Get the access to the tracks
132 //---------------------------------------------------------------
134 TTree *tH = loader->TreeH();
136 AliFatal("Can not find TreeH in folder");
139 tpc->SetTreeAddress();
141 Stat_t ntracks = tH->GetEntries();
143 //Switch to the output file
145 if (loader->TreeR() == 0x0) loader->MakeTree("R");
147 AliDebug(1,Form("param->GetTitle() = %s",param->GetTitle()));
149 runLoader->CdGAFile();
150 //param->Write(param->GetTitle());
152 AliTPCClustersArray carray;
154 carray.SetClusterType("AliTPCcluster");
155 carray.MakeTree(loader->TreeR());
157 Int_t nclusters=0; //cluster counter
159 //------------------------------------------------------------
160 // Loop over all sectors (72 sectors for 20 deg
161 // segmentation for both lower and upper sectors)
162 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
163 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
165 // First cluster for sector 0 starts at "0"
166 //------------------------------------------------------------
168 for(Int_t isec=0;isec<param->GetNSector();isec++){
170 param->AdjustCosSin(isec,cph,sph);
172 //------------------------------------------------------------
174 //------------------------------------------------------------
176 for(Int_t track=0;track<ntracks;track++){
180 // Get number of the TPC hits
182 tpcHit = (AliTPChit*)tpc->FirstHit(-1);
188 if (tpcHit->fQ == 0.) {
189 tpcHit = (AliTPChit*) tpc->NextHit();
190 continue; //information about track (I.Belikov)
192 sector=tpcHit->fSector; // sector number
195 tpcHit = (AliTPChit*) tpc->NextHit();
198 ipart=tpcHit->Track();
199 particle=aliRun->GetMCApp()->Particle(ipart);
202 if(pt < 1.e-9) pt=1.e-9;
204 tanth = TMath::Abs(tanth);
205 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
206 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
208 // space-point resolutions
210 sigmaRphi=AliTPCcluster::SigmaY2(rpad,tanth,pt);
211 sigmaZ =AliTPCcluster::SigmaZ2(rpad,tanth );
215 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
216 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
218 // temporary protection
220 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
221 if(sigmaZ < 0.) sigmaZ=0.4e-3;
222 if(clRphi < 0.) clRphi=2.5e-3;
223 if(clZ < 0.) clZ=2.5e-5;
228 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
229 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
231 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
232 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
233 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
234 Float_t alpha=(isec < param->GetNInnerSector()) ?
235 param->GetInnerAngle() : param->GetOuterAngle();
236 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
237 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
238 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
239 if (TMath::Abs(xyz[1])>param->GetZLength(isec)) xyz[1]=tpcHit->Z();
240 xyz[2]=sigmaRphi; // fSigmaY2
241 xyz[3]=sigmaZ; // fSigmaZ2
242 xyz[4]=tpcHit->fQ; // q
244 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
245 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
247 Int_t tracks[3]={tpcHit->Track(), -1, -1};
248 AliTPCcluster cluster(tracks,xyz);
250 clrow->InsertCluster(&cluster); nclusters++;
252 tpcHit = (AliTPChit*)tpc->NextHit();
255 } // end of loop over hits
257 } // end of loop over tracks
259 Int_t nrows=param->GetNRow(isec);
260 for (Int_t irow=0; irow<nrows; irow++) {
261 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
262 if (!clrow) continue;
263 carray.StoreRow(isec,irow);
264 carray.ClearRow(isec,irow);
267 } // end of loop over sectors
269 // cerr<<"Number of made clusters : "<<nclusters<<" \n";
270 loader->WriteRecPoints("OVERWRITE");
277 //_________________________________________________________________
281 void AliTPCFast::Hits2ExactClusters(AliRunLoader* runLoader) const{
285 AliLoader* loader = runLoader->GetLoader("TPCLoader");
287 AliError("No TPC loader found");
290 AliTPC* tpc = (AliTPC*) gAlice->GetDetector("TPC");
292 AliError("Couldn't get TPC detector");
295 AliTPCParam* param = tpc->GetParam();
297 AliError("No TPC parameters available");
300 //---------------------------------------------------------------
301 // Get the access to the tracks
302 //---------------------------------------------------------------
304 TTree *tH = loader->TreeH();
305 if (tH == 0x0) { runLoader->LoadHits("TPC"); loader->TreeH();}
307 tpc->SetTreeAddress();
310 //Switch to the output file
312 if (loader->TreeR() == 0x0) loader->MakeTree("R");
314 AliDebug(1,Form("param->GetTitle() = %s",param->GetTitle()));
316 runLoader->CdGAFile();
317 //param->Write(param->GetTitle());
319 AliTPCClustersArray carray;
321 carray.SetClusterType("AliTPCclusterMI");
322 carray.MakeTree(loader->TreeR());
324 //------------------------------------------------------------
325 // Loop over all sectors (72 sectors for 20 deg)
326 //------------------------------------------------------------
328 for(Int_t isec=0;isec<param->GetNSector();isec++){
329 Hits2ExactClustersSector(runLoader, &carray, isec);
330 } // end of loop over sectors
331 loader->WriteRecPoints("OVERWRITE");
337 //_________________________________________________________________
338 void AliTPCFast::Hits2ExactClustersSector(AliRunLoader* runLoader,
339 AliTPCClustersArray* clustersArray,
342 //--------------------------------------------------------
343 //calculate exact cross point of track and given pad row
344 //resulting values are expressed in "local" coordinata
345 //the sigmaY2 and sigmaZ2 of cluster are the shape of cluster parameters
346 // - thay are used later on for error parameterization
347 //--------------------------------------------------------
349 //-----------------------------------------------------------------
350 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
351 //-----------------------------------------------------------------
353 if (clustersArray==0){
356 AliLoader* loader = runLoader->GetLoader("TPCLoader");
358 AliError("No TPC loader found");
361 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
362 AliRun* aliRun = runLoader->GetAliRun();
364 AliError("Couldn't get AliRun object");
367 AliTPC* tpc = (AliTPC*) aliRun->GetDetector("TPC");
369 AliError("Couldn't get TPC detector");
372 AliTPCParam* param = tpc->GetParam();
374 AliError("No TPC parameters available");
379 AliTPChit *tpcHit; // pointer to a sigle TPC hit
380 // Int_t sector,nhits;
382 const Int_t kcmaxhits=30000;
383 TVector * xxxx = new TVector(kcmaxhits*4);
384 TVector & xxx = *xxxx;
385 Int_t maxhits = kcmaxhits;
386 //construct array for each padrow
387 for (Int_t i=0; i<param->GetNRow(isec);i++)
388 clustersArray->CreateRow(isec,i);
390 //---------------------------------------------------------------
391 // Get the access to the tracks
392 //---------------------------------------------------------------
394 TTree *tH = loader->TreeH();
396 AliFatal("Can not find TreeH in folder");
399 tpc->SetTreeAddress();
401 Stat_t ntracks = tH->GetEntries();
404 if (tpc->GetHitType()>1) branch = tH->GetBranch("TPC2");
405 else branch = tH->GetBranch("TPC");
407 //------------------------------------------------------------
409 //------------------------------------------------------------
411 for(Int_t track=0;track<ntracks;track++){
412 Bool_t isInSector=kTRUE;
414 isInSector = tpc->TrackInVolume(isec,track);
415 if (!isInSector) continue;
417 branch->GetEntry(track); // get next track
421 Int_t currentIndex=0;
422 Int_t lastrow=-1; //last writen row
426 tpcHit = (AliTPChit*)tpc->FirstHit(-1);
429 Int_t sector=tpcHit->fSector; // sector number
431 tpcHit = (AliTPChit*) tpc->NextHit();
435 ipart=tpcHit->Track();
439 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
440 Int_t index[3]={1,isec,0};
441 Int_t currentrow = param->GetPadRow(x,index);
443 if (currentrow<0) {tpcHit = (AliTPChit*)tpc->NextHit(); continue;}
444 if (lastrow<0) lastrow=currentrow;
447 if (currentrow!=lastrow){
460 for (Int_t cindex=0;cindex<currentIndex;cindex++){
462 x1=x2=x3=x4=xxx(cindex*4);
470 sumy+=xxx(cindex*4+1);
471 sumxy+=xxx(cindex*4+1)*x1;
472 sumx2y+=xxx(cindex*4+1)*x2;
473 sumz+=xxx(cindex*4+2);
474 sumxz+=xxx(cindex*4+2)*x1;
475 sumx2z+=xxx(cindex*4+2)*x2;
476 sumq+=xxx(cindex*4+3);
478 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
479 sumx2*(sumx*sumx3-sumx2*sumx2);
481 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
482 sumx2*(sumxy*sumx3-sumx2y*sumx2);
483 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
484 sumx2*(sumxz*sumx3-sumx2z*sumx2);
486 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
487 sumx2*(sumx*sumx2y-sumx2*sumxy);
488 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
489 sumx2*(sumx*sumx2z-sumx2*sumxz);
491 if (TMath::Abs(det)<0.00000000000000001){
492 tpcHit = (AliTPChit*)tpc->NextHit();
498 Float_t by=detby/det; //y angle
499 Float_t bz=detbz/det; //z angle
500 sumy/=Float_t(currentIndex);
501 sumz/=Float_t(currentIndex);
506 Float_t sign = (tpcHit->Z()>0)? 1.:-1.;
507 y = (y+0.5)*param->GetPadPitchWidth(isec);
508 z = z*param->GetZWidth();
511 Double_t sigmay2 = z*fParam->GetDiffL();
513 Float_t angulary = by*param->GetPadPitchLength(isec,lastrow);
516 sigmay2 +=angulary+0.25*param->GetPadPitchWidth(isec)*param->GetPadPitchWidth(isec);
519 Double_t sigmaz2 = z*fParam->GetDiffT();
521 Float_t angularz = bz*param->GetPadPitchLength(isec,lastrow);
524 sigmaz2 +=angularz+0.25;
526 sigmaz2 = TMath::Min(sigmaz2,1.);
527 sigmay2 = TMath::Min(sigmay2,1.);
530 z = sign*(param->GetZLength(isec) - z);
531 if (TMath::Abs(z)< param->GetZLength(isec)-1){
532 AliTPCClustersRow * row = (clustersArray->GetRow(isec,lastrow));
534 AliTPCclusterMI* cl = new((AliTPCclusterMI*)row->Append()) AliTPCclusterMI ;
535 // AliTPCclusterMI cl;
539 if (TMath::Abs(sumq)<1000){
540 cl->SetMax(Short_t(sumq));
545 cl->SetSigmaZ2(sigmaz2);
546 cl->SetSigmaY2(sigmay2);
547 cl->SetLabel(ipart,0);
553 } //end of calculating cluster for given row
556 } // end of crossing rows
558 if ( currentIndex>=maxhits){
560 xxx.ResizeTo(4*maxhits);
562 xxx(currentIndex*4)=x[0];
563 xxx(currentIndex*4+1)=x[1];
564 xxx(currentIndex*4+2)=x[2];
565 xxx(currentIndex*4+3)=tpcHit->fQ;
567 tpcHit = (AliTPChit*)tpc->NextHit();
568 } // end of loop over hits
569 } // end of loop over tracks
570 //write padrows to tree
571 for (Int_t ii=0; ii<param->GetNRow(isec);ii++) {
572 clustersArray->StoreRow(isec,ii);
573 clustersArray->ClearRow(isec,ii);