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 Revision 1.4 2000/10/02 21:28:14 fca
19 Removal of useless dependecies via forward declarations
21 Revision 1.3 2000/07/13 16:19:09 fca
22 Mainly coding conventions + some small bug fixes
24 Revision 1.2 2000/07/12 08:56:25 fca
25 Coding convention correction and warning removal
27 Revision 1.1 2000/07/11 18:24:59 fca
28 Coding convention corrections + few minor bug fixes
34 #include "AliMagFDM.h"
40 //________________________________________
41 AliMagFDM::AliMagFDM(const char *name, const char *title, const Int_t integ,
42 const Int_t map, const Float_t factor, const Float_t fmax)
43 : AliMagF(name,title,integ,map,factor,fmax)
47 // Standard constructor for the Dipole field
51 printf("Field Map for Muon Arm from IP till muon filter %s created: map= %d, factor= %f, file=%s\n",fName.Data(),map,factor,fTitle.Data());
55 //________________________________________
57 void AliMagFDM::Field(Float_t *xfi, Float_t *b)
60 // Main routine to compute the field in a point
62 static const Double_t keps=0.1E-06;
63 static const Double_t kpi2=.6283185E+01;
64 static const Double_t kone=1;
66 static const Int_t kiip=33;
67 static const Int_t kmiip=0;
68 static const Int_t kliip=0;
70 static const Int_t kiic=0;
71 static const Int_t kmiic=0;
72 static const Int_t kliic=0;
74 static const Double_t kfZbg=502.92; // Start of Map using in z
75 static const Double_t kfZL3=600; // Beginning of L3 door in z
86 Double_t zp1, zp2,xp1,xp2,yp1,yp2;
87 Double_t zz1, zz2,yy1,yy2,x2,x1;
89 // --- start the map fiel from z = 502.92 cm ---
96 if (x[0]==0) x[0]=0.1E-06;
97 if (x[1]==0) x[1]=0.1E-06;
100 // printf("x[0] %f,x[1] %f,x[2] %f\n",x[0],x[1],x[2]);
102 Double_t rr=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
106 if ( (-700<x[2] && x[2]<=kfZbg &&
107 (x[0]*x[0]+(x[1]+30)*(x[1]+30))< 560*560)
108 || (kfZbg<x[2] && x[2]<=kfZL3 && (rr>rPmax*100 && rr< 560)) )
115 xL3[1]=(x[1]+30)/100;
119 if (TMath::Abs(xL3[0])<=0.1E-06) xL3[0]=TMath::Sign(0.1E-05,xL3[0]);
120 if (TMath::Abs(xL3[1])<=0.1E-06) xL3[1]=TMath::Sign(0.1E-05,xL3[1]);
122 Double_t xminn=xL3[2]*fAx1+fCx1;
123 Double_t xmaxx=xL3[2]*fAx2+fCx2;
124 Double_t zCmin,zCmax,yCmin,yCmax;
131 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)))
133 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)))
137 if (kfZbg/100<xL3[2] && xL3[2]<=zCmin && r0<=rPmax)
138 // if (xL3[2]<zCmin && r0<rPmax)
140 //--------------------- Polar part ----------------------
145 Double_t alp1,alp2,alp3;
146 Double_t zpz,rp,fip,cphi;
154 FZ(&zpz, fZp ,&fZpdl,&kpi,&kp0,&zp1 ,&zp2,&fZpl) ;
158 ph0=TMath::ACos(cphi);
159 if (xL3[0]< 0) {ph0=kpi2 - ph0;}
162 FZ(&fip,fPhi,&fPhid ,&mpi,&mp0, &xp1,&xp2,&fPhin);
173 bint[0]=(zp1*fBpx[kp0][0][0] + zp2*fBpx[kp0+1][0][0])*10;
174 bint[1]=(zp1*fBpy[kp0][0][0] + zp2*fBpy[kp0+1][0][0])*10;
175 bint[2]=(zp1*fBpz[kp0][0][0] + zp2*fBpz[kp0+1][0][0])*10;
179 alp2= fB[0][0][mp0]*yyp + fB[0][1][mp0]*xL3[0];
180 alp3= fB[1][0][mp0]*yyp + fB[1][1][mp0]*xL3[0];
181 alp1= kone - alp2 - alp3;
183 for (jb=0; jb<3 ; jb++)
186 FRfuncBi(&iKvar,&zp1,&zp2,&alp1,&alp2,&alp3, &kp0,&mp0, &bbj);
189 } // end of keps <=r0
195 FZ(&rp,fR ,&fRdel,&lpi,&lp0,&yp1,&yp2,&fRn);
197 for (jb=0; jb<3 ; jb++)
200 FGfuncBi(&zp1,&zp2,&yp1,&yp2,&xp1,&xp2,&iKvar,&kp0,&lp0,&mp0,&bbj);
210 // fprintf(fitest,"------------- Freg2 run -------------\n");
215 //-------------- Cartensian part ------------------
219 Double_t xx1, xx2,dx, xxx ,xXl;
226 xx1 = fAx1*xL3[2] + fCx1;
227 xx2 = fAx2*xL3[2] + fCx2;
230 FZ(&zzc, fZc ,&fZdel, &kci,&k0, &zz1, &zz2, &fZl);
233 FZ(&yyc, fY , &fYdel,&lci, &l0, &yy1, &yy2,&fYl);
241 if(xL3[0]<(xx1+m0*dx) || xL3[0] >(xx1+(m0+1)*dx))
244 printf(" m0 %d, m0+1 %d\n",m0,m0+1);
247 x2=(xL3[0]-( xx1+m0*dx))/dx;
250 for (jb=3; jb<6; jb++)
253 FGfuncBi(&zz1,&zz2,&yy1,&yy2,&x1,&x2,&iKvar,&k0, &l0, &m0, &bbj);
254 bint[jb-3] = bbj*10 ;
261 // fprintf(fitest,"------------ Freg1 run -----------------\n");
265 printf("Unknown map of Dipole region %d\n",fMap);
270 //This is the ZDC part
271 Float_t rad2=x[0]*x[0]+x[1]*x[1];
275 // Separator Dipole D2
276 if(x[2]<kD2END) b[1]=kFDIP;
277 } else if(x[2]>kD1BEG) {
279 // Separator Dipole D1
280 if(x[2]<kD1END) b[1]=-kFDIP;
284 // First quadrupole of inner triplet de-focussing in x-direction
293 } else if(x[2]>kZ3BEG) {
300 } else if(x[2]>kZ2BEG) {
307 } else if(x[2]>kZ1BEG) {
314 } else if(x[2]>kCORBEG) {
316 // Corrector dipole (because of dimuon arm)
332 //_________________________________________
334 void AliMagFDM::FZ(Double_t *u, Float_t *Ar, Float_t *du,Int_t *ki,Int_t *kf,Double_t *a1,Double_t *a2 ,Int_t *nu)
337 // Z component of the field
339 static const Double_t kone=1;
342 Double_t ddu,delu,ar;
354 // ikj=ik+ku; //falsh
355 ikj=ik+ku+1; //correct
358 for(l=ikj; l<nk; l++)
365 *a2=(temp-Ar[l-1])/(Ar[l]-Ar[l-1]);
369 *a2=(temp-Ar[l])/(Ar[l+1]-Ar[l]);
374 // *a2=(temp-Ar[*kf])/(Ar[*kf+1]-Ar[*kf]);
378 /*-------------FRfuncBi----------------*/
380 void AliMagFDM::FRfuncBi(Int_t *kai,Double_t *za1, Double_t *za2, Double_t *al1, Double_t *al2, Double_t *al3, Int_t *ka, Int_t *ma, Double_t *ba)
383 // This method needs to be commented
385 Double_t fa11,fa12,fa13;
386 Double_t fa21,fa22,fa23;
390 Double_t zaa1,zaa2,alf1,alf2,alf3;
403 fa11 = fBpx[kaa][0][0];
404 fa12 = fBpx[kaa][0][maa];
405 fa13 = fBpx[kaa][0][maa+1];
406 fa21 = fBpx[kaa+1][0][0];
407 fa22 = fBpx[kaa+1][0][maa];
408 fa23 = fBpx[kaa+1][0][maa+1];
411 fa11 = fBpy[kaa][0][0];
412 fa12 = fBpy[kaa][0][maa];
413 fa13 = fBpy[kaa][0][maa+1];
414 fa21 = fBpy[kaa+1][0][0];
415 fa22 = fBpy[kaa+1][0][maa];
416 fa23 = fBpy[kaa+1][0][maa+1];
419 fa11 = fBpz[kaa][0][0];
420 fa12 = fBpz[kaa][0][maa];
421 fa13 = fBpz[kaa][0][maa+1];
422 fa21 = fBpz[kaa+1][0][0];
423 fa22 = fBpz[kaa+1][0][maa];
424 fa23 = fBpz[kaa+1][0][maa+1];
427 Fatal("FRfuncBi","Invalid value of kaai %d\n",kaai);
430 faY1=alf1*fa11+alf2*fa12+alf3*fa13;
431 faY2=alf1*fa21+alf2*fa22+alf3*fa23;
432 bba = zaa1*faY1+zaa2*faY2;
438 /*----------- FGfuncBi------------*/
440 void AliMagFDM::FGfuncBi(Double_t *zz1,Double_t *zz2, Double_t *yy1,Double_t *yy2, Double_t *xx1,Double_t *xx2, Int_t *kvr, Int_t *kk, Int_t *ll, Int_t *mm, Double_t *bb)
443 // This method needs to be commented
445 Double_t fy1, fy2, ffy;
446 Double_t gy1,gy2,ggy;
447 Double_t z1,z2,y1,y2,x1,x2;
452 Double_t bf11,bf12,bf21,bf22;
453 Double_t bg11,bg12,bg21,bg22;
467 /*-----------------Polar part ------------------*/
472 bf12=fBpx[k+1][l][m];
473 bf21=fBpx[k+1][l+1][m];
474 bf22=fBpx[k][l+1][m];
476 bg11=fBpx[k][l][m+1];
477 bg12=fBpx[k+1][l][m+1];
478 bg21=fBpx[k+1][l+1][m+1];
479 bg22=fBpx[k][l+1][m+1];
484 bf12=fBpy[k+1][l][m];
485 bf21=fBpy[k+1][l+1][m];
486 bf22=fBpy[k][l+1][m];
488 bg11=fBpy[k][l][m+1];
489 bg12=fBpy[k+1][l][m+1];
490 bg21=fBpy[k+1][l+1][m+1];
491 bg22=fBpy[k][l+1][m+1];
496 bf12=fBpz[k+1][l][m];
497 bf21=fBpz[k+1][l+1][m];
498 bf22=fBpz[k][l+1][m];
500 bg11=fBpz[k][l][m+1];
501 bg12=fBpz[k+1][l][m+1];
502 bg21=fBpz[k+1][l+1][m+1];
503 bg22=fBpz[k][l+1][m+1];
505 /*-----------------Cartensian part ---------------*/
509 bf12=fBcx[k+1][l][m];
510 bf21=fBcx[k+1][l+1][m];
511 bf22=fBcx[k][l+1][m];
513 bg11=fBcx[k][l][m+1];
514 bg12=fBcx[k+1][l][m+1];
515 bg21=fBcx[k+1][l+1][m+1];
516 bg22=fBcx[k][l+1][m+1];
521 bf12=fBcy[k+1][l][m];
522 bf21=fBcy[k+1][l+1][m];
523 bf22=fBcy[k][l+1][m];
525 bg11=fBcy[k][l][m+1];
526 bg12=fBcy[k+1][l][m+1];
527 bg21=fBcy[k+1][l+1][m+1];
528 bg22=fBcy[k][l+1][m+1];
533 bf12=fBcz[k+1][l][m];
534 bf21=fBcz[k+1][l+1][m];
535 bf22=fBcz[k][l+1][m];
537 bg11=fBcz[k][l][m+1];
538 bg12=fBcz[k+1][l][m+1];
539 bg21=fBcz[k+1][l+1][m+1];
540 bg22=fBcz[k][l+1][m+1];
544 Fatal("FGfuncBi","Invalid value of kv %d\n",kv);
551 fy2=z2*bf21+z1* bf22;
555 gy1 = z1*bg11+z2*bg12;
556 gy2 = z2*bg21+z1*bg22;
557 ggy= y1*gy1 + y2*gy2;
564 //____________________________________________
566 void AliMagFDM::ReadField()
569 // Method to read the magnetic field from file
574 Float_t zzp, rr,phii;
575 Float_t zz, yy, bx,by,bz,bb;
578 printf("Reading Magnetic Field %s from file %s\n",fName.Data(),fTitle.Data());
579 fname = gSystem->ExpandPathName(fTitle.Data());
580 magfile=fopen(fname,"r");
583 printf("Cartensian part\n");
589 fscanf(magfile,"%d %d %d ",&fYl, &fXl, &fZl);
591 printf("fYl %d, fXl %d, fZl %d\n",fYl, fXl, fZl);
593 for (ik=0; ik<fZl; ik++)
596 fscanf(magfile, " %e ", &zz);
601 for (ik=0; ik<fYl; ik++)
603 fscanf(magfile, " %e ", &yy);
607 for (ik=0; ik<81; ik++)
609 printf("fZc %e,fY %e\n", fZc[ik],fY[ik]);
612 fscanf(magfile," %e %e %e %e %e %e %e %e %e %e %e ", &fYdel,&fXdel,&fZdel,&fZmax,&fZmin,&fYmax,&fYmin,&fAx1,&fCx1,&fAx2,&fCx2);
614 printf("fYdel %e, fXdel %e, fZdel %e\n",fYdel,fXdel,fZdel);
615 printf("fZmax %e, fZmin %e, fYmax %e,fYmin %e\n",fZmax,fZmin,fYmax,fYmin);
616 printf("fAx1 %e, fCx1 %e, fAx2 %e, fCx %e\n",fAx1,fCx1,fAx2,fCx2);
618 for (il=0; il<44; il++) {
619 for (im=0; im<81; im++) {
620 for (ik=0; ik<81; ik++) {
622 fscanf(magfile, " %e ", &by);
628 for (il=0; il<44; il++) {
629 for (im=0; im<81; im++) {
630 for (ik=0; ik<81; ik++) {
632 fscanf(magfile, " %e ", &bx);
638 for (il=0; il<44; il++) {
639 for (im=0; im<81; im++) {
640 for (ik=0; ik<81; ik++) {
642 fscanf(magfile, " %e ", &bz);
647 //---------------------- Polar part ---------------------------------
649 printf("Polar part\n");
650 fscanf(magfile,"%d %d %d ", &fZpl, &fRn, &fPhin);
651 printf("fZpl %d, fRn %d, fPhin %d\n",fZpl,fRn,fPhin);
653 printf(" fZp array\n");
655 for (ik=0; ik<51; ik++)
657 fscanf(magfile, " %e ", &zzp);
659 printf(" %e\n",fZp[ik]);
662 printf(" fR array\n");
664 for (ik=0; ik<10; ik++)
666 fscanf(magfile, " %e ", &rr);
668 printf(" %e\n",fR[ik]);
671 // printf("fPhi array\n");
673 for (il=0; il<33; il++)
675 fscanf(magfile, " %e ", &phii);
677 // printf(" %e\n",fPhi[il]);
680 fscanf(magfile," %e %e %e %e %e %e %e ",&fZpdl,&fPhid,&fRdel,&fZpmx,&fZpmn,&fRmax, &fRmin);
682 printf("fZpdl %e, fPhid %e, fRdel %e, fZpmx %e, fZpmn %e,fRmax %e,fRmin %e \n", fZpdl,fPhid, fRdel,fZpmx, fZpmn,fRmax, fRmin);
685 for (il=0; il<33; il++) {
686 for (im=0; im<10; im++) {
687 for (ik=0; ik<51; ik++) {
688 fscanf(magfile, " %e ", &by);
694 for (il=0; il<33; il++) {
695 for (im=0; im<10; im++) {
696 for (ik=0; ik<51; ik++) {
697 fscanf(magfile, " %e ", &bx);
704 for (il=0; il<33; il++) {
705 for (im=0; im<10; im++) {
706 for (ik=0; ik<51; ik++) {
707 fscanf(magfile, " %e ", &bz);
714 for (il=0; il<32; il++) {
715 for (im=0; im<2; im++) {
716 for (ik=0; ik<2; ik++) {
717 fscanf(magfile, " %e ", &bb);
724 printf("File %s not found !\n",fTitle.Data());
728 //________________________________