/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Simulation/BOOST/BesSim/BesSim-00-01-24/src/BesMagneticField.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * DISCLAIMER                                                       *
00004 // *                                                                  *
00005 // * The following disclaimer summarizes all the specific disclaimers *
00006 // * of contributors to this software. The specific disclaimers,which *
00007 // * govern, are listed with their locations in:                      *
00008 // *   http://cern.ch/geant4/license                                  *
00009 // *                                                                  *
00010 // * Neither the authors of this software system, nor their employing *
00011 // * institutes,nor the agencies providing financial support for this *
00012 // * work  make  any representation or  warranty, express or implied, *
00013 // * regarding  this  software system or assume any liability for its *
00014 // * use.                                                             *
00015 // *                                                                  *
00016 // * This  code  implementation is the  intellectual property  of the *
00017 // * GEANT4 collaboration.                                            *
00018 // * By copying,  distributing  or modifying the Program (or any work *
00019 // * based  on  the Program)  you indicate  your  acceptance of  this *
00020 // * statement, and all its terms.                                    *
00021 // ********************************************************************
00022 //
00023 //
00024 // $Id: BesMagneticField.cc,v 1.9 2015/03/17 05:50:57 sunss Exp $
00025 // GEANT4 tag $Name: BesSim-00-01-24 $
00026 //
00027 //   User Field setup class implementation.
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 //#include "GaudiKernel/IMagneticFieldSvc.h"
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 //#include "MagneticField/MagneticFieldSvc.h"
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 //  Magnetic field
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 //caogf debug   
00122 //      ofstream haha("field_out.dat",ios_base::app);
00123 //      haha<<x/mm<<" "<<y/mm<<" "<<z/mm<<" "<<Bfield[0]/tesla<<" "<<Bfield[1]/tesla<<" "<<Bfield[2]/tesla<<G4endl;
00124 //      haha.close();
00125 } 
00126 
00128 //Initialise
00129 
00130 void BesMagneticField::InitialiseAll()
00131 {
00132     
00133   fFieldMessenger=new BesMagneticFieldMessenger(this); 
00134   fEquation = new G4Mag_UsualEqRhs(this); 
00135  
00136   fMinStep     = 0.01*mm ; // minimal step of 1 mm is default
00137 
00138   fStepperType =4;      // ClassicalRK4 is default stepper
00139   fFieldManager = G4TransportationManager::GetTransportationManager()
00140                                          ->GetFieldManager();
00141   G4cout<<"before CreateStepperAndChordFinder"<<G4endl;
00142   CreateStepperAndChordFinder();
00143 }
00144 
00146 // Update field
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 //read some values
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 // Set stepper according to the stepper type
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         

Generated on Tue Nov 29 23:14:23 2016 for BOSS_7.0.2 by  doxygen 1.4.7