|
@@ -90,27 +90,33 @@ namespace fv_root_util {
|
|
namespace fv_root {
|
|
namespace fv_root {
|
|
using namespace fv;
|
|
using namespace fv;
|
|
|
|
|
|
- struct TH1Params {
|
|
|
|
|
|
+ struct THParams {
|
|
std::string label_x;
|
|
std::string label_x;
|
|
- int nbins;
|
|
|
|
- double low;
|
|
|
|
- double high;
|
|
|
|
|
|
+ int nbins_x;
|
|
|
|
+ double low_x;
|
|
|
|
+ double high_x;
|
|
std::string label_y;
|
|
std::string label_y;
|
|
|
|
+ int nbins_y;
|
|
|
|
+ double low_y;
|
|
|
|
+ double high_y;
|
|
|
|
|
|
- static TH1Params lookup(const std::string &¶m_key) {
|
|
|
|
|
|
+ static THParams lookup(const std::string &¶m_key) {
|
|
auto hist_params = fv_util::the_config->get("hist-params");
|
|
auto hist_params = fv_util::the_config->get("hist-params");
|
|
if (!hist_params[param_key]) {
|
|
if (!hist_params[param_key]) {
|
|
- CRITICAL(
|
|
|
|
- "Key \"" << param_key << "\" does not exist under hist-params in supplied config file. Add it!",
|
|
|
|
- true);
|
|
|
|
|
|
+ CRITICAL("Key \"" << param_key
|
|
|
|
+ << "\" does not exist under hist-params in supplied config file. Add it!",
|
|
|
|
+ true);
|
|
} else {
|
|
} else {
|
|
auto params = hist_params[param_key];
|
|
auto params = hist_params[param_key];
|
|
- return TH1Params({params["label_x"].as<std::string>(),
|
|
|
|
- params["nbins"].as<int>(),
|
|
|
|
- params["low"].as<double>(),
|
|
|
|
- params["high"].as<double>(),
|
|
|
|
- params["label_y"].as<std::string>()
|
|
|
|
- });
|
|
|
|
|
|
+ return THParams({params["label_x"].as<std::string>(""),
|
|
|
|
+ params["nbins_x"].as<int>(20),
|
|
|
|
+ params["low_x"].as<double>(0),
|
|
|
|
+ params["high_x"].as<double>(1),
|
|
|
|
+ params["label_y"].as<std::string>(""),
|
|
|
|
+ params["nbins_y"].as<int>(20),
|
|
|
|
+ params["low_y"].as<double>(0),
|
|
|
|
+ params["high_y"].as<double>(1)
|
|
|
|
+ });
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -120,18 +126,18 @@ namespace fv_root {
|
|
class ContainerTH1 : public Container<TH1, V> {
|
|
class ContainerTH1 : public Container<TH1, V> {
|
|
protected:
|
|
protected:
|
|
std::string title;
|
|
std::string title;
|
|
- TH1Params params;
|
|
|
|
|
|
+ THParams params;
|
|
|
|
|
|
public:
|
|
public:
|
|
- ContainerTH1(const std::string &name, const std::string &title, const TH1Params ¶ms)
|
|
|
|
|
|
+ ContainerTH1(const std::string &name, const std::string &title, const THParams ¶ms)
|
|
: Container<TH1, V>(name), title(title), params(params) {
|
|
: Container<TH1, V>(name), title(title), params(params) {
|
|
this->container = new TH1D(this->get_name().c_str(), this->title.c_str(),
|
|
this->container = new TH1D(this->get_name().c_str(), this->title.c_str(),
|
|
- params.nbins, params.low, params.high);
|
|
|
|
|
|
+ params.nbins_x, params.low_x, params.high_x);
|
|
this->container->SetXTitle(params.label_x.c_str());
|
|
this->container->SetXTitle(params.label_x.c_str());
|
|
this->container->SetYTitle(params.label_y.c_str());
|
|
this->container->SetYTitle(params.label_y.c_str());
|
|
}
|
|
}
|
|
|
|
|
|
- ContainerTH1(const std::string &name, const TH1Params ¶ms)
|
|
|
|
|
|
+ ContainerTH1(const std::string &name, const THParams ¶ms)
|
|
: ContainerTH1<V>(name, name, params) { }
|
|
: ContainerTH1<V>(name, name, params) { }
|
|
|
|
|
|
void fill(const V &v) {
|
|
void fill(const V &v) {
|
|
@@ -157,45 +163,13 @@ namespace fv_root {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- struct TH2Params {
|
|
|
|
- std::string label_x;
|
|
|
|
- int nbins_x;
|
|
|
|
- double low_x;
|
|
|
|
- double high_x;
|
|
|
|
- std::string label_y;
|
|
|
|
- int nbins_y;
|
|
|
|
- double low_y;
|
|
|
|
- double high_y;
|
|
|
|
-
|
|
|
|
- static TH2Params lookup(const std::string &¶m_key) {
|
|
|
|
- auto hist_params = fv_util::the_config->get("hist-params");
|
|
|
|
- if (!hist_params[param_key]) {
|
|
|
|
- CRITICAL(
|
|
|
|
- "Key \"" << param_key << "\" does not exist under hist-params in supplied config file. Add it!",
|
|
|
|
- true);
|
|
|
|
- } else {
|
|
|
|
- auto params = hist_params[param_key];
|
|
|
|
- return TH2Params({params["label_x"].as<std::string>(),
|
|
|
|
- params["nbins_x"].as<int>(),
|
|
|
|
- params["low_x"].as<double>(),
|
|
|
|
- params["high_x"].as<double>(),
|
|
|
|
- params["label_y"].as<std::string>(),
|
|
|
|
- params["nbins_y"].as<int>(),
|
|
|
|
- params["low_y"].as<double>(),
|
|
|
|
- params["high_y"].as<double>()
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
template<typename V>
|
|
template<typename V>
|
|
class ContainerTH2 : public Container<TH2, V> {
|
|
class ContainerTH2 : public Container<TH2, V> {
|
|
private:
|
|
private:
|
|
std::string title;
|
|
std::string title;
|
|
- TH2Params params;
|
|
|
|
|
|
+ THParams params;
|
|
public:
|
|
public:
|
|
- ContainerTH2(const std::string &name, const std::string &title, TH2Params params)
|
|
|
|
|
|
+ ContainerTH2(const std::string &name, const std::string &title, THParams params)
|
|
: Container<TH2, V>(name), title(title), params(params) {
|
|
: Container<TH2, V>(name), title(title), params(params) {
|
|
this->container = new TH2D(this->get_name().c_str(), this->title.c_str(),
|
|
this->container = new TH2D(this->get_name().c_str(), this->title.c_str(),
|
|
params.nbins_x, params.low_x, params.high_x,
|
|
params.nbins_x, params.low_x, params.high_x,
|
|
@@ -204,7 +178,7 @@ namespace fv_root {
|
|
this->container->SetYTitle(params.label_y.c_str());
|
|
this->container->SetYTitle(params.label_y.c_str());
|
|
}
|
|
}
|
|
|
|
|
|
- ContainerTH2(const std::string &name, const TH2Params ¶ms)
|
|
|
|
|
|
+ ContainerTH2(const std::string &name, const THParams ¶ms)
|
|
: ContainerTH2<V>(name, name, params) { }
|
|
: ContainerTH2<V>(name, name, params) { }
|
|
|
|
|
|
void fill(const V& x, const V& y) {
|
|
void fill(const V& x, const V& y) {
|
|
@@ -306,14 +280,14 @@ namespace fv_root {
|
|
TH1F den;
|
|
TH1F den;
|
|
TH1F eff;
|
|
TH1F eff;
|
|
|
|
|
|
- TH1Params params;
|
|
|
|
|
|
+ THParams params;
|
|
|
|
|
|
public:
|
|
public:
|
|
- EfficiencyContainer(const std::string &name, TH1Params params)
|
|
|
|
|
|
+ EfficiencyContainer(const std::string &name, THParams params)
|
|
: Container<TH1F, V>(name),
|
|
: Container<TH1F, V>(name),
|
|
- num{(name + "_num").c_str(), (name + "_num").c_str(), params.nbins, params.low, params.high},
|
|
|
|
- den{(name + "_den").c_str(), (name + "_den").c_str(), params.nbins, params.low, params.high},
|
|
|
|
- eff{name.c_str(), name.c_str(), params.nbins, params.low, params.high}, params(params) {
|
|
|
|
|
|
+ num{(name + "_num").c_str(), (name + "_num").c_str(), params.nbins_x, params.low_x, params.high_x},
|
|
|
|
+ den{(name + "_den").c_str(), (name + "_den").c_str(), params.nbins_x, params.low_x, params.high_x},
|
|
|
|
+ eff{name.c_str(), name.c_str(), params.nbins_x, params.low_x, params.high_x}, params(params) {
|
|
num.SetXTitle(params.label_x.c_str());
|
|
num.SetXTitle(params.label_x.c_str());
|
|
num.SetYTitle(params.label_y.c_str());
|
|
num.SetYTitle(params.label_y.c_str());
|
|
den.SetXTitle(params.label_x.c_str());
|
|
den.SetXTitle(params.label_x.c_str());
|
|
@@ -341,5 +315,51 @@ namespace fv_root {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ template<typename V>
|
|
|
|
+ class EfficiencyContainer2D : public Container<TH2F, V> {
|
|
|
|
+ private:
|
|
|
|
+ TH2F num;
|
|
|
|
+ TH2F den;
|
|
|
|
+ TH2F eff;
|
|
|
|
+
|
|
|
|
+ THParams params;
|
|
|
|
+
|
|
|
|
+ public:
|
|
|
|
+ EfficiencyContainer2D(const std::string &name, THParams params)
|
|
|
|
+ : Container<TH2F, V>(name),
|
|
|
|
+ num{(name + "_num").c_str(), (name + "_num").c_str(),
|
|
|
|
+ params.nbins_x, params.low_x, params.high_x, params.nbins_y, params.low_y, params.high_y},
|
|
|
|
+ den{(name + "_den").c_str(), (name + "_den").c_str(),
|
|
|
|
+ params.nbins_x, params.low_x, params.high_x, params.nbins_y, params.low_y, params.high_y},
|
|
|
|
+ eff{name.c_str(), name.c_str(),
|
|
|
|
+ params.nbins_x, params.low_x, params.high_x, params.nbins_y, params.low_y, params.high_y},
|
|
|
|
+ params(params) {
|
|
|
|
+ num.SetXTitle(params.label_x.c_str());
|
|
|
|
+ num.SetYTitle(params.label_y.c_str());
|
|
|
|
+ den.SetXTitle(params.label_x.c_str());
|
|
|
|
+ den.SetYTitle(params.label_y.c_str());
|
|
|
|
+ eff.SetXTitle(params.label_x.c_str());
|
|
|
|
+ eff.SetYTitle(params.label_y.c_str());
|
|
|
|
+ this->container = &eff;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TH2F *get_container() {
|
|
|
|
+ eff.Sumw2();
|
|
|
|
+ eff.Divide(&num, &den, 1, 1, "B");
|
|
|
|
+ return this->container;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void save_as(const std::string &fname, const SaveOption &option = SaveOption::PNG) {
|
|
|
|
+ fv_root_util::save_as(this->get_container(), fname, option);
|
|
|
|
+ fv_root_util::save_as(&num, fname, option);
|
|
|
|
+ fv_root_util::save_as(&den, fname, option);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void fill(const V& x,const V& y, bool pass) {
|
|
|
|
+ den.Fill(x, y);
|
|
|
|
+ if (pass) num.Fill(x, y);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
}
|
|
}
|
|
#endif // root_container_hpp
|
|
#endif // root_container_hpp
|