BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSModulatorSinT.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSModulatorSinT.hh"
22
23#include "CLHEP/Units/PhysicalConstants.h"
24#include "CLHEP/Units/SystemOfUnits.h"
25
26#include <cmath>
27#include <limits>
28
29BDSModulatorSinT::BDSModulatorSinT(G4double frequencyIn,
30 G4double phaseIn,
31 G4double amplitudeOffsetIn,
32 G4double amplitudeScaleIn):
33 angularFrequency(CLHEP::twopi * frequencyIn),
34 phase(phaseIn),
35 offset(amplitudeOffsetIn),
36 scale(amplitudeScaleIn)
37{
38 if (frequencyIn < 0)
39 {throw BDSException(__METHOD_NAME__, "\frequency\" must be >= 0");}
40}
41
42G4double BDSModulatorSinT::Factor(const G4ThreeVector& /*xyz*/,
43 G4double T) const
44{
45 G4double factor = offset + scale*std::sin(angularFrequency*T + phase);
46 return factor;
47}
48
50{
51 if (angularFrequency == 0)
52 {return std::numeric_limits<double>::max();}
53 else
54 {
55 G4double wavelength = CLHEP::twopi * CLHEP::c_light / angularFrequency;
56 return wavelength / 20;
57 }
58}
General exception with possible name of object and message.
Definition: BDSException.hh:35
virtual G4double Factor(const G4ThreeVector &xyz, G4double T) const
Returns value of equation in brief at the top of this file.
virtual G4double RecommendedMaxStepLength() const
Return the wavlength / 20 of the oscillator.