File indexing completed on 2024-04-06 12:07:36
0001 #include "DQM/HLTEvF/plugins/DQMCorrelationClient.h"
0002
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004
0005
0006
0007
0008 DQMCorrelationClient::DQMCorrelationClient(const edm::ParameterSet& iConfig)
0009 : me1onX_(iConfig.getParameter<bool>("me1onX")),
0010 meXpset_(me1onX_ ? getHistoPSet(iConfig.getParameter<edm::ParameterSet>("me1"))
0011 : getHistoPSet(iConfig.getParameter<edm::ParameterSet>("me2"))),
0012 meYpset_(me1onX_ ? getHistoPSet(iConfig.getParameter<edm::ParameterSet>("me2"))
0013 : getHistoPSet(iConfig.getParameter<edm::ParameterSet>("me1"))),
0014 mepset_(getOutputHistoPSet(iConfig.getParameter<edm::ParameterSet>("me"))) {
0015 edm::LogInfo("DQMCorrelationClient") << "Constructor DQMCorrelationClient::DQMCorrelationClient " << std::endl;
0016
0017 correlation_ = nullptr;
0018 }
0019
0020 MEPSet DQMCorrelationClient::getHistoPSet(edm::ParameterSet pset) {
0021 return MEPSet{
0022 pset.getParameter<std::string>("name"),
0023 pset.getParameter<std::string>("folder"),
0024 pset.getParameter<bool>("profileX"),
0025 };
0026 }
0027
0028 OutputMEPSet DQMCorrelationClient::getOutputHistoPSet(edm::ParameterSet pset) {
0029 return OutputMEPSet{
0030 pset.getParameter<std::string>("name"),
0031 pset.getParameter<std::string>("folder"),
0032 pset.getParameter<bool>("doXaxis"),
0033 pset.getParameter<int>("nbinsX"),
0034 pset.getParameter<double>("xminX"),
0035 pset.getParameter<double>("xmaxX"),
0036 pset.getParameter<bool>("doYaxis"),
0037 pset.getParameter<int>("nbinsY"),
0038 pset.getParameter<double>("xminY"),
0039 pset.getParameter<double>("xmaxY"),
0040 };
0041 }
0042
0043
0044
0045
0046 void DQMCorrelationClient::beginJob() {
0047 edm::LogInfo("DQMCorrelationClient") << "DQMCorrelationClient::beginJob " << std::endl;
0048 }
0049
0050 TH1* DQMCorrelationClient::getTH1(MonitorElement* me, bool profileX = true) {
0051 TH1* th1 = nullptr;
0052
0053 MonitorElement::Kind kind = me->kind();
0054 switch (kind) {
0055 case (MonitorElement::Kind::TH2D):
0056 th1 = (profileX ? me->getTH2D()->ProfileX() : me->getTH2D()->ProfileY());
0057 break;
0058 case (MonitorElement::Kind::TH2F):
0059 th1 = (profileX ? me->getTH2F()->ProfileX() : me->getTH2F()->ProfileY());
0060 break;
0061 case (MonitorElement::Kind::TH2S):
0062 th1 = (profileX ? me->getTH2S()->ProfileX() : me->getTH2S()->ProfileY());
0063 break;
0064 case (MonitorElement::Kind::TPROFILE):
0065 th1 = me->getTH1();
0066 break;
0067 default:
0068 break;
0069 }
0070
0071 return th1;
0072 }
0073 void DQMCorrelationClient::setAxisTitle(MonitorElement* meX, MonitorElement* meY) {
0074 if (correlation_ == nullptr)
0075 return;
0076 correlation_->setAxisTitle(meX->getTH1()->GetYaxis()->GetTitle(), 1);
0077 correlation_->setAxisTitle(meY->getTH1()->GetYaxis()->GetTitle(), 2);
0078
0079 if (!mepset_.doXaxis) {
0080 TAxis* axis = (meX->getTH1()->GetYaxis());
0081 for (int i = 1; i <= axis->GetNbins(); ++i)
0082 correlation_->getTH1()->GetXaxis()->SetBinLabel(i, axis->GetBinLabel(i));
0083 }
0084
0085 if (!mepset_.doYaxis) {
0086 TAxis* axis = (meY->getTH1()->GetYaxis());
0087 for (int i = 1; i <= axis->GetNbins(); ++i)
0088 correlation_->getTH1()->GetYaxis()->SetBinLabel(i, axis->GetBinLabel(i));
0089 }
0090 }
0091
0092
0093
0094
0095 void DQMCorrelationClient::dqmEndJob(DQMStore::IBooker& ibooker_, DQMStore::IGetter& igetter_) {
0096 std::string hname = "";
0097
0098
0099 hname = meXpset_.folder + "/" + meXpset_.name;
0100 MonitorElement* meX = igetter_.get(hname);
0101 hname = meYpset_.folder + "/" + meYpset_.name;
0102 MonitorElement* meY = igetter_.get(hname);
0103
0104 if (!meX || !meY) {
0105 edm::LogError("DQMCorrelationClient")
0106 << "MEs not found! " << (!meX ? meXpset_.folder + "/" + meXpset_.name + " not found " : "")
0107 << (!meY ? meYpset_.folder + "/" + meYpset_.name + " not found " : "") << std::endl;
0108 return;
0109 }
0110
0111
0112 int nbinsX = (mepset_.doXaxis ? mepset_.nbinsX : meX->getNbinsY());
0113 double xminX = (mepset_.doXaxis ? mepset_.xminX : meX->getTH1()->GetYaxis()->GetXmin());
0114 double xmaxX = (mepset_.doXaxis ? mepset_.xmaxX : meX->getTH1()->GetYaxis()->GetXmax());
0115 int nbinsY = (mepset_.doYaxis ? mepset_.nbinsY : meY->getNbinsY());
0116 double xminY = (mepset_.doYaxis ? mepset_.xminY : meY->getTH1()->GetYaxis()->GetXmin());
0117 double xmaxY = (mepset_.doYaxis ? mepset_.xmaxY : meY->getTH1()->GetYaxis()->GetXmax());
0118
0119
0120 std::string currentFolder = mepset_.folder;
0121 ibooker_.setCurrentFolder(currentFolder);
0122
0123
0124 hname = mepset_.name;
0125 correlation_ = ibooker_.book2D(hname, hname, nbinsX, xminX, xmaxX, nbinsY, xminY, xmaxY);
0126 setAxisTitle(meX, meY);
0127
0128
0129 TH1* x = nullptr;
0130 TH1* y = nullptr;
0131 x = getTH1(meX, meXpset_.profileX);
0132 y = getTH1(meY, meYpset_.profileX);
0133
0134 size_t size = x->GetXaxis()->GetNbins();
0135
0136 std::vector<double> xvalue;
0137 std::vector<int> xbinvalue;
0138 for (size_t ibin = 1; ibin <= size; ++ibin) {
0139
0140 if (x->GetBinContent(ibin) == 0.)
0141 continue;
0142 xvalue.push_back(x->GetBinContent(ibin));
0143 xbinvalue.push_back(x->GetXaxis()->GetBinCenter(ibin));
0144 }
0145
0146 for (size_t i = 0; i < xbinvalue.size(); ++i) {
0147 int ybin = y->GetXaxis()->FindBin(xbinvalue[i]);
0148 double yvalue = y->GetBinContent(ybin);
0149 correlation_->Fill(xvalue[i], yvalue);
0150 }
0151 }
0152
0153
0154
0155
0156 void DQMCorrelationClient::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker_,
0157 DQMStore::IGetter& igetter_,
0158 edm::LuminosityBlock const& iLumi,
0159 edm::EventSetup const& iSetup) {
0160 edm::LogInfo("DQMCorrelationClient") << "DQMCorrelationClient::endLumi " << std::endl;
0161 }
0162
0163 void DQMCorrelationClient::fillMePSetDescription(edm::ParameterSetDescription& pset) {
0164 pset.add<std::string>("folder", "");
0165 pset.add<std::string>("name", "");
0166 pset.add<bool>("profileX", true);
0167 }
0168
0169 void DQMCorrelationClient::fillOutputMePSetDescription(edm::ParameterSetDescription& pset) {
0170
0171 pset.add<std::string>("folder");
0172 pset.add<std::string>("name");
0173 pset.add<bool>("doXaxis", true);
0174 pset.add<int>("nbinsX", 2500);
0175 pset.add<double>("xminX", 0.);
0176 pset.add<double>("xmaxX", 2500.);
0177 pset.add<bool>("doYaxis", true);
0178 pset.add<int>("nbinsY", 2500);
0179 pset.add<double>("xminY", 0.);
0180 pset.add<double>("xmaxY", 2500.);
0181 }
0182
0183 void DQMCorrelationClient::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0184 edm::ParameterSetDescription desc;
0185 desc.add<bool>("me1onX", true);
0186
0187 edm::ParameterSetDescription mePSet;
0188 fillOutputMePSetDescription(mePSet);
0189 desc.add<edm::ParameterSetDescription>("me", mePSet);
0190
0191 edm::ParameterSetDescription me1PSet;
0192 fillMePSetDescription(me1PSet);
0193 desc.add<edm::ParameterSetDescription>("me1", me1PSet);
0194
0195 edm::ParameterSetDescription me2PSet;
0196 fillMePSetDescription(me2PSet);
0197 desc.add<edm::ParameterSetDescription>("me2", me2PSet);
0198
0199 descriptions.add("dqmCorrelationClient", desc);
0200 }
0201
0202
0203 #include "FWCore/Framework/interface/MakerMacros.h"
0204 DEFINE_FWK_MODULE(DQMCorrelationClient);