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 - 2024.
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 synchronousTIn,
32 G4double amplitudeOffsetIn,
33 G4double amplitudeScaleIn):
34 angularFrequency(CLHEP::twopi * frequencyIn),
35 phase(phaseIn),
36 synchronousT(synchronousTIn),
37 offset(amplitudeOffsetIn),
38 scale(amplitudeScaleIn)
39{
40 if (frequencyIn < 0)
41 {throw BDSException(__METHOD_NAME__, "\frequency\" must be >= 0");}
42}
43
44G4double BDSModulatorSinT::Factor(const G4ThreeVector& /*xyz*/,
45 G4double T) const
46{
47 G4double factor = offset + scale*std::sin(angularFrequency*(T-synchronousT) + phase);
48 return factor;
49}
50
52{
53 if (angularFrequency == 0)
54 {return std::numeric_limits<double>::max();}
55 else
56 {
57 G4double wavelength = CLHEP::twopi * CLHEP::c_light / angularFrequency;
58 return wavelength / 20;
59 }
60}
General exception with possible name of object and message.
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 wavelength / 20 of the oscillator.