14#include <fmt/format.h>
22 LOG(info) <<
"kf::SetupBuilder initilization: ...";
25 throw std::runtime_error(
"kf::SetupBuilder: no field is provided");
28 LOG(info) <<
"kf::SetupBuilder initilization: done";
34 throw std::runtime_error(
"kf::SetupBuilder: no geometry layers initialized");
37 throw std::runtime_error(
"kf::SetupBuilder: no material map factory provided");
40 throw std::runtime_error(
"kf::SetupBuilder: target properties were not set");
44 bool bMaterialLoaded{
false};
50 if (!bMaterialLoaded) {
62 double acceptanceSlope = -1.;
64 double tCurr = std::max(std::fabs(layer.fXmax), std::fabs(layer.fYmax)) / (layer.fZref -
fTarget.
GetZ());
66 acceptanceSlope = std::max(acceptanceSlope, tCurr);
69 if (!bMaterialLoaded) {
75 double z1 = layerIt->fZmax;
78 z2 = std::next(layerIt)->fZmin;
80 double zNew{0.5 * (z1 + z2)};
81 double xyMax{acceptanceSlope * (layerIt->fZref -
fTarget.
GetZ())};
82 if (!bMaterialLoaded) {
100 LOG(info) <<
"kf::SetupBuilder initialization: done";
107 std::stringstream msg;
108 msg <<
"kf::SetupBuilder initialization: failed:\n";
109 msg << fmt::format(
"\n - {<30} {}",
"target property set:",
fbIfTargetSet);
113 msg << fmt::format(
"\n - {<30} {}",
"material map creator set:",
bool(
fpMaterialMapFactory.get()));
126 boost::archive::binary_iarchive ia(ifs);
131 LOG(warn) <<
"kf::SetupBuilder::LoadMaterial: reference hash from input file \"" <<
fsMaterialCacheFile
133 "diverges from one, obtained from the actual detector setup geometry. Material budget will be "
134 "re-generated, and a new file will be created";
141 catch (
const std::exception& err) {
143 <<
"\" has inconsistent format "
144 "or was corrupted. The material maps will be re-generated";
147 LOG(info) <<
"kf::SetupBuilder::LoadMaterial: the material maps were loaded from cache file \"" <<
fsMaterialCacheFile
186 std::ofstream ofs(fileName, std::ios::binary);
188 std::stringstream msg;
189 msg <<
"kf::SetupBuilder::Store: failed opening file \"" << fileName <<
"\" to store the setup";
190 throw std::runtime_error(msg.str());
192 boost::archive::binary_oarchive oa(ofs);
202 std::stringstream msg;
203 msg <<
"kf::SetupBuilder::Store: failed opening cache file \"" <<
fsMaterialCacheFile <<
"\" to store the setup";
204 throw std::runtime_error(msg.str());
206 boost::archive::binary_oarchive oa(ofs);
A base KF-Setup initialization class (source)
void SetTarget(double x, double y, double z)
Sets target.
void Reset()
Resets the instance.
void AddSliceReference(double halfSizeX, double halfSizeY, double refZ)
Adds a slice reference.
A map of station thickness in units of radiation length (X0) to the specific point in XY plane.
void Reset()
Resets the instance.
void AddComponent(EDetID detId, int locId, double z)
Adds component info.
Creates a valid initialized Setup instance.
void Reset()
Resets the instance.
int fMatMapNofBins
Number of bins in material maps.
std::string fsMaterialCacheFile
A cache file for the material.
static constexpr double kTargetMaterialOffset
std::string InitStatusMsg() const
Prints initialization status message.
bool fbIfFieldFunctionSet
Field function initialized.
static constexpr double kTargetMaterialTransverseSizeMargin
std::set< GeoLayer< int > > fGeoLayers
Set of geo layers.
FieldFactory fFieldFactory
Instance of field factory.
ModuleIndexMapFactory fModuleIndexFactory
Module index factory.
Target< double > fTarget
Target properties.
bool fbIfGeoLayersInit
Geo layers initialized.
bool LoadMaterial()
Reads material from file.
void StoreMaterial() const
Stores material to file.
void Init()
Initializes, validates and caches the parameters.
void SetTargetProperty(double x, double y, double z, double dz, double r)
Sets target initialization properties.
static constexpr int kTargetMaterialMapNofBins
static constexpr double kTargetCenterOffset
std::vector< MaterialMap > fvMaterial
Material map container.
bool fbIfTargetSet
Target initialized.
bool fbReady
Instance is ready for setup generation.
static void Store(const Setup< double > &setup, const std::string &fileName)
Stores a serialized setup to a file.
std::shared_ptr< IMaterialMapFactory > fpMaterialMapFactory
Material map creator.
size_t fGeoHash
A hash of the geometry.
KF-framework representation of the detector setup.
void SetR(const T &r)
Sets target transverse size.
const T & GetDz() const
Gets target half-thickness.
const MaterialMap & GetMaterial() const
Gets material map.
void SetDz(const T &dz)
Sets target half-thickness.
void SetY(const T &y)
Sets y-coordinate of the nominal target center.
void SetZ(const T &z)
Sets x-coordinate of the nominal target center.
void SetMaterial(const MaterialMap &material)
Sets material map.
const T & GetR() const
Gets transverse size of target.
void SetX(const T &x)
Sets x-coordinate of the nominal target center.
const T & GetZ() const
Gets z-coordinate of the nominal target center.