1 ///////////////////////////////////////////////////////////////////////////////
3 // Pad response function object in two dimesions //
4 // This class contains the basic functions for the //
5 // calculation of PRF according generic charge distribution //
6 // In Update function object calculate table of response function //
7 // in discrete x and y position //
8 // This table is used for interpolation od response function in any position //
9 // (function GetPRF) //
11 // Origin: Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk //
13 ///////////////////////////////////////////////////////////////////////////////
15 #include "AliTPCPRF2D.h"
24 #include "TPaveText.h"
27 extern TStyle * gStyle;
29 static const Float_t sqrt12=3.46;
30 static const Int_t NPRF = 100;
33 static Double_t funGauss2D(Double_t *x, Double_t * par)
35 return ( TMath::Exp(-(x[0]*x[0])/(2*par[0]*par[0]))*
36 TMath::Exp(-(x[1]*x[1])/(2*par[1]*par[1])));
40 static Double_t funCosh2D(Double_t *x, Double_t * par)
42 return ( 1/(TMath::CosH(3.14159*x[0]/(2*par[0]))*
43 TMath::CosH(3.14159*x[1]/(2*par[1]))));
46 static Double_t funGati2D(Double_t *x, Double_t * par)
48 //par[1] = is equal to k3X
49 //par[0] is equal to pad wire distance
51 Float_t K3R=TMath::Sqrt(K3);
52 Float_t K2=(TMath::Pi()/2)*(1-K3R/2.);
53 Float_t K1=K2*K3R/(4*TMath::ATan(K3R));
54 Float_t l=x[0]/par[0];
55 Float_t tan2=TMath::TanH(K2*l);
57 Float_t res = K1*(1-tan2)/(1+K3*tan2);
58 //par[4] = is equal to k3Y
61 K2=(TMath::Pi()/2)*(1-K3R/2.);
62 K1=K2*K3R/(4*TMath::ATan(K3R));
64 tan2=TMath::TanH(K2*l);
66 res = res*K1*(1-tan2)/(1+K3*tan2);
71 ///////////////////////////////////////////////////////////////////////////
72 ///////////////////////////////////////////////////////////////////////////
73 ///////////////////////////////////////////////////////////////////////////
74 ///////////////////////////////////////////////////////////////////////////
78 AliTPCPRF2D::AliTPCPRF2D()
89 //chewron default values
91 SetChevron(0.2,0.0,1.0);
93 // SetGauss(0.22,0.22,1);
96 AliTPCPRF2D::~AliTPCPRF2D()
98 if (ffcharge!=0) delete [] ffcharge;
99 if (fGRF !=0 ) fGRF->Delete();
102 void AliTPCPRF2D::SetY(Float_t y1, Float_t y2, Int_t nYdiv)
105 //set virtual line position
106 //first and last line and number of lines
108 if (ffcharge!=0) delete [] ffcharge;
109 ffcharge = new Float_t[fNPRF*fNYdiv];
114 void AliTPCPRF2D::SetPad(Float_t width, Float_t height)
116 //set base chevron parameters
120 void AliTPCPRF2D::SetChevron(Float_t hstep,
124 //set shaping of chewron parameters
130 void AliTPCPRF2D::SetChParam(Float_t width, Float_t height,
131 Float_t hstep, Float_t shifty, Float_t fac)
133 SetPad(width,height);
134 SetChevron(hstep,shifty,fac);
138 Float_t AliTPCPRF2D::GetPRF(Float_t xin, Float_t yin, Bool_t inter)
140 if (ffcharge==0) return 0;
141 // Float_t y=Float_t(fNYdiv-1)*(yin-fY1)/(fY2-fY1);
142 //transform position to "wire position"
143 Float_t y=fDYtoWire*(yin-fY1);
144 if (fNYdiv == 1) y=fY1;
145 //normaly it find nearest line charge
147 Int_t i=Int_t(0.5+y);
148 if (y<0) i=Int_t(-0.5+y);
149 if ((i<0) || (i>=fNYdiv) ) return 0;
150 fcharge = &(ffcharge[i*fNPRF]);
151 return GetPRFActiv(xin);
154 //make interpolation from more fore lines
156 if ((i<0) || (i>=fNYdiv) ) return 0;
162 fcharge =&(ffcharge[(i-1)*fNPRF]);
163 z0 = GetPRFActiv(xin);
165 fcharge =&(ffcharge[i*fNPRF]);
168 fcharge =&(ffcharge[(i+1)*fNPRF]);
169 z2 = GetPRFActiv(xin);
172 fcharge =&(ffcharge[(i+2)*fNPRF]);
173 z3 = GetPRFActiv(xin);
182 Float_t dy=y-Float_t(i);
183 Float_t res = a+b*dy+c*dy*dy+d*dy*dy*dy;
184 //Float_t res = z1*(1-dy)+z2*dy;
191 Float_t AliTPCPRF2D::GetPRFActiv(Float_t xin)
194 //return splaine aproximaton
195 Float_t x = (xin*fDStepM1)+fNPRF/2;
198 if ( (i>0) && ((i+2)<fNPRF)) {
201 b = (fcharge[i+1]-fcharge[i-1])*0.5;
202 K = fcharge[i+1]-a-b;
203 L = (fcharge[i+2]-fcharge[i])*0.5-b;
206 Float_t dx=x-Float_t(i);
207 Float_t res = a+b*dx+c*dx*dx+d*dx*dx*dx;
214 Float_t AliTPCPRF2D::GetGRF(Float_t xin, Float_t yin)
217 return fkNorm*fGRF->Eval(xin,yin)/fInteg;
223 void AliTPCPRF2D::SetParam( TF2 * GRF, Float_t kNorm,
224 Float_t sigmaX, Float_t sigmaY)
226 if (fGRF !=0 ) fGRF->Delete();
229 if (sigmaX ==0) sigmaX=(fWidth+fK*fHeightS)/sqrt12;
230 if (sigmaY ==0) sigmaY=(fWidth+fK*fHeightS)/sqrt12;
233 fDStep = TMath::Sqrt(sigmaX*sigmaX+fWidth*fWidth/6.)/10.;
235 sprintf(fType,"User");
239 void AliTPCPRF2D::SetGauss(Float_t sigmaX, Float_t sigmaY,
243 if (fGRF !=0 ) fGRF->Delete();
244 fGRF = new TF2("fun",funGauss2D,-5.,5.,-5.,5.,4);
248 funParam[3]=fHeightS;
251 fGRF->SetParameters(funParam);
252 fDStep = TMath::Sqrt(sigmaX*sigmaX+fWidth*fWidth/6.)/10.;
253 //by default I set the step as one tenth of sigma
255 sprintf(fType,"Gauss");
258 void AliTPCPRF2D::SetCosh(Float_t sigmaX, Float_t sigmaY,
262 if (fGRF !=0 ) fGRF->Delete();
263 fGRF = new TF2("fun", funCosh2D,-5.,5.,-5.,5.,4);
267 funParam[3]=fHeightS;
268 fGRF->SetParameters(funParam);
271 fDStep = TMath::Sqrt(sigmaX*sigmaX+fWidth*fWidth/6.)/10.;
272 //by default I set the step as one tenth of sigma
274 sprintf(fType,"Cosh");
277 void AliTPCPRF2D::SetGati(Float_t K3X, Float_t K3Y,
282 if (fGRF !=0 ) fGRF->Delete();
283 fGRF = new TF2("fun", funGati2D,-5.,5.,-5.,5.,5);
286 fPadDistance=padDistance;
287 funParam[0]=padDistance;
290 funParam[3]=fHeightS;
292 fGRF->SetParameters(funParam);
293 forigsigmaX=padDistance;
294 forigsigmaY=padDistance;
295 fDStep = TMath::Sqrt(padDistance*padDistance+fWidth*fWidth/6.)/10.;
296 //by default I set the step as one tenth of sigma
298 sprintf(fType,"Gati");
303 void AliTPCPRF2D::Update()
305 for (Int_t i=0; i<fNYdiv; i++){
306 if (fNYdiv == 1) fActualY = fY1;
308 fActualY = fY1+Float_t(i)*(fY2-fY1)/Float_t(fNYdiv-1);
309 fcharge = &(ffcharge[i*fNPRF]);
316 void AliTPCPRF2D::Update1()
323 for (i =0; i<fNPRF;i++) fcharge[i] = 0;
324 if ( fGRF == 0 ) return;
325 ////////////////////////////////////////////////////////
326 //I'm waiting for normal integral
327 //in this moment only sum
328 Float_t x2= 4*forigsigmaX;
329 Float_t y2= 4*forigsigmaY;
330 Float_t dx = forigsigmaX/Float_t(fNdiv*6);
331 Float_t dy = forigsigmaY/Float_t(fNdiv*6);
333 for (x=0.;x<x2;x+=dx)
334 for (Float_t y=0;y<y2;y+=dy) fInteg+=fGRF->Eval(x,y)*dx*dy;
336 /////////////////////////////////////////////////////
339 if ( fInteg == 0 ) fInteg = 1;
341 //integrate charge over pad for different distance of pad
342 for (i =0; i<fNPRF;i++)
343 { //x in cm fWidth in cm
345 Float_t xch = fDStep * (Float_t)(i-fNPRF/2);
348 for (Float_t y=-fHeightFull/2.-fShiftY;
349 y<fHeightFull/2.;y+=fHeightS){
350 Float_t y2=TMath::Min((y+fHeightS),Float_t(fHeightFull/2.));
351 Float_t y1=TMath::Max((y),Float_t(-fHeightFull/2.));
355 x1 = (y2-y1)*fK-(fWidth+fK*fHeightS)/2.;
357 x1 =-(fWidth+fK*fHeightS)/2. ;
358 Float_t x2=x1+fWidth;
362 if ((x2-x1)*fNdiv<forigsigmaX) dx=(x2-x1);
364 dx= forigsigmaX/Float_t(fNdiv);
365 dx = (x2-x1)/Float_t(Int_t(3+(x2-x1)/dx));
368 if ((y2-y1)*fNdiv<forigsigmaY) dy=(y2-y1);
370 dy= forigsigmaY/Float_t(fNdiv);
371 dy = (y2-y1)/Float_t(Int_t(3+(y2-y1)/dy));
374 for (x=x1;x<x2;x+=dx)
375 for (Float_t y=y1;y<y2;y+=dy){
376 if ( (y>(fActualY-(4.0*forigsigmaY))) &&
377 (y<(fActualY+(4.0*forigsigmaY)))){
378 Float_t xt=x-k*fK*(y-y1);
379 if ((TMath::Abs(xch-xt)<4*forigsigmaX)){
381 Float_t z0=fGRF->Eval(xch-(xt+dx/2.),fActualY-(y+dy/2.));
383 Float_t z1=fGRF->Eval(xch-(xt+dx/2.),fActualY-y);
384 Float_t z2=fGRF->Eval(xch-xt,fActualY-(y+dy/2.));
385 Float_t z3=fGRF->Eval(xch-(xt-dx/2.),fActualY-y);
386 Float_t z4=fGRF->Eval(xch-xt,fActualY-(y-dy/2.));
393 // Float_t a=(z1-z3)/2;
394 // Float_t b=(z2-z4)/2;
395 Float_t c= (z3+z1-2*z0)/2.;
396 Float_t d= (z2+z4-2*z0)/2.;
397 Float_t z= (z0+c/12.+d/12.);
399 //Float_t z= fGRF->Eval(xch-xt,fActualY-y);
400 if (z>0.) fcharge[i]+=z*dx*dy/fInteg;
412 for (x =-fNPRF*fDStep; x<fNPRF*fDStep;x+=fDStep)
413 { //x in cm fWidth in cm
414 Float_t weight = GetPRFActiv(x);
421 fSigmaX = TMath::Sqrt(fSigmaX/sum-mean*mean);
424 //calculate conversion coefitient to convert position to virtual wire
425 fDYtoWire=Float_t(fNYdiv-1)/(fY2-fY1);
429 void AliTPCPRF2D::Streamer(TBuffer &R__b)
431 // Stream an object of class AliTPCPRF2D
433 if (R__b.IsReading()) {
434 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
435 TObject::Streamer(R__b);
436 //read chewron parameters
444 //read charge parameters
455 R__b >> fPadDistance;
463 if (strncmp(fType,"User",3)==0){
467 if (strncmp(fType,"Gauss",3)==0)
468 fGRF = new TF2("fun",funGauss2D,-5.,5.,-5.,5.,4);
469 if (strncmp(fType,"Cosh",3)==0)
470 fGRF = new TF2("fun",funCosh2D,-5.,5.,-5.,5.,4);
471 if (strncmp(fType,"Gati",3)==0)
472 fGRF = new TF2("fun",funGati2D,-5.,5.,-5.,5.,5);
474 //read interpolation parameters
480 if (ffcharge!=0) delete [] ffcharge;
481 ffcharge = new Float_t[fNPRF*fNYdiv];
482 R__b.ReadFastArray(ffcharge,fNPRF*fNYdiv);
483 R__b.ReadFastArray(funParam,5);
484 if (fGRF!=0) fGRF->SetParameters(funParam);
485 //calculate conversion coefitient to convert position to virtual wire
486 fDYtoWire=Float_t(fNYdiv-1)/(fY2-fY1);
489 R__b.WriteVersion(AliTPCPRF2D::IsA());
490 TObject::Streamer(R__b);
491 //write chewron parameters
499 //write charge parameters
511 R__b << fPadDistance;
514 if (strncmp(fType,"User",3)==0) R__b <<fGRF;
515 //write interpolation parameters
521 R__b.WriteFastArray(ffcharge,fNPRF*fNYdiv);
522 R__b.WriteFastArray(funParam,5);
529 void AliTPCPRF2D::DrawX(Float_t x1 ,Float_t x2,Float_t y, Bool_t inter)
531 if (fGRF==0) return ;
534 TCanvas * c1 = new TCanvas("canPRF","Pad response function",700,900);
536 TPad * pad1 = new TPad("pad1PRF","",0.05,0.61,0.95,0.97,21);
538 TPad * pad2 = new TPad("pad2PRF","",0.05,0.22,0.95,0.60,21);
543 gStyle->SetOptFit(1);
544 gStyle->SetOptStat(0);
545 sprintf(s,"PRF response function for chevron pad");
546 TH1F * hPRFc = new TH1F("hPRFc",s,N+1,x1,x2);
551 for (Float_t i = 0;i<N+1;i++)
553 x+=(x2-x1)/Float_t(N);
554 y1 = GetPRF(x,y,inter);
559 fGRF->SetRange(x1,x1,x2,x2);
563 // hPRFo->Fit("gaus");
564 gStyle->SetOptStat(1);
568 TPaveText * comment = new TPaveText(0.05,0.02,0.95,0.20,"NDC");
569 comment->SetTextAlign(12);
570 comment->SetFillColor(42);
571 TText *title = comment->AddText("Chevron pad parameters:");
572 title->SetTextSize(0.03);
573 sprintf(s,"Full height of pad: %2.2f",fHeightFull);
575 sprintf(s,"Height of one chevron unit h: %2.2f cm",2*fHeightS);
577 sprintf(s,"Width of one chevron unit w: %2.2f cm",fWidth);
579 sprintf(s,"Overlap factor: %2.2f",fK*fHeightS/fWidth);
581 sprintf(s,"Y position: %2.2f ",y);
583 sprintf(s,"Sigma x of original distribution: %2.2f ",forigsigmaX);
585 sprintf(s,"Sigma y of original distribution: %2.2f ",forigsigmaY);
587 sprintf(s,"Type of original distribution: %s ",fType);
594 void AliTPCPRF2D::Draw(Float_t x1 ,Float_t x2,Float_t y1, Float_t y2,
595 Bool_t inter, Int_t Nx, Int_t Ny)
598 if (fGRF==0) return ;
599 TCanvas * c1 = new TCanvas("canPRF","Pad response function",700,900);
601 TPad * pad1 = new TPad("pad1PRF","",0.05,0.61,0.95,0.97,21);
603 TPad * pad2 = new TPad("pad2PRF","",0.05,0.22,0.95,0.60,21);
608 gStyle->SetOptFit(1);
609 gStyle->SetOptStat(0);
610 sprintf(s,"PRF response function for chevron pad");
611 TH2F * hPRFc = new TH2F("hPRFc",s,Nx+1,x1,x2,Ny+1,y1,y2);
612 Float_t dx=(x2-x1)/Float_t(Nx);
613 Float_t dy=(y2-y1)/Float_t(Ny) ;
616 for ( x = x1;x<=x2;x+=dx){
617 for(y = y1;y<=y2;y+=dy)
619 z = GetPRF(x,y,inter);
624 fGRF->SetRange(x1,y1,x2,y2);
628 // hPRFo->Fit("gaus");
629 gStyle->SetOptStat(1);
631 hPRFc->Draw("lego2");
633 TPaveText * comment = new TPaveText(0.05,0.02,0.95,0.20,"NDC");
634 comment->SetTextAlign(12);
635 comment->SetFillColor(42);
636 TText *title = comment->AddText("Chevron pad parameters:");
637 title->SetTextSize(0.03);
638 sprintf(s,"Full height of pad: %2.2f",fHeightFull);
640 sprintf(s,"Height of one chevron unit h: %2.2f cm",2*fHeightS);
642 sprintf(s,"Width of one chevron unit w: %2.2f cm",fWidth);
644 sprintf(s,"Overlap factor: %2.2f",fK*fHeightS/fWidth);
646 sprintf(s,"Sigma x of original distribution: %2.2f ",forigsigmaX);
648 sprintf(s,"Sigma y of original distribution: %2.2f ",forigsigmaY);
650 sprintf(s,"Type of original distribution: %s ",fType);
655 void AliTPCPRF2D::DrawDist(Float_t x1 ,Float_t x2,Float_t y1, Float_t y2,
656 Bool_t inter, Int_t Nx, Int_t Ny, Float_t thr)
658 const Float_t minth=0.00001;
659 if (thr<minth) thr=minth;
661 if (fGRF==0) return ;
662 TCanvas * c1 = new TCanvas("padDistortion","COG distortion",700,900);
664 TPad * pad1 = new TPad("CHARGE","",0.05,0.61,0.95,0.97,21);
666 TPad * pad2 = new TPad("dist","",0.05,0.22,0.95,0.60,21);
671 gStyle->SetOptFit(1);
672 gStyle->SetOptStat(0);
673 sprintf(s,"COG distortion (threshold=%2.2f)",thr);
674 TH2F * hPRFDist = new TH2F("hDistortion",s,Nx+1,x1,x2,Ny+1,y1,y2);
675 Float_t dx=(x2-x1)/Float_t(Nx);
676 Float_t dy=(y2-y1)/Float_t(Ny) ;
679 for ( x = x1;x<(x2+dx/2.);x+=dx)
680 for(y = y1;y<=(y2+dx/2.);y+=dy)
684 for (Float_t padx=-fWidth;padx<(fWidth*1.1);padx+=fWidth)
686 z = GetPRF(x-padx,y,inter);
694 ddx = (x-(sumx/sum));
697 if (TMath::Abs(ddx)<10) hPRFDist->Fill(x,y,ddx);
700 fGRF->SetRange(x1,y1,x2,y2);
704 // hPRFo->Fit("gaus");
705 // gStyle->SetOptStat(1);
707 hPRFDist->Draw("lego2");
710 TPaveText * comment = new TPaveText(0.05,0.02,0.95,0.20,"NDC");
711 comment->SetTextAlign(12);
712 comment->SetFillColor(42);
713 // TText *title = comment->AddText("Distortion of COG method");
714 // title->SetTextSize(0.03);
715 TText * title = comment->AddText("Chevron pad parameters:");
716 title->SetTextSize(0.03);
717 sprintf(s,"Full height of pad: %2.2f",fHeightFull);
719 sprintf(s,"Height of one chevron unit h: %2.2f cm",2*fHeightS);
721 sprintf(s,"Width of one chevron unit w: %2.2f cm",fWidth);
723 sprintf(s,"Overlap factor: %2.2f",fK*fHeightS/fWidth);
725 sprintf(s,"Sigma x of original distribution: %2.2f ",forigsigmaX);
727 sprintf(s,"Sigma y of original distribution: %2.2f ",forigsigmaY);
729 sprintf(s,"Type of original distribution: %s ",fType);