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>
28 #include "AliRunLoader.h"
32 #include "AliTPCParam.h"
33 #include "AliTPCClustersArray.h"
34 #include "AliTPCClustersRow.h"
35 #include "AliTPCcluster.h"
36 #include "AliComplexCluster.h"
37 #include "AliTPCFast.h"
41 //____________________________________________________________________
42 AliTPCFast::AliTPCFast(const AliTPCFast ¶m)
43 :TObject(param),fParam(0)
47 // copy constructor - dummy
49 fParam = param.fParam;
51 AliTPCFast & AliTPCFast::operator =(const AliTPCFast & param)
54 // assignment operator - dummy
60 //_____________________________________________________________________________
61 void AliTPCFast::Hits2Clusters(AliRunLoader* runLoader) const
63 //--------------------------------------------------------
64 // TPC simple cluster generator from hits
65 // obtained from the TPC Fast Simulator
66 // The point errors are taken from the parametrization
67 //--------------------------------------------------------
69 //-----------------------------------------------------------------
70 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
71 //-----------------------------------------------------------------
72 // Adopted to Marian's cluster data structure by I.Belikov, CERN,
73 // Jouri.Belikov@cern.ch
74 //----------------------------------------------------------------
76 /////////////////////////////////////////////////////////////////////////////
78 //---------------------------------------------------------------------
79 // ALICE TPC Cluster Parameters
80 //--------------------------------------------------------------------
84 // Cluster width in rphi
85 const Float_t kACrphi=0.18322;
86 const Float_t kBCrphi=0.59551e-3;
87 const Float_t kCCrphi=0.60952e-1;
89 const Float_t kACz=0.19081;
90 const Float_t kBCz=0.55938e-3;
91 const Float_t kCCz=0.30428;
94 AliLoader* loader = runLoader->GetLoader("TPCLoader");
96 AliError("No TPC loader found");
99 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
100 AliRun* aliRun = runLoader->GetAliRun();
102 AliError("Couldn't get AliRun object");
105 AliTPC* tpc = (AliTPC*) aliRun->GetDetector("TPC");
107 AliError("Couldn't get TPC detector");
110 AliTPCParam* param = tpc->GetParam();
112 AliError("No TPC parameters available");
116 //if(fDefaults == 0) SetDefaults();
118 Float_t sigmaRphi,sigmaZ,clRphi,clZ;
120 TParticle *particle; // pointer to a given particle
121 AliTPChit *tpcHit; // pointer to a sigle TPC hit
125 Float_t pl,pt,tanth,rpad,ratio;
128 //---------------------------------------------------------------
129 // Get the access to the tracks
130 //---------------------------------------------------------------
132 TTree *tH = loader->TreeH();
134 AliFatal("Can not find TreeH in folder");
137 tpc->SetTreeAddress();
139 Stat_t ntracks = tH->GetEntries();
141 //Switch to the output file
143 if (loader->TreeR() == 0x0) loader->MakeTree("R");
145 AliDebug(1,Form("param->GetTitle() = %s",param->GetTitle()));
147 runLoader->CdGAFile();
148 //param->Write(param->GetTitle());
150 AliTPCClustersArray carray;
152 carray.SetClusterType("AliTPCcluster");
153 carray.MakeTree(loader->TreeR());
155 Int_t nclusters=0; //cluster counter
157 //------------------------------------------------------------
158 // Loop over all sectors (72 sectors for 20 deg
159 // segmentation for both lower and upper sectors)
160 // Sectors 0-35 are lower sectors, 0-17 z>0, 17-35 z<0
161 // Sectors 36-71 are upper sectors, 36-53 z>0, 54-71 z<0
163 // First cluster for sector 0 starts at "0"
164 //------------------------------------------------------------
166 for(Int_t isec=0;isec<param->GetNSector();isec++){
168 param->AdjustCosSin(isec,cph,sph);
170 //------------------------------------------------------------
172 //------------------------------------------------------------
174 for(Int_t track=0;track<ntracks;track++){
178 // Get number of the TPC hits
180 tpcHit = (AliTPChit*)tpc->FirstHit(-1);
186 if (tpcHit->fQ == 0.) {
187 tpcHit = (AliTPChit*) tpc->NextHit();
188 continue; //information about track (I.Belikov)
190 sector=tpcHit->fSector; // sector number
193 tpcHit = (AliTPChit*) tpc->NextHit();
196 ipart=tpcHit->Track();
197 particle=aliRun->GetMCApp()->Particle(ipart);
200 if(pt < 1.e-9) pt=1.e-9;
202 tanth = TMath::Abs(tanth);
203 rpad=TMath::Sqrt(tpcHit->X()*tpcHit->X() + tpcHit->Y()*tpcHit->Y());
204 ratio=0.001*rpad/pt; // pt must be in MeV/c - historical reason
206 // space-point resolutions
208 sigmaRphi=AliTPCcluster::SigmaY2(rpad,tanth,pt);
209 sigmaZ =AliTPCcluster::SigmaZ2(rpad,tanth );
213 clRphi=kACrphi-kBCrphi*rpad*tanth+kCCrphi*ratio*ratio;
214 clZ=kACz-kBCz*rpad*tanth+kCCz*tanth*tanth;
216 // temporary protection
218 if(sigmaRphi < 0.) sigmaRphi=0.4e-3;
219 if(sigmaZ < 0.) sigmaZ=0.4e-3;
220 if(clRphi < 0.) clRphi=2.5e-3;
221 if(clZ < 0.) clZ=2.5e-5;
226 // smearing --> rotate to the 1 (13) or to the 25 (49) sector,
227 // then the inaccuracy in a X-Y plane is only along Y (pad row)!
229 Float_t xprim= tpcHit->X()*cph + tpcHit->Y()*sph;
230 Float_t yprim=-tpcHit->X()*sph + tpcHit->Y()*cph;
231 xyz[0]=gRandom->Gaus(yprim,TMath::Sqrt(sigmaRphi)); // y
232 Float_t alpha=(isec < param->GetNInnerSector()) ?
233 param->GetInnerAngle() : param->GetOuterAngle();
234 Float_t ymax=xprim*TMath::Tan(0.5*alpha);
235 if (TMath::Abs(xyz[0])>ymax) xyz[0]=yprim;
236 xyz[1]=gRandom->Gaus(tpcHit->Z(),TMath::Sqrt(sigmaZ)); // z
237 if (TMath::Abs(xyz[1])>param->GetZLength(isec)) xyz[1]=tpcHit->Z();
238 xyz[2]=sigmaRphi; // fSigmaY2
239 xyz[3]=sigmaZ; // fSigmaZ2
240 xyz[4]=tpcHit->fQ; // q
242 AliTPCClustersRow *clrow=carray.GetRow(sector,tpcHit->fPadRow);
243 if (!clrow) clrow=carray.CreateRow(sector,tpcHit->fPadRow);
245 Int_t tracks[3]={tpcHit->Track(), -1, -1};
246 AliTPCcluster cluster(tracks,xyz);
248 clrow->InsertCluster(&cluster); nclusters++;
250 tpcHit = (AliTPChit*)tpc->NextHit();
253 } // end of loop over hits
255 } // end of loop over tracks
257 Int_t nrows=param->GetNRow(isec);
258 for (Int_t irow=0; irow<nrows; irow++) {
259 AliTPCClustersRow *clrow=carray.GetRow(isec,irow);
260 if (!clrow) continue;
261 carray.StoreRow(isec,irow);
262 carray.ClearRow(isec,irow);
265 } // end of loop over sectors
267 // cerr<<"Number of made clusters : "<<nclusters<<" \n";
268 loader->WriteRecPoints("OVERWRITE");
275 //_________________________________________________________________
279 void AliTPCFast::Hits2ExactClusters(AliRunLoader* runLoader) const{
283 AliLoader* loader = runLoader->GetLoader("TPCLoader");
285 AliError("No TPC loader found");
288 AliTPC* tpc = (AliTPC*) gAlice->GetDetector("TPC");
290 AliError("Couldn't get TPC detector");
293 AliTPCParam* param = tpc->GetParam();
295 AliError("No TPC parameters available");
298 //---------------------------------------------------------------
299 // Get the access to the tracks
300 //---------------------------------------------------------------
302 TTree *tH = loader->TreeH();
303 if (tH == 0x0) { runLoader->LoadHits("TPC"); loader->TreeH();}
305 tpc->SetTreeAddress();
308 //Switch to the output file
310 if (loader->TreeR() == 0x0) loader->MakeTree("R");
312 AliDebug(1,Form("param->GetTitle() = %s",param->GetTitle()));
314 runLoader->CdGAFile();
315 //param->Write(param->GetTitle());
317 AliTPCClustersArray carray;
319 carray.SetClusterType("AliTPCclusterMI");
320 carray.MakeTree(loader->TreeR());
322 //------------------------------------------------------------
323 // Loop over all sectors (72 sectors for 20 deg)
324 //------------------------------------------------------------
326 for(Int_t isec=0;isec<param->GetNSector();isec++){
327 Hits2ExactClustersSector(runLoader, &carray, isec);
328 } // end of loop over sectors
329 loader->WriteRecPoints("OVERWRITE");
335 //_________________________________________________________________
336 void AliTPCFast::Hits2ExactClustersSector(AliRunLoader* runLoader,
337 AliTPCClustersArray* clustersArray,
340 //--------------------------------------------------------
341 //calculate exact cross point of track and given pad row
342 //resulting values are expressed in "local" coordinata
343 //the sigmaY2 and sigmaZ2 of cluster are the shape of cluster parameters
344 // - thay are used later on for error parameterization
345 //--------------------------------------------------------
347 //-----------------------------------------------------------------
348 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
349 //-----------------------------------------------------------------
351 if (clustersArray==0){
354 AliLoader* loader = runLoader->GetLoader("TPCLoader");
356 AliError("No TPC loader found");
359 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
360 AliRun* aliRun = runLoader->GetAliRun();
362 AliError("Couldn't get AliRun object");
365 AliTPC* tpc = (AliTPC*) aliRun->GetDetector("TPC");
367 AliError("Couldn't get TPC detector");
370 AliTPCParam* param = tpc->GetParam();
372 AliError("No TPC parameters available");
377 AliTPChit *tpcHit; // pointer to a sigle TPC hit
378 // Int_t sector,nhits;
380 const Int_t kcmaxhits=30000;
381 TVector * xxxx = new TVector(kcmaxhits*4);
382 TVector & xxx = *xxxx;
383 Int_t maxhits = kcmaxhits;
384 //construct array for each padrow
385 for (Int_t i=0; i<param->GetNRow(isec);i++)
386 clustersArray->CreateRow(isec,i);
388 //---------------------------------------------------------------
389 // Get the access to the tracks
390 //---------------------------------------------------------------
392 TTree *tH = loader->TreeH();
394 AliFatal("Can not find TreeH in folder");
397 tpc->SetTreeAddress();
399 Stat_t ntracks = tH->GetEntries();
402 if (tpc->GetHitType()>1) branch = tH->GetBranch("TPC2");
403 else branch = tH->GetBranch("TPC");
405 //------------------------------------------------------------
407 //------------------------------------------------------------
409 for(Int_t track=0;track<ntracks;track++){
410 Bool_t isInSector=kTRUE;
412 isInSector = tpc->TrackInVolume(isec,track);
413 if (!isInSector) continue;
415 branch->GetEntry(track); // get next track
419 Int_t currentIndex=0;
420 Int_t lastrow=-1; //last writen row
424 tpcHit = (AliTPChit*)tpc->FirstHit(-1);
427 Int_t sector=tpcHit->fSector; // sector number
429 tpcHit = (AliTPChit*) tpc->NextHit();
433 ipart=tpcHit->Track();
437 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
438 Int_t index[3]={1,isec,0};
439 Int_t currentrow = param->GetPadRow(x,index);
441 if (currentrow<0) {tpcHit = (AliTPChit*)tpc->NextHit(); continue;}
442 if (lastrow<0) lastrow=currentrow;
445 if (currentrow!=lastrow){
458 for (Int_t cindex=0;cindex<currentIndex;cindex++){
460 x1=x2=x3=x4=xxx(cindex*4);
468 sumy+=xxx(cindex*4+1);
469 sumxy+=xxx(cindex*4+1)*x1;
470 sumx2y+=xxx(cindex*4+1)*x2;
471 sumz+=xxx(cindex*4+2);
472 sumxz+=xxx(cindex*4+2)*x1;
473 sumx2z+=xxx(cindex*4+2)*x2;
474 sumq+=xxx(cindex*4+3);
476 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
477 sumx2*(sumx*sumx3-sumx2*sumx2);
479 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
480 sumx2*(sumxy*sumx3-sumx2y*sumx2);
481 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
482 sumx2*(sumxz*sumx3-sumx2z*sumx2);
484 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
485 sumx2*(sumx*sumx2y-sumx2*sumxy);
486 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
487 sumx2*(sumx*sumx2z-sumx2*sumxz);
489 if (TMath::Abs(det)<0.00000000000000001){
490 tpcHit = (AliTPChit*)tpc->NextHit();
496 Float_t by=detby/det; //y angle
497 Float_t bz=detbz/det; //z angle
498 sumy/=Float_t(currentIndex);
499 sumz/=Float_t(currentIndex);
504 Float_t sign = (tpcHit->Z()>0)? 1.:-1.;
505 y = (y+0.5)*param->GetPadPitchWidth(isec);
506 z = z*param->GetZWidth();
509 Double_t sigmay2 = z*fParam->GetDiffL();
511 Float_t angulary = by*param->GetPadPitchLength(isec,lastrow);
514 sigmay2 +=angulary+0.25*param->GetPadPitchWidth(isec)*param->GetPadPitchWidth(isec);
517 Double_t sigmaz2 = z*fParam->GetDiffT();
519 Float_t angularz = bz*param->GetPadPitchLength(isec,lastrow);
522 sigmaz2 +=angularz+0.25;
524 sigmaz2 = TMath::Min(sigmaz2,1.);
525 sigmay2 = TMath::Min(sigmay2,1.);
528 z = sign*(param->GetZLength(isec) - z);
529 if (TMath::Abs(z)< param->GetZLength(isec)-1){
530 AliTPCClustersRow * row = (clustersArray->GetRow(isec,lastrow));
532 AliTPCclusterMI* cl = new((AliTPCclusterMI*)row->Append()) AliTPCclusterMI ;
533 // AliTPCclusterMI cl;
537 if (TMath::Abs(sumq)<1000){
538 cl->SetMax(Short_t(sumq));
543 cl->SetSigmaZ2(sigmaz2);
544 cl->SetSigmaY2(sigmay2);
545 cl->SetLabel(ipart,0);
551 } //end of calculating cluster for given row
554 } // end of crossing rows
556 if ( currentIndex>=maxhits){
558 xxx.ResizeTo(4*maxhits);
560 xxx(currentIndex*4)=x[0];
561 xxx(currentIndex*4+1)=x[1];
562 xxx(currentIndex*4+2)=x[2];
563 xxx(currentIndex*4+3)=tpcHit->fQ;
565 tpcHit = (AliTPChit*)tpc->NextHit();
566 } // end of loop over hits
567 } // end of loop over tracks
568 //write padrows to tree
569 for (Int_t ii=0; ii<param->GetNRow(isec);ii++) {
570 clustersArray->StoreRow(isec,ii);
571 clustersArray->ClearRow(isec,ii);