Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:35

0001 // -*- C++ -*-
0002 //
0003 // Package:    MultiplicityCorrelator
0004 // Class:      MultiplicityCorrelator
0005 //
0006 /**\class MultiplicityCorrelator MultiplicityCorrelator.cc DPGAnalysis/SiStripTools/src/MultiplicityCorrelator.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Andrea Venturi
0015 //         Created:  Mon Oct 27 17:37:53 CET 2008
0016 // $Id: MultiplicityCorrelator.cc,v 1.3 2011/12/11 10:04:09 venturia Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 
0025 #include <vector>
0026 #include <map>
0027 #include <limits>
0028 
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0031 #include "FWCore/Framework/interface/Event.h"
0032 #include "FWCore/Framework/interface/Run.h"
0033 #include "FWCore/Framework/interface/MakerMacros.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0036 #include "FWCore/Utilities/interface/InputTag.h"
0037 
0038 #include "DPGAnalysis/SiStripTools/interface/MultiplicityCorrelatorHistogramMaker.h"
0039 
0040 //
0041 // class decleration
0042 //
0043 
0044 class MultiplicityCorrelator : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0045 public:
0046   explicit MultiplicityCorrelator(const edm::ParameterSet&);
0047   ~MultiplicityCorrelator() override;
0048 
0049 private:
0050   void beginJob() override;
0051   void analyze(const edm::Event&, const edm::EventSetup&) override;
0052   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0053   void endRun(const edm::Run&, const edm::EventSetup&) override {}
0054   void endJob() override;
0055 
0056   // ----------member data ---------------------------
0057 
0058   std::vector<MultiplicityCorrelatorHistogramMaker*> m_mchms;
0059 
0060   std::vector<edm::EDGetTokenT<std::map<unsigned int, int> > > m_xMultiplicityMapTokens;
0061   std::vector<edm::EDGetTokenT<std::map<unsigned int, int> > > m_yMultiplicityMapTokens;
0062   std::vector<std::string> m_xLabels;
0063   std::vector<std::string> m_yLabels;
0064   std::vector<unsigned int> m_xSelections;
0065   std::vector<unsigned int> m_ySelections;
0066 };
0067 
0068 //
0069 // constants, enums and typedefs
0070 //
0071 
0072 //
0073 // static data member definitions
0074 //
0075 
0076 //
0077 // constructors and destructor
0078 //
0079 MultiplicityCorrelator::MultiplicityCorrelator(const edm::ParameterSet& iConfig)
0080     : m_mchms(),
0081       m_xMultiplicityMapTokens(),
0082       m_yMultiplicityMapTokens(),
0083       m_xLabels(),
0084       m_yLabels(),
0085       m_xSelections(),
0086       m_ySelections() {
0087   //now do what ever initialization is needed
0088 
0089   std::vector<edm::ParameterSet> correlationConfigs =
0090       iConfig.getParameter<std::vector<edm::ParameterSet> >("correlationConfigurations");
0091 
0092   for (std::vector<edm::ParameterSet>::const_iterator ps = correlationConfigs.begin(); ps != correlationConfigs.end();
0093        ++ps) {
0094     m_xMultiplicityMapTokens.push_back(
0095         consumes<std::map<unsigned int, int> >(ps->getParameter<edm::InputTag>("xMultiplicityMap")));
0096     m_yMultiplicityMapTokens.push_back(
0097         consumes<std::map<unsigned int, int> >(ps->getParameter<edm::InputTag>("yMultiplicityMap")));
0098     m_xLabels.push_back(ps->getParameter<std::string>("xDetLabel"));
0099     m_yLabels.push_back(ps->getParameter<std::string>("yDetLabel"));
0100     m_xSelections.push_back(ps->getParameter<unsigned int>("xDetSelection"));
0101     m_ySelections.push_back(ps->getParameter<unsigned int>("yDetSelection"));
0102 
0103     m_mchms.push_back(new MultiplicityCorrelatorHistogramMaker(*ps, consumesCollector()));
0104   }
0105 }
0106 
0107 MultiplicityCorrelator::~MultiplicityCorrelator() {
0108   for (unsigned int i = 0; i < m_mchms.size(); ++i) {
0109     delete m_mchms[i];
0110   }
0111 }
0112 
0113 //
0114 // member functions
0115 //
0116 
0117 // ------------ method called to for each event  ------------
0118 void MultiplicityCorrelator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0119   using namespace edm;
0120 
0121   for (unsigned int i = 0; i < m_mchms.size(); ++i) {
0122     Handle<std::map<unsigned int, int> > xMults;
0123     iEvent.getByToken(m_xMultiplicityMapTokens[i], xMults);
0124     Handle<std::map<unsigned int, int> > yMults;
0125     iEvent.getByToken(m_yMultiplicityMapTokens[i], yMults);
0126 
0127     // check if the selection exists
0128 
0129     std::map<unsigned int, int>::const_iterator xmult = xMults->find(m_xSelections[i]);
0130     std::map<unsigned int, int>::const_iterator ymult = yMults->find(m_ySelections[i]);
0131 
0132     if (xmult != xMults->end() && ymult != yMults->end()) {
0133       m_mchms[i]->fill(iEvent, xmult->second, ymult->second);
0134 
0135     } else {
0136       edm::LogWarning("DetSelectionNotFound")
0137           << " DetSelection " << m_xSelections[i] << " " << m_ySelections[i] << " not found";
0138     }
0139   }
0140 }
0141 
0142 // ------------ method called once each job just before starting event loop  ------------
0143 void MultiplicityCorrelator::beginJob() {}
0144 
0145 void MultiplicityCorrelator::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0146   for (unsigned int i = 0; i < m_mchms.size(); ++i) {
0147     m_mchms[i]->beginRun(iRun);
0148   }
0149 }
0150 // ------------ method called once each job just after ending the event loop  ------------
0151 void MultiplicityCorrelator::endJob() {}
0152 //define this as a plug-in
0153 DEFINE_FWK_MODULE(MultiplicityCorrelator);