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 //-------------------------------------------------------------------------
28 #include "AliMagFDM.h"
32 //_______________________________________________________________________
33 AliMagFDM::AliMagFDM():
62 // Default constructor for the Dipole field
66 //_______________________________________________________________________
67 AliMagFDM::AliMagFDM(const char *name, const char *title, Int_t integ,
68 Float_t factor, Float_t fmax):
69 AliMagFC(name,title,integ,factor,fmax),
98 // Standard constructor for the Dipole field
105 "Field Map for Muon Arm from IP till muon filter %s created: map= %d, integ= %d, factor= %f, file=%s",
106 fName.Data(), fMap ,integ,factor,fTitle.Data()));
110 //_______________________________________________________________________
111 void AliMagFDM::Field(Float_t *xfi, Float_t *b) const
114 // Main routine to compute the field in a point
116 const Double_t keps=0.1E-06;
117 const Double_t kPI2=2.*TMath::Pi();
118 const Double_t kone=1;
128 const Double_t kfZbg=502.92; // Start of Map using in z
129 const Double_t kfZL3=600; // Beginning of L3 door in z
138 Double_t zp1, zp2,xp1,xp2,yp1,yp2;
139 Double_t zz1, zz2,yy1,yy2,x2,x1;
141 // --- start the map fiel from z = 502.92 cm ---
143 // This map has been calculated in a coordinate system in which the muon spectrometer sits at z > 0
144 // Transfor correspondingly.
151 // printf("x[0] %f,x[1] %f,x[2] %f\n",x[0],x[1],x[2]);
153 Double_t rr=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
157 if ( (-700<x[2] && x[2]<=kfZbg &&
158 (x[0]*x[0]+(x[1]+30)*(x[1]+30))< 560*560)
159 || (kfZbg<x[2] && x[2]<=kfZL3 && (rr>rPmax*100 && rr< 560)) )
166 xL3[1]=(x[1]+30)/100;
170 if (TMath::Abs(xL3[0])<=0.1E-06) xL3[0]=TMath::Sign(0.1E-05,xL3[0]);
171 if (TMath::Abs(xL3[1])<=0.1E-06) xL3[1]=TMath::Sign(0.1E-05,xL3[1]);
173 Double_t xminn=xL3[2]*fAx1+fCx1;
174 Double_t xmaxx=xL3[2]*fAx2+fCx2;
175 Double_t zCmin,zCmax,yCmin,yCmax;
181 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)))
185 if (kfZbg/100<xL3[2] && xL3[2]<=zCmin && r0<=rPmax)
187 //--------------------- Polar part ----------------------
192 Double_t alp1,alp2,alp3;
193 Double_t zpz,rp,fip,cphi;
200 kp0=FZ(zpz, fZp ,fZpdl,kpi,fZpl) ;
201 zp2=(zpz-fZp[kp0])/(fZp[kp0+1]-fZp[kp0]);
204 cphi=TMath::Abs(yyp/r0);
207 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));
211 ph0=TMath::ACos(cphi);
212 if (xL3[0] < 0 && yyp > 0 ) {ph0=kPI2/2 - ph0;}
213 if (xL3[0] < 0 && yyp < 0 ) {ph0=kPI2/2 + ph0;}
214 if (xL3[0] > 0 && yyp < 0 ) {ph0=kPI2 - ph0;}
215 if (ph0 > kPI2) { ph0=ph0 - kPI2;}
217 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));
220 mp0=FZ(fip,fPhi,fPhid ,mpi,fPhin);
221 xp2=(fip-fPhi[mp0])/(fPhi[mp0+1]-fPhi[mp0]);
233 bint[0]=(zp1*fBpx[kp0][0][0] + zp2*fBpx[kp0+1][0][0])*10;
234 bint[1]=(zp1*fBpy[kp0][0][0] + zp2*fBpy[kp0+1][0][0])*10;
235 bint[2]=(zp1*fBpz[kp0][0][0] + zp2*fBpz[kp0+1][0][0])*10;
239 alp2= fB[0][0][mp0]*yyp + fB[0][1][mp0]*xL3[0];
240 alp3= fB[1][0][mp0]*yyp + fB[1][1][mp0]*xL3[0];
241 alp1= kone - alp2 - alp3;
243 for (jb=0; jb<3 ; jb++)
246 bint[jb] = Ba(iKvar,zp1,zp2,alp1,alp2,alp3, kp0,mp0)*10 ;
248 } // end of keps <=r0
254 lp0=FZ(rp,fR ,fRdel,lpi,fRn);
255 yp2=(rp-fR[lp0])/(fR[lp0+1]-fR[lp0]);
258 for (jb=0; jb<3 ; jb++)
261 bint[jb] = Bb(zp1,zp2,yp1,yp2,xp1,xp2,iKvar,kp0,lp0,mp0)*10 ;
272 //-------------- Cartensian part ------------------
276 Double_t xx1, xx2,dx, xxx ,xXl;
283 xx1 = fAx1*xL3[2] + fCx1;
284 xx2 = fAx2*xL3[2] + fCx2;
287 k0=FZ(zzc, fZc ,fZdel, kci, fZl);
288 zz2=(zzc-fZc[k0])/(fZc[k0+1]-fZc[k0]);
292 l0=FZ(yyc, fY , fYdel,lci,fYl);
293 yy2=(yyc-fY[l0])/(fY[l0+1]-fY[l0]);;
300 if(xL3[0]<(xx1+m0*dx) || xL3[0] >(xx1+(m0+1)*dx))
303 AliDebug(2,Form(" m0 %d, m0+1 %d\n",m0,m0+1));
306 x2=(xL3[0]-( xx1+m0*dx))/dx;
309 for (jb=3; jb<6; jb++)
312 bint[jb-3] = Bb(zz1,zz2,yy1,yy2,x1,x2,iKvar,k0, l0, m0)*10 ;
323 AliError(Form("Unknown map of Dipole region %d",fMap));
338 //_______________________________________________________________________
339 Int_t AliMagFDM::FZ(Double_t temp, const Float_t *Ar,
340 Float_t delu, Int_t ik, Int_t nk) const
343 // Quest of a point position at x,y,z (Cartensian) and R,Phi,z (Polar) axises
357 for(l=ikj; l<nk; l++)
370 //_______________________________________________________________________
371 Double_t AliMagFDM::Ba(Int_t kaai,Double_t zaa1, Double_t zaa2,
372 Double_t alf1, Double_t alf2, Double_t alf3,
373 Int_t kaa, Int_t maa) const
376 // Calculation of field componet for case (keps <r0<= fRdel) at a given axis
378 Double_t fa11=0,fa12=0,fa13=0;
379 Double_t fa21=0,fa22=0,fa23=0;
380 Double_t faY1=0,faY2=0;
385 fa11 = fBpx[kaa][0][0];
386 fa12 = fBpx[kaa][0][maa];
387 fa13 = fBpx[kaa][0][maa+1];
388 fa21 = fBpx[kaa+1][0][0];
389 fa22 = fBpx[kaa+1][0][maa];
390 fa23 = fBpx[kaa+1][0][maa+1];
393 fa11 = fBpy[kaa][0][0];
394 fa12 = fBpy[kaa][0][maa];
395 fa13 = fBpy[kaa][0][maa+1];
396 fa21 = fBpy[kaa+1][0][0];
397 fa22 = fBpy[kaa+1][0][maa];
398 fa23 = fBpy[kaa+1][0][maa+1];
401 fa11 = fBpz[kaa][0][0];
402 fa12 = fBpz[kaa][0][maa];
403 fa13 = fBpz[kaa][0][maa+1];
404 fa21 = fBpz[kaa+1][0][0];
405 fa22 = fBpz[kaa+1][0][maa];
406 fa23 = fBpz[kaa+1][0][maa+1];
409 AliFatal(Form("Invalid value of kaai %d",kaai));
411 faY1=alf1*fa11+alf2*fa12+alf3*fa13;
412 faY2=alf1*fa21+alf2*fa22+alf3*fa23;
413 bba = zaa1*faY1+zaa2*faY2;
418 //_______________________________________________________________________
419 Double_t AliMagFDM::Bb(Double_t z1,Double_t z2, Double_t y1,Double_t y2,
420 Double_t x1,Double_t x2, Int_t kv, Int_t k, Int_t l, Int_t m) const
423 // Calculation of field componet at a given axis (general case)
425 Double_t fy1=0,fy2=0,ffy=0;
426 Double_t gy1=0,gy2=0,ggy=0;
428 Double_t bf11=0,bf12=0,bf21=0,bf22=0;
429 Double_t bg11=0,bg12=0,bg21=0,bg22=0;
432 /*-----------------Polar part ------------------*/
437 bf12=fBpx[k+1][l][m];
438 bf21=fBpx[k+1][l+1][m];
439 bf22=fBpx[k][l+1][m];
441 bg11=fBpx[k][l][m+1];
442 bg12=fBpx[k+1][l][m+1];
443 bg21=fBpx[k+1][l+1][m+1];
444 bg22=fBpx[k][l+1][m+1];
449 bf12=fBpy[k+1][l][m];
450 bf21=fBpy[k+1][l+1][m];
451 bf22=fBpy[k][l+1][m];
453 bg11=fBpy[k][l][m+1];
454 bg12=fBpy[k+1][l][m+1];
455 bg21=fBpy[k+1][l+1][m+1];
456 bg22=fBpy[k][l+1][m+1];
461 bf12=fBpz[k+1][l][m];
462 bf21=fBpz[k+1][l+1][m];
463 bf22=fBpz[k][l+1][m];
465 bg11=fBpz[k][l][m+1];
466 bg12=fBpz[k+1][l][m+1];
467 bg21=fBpz[k+1][l+1][m+1];
468 bg22=fBpz[k][l+1][m+1];
470 /*-----------------Cartensian part ---------------*/
474 bf12=fBcx[k+1][l][m];
475 bf21=fBcx[k+1][l+1][m];
476 bf22=fBcx[k][l+1][m];
478 bg11=fBcx[k][l][m+1];
479 bg12=fBcx[k+1][l][m+1];
480 bg21=fBcx[k+1][l+1][m+1];
481 bg22=fBcx[k][l+1][m+1];
486 bf12=fBcy[k+1][l][m];
487 bf21=fBcy[k+1][l+1][m];
488 bf22=fBcy[k][l+1][m];
490 bg11=fBcy[k][l][m+1];
491 bg12=fBcy[k+1][l][m+1];
492 bg21=fBcy[k+1][l+1][m+1];
493 bg22=fBcy[k][l+1][m+1];
498 bf12=fBcz[k+1][l][m];
499 bf21=fBcz[k+1][l+1][m];
500 bf22=fBcz[k][l+1][m];
502 bg11=fBcz[k][l][m+1];
503 bg12=fBcz[k+1][l][m+1];
504 bg21=fBcz[k+1][l+1][m+1];
505 bg22=fBcz[k][l+1][m+1];
509 AliFatal(Form("Invalid value of kv %d",kv));
515 fy2=z2*bf21+z1* bf22;
519 gy1 = z1*bg11+z2*bg12;
520 gy2 = z2*bg21+z1*bg22;
521 ggy= y1*gy1 + y2*gy2;
529 //_______________________________________________________________________
530 void AliMagFDM::ReadField()
533 // Method to read the magnetic field from file
538 Float_t zzp, rr,phii;
539 Float_t zz, yy, bx,by,bz,bb;
542 AliDebug(1,Form("Reading Magnetic Field %s from file %s",fName.Data(),fTitle.Data()));
543 fname = gSystem->ExpandPathName(fTitle.Data());
544 magfile=fopen(fname,"r");
547 AliDebug(2,"Cartensian part");
553 fscanf(magfile,"%d %d %d ",&fYl, &fXl, &fZl);
555 AliDebug(3,Form("fYl %d, fXl %d, fZl %d",fYl, fXl, fZl));
557 for (ik=0; ik<fZl; ik++)
560 fscanf(magfile, " %e ", &zz);
565 for (ik=0; ik<fYl; ik++)
567 fscanf(magfile, " %e ", &yy);
571 for (ik=0; ik<81; ik++)
573 AliDebug(4,Form("fZc %e,fY %e", fZc[ik],fY[ik]));
576 fscanf(magfile," %e %e %e %e %e %e %e %e %e %e %e ", &fYdel,&fXdel,&fZdel,&fZmax,&fZmin,&fYmax,&fYmin,&fAx1,&fCx1,&fAx2,&fCx2);
578 AliDebug(3,Form("fYdel %e, fXdel %e, fZdel %e",fYdel,fXdel,fZdel));
579 AliDebug(3,Form("fZmax %e, fZmin %e, fYmax %e,fYmin %e",fZmax,fZmin,fYmax,fYmin));
580 AliDebug(3,Form("fAx1 %e, fCx1 %e, fAx2 %e, fCx %e",fAx1,fCx1,fAx2,fCx2));
582 for (il=0; il<44; il++) {
583 for (im=0; im<81; im++) {
584 for (ik=0; ik<81; ik++) {
586 fscanf(magfile, " %e ", &by);
592 for (il=0; il<44; il++) {
593 for (im=0; im<81; im++) {
594 for (ik=0; ik<81; ik++) {
596 fscanf(magfile, " %e ", &bx);
602 for (il=0; il<44; il++) {
603 for (im=0; im<81; im++) {
604 for (ik=0; ik<81; ik++) {
606 fscanf(magfile, " %e ", &bz);
611 //---------------------- Polar part ---------------------------------
613 AliDebug(2,"Polar part");
614 fscanf(magfile,"%d %d %d ", &fZpl, &fRn, &fPhin);
615 AliDebug(3,Form("fZpl %d, fRn %d, fPhin %d",fZpl,fRn,fPhin));
617 AliDebug(4," fZp array");
619 for (ik=0; ik<51; ik++)
621 fscanf(magfile, " %e ", &zzp);
623 AliDebug(4,Form(" %e",fZp[ik]));
626 AliDebug(4," fR array");
628 for (ik=0; ik<10; ik++)
630 fscanf(magfile, " %e ", &rr);
632 AliDebug(4,Form(" %e",fR[ik]));
635 // AliDebug(4,"fPhi array");
637 for (il=0; il<33; il++)
639 fscanf(magfile, " %e ", &phii);
641 // AliDebug(4,Form(" %e",fPhi[il]));
644 fscanf(magfile," %e %e %e %e %e %e %e ",&fZpdl,&fPhid,&fRdel,&fZpmx,&fZpmn,&fRmax, &fRmin);
646 AliDebug(3,Form("fZpdl %e, fPhid %e, fRdel %e, fZpmx %e, fZpmn %e,fRmax %e,fRmin %e", fZpdl,fPhid, fRdel,fZpmx, fZpmn,fRmax, fRmin));
649 for (il=0; il<33; il++) {
650 for (im=0; im<10; im++) {
651 for (ik=0; ik<51; ik++) {
652 fscanf(magfile, " %e ", &by);
658 for (il=0; il<33; il++) {
659 for (im=0; im<10; im++) {
660 for (ik=0; ik<51; ik++) {
661 fscanf(magfile, " %e ", &bx);
668 for (il=0; il<33; il++) {
669 for (im=0; im<10; im++) {
670 for (ik=0; ik<51; ik++) {
671 fscanf(magfile, " %e ", &bz);
678 for (il=0; il<32; il++) {
679 for (im=0; im<2; im++) {
680 for (ik=0; ik<2; ik++) {
681 fscanf(magfile, " %e ", &bb);
688 AliFatal(Form("File %s not found !",fTitle.Data()));