From a05723b7dae2062c83b1a976a3a56131e4c90504 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Mon, 25 Nov 2024 06:06:08 +0000 Subject: [PATCH] Allow to PCA older cov base cosnturctor and some fixes to plotting --- CMakeLists.txt | 2 +- Doc/Doxyfile | 2 +- covariance/covarianceBase.cpp | 17 +++++++++++++---- covariance/covarianceBase.h | 2 +- plotting/GetPostfitParamPlots.cpp | 25 ++++++++++++++++++------- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f760d90df..70eaeaf6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON) # CMake version check cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(MaCh3 VERSION 1.2.0 LANGUAGES CXX) +project(MaCh3 VERSION 1.2.1 LANGUAGES CXX) set(MaCh3_VERSION ${PROJECT_VERSION}) #LP - This option name is confusing, but I wont change it now. diff --git a/Doc/Doxyfile b/Doc/Doxyfile index b102af41c..8eb84dc14 100644 --- a/Doc/Doxyfile +++ b/Doc/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "MaCh3" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.2.0 +PROJECT_NUMBER = 1.2.1 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/covariance/covarianceBase.cpp b/covariance/covarianceBase.cpp index 911dff22e..e7f6e40b5 100644 --- a/covariance/covarianceBase.cpp +++ b/covariance/covarianceBase.cpp @@ -1,17 +1,26 @@ #include "covariance/covarianceBase.h" // ******************************************** -covarianceBase::covarianceBase(std::string name, std::string file) : inputFile(file), pca(false) { +covarianceBase::covarianceBase(std::string name, std::string file, double threshold, int FirstPCA, int LastPCA) : inputFile(file), pca(false), +eigen_threshold(threshold), FirstPCAdpar(FirstPCA), LastPCAdpar(LastPCA) { // ******************************************** MACH3LOG_INFO("Constructing instance of covarianceBase"); + if (threshold < 0 || threshold >= 1) { + MACH3LOG_INFO("NOTE: {} {}", name, file); + MACH3LOG_INFO("Principal component analysis but given the threshold for the principal components to be less than 0, or greater than (or equal to) 1. This will not work"); + MACH3LOG_INFO("Please specify a number between 0 and 1"); + MACH3LOG_INFO("You specified: "); + MACH3LOG_INFO("Am instead calling the usual non-PCA constructor..."); + pca = false; + } init(name, file); - FirstPCAdpar = -999; - LastPCAdpar = -999; + + // Call the innocent helper function + if (pca) ConstructPCA(); } // ******************************************** covarianceBase::covarianceBase(const std::vector& YAMLFile, std::string name, double threshold, int FirstPCA, int LastPCA) : inputFile(YAMLFile[0].c_str()), matrixName(name), pca(true), eigen_threshold(threshold), FirstPCAdpar(FirstPCA), LastPCAdpar(LastPCA) { // ******************************************** - MACH3LOG_INFO("Constructing instance of covarianceBase using "); for(unsigned int i = 0; i < YAMLFile.size(); i++) { diff --git a/covariance/covarianceBase.h b/covariance/covarianceBase.h index 62a6d2197..b7fc6c7b0 100644 --- a/covariance/covarianceBase.h +++ b/covariance/covarianceBase.h @@ -24,7 +24,7 @@ class covarianceBase { /// @brief "Usual" constructors from root file /// @param name Matrix name /// @param file Path to matrix root file - covarianceBase(std::string name, std::string file); + covarianceBase(std::string name, std::string file, double threshold = -1, int FirstPCAdpar = -999, int LastPCAdpar = -999); /// @brief Destructor virtual ~covarianceBase(); diff --git a/plotting/GetPostfitParamPlots.cpp b/plotting/GetPostfitParamPlots.cpp index b816b37d2..10aa6f5bf 100644 --- a/plotting/GetPostfitParamPlots.cpp +++ b/plotting/GetPostfitParamPlots.cpp @@ -556,7 +556,7 @@ void MakeXsecRidgePlots() auto blockContents = paramBlock[2].as>(); // the directory of histograms - TDirectoryFile *posteriorDir = man->input().getFile(0).file->Get("Post"); + TDirectoryFile *posteriorDir = man->input().getFile(0).file->Get("Post_1d_hists"); // get num of params in the block int nParams = static_cast(blockContents.size()); @@ -579,12 +579,10 @@ void MakeXsecRidgePlots() // use this to set the limits and also to plot the x axis and grid TH1D *axisPlot = new TH1D("axis plot", "", 1, blockLimits[0], blockLimits[1]); - for(int parId = 0; parId < nParams; parId++){ + for(int parId = 0; parId < nParams; parId++) { std::string paramName = blockContents[parId]; - TCanvas *posteriorDistCanv = nullptr; TH1D *posteriorDist = nullptr; - // get the list of objects in the directory TIter next(posteriorDir->GetListOfKeys()); while (TKey* key = static_cast(next())) { @@ -595,13 +593,12 @@ void MakeXsecRidgePlots() bool foundPar = (pos == str.length() - name.length()); if(foundPar){ - posteriorDistCanv = posteriorDir->Get(key->GetName()); - posteriorDist = static_cast(posteriorDistCanv->GetPrimitive(key->GetName())); + posteriorDist = posteriorDir->Get(key->GetName()); } } if(posteriorDist == nullptr){ - MACH3LOG_WARN("Couldnt find parameter {} when making ridgeline plots", paramName); + MACH3LOG_WARN("Couldn't find parameter {} when making ridgeline plots", paramName); continue; } @@ -758,6 +755,20 @@ void GetPostfitParamPlots() postFitHist_tmp->SetLineWidth(man->getOption("plotLineWidth")); leg->AddEntry(postFitHist_tmp, man->getFileLabel(fileId).c_str(), "lpf"); } + /// @todo this is temporary hack + for(unsigned int fileId = 0; fileId < man->getNFiles(); fileId++) + { + TH1D *Hist = static_cast((man->input().getFile(fileId).file->Get( ("param_xsec_"+plotType).c_str()))->Clone()); + + Hist->SetMarkerColor(TColor::GetColorPalette(fileId)); + Hist->SetLineColor(TColor::GetColorPalette(fileId)); + Hist->SetMarkerStyle(7); + Hist->SetLineStyle(1+fileId); + Hist->SetLineWidth(man->getOption("plotLineWidth")); + + PostfitHistVec.push_back(Hist); + } + canv->cd(); canv->Clear(); leg->Draw();