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