Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-26 22:39:24

0001 #include "DQM/GEM/plugins/GEMEfficiencyHarvester.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/Utilities/interface/isFinite.h"
0005 
0006 GEMEfficiencyHarvester::GEMEfficiencyHarvester(const edm::ParameterSet& ps)
0007     : GEMDQMEfficiencyClientBase(ps), kFolders_(ps.getUntrackedParameter<std::vector<std::string> >("folders")) {}
0008 
0009 GEMEfficiencyHarvester::~GEMEfficiencyHarvester() {}
0010 
0011 void GEMEfficiencyHarvester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0012   edm::ParameterSetDescription desc;
0013 
0014   // GEMDQMEfficiencyClientBase
0015   desc.addUntracked<double>("confidenceLevel", 0.683);  // 1-sigma
0016   desc.addUntracked<std::string>("logCategory", "GEMEfficiencyHarvester");
0017 
0018   // GEMEfficiencyHarvester
0019   desc.addUntracked<std::vector<std::string> >("folders", {"GEM/Efficiency/muonSTA"});
0020   descriptions.add("gemEfficiencyHarvester", desc);
0021 }
0022 
0023 // boook MEs for
0024 //   - efficiency vs camber id
0025 //   - efficiency vs ieta
0026 // by projecting MEs used for 2d chamber-ieta efficiency.
0027 void GEMEfficiencyHarvester::bookDetector1DEfficiency(DQMStore::IBooker& ibooker,
0028                                                       DQMStore::IGetter& igetter,
0029                                                       const std::string& folder) {
0030   const std::map<std::string, MEPair> me_pairs = makeEfficiencySourcePair(ibooker, igetter, folder, "chamber_ieta_");
0031 
0032   for (const auto& [key, value] : me_pairs) {
0033     // numerator and denominator
0034     const auto& [me_num, me_den] = value;
0035 
0036     if (me_num->kind() != MonitorElement::Kind::TH2F) {
0037       edm::LogError(kLogCategory_) << key << "expected TH2F but got ";  // TODO
0038       continue;
0039     }
0040 
0041     const TH2F* h_num = me_num->getTH2F();
0042     if (h_num == nullptr) {
0043       edm::LogError(kLogCategory_) << "numerator: failed to get TH2F from MonitorElement" << key;
0044       continue;
0045     }
0046 
0047     const TH2F* h_den = me_den->getTH2F();
0048     if (h_den == nullptr) {
0049       edm::LogError(kLogCategory_) << "denominator: failed to get TH2F from MonitorElement" << key;
0050       continue;
0051     }
0052 
0053     const auto [parsing_success, var_name, gem_name, is_matched] = parseEfficiencySourceName(me_den->getName());
0054     if (not parsing_success) {
0055       edm::LogError(kLogCategory_) << "failed to parse " << me_den->getName();
0056       continue;
0057     }
0058 
0059     // TODO sanity-check
0060     const TH1F* h_chamber_num = projectHistogram(h_num, TH1::kXaxis);
0061     const TH1F* h_chamber_den = projectHistogram(h_den, TH1::kXaxis);
0062     const char* eff_chamber_name = Form("eff_chamber_%s", gem_name.c_str());
0063     if (TH1F* eff = makeEfficiency(h_chamber_num, h_chamber_den, eff_chamber_name)) {
0064       ibooker.book1D(eff_chamber_name, eff);
0065     }
0066 
0067     const TH1F* h_ieta_num = projectHistogram(h_num, TH1::kYaxis);
0068     const TH1F* h_ieta_den = projectHistogram(h_den, TH1::kYaxis);
0069     const char* eff_ieta_name = Form("eff_ieta_%s", gem_name.c_str());
0070     if (TH1F* eff = makeEfficiency(h_ieta_num, h_ieta_den, eff_ieta_name)) {
0071       ibooker.book1D(eff_ieta_name, eff);
0072     }
0073   }  // pairs
0074 }
0075 
0076 void GEMEfficiencyHarvester::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0077   for (const std::string& folder : kFolders_) {
0078     bookEfficiencyAuto(ibooker, igetter, folder);
0079     bookDetector1DEfficiency(ibooker, igetter, folder);
0080   }
0081 }