Skip to content

Commit

Permalink
updated nomenclature
Browse files Browse the repository at this point in the history
  • Loading branch information
martinunland committed Aug 29, 2024
1 parent 2fe535b commit d9178f1
Show file tree
Hide file tree
Showing 56 changed files with 1,016 additions and 1,227 deletions.
12 changes: 7 additions & 5 deletions common/framework/src/OMSim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ int OMSim::determineNumberOfThreads()
void OMSim::initialiseSimulation(OMSimDetectorConstruction* p_detectorConstruction)
{
OMSimHitManager::init();
configureLogger();

OMSimCommandArgsTable &args = OMSimCommandArgsTable::getInstance();
Tools::ensureDirectoryExists(args.get<std::string>("output_file"));
Expand Down Expand Up @@ -165,7 +164,7 @@ void OMSim::initialiseSimulation(OMSimDetectorConstruction* p_detectorConstructi
OMSimUIinterface &uiInterface = OMSimUIinterface::getInstance();
uiInterface.setUI(G4UImanager::GetUIpointer());

m_navigator.get()->SetWorldVolume(p_detectorConstruction->mWorldPhysical);
m_navigator.get()->SetWorldVolume(p_detectorConstruction->m_worldPhysical);
m_navigator.get()->LocateGlobalPointAndSetup(G4ThreeVector(0., 0., 0.));

m_history = std::unique_ptr<G4TouchableHistory>(m_navigator->CreateTouchableHistory());
Expand Down Expand Up @@ -233,6 +232,9 @@ bool OMSim::handleArguments(int p_argumentCount, char *p_argumentVector[])

//If no help needed continue and set arguments to arg table
setUserArgumentsToArgTable(variableMap);

//now we know the log level, lets configure the logger as intended
configureLogger();
return true;
}

Expand Down Expand Up @@ -266,7 +268,7 @@ OMSim::~OMSim()
OMSimUIinterface::shutdown();

log_trace("OMSim destructor finished");
std::chrono::high_resolution_clock::time_point lFinishtime = std::chrono::high_resolution_clock::now();
const std::chrono::duration<double> lDiff = lFinishtime - m_startingTime;
log_info("Computation time: {} {}", lDiff.count(), " seconds.");
std::chrono::high_resolution_clock::time_point finishTime = std::chrono::high_resolution_clock::now();
const std::chrono::duration<double> deltaT = finishTime - m_startingTime;
log_info("Computation time: {} {}", deltaT.count(), " seconds.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public:
void ConstructSDandField() override;
void registerSensitiveDetector(G4LogicalVolume* logVol, G4VSensitiveDetector* aSD);

G4VPhysicalVolume *mWorldPhysical;
G4VPhysicalVolume *m_worldPhysical;

protected:
virtual void constructWorld() = 0;
Expand Down
4 changes: 2 additions & 2 deletions common/geometry_construction/src/OMSimDetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "G4SDManager.hh"

OMSimDetectorConstruction::OMSimDetectorConstruction()
: m_worldSolid(0), m_worldLogical(0), mWorldPhysical(0)
: m_worldSolid(0), m_worldLogical(0), m_worldPhysical(0)
{
OMSimInputData::init();
m_data = &OMSimInputData::getInstance();
Expand All @@ -35,7 +35,7 @@ G4VPhysicalVolume *OMSimDetectorConstruction::Construct()
log_trace("Starting detector construction");
constructWorld();
constructDetector();
return mWorldPhysical;
return m_worldPhysical;
}

void OMSimDetectorConstruction::ConstructSDandField()
Expand Down
64 changes: 32 additions & 32 deletions simulations/effective_area/OMSim_effective_area.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,52 @@
#include "OMSimTools.hh"

std::shared_ptr<spdlog::logger> g_logger;

namespace po = boost::program_options;

void runEffectiveAreaSimulation()
{
OMSimEffectiveAreaAnalyisis lAnalysisManager;
OMSimCommandArgsTable &lArgs = OMSimCommandArgsTable::getInstance();
OMSimHitManager &lHitManager = OMSimHitManager::getInstance();
AngularScan *lScanner = new AngularScan(lArgs.get<G4double>("radius"), lArgs.get<G4double>("distance"), lArgs.get<G4double>("wavelength"));
OMSimEffectiveAreaAnalyisis analysisManager;
OMSimCommandArgsTable &args = OMSimCommandArgsTable::getInstance();
OMSimHitManager &hitManager = OMSimHitManager::getInstance();
AngularScan *scanner = new AngularScan(args.get<G4double>("radius"), args.get<G4double>("distance"), args.get<G4double>("wavelength"));

lAnalysisManager.mOutputFileName = lArgs.get<std::string>("output_file") + ".dat";
analysisManager.m_outputFileName = args.get<std::string>("output_file") + ".dat";

bool lWriteHeader = !lArgs.get<bool>("no_header");
if (lWriteHeader) lAnalysisManager.writeHeader("Phi", "Theta", "Wavelength");
bool writeHeader = !args.get<bool>("no_header");
if (writeHeader) analysisManager.writeHeader("Phi", "Theta", "Wavelength");

// If angle file is provided, run over all angle pairs in file
if (lArgs.keyExists("angles_file"))
if (args.keyExists("angles_file"))
{
std::vector<G4PV2DDataVector> data = Tools::loadtxt(lArgs.get<std::string>("angles_file"), true);
std::vector<G4double> lThetas = data.at(0);
std::vector<G4double> lPhis = data.at(1);
std::vector<G4PV2DDataVector> data = Tools::loadtxt(args.get<std::string>("angles_file"), true);
std::vector<G4double> thetas = data.at(0);
std::vector<G4double> phis = data.at(1);

for (std::vector<int>::size_type i = 0; i != lThetas.size(); i++)
for (std::vector<int>::size_type i = 0; i != thetas.size(); i++)
{
lScanner->runSingleAngularScan(lPhis.at(i), lThetas.at(i));
lAnalysisManager.writeScan(lPhis.at(i), lThetas.at(i), lArgs.get<G4double>("wavelength"));
lHitManager.reset();
scanner->runSingleAngularScan(phis.at(i), thetas.at(i));
analysisManager.writeScan(phis.at(i), thetas.at(i), args.get<G4double>("wavelength"));
hitManager.reset();
}
}
// If file with angle pairs was not provided, use the angle pairs provided through command-line arguments
else
{
lScanner->runSingleAngularScan(lArgs.get<G4double>("phi"), lArgs.get<G4double>("theta"));
lAnalysisManager.writeScan(lArgs.get<G4double>("phi"), lArgs.get<G4double>("theta"), lArgs.get<G4double>("wavelength"));
lHitManager.reset();
scanner->runSingleAngularScan(args.get<G4double>("phi"), args.get<G4double>("theta"));
analysisManager.writeScan(args.get<G4double>("phi"), args.get<G4double>("theta"), args.get<G4double>("wavelength"));
hitManager.reset();
}
}

/**
* @brief Add options for the user input arguments for the effective area module
*/
void addModuleOptions(OMSim* pSimulation)
void addModuleOptions(OMSim* p_simulation)
{
po::options_description lSpecific("Effective area specific arguments");
po::options_description effectiveAreaOptions("Effective area specific arguments");

// Do not use G4String as type here...
lSpecific.add_options()
effectiveAreaOptions.add_options()
("world_radius,w", po::value<G4double>()->default_value(3.0), "radius of world sphere in m")
("radius,r", po::value<G4double>()->default_value(300.0), "plane wave radius in mm")
("distance,d", po::value<G4double>()->default_value(2000), "plane wave distance from origin, in mm")
Expand All @@ -67,25 +66,26 @@ void addModuleOptions(OMSim* pSimulation)
("angles_file,i", po::value<std::string>(), "The input angle pairs file to be scanned. The file should contain two columns, the first column with the theta (zenith) and the second with phi (azimuth) in degrees.")
("no_header", po::bool_switch(), "if given, the header of the output file will not be written");

pSimulation->extendOptions(lSpecific);
p_simulation->extendOptions(effectiveAreaOptions);
}

int main(int pArgumentCount, char *pArgumentVector[])
int main(int p_argCount, char *p_argumentVector[])
{

OMSim lSimulation;
addModuleOptions(&lSimulation);
bool lContinue = lSimulation.handleArguments(pArgumentCount, pArgumentVector);
if (!lContinue)
OMSim simulation;
addModuleOptions(&simulation);
bool successful = simulation.handleArguments(p_argCount, p_argumentVector);
if (!successful)
return 0;

std::unique_ptr<OMSimEffectiveAreaDetector> lDetectorConstruction = std::make_unique<OMSimEffectiveAreaDetector>();
lSimulation.initialiseSimulation(lDetectorConstruction.get());
lDetectorConstruction.release();
std::unique_ptr<OMSimEffectiveAreaDetector> detectorConstruction = std::make_unique<OMSimEffectiveAreaDetector>();
simulation.initialiseSimulation(detectorConstruction.get());
detectorConstruction.release();

runEffectiveAreaSimulation();

if (OMSimCommandArgsTable::getInstance().get<bool>("visual"))
lSimulation.startVisualisation();
simulation.startVisualisation();

return 0;
}
12 changes: 5 additions & 7 deletions simulations/effective_area/include/OMSimAngularScan.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* @ingroup EffectiveArea
*/

#ifndef OMSimAngularScan_h
#define OMSimAngularScan_h 1
#pragma once

#include "globals.hh"
/**
Expand Down Expand Up @@ -33,11 +32,10 @@ private:

void configurePosCoordinates();
void configureAngCoordinates();
G4double mBeamRadius;
G4double mBeamDistance;
G4double m_beamRadius;
G4double m_beamDistance;
G4double m_wavelength;
G4double mTheta;
G4double mPhi;
G4double m_theta;
G4double m_phi;
};

#endif
55 changes: 26 additions & 29 deletions simulations/effective_area/include/OMSimEffectiveAreaAnalyisis.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* @brief Defines the OMSimEffectiveAreaAnalyisis class for calculating effective area and writing results to output file.
* @ingroup EffectiveArea
*/
#ifndef OMSimAngularAnalysis_h
#define OMSimAngularAnalysis_h 1
#pragma once

#include "OMSimPMTResponse.hh"
#include "OMSimHitManager.hh"
Expand Down Expand Up @@ -33,61 +32,59 @@ public:
~OMSimEffectiveAreaAnalyisis(){};

template <typename... Args>
void writeScan(Args... args);
void writeScan(Args... p_args);
template <typename... Args>
void writeHeader(Args... args);
void writeHeader(Args... p_args);

effectiveAreaResult calculateEffectiveArea(double pHits);
G4String mOutputFileName;
effectiveAreaResult calculateEffectiveArea(double p_hits);
G4String m_outputFileName;
};

/**
* @brief Writes a scan result to the output file.
* @param args The values to be written to the output file.
* @param p_args The values to be written to the output file.
*/
template <typename... Args>
void OMSimEffectiveAreaAnalyisis::writeScan(Args... args)
void OMSimEffectiveAreaAnalyisis::writeScan(Args... p_args)
{
std::vector<double> lHits = OMSimHitManager::getInstance().countMergedHits();
std::vector<double> hits = OMSimHitManager::getInstance().countMergedHits();

std::fstream lDataFile;
lDataFile.open(mOutputFileName.c_str(), std::ios::out | std::ios::app);
std::fstream dataFile;
dataFile.open(m_outputFileName.c_str(), std::ios::out | std::ios::app);

// Write all arguments to the file
((lDataFile << args << "\t"), ...);
((dataFile << p_args << "\t"), ...);

G4double lTotalHits = 0;
for (const auto &hit : lHits)
G4double totalHits = 0;
for (const auto &hit : hits)
{
lDataFile << hit << "\t";
lTotalHits = hit; // last element is total nr of hits
dataFile << hit << "\t";
totalHits = hit; // last element is total nr of hits
}

effectiveAreaResult lEffectiveArea = calculateEffectiveArea(lTotalHits);
lDataFile << lEffectiveArea.EA << "\t" << lEffectiveArea.EAError << "\t";
lDataFile << G4endl;
lDataFile.close();
effectiveAreaResult effectiveArea = calculateEffectiveArea(totalHits);
dataFile << effectiveArea.EA << "\t" << effectiveArea.EAError << "\t";
dataFile << G4endl;
dataFile.close();
}

/**
* @brief Writes the header line to the output file.
*/
template <typename... Args>
void OMSimEffectiveAreaAnalyisis::writeHeader(Args... args)
void OMSimEffectiveAreaAnalyisis::writeHeader(Args... p_args)
{
std::fstream lDataFile;
lDataFile.open(mOutputFileName.c_str(), std::ios::out | std::ios::app);
lDataFile << "# ";
((lDataFile << args << "\t"), ...);
lDataFile << "hits[1perPMT]"
std::fstream dataFile;
dataFile.open(m_outputFileName.c_str(), std::ios::out | std::ios::app);
dataFile << "# ";
((dataFile << p_args << "\t"), ...);
dataFile << "hits[1perPMT]"
<< "\t"
<< "total_hits"
<< "\t"
<< "EA_Total(cm^2)"
<< "\t"
<< "EA_Total_error(cm^2)"
<< "\t" << G4endl;
lDataFile.close();
dataFile.close();
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* @ingroup EffectiveArea
*/

#ifndef OMSimEffectiveAreaDetector_h
#define OMSimEffectiveAreaDetector_h 1
#pragma once

#include "OMSimDetectorConstruction.hh"

Expand All @@ -24,6 +23,3 @@ private:
void constructWorld();
void constructDetector();
};

#endif
//
44 changes: 1 addition & 43 deletions simulations/effective_area/include/OMSimEventAction.hh
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
#ifndef OMSimEventAction_h
#define OMSimEventAction_h 1
#pragma once

#include "G4UserEventAction.hh"
#include <string>
#include "G4Types.hh"

class G4Event;


/**
* @class OMSimEventAction
* @brief Handles custom actions at the beginning and end of each event.
*
* This class defines custom actions that are performed at the start and end
* of each Geant4 event simulation. It interacts with analysis and hit managers
* to handle, record, and reset event information.
* @ingroup EffectiveArea
*/
class OMSimEventAction : public G4UserEventAction
{
public:
Expand All @@ -30,34 +19,3 @@ class OMSimEventAction : public G4UserEventAction

private:
};

/**
* @class EventInfoManager
* @brief Singleton class for managing event-specific information.
* @ingroup EffectiveArea
*
* This class provides a mechanism to set and get the current event ID
* across different parts of the simulation without having to pass event objects around.
*/
class EventInfoManager {
public:
static EventInfoManager& getInstance() {
static EventInfoManager instance;
return instance;
}

void setCurrentEventID(G4int id) {
currentEventID = id;
}

G4int getCurrentEventID() const {
return currentEventID;
}

private:
EventInfoManager() : currentEventID(-1) {}

G4int currentEventID;
};

#endif
5 changes: 1 addition & 4 deletions simulations/effective_area/include/OMSimPhysicsList.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef OMSimPhysicsList_h
#define OMSimPhysicsList_h 1

#pragma once
#include <G4VUserPhysicsList.hh>

class G4VPhysicsConstructor;
Expand Down Expand Up @@ -29,4 +27,3 @@ class OMSimPhysicsList: public G4VUserPhysicsList
private:

};
#endif
Loading

0 comments on commit d9178f1

Please sign in to comment.