16 #define NSAMPLES 1000000
18 int main (
int argc,
char* argv[])
30 "Convert field map from ASCII to binary");
33 "Time magnetic field reading routines");
43 std::string mapname = mapfile.substr(0,mapfile.find_last_of(
"."));
45 timeval time_start, time_finish;
49 gettimeofday(&time_start, 0);
51 gettimeofday(&time_finish, 0);
53 int time_initialize_sec = ((int) time_finish.tv_sec - (
int) time_start.tv_sec);
54 int time_initialize_usec = ((int) time_finish.tv_usec - (
int) time_start.tv_usec);
55 if (time_initialize_usec < 0) { time_initialize_usec += 1000000; time_initialize_sec--; }
57 << time_initialize_sec <<
" sec and "
72 int time_sampling_sec;
73 int time_sampling_usec;
84 gettimeofday(&time_start, 0);
87 gettimeofday(&time_finish, 0);
89 int time_reading_sec = ((int) time_finish.tv_sec - (
int) time_start.tv_sec);
90 int time_reading_usec = ((int) time_finish.tv_usec - (
int) time_start.tv_usec);
91 if (time_reading_usec < 0) { time_reading_usec += 1000000; time_reading_sec--; }
93 << time_reading_sec <<
" sec and "
98 <<
"is " << field[0]/
Qw::kG <<
"," << field[1]/
Qw::kG <<
"," << field[2]/
Qw::kG <<
" kG"
105 gettimeofday(&time_start, 0);
107 gettimeofday(&time_finish, 0);
109 int time_writing_sec = ((int) time_finish.tv_sec - (
int) time_start.tv_sec);
110 int time_writing_usec = ((int) time_finish.tv_usec - (
int) time_start.tv_usec);
111 if (time_writing_usec < 0) { time_writing_usec += 1000000; time_writing_sec--; }
112 QwMessage <<
"Writing field map (binary): "
113 << time_writing_sec <<
" sec and "
118 gettimeofday(&time_start, 0);
119 delete magneticfield;
120 gettimeofday(&time_finish, 0);
122 int time_destruction_sec = ((int) time_finish.tv_sec - (
int) time_start.tv_sec);
123 int time_destruction_usec = ((int) time_finish.tv_usec - (
int) time_start.tv_usec);
124 if (time_destruction_usec < 0) { time_destruction_usec += 1000000; time_destruction_sec--; }
126 << time_destruction_sec <<
" sec and "
127 << time_destruction_usec <<
" usec" <<
QwLog::endl;
131 gettimeofday(&time_start, 0);
133 gettimeofday(&time_finish, 0);
135 int time_initialize2_sec = ((int) time_finish.tv_sec - (
int) time_start.tv_sec);
136 int time_initialize2_usec = ((int) time_finish.tv_usec - (
int) time_start.tv_usec);
137 if (time_initialize2_usec < 0) { time_initialize2_usec += 1000000; time_initialize2_sec--; }
139 << time_initialize2_sec <<
" sec and "
140 << time_initialize2_usec <<
" usec" <<
QwLog::endl;
144 gettimeofday(&time_start, 0);
147 gettimeofday(&time_finish, 0);
149 int time_reading2_sec = ((int) time_finish.tv_sec - (
int) time_start.tv_sec);
150 int time_reading2_usec = ((int) time_finish.tv_usec - (
int) time_start.tv_usec);
151 if (time_reading2_usec < 0) { time_reading2_usec += 1000000; time_reading2_sec--; }
152 QwMessage <<
"Reading field map (binary): "
153 << time_reading2_sec <<
" sec and "
161 QwMessage <<
"Interpolation method set to multilinear, method "
166 <<
"is " << field[0]/
Qw::kG <<
"," << field[1]/
Qw::kG <<
"," << field[2]/
Qw::kG <<
" kG"
170 gettimeofday(&time_start, 0);
172 for (
int i = 0; i <
NSAMPLES; i++) {
173 rpoint[0] = point[0] + random.Gaus(mean,sigma);
174 rpoint[1] = point[1] + random.Gaus(mean,sigma);
175 rpoint[2] = point[2] + random.Gaus(mean,sigma);
178 gettimeofday(&time_finish, 0);
179 time_sampling_sec = ((int) time_finish.tv_sec - (
int) time_start.tv_sec);
180 time_sampling_usec = ((int) time_finish.tv_usec - (
int) time_start.tv_usec);
181 if (time_sampling_usec < 0) { time_sampling_usec += 1000000; time_sampling_sec--; }
182 time_sampling = 1000000 * time_sampling_sec + time_sampling_usec;
183 QwMessage <<
"Sampling (total of " << NSAMPLES <<
" samples): "
184 << time_sampling_sec <<
" sec and "
191 QwMessage <<
"Interpolation method set to nearest-neighbor, method "
196 <<
"is " << field[0]/
Qw::kG <<
"," << field[1]/
Qw::kG <<
"," << field[2]/
Qw::kG <<
" kG"
200 gettimeofday(&time_start, 0);
202 for (
int i = 0; i <
NSAMPLES; i++) {
203 rpoint[0] = point[0] + random.Gaus(mean,sigma);
204 rpoint[1] = point[1] + random.Gaus(mean,sigma);
205 rpoint[2] = point[2] + random.Gaus(mean,sigma);
208 gettimeofday(&time_finish, 0);
209 time_sampling_sec = ((int) time_finish.tv_sec - (
int) time_start.tv_sec);
210 time_sampling_usec = ((int) time_finish.tv_usec - (
int) time_start.tv_usec);
211 if (time_sampling_usec < 0) { time_sampling_usec += 1000000; time_sampling_sec--; }
212 time_sampling = 1000000 * time_sampling_sec + time_sampling_usec;
213 QwMessage <<
"Sampling (total of " << NSAMPLES <<
" samples): "
214 << time_sampling_sec <<
" sec and "
220 delete magneticfield;
#define QwMessage
Predefined log drain for regular messages.
static void AppendToSearchPath(const TString &searchdir)
Add a directory to the search path.
Magnetic field map object.
#define default_bool_value(b)
void SetFilename(const std::string &filename)
Set the filename.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
T GetValue(const std::string &key)
Get a templated value.
void SetInterpolationMethod(const EQwInterpolationMethod method)
Set interpolation method.
void GetCartesianFieldValue(const double point_xyz[3], double field_xyz[3]) const
Get the cartesian components of the field value.
A logfile class, based on an identical class in the Hermes analyzer.
static std::ostream & endl(std::ostream &)
End of the line.
const std::string getenv_safe_string(const char *name)
An options class which parses command line, config file and environment.
static void DefineOptions(QwOptions &options)
Define command line and config file options.
bool WriteBinaryFile(const std::string &fieldmap) const
Write a binary field map.
EQwInterpolationMethod GetInterpolationMethod() const
Get interpolation method.
int main(int argc, char **argv)
void SetCommandLine(int argc, char *argv[], bool default_config_file=true)
Set the command line arguments.
static const double cm
Length units: base unit is mm.
bool ReadFieldMap()
Read a field map.