BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMagneticField.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * DISCLAIMER *
4// * *
5// * The following disclaimer summarizes all the specific disclaimers *
6// * of contributors to this software. The specific disclaimers,which *
7// * govern, are listed with their locations in: *
8// * http://cern.ch/geant4/license *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. *
15// * *
16// * This code implementation is the intellectual property of the *
17// * GEANT4 collaboration. *
18// * By copying, distributing or modifying the Program (or any work *
19// * based on the Program) you indicate your acceptance of this *
20// * statement, and all its terms. *
21// ********************************************************************
22//
23//
24// $Id: BesMagneticField.cc,v 1.10 2022/01/24 23:40:34 dengzy Exp $
25// GEANT4 tag $Name: BesSim-00-01-30 $
26//
27// User Field setup class implementation.
28//
29
30#include "BesMagneticField.hh"
32
33#include "G4MagneticField.hh"
34
35#include "G4FieldManager.hh"
36#include "G4TransportationManager.hh"
37#include "G4Mag_UsualEqRhs.hh"
38#include "G4MagIntegratorStepper.hh"
39#include "G4ChordFinder.hh"
40#include "G4PropagatorInField.hh"
41
42#include "G4ExplicitEuler.hh"
43#include "G4ImplicitEuler.hh"
44#include "G4SimpleRunge.hh"
45#include "G4SimpleHeum.hh"
46#include "G4ClassicalRK4.hh"
47#include "G4HelixExplicitEuler.hh"
48#include "G4HelixImplicitEuler.hh"
49#include "G4HelixSimpleRunge.hh"
50#include "G4CashKarpRKF45.hh"
51#include "G4RKG3_Stepper.hh"
52#include "Randomize.hh"
53#include "CLHEP/Random/RanecuEngine.h"
54#include "CLHEP/Random/RandGauss.h"
55
56#include "GaudiKernel/AlgFactory.h"
57#include "GaudiKernel/MsgStream.h"
58#include "GaudiKernel/SvcFactory.h"
59#include "GaudiKernel/ISvcLocator.h"
60#include "GaudiKernel/SmartDataPtr.h"
61//#include "GaudiKernel/IMagneticFieldSvc.h"
62#include "GaudiKernel/Bootstrap.h"
63
64#include "CLHEP/Geometry/Vector3D.h"
65#include "CLHEP/Geometry/Point3D.h"
66#include "CLHEP/Units/PhysicalConstants.h"
67//#include "MagneticField/MagneticFieldSvc.h"
68
69#include "ReadBoostRoot.hh"
70#include <fstream>
71
72#include "G4SystemOfUnits.hh"
73
74
75#ifndef ENABLE_BACKWARDS_COMPATIBILITY
77#endif
78#ifndef ENABLE_BACKWARDS_COMPATIBILITY
80#endif
81
82//////////////////////////////////////////////////////////////////////////
83//
84// Magnetic field
85
87 : fChordFinder(0), fStepper(0),m_pIMF(0)
88{
89 ISvcLocator* svcLocator = Gaudi::svcLocator();
90 StatusCode sc = svcLocator->service("MagneticFieldSvc",m_pIMF);
91 if(sc!=StatusCode::SUCCESS) {
92 G4cout<< "Unable to open Magnetic field service"<<G4endl;
93 }
95}
96
104///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105
106void BesMagneticField::GetFieldValue( const double Point[3], double *Bfield) const
107{
108 double x=Point[0];
109 double y=Point[1];
110 double z=Point[2];
111
112 HepPoint3D r(x,y,z);
114
116 m_pIMF->fieldVector(r,b);
117 else
119
120 Bfield[0]=b.x();
121 Bfield[1]=b.y();
122 Bfield[2]=b.z();
123
124//caogf debug
125// ofstream haha("field_out.dat",ios_base::app);
126// haha<<x/mm<<" "<<y/mm<<" "<<z/mm<<" "<<Bfield[0]/tesla<<" "<<Bfield[1]/tesla<<" "<<Bfield[2]/tesla<<G4endl;
127// haha.close();
128}
129
130//////////////////////////////////////////////////////////////
131//Initialise
132
134{
135
137 fEquation = new G4Mag_UsualEqRhs(this);
138
139 fMinStep = 0.01*mm ; // minimal step of 1 mm is default
140
141 fStepperType =4; // ClassicalRK4 is default stepper
142 fFieldManager = G4TransportationManager::GetTransportationManager()
143 ->GetFieldManager();
144 G4cout<<"before CreateStepperAndChordFinder"<<G4endl;
146}
147
148////////////////////////////////////////////////////////////////////////////////
149// Update field
150//
151
153{
154 SetStepper();
155 G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl ;
156
157 fFieldManager->SetDetectorField(this );
158
159 if(fChordFinder) delete fChordFinder;
160
161 fChordFinder = new G4ChordFinder(this , fMinStep,fStepper);
162
163 fChordFinder->SetDeltaChord(0.25*mm);
164 fFieldManager->SetChordFinder( fChordFinder );
165 fFieldManager->SetDeltaOneStep(1.0e-2*mm);
166 fFieldManager->SetDeltaIntersection(1.0e-3*mm);
167 fFieldManager->SetMinimumEpsilonStep(5.0e-5);
168 fFieldManager->SetMaximumEpsilonStep(1.0e-3);
169
170 G4PropagatorInField* fieldPropagator
171 = G4TransportationManager::GetTransportationManager()
172 ->GetPropagatorInField();
173 G4cout<<"LargestAcceptableStep is "<<fieldPropagator->GetLargestAcceptableStep()/m<<G4endl;
174//read some values
175 G4cout<<"field has created"<<G4endl;
176 G4cout<<"fDelta_One_Step_Value is "<<fFieldManager->GetDeltaOneStep()<<G4endl;
177 G4cout<<"fDelta_Intersection_Val is "<<fFieldManager->GetDeltaIntersection()<<G4endl;
178 G4cout<<"fEpsilonMin is "<<fFieldManager->GetMinimumEpsilonStep()<<G4endl;
179 G4cout<<"fEpsilonMax is "<< fFieldManager->GetMaximumEpsilonStep()<<G4endl;
180 return;
181}
182
183/////////////////////////////////////////////////////////////////////////////
184//
185// Set stepper according to the stepper type
186//
187
189{
190 if(fStepper) delete fStepper;
191
192 switch ( fStepperType )
193 {
194 case 0:
195 fStepper = new G4ExplicitEuler( fEquation );
196 G4cout<<"G4ExplicitEuler is called"<<G4endl;
197 break;
198 case 1:
199 fStepper = new G4ImplicitEuler( fEquation );
200 G4cout<<"G4ImplicitEuler is called"<<G4endl;
201 break;
202 case 2:
203 fStepper = new G4SimpleRunge( fEquation );
204 G4cout<<"G4SimpleRunge is called"<<G4endl;
205 break;
206 case 3:
207 fStepper = new G4SimpleHeum( fEquation );
208 G4cout<<"G4SimpleHeum is called"<<G4endl;
209 break;
210 case 4:
211 fStepper = new G4ClassicalRK4( fEquation );
212 G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
213 break;
214 case 5:
215 fStepper = new G4HelixExplicitEuler( fEquation );
216 G4cout<<"G4HelixExplicitEuler is called"<<G4endl;
217 break;
218 case 6:
219 fStepper = new G4HelixImplicitEuler( fEquation );
220 G4cout<<"G4HelixImplicitEuler is called"<<G4endl;
221 break;
222 case 7:
223 fStepper = new G4HelixSimpleRunge( fEquation );
224 G4cout<<"G4HelixSimpleRunge is called"<<G4endl;
225 break;
226 case 8:
227 fStepper = new G4CashKarpRKF45( fEquation );
228 G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
229 break;
230 case 9:
231 fStepper = new G4RKG3_Stepper( fEquation );
232 G4cout<<"G4RKG3_Stepper is called"<<G4endl;
233 break;
234 default: fStepper = 0;
235 }
236 return;
237}
238
239/////////////////////////////////////////////////////////////////////////////
241{
242 fFieldManager = G4TransportationManager::GetTransportationManager()
243 ->GetFieldManager();
244 fFieldManager->SetDeltaOneStep(newvalue);
245}
247{
248 fFieldManager = G4TransportationManager::GetTransportationManager()->GetFieldManager();
249 fFieldManager->SetDeltaIntersection(newvalue);
250}
252{
253 fFieldManager = G4TransportationManager::GetTransportationManager()->GetFieldManager();
254 fFieldManager->SetMinimumEpsilonStep(newvalue);
255}
257{
258 fFieldManager =G4TransportationManager::GetTransportationManager()->GetFieldManager();
259 fFieldManager->SetMaximumEpsilonStep(newvalue);
260}
261
HepGeom::Point3D< double > HepPoint3D
HepGeom::Vector3D< double > HepVector3D
Double_t x[10]
G4Mag_UsualEqRhs * fEquation
void SetMaximumEpsilonStep(double newvalue)
G4MagIntegratorStepper * fStepper
IMagneticFieldSvc * m_pIMF
G4FieldManager * fFieldManager
void SetDeltaIntersection(double newvalue)
G4ChordFinder * fChordFinder
BesMagneticFieldMessenger * fFieldMessenger
void GetFieldValue(const double Point[3], double *Bfield) const
void SetMinimumEpsilonStep(double newvalue)
void SetDeltaOneStep(double newvalue)
virtual StatusCode uniFieldVector(const HepGeom::Point3D< double > &xyz, HepGeom::Vector3D< double > &fvec) const =0
virtual StatusCode fieldVector(const HepGeom::Point3D< double > &xyz, HepGeom::Vector3D< double > &fvec) const =0
static G4int GetField()
double y[1000]
const double b
Definition slope.cxx:9