Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:   ECALActivity
0004 // Class:     ECALActivity
0005 //
0006 //
0007 // Original Author:  Luca Malgeri
0008 
0009 #include <memory>
0010 #include <vector>
0011 #include <map>
0012 #include <set>
0013 
0014 // user include files
0015 #include "DPGAnalysis/Skims/interface/ECALActivity.h"
0016 
0017 #include "FWCore/Utilities/interface/InputTag.h"
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/Framework/interface/ESHandle.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0025 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0026 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0027 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0028 
0029 using namespace edm;
0030 using namespace std;
0031 
0032 ECALActivity::ECALActivity(const edm::ParameterSet& iConfig) {
0033   EBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
0034   EERecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
0035 
0036   EBnum = iConfig.getUntrackedParameter<int>("EBnum");
0037   EBthresh = iConfig.getUntrackedParameter<double>("EBthresh");
0038   EEnum = iConfig.getUntrackedParameter<int>("EEnum");
0039   EEthresh = iConfig.getUntrackedParameter<double>("EEthresh");
0040   ETOTnum = iConfig.getUntrackedParameter<int>("ETOTnum");
0041   ETOTthresh = iConfig.getUntrackedParameter<double>("ETOTthresh");
0042   applyfilter = iConfig.getUntrackedParameter<bool>("applyfilter", true);
0043 }
0044 
0045 ECALActivity::~ECALActivity() {}
0046 
0047 bool ECALActivity::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0048   bool accepted = false;
0049   bool eb = false;
0050   bool ee = false;
0051   bool etot = false;
0052 
0053   //int ievt = iEvent.id().event();
0054   //int irun = iEvent.id().run();
0055   //int ils = iEvent.luminosityBlock();
0056 
0057   int ebabovethresh = 0;
0058   int eeabovethresh = 0;
0059   int etotabovethresh = 0;
0060 
0061   Handle<EBRecHitCollection> pEBRecHits;
0062   Handle<EERecHitCollection> pEERecHits;
0063 
0064   const EBRecHitCollection* EBRecHits = nullptr;
0065   const EERecHitCollection* EERecHits = nullptr;
0066 
0067   if (!EBRecHitCollection_.label().empty() && !EBRecHitCollection_.instance().empty()) {
0068     iEvent.getByLabel(EBRecHitCollection_, pEBRecHits);
0069     if (pEBRecHits.isValid()) {
0070       EBRecHits = pEBRecHits.product();  // get a ptr to the product
0071     } else {
0072       edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBRecHitCollection_.label();
0073     }
0074   }
0075 
0076   if (!EERecHitCollection_.label().empty() && !EERecHitCollection_.instance().empty()) {
0077     iEvent.getByLabel(EERecHitCollection_, pEERecHits);
0078 
0079     if (pEERecHits.isValid()) {
0080       EERecHits = pEERecHits.product();  // get a ptr to the product
0081     } else {
0082       edm::LogError("EcalRecHitError") << "Error! can't get the product " << EERecHitCollection_.label();
0083     }
0084   }
0085 
0086   // now loop over them
0087   if (EBRecHits) {
0088     for (EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
0089       if (it->energy() > EBthresh)
0090         ebabovethresh++;
0091       if (it->energy() > ETOTthresh)
0092         etotabovethresh++;
0093     }
0094   }
0095   if (EERecHits) {
0096     for (EERecHitCollection::const_iterator it = EERecHits->begin(); it != EERecHits->end(); ++it) {
0097       if (it->energy() > EEthresh)
0098         eeabovethresh++;
0099       if (it->energy() > ETOTthresh)
0100         etotabovethresh++;
0101     }
0102   }
0103 
0104   if (ebabovethresh >= EBnum)
0105     eb = true;
0106   if (eeabovethresh >= EEnum)
0107     ee = true;
0108   if (etotabovethresh >= ETOTnum)
0109     etot = true;
0110 
0111   accepted = eb | ee | etot;
0112 
0113   if (applyfilter)
0114     return accepted;
0115   else
0116     return true;
0117 }
0118 
0119 //define this as a plug-in
0120 DEFINE_FWK_MODULE(ECALActivity);