Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-08 08:16:01

0001 // -*- C++ -*-
0002 //
0003 // Package:    FromClusterSummaryMultiplicityProducer
0004 // Class:      FromClusterSummaryMultiplicityProducer
0005 //
0006 /**\class FromClusterSummaryMultiplicityProducer FromClusterSummaryMultiplicityProducer.cc DPGAnalysis/SiStripTools/plugins/FromClusterSummaryMultiplicityProducer.cc
0007 
0008  Description: EDProducer of multiplicity maps
0009  Implementation:
0010 
0011 */
0012 //
0013 // Original Author:  Andrea Venturi
0014 //         Created:  Fri Dec 04 2009
0015 //
0016 //
0017 
0018 // system include files
0019 #include <memory>
0020 #include <string>
0021 #include <map>
0022 #include <vector>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/global/EDProducer.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/Utilities/interface/InputTag.h"
0034 
0035 #include "DataFormats/TrackerCommon/interface/ClusterSummary.h"
0036 
0037 //
0038 // class decleration
0039 //
0040 class FromClusterSummaryMultiplicityProducer : public edm::global::EDProducer<> {
0041 public:
0042   explicit FromClusterSummaryMultiplicityProducer(const edm::ParameterSet&);
0043 
0044 private:
0045   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0046 
0047   // ----------member data ---------------------------
0048 
0049   edm::EDGetTokenT<ClusterSummary> m_collectionToken;
0050   std::vector<ClusterSummary::CMSTracker> m_subdetenums;
0051   std::vector<int> m_subdetsel;
0052   ClusterSummary::VariablePlacement m_subdetvar;
0053 };
0054 
0055 //
0056 // constants, enums and typedefs
0057 //
0058 
0059 //
0060 // static data member definitions
0061 //
0062 
0063 //
0064 // constructors and destructor
0065 //
0066 FromClusterSummaryMultiplicityProducer::FromClusterSummaryMultiplicityProducer(const edm::ParameterSet& iConfig)
0067     : m_collectionToken(consumes<ClusterSummary>(iConfig.getParameter<edm::InputTag>("clusterSummaryCollection"))),
0068       m_subdetenums(),
0069       m_subdetsel(),
0070       m_subdetvar(ClusterSummary::NCLUSTERS) {
0071   produces<std::map<unsigned int, int> >();
0072 
0073   //now do what ever other initialization is needed
0074 
0075   std::vector<edm::ParameterSet> wantedsubds(iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedSubDets"));
0076   m_subdetenums.reserve(wantedsubds.size());
0077   m_subdetsel.reserve(wantedsubds.size());
0078 
0079   for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
0080     m_subdetenums.push_back((ClusterSummary::CMSTracker)ps->getParameter<int>("subDetEnum"));
0081     m_subdetsel.push_back(ps->getParameter<int>("subDetEnum"));
0082   }
0083   m_subdetvar = (ClusterSummary::VariablePlacement)iConfig.getParameter<int>("varEnum");
0084 }
0085 
0086 //
0087 // member functions
0088 //
0089 
0090 // ------------ method called to produce the data  ------------
0091 void FromClusterSummaryMultiplicityProducer::produce(edm::StreamID,
0092                                                      edm::Event& iEvent,
0093                                                      const edm::EventSetup& iSetup) const {
0094   LogDebug("Multiplicity") << " Ready to go";
0095 
0096   using namespace edm;
0097 
0098   std::unique_ptr<std::map<unsigned int, int> > mults(new std::map<unsigned int, int>);
0099 
0100   Handle<ClusterSummary> clustsumm;
0101   iEvent.getByToken(m_collectionToken, clustsumm);
0102 
0103   switch (m_subdetvar) {
0104     case ClusterSummary::NCLUSTERS:
0105       for (unsigned int iS = 0; iS < m_subdetenums.size(); ++iS)
0106         (*mults)[m_subdetsel[iS]] = int(clustsumm->getNClus(m_subdetenums[iS]));
0107       break;
0108     case ClusterSummary::CLUSTERSIZE:
0109       for (unsigned int iS = 0; iS < m_subdetenums.size(); ++iS)
0110         (*mults)[m_subdetsel[iS]] = int(clustsumm->getClusSize(m_subdetenums[iS]));
0111       break;
0112     case ClusterSummary::CLUSTERCHARGE:
0113       for (unsigned int iS = 0; iS < m_subdetenums.size(); ++iS)
0114         (*mults)[m_subdetsel[iS]] = int(clustsumm->getClusCharge(m_subdetenums[iS]));
0115       break;
0116     default:
0117       for (unsigned int iS = 0; iS < m_subdetenums.size(); ++iS)
0118         (*mults)[m_subdetsel[iS]] = -1;
0119   }
0120 
0121   for (unsigned int iS = 0; iS < m_subdetenums.size(); ++iS)
0122     LogDebug("Multiplicity") << "GetModuleLocation result: " << m_subdetenums[iS] << " "
0123                              << clustsumm->getModuleLocation(m_subdetenums[iS]);
0124 
0125   for (std::map<unsigned int, int>::const_iterator it = mults->begin(); it != mults->end(); ++it) {
0126     LogDebug("Multiplicity") << " Found " << it->second << " digis/clusters in " << it->first;
0127   }
0128 
0129   iEvent.put(std::move(mults));
0130 }
0131 
0132 DEFINE_FWK_MODULE(FromClusterSummaryMultiplicityProducer);