00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "BesMagneticField.hh"
00031 #include "BesMagneticFieldMessenger.hh"
00032
00033 #include "G4MagneticField.hh"
00034
00035 #include "G4FieldManager.hh"
00036 #include "G4TransportationManager.hh"
00037 #include "G4Mag_UsualEqRhs.hh"
00038 #include "G4MagIntegratorStepper.hh"
00039 #include "G4ChordFinder.hh"
00040 #include "G4PropagatorInField.hh"
00041
00042 #include "G4ExplicitEuler.hh"
00043 #include "G4ImplicitEuler.hh"
00044 #include "G4SimpleRunge.hh"
00045 #include "G4SimpleHeum.hh"
00046 #include "G4ClassicalRK4.hh"
00047 #include "G4HelixExplicitEuler.hh"
00048 #include "G4HelixImplicitEuler.hh"
00049 #include "G4HelixSimpleRunge.hh"
00050 #include "G4CashKarpRKF45.hh"
00051 #include "G4RKG3_Stepper.hh"
00052 #include "Randomize.hh"
00053 #include "CLHEP/Random/RanecuEngine.h"
00054 #include "CLHEP/Random/RandGauss.h"
00055
00056 #include "GaudiKernel/AlgFactory.h"
00057 #include "GaudiKernel/MsgStream.h"
00058 #include "GaudiKernel/SvcFactory.h"
00059 #include "GaudiKernel/ISvcLocator.h"
00060 #include "GaudiKernel/SmartDataPtr.h"
00061
00062 #include "GaudiKernel/Bootstrap.h"
00063
00064 #include "CLHEP/Geometry/Vector3D.h"
00065 #include "CLHEP/Geometry/Point3D.h"
00066 #include "CLHEP/Units/PhysicalConstants.h"
00067
00068
00069 #include "ReadBoostRoot.hh"
00070 #include <fstream>
00071
00072 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
00073 typedef HepGeom::Point3D<double> HepPoint3D;
00074 #endif
00075 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
00076 typedef HepGeom::Vector3D<double> HepVector3D;
00077 #endif
00078
00080
00081
00082
00083 BesMagneticField::BesMagneticField()
00084 : fChordFinder(0), fStepper(0),m_pIMF(0)
00085 {
00086 ISvcLocator* svcLocator = Gaudi::svcLocator();
00087 StatusCode sc = svcLocator->service("MagneticFieldSvc",m_pIMF);
00088 if(sc!=StatusCode::SUCCESS) {
00089 G4cout<< "Unable to open Magnetic field service"<<G4endl;
00090 }
00091 InitialiseAll();
00092 }
00093
00094 BesMagneticField::~BesMagneticField()
00095 {
00096 if(fFieldMessenger) delete fFieldMessenger;
00097 if(fChordFinder) delete fChordFinder;
00098 if(fEquation) delete fEquation;
00099 if(fStepper) delete fStepper;
00100 }
00102
00103 void BesMagneticField::GetFieldValue( const double Point[3], double *Bfield) const
00104 {
00105 double x=Point[0];
00106 double y=Point[1];
00107 double z=Point[2];
00108
00109 HepPoint3D r(x,y,z);
00110 HepVector3D b;
00111
00112 if(ReadBoostRoot::GetField()==2)
00113 m_pIMF->fieldVector(r,b);
00114 else
00115 m_pIMF->uniFieldVector(r,b);
00116
00117 Bfield[0]=b.x();
00118 Bfield[1]=b.y();
00119 Bfield[2]=b.z();
00120
00121
00122
00123
00124
00125 }
00126
00128
00129
00130 void BesMagneticField::InitialiseAll()
00131 {
00132
00133 fFieldMessenger=new BesMagneticFieldMessenger(this);
00134 fEquation = new G4Mag_UsualEqRhs(this);
00135
00136 fMinStep = 0.01*mm ;
00137
00138 fStepperType =4;
00139 fFieldManager = G4TransportationManager::GetTransportationManager()
00140 ->GetFieldManager();
00141 G4cout<<"before CreateStepperAndChordFinder"<<G4endl;
00142 CreateStepperAndChordFinder();
00143 }
00144
00146
00147
00148
00149 void BesMagneticField::CreateStepperAndChordFinder()
00150 {
00151 SetStepper();
00152 G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl ;
00153
00154 fFieldManager->SetDetectorField(this );
00155
00156 if(fChordFinder) delete fChordFinder;
00157
00158 fChordFinder = new G4ChordFinder(this , fMinStep,fStepper);
00159
00160 fChordFinder->SetDeltaChord(0.25*mm);
00161 fFieldManager->SetChordFinder( fChordFinder );
00162 fFieldManager->SetDeltaOneStep(1.0e-2*mm);
00163 fFieldManager->SetDeltaIntersection(1.0e-3*mm);
00164 fFieldManager->SetMinimumEpsilonStep(5.0e-5);
00165 fFieldManager->SetMaximumEpsilonStep(1.0e-3);
00166
00167 G4PropagatorInField* fieldPropagator
00168 = G4TransportationManager::GetTransportationManager()
00169 ->GetPropagatorInField();
00170 G4cout<<"LargestAcceptableStep is "<<fieldPropagator->GetLargestAcceptableStep()/m<<G4endl;
00171
00172 G4cout<<"field has created"<<G4endl;
00173 G4cout<<"fDelta_One_Step_Value is "<<fFieldManager->GetDeltaOneStep()<<G4endl;
00174 G4cout<<"fDelta_Intersection_Val is "<<fFieldManager->GetDeltaIntersection()<<G4endl;
00175 G4cout<<"fEpsilonMin is "<<fFieldManager->GetMinimumEpsilonStep()<<G4endl;
00176 G4cout<<"fEpsilonMax is "<< fFieldManager->GetMaximumEpsilonStep()<<G4endl;
00177 return;
00178 }
00179
00181
00182
00183
00184
00185 void BesMagneticField::SetStepper()
00186 {
00187 if(fStepper) delete fStepper;
00188
00189 switch ( fStepperType )
00190 {
00191 case 0:
00192 fStepper = new G4ExplicitEuler( fEquation );
00193 G4cout<<"G4ExplicitEuler is called"<<G4endl;
00194 break;
00195 case 1:
00196 fStepper = new G4ImplicitEuler( fEquation );
00197 G4cout<<"G4ImplicitEuler is called"<<G4endl;
00198 break;
00199 case 2:
00200 fStepper = new G4SimpleRunge( fEquation );
00201 G4cout<<"G4SimpleRunge is called"<<G4endl;
00202 break;
00203 case 3:
00204 fStepper = new G4SimpleHeum( fEquation );
00205 G4cout<<"G4SimpleHeum is called"<<G4endl;
00206 break;
00207 case 4:
00208 fStepper = new G4ClassicalRK4( fEquation );
00209 G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
00210 break;
00211 case 5:
00212 fStepper = new G4HelixExplicitEuler( fEquation );
00213 G4cout<<"G4HelixExplicitEuler is called"<<G4endl;
00214 break;
00215 case 6:
00216 fStepper = new G4HelixImplicitEuler( fEquation );
00217 G4cout<<"G4HelixImplicitEuler is called"<<G4endl;
00218 break;
00219 case 7:
00220 fStepper = new G4HelixSimpleRunge( fEquation );
00221 G4cout<<"G4HelixSimpleRunge is called"<<G4endl;
00222 break;
00223 case 8:
00224 fStepper = new G4CashKarpRKF45( fEquation );
00225 G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
00226 break;
00227 case 9:
00228 fStepper = new G4RKG3_Stepper( fEquation );
00229 G4cout<<"G4RKG3_Stepper is called"<<G4endl;
00230 break;
00231 default: fStepper = 0;
00232 }
00233 return;
00234 }
00235
00237 void BesMagneticField::SetDeltaOneStep(double newvalue)
00238 {
00239 fFieldManager = G4TransportationManager::GetTransportationManager()
00240 ->GetFieldManager();
00241 fFieldManager->SetDeltaOneStep(newvalue);
00242 }
00243 void BesMagneticField::SetDeltaIntersection(double newvalue)
00244 {
00245 fFieldManager = G4TransportationManager::GetTransportationManager()->GetFieldManager();
00246 fFieldManager->SetDeltaIntersection(newvalue);
00247 }
00248 void BesMagneticField::SetMinimumEpsilonStep(double newvalue)
00249 {
00250 fFieldManager = G4TransportationManager::GetTransportationManager()->GetFieldManager();
00251 fFieldManager->SetMinimumEpsilonStep(newvalue);
00252 }
00253 void BesMagneticField::SetMaximumEpsilonStep(double newvalue)
00254 {
00255 fFieldManager =G4TransportationManager::GetTransportationManager()->GetFieldManager();
00256 fFieldManager->SetMaximumEpsilonStep(newvalue);
00257 }
00258