BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagSextupole.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSDebug.hh"
19#include "BDSFieldMagSextupole.hh"
20#include "BDSMagnetStrength.hh"
21#include "BDSUtilities.hh"
22
23#include "globals.hh" // geant4 types / globals
24#include "G4ThreeVector.hh"
25
26#include "CLHEP/Units/SystemOfUnits.h"
27
28#include <cmath>
29
31 G4double const brho)
32{
33 // B'' = d^2By/dx^2 = Brho * (1/Brho d^2By/dx^2) = Brho * k2
34 bDoublePrime = brho * (*strength)["k2"] / CLHEP::m3;
37#ifdef BDSDEBUG
38 G4cout << __METHOD_NAME__ << "B'' = " << bDoublePrime << G4endl;
39#endif
40}
41
42G4ThreeVector BDSFieldMagSextupole::GetField(const G4ThreeVector& position,
43 const G4double /*t*/) const
44{
45 // B_x = 2*x*y * (B''/2!)
46 // B_y = (x^2 - y^2) * (B''/2!)
47 // B_z = 0
48
49 G4ThreeVector localField;
50 localField[0] = position.x() * position.y() * bDoublePrime;
51 localField[1] = (std::pow(position.x(),2) - std::pow(position.y(),2)) * halfBDoublePrime;
52 localField[2] = 0;
53
54 return localField;
55}
BDSFieldMagSextupole()
Private default constructor to avoid usage.
G4double bDoublePrime
B'' - second derivative of the magnetic field.
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Access the field value.
G4double halfBDoublePrime
bDoublePrime / 2! cached
G4bool finiteStrength
Flag to cache whether finite nor not.
Efficient storage of magnet strengths.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())