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 // Field with Magnetic Field map
22 //-------------------------------------------------------------------------
28 #include "AliMagFDM.h"
33 //_______________________________________________________________________
34 AliMagFDM::AliMagFDM():
63 // Default constructor for the Dipole field
67 //_______________________________________________________________________
68 AliMagFDM::AliMagFDM(const char *name, const char *title, const Int_t integ,
69 const Float_t factor, const Float_t fmax):
70 AliMagF(name,title,integ,factor,fmax),
99 // Standard constructor for the Dipole field
106 "Field Map for Muon Arm from IP till muon filter %s created: map= %d, integ= %d, factor= %f, file=%s\n",
107 fName.Data(), fMap ,integ,factor,fTitle.Data());
111 //_______________________________________________________________________
112 void AliMagFDM::Field(Float_t *xfi, Float_t *b)
115 // Main routine to compute the field in a point
117 const Double_t keps=0.1E-06;
118 const Double_t kPI2=2.*TMath::Pi();
119 const Double_t kone=1;
129 const Double_t kfZbg=502.92; // Start of Map using in z
130 const Double_t kfZL3=600; // Beginning of L3 door in z
139 Double_t zp1, zp2,xp1,xp2,yp1,yp2;
140 Double_t zz1, zz2,yy1,yy2,x2,x1;
142 // --- start the map fiel from z = 502.92 cm ---
148 // printf("x[0] %f,x[1] %f,x[2] %f\n",x[0],x[1],x[2]);
150 Double_t rr=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
154 if ( (-700<x[2] && x[2]<=kfZbg &&
155 (x[0]*x[0]+(x[1]+30)*(x[1]+30))< 560*560)
156 || (kfZbg<x[2] && x[2]<=kfZL3 && (rr>rPmax*100 && rr< 560)) )
163 xL3[1]=(x[1]+30)/100;
167 if (TMath::Abs(xL3[0])<=0.1E-06) xL3[0]=TMath::Sign(0.1E-05,xL3[0]);
168 if (TMath::Abs(xL3[1])<=0.1E-06) xL3[1]=TMath::Sign(0.1E-05,xL3[1]);
170 Double_t xminn=xL3[2]*fAx1+fCx1;
171 Double_t xmaxx=xL3[2]*fAx2+fCx2;
172 Double_t zCmin,zCmax,yCmin,yCmax;
178 if ((kfZbg/100<xL3[2] && xL3[2]<=zCmin && r0<=rPmax) || ((zCmin<xL3[2] && xL3[2] <= zCmax ) && (yCmin<xL3[1] && xL3[1]<= yCmax) && (xminn<xL3[0] && xL3[0] <= xmaxx)))
182 if (kfZbg/100<xL3[2] && xL3[2]<=zCmin && r0<=rPmax)
184 //--------------------- Polar part ----------------------
189 Double_t alp1,alp2,alp3;
190 Double_t zpz,rp,fip,cphi;
197 kp0=FZ(zpz, fZp ,fZpdl,kpi,fZpl) ;
198 zp2=(zpz-fZp[kp0])/(fZp[kp0+1]-fZp[kp0]);
201 cphi=TMath::Abs(yyp/r0);
204 printf("xL3[0] %e, xL3[1] %e, xL3[2] %e, yyp %e, r0 %e, cphi %e\n",xL3[0],xL3[1],xL3[2],yyp,r0,cphi);
208 ph0=TMath::ACos(cphi);
209 if (xL3[0] < 0 && yyp > 0 ) {ph0=kPI2/2 - ph0;}
210 if (xL3[0] < 0 && yyp < 0 ) {ph0=kPI2/2 + ph0;}
211 if (xL3[0] > 0 && yyp < 0 ) {ph0=kPI2 - ph0;}
212 if (ph0 > kPI2) { ph0=ph0 - kPI2;}
214 printf("xL3[0] %e, xL3[1] %e, xL3[2] %e, yyp %e, r0 %e, ph0 %e\n",xL3[0],xL3[1],xL3[2],yyp,r0,ph0);
217 mp0=FZ(fip,fPhi,fPhid ,mpi,fPhin);
218 xp2=(fip-fPhi[mp0])/(fPhi[mp0+1]-fPhi[mp0]);
230 bint[0]=(zp1*fBpx[kp0][0][0] + zp2*fBpx[kp0+1][0][0])*10;
231 bint[1]=(zp1*fBpy[kp0][0][0] + zp2*fBpy[kp0+1][0][0])*10;
232 bint[2]=(zp1*fBpz[kp0][0][0] + zp2*fBpz[kp0+1][0][0])*10;
236 alp2= fB[0][0][mp0]*yyp + fB[0][1][mp0]*xL3[0];
237 alp3= fB[1][0][mp0]*yyp + fB[1][1][mp0]*xL3[0];
238 alp1= kone - alp2 - alp3;
240 for (jb=0; jb<3 ; jb++)
243 bint[jb] = Ba(iKvar,zp1,zp2,alp1,alp2,alp3, kp0,mp0)*10 ;
245 } // end of keps <=r0
251 lp0=FZ(rp,fR ,fRdel,lpi,fRn);
252 yp2=(rp-fR[lp0])/(fR[lp0+1]-fR[lp0]);
255 for (jb=0; jb<3 ; jb++)
258 bint[jb] = Bb(zp1,zp2,yp1,yp2,xp1,xp2,iKvar,kp0,lp0,mp0)*10 ;
269 //-------------- Cartensian part ------------------
273 Double_t xx1, xx2,dx, xxx ,xXl;
280 xx1 = fAx1*xL3[2] + fCx1;
281 xx2 = fAx2*xL3[2] + fCx2;
284 k0=FZ(zzc, fZc ,fZdel, kci, fZl);
285 zz2=(zzc-fZc[k0])/(fZc[k0+1]-fZc[k0]);
289 l0=FZ(yyc, fY , fYdel,lci,fYl);
290 yy2=(yyc-fY[l0])/(fY[l0+1]-fY[l0]);;
297 if(xL3[0]<(xx1+m0*dx) || xL3[0] >(xx1+(m0+1)*dx))
300 printf(" m0 %d, m0+1 %d\n",m0,m0+1);
303 x2=(xL3[0]-( xx1+m0*dx))/dx;
306 for (jb=3; jb<6; jb++)
309 bint[jb-3] = Bb(zz1,zz2,yy1,yy2,x1,x2,iKvar,k0, l0, m0)*10 ;
320 printf("Unknown map of Dipole region %d\n",fMap);
325 //This is the ZDC part
326 Float_t rad2=x[0]*x[0]+x[1]*x[1];
327 if(x[2]>kCORBEG2 && x[2]<kCOREND2){
332 else if(x[2]>kZ1BEG && x[2]<kZ1END){
338 else if(x[2]>kZ2BEG && x[2]<kZ2END){
344 else if(x[2]>kZ3BEG && x[2]<kZ3END){
350 else if(x[2]>kZ4BEG && x[2]<kZ4END){
356 else if(x[2]>kD1BEG && x[2]<kD1END){
361 else if(x[2]>kD2BEG && x[2]<kD2END){
362 if(((x[0]-kXCEN1D2)*(x[0]-kXCEN1D2)+(x[1]-kYCEN1D2)*(x[1]-kYCEN1D2))<kD2RA2
363 || ((x[0]-kXCEN2D2)*(x[0]-kXCEN2D2)+(x[1]-kYCEN2D2)*(x[1]-kYCEN2D2))<kD2RA2){
377 //_______________________________________________________________________
378 Int_t AliMagFDM::FZ(Double_t temp, Float_t *Ar,
379 Float_t delu, Int_t ik,Int_t nk) const
382 // Quest of a point position at x,y,z (Cartensian) and R,Phi,z (Polar) axises
396 for(l=ikj; l<nk; l++)
409 //_______________________________________________________________________
410 Double_t AliMagFDM::Ba(Int_t kaai,Double_t zaa1, Double_t zaa2,
411 Double_t alf1, Double_t alf2, Double_t alf3,
412 Int_t kaa, Int_t maa)
415 // Calculation of field componet for case (keps <r0<= fRdel) at a given axis
417 Double_t fa11,fa12,fa13;
418 Double_t fa21,fa22,fa23;
424 fa11 = fBpx[kaa][0][0];
425 fa12 = fBpx[kaa][0][maa];
426 fa13 = fBpx[kaa][0][maa+1];
427 fa21 = fBpx[kaa+1][0][0];
428 fa22 = fBpx[kaa+1][0][maa];
429 fa23 = fBpx[kaa+1][0][maa+1];
432 fa11 = fBpy[kaa][0][0];
433 fa12 = fBpy[kaa][0][maa];
434 fa13 = fBpy[kaa][0][maa+1];
435 fa21 = fBpy[kaa+1][0][0];
436 fa22 = fBpy[kaa+1][0][maa];
437 fa23 = fBpy[kaa+1][0][maa+1];
440 fa11 = fBpz[kaa][0][0];
441 fa12 = fBpz[kaa][0][maa];
442 fa13 = fBpz[kaa][0][maa+1];
443 fa21 = fBpz[kaa+1][0][0];
444 fa22 = fBpz[kaa+1][0][maa];
445 fa23 = fBpz[kaa+1][0][maa+1];
448 Fatal("Ba","Invalid value of kaai %d\n",kaai);
451 faY1=alf1*fa11+alf2*fa12+alf3*fa13;
452 faY2=alf1*fa21+alf2*fa22+alf3*fa23;
453 bba = zaa1*faY1+zaa2*faY2;
458 //_______________________________________________________________________
459 Double_t AliMagFDM::Bb(Double_t z1,Double_t z2, Double_t y1,Double_t y2,
460 Double_t x1,Double_t x2, Int_t kv, Int_t k, Int_t l, Int_t m)
463 // Calculation of field componet at a given axis (general case)
465 Double_t fy1, fy2, ffy;
466 Double_t gy1,gy2,ggy;
468 Double_t bf11,bf12,bf21,bf22;
469 Double_t bg11,bg12,bg21,bg22;
472 /*-----------------Polar part ------------------*/
477 bf12=fBpx[k+1][l][m];
478 bf21=fBpx[k+1][l+1][m];
479 bf22=fBpx[k][l+1][m];
481 bg11=fBpx[k][l][m+1];
482 bg12=fBpx[k+1][l][m+1];
483 bg21=fBpx[k+1][l+1][m+1];
484 bg22=fBpx[k][l+1][m+1];
489 bf12=fBpy[k+1][l][m];
490 bf21=fBpy[k+1][l+1][m];
491 bf22=fBpy[k][l+1][m];
493 bg11=fBpy[k][l][m+1];
494 bg12=fBpy[k+1][l][m+1];
495 bg21=fBpy[k+1][l+1][m+1];
496 bg22=fBpy[k][l+1][m+1];
501 bf12=fBpz[k+1][l][m];
502 bf21=fBpz[k+1][l+1][m];
503 bf22=fBpz[k][l+1][m];
505 bg11=fBpz[k][l][m+1];
506 bg12=fBpz[k+1][l][m+1];
507 bg21=fBpz[k+1][l+1][m+1];
508 bg22=fBpz[k][l+1][m+1];
510 /*-----------------Cartensian part ---------------*/
514 bf12=fBcx[k+1][l][m];
515 bf21=fBcx[k+1][l+1][m];
516 bf22=fBcx[k][l+1][m];
518 bg11=fBcx[k][l][m+1];
519 bg12=fBcx[k+1][l][m+1];
520 bg21=fBcx[k+1][l+1][m+1];
521 bg22=fBcx[k][l+1][m+1];
526 bf12=fBcy[k+1][l][m];
527 bf21=fBcy[k+1][l+1][m];
528 bf22=fBcy[k][l+1][m];
530 bg11=fBcy[k][l][m+1];
531 bg12=fBcy[k+1][l][m+1];
532 bg21=fBcy[k+1][l+1][m+1];
533 bg22=fBcy[k][l+1][m+1];
538 bf12=fBcz[k+1][l][m];
539 bf21=fBcz[k+1][l+1][m];
540 bf22=fBcz[k][l+1][m];
542 bg11=fBcz[k][l][m+1];
543 bg12=fBcz[k+1][l][m+1];
544 bg21=fBcz[k+1][l+1][m+1];
545 bg22=fBcz[k][l+1][m+1];
549 Fatal("Bb","Invalid value of kv %d\n",kv);
556 fy2=z2*bf21+z1* bf22;
560 gy1 = z1*bg11+z2*bg12;
561 gy2 = z2*bg21+z1*bg22;
562 ggy= y1*gy1 + y2*gy2;
570 //_______________________________________________________________________
571 void AliMagFDM::ReadField()
574 // Method to read the magnetic field from file
579 Float_t zzp, rr,phii;
580 Float_t zz, yy, bx,by,bz,bb;
583 printf("Reading Magnetic Field %s from file %s\n",fName.Data(),fTitle.Data());
584 fname = gSystem->ExpandPathName(fTitle.Data());
585 magfile=fopen(fname,"r");
588 printf("Cartensian part\n");
594 fscanf(magfile,"%d %d %d ",&fYl, &fXl, &fZl);
596 printf("fYl %d, fXl %d, fZl %d\n",fYl, fXl, fZl);
598 for (ik=0; ik<fZl; ik++)
601 fscanf(magfile, " %e ", &zz);
606 for (ik=0; ik<fYl; ik++)
608 fscanf(magfile, " %e ", &yy);
612 for (ik=0; ik<81; ik++)
614 printf("fZc %e,fY %e\n", fZc[ik],fY[ik]);
617 fscanf(magfile," %e %e %e %e %e %e %e %e %e %e %e ", &fYdel,&fXdel,&fZdel,&fZmax,&fZmin,&fYmax,&fYmin,&fAx1,&fCx1,&fAx2,&fCx2);
619 printf("fYdel %e, fXdel %e, fZdel %e\n",fYdel,fXdel,fZdel);
620 printf("fZmax %e, fZmin %e, fYmax %e,fYmin %e\n",fZmax,fZmin,fYmax,fYmin);
621 printf("fAx1 %e, fCx1 %e, fAx2 %e, fCx %e\n",fAx1,fCx1,fAx2,fCx2);
623 for (il=0; il<44; il++) {
624 for (im=0; im<81; im++) {
625 for (ik=0; ik<81; ik++) {
627 fscanf(magfile, " %e ", &by);
633 for (il=0; il<44; il++) {
634 for (im=0; im<81; im++) {
635 for (ik=0; ik<81; ik++) {
637 fscanf(magfile, " %e ", &bx);
643 for (il=0; il<44; il++) {
644 for (im=0; im<81; im++) {
645 for (ik=0; ik<81; ik++) {
647 fscanf(magfile, " %e ", &bz);
652 //---------------------- Polar part ---------------------------------
654 printf("Polar part\n");
655 fscanf(magfile,"%d %d %d ", &fZpl, &fRn, &fPhin);
656 printf("fZpl %d, fRn %d, fPhin %d\n",fZpl,fRn,fPhin);
658 printf(" fZp array\n");
660 for (ik=0; ik<51; ik++)
662 fscanf(magfile, " %e ", &zzp);
664 printf(" %e\n",fZp[ik]);
667 printf(" fR array\n");
669 for (ik=0; ik<10; ik++)
671 fscanf(magfile, " %e ", &rr);
673 printf(" %e\n",fR[ik]);
676 // printf("fPhi array\n");
678 for (il=0; il<33; il++)
680 fscanf(magfile, " %e ", &phii);
682 // printf(" %e\n",fPhi[il]);
685 fscanf(magfile," %e %e %e %e %e %e %e ",&fZpdl,&fPhid,&fRdel,&fZpmx,&fZpmn,&fRmax, &fRmin);
687 printf("fZpdl %e, fPhid %e, fRdel %e, fZpmx %e, fZpmn %e,fRmax %e,fRmin %e \n", fZpdl,fPhid, fRdel,fZpmx, fZpmn,fRmax, fRmin);
690 for (il=0; il<33; il++) {
691 for (im=0; im<10; im++) {
692 for (ik=0; ik<51; ik++) {
693 fscanf(magfile, " %e ", &by);
699 for (il=0; il<33; il++) {
700 for (im=0; im<10; im++) {
701 for (ik=0; ik<51; ik++) {
702 fscanf(magfile, " %e ", &bx);
709 for (il=0; il<33; il++) {
710 for (im=0; im<10; im++) {
711 for (ik=0; ik<51; ik++) {
712 fscanf(magfile, " %e ", &bz);
719 for (il=0; il<32; il++) {
720 for (im=0; im<2; im++) {
721 for (ik=0; ik<2; ik++) {
722 fscanf(magfile, " %e ", &bb);
729 printf("File %s not found !\n",fTitle.Data());