Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-15 23:34:16

0001 // -*- C++ -*-
0002 
0003 #include <memory>
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/stream/EDFilter.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 
0010 // to access recHits and BasicClusters
0011 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0012 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
0013 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0014 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0015 
0016 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterSeverityLevelAlgo.h"
0017 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
0018 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h"
0019 
0020 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0021 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0022 
0023 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0024 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0025 
0026 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0027 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0028 
0029 class ProbClustersFilter : public edm::stream::EDFilter<> {
0030 public:
0031   explicit ProbClustersFilter(const edm::ParameterSet&);
0032   ~ProbClustersFilter() override = default;
0033 
0034   bool filter(edm::Event&, const edm::EventSetup&) override;
0035 
0036 private:
0037   int maxDistance_;
0038   float maxGoodFraction_;
0039   edm::ParameterSet conf_;
0040   edm::InputTag barrelClusterCollection_;
0041   edm::InputTag endcapClusterCollection_;
0042   edm::InputTag reducedBarrelRecHitCollection_;
0043   edm::InputTag reducedEndcapRecHitCollection_;
0044 
0045   const edm::EDGetTokenT<reco::SuperClusterCollection> ebSCToken_;
0046   const edm::EDGetTokenT<EcalRecHitCollection> ebRecHitsToken_;
0047   const edm::ESGetToken<CaloTopology, CaloTopologyRecord> topologyToken_;
0048   const edm::ESGetToken<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd> severityLevelAlgoToken_;
0049 };
0050 
0051 ProbClustersFilter::ProbClustersFilter(const edm::ParameterSet& iConfig)
0052     : maxDistance_(iConfig.getParameter<int>("maxDistance")),
0053       maxGoodFraction_(iConfig.getParameter<double>("maxGoodFraction")),
0054       conf_(iConfig),
0055       barrelClusterCollection_(iConfig.getParameter<edm::InputTag>("barrelClusterCollection")),
0056       endcapClusterCollection_(iConfig.getParameter<edm::InputTag>("endcapClusterCollection")),
0057       reducedBarrelRecHitCollection_(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection")),
0058       reducedEndcapRecHitCollection_(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection")),
0059       ebSCToken_(consumes<reco::SuperClusterCollection>(barrelClusterCollection_)),
0060       ebRecHitsToken_(consumes<EcalRecHitCollection>(reducedBarrelRecHitCollection_)),
0061       topologyToken_(esConsumes()),
0062       severityLevelAlgoToken_(esConsumes()) {}
0063 
0064 bool ProbClustersFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0065   int problematicClusters = 0;
0066 
0067   edm::Handle<reco::SuperClusterCollection> pEBClusters;
0068   iEvent.getByToken(ebSCToken_, pEBClusters);
0069   const reco::SuperClusterCollection* ebClusters = pEBClusters.product();
0070 
0071   edm::Handle<EcalRecHitCollection> pEBRecHits;
0072   iEvent.getByToken(ebRecHitsToken_, pEBRecHits);
0073   const EcalRecHitCollection* ebRecHits = pEBRecHits.product();
0074 
0075   const auto& topology = iSetup.getData(topologyToken_);
0076   const auto& sevLv = iSetup.getData(severityLevelAlgoToken_);
0077 
0078   for (reco::SuperClusterCollection::const_iterator it = ebClusters->begin(); it != ebClusters->end(); ++it) {
0079     float goodFraction = EcalClusterSeverityLevelAlgo::goodFraction(*it, *ebRecHits, sevLv);
0080     std::pair<int, int> distance =
0081         EcalClusterSeverityLevelAlgo::etaphiDistanceClosestProblematic(*it, *ebRecHits, &topology, sevLv);
0082     if (distance.first == -1 && distance.second == -1) {
0083       distance.first = 999;
0084       distance.second = 999;
0085     }
0086     if (goodFraction >= maxGoodFraction_ &&
0087         sqrt(distance.first * distance.first + distance.second * distance.second) >= maxDistance_)
0088       continue;
0089     ++problematicClusters;
0090   }
0091 
0092   return problematicClusters;
0093 }
0094 
0095 DEFINE_FWK_MODULE(ProbClustersFilter);