00001
00007
00008
00009
00010
00011 #include "BDSGlobalConstants.hh"
00012
00013 #include "BDSMultipoleMagField.hh"
00014
00015 #include "G4Navigator.hh"
00016 #include "G4TransportationManager.hh"
00017
00018 ofstream testf;
00019
00020
00021 BDSMultipoleMagField::BDSMultipoleMagField(list<G4double> knl, list<G4double> ksl)
00022 {
00023
00024
00025
00026
00027
00028
00029
00030
00031 G4double charge = BDSGlobals->GetParticleDefinition()->GetPDGCharge();
00032 G4double momentum = BDSGlobals->GetBeamMomentum();
00033 G4double brho = ( (momentum/GeV) / (0.299792458 * fabs(charge))) * (tesla*m);
00034
00035 bnl = knl;
00036 bsl = ksl;
00037
00038 list<G4double>::iterator it;
00039 list<G4double>::iterator its;
00040
00041 for(it=bnl.begin(), its=bsl.begin();it!=bnl.end();it++, its++)
00042 {
00043
00044 (*it) *= (brho*tesla );
00045
00046 (*its) *= (brho*tesla );
00047 }
00048
00049 testf.open("field.txt");
00050
00051 G4double pt[4];
00052 G4double b[3];
00053
00054 for(G4double x=-1*cm;x<1*cm;x+=0.1*mm)
00055 for(G4double y=-1*cm;y<1*cm;y+=0.1*mm){
00056 pt[0]= x;
00057 pt[1]= y;
00058 pt[2]= pt[3]=0;
00059 GetFieldValue(pt,b);
00060 testf<<pt[0]<<" "<<pt[1]<<" "<<b[0]/tesla<<" "<<b[1]/tesla<<" "<<b[2]/tesla<<G4endl;
00061 }
00062
00063
00064 }
00065
00066 BDSMultipoleMagField::~BDSMultipoleMagField(){}
00067
00068 void BDSMultipoleMagField::GetFieldValue( const G4double Point[4],
00069 G4double *Bfield ) const
00070 {
00071 G4Navigator* MulNavigator=
00072 G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
00073
00074 G4ThreeVector LocalR, GlobalR;
00075
00076 GlobalR.setX(Point[0]);
00077 GlobalR.setY(Point[1]);
00078 GlobalR.setZ(Point[2]);
00079
00080 G4AffineTransform GlobalAffine=MulNavigator->GetGlobalToLocalTransform();
00081 LocalR=GlobalAffine.TransformPoint(GlobalR);
00082
00083
00084 Bfield[0]=0;
00085 Bfield[1]=0;
00086
00087
00088 G4double br = 0;
00089 G4double bphi = 0;
00090
00091
00092 list<G4double>::const_iterator it;
00093 list<G4double>::const_iterator its;
00094
00095
00096
00097
00098 G4double r = sqrt(LocalR[0]*LocalR[0] + LocalR[1]*LocalR[1]);
00099 G4double phi;
00100 if(fabs(r)>1.e-11*m) phi = asin(LocalR[1]/r);
00101 else phi = 0;
00102
00103
00104
00105
00106
00107 G4int order=0;
00108 G4double fact = -1;
00109
00110
00111
00112
00113
00114 for(it=bnl.begin(), its=bsl.begin();it!=bnl.end();it++, its++)
00115 {
00116 order++;
00117 br += (*it) * pow(r,order-1) * sin(order*phi) / fact;
00118 bphi += (*it) * pow(r,order-1) * cos(order*phi)/ fact;
00119
00120 if(order==1) {br *= -1; bphi *=-1; }
00121
00122 fact *= (order*m);
00123 }
00124
00125
00126
00127
00128
00129 Bfield[0]=( br*cos(phi)-bphi*sin(phi) );
00130 Bfield[1]=( br*sin(phi)+bphi*cos(phi) );
00131
00132
00133 Bfield[2]=0;
00134
00135 Bfield[3]=0;
00136 Bfield[4]=0;
00137 Bfield[5]=0;
00138
00139
00140 }
00141
00142
00143