Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiStripTools
0004 // Class:      LargeEvents
0005 //
0006 /**\class LargeEvents LargeEvents.cc DPGAnalysis/SiStripTools/LargeEvents.cc
0007 
0008  Description: templated EDFilter to select events with large number of SiStripDigi or SiStripCluster
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Andrea Venturi
0015 //         Created:  Tue Oct 21 20:55:22 CEST 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <string>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/global/EDFilter.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 #include "FWCore/Framework/interface/ESWatcher.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
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/SiPixelCluster/interface/SiPixelCluster.h"
0040 #include "DataFormats/Common/interface/DetSetVector.h"
0041 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0042 #include "DataFormats/Common/interface/DetSet.h"
0043 
0044 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0045 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
0046 
0047 //
0048 // class declaration
0049 //
0050 
0051 template <class T>
0052 class LargeEvents : public edm::global::EDFilter<> {
0053 public:
0054   explicit LargeEvents(const edm::ParameterSet&);
0055   ~LargeEvents() override;
0056 
0057 private:
0058   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0059 
0060   // ----------member data ---------------------------
0061 
0062   const edm::EDGetTokenT<T> _collectionToken;
0063   const int _absthr;
0064   const int _modthr;
0065   const bool _useQuality;
0066   const edm::ESGetToken<SiStripQuality, SiStripQualityRcd> _qualityToken;
0067 };
0068 
0069 //
0070 // constants, enums and typedefs
0071 //
0072 
0073 //
0074 // static data member definitions
0075 //
0076 
0077 //
0078 // constructors and destructor
0079 //
0080 template <class T>
0081 LargeEvents<T>::LargeEvents(const edm::ParameterSet& iConfig)
0082     : _collectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("collectionName"))),
0083       _absthr(iConfig.getUntrackedParameter<int>("absoluteThreshold")),
0084       _modthr(iConfig.getUntrackedParameter<int>("moduleThreshold")),
0085       _useQuality(iConfig.getUntrackedParameter<bool>("useQuality", false)),
0086       _qualityToken(esConsumes(edm::ESInputTag{"", iConfig.getUntrackedParameter<std::string>("qualityLabel", "")})) {
0087   //now do what ever initialization is needed
0088 }
0089 
0090 template <class T>
0091 LargeEvents<T>::~LargeEvents() {
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 LargeEvents<T>::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0103   using namespace edm;
0104 
0105   const SiStripQuality* _qualityHandle = nullptr;
0106 
0107   if (_useQuality) {
0108     _qualityHandle = &iSetup.getData(_qualityToken);
0109     LogDebug("SiStripQualityUpdated") << "SiStripQuality has changed and it will be updated";
0110   }
0111 
0112   Handle<T> digis;
0113   iEvent.getByToken(_collectionToken, digis);
0114 
0115   int ndigitot = 0;
0116   for (typename T::const_iterator it = digis->begin(); it != digis->end(); it++) {
0117     if (!_useQuality || !_qualityHandle->IsModuleBad(it->detId())) {
0118       if (_modthr < 0 || int(it->size()) < _modthr) {
0119         ndigitot += it->size();
0120       }
0121     }
0122   }
0123 
0124   if (ndigitot > _absthr) {
0125     LogDebug("LargeEventSelected") << "event with " << ndigitot << " digi/cluster selected";
0126     return true;
0127   }
0128 
0129   return false;
0130 }
0131 
0132 //define this as a plug-in
0133 typedef LargeEvents<edm::DetSetVector<SiStripDigi> > LargeSiStripDigiEvents;
0134 typedef LargeEvents<edmNew::DetSetVector<SiStripCluster> > LargeSiStripClusterEvents;
0135 typedef LargeEvents<edmNew::DetSetVector<SiPixelCluster> > LargeSiPixelClusterEvents;
0136 
0137 DEFINE_FWK_MODULE(LargeSiStripDigiEvents);
0138 DEFINE_FWK_MODULE(LargeSiStripClusterEvents);
0139 DEFINE_FWK_MODULE(LargeSiPixelClusterEvents);