BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagMuonSpoiler.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 "BDSFieldMagMuonSpoiler.hh"
20#include "BDSMagnetStrength.hh"
21#include "BDSUtilities.hh"
22
23#include "globals.hh"
24#include "G4ThreeVector.hh"
25
26#include <cmath>
27
28BDSFieldMagMuonSpoiler::BDSFieldMagMuonSpoiler(BDSMagnetStrength const* strength,
29 G4double const /*brho*/)
30{
31 bField = (*strength)["field"];
33#ifdef BDSDEBUG
34 G4cout << __METHOD_NAME__ << "B = " << bField << G4endl;
35#endif
36}
37
38G4ThreeVector BDSFieldMagMuonSpoiler::GetField(const G4ThreeVector &position,
39 const G4double /*t*/) const
40{
41 G4double x = position.x();
42 G4double y = position.y();
43 G4double r = std::hypot(std::abs(x), std::abs(y));
44
45 G4ThreeVector localField;
46 G4double cyor = y/r;
47 if (std::isnan(cyor))
48 {cyor = 0;}
49 G4double cxor = -x/r;
50 if (std::isnan(cxor))
51 {cxor = 0;}
52 localField[0] = cyor * bField;
53 localField[1] = cxor * bField;
54 localField[2] = 0;
55
56 return localField;
57}
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Access the field value.
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())