BOSS 7.0.6
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.9 2015/03/17 05:50:57 sunss Exp $
25// GEANT4 tag $Name: BesSim-00-01-24 $
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#ifndef ENABLE_BACKWARDS_COMPATIBILITY
74#endif
75#ifndef ENABLE_BACKWARDS_COMPATIBILITY
77#endif
78
79//////////////////////////////////////////////////////////////////////////
80//
81// Magnetic field
82
84 : fChordFinder(0), fStepper(0),m_pIMF(0)
85{
86 ISvcLocator* svcLocator = Gaudi::svcLocator();
87 StatusCode sc = svcLocator->service("MagneticFieldSvc",m_pIMF);
88 if(sc!=StatusCode::SUCCESS) {
89 G4cout<< "Unable to open Magnetic field service"<<G4endl;
90 }
92}
93
95{
97 if(fChordFinder) delete fChordFinder;
98 if(fEquation) delete fEquation;
99 if(fStepper) delete fStepper;
100}
101///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102
103void BesMagneticField::GetFieldValue( const double Point[3], double *Bfield) const
104{
105 double x=Point[0];
106 double y=Point[1];
107 double z=Point[2];
108
109 HepPoint3D r(x,y,z);
111
113 m_pIMF->fieldVector(r,b);
114 else
116
117 Bfield[0]=b.x();
118 Bfield[1]=b.y();
119 Bfield[2]=b.z();
120
121//caogf debug
122// ofstream haha("field_out.dat",ios_base::app);
123// haha<<x/mm<<" "<<y/mm<<" "<<z/mm<<" "<<Bfield[0]/tesla<<" "<<Bfield[1]/tesla<<" "<<Bfield[2]/tesla<<G4endl;
124// haha.close();
125}
126
127//////////////////////////////////////////////////////////////
128//Initialise
129
131{
132
134 fEquation = new G4Mag_UsualEqRhs(this);
135
136 fMinStep = 0.01*mm ; // minimal step of 1 mm is default
137
138 fStepperType =4; // ClassicalRK4 is default stepper
139 fFieldManager = G4TransportationManager::GetTransportationManager()
140 ->GetFieldManager();
141 G4cout<<"before CreateStepperAndChordFinder"<<G4endl;
143}
144
145////////////////////////////////////////////////////////////////////////////////
146// Update field
147//
148
150{
151 SetStepper();
152 G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl ;
153
154 fFieldManager->SetDetectorField(this );
155
156 if(fChordFinder) delete fChordFinder;
157
158 fChordFinder = new G4ChordFinder(this , fMinStep,fStepper);
159
160 fChordFinder->SetDeltaChord(0.25*mm);
161 fFieldManager->SetChordFinder( fChordFinder );
162 fFieldManager->SetDeltaOneStep(1.0e-2*mm);
163 fFieldManager->SetDeltaIntersection(1.0e-3*mm);
164 fFieldManager->SetMinimumEpsilonStep(5.0e-5);
165 fFieldManager->SetMaximumEpsilonStep(1.0e-3);
166
167 G4PropagatorInField* fieldPropagator
168 = G4TransportationManager::GetTransportationManager()
169 ->GetPropagatorInField();
170 G4cout<<"LargestAcceptableStep is "<<fieldPropagator->GetLargestAcceptableStep()/m<<G4endl;
171//read some values
172 G4cout<<"field has created"<<G4endl;
173 G4cout<<"fDelta_One_Step_Value is "<<fFieldManager->GetDeltaOneStep()<<G4endl;
174 G4cout<<"fDelta_Intersection_Val is "<<fFieldManager->GetDeltaIntersection()<<G4endl;
175 G4cout<<"fEpsilonMin is "<<fFieldManager->GetMinimumEpsilonStep()<<G4endl;
176 G4cout<<"fEpsilonMax is "<< fFieldManager->GetMaximumEpsilonStep()<<G4endl;
177 return;
178}
179
180/////////////////////////////////////////////////////////////////////////////
181//
182// Set stepper according to the stepper type
183//
184
186{
187 if(fStepper) delete fStepper;
188
189 switch ( fStepperType )
190 {
191 case 0:
192 fStepper = new G4ExplicitEuler( fEquation );
193 G4cout<<"G4ExplicitEuler is called"<<G4endl;
194 break;
195 case 1:
196 fStepper = new G4ImplicitEuler( fEquation );
197 G4cout<<"G4ImplicitEuler is called"<<G4endl;
198 break;
199 case 2:
200 fStepper = new G4SimpleRunge( fEquation );
201 G4cout<<"G4SimpleRunge is called"<<G4endl;
202 break;
203 case 3:
204 fStepper = new G4SimpleHeum( fEquation );
205 G4cout<<"G4SimpleHeum is called"<<G4endl;
206 break;
207 case 4:
208 fStepper = new G4ClassicalRK4( fEquation );
209 G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
210 break;
211 case 5:
212 fStepper = new G4HelixExplicitEuler( fEquation );
213 G4cout<<"G4HelixExplicitEuler is called"<<G4endl;
214 break;
215 case 6:
216 fStepper = new G4HelixImplicitEuler( fEquation );
217 G4cout<<"G4HelixImplicitEuler is called"<<G4endl;
218 break;
219 case 7:
220 fStepper = new G4HelixSimpleRunge( fEquation );
221 G4cout<<"G4HelixSimpleRunge is called"<<G4endl;
222 break;
223 case 8:
224 fStepper = new G4CashKarpRKF45( fEquation );
225 G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
226 break;
227 case 9:
228 fStepper = new G4RKG3_Stepper( fEquation );
229 G4cout<<"G4RKG3_Stepper is called"<<G4endl;
230 break;
231 default: fStepper = 0;
232 }
233 return;
234}
235
236/////////////////////////////////////////////////////////////////////////////
238{
239 fFieldManager = G4TransportationManager::GetTransportationManager()
240 ->GetFieldManager();
241 fFieldManager->SetDeltaOneStep(newvalue);
242}
244{
245 fFieldManager = G4TransportationManager::GetTransportationManager()->GetFieldManager();
246 fFieldManager->SetDeltaIntersection(newvalue);
247}
249{
250 fFieldManager = G4TransportationManager::GetTransportationManager()->GetFieldManager();
251 fFieldManager->SetMinimumEpsilonStep(newvalue);
252}
254{
255 fFieldManager =G4TransportationManager::GetTransportationManager()->GetFieldManager();
256 fFieldManager->SetMaximumEpsilonStep(newvalue);
257}
258
HepGeom::Point3D< double > HepPoint3D
HepGeom::Vector3D< double > HepVector3D
G4Mag_UsualEqRhs * fEquation
void SetMaximumEpsilonStep(double newvalue)
void CreateStepperAndChordFinder()
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]
double x[1000]
const double b
Definition: slope.cxx:9