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:      FEDBadModuleFilter
0005 //
0006 /**\class FEDBadModuleFilter FEDBadModuleFilter.cc DPGAnalysis/SiStripTools/plugins/FEDBadModuleFilter.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 #include "TProfile.h"
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDFilter.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 #include <vector>
0033 #include <set>
0034 
0035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0036 
0037 #include "FWCore/Utilities/interface/InputTag.h"
0038 
0039 #include "DataFormats/DetId/interface/DetId.h"
0040 #include "DataFormats/DetId/interface/DetIdVector.h"
0041 
0042 #include "DPGAnalysis/SiStripTools/interface/RunHistogramManager.h"
0043 #include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
0044 
0045 //
0046 // class declaration
0047 //
0048 
0049 class FEDBadModuleFilter : public edm::one::EDFilter<edm::one::WatchRuns> {
0050 public:
0051   explicit FEDBadModuleFilter(const edm::ParameterSet&);
0052   ~FEDBadModuleFilter() override;
0053 
0054 private:
0055   void beginJob() override;
0056   bool filter(edm::Event&, const edm::EventSetup&) override;
0057   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0058   void endRun(const edm::Run&, const edm::EventSetup&) override {}
0059   void endJob() override;
0060 
0061   // ----------member data ---------------------------
0062 
0063   edm::EDGetTokenT<DetIdVector> m_digibadmodulecollectionToken;
0064   unsigned int m_modulethr;
0065   std::set<unsigned int> m_modules;
0066   DetIdSelector m_modsel;
0067   bool m_wantedhist;
0068   bool m_printlist;
0069   const unsigned int m_maxLS;
0070   const unsigned int m_LSfrac;
0071   RunHistogramManager m_rhm;
0072   TH1F** m_nbadrun;
0073   TProfile** m_nbadvsorbrun;
0074 };
0075 
0076 //
0077 // constants, enums and typedefs
0078 //
0079 
0080 //
0081 // static data member definitions
0082 //
0083 
0084 //
0085 // constructors and destructor
0086 //
0087 FEDBadModuleFilter::FEDBadModuleFilter(const edm::ParameterSet& iConfig)
0088     : m_digibadmodulecollectionToken(consumes(iConfig.getParameter<edm::InputTag>("collectionName"))),
0089       m_modulethr(iConfig.getParameter<unsigned int>("badModThr")),
0090       m_modsel(),
0091       m_wantedhist(iConfig.getUntrackedParameter<bool>("wantedHisto", false)),
0092       m_printlist(iConfig.getUntrackedParameter<bool>("printList", false)),
0093       m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin", 100)),
0094       m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction", 4)),
0095       m_rhm(consumesCollector())
0096 
0097 {
0098   //now do what ever initialization is needed
0099 
0100   if (m_wantedhist) {
0101     m_nbadrun = m_rhm.makeTH1F("nbadrun", "Number of bad channels", 500, -0.5, 499.5);
0102     m_nbadvsorbrun =
0103         m_rhm.makeTProfile("nbadvsorbrun", "Number of bad channels vs time", m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
0104   }
0105 
0106   std::vector<unsigned int> modules =
0107       iConfig.getUntrackedParameter<std::vector<unsigned int> >("moduleList", std::vector<unsigned int>());
0108   m_modules = std::set<unsigned int>(modules.begin(), modules.end());
0109 
0110   if (iConfig.exists("moduleSelection")) {
0111     m_modsel = DetIdSelector(iConfig.getUntrackedParameter<edm::ParameterSet>("moduleSelection"));
0112   }
0113 }
0114 
0115 FEDBadModuleFilter::~FEDBadModuleFilter() {
0116   // do anything here that needs to be done at desctruction time
0117   // (e.g. close files, deallocate resources etc.)
0118 }
0119 
0120 //
0121 // member functions
0122 //
0123 
0124 // ------------ method called on each new Event  ------------
0125 bool FEDBadModuleFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0126   using namespace edm;
0127 
0128   auto badmodules = iEvent.getHandle(m_digibadmodulecollectionToken);
0129 
0130   unsigned int nbad = 0;
0131   if (m_printlist || !m_modules.empty() || m_modsel.isValid()) {
0132     for (auto const& mod : *badmodules) {
0133       if ((m_modules.empty() || m_modules.find(mod) != m_modules.end()) &&
0134           (!m_modsel.isValid() || m_modsel.isSelected(mod))) {
0135         ++nbad;
0136         if (m_printlist)
0137           edm::LogInfo("FEDBadModule") << mod;
0138       }
0139     }
0140   } else {
0141     nbad = badmodules->size();
0142   }
0143 
0144   if (m_wantedhist) {
0145     if (m_nbadvsorbrun && *m_nbadvsorbrun)
0146       (*m_nbadvsorbrun)->Fill(iEvent.orbitNumber(), nbad);
0147     if (m_nbadrun && *m_nbadrun)
0148       (*m_nbadrun)->Fill(nbad);
0149   }
0150 
0151   return (nbad >= m_modulethr);
0152 }
0153 
0154 // ------------ method called once each job just before starting event loop  ------------
0155 void FEDBadModuleFilter::beginJob() {}
0156 
0157 // ------------ method called once each job just after ending the event loop  ------------
0158 void FEDBadModuleFilter::endJob() {}
0159 
0160 void FEDBadModuleFilter::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0161   if (m_wantedhist) {
0162     m_rhm.beginRun(iRun);
0163     if (*m_nbadvsorbrun) {
0164       (*m_nbadvsorbrun)->SetCanExtend(TH1::kXaxis);
0165       (*m_nbadvsorbrun)->GetXaxis()->SetTitle("time [Orb#]");
0166       (*m_nbadvsorbrun)->GetYaxis()->SetTitle("Bad Channels");
0167     }
0168   }
0169 }
0170 
0171 //define this as a plug-in
0172 DEFINE_FWK_MODULE(FEDBadModuleFilter);