File indexing completed on 2024-04-06 12:09:43
0001
0002
0003
0004
0005
0006
0007
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009
0010 #include "DQMServices/Core/interface/DQMStore.h"
0011
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016
0017 #include "DQMServices/Core/interface/DQMEDHarvester.h"
0018
0019 class TnPEfficiencyClient : public DQMEDHarvester {
0020 public:
0021 TnPEfficiencyClient(const edm::ParameterSet& pSet);
0022 ~TnPEfficiencyClient() override;
0023
0024 protected:
0025 void beginRun(const edm::Run&, const edm::EventSetup&) override;
0026 void dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter&) override;
0027
0028 void dqmEndLuminosityBlock(DQMStore::IBooker&,
0029 DQMStore::IGetter&,
0030 edm::LuminosityBlock const&,
0031 edm::EventSetup const&) override;
0032
0033
0034 inline std::string topFolder() const { return subsystem + "/Segment_TnP/"; };
0035
0036 private:
0037 std::map<std::string, MonitorElement*> effHistos;
0038 std::vector<std::string> passNfailHistoNames;
0039 std::string subsystem;
0040 };
0041
0042 TnPEfficiencyClient::TnPEfficiencyClient(const edm::ParameterSet& pSet)
0043 : passNfailHistoNames(pSet.getUntrackedParameter<std::vector<std::string>>("histoNames")),
0044 subsystem(pSet.getUntrackedParameter<std::string>("subsystem")) {
0045 edm::LogVerbatim("DQMOffline|MuonDPG|TnPEfficiencyClient") << "TnPEfficiencyClient: Constructor called";
0046 };
0047
0048 TnPEfficiencyClient::~TnPEfficiencyClient() {
0049 edm::LogVerbatim("DQMOffline|MuonDPG|TnPEfficiencyClient") << "TnPEfficiencyClient: Constructor called";
0050 };
0051
0052 void TnPEfficiencyClient::beginRun(const edm::Run& run, const edm::EventSetup& setup) {}
0053
0054 void TnPEfficiencyClient::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0055 DQMStore::IGetter& igetter,
0056 edm::LuminosityBlock const& lumiSeg,
0057 edm::EventSetup const& setup) {
0058 edm::LogVerbatim("DQMOffline|MuonDPG|TnPEfficiencyClient") << "TnPEfficiencyClient: endluminosityBlock";
0059 }
0060
0061 void TnPEfficiencyClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0062 edm::LogVerbatim("DQMOffline|MuonDPG|TnPEfficiencyClient") << "TnPEfficiencyClient: endRun";
0063
0064 std::string outFolder = "Task";
0065
0066 ibooker.setCurrentFolder(topFolder() + outFolder + "/");
0067 std::string baseFolder = topFolder() + outFolder + "/";
0068
0069 TH1::SetDefaultSumw2(kTRUE);
0070
0071 for (const auto& s : passNfailHistoNames) {
0072 TH1::SetDefaultSumw2(kTRUE);
0073
0074 std::string passHistoName = s.substr(0, s.find(':'));
0075 std::string failHistoName = s.substr(s.find(':') + 1, s.length());
0076
0077 std::string histoName_pass = baseFolder + passHistoName;
0078 std::string histoName_fail = baseFolder + failHistoName;
0079
0080 MonitorElement* me_pass = igetter.get(histoName_pass);
0081 MonitorElement* me_fail = igetter.get(histoName_fail);
0082
0083 int fir = passHistoName.find('_');
0084 int sec = passHistoName.find('_', fir + 1);
0085 std::string chName = passHistoName.substr(0, fir);
0086 std::string specifier = passHistoName.substr(sec + 1);
0087 std::string effHistoName = chName + "_chamberEff_" + specifier;
0088
0089 if (!me_pass || !me_fail) {
0090 edm::LogWarning("TnPEfficiencyClient") << "Monitor Element not available" << std::endl;
0091 return;
0092 }
0093
0094
0095 if ((int)me_pass->kind() == DQMNet::DQM_PROP_TYPE_TH1F && (int)me_fail->kind() == DQMNet::DQM_PROP_TYPE_TH1F) {
0096 if (!(me_pass->getTH1F()) || !(me_fail->getTH1F())) {
0097 edm::LogWarning("TnPEfficiencyClient") << "Monitor Element not available" << std::endl;
0098 return;
0099 }
0100
0101 TH1F* h1_pass = me_pass->getTH1F();
0102 TH1F* h1_fail = me_fail->getTH1F();
0103
0104 const int nBinX_pass = h1_pass->GetNbinsX();
0105 const int nBinX_fail = h1_fail->GetNbinsX();
0106
0107 if (nBinX_pass != nBinX_fail) {
0108 edm::LogWarning("TnPEfficiencyClient")
0109 << "Histograms with different number of bins: unable to compute the ratio" << std::endl;
0110 return;
0111 }
0112
0113 TH1F* h1_den = (TH1F*)h1_pass->Clone();
0114 TH1F* h1_num = (TH1F*)h1_pass->Clone();
0115 h1_den->Sumw2();
0116 h1_num->Sumw2();
0117 h1_den->Add(h1_fail);
0118
0119 h1_num->Divide(h1_den);
0120 TH1F* h1_ratio = (TH1F*)h1_num->Clone();
0121
0122 effHistos[effHistoName] = ibooker.book1D(effHistoName, h1_ratio);
0123 effHistos[effHistoName]->setTitle(effHistoName);
0124 effHistos[effHistoName]->setAxisTitle("Efficiency", 2);
0125 }
0126
0127
0128 if ((int)me_pass->kind() == DQMNet::DQM_PROP_TYPE_TH2F && (int)me_fail->kind() == DQMNet::DQM_PROP_TYPE_TH2F) {
0129 if (!(me_pass->getTH2F()) || !(me_fail->getTH2F())) {
0130 edm::LogWarning("TnPEfficiencyClient")
0131 << "Monitor Element not available: unable to compute the ratio" << std::endl;
0132 return;
0133 }
0134
0135 TH2F* h2_pass = me_pass->getTH2F();
0136 TH2F* h2_fail = me_fail->getTH2F();
0137
0138 const int nBinX_pass = h2_pass->GetNbinsX();
0139 const int nBinX_fail = h2_fail->GetNbinsX();
0140 const int nBinY_pass = h2_pass->GetNbinsY();
0141 const int nBinY_fail = h2_fail->GetNbinsY();
0142
0143 if ((nBinX_pass != nBinX_fail) || (nBinY_pass != nBinY_fail)) {
0144 edm::LogWarning("TnPEfficiencyClient")
0145 << "Histograms with different number of bins: unable to compute the ratio" << std::endl;
0146 return;
0147 }
0148
0149 TH2F* h2_den = (TH2F*)h2_pass->Clone();
0150 TH2F* h2_num = (TH2F*)h2_pass->Clone();
0151 h2_den->Sumw2();
0152 h2_num->Sumw2();
0153 h2_den->Add(h2_fail);
0154
0155 h2_num->Divide(h2_den);
0156 TH2F* h2_ratio = (TH2F*)h2_num->Clone();
0157
0158 effHistos[effHistoName] = ibooker.book2D(effHistoName, h2_ratio);
0159 effHistos[effHistoName]->setTitle(effHistoName);
0160 effHistos[effHistoName]->setAxisTitle("Efficiency", 3);
0161 }
0162 }
0163
0164 return;
0165 }
0166
0167 DEFINE_FWK_MODULE(TnPEfficiencyClient);