2 gSystem->Load("libSTAT.so");
5 .L $ALICE_ROOT/TPC/fastSimul/AliTPCclusterFast.cxx+
7 AliTPCclusterFast::fPRF = new TF1("fprf","gausn",-5,5);
8 AliTPCclusterFast::fTRF = new TF1("ftrf","gausn",-5,5);
9 AliTPCclusterFast::fPRF->SetParameters(1,0,0.5);
10 AliTPCclusterFast::fTRF->SetParameters(1,0,0.5);
13 AliTPCtrackFast::Simul("trackerSimul.root",100);
14 // AliTPCclusterFast::Simul("cluterSimul.root",20000);
24 #include "TClonesArray.h"
25 #include "TTreeStream.h"
27 class AliTPCclusterFast: public TObject {
30 virtual ~AliTPCclusterFast();
31 void SetParam(Float_t mnprim, Float_t diff, Float_t y, Float_t z, Float_t ky, Float_t kz);
32 void GenerElectrons();
34 Double_t GetQtot(Float_t gain,Float_t thr, Float_t noise, Bool_t rounding=kTRUE, Bool_t addPedestal=kTRUE);
35 Double_t GetQmax(Float_t gain,Float_t thr, Float_t noise, Bool_t rounding=kTRUE, Bool_t addPedestal=kTRUE);
36 Double_t GetQmaxCorr(Float_t rmsy0, Float_t rmsz0);
37 Double_t GetQtotCorr(Float_t rmsy0, Float_t rmsz0, Float_t gain, Float_t thr);
40 static void Simul(const char* simul, Int_t npoints);
41 static Double_t GaussConvolution(Double_t x0, Double_t x1, Double_t k0, Double_t k1, Double_t s0, Double_t s1);
42 static Double_t GaussExpConvolution(Double_t x0, Double_t s0,Double_t t1);
43 static Double_t GaussGamma4(Double_t x, Double_t s0, Double_t p1);
44 static Double_t Gamma4(Double_t x, Double_t p0, Double_t p1);
46 Float_t fMNprim; // mean number of primary electrons
47 // //electrons part input
48 Int_t fNprim; // mean number of primary electrons
49 Int_t fNtot; // total number of electrons
50 Float_t fQtot; // total charge - Gas gain flucuation taken into account
52 Float_t fDiff; // diffusion sigma
53 Float_t fY; // y position
54 Float_t fZ; // z postion
55 Float_t fAngleY; // y angle - tan(y)
56 Float_t fAngleZ; // z angle - tan z
59 // // electron part simul
60 TVectorD fSec; //! number of secondary electrons
61 TVectorD fPosY; //! position y for each electron
62 TVectorD fPosZ; //! position z for each electron
63 TVectorD fGain; //! gg for each electron
65 TVectorD fStatY; //!stat Y
66 TVectorD fStatZ; //!stat Y
70 TMatrixD fDigits; // response matrix
71 static TF1* fPRF; // Pad response
72 static TF1* fTRF; // Time response function
73 ClassDef(AliTPCclusterFast,1) // container for
77 class AliTPCtrackFast: public TObject {
80 void Add(AliTPCtrackFast &track2);
82 static void Simul(const char* simul, Int_t ntracks);
83 Double_t CookdEdxNtot(Double_t f0,Float_t f1);
84 Double_t CookdEdxQtot(Double_t f0,Float_t f1);
86 Double_t CookdEdxDtot(Double_t f0,Float_t f1, Float_t gain,Float_t thr, Float_t noise, Bool_t corr = kTRUE);
87 Double_t CookdEdxDmax(Double_t f0,Float_t f1,Float_t gain,Float_t thr, Float_t noise, Bool_t corr=kTRUE);
89 Double_t CookdEdx(Int_t npoints, Double_t *amp, Double_t f0,Float_t f1);
91 Float_t fMNprim; // mean number of primary electrons
92 Float_t fAngleY; // y angle - tan(y)
93 Float_t fAngleZ; // z angle - tan z
94 Float_t fDiff; // diffusion
95 Int_t fN; // number of clusters
96 TClonesArray *fCl; // array of clusters
98 Bool_t fInit; // initialization flag
101 ClassDef(AliTPCtrackFast,2) // container for
106 ClassImp(AliTPCclusterFast)
107 ClassImp(AliTPCtrackFast)
113 TF1 *AliTPCclusterFast::fPRF=0;
114 TF1 *AliTPCclusterFast::fTRF=0;
117 AliTPCtrackFast::AliTPCtrackFast():
131 void AliTPCtrackFast::Add(AliTPCtrackFast &track2){
132 if (!track2.fInit) return;
138 void AliTPCtrackFast::MakeTrack(){
142 if (!fCl) fCl = new TClonesArray("AliTPCclusterFast",160);
143 for (Int_t i=0;i<fN;i++){
144 Double_t tY = i*fAngleY;
145 Double_t tZ = i*fAngleZ;
146 AliTPCclusterFast * cluster = (AliTPCclusterFast*) fCl->UncheckedAt(i);
147 if (!cluster) cluster = new ((*fCl)[i]) AliTPCclusterFast;
149 Double_t posY = tY-TMath::Nint(tY);
150 Double_t posZ = tZ-TMath::Nint(tZ);
151 cluster->SetParam(fMNprim,fDiff,posY,posZ,fAngleY,fAngleZ);
153 cluster->GenerElectrons();
158 Double_t AliTPCtrackFast::CookdEdxNtot(Double_t f0,Float_t f1){
161 for (Int_t i=0;i<fN;i++){
162 AliTPCclusterFast * cluster = ( AliTPCclusterFast *)((*fCl)[i]);
163 amp[i]=cluster->fNtot;
165 return CookdEdx(fN,amp,f0,f1);
168 Double_t AliTPCtrackFast::CookdEdxQtot(Double_t f0,Float_t f1){
171 for (Int_t i=0;i<fN;i++){
172 AliTPCclusterFast * cluster = ( AliTPCclusterFast *)((*fCl)[i]);
173 amp[i]=cluster->fQtot;
175 return CookdEdx(fN,amp,f0,f1);
178 Double_t AliTPCtrackFast::CookdEdxDtot(Double_t f0,Float_t f1, Float_t gain,Float_t thr, Float_t noise, Bool_t doCorr){
184 for (Int_t i=0;i<fN;i++){
185 AliTPCclusterFast * cluster = ( AliTPCclusterFast *)((*fCl)[i]);
186 Float_t camp = cluster->GetQtot(gain,thr,noise);
187 if (camp==0) continue;
189 if (doCorr) corr = cluster->GetQtotCorr(0.5,0.5,gain,thr);
193 return CookdEdx(over,amp,f0,f1);
197 Double_t AliTPCtrackFast::CookdEdxDmax(Double_t f0,Float_t f1, Float_t gain,Float_t thr, Float_t noise, Bool_t doCorr){
203 for (Int_t i=0;i<fN;i++){
204 AliTPCclusterFast * cluster = ( AliTPCclusterFast *)((*fCl)[i]);
205 Float_t camp = cluster->GetQmax(gain,thr,noise);
206 if (camp==0) continue;
208 if (doCorr) corr = cluster->GetQmaxCorr(0.5,0.5);
212 return CookdEdx(over,amp,f0,f1);
217 Double_t AliTPCtrackFast::CookdEdx(Int_t npoints, Double_t *amp,Double_t f0,Float_t f1){
222 TMath::Sort(npoints,amp,index,kFALSE);
223 Float_t sum0=0, sum1=0,sum2=0;
224 for (Int_t i=0;i<npoints;i++){
225 if (i<npoints*f0) continue;
226 if (i>npoints*f1) continue;
228 sum1+= amp[index[i]];
229 sum2+= amp[index[i]];
231 if (sum0<=0) return 0;
235 void AliTPCtrackFast::Simul(const char* fname, Int_t ntracks){
239 AliTPCtrackFast fast;
240 TTreeSRedirector cstream(fname,"recreate");
241 for (Int_t itr=0; itr<ntracks; itr++){
243 fast.fMNprim=(5+50*gRandom->Rndm());
244 fast.fDiff =0.01 +0.35*gRandom->Rndm();
246 fast.fAngleY = 4.0*(gRandom->Rndm()-0.5);
247 fast.fAngleZ = 4.0*(gRandom->Rndm()-0.5);
248 fast.fN = TMath::Nint(80.+gRandom->Rndm()*80.);
250 if (itr%100==0) printf("%d\n",itr);
251 cstream<<"simulTrack"<<
260 AliTPCclusterFast::AliTPCclusterFast(){
263 fDigits.ResizeTo(5,7);
266 AliTPCclusterFast::~AliTPCclusterFast(){
270 void AliTPCclusterFast::SetParam(Float_t mnprim, Float_t diff, Float_t y, Float_t z, Float_t ky, Float_t kz){
273 fMNprim = mnprim; fDiff = diff;
275 fAngleY=ky; fAngleZ=kz;
277 Double_t AliTPCclusterFast::GetNsec(){
279 // Generate number of secondary electrons
280 // copy of procedure implemented in geant
282 const Double_t FPOT=20.77E-9, EEND=10E-6, EEXPO=2.2, EEND1=1E-6;
283 const Double_t XEXPO=-EEXPO+1, YEXPO=1/XEXPO;
284 const Double_t W=20.77E-9;
285 Float_t RAN = gRandom->Rndm();
286 //Double_t edep = TMath::Power((TMath::Power(FPOT,XEXPO)*(1-RAN)+TMath::Power(EEND,XEXPO)*RAN),YEXPO);
287 //edep = TMath::Min(edep, EEND);
288 //return TMath::Nint(edep/W);
289 return TMath::Nint(TMath::Power((TMath::Power(FPOT,XEXPO)*(1-RAN)+TMath::Power(EEND,XEXPO)*RAN),YEXPO)/W);
292 void AliTPCclusterFast::GenerElectrons(){
297 const Int_t knMax=1000;
298 if (fPosY.GetNrows()<knMax){
299 fPosY.ResizeTo(knMax);
300 fPosZ.ResizeTo(knMax);
301 fGain.ResizeTo(knMax);
302 fSec.ResizeTo(knMax);
306 fNprim = gRandom->Poisson(fMNprim); //number of primary electrons
307 fNtot=0; //total number of electrons
308 fQtot=0; //total number of electrons after gain multiplification
315 for (Int_t i=0;i<knMax;i++){
318 for (Int_t iprim=0; iprim<fNprim;iprim++){
319 Float_t dN = GetNsec();
321 Double_t yc = fY+(gRandom->Rndm()-0.5)*fAngleY;
322 Double_t zc = fZ+(gRandom->Rndm()-0.5)*fAngleZ;
323 for (Int_t isec=0;isec<=dN;isec++){
326 Double_t y = gRandom->Gaus(0,fDiff)+yc;
327 Double_t z = gRandom->Gaus(0,fDiff)+zc;
328 Double_t gg = -TMath::Log(gRandom->Rndm());
339 if (fNtot>=knMax) break;
341 if (fNtot>=knMax) break;
345 fStatY[1]=sumYQ/sumQ;
346 fStatY[2]=sumY2Q/sumQ-fStatY[1]*fStatY[1];
348 fStatZ[1]=sumZQ/sumQ;
349 fStatZ[2]=sumZ2Q/sumQ-fStatZ[1]*fStatZ[1];
353 void AliTPCclusterFast::Digitize(){
358 for (Int_t i=0; i<5;i++)
359 for (Int_t j=0; j<7;j++){
364 for (Int_t iel = 0; iel<fNtot; iel++){
365 for (Int_t di=-2; di<=2;di++)
366 for (Int_t dj=-3; dj<=3;dj++){
367 Float_t fac = fPRF->Eval(di-fPosY[iel])*fTRF->Eval(dj-fPosZ[iel]);
369 fDigits(2+di,3+dj)+=fac;
377 void AliTPCclusterFast::Simul(const char* fname, Int_t npoints){
381 AliTPCclusterFast fast;
382 TTreeSRedirector cstream(fname);
383 for (Int_t icl=0; icl<npoints; icl++){
384 Float_t nprim=(10+20*gRandom->Rndm());
385 Float_t diff =0.01 +0.35*gRandom->Rndm();
386 Float_t posY = gRandom->Rndm()-0.5;
387 Float_t posZ = gRandom->Rndm()-0.5;
389 Float_t ky = 4.0*(gRandom->Rndm()-0.5);
390 Float_t kz = 4.0*(gRandom->Rndm()-0.5);
391 fast.SetParam(nprim,diff,posY,posZ,ky,kz);
392 fast.GenerElectrons();
394 if (icl%10000==0) printf("%d\n",icl);
402 Double_t AliTPCclusterFast::GetQtot(Float_t gain, Float_t thr, Float_t noise, Bool_t brounding, Bool_t baddPedestal){
407 for (Int_t ip=0;ip<5;ip++){
408 Float_t pedestal=gRandom->Rndm()-0.5; //pedestal offset different for each pad
409 for (Int_t it=0;it<7;it++){
410 Float_t amp = gain*fDigits(ip,it)+gRandom->Gaus()*noise;
411 if (baddPedestal) amp+=pedestal;
412 if (brounding) amp=TMath::Nint(amp);
413 if (amp>thr) sum+=amp;
419 Double_t AliTPCclusterFast::GetQmax(Float_t gain, Float_t thr, Float_t noise, Bool_t brounding, Bool_t baddPedestal){
424 for (Int_t ip=0;ip<5;ip++){
425 Float_t pedestal=gRandom->Rndm()-0.5; //pedestal offset different for each pad
426 for (Int_t it=0;it<7;it++){
427 Float_t amp = gain*fDigits(ip,it)+gRandom->Gaus()*noise;
428 if (baddPedestal) amp+=pedestal;
429 if (brounding) amp=TMath::Nint(amp);
430 if (amp>max && amp>thr) max=amp;
438 Double_t AliTPCclusterFast::GetQmaxCorr(Float_t rmsy0, Float_t rmsz0){
440 // Gaus distribution convolueted with rectangular
441 // Gaus width sy and sz is determined by RF width and diffusion
442 // Integral of Q is equal 1
443 // Q max is calculated at position fY,fX
447 Double_t sy = TMath::Sqrt(rmsy0*rmsy0+fDiff*fDiff);
448 Double_t sz = TMath::Sqrt(rmsz0*rmsz0+fDiff*fDiff);
449 return GaussConvolution(fY,fZ, fAngleY,fAngleZ,sy,sz);
453 Double_t AliTPCclusterFast::GetQtotCorr(Float_t rmsy0, Float_t rmsz0, Float_t gain, Float_t thr){
455 // Calculates the fraction of the charge over threshol to total charge
456 // The response function
458 Double_t sy = TMath::Sqrt(rmsy0*rmsy0+fDiff*fDiff);
459 Double_t sz = TMath::Sqrt(rmsz0*rmsz0+fDiff*fDiff);
460 Double_t sumAll=0,sumThr=0;
461 Double_t qtot = GetQtot(gain,thr,0); // sum of signal over threshold
465 for (Int_t iter=0;iter<2;iter++){
466 for (Int_t iy=-2;iy<=2;iy++)
467 for (Int_t iz=-2;iz<=2;iz++){
468 Double_t val = GaussConvolution(fY-iy,fZ-iz, fAngleY,fAngleZ,sy,sz);
469 Double_t qlocal =TMath::Nint(qnorm*val);
470 if (qlocal>thr) sumThr+=qlocal;
473 if (sumAll>0&&sumThr>0) corr=(sumThr)/sumAll;
475 if (corr>0) qnorm=qtot/corr;
485 Double_t AliTPCclusterFast::GaussConvolution(Double_t x0, Double_t x1, Double_t k0, Double_t k1, Double_t s0, Double_t s1){
487 // 2 D gaus convoluted with angular effect
488 // See in mathematica:
489 //Simplify[Integrate[Exp[-(x0-k0*xd)*(x0-k0*xd)/(2*s0*s0)-(x1-k1*xd)*(x1-k1*xd)/(2*s1*s1)]/(s0*s1),{xd,-1/2,1/2}]]
491 //TF1 f1("f1","AliTPCclusterFast::GaussConvolution(x,0,1,0,0.1,0.1)",-2,2)
492 //TF2 f2("f2","AliTPCclusterFast::GaussConvolution(x,y,1,1,0.1,0.1)",-2,2,-2,2)
494 const Float_t kEpsilon = 0.0001;
495 if ((TMath::Abs(k0)+TMath::Abs(k1))<kEpsilon*(s0+s1)){
496 // small angular effect
497 Double_t val = (TMath::Gaus(x0,0,s0)*TMath::Gaus(x1,0,s1))/(s0*s1*2.*TMath::Pi());
501 Double_t sigma2 = k1*k1*s0*s0+k0*k0*s1*s1;
502 Double_t exp0 = TMath::Exp(-(k1*x0-k0*x1)*(k1*x0-k0*x1)/(2*sigma2));
504 Double_t sigmaErf = 2*s0*s1*TMath::Sqrt(2*sigma2);
505 Double_t erf0 = TMath::Erf( (k0*s1*s1*(k0-2*x0)+k1*s0*s0*(k1-2*x1))/sigmaErf);
506 Double_t erf1 = TMath::Erf( (k0*s1*s1*(k0+2*x0)+k1*s0*s0*(k1+2*x1))/sigmaErf);
507 Double_t norm = 1./TMath::Sqrt(sigma2);
508 norm/=2.*TMath::Sqrt(2.*TMath::Pi());
509 Double_t val = norm*exp0*(erf0+erf1);
515 Double_t AliTPCclusterFast::GaussExpConvolution(Double_t x0, Double_t s0,Double_t t1){
517 // 2 D gaus convoluted with exponential
518 // Integral nomalized to 1
519 // See in mathematica:
520 //Simplify[Integrate[Exp[-(x0-x1)*(x0-x1)/(2*s0*s0)]*Exp[-x1*t1],{x1,0,Infinity}]]
521 // TF1 fgexp("fgexp","AliTPCclusterFast::GaussExpConvolution(x,0.5,1)",-2,2)
522 Double_t exp1 = (s0*s0*t1-2*x0)*t1/2.;
523 exp1 = TMath::Exp(exp1);
524 Double_t erf = 1+TMath::Erf((-s0*s0*t1+x0)/(s0*TMath::Sqrt(2.)));
525 Double_t val = exp1*erf;
532 Double_t AliTPCclusterFast::Gamma4(Double_t x, Double_t p0, Double_t p1){
534 // Gamma 4 Time response function of ALTRO
537 Double_t g1 = TMath::Exp(-4.*x/p1);
538 Double_t g2 = TMath::Power(x/p1,4);
544 Double_t AliTPCclusterFast::GaussGamma4(Double_t x, Double_t s0, Double_t p1){
546 // Gamma 4 Time response function of ALTRO convoluted with Gauss
547 // Simplify[Integrate[Exp[-(x0-x1)*(x0-x1)/(2*s0*s0)]*Exp[-4*x1/p1]*(x/p1)^4/s0,{x1,0,Infinity}]]
548 //TF1 fgg4("fgg4","AliTPCclusterFast::GaussGamma4(x,0.5,0.5)",-2,2)
550 Double_t exp1 = (8*s0*s0-4.*p1*x)/(p1*p1);
551 exp1 = TMath::Exp(exp1);
552 Double_t erf1 = 1+TMath::Erf((-4*s0/p1+x/s0)/TMath::Sqrt(2));
553 // Double_t xp14 = TMath::Power(TMath::Abs((x/p1)),4);
559 // Analytical sollution only in 1D - too long expression
560 // Simplify[Integrate[Exp[-(x0-(x1-k*x2))*(x0-(x1-k*x2))/(2*s0*s0)]*Exp[-(x1*t1-k*x2)],{x2,-1,1}]]
563 // No analytical solution
565 //Simplify[Integrate[Exp[-(x0-k0*xd)*(x0-k0*xd)/(2*s0*s0)-(x1-xt-k1*xd)*(x1-xt-k1*xd)/(2*s1*s1)]*Exp[-kt*xt]/(s0*s1),{xd,-1/2,1/2},{xt,0,Infinity}]]