Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Apps/EventRates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ int main(int argc, char * argv[]) {
}
}

std::string OutFileName = GetFromManager<std::string>(FitManager->raw()["General"]["OutputFile"], "EventRatesOutput.root");
Write1DHistogramsToFile(OutFileName, DUNEHists);
std::string OutFileName = GetFromManager<std::string>(FitManager->raw()["General"]["OutputFile"], "EventRatesOutput.root", __FILE__, __LINE__);
Write1DHistogramsToFile(OutFileName, DUNEHists);
Write1DHistogramsToPdf(OutFileName, DUNEHists);

//###############################################################################################################################
Expand All @@ -77,7 +77,7 @@ int main(int argc, char * argv[]) {
MACH3LOG_INFO("========================================================================");
MACH3LOG_INFO("========================================================================");
MACH3LOG_INFO("Oscillation Mode Breakdown:");

for(auto handler : samples) {
for (int iSample = 0; iSample < handler->GetNSamples(); iSample++) {
MACH3LOG_INFO("======================");
Expand All @@ -90,7 +90,7 @@ int main(int argc, char * argv[]) {
SelecChannel.LowerBound = iOscChan;
SelecChannel.UpperBound = iOscChan+1;
SelectionVec.push_back(SelecChannel);

auto Hist = handler->Get1DVarHist(iSample, handler->GetKinVarName(iSample, 0),SelectionVec);
MACH3LOG_INFO("{:<20} : {:<20} : {:<20.2f}",handler->GetSampleTitle(iSample),handler->GetFlavourName(iSample, iOscChan),Hist->Integral());
}
Expand Down
18 changes: 9 additions & 9 deletions Apps/Fit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ int main(int argc, char * argv[]) {

for (auto handler : samples) {
for (unsigned iSample = 0; iSample < handler->GetNSamples(); ++iSample) {

std::string name = handler->GetSampleTitle(iSample);
sample_names.push_back(name);
TString NameTString = TString(name.c_str());

handler->Reweight();
PredictionHistograms.push_back(static_cast<TH1*>(handler->GetMCHist(iSample)->Clone(NameTString+"_DataHist")));

Expand All @@ -46,9 +46,9 @@ int main(int argc, char * argv[]) {
} else if (handler->GetNDim(iSample) == 2){
handler->AddData(iSample, static_cast<TH2D*>(PredictionHistograms.back()));
}

else {
MACH3LOG_ERROR("Unsupported number of dimensions > 2 - Quitting");
MACH3LOG_ERROR("Unsupported number of dimensions > 2 - Quitting");
throw MaCh3Exception(__FILE__ , __LINE__ );
}

Expand All @@ -57,16 +57,16 @@ int main(int argc, char * argv[]) {
MACH3LOG_INFO("--------------");
}
}

//###########################################################################################################
//MCMC

auto MaCh3Fitter = MaCh3FitterFactory(FitManager.get());

bool StartFromPreviousChain = GetFromManager(FitManager->raw()["General"]["StartFromPos"], false);
bool StartFromPreviousChain = GetFromManager(FitManager->raw()["General"]["StartFromPos"], false, __FILE__, __LINE__);
//Start chain from random position unless continuing a chain
if(!StartFromPreviousChain){
if (!GetFromManager(FitManager->raw()["General"]["StatOnly"], false)) {
if (!GetFromManager(FitManager->raw()["General"]["StatOnly"], false, __FILE__, __LINE__)) {
param_handler->ThrowParameters();
}
}
Expand All @@ -79,13 +79,13 @@ int main(int argc, char * argv[]) {
MACH3LOG_INFO("MCMC getting starting position from: {}",PreviousChainPath);
MaCh3Fitter->StartFromPreviousFit(PreviousChainPath);
}

//Add samples
for(auto Sample : samples){
MaCh3Fitter->AddSampleHandler(Sample);
}


//Run fit
MaCh3Fitter->RunMCMC();

Expand Down
10 changes: 5 additions & 5 deletions Apps/LikelihoodScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ int main(int argc, char * argv[]) {
auto FitManager = MaCh3ManagerFactory(argc, argv);

// 1D scan on by default, and 2D off
const bool do_1d_llhscan = GetFromManager(FitManager->raw()["General"]["1DLLHScan"], true);
const bool do_2d_llhscan = GetFromManager(FitManager->raw()["General"]["2DLLHScan"], false);
const bool do_1d_llhscan = GetFromManager(FitManager->raw()["General"]["1DLLHScan"], true, __FILE__, __LINE__);
const bool do_2d_llhscan = GetFromManager(FitManager->raw()["General"]["2DLLHScan"], false, __FILE__, __LINE__);

if (!do_1d_llhscan && !do_2d_llhscan) {
MACH3LOG_ERROR("Neither 1D or 2D llhscan enabled");
Expand Down Expand Up @@ -52,15 +52,15 @@ int main(int argc, char * argv[]) {
auto MaCh3Fitter = MaCh3FitterFactory(FitManager.get());

//###############################################################################################################################
//Lets benefit from the core code utilities
//Lets benefit from the core code utilities

//Add samples to FitterBase
for(auto Sample : samples){
MaCh3Fitter->AddSampleHandler(Sample);
}

MaCh3Fitter->AddSystObj(param_handler.get());

if (do_1d_llhscan) {
MaCh3Fitter->RunLLHScan();
}
Expand Down
10 changes: 5 additions & 5 deletions Apps/SigmaVariation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ int main(int argc, char * argv[]) {

std::string OutputFileName = FitManager->raw()["General"]["OutputFile"].as<std::string>();
TFile* File = TFile::Open(OutputFileName.c_str(),"RECREATE");

MACH3LOG_INFO("Starting Variations for covarianceBase Object: {}",param_handler->GetName());

int nPars = param_handler->GetNumParams();
for (int iPar=0;iPar<nPars;iPar++) {
std::string ParName = param_handler->GetParFancyName(iPar);
double VarInit = param_handler->GetParInit(iPar);
double VarInit = param_handler->GetParPreFit(iPar);
double VarSigma = param_handler->GetDiagonalError(iPar);

MACH3LOG_INFO("\tParameter : {:<30} - Variations around value : {:<10.7f} , in units of 1 Sigma : {:<10.7f}",ParName,VarInit,VarSigma);

File->cd();
File->mkdir(ParName.c_str());
File->cd(ParName.c_str());

for (size_t iSigVar=0;iSigVar<sigmaVariations.size();iSigVar++) {
double VarVal = VarInit + sigmaVariations[iSigVar] * VarSigma;
if (VarVal < param_handler->GetLowerBound(iPar)) VarVal = param_handler->GetLowerBound(iPar);
Expand Down
70 changes: 18 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
# download CPM.cmake
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.2/CPM.cmake
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.43.1/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
Expand Down Expand Up @@ -68,7 +68,7 @@ option(MaCh3_DUNE_USE_SRProxy "Whether to build proxy classes for Standard Recor

if(MaCh3_DUNE_USE_SRProxy)
find_package(duneanaobj)

if(NOT duneanaobj_FOUND)
CPMFindPackage(
NAME duneanaobj
Expand All @@ -77,78 +77,44 @@ if(MaCh3_DUNE_USE_SRProxy)
VERSION 4.0.0
)
endif()

if(NOT TARGET duneanaobj::all)
cmessage(FATAL_ERROR "MaCh3 DUNE Expected dependency target: duneanaobj::all")
endif()
else()
CPMAddPackage(
NAME duneanaobj
GIT_TAG ${DUNE_ANAOBJ_BRANCH}
GITHUB_REPOSITORY DUNE/duneanaobj
DOWNLOAD_ONLY YES
)
include_directories(${duneanaobj_SOURCE_DIR})

ROOT_GENERATE_DICTIONARY(StandardRecordDict ${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord/StandardRecord.h
LINKDEF ${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord/classes_def.xml)

file(GLOB SR_IMPL_FILES "${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord/*.cxx")
LIST(APPEND SR_IMPL_FILES ${CMAKE_CURRENT_BINARY_DIR}/StandardRecordDict.cxx)

add_library(duneanaobj_StandardRecord SHARED ${SR_IMPL_FILES})
target_link_libraries(duneanaobj_StandardRecord PUBLIC ROOT::MathCore)

target_include_directories(duneanaobj_StandardRecord PUBLIC
$<BUILD_INTERFACE:${duneanaobj_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(duneanaobj_StandardRecord PRIVATE
$<BUILD_INTERFACE:${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord> #root puts this in the dictionary
)

set_target_properties(duneanaobj_StandardRecord PROPERTIES EXPORT_NAME all)
install(TARGETS duneanaobj_StandardRecord EXPORT mach3dune-targets DESTINATION lib)

file(GLOB SR_HEADER_FILES "${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord/*.h")

install(FILES ${SR_HEADER_FILES} DESTINATION include/duneanaobj/StandardRecord)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libStandardRecordDict_rdict.pcm
${CMAKE_CURRENT_BINARY_DIR}/libStandardRecordDict.rootmap
DESTINATION lib)

add_library(duneanaobj::all ALIAS duneanaobj_StandardRecord)

include(fetchduneanaobj)
fetchduneanaobj(${DUNE_ANAOBJ_BRANCH})
endif()

################################## MaCh3 ######################################
#If MaCh3 was sourced find it, otherwise use CPM
SET(MaCh3_FOUND FALSE)
find_package(MaCh3 2.5.1 EXACT QUIET)
set(MaCh3_CORE_BRANCH v2.5.1 CACHE STRING "Specify the MaCh3 core branch to use")
find_package(MaCh3 2.6.0 EXACT QUIET)
set(MaCh3_CORE_BRANCH v2.6.0 CACHE STRING "Specify the MaCh3 core branch to use")
message(STATUS "Using MaCh3_CORE_BRANCH: ${MaCh3_CORE_BRANCH}")

if(NOT MaCh3_FOUND)
cmessage(STATUS "Didn't find MaCh3, attempting to use built in MaCh3")

if(NOT DEFINED MaCh3_GPU_ENABLED)
set(MaCh3_GPU_ENABLED ON)
endif()

if(NOT DEFINED MaCh3_DEBUG_ENABLED)
set(MaCh3_DEBUG_ENABLED FALSE)
endif()

if(NOT DEFINED MaCh3_MULTITHREAD_ENABLED)
set(MaCh3_MULTITHREAD_ENABLED TRUE)
endif()

# Options list construction
set(MaCh3_OPTIONS
"MaCh3_GPU_ENABLED ${MaCh3_GPU_ENABLED}"
"MaCh3_DEBUG_ENABLED ${MaCh3_DEBUG_ENABLED}"
"MaCh3_MULTITHREAD_ENABLED ${MaCh3_MULTITHREAD_ENABLED}"
"MaCh3_CORE_BRANCH ${MaCh3_CORE_BRANCH}"
"MaCh3_WERROR_ENABLED OFF" #required due to small uninitialized issue in MaCh3Core 2.6.0, revert when fixed
)

# Add LOG_LEVEL if defined
Expand All @@ -159,7 +125,7 @@ if(NOT MaCh3_FOUND)
list(APPEND MaCh3_OPTIONS "NuFastLinear_ENABLED TRUE")
list(APPEND MaCh3_OPTIONS "CUDAProb3_ENABLED TRUE")
list(APPEND MaCh3_OPTIONS "CUDAProb3Linear_ENABLED TRUE")

CPMAddPackage(
NAME MaCh3
GIT_TAG ${MaCh3_CORE_BRANCH}
Expand All @@ -171,7 +137,7 @@ else()
##KS: This ensure that all executables that are in core will be moved
FILE(GLOB MaCh3Exe $ENV{MaCh3_ROOT}/Diagnostics/*)
FILE(COPY ${MaCh3Exe} DESTINATION ${CMAKE_BINARY_DIR}/Diagnostics/)

FILE(GLOB MaCh3Exe $ENV{MaCh3_ROOT}/plotting/*)
FILE(COPY ${MaCh3Exe} DESTINATION ${CMAKE_BINARY_DIR}/plotting/)
endif()
Expand Down Expand Up @@ -286,16 +252,16 @@ if(NOT DEFINED MaCh3_PREFIX OR MaCh3_PREFIX STREQUAL "")
cmessage(STATUS "Detected MaCh3 from target include dirs: ${MaCh3_PREFIX}")
endif()
endif()

# Final validation
if(NOT DEFINED MaCh3_PREFIX OR MaCh3_PREFIX STREQUAL "")
cmessage(FATAL_ERROR "Could not determine MaCh3_PREFIX. Please set it manually with -DMaCh3_PREFIX=<path>")
endif()

if(NOT EXISTS "${MaCh3_PREFIX}")
cmessage(FATAL_ERROR "MaCh3_PREFIX does not exist: ${MaCh3_PREFIX}")
endif()

# Cache it for use in subdirectories
set(MaCh3_PREFIX "${MaCh3_PREFIX}" CACHE PATH "MaCh3 installation or source directory" FORCE)
cmessage(STATUS "Set MaCh3_PREFIX: ${MaCh3_PREFIX}")
Expand Down Expand Up @@ -350,4 +316,4 @@ install(FILES
${CMAKE_BINARY_DIR}/MaCh3DUNEConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/MaCh3DUNE)

include(mach3dune-config)
include(mach3dune-config)
4 changes: 2 additions & 2 deletions Samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ set_target_properties(SamplesDUNE PROPERTIES
PUBLIC_HEADER "${HEADERS}"
EXPORT_NAME SamplesDUNE)

target_link_libraries(SamplesDUNE PUBLIC SplinesDUNE duneanaobj::all MaCh3::All MaCh3DUNECompilerOptions)
target_link_libraries(SamplesDUNE PRIVATE DUNEMaCh3Warnings)
target_link_libraries(SamplesDUNE PUBLIC SplinesDUNE MaCh3::All MaCh3DUNECompilerOptions)
target_link_libraries(SamplesDUNE PRIVATE duneanaobj::StandardRecord DUNEMaCh3Warnings)

target_include_directories(SamplesDUNE PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../>
Expand Down
24 changes: 15 additions & 9 deletions Samples/MaCh3DUNEFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#include "Samples/MaCh3DUNEFactory.h"

// DUNE Handlers
#include "Samples/SampleHandlerBeamFD.h"
#include "Samples/SampleHandlerBeamND.h"
#include "Samples/SampleHandlerBeamNDGAr.h"
#include "Samples/SampleHandlerAtm.h"

// ###############################################################
SampleHandlerBase* GetMaCh3DuneInstance(std::string SampleType, std::string SampleConfig, std::unique_ptr<ParameterHandlerGeneric>& param_handler, const std::shared_ptr<OscillationHandler>& BeamOscillator_, const std::shared_ptr<OscillationHandler>& AtmOscillator_, BeamNDCov beamNDCov) {
// ###############################################################
SampleHandlerBase *Sample;
if (SampleType == "BeamFD") {
Sample = new SampleHandlerBeamFD(SampleConfig, param_handler.get(), BeamOscillator_);
} else if (SampleType == "BeamND") {

if (beamNDCov.NDCov_FHC == nullptr || beamNDCov.NDCov_RHC == nullptr || beamNDCov.NDCov_all == nullptr) {
MACH3LOG_ERROR("NDCov objects are not defined");
throw MaCh3Exception(__FILE__, __LINE__);
}
Sample = new SampleHandlerBeamND(SampleConfig, param_handler.get(), beamNDCov);
Sample = new SampleHandlerBeamND(SampleConfig, param_handler.get(), beamNDCov);
} else if (SampleType == "Atm") {
Sample = new SampleHandlerAtm(SampleConfig, param_handler.get(), AtmOscillator_);
} else if (SampleType == "BeamNDGAr") {
Expand All @@ -22,7 +28,7 @@ SampleHandlerBase* GetMaCh3DuneInstance(std::string SampleType, std::string Samp
MACH3LOG_ERROR("Invalid SampleType: {} defined in {}", SampleType, SampleConfig);
throw MaCh3Exception(__FILE__, __LINE__);
}

return Sample;
}

Expand Down Expand Up @@ -58,7 +64,7 @@ BeamNDCov SetupBeamNDCov(std::unique_ptr<Manager> &FitManager)
}

std::string NDCovMatrixFile = FitManager->raw()["General"]["Systematics"]["NDCovFile"].as<std::string>();
bool useCombinedNDCov = GetFromManager(FitManager->raw()["General"]["Systematics"]["UseCombinedNDCov"], true);
bool useCombinedNDCov = GetFromManager(FitManager->raw()["General"]["Systematics"]["UseCombinedNDCov"], true, __FILE__, __LINE__);

auto NDCovFile = M3::Open(NDCovMatrixFile, "READ", __FILE__, __LINE__);

Expand Down Expand Up @@ -98,7 +104,7 @@ std::vector<SampleHandlerBase *> MaCh3DuneSampleFactory(std::unique_ptr<Manager>
throw MaCh3Exception(__FILE__, __LINE__);
}


// ==========================================================
// Setup oscillation handlers
auto AtmOscHandler = SetupOscillationHandler(FitManager, param_handler, "ATM", "ATM");
Expand All @@ -122,7 +128,7 @@ std::vector<SampleHandlerBase *> MaCh3DuneSampleFactory(std::unique_ptr<Manager>
std::string SampleType = tempSampleManager->raw()["SampleHandlerName"].as<std::string>();

auto sample = GetMaCh3DuneInstance(SampleType, DUNESampleConfigs[Sample_i], param_handler, BeamOscHandler, AtmOscHandler, beamNDCov);

#if DEBUG_DUNE_WEIGHTS==1
// Pure for debugging, lets us set which weights we don't want via the manager
sample->setWeightSwitchOffVector(FitManager->getWeightSwitchOffVector());
Expand All @@ -137,11 +143,11 @@ std::vector<SampleHandlerBase *> MaCh3DuneSampleFactory(std::unique_ptr<Manager>
std::pair<std::unique_ptr<ParameterHandlerGeneric>, std::vector<SampleHandlerBase*>> MaCh3DuneFactory(std::unique_ptr<Manager> &FitManager) {
/// Generates a MaCh3 DUNE instance
auto param_handler = MaCh3CovarianceFactory<ParameterHandlerGeneric>(FitManager.get(), "Xsec");

if (CheckNodeExists(FitManager->raw(), "General", "OscillationParameters")){
auto oscpars = Get<std::vector<double>>(FitManager->raw()["General"]["OscillationParameters"], __FILE__, __LINE__);
param_handler->SetGroupOnlyParameters("Osc", oscpars);
}
}

auto samples = MaCh3DuneSampleFactory(FitManager, param_handler);

Expand All @@ -150,4 +156,4 @@ std::pair<std::unique_ptr<ParameterHandlerGeneric>, std::vector<SampleHandlerBas
}

return {std::move(param_handler), samples};
}
}
Loading