CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DPGAnalysis/SiStripTools/plugins/MultiplicityProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MultiplicityProducer
00004 // Class:      MultiplicityProducer
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/DetId/interface/DetId.h"
00037 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00038 #include "DataFormats/Common/interface/DetSetVector.h"
00039 
00040 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00041 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00042 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
00043 //
00044 // class decleration
00045 //
00046 template <class T>
00047 class MultiplicityProducer : public edm::EDProducer {
00048    public:
00049       explicit MultiplicityProducer(const edm::ParameterSet&);
00050       ~MultiplicityProducer();
00051 
00052    private:
00053       virtual void beginJob() ;
00054       virtual void produce(edm::Event&, const edm::EventSetup&);
00055       virtual void endJob() ;
00056       
00057       // ----------member data ---------------------------
00058 
00059   edm::InputTag _collection;
00060   std::map<unsigned int, std::string> _subdets;
00061 
00062 };
00063 
00064 //
00065 // constants, enums and typedefs
00066 //
00067 
00068 
00069 //
00070 // static data member definitions
00071 //
00072 
00073 //
00074 // constructors and destructor
00075 //
00076 template <class T>
00077 MultiplicityProducer<T>::MultiplicityProducer(const edm::ParameterSet& iConfig):
00078   _collection(iConfig.getParameter<edm::InputTag>("clusterdigiCollection")),
00079   _subdets()
00080 {
00081 
00082   produces<std::map<unsigned int,int> >();
00083 
00084    //now do what ever other initialization is needed
00085 
00086   std::vector<edm::ParameterSet> wantedsubds(iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedSubDets"));
00087                                              
00088   for(std::vector<edm::ParameterSet>::iterator ps=wantedsubds.begin();ps!=wantedsubds.end();++ps) {
00089     _subdets[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
00090   }
00091 }
00092 
00093 template <class T>
00094 MultiplicityProducer<T>::~MultiplicityProducer()
00095 {
00096  
00097    // do anything here that needs to be done at desctruction time
00098    // (e.g. close files, deallocate resources etc.)
00099 
00100 }
00101 
00102 
00103 //
00104 // member functions
00105 //
00106 
00107 // ------------ method called to produce the data  ------------
00108 template <class T>
00109 void
00110 MultiplicityProducer<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00111 {
00112 
00113   LogDebug("Multiplicity") << " Ready to loop";
00114 
00115   using namespace edm;
00116 
00117   std::auto_ptr<std::map<unsigned int,int> > mults(new std::map<unsigned int,int> );
00118   
00119   
00120   Handle<T> digis;
00121   iEvent.getByLabel(_collection,digis);
00122   
00123   for(std::map<unsigned int,std::string>::const_iterator sdet=_subdets.begin();sdet!=_subdets.end();++sdet) { (*mults)[sdet->first]=0; }
00124 
00125   
00126   for(typename T::const_iterator det = digis->begin();det!=digis->end();++det) {
00127     
00128     if(_subdets.find(0)!=_subdets.end()) (*mults)[0]+= det->size();
00129 
00130     DetId detid(det->detId());
00131     unsigned int subdet = detid.subdetId();
00132 
00133     if(_subdets.find(subdet)!=_subdets.end()) (*mults)[subdet] += det->size();
00134 
00135 
00136   }
00137   
00138   
00139   for(std::map<unsigned int,int>::const_iterator it=mults->begin();it!=mults->end();++it) {
00140     LogDebug("Multiplicity") << " Found " << it->second << " digis/clusters in " << it->first << " " << _subdets[it->first];
00141   }
00142   
00143   iEvent.put(mults);
00144   
00145 }
00146 
00147 // ------------ method called once each job just before starting event loop  ------------
00148 template <class T>
00149 void 
00150 MultiplicityProducer<T>::beginJob()
00151 {
00152 }
00153 
00154 // ------------ method called once each job just after ending the event loop  ------------
00155 template <class T>
00156 void 
00157 MultiplicityProducer<T>::endJob() {
00158 }
00159 
00160 //define this as a plug-in
00161 typedef MultiplicityProducer<edmNew::DetSetVector<SiStripCluster> > SiStripClusterMultiplicityProducer;
00162 typedef MultiplicityProducer<edmNew::DetSetVector<SiPixelCluster> > SiPixelClusterMultiplicityProducer;
00163 typedef MultiplicityProducer<edm::DetSetVector<SiStripDigi> > SiStripDigiMultiplicityProducer;
00164 
00165 
00166 DEFINE_FWK_MODULE(SiStripClusterMultiplicityProducer);
00167 DEFINE_FWK_MODULE(SiPixelClusterMultiplicityProducer);
00168 DEFINE_FWK_MODULE(SiStripDigiMultiplicityProducer);