Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App->CIValidaitions and some tweaks to NuMCMC Tools #31

Merged
merged 2 commits into from
Oct 25, 2024
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
101 changes: 0 additions & 101 deletions Apps/NuMCMCconversion.cpp

This file was deleted.

5 changes: 3 additions & 2 deletions Apps/CMakeLists.txt → CIValidations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ install(PROGRAMS
NuMCMCvalidations.sh
TestNuMCMC.py

DESTINATION Apps)
DESTINATION CIValidations)

install(DIRECTORY
TestOutputs
Scripts

DESTINATION Apps)
DESTINATION CIValidations)
File renamed without changes.
144 changes: 144 additions & 0 deletions CIValidations/NuMCMCconversion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#include <iostream>

#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<std::string, std::string> 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<std::string, double*> 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 corresponding titles
std::vector<std::pair<std::string, std::string>> params;

// Iterate over each systematic entry in the YAML

for (auto const &entry : OscSettings["Systematics"])
{
std::string param_name = entry["Systematic"]["Names"]["ParameterName"].as<std::string>();
bool flat_prior = entry["Systematic"]["FlatPrior"].as<bool>();
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>();
double error = entry["Systematic"]["Error"].as<double>();
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>();
double error = entry["Systematic"]["Error"].as<double>();
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;
}
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down