Skip to content

Commit

Permalink
numpy histogram analogue
Browse files Browse the repository at this point in the history
  • Loading branch information
martinunland committed Aug 1, 2024
1 parent ad7b7a8 commit a1e7598
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 209 deletions.
2 changes: 1 addition & 1 deletion common/framework/include/OMSim.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public:
void initialiseSimulation(OMSimDetectorConstruction *pDetectorConstruction);
void configureLogger();
bool handleArguments(int pArgumentCount, char *pArgumentVector[]);
void startVisualisationIfRequested();
void startVisualisation();

G4Navigator *getNavigator() { return mNavigator.get(); };
void extendOptions(po::options_description pNewOptions);
Expand Down
28 changes: 17 additions & 11 deletions common/framework/include/OMSimTools.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@

#include "OMSimLogger.hh"
#include "globals.hh"

#include <variant>
/**
* @namespace Tools
* @brief A collection of helper functions for numerical operations.
*
* This namespace provides static methods for common numerical tasks such as
* loading data from a file, and generating linearly and logarithmically
* spaced sequences.
*
*
* This namespace provides static methods for common numerical tasks such as
* loading data from a file, and generating linearly and logarithmically
* spaced sequences.
*
* @ingroup common
*/
namespace Tools
{
std::vector<double> arange(double start, double stop, double step);
void ensureDirectoryExists(const std::string &filepath);
std::pair<std::vector<double>, std::vector<double>> histogram(
const std::vector<double> &data,
const std::variant<int, std::vector<double>> &bins = 10,
const std::optional<std::pair<double, double>> &range = std::nullopt);

G4String getThreadIDStr();
std::vector<std::vector<double>> loadtxt(const std::string &pFilePath,
bool pUnpack = true,
size_t pSkipRows = 0,
char pDelimiter = ' ');
std::vector<double> linspace(double start, double end, int num_points);
std::vector<double> logspace(double start, double end, int num_points);
bool pUnpack = true,
size_t pSkipRows = 0,
char pDelimiter = ' ');
std::vector<double> linspace(double start, double end, int num_points, bool endpoint = true);
std::vector<double> logspace(double start, double end, int num_points, double base = 10.0, bool endpoint = true);
void sortVectorByReference(std::vector<G4double> &referenceVector, std::vector<G4double> &sortVector);
};

Expand Down
20 changes: 8 additions & 12 deletions common/framework/src/OMSim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,17 @@ void OMSim::configureLogger()
/**
* @brief UIEx session is started for visualisation.
*/
void OMSim::startVisualisationIfRequested()
void OMSim::startVisualisation()
{
if (OMSimCommandArgsTable::getInstance().get<bool>("visual"))
{
OMSimUIinterface &lUIinterface = OMSimUIinterface::getInstance();
char lArg0[] = "all";
char *lArgv[] = {lArg0, NULL};
G4UIExecutive *UIEx = new G4UIExecutive(1, lArgv);
lUIinterface.applyCommand("/control/execute ../common/data/vis/init_vis.mac");
UIEx->SessionStart();
delete UIEx;
}
OMSimUIinterface &lUIinterface = OMSimUIinterface::getInstance();
char lArg0[] = "all";
char *lArgv[] = {lArg0, NULL};
G4UIExecutive *UIEx = new G4UIExecutive(1, lArgv);
lUIinterface.applyCommand("/control/execute ../common/data/vis/init_vis.mac");
UIEx->SessionStart();
delete UIEx;
}


int OMSim::determineNumberOfThreads()
{
int requestedThreads = OMSimCommandArgsTable::getInstance().get<int>("threads");
Expand Down
Loading

0 comments on commit a1e7598

Please sign in to comment.