90 TFile* outfile{
nullptr};
93 outfile =
new TFile(
m_filename.c_str(),
"RECREATE");
111 auto showProgress = [&]() {
113 const int64_t donePercent = 100 * ++curStep / nSteps;
114 if (donePercent > lastPercent) {
116 const double perStep = totalTime / curStep;
117 if (donePercent == 100) {
118 B2INFO(boost::format(
"BField %s Scan: %d samples, %.3f us per sample, total: %.2f seconds")
122 B2INFO(boost::format(
"BField %s Scan: %3d%%, %.3f us per sample")
126 lastPercent = donePercent;
130 struct {
float x{0}, y{0}, z{0}, bx{0}, by{0}, bz{0}; } field_point;
131 TTree* all_values{
nullptr};
133 all_values =
new TTree(
"bfield_values",
"All B field values");
134 all_values->Branch(
"x", &field_point.x,
"x/F");
135 all_values->Branch(
"y", &field_point.y,
"y/F");
136 all_values->Branch(
"z", &field_point.z,
"z/F");
137 all_values->Branch(
"bx", &field_point.bx,
"bx/F");
138 all_values->Branch(
"by", &field_point.by,
"by/F");
139 all_values->Branch(
"bz", &field_point.bz,
"bz/F");
141 auto fillTree = [&](
const ROOT::Math::XYZVector & p,
const ROOT::Math::XYZVector & b) {
142 if (!all_values)
return;
143 field_point.x = p.X();
144 field_point.y = p.Y();
145 field_point.z = p.Z();
146 field_point.bx = b.X();
147 field_point.by = b.Y();
148 field_point.bz = b.Z();
157 for (
int iU = 0; iU <
m_nU; ++iU) {
158 for (
int iV = 0; iV <
m_nV; ++iV) {
160 const double u = h_b->GetXaxis()->GetBinCenter(iU + 1);
161 const double v = h_b->GetYaxis()->GetBinCenter(iV + 1);
163 for (
int iPhi = 0; iPhi <
m_nPhi; ++iPhi) {
164 ROOT::Math::XYZVector pos(v, 0, u);
165 pos = ROOT::Math::VectorUtil::RotateZ(pos, 2 * M_PI * iPhi /
m_nPhi);
170 h_br->Fill(u, v, bfield.Rho());
171 h_bz->Fill(u, v, bfield.Z());
172 h_b->Fill(u, v, bfield.R());
173 fillTree(pos, bfield);
181 for (TH2D* h : {h_br, h_bz, h_b}) {
187 const std::string nu =
m_type.substr(0, 1);
188 const std::string nv =
m_type.substr(1, 1);
195 for (
int iU = 0; iU <
m_nU; ++iU) {
196 for (
int iV = 0; iV <
m_nV; ++iV) {
197 ROOT::Math::XYZVector pos(0, 0, 0);
199 const double u = h_bx->GetXaxis()->GetBinCenter(iU + 1);
200 const double v = h_bx->GetYaxis()->GetBinCenter(iV + 1);
215 pos = ROOT::Math::VectorUtil::RotateZ(pos,
m_phi);
220 h_bx->Fill(u, v, bfield.X());
221 h_by->Fill(u, v, bfield.Y());
222 h_bz->Fill(u, v, bfield.Z());
223 h_b->Fill(u, v, bfield.R());
224 fillTree(pos, bfield);
231 for (TH2D* h : {h_bx, h_by, h_bz, h_b}) {
237 if (all_values) all_values->Write();
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.