BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSSamplerCustom.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 "BDSApertureInfo.hh"
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSGlobalConstants.hh"
22#include "BDSSamplerCustom.hh"
23
24#include "globals.hh" // geant4 types / globals
25#include "G4Box.hh"
26#include "G4LogicalVolume.hh"
27#include "G4Tubs.hh"
28
29G4double BDSSamplerCustom::chordLength = -1;
30
31BDSSamplerCustom::BDSSamplerCustom(const G4String& nameIn,
32 const BDSApertureInfo& shape,
33 G4int filterSetIDIn):
34 BDSSampler(nameIn, filterSetIDIn)
35{
36 /*
37 BDSApertureFactory fac;
38 containerSolid = fac.CreateAperture(name + "_aperture",
39 BDSSamplerPlane::chordLength,
40 shape);
41 */
42 // We make the sampler 10x bigger than normal as it's still really small
43 // but less likely to cause overlap problems. The original sampler width
44 // is designed to be functional but as small as possible to avoid introducing
45 // extra length for optical tracking.
46 switch (shape.apertureType.underlying())
47 {
48 case BDSApertureType::circular:
49 case BDSApertureType::circularvacuum:
50 {
51 containerSolid = new G4Tubs(name + "_solid",
52 0,
53 shape.aper1,
54 0.5*chordLength,
55 0,
56 CLHEP::twopi);
57 break;
58 }
59 case BDSApertureType::rectangular:
60 {
61 containerSolid = new G4Box(name + "_solid",
62 shape.aper1,
63 shape.aper2,
64 0.5*chordLength);
65 break;
66 }
67 default:
68 {
69 std::string msg = "Shape \"" + shape.apertureType.ToString() + "\" is not currently supported.\n";
70 msg += "Please use circular or rectangular.";
71 throw BDSException(__METHOD_NAME__, msg);
72 break;
73 }
74 }
75
76 BDSExtent ae = shape.Extent();
77 G4double dz = 0.5*chordLength;
78 SetExtent(BDSExtent(ae.XNeg(), ae.XPos(), ae.YNeg(), ae.YPos(), -dz, dz));
79
80 CommonConstruction();
81}
Holder class for all information required to describe an aperture.
G4double aper1
Public member for direct access.
G4double aper2
Public member for direct access.
BDSExtent Extent() const
BDSApertureType apertureType
Public member for direct access.
General exception with possible name of object and message.
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
G4double XPos() const
Accessor.
Definition BDSExtent.hh:65
G4double XNeg() const
Accessor.
Definition BDSExtent.hh:64
G4double YNeg() const
Accessor.
Definition BDSExtent.hh:66
G4double YPos() const
Accessor.
Definition BDSExtent.hh:67
BDSSamplerCustom()=delete
No default constructor.
Base class and registry of sampler instances.
Definition BDSSampler.hh:35
type underlying() const
return underlying value (can be used in switch statement)