1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
//
//
// TestTorus
//.. ensure asserts are compiled in
#undef NDEBUG
#include "VecGeom/base/FpeEnable.h"
#include "VecGeom/base/Global.h"
#include "VecGeom/base/Vector3D.h"
#include "ApproxEqual.h"
#include "VecGeom/volumes/Torus2.h"
#include <cmath>
using vecgeom::kPi;
template <class Torus_t, class Vec_t = vecgeom::Vector3D<vecgeom::Precision>>
bool testTorus()
{
int i;
Precision Rtor = 100;
Precision Rmax = Rtor * 0.9;
Precision Rmin = Rtor * 0.1;
Precision x;
Precision z;
Precision Dist, dist, vol, volCheck;
Vec_t normal;
bool valid;
Precision tolerance = 1e-9;
Vec_t pzero(0, 0, 0);
Vec_t pbigx(240, 0, 0), pbigy(0, 240, 0), pbigz(0, 0, 240);
Vec_t pbigmx(-240, 0, 0), pbigmy(0, -240, 0), pbigmz(0, 0, -240);
Vec_t ponrmax(190, 0, 0);
Vec_t ponrmin(0, 110, 0);
Vec_t ponrtor(0, 100, 0);
Vec_t ponphi1(100 / std::sqrt(2.), 100 / std::sqrt(2.), 0);
Vec_t ponphi2(-100 / std::sqrt(2.), 100 / std::sqrt(2.), 0);
Vec_t ponphi12(190 / std::sqrt(2.), 190 / std::sqrt(2.), 0);
Vec_t ponphi22(-120 / std::sqrt(2.), 120 / std::sqrt(2.), 0);
Vec_t ponphi23(-120 / std::sqrt(2.) + 0.5, 120 / std::sqrt(2.), 0);
Vec_t vx(1, 0, 0), vy(0, 1, 0), vz(0, 0, 1);
Vec_t vmx(-1, 0, 0), vmy(0, -1, 0), vmz(0, 0, -1);
Vec_t vxy(1 / std::sqrt(2.0), 1 / std::sqrt(2.0), 0);
Vec_t vmxy(-1 / std::sqrt(2.0), 1 / std::sqrt(2.0), 0);
Vec_t vmxmy(-1 / std::sqrt(2.0), -1 / std::sqrt(2.0), 0);
Vec_t vxmy(1 / std::sqrt(2.0), -1 / std::sqrt(2.0), 0);
Vec_t pstart((Rtor + Rmax) / std::sqrt(2.0), (Rtor + Rmax) / std::sqrt(2.0), 0);
Vec_t vdirect(1 / std::sqrt(2.0), -1 / std::sqrt(2.0), 0);
Vec_t pother(90, 0, 0);
vdirect = vdirect.Unit();
Vec_t p1;
Vec_t v1(1, 0, 0);
v1 = v1.Unit();
std::cout << "Starting Torus unit test..." << std::endl;
// Check torus roots
Torus_t t1("Solid Torus #1", 0, Rmax, Rtor, 0, vecgeom::kTwoPi);
Torus_t t2("Hole cutted Torus #2", Rmin, Rmax, Rtor, 0, kPi / 2.); // kPi/4., kPi/2.);
Torus_t tn2("tn2", Rmin, Rmax, Rtor, vecgeom::kPi / 2., vecgeom::kPi / 2.);
Torus_t tn3("tn3", Rmin, Rmax, Rtor, vecgeom::kPi / 2., 3 * vecgeom::kPi / 2.);
Torus_t t3("Hole cutted Torus #3", 4 * Rmin, Rmax, Rtor, vecgeom::kPi / 2. - vecgeom::kPi / 24, vecgeom::kPi / 12);
Torus_t t4("Solid Torus #4", 0, Rtor - 2.e3 * tolerance, Rtor, 0, vecgeom::kTwoPi);
Torus_t t5("Solid cutted Torus #5", 0, Rtor - 2.e3 * tolerance, Rtor, vecgeom::kPi / 4, vecgeom::kPi / 2);
Torus_t *aTub = new Torus_t("Ring1", 0, 100, 1000, 0, vecgeom::kTwoPi);
Torus_t t6("t6", 100, 150, 200, 0, vecgeom::kPi / 3);
Torus_t *clad = new Torus_t("clad", 0., 10., 100., 0., vecgeom::kPi); // external
Torus_t *core = new Torus_t("core", 0., 5, 100, 0., vecgeom::kPi); // internal
Torus_t *cmsEECool3 = new Torus_t("cmsEECool3", 0, 6, 1640, 0.09599, 1.4312);
Vec_t temp1 = Vec_t(-0.646752, -0.762700, -0.000012);
temp1 = temp1 / (temp1.Mag());
// std::cout << "Dout=" << cmsEECool3->DistanceToOut(Vec_t(1230.993171, 1078.075896, -2.947036), temp1)
// << std::endl; //: inf / inf / inf / 1.57856
// std::cout<<"In="<<cmsEECool3->Inside(Vec_t(1230.993171, 1078.075896, -2.947036))<<"
// Rtor="<<std::sqrt(1230.99*1230.99+1078.07*1078.07)<<std::endl;
assert(cmsEECool3->Inside(Vec_t(1230.993171, 1078.075896, -2.947036)) == vecgeom::EInside::kInside);
Vec_t p1t6(60.73813233071262, -27.28494547459707, 37.47827539879173);
Vec_t vt6(0.3059312222729116, 0.8329513862588347, -0.461083588265824);
Vec_t p2t6(70.75950555416668, -3.552713678800501e-15, 22.37458414788935);
// Check cubic volume
vol = t1.Capacity();
volCheck = vecgeom::kTwoPi * vecgeom::kPi * Rtor * (Rmax * Rmax);
assert(ApproxEqual<Precision>(vol, volCheck));
vol = t2.Capacity();
volCheck = vecgeom::kPi / 2. * vecgeom::kPi * Rtor * (Rmax * Rmax - Rmin * Rmin);
assert(ApproxEqual<Precision>(vol, volCheck));
// Check Inside
// std::cout<<t1.Inside(pzero)<<std::endl;
assert(t1.Inside(pzero) == vecgeom::EInside::kOutside);
assert(t1.Inside(pbigx) == vecgeom::EInside::kOutside);
assert(t1.Inside(ponrmax) == vecgeom::EInside::kSurface);
assert(t2.Inside(ponrmin) == vecgeom::EInside::kSurface);
assert(t2.Inside(pbigx) == vecgeom::EInside::kOutside);
assert(t2.Inside(pbigy) == vecgeom::EInside::kOutside);
assert(t2.Inside(ponphi1) == vecgeom::EInside::kOutside);
assert(t2.Inside(ponphi2) == vecgeom::EInside::kOutside);
assert(t2.Inside(Vec_t(20, 0, 0)) == vecgeom::EInside::kSurface);
assert(t2.Inside(Vec_t(0, 20, 0)) == vecgeom::EInside::kSurface);
vecgeom::EnumInside side;
side = t6.Inside(p1t6);
// std::cout << "t6.Inside(p1t6) = " << side << std::endl;
side = t6.Inside(p2t6);
// std::cout << "t6.Inside(p2t6) = " << side << std::endl;
assert(t6.Inside(p2t6) == vecgeom::EInside::kSurface);
assert(side == vecgeom::EInside::kSurface);
// Check Surface Normal
Precision p2 = 1. / std::sqrt(2.); // ,p3=1./std::sqrt(3.);
valid = t1.Normal(ponrmax, normal);
assert(ApproxEqual(normal, vx) && valid);
valid = t1.Normal(Vec_t(0., 190., 0.), normal);
assert(ApproxEqual(normal, vy));
valid = tn2.Normal(Vec_t(0., Rtor + Rmax, 0.), normal);
assert(ApproxEqual(normal, Vec_t(p2, p2, 0.)));
valid = tn2.Normal(Vec_t(0., Rtor + Rmin, 0.), normal);
assert(ApproxEqual(normal, Vec_t(p2, -p2, 0.)));
valid = tn2.Normal(Vec_t(0., Rtor - Rmin, 0.), normal);
assert(ApproxEqual(normal, Vec_t(p2, p2, 0.)));
valid = tn2.Normal(Vec_t(0., Rtor - Rmax, 0.), normal);
assert(ApproxEqual(normal, Vec_t(p2, -p2, 0.)));
valid = tn3.Normal(Vec_t(Rtor, 0., Rmax), normal);
assert(ApproxEqual(normal, Vec_t(0., p2, p2)));
valid = tn3.Normal(Vec_t(0., Rtor, Rmax), normal);
assert(ApproxEqual(normal, Vec_t(p2, 0., p2)));
valid = t2.Normal(ponrmin, normal);
// std::cout<<" normal="<<normal<<std::endl;
assert(ApproxEqual(normal, vmxmy));
valid = t2.Normal(Vec_t(20., 0., 0.), normal);
assert(ApproxEqual(normal, vmy));
valid = t2.Normal(Vec_t(0, 20, 0), normal);
assert(ApproxEqual(normal, vmx));
// SafetyToOut(P)
Dist = t1.SafetyToOut(ponrmin);
assert(ApproxEqual<Precision>(Dist, 80));
Dist = t1.SafetyToOut(ponrmax);
assert(ApproxEqual<Precision>(Dist, 0));
// later: why it was introduced, while they are outside (see above)
Dist = t2.SafetyToOut(Vec_t(20, 0, 0));
assert(ApproxEqual<Precision>(Dist, 0));
Dist = t2.SafetyToOut(Vec_t(0, 20, 0));
assert(ApproxEqual<Precision>(Dist, 0));
// DistanceToOut(P,V)
Dist = t1.DistanceToOut(ponrmax, vx);
// std::cout << "t1.DistanceToOut(p,vx...) = " << Dist << " norm=" << normal << std::endl;
valid = t1.Normal(ponrmax + Dist * vx, normal);
assert(ApproxEqual<Precision>(Dist, 0) && ApproxEqual(normal, vx));
Vec_t ptest = Vec_t(130, 0, 0);
Dist = t1.DistanceToOut(ptest, vx);
// Dist=t1.DistanceToOut(Vec_t(130,0.00001,0.00001),Vec_t(1,0.001,0.001).Unit(),normal,convex);
// std::cout << "t1.DistanceToOut(ponphi1,vz,...) = " << Dist << " n=" << normal << std::endl;
valid = t1.Normal(ptest + Dist * vx, normal);
assert(ApproxEqual<Precision>(Dist, 60) && ApproxEqual(normal, vx));
Dist = t1.DistanceToOut(ponrmin, vy);
valid = t1.Normal(ponrmin + Dist * vy, normal);
assert(ApproxEqual<Precision>(Dist, 80) && ApproxEqual(normal, vy));
Dist = t1.DistanceToOut(ponrmin, vmy);
valid = t1.Normal(ponrmin + Dist * vmy, normal);
assert(ApproxEqual<Precision>(Dist, 100));
// std::cout << "(vz + Vec_t(0.00001, 0.000001, 0): " << (vz + Vec_t(0.00001, 0.000001, 0)) << '\n';
// std::cout << "Vec_t(0.00001, 0.000001, 0)).Unit() = " << (vz + Vec_t(0.00001, 0.000001, 0)).Unit() << '\n';
Dist = t1.DistanceToOut(Vec_t(100, 0, 0), (vz + Vec_t(0.00001, 0.000001, 0)).Unit());
// std::cout << "t1.DistanceToOut(100,0,0,vz,...) = " << Dist << " n=" << norm << std::endl;
assert(ApproxEqual<Precision>(Dist, 90));
// std::cout << "Dist=t2.DistanceToOut(ponphi12,vy) = " << Dist << ", n=" << norm << ", -vy = " << -vy << std::endl;
// std::cout << "norm: " << norm << '\n';
Dist = t2.DistanceToOut(Vec_t(7.07106781186547524400844362, 7.07106781186547524400844362, 0), vmx);
// std::cout << "Dist = t2.DistanceToOut(Vec_t(7.07106781186547524400844362, 7.07106781186547524400844362, 0), vmx,
// normal, convex) = " << Dist << std::endl;
assert(ApproxEqual<Precision>(Dist, 0));
Vec_t test(0., 0., 1);
for (int i = 1; i < 5; i++) {
Dist = t1.DistanceToOut(Vec_t(90, 0, 0), test);
// std::cout << " i=" << i << " Dist=t2.DistanceToOut(90,test) = " << Dist << " n=" << norm << std::endl;
test = test + Vec_t(0.00001, 0.00001, 0);
test = test.Unit();
}
// SafetyToIn(P)
Dist = t1.SafetyToIn(pbigx);
assert(ApproxEqual<Precision>(Dist, 50));
Dist = t1.SafetyToIn(pbigmx);
assert(ApproxEqual<Precision>(Dist, 50));
Dist = t1.SafetyToIn(pbigy);
assert(ApproxEqual<Precision>(Dist, 50));
Dist = t1.SafetyToIn(pbigmy);
assert(ApproxEqual<Precision>(Dist, 50));
Dist = t1.SafetyToIn(pbigz);
// std::cout<<"Dist=t1.SafetyToIn (pbigz) = "<<Dist<<std::endl;
// assert(ApproxEqual<Precision>(Dist,50));
Dist = t1.SafetyToIn(pbigmz);
// std::cout<<"Dist=t1.SafetyToIn (pbigmz) = "<<Dist<<std::endl;
// assert(ApproxEqual<Precision>(Dist,50));
// DistanceToIn(P,V)
// std::cout << "LOGT pbigx: " << pbigx << '\n';
// std::cout << "LOGT vmx: " << vmx << '\n';
Dist = t1.DistanceToIn(pbigx, vmx);
// std::cout << "LOGT Dist = t1.DistanceToIn(pbigx, vmx): " << Dist << '\n';
assert(ApproxEqual<Precision>(Dist, 50));
Dist = t1.DistanceToIn(pbigmx, vx);
assert(ApproxEqual<Precision>(Dist, 50));
Dist = t1.DistanceToIn(pbigy, vmy);
assert(ApproxEqual<Precision>(Dist, 50));
Dist = t1.DistanceToIn(pbigmy, vy);
assert(ApproxEqual<Precision>(Dist, 50));
Dist = t1.DistanceToIn(pbigz, vmz);
assert(ApproxEqual<Precision>(Dist, vecgeom::kInfLength));
Dist = t1.DistanceToIn(pbigmz, vz);
assert(ApproxEqual<Precision>(Dist, vecgeom::kInfLength));
Dist = t1.DistanceToIn(pbigx, vxy);
assert(ApproxEqual<Precision>(Dist, vecgeom::kInfLength));
Dist = t1.DistanceToIn(ponrmax, vx);
// std::cout << "Dist=t1.DIN (p,v) = " << Dist << std::endl;
// assert(ApproxEqual<Precision>(Dist,vecgeom::kInfLength));
Dist = t1.DistanceToIn(ponrmax, vmx);
// std::cout << "Dist=t1.DIN (p,v) = " << Dist << std::endl;
// assert(ApproxEqual<Precision>(Dist,0));
// Vec_t vnew(1,0,0) ;
// vnew.rotateZ(pi/4-5*1e-9) ; // old test: check pzero with vxy
// Dist=t2.DistanceToIn(pzero,vnew);
// assert(ApproxEqual<Precision>(Dist,vecgeom::kInfLength));
// std::cout << "Dist=t2.DIN (p,v) = " << Dist << std::endl;
Dist = t2.DistanceToIn(pzero, vy);
assert(ApproxEqual<Precision>(Dist, 10));
Dist = t2.DistanceToIn(ponphi12, vy);
// std::cout << "Dist = t2.DistanceToIn(ponphi12, vy) = " << Dist << ", ponphi12 = " << ponphi12 << ", vy = " << vy <<
// std::endl;
assert(ApproxEqual<Precision>(Dist, vecgeom::kInfLength));
Dist = t2.DistanceToIn(ponphi12, vmy);
assert(ApproxEqual<Precision>(Dist, 0));
Dist = t2.DistanceToIn(ponphi1, vy);
assert(ApproxEqual<Precision>(Dist, 13.550819613108856743)); // Not sure about this
// Torus t2 is ends at pi/2 rad, we expect infinity
Dist = t2.DistanceToIn(ponrmin, vy);
assert(ApproxEqual<Precision>(Dist, vecgeom::kInfLength));
Dist = t2.DistanceToIn(ponrmin, vmy);
assert(ApproxEqual<Precision>(Dist, vecgeom::kInfLength));
Dist = t3.DistanceToIn(ponrtor, vy);
assert(ApproxEqual<Precision>(Dist, 40));
Dist = t3.DistanceToIn(ponrtor, vmy);
assert(ApproxEqual<Precision>(Dist, 40));
Dist = t3.DistanceToIn(ponrtor, vz);
assert(ApproxEqual<Precision>(Dist, 40));
Dist = t3.DistanceToIn(ponrtor, vmz);
assert(ApproxEqual<Precision>(Dist, 40));
Dist = t3.DistanceToIn(ponrtor, vx);
assert(ApproxEqual<Precision>(Dist, vecgeom::kInfLength));
Dist = t3.DistanceToIn(ponrtor, vmx);
assert(ApproxEqual<Precision>(Dist, vecgeom::kInfLength));
Dist = t6.DistanceToIn(p1t6, vt6);
// std::cout<<"t6.DistanceToIn(p1t6,vt6) = "<<Dist<<std::endl;
// Bug 810
Vec_t pTmp(0., 0., 0.);
dist = clad->DistanceToIn(pTmp, vy);
pTmp += dist * vy;
// std::cout << "pTmpX = " << pTmp.x() << "; pTmpY = " << pTmp.y() << "; pTmpZ = " << pTmp.z() << std::endl;
side = core->Inside(pTmp);
// std::cout << "core->Inside(pTmp) = " << side << std::endl;
side = clad->Inside(pTmp);
// std::cout << "clad->Inside(pTmp) = " << side << std::endl;
dist = core->DistanceToIn(pTmp, vy);
pTmp += dist * vy;
// std::cout << "pTmpX = " << pTmp.x() << "; pTmpY = " << pTmp.y() << "; pTmpZ = " << pTmp.z() << std::endl;
side = core->Inside(pTmp);
// std::cout << "core->Inside(pTmp) = " << side << std::endl;
side = clad->Inside(pTmp);
// std::cout << "clad->Inside(pTmp) = " << side << std::endl;
dist = core->DistanceToOut(pTmp, vy);
pTmp += dist * vy;
// std::cout << "pTmpX = " << pTmp.x() << "; pTmpY = " << pTmp.y() << "; pTmpZ = " << pTmp.z() << std::endl;
side = core->Inside(pTmp);
// std::cout << "core->Inside(pTmp) = " << side << std::endl;
side = clad->Inside(pTmp);
// std::cout << "clad->Inside(pTmp) = " << side << std::endl;
dist = clad->DistanceToOut(pTmp, vy);
pTmp += dist * vy;
// std::cout << "pTmpX = " << pTmp.x() << "; pTmpY = " << pTmp.y() << "; pTmpZ = " << pTmp.z() << std::endl;
side = core->Inside(pTmp);
// std::cout << "core->Inside(pTmp) = " << side << std::endl;
side = clad->Inside(pTmp);
// std::cout << "clad->Inside(pTmp) = " << side << std::endl;
// Check for Distance to In ( start from an external point )
for (i = 0; i < 12; i++) {
x = -1200;
z = Precision(i) / 10;
p1 = Vec_t(x, 0, z);
// std::cout << p1 << " - " << v1 << std::endl;
Dist = aTub->DistanceToIn(p1, v1);
// std::cout << "Distance to in dir: " << Dist ;
Dist = aTub->DistanceToOut(p1, v1);
// std::cout << " Distance to out dir: " << Dist << std::endl ;
// std::cout << "Distance to in : " << aTub->DistanceToIn (p1);
// std::cout << " Distance to out : " << aTub->DistanceToOut (p1)
// << std::endl;
// std::cout << " Inside : " << aTub->Inside (p1);
// std::cout << std::endl;
}
// CalculateExtent
std::cout << "Test passed." << std::endl;
return true;
}
int main()
{
#ifdef NDEBUG
G4Exception("FAIL: *** Assertions must be compiled in! ***");
#endif
assert(testTorus<vecgeom::SimpleTorus2>());
return 0;
}
|