47 #define M_PI 3.14159265358979323846
50 string EGS_SimpleCone::type =
"EGS_SimpleCone";
51 string EGS_ParallelCones::type =
"EGS_ParallelCones";
52 string EGS_ConeSet::type =
"EGS_ConeSet";
53 string EGS_ConeStack::type =
"EGS_ConeStack";
55 void EGS_ConeStack::clear(
bool all) {
58 for (
int j=0; j<nl; j++) {
59 for (
int i=0; i<nr[j]; i++)
60 if (!cones[j][i]->
deref()) {
76 void EGS_ConeStack::resize() {
77 int nnew = nltot + N_CS_GROW;
78 int *new_nr =
new int [nnew], *new_flag =
new int [nnew];
79 EGS_Float *new_pos =
new EGS_Float [nnew+1];
81 for (
int j=0; j<nl; j++) {
83 new_flag[j] = flag[j];
85 new_cones[j] = cones[j];
88 new_pos[nl] = pos[nl];
98 void EGS_ConeStack::addLayer(EGS_Float thick,
const vector<EGS_Float> &rtop,
99 const vector<EGS_Float> &rbottom,
100 const vector<string> &med_names) {
101 int this_nr = rbottom.size();
103 egsWarning(
"EGS_ConeStack::addLayer: no bottom radii?\n");
107 if ((
int)med_names.size() != this_nr) {
108 egsWarning(
"EGS_ConeStack::addLayer: number of cone radii (%d) is"
109 " different from number of media (%d)\n",this_nr,med_names.size());
113 bool same_radii =
false;
114 if (rtop.size() != rbottom.size()) {
117 egsWarning(
"EGS_ConeStack::addLayer: zero top radii does not"
118 " work for the first layer\n");
125 egsWarning(
"EGS_ConeStack::addLayer: number of bottom radii (%d)"
126 " is different from number of top radii (%d)\n",this_nr,
137 Rout = rbottom[this_nr-1];
147 pos[nl+1] = pos[nl] + thick;
150 for (
int ir=0; ir<this_nr; ir++) {
151 EGS_Float Rtop = same_radii ? cones[nl-1][ir]->getRadius(x) : rtop[ir];
154 cones[nl][ir]->
ref();
155 if (ir == this_nr-1) {
173 if (this_nr > nmax) {
183 void EGS_ConeStack::printInfo()
const {
186 for (
int il=0; il<nl; il++) {
192 for (i=0; i<nr[il]; i++) {
196 x = xo + a*(pos[il+1]-pos[0]);
197 for (i=0; i<nr[il]; i++) {
201 for (i=0; i<nr[il]; i++) {
206 egsInformation(
"=====================================================\n");
209 void EGS_SimpleCone::printInfo()
const {
213 egsInformation(
" opening angle = %g degrees\n",180*atan(gamma)/M_PI);
220 egsInformation(
"=====================================================\n");
223 void EGS_ParallelCones::printInfo()
const {
226 egsInformation(
" opening angle = %g degrees\n",180*atan(gamma)/M_PI);
229 for (
int j=0; j<nc; j++) {
232 egsInformation(
"\n=====================================================\n");
235 void EGS_ConeSet::printInfo()
const {
241 for (
int j=0; j<nc; j++) {
244 egsInformation(
"\n=====================================================\n");
253 egsWarning(
"createGeometry(cones): null input?\n");
257 int err = input->
getInput(
"type",type);
259 egsWarning(
"createGeometry(cones): object type not specified\n");
262 if (type ==
"EGS_ConeStack") {
263 vector<EGS_Float> axis;
266 egsWarning(
"createGeometry(EGS_ConeStack): no axis input\n");
269 if (axis.size() != 6) {
270 egsWarning(
"createGeometry(EGS_ConeStack): wrong axis input"
271 " (expecting 6 instead of %d inputs)\n",axis.size());
279 vector<int> layerLabels;
281 vector<EGS_Float> rtop, rbottom;
282 vector<string> media;
284 err = layer->
getInput(
"thickness",thickness);
286 egsWarning(
"createGeometry(EGS_ConeStack): missing 'thickness'"
287 " input for layer %d\n --> layer ignored\n",nl);
289 err = layer->
getInput(
"top radii",rtop);
290 err = layer->
getInput(
"bottom radii",rbottom);
291 if (err)
egsWarning(
"createGeometry(EGS_ConeStack): missing "
292 "'bottom radii' input for layer %d\n",nl);
293 int err1 = layer->
getInput(
"media",media);
294 if (err1)
egsWarning(
"createGeometry(EGS_ConeStack): missing "
295 "'media' input for layer %d\n",nl);
300 g->addLayer(thickness,rtop,rbottom,media);
303 layerLabels.push_back(g->
setLabels(layer));
308 egsWarning(
"createGeometry(EGS_ConeStack): zero layers\n");
315 for (
size_t i=0; i<layerLabels.size(); i++) {
316 for (
int j=0; j<layerLabels[i]; j++) {
317 g->shiftLabelRegions(count,i);
330 vector<EGS_Float> tmp;
333 if (err || tmp.size() != 3)
334 egsWarning(
"createGeometry(cones): no 'apex' input, "
335 "assuming (0,0,0)\n");
346 if (err || tmp.size() != 3)
347 egsWarning(
"createGeometry(cones): no 'axis' input, assuming "
356 if (input->
compare(type,
"EGS_ConeSet")) {
357 vector<EGS_Float> angles;
358 err = input->
getInput(
"opening angles",angles);
359 bool is_radian =
false;
362 err = input->
getInput(
"opening angles in radian",angles);
364 egsWarning(
"createGeometry(cones): no 'opening angles' or "
365 "'opening angles in radian' input\n");
372 int nc = angles.size();
373 EGS_Float *gamma =
new EGS_Float [nc];
374 for (
int j=0; j<nc; j++) {
375 if (angles[j] <= 0) {
376 egsWarning(
"createGeometry(cones): opening angles must be"
381 EGS_Float a = angles[j];
386 egsWarning(
"createGeometry(cones): opening angles can not be"
387 " greater than Pi/2\n");
392 if (angles[j] <= angles[j-1]) {
393 egsWarning(
"createGeometry(cones): opening angles must be"
394 " in increasing order\n");
408 err = input->
getInput(
"opening angle",angle);
410 err = input->
getInput(
"opening angle in radian",angle);
412 egsWarning(
"createGeometry(cones): no 'opening angle' or "
413 "'opening angle in radian' input\n");
420 if (angle >= M_PI/2) {
421 egsWarning(
"createGeometry(cones): it is not allowed to have"
422 " an opening angle greater than Pi/2, your input was %g\n",angle);
425 EGS_Float gamma = tan(angle);
426 if (input->
compare(type,
"EGS_SimpleCone")) {
429 err = input->
getInput(
"height",height);
432 egsWarning(
"createGeometry(cones): the cone height"
433 " must be greater than zero, your input was %g\n",height);
440 else if (input->
compare(type,
"EGS_ParallelCones")) {
442 err = input->
getInput(
"apex distances",d);
445 if (!err && d.size() > 0) {
446 dist =
new EGS_Float [d.size()];
447 for (
size_t j=0; j<d.size(); j++) {
458 egsWarning(
"createGeometry(cones): unknown object type %s\n",
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
int deref()
Decrease the reference count to this geometry.
virtual void setBScaling(int start, int end, EGS_Float bf)
Set the B field scaling factor in regions.
void setMedia(EGS_Input *inp)
Set the media in the geometry from the input pointed to by inp.
int nreg
Number of local regions in this geometry.
bool is_convex
Is this geometry convex?
EGS_Float boundaryTolerance
Boundary tolerance for geometries that need it.
void setName(EGS_Input *inp)
Set the name of the geometry from the input inp.
void setMedium(const string &Name)
Set all regions to a medium with name Name.
int setLabels(EGS_Input *input)
Set the labels from an input block.
virtual void printInfo() const
Print information about this geometry.
int ref()
Increase the reference count to this geometry.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
A set of cones with different opening angles but the same axis and apexes.
A set of "parallel cones" (i.e. cones with the same axis and opening angles but different apexes)
A single cone that may be open (i.e. extends to infinity or closed by a plane perpendicular to the co...
A class representing 3D vectors.
Various cone geometries: header.
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.