5 #include "TEfficiency.h"
17 descriptions.
add(
"gemEfficiencyHarvesterDefault",
desc);
21 const TH1F*
passed,
const TH1F*
total,
const char*
name,
const char*
title,
const double confidence_level) {
22 if (not TEfficiency::CheckConsistency(*
passed, *
total)) {
27 const TAxis* total_x =
total->GetXaxis();
29 TProfile* eff_profile =
new TProfile(
name,
title, total_x->GetNbins(), total_x->GetXmin(), total_x->GetXmax());
30 eff_profile->GetXaxis()->SetTitle(total_x->GetTitle());
31 eff_profile->GetYaxis()->SetTitle(
"Efficiency");
34 double num_passed =
passed->GetBinContent(
bin);
35 double num_total =
total->GetBinContent(
bin);
38 eff_profile->SetBinEntries(
bin, 0);
44 double lower_bound = TEfficiency::ClopperPearson(num_total, num_passed, confidence_level,
false);
45 double upper_bound = TEfficiency::ClopperPearson(num_total, num_passed, confidence_level,
true);
51 eff_profile->SetBinError(
bin,
error);
52 eff_profile->SetBinEntries(
bin, 1);
62 if (not TEfficiency::CheckConsistency(*
passed, *
total)) {
68 TH2F* eff_hist = dynamic_cast<TH2F*>(eff.CreateHistogram());
69 eff_hist->SetName(
name);
70 eff_hist->SetTitle(
title);
72 const TAxis* total_x =
total->GetXaxis();
73 TAxis* eff_hist_x = eff_hist->GetXaxis();
74 eff_hist_x->SetTitle(total_x->GetTitle());
76 const char*
label = total_x->GetBinLabel(
bin);
80 const TAxis* total_y =
total->GetYaxis();
81 TAxis* eff_hist_y = eff_hist->GetYaxis();
82 eff_hist_y->SetTitle(total_y->GetTitle());
84 const char*
label = total_y->GetBinLabel(
bin);
96 std::map<std::string, std::pair<const MonitorElement*, const MonitorElement*> > me_pairs;
108 const bool is_matched =
name.find(
matched) != std::string::npos;
114 if (me_pairs.find(
key) == me_pairs.end()) {
115 me_pairs[
key] = {
nullptr,
nullptr};
119 me_pairs[
key].first =
me;
121 me_pairs[
key].second =
me;
124 for (
auto&& [
key,
value] : me_pairs) {
125 const auto& [me_passed, me_total] =
value;
126 if (me_passed ==
nullptr) {
131 if (me_total ==
nullptr) {
136 if (me_passed->kind() != me_total->kind()) {
145 TH1F* h_passed = me_passed->getTH1F();
146 if (h_passed ==
nullptr) {
152 TH1F* h_total = me_total->getTH1F();
153 if (h_total ==
nullptr) {
160 if (eff ==
nullptr) {
168 TH2F* h_passed = me_passed->
getTH2F();
169 if (h_passed ==
nullptr) {
175 TH2F* h_total = me_total->getTH2F();
176 if (h_total ==
nullptr) {
183 if (eff ==
nullptr) {
198 std::vector<std::string> tokens;
199 size_t delimiter_pos;
200 size_t delimiter_len =
delimiter.length();
201 while ((delimiter_pos =
name.find(
'_')) != std::string::npos) {
202 tokens.push_back(
name.substr(0, delimiter_pos));
203 name.erase(0, delimiter_pos + delimiter_len);
205 tokens.push_back(
name);
221 const size_t num_tokens = tokens.size();
223 if (num_tokens != 2) {
224 return std::make_tuple(
"", -1, -1);
228 std::string region_sign = tokens.front().substr(0, 1);
230 TString station_str = tokens.front().substr(1, 1);
233 TString ieta_str = tokens.back().substr(1);
235 const int station = station_str.IsDigit() ? station_str.Atoi() : -1;
236 const int ieta = ieta_str.IsDigit() ? ieta_str.Atoi() : -1;
238 return std::make_tuple(region_sign,
station,
ieta);
250 std::vector<std::tuple<const TH1F*, std::pair<std::string, int>,
int> > hist_vector;
252 std::vector<std::pair<std::string, int> > re_st_vec;
254 std::vector<int> ieta_vec;
267 const TH1F*
hist =
me->getTH1F();
268 if (
hist ==
nullptr) {
278 std::pair<std::string, int> region_station(region_sign,
station);
280 hist_vector.emplace_back(
hist, region_station,
ieta);
281 if (
std::find(re_st_vec.begin(), re_st_vec.end(), region_station) == re_st_vec.end())
282 re_st_vec.push_back(region_station);
283 if (
std::find(ieta_vec.begin(), ieta_vec.end(),
ieta) == ieta_vec.end())
284 ieta_vec.push_back(
ieta);
287 if (hist_vector.empty()) {
294 auto f_sort = [](
const std::pair<std::string, int>& lhs,
const std::pair<std::string, int>& rhs) ->
bool {
295 if (lhs.first == rhs.first) {
296 if (lhs.first ==
"-")
297 return lhs.second > rhs.second;
299 return lhs.second < rhs.second;
302 return (lhs.first ==
"-");
306 std::sort(re_st_vec.begin(), re_st_vec.end(), f_sort);
307 std::sort(ieta_vec.begin(), ieta_vec.end());
309 const int num_st = re_st_vec.size();
310 const int num_ieta = ieta_vec.size();
313 TString tmp_title{std::get<0>(hist_vector.front())->GetTitle()};
315 const TObjArray* tokens = tmp_title.Tokenize(
":");
316 const TString title_prefix = dynamic_cast<TObjString*>(tokens->At(0))->GetString();
318 const TString h_mean_name =
prefix +
"_mean";
319 const TString h_stddev_name =
prefix +
"_stddev";
320 const TString h_skewness_name =
prefix +
"_skewness";
322 const TString h_mean_title = title_prefix +
" : Mean";
323 const TString h_stddev_title = title_prefix +
" : Standard Deviation";
324 const TString h_skewness_title = title_prefix +
" : Skewness";
326 TH2F* h_mean =
new TH2F(h_mean_name, h_mean_title, num_ieta, 0.5, num_ieta + 0.5, num_st, 0.5, num_st + 0.5);
328 h_mean->GetXaxis()->SetTitle(
"i#eta");
329 for (
unsigned int idx = 0;
idx < ieta_vec.size();
idx++) {
330 const int xbin =
idx + 1;
331 const char*
label = Form(
"%d", ieta_vec[
idx]);
332 h_mean->GetXaxis()->SetBinLabel(xbin,
label);
335 for (
unsigned int idx = 0;
idx < re_st_vec.size();
idx++) {
337 const char*
label = Form(
"GE%s%d/1", region_sign.c_str(),
station);
338 const int ybin =
idx + 1;
339 h_mean->GetYaxis()->SetBinLabel(ybin,
label);
342 TH2F* h_stddev = dynamic_cast<TH2F*>(h_mean->Clone(h_stddev_name));
343 TH2F* h_skewness = dynamic_cast<TH2F*>(h_mean->Clone(h_skewness_name));
345 h_stddev->SetTitle(h_stddev_title);
346 h_skewness->SetTitle(h_skewness_title);
349 for (
auto [
hist, region_station,
ieta] : hist_vector) {
362 h_mean->SetBinContent(xbin, ybin,
hist->GetMean());
363 h_stddev->SetBinContent(xbin, ybin,
hist->GetStdDev());
366 const double skewness =
hist->GetSkewness();
368 h_skewness->SetBinContent(xbin, ybin, skewness);
370 h_mean->SetBinError(xbin, ybin,
hist->GetMeanError());
371 h_stddev->SetBinError(xbin, ybin,
hist->GetStdDevError());
372 h_skewness->SetBinError(xbin, ybin,
hist->GetSkewness(11));
375 for (
auto&& each : {h_mean, h_stddev, h_skewness}) {
376 ibooker.
book2D(each->GetName(), each);