Skip to content
Open
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
36 changes: 4 additions & 32 deletions apps/examples/histogrammer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,11 @@

using namespace std;

void CheckArgs(int argc, char **argv) {
if (argc != 2 && argc != 4 && argc != 6) {
fatal() << "Usage: " << argv[0] << " config_path"<<endl;
fatal() << "or"<<endl;
fatal() << argv[0] << " config_path input_path output_path"<<endl;
fatal() << "or"<<endl;
fatal() << argv[0] << " config_path input_path output_path apply_muon_scale_factors apply_muon_trigger_scale_factors"<<endl;
exit(1);
}
}

int main(int argc, char **argv) {
auto args = make_unique<ArgsManager>(argc, argv);
if (!args->GetString("config").has_value()) {
fatal() << "No config file provided" << endl;
exit(1);
}

ConfigManager::Initialize(args->GetString("config").value());
auto &config = ConfigManager::GetInstance();

if (args->GetString("input_path").has_value()) {
config.SetInputPath(args->GetString("input_path").value());
}
if (args->GetString("output_path").has_value()) {
config.SetHistogramsOutputPath(args->GetString("output_path").value());
}
if (args->GetString("output_hists_path").has_value()) {
config.SetHistogramsOutputPath(args->GetString("output_hists_path").value());
}
if (args->GetString("output_trees_path").has_value()) {
config.SetTreesOutputPath(args->GetString("output_trees_path").value());
}
vector<string> requiredArgs = {"config"};
vector<string> optionalArgs = {"input_path", "output_hists_path"};
auto args = make_unique<ArgsManager>(argc, argv, requiredArgs, optionalArgs);
ConfigManager::Initialize(args);

auto eventReader = make_shared<EventReader>();
auto histogramsHandler = make_shared<HistogramsHandler>();
Expand Down
19 changes: 4 additions & 15 deletions apps/examples/skimmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,11 @@
using namespace std;

int main(int argc, char **argv) {
auto args = make_unique<ArgsManager>(argc, argv);
if (!args->GetString("config").has_value()) {
fatal() << "No config file provided" << endl;
exit(1);
}

ConfigManager::Initialize(args->GetString("config").value());
auto &config = ConfigManager::GetInstance();
vector<string> requiredArgs = {"config"};
vector<string> optionalArgs = {"input_path", "output_trees_path"};
auto args = make_unique<ArgsManager>(argc, argv, requiredArgs, optionalArgs);
ConfigManager::Initialize(args);

if (args->GetString("input_path").has_value()) {
config.SetInputPath(args->GetString("input_path").value());
}
if (args->GetString("output_trees_path").has_value()) {
config.SetTreesOutputPath(args->GetString("output_trees_path").value());
}

auto eventReader = make_shared<EventReader>();
auto eventWriter = make_shared<EventWriter>(eventReader);
auto cutFlowManager = make_shared<CutFlowManager>(eventReader, eventWriter);
Expand Down
2 changes: 1 addition & 1 deletion jsonPOG
Submodule jsonPOG updated from 377439 to ea5e2a
57 changes: 31 additions & 26 deletions libs/core/include/ArgsManager.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
#pragma once

#include "Helpers.hpp"
#include "Multitype.hpp"

class ArgsManager {
public:
ArgsManager(int argc, char **argv);
~ArgsManager() {}

inline std::optional<std::string> GetString(std::string key) {
if(args.count(key) == 0) return std::nullopt;
return args[key];
}

inline std::optional<int> GetInt(std::string key) {
if(args.count(key) == 0) return std::nullopt;
return std::stoi(args[key]);
}

inline std::optional<float> GetFloat(std::string key) {
if(args.count(key) == 0) return std::nullopt;
return std::stof(args[key]);
}

inline std::optional<bool> GetBool(std::string key) {
if(args.count(key) == 0) return std::nullopt;
return args[key] == "True";
}

private:
std::map<std::string, std::string> args;
public:
ArgsManager(int argc, char** argv, std::vector<std::string> _requiredArgs, std::vector<std::string> _optionalArgs);
~ArgsManager() {}

inline std::optional<std::string> GetString(std::string key) {
if (args.count(key) == 0) return std::nullopt;
return args[key];
}

inline std::optional<int> GetInt(std::string key) {
if (args.count(key) == 0) return std::nullopt;
return std::stoi(args[key]);
}

inline std::optional<float> GetFloat(std::string key) {
if (args.count(key) == 0) return std::nullopt;
return std::stof(args[key]);
}

inline std::optional<bool> GetBool(std::string key) {
if (args.count(key) == 0) return std::nullopt;
return args[key] == "True";
}

private:
void ValidateArgs();

std::vector<std::string> requiredArgs, optionalArgs;
std::map<std::string, std::string> args;
};
64 changes: 42 additions & 22 deletions libs/core/include/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,63 @@

#include "Helpers.hpp"

#include "ArgsManager.hpp"

class ConfigManager {
public:
static ConfigManager& GetInstance(){ return getInstanceImpl(); }
static ConfigManager& GetInstance() { return getInstanceImpl(); }
static void Initialize(std::string _configPath) { getInstanceImpl(&_configPath); }
static void Initialize(const std::unique_ptr<ArgsManager> &args) {
std::string _configPath = args->GetString("config").value();
getInstanceImpl(&_configPath);

auto &config = GetInstance();

if (args->GetString("input_path").has_value()) {
config.SetInputPath(args->GetString("input_path").value());
}

if (args->GetString("output_hists_path").has_value()) {
config.SetHistogramsOutputPath(args->GetString("output_hists_path").value());
}

if (args->GetString("output_trees_path").has_value()) {
config.SetTreesOutputPath(args->GetString("output_trees_path").value());
}
}

ConfigManager(ConfigManager const&) = delete;
void operator=(ConfigManager const&) = delete;

template <typename T>
void GetValue(std::string name, T &outputValue);
void GetValue(std::string name, T& outputValue);

template <typename T>
void GetVector(std::string name, std::vector<T> &outputVector);
void GetVector(std::string name, std::vector<T>& outputVector);

template <typename T, typename U>
void GetMap(std::string name, std::map<T, U> &outputMap);
void GetMap(std::string name, std::map<T, U>& outputMap);

template <typename T, typename U>
void GetPair(std::string name, std::pair<T, U> &outputPair);
void GetPair(std::string name, std::pair<T, U>& outputPair);

void GetExtraEventCollections(insertion_ordered_map<std::string, ExtraCollection> &extraEventCollections);
void GetHistogramsParams(std::map<std::string, HistogramParams> &histogramsParams, std::string collectionName);
void GetHistogramsParams(std::map<std::string, HistogramParams2D> &histogramsParams, std::string collectionName);
void GetHistogramsParams(std::map<std::string, IrregularHistogramParams> &histogramsParams, std::string collectionName);
void GetHistogramsParams(std::map<std::string, IrregularHistogramParams2D> &histogramsParams, std::string collectionName);
void GetExtraEventCollections(insertion_ordered_map<std::string, ExtraCollection>& extraEventCollections);
void GetHistogramsParams(std::map<std::string, HistogramParams>& histogramsParams, std::string collectionName);
void GetHistogramsParams(std::map<std::string, HistogramParams2D>& histogramsParams, std::string collectionName);
void GetHistogramsParams(std::map<std::string, IrregularHistogramParams>& histogramsParams, std::string collectionName);
void GetHistogramsParams(std::map<std::string, IrregularHistogramParams2D>& histogramsParams, std::string collectionName);

void GetScaleFactors(std::string name, std::map<std::string, ScaleFactorsMap> &scaleFactors);
void GetScaleFactors(std::string name, std::map<std::string, ScaleFactorsTuple> &scaleFactors);
void GetScaleFactors(std::string name, std::map<std::string, ScaleFactorsMap>& scaleFactors);
void GetScaleFactors(std::string name, std::map<std::string, ScaleFactorsTuple>& scaleFactors);

void GetCuts(std::vector<std::pair<std::string, std::pair<float, float>>> &cuts);
void GetCuts(std::vector<std::pair<std::string, std::pair<float, float>>>& cuts);

void SetInputPath(std::string path) { inputPath = path; }
void SetTreesOutputPath(std::string path) { treesOutputPath = path; }
void SetHistogramsOutputPath(std::string path) { histogramsOutputPath = path; }

std::string GetYear();

private:
std::string configPath;
ConfigManager(std::string* const _configPath);
Expand All @@ -54,16 +74,16 @@ class ConfigManager {

void PrintBanner();

FILE *pythonFile;
PyObject *pythonModule;
PyObject *config;
FILE* pythonFile;
PyObject* pythonModule;
PyObject* config;

PyObject *GetPythonValue(std::string name);
PyObject *GetPythonList(std::string name);
PyObject *GetPythonDict(std::string name);
PyObject* GetPythonValue(std::string name);
PyObject* GetPythonList(std::string name);
PyObject* GetPythonDict(std::string name);

int GetCollectionSize(PyObject *collection);
PyObject *GetItem(PyObject *collection, int index);
int GetCollectionSize(PyObject* collection);
PyObject* GetItem(PyObject* collection, int index);

std::string inputPath = "";
std::string treesOutputPath = "";
Expand Down
3 changes: 2 additions & 1 deletion libs/core/include/EventWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ class EventWriter {

private:
TFile *outFile;
std::string outputFilePath;
std::map<std::string, TTree *> outputTrees;

std::shared_ptr<EventReader> eventReader;

std::vector<std::string> branchesToKeep;
std::vector<std::string> branchesToRemove;

void SetupOutputTree(std::string outFileName);
void SetupOutputTree();

friend class CutFlowManager;
};
Expand Down
42 changes: 32 additions & 10 deletions libs/core/src/ArgsManager.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
#include "ArgsManager.hpp"

#include "Logger.hpp"

ArgsManager::ArgsManager(int argc, char **argv) {
for (int i = 1; i < argc; i += 2) {
std::string key = argv[i];
if (key.size() < 2 || key[0] != '-' || key[1] != '-') {
fatal() << "Invalid key: " << key << std::endl;
exit(1);
}
key = key.substr(2);
std::string value = argv[i + 1];
args[key] = value;
using namespace std;

ArgsManager::ArgsManager(int argc, char** argv, std::vector<std::string> _requiredArgs, std::vector<std::string> _optionalArgs)
: requiredArgs(_requiredArgs), optionalArgs(_optionalArgs) {
for (int i = 1; i < argc; i += 2) {
string key = argv[i];
if (key.size() < 2 || key[0] != '-' || key[1] != '-') {
fatal() << "Invalid key: " << key << endl;
exit(1);
}
key = key.substr(2);
string value = argv[i + 1];
args[key] = value;
}

ValidateArgs();
}

void ArgsManager::ValidateArgs() {
for (const auto& [key, value] : args) {
if (std::find(requiredArgs.begin(), requiredArgs.end(), key) == requiredArgs.end() &&
std::find(optionalArgs.begin(), optionalArgs.end(), key) == optionalArgs.end()) {
fatal() << "ArgsManager -- Unknown argument provided: " << key << endl;
exit(7);
}
}
for (string requiredArg : requiredArgs) {
if (args.count(requiredArg) == 0) {
fatal() << "ArgsManager -- Required argument not provided: " << requiredArg << endl;
exit(8);
}
}
}
7 changes: 2 additions & 5 deletions libs/core/src/EventProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ bool EventProcessor::PassesTriggerCuts(const shared_ptr<Event> event) {
for (auto& triggerName : triggerNames) {
passes = false;
try {
passes = event->Get(triggerName);
passes = event->GetAs<bool>(triggerName);
} catch (Exception&) {
if (find(triggerWarningsPrinted.begin(), triggerWarningsPrinted.end(), triggerName) == triggerWarningsPrinted.end()) {
warn() << "Trigger not present: " << triggerName << endl;
triggerWarningsPrinted.push_back(triggerName);
}
warn() << "Trigger not present: " << triggerName << endl;
}
if (passes) return true;
}
Expand Down
10 changes: 5 additions & 5 deletions libs/core/src/EventWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ int FilterBranch(T* vec, const std::vector<int>& keepIndices) {

EventWriter::EventWriter(const shared_ptr<EventReader> &eventReader_) : eventReader(eventReader_) {
auto &config = ConfigManager::GetInstance();
string outputFilePath;
config.GetValue("treeOutputFilePath", outputFilePath);

try {
Expand All @@ -37,15 +36,15 @@ EventWriter::EventWriter(const shared_ptr<EventReader> &eventReader_) : eventRea
branchesToRemove = {}; // Remove no branches by default
}

SetupOutputTree(outputFilePath);
SetupOutputTree();
}

EventWriter::~EventWriter() {}

void EventWriter::SetupOutputTree(string outFileName) {
makeParentDirectories(outFileName);
void EventWriter::SetupOutputTree() {
makeParentDirectories(outputFilePath);

outFile = new TFile(outFileName.c_str(), "recreate");
outFile = new TFile(outputFilePath.c_str(), "recreate");
outFile->cd();

for (auto &[name, tree] : eventReader->inputTrees) {
Expand Down Expand Up @@ -104,5 +103,6 @@ void EventWriter::Save() {
for (auto &[name, tree] : outputTrees) {
tree->Write();
}
info() << "Saved output trees to " << outputFilePath << endl;
outFile->Close();
}
3 changes: 2 additions & 1 deletion pylibs/plotting/Legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Legend:
y2: float = 0.5
options: str = ""
title: str = ""
text_size: float = 20

def getRootLegend(self):
legend = TLegend(self.x1, self.y1, self.x2, self.y2)
Expand All @@ -21,7 +22,7 @@ def __setupLegend(self, legend):
# legend.SetFillColor(0)
# legend.SetFillStyle(0)
legend.SetTextFont(43)
legend.SetTextSize(20)
legend.SetTextSize(self.text_size)

# set legend title
if self.title != "":
Expand Down
2 changes: 1 addition & 1 deletion pylibs/plotting/Sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum

from Legend import Legend
from Logger import error
from Logger import fatal

# enum class with signal, background, data

Expand Down