Skip to content

Commit 7929ed4

Browse files
committed
new option for global field
1 parent 6cca221 commit 7929ed4

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

gemc/gdetector/gdetectorConstruction.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ void GDetectorConstruction::ConstructSDandField() {
211211
}
212212
}
213213

214+
// Process the global field, if requested.
215+
// A global field is associated with the ROOT world volume and propagated to all daughters, so it
216+
// applies everywhere a more specific per-volume field has not been installed.
217+
const auto global_field_name = gopt->getScalarString(GLOBAL_FIELD_OPTION);
218+
if (global_field_name != "" && global_field_name != UNINITIALIZEDSTRINGQUANTITY) {
219+
if (gmagneto == nullptr) { gmagneto = new GMagneto(gopt); }
220+
log->info(2, "Setting global field manager for the ROOT world volume <", ROOTWORLDGVOLUMENAME,
221+
"> with field <", global_field_name, ">");
222+
g4world->setFieldManagerForVolume(ROOTWORLDGVOLUMENAME,
223+
gmagneto->getFieldMgr(global_field_name).get(), true);
224+
}
225+
214226
// Load digitization plugins only when geometry has changed and only on the master thread.
215227
// digiplugins_need_reload is set true by reload_geometry() and prepare_geometry_for_run()
216228
// so that routine BeamOn re-initializations (which also call ConstructSDandField() on the

gemc/gdetector/gdetector_options.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "g4system_options.h"
44
#include "gdynamicdigitization_options.h"
55
#include "gsd.h"
6+
#include "gfield_options.h"
67

78
/**
89
* \file gdetector_options.cc
@@ -35,6 +36,10 @@ GOptions defineOptions() {
3536
goptions += gdynamicdigitization::defineOptions();
3637
goptions += gsensitivedetector::defineOptions();
3738

39+
// Field options are consumed by GDetectorConstruction (per-volume emfield and the
40+
// global_field association on the ROOT world volume), so they must be defined here too.
41+
goptions += gfields::defineOptions();
42+
3843
return goptions;
3944
}
4045
}

gemc/gfields/gfieldConventions.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636
*/
3737
#define GFIELD_DEFAULT_VERBOSITY "0"
3838

39+
/**
40+
* \brief Command-line option name used to associate a field with the ROOT world volume.
41+
*
42+
* The value is the name of a configured field (see \c gmultipoles / \c gfields). The corresponding
43+
* \c G4FieldManager is installed on the ROOT world volume and propagated to all daughters, acting as a
44+
* global field wherever a more specific per-volume field is not set.
45+
*/
46+
#define GLOBAL_FIELD_OPTION "global_field"
47+
3948

4049
// Error codes in the 1200 range (module-local).
4150
#define ERR_WRONG_FIELD_ROTATION 1201

gemc/gfields/gfield_options.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ GOptions defineOptions() {
231231
};
232232
goptions.defineOption("gfields", "define a generic plugin-backed e.m. field", gfields, gfields_help);
233233

234+
goptions.defineOption(
235+
GVariable(GLOBAL_FIELD_OPTION, UNINITIALIZEDSTRINGQUANTITY, "associate a field with the ROOT world volume"),
236+
"Associates a configured electromagnetic field with the ROOT (top-level) world volume.\n \n"
237+
"The value must be the name of a field defined with -gmultipoles or -gfields. The field's\n"
238+
"G4FieldManager is installed on the ROOT world volume and propagated to all daughters, so it\n"
239+
"applies everywhere a more specific per-volume field has not been set.\n \n"
240+
"Example: -global_field=dipole1\n \n");
241+
234242
goptions.defineOption(
235243
GVariable("fieldAt", UNINITIALIZEDSTRINGQUANTITY, "query all configured fields at x y z"),
236244
"Evaluate all configured electromagnetic fields at one absolute coordinate.\n \n"

0 commit comments

Comments
 (0)