CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DPGAnalysis/SiStripTools/plugins/FromClusterSummaryMultiplicityProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    FromClusterSummaryMultiplicityProducer
00004 // Class:      FromClusterSummaryMultiplicityProducer
00005 // 
00012 //
00013 // Original Author:  Andrea Venturi
00014 //         Created:  Fri Dec 04 2009
00015 //
00016 //
00017 
00018 
00019 // system include files
00020 #include <memory>
00021 #include <string>
00022 #include <map>
00023 #include <vector>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDProducer.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 
00032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 #include "FWCore/Utilities/interface/InputTag.h"
00035 
00036 #include "DataFormats/TrackerCommon/interface/ClusterSummary.h"
00037 
00038 //
00039 // class decleration
00040 //
00041 class FromClusterSummaryMultiplicityProducer : public edm::EDProducer {
00042 
00043 public:
00044   explicit FromClusterSummaryMultiplicityProducer(const edm::ParameterSet&);
00045   ~FromClusterSummaryMultiplicityProducer();
00046   
00047 private:
00048   virtual void beginJob() ;
00049   virtual void produce(edm::Event&, const edm::EventSetup&) override;
00050   virtual void endJob() ;
00051 
00052       // ----------member data ---------------------------
00053 
00054   edm::InputTag m_collection;
00055   std::map<unsigned int, std::string> m_subdets;
00056   std::map<unsigned int, int> m_subdetenums;
00057   std::map<unsigned int, std::string> m_subdetvars;
00058   std::vector<std::string> m_clustsummvar;
00059 
00060 };
00061 
00062 //
00063 // constants, enums and typedefs
00064 //
00065 
00066 
00067 //
00068 // static data member definitions
00069 //
00070 
00071 //
00072 // constructors and destructor
00073 //
00074 FromClusterSummaryMultiplicityProducer::FromClusterSummaryMultiplicityProducer(const edm::ParameterSet& iConfig):
00075   m_collection(iConfig.getParameter<edm::InputTag>("clusterSummaryCollection")),
00076   m_subdets(),m_subdetenums(),m_subdetvars(),m_clustsummvar()
00077 {
00078 
00079   m_clustsummvar.push_back("cHits");
00080   m_clustsummvar.push_back("cSize");
00081   m_clustsummvar.push_back("cCharge");
00082   m_clustsummvar.push_back("pHits");
00083   m_clustsummvar.push_back("pSize");
00084   m_clustsummvar.push_back("pCharge");
00085 
00086   produces<std::map<unsigned int,int> >();
00087 
00088    //now do what ever other initialization is needed
00089 
00090   std::vector<edm::ParameterSet> wantedsubds(iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedSubDets"));
00091                                              
00092   for(std::vector<edm::ParameterSet>::iterator ps=wantedsubds.begin();ps!=wantedsubds.end();++ps) {
00093     m_subdets[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
00094     m_subdetenums[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int >("subDetEnum");
00095     m_subdetvars[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("subDetVariable");
00096   }
00097 }
00098 
00099 FromClusterSummaryMultiplicityProducer::~FromClusterSummaryMultiplicityProducer()
00100 {
00101  
00102    // do anything here that needs to be done at desctruction time
00103    // (e.g. close files, deallocate resources etc.)
00104 
00105 }
00106 
00107 
00108 //
00109 // member functions
00110 //
00111 
00112 // ------------ method called to produce the data  ------------
00113 void
00114 FromClusterSummaryMultiplicityProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00115 {
00116 
00117   LogDebug("Multiplicity") << " Ready to go";
00118 
00119   using namespace edm;
00120 
00121   std::auto_ptr<std::map<unsigned int,int> > mults(new std::map<unsigned int,int> );
00122   
00123   
00124   Handle<ClusterSummary> clustsumm;
00125   iEvent.getByLabel(m_collection,clustsumm);
00126 
00127   clustsumm->SetUserContent(m_clustsummvar);
00128   
00129   for(std::map<unsigned int,std::string>::const_iterator sdet=m_subdets.begin();sdet!=m_subdets.end();++sdet) { (*mults)[sdet->first]=0; }
00130 
00131   for(std::map<unsigned int,int>::const_iterator detsel=m_subdetenums.begin();detsel!=m_subdetenums.end();++detsel) {
00132 
00133     //    (*mults)[detsel->first] = int(clustsumm->GetGenericVariable(m_subdetvars[detsel->first])[clustsumm->GetModuleLocation(detsel->second)]);
00134     (*mults)[detsel->first] = int(clustsumm->GetGenericVariable(m_subdetvars[detsel->first],detsel->second));
00135     LogDebug("Multiplicity") << "GetModuleLocation result: " << detsel->second << " " << clustsumm->GetModuleLocation(detsel->second);
00136   }
00137 
00138   
00139   
00140   for(std::map<unsigned int,int>::const_iterator it=mults->begin();it!=mults->end();++it) {
00141     LogDebug("Multiplicity") << " Found " << it->second << " digis/clusters in " << it->first << " " << m_subdets[it->first];
00142   }
00143   
00144   iEvent.put(mults);
00145   
00146 }
00147 
00148 // ------------ method called once each job just before starting event loop  ------------
00149 void 
00150 FromClusterSummaryMultiplicityProducer::beginJob()
00151 {
00152 }
00153 
00154 // ------------ method called once each job just after ending the event loop  ------------
00155 void 
00156 FromClusterSummaryMultiplicityProducer::endJob() {
00157 }
00158 
00159 DEFINE_FWK_MODULE(FromClusterSummaryMultiplicityProducer);