15 #include "GeoModelKernel/GeoBox.h"
16 #include "GeoModelKernel/GeoCons.h"
17 #include "GeoModelKernel/GeoPara.h"
18 #include "GeoModelKernel/GeoPcon.h"
19 #include "GeoModelKernel/GeoPgon.h"
20 #include "GeoModelKernel/GeoShape.h"
21 #include "GeoModelKernel/GeoShapeIntersection.h"
22 #include "GeoModelKernel/GeoShapeShift.h"
23 #include "GeoModelKernel/GeoShapeSubtraction.h"
24 #include "GeoModelKernel/GeoShapeUnion.h"
25 #include "GeoModelKernel/GeoSimplePolygonBrep.h"
26 #include "GeoModelKernel/GeoTrap.h"
27 #include "GeoModelKernel/GeoTrd.h"
28 #include "GeoModelKernel/GeoTube.h"
29 #include "GeoModelKernel/GeoTubs.h"
30 #include "GeoModelKernel/GeoVPhysVol.h"
43 const GeoVPhysVol* gv2,
50 if (gv1->getLogVol()->getName() != gv2->getLogVol()->getName()) {
53 std::cout <<
"CASE 1: names differ at level:" <<
level <<
":"
54 << gv1->getLogVol()->getName() <<
":"
55 << gv2->getLogVol()->getName() << std::endl;
61 if (gv1->getLogVol()->getMaterial()->getName() !=
62 gv2->getLogVol()->getMaterial()->getName()) {
65 std::cout <<
"CASE 2: material types differ for volume:"
66 << gv1->getLogVol()->getName() <<
":at level:" <<
level
67 <<
":" << gv1->getLogVol()->getMaterial()->getName()
69 << gv2->getLogVol()->getMaterial()->getName()
75 if (gv1->getLogVol()->getShape()->typeID() !=
76 gv2->getLogVol()->getShape()->typeID()) {
79 std::cout <<
"CASE 3: shape types differ at level:" <<
level
80 <<
":volume name:" << gv1->getLogVol()->getName()
81 <<
":shape:" << gv1->getLogVol()->getShape()->type()
82 <<
":shape ref:" << gv2->getLogVol()->getShape()->type()
89 gv2->getLogVol()->getShape(),
tolerance)) {
92 std::cout <<
"CASE 4: shape definition differ at level:" <<
level
97 unsigned int nChild1 = gv1->getNChildVols();
99 if (nChild1 != gv2->getNChildVols()) {
102 std::cout <<
"CASE 5: number of child vols differ at level:"
103 <<
level <<
":volume name:" << gv1->getLogVol()->getName()
104 <<
":nChildVols:" << gv1->getNChildVols()
105 <<
":nChildVols ref:" << gv2->getNChildVols()
128 assert (children1.size() == nChild1 && children2.size() == nChild1);
129 for (
unsigned int ic = 0;
ic < nChild1;
ic++) {
133 const GeoVPhysVol* cv1 = children1.at(
ic).first;
134 const GeoVPhysVol* cv2 = children2.at(
ic).first;
136 if ((transf1.translation() - transf2.translation()).norm() >
140 std::cout <<
"CASE 6: translation differs at level:" <<
level
141 <<
": between mother and child:"
142 << gv1->getLogVol()->getName() <<
":"
143 << cv1->getLogVol()->getName() << std::endl;
150 transf1.rotation() * transf2.rotation().transpose();
156 std::cout <<
"CASE 7: rotation differs at level:" <<
level
157 <<
":between mother and child:"
158 << gv1->getLogVol()->getName() <<
":"
159 << cv1->getLogVol()->getName() << std::endl;
185 if (sh1->typeID() != sh2->typeID())
188 if (sh1->type() ==
"Pgon") {
189 const GeoPgon* pgon1 =
static_cast<const GeoPgon*
>(sh1);
190 const GeoPgon* pgon2 =
static_cast<const GeoPgon*
>(sh2);
191 if (!pgon1 || !pgon2)
194 if (pgon1->getNPlanes() != pgon2->getNPlanes())
196 if (pgon1->getNSides() != pgon2->getNSides())
198 if (std::abs(pgon1->getSPhi() - pgon2->getSPhi()) > tol)
200 if (std::abs(pgon1->getDPhi() - pgon2->getDPhi()) > tol)
205 }
else if (sh1->type() ==
"Trd") {
206 const GeoTrd* trd1 =
static_cast<const GeoTrd*
>(sh1);
207 const GeoTrd* trd2 =
static_cast<const GeoTrd*
>(sh2);
209 if (std::abs(trd1->getXHalfLength1() - trd2->getXHalfLength1()) > tol)
211 if (std::abs(trd1->getXHalfLength2() - trd2->getXHalfLength2()) > tol)
213 if (std::abs(trd1->getYHalfLength1() - trd2->getYHalfLength1()) > tol)
215 if (std::abs(trd1->getYHalfLength2() - trd2->getYHalfLength2()) > tol)
217 if (std::abs(trd1->getZHalfLength() - trd2->getZHalfLength()) > tol)
222 }
else if (sh1->type() ==
"Box") {
223 const GeoBox* box1 =
static_cast<const GeoBox*
>(sh1);
224 const GeoBox* box2 =
static_cast<const GeoBox*
>(sh2);
226 if (std::abs(box1->getXHalfLength() - box2->getXHalfLength()) > tol)
228 if (std::abs(box1->getYHalfLength() - box2->getYHalfLength()) > tol)
230 if (std::abs(box1->getZHalfLength() - box2->getZHalfLength()) > tol)
235 }
else if (sh1->type() ==
"Tube") {
236 const GeoTube* tube1 =
static_cast<const GeoTube*
>(sh1);
237 const GeoTube* tube2 =
static_cast<const GeoTube*
>(sh2);
239 if (std::abs(tube1->getRMin() - tube2->getRMin()) > tol)
241 if (std::abs(tube1->getRMax() - tube2->getRMax()) > tol)
243 if (std::abs(tube1->getZHalfLength() - tube2->getZHalfLength()) > tol)
248 }
else if (sh1->type() ==
"Tubs") {
249 const GeoTubs* tubs1 =
static_cast<const GeoTubs*
>(sh1);
250 const GeoTubs* tubs2 =
static_cast<const GeoTubs*
>(sh2);
252 if (std::abs(tubs1->getRMin() - tubs2->getRMin()) > tol)
254 if (std::abs(tubs1->getRMax() - tubs2->getRMax()) > tol)
256 if (std::abs(tubs1->getZHalfLength() - tubs2->getZHalfLength()) > tol)
258 if (std::abs(tubs1->getSPhi() - tubs2->getSPhi()) > tol)
260 if (std::abs(tubs1->getDPhi() - tubs2->getDPhi()) > tol)
265 }
else if (sh1->type() ==
"Cons") {
266 const GeoCons* cons1 =
static_cast<const GeoCons*
>(sh1);
267 const GeoCons* cons2 =
static_cast<const GeoCons*
>(sh2);
269 if (std::abs(cons1->getRMin1() - cons2->getRMin1()) > tol)
271 if (std::abs(cons1->getRMin2() - cons2->getRMin2()) > tol)
273 if (std::abs(cons1->getRMax1() - cons2->getRMax1()) > tol)
275 if (std::abs(cons1->getRMax2() - cons2->getRMax2()) > tol)
277 if (std::abs(cons1->getDZ() - cons2->getDZ()) > tol)
279 if (std::abs(cons1->getSPhi() - cons2->getSPhi()) > tol)
281 if (std::abs(cons1->getDPhi() - cons2->getDPhi()) > tol)
286 }
else if (sh1->type() ==
"SimplePolygonBrep") {
287 const GeoSimplePolygonBrep* spb1 =
288 static_cast<const GeoSimplePolygonBrep*
>(sh1);
289 const GeoSimplePolygonBrep* spb2 =
290 static_cast<const GeoSimplePolygonBrep*
>(sh2);
294 unsigned int nv1 = spb1->getNVertices();
295 unsigned int nv2 = spb2->getNVertices();
298 if (std::abs(spb1->getDZ() - spb2->getDZ()) > tol)
301 for (
unsigned int iv = 0; iv < nv1; iv++) {
303 if (std::abs(spb1->getXVertex(iv) - spb2->getXVertex(iv)) > tol)
305 if (std::abs(spb1->getYVertex(iv) - spb2->getYVertex(iv)) > tol)
311 }
else if (sh1->type() ==
"Pcon") {
312 const GeoPcon* pc1 =
static_cast<const GeoPcon*
>(sh1);
313 const GeoPcon* pc2 =
static_cast<const GeoPcon*
>(sh2);
317 if (std::abs(pc1->getSPhi() - pc2->getSPhi()) > tol)
319 if (std::abs(pc1->getDPhi() - pc2->getDPhi()) > tol)
322 unsigned int nv1 = pc1->getNPlanes();
323 unsigned int nv2 = pc2->getNPlanes();
327 for (
unsigned int iv = 0; iv < nv1; iv++) {
329 if (std::abs(pc1->getZPlane(iv) - pc2->getZPlane(iv)) > tol)
331 if (std::abs(pc1->getRMinPlane(iv) - pc2->getRMinPlane(iv)) > tol)
333 if (std::abs(pc1->getRMaxPlane(iv) - pc2->getRMaxPlane(iv)) > tol)
339 }
else if (sh1->type() ==
"Subtraction") {
340 const GeoShapeSubtraction* sub1 =
341 static_cast<const GeoShapeSubtraction*
>(sh1);
342 const GeoShapeSubtraction* sub2 =
343 static_cast<const GeoShapeSubtraction*
>(sh2);
348 if (!compareShapes(sub1->getOpA(), sub2->getOpA(), tol))
350 if (!compareShapes(sub1->getOpB(), sub2->getOpB(), tol))
355 }
else if (sh1->type() ==
"Union") {
356 const GeoShapeUnion* sub1 =
static_cast<const GeoShapeUnion*
>(sh1);
357 const GeoShapeUnion* sub2 =
static_cast<const GeoShapeUnion*
>(sh2);
362 if (!compareShapes(sub1->getOpA(), sub2->getOpA(), tol))
364 if (!compareShapes(sub1->getOpB(), sub2->getOpB(), tol))
369 }
else if (sh1->type() ==
"Shift") {
370 const GeoShapeShift* shift1 =
static_cast<const GeoShapeShift*
>(sh1);
371 const GeoShapeShift* shift2 =
static_cast<const GeoShapeShift*
>(sh2);
373 if (!shift1 || !shift2)
376 if (!compareShapes(shift1->getOp(), shift2->getOp(), tol))
382 if ((transf1.translation() - transf2.translation()).
norm() > tol)
386 if (!identity_check(transf1.rotation() * transf2.rotation().transpose(),
393 std::cout <<
"unknown shape to compare:" << sh1->type() << std::endl;
399 std::string_view
name)
const {
401 if (gv->getLogVol()->getName().find(
name) != std::string::npos)
404 for (
unsigned int ic = 0;
ic < gv->getNChildVols();
ic++) {
406 const GeoVPhysVol* cv = &(*(gv->getChildVol(
ic)));
407 if (this->findNamePattern(cv,
name))
416 class GeoFindTopName :
public GeoNodeAction
419 explicit GeoFindTopName (
const std::string_view
name) : m_name (
name)
422 virtual void handlePhysVol (
const GeoPhysVol*
v)
override
424 virtual void handleFullPhysVol (
const GeoFullPhysVol*
v)
override
426 const GeoVPhysVol* topName()
const {
return m_topName; }
428 void handleVol (
const GeoVPhysVol*
v)
430 const GeoLogVol* clv =
v->getLogVol();
431 if (clv && clv->getName().find(m_name) != std::string::npos) {
432 m_topName =
v->getParent();
436 const std::string_view m_name;
437 const GeoVPhysVol* m_topName =
nullptr;
443 const GeoVPhysVol* gv, std::string_view
name) {
445 GeoFindTopName topName (
name);
447 return topName.topName();
466 std::ios oldState(
nullptr);
467 oldState.copyfmt(std::cout);
469 std::cout << std::fixed << std::setprecision(4);
470 std::cout <<
"test translation:x:y:z:" << tr_test.translation().x() <<
":"
471 << tr_test.translation().y() <<
":" << tr_test.translation().z()
473 std::cout <<
" ref translation:x:y:z:" << tr_ref.translation().x() <<
":"
474 << tr_ref.translation().y() <<
":" << tr_ref.translation().z()
476 std::cout <<
" absolute shift :"
477 << (tr_test.translation() - tr_ref.translation()).
norm()
478 <<
": to be compared with the tolerance limit:" <<
tolerance
480 std::cout.copyfmt(oldState);
490 std::ios oldState(
nullptr);
491 oldState.copyfmt(std::cout);
493 std::cout << std::fixed << std::setprecision(4);
494 std::cout <<
"test rotation:" << rotest(0, 0) <<
":" << rotest(0, 1) <<
":"
495 << rotest(0, 2) << std::endl;
496 std::cout <<
" " << rotest(1, 0) <<
":" << rotest(1, 1)
497 <<
":" << rotest(1, 2) << std::endl;
498 std::cout <<
" " << rotest(2, 0) <<
":" << rotest(2, 1)
499 <<
":" << rotest(2, 2) << std::endl;
500 std::cout <<
" ref rotation:" << rotref(0, 0) <<
":" << rotref(0, 1) <<
":"
501 << rotref(0, 2) << std::endl;
502 std::cout <<
" " << rotref(1, 0) <<
":" << rotref(1, 1)
503 <<
":" << rotref(1, 2) << std::endl;
504 std::cout <<
" " << rotref(2, 0) <<
":" << rotref(2, 1)
505 <<
":" << rotref(2, 2) << std::endl;
506 std::cout <<
"test*inv(ref):" << rotid(0, 0) <<
":" << rotid(0, 1) <<
":"
507 << rotid(0, 2) << std::endl;
508 std::cout <<
" " << rotid(1, 0) <<
":" << rotid(1, 1)
509 <<
":" << rotid(1, 2) << std::endl;
510 std::cout <<
" " << rotid(2, 0) <<
":" << rotid(2, 1)
511 <<
":" << rotid(2, 2) << std::endl;
512 std::cout <<
" identity check fails within the tolerance limit:"
514 std::cout.copyfmt(oldState);