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 //-------------------------------------------------------------------------
27 #include "AliMagFDM.h"
31 //_______________________________________________________________________
32 AliMagFDM::AliMagFDM():
61 // Default constructor for the Dipole field
65 //_______________________________________________________________________
66 AliMagFDM::AliMagFDM(const char *name, const char *title, Int_t integ,
67 Float_t factor, Float_t fmax):
68 AliMagFC(name,title,integ,factor,fmax),
97 // Standard constructor for the Dipole field
104 "Field Map for Muon Arm from IP till muon filter %s created: map= %d, integ= %d, factor= %f, file=%s",
105 fName.Data(), fMap ,integ,factor,fTitle.Data()));
109 //_______________________________________________________________________
110 void AliMagFDM::Field(Float_t *xfi, Float_t *b) const
113 // Main routine to compute the field in a point
115 const Double_t keps=0.1E-06;
116 const Double_t kPI2=2.*TMath::Pi();
117 const Double_t kone=1;
127 const Double_t kfZbg=502.92; // Start of Map using in z
128 const Double_t kfZL3=600; // Beginning of L3 door in z
137 Double_t zp1, zp2,xp1,xp2,yp1,yp2;
138 Double_t zz1, zz2,yy1,yy2,x2,x1;
140 // --- start the map fiel from z = 502.92 cm ---
142 // This map has been calculated in a coordinate system in which the muon spectrometer sits at z > 0
143 // Transfor correspondingly.
150 // printf("x[0] %f,x[1] %f,x[2] %f\n",x[0],x[1],x[2]);
152 Double_t rr=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
156 if ( (-700<x[2] && x[2]<=kfZbg &&
157 (x[0]*x[0]+(x[1]+30)*(x[1]+30))< 560*560)
158 || (kfZbg<x[2] && x[2]<=kfZL3 && (rr>rPmax*100 && rr< 560)) )
165 xL3[1]=(x[1]+30)/100;
169 if (TMath::Abs(xL3[0])<=0.1E-06) xL3[0]=TMath::Sign(0.1E-05,xL3[0]);
170 if (TMath::Abs(xL3[1])<=0.1E-06) xL3[1]=TMath::Sign(0.1E-05,xL3[1]);
172 Double_t xminn=xL3[2]*fAx1+fCx1;
173 Double_t xmaxx=xL3[2]*fAx2+fCx2;
174 Double_t zCmin,zCmax,yCmin,yCmax;
180 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)))
184 if (kfZbg/100<xL3[2] && xL3[2]<=zCmin && r0<=rPmax)
186 //--------------------- Polar part ----------------------
191 Double_t alp1,alp2,alp3;
192 Double_t zpz,rp,fip,cphi;
199 kp0=FZ(zpz, fZp ,fZpdl,kpi,fZpl) ;
200 zp2=(zpz-fZp[kp0])/(fZp[kp0+1]-fZp[kp0]);
203 cphi=TMath::Abs(yyp/r0);
206 AliDebug(2,Form("xL3[0] %e, xL3[1] %e, xL3[2] %e, yyp %e, r0 %e, cphi %e",xL3[0],xL3[1],xL3[2],yyp,r0,cphi));
210 ph0=TMath::ACos(cphi);
211 if (xL3[0] < 0 && yyp > 0 ) {ph0=kPI2/2 - ph0;}
212 if (xL3[0] < 0 && yyp < 0 ) {ph0=kPI2/2 + ph0;}
213 if (xL3[0] > 0 && yyp < 0 ) {ph0=kPI2 - ph0;}
214 if (ph0 > kPI2) { ph0=ph0 - kPI2;}
216 AliDebug(2,Form("xL3[0] %e, xL3[1] %e, xL3[2] %e, yyp %e, r0 %e, ph0 %e",xL3[0],xL3[1],xL3[2],yyp,r0,ph0));
219 mp0=FZ(fip,fPhi,fPhid ,mpi,fPhin);
220 xp2=(fip-fPhi[mp0])/(fPhi[mp0+1]-fPhi[mp0]);
232 bint[0]=(zp1*fBpx[kp0][0][0] + zp2*fBpx[kp0+1][0][0])*10;
233 bint[1]=(zp1*fBpy[kp0][0][0] + zp2*fBpy[kp0+1][0][0])*10;
234 bint[2]=(zp1*fBpz[kp0][0][0] + zp2*fBpz[kp0+1][0][0])*10;
238 alp2= fB[0][0][mp0]*yyp + fB[0][1][mp0]*xL3[0];
239 alp3= fB[1][0][mp0]*yyp + fB[1][1][mp0]*xL3[0];
240 alp1= kone - alp2 - alp3;
242 for (jb=0; jb<3 ; jb++)
245 bint[jb] = Ba(iKvar,zp1,zp2,alp1,alp2,alp3, kp0,mp0)*10 ;
247 } // end of keps <=r0
253 lp0=FZ(rp,fR ,fRdel,lpi,fRn);
254 yp2=(rp-fR[lp0])/(fR[lp0+1]-fR[lp0]);
257 for (jb=0; jb<3 ; jb++)
260 bint[jb] = Bb(zp1,zp2,yp1,yp2,xp1,xp2,iKvar,kp0,lp0,mp0)*10 ;
271 //-------------- Cartensian part ------------------
275 Double_t xx1, xx2,dx, xxx ,xXl;
282 xx1 = fAx1*xL3[2] + fCx1;
283 xx2 = fAx2*xL3[2] + fCx2;
286 k0=FZ(zzc, fZc ,fZdel, kci, fZl);
287 zz2=(zzc-fZc[k0])/(fZc[k0+1]-fZc[k0]);
291 l0=FZ(yyc, fY , fYdel,lci,fYl);
292 yy2=(yyc-fY[l0])/(fY[l0+1]-fY[l0]);;
299 if(xL3[0]<(xx1+m0*dx) || xL3[0] >(xx1+(m0+1)*dx))
302 AliDebug(2,Form(" m0 %d, m0+1 %d\n",m0,m0+1));
305 x2=(xL3[0]-( xx1+m0*dx))/dx;
308 for (jb=3; jb<6; jb++)
311 bint[jb-3] = Bb(zz1,zz2,yy1,yy2,x1,x2,iKvar,k0, l0, m0)*10 ;
322 AliError(Form("Unknown map of Dipole region %d",fMap));
337 //_______________________________________________________________________
338 Int_t AliMagFDM::FZ(Double_t temp, const Float_t *Ar,
339 Float_t delu, Int_t ik, Int_t nk) const
342 // Quest of a point position at x,y,z (Cartensian) and R,Phi,z (Polar) axises
356 for(l=ikj; l<nk; l++)
369 //_______________________________________________________________________
370 Double_t AliMagFDM::Ba(Int_t kaai,Double_t zaa1, Double_t zaa2,
371 Double_t alf1, Double_t alf2, Double_t alf3,
372 Int_t kaa, Int_t maa) const
375 // Calculation of field componet for case (keps <r0<= fRdel) at a given axis
377 Double_t fa11=0,fa12=0,fa13=0;
378 Double_t fa21=0,fa22=0,fa23=0;
379 Double_t faY1=0,faY2=0;
384 fa11 = fBpx[kaa][0][0];
385 fa12 = fBpx[kaa][0][maa];
386 fa13 = fBpx[kaa][0][maa+1];
387 fa21 = fBpx[kaa+1][0][0];
388 fa22 = fBpx[kaa+1][0][maa];
389 fa23 = fBpx[kaa+1][0][maa+1];
392 fa11 = fBpy[kaa][0][0];
393 fa12 = fBpy[kaa][0][maa];
394 fa13 = fBpy[kaa][0][maa+1];
395 fa21 = fBpy[kaa+1][0][0];
396 fa22 = fBpy[kaa+1][0][maa];
397 fa23 = fBpy[kaa+1][0][maa+1];
400 fa11 = fBpz[kaa][0][0];
401 fa12 = fBpz[kaa][0][maa];
402 fa13 = fBpz[kaa][0][maa+1];
403 fa21 = fBpz[kaa+1][0][0];
404 fa22 = fBpz[kaa+1][0][maa];
405 fa23 = fBpz[kaa+1][0][maa+1];
408 AliFatal(Form("Invalid value of kaai %d",kaai));
410 faY1=alf1*fa11+alf2*fa12+alf3*fa13;
411 faY2=alf1*fa21+alf2*fa22+alf3*fa23;
412 bba = zaa1*faY1+zaa2*faY2;
417 //_______________________________________________________________________
418 Double_t AliMagFDM::Bb(Double_t z1,Double_t z2, Double_t y1,Double_t y2,
419 Double_t x1,Double_t x2, Int_t kv, Int_t k, Int_t l, Int_t m) const
422 // Calculation of field componet at a given axis (general case)
424 Double_t fy1=0,fy2=0,ffy=0;
425 Double_t gy1=0,gy2=0,ggy=0;
427 Double_t bf11=0,bf12=0,bf21=0,bf22=0;
428 Double_t bg11=0,bg12=0,bg21=0,bg22=0;
431 /*-----------------Polar part ------------------*/
436 bf12=fBpx[k+1][l][m];
437 bf21=fBpx[k+1][l+1][m];
438 bf22=fBpx[k][l+1][m];
440 bg11=fBpx[k][l][m+1];
441 bg12=fBpx[k+1][l][m+1];
442 bg21=fBpx[k+1][l+1][m+1];
443 bg22=fBpx[k][l+1][m+1];
448 bf12=fBpy[k+1][l][m];
449 bf21=fBpy[k+1][l+1][m];
450 bf22=fBpy[k][l+1][m];
452 bg11=fBpy[k][l][m+1];
453 bg12=fBpy[k+1][l][m+1];
454 bg21=fBpy[k+1][l+1][m+1];
455 bg22=fBpy[k][l+1][m+1];
460 bf12=fBpz[k+1][l][m];
461 bf21=fBpz[k+1][l+1][m];
462 bf22=fBpz[k][l+1][m];
464 bg11=fBpz[k][l][m+1];
465 bg12=fBpz[k+1][l][m+1];
466 bg21=fBpz[k+1][l+1][m+1];
467 bg22=fBpz[k][l+1][m+1];
469 /*-----------------Cartensian part ---------------*/
473 bf12=fBcx[k+1][l][m];
474 bf21=fBcx[k+1][l+1][m];
475 bf22=fBcx[k][l+1][m];
477 bg11=fBcx[k][l][m+1];
478 bg12=fBcx[k+1][l][m+1];
479 bg21=fBcx[k+1][l+1][m+1];
480 bg22=fBcx[k][l+1][m+1];
485 bf12=fBcy[k+1][l][m];
486 bf21=fBcy[k+1][l+1][m];
487 bf22=fBcy[k][l+1][m];
489 bg11=fBcy[k][l][m+1];
490 bg12=fBcy[k+1][l][m+1];
491 bg21=fBcy[k+1][l+1][m+1];
492 bg22=fBcy[k][l+1][m+1];
497 bf12=fBcz[k+1][l][m];
498 bf21=fBcz[k+1][l+1][m];
499 bf22=fBcz[k][l+1][m];
501 bg11=fBcz[k][l][m+1];
502 bg12=fBcz[k+1][l][m+1];
503 bg21=fBcz[k+1][l+1][m+1];
504 bg22=fBcz[k][l+1][m+1];
508 AliFatal(Form("Invalid value of kv %d",kv));
514 fy2=z2*bf21+z1* bf22;
518 gy1 = z1*bg11+z2*bg12;
519 gy2 = z2*bg21+z1*bg22;
520 ggy= y1*gy1 + y2*gy2;
528 //_______________________________________________________________________
529 void AliMagFDM::ReadField()
532 // Method to read the magnetic field from file
537 Float_t zzp, rr,phii;
538 Float_t zz, yy, bx,by,bz,bb;
541 AliDebug(1,Form("Reading Magnetic Field %s from file %s",fName.Data(),fTitle.Data()));
542 fname = gSystem->ExpandPathName(fTitle.Data());
543 magfile=fopen(fname,"r");
546 AliDebug(2,"Cartensian part");
552 fscanf(magfile,"%d %d %d ",&fYl, &fXl, &fZl);
554 AliDebug(3,Form("fYl %d, fXl %d, fZl %d",fYl, fXl, fZl));
556 for (ik=0; ik<fZl; ik++)
559 fscanf(magfile, " %e ", &zz);
564 for (ik=0; ik<fYl; ik++)
566 fscanf(magfile, " %e ", &yy);
570 for (ik=0; ik<81; ik++)
572 AliDebug(4,Form("fZc %e,fY %e", fZc[ik],fY[ik]));
575 fscanf(magfile," %e %e %e %e %e %e %e %e %e %e %e ", &fYdel,&fXdel,&fZdel,&fZmax,&fZmin,&fYmax,&fYmin,&fAx1,&fCx1,&fAx2,&fCx2);
577 AliDebug(3,Form("fYdel %e, fXdel %e, fZdel %e",fYdel,fXdel,fZdel));
578 AliDebug(3,Form("fZmax %e, fZmin %e, fYmax %e,fYmin %e",fZmax,fZmin,fYmax,fYmin));
579 AliDebug(3,Form("fAx1 %e, fCx1 %e, fAx2 %e, fCx %e",fAx1,fCx1,fAx2,fCx2));
581 for (il=0; il<44; il++) {
582 for (im=0; im<81; im++) {
583 for (ik=0; ik<81; ik++) {
585 fscanf(magfile, " %e ", &by);
591 for (il=0; il<44; il++) {
592 for (im=0; im<81; im++) {
593 for (ik=0; ik<81; ik++) {
595 fscanf(magfile, " %e ", &bx);
601 for (il=0; il<44; il++) {
602 for (im=0; im<81; im++) {
603 for (ik=0; ik<81; ik++) {
605 fscanf(magfile, " %e ", &bz);
610 //---------------------- Polar part ---------------------------------
612 AliDebug(2,"Polar part");
613 fscanf(magfile,"%d %d %d ", &fZpl, &fRn, &fPhin);
614 AliDebug(3,Form("fZpl %d, fRn %d, fPhin %d",fZpl,fRn,fPhin));
616 AliDebug(4," fZp array");
618 for (ik=0; ik<51; ik++)
620 fscanf(magfile, " %e ", &zzp);
622 AliDebug(4,Form(" %e",fZp[ik]));
625 AliDebug(4," fR array");
627 for (ik=0; ik<10; ik++)
629 fscanf(magfile, " %e ", &rr);
631 AliDebug(4,Form(" %e",fR[ik]));
634 // AliDebug(4,"fPhi array");
636 for (il=0; il<33; il++)
638 fscanf(magfile, " %e ", &phii);
640 // AliDebug(4,Form(" %e",fPhi[il]));
643 fscanf(magfile," %e %e %e %e %e %e %e ",&fZpdl,&fPhid,&fRdel,&fZpmx,&fZpmn,&fRmax, &fRmin);
645 AliDebug(3,Form("fZpdl %e, fPhid %e, fRdel %e, fZpmx %e, fZpmn %e,fRmax %e,fRmin %e", fZpdl,fPhid, fRdel,fZpmx, fZpmn,fRmax, fRmin));
648 for (il=0; il<33; il++) {
649 for (im=0; im<10; im++) {
650 for (ik=0; ik<51; ik++) {
651 fscanf(magfile, " %e ", &by);
657 for (il=0; il<33; il++) {
658 for (im=0; im<10; im++) {
659 for (ik=0; ik<51; ik++) {
660 fscanf(magfile, " %e ", &bx);
667 for (il=0; il<33; il++) {
668 for (im=0; im<10; im++) {
669 for (ik=0; ik<51; ik++) {
670 fscanf(magfile, " %e ", &bz);
677 for (il=0; il<32; il++) {
678 for (im=0; im<2; im++) {
679 for (ik=0; ik<2; ik++) {
680 fscanf(magfile, " %e ", &bb);
687 AliFatal(Form("File %s not found !",fTitle.Data()));