Skip to content

Commit

Permalink
Allow to PCA older cov base cosnturctor and some fixes to plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
KSkwarczynski committed Nov 25, 2024
1 parent 863e488 commit a05723b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions covariance/covarianceBase.cpp
Original file line number Diff line number Diff line change
@@ -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<std::string>& 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++)
{
Expand Down
2 changes: 1 addition & 1 deletion covariance/covarianceBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
25 changes: 18 additions & 7 deletions plotting/GetPostfitParamPlots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void MakeXsecRidgePlots()
auto blockContents = paramBlock[2].as<std::vector<std::string>>();

// the directory of histograms
TDirectoryFile *posteriorDir = man->input().getFile(0).file->Get<TDirectoryFile>("Post");
TDirectoryFile *posteriorDir = man->input().getFile(0).file->Get<TDirectoryFile>("Post_1d_hists");

// get num of params in the block
int nParams = static_cast<int>(blockContents.size());
Expand All @@ -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<TKey*>(next())) {
Expand All @@ -595,13 +593,12 @@ void MakeXsecRidgePlots()
bool foundPar = (pos == str.length() - name.length());

if(foundPar){
posteriorDistCanv = posteriorDir->Get<TCanvas>(key->GetName());
posteriorDist = static_cast<TH1D*>(posteriorDistCanv->GetPrimitive(key->GetName()));
posteriorDist = posteriorDir->Get<TH1D>(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;
}

Expand Down Expand Up @@ -758,6 +755,20 @@ void GetPostfitParamPlots()
postFitHist_tmp->SetLineWidth(man->getOption<int>("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<TH1D*>((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<int>("plotLineWidth"));

PostfitHistVec.push_back(Hist);
}

canv->cd();
canv->Clear();
leg->Draw();
Expand Down

0 comments on commit a05723b

Please sign in to comment.