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) 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 "BDSException.hh"
20#include "BDSModulatorSinT.hh"
21
22#include "CLHEP/Units/PhysicalConstants.h"
23#include "CLHEP/Units/SystemOfUnits.h"
24
25#include <cmath>
26#include <limits>
27
28BDSModulatorSinT::BDSModulatorSinT(G4double frequencyIn,
29 G4double phaseIn,
30 G4double synchronousTIn,
31 G4double amplitudeOffsetIn,
32 G4double amplitudeScaleIn):
33 angularFrequency(CLHEP::twopi * frequencyIn),
34 phase(phaseIn),
35 synchronousT(synchronousTIn),
36 offset(amplitudeOffsetIn),
37 scale(amplitudeScaleIn)
38{
39 if (frequencyIn < 0)
40 {throw BDSException(__METHOD_NAME__, "\frequency\" must be >= 0");}
41}
42
43G4double BDSModulatorSinT::Factor(const G4ThreeVector& /*xyz*/,
44 G4double T) const
45{
46 G4double factor = offset + scale*std::sin(angularFrequency*(T-synchronousT) + phase);
47 return factor;
48}
49
51{
52 if (angularFrequency == 0)
53 {return std::numeric_limits<double>::max();}
54 else
55 {
56 G4double wavelength = CLHEP::twopi * CLHEP::c_light / angularFrequency;
57 return wavelength / 20;
58 }
59}
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.