BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagDecapole.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 "BDSFieldMagDecapole.hh"
20#include "BDSMagnetStrength.hh"
21
22#include "globals.hh" // geant4 types / globals
23#include "G4ThreeVector.hh"
24
25#include "CLHEP/Units/SystemOfUnits.h"
26
27#include <cmath>
28
30 G4double const brho)
31{
32 // B'''' = d^4By/dx^4 = Brho * (1/Brho d^4By/dx^4) = Brho * k4
33 bQuadruplePrime = brho * (*strength)["k4"] / (CLHEP::m3*CLHEP::m2);
35#ifdef BDSDEBUG
36 G4cout << __METHOD_NAME__ << "B'''' = " << bQuadruplePrime << G4endl;
37#endif
38}
39
40G4ThreeVector BDSFieldMagDecapole::GetField(const G4ThreeVector &position,
41 const G4double /*t*/) const
42{
43 // B_x = 4xy(x^2-y^2) * ( B''''/4!)
44 // B_y = (x^4 - 6x^2y^2 + y^4) * ( B''''/4!)
45 // B_z = 0
46
47 //shortcuts
48 G4double x = position.x();
49 G4double y = position.y();
50
51 G4ThreeVector localField;
52 localField[0] = 4 * x * y * (std::pow(x,2)-std::pow(y,2)) * bQPNormed;
53 localField[1] = (std::pow(x,4) - 6 * std::pow(x,2) * std::pow(y,2) + std::pow(y,4)) * bQPNormed;
54 localField[2] = 0;
55
56 return localField;
57}
G4double bQuadruplePrime
B'''' - the fourth derivative of the magnetic field.
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Access the field value.
BDSFieldMagDecapole()
Private default constructor to force use of supplied constructor.
G4double bQPNormed
B'''' / 4!
Efficient storage of magnet strengths.