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");
256 //_________________________________________________________________
260 void AliTPCFast::Hits2ExactClusters(AliRunLoader* runLoader) const{
264 AliLoader* loader = runLoader->GetLoader("TPCLoader");
266 AliError("No TPC loader found");
269 AliTPC* tpc = (AliTPC*) gAlice->GetDetector("TPC");
271 AliError("Couldn't get TPC detector");
274 AliTPCParam* param = tpc->GetParam();
276 AliError("No TPC parameters available");
279 //---------------------------------------------------------------
280 // Get the access to the tracks
281 //---------------------------------------------------------------
283 TTree *tH = loader->TreeH();
284 if (tH == 0x0) { runLoader->LoadHits("TPC"); loader->TreeH();}
286 tpc->SetTreeAddress();
289 //Switch to the output file
291 if (loader->TreeR() == 0x0) loader->MakeTree("R");
293 AliDebug(1,Form("param->GetTitle() = %s",param->GetTitle()));
295 runLoader->CdGAFile();
296 //param->Write(param->GetTitle());
298 AliTPCClustersArray carray;
300 carray.SetClusterType("AliTPCclusterMI");
301 carray.MakeTree(loader->TreeR());
303 //------------------------------------------------------------
304 // Loop over all sectors (72 sectors for 20 deg)
305 //------------------------------------------------------------
307 for(Int_t isec=0;isec<param->GetNSector();isec++){
308 Hits2ExactClustersSector(runLoader, &carray, isec);
309 } // end of loop over sectors
310 loader->WriteRecPoints("OVERWRITE");
316 //_________________________________________________________________
317 void AliTPCFast::Hits2ExactClustersSector(AliRunLoader* runLoader,
318 AliTPCClustersArray* clustersArray,
321 //--------------------------------------------------------
322 //calculate exact cross point of track and given pad row
323 //resulting values are expressed in "local" coordinata
324 //the sigmaY2 and sigmaZ2 of cluster are the shape of cluster parameters
325 // - thay are used later on for error parameterization
326 //--------------------------------------------------------
328 //-----------------------------------------------------------------
329 // Origin: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
330 //-----------------------------------------------------------------
332 if (clustersArray==0){
335 AliLoader* loader = runLoader->GetLoader("TPCLoader");
337 AliError("No TPC loader found");
340 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
341 AliRun* aliRun = runLoader->GetAliRun();
343 AliError("Couldn't get AliRun object");
346 AliTPC* tpc = (AliTPC*) aliRun->GetDetector("TPC");
348 AliError("Couldn't get TPC detector");
351 AliTPCParam* param = tpc->GetParam();
353 AliError("No TPC parameters available");
358 AliTPChit *tpcHit; // pointer to a sigle TPC hit
359 // Int_t sector,nhits;
361 const Int_t kcmaxhits=30000;
362 TVector * xxxx = new TVector(kcmaxhits*4);
363 TVector & xxx = *xxxx;
364 Int_t maxhits = kcmaxhits;
365 //construct array for each padrow
366 for (Int_t i=0; i<param->GetNRow(isec);i++)
367 clustersArray->CreateRow(isec,i);
369 //---------------------------------------------------------------
370 // Get the access to the tracks
371 //---------------------------------------------------------------
373 TTree *tH = loader->TreeH();
375 AliFatal("Can not find TreeH in folder");
377 tpc->SetTreeAddress();
379 Stat_t ntracks = tH->GetEntries();
382 if (tpc->GetHitType()>1) branch = tH->GetBranch("TPC2");
383 else branch = tH->GetBranch("TPC");
385 //------------------------------------------------------------
387 //------------------------------------------------------------
389 for(Int_t track=0;track<ntracks;track++){
390 Bool_t isInSector=kTRUE;
392 isInSector = tpc->TrackInVolume(isec,track);
393 if (!isInSector) continue;
395 branch->GetEntry(track); // get next track
399 Int_t currentIndex=0;
400 Int_t lastrow=-1; //last writen row
404 tpcHit = (AliTPChit*)tpc->FirstHit(-1);
407 Int_t sector=tpcHit->fSector; // sector number
409 tpcHit = (AliTPChit*) tpc->NextHit();
413 ipart=tpcHit->Track();
417 Float_t x[3]={tpcHit->X(),tpcHit->Y(),tpcHit->Z()};
418 Int_t index[3]={1,isec,0};
419 Int_t currentrow = param->GetPadRow(x,index);
421 if (currentrow<0) {tpcHit = (AliTPChit*)tpc->NextHit(); continue;}
422 if (lastrow<0) lastrow=currentrow;
425 if (currentrow!=lastrow){
438 for (Int_t index=0;index<currentIndex;index++){
440 x=x2=x3=x4=xxx(index*4);
448 sumy+=xxx(index*4+1);
449 sumxy+=xxx(index*4+1)*x;
450 sumx2y+=xxx(index*4+1)*x2;
451 sumz+=xxx(index*4+2);
452 sumxz+=xxx(index*4+2)*x;
453 sumx2z+=xxx(index*4+2)*x2;
454 sumq+=xxx(index*4+3);
456 Float_t det=currentIndex*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumx*sumx4-sumx2*sumx3)+
457 sumx2*(sumx*sumx3-sumx2*sumx2);
459 Float_t detay=sumy*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxy*sumx4-sumx2y*sumx3)+
460 sumx2*(sumxy*sumx3-sumx2y*sumx2);
461 Float_t detaz=sumz*(sumx2*sumx4-sumx3*sumx3)-sumx*(sumxz*sumx4-sumx2z*sumx3)+
462 sumx2*(sumxz*sumx3-sumx2z*sumx2);
464 Float_t detby=currentIndex*(sumxy*sumx4-sumx2y*sumx3)-sumy*(sumx*sumx4-sumx2*sumx3)+
465 sumx2*(sumx*sumx2y-sumx2*sumxy);
466 Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
467 sumx2*(sumx*sumx2z-sumx2*sumxz);
469 if (TMath::Abs(det)<0.00000000000000001){
470 tpcHit = (AliTPChit*)tpc->NextHit();
476 Float_t by=detby/det; //y angle
477 Float_t bz=detbz/det; //z angle
478 sumy/=Float_t(currentIndex);
479 sumz/=Float_t(currentIndex);
484 Float_t sign = (tpcHit->Z()>0)? 1.:-1.;
485 y = (y+0.5)*param->GetPadPitchWidth(isec);
486 z = z*param->GetZWidth();
489 Double_t sigmay2 = z*fParam->GetDiffL();
491 Float_t angulary = by*param->GetPadPitchLength(isec,lastrow);
494 sigmay2 +=angulary+0.25*param->GetPadPitchWidth(isec)*param->GetPadPitchWidth(isec);
497 Double_t sigmaz2 = z*fParam->GetDiffT();
499 Float_t angularz = bz*param->GetPadPitchLength(isec,lastrow);
502 sigmaz2 +=angularz+0.25;
504 sigmaz2 = TMath::Min(sigmaz2,1.);
505 sigmay2 = TMath::Min(sigmay2,1.);
508 z = sign*(param->GetZLength() - z);
509 if (TMath::Abs(z)< param->GetZLength()-1){
510 AliTPCClustersRow * row = (clustersArray->GetRow(isec,lastrow));
512 AliTPCclusterMI* cl = new((AliTPCclusterMI*)row->Append()) AliTPCclusterMI ;
513 // AliTPCclusterMI cl;
517 if (TMath::Abs(sumq)<1000){
518 cl->SetMax(Short_t(sumq));
523 cl->SetSigmaZ2(sigmaz2);
524 cl->SetSigmaY2(sigmay2);
525 cl->SetLabel(ipart,0);
531 } //end of calculating cluster for given row
534 } // end of crossing rows
536 if ( currentIndex>=maxhits){
538 xxx.ResizeTo(4*maxhits);
540 xxx(currentIndex*4)=x[0];
541 xxx(currentIndex*4+1)=x[1];
542 xxx(currentIndex*4+2)=x[2];
543 xxx(currentIndex*4+3)=tpcHit->fQ;
545 tpcHit = (AliTPChit*)tpc->NextHit();
546 } // end of loop over hits
547 } // end of loop over tracks
548 //write padrows to tree
549 for (Int_t ii=0; ii<param->GetNRow(isec);ii++) {
550 clustersArray->StoreRow(isec,ii);
551 clustersArray->ClearRow(isec,ii);