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