File indexing completed on 2024-04-06 12:24:42
0001
0002
0003
0004
0005
0006
0007
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0010 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0011 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/global/EDProducer.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018
0019 #include <iostream>
0020 #include <memory>
0021 #include <vector>
0022
0023 class RecHitFilter : public edm::global::EDProducer<> {
0024 public:
0025 RecHitFilter(const edm::ParameterSet& ps);
0026
0027 ~RecHitFilter() override;
0028
0029 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0030
0031 private:
0032 const double noiseEnergyThreshold_;
0033 const double noiseChi2Threshold_;
0034 const std::string reducedHitCollection_;
0035 const edm::EDGetTokenT<EcalRecHitCollection> hitCollection_;
0036 };
0037
0038 #include "FWCore/Framework/interface/MakerMacros.h"
0039 DEFINE_FWK_MODULE(RecHitFilter);
0040
0041 RecHitFilter::RecHitFilter(const edm::ParameterSet& ps)
0042 : noiseEnergyThreshold_(ps.getParameter<double>("noiseEnergyThreshold")),
0043 noiseChi2Threshold_(ps.getParameter<double>("noiseChi2Threshold")),
0044 reducedHitCollection_(ps.getParameter<std::string>("reducedHitCollection")),
0045 hitCollection_(consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("hitCollection"))) {
0046 produces<EcalRecHitCollection>(reducedHitCollection_);
0047 }
0048
0049 RecHitFilter::~RecHitFilter() {}
0050
0051 void RecHitFilter::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
0052
0053 edm::Handle<EcalRecHitCollection> rhcHandle;
0054 evt.getByToken(hitCollection_, rhcHandle);
0055 const EcalRecHitCollection* hit_collection = rhcHandle.product();
0056
0057 int nTot = hit_collection->size();
0058 int nRed = 0;
0059
0060
0061 auto redCollection = std::make_unique<EcalRecHitCollection>();
0062
0063 for (EcalRecHitCollection::const_iterator it = hit_collection->begin(); it != hit_collection->end(); ++it) {
0064
0065 if (it->energy() > noiseEnergyThreshold_ && it->chi2() < noiseChi2Threshold_) {
0066 nRed++;
0067 redCollection->push_back(EcalRecHit(*it));
0068 }
0069 }
0070
0071 edm::LogInfo("") << "total # hits: " << nTot << " #hits with E > " << noiseEnergyThreshold_ << " GeV and chi2 < "
0072 << noiseChi2Threshold_ << " : " << nRed << std::endl;
0073
0074 evt.put(std::move(redCollection), reducedHitCollection_);
0075 }