gfields
Loading...
Searching...
No Matches
gfield_asciimap.h
Go to the documentation of this file.
1#pragma once
2
3// gemc gfield framework
4#include "gfield.h"
5
6// c++
7#include <array>
8#include <string>
9#include <vector>
10
78
79public:
80 explicit GField_AsciiMapFactory(const std::shared_ptr<GOptions>& gopt) : GField(gopt) {}
81
83 void GetFieldValue(const double pos[3], G4double* bfield) const override;
84
87
88private:
90 enum class Symmetry {
91 dipole_x, dipole_y, dipole_z,
92 cyl_x, cyl_y, cyl_z,
93 phi_segmented,
94 cartesian_3d, cartesian_3d_quadrant
95 };
96
97 Symmetry symmetry = Symmetry::dipole_z;
98 int ndim = 2;
99 int ncomp = 1;
100 bool linear = true;
101
102 // Grid geometry in canonical per-symmetry axis order (see class documentation).
103 std::array<unsigned, 3> np = {0, 0, 0};
104 std::array<double, 3> startMap = {0.0, 0.0, 0.0};
105 std::array<double, 3> endMap = {0.0, 0.0, 0.0};
106 std::array<double, 3> cellSize = {1.0, 1.0, 1.0};
107
108 // One map-file column per grid coordinate, in file-column order (coordinate1, coordinate2, ...).
109 struct Column {
110 int axis = 0;
111 double unitFactor = 1.0;
112 };
113 std::vector<Column> columns;
114
115 // Field buffers (contiguous). B2/B3 stay empty for symmetries that do not use them.
116 std::vector<float> B1;
117 std::vector<float> B2;
118 std::vector<float> B3;
119
120 // Overall placement (lab frame). Origin in Geant4 length units, rotation in radians.
121 double mapOrigin[3] = {0.0, 0.0, 0.0};
122 double mapRotation[3] = {0.0, 0.0, 0.0};
123 double sinAlpha = 0.0, cosAlpha = 1.0; // about X
124 double sinBeta = 0.0, cosBeta = 1.0; // about Y
125 double sinGamma = 0.0, cosGamma = 1.0; // about Z
126
127 // Flat indexing helpers (canonical axis order).
128 inline std::size_t idx2(unsigned i0, unsigned i1) const { return static_cast<std::size_t>(i0) * np[1] + i1; }
129 inline std::size_t idx3(unsigned i0, unsigned i1, unsigned i2) const {
130 return (static_cast<std::size_t>(i0) * np[1] + i1) * np[2] + i2;
131 }
132
133 // Per-symmetry field evaluation (point already shifted by mapOrigin).
134 void value_dipole(const double x[3], double* bfield) const;
135 void value_cylindrical(const double x[3], double* bfield) const;
136 void value_phi_segmented(const double x[3], double* bfield) const;
137 void value_cartesian3d(const double x[3], double* bfield) const;
138
139 // Rotate the field vector (not the point): each rotation is the inverse of the point rotation.
140 void rotate_field(double* bfield) const;
141
142 // Configuration helpers (the generic node only guarantees name/type).
143 std::string param_string(const std::string& key, const std::string& dflt) const;
144 double param_g4number(const std::string& key, const std::string& dflt) const;
145
146 // Map the canonical axis of a coordinate name for the current symmetry, or -1 if it does not belong.
147 int axis_of_coordinate(const std::string& name) const;
148
149 // Parse one "name, npoints, min, max" coordinate string into the grid arrays and a Column.
150 void load_coordinate(const std::string& key);
151
152 // Read the map file and fill the field buffers.
153 void load_map_file();
154
155 // Default field-map directory: <plugin_dir>/../fields (the `meson install` layout). No env var.
156 std::string field_maps_directory() const;
157};
Concrete GField reading a magnetic field from an ASCII map and a YAML definition.
GField_AsciiMapFactory(const std::shared_ptr< GOptions > &gopt)
void load_field_definitions(GFieldDefinition gfd) override
Parse the YAML definition, build the grid and read the map file.
void GetFieldValue(const double pos[3], G4double *bfield) const override
Compute the field at the lab-frame point pos, writing {Bx,By,Bz} (Geant4 units) into bfield.
Abstract base class representing a magnetic field.
Definition gfield.h:105
Lightweight configuration carrier used to load and configure a GField plugin.
Definition gfield.h:27