BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSApertureInfo.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 "BDSApertureType.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSExtent.hh"
23#include "BDSUtilities.hh"
24
25#include "globals.hh" // geant4 types / globals
26
27#include <cmath>
28
30 G4double aper1In,
31 G4double aper2In,
32 G4double aper3In,
33 G4double aper4In,
34 G4String nameForError):
35 apertureType(apertureTypeIn),
36 aper1(aper1In),
37 aper2(aper2In),
38 aper3(aper3In),
39 aper4(aper4In)
40{
41 CheckApertureInfo(nameForError);
42}
43
44BDSApertureInfo::BDSApertureInfo(G4String apertureTypeIn,
45 G4double aper1In,
46 G4double aper2In,
47 G4double aper3In,
48 G4double aper4In,
49 G4String nameForError):
50 aper1(aper1In),
51 aper2(aper2In),
52 aper3(aper3In),
53 aper4(aper4In)
54{
56 CheckApertureInfo(nameForError);
57}
58
60 G4String apertureTypeIn,
61 G4double aper1In,
62 G4double aper2In,
63 G4double aper3In,
64 G4double aper4In,
65 G4String nameForError)
66{
67 if (apertureTypeIn.empty())
68 {apertureType = defaultInfo->apertureType;}
69 else
70 {apertureType = BDS::DetermineApertureType(apertureTypeIn);}
71
72 if (!BDS::IsFinite(aper1In))
73 {aper1 = defaultInfo->aper1;}
74 else
75 {aper1 = aper1In;}
76 if (!BDS::IsFinite(aper2In))
77 {aper2 = defaultInfo->aper2;}
78 else
79 {aper2 = aper2In;}
80 if (!BDS::IsFinite(aper3In))
81 {aper3 = defaultInfo->aper3;}
82 else
83 {aper3 = aper3In;}
84 if (!BDS::IsFinite(aper4In))
85 {aper4 = defaultInfo->aper4;}
86 else
87 {aper4 = aper4In;}
88
89 CheckApertureInfo(nameForError);
90}
91
92void BDSApertureInfo::CheckApertureInfo(const G4String& nameForError)
93{
94 try
95 {
96 switch (apertureType.underlying())
97 {
98 case BDSApertureType::circular:
99 {InfoOKForCircular(); break;}
100 case BDSApertureType::elliptical:
101 {InfoOKForElliptical(); break;}
102 case BDSApertureType::rectangular:
103 {InfoOKForRectangular(); break;}
104 case BDSApertureType::lhc:
105 {InfoOKForLHC(); break;}
106 case BDSApertureType::lhcdetailed:
107 {InfoOKForLHCDetailed(); break;}
108 case BDSApertureType::rectellipse:
109 {InfoOKForRectEllipse(); break;}
110 case BDSApertureType::racetrack:
111 {InfoOKForRaceTrack(); break;}
112 case BDSApertureType::octagonal:
113 {InfoOKForOctagonal(); break;}
114 case BDSApertureType::clicpcl:
115 {InfoOKForClicPCL(); break;}
116 default:
118 }
119 }
120 catch (BDSException& exception)
121 {
122 exception.SetName(nameForError);
123 throw;
124 }
125}
126
128{
129 G4double extX = 0;
130 G4double extY = 0;
131 switch (apertureType.underlying())
132 {
133 case BDSApertureType::circular:
134 case BDSApertureType::circularvacuum:
135 {
136 extX = aper1;
137 extY = aper1;
138 break;
139 }
140 case BDSApertureType::elliptical:
141 case BDSApertureType::rectangular:
142 case BDSApertureType::octagonal:
143 {
144 extX = aper1;
145 extY = aper2;
146 break;
147 }
148 case BDSApertureType::lhc:
149 case BDSApertureType::lhcdetailed:
150 case BDSApertureType::rectellipse:
151 {
152 extX = std::min(aper1, aper3);
153 extY = std::min(aper2, aper3);
154 break;
155 }
156 case BDSApertureType::racetrack:
157 {
158 extX = aper1 + aper3;
159 extY = aper2 + aper3;
160 break;
161 }
162 case BDSApertureType::clicpcl:
163 {// this one is asymmetric so done separately
164 G4double extentX = aper1;
165 G4double extentYLow = -std::abs(aper3);
166 G4double extentYHigh = aper2 + aper4;
167 BDSExtent ext = BDSExtent(-extentX, extentX,
168 extentYLow, extentYHigh,
169 0,0);
170 return ext;
171 break;
172 }
173 default:break;
174 }
175 BDSExtent ext = BDSExtent(extX, extY, 0);
176 return ext;
177}
178
180{
181 BDSExtent ext = Extent();
182 return ext.MaximumAbsTransverse();
183}
184
186 G4bool setAper2,
187 G4bool setAper3,
188 G4bool setAper4)
189{
190#ifdef BDSDEBUG
191 G4cout << __METHOD_NAME__ << G4endl;
192 G4cout << "aper1: " << aper1 << " check it? " << setAper1 << G4endl;
193 G4cout << "aper2: " << aper2 << " check it? " << setAper2 << G4endl;
194 G4cout << "aper3: " << aper3 << " check it? " << setAper3 << G4endl;
195 G4cout << "aper4: " << aper4 << " check it? " << setAper4 << G4endl;
196#endif
197 if (setAper1 && !BDS::IsFinite(aper1))
198 {throw BDSException("","\"aper1\" not set, but required to be.");}
199 if (setAper2 && !BDS::IsFinite(aper2))
200 {throw BDSException("","\"aper2\" not set, but required to be.");}
201 if (setAper3 && !BDS::IsFinite(aper3))
202 {throw BDSException("","\"aper3\" not set, but required to be.");}
203 if (setAper4 && !BDS::IsFinite(aper4))
204 {throw BDSException("","\"aper4\" not set, but required to be.");}
205}
206
208{
209 CheckRequiredParametersSet(true, false, false, false);
210}
211
213{
214 CheckRequiredParametersSet(true, true, false, false);
215}
216
218{
219 CheckRequiredParametersSet(true, true, false, false);
220}
221
223{
224 CheckRequiredParametersSet(true, true, true, false);
225
226 if ((aper3 > aper1) && (aper2 < aper3))
227 {throw BDSException("\"aper3\" > \"aper1\" (or \"beamPipeRadius\") for lhc aperture model - will not produce desired shape");}
228
229 if ((aper3 > aper2) && (aper1 < aper3))
230 {throw BDSException("\"aper3\" > \"aper2\" (or \"beamPipeRadius\") for lhc aperture model - will not produce desired shape");}
231}
232
237
239{
240 CheckRequiredParametersSet(true, true, true, true);
241
242 // TODO
243
244 /*
245 //treat rectangle as point coordinates. If this point is inside ellipse,
246 //rectangle is too small -> error should just use elliptical aperture
247 G4double test = std::hypot((aper1/aper3),(aper2/aper4));
248 if (test < 1)
249 {
250 //rectangle too small
251 G4cerr << __METHOD_NAME__ << "WARNING - combination of \"aper1\" and \"aper2\" too small"
252 << " rectangle is entirely inside ellipse - simply use elliptical aperture" << G4endl;
253 throw BDSException(__METHOD_NAME__, "");
254 }
255 */
256 //check if ellipse is b
257 //if ((aper1 > aper3) && (aper2 > aper4))
258 // {;}
259}
260
262{
263 CheckRequiredParametersSet(true, true, true, false);
264}
265
267{
268 CheckRequiredParametersSet(true, true, true, true);
269
270 if (aper3 >= aper1)
271 {throw BDSException("aper3 is >= aper1 - invalid for an octagonal aperture");}
272 if (aper4 >= aper2)
273 {throw BDSException("aper4 is >= aper2 - invalid for an octagonal aperture");}
274}
275
277{
278 CheckRequiredParametersSet(true, true, true, false);
279}
Holder class for all information required to describe an aperture.
void InfoOKForRectangular()
Aperture info check for rectangular aperture.
void CheckApertureInfo(const G4String &nameForError)
void InfoOKForRectEllipse()
Aperture info check for rectellipse aperture.
void InfoOKForLHCDetailed()
Aperture info check for lhc detailed aperture.
G4double IndicativeRadius() const
Return an indicative extent of the beam pipe - typically the maximum of x or y extent.
G4double aper1
Public member for direct access.
void InfoOKForRaceTrack()
Aperture info check for racetrack aperture.
void InfoOKForElliptical()
Aperture info check for elliptical aperture.
G4double aper2
Public member for direct access.
BDSExtent Extent() const
G4double aper3
Public member for direct access.
G4double aper4
Public member for direct access.
BDSApertureInfo()=delete
Private default constructor to ensure one of supplied constructors is used.
void CheckRequiredParametersSet(G4bool setAper1, G4bool setAper2, G4bool setAper3, G4bool setAper4)
void InfoOKForClicPCL()
Aperture info check for CLIC PCL aperture.
void InfoOKForOctagonal()
Aperture info check for octagonal aperture.
void InfoOKForLHC()
Aperture info check for lhc aperture.
void InfoOKForCircular()
Aperture info check for circular aperture.
BDSApertureType apertureType
Public member for direct access.
General exception with possible name of object and message.
void SetName(const std::string &nameIn)
Allow setting of name later.
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
G4double MaximumAbsTransverse() const
Return the maximum absolute value considering only x,y.
Definition BDSExtent.cc:170
type underlying() const
return underlying value (can be used in switch statement)
BDSApertureType DetermineApertureType(G4String apertureType)
function that gives corresponding enum value for string (case-insensitive)
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())