Skip to content

Commit 4297373

Browse files
committed
doxygen docs for g4system, g4dialog
1 parent cd4db7d commit 4297373

56 files changed

Lines changed: 3525 additions & 2362 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ci/create_doxygen.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ OUTPUT_DIRECTORY = ../pages
138138
HTML_OUTPUT = $mod
139139
GENERATE_TAGFILE = ../pages/$mod/$mod.tag
140140
HTML_EXTRA_STYLESHEET = mydoxygen.css
141+
EXCLUDE_PATTERNS += CADMesh.hh
141142
142143
# TAGFILES is injected by ci/doxygen.sh in pass 2
143144
EOF

ci/generate_html.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
modules_map = {
77
"base": "guts goptions glogging gbase textProgressBar utilities",
8-
"plugins": "gfactory gdynamicDigitization gsd",
9-
"hits": "gtouchable ghit",
8+
"plugins": "gfactory gdynamicDigitization gsd gfields",
9+
"sensitivity": "gtouchable ghit",
1010
"gui": "gboard gqtbuttonswidget g4display g4dialog gsplash gtree dbselect gui",
1111
"detector": "gsystem g4system gdetector gtranslationTable",
1212
"i/o": "gdata gstreamer eventDispenser",
13-
"geant4": "gparticle gphysics gfields actions",
13+
"geant4": "gparticle gphysics actions",
1414
}
1515

1616
# Path to the directory containing subdirectories with Doxygen documentation

eventDispenser/eventDispenser.cc

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
1-
/**
2-
* \file eventDispenser.cc
3-
* \brief Implements the EventDispenser class which distributes events among runs.
4-
*
5-
* \mainpage Event Dispenser Module
6-
*
7-
* \section intro_sec Introduction
8-
* The Event Dispenser module is responsible for distributing simulation events
9-
* among different runs based on a user–defined weighting scheme. It reads run weight
10-
* information from a file (if provided) or uses options provided via GOptions. It then
11-
* randomly assigns events to runs and executes them using Geant4 commands.
12-
*
13-
* \section details_sec Details
14-
* The module initializes the run weight maps, distributes events randomly based on the weights,
15-
* and processes events by calling Geant4 UI commands (e.g., /run/beamOn). The class also logs
16-
* progress and summary information.
17-
*
18-
* \section usage_sec Usage
19-
* To use the EventDispenser, instantiate it with a pointer to GOptions and a global map of
20-
* GDynamicDigitization plugins. Call processEvents() to run the events.
21-
*
22-
* \author Your Name
23-
* \date YYYY-MM-DD
24-
*/
1+
// Implements EventDispenser: run-weight parsing, event distribution, and per-run dispatch through Geant4.
2+
//
3+
// Doxygen documentation for the public API is maintained in eventDispenser.h.
4+
// This implementation file keeps only short, non-Doxygen summaries and inline clarifying comments.
255

266
#include "eventDispenserConventions.h"
277
#include "eventDispenser_options.h"
288
#include "eventDispenser.h"
299
#include "gdynamicdigitizationConventions.h"
3010

31-
3211
// c++
3312
#include <fstream>
3413
#include <random>
@@ -39,73 +18,81 @@
3918

4019
using namespace std;
4120

42-
//
43-
// Constructor: Initializes the EventDispenser using options from GOptions and a pointer to the global
44-
// GDynamicDigitization plugins map.
45-
//
46-
EventDispenser::EventDispenser(const std::shared_ptr<GOptions>& gopt, const std::shared_ptr<const gdynamicdigitization::dRoutinesMap>& gdynamicDigitizationMap)
21+
// Constructor summary:
22+
// - Reads configuration (number of events, run number, optional run-weight file).
23+
// - Builds runWeights/runEvents/listOfRuns when weights are provided.
24+
// - Otherwise, falls back to single-run mode.
25+
EventDispenser::EventDispenser(const std::shared_ptr<GOptions>& gopt,
26+
const std::shared_ptr<const gdynamicdigitization::dRoutinesMap>& gdynamicDigitizationMap)
4727
: GBase(gopt, EVENTDISPENSER_LOGGER), gDigitizationMap(gdynamicDigitizationMap) {
48-
4928
// Retrieve configuration parameters from GOptions.
5029
string filename = gopt->getScalarString("run_weights");
5130
userRunno = gopt->getScalarInt("run");
5231
neventsToProcess = gopt->getScalarInt("n");
5332

54-
// If there are no events to process, nothing more to do.
33+
// If there are no events to process, keep the object in an initialized-but-idle state.
5534
if (neventsToProcess == 0) return;
5635

57-
// If no file is provided, use the user-specified run number.
36+
// If no file is provided, use the user-specified run number (single-run mode).
5837
if (filename == UNINITIALIZEDSTRINGQUANTITY && neventsToProcess > 0) {
59-
// Only one run is defined via the option.
6038
runEvents[userRunno] = neventsToProcess;
6139
return;
6240
}
6341
else {
64-
// A filename was specified; attempt to open the run weights input file.
42+
// Multi-run mode: a filename was specified; attempt to open the run weights input file.
6543
ifstream in(filename.c_str());
66-
if (!in) { log->error(ERR_EVENTDISTRIBUTIONFILENOTFOUND, "Error: can't open run weights input file >", filename, "<. Check your spelling. Exiting."); }
44+
if (!in) {
45+
// Keep behavior unchanged: log error and continue with an empty distribution.
46+
log->error(ERR_EVENTDISTRIBUTIONFILENOTFOUND,
47+
"Error: can't open run weights input file >", filename, "<. Check your spelling. Exiting.");
48+
}
6749
else {
6850
log->info(1, "Loading run weights from ", filename);
69-
// Fill the run weight map by reading each line from the file.
51+
52+
// Read "run weight" pairs, one per line.
53+
// The order of insertion into listOfRuns reflects the file order and may be used by clients.
7054
int run;
7155
double weight;
72-
// Use a robust loop to read pairs from the file.
7356
while (in >> run >> weight) {
7457
listOfRuns.push_back(run);
7558
runWeights[run] = weight;
76-
runEvents[run] = 0;
59+
runEvents[run] = 0; // initialize per-run counters before distribution
7760
}
78-
// Distribute the total number of events among the runs according to the weights.
61+
62+
// Distribute the total number of events among runs according to their weights.
7963
distributeEvents(neventsToProcess);
8064
}
8165
in.close();
8266

83-
// Log summary information.
84-
log->info(0, "EventDispenser initialized with ", neventsToProcess, " events distributed among ", runWeights.size(), " runs:");
67+
// Log summary information: overall distribution table.
68+
log->info(0, "EventDispenser initialized with ", neventsToProcess, " events distributed among ",
69+
runWeights.size(), " runs:");
8570
log->info(0, " run\t weight\t n. events");
86-
for (const auto& weight : runWeights) { log->info(0, " ", weight.first, "\t ", weight.second, "\t ", runEvents[weight.first]); }
71+
for (const auto& weight : runWeights) {
72+
log->info(0, " ", weight.first, "\t ", weight.second, "\t ", runEvents[weight.first]);
73+
}
8774
}
8875
}
8976

9077

91-
// Sets the total number of events to process. Clears previous run events and assigns all events to the user run.
78+
// setNumberOfEvents summary:
79+
// - Clears any existing distribution and assigns all events to the user-selected run number.
9280
void EventDispenser::setNumberOfEvents(int nevents_to_process) {
9381
runEvents.clear();
9482
runEvents[userRunno] = nevents_to_process;
9583
}
9684

9785

98-
// Randomly distributes events among runs according to the weights read from the input file.
86+
// distributeEvents summary:
87+
// - Performs stochastic sampling to convert runWeights into integer runEvents counts.
9988
void EventDispenser::distributeEvents(int nevents_to_process) {
100-
// Initialize a progress bar for visual feedback.
101-
// TextProgressBar bar(50, string(EVENTDISPENSERLOGMSGITEM) + " Distributing events according to run weights ", 0, nevents_to_process);
102-
103-
// Set up a random number generator.
89+
// Set up a random number generator drawing from U[0, 1].
10490
random_device randomDevice;
10591
mt19937 generator(randomDevice());
10692
uniform_real_distribution<> randomDistribution(0, 1);
10793

108-
// Loop over each event and assign it to a run based on the cumulative weight.
94+
// For each event, select a run by comparing a random draw to the cumulative weight intervals.
95+
// This assumes runWeights values represent fractions or relative weights normalized to sum to 1.
10996
for (int i = 0; i < nevents_to_process; i++) {
11097
double randomNumber = randomDistribution(generator);
11198

@@ -117,59 +104,61 @@ void EventDispenser::distributeEvents(int nevents_to_process) {
117104
break;
118105
}
119106
}
120-
// bar.setProgress(i);
121107
}
122108
}
123109

124110

125-
// Sums the number of events assigned to all runs.
111+
// getTotalNumberOfEvents summary:
112+
// - Sums all per-run event counts from runEvents.
126113
int EventDispenser::getTotalNumberOfEvents() const {
127114
int totalEvents = 0;
128115
for (auto rEvents : runEvents) { totalEvents += rEvents.second; }
129116
return totalEvents;
130117
}
131118

132119

133-
// Processes events by iterating over runs, initializing plugins, and executing Geant4 commands.
120+
// processEvents summary:
121+
// - Iterates the run allocation.
122+
// - For each run, loads run-dependent constants/TT via digitization routines (if run changed).
123+
// - Dispatches the events to Geant4 via \c /run/beamOn.
134124
int EventDispenser::processEvents() {
135-
// Get the Geant4 UI manager pointer.
125+
// Get the Geant4 UI manager pointer used to apply macro commands.
136126
G4UImanager* g4uim = G4UImanager::GetUIpointer();
137127

138-
// Set the progress print command based on the elog level.
139-
// g4uim->ApplyCommand("/run/printProgress " + to_string(elog));
140-
141128
// Iterate over each run in the run events map.
142129
for (auto& run : runEvents) {
143130
int runNumber = run.first;
144131
int nevents = run.second;
145132

146-
// Load constants and translation table if the run number has changed.
133+
// Load constants and translation tables if the run number has changed.
147134
if (runNumber != currentRunno) {
148-
// read-only loop over the map of shared pointers to GDynamicDigitization
149-
// plugin is a const std::string&
150-
// routine is a std::shared_ptr<GDynamicDigitization>
151-
// *dmap dereferences the shared_ptr to access the underlying const std::unordered_map.
135+
// Iterate the (plugin name -> digitization routine) map.
136+
// digiRoutine is a std::shared_ptr<GDynamicDigitization>.
152137
for (const auto& [plugin, digiRoutine] : *gDigitizationMap) {
153138
log->debug(NORMAL, FUNCTION_NAME, "Calling ", plugin, " loadConstants for run ", runNumber);
154139
if (digiRoutine->loadConstants(runNumber, variation) == false) {
155-
log->error(ERR_LOADCONSTANTFAIL, "Failed to load constants for ", plugin, " for run ", runNumber, " with variation ", variation);
140+
log->error(ERR_LOADCONSTANTFAIL,
141+
"Failed to load constants for ", plugin, " for run ", runNumber, " with variation ",
142+
variation);
156143
}
157144

158145
log->debug(NORMAL, FUNCTION_NAME, "Calling ", plugin, " loadTT for run ", runNumber);
159146
if (digiRoutine->loadTT(runNumber, variation) == false) {
160-
log->error(ERR_LOADTTFAIL, "Failed to load translation table for ", plugin, " for run ", runNumber, " with variation ", variation);
147+
log->error(ERR_LOADTTFAIL,
148+
"Failed to load translation table for ", plugin, " for run ", runNumber,
149+
" with variation ", variation);
161150
}
162151
}
163152
currentRunno = runNumber;
164153
}
165154

166155
log->info(1, "Starting run ", runNumber, " with ", nevents, " events.");
167156

168-
// If events are fewer than the buffer size, process all in one go.
157+
// Dispatch all events for this run in a single call.
158+
// The command string is a standard Geant4 UI command: \c /run/beamOn <N>.
169159
log->info(1, "Processing ", nevents, " events in one go");
170160
g4uim->ApplyCommand("/run/beamOn " + to_string(nevents));
171161

172-
173162
log->info(1, "Run ", runNumber, " done with ", nevents, " events");
174163
}
175164

0 commit comments

Comments
 (0)