19#include "CLHEP/Units/SystemOfUnits.h"
20#include "CLHEP/Units/PhysicalConstants.h"
51 if(m) std::cout << m << std::endl;
55static void get_r(
const G4VSolid *p, G4double
z,
56 G4double &rmin, G4double &rmax
59 G4ThreeVector from(10.*CLHEP::m, 0.,
z);
60 rmax = from[0] - p->DistanceToIn(from, G4ThreeVector(-1., 0., 0.));
62 rmin = p->DistanceToIn(from, G4ThreeVector(1., 0., 0.));
65static 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");
79 if(v) level1 = atof(v);
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.;
127 if(d1 > 10.*CLHEP::m){
131 if(d1 > 10.*CLHEP::m){
137 G4ThreeVector B = p + D * d1;
138 G4double dphi = B.phi();
154 G4ThreeVector D1 = (p - B).
unit();
156 if(
Inside(X) == kSurface){
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();
222 step = d1 > d2? d1 : d2;
223 if(inner) step *= -2;
228 step = d1 > d2? d1 : d2;
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();
276 if(phi1 > 0. && phi2 < 0.) phi2 += CLHEP::twopi;
277 G4double phiX =
rnd->Uniform(phi1, phi2);
278 if(phiX > CLHEP::pi) phiX -= CLHEP::twopi;
281 if(
Inside(X) == kSurface){
297 p[1] =
rnd->Uniform(rmin, rmax);
299 G4double dphi = p.phi();
335 G4double result = 0.;
338 result += rmax - rmin;
340 result += rmax - rmin;
350 G4ThreeVector(0.,
r, -
m_Zmin), G4ThreeVector(0., 0., 1.)
354 G4ThreeVector(0.,
r,
m_Zmax), G4ThreeVector(0., 0., -1.)
357 double result =
m_f_length->Integral(zmin, zmax);
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 const char *on = getenv(
"LARWHEELSOLID_TEST");
400 std::string test_mode = on;
402 std::cout <<
"============| LArWheelSolid test() routine |=============="
406 const char *prec = getenv(
"LARWHEELSOLID_TEST_INTPRECISION");
408 std::cout << std::format(
"Int. precision {:.6f}\n",
IntPrecision);
409 std::cout <<
"test mode " << test_mode << std::endl;
411 std::cout << std::format(
"m_Rmin = {:.6f} m_Rmax = {:.6f}\n",
m_Rmin,
m_Rmax)
412 << std::format(
"m_Zmin = {:.6f} m_Zmax = {:.6f}\n",
m_Zmin,
m_Zmax);
417 if(test_mode.find(
"root") != std::string::npos){
418 F =
new TFile(
"LArWheelSolid_test.root",
"UPDATE");
419 T =
new TNtupleD(GetName(), GetName(),
"x:y:z");
422 const int Nmax(1000000000);
423 char *NN = getenv(
"LARWHEELSOLID_TEST_NPOINTS");
427 N = strtol(NN, &endptr, 0);
428 if (endptr[0] !=
'\0') {
429 throw std::invalid_argument(
"Could not convert string to int: " + std::string(NN));
433 std::cout <<
"Number of points from LARWHEELSOLID_TEST_NPOINTS environment variable ("<<N<<
") is too large. Using " << Nmax <<
" instead." << std::endl;
437 std::cout <<
"Number of points from LARWHEELSOLID_TEST_NPOINTS environment variable ("<<N<<
") is negative!!. Using 0 instead." << std::endl;
440 if(test_mode.find(
"points") == std::string::npos){
443 std::cout << N <<
" points" << std::endl;
445 for(
int i = 0; i < N; ++ i){
450 std::cout << i <<
" "
451 << (ii == kInside?
"inside":
"outside")
455 if(T) T->Fill(p[0], p[1], p[2]);
464 if(test_mode.find(
"volume") != std::string::npos){
466 std::cout <<
"GetCubicVolume: " << cv/CLHEP::mm3 <<
" mm^3" << std::endl;
469 if(test_mode.find(
"area") != std::string::npos){
471 std::cout <<
"GetSurfaceArea: " << sa/CLHEP::mm2 <<
" mm^2" << std::endl;
474 std::cout <<
"======= end of ArWheelSolid test() routine ============="
478 if(test_mode.find(
"once") != std::string::npos) exit(0); }
512 G4ThreeVector(0.,
r,
m_Zmin), G4ThreeVector(0., 0., 1.)
515 G4ThreeVector(0.,
r,
m_Zmax), G4ThreeVector(0., 0., -1.)
519 double result =
m_f_area->Integral(zmin, zmax);
524static std::map<double, LArWheelSolid *>
solid;
528 const double &
z =
x[0];
529 const double &
r = p[0];
530 const double &
index = p[1];
532 G4ThreeVector
a(0.,
r,
z);
533 double b =
solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, -1, 121)
534 -
solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, 1, 121);
540 const double &
r =
x[0];
541 const double &
index = p[0];
548 const double &
z =
x[0];
549 const double &
index = p[0];
555 G4ThreeVector
a(0., rmin,
z);
556 result +=
solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, -1, 232)
557 -
solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, 1, 232);
559 result +=
solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, -1, 343)
560 -
solid[
index]->GetCalculator()->AmplitudeOfSurface(
a, 1, 343);
568 const double &
z =
x[0];
569 const double &
r = par[0];
570 const double &
index = par[1];
572 const double h = 0.001;
575 G4ThreeVector p(0.,
r,
z +
h);
576 G4double D1 =
solid[
index]->GetCalculator()->AmplitudeOfSurface(p, side, 5665);
578 D1 -=
solid[
index]->GetCalculator()->AmplitudeOfSurface(p, side, 5665);
582 G4double D2 =
solid[
index]->GetCalculator()->AmplitudeOfSurface(p, side, 5665);
584 D2 -=
solid[
index]->GetCalculator()->AmplitudeOfSurface(p, side, 5665);
587 G4double D = (D2 * 4 - D1) / 3.;
588 G4double dl = sqrt(1 + D * D);
600 const double &
r =
x[0];
601 const double &
index = p[0];
611#ifdef DEBUG_LARWHEELSOLID
612 std::cout <<
"LArWheelSolid::init_tests: put " <<
this
635 (GetName() +
"_f_length").c_str(), &
fcn_length,
647#ifdef DEBUG_LARWHEELSOLID
648G4bool LArWheelSolid::test_dti(
649 const G4ThreeVector &inputP,
const G4ThreeVector &inputV,
650 const G4double distance
653 if(distance > 10.*CLHEP::m){
654 LWSDBG(1, std::cout <<
"DTI test skipped, distance > 10 m"
664 const G4double
phi0 =
p.phi();
668 std::cout <<
"DTI test already inside" << MSG_VECTOR(p) << std::endl;
671 G4ThreeVector
v( inputV );
672 v.rotateZ(
p.phi() - phi0);
674 LWSDBG(1, std::cout <<
"Start DTI test, expect "
675 <<
long(distance / dd) <<
" iterations"
684 G4ThreeVector
p1 =
p +
v *
t;
686 std::cout <<
"DTI test at " << MSG_VECTOR(inputP) <<
" -> "
687 << MSG_VECTOR(inputV) <<
", translated to "
688 << MSG_VECTOR(p) <<
" - > " << MSG_VECTOR(v)
690 <<
distance <<
": found nearer intersection at local point"
691 << MSG_VECTOR(p1) <<
", distance " <<
t
698 FILE *
F = fopen(
"dti_error.dat",
"w");
700 fprintf(
F,
"%10e %10e %10e\n",
p.x(),
p.y(),
p.z());
701 fprintf(
F,
"%10e %10e %10e\n",
v.x(),
v.y(),
v.z());
705 fprintf(
F,
"%10e %10e\n", e, f);
715 LWSDBG(1, std::cout <<
"DTI test at " << MSG_VECTOR(p) <<
" -> "
716 << MSG_VECTOR(v) <<
" in range of "
717 << distance <<
": allright" << std::endl);
721G4bool LArWheelSolid::test_dto(
722 const G4ThreeVector &inputP,
const G4ThreeVector &inputV,
723 const G4double distance
726 if(distance > 10.*CLHEP::m){
727 LWSDBG(1, std::cout <<
"DTO test skipped, distance > 10 m"
733 G4ThreeVector
p( inputP );
734 const G4double
phi0 =
p.phi();
738 std::cout <<
"DTO test already outside" << MSG_VECTOR(p) << std::endl;
741 G4ThreeVector
v( inputV );
742 v.rotateZ(
p.phi() - phi0);
744 LWSDBG(1, std::cout <<
"Start DTO test, expect "
745 <<
long(distance / dd) <<
" iterations"
752 static bool first =
true;
754 G4ThreeVector
p1 =
p +
v *
t;
756 std::cout <<
"DTO test at " << MSG_VECTOR(inputP) <<
" -> "
757 << MSG_VECTOR(inputV) <<
", translated to "
758 << MSG_VECTOR(p) <<
" - > " << MSG_VECTOR(v)
760 <<
distance <<
": found nearer intersection at local point"
761 << MSG_VECTOR(p1) <<
", distance " <<
t
768 FILE *
F = fopen(
"dto_error.dat",
"w");
770 fprintf(
F,
"%10e %10e %10e\n",
p.x(),
p.y(),
p.z());
771 fprintf(
F,
"%10e %10e %10e\n",
v.x(),
v.y(),
v.z());
775 fprintf(
F,
"%10e %10e\n", e, f);
785 LWSDBG(1, std::cout <<
"DTO test at " << MSG_VECTOR(p) <<
" -> "
786 << MSG_VECTOR(v) <<
" in range of "
787 << distance <<
": allright" << std::endl);
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
static std::map< double, LArWheelSliceSolid * > solid
static double fcn_length(double *x, double *p)
static void get_r(const G4VSolid *p, G4double z, G4double &rmin, G4double &rmax)
static double IntPrecision
double LArWheelSolid_get_dl(double *x, double *par, G4int side)
double LArWheelSolid_fcn_area(double *x, double *p)
double LArWheelSolid_fcn_vol(double *x, double *p)
double LArWheelSolid_fcn_side_area(double *x, double *p)
double LArWheelSolid_fcn_area_on_pc(double *x, double *p)
static double fcn_length(double *x, double *p)
static void get_r(const G4VSolid *p, G4double z, G4double &rmin, G4double &rmax)
const char * LArWheelSolidTypeString(LArWheelSolid_t type)
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Header file for AthHistogramAlgorithm.
int GetNumberOfFans() const
double AmplitudeOfSurface(const CLHEP::Hep3Vector &P, int side, int fan_number) const
double GetFanHalfThickness(LArG4::LArWheelCalculator_t) const
double DistanceToTheNearestFan(CLHEP::Hep3Vector &p, int &out_fan_number) const
Determines the nearest to the input point fan.
G4double get_area_on_face(void) const
void get_point_on_accordion_surface(G4ThreeVector &) const
G4double get_area_on_polycone(void) const
const LArWheelSolid_t m_Type
static const G4double s_IterationPrecision
G4double GetSurfaceArea(void)
static const G4double s_Tolerance
friend double LArWheelSolid_fcn_area(double *, double *)
EInside Inside_accordion(const G4ThreeVector &) const
G4VSolid * m_BoundingShape
friend double LArWheelSolid_fcn_vol(double *, double *)
G4double get_area_at_r(G4double r) const
friend double LArWheelSolid_fcn_side_area(double *, double *)
G4double get_length_at_r(G4double r) const
friend double LArWheelSolid_fcn_area_on_pc(double *, double *)
void set_failover_point(G4ThreeVector &p, const char *m=0) const
G4double GetCubicVolume(void)
EInside Inside(const G4ThreeVector &) const
G4ThreeVector GetPointOnSurface(void) const
void get_point_on_flat_surface(G4ThreeVector &) const
G4double get_area_on_side(void) const
void get_point_on_polycone_surface(G4ThreeVector &) const
G4double m_FanHalfThickness
const LArWheelCalculator * GetCalculator(void) const
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)