Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiStripTools
0004 // Class:      SiStripDetWithSomething
0005 //
0006 /**\class SiStripDetWithSomething SiStripDetWithSomething.cc DPGAnalysis/SiStripTools/plugins/SiStripDetWithSomething.cc
0007 
0008  Description: template EDFilter to select events with selected modules with SiStripDigis or SiStripClusters
0009 
0010  Implementation:
0011 
0012 */
0013 //
0014 // Original Author:  Andrea Venturi
0015 //         Created:  Wed Oct 22 17:54:30 CEST 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/global/EDFilter.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include <vector>
0032 
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 
0035 #include "FWCore/Utilities/interface/InputTag.h"
0036 
0037 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0038 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0039 #include "DataFormats/Common/interface/DetSetVector.h"
0040 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0041 
0042 //
0043 // class declaration
0044 //
0045 
0046 template <class T>
0047 class SiStripDetWithSomething : public edm::global::EDFilter<> {
0048 public:
0049   explicit SiStripDetWithSomething(const edm::ParameterSet&);
0050   ~SiStripDetWithSomething() override;
0051 
0052 private:
0053   void beginJob() override;
0054   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0055   void endJob() override;
0056 
0057   // ----------member data ---------------------------
0058 
0059   edm::EDGetTokenT<T> _digicollectionToken;
0060   std::vector<unsigned int> _wantedmod;
0061 };
0062 
0063 //
0064 // constants, enums and typedefs
0065 //
0066 
0067 //
0068 // static data member definitions
0069 //
0070 
0071 //
0072 // constructors and destructor
0073 //
0074 template <class T>
0075 SiStripDetWithSomething<T>::SiStripDetWithSomething(const edm::ParameterSet& iConfig)
0076     : _digicollectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("collectionName"))),
0077       _wantedmod(iConfig.getUntrackedParameter<std::vector<unsigned int> >("selectedModules"))
0078 
0079 {
0080   //now do what ever initialization is needed
0081 
0082   sort(_wantedmod.begin(), _wantedmod.end());
0083 
0084   edm::LogInfo("SelectedModules") << "Selected module list";
0085   for (std::vector<unsigned int>::const_iterator mod = _wantedmod.begin(); mod != _wantedmod.end(); mod++) {
0086     edm::LogVerbatim("SelectedModules") << *mod;
0087   }
0088 }
0089 
0090 template <class T>
0091 SiStripDetWithSomething<T>::~SiStripDetWithSomething() {
0092   // do anything here that needs to be done at desctruction time
0093   // (e.g. close files, deallocate resources etc.)
0094 }
0095 
0096 //
0097 // member functions
0098 //
0099 
0100 // ------------ method called on each new Event  ------------
0101 template <class T>
0102 bool SiStripDetWithSomething<T>::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0103   using namespace edm;
0104 
0105   Handle<T> digis;
0106   iEvent.getByToken(_digicollectionToken, digis);
0107 
0108   for (typename T::const_iterator it = digis->begin(); it != digis->end(); it++) {
0109     for (std::vector<unsigned int>::const_iterator mod = _wantedmod.begin();
0110          mod != _wantedmod.end() && it->detId() >= *mod;
0111          mod++) {
0112       if (*mod == it->detId()) {
0113         edm::LogInfo("ModuleFound") << " module " << *mod << " found with " << it->size() << " digis/clusters";
0114         return true;
0115       }
0116     }
0117   }
0118 
0119   return false;
0120 }
0121 
0122 // ------------ method called once each job just before starting event loop  ------------
0123 template <class T>
0124 void SiStripDetWithSomething<T>::beginJob() {}
0125 
0126 // ------------ method called once each job just after ending the event loop  ------------
0127 template <class T>
0128 void SiStripDetWithSomething<T>::endJob() {}
0129 
0130 typedef SiStripDetWithSomething<edm::DetSetVector<SiStripDigi> > SiStripDetWithDigi;
0131 typedef SiStripDetWithSomething<edmNew::DetSetVector<SiStripCluster> > SiStripDetWithCluster;
0132 
0133 //define this as a plug-in
0134 DEFINE_FWK_MODULE(SiStripDetWithDigi);
0135 DEFINE_FWK_MODULE(SiStripDetWithCluster);