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 **************************************************************************/
20 ///////////////////////////////////////////////////////////////////////////////
22 // Pad response function object in two dimesions //
23 // This class contains the basic functions for the //
24 // calculation of PRF according generic charge distribution //
25 // In Update function object calculate table of response function //
26 // in discrete x and y position //
27 // This table is used for interpolation od response function in any position //
28 // (function GetPRF) //
30 // Origin: Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk //
32 ///////////////////////////////////////////////////////////////////////////////
34 #include "AliTPCPRF2D.h"
43 #include "TPaveText.h"
46 extern TStyle * gStyle;
48 static const Float_t sqrt12=3.46;
49 static const Int_t NPRF = 100;
52 static Double_t funGauss2D(Double_t *x, Double_t * par)
54 return ( TMath::Exp(-(x[0]*x[0])/(2*par[0]*par[0]))*
55 TMath::Exp(-(x[1]*x[1])/(2*par[1]*par[1])));
59 static Double_t funCosh2D(Double_t *x, Double_t * par)
61 return ( 1/(TMath::CosH(3.14159*x[0]/(2*par[0]))*
62 TMath::CosH(3.14159*x[1]/(2*par[1]))));
65 static Double_t funGati2D(Double_t *x, Double_t * par)
67 //par[1] = is equal to k3X
68 //par[0] is equal to pad wire distance
70 Float_t K3R=TMath::Sqrt(K3);
71 Float_t K2=(TMath::Pi()/2)*(1-K3R/2.);
72 Float_t K1=K2*K3R/(4*TMath::ATan(K3R));
73 Float_t l=x[0]/par[0];
74 Float_t tan2=TMath::TanH(K2*l);
76 Float_t res = K1*(1-tan2)/(1+K3*tan2);
77 //par[4] = is equal to k3Y
80 K2=(TMath::Pi()/2)*(1-K3R/2.);
81 K1=K2*K3R/(4*TMath::ATan(K3R));
83 tan2=TMath::TanH(K2*l);
85 res = res*K1*(1-tan2)/(1+K3*tan2);
90 ///////////////////////////////////////////////////////////////////////////
91 ///////////////////////////////////////////////////////////////////////////
92 ///////////////////////////////////////////////////////////////////////////
93 ///////////////////////////////////////////////////////////////////////////
97 AliTPCPRF2D::AliTPCPRF2D()
108 //chewron default values
110 SetChevron(0.2,0.0,1.0);
112 // SetGauss(0.22,0.22,1);
115 AliTPCPRF2D::~AliTPCPRF2D()
117 if (ffcharge!=0) delete [] ffcharge;
118 if (fGRF !=0 ) fGRF->Delete();
121 void AliTPCPRF2D::SetY(Float_t y1, Float_t y2, Int_t nYdiv)
124 //set virtual line position
125 //first and last line and number of lines
127 if (ffcharge!=0) delete [] ffcharge;
128 ffcharge = new Float_t[fNPRF*fNYdiv];
133 void AliTPCPRF2D::SetPad(Float_t width, Float_t height)
135 //set base chevron parameters
139 void AliTPCPRF2D::SetChevron(Float_t hstep,
143 //set shaping of chewron parameters
149 void AliTPCPRF2D::SetChParam(Float_t width, Float_t height,
150 Float_t hstep, Float_t shifty, Float_t fac)
152 SetPad(width,height);
153 SetChevron(hstep,shifty,fac);
157 Float_t AliTPCPRF2D::GetPRF(Float_t xin, Float_t yin, Bool_t inter)
159 if (ffcharge==0) return 0;
160 // Float_t y=Float_t(fNYdiv-1)*(yin-fY1)/(fY2-fY1);
161 //transform position to "wire position"
162 Float_t y=fDYtoWire*(yin-fY1);
163 if (fNYdiv == 1) y=fY1;
164 //normaly it find nearest line charge
166 Int_t i=Int_t(0.5+y);
167 if (y<0) i=Int_t(-0.5+y);
168 if ((i<0) || (i>=fNYdiv) ) return 0;
169 fcharge = &(ffcharge[i*fNPRF]);
170 return GetPRFActiv(xin);
173 //make interpolation from more fore lines
175 if ((i<0) || (i>=fNYdiv) ) return 0;
181 fcharge =&(ffcharge[(i-1)*fNPRF]);
182 z0 = GetPRFActiv(xin);
184 fcharge =&(ffcharge[i*fNPRF]);
187 fcharge =&(ffcharge[(i+1)*fNPRF]);
188 z2 = GetPRFActiv(xin);
191 fcharge =&(ffcharge[(i+2)*fNPRF]);
192 z3 = GetPRFActiv(xin);
201 Float_t dy=y-Float_t(i);
202 Float_t res = a+b*dy+c*dy*dy+d*dy*dy*dy;
203 //Float_t res = z1*(1-dy)+z2*dy;
210 Float_t AliTPCPRF2D::GetPRFActiv(Float_t xin)
213 //return splaine aproximaton
214 Float_t x = (xin*fDStepM1)+fNPRF/2;
217 if ( (i>0) && ((i+2)<fNPRF)) {
220 b = (fcharge[i+1]-fcharge[i-1])*0.5;
221 K = fcharge[i+1]-a-b;
222 L = (fcharge[i+2]-fcharge[i])*0.5-b;
225 Float_t dx=x-Float_t(i);
226 Float_t res = a+b*dx+c*dx*dx+d*dx*dx*dx;
233 Float_t AliTPCPRF2D::GetGRF(Float_t xin, Float_t yin)
236 return fkNorm*fGRF->Eval(xin,yin)/fInteg;
242 void AliTPCPRF2D::SetParam( TF2 * GRF, Float_t kNorm,
243 Float_t sigmaX, Float_t sigmaY)
245 if (fGRF !=0 ) fGRF->Delete();
248 if (sigmaX ==0) sigmaX=(fWidth+fK*fHeightS)/sqrt12;
249 if (sigmaY ==0) sigmaY=(fWidth+fK*fHeightS)/sqrt12;
252 fDStep = TMath::Sqrt(sigmaX*sigmaX+fWidth*fWidth/6.)/10.;
254 sprintf(fType,"User");
258 void AliTPCPRF2D::SetGauss(Float_t sigmaX, Float_t sigmaY,
262 if (fGRF !=0 ) fGRF->Delete();
263 fGRF = new TF2("fun",funGauss2D,-5.,5.,-5.,5.,4);
267 funParam[3]=fHeightS;
270 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,"Gauss");
277 void AliTPCPRF2D::SetCosh(Float_t sigmaX, Float_t sigmaY,
281 if (fGRF !=0 ) fGRF->Delete();
282 fGRF = new TF2("fun", funCosh2D,-5.,5.,-5.,5.,4);
286 funParam[3]=fHeightS;
287 fGRF->SetParameters(funParam);
290 fDStep = TMath::Sqrt(sigmaX*sigmaX+fWidth*fWidth/6.)/10.;
291 //by default I set the step as one tenth of sigma
293 sprintf(fType,"Cosh");
296 void AliTPCPRF2D::SetGati(Float_t K3X, Float_t K3Y,
301 if (fGRF !=0 ) fGRF->Delete();
302 fGRF = new TF2("fun", funGati2D,-5.,5.,-5.,5.,5);
305 fPadDistance=padDistance;
306 funParam[0]=padDistance;
309 funParam[3]=fHeightS;
311 fGRF->SetParameters(funParam);
312 forigsigmaX=padDistance;
313 forigsigmaY=padDistance;
314 fDStep = TMath::Sqrt(padDistance*padDistance+fWidth*fWidth/6.)/10.;
315 //by default I set the step as one tenth of sigma
317 sprintf(fType,"Gati");
322 void AliTPCPRF2D::Update()
324 for (Int_t i=0; i<fNYdiv; i++){
325 if (fNYdiv == 1) fActualY = fY1;
327 fActualY = fY1+Float_t(i)*(fY2-fY1)/Float_t(fNYdiv-1);
328 fcharge = &(ffcharge[i*fNPRF]);
335 void AliTPCPRF2D::Update1()
342 for (i =0; i<fNPRF;i++) fcharge[i] = 0;
343 if ( fGRF == 0 ) return;
344 ////////////////////////////////////////////////////////
345 //I'm waiting for normal integral
346 //in this moment only sum
347 Float_t x2= 4*forigsigmaX;
348 Float_t y2= 4*forigsigmaY;
349 Float_t dx = forigsigmaX/Float_t(fNdiv*6);
350 Float_t dy = forigsigmaY/Float_t(fNdiv*6);
352 for (x=0.;x<x2;x+=dx)
353 for (Float_t y=0;y<y2;y+=dy) fInteg+=fGRF->Eval(x,y)*dx*dy;
355 /////////////////////////////////////////////////////
358 if ( fInteg == 0 ) fInteg = 1;
360 //integrate charge over pad for different distance of pad
361 for (i =0; i<fNPRF;i++)
362 { //x in cm fWidth in cm
364 Float_t xch = fDStep * (Float_t)(i-fNPRF/2);
367 for (Float_t y=-fHeightFull/2.-fShiftY;
368 y<fHeightFull/2.;y+=fHeightS){
369 Float_t y2=TMath::Min((y+fHeightS),Float_t(fHeightFull/2.));
370 Float_t y1=TMath::Max((y),Float_t(-fHeightFull/2.));
374 x1 = (y2-y1)*fK-(fWidth+fK*fHeightS)/2.;
376 x1 =-(fWidth+fK*fHeightS)/2. ;
377 Float_t x2=x1+fWidth;
381 if ((x2-x1)*fNdiv<forigsigmaX) dx=(x2-x1);
383 dx= forigsigmaX/Float_t(fNdiv);
384 dx = (x2-x1)/Float_t(Int_t(3+(x2-x1)/dx));
387 if ((y2-y1)*fNdiv<forigsigmaY) dy=(y2-y1);
389 dy= forigsigmaY/Float_t(fNdiv);
390 dy = (y2-y1)/Float_t(Int_t(3+(y2-y1)/dy));
393 for (x=x1;x<x2;x+=dx)
394 for (Float_t y=y1;y<y2;y+=dy){
395 if ( (y>(fActualY-(4.0*forigsigmaY))) &&
396 (y<(fActualY+(4.0*forigsigmaY)))){
397 Float_t xt=x-k*fK*(y-y1);
398 if ((TMath::Abs(xch-xt)<4*forigsigmaX)){
400 Float_t z0=fGRF->Eval(xch-(xt+dx/2.),fActualY-(y+dy/2.));
402 Float_t z1=fGRF->Eval(xch-(xt+dx/2.),fActualY-y);
403 Float_t z2=fGRF->Eval(xch-xt,fActualY-(y+dy/2.));
404 Float_t z3=fGRF->Eval(xch-(xt-dx/2.),fActualY-y);
405 Float_t z4=fGRF->Eval(xch-xt,fActualY-(y-dy/2.));
412 // Float_t a=(z1-z3)/2;
413 // Float_t b=(z2-z4)/2;
414 Float_t c= (z3+z1-2*z0)/2.;
415 Float_t d= (z2+z4-2*z0)/2.;
416 Float_t z= (z0+c/12.+d/12.);
418 //Float_t z= fGRF->Eval(xch-xt,fActualY-y);
419 if (z>0.) fcharge[i]+=z*dx*dy/fInteg;
431 for (x =-fNPRF*fDStep; x<fNPRF*fDStep;x+=fDStep)
432 { //x in cm fWidth in cm
433 Float_t weight = GetPRFActiv(x);
440 fSigmaX = TMath::Sqrt(fSigmaX/sum-mean*mean);
443 //calculate conversion coefitient to convert position to virtual wire
444 fDYtoWire=Float_t(fNYdiv-1)/(fY2-fY1);
448 void AliTPCPRF2D::Streamer(TBuffer &R__b)
450 // Stream an object of class AliTPCPRF2D
452 if (R__b.IsReading()) {
453 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
454 TObject::Streamer(R__b);
455 //read chewron parameters
463 //read charge parameters
474 R__b >> fPadDistance;
482 if (strncmp(fType,"User",3)==0){
486 if (strncmp(fType,"Gauss",3)==0)
487 fGRF = new TF2("fun",funGauss2D,-5.,5.,-5.,5.,4);
488 if (strncmp(fType,"Cosh",3)==0)
489 fGRF = new TF2("fun",funCosh2D,-5.,5.,-5.,5.,4);
490 if (strncmp(fType,"Gati",3)==0)
491 fGRF = new TF2("fun",funGati2D,-5.,5.,-5.,5.,5);
493 //read interpolation parameters
499 if (ffcharge!=0) delete [] ffcharge;
500 ffcharge = new Float_t[fNPRF*fNYdiv];
501 R__b.ReadFastArray(ffcharge,fNPRF*fNYdiv);
502 R__b.ReadFastArray(funParam,5);
503 if (fGRF!=0) fGRF->SetParameters(funParam);
504 //calculate conversion coefitient to convert position to virtual wire
505 fDYtoWire=Float_t(fNYdiv-1)/(fY2-fY1);
508 R__b.WriteVersion(AliTPCPRF2D::IsA());
509 TObject::Streamer(R__b);
510 //write chewron parameters
518 //write charge parameters
530 R__b << fPadDistance;
533 if (strncmp(fType,"User",3)==0) R__b <<fGRF;
534 //write interpolation parameters
540 R__b.WriteFastArray(ffcharge,fNPRF*fNYdiv);
541 R__b.WriteFastArray(funParam,5);
548 void AliTPCPRF2D::DrawX(Float_t x1 ,Float_t x2,Float_t y, Bool_t inter)
550 if (fGRF==0) return ;
553 TCanvas * c1 = new TCanvas("canPRF","Pad response function",700,900);
555 TPad * pad1 = new TPad("pad1PRF","",0.05,0.61,0.95,0.97,21);
557 TPad * pad2 = new TPad("pad2PRF","",0.05,0.22,0.95,0.60,21);
562 gStyle->SetOptFit(1);
563 gStyle->SetOptStat(0);
564 sprintf(s,"PRF response function for chevron pad");
565 TH1F * hPRFc = new TH1F("hPRFc",s,N+1,x1,x2);
570 for (Float_t i = 0;i<N+1;i++)
572 x+=(x2-x1)/Float_t(N);
573 y1 = GetPRF(x,y,inter);
578 fGRF->SetRange(x1,x1,x2,x2);
582 // hPRFo->Fit("gaus");
583 gStyle->SetOptStat(1);
587 TPaveText * comment = new TPaveText(0.05,0.02,0.95,0.20,"NDC");
588 comment->SetTextAlign(12);
589 comment->SetFillColor(42);
590 TText *title = comment->AddText("Chevron pad parameters:");
591 title->SetTextSize(0.03);
592 sprintf(s,"Full height of pad: %2.2f",fHeightFull);
594 sprintf(s,"Height of one chevron unit h: %2.2f cm",2*fHeightS);
596 sprintf(s,"Width of one chevron unit w: %2.2f cm",fWidth);
598 sprintf(s,"Overlap factor: %2.2f",fK*fHeightS/fWidth);
600 sprintf(s,"Y position: %2.2f ",y);
602 sprintf(s,"Sigma x of original distribution: %2.2f ",forigsigmaX);
604 sprintf(s,"Sigma y of original distribution: %2.2f ",forigsigmaY);
606 sprintf(s,"Type of original distribution: %s ",fType);
613 void AliTPCPRF2D::Draw(Float_t x1 ,Float_t x2,Float_t y1, Float_t y2,
614 Bool_t inter, Int_t Nx, Int_t Ny)
617 if (fGRF==0) return ;
618 TCanvas * c1 = new TCanvas("canPRF","Pad response function",700,900);
620 TPad * pad1 = new TPad("pad1PRF","",0.05,0.61,0.95,0.97,21);
622 TPad * pad2 = new TPad("pad2PRF","",0.05,0.22,0.95,0.60,21);
627 gStyle->SetOptFit(1);
628 gStyle->SetOptStat(0);
629 sprintf(s,"PRF response function for chevron pad");
630 TH2F * hPRFc = new TH2F("hPRFc",s,Nx+1,x1,x2,Ny+1,y1,y2);
631 Float_t dx=(x2-x1)/Float_t(Nx);
632 Float_t dy=(y2-y1)/Float_t(Ny) ;
635 for ( x = x1;x<=x2;x+=dx){
636 for(y = y1;y<=y2;y+=dy)
638 z = GetPRF(x,y,inter);
643 fGRF->SetRange(x1,y1,x2,y2);
647 // hPRFo->Fit("gaus");
648 gStyle->SetOptStat(1);
650 hPRFc->Draw("lego2");
652 TPaveText * comment = new TPaveText(0.05,0.02,0.95,0.20,"NDC");
653 comment->SetTextAlign(12);
654 comment->SetFillColor(42);
655 TText *title = comment->AddText("Chevron pad parameters:");
656 title->SetTextSize(0.03);
657 sprintf(s,"Full height of pad: %2.2f",fHeightFull);
659 sprintf(s,"Height of one chevron unit h: %2.2f cm",2*fHeightS);
661 sprintf(s,"Width of one chevron unit w: %2.2f cm",fWidth);
663 sprintf(s,"Overlap factor: %2.2f",fK*fHeightS/fWidth);
665 sprintf(s,"Sigma x of original distribution: %2.2f ",forigsigmaX);
667 sprintf(s,"Sigma y of original distribution: %2.2f ",forigsigmaY);
669 sprintf(s,"Type of original distribution: %s ",fType);
674 void AliTPCPRF2D::DrawDist(Float_t x1 ,Float_t x2,Float_t y1, Float_t y2,
675 Bool_t inter, Int_t Nx, Int_t Ny, Float_t thr)
677 const Float_t minth=0.00001;
678 if (thr<minth) thr=minth;
680 if (fGRF==0) return ;
681 TCanvas * c1 = new TCanvas("padDistortion","COG distortion",700,900);
683 TPad * pad1 = new TPad("CHARGE","",0.05,0.61,0.95,0.97,21);
685 TPad * pad2 = new TPad("dist","",0.05,0.22,0.95,0.60,21);
690 gStyle->SetOptFit(1);
691 gStyle->SetOptStat(0);
692 sprintf(s,"COG distortion (threshold=%2.2f)",thr);
693 TH2F * hPRFDist = new TH2F("hDistortion",s,Nx+1,x1,x2,Ny+1,y1,y2);
694 Float_t dx=(x2-x1)/Float_t(Nx);
695 Float_t dy=(y2-y1)/Float_t(Ny) ;
698 for ( x = x1;x<(x2+dx/2.);x+=dx)
699 for(y = y1;y<=(y2+dx/2.);y+=dy)
703 for (Float_t padx=-fWidth;padx<(fWidth*1.1);padx+=fWidth)
705 z = GetPRF(x-padx,y,inter);
713 ddx = (x-(sumx/sum));
716 if (TMath::Abs(ddx)<10) hPRFDist->Fill(x,y,ddx);
719 fGRF->SetRange(x1,y1,x2,y2);
723 // hPRFo->Fit("gaus");
724 // gStyle->SetOptStat(1);
726 hPRFDist->Draw("lego2");
729 TPaveText * comment = new TPaveText(0.05,0.02,0.95,0.20,"NDC");
730 comment->SetTextAlign(12);
731 comment->SetFillColor(42);
732 // TText *title = comment->AddText("Distortion of COG method");
733 // title->SetTextSize(0.03);
734 TText * title = comment->AddText("Chevron pad parameters:");
735 title->SetTextSize(0.03);
736 sprintf(s,"Full height of pad: %2.2f",fHeightFull);
738 sprintf(s,"Height of one chevron unit h: %2.2f cm",2*fHeightS);
740 sprintf(s,"Width of one chevron unit w: %2.2f cm",fWidth);
742 sprintf(s,"Overlap factor: %2.2f",fK*fHeightS/fWidth);
744 sprintf(s,"Sigma x of original distribution: %2.2f ",forigsigmaX);
746 sprintf(s,"Sigma y of original distribution: %2.2f ",forigsigmaY);
748 sprintf(s,"Type of original distribution: %s ",fType);