Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:50

0001 #ifndef PhysicsTools_PatAlgos_interface_OverlapTest_h
0002 #define PhysicsTools_PatAlgos_interface_OverlapTest_h
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/ConsumesCollector.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Utilities/interface/InputTag.h"
0008 
0009 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0010 #include "DataFormats/Candidate/interface/Candidate.h"
0011 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
0012 #include "PhysicsTools/PatUtils/interface/StringParserTools.h"
0013 #include "PhysicsTools/PatUtils/interface/PATDiObjectProxy.h"
0014 
0015 namespace pat {
0016   namespace helper {
0017 
0018     // Base class for a test for overlaps
0019     class OverlapTest {
0020     public:
0021       /// constructor: reads 'src' and 'requireNoOverlaps' parameters
0022       OverlapTest(const std::string &name, const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
0023           : srcToken_(iC.consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("src"))),
0024             name_(name),
0025             requireNoOverlaps_(iConfig.getParameter<bool>("requireNoOverlaps")) {}
0026       /// destructor, does nothing
0027       virtual ~OverlapTest() {}
0028       /// initializer for each event. to be implemented in child classes.
0029       virtual void readInput(const edm::Event &iEvent, const edm::EventSetup &iSetup) = 0;
0030       /// check for overlaps for a given item. to be implemented in child classes
0031       /// return true if overlaps have been found, and fills the PtrVector
0032       virtual bool fillOverlapsForItem(const reco::Candidate &item, reco::CandidatePtrVector &overlapsToFill) const = 0;
0033       /// end of event method. does nothing
0034       virtual void done() {}
0035       // -- basic getters ---
0036 
0037       const std::string &name() const { return name_; }
0038       bool requireNoOverlaps() const { return requireNoOverlaps_; }
0039 
0040     protected:
0041       edm::EDGetTokenT<reco::CandidateView> srcToken_;
0042       std::string name_;
0043       bool requireNoOverlaps_;
0044     };
0045 
0046     class BasicOverlapTest : public OverlapTest {
0047     public:
0048       BasicOverlapTest(const std::string &name, const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
0049           : OverlapTest(name, iConfig, iC),
0050             presel_(iConfig.getParameter<std::string>("preselection")),
0051             deltaR_(iConfig.getParameter<double>("deltaR")),
0052             checkRecoComponents_(iConfig.getParameter<bool>("checkRecoComponents")),
0053             pairCut_(iConfig.getParameter<std::string>("pairCut")) {}
0054       // implementation of mother methods
0055       /// Read input, apply preselection cut
0056       void readInput(const edm::Event &iEvent, const edm::EventSetup &iSetup) override;
0057       /// Check for overlaps
0058       bool fillOverlapsForItem(const reco::Candidate &item, reco::CandidatePtrVector &overlapsToFill) const override;
0059 
0060     protected:
0061       // ---- configurables ----
0062       /// A generic preselection cut that can work on any Candidate, but has access also to methods of PAT specific objects
0063       PATStringCutObjectSelector presel_;
0064       /// Delta R for the match
0065       double deltaR_;
0066       /// Check the overlapping by RECO components
0067       bool checkRecoComponents_;
0068       /// Cut on the pair of objects together
0069       StringCutObjectSelector<pat::DiObjectProxy> pairCut_;
0070       // ---- working variables ----
0071       /// The collection to check overlaps against
0072       edm::Handle<reco::CandidateView> candidates_;
0073       /// Flag saying if each element has passed the preselection or not
0074       std::vector<bool> isPreselected_;
0075     };
0076 
0077     class OverlapBySuperClusterSeed : public OverlapTest {
0078     public:
0079       // constructor: nothing except initialize the base class
0080       OverlapBySuperClusterSeed(const std::string &name, const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
0081           : OverlapTest(name, iConfig, iC) {}
0082       // every event: nothing except read the input list
0083       void readInput(const edm::Event &iEvent, const edm::EventSetup &iSetup) override {
0084         iEvent.getByToken(srcToken_, others_);
0085       }
0086       /// Check for overlaps
0087       bool fillOverlapsForItem(const reco::Candidate &item, reco::CandidatePtrVector &overlapsToFill) const override;
0088 
0089     protected:
0090       //         edm::Handle<edm::View<reco::RecoCandidate> > others_;
0091       edm::Handle<reco::CandidateView> others_;
0092     };
0093 
0094   }  // namespace helper
0095 }  // namespace pat
0096 
0097 #endif