6 #include "TEfficiency.h" 11 : kConfidenceLevel_(ps.getUntrackedParameter<double>(
"confidenceLevel")),
12 kLogCategory_(ps.getUntrackedParameter<
std::
string>(
"logCategory")) {}
23 const bool success = TPRegexp(
"\\w+(?:_match)?_GE\\d1-(P|M)[0-9\\-]*").MatchB(
name);
25 return std::make_tuple(
success,
"",
"",
false);
29 const auto numerator_pattern_start =
name.find(numerator_pattern);
30 const bool is_numerator = numerator_pattern_start != std::string::npos;
34 name.erase(numerator_pattern_start, numerator_pattern.length());
39 const unsigned long last_pos =
name.find_last_of(
'_');
60 std::vector<std::string> tokens;
63 const std::regex re_station{
"GE\\d1"};
64 const std::regex re_region{
"(P|M)"};
65 const std::regex re_layer{
"L\\d"};
66 const std::regex re_chamber_layer{
"\\d+L\\d"};
67 const std::regex re_ieta{
"E\\d+"};
71 while ((
pos != std::string::npos)
or (last_pos != std::string::npos)) {
74 if (std::regex_match(
token, re_region)) {
77 }
else if (std::regex_match(
token, re_station)) {
80 }
else if (std::regex_match(
token, re_layer)) {
83 }
else if (std::regex_match(
token, re_chamber_layer)) {
84 const unsigned long layer_prefix_pos =
token.find(
'L');
86 layer = std::stoi(
token.substr(layer_prefix_pos + 1));
88 }
else if (std::regex_match(
token, re_ieta)) {
105 std::map<std::string, MEPair> me_pairs;
123 if (not parsing_success) {
130 if (me_pairs.find(
key) == me_pairs.end()) {
131 me_pairs[
key] = {
nullptr,
nullptr};
135 me_pairs[
key].first =
me;
137 me_pairs[
key].second =
me;
141 for (
auto it = me_pairs.cbegin();
it != me_pairs.cend();) {
142 auto [me_numerator, me_denominator] = (*it).second;
145 if (me_numerator ==
nullptr) {
148 }
else if (me_denominator ==
nullptr) {
151 }
else if (me_numerator->kind() != me_denominator->kind()) {
160 it = me_pairs.erase(
it);
168 const int nbins = src_axis->GetNbins();
169 if (src_axis->IsVariableBinSize()) {
170 std::vector<double>
edges;
174 edges.push_back(src_axis->GetBinLowEdge(
bin));
176 edges.push_back(src_axis->GetBinUpEdge(
nbins));
181 const double xlow = src_axis->GetBinLowEdge(1);
182 const double xup = src_axis->GetBinUpEdge(
nbins);
184 dst_hist->SetBins(
nbins, xlow, xup);
188 const TString
label{src_axis->GetBinLabel(
bin)};
189 if (
label.Length() > 0) {
190 dst_hist->GetXaxis()->SetBinLabel(
bin,
label);
202 if (pass.GetDimension() !=
total.GetDimension()) {
208 if (not TEfficiency::CheckBinning(pass,
total)) {
214 if (not TEfficiency::CheckEntries(pass,
total)) {
216 <<
" & " <<
total.GetName();
225 const TH1F* h_denominator,
228 if (h_numerator ==
nullptr) {
233 if (h_denominator ==
nullptr) {
242 if (
name ==
nullptr) {
243 name = Form(
"eff_%s", h_denominator->GetName());
246 if (
title ==
nullptr) {
247 title = h_denominator->GetTitle();
250 const TAxis* x_axis = h_denominator->GetXaxis();
253 TH1F* h_eff =
new TH1F();
254 h_eff->SetName(
name);
255 h_eff->SetTitle(
title);
256 h_eff->GetXaxis()->SetTitle(x_axis->GetTitle());
257 h_eff->GetYaxis()->SetTitle(
"Efficiency");
258 setBins(h_eff, h_denominator->GetXaxis());
261 const int nbins = x_axis->GetNbins();
263 const double passed = h_numerator->GetBinContent(
bin);
264 const double total = h_denominator->GetBinContent(
bin);
284 const TH2F* h_denominator,
287 if (h_numerator ==
nullptr) {
292 if (h_denominator ==
nullptr) {
301 if (
name ==
nullptr) {
302 name = Form(
"eff_%s", h_denominator->GetName());
305 if (
title ==
nullptr) {
306 title = h_denominator->GetTitle();
309 TEfficiency eff(*h_numerator, *h_denominator);
310 auto h_eff =
dynamic_cast<TH2F*
>(eff.CreateHistogram());
311 h_eff->SetName(
name);
312 h_eff->SetTitle(
title);
319 if ((on_which_axis != TH1::kXaxis) and (on_which_axis != TH1::kYaxis)) {
321 <<
" choose from [TH1::kXaxis (=1), TH1::kYaxis (=2)]";
325 const bool on_x_axis = (on_which_axis == TH1::kXaxis);
328 const TAxis* src_proj_axis = on_x_axis ? h_2d->GetXaxis() : h_2d->GetYaxis();
330 const TAxis* src_accum_axis = on_x_axis ? h_2d->GetYaxis() : h_2d->GetXaxis();
332 const TString
prefix = on_x_axis ?
"_proj_on_x" :
"_proj_on_y";
333 const TString
name = h_2d->GetName() +
prefix;
334 const TString
title = h_2d->GetTitle();
336 TH1F* h_proj =
new TH1F();
337 h_proj->SetName(
name);
338 h_proj->SetTitle(
title);
339 h_proj->GetXaxis()->SetTitle(src_proj_axis->GetTitle());
340 setBins(h_proj, src_proj_axis);
342 for (
int proj_bin = 1; proj_bin <= src_proj_axis->GetNbins(); proj_bin++) {
344 for (
int accum_bin = 1; accum_bin <= src_accum_axis->GetNbins(); accum_bin++) {
346 cumsum += h_2d->GetBinContent(proj_bin, accum_bin);
348 cumsum += h_2d->GetBinContent(accum_bin, proj_bin);
351 h_proj->SetBinContent(proj_bin, cumsum);
362 for (
auto& [
key,
value] : me_pairs) {
363 const auto& [me_numerator, me_denominator] =
value;
367 TH1F* h_numerator = me_numerator->getTH1F();
368 if (h_numerator ==
nullptr) {
373 TH1F* h_denominator = me_denominator->getTH1F();
374 if (h_denominator ==
nullptr) {
380 ibooker.
book1D(eff->GetName(), eff);
388 TH2F* h_numerator = me_numerator->
getTH2F();
389 if (h_numerator ==
nullptr) {
394 TH2F* h_denominator = me_denominator->getTH2F();
395 if (h_denominator ==
nullptr) {
401 ibooker.
book2D(eff->GetName(), eff);
410 <<
"0x" << std::hex << static_cast<int>(me_kind);
GEMDetId parseGEMLabel(const std::string, const std::string delimiter="-")
virtual void setCurrentFolder(std::string const &fullpath)
const double kConfidenceLevel_
virtual std::vector< std::string > getMEs() const
TH1F * makeEfficiency(const TH1F *, const TH1F *, const char *name=nullptr, const char *title=nullptr)
GEMDQMEfficiencyClientBase(const edm::ParameterSet &)
void setBins(TH1F *, const TAxis *)
const std::string kLogCategory_
void bookEfficiencyAuto(DQMStore::IBooker &, DQMStore::IGetter &, const std::string &)
Log< level::Error, false > LogError
bool checkConsistency(const TH1 &, const TH1 &)
virtual TH2F * getTH2F() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
TH1F * projectHistogram(const TH2F *, const unsigned int)
key
prepare the HTCondor submission files and eventually submit them
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
virtual MonitorElement * get(std::string const &fullpath) const
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
std::tuple< bool, std::string, std::string, bool > parseEfficiencySourceName(std::string)
std::map< std::string, MEPair > makeEfficiencySourcePair(DQMStore::IBooker &, DQMStore::IGetter &, const std::string &, const std::string prefix="")