CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQMServices/Components/plugins/DQMLumiMonitor.cc

Go to the documentation of this file.
00001 /*
00002  * \file DQMLumiMonitor.cc
00003  * \author S. Dutta
00004  * Last Update:
00005  * $Date: 2012/04/13 14:10:24 $
00006  * $Revision: 1.4 $
00007  * $Author: dutta $
00008  *
00009  * Description: Pixel Luminosity Monitoring 
00010  *
00011 */
00012 #include "DQMServices/Components/plugins/DQMLumiMonitor.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 #include "FWCore/Framework/interface/LuminosityBlock.h"
00015 #include "FWCore/ServiceRegistry/interface/Service.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "DataFormats/Common/interface/Handle.h"
00019 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
00020 #include "RecoLuminosity/LumiProducer/interface/DIPLuminosityRcd.h" 
00021 #include "RecoLuminosity/LumiProducer/interface/DIPLumiSummary.h" 
00022 #include "TPRegexp.h"
00023 
00024 
00025 // -----------------------------
00026 //  constructors and destructor
00027 // -----------------------------
00028 
00029 DQMLumiMonitor::DQMLumiMonitor( const edm::ParameterSet& ps ) : parameters_(ps) {
00030 
00031 
00032   moduleName_          = parameters_.getParameter<std::string>("ModuleName");
00033   folderName_          = parameters_.getParameter<std::string>("FolderName");
00034   pixelClusterInputTag_= parameters_.getParameter<edm::InputTag>("PixelClusterInputTag");
00035   lumiRecordName_      = parameters_.getParameter<std::string>("LumiRecordName");
00036 
00037   nClusME_ = 0;
00038   nClusVsLSME_ = 0;
00039   intLumiVsLSME_= 0;  
00040   corrIntLumiAndClusVsLSME_ = 0;
00041 }
00042 
00043 DQMLumiMonitor::~DQMLumiMonitor() {
00044 
00045 }
00046 
00047 void DQMLumiMonitor::bookHistograms() {
00048     
00049   edm::ParameterSet ClusHistoPar =  parameters_.getParameter<edm::ParameterSet>("TH1ClusPar");
00050   edm::ParameterSet LumiHistoPar =  parameters_.getParameter<edm::ParameterSet>("TH1LumiPar");
00051   edm::ParameterSet LumiSecHistoPar =  parameters_.getParameter<edm::ParameterSet>("TH1LSPar");
00052 
00053   std::string currentFolder = moduleName_ + "/" + folderName_ ;
00054   dbe_->setCurrentFolder(currentFolder.c_str());
00055 
00056   if (nClusME_ == 0) nClusME_ = dbe_->book1D("nPlxClus", " Number of Pixel Clusters ",
00057                                              ClusHistoPar.getParameter<int32_t>("Xbins"),
00058                                              ClusHistoPar.getParameter<double>("Xmin"),
00059                                              ClusHistoPar.getParameter<double>("Xmax"));
00060   else nClusME_->Reset();
00061   if (nClusVsLSME_ == 0) nClusVsLSME_ = dbe_->bookProfile("nClusVsLS", " Number of Pixel Cluster Vs LS number",
00062                                                               LumiSecHistoPar.getParameter<int32_t>("Xbins"),
00063                                                               LumiSecHistoPar.getParameter<double>("Xmin"),
00064                                                               LumiSecHistoPar.getParameter<double>("Xmax"),
00065                                                           0.0, 0.0, "");
00066   else nClusVsLSME_->Reset();
00067   if (intLumiVsLSME_ == 0) intLumiVsLSME_ = dbe_->bookProfile("intLumiVsLS", " Integrated Luminosity Vs LS number",
00068                                                               LumiSecHistoPar.getParameter<int32_t>("Xbins"),
00069                                                               LumiSecHistoPar.getParameter<double>("Xmin"),
00070                                                               LumiSecHistoPar.getParameter<double>("Xmax"),
00071                                                               0.0, 0.0, "");
00072   else intLumiVsLSME_->Reset();
00073 
00074   if (corrIntLumiAndClusVsLSME_== 0) corrIntLumiAndClusVsLSME_ = dbe_->bookProfile2D("corrIntLumiAndClusVsLS", " Correlation of nCluster and Integrated Luminosity Vs LS number",
00075                                                                                      LumiSecHistoPar.getParameter<int32_t>("Xbins"),
00076                                                                                      LumiSecHistoPar.getParameter<double>("Xmin"),
00077                                                                                      LumiSecHistoPar.getParameter<double>("Xmax"),
00078                                                                                      LumiHistoPar.getParameter<int32_t>("Xbins"),
00079                                                                                      LumiHistoPar.getParameter<double>("Xmin"),
00080                                                                                      LumiHistoPar.getParameter<double>("Xmax"),
00081                                                                                      0.0, 0.0);
00082   else corrIntLumiAndClusVsLSME_->Reset();
00083 }
00084 void DQMLumiMonitor::beginJob() {
00085   dbe_ = edm::Service<DQMStore>().operator->();
00086   intLumi_  = -1.0; 
00087   nLumi_ = -1;
00088 }
00089 
00090 void DQMLumiMonitor::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
00091   bookHistograms();
00092 
00093 }
00094 void DQMLumiMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup)  {
00095 
00096   //Access Pixel Clusters
00097   edm::Handle< edmNew::DetSetVector<SiPixelCluster> > siPixelClusters;
00098   //  edm::Handle< SiPixelClusterCollectionNew > siPixelClusters;
00099   iEvent.getByLabel(pixelClusterInputTag_, siPixelClusters);
00100   
00101   if(!siPixelClusters.isValid()) {
00102     edm::LogError("PixelLumiMonotor") << "Could not find Cluster Collection " << pixelClusterInputTag_;
00103     return;
00104   }
00105   unsigned int nClusterPix   = (*siPixelClusters).dataSize(); 
00106   nClusME_->Fill(nClusterPix);
00107   if (nLumi_ != -1) nClusVsLSME_->Fill(nLumi_, nClusterPix);
00108   if (intLumi_ != -1 || nLumi_ != -1) corrIntLumiAndClusVsLSME_->Fill(nLumi_, intLumi_, nClusterPix);
00109 }
00110 
00111 void DQMLumiMonitor::endLuminosityBlock(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& eSetup){
00112   std::cout <<" Run Number "<<lumiBlock.run() <<" Lumi Section Numnber "<< lumiBlock.luminosityBlock()<<std::endl;
00113   nLumi_ = lumiBlock.luminosityBlock();
00114   edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType(lumiRecordName_));
00115   
00116   if( recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
00117     std::cout <<"Record \"DIPLuminosityRcd"<<"\" does not exist "<<std::endl;
00118     return;
00119   }
00120   edm::ESHandle<DIPLumiSummary> datahandle;
00121   eSetup.getData(datahandle);
00122   if(datahandle.isValid()){
00123     const DIPLumiSummary* dipLumiSummary_=datahandle.product();
00124     if (!dipLumiSummary_->isNull()) {
00125       intLumi_ = dipLumiSummary_->intgDelLumiByLS();
00126       edm::LogInfo("PixelLumiMonotor") <<" Luminosity in this Lumi Section " << intLumi_ ;
00127       intLumiVsLSME_->Fill(nLumi_, intLumi_);
00128     }else{  
00129       edm::LogError("PixelLumiMonotor") << "Empty data found !";
00130     } 
00131   } else {
00132     edm::LogError("PixelLumiMonotor") << "No valid data found!";
00133   }
00134 }
00135 
00136 void DQMLumiMonitor::endRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
00137 
00138 }
00139 
00140 
00141 void DQMLumiMonitor::endJob() {
00142 
00143 }
00144 // Define this as a plug-in
00145 #include "FWCore/Framework/interface/MakerMacros.h"
00146 DEFINE_FWK_MODULE(DQMLumiMonitor);