6 #include "TEfficiency.h"
18 descriptions.
add(
"gemEfficiencyHarvesterDefault",
desc);
22 const TH1F*
passed,
const TH1F*
total,
const char*
name,
const char*
title,
const double confidence_level) {
23 if (not TEfficiency::CheckConsistency(*
passed, *
total)) {
28 const TAxis* total_x =
total->GetXaxis();
30 TProfile* eff_profile =
new TProfile(
name,
title, total_x->GetNbins(), total_x->GetXmin(), total_x->GetXmax());
31 eff_profile->GetXaxis()->SetTitle(total_x->GetTitle());
32 eff_profile->GetYaxis()->SetTitle(
"Efficiency");
35 double num_passed =
passed->GetBinContent(
bin);
36 double num_total =
total->GetBinContent(
bin);
39 eff_profile->SetBinEntries(
bin, 0);
45 double lower_bound = TEfficiency::ClopperPearson(num_total, num_passed, confidence_level,
false);
46 double upper_bound = TEfficiency::ClopperPearson(num_total, num_passed, confidence_level,
true);
52 eff_profile->SetBinError(
bin,
error);
53 eff_profile->SetBinEntries(
bin, 1);
63 if (not TEfficiency::CheckConsistency(*
passed, *
total)) {
69 TH2F* eff_hist = dynamic_cast<TH2F*>(eff.CreateHistogram());
70 eff_hist->SetName(
name);
71 eff_hist->SetTitle(
title);
73 const TAxis* total_x =
total->GetXaxis();
74 TAxis* eff_hist_x = eff_hist->GetXaxis();
75 eff_hist_x->SetTitle(total_x->GetTitle());
77 const char*
label = total_x->GetBinLabel(
bin);
81 const TAxis* total_y =
total->GetYaxis();
82 TAxis* eff_hist_y = eff_hist->GetYaxis();
83 eff_hist_y->SetTitle(total_y->GetTitle());
85 const char*
label = total_y->GetBinLabel(
bin);
97 std::map<std::string, std::pair<const MonitorElement*, const MonitorElement*> > me_pairs;
109 const bool is_matched =
name.find(
matched) != std::string::npos;
115 if (me_pairs.find(
key) == me_pairs.end()) {
116 me_pairs[
key] = {
nullptr,
nullptr};
120 me_pairs[
key].first =
me;
122 me_pairs[
key].second =
me;
125 for (
auto&& [
key,
value] : me_pairs) {
126 const auto& [me_passed, me_total] =
value;
127 if (me_passed ==
nullptr) {
132 if (me_total ==
nullptr) {
137 if (me_passed->kind() != me_total->kind()) {
146 TH1F* h_passed = me_passed->getTH1F();
147 if (h_passed ==
nullptr) {
153 TH1F* h_total = me_total->getTH1F();
154 if (h_total ==
nullptr) {
161 if (eff ==
nullptr) {
169 TH2F* h_passed = me_passed->
getTH2F();
170 if (h_passed ==
nullptr) {
176 TH2F* h_total = me_total->getTH2F();
177 if (h_total ==
nullptr) {
184 if (eff ==
nullptr) {
199 std::vector<std::string> tokens;
200 size_t delimiter_pos;
201 size_t delimiter_len =
delimiter.length();
202 while ((delimiter_pos =
name.find(
'_')) != std::string::npos) {
203 tokens.push_back(
name.substr(0, delimiter_pos));
204 name.erase(0, delimiter_pos + delimiter_len);
206 tokens.push_back(
name);
222 const size_t num_tokens = tokens.size();
224 if (num_tokens != 2) {
225 return std::make_tuple(
"", -1, -1);
229 std::string region_sign = tokens.front().substr(0, 1);
231 TString station_str = tokens.front().substr(1, 1);
234 TString ieta_str = tokens.back().substr(1);
236 const int station = station_str.IsDigit() ? station_str.Atoi() : -1;
237 const int ieta = ieta_str.IsDigit() ? ieta_str.Atoi() : -1;
239 return std::make_tuple(region_sign,
station,
ieta);
251 std::vector<std::tuple<const TH1F*, std::pair<std::string, int>,
int> > hist_vector;
253 std::vector<std::pair<std::string, int> > re_st_vec;
255 std::vector<int> ieta_vec;
268 const TH1F*
hist =
me->getTH1F();
269 if (
hist ==
nullptr) {
279 std::pair<std::string, int> region_station(region_sign,
station);
281 hist_vector.emplace_back(
hist, region_station,
ieta);
282 if (
std::find(re_st_vec.begin(), re_st_vec.end(), region_station) == re_st_vec.end())
283 re_st_vec.push_back(region_station);
284 if (
std::find(ieta_vec.begin(), ieta_vec.end(),
ieta) == ieta_vec.end())
285 ieta_vec.push_back(
ieta);
288 if (hist_vector.empty()) {
295 auto f_sort = [](
const std::pair<std::string, int>& lhs,
const std::pair<std::string, int>& rhs) ->
bool {
296 if (lhs.first == rhs.first) {
297 if (lhs.first ==
"-")
298 return lhs.second > rhs.second;
300 return lhs.second < rhs.second;
303 return (lhs.first ==
"-");
307 std::sort(re_st_vec.begin(), re_st_vec.end(), f_sort);
308 std::sort(ieta_vec.begin(), ieta_vec.end());
310 const int num_st = re_st_vec.size();
311 const int num_ieta = ieta_vec.size();
314 TString tmp_title{std::get<0>(hist_vector.front())->GetTitle()};
316 const TObjArray* tokens = tmp_title.Tokenize(
":");
317 const TString title_prefix = dynamic_cast<TObjString*>(tokens->At(0))->GetString();
319 const TString h_mean_name =
prefix +
"_mean";
320 const TString h_stddev_name =
prefix +
"_stddev";
321 const TString h_skewness_name =
prefix +
"_skewness";
323 const TString h_mean_title = title_prefix +
" : Mean";
324 const TString h_stddev_title = title_prefix +
" : Standard Deviation";
325 const TString h_skewness_title = title_prefix +
" : Skewness";
327 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);
329 h_mean->GetXaxis()->SetTitle(
"i#eta");
330 for (
unsigned int idx = 0;
idx < ieta_vec.size();
idx++) {
331 const int xbin =
idx + 1;
332 const char*
label = Form(
"%d", ieta_vec[
idx]);
333 h_mean->GetXaxis()->SetBinLabel(xbin,
label);
336 for (
unsigned int idx = 0;
idx < re_st_vec.size();
idx++) {
338 const char*
label = Form(
"GE%s%d/1", region_sign.c_str(),
station);
339 const int ybin =
idx + 1;
340 h_mean->GetYaxis()->SetBinLabel(ybin,
label);
343 TH2F* h_stddev = dynamic_cast<TH2F*>(h_mean->Clone(h_stddev_name));
344 TH2F* h_skewness = dynamic_cast<TH2F*>(h_mean->Clone(h_skewness_name));
346 h_stddev->SetTitle(h_stddev_title);
347 h_skewness->SetTitle(h_skewness_title);
350 for (
auto [
hist, region_station,
ieta] : hist_vector) {
363 h_mean->SetBinContent(xbin, ybin,
hist->GetMean());
364 h_stddev->SetBinContent(xbin, ybin,
hist->GetStdDev());
368 const double skewness =
hist->GetSkewness();
370 h_skewness->SetBinContent(xbin, ybin, skewness);
372 h_mean->SetBinError(xbin, ybin,
hist->GetMeanError());
373 h_stddev->SetBinError(xbin, ybin,
hist->GetStdDevError());
374 h_skewness->SetBinError(xbin, ybin,
hist->GetSkewness(11));
377 for (
auto&& each : {h_mean, h_stddev, h_skewness}) {
378 ibooker.
book2D(each->GetName(), each);