24 #include "TTreeStream.h"
26 #include "TLinearFitter.h"
45 for (Int_t i=0; i<3; i++){
56 fUseLinear(useLinear),
61 for (Int_t i=0; i<3; i++){
64 fWorkspace=
new TTreeSRedirector(Form(
"%s.root",name));
79 if (
fIs2D) nfunctions = 1+(maxFreq)*8;
80 if (!
fIs2D) nfunctions = 1+(maxFreq)*8;
84 fFitCovar =
new TMatrixD(nfunctions,nfunctions);
92 for (Int_t ifx=0; ifx<=1; ifx++)
93 for (Int_t ify=0; ify<=1; ify++)
94 for (Int_t ifz=0; ifz<=1; ifz++){
95 if (
fIs2D && ifz>0)
continue;
96 if ((ifx+ify+ifz)==0)
continue;
97 if ((ifx+ify+ifz)>1)
continue;
100 fitF(counter,2)= ify;
101 fitF(counter,3)= ifz;
106 for (Int_t ihyp=0; ihyp<2; ihyp++)
107 for (Int_t ifx=-maxFreq; ifx<=maxFreq; ifx++)
108 for (Int_t ify=-maxFreq; ify<=maxFreq; ify++){
109 if (TMath::Abs(ify)!=TMath::Abs(ifx))
continue;
110 if (ifx==0)
continue;
111 if (ify==0)
continue;
112 fitF(counter,0)= 2+ihyp;
113 fitF(counter,1)= ifx;
114 fitF(counter,2)= ify;
137 if (
fIs2D)
fScale=0.5*(TMath::Abs(x1-x0)+TMath::Abs(y1-y0));
138 if (!
fIs2D)
fScale=0.5*(TMath::Abs(x1-x0)+TMath::Abs(y1-y0)+TMath::Abs(z1-z0));
149 Double_t deltaX = (x1-x0);
150 Double_t deltaY = (y1-y0);
151 Double_t deltaZ = (z1-z0);
152 Double_t deltaV = (v1-
v0);
153 for (Int_t ipoint=0; ipoint<
npoints; ipoint++){
154 Double_t bpoint=gRandom->Rndm();
155 Double_t x = x0+deltaX*bpoint;
156 Double_t y = y0+deltaY*bpoint;
157 Double_t z = z0+deltaZ*bpoint;
158 Double_t v = v0+deltaV*bpoint;
159 (*fWorkspace)<<
"Boundary"<<
175 Double_t
AliTPCEfield::Field(Int_t ftype, Double_t ifx, Double_t ify, Double_t ifz, Double_t x, Double_t y, Double_t z){
179 Double_t fx=1,fy=1,fz=1;
180 const Double_t kEps=0.01;
182 if (ftype==0)
return 1;
184 if (TMath::Nint(ifx)==1)
return x;
185 if (TMath::Nint(ify)==1)
return y;
186 if (TMath::Nint(ifz)==1)
return z;
188 Double_t pi = TMath::Pi();
189 if (ifx>kEps) fx = (ftype==2) ?
SinHNorm(ifx*pi*x,TMath::Abs(ifx*pi)): TMath::Sin(ifx*pi*x);
190 if (ifx<-kEps) fx = (ftype==2) ?
CosHNorm(ifx*pi*x,TMath::Abs(ifx*pi)): TMath::Cos(ifx*pi*x);
192 if (ify>kEps) fy = (ftype==3) ?
SinHNorm(ify*pi*y,TMath::Abs(ify*pi)): TMath::Sin(ify*pi*y);
193 if (ify<-kEps) fy = (ftype==3) ?
CosHNorm(ify*pi*y,TMath::Abs(ify*pi)): TMath::Cos(ify*pi*y);
195 if (ifz>kEps) fz = (ftype==4) ?
SinHNorm(ifz*pi*z,TMath::Abs(ifz*pi)): TMath::Sin(ifz*pi*z);
196 if (ifz<-kEps) fz = (ftype==4) ?
CosHNorm(ifz*pi*z,TMath::Abs(ifz*pi)): TMath::Cos(ifz*pi*z);
197 (*fWorkspace)<<
"eval"<<
213 Double_t
AliTPCEfield::FieldDn(Int_t ftype, Double_t ifx, Double_t ify, Double_t ifz, Int_t dn, Double_t x, Double_t y, Double_t z){
217 Double_t fx=1,fy=1,fz=1;
218 const Double_t kEps=0.01;
220 if (ftype==0)
return 0.;
223 if (TMath::Nint(ifx)==1 &&dn==0) value=1.;
224 if (TMath::Nint(ify)==1 &&dn==1) value=1.;
225 if (TMath::Nint(ifz)==1 &&dn==2) value=1.;
228 Double_t pi = TMath::Pi();
229 if (ifx>kEps) fx = (ftype==2) ?
SinHNorm(ifx*pi*x,TMath::Abs(ifx*pi)): TMath::Sin(ifx*pi*x);
230 if (ifx<-kEps) fx = (ftype==2) ?
CosHNorm(ifx*pi*x,TMath::Abs(ifx*pi)): TMath::Cos(ifx*pi*x);
232 if (ify>kEps) fy = (ftype==3) ?
SinHNorm(ify*pi*y,TMath::Abs(ify*pi)): TMath::Sin(ify*pi*y);
233 if (ify<-kEps) fy = (ftype==3) ?
CosHNorm(ify*pi*y,TMath::Abs(ify*pi)): TMath::Cos(ify*pi*y);
235 if (ifz>kEps) fz = (ftype==4) ?
SinHNorm(ifz*pi*z,TMath::Abs(ifz*pi)): TMath::Sin(ifz*pi*z);
236 if (ifz<-kEps) fz = (ftype==4) ?
CosHNorm(ifz*pi*z,-TMath::Abs(ifz*pi)): TMath::Cos(ifz*pi*z);
239 if (ifx>kEps) fx = (ftype==2) ?
CosHNorm(ifx*pi*x,TMath::Abs(ifx*pi)): TMath::Cos(ifx*pi*x);
240 if (ifx<-kEps) fx = (ftype==2) ?
SinHNorm(ifx*pi*x,TMath::Abs(ifx*pi)): -TMath::Sin(ifx*pi*x);
244 if (ify>kEps) fy = (ftype==3) ?
CosHNorm(ify*pi*y,TMath::Abs(ify*pi)): TMath::Cos(ify*pi*y);
245 if (ify<-kEps) fy = (ftype==3) ?
SinHNorm(ify*pi*y,TMath::Abs(ify*pi)): -TMath::Sin(ify*pi*y);
249 if (ifz>kEps) fz = (ftype==4) ?
CosHNorm(ifz*pi*z,TMath::Abs(ifz*pi)): TMath::Cos(ifz*pi*z);
250 if (ifz<-kEps) fz = (ftype==4) ?
SinHNorm(ifz*pi*z,TMath::Abs(ifz*pi)): -TMath::Sin(ifz*pi*z);
268 Int_t fid = TMath::Nint(
mat(ifun,0));
269 Double_t ifx = (
mat(ifun,1));
270 Double_t ify = (
mat(ifun,2));
271 Double_t ifz = (
mat(ifun,3));
273 if (type==0)
return Field(fid,ifx,ify,ifz, x, y,z);
274 if (type>0)
return FieldDn(fid,ifx,ify,ifz,type-1, x, y,z);
291 for (Int_t ifun=0; ifun<nfun; ifun++){
292 if (type==0) value+=(*fFitParam)[ifun]*
EvalField(ifun,lx,ly,lz,type);
293 if (type>0) value+=2*(*fFitParam)[ifun]*
EvalField(ifun,lx,ly,lz,type)/
fScale;
310 Double_t *fun =
new Double_t[nfun];
311 fFitter=
new TLinearFitter(nfun, Form(
"hyp%d", nfun-1));
314 Int_t
npoints = tree->GetEntries();
315 Int_t *indexes =
new Int_t[
npoints];
316 Double_t *rindex =
new Double_t[
npoints];
319 Double_t x=0, y=0, z=0, v=0;
320 tree->SetBranchAddress(
"x",&x);
321 tree->SetBranchAddress(
"y",&y);
322 tree->SetBranchAddress(
"z",&z);
323 tree->SetBranchAddress(
"v",&v);
324 TMatrixD valMatrix(npoints,4);
325 for (Int_t ipoint=0; ipoint<
npoints; ipoint++){
326 tree->GetEntry(ipoint);
330 valMatrix(ipoint,3)=v;
331 rindex[ipoint]=gRandom->Rndm();
333 TMath::Sort(npoints,rindex,indexes);
334 for (Int_t jpoint=0; jpoint<
npoints; jpoint++){
335 Int_t ipoint=indexes[jpoint];
337 Double_t lx= valMatrix(ipoint,0);
338 Double_t ly= valMatrix(ipoint,1);
339 Double_t lz= valMatrix(ipoint,2);
340 Double_t value = valMatrix(ipoint,3);
341 for (Int_t ifun=1; ifun<nfun; ifun++){
342 Double_t ffun=
EvalField(ifun,lx,ly,lz,0);
345 fFitter->AddPoint(fun,value,1);
351 (*fWorkspace)<<
"fitGlobal"<<
357 for (Int_t ifun=1; ifun<nfun; ifun++){
368 Int_t nrows = matrix.GetNrows();
369 TMatrixD *
mat =
new TMatrixD(nrows,nrows);
370 for (Int_t irow=0; irow<nrows; irow++)
371 for (Int_t icol=0; icol<nrows; icol++){
372 (*mat)(irow,icol)= matrix(irow,icol)/TMath::Sqrt(matrix(irow,irow)*matrix(icol,icol));
385 for (Double_t x =
fMin[0]+stepSize; x<=
fMax[0]-stepSize; x+=gridSize){
386 for (Double_t y =
fMin[1]+stepSize; y<=
fMax[1]-stepSize; y+=gridSize)
387 for (Double_t z =
fMin[2]; z<=
fMax[2]; z+=gridSize){
390 Double_t v =
Eval(x,y,z,0);
391 Double_t ex =
Eval(x,y,z,1);
392 Double_t ey =
Eval(x,y,z,2);
393 Double_t ez =
Eval(x,y,z,3);
394 Double_t dexdx = (
Eval(x,y,z,1)-
Eval(x-stepSize,y,z,1))/stepSize;
395 Double_t deydy = (
Eval(x,y,z,2)-
Eval(x,y-stepSize,z,2))/stepSize;
396 Double_t dezdz = (
Eval(x,y,z,3)-
Eval(x,y,z-stepSize,3))/stepSize;
397 (*fWorkspace)<<
"dumpField"<<
413 for (Double_t x =
fMin[0]+stepSize; x<=
fMax[0]-stepSize; x+=gridSize){
417 for (Double_t y =
fMin[1]+0.2; y<=
fMax[1]-stepSize; y+=step)
418 for (Double_t z =
fMin[2]; z<=
fMax[2]; z+=gridSize){
421 Double_t v =
Eval(x,y+step*0.5,z,0);
422 Double_t ex =
Eval(x,y+step*0.5,z,1);
423 Double_t ey =
Eval(x,y+step*0.5,z,2);
424 Double_t ez =
Eval(x,y+step*0.5,z,3);
427 sumExEy+=(ex/ey)*step;
428 (*fWorkspace)<<
"dumpDistortion"<<
481 Double_t xmin=85, xmax=245;
482 Double_t ymin=0, ymax=250, deltaY=0.1*ymax;
485 field->
SetRange(xmin, xmax,ymin,ymax,0,0);
487 p0[0]=xmin; p0[1]=ymax+deltaY; p0[2]=0; p0[3]=vup;
488 p1[0]=xmax; p1[1]=ymax-deltaY; p1[2]=0; p1[3]=vup;
489 field->
AddBoundaryLine(p0[0],p0[1], p0[2],p0[3],p1[0],p1[1], p1[2],p1[3],1,npoints);
491 p0[0]=xmin; p0[1]=ymin+deltaY; p0[2]=0; p0[3]=0;
492 p1[0]=xmin; p1[1]=ymax+deltaY; p1[2]=0; p1[3]=vup;
493 field->
AddBoundaryLine(p0[0],p0[1], p0[2],p0[3],p1[0],p1[1], p1[2],p1[3],2,npoints);
495 p0[0]=xmax; p0[1]=ymin-deltaY; p0[2]=0; p0[3]=0;
496 p1[0]=xmax; p1[1]=ymax-deltaY; p1[2]=0; p1[3]=vup;
497 field->
AddBoundaryLine(p0[0],p0[1], p0[2],p0[3],p1[0],p1[1], p1[2],p1[3],3,npoints);
500 p0[0]=xmin; p0[1]=deltaY; p0[2]=0; p0[3]=-0;
501 p1[0]=xmax; p1[1]=-deltaY; p1[2]=0; p1[3]=0;
502 field->
AddBoundaryLine(p0[0],p0[1], p0[2],p0[3],p1[0],p1[1], p1[2],p1[3],4,npoints);
void DumpField(Double_t gridSize=5, Double_t step=0.5)
Double_t EvalField(Int_t ifun, Double_t x, Double_t y, Double_t z, Int_t type=0)
Bool_t fIs2D
flag for 2D field
Double_t fScale
scaling factor
static Double_t EvalS(Double_t x, Double_t y, Double_t z, Int_t type=0)
void AddBoundaryLine(Double_t x0, Double_t y0, Double_t z0, Double_t v0, Double_t x1, Double_t y1, Double_t z1, Double_t v1, Int_t id=0, Int_t npoints=100)
void SetRange(Double_t x0, Double_t x1, Double_t y0, Double_t y1, Double_t z00, Double_t z1=0)
Double_t fMin[3]
range of coordinates from Min to Max
TMatrixD * fFitFunctions
fit function description
Double_t FieldDn(Int_t ftype, Double_t ifx, Double_t ify, Double_t ifz, Int_t dn, Double_t x, Double_t y, Double_t z)
Double_t Field(Int_t ftype, Double_t ifx, Double_t ify, Double_t ifz, Double_t x, Double_t y, Double_t z)
TMatrixD * fFitCovar
fit covariance
Double_t Eval(Double_t x, Double_t y, Double_t z, Int_t type=0)
Int_t fMaxFreq
maximal frequency of expansion
Double_t CosHNorm(Double_t x, Double_t norm)
TLinearFitter * fFitter
linear fitter - temporary solution - integrals to be calculated
TMatrixD * MakeCorrelation(TMatrixD &matrix)
void MakeFitFunctions(Int_t maxFreq)
TTreeSRedirector * fWorkspace
! workspace
TVectorD * fFitParam
fit parameters - coeficients
TTree * GetTree(const char *tname="Boundary")
void MakeTPC2DExample(AliTPCEfield *field)
Double_t SinHNorm(Double_t x, Double_t norm)
Calculation of the electric field.
static AliTPCEfield * fgInstance
instance of fied - for visualization
Bool_t fUseLinear
flag to use also linear term of the field