00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "G4VisAttributes.hh"
00022 #include "G4Tubs.hh"
00023 #include "G4LogicalVolume.hh"
00024 #include "G4VPhysicalVolume.hh"
00025 #include "G4PVPlacement.hh"
00026 #include "G4Color.hh"
00027 #include "G4UserLimits.hh"
00028 #include "G4Material.hh"
00029
00030 #include "BLElement.hh"
00031 #include "BLElementField.hh"
00032 #include "BLGlobalField.hh"
00033 #include "BLParam.hh"
00034
00035 #include <math.h>
00036 #include <gsl/gsl_sf_bessel.h>
00037 #include <gsl/gsl_sf_pow_int.h>
00038 #include <gsl/gsl_sf_gamma.h>
00039
00040 #ifndef M_PI
00041 #define M_PI 3.14159265358979323846264338327950288
00042 #endif
00043
00044
00045 #define cylPHI 0
00046 #define cylRHO 1
00047 #define cylZ 2
00048
00049
00050 #define rectX 0
00051 #define rectY 1
00052 #define rectZ 2
00053
00054
00055 #define LEFT_HANDED_THREAD (-1)
00056 #define RIGHT_HANDED_THREAD (+1)
00057
00058 #define MuonsInc_PITCH_CONVENTION RIGHT_HANDED_THREAD
00059
00060 #define MuonsInc_Target_Radius_mm 159.15494
00061
00062 #define ESSENTIALLY_ZERO 1.E-33
00063
00064
00065 G4ThreeVector CYLTOCARTESIAN(G4ThreeVector Bcyl,G4double phi)
00066 {
00067 const int PHI=cylPHI,RHO=cylRHO,Z=cylZ;
00068 G4ThreeVector Bcart;
00069
00070 Bcart[rectX] = (Bcyl[RHO] * cos(phi)- Bcyl[PHI]*sin(phi));
00071 Bcart[rectY] = (Bcyl[RHO] * sin(phi)+ Bcyl[PHI]*cos(phi));
00072 Bcart[rectZ] = Bcyl[Z];
00073 return Bcart;
00074 }
00075
00076
00077
00078 G4ThreeVector SIMPLEFIELD(G4double b,G4double kz,G4double Bsolenoid,G4double model)
00079 {
00080 const int X=rectX,Y=rectY,Z=rectZ;
00081 G4ThreeVector SFIELD;
00082
00083 SFIELD[X] = b * sin( MuonsInc_PITCH_CONVENTION * kz );
00084 SFIELD[Y] = b * cos( MuonsInc_PITCH_CONVENTION * kz );
00085 SFIELD[Z] = Bsolenoid + b;
00086
00087 return SFIELD;
00088 }
00089
00090 G4double ICOOLDiv(G4int n, G4double lambda)
00091 {
00092 G4double k =2*M_PI/lambda;
00093 G4double bip =gsl_sf_bessel_In(n,n);
00094 G4double bipp =gsl_sf_bessel_In(n-1,n);
00095 return k*(n*bipp-(1+n)*bip);
00096 }
00097
00098 G4double ICOOLFact(G4int n, G4double krad)
00099 {
00100 return gsl_sf_gamma(n+1)*gsl_sf_pow_int(2.0/(n*krad),n);
00101 }
00102
00103
00104
00105 G4ThreeVector ICOOLFIELD(G4int n, G4double rho, G4double psi, G4double k, G4double refrad)
00106 {
00107 const int PHI=cylPHI, RHO=cylRHO, Z=cylZ;
00108 G4ThreeVector BICOOL;
00109 G4double bn,bnp;
00110 G4double kr,sz,cz,fac;
00111 G4double bref0=-1.0;
00112
00113 kr = k*rho;
00114 sz = sin(n*psi);
00115 cz = cos(n*psi);
00116 fac = ICOOLFact(n,k*refrad);
00117
00118 bnp = 0.5*(gsl_sf_bessel_In(n+1,n*kr)+gsl_sf_bessel_In(n-1,n*kr));
00119 bn = gsl_sf_bessel_In(n,n*kr);
00120
00121 BICOOL[RHO] = bref0*refrad*fac*k*bnp*(-0.0*cz+1.0*sz);
00122 BICOOL[Z] = -bref0*refrad*fac*k*bn*(0.0*sz+1.0*cz);
00123
00124 if(rho > 0.0){
00125 BICOOL[PHI] = -BICOOL[Z]/kr;
00126 }else{
00127 BICOOL[PHI] = 0.0;
00128 }
00129
00130
00131
00132 return BICOOL;
00133 }
00134
00135 G4ThreeVector DIPOLF(G4double bd,G4double k,G4double rho,G4double psiangle)
00136 {
00137 const int PHI=cylPHI,RHO=cylRHO,Z=cylZ;
00138 G4double t,I0,I1_t,psi;
00139 G4ThreeVector Bcyl;
00140
00141 t= k * rho;
00142 I0 = gsl_sf_bessel_In(0,t);
00143 I1_t = gsl_sf_bessel_In(1,t);
00144
00145 Bcyl[PHI]= 2 * bd * I1_t * cos(psiangle);
00146 Bcyl[RHO]= 2 * bd * (I0-I1_t) * sin(psiangle);
00147
00148 Bcyl[Z]= - k * rho * Bcyl[PHI];
00149 return Bcyl;
00150 }
00151
00152
00153 G4ThreeVector QUADF(G4double bprime,G4double k,G4double rho,G4double psiangle)
00154 {
00155 const char *CoDE="QUADRUPOLEFIELD";
00156 const int PHI=cylPHI,RHO=cylRHO,Z=cylZ;
00157 static int messageCount=0;
00158 G4double t,I1,I2_t,Bprime;
00159 G4ThreeVector Bcyl;
00160 if( 0==messageCount++ ) printf("%s: version of 4/27/04\n", CoDE);
00161 Bprime= bprime/(tesla/meter) * (millimeter/meter) * (tesla/millimeter);
00162
00163 t= 2 * k * rho;
00164 I2_t = gsl_sf_bessel_In(2,t);
00165 I1 = gsl_sf_bessel_In(1,t);
00166
00167 Bcyl[PHI] = 2/k * Bprime * I2_t * cos(2*psiangle);
00168 Bcyl[RHO] = 1/k * Bprime * (I1 - 2*I2_t) * sin(2*psiangle);
00169 Bcyl[Z] = - k * rho * Bcyl[PHI];
00170
00171 return Bcyl;
00172 }