diff --git a/CMakeLists.txt b/CMakeLists.txt index 27fae7d151..0519cfad6a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/effective_area/CMakeLists.txt b/effective_area/CMakeLists.txt index 44c899c4b3..f23ac77981 100755 --- a/effective_area/CMakeLists.txt +++ b/effective_area/CMakeLists.txt @@ -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 $<$:ws2_32>) +target_link_libraries(OMSim_effective_area ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} ${OPENSSL_LIBRARIES} Boost::program_options spdlog::spdlog $<$:ws2_32>) diff --git a/effective_area/OMSim_effective_area.cc b/effective_area/OMSim_effective_area.cc index 9fc4d50b60..be4b5a321c 100755 --- a/effective_area/OMSim_effective_area.cc +++ b/effective_area/OMSim_effective_area.cc @@ -23,7 +23,7 @@ void effectiveAreaSimulation() lAnalysisManager.mOutputFileName = lArgs.get("output_file") + ".dat"; bool lWriteHeader = !lArgs.get("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")) @@ -35,7 +35,7 @@ void effectiveAreaSimulation() for (std::vector::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("wavelength")); lHitManager.reset(); } } @@ -43,7 +43,7 @@ void effectiveAreaSimulation() else { lScanner->runSingleAngularScan(lArgs.get("phi"), lArgs.get("theta")); - lAnalysisManager.writeScan(lArgs.get("phi"), lArgs.get("theta")); + lAnalysisManager.writeScan(lArgs.get("phi"), lArgs.get("theta"), lArgs.get("wavelength")); lHitManager.reset(); } } diff --git a/effective_area/include/OMSimEffectiveAreaAnalyisis.hh b/effective_area/include/OMSimEffectiveAreaAnalyisis.hh index 9959a61005..d5a66d6cd2 100644 --- a/effective_area/include/OMSimEffectiveAreaAnalyisis.hh +++ b/effective_area/include/OMSimEffectiveAreaAnalyisis.hh @@ -31,8 +31,11 @@ public: OMSimEffectiveAreaAnalyisis(){}; ~OMSimEffectiveAreaAnalyisis(){}; - void writeScan(G4double pPhi, G4double pTheta); - void writeHeader(); + template + void writeScan(Args... args); + template + void writeHeader(Args... args); + effectiveAreaResult calculateEffectiveArea(double pHits); G4String mOutputFileName; @@ -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 +void OMSimEffectiveAreaAnalyisis::writeScan(Args... args) { + std::vector 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 +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 diff --git a/effective_area/src/OMSimEffectiveAreaAnalyisis.cc b/effective_area/src/OMSimEffectiveAreaAnalyisis.cc index e276057209..8adb74eff2 100644 --- a/effective_area/src/OMSimEffectiveAreaAnalyisis.cc +++ b/effective_area/src/OMSimEffectiveAreaAnalyisis.cc @@ -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(); -} /** @@ -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 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(); -}