Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:44

0001 // -*- C++ -*-
0002 //
0003 // Package:    HLTVertexFilter
0004 // Class:      HLTVertexFilter
0005 //
0006 /**\class HLTVertexFilter HLTVertexFilter.cc
0007 
0008  Description: HLTFilter to accept events with at least a given number of vertices
0009 
0010  Implementation:
0011      This class implements an HLTFilter to select events with at least
0012      a certain number of vertices matching some selection criteria.
0013 */
0014 // Original Author:  Andrea Bocci
0015 //         Created:  Tue Apr 20 12:34:27 CEST 2010
0016 
0017 #include <cmath>
0018 
0019 // user include files
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 #include "DataFormats/Common/interface/Handle.h"
0026 #include "DataFormats/VertexReco/interface/Vertex.h"
0027 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0028 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0029 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0030 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
0031 
0032 //
0033 // class declaration
0034 //
0035 class HLTVertexFilter : public HLTFilter {
0036 public:
0037   explicit HLTVertexFilter(const edm::ParameterSet& config);
0038   ~HLTVertexFilter() override;
0039   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0040 
0041 private:
0042   bool hltFilter(edm::Event& event,
0043                  const edm::EventSetup& setup,
0044                  trigger::TriggerFilterObjectWithRefs& filterproduct) const override;
0045 
0046   edm::EDGetTokenT<reco::VertexCollection> m_inputToken;
0047   edm::InputTag m_inputTag;  // input vertex collection
0048   double m_minNDoF;          // minimum vertex NDoF
0049   double m_maxChi2;          // maximum vertex chi2
0050   double m_maxD0;            // maximum transverse distance from the beam
0051   double m_maxZ;             // maximum longitudinal distance nominal center of the detector
0052   unsigned int m_minVertices;
0053 };
0054 
0055 //
0056 // constructors and destructor
0057 //
0058 HLTVertexFilter::HLTVertexFilter(const edm::ParameterSet& config)
0059     : HLTFilter(config),
0060       m_inputTag(config.getParameter<edm::InputTag>("inputTag")),
0061       m_minNDoF(config.getParameter<double>("minNDoF")),
0062       m_maxChi2(config.getParameter<double>("maxChi2")),
0063       m_maxD0(config.getParameter<double>("maxD0")),
0064       m_maxZ(config.getParameter<double>("maxZ")),
0065       m_minVertices(config.getParameter<unsigned int>("minVertices")) {
0066   m_inputToken = consumes<reco::VertexCollection>(m_inputTag);
0067 }
0068 
0069 HLTVertexFilter::~HLTVertexFilter() = default;
0070 
0071 void HLTVertexFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0072   edm::ParameterSetDescription desc;
0073   makeHLTFilterDescription(desc);
0074   desc.add<edm::InputTag>("inputTag", edm::InputTag("hltPixelVertices"));
0075   desc.add<double>("minNDoF", 0.);
0076   desc.add<double>("maxChi2", 99999.);
0077   desc.add<double>("maxD0", 1.);
0078   desc.add<double>("maxZ", 15.);
0079   desc.add<unsigned int>("minVertices", 1);
0080   descriptions.add("hltVertexFilter", desc);
0081 }
0082 
0083 //
0084 // member functions
0085 //
0086 
0087 // ------------ method called on each new Event  ------------
0088 bool HLTVertexFilter::hltFilter(edm::Event& event,
0089                                 edm::EventSetup const& setup,
0090                                 trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0091   // get hold of collection of objects
0092   edm::Handle<reco::VertexCollection> vertices;
0093   event.getByToken(m_inputToken, vertices);
0094 
0095   unsigned int n = 0;
0096   if (vertices.isValid()) {
0097     for (auto const& vertex : *vertices) {
0098       if (vertex.isValid() and not vertex.isFake() and (vertex.chi2() <= m_maxChi2) and (vertex.ndof() >= m_minNDoF) and
0099           (std::abs(vertex.z()) <= m_maxZ) and (std::abs(vertex.y()) <= m_maxD0) and
0100           (std::abs(vertex.x()) <= m_maxD0) and
0101           (std::sqrt(std::pow(vertex.x(), 2) + std::pow(vertex.y(), 2)) <= m_maxD0))
0102         ++n;
0103     }
0104   }
0105 
0106   // filter decision
0107   return (n >= m_minVertices);
0108 }
0109 
0110 // declare this class as a framework plugin
0111 #include "FWCore/Framework/interface/MakerMacros.h"
0112 DEFINE_FWK_MODULE(HLTVertexFilter);