Belle II Software development
MagneticField.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <simulation/kernel/MagneticField.h>
10#include <framework/geometry/BFieldManager.h>
11
12#include <framework/gearbox/Unit.h>
13
14#include <CLHEP/Units/SystemOfUnits.h>
15
16#include <globals.hh>
17
18namespace Belle2 {
23 namespace Simulation {
24
25 MagneticField::MagneticField(): G4MagneticField()
26 {
27 }
28
30 {
31 }
32
33 void MagneticField::GetFieldValue(const G4double Point[3], G4double* Bfield) const
34 {
35 static const double pos_conversion{Unit::mm / CLHEP::mm};
36 static const double mag_conversion{CLHEP::tesla / Unit::T};
37 //Get the magnetic field vector from the central magnetic field map (Geant4 uses [mm] as a length unit)
38 const ROOT::Math::XYZVector point = ROOT::Math::XYZVector(Point[0], Point[1], Point[2]) * pos_conversion;
39 // get the field in Geant4 units
40 ROOT::Math::XYZVector magField = BFieldManager::getField(point) * mag_conversion;
41 // and set it
42 magField.GetCoordinates(Bfield);
43 }
44
45 }
47}
void GetFieldValue(const G4double Point[3], G4double *Bfield) const
Sets the magnetic field vector for a specified space point.
static const double mm
[millimeters]
Definition: Unit.h:70
static const double T
[tesla]
Definition: Unit.h:120
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Definition: BFieldManager.h:91
Abstract base class for different kinds of events.