Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-07 00:41:11

0001 /*
0002  * \file DQMLumiMonitor.cc
0003  * \author S. Dutta
0004  * Last Update:
0005  *
0006  * Description: Pixel Luminosity Monitoring 
0007  *
0008 */
0009 #include <string>
0010 #include <vector>
0011 #include <map>
0012 
0013 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0014 #include "DQMServices/Core/interface/DQMStore.h"
0015 #include "DataFormats/Common/interface/Handle.h"
0016 #include "DataFormats/Luminosity/interface/LumiDetails.h"
0017 #include "DataFormats/Luminosity/interface/LumiSummary.h"
0018 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/LuminosityBlock.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0025 
0026 #include "TPRegexp.h"
0027 
0028 //
0029 // class declaration
0030 //
0031 
0032 class DQMLumiMonitor : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0033 public:
0034   typedef dqm::legacy::DQMStore DQMStore;
0035   typedef dqm::legacy::MonitorElement MonitorElement;
0036   DQMLumiMonitor(const edm::ParameterSet&);
0037   ~DQMLumiMonitor() override = default;
0038 
0039 protected:
0040   void beginJob() override;
0041   void beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0042   void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0043   void beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) override;
0044   void endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) override;
0045   void endRun(edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0046 
0047 private:
0048   void bookHistograms();
0049 
0050   edm::ParameterSet parameters_;
0051 
0052   std::string moduleName_;
0053   std::string folderName_;
0054   edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster> > pixelClusterInputTag_;
0055   edm::EDGetTokenT<LumiSummary> lumiRecordName_;
0056 
0057   DQMStore* dbe_;
0058 
0059   MonitorElement* nClusME_;
0060   MonitorElement* intLumiVsLSME_;
0061   MonitorElement* nClusVsLSME_;
0062   MonitorElement* corrIntLumiAndClusVsLSME_;
0063 
0064   float intLumi_;
0065   int nLumi_;
0066   unsigned long long m_cacheID_;
0067 };
0068 
0069 // -----------------------------
0070 //  constructors and destructor
0071 // -----------------------------
0072 
0073 DQMLumiMonitor::DQMLumiMonitor(const edm::ParameterSet& ps) : parameters_(ps) {
0074   moduleName_ = parameters_.getParameter<std::string>("ModuleName");
0075   folderName_ = parameters_.getParameter<std::string>("FolderName");
0076   pixelClusterInputTag_ =
0077       consumes<edmNew::DetSetVector<SiPixelCluster> >(parameters_.getParameter<edm::InputTag>("PixelClusterInputTag"));
0078   lumiRecordName_ = consumes<LumiSummary, edm::InLumi>(parameters_.getParameter<std::string>("LumiRecordName"));
0079 
0080   nClusME_ = nullptr;
0081   nClusVsLSME_ = nullptr;
0082   intLumiVsLSME_ = nullptr;
0083   corrIntLumiAndClusVsLSME_ = nullptr;
0084 }
0085 
0086 void DQMLumiMonitor::bookHistograms() {
0087   edm::ParameterSet ClusHistoPar = parameters_.getParameter<edm::ParameterSet>("TH1ClusPar");
0088   edm::ParameterSet LumiHistoPar = parameters_.getParameter<edm::ParameterSet>("TH1LumiPar");
0089   edm::ParameterSet LumiSecHistoPar = parameters_.getParameter<edm::ParameterSet>("TH1LSPar");
0090 
0091   std::string currentFolder = moduleName_ + "/" + folderName_;
0092   dbe_->setCurrentFolder(currentFolder);
0093 
0094   if (nClusME_ == nullptr)
0095     nClusME_ = dbe_->book1D("nPlxClus",
0096                             " Number of Pixel Clusters ",
0097                             ClusHistoPar.getParameter<int32_t>("Xbins"),
0098                             ClusHistoPar.getParameter<double>("Xmin"),
0099                             ClusHistoPar.getParameter<double>("Xmax"));
0100   else
0101     nClusME_->Reset();
0102   if (nClusVsLSME_ == nullptr)
0103     nClusVsLSME_ = dbe_->bookProfile("nClusVsLS",
0104                                      " Number of Pixel Cluster Vs LS number",
0105                                      LumiSecHistoPar.getParameter<int32_t>("Xbins"),
0106                                      LumiSecHistoPar.getParameter<double>("Xmin"),
0107                                      LumiSecHistoPar.getParameter<double>("Xmax"),
0108                                      0.0,
0109                                      0.0,
0110                                      "");
0111   else
0112     nClusVsLSME_->Reset();
0113   if (intLumiVsLSME_ == nullptr)
0114     intLumiVsLSME_ = dbe_->bookProfile("intLumiVsLS",
0115                                        " Integrated Luminosity Vs LS number",
0116                                        LumiSecHistoPar.getParameter<int32_t>("Xbins"),
0117                                        LumiSecHistoPar.getParameter<double>("Xmin"),
0118                                        LumiSecHistoPar.getParameter<double>("Xmax"),
0119                                        0.0,
0120                                        0.0,
0121                                        "");
0122   else
0123     intLumiVsLSME_->Reset();
0124 
0125   if (corrIntLumiAndClusVsLSME_ == nullptr)
0126     corrIntLumiAndClusVsLSME_ = dbe_->bookProfile2D("corrIntLumiAndClusVsLS",
0127                                                     " Correlation of nCluster and Integrated Luminosity Vs LS number",
0128                                                     LumiSecHistoPar.getParameter<int32_t>("Xbins"),
0129                                                     LumiSecHistoPar.getParameter<double>("Xmin"),
0130                                                     LumiSecHistoPar.getParameter<double>("Xmax"),
0131                                                     LumiHistoPar.getParameter<int32_t>("Xbins"),
0132                                                     LumiHistoPar.getParameter<double>("Xmin"),
0133                                                     LumiHistoPar.getParameter<double>("Xmax"),
0134                                                     0.0,
0135                                                     0.0);
0136   else
0137     corrIntLumiAndClusVsLSME_->Reset();
0138 }
0139 void DQMLumiMonitor::beginJob() {
0140   dbe_ = edm::Service<DQMStore>().operator->();
0141   intLumi_ = -1.0;
0142   nLumi_ = -1;
0143 }
0144 
0145 void DQMLumiMonitor::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) { bookHistograms(); }
0146 void DQMLumiMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0147   //Access Pixel Clusters
0148   edm::Handle<edmNew::DetSetVector<SiPixelCluster> > siPixelClusters;
0149   iEvent.getByToken(pixelClusterInputTag_, siPixelClusters);
0150 
0151   if (!siPixelClusters.isValid()) {
0152     edm::LogError("PixelLumiMonotor") << "Could not find Cluster Collection ";
0153     return;
0154   }
0155   unsigned int nClusterPix = (*siPixelClusters).dataSize();
0156   nClusME_->Fill(nClusterPix);
0157   if (nLumi_ != -1)
0158     nClusVsLSME_->Fill(nLumi_, nClusterPix);
0159   if (intLumi_ != -1 || nLumi_ != -1)
0160     corrIntLumiAndClusVsLSME_->Fill(nLumi_, intLumi_, nClusterPix);
0161 }
0162 
0163 void DQMLumiMonitor::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) {}
0164 
0165 void DQMLumiMonitor::endLuminosityBlock(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& eSetup) {
0166   edm::LogInfo("PixelLumiMonotor") << " Run Number " << lumiBlock.run() << " Lumi Section Numnber "
0167                                    << lumiBlock.luminosityBlock();
0168 
0169   nLumi_ = lumiBlock.luminosityBlock();
0170 
0171   // Access Lumi Summary
0172   edm::Handle<LumiSummary> lumiSummary_;
0173   lumiBlock.getByToken(lumiRecordName_, lumiSummary_);
0174   if (lumiSummary_->isValid()) {
0175     intLumi_ = lumiSummary_->intgDelLumi();
0176     edm::LogInfo("PixelLumiMonotor") << " Luminosity in this Lumi Section " << intLumi_;
0177     intLumiVsLSME_->Fill(nLumi_, intLumi_);
0178   } else {
0179     edm::LogError("PixelLumiMonotor") << "No valid data found!";
0180   }
0181   /*
0182   // Access Lumi Details
0183   Handle<LumiDetails> lumiDetails;
0184   lumiBlock.getByLabel("expressLumiProducer", lumiDetails);
0185   if(lumiDetails->isValid()){
0186     std::cout<<"valid detail"<<std::endl;
0187   }else{
0188     std::cout << "no valid lumi detail data" <<std::endl;
0189   }  */
0190 }
0191 
0192 void DQMLumiMonitor::endRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {}
0193 
0194 // Define this as a plug-in
0195 #include "FWCore/Framework/interface/MakerMacros.h"
0196 DEFINE_FWK_MODULE(DQMLumiMonitor);