44 #define M_PI 3.14159265358979323846
47 string EGS_SimpleCone::type =
"EGS_SimpleCone";
48 string EGS_ParallelCones::type =
"EGS_ParallelCones";
49 string EGS_ConeSet::type =
"EGS_ConeSet";
50 string EGS_ConeStack::type =
"EGS_ConeStack";
52 void EGS_ConeStack::clear(
bool all) {
55 for (
int j=0; j<nl; j++) {
56 for (
int i=0; i<nr[j]; i++)
57 if (!cones[j][i]->
deref()) {
73 void EGS_ConeStack::resize() {
74 int nnew = nltot + N_CS_GROW;
75 int *new_nr =
new int [nnew], *new_flag =
new int [nnew];
76 EGS_Float *new_pos =
new EGS_Float [nnew+1];
78 for (
int j=0; j<nl; j++) {
80 new_flag[j] = flag[j];
82 new_cones[j] = cones[j];
85 new_pos[nl] = pos[nl];
95 void EGS_ConeStack::addLayer(EGS_Float thick,
const vector<EGS_Float> &rtop,
96 const vector<EGS_Float> &rbottom,
97 const vector<string> &med_names) {
98 int this_nr = rbottom.size();
100 egsWarning(
"EGS_ConeStack::addLayer: no bottom radii?\n");
104 if ((
int)med_names.size() != this_nr) {
105 egsWarning(
"EGS_ConeStack::addLayer: number of cone radii (%d) is"
106 " different from number of media (%d)\n",this_nr,med_names.size());
110 bool same_radii =
false;
111 if (rtop.size() != rbottom.size()) {
114 egsWarning(
"EGS_ConeStack::addLayer: zero top radii does not"
115 " work for the first layer\n");
122 egsWarning(
"EGS_ConeStack::addLayer: number of bottom radii (%d)"
123 " is different from number of top radii (%d)\n",this_nr,
134 Rout = rbottom[this_nr-1];
144 pos[nl+1] = pos[nl] + thick;
147 for (
int ir=0; ir<this_nr; ir++) {
148 EGS_Float Rtop = same_radii ? cones[nl-1][ir]->getRadius(x) : rtop[ir];
151 cones[nl][ir]->
ref();
152 if (ir == this_nr-1) {
170 if (this_nr > nmax) {
180 void EGS_ConeStack::printInfo()
const {
183 for (
int il=0; il<nl; il++) {
189 for (i=0; i<nr[il]; i++) {
193 x = xo + a*(pos[il+1]-pos[0]);
194 for (i=0; i<nr[il]; i++) {
198 for (i=0; i<nr[il]; i++) {
203 egsInformation(
"=====================================================\n");
206 void EGS_SimpleCone::printInfo()
const {
210 egsInformation(
" opening angle = %g degrees\n",180*atan(gamma)/M_PI);
217 egsInformation(
"=====================================================\n");
220 void EGS_ParallelCones::printInfo()
const {
223 egsInformation(
" opening angle = %g degrees\n",180*atan(gamma)/M_PI);
226 for (
int j=0; j<nc; j++) {
229 egsInformation(
"\n=====================================================\n");
232 void EGS_ConeSet::printInfo()
const {
238 for (
int j=0; j<nc; j++) {
241 egsInformation(
"\n=====================================================\n");
250 egsWarning(
"createGeometry(cones): null input?\n");
254 int err = input->
getInput(
"type",type);
256 egsWarning(
"createGeometry(cones): object type not specified\n");
259 if (type ==
"EGS_ConeStack") {
260 vector<EGS_Float> axis;
263 egsWarning(
"createGeometry(EGS_ConeStack): no axis input\n");
266 if (axis.size() != 6) {
267 egsWarning(
"createGeometry(EGS_ConeStack): wrong axis input"
268 " (expecting 6 instead of %d inputs)\n",axis.size());
276 vector<int> layerLabels;
278 vector<EGS_Float> rtop, rbottom;
279 vector<string> media;
281 err = layer->
getInput(
"thickness",thickness);
283 egsWarning(
"createGeometry(EGS_ConeStack): missing 'thickness'"
284 " input for layer %d\n --> layer ignored\n",nl);
286 err = layer->
getInput(
"top radii",rtop);
287 err = layer->
getInput(
"bottom radii",rbottom);
288 if (err)
egsWarning(
"createGeometry(EGS_ConeStack): missing "
289 "'bottom radii' input for layer %d\n",nl);
290 int err1 = layer->
getInput(
"media",media);
291 if (err1)
egsWarning(
"createGeometry(EGS_ConeStack): missing "
292 "'media' input for layer %d\n",nl);
297 g->addLayer(thickness,rtop,rbottom,media);
300 layerLabels.push_back(g->
setLabels(layer));
305 egsWarning(
"createGeometry(EGS_ConeStack): zero layers\n");
312 for (
size_t i=0; i<layerLabels.size(); i++) {
313 for (
int j=0; j<layerLabels[i]; j++) {
314 g->shiftLabelRegions(count,i);
327 vector<EGS_Float> tmp;
330 if (err || tmp.size() != 3)
331 egsWarning(
"createGeometry(cones): no 'apex' input, "
332 "assuming (0,0,0)\n");
343 if (err || tmp.size() != 3)
344 egsWarning(
"createGeometry(cones): no 'axis' input, assuming "
353 if (input->
compare(type,
"EGS_ConeSet")) {
354 vector<EGS_Float> angles;
355 err = input->
getInput(
"opening angles",angles);
356 bool is_radian =
false;
359 err = input->
getInput(
"opening angles in radian",angles);
361 egsWarning(
"createGeometry(cones): no 'opening angles' or "
362 "'opening angles in radian' input\n");
369 int nc = angles.size();
370 EGS_Float *gamma =
new EGS_Float [nc];
371 for (
int j=0; j<nc; j++) {
372 if (angles[j] <= 0) {
373 egsWarning(
"createGeometry(cones): opening angles must be"
378 EGS_Float a = angles[j];
383 egsWarning(
"createGeometry(cones): opening angles can not be"
384 " greater than Pi/2\n");
389 if (angles[j] <= angles[j-1]) {
390 egsWarning(
"createGeometry(cones): opening angles must be"
391 " in increasing order\n");
405 err = input->
getInput(
"opening angle",angle);
407 err = input->
getInput(
"opening angle in radian",angle);
409 egsWarning(
"createGeometry(cones): no 'opening angle' or "
410 "'opening angle in radian' input\n");
417 if (angle >= M_PI/2) {
418 egsWarning(
"createGeometry(cones): it is not allowed to have"
419 " an opening angle greater than Pi/2, your input was %g\n",angle);
422 EGS_Float gamma = tan(angle);
423 if (input->
compare(type,
"EGS_SimpleCone")) {
426 err = input->
getInput(
"height",height);
429 egsWarning(
"createGeometry(cones): the cone height"
430 " must be greater than zero, your input was %g\n",height);
437 else if (input->
compare(type,
"EGS_ParallelCones")) {
439 err = input->
getInput(
"apex distances",d);
442 if (!err && d.size() > 0) {
443 dist =
new EGS_Float [d.size()];
444 for (
size_t j=0; j<d.size(); j++) {
455 egsWarning(
"createGeometry(cones): unknown object type %s\n",
A single cone that may be open (i.e. extends to infinity or closed by a plane perpendicular to the co...
int deref()
Decrease the reference count to this geometry.
virtual void printInfo() const
Print information about this geometry.
A class representing 3D vectors.
int setLabels(EGS_Input *input)
Set the labels from an input block.
A set of "parallel cones" (i.e. cones with the same axis and opening angles but different apexes) ...
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
virtual void setBScaling(int start, int end, EGS_Float bf)
Set the B field scaling factor in regions.
Various cone geometries: header.
void setMedia(EGS_Input *inp)
Set the media in the geometry from the input pointed to by inp.
A set of cones with different opening angles but the same axis and apexes.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
bool is_convex
Is this geometry convex?
void setMedium(const string &Name)
Set all regions to a medium with name Name.
void setName(EGS_Input *inp)
Set the name of the geometry from the input inp.
EGS_Float boundaryTolerance
Boundary tolerance for geometries that need it.
int ref()
Increase the reference count to this geometry.
int nreg
Number of local regions in this geometry.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.