Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:00

0001 #include "DQM/L1TMonitorClient/interface/L1TGMTClient.h"
0002 
0003 #include "FWCore/ServiceRegistry/interface/Service.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "DQMServices/Core/interface/DQMStore.h"
0007 
0008 #include <sstream>
0009 
0010 L1TGMTClient::L1TGMTClient(const edm::ParameterSet& ps) {
0011   parameters_ = ps;
0012   initialize();
0013 }
0014 
0015 L1TGMTClient::~L1TGMTClient() { LogDebug("TriggerDQM") << "[TriggerDQM]: ending... "; }
0016 
0017 //--------------------------------------------------------
0018 void L1TGMTClient::initialize() {
0019   // base folder for the contents of this job
0020   monitorName_ = parameters_.getUntrackedParameter<std::string>("monitorName", "");
0021   LogDebug("TriggerDQM") << "Monitor name = " << monitorName_ << std::endl;
0022 
0023   output_dir_ = parameters_.getUntrackedParameter<std::string>("output_dir", "");
0024   LogDebug("TriggerDQM") << "DQM output dir = " << output_dir_ << std::endl;
0025 
0026   input_dir_ = parameters_.getUntrackedParameter<std::string>("input_dir", "");
0027   LogDebug("TriggerDQM") << "DQM input dir = " << input_dir_ << std::endl;
0028 
0029   m_runInEventLoop = parameters_.getUntrackedParameter<bool>("runInEventLoop", false);
0030   m_runInEndLumi = parameters_.getUntrackedParameter<bool>("runInEndLumi", false);
0031   m_runInEndRun = parameters_.getUntrackedParameter<bool>("runInEndRun", false);
0032   m_runInEndJob = parameters_.getUntrackedParameter<bool>("runInEndJob", false);
0033 }
0034 
0035 //--------------------------------------------------------
0036 void L1TGMTClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0037   // booking histograms in the output_dir_
0038 
0039   ibooker.setCurrentFolder(output_dir_);
0040 
0041   eff_eta_dtcsc = bookClone1DVB(ibooker, igetter, "eff_eta_dtcsc", "efficiency DTCSC vs eta", "eta_DTCSC_and_RPC");
0042 
0043   if (eff_eta_dtcsc != nullptr) {
0044     eff_eta_dtcsc->setAxisTitle("eta", 1);
0045     if (eff_eta_dtcsc->getTH1F()->GetSumw2N() == 0)
0046       eff_eta_dtcsc->enableSumw2();
0047   }
0048 
0049   eff_eta_rpc = bookClone1DVB(ibooker, igetter, "eff_eta_rpc", "efficiency RPC vs eta", "eta_DTCSC_and_RPC");
0050 
0051   if (eff_eta_rpc != nullptr) {
0052     eff_eta_rpc->setAxisTitle("eta", 1);
0053     if (eff_eta_rpc->getTH1F()->GetSumw2N() == 0)
0054       eff_eta_rpc->enableSumw2();
0055   }
0056 
0057   eff_phi_dtcsc = bookClone1D(ibooker, igetter, "eff_phi_dtcsc", "efficiency DTCSC vs phi", "phi_DTCSC_and_RPC");
0058 
0059   if (eff_phi_dtcsc != nullptr) {
0060     eff_phi_dtcsc->setAxisTitle("phi (deg)", 1);
0061     if (eff_phi_dtcsc->getTH1F()->GetSumw2N() == 0)
0062       eff_phi_dtcsc->enableSumw2();
0063   }
0064 
0065   eff_phi_rpc = bookClone1D(ibooker, igetter, "eff_phi_rpc", "efficiency RPC vs phi", "phi_DTCSC_and_RPC");
0066 
0067   if (eff_phi_rpc != nullptr) {
0068     eff_phi_rpc->setAxisTitle("phi (deg)", 1);
0069     if (eff_phi_rpc->getTH1F()->GetSumw2N() == 0)
0070       eff_phi_rpc->enableSumw2();
0071   }
0072 
0073   eff_etaphi_dtcsc =
0074       bookClone2D(ibooker, igetter, "eff_etaphi_dtcsc", "efficiency DTCSC vs eta and phi", "etaphi_DTCSC_and_RPC");
0075 
0076   if (eff_etaphi_dtcsc != nullptr) {
0077     eff_etaphi_dtcsc->setAxisTitle("eta", 1);
0078     eff_etaphi_dtcsc->setAxisTitle("phi (deg)", 2);
0079     if (eff_etaphi_dtcsc->getTH2F()->GetSumw2N() == 0)
0080       eff_etaphi_dtcsc->enableSumw2();
0081   }
0082 
0083   eff_etaphi_rpc =
0084       bookClone2D(ibooker, igetter, "eff_etaphi_rpc", "efficiency RPC vs eta and phi", "etaphi_DTCSC_and_RPC");
0085 
0086   if (eff_etaphi_rpc != nullptr) {
0087     eff_etaphi_rpc->setAxisTitle("eta", 1);
0088     eff_etaphi_rpc->setAxisTitle("phi (deg)", 2);
0089     if (eff_etaphi_rpc->getTH2F()->GetSumw2N() == 0)
0090       eff_etaphi_rpc->enableSumw2();
0091   }
0092 
0093   processHistograms(ibooker, igetter);
0094 }
0095 
0096 //--------------------------------------------------------
0097 
0098 void L1TGMTClient::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0099                                          DQMStore::IGetter& igetter,
0100                                          const edm::LuminosityBlock& lumiSeg,
0101                                          const edm::EventSetup& evSetup) {}
0102 
0103 //--------------------------------------------------------
0104 void L1TGMTClient::processHistograms(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0105   LogDebug("TriggerDQM") << "L1TGMTClient: processing..." << std::endl;
0106 
0107   makeEfficiency1D(ibooker, igetter, eff_eta_dtcsc, "eta_DTCSC_and_RPC", "eta_RPC_only");
0108   makeEfficiency1D(ibooker, igetter, eff_eta_rpc, "eta_DTCSC_and_RPC", "eta_DTCSC_only");
0109 
0110   makeEfficiency1D(ibooker, igetter, eff_phi_dtcsc, "phi_DTCSC_and_RPC", "phi_RPC_only");
0111   makeEfficiency1D(ibooker, igetter, eff_phi_rpc, "phi_DTCSC_and_RPC", "phi_DTCSC_only");
0112 
0113   makeEfficiency2D(ibooker, igetter, eff_etaphi_dtcsc, "etaphi_DTCSC_and_RPC", "etaphi_RPC_only");
0114   makeEfficiency2D(ibooker, igetter, eff_etaphi_rpc, "etaphi_DTCSC_and_RPC", "etaphi_DTCSC_only");
0115 }
0116 
0117 //////////////////////////////////////////////////////////////////////////////////////////////////
0118 void L1TGMTClient::makeRatio1D(DQMStore::IBooker& ibooker,
0119                                DQMStore::IGetter& igetter,
0120                                MonitorElement* mer,
0121                                std::string h1Name,
0122                                std::string h2Name) {
0123   igetter.setCurrentFolder(output_dir_);
0124 
0125   TH1F* h1 = get1DHisto(input_dir_ + "/" + h1Name, igetter);
0126   TH1F* h2 = get1DHisto(input_dir_ + "/" + h2Name, igetter);
0127 
0128   if (mer == nullptr) {
0129     LogDebug("TriggerDQM") << "\nL1TGMTClient::makeRatio1D: monitoring element zero, not able to retrieve histogram"
0130                            << std::endl;
0131     return;
0132   }
0133 
0134   TH1F* hr = mer->getTH1F();
0135 
0136   if (hr && h1 && h2) {
0137     hr->Divide(h1, h2, 1., 1., " ");
0138   }
0139 }
0140 
0141 //////////////////////////////////////////////////////////////////////////////////////////////////
0142 void L1TGMTClient::makeEfficiency1D(DQMStore::IBooker& ibooker,
0143                                     DQMStore::IGetter& igetter,
0144                                     MonitorElement* meeff,
0145                                     std::string heName,
0146                                     std::string hiName) {
0147   igetter.setCurrentFolder(output_dir_);
0148 
0149   TH1F* he = get1DHisto(input_dir_ + "/" + heName, igetter);
0150   TH1F* hi = get1DHisto(input_dir_ + "/" + hiName, igetter);
0151 
0152   if (meeff == nullptr) {
0153     LogDebug("TriggerDQM") << "L1TGMTClient::makeEfficiency1D: monitoring element zero, not able to retrieve histogram"
0154                            << std::endl;
0155     return;
0156   }
0157 
0158   TH1F* heff = meeff->getTH1F();
0159 
0160   if (heff && he && hi) {
0161     TH1F* hall = (TH1F*)he->Clone("hall");
0162     hall->Add(hi);
0163     heff->Divide(he, hall, 1., 1., "B");
0164     delete hall;
0165   }
0166 }
0167 
0168 //////////////////////////////////////////////////////////////////////////////////////////////////
0169 void L1TGMTClient::makeEfficiency2D(DQMStore::IBooker& ibooker,
0170                                     DQMStore::IGetter& igetter,
0171                                     MonitorElement* meeff,
0172                                     std::string heName,
0173                                     std::string hiName) {
0174   igetter.setCurrentFolder(output_dir_);
0175 
0176   TH2F* he = get2DHisto(input_dir_ + "/" + heName, igetter);
0177   TH2F* hi = get2DHisto(input_dir_ + "/" + hiName, igetter);
0178 
0179   if (meeff == nullptr) {
0180     LogDebug("TriggerDQM")
0181         << "\nL1TGMTClient::makeEfficiency2D: monitoring element zero, not able to retrieve histogram" << std::endl;
0182     return;
0183   }
0184 
0185   TH2F* heff = meeff->getTH2F();
0186 
0187   if (heff && he && hi) {
0188     TH2F* hall = (TH2F*)he->Clone("hall");
0189     hall->Add(hi);
0190     heff->Divide(he, hall, 1., 1., "B");
0191     delete hall;
0192   }
0193 }
0194 
0195 //////////////////////////////////////////////////////////////////////////////////////////////////
0196 TH1F* L1TGMTClient::get1DHisto(std::string meName, DQMStore::IGetter& igetter) {
0197   MonitorElement* me_ = igetter.get(meName);
0198 
0199   if (!me_) {
0200     LogDebug("TriggerDQM") << "\nL1TGMTClient: " << meName << " NOT FOUND.";
0201     return nullptr;
0202   }
0203 
0204   return me_->getTH1F();
0205 }
0206 
0207 //////////////////////////////////////////////////////////////////////////////////////////////////
0208 TH2F* L1TGMTClient::get2DHisto(std::string meName, DQMStore::IGetter& igetter) {
0209   MonitorElement* me_ = igetter.get(meName);
0210 
0211   if (!me_) {
0212     LogDebug("TriggerDQM") << "\nL1TGMTClient: " << meName << " NOT FOUND.";
0213     return nullptr;
0214   }
0215   return me_->getTH2F();
0216 }
0217 
0218 //////////////////////////////////////////////////////////////////////////////////////////////////
0219 L1TGMTClient::MonitorElement* L1TGMTClient::bookClone1D(DQMStore::IBooker& ibooker,
0220                                                         DQMStore::IGetter& igetter,
0221                                                         const std::string& name,
0222                                                         const std::string& title,
0223                                                         const std::string& hrefName) {
0224   MonitorElement* me;
0225 
0226   TH1F* href = get1DHisto(input_dir_ + "/" + hrefName, igetter);
0227 
0228   if (href) {
0229     LogDebug("TriggerDQM") << "\nL1TGMTClient::bookClone1D: booking histogram " << hrefName << std::endl;
0230     const unsigned nbx = href->GetNbinsX();
0231     const double xmin = href->GetXaxis()->GetXmin();
0232     const double xmax = href->GetXaxis()->GetXmax();
0233     ibooker.setCurrentFolder(output_dir_);
0234     me = ibooker.book1D(name, title, nbx, xmin, xmax);
0235   } else {
0236     LogDebug("TriggerDQM") << "\nL1TGMTClient::bookClone1D: not able to clone histogram " << hrefName << std::endl;
0237     me = nullptr;
0238   }
0239 
0240   return me;
0241 }
0242 
0243 //////////////////////////////////////////////////////////////////////////////////////////////////
0244 L1TGMTClient::MonitorElement* L1TGMTClient::bookClone1DVB(DQMStore::IBooker& ibooker,
0245                                                           DQMStore::IGetter& igetter,
0246                                                           const std::string& name,
0247                                                           const std::string& title,
0248                                                           const std::string& hrefName) {
0249   MonitorElement* me;
0250 
0251   TH1F* href = get1DHisto(input_dir_ + "/" + hrefName, igetter);
0252 
0253   if (href) {
0254     LogDebug("TriggerDQM") << "\nL1TGMTClient::bookClone1DVB: booking histogram " << hrefName << std::endl;
0255     int nbx = href->GetNbinsX();
0256     if (nbx > 99)
0257       nbx = 99;
0258     float xbins[100];
0259     for (int i = 0; i < nbx; i++) {
0260       xbins[i] = href->GetBinLowEdge(i + 1);
0261     }
0262     xbins[nbx] = href->GetXaxis()->GetXmax();
0263 
0264     ibooker.setCurrentFolder(output_dir_);
0265     me = ibooker.book1D(name, title, nbx, xbins);
0266 
0267   } else {
0268     LogDebug("TriggerDQM") << "\nL1TGMTClient::bookClone1DVB: not able to clone histogram " << hrefName << std::endl;
0269     me = nullptr;
0270   }
0271 
0272   return me;
0273 }
0274 
0275 //////////////////////////////////////////////////////////////////////////////////////////////////
0276 L1TGMTClient::MonitorElement* L1TGMTClient::bookClone2D(DQMStore::IBooker& ibooker,
0277                                                         DQMStore::IGetter& igetter,
0278                                                         const std::string& name,
0279                                                         const std::string& title,
0280                                                         const std::string& hrefName) {
0281   MonitorElement* me;
0282 
0283   TH2F* href = get2DHisto(input_dir_ + "/" + hrefName, igetter);
0284 
0285   if (href) {
0286     LogDebug("TriggerDQM") << "\nL1TGMTClient::bookClone2D: booking histogram " << hrefName << std::endl;
0287     const unsigned nbx = href->GetNbinsX();
0288     const double xmin = href->GetXaxis()->GetXmin();
0289     const double xmax = href->GetXaxis()->GetXmax();
0290     const unsigned nby = href->GetNbinsY();
0291     const double ymin = href->GetYaxis()->GetXmin();
0292     const double ymax = href->GetYaxis()->GetXmax();
0293     ibooker.setCurrentFolder(output_dir_);
0294     me = ibooker.book2D(name, title, nbx, xmin, xmax, nby, ymin, ymax);
0295   } else {
0296     LogDebug("TriggerDQM") << "\nL1TGMTClient::bookClone2D: not able to clone histogram " << hrefName << std::endl;
0297     me = nullptr;
0298   }
0299 
0300   return me;
0301 }
0302 
0303 //////////////////////////////////////////////////////////////////////////////////////////////////