7 #include "boost/io/ios_state.hpp"
19 #include "CLHEP/Units/SystemOfUnits.h"
20 #include "CLHEP/Units/PhysicalConstants.h"
27 static double IntPrecision = 0.0001;
46 p[0] = 0.;
p[1] = m_Rmin;
p[2] = m_Zmin;
48 GetCalculator()->DistanceToTheNearestFan(
p, p_fan);
51 if(
m) std::cout <<
m << std::endl;
55 static void get_r(
const G4VSolid *
p, G4double
z,
56 G4double &rmin, G4double &rmax
60 rmax = from[0] -
p->DistanceToIn(from, G4ThreeVector(-1., 0., 0.));
62 rmin =
p->DistanceToIn(from, G4ThreeVector(1., 0., 0.));
65 static TRandom *rnd = 0;
69 rnd =
new TRandom3(0);
72 G4double
r = rnd->Uniform();
74 G4ThreeVector
p(0., 0., 0.);
76 G4double level1 = .980;
77 G4double level2 = .993;
78 const char *
v =
getenv(
"LARWHEELSOLID_TEST_MODE_LEVEL1");
80 const char *v1 =
getenv(
"LARWHEELSOLID_TEST_MODE_LEVEL2");
81 if(v1) level2 =
atof(v1);
84 std::cout <<
"LWS::GPOS " <<
r << std::endl;
89 }
else if(
r <= level2){
94 G4Exception(
"LArWheelSolid",
"Rnd generator error", FatalException,
"GetPointOnSurface: Wrong data from rnd generator");
108 p[1] = rnd->Uniform(rmin, rmax);
110 G4double dphi =
p.phi();
116 if(
d < 0.)
side = -1;
117 if(
d >= 0.)
side = 1;
125 G4ThreeVector D =
p; D[2] = 0.;
137 G4ThreeVector
B =
p + D *
d1;
138 G4double dphi =
B.phi();
154 G4ThreeVector D1 = (
p -
B).
unit();
170 const bool inner = rnd->Uniform() > 0.5?
true:
false;
172 p[0] = 0.;
p[1] = inner? rmin: rmax;
p[2] =
z;
174 G4double dphi =
p.phi();
179 const G4double
r =
p[1];
181 G4ThreeVector A1(0.,
r,
z);
193 G4ThreeVector A2(0.,
r,
z);
211 G4ThreeVector
d = (A2 - A1).
unit();
223 if(inner)
step *= -2;
233 G4ThreeVector B1(0.,
r +
step,
z);
244 G4ThreeVector B2(0.,
r +
step,
z);
256 if(B1i == A1i || B2i == A1i){
268 G4ThreeVector
d1 = (A1 - B1).
unit();
270 G4ThreeVector
d2 = (A2 - B2).
unit();
273 G4ThreeVector
X = X1;
274 G4double phi1 = X1.phi(), phi2 = X2.phi();
277 G4double phiX = rnd->Uniform(phi1, phi2);
297 p[1] = rnd->Uniform(rmin, rmax);
299 G4double dphi =
p.phi();
350 G4ThreeVector(0.,
r, -
m_Zmin), G4ThreeVector(0., 0., 1.)
354 G4ThreeVector(0.,
r,
m_Zmax), G4ThreeVector(0., 0., -1.)
373 std::cout <<
"get_area_on_polycone: " << a1/
mm2 << std::endl;
379 std::cout <<
"get_area_on_face: " << a2/
mm2 << std::endl;
385 std::cout <<
"get_area_on_side: " << a3/
mm2 << std::endl;
398 boost::io::ios_all_saver ias(std::cout);
399 const char *on =
getenv(
"LARWHEELSOLID_TEST");
401 std::string test_mode = on;
403 std::cout <<
"============| LArWheelSolid test() routine |=============="
407 std::cout.precision(6);
408 std::cout << std::fixed;
409 const char *
prec =
getenv(
"LARWHEELSOLID_TEST_INTPRECISION");
411 std::cout <<
"Int. precision " << IntPrecision << std::endl;
412 std::cout <<
"test mode " << test_mode << std::endl;
414 std::cout <<
"m_Rmin = " <<
m_Rmin <<
" m_Rmax = " <<
m_Rmax << std::endl
415 <<
"m_Zmin = " <<
m_Zmin <<
" m_Zmax = " <<
m_Zmax << std::endl;
420 if(test_mode.find(
"root") != std::string::npos){
421 F =
new TFile(
"LArWheelSolid_test.root",
"UPDATE");
422 T =
new TNtupleD(GetName(), GetName(),
"x:y:z");
425 const int Nmax(1000000000);
426 char *NN =
getenv(
"LARWHEELSOLID_TEST_NPOINTS");
430 N = strtol(NN, &endptr, 0);
431 if (endptr[0] !=
'\0') {
432 throw std::invalid_argument(
"Could not convert string to int: " + std::string(NN));
436 std::cout <<
"Number of points from LARWHEELSOLID_TEST_NPOINTS environment variable ("<<
N<<
") is too large. Using " << Nmax <<
" instead." << std::endl;
440 std::cout <<
"Number of points from LARWHEELSOLID_TEST_NPOINTS environment variable ("<<
N<<
") is negative!!. Using 0 instead." << std::endl;
443 if(test_mode.find(
"points") == std::string::npos){
446 std::cout <<
N <<
" points" << std::endl;
448 for(
int i = 0;
i <
N; ++
i){
453 std::cout <<
i <<
" "
454 << (ii == kInside?
"inside":
"outside")
458 if(
T)
T->Fill(
p[0],
p[1],
p[2]);
467 if(test_mode.find(
"volume") != std::string::npos){
469 std::cout <<
"GetCubicVolume: " << cv/
CLHEP::mm3 <<
" mm^3" << std::endl;
472 if(test_mode.find(
"area") != std::string::npos){
474 std::cout <<
"GetSurfaceArea: " << sa/
CLHEP::mm2 <<
" mm^2" << std::endl;
477 std::cout <<
"======= end of ArWheelSolid test() routine ============="
481 if(test_mode.find(
"once") != std::string::npos)
exit(0); }
516 G4ThreeVector(0.,
r,
m_Zmin), G4ThreeVector(0., 0., 1.)
519 G4ThreeVector(0.,
r,
m_Zmax), G4ThreeVector(0., 0., -1.)
528 static std::map<double, LArWheelSolid *> solid;
532 const double &
z =
x[0];
533 const double &
r =
p[0];
534 const double &
index =
p[1];
536 G4ThreeVector
a(0.,
r,
z);
537 double b = solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, -1, 121)
538 - solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, 1, 121);
544 const double &
r =
x[0];
545 const double &
index =
p[0];
547 return solid[
index]->get_area_at_r(
r);
552 const double &
z =
x[0];
553 const double &
index =
p[0];
556 get_r(solid[
index]->m_BoundingShape,
z, rmin, rmax);
559 G4ThreeVector
a(0., rmin,
z);
560 result += solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, -1, 232)
561 - solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, 1, 232);
563 result += solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, -1, 343)
564 - solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, 1, 343);
572 const double &
z =
x[0];
573 const double &
r =
par[0];
576 const double h = 0.001;
579 G4ThreeVector
p(0.,
r,
z +
h);
580 G4double D1 = solid[
index]->GetCalculator()->AmplitudeOfSurface(
p,
side, 5665);
582 D1 -= solid[
index]->GetCalculator()->AmplitudeOfSurface(
p,
side, 5665);
586 G4double D2 = solid[
index]->GetCalculator()->AmplitudeOfSurface(
p,
side, 5665);
588 D2 -= solid[
index]->GetCalculator()->AmplitudeOfSurface(
p,
side, 5665);
591 G4double D = (D2 * 4 - D1) / 3.;
592 G4double
dl = sqrt(1 + D * D);
597 static double fcn_length(
double *
x,
double *
p)
604 const double &
r =
x[0];
605 const double &
index =
p[0];
607 return solid[
index]->get_length_at_r(
r);
615 #ifdef DEBUG_LARWHEELSOLID
616 std::cout <<
"LArWheelSolid::init_tests: put " <<
this
639 (GetName() +
"_f_length").c_str(), &fcn_length,
651 #ifdef DEBUG_LARWHEELSOLID
652 G4bool LArWheelSolid::test_dti(
653 const G4ThreeVector &inputP,
const G4ThreeVector &inputV,
658 LWSDBG(1, std::cout <<
"DTI test skipped, distance > 10 m"
668 const G4double
phi0 =
p.phi();
672 std::cout <<
"DTI test already inside" << MSG_VECTOR(
p) << std::endl;
675 G4ThreeVector
v( inputV );
676 v.rotateZ(
p.phi() -
phi0);
678 LWSDBG(1, std::cout <<
"Start DTI test, expect "
688 G4ThreeVector
p1 =
p +
v *
t;
690 std::cout <<
"DTI test at " << MSG_VECTOR(inputP) <<
" -> "
691 << MSG_VECTOR(inputV) <<
", translated to "
692 << MSG_VECTOR(
p) <<
" - > " << MSG_VECTOR(
v)
694 <<
distance <<
": found nearer intersection at local point"
695 << MSG_VECTOR(
p1) <<
", distance " <<
t
702 FILE *
F = fopen(
"dti_error.dat",
"w");
704 fprintf(
F,
"%10e %10e %10e\n",
p.x(),
p.y(),
p.z());
705 fprintf(
F,
"%10e %10e %10e\n",
v.x(),
v.y(),
v.z());
709 fprintf(
F,
"%10e %10e\n",
e,
f);
719 LWSDBG(1, std::cout <<
"DTI test at " << MSG_VECTOR(
p) <<
" -> "
720 << MSG_VECTOR(
v) <<
" in range of "
721 <<
distance <<
": allright" << std::endl);
725 G4bool LArWheelSolid::test_dto(
726 const G4ThreeVector &inputP,
const G4ThreeVector &inputV,
731 LWSDBG(1, std::cout <<
"DTO test skipped, distance > 10 m"
737 G4ThreeVector
p( inputP );
738 const G4double
phi0 =
p.phi();
742 std::cout <<
"DTO test already outside" << MSG_VECTOR(
p) << std::endl;
745 G4ThreeVector
v( inputV );
746 v.rotateZ(
p.phi() -
phi0);
748 LWSDBG(1, std::cout <<
"Start DTO test, expect "
756 static bool first =
true;
758 G4ThreeVector
p1 =
p +
v *
t;
760 std::cout <<
"DTO test at " << MSG_VECTOR(inputP) <<
" -> "
761 << MSG_VECTOR(inputV) <<
", translated to "
762 << MSG_VECTOR(
p) <<
" - > " << MSG_VECTOR(
v)
764 <<
distance <<
": found nearer intersection at local point"
765 << MSG_VECTOR(
p1) <<
", distance " <<
t
772 FILE *
F = fopen(
"dto_error.dat",
"w");
774 fprintf(
F,
"%10e %10e %10e\n",
p.x(),
p.y(),
p.z());
775 fprintf(
F,
"%10e %10e %10e\n",
v.x(),
v.y(),
v.z());
779 fprintf(
F,
"%10e %10e\n",
e,
f);
789 LWSDBG(1, std::cout <<
"DTO test at " << MSG_VECTOR(
p) <<
" -> "
790 << MSG_VECTOR(
v) <<
" in range of "
791 <<
distance <<
": allright" << std::endl);