Belle II Software light-2406-ragdoll
Belle2::geometry Namespace Reference

Common code concerning the geometry representation of the detector. More...

Classes

class  CreatorBase
 Pure virtual base class for all geometry creators. More...
 
struct  CreatorFactory
 Very simple class to provide an easy way to register creators with the CreatorManager. More...
 
class  CreatorManager
 Class to manage all creators and provide factory access. More...
 
class  GeometryManager
 Class to manage the creation and conversion of the geometry. More...
 
class  Materials
 Thin wrapper around the Geant4 Material system. More...
 

Enumerations

enum  GeometryTypes {
  FullGeometry ,
  TrackingGeometry ,
  DisplayGeometry
}
 Flag indiciating the type of geometry to be used. More...
 

Functions

void setColor (G4LogicalVolume &volume, const std::string &color)
 Set the color of a logical volume.
 
void setVisibility (G4LogicalVolume &volume, bool visible)
 Helper function to quickly set the visibility of a given volume.
 
G4Polycone * createPolyCone (const std::string &name, const GearDir &params, double &minZ, double &maxZ)
 Create Polycone Shape from XML Parameters.
 
G4Polycone * createRotationSolid (const std::string &name, const GearDir &params, double &minZ, double &maxZ)
 Create a solid by roating two polylines around the Z-Axis.
 
G4Polycone * createRotationSolid (const std::string &name, std::list< std::pair< double, double > > innerPoints, std::list< std::pair< double, double > > outerPoints, double minPhi, double maxPhi, double &minZ, double &maxZ)
 Create a solid by rotating two polylines around the Z-Axis.
 
G4Colour parseColor (std::string colorString)
 Parse a color string of the form "#rgb", "#rrggbb", "#rgba", "#rrggbbaa" or "rgb(r, g, b)" and return a corresponding G4Colour.
 
 TEST (Materials, Element)
 Check that we can find hydrogen and that the basic Parameters are correct.
 
 TEST (Materials, Material)
 Check if we find the Air Material which is named G4_AIR in Geant4 So check if Air and G4_AIR refer to the same material.
 
 TEST (Materials, Create)
 Check creation of a simple mixture with fractions of other materials The density of the new material should be equal to the weighted sum of the original densities.
 
 TEST (Materials, CreateDensityError)
 When adding elements one has to specify a density since elements do not have a density.
 
 TEST (Materials, CreateDensity)
 Same as above, but with density so it should work.
 
 TEST (Materials, CreateMaterialError)
 When adding unknown materials we should get NULL.
 
 TEST (Materials, CreateElementError)
 When adding unknown elements we should get NULL.
 
 TEST (Materials, OpticalSurface)
 Check the OpticalSurface setting.
 
 TEST (Materials, Properties)
 Check the material properties (need to be checked)
 

Detailed Description

Common code concerning the geometry representation of the detector.

Enumeration Type Documentation

◆ GeometryTypes

Flag indiciating the type of geometry to be used.

Enumerator
FullGeometry 

Full geometry for simulation.

TrackingGeometry 

Simplified geometry for tracking purposes.

DisplayGeometry 

Simplified geometry for display purposes.

Definition at line 36 of file GeometryManager.h.

36 {
40 };
@ TrackingGeometry
Simplified geometry for tracking purposes.
@ FullGeometry
Full geometry for simulation.
@ DisplayGeometry
Simplified geometry for display purposes.

Function Documentation

◆ createPolyCone()

G4Polycone * createPolyCone ( const std::string &  name,
const GearDir params,
double &  minZ,
double &  maxZ 
)

Create Polycone Shape from XML Parameters.

This function will create a polycone shape directly from Gearbox Parameters of the form

<minPhi unit="deg"> 0</minPhi>
<maxPhi unit="deg">360</maxPhi>
<Plane>
<posZ unit="mm">-10.0</posZ>
<innerRadius unit="mm"> 20.000</innerRadius>
<outerRadius unit="mm"> 20.000</outerRadius>
</Plane>
...
<Plane>
<posZ unit="mm">10.0</posZ>
<innerRadius unit="mm"> 15.000</innerRadius>
<outerRadius unit="mm"> 30.000</outerRadius>
</Plane>

There must be at least two Plane definitions, minPhi and maxPhi can be omitted. minZ and maxZ will return the extents of the Polycone along z

Parameters
nameName of the shape to create
paramsGearDir pointing to the parameters
[out]minZwill contain the minimal z coordinate of the polycone
[out]maxZwill contain the maximal z coordinate of the polycone

Definition at line 116 of file utilities.cc.

117 {
118 if (!params) return nullptr;
119
120 double minPhi = params.getAngle("minPhi", 0);
121 double dPhi = params.getAngle("maxPhi", 2 * M_PI) - minPhi;
122 const std::vector<GearDir> planes = params.getNodes("Plane");
123 int nPlanes = planes.size();
124 if (nPlanes < 2) {
125 B2ERROR("Polycone needs at least two planes");
126 return nullptr;
127 }
128 std::vector<double> z(nPlanes, 0);
129 std::vector<double> rMin(nPlanes, 0);
130 std::vector<double> rMax(nPlanes, 0);
131 int index(0);
132 minZ = std::numeric_limits<double>::infinity();
133 maxZ = -std::numeric_limits<double>::infinity();
134 for (const GearDir& plane : planes) {
135 z[index] = plane.getLength("posZ") / Unit::mm;
136 minZ = std::min(minZ, z[index]);
137 maxZ = std::max(maxZ, z[index]);
138 rMin[index] = plane.getLength("innerRadius") / Unit::mm;
139 rMax[index] = plane.getLength("outerRadius") / Unit::mm;
140 ++index;
141 }
142 G4Polycone* polycone = new G4Polycone(name, minPhi, dPhi, nPlanes, z.data(), rMin.data(), rMax.data());
143 return polycone;
144 }
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
double getAngle(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard angle unit.
Definition: Interface.h:299
std::vector< GearDir > getNodes(const std::string &path="") const
Get vector of GearDirs which point to all the nodes the given path evaluates to.
Definition: Interface.cc:21

◆ createRotationSolid() [1/2]

G4Polycone * createRotationSolid ( const std::string &  name,
const GearDir params,
double &  minZ,
double &  maxZ 
)

Create a solid by roating two polylines around the Z-Axis.

This function will create a polycone shape directly from Gearbox Parameters describing the inner and the outer envelope of the polycone. The XML Parameters should be of the form

<minPhi unit="deg"> 0</minPhi>
<maxPhi unit="deg">360</maxPhi>
<OuterPoints>
<point><z unit="mm">-393.000</z><x unit="mm">100.000</x></point>
<point><z unit="mm">-337.000</z><x unit="mm"> 85.500</x></point>
...
<point><z unit="mm">-138.000</z><x unit="mm"> 35.000</x></point>
</OuterPoints>
<InnerPoints>
<point><z unit="mm">-393.000</z><x unit="mm"> 97.934</x></point>
<point><z unit="mm">-339.000</z><x unit="mm"> 83.952</x></point>
...
<point><z unit="mm">-138.000</z><x unit="mm"> 33.000</x></point>
</InnerPoints>

Where OuterPoints and InnerPoints specify a polyline which is the outer respective inner envelope of the Polycone. The number of points doe s not have to be the same for Outer- and InnerPoints. Needed positions will be interpolated when creating the Polycone.

The Positions for Outer- and InnerPoints have to be in ascending Z coordinates. The first and last point of OuterPoints will be connected to the first respective last point of InnerPoints. The resulting shape will be rotated around the z axis to create the polycone.

Parameters
nameName of the Solid
paramsParameters to use for the Solid
[out]minZwill contain the minimal z coordinate of the polycone
[out]maxZwill contain the maximal z coordinate of the polycone

Definition at line 203 of file utilities.cc.

204 {
205
206 //Make a list of all the points (ZX coordinates)
207 PointList innerPoints;
208 PointList outerPoints;
209 for (const GearDir& point : params.getNodes("InnerPoints/point")) {
210 innerPoints.push_back(ZXPoint(point.getLength("z") / Unit::mm, point.getLength("x") / Unit::mm));
211 }
212 for (const GearDir& point : params.getNodes("OuterPoints/point")) {
213 outerPoints.push_back(ZXPoint(point.getLength("z") / Unit::mm, point.getLength("x") / Unit::mm));
214 }
215 //Subdivide the segments to have an x position for each z specified for
216 //either inner or outer boundary
217 subdivideSegments(innerPoints, outerPoints);
218 subdivideSegments(outerPoints, innerPoints);
219 minZ = innerPoints.front().first;
220 maxZ = outerPoints.front().first;
221
222 //Now we create the array of planes needed for the polycone
223 std::vector<double> z;
224 std::vector<double> rMin;
225 std::vector<double> rMax;
226
227 double innerZ{0};
228 double innerX{0};
229 double outerZ{0};
230 double outerX{0};
231 //We go through both lists until both are empty
232 while (!(innerPoints.empty() && outerPoints.empty())) {
233 bool popInner = false;
234 //We could have more than one point at the same z position for segments
235 //going directly along x. because of that we check that the z
236 //coordinates for inner and outer line are always the same, reusing one
237 //point if neccessary
238 if (!innerPoints.empty() && innerPoints.front().first <= outerPoints.front().first) {
239 boost::tie(innerZ, innerX) = innerPoints.front();
240 popInner = true;
241 }
242 if (!outerPoints.empty() && outerPoints.front().first <= innerPoints.front().first) {
243 boost::tie(outerZ, outerX) = outerPoints.front();
244 outerPoints.pop_front();
245 }
246 if (popInner) innerPoints.pop_front();
247 if (innerZ != outerZ) {
248 B2ERROR("createRotationSolid: Something is wrong, z values should be identical");
249 return nullptr;
250 }
251 z.push_back(innerZ);
252 rMin.push_back(innerX);
253 rMax.push_back(outerX);
254 }
255
256 //Finally create the Polycone
257 int nPlanes = z.size();
258 double minPhi = params.getAngle("minPhi", 0);
259 double dPhi = params.getAngle("maxPhi", 2 * M_PI) - minPhi;
260 return new G4Polycone(name, minPhi, dPhi, nPlanes, &z.front(), &rMin.front(), &rMax.front());
261 }

◆ createRotationSolid() [2/2]

G4Polycone * createRotationSolid ( const std::string &  name,
std::list< std::pair< double, double > >  innerPoints,
std::list< std::pair< double, double > >  outerPoints,
double  minPhi,
double  maxPhi,
double &  minZ,
double &  maxZ 
)

Create a solid by rotating two polylines around the Z-Axis.

This function will create a polycone shape. The InnerPoints and OuterPoints are passed directly as stl::lists to avoid dependence on gearbox.

Where OuterPoints and InnerPoints specify a polyline which is the outer respective inner envelope of the Polycone. The number of points does not have to be the same for Outer- and InnerPoints. Needed positions will be interpolated when creating the Polycone.

The Positions for Outer- and InnerPoints have to be in ascending Z coordinates. The first and last point of OuterPoints will be connected to the first respective last point of InnerPoints. The resulting shape will be rotated around the z axis to create the polycone.

Parameters
[in]nameName of the solid.
[in]innerPointsList of inner points.
[in]outerPointsList of outer points.
[in]minPhiMinimum phi angle.
[in]maxPhiMaximum phi angle.
[out]minZMinimum z coordinate.
[out]maxZMaximum z coordinate.

Definition at line 263 of file utilities.cc.

267 {
268 //Subdivide the segments to have an x position for each z specified for
269 //either inner or outer boundary
270 subdivideSegments(innerPoints, outerPoints);
271 subdivideSegments(outerPoints, innerPoints);
272 minZ = innerPoints.front().first;
273 maxZ = outerPoints.front().first;
274
275 //Now we create the array of planes needed for the polycone
276 std::vector<double> z;
277 std::vector<double> rMin;
278 std::vector<double> rMax;
279
280 double innerZ{0};
281 double innerX{0};
282 double outerZ{0};
283 double outerX{0};
284 //We go through both lists until both are empty
285 while (!(innerPoints.empty() && outerPoints.empty())) {
286 bool popInner = false;
287 //We could have more than one point at the same z position for segments
288 //going directly along x. because of that we check that the z
289 //coordinates for inner and outer line are always the same, reusing one
290 //point if necessary
291 // cppcheck-suppress knownConditionTrueFalse
292 if (!innerPoints.empty() && innerPoints.front().first <= outerPoints.front().first) {
293 boost::tie(innerZ, innerX) = innerPoints.front();
294 popInner = true;
295 }
296 if (!outerPoints.empty() && outerPoints.front().first <= innerPoints.front().first) {
297 boost::tie(outerZ, outerX) = outerPoints.front();
298 outerPoints.pop_front();
299 }
300 if (popInner) innerPoints.pop_front();
301 if (innerZ != outerZ) {
302 B2ERROR("createRotationSolid: Something is wrong, z values should be identical");
303 return nullptr;
304 }
305 z.push_back(innerZ / Unit::mm);
306 rMin.push_back(innerX / Unit::mm);
307 rMax.push_back(outerX / Unit::mm);
308 }
309
310 //Finally create the Polycone
311 int nPlanes = z.size();
312 double dPhi = maxPhi - minPhi;
313 return new G4Polycone(name, minPhi, dPhi, nPlanes, &z.front(), &rMin.front(), &rMax.front());
314
315 }

◆ parseColor()

G4Colour parseColor ( std::string  colorString)

Parse a color string of the form "#rgb", "#rrggbb", "#rgba", "#rrggbbaa" or "rgb(r, g, b)" and return a corresponding G4Colour.

For "#rgb" and "#rgba" the color for red, green, blue (and optionally alpha) is each represented by one hexadecimal digit, "#rrggbb" and "#rrggbbaa" is the same with two digits per colour.

"rgb(r, g, b)" expects the fraction of red, green and blue as float between 0 and 1.

Definition at line 44 of file utilities.cc.

45 {
46 boost::to_lower(colorString);
47 double red(0), green(0), blue(0), alpha(0);
48 if (colorString[0] == '#') {
49 size_t size = colorString.size();
50 unsigned int colorValue;
51 std::stringstream in(colorString);
52 in.get();
53 in >> std::hex >> colorValue;
54 if (in.fail()) size = 0;
55 switch (size) {
56 case 4: //#rgb, add alpha since none was specified
57 colorValue = (colorValue << 4) + 15;
58 // and then continue with rgba case
59 [[fallthrough]];
60 case 5: //#rgba
61 red = ((colorValue & 0xf000) >> 12) / 15.;
62 green = ((colorValue & 0x0f00) >> 8) / 15.;
63 blue = ((colorValue & 0x00f0) >> 4) / 15.;
64 alpha = ((colorValue & 0x000f) >> 0) / 15.;
65 break;
66 case 7: //#rrggbb, add alpha since none was specified
67 colorValue = (colorValue << 8) + 255;
68 // and then continue with #rrggbbaa case
69 [[fallthrough]];
70 case 9: //#rrggbbaa
71 red = ((colorValue & 0xff000000) >> 24) / 255.;
72 green = ((colorValue & 0x00ff0000) >> 16) / 255.;
73 blue = ((colorValue & 0x0000ff00) >> 8) / 255.;
74 alpha = ((colorValue & 0x000000ff) >> 0) / 255.;
75 break;
76 default:
77 B2WARNING("Could not parse color string '" + colorString + "'");
78 }
79 } else if (colorString.substr(0, 3) == "rgb") {
80 //Parse value of the type rgb(1.0,1.0,1.0)
81 size_t startPos = colorString.find('(');
82 size_t stopPos = colorString.find(')');
83 std::string ws(" \t\r\n,");
84 std::stringstream in(colorString.substr(startPos + 1, stopPos - startPos - 1));
85 in >> red;
86 while (ws.find(in.peek()) != std::string::npos) in.get();
87 in >> green;
88 while (ws.find(in.peek()) != std::string::npos) in.get();
89 in >> blue;
90 while (ws.find(in.peek()) != std::string::npos) in.get();
91 in >> alpha;
92 red = std::min(1.0, std::max(0.0, red));
93 green = std::min(1.0, std::max(0.0, green));
94 blue = std::min(1.0, std::max(0.0, blue));
95 alpha = std::min(1.0, std::max(0.0, alpha));
96 }
97 return G4Colour(red, green, blue, alpha);
98 }

◆ setColor()

void setColor ( G4LogicalVolume &  volume,
const std::string &  color 
)

Set the color of a logical volume.

This function will set the visualization color of a logical volume from a string representation of the color. Recognized formats for the color are:

  • "#rgb" where r,g,b are hexadecimal values from 0 to f representing the color values for red, green and blue respectively
  • "#rgba" where r,g,b,a are hexadecimal values from 0 to f and a represents the alpha value
  • "#rrggbb" where rr,gg,bb are hexadecimal values from 00 to ff representing the color values for red, green and blue respectively
  • "#rrggbbaa" where rr,gg,bb,aa are hexadecimal values from 00 to ff and aa represents the alpha value
  • "rgb(r,g,b)" where r,g,b are float values between 0.0 and 1.0 representing the color values for red, green and blue respectively
  • "rgb(r,g,b,a)" where r,g,b,a are float values between 0.0 and 1.0 representing the color values for red, green, blue and alpha respectively
Parameters
volumeVolume for which to set the color
colorString representation of the color

Definition at line 100 of file utilities.cc.

101 {
102 auto* attr = const_cast<G4VisAttributes*>(volume.GetVisAttributes());
103 if (!attr) attr = GeometryManager::getInstance().newVisAttributes();
104 attr->SetColor(parseColor(color));
105 volume.SetVisAttributes(attr);
106 }
G4Colour parseColor(std::string colorString)
Parse a color string of the form "#rgb", "#rrggbb", "#rgba", "#rrggbbaa" or "rgb(r,...
Definition: utilities.cc:44

◆ setVisibility()

void setVisibility ( G4LogicalVolume &  volume,
bool  visible 
)

Helper function to quickly set the visibility of a given volume.

Parameters
volumeVolume for which to set the visibility
visibletrue if the volume should be visible, false otherwise

Definition at line 108 of file utilities.cc.

109 {
110 auto* attr = const_cast<G4VisAttributes*>(volume.GetVisAttributes());
111 if (!attr) attr = GeometryManager::getInstance().newVisAttributes();
112 attr->SetVisibility(visible);
113 volume.SetVisAttributes(attr);
114 }

◆ TEST() [1/9]

TEST ( Materials  ,
Create   
)

Check creation of a simple mixture with fractions of other materials The density of the new material should be equal to the weighted sum of the original densities.

Definition at line 59 of file Materials.cc.

60 {
61 Gearbox& gb = Gearbox::getInstance();
62 vector<string> backends;
63 backends.emplace_back("string:<Material name='Test'><state>Gas</state><Components>"
64 "<Material fraction='1.5'>Si</Material>"
65 "<Material fraction='2.5612'>Au</Material>"
66 "</Components></Material>");
67 gb.setBackends(backends);
68 gb.open();
69 Materials& m = Materials::getInstance();
70 ASSERT_EQ(0, gb.getNumberNodes("/Material/density"));
71 ASSERT_EQ(1, gb.getNumberNodes("/Material/@name"));
72
73 G4Material* au = Materials::get("Au");
74 G4Material* si = Materials::get("Si");
75 G4Material* mat = m.createMaterial(GearDir("/Material"));
76 ASSERT_TRUE(mat);
77 EXPECT_EQ("Test", mat->GetName());
78 EXPECT_DOUBLE_EQ((2.5612 * au->GetDensity() + 1.5 * si->GetDensity()) / 4.0612, mat->GetDensity());
79 gb.close();
80 }
Singleton class responsible for loading detector parameters from an XML file.
Definition: Gearbox.h:34
virtual int getNumberNodes(const std::string &path="") const override
Return the number of nodes a given path will expand to.
Definition: Gearbox.h:112
Thin wrapper around the Geant4 Material system.
Definition: Materials.h:48
void close()
Free internal structures of previously parsed tree and clear cache.
Definition: Gearbox.cc:169
void setBackends(const std::vector< std::string > &backends)
Select the backends to use to find resources.
Definition: Gearbox.cc:99
void open(const std::string &name="Belle2.xml", size_t cacheSize=c_DefaultCacheSize)
Open connection to backend and parse tree.
Definition: Gearbox.cc:133

◆ TEST() [2/9]

TEST ( Materials  ,
CreateDensity   
)

Same as above, but with density so it should work.

Definition at line 103 of file Materials.cc.

104 {
105 Gearbox& gb = Gearbox::getInstance();
106 vector<string> backends;
107 backends.emplace_back("string:<Material name='Test2'><state>Liquid</state><density>1</density><Components>"
108 "<Material>Si</Material>"
109 "<Element>Au</Element>"
110 "</Components></Material>");
111 gb.setBackends(backends);
112 gb.open();
113
114 Materials& m = Materials::getInstance();
115 G4Material* mat = m.createMaterial(GearDir("/Material"));
116 ASSERT_TRUE(mat);
117 gb.close();
118 }

◆ TEST() [3/9]

TEST ( Materials  ,
CreateDensityError   
)

When adding elements one has to specify a density since elements do not have a density.

Definition at line 84 of file Materials.cc.

85 {
86 Gearbox& gb = Gearbox::getInstance();
87 vector<string> backends;
88 backends.emplace_back("string:<Material name='Test1'><state>Solid</state><Components>"
89 "<Material fraction='0.5'>Si</Material>"
90 "<Element fraction='0.5'>Au</Element>"
91 "</Components></Material>");
92 gb.setBackends(backends);
93 gb.open();
94
95 Materials& m = Materials::getInstance();
96 G4Material* mat = m.createMaterial(GearDir("/Material"));
97 ASSERT_FALSE(mat);
98 gb.close();
99 }

◆ TEST() [4/9]

TEST ( Materials  ,
CreateElementError   
)

When adding unknown elements we should get NULL.

Definition at line 140 of file Materials.cc.

141 {
142 Gearbox& gb = Gearbox::getInstance();
143 vector<string> backends;
144 backends.emplace_back("string:<Material name='Test4'><density>1</density><Components>"
145 "<Element>Foo</Element>"
146 "</Components></Material>");
147 gb.setBackends(backends);
148 gb.open();
149
150 Materials& m = Materials::getInstance();
151 G4Material* mat = m.createMaterial(GearDir("/Material"));
152 ASSERT_FALSE(mat);
153 gb.close();
154 }

◆ TEST() [5/9]

TEST ( Materials  ,
CreateMaterialError   
)

When adding unknown materials we should get NULL.

Definition at line 122 of file Materials.cc.

123 {
124 Gearbox& gb = Gearbox::getInstance();
125 vector<string> backends;
126 backends.emplace_back("string:<Material name='Test3'><Components>"
127 "<Material>Foo</Material>"
128 "</Components></Material>");
129 gb.setBackends(backends);
130 gb.open();
131
132 Materials& m = Materials::getInstance();
133 G4Material* mat = m.createMaterial(GearDir("/Material"));
134 ASSERT_FALSE(mat);
135 gb.close();
136 }

◆ TEST() [6/9]

TEST ( Materials  ,
Element   
)

Check that we can find hydrogen and that the basic Parameters are correct.

Definition at line 33 of file Materials.cc.

34 {
35 Materials& m = Materials::getInstance();
36 G4Element* e1 = m.getElement("H");
37 ASSERT_TRUE(e1);
38 EXPECT_EQ("H", e1->GetName());
39 EXPECT_EQ("H", e1->GetSymbol());
40 EXPECT_EQ(1., e1->GetZ());
41 }

◆ TEST() [7/9]

TEST ( Materials  ,
Material   
)

Check if we find the Air Material which is named G4_AIR in Geant4 So check if Air and G4_AIR refer to the same material.

Definition at line 46 of file Materials.cc.

47 {
48 G4Material* m1 = Materials::get("Air");
49 G4Material* m2 = Materials::get("G4_AIR");
50 EXPECT_EQ(m1, m2);
51 ASSERT_TRUE(m1);
52 EXPECT_EQ("G4_AIR", m1->GetName());
53 EXPECT_TRUE(Materials::get("Si"));
54 }

◆ TEST() [8/9]

TEST ( Materials  ,
OpticalSurface   
)

Check the OpticalSurface setting.

Definition at line 158 of file Materials.cc.

159 {
160 Gearbox& gb = Gearbox::getInstance();
161 vector<string> backends;
162 backends.emplace_back("string:<test><Surface/>"
163 "<Surface name='test'><Model>unified</Model><Finish>Ground</Finish>"
164 "<Type>x_ray</Type><Value>2.0</Value></Surface>"
165 "<Surface><Model>not existing</Model></Surface>"
166 "<Surface><Finish>not existing</Finish></Surface>"
167 "<Surface><Type>not existing</Type></Surface></test>"
168 );
169 gb.setBackends(backends);
170 gb.open();
171
172 Materials& m = Materials::getInstance();
173
174 G4OpticalSurface* surf1 = m.createOpticalSurface(GearDir("/test/Surface[1]"));
175 ASSERT_TRUE(surf1);
176 EXPECT_EQ("OpticalSurface", surf1->GetName());
177 EXPECT_EQ(glisur, surf1->GetModel());
178 EXPECT_EQ(polished, surf1->GetFinish());
179 EXPECT_EQ(dielectric_dielectric, surf1->GetType());
180 EXPECT_EQ(1.0, surf1->GetPolish());
181
182 G4OpticalSurface* surf2 = m.createOpticalSurface(GearDir("/test/Surface[2]"));
183 ASSERT_TRUE(surf2);
184 EXPECT_EQ("test", surf2->GetName());
185 EXPECT_EQ(unified, surf2->GetModel());
186 EXPECT_EQ(ground, surf2->GetFinish());
187 EXPECT_EQ(x_ray, surf2->GetType());
188 EXPECT_EQ(2.0, surf2->GetSigmaAlpha());
189
190 EXPECT_B2FATAL(m.createOpticalSurface(GearDir("/test/Surface[3]")));
191 EXPECT_B2FATAL(m.createOpticalSurface(GearDir("/test/Surface[4]")));
192 EXPECT_B2FATAL(m.createOpticalSurface(GearDir("/test/Surface[5]")));
193 }

◆ TEST() [9/9]

TEST ( Materials  ,
Properties   
)

Check the material properties (need to be checked)

Definition at line 197 of file Materials.cc.

198 {
199 Gearbox& gb = Gearbox::getInstance();
200 vector<string> backends;
201 backends.emplace_back("string:<Material name='TestProperties'>"
202 "<Components><Material>Si</Material></Components>"
203 "<Property name='RINDEX' unit='eV'>"
204 "<value energy='1.0'>1.40</value>"
205 "<value energy='1.5'>1.41</value>"
206 "<value energy='2.0'>1.42</value>"
207 "<value energy='3.5'>1.43</value>"
208 "</Property>"
209 "</Material>");
210 gb.setBackends(backends);
211 gb.open();
212 Materials& m = Materials::getInstance();
213
214 G4Material* mat = m.createMaterial(GearDir("/Material"));
215 ASSERT_TRUE(mat);
216 G4MaterialPropertiesTable* properties = mat->GetMaterialPropertiesTable();
217 ASSERT_TRUE(properties);
218 G4MaterialPropertyVector* property = properties->GetProperty("RINDEX");
219 ASSERT_TRUE(property);
220 EXPECT_EQ(4u, property->GetVectorLength());
221 EXPECT_DOUBLE_EQ(1.40, property->GetMinValue());
222 EXPECT_DOUBLE_EQ(1.43, property->GetMaxValue());
223 EXPECT_DOUBLE_EQ(1 * CLHEP::eV, property->GetMinEnergy());
224 EXPECT_DOUBLE_EQ(3.5 * CLHEP::eV, property->GetMaxEnergy());
225 EXPECT_DOUBLE_EQ(1.0 * CLHEP::eV, property->Energy(0));
226 EXPECT_DOUBLE_EQ(1.5 * CLHEP::eV, property->Energy(1));
227 EXPECT_DOUBLE_EQ(2.0 * CLHEP::eV, property->Energy(2));
228 EXPECT_DOUBLE_EQ(3.5 * CLHEP::eV, property->Energy(3));
229 EXPECT_DOUBLE_EQ(1.40, (*property)[0]);
230 EXPECT_DOUBLE_EQ(1.41, (*property)[1]);
231 EXPECT_DOUBLE_EQ(1.42, (*property)[2]);
232 EXPECT_DOUBLE_EQ(1.43, (*property)[3]);
233 gb.close();
234 }