Skip to content

Commit

Permalink
effective area ouput with ...args
Browse files Browse the repository at this point in the history
  • Loading branch information
martinunland committed May 21, 2024
1 parent 5863a94 commit 9205aa8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ find_package(OpenSSL REQUIRED)

# For logging with spdlog
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED) # Find fmt library
#find_package(fmt REQUIRED) # Find fmt library


# Include OpenSSL's headers in the project
Expand Down
2 changes: 1 addition & 1 deletion effective_area/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ target_include_directories(OMSim_effective_area PUBLIC
)

# Link the libraries
target_link_libraries(OMSim_effective_area ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} ${OPENSSL_LIBRARIES} /usr/lib/x86_64-linux-gnu/libargtable2.so.0 Boost::program_options spdlog::spdlog fmt::fmt $<$<BOOL:${MINGW}>:ws2_32>)
target_link_libraries(OMSim_effective_area ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} ${OPENSSL_LIBRARIES} Boost::program_options spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
6 changes: 3 additions & 3 deletions effective_area/OMSim_effective_area.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void effectiveAreaSimulation()
lAnalysisManager.mOutputFileName = lArgs.get<std::string>("output_file") + ".dat";

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

// If angle file is provided, run over all angle pairs in file
if (lArgs.keyExists("angles_file"))
Expand All @@ -35,15 +35,15 @@ void effectiveAreaSimulation()
for (std::vector<int>::size_type i = 0; i != lThetas.size(); i++)
{
lScanner->runSingleAngularScan(lPhis.at(i), lThetas.at(i));
lAnalysisManager.writeScan(lPhis.at(i), lThetas.at(i));
lAnalysisManager.writeScan(lPhis.at(i), lThetas.at(i), lArgs.get<G4double>("wavelength"));
lHitManager.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"));
lAnalysisManager.writeScan(lArgs.get<G4double>("phi"), lArgs.get<G4double>("theta"), lArgs.get<G4double>("wavelength"));
lHitManager.reset();
}
}
Expand Down
54 changes: 52 additions & 2 deletions effective_area/include/OMSimEffectiveAreaAnalyisis.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ public:
OMSimEffectiveAreaAnalyisis(){};
~OMSimEffectiveAreaAnalyisis(){};

void writeScan(G4double pPhi, G4double pTheta);
void writeHeader();
template<typename... Args>
void writeScan(Args... args);
template<typename... Args>
void writeHeader(Args... args);

effectiveAreaResult calculateEffectiveArea(double pHits);

G4String mOutputFileName;
Expand All @@ -41,4 +44,51 @@ private:

};

/**
* @brief Writes a scan result to the output file.
* @param args The values to be written to the output file.
*/
template<typename... Args>
void OMSimEffectiveAreaAnalyisis::writeScan(Args... args) {
std::vector<double> lHits = OMSimHitManager::getInstance().countHits();
mDatafile.open(mOutputFileName.c_str(), std::ios::out | std::ios::app);

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


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

effectiveAreaResult lEffectiveArea = calculateEffectiveArea(lTotalHits);
mDatafile << lEffectiveArea.EA << "\t" << lEffectiveArea.EAError << "\t";
mDatafile << G4endl;
mDatafile.close();
}


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


#endif
44 changes: 0 additions & 44 deletions effective_area/src/OMSimEffectiveAreaAnalyisis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@
#include "OMSimHitManager.hh"


/**
* @brief Writes the header line to the output file.
*/
void OMSimEffectiveAreaAnalyisis::writeHeader()
{
mDatafile.open(mOutputFileName.c_str(), std::ios::out | std::ios::app);
mDatafile << "# Phi(deg)"
<< "\t"
<< "Theta(deg)"
<< "\t"
<< "hits[1perPMT]"
<< "\t"
<< "total_hits"
<< "\t"
<< "EA_Total(cm^2)"
<< "\t"
<< "EA_Total_error(cm^2)"
<< "\t" << G4endl;
mDatafile.close();
}


/**
Expand All @@ -41,28 +21,4 @@ effectiveAreaResult OMSimEffectiveAreaAnalyisis::calculateEffectiveArea(double p
return { lEA, lEAError };
}

/**
* @brief Writes a scan result to the output file.
* @param pPhi The phi angle used in the scan to be written to the output file.
* @param pTheta The phi angle used in the scan to be written to the output file.
*/
void OMSimEffectiveAreaAnalyisis::writeScan(G4double pPhi, G4double pTheta)
{
std::vector<double> lHits = OMSimHitManager::getInstance().countHits();

mDatafile.open(mOutputFileName.c_str(), std::ios::out | std::ios::app);
mDatafile << pPhi << "\t" << pTheta << "\t";
G4double lTotalHits = 0;

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

effectiveAreaResult lEffectiveArea = calculateEffectiveArea(lTotalHits);

mDatafile << lEffectiveArea.EA << "\t" << lEffectiveArea.EAError << "\t";
mDatafile << G4endl;
mDatafile.close();
}

0 comments on commit 9205aa8

Please sign in to comment.