Skip to content

Commit

Permalink
feat(Examples): Add options for usage of solenoid field (#766)
Browse files Browse the repository at this point in the history
This PR add the magnetic field options for usage of solenoid field for the examples.
  • Loading branch information
XiaocongAi committed Apr 19, 2021
1 parent e040867 commit 5ea8df7
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Examples/Detectors/MagneticField/src/MagneticFieldOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "ActsExamples/MagneticField/MagneticFieldOptions.hpp"

#include "Acts/Definitions/Units.hpp"
#include "Acts/MagneticField/BFieldMapUtils.hpp"
#include "Acts/MagneticField/MagneticFieldProvider.hpp"
#include "Acts/MagneticField/SolenoidBField.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/Framework/Sequencer.hpp"
#include "ActsExamples/MagneticField/ScalableBFieldService.hpp"
Expand Down Expand Up @@ -66,6 +68,27 @@ void ActsExamples::Options::addMagneticFieldOptions(Description& desc) {
"option only needs to be set if the field value unit in the field map "
"file is not `Tesla`. The value must scale from the stored unit to the "
"equvalent value in `Tesla`.");
opt("bf-solenoid-mag-tesla", value<double>()->default_value(0.),
"The magnitude of a solenoid magnetic field in the center in `Tesla`. "
"Only used "
"if neither constant field nor a magnetic field map is given.");
opt("bf-solenoid-length", value<double>()->default_value(6000),
"The length of the solenoid magnetic field in `mm`.");
opt("bf-solenoid-radius", value<double>()->default_value(1200),
"The radius of the solenoid magnetic field in `mm`.");
opt("bf-solenoid-ncoils", value<size_t>()->default_value(1194),
"Number of coils for the solenoid magnetic field.");
opt("bf-solenoid-map-rlim",
value<Interval>()->value_name("MIN:MAX")->default_value({0, 1200}),
"The length bounds of the grid created from the analytical solenoid "
"field in `mm`.");
opt("bf-solenoid-map-zlim",
value<Interval>()->value_name("MIN:MAX")->default_value({-3000, 3000}),
"The radius bounds of the grid created from the analytical solenoid "
"field in `mm`.");
opt("bf-solenoid-map-nbins", value<Reals<2>>()->default_value({{150, 200}}),
"The number of bins in r-z directions for the grid created from the "
"analytical solenoid field.");
}

void ActsExamples::Options::setupMagneticFieldServices(const Variables& vars,
Expand Down Expand Up @@ -175,6 +198,39 @@ ActsExamples::Options::readMagneticField(const Variables& vars) {
}
}

// third option: create a solenoid field
if (vars["bf-solenoid-mag-tesla"].as<double>() > 0) {
// Construct a solenoid field
Acts::SolenoidBField::Config solenoidConfig;
solenoidConfig.length =
vars["bf-solenoid-length"].as<double>() * Acts::UnitConstants::mm;
solenoidConfig.radius =
vars["bf-solenoid-radius"].as<double>() * Acts::UnitConstants::mm;
solenoidConfig.nCoils = vars["bf-solenoid-ncoils"].as<size_t>();
solenoidConfig.bMagCenter =
vars["bf-solenoid-mag-tesla"].as<double>() * Acts::UnitConstants::T;
ACTS_INFO("Use solenoid magnetic field with magnitude "
<< solenoidConfig.bMagCenter / Acts::UnitConstants::T
<< " Tesla at the center.");
const auto solenoidField = Acts::SolenoidBField(solenoidConfig);
// The parameters for creating a field map
auto getRange = [&](const char* name, auto unit, auto& lower, auto& upper) {
auto interval = vars[name].as<Options::Interval>();
lower = interval.lower.value() * unit;
upper = interval.upper.value() * unit;
};
std::pair<double, double> rlim, zlim;
getRange("bf-solenoid-map-rlim", Acts::UnitConstants::mm, rlim.first,
rlim.second);
getRange("bf-solenoid-map-zlim", Acts::UnitConstants::mm, zlim.first,
zlim.second);
const auto nbins = vars["bf-solenoid-map-nbins"].as<Reals<2>>();
auto mapper = Acts::solenoidFieldMapper(rlim, zlim, {nbins[0], nbins[1]},
solenoidField);
InterpolatedMagneticField2::Config cfg(std::move(mapper));
return std::make_shared<InterpolatedMagneticField2>(std::move(cfg));
}

// default option: no field
ACTS_INFO("Use no magnetic field");
return std::make_shared<Acts::NullBField>();
Expand Down

0 comments on commit 5ea8df7

Please sign in to comment.