From a877ea03f0ac1556de5a605a5b2763c7c87ad261 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Fri, 25 Oct 2024 19:24:40 +0000 Subject: [PATCH 1/2] App->CIValidaitions and some tweaks to NuMCMC Tool converter to make it more flexible --- Apps/NuMCMCconversion.cpp | 101 ------------ {Apps => CIValidations}/CMakeLists.txt | 5 +- .../CovarianceValidations.cpp | 0 {Apps => CIValidations}/FitterValidations.cpp | 0 .../MaCh3ModeValidations.cpp | 0 CIValidations/NuMCMCconversion.cpp | 155 ++++++++++++++++++ {Apps => CIValidations}/NuMCMCvalidations.sh | 6 +- .../Scripts}/CreateSplineFile.cpp | 0 .../Scripts}/FilterFiles.cpp | 0 {Apps => CIValidations}/SplineValidations.cpp | 0 {Apps => CIValidations}/TestNuMCMC.py | 0 .../TestOutputs/CovarianceOut.txt | 0 .../TestOutputs/MaCh3ModeOut.txt | 0 .../TestOutputs/SplineMonoOut.txt | 0 CMakeLists.txt | 3 +- 15 files changed, 162 insertions(+), 108 deletions(-) delete mode 100755 Apps/NuMCMCconversion.cpp rename {Apps => CIValidations}/CMakeLists.txt (85%) rename {Apps => CIValidations}/CovarianceValidations.cpp (100%) rename {Apps => CIValidations}/FitterValidations.cpp (100%) rename {Apps => CIValidations}/MaCh3ModeValidations.cpp (100%) create mode 100755 CIValidations/NuMCMCconversion.cpp rename {Apps => CIValidations}/NuMCMCvalidations.sh (53%) rename {Scripts => CIValidations/Scripts}/CreateSplineFile.cpp (100%) rename {Scripts => CIValidations/Scripts}/FilterFiles.cpp (100%) rename {Apps => CIValidations}/SplineValidations.cpp (100%) rename {Apps => CIValidations}/TestNuMCMC.py (100%) rename {Apps => CIValidations}/TestOutputs/CovarianceOut.txt (100%) rename {Apps => CIValidations}/TestOutputs/MaCh3ModeOut.txt (100%) rename {Apps => CIValidations}/TestOutputs/SplineMonoOut.txt (100%) diff --git a/Apps/NuMCMCconversion.cpp b/Apps/NuMCMCconversion.cpp deleted file mode 100755 index ef04340..0000000 --- a/Apps/NuMCMCconversion.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include - -#include "TChain.h" -#include "TFile.h" -#include "TTree.h" -#include "TNamed.h" -#include "TObjString.h" - -/// @todo actually save gaussian - -int main(int argc, char *argv[]) -{ - if (argc != 3) - { - return 1; - } - - double t_sin2th_23; - double t_sin2th_13; - double t_sin2th_12; - double t_delm2_23; - double t_delm2_12; - double t_delta_cp; - - TChain* myChain = new TChain("posteriors",""); - myChain->Add(argv[1]); - - myChain->SetBranchStatus("*",0); - myChain->SetBranchStatus("sin2th_23",1); - myChain->SetBranchAddress("sin2th_23", &t_sin2th_23); - myChain->SetBranchStatus("sin2th_13",1); - myChain->SetBranchAddress("sin2th_13", &t_sin2th_13); - myChain->SetBranchStatus("sin2th_12",1); - myChain->SetBranchAddress("sin2th_12", &t_sin2th_12); - myChain->SetBranchStatus("delm2_12",1); - myChain->SetBranchAddress("delm2_12", &t_delm2_12); - myChain->SetBranchAddress("delm2_23", &t_delm2_23); - myChain->SetBranchStatus("delm2_23",1); - myChain->SetBranchStatus("delta_cp",1); - myChain->SetBranchAddress("delta_cp", &t_delta_cp); - - - TFile *newfile = new TFile(argv[2],"recreate"); - TTree *newtree = new TTree("mcmc", "mcmc"); - - newtree->Branch("Theta23", &t_sin2th_23, "Theta23/D"); - newtree->Branch("Theta13", &t_sin2th_13, "Theta13/D"); - newtree->Branch("Theta12", &t_sin2th_12, "Theta12/D"); - newtree->Branch("Deltam2_32", &t_delm2_23, "Deltam2_32/D"); - newtree->Branch("Deltam2_21", &t_delm2_12, "Deltam2_21/D"); - newtree->Branch("DeltaCP", &t_delta_cp, "DeltaCP/D"); - - for (int i = 0; i < myChain->GetEntries(); ++i) - { - if (i % 10000 == 0) std::cout << i << std::endl; - myChain->GetEntry(i); - - t_sin2th_23 = std::asin(std::sqrt(t_sin2th_23)); - t_sin2th_13 = std::asin(std::sqrt(t_sin2th_13)); - t_sin2th_12 = std::asin(std::sqrt(t_sin2th_12)); - - newtree->Fill(); - } - - newtree->Print(); - newtree->AutoSave(); - - // List of parameter names and their corresponding titles - std::vector> params = { - {"Theta23", "Uniform:Theta23"}, - {"Theta13", "Uniform:Theta13"}, - {"Theta12", "Uniform:Theta12"}, - {"Deltam2_32", "Uniform:Deltam2_32"}, - {"Deltam2_21", "Uniform:Deltam2_21"}, - {"DeltaCP", "Uniform:DeltaCP"} - }; - - // Create a TList to hold the TNamed objects - TList *paramList = new TList(); - - // Create TNamed objects for each parameter and add them to the list - for (const auto& param : params) { - TNamed *namedParam = new TNamed(param.first.c_str(), param.second.c_str()); - paramList->Add(namedParam); // Add to TList - } - - // Write the TList to the directory - paramList->Write("priors", TObject::kSingleKey); - - - TObjString doi("https://doi.org/10.5281/zenodo.13642670"); - - doi.Write("citation"); - - // Close the file - newfile->Close(); - - delete newfile; - - return 0; -} diff --git a/Apps/CMakeLists.txt b/CIValidations/CMakeLists.txt similarity index 85% rename from Apps/CMakeLists.txt rename to CIValidations/CMakeLists.txt index f82371d..6bc51e8 100755 --- a/Apps/CMakeLists.txt +++ b/CIValidations/CMakeLists.txt @@ -17,9 +17,10 @@ install(PROGRAMS NuMCMCvalidations.sh TestNuMCMC.py - DESTINATION Apps) + DESTINATION CIValidations) install(DIRECTORY TestOutputs + Scripts - DESTINATION Apps) + DESTINATION CIValidations) diff --git a/Apps/CovarianceValidations.cpp b/CIValidations/CovarianceValidations.cpp similarity index 100% rename from Apps/CovarianceValidations.cpp rename to CIValidations/CovarianceValidations.cpp diff --git a/Apps/FitterValidations.cpp b/CIValidations/FitterValidations.cpp similarity index 100% rename from Apps/FitterValidations.cpp rename to CIValidations/FitterValidations.cpp diff --git a/Apps/MaCh3ModeValidations.cpp b/CIValidations/MaCh3ModeValidations.cpp similarity index 100% rename from Apps/MaCh3ModeValidations.cpp rename to CIValidations/MaCh3ModeValidations.cpp diff --git a/CIValidations/NuMCMCconversion.cpp b/CIValidations/NuMCMCconversion.cpp new file mode 100755 index 0000000..a53675f --- /dev/null +++ b/CIValidations/NuMCMCconversion.cpp @@ -0,0 +1,155 @@ +#include + +#include "TChain.h" +#include "TFile.h" +#include "TTree.h" +#include "TNamed.h" +#include "TObjString.h" + +#include "mcmc/MaCh3Factory.h" + +int main(int argc, char *argv[]) +{ + if (argc != 3) + { + return 1; + } + + double t_sin2th_23; + double t_sin2th_13; + double t_sin2th_12; + double t_delm2_23; + double t_delm2_12; + double t_delta_cp; + + TChain* myChain = new TChain("posteriors",""); + myChain->Add(argv[1]); + + std::map branch_map = { + {"sin2th_23", "Theta23"}, + {"sin2th_13", "Theta13"}, + {"sin2th_12", "Theta12"}, + {"delm2_12", "Deltam2_21"}, + {"delm2_23", "Deltam2_32"}, + {"delta_cp", "DeltaCP"} + }; + + // Map for pointers to the original branches + std::map branch_pointers = { + {"sin2th_23", &t_sin2th_23}, + {"sin2th_13", &t_sin2th_13}, + {"sin2th_12", &t_sin2th_12}, + {"delm2_12", &t_delm2_12}, + {"delm2_23", &t_delm2_23}, + {"delta_cp", &t_delta_cp} + }; + + // Disable all branches by default + myChain->SetBranchStatus("*", 0); + + // Enable branches based on map and set their addresses + for (const auto& [old_name, new_name] : branch_map) { + myChain->SetBranchStatus(old_name.c_str(), 1); + myChain->SetBranchAddress(old_name.c_str(), branch_pointers[old_name]); + } + + /// Load cov osc + TFile *TempFile = new TFile(argv[1], "open"); + TDirectory* CovarianceFolder = (TDirectory*)TempFile->Get("CovarianceFolder"); + + TMacro *OscConfig = (TMacro*)(CovarianceFolder->Get("Config_osc_cov")); + + YAML::Node OscSettings = TMacroToYAML(*OscConfig); + + // Create the new file and tree + TFile* newfile = new TFile(argv[2], "recreate"); + TTree* newtree = new TTree("mcmc", "mcmc"); + + // Create new branches in new tree with the mapped names + for (const auto& [old_name, new_name] : branch_map) { + newtree->Branch(new_name.c_str(), branch_pointers[old_name], (new_name + "/D").c_str()); + } + + for (int i = 0; i < myChain->GetEntries(); ++i) + { + if (i % 10000 == 0) std::cout << i << std::endl; + myChain->GetEntry(i); + + t_sin2th_23 = std::asin(std::sqrt(t_sin2th_23)); + t_sin2th_13 = std::asin(std::sqrt(t_sin2th_13)); + t_sin2th_12 = std::asin(std::sqrt(t_sin2th_12)); + + newtree->Fill(); + } + + newtree->Print(); + newtree->AutoSave(); + + // List of parameter names and their corresponding titles + /* + std::vector> params = { + {"Theta23", "Uniform:Theta23"}, + {"Theta13", "Uniform:Theta13"}, + {"Theta12", "Uniform:Theta12"}, + {"Deltam2_32", "Uniform:Deltam2_32"}, + {"Deltam2_21", "Uniform:Deltam2_21"}, + {"DeltaCP", "Uniform:DeltaCP"} + }; + */ + // List of parameter names and corresponding titles + std::vector> params; + + // Iterate over each systematic entry in the YAML + + for (auto const &entry : OscSettings["Systematics"]) + { + std::string param_name = entry["Systematic"]["Names"]["ParameterName"].as(); + bool flat_prior = entry["Systematic"]["FlatPrior"].as(); + std::string mapped_name = branch_map[param_name]; // Get the mapped name + if(mapped_name == "") continue; + std::string distribution; + + if (param_name.rfind("sin", 0) == 0) { + if (flat_prior) { + distribution = "Uniform:sin^2(" + mapped_name + ")"; + } else { + double prefit_value = entry["Systematic"]["ParameterValues"]["PreFitValue"].as(); + double error = entry["Systematic"]["Error"].as(); + distribution = "Gaussian(" + std::to_string(prefit_value) + ", " + std::to_string(error) + "):sin^2(" + mapped_name + ")"; + } + } else { + if (flat_prior) { + distribution = "Uniform:" + mapped_name; + } else { + double prefit_value = entry["Systematic"]["ParameterValues"]["PreFitValue"].as(); + double error = entry["Systematic"]["Error"].as(); + distribution = "Gaussian(" + std::to_string(prefit_value) + ", " + std::to_string(error) + "):" + mapped_name; + } + } + params.emplace_back(mapped_name, distribution); + } + + // Create a TList to hold the TNamed objects + TList *paramList = new TList(); + + // Create TNamed objects for each parameter and add them to the list + for (const auto& param : params) { + TNamed *namedParam = new TNamed(param.first.c_str(), param.second.c_str()); + paramList->Add(namedParam); // Add to TList + } + + // Write the TList to the directory + paramList->Write("priors", TObject::kSingleKey); + + + TObjString doi("https://doi.org/10.5281/zenodo.13642670"); + + doi.Write("citation"); + + // Close the file + newfile->Close(); + + delete newfile; + + return 0; +} diff --git a/Apps/NuMCMCvalidations.sh b/CIValidations/NuMCMCvalidations.sh similarity index 53% rename from Apps/NuMCMCvalidations.sh rename to CIValidations/NuMCMCvalidations.sh index ce1d5f5..0f0e4ef 100755 --- a/Apps/NuMCMCvalidations.sh +++ b/CIValidations/NuMCMCvalidations.sh @@ -1,11 +1,11 @@ ./bin/MCMCTutorial Inputs/ManagerTest.yaml -./Apps/NuMCMCconversion Test.root NewChain.root +./CIValidations/NuMCMCconversion Test.root NewChain.root pip install -r NuMCMCTools/requirements.txt export PYTHONPATH="$PYTHONPATH:/${MaCh3Tutorial_ROOT}/NuMCMCTools" -cp NewChain.root Apps/NewChain.root +cp NewChain.root CIValidations/NewChain.root -python3 Apps/TestNuMCMC.py +python3 CIValidations/TestNuMCMC.py diff --git a/Scripts/CreateSplineFile.cpp b/CIValidations/Scripts/CreateSplineFile.cpp similarity index 100% rename from Scripts/CreateSplineFile.cpp rename to CIValidations/Scripts/CreateSplineFile.cpp diff --git a/Scripts/FilterFiles.cpp b/CIValidations/Scripts/FilterFiles.cpp similarity index 100% rename from Scripts/FilterFiles.cpp rename to CIValidations/Scripts/FilterFiles.cpp diff --git a/Apps/SplineValidations.cpp b/CIValidations/SplineValidations.cpp similarity index 100% rename from Apps/SplineValidations.cpp rename to CIValidations/SplineValidations.cpp diff --git a/Apps/TestNuMCMC.py b/CIValidations/TestNuMCMC.py similarity index 100% rename from Apps/TestNuMCMC.py rename to CIValidations/TestNuMCMC.py diff --git a/Apps/TestOutputs/CovarianceOut.txt b/CIValidations/TestOutputs/CovarianceOut.txt similarity index 100% rename from Apps/TestOutputs/CovarianceOut.txt rename to CIValidations/TestOutputs/CovarianceOut.txt diff --git a/Apps/TestOutputs/MaCh3ModeOut.txt b/CIValidations/TestOutputs/MaCh3ModeOut.txt similarity index 100% rename from Apps/TestOutputs/MaCh3ModeOut.txt rename to CIValidations/TestOutputs/MaCh3ModeOut.txt diff --git a/Apps/TestOutputs/SplineMonoOut.txt b/CIValidations/TestOutputs/SplineMonoOut.txt similarity index 100% rename from Apps/TestOutputs/SplineMonoOut.txt rename to CIValidations/TestOutputs/SplineMonoOut.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6772fc7..1690fe6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,7 +112,7 @@ cmessage(STATUS "CMAKE CXX Standard: ${CMAKE_CXX_STANDARD}") ################################# Build MaCh3 ################################## add_subdirectory(Utils) -add_subdirectory(Apps) +add_subdirectory(CIValidations) add_subdirectory(Tutorial) configure_file(cmake/Templates/setup.MaCh3Tutorial.sh.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.MaCh3Tutorial.sh" @ONLY) @@ -121,7 +121,6 @@ install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.MaCh3Tutorial ############################ Install #################################### install(DIRECTORY Inputs DESTINATION ${CMAKE_BINARY_DIR}) install(DIRECTORY plotting DESTINATION ${CMAKE_BINARY_DIR}) -install(DIRECTORY Scripts DESTINATION ${CMAKE_BINARY_DIR}) include(CMakePackageConfigHelpers) configure_package_config_file( From 913f7f658260586c07f4061951c6b3cdf0a5d117 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Fri, 25 Oct 2024 19:36:55 +0000 Subject: [PATCH 2/2] remove comments --- CIValidations/NuMCMCconversion.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/CIValidations/NuMCMCconversion.cpp b/CIValidations/NuMCMCconversion.cpp index a53675f..dc5d9d0 100755 --- a/CIValidations/NuMCMCconversion.cpp +++ b/CIValidations/NuMCMCconversion.cpp @@ -85,17 +85,6 @@ int main(int argc, char *argv[]) newtree->Print(); newtree->AutoSave(); - // List of parameter names and their corresponding titles - /* - std::vector> params = { - {"Theta23", "Uniform:Theta23"}, - {"Theta13", "Uniform:Theta13"}, - {"Theta12", "Uniform:Theta12"}, - {"Deltam2_32", "Uniform:Deltam2_32"}, - {"Deltam2_21", "Uniform:Deltam2_21"}, - {"DeltaCP", "Uniform:DeltaCP"} - }; - */ // List of parameter names and corresponding titles std::vector> params;