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 //-------------------------------------------------------------------------
19 // Field with Magnetic Field map
20 // Used by AliRun class
22 //-------------------------------------------------------------------------
26 #include "AliMagFDM.h"
30 //_______________________________________________________________________
31 AliMagFDM::AliMagFDM():
60 // Default constructor for the Dipole field
64 //_______________________________________________________________________
65 AliMagFDM::AliMagFDM(const char *name, const char *title, Int_t integ,
66 Float_t factor, Float_t fmax):
67 AliMagFC(name,title,integ,factor,fmax),
96 // Standard constructor for the Dipole field
103 "Field Map for Muon Arm from IP till muon filter %s created: map= %d, integ= %d, factor= %f, file=%s\n",
104 fName.Data(), fMap ,integ,factor,fTitle.Data());
108 //_______________________________________________________________________
109 void AliMagFDM::Field(Float_t *xfi, Float_t *b)
112 // Main routine to compute the field in a point
114 const Double_t keps=0.1E-06;
115 const Double_t kPI2=2.*TMath::Pi();
116 const Double_t kone=1;
126 const Double_t kfZbg=502.92; // Start of Map using in z
127 const Double_t kfZL3=600; // Beginning of L3 door in z
136 Double_t zp1, zp2,xp1,xp2,yp1,yp2;
137 Double_t zz1, zz2,yy1,yy2,x2,x1;
139 // --- start the map fiel from z = 502.92 cm ---
141 // This map has been calculated in a coordinate system in which the muon spectrometer sits at z > 0
142 // Transfor correspondingly.
149 // printf("x[0] %f,x[1] %f,x[2] %f\n",x[0],x[1],x[2]);
151 Double_t rr=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
155 if ( (-700<x[2] && x[2]<=kfZbg &&
156 (x[0]*x[0]+(x[1]+30)*(x[1]+30))< 560*560)
157 || (kfZbg<x[2] && x[2]<=kfZL3 && (rr>rPmax*100 && rr< 560)) )
164 xL3[1]=(x[1]+30)/100;
168 if (TMath::Abs(xL3[0])<=0.1E-06) xL3[0]=TMath::Sign(0.1E-05,xL3[0]);
169 if (TMath::Abs(xL3[1])<=0.1E-06) xL3[1]=TMath::Sign(0.1E-05,xL3[1]);
171 Double_t xminn=xL3[2]*fAx1+fCx1;
172 Double_t xmaxx=xL3[2]*fAx2+fCx2;
173 Double_t zCmin,zCmax,yCmin,yCmax;
179 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)))
183 if (kfZbg/100<xL3[2] && xL3[2]<=zCmin && r0<=rPmax)
185 //--------------------- Polar part ----------------------
190 Double_t alp1,alp2,alp3;
191 Double_t zpz,rp,fip,cphi;
198 kp0=FZ(zpz, fZp ,fZpdl,kpi,fZpl) ;
199 zp2=(zpz-fZp[kp0])/(fZp[kp0+1]-fZp[kp0]);
202 cphi=TMath::Abs(yyp/r0);
205 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);
209 ph0=TMath::ACos(cphi);
210 if (xL3[0] < 0 && yyp > 0 ) {ph0=kPI2/2 - ph0;}
211 if (xL3[0] < 0 && yyp < 0 ) {ph0=kPI2/2 + ph0;}
212 if (xL3[0] > 0 && yyp < 0 ) {ph0=kPI2 - ph0;}
213 if (ph0 > kPI2) { ph0=ph0 - kPI2;}
215 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);
218 mp0=FZ(fip,fPhi,fPhid ,mpi,fPhin);
219 xp2=(fip-fPhi[mp0])/(fPhi[mp0+1]-fPhi[mp0]);
231 bint[0]=(zp1*fBpx[kp0][0][0] + zp2*fBpx[kp0+1][0][0])*10;
232 bint[1]=(zp1*fBpy[kp0][0][0] + zp2*fBpy[kp0+1][0][0])*10;
233 bint[2]=(zp1*fBpz[kp0][0][0] + zp2*fBpz[kp0+1][0][0])*10;
237 alp2= fB[0][0][mp0]*yyp + fB[0][1][mp0]*xL3[0];
238 alp3= fB[1][0][mp0]*yyp + fB[1][1][mp0]*xL3[0];
239 alp1= kone - alp2 - alp3;
241 for (jb=0; jb<3 ; jb++)
244 bint[jb] = Ba(iKvar,zp1,zp2,alp1,alp2,alp3, kp0,mp0)*10 ;
246 } // end of keps <=r0
252 lp0=FZ(rp,fR ,fRdel,lpi,fRn);
253 yp2=(rp-fR[lp0])/(fR[lp0+1]-fR[lp0]);
256 for (jb=0; jb<3 ; jb++)
259 bint[jb] = Bb(zp1,zp2,yp1,yp2,xp1,xp2,iKvar,kp0,lp0,mp0)*10 ;
270 //-------------- Cartensian part ------------------
274 Double_t xx1, xx2,dx, xxx ,xXl;
281 xx1 = fAx1*xL3[2] + fCx1;
282 xx2 = fAx2*xL3[2] + fCx2;
285 k0=FZ(zzc, fZc ,fZdel, kci, fZl);
286 zz2=(zzc-fZc[k0])/(fZc[k0+1]-fZc[k0]);
290 l0=FZ(yyc, fY , fYdel,lci,fYl);
291 yy2=(yyc-fY[l0])/(fY[l0+1]-fY[l0]);;
298 if(xL3[0]<(xx1+m0*dx) || xL3[0] >(xx1+(m0+1)*dx))
301 printf(" m0 %d, m0+1 %d\n",m0,m0+1);
304 x2=(xL3[0]-( xx1+m0*dx))/dx;
307 for (jb=3; jb<6; jb++)
310 bint[jb-3] = Bb(zz1,zz2,yy1,yy2,x1,x2,iKvar,k0, l0, m0)*10 ;
321 printf("Unknown map of Dipole region %d\n",fMap);
336 //_______________________________________________________________________
337 Int_t AliMagFDM::FZ(Double_t temp, Float_t *Ar,
338 Float_t delu, Int_t ik,Int_t nk) const
341 // Quest of a point position at x,y,z (Cartensian) and R,Phi,z (Polar) axises
355 for(l=ikj; l<nk; l++)
368 //_______________________________________________________________________
369 Double_t AliMagFDM::Ba(Int_t kaai,Double_t zaa1, Double_t zaa2,
370 Double_t alf1, Double_t alf2, Double_t alf3,
371 Int_t kaa, Int_t maa)
374 // Calculation of field componet for case (keps <r0<= fRdel) at a given axis
376 Double_t fa11=0,fa12=0,fa13=0;
377 Double_t fa21=0,fa22=0,fa23=0;
378 Double_t faY1=0,faY2=0;
383 fa11 = fBpx[kaa][0][0];
384 fa12 = fBpx[kaa][0][maa];
385 fa13 = fBpx[kaa][0][maa+1];
386 fa21 = fBpx[kaa+1][0][0];
387 fa22 = fBpx[kaa+1][0][maa];
388 fa23 = fBpx[kaa+1][0][maa+1];
391 fa11 = fBpy[kaa][0][0];
392 fa12 = fBpy[kaa][0][maa];
393 fa13 = fBpy[kaa][0][maa+1];
394 fa21 = fBpy[kaa+1][0][0];
395 fa22 = fBpy[kaa+1][0][maa];
396 fa23 = fBpy[kaa+1][0][maa+1];
399 fa11 = fBpz[kaa][0][0];
400 fa12 = fBpz[kaa][0][maa];
401 fa13 = fBpz[kaa][0][maa+1];
402 fa21 = fBpz[kaa+1][0][0];
403 fa22 = fBpz[kaa+1][0][maa];
404 fa23 = fBpz[kaa+1][0][maa+1];
407 Fatal("Ba","Invalid value of kaai %d\n",kaai);
409 faY1=alf1*fa11+alf2*fa12+alf3*fa13;
410 faY2=alf1*fa21+alf2*fa22+alf3*fa23;
411 bba = zaa1*faY1+zaa2*faY2;
416 //_______________________________________________________________________
417 Double_t AliMagFDM::Bb(Double_t z1,Double_t z2, Double_t y1,Double_t y2,
418 Double_t x1,Double_t x2, Int_t kv, Int_t k, Int_t l, Int_t m)
421 // Calculation of field componet at a given axis (general case)
423 Double_t fy1=0,fy2=0,ffy=0;
424 Double_t gy1=0,gy2=0,ggy=0;
426 Double_t bf11=0,bf12=0,bf21=0,bf22=0;
427 Double_t bg11=0,bg12=0,bg21=0,bg22=0;
430 /*-----------------Polar part ------------------*/
435 bf12=fBpx[k+1][l][m];
436 bf21=fBpx[k+1][l+1][m];
437 bf22=fBpx[k][l+1][m];
439 bg11=fBpx[k][l][m+1];
440 bg12=fBpx[k+1][l][m+1];
441 bg21=fBpx[k+1][l+1][m+1];
442 bg22=fBpx[k][l+1][m+1];
447 bf12=fBpy[k+1][l][m];
448 bf21=fBpy[k+1][l+1][m];
449 bf22=fBpy[k][l+1][m];
451 bg11=fBpy[k][l][m+1];
452 bg12=fBpy[k+1][l][m+1];
453 bg21=fBpy[k+1][l+1][m+1];
454 bg22=fBpy[k][l+1][m+1];
459 bf12=fBpz[k+1][l][m];
460 bf21=fBpz[k+1][l+1][m];
461 bf22=fBpz[k][l+1][m];
463 bg11=fBpz[k][l][m+1];
464 bg12=fBpz[k+1][l][m+1];
465 bg21=fBpz[k+1][l+1][m+1];
466 bg22=fBpz[k][l+1][m+1];
468 /*-----------------Cartensian part ---------------*/
472 bf12=fBcx[k+1][l][m];
473 bf21=fBcx[k+1][l+1][m];
474 bf22=fBcx[k][l+1][m];
476 bg11=fBcx[k][l][m+1];
477 bg12=fBcx[k+1][l][m+1];
478 bg21=fBcx[k+1][l+1][m+1];
479 bg22=fBcx[k][l+1][m+1];
484 bf12=fBcy[k+1][l][m];
485 bf21=fBcy[k+1][l+1][m];
486 bf22=fBcy[k][l+1][m];
488 bg11=fBcy[k][l][m+1];
489 bg12=fBcy[k+1][l][m+1];
490 bg21=fBcy[k+1][l+1][m+1];
491 bg22=fBcy[k][l+1][m+1];
496 bf12=fBcz[k+1][l][m];
497 bf21=fBcz[k+1][l+1][m];
498 bf22=fBcz[k][l+1][m];
500 bg11=fBcz[k][l][m+1];
501 bg12=fBcz[k+1][l][m+1];
502 bg21=fBcz[k+1][l+1][m+1];
503 bg22=fBcz[k][l+1][m+1];
507 Fatal("Bb","Invalid value of kv %d\n",kv);
513 fy2=z2*bf21+z1* bf22;
517 gy1 = z1*bg11+z2*bg12;
518 gy2 = z2*bg21+z1*bg22;
519 ggy= y1*gy1 + y2*gy2;
527 //_______________________________________________________________________
528 void AliMagFDM::ReadField()
531 // Method to read the magnetic field from file
536 Float_t zzp, rr,phii;
537 Float_t zz, yy, bx,by,bz,bb;
540 printf("Reading Magnetic Field %s from file %s\n",fName.Data(),fTitle.Data());
541 fname = gSystem->ExpandPathName(fTitle.Data());
542 magfile=fopen(fname,"r");
545 printf("Cartensian part\n");
551 fscanf(magfile,"%d %d %d ",&fYl, &fXl, &fZl);
553 printf("fYl %d, fXl %d, fZl %d\n",fYl, fXl, fZl);
555 for (ik=0; ik<fZl; ik++)
558 fscanf(magfile, " %e ", &zz);
563 for (ik=0; ik<fYl; ik++)
565 fscanf(magfile, " %e ", &yy);
569 for (ik=0; ik<81; ik++)
571 printf("fZc %e,fY %e\n", fZc[ik],fY[ik]);
574 fscanf(magfile," %e %e %e %e %e %e %e %e %e %e %e ", &fYdel,&fXdel,&fZdel,&fZmax,&fZmin,&fYmax,&fYmin,&fAx1,&fCx1,&fAx2,&fCx2);
576 printf("fYdel %e, fXdel %e, fZdel %e\n",fYdel,fXdel,fZdel);
577 printf("fZmax %e, fZmin %e, fYmax %e,fYmin %e\n",fZmax,fZmin,fYmax,fYmin);
578 printf("fAx1 %e, fCx1 %e, fAx2 %e, fCx %e\n",fAx1,fCx1,fAx2,fCx2);
580 for (il=0; il<44; il++) {
581 for (im=0; im<81; im++) {
582 for (ik=0; ik<81; ik++) {
584 fscanf(magfile, " %e ", &by);
590 for (il=0; il<44; il++) {
591 for (im=0; im<81; im++) {
592 for (ik=0; ik<81; ik++) {
594 fscanf(magfile, " %e ", &bx);
600 for (il=0; il<44; il++) {
601 for (im=0; im<81; im++) {
602 for (ik=0; ik<81; ik++) {
604 fscanf(magfile, " %e ", &bz);
609 //---------------------- Polar part ---------------------------------
611 printf("Polar part\n");
612 fscanf(magfile,"%d %d %d ", &fZpl, &fRn, &fPhin);
613 printf("fZpl %d, fRn %d, fPhin %d\n",fZpl,fRn,fPhin);
615 printf(" fZp array\n");
617 for (ik=0; ik<51; ik++)
619 fscanf(magfile, " %e ", &zzp);
621 printf(" %e\n",fZp[ik]);
624 printf(" fR array\n");
626 for (ik=0; ik<10; ik++)
628 fscanf(magfile, " %e ", &rr);
630 printf(" %e\n",fR[ik]);
633 // printf("fPhi array\n");
635 for (il=0; il<33; il++)
637 fscanf(magfile, " %e ", &phii);
639 // printf(" %e\n",fPhi[il]);
642 fscanf(magfile," %e %e %e %e %e %e %e ",&fZpdl,&fPhid,&fRdel,&fZpmx,&fZpmn,&fRmax, &fRmin);
644 printf("fZpdl %e, fPhid %e, fRdel %e, fZpmx %e, fZpmn %e,fRmax %e,fRmin %e \n", fZpdl,fPhid, fRdel,fZpmx, fZpmn,fRmax, fRmin);
647 for (il=0; il<33; il++) {
648 for (im=0; im<10; im++) {
649 for (ik=0; ik<51; ik++) {
650 fscanf(magfile, " %e ", &by);
656 for (il=0; il<33; il++) {
657 for (im=0; im<10; im++) {
658 for (ik=0; ik<51; ik++) {
659 fscanf(magfile, " %e ", &bx);
666 for (il=0; il<33; il++) {
667 for (im=0; im<10; im++) {
668 for (ik=0; ik<51; ik++) {
669 fscanf(magfile, " %e ", &bz);
676 for (il=0; il<32; il++) {
677 for (im=0; im<2; im++) {
678 for (ik=0; ik<2; ik++) {
679 fscanf(magfile, " %e ", &bb);
686 Fatal("ReadField","File %s not found !\n",fTitle.Data());