31 double bz0 = fld->solenoidField();
32 LOG(info) <<
"Created default magnetic field for " << bz0 <<
"kG";
33 const double nomBz = 5.00685;
34 BOOST_CHECK_CLOSE(bz0, nomBz, 0.1);
36 const int ntst = 10000;
38 double xyz[ntst][3] = {}, bxyz[ntst][3] = {}, dummyAcc = 0.;
40 for (
int it = ntst; it--;) {
41 gRandom->RndmArray(3, rnd);
42 xyz[it][0] = rnd[0] * 400. * TMath::Cos(rnd[1] * TMath::Pi() * 2);
43 xyz[it][1] = rnd[1] * 400. * TMath::Sin(rnd[1] * TMath::Pi() * 2);
44 xyz[it][2] = (rnd[0] - 0.5) * 250;
47 const int repFactor = 50;
51 for (
int ii = repFactor; ii--;) {
52 for (
int it = ntst; it--;) {
53 fld->Field(xyz[it], bxyz[it]);
59 fld->AllowFastField(
true);
65 for (
int ii = repFactor; ii--;) {
66 for (
int it = ntst; it--;) {
67 fld->Field(xyz[it], bfast);
72 double sS = swSlow.CpuTime() / (ntst * repFactor);
73 double sF = swFast.CpuTime() / (ntst * repFactor);
74 double rat = sF > 0. ? sS / sF : -1;
75 LOG(info) <<
"Timing: Exact param: " << sS <<
" Fast param: " << sF
76 <<
"s/call -> factor " << rat;
79 double mean[3] = {0.}, rms[3] = {0.};
80 const char comp[] =
"XYZ";
81 LOG(info) <<
"Relative precision of fast field wrt exact field";
82 for (
int it = ntst; it--;) {
83 fld->Field(xyz[it], bfast);
84 for (
int i = 0;
i < 3;
i++) {
85 double df = bxyz[it][
i] - bfast[
i];
90 for (
int i = 0;
i < 3;
i++) {
93 rms[
i] -= mean[
i] * mean[
i];
94 rms[
i] = TMath::Sqrt(rms[
i]);
95 LOG(info) <<
"deltaB" << comp[
i] <<
": "
96 <<
" mean=" << mean[
i] <<
"(" << mean[
i] / nomBz * 100. <<
"%)"
97 <<
" RMS =" << rms[
i] <<
"(" << rms[
i] / nomBz * 100. <<
"%)";
108 const double points[][3] = {
116 const int npoints =
sizeof(points) /
sizeof(points[0]);
117 const double tolerance = 1.e-9;
119 std::unique_ptr<MagneticField> fld = std::make_unique<MagneticField>(
"Maps",
"Maps", 1., 1.,
MagFieldParam::k5kG);
120 const double facSol = fld->getFactorSolenoid(), facDip = fld->getFactorDipole();
121 double bref[npoints][3] = {};
122 for (
int ip = 0; ip < npoints; ip++) {
123 fld->Field(points[ip], bref[ip]);
125 BOOST_CHECK(TMath::Abs(bref[ip][0]) + TMath::Abs(bref[ip][1]) + TMath::Abs(bref[ip][2]) > tolerance);
128 const char* fname =
"testMagneticFieldReinitialization.root";
130 TFile fout(fname,
"recreate");
131 fout.WriteObject(fld.get(),
"field");
135 BOOST_REQUIRE(fldRead !=
nullptr);
136 fldRead->CreateField();
139 for (
int ip = 0; ip < npoints; ip++) {
141 fldRead->Field(points[ip],
b);
142 for (
int i = 0;
i < 3;
i++) {
143 BOOST_CHECK_SMALL(
b[
i] - bref[ip][
i], tolerance);