Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
surface.h
Go to the documentation of this file.
1#ifndef SURFACE_H
2#define SURFACE_H
3#include <iostream>
6/*
7Volume building from surfaces.
8
9Copyright (c) 2000 Igor B. Smirnov
10
11The file can be used, copied, modified, and distributed
12according to the terms of GNU Lesser General Public License version 2.1
13as published by the Free Software Foundation,
14and provided that the above copyright notice, this permission notice,
15and notices about any modifications of the original text
16appear in all copies and in supporting documentation.
17The file is provided "as is" without express or implied warranty.
18*/
19
20namespace Heed {
21
22const int pqqsurf = 10;
23const int pqcrossurf = 4;
24
25/// Surface base class.
26
27class surface : public absref {
28 public:
29 virtual surface* copy() const = 0;
30 virtual ~surface() {}
31 virtual int check_point_inside(const point& fpt, const vec& dir,
32 vfloat fprec) const = 0;
33 // If two volumes are exactly adjusted, it may happens that the point
34 // belongs to both volumes, to their borders. If dir != dv0,
35 // the exiting volume is ignored.
36
37 virtual int check_point_inside1(const point& fpt, int s_ext,
38 vfloat fprec) const = 0;
39 // s_ext=0 - entering
40 // 1 - exiting
41
42 virtual int range(const trajestep& fts, vfloat* crange, point* cpt,
43 int* s_ext) const = 0;
44 // Does not change fts
45 // If no cross or cross father than fts.mrange,
46 // returns 0 and does not change fts
47 // If there are crosses nearer than fts.mrange,
48 // returns number of crosses and assign crange, cpt, and s_ext.
49 // crange and cpt should be arranged.
50 // s_ext: 0 - entry to inside
51 // 1 - exit from inside
52 // 2 - uncertain
53 // The last crossing are then ignored.
54 // The following case should be excluded:
55 // The point is approximately on the surface.
56 // dir is directed outside from the inside space.
57 //
58 // if surface is unlimited like a plane, and point is exactly on the plane,
59 // the range is 0, s_ext is taken from direction.
60 // In case of parallel to border, s_ext=2.
61
62 virtual int cross(const polyline& fpl, point* cntrpt, int& qcntrpt,
63 vfloat prec) const = 0;
64 virtual void print(std::ostream& file, int l) const = 0;
65};
66
67// **** splane ****
68
69class splane : public surface {
70 public:
72 vec dir_ins; // direction to inside, supposed to be unit length (What for?)
73 protected:
74 virtual void get_components(ActivePtr<absref_transmit>& aref_tran);
76
77 public:
78 /// Default constructor
79 splane() : pn() {}
80 splane(const splane& fsp) : surface(fsp), pn(fsp.pn), dir_ins(fsp.dir_ins) {}
81 splane(const plane& fpn, const vec& fdir_ins)
82 : pn(fpn), dir_ins(unit_vec(fdir_ins)) {}
83 /// Destructor
84 virtual ~splane() {}
85
86 int check_point_inside(const point& fpt, const vec& dir, vfloat fprec) const;
87 int check_point_inside1(const point& fpt, int s_ext, vfloat fprec) const;
88 // s_ext=0 - entering
89 // 1 - exiting
90 // 15.02.2006: Remark on check_point_inside vs. check_point_inside1.
91 // check_point_inside1 allows one to override the behaviour when
92 // the point is exactly on the surface.
93 // If the moving point is entering one surface and simultaneously exiting
94 // another one, it would not be recognized as entering the volume.
95 // This virtually prohibits the creation of the control surfaces: volumes
96 // with zero width, where the particle makes stop in order to be registered
97 // in user check_point function.
98 // Therefore when the function ulsvolume::range_ext checks that the
99 // entry point is inside the volume, it calls check_point_inside1
100 // with s_ext == 0, implying that the particle is entering
101 // all the surfaces, thus faking the entering even if the particle is
102 // actually exiting. This allows to make a stop there.
103
104 int range(const trajestep& fts, vfloat* crange, point* cpt, int* s_ext) const;
105 // Does not change fts
106 // If no cross, returns 0 a
107 // If there are crosses, returns number of them and
108 // assign crange and cpt
109
110 int cross(const polyline& fpl, point* cntrpt, int& qcntrpt,
111 vfloat prec) const {
112 polyline* plh = new polyline[fpl.Gqsl()];
113 int qplh;
114 int i = pn.cross(fpl, cntrpt, qcntrpt, plh, qplh, prec);
115 delete[] plh;
116 return i;
117 }
118 virtual void print(std::ostream& file, int l) const;
119 virtual splane* copy() const { return new splane(*this); }
120};
121
122/// Unlimited surfaces volume.
123
124class ulsvolume : public absvol {
125 // The surface itself can be not convex.
126 // But that part of surface which is border of the volume
127 // must be from the right internal side from the other surfaces.
128 // It can be formulated by the other way: neigbouring crossing surfaces
129 // should cross only in the corners of the shape.
130 // This allows to formulate algorithm of finding nearest cross of a track
131 // with border of this type of volume:
132 // For tracks coming (entering) from outside:
133 // Nearest entering crossing point of track with a surface
134 // which is from inside of the other surfaces.
135 // For tracks exiting from inside:
136 // Nearest crossing point of track with a surface for exiting track.
137 // For each crossing point we know whether or not the track exits or
138 // enters to inside of this surface.
139 // This allows to reject that crossing points which are exiting for
140 // track going from outside volume.
141 // It allows to make cylinders, tubes and many other complicated shapes.
142
143 public:
144 int qsurf;
146 std::string name;
147
148 protected:
149 surface* adrsurf[pqqsurf]; // used only for get_components
150 virtual void get_components(ActivePtr<absref_transmit>& aref_tran);
151
152 public:
153 /// Default constructor.
154 ulsvolume();
155 ulsvolume(surface* fsurf[pqqsurf], int fqsurf, char* fname, vfloat fprec);
157 ulsvolume(const ulsvolume& fv);
158 /// Destructor
159 virtual ~ulsvolume() {}
160
161 int check_point_inside(const point& fpt, const vec& dir) const;
162
163 int range_ext(trajestep& fts, int s_ext) const;
164 // If no cross, returns 0 and does not change fts
165 // If there is cross, returns 1 and assign fts.mrange and fts.mpoint
166 void ulsvolume_init(surface* fsurf[pqqsurf], int fqsurf,
167 const std::string& fname, vfloat fprec);
168
169 virtual void income(gparticle* /*gp*/) {}
170 virtual void chname(char* nm) const {
171 strcpy(nm, "ulsvolume: ");
172 strcat(nm, name.c_str());
173 }
174 virtual void print(std::ostream& file, int l) const;
175 virtual ulsvolume* copy() const { return new ulsvolume(*this); }
176};
177
178class manip_ulsvolume : public manip_absvol, public ulsvolume {
179 public:
183 /// Destructor
184 virtual ~manip_ulsvolume() {}
185
186 virtual absvol* Gavol() const { return (ulsvolume*)this; }
187 virtual void chname(char* nm) const {
188 strcpy(nm, "manip_ulsvolume: ");
189 strcat(nm, name.c_str());
190 }
191 virtual void print(std::ostream& file, int l) const;
192 virtual manip_ulsvolume* copy() const { return new manip_ulsvolume(*this); }
193};
194}
195
196#endif
Active pointer or automatic container or controlling pointer.
Definition: AbsPtr.h:199
Abstract base classs for volume "manipulators".
Definition: volume.h:178
virtual ~manip_ulsvolume()
Destructor.
Definition: surface.h:184
virtual absvol * Gavol() const
Get the volume.
Definition: surface.h:186
virtual void chname(char *nm) const
Definition: surface.h:187
virtual void print(std::ostream &file, int l) const
Definition: surface.cpp:402
virtual manip_ulsvolume * copy() const
Definition: surface.h:192
manip_ulsvolume(const ulsvolume &f)
Definition: surface.h:182
Plane, defined by defined by a point and a vector normal to the plane.
Definition: plane.h:24
point cross(const straight &sl) const
Definition: plane.cpp:74
Point.
Definition: vec.h:374
Polyline.
Definition: polyline.h:23
int Gqsl() const
Definition: polyline.h:40
plane pn
Definition: surface.h:71
virtual ~splane()
Destructor.
Definition: surface.h:84
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: surface.cpp:21
splane(const plane &fpn, const vec &fdir_ins)
Definition: surface.h:81
int range(const trajestep &fts, vfloat *crange, point *cpt, int *s_ext) const
Definition: surface.cpp:58
int check_point_inside1(const point &fpt, int s_ext, vfloat fprec) const
Definition: surface.cpp:47
vec dir_ins
Definition: surface.h:72
virtual splane * copy() const
Definition: surface.h:119
splane()
Default constructor.
Definition: surface.h:79
virtual void print(std::ostream &file, int l) const
Definition: surface.cpp:178
splane(const splane &fsp)
Definition: surface.h:80
static absrefabsref::*[2] aref_splane
Definition: surface.h:75
int check_point_inside(const point &fpt, const vec &dir, vfloat fprec) const
Definition: surface.cpp:25
int cross(const polyline &fpl, point *cntrpt, int &qcntrpt, vfloat prec) const
Definition: surface.h:110
Surface base class.
Definition: surface.h:27
virtual int range(const trajestep &fts, vfloat *crange, point *cpt, int *s_ext) const =0
virtual int check_point_inside1(const point &fpt, int s_ext, vfloat fprec) const =0
virtual void print(std::ostream &file, int l) const =0
virtual ~surface()
Definition: surface.h:30
virtual int cross(const polyline &fpl, point *cntrpt, int &qcntrpt, vfloat prec) const =0
virtual surface * copy() const =0
virtual int check_point_inside(const point &fpt, const vec &dir, vfloat fprec) const =0
Unlimited surfaces volume.
Definition: surface.h:124
virtual void income(gparticle *)
Definition: surface.h:169
ulsvolume()
Default constructor.
Definition: surface.cpp:335
std::string name
Definition: surface.h:146
virtual ulsvolume * copy() const
Definition: surface.h:175
surface * adrsurf[pqqsurf]
Definition: surface.h:149
virtual void print(std::ostream &file, int l) const
Definition: surface.cpp:377
virtual void chname(char *nm) const
Definition: surface.h:170
int check_point_inside(const point &fpt, const vec &dir) const
Definition: surface.cpp:194
int range_ext(trajestep &fts, int s_ext) const
Definition: surface.cpp:212
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: surface.cpp:189
virtual ~ulsvolume()
Destructor.
Definition: surface.h:159
void ulsvolume_init(surface *fsurf[pqqsurf], int fqsurf, const std::string &fname, vfloat fprec)
Definition: surface.cpp:339
ActivePtr< surface > surf[pqqsurf]
Definition: surface.h:145
Definition: vec.h:186
Definition: BGMesh.cpp:5
const int pqqsurf
Definition: surface.h:22
const int pqcrossurf
Definition: surface.h:23
double vfloat
Definition: vfloat.h:16