Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:26:52

0001 // -*- C++ -*-
0002 //
0003 // Package:    JetVertexChecker
0004 // Class:      JetVertexChecker
0005 //
0006 /**\class JetVertexChecker JetVertexChecker.cc RecoBTag/JetVertexChecker/src/JetVertexChecker.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Andrea RIZZI
0015 //         Created:  Mon Jan 16 11:19:48 CET 2012
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDFilter.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "DataFormats/TrackReco/interface/Track.h"
0031 #include "DataFormats/JetReco/interface/JetTracksAssociation.h"
0032 #include "FWCore/Utilities/interface/InputTag.h"
0033 
0034 #include "DataFormats/JetReco/interface/CaloJet.h"
0035 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0036 
0037 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0038 #include "DataFormats/VertexReco/interface/Vertex.h"
0039 
0040 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0041 
0042 //
0043 // class declaration
0044 //
0045 
0046 class JetVertexChecker : public edm::stream::EDFilter<> {
0047 public:
0048   explicit JetVertexChecker(const edm::ParameterSet&);
0049   ~JetVertexChecker() override;
0050 
0051   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052 
0053 private:
0054   bool filter(edm::Event&, const edm::EventSetup&) override;
0055 
0056   // ----------member data ---------------------------
0057   const edm::EDGetTokenT<reco::JetTracksAssociationCollection> m_associator;
0058   const edm::EDGetTokenT<reco::BeamSpot> m_beamSpot;
0059   const bool m_doFilter;
0060   const double m_cutMinPt;
0061   const double m_cutMinPtRatio;
0062   const double m_maxTrackPt;
0063   const double m_maxChi2;
0064   const int32_t m_maxNjets;
0065   const int32_t m_maxNjetsOutput;
0066 
0067   const bool m_newMethod;
0068 
0069   const double m_maxETA;
0070   const double m_pvErr_x;
0071   const double m_pvErr_y;
0072   const double m_pvErr_z;
0073 };
0074 
0075 //
0076 // constants, enums and typedefs
0077 //
0078 
0079 //
0080 // static data member definitions
0081 //
0082 
0083 //
0084 // constructors and destructor
0085 //
0086 JetVertexChecker::JetVertexChecker(const edm::ParameterSet& iConfig)
0087     : m_associator(consumes<reco::JetTracksAssociationCollection>(iConfig.getParameter<edm::InputTag>("jetTracks"))),
0088       m_beamSpot(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
0089       m_doFilter(iConfig.getParameter<bool>("doFilter")),
0090       m_cutMinPt(iConfig.getParameter<double>("minPt")),
0091       m_cutMinPtRatio(iConfig.getParameter<double>("minPtRatio")),
0092       m_maxTrackPt(iConfig.getParameter<double>("maxTrackPt")),
0093       m_maxChi2(iConfig.getParameter<double>("maxChi2")),
0094       m_maxNjets(iConfig.getParameter<int32_t>("maxNJetsToCheck")),
0095       m_maxNjetsOutput(iConfig.getParameter<int32_t>("maxNjetsOutput")),
0096       m_newMethod(iConfig.getParameter<bool>("newMethod")),
0097       m_maxETA(iConfig.getParameter<double>("maxETA")),
0098       m_pvErr_x(iConfig.getParameter<double>("pvErr_x")),
0099       m_pvErr_y(iConfig.getParameter<double>("pvErr_y")),
0100       m_pvErr_z(iConfig.getParameter<double>("pvErr_z")) {
0101   //now do what ever initialization is needed
0102   produces<std::vector<reco::CaloJet>>();
0103   produces<reco::VertexCollection>();
0104 }
0105 
0106 JetVertexChecker::~JetVertexChecker() {
0107   // do anything here that needs to be done at desctruction time
0108   // (e.g. close files, deallocate resources etc.)
0109 }
0110 
0111 //
0112 // member functions
0113 //  m_maxChi2 m_maxTrackPt
0114 
0115 // ------------ method called on each new Event  ------------
0116 bool JetVertexChecker::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0117   using namespace edm;
0118   Handle<reco::JetTracksAssociationCollection> jetTracksAssociation;
0119   iEvent.getByToken(m_associator, jetTracksAssociation);
0120   auto pOut = std::make_unique<std::vector<reco::CaloJet>>();
0121 
0122   bool result = true;
0123   int i = 0;
0124   float calopt = 0;
0125   float trkpt = 0;
0126   //limit to first two jets
0127   for (reco::JetTracksAssociationCollection::const_iterator it = jetTracksAssociation->begin(),
0128                                                             et = jetTracksAssociation->end();
0129        it != et && i < m_maxNjets;
0130        it++, i++) {
0131     if (std::abs(it->first->eta()) < m_maxETA) {
0132       reco::TrackRefVector tracks = it->second;
0133       math::XYZVector jetMomentum = it->first->momentum();
0134       math::XYZVector trMomentum;
0135       for (reco::TrackRefVector::const_iterator itTrack = tracks.begin(); itTrack != tracks.end(); ++itTrack) {
0136         const reco::Track& iTrack = **itTrack;
0137         if (m_newMethod && iTrack.chi2() > m_maxChi2)
0138           continue;
0139         trMomentum += iTrack.momentum();
0140         if (m_newMethod)
0141           trkpt += std::min(m_maxTrackPt, (iTrack.pt()));
0142         else
0143           trkpt += iTrack.pt();
0144       }
0145       calopt += jetMomentum.rho();
0146       if (trMomentum.rho() / jetMomentum.rho() < m_cutMinPtRatio || trMomentum.rho() < m_cutMinPt) {
0147         pOut->push_back(*dynamic_cast<const reco::CaloJet*>(&(*it->first)));
0148       }
0149     }
0150   }
0151   iEvent.put(std::move(pOut));
0152 
0153   edm::Handle<reco::BeamSpot> beamSpot;
0154   iEvent.getByToken(m_beamSpot, beamSpot);
0155 
0156   reco::Vertex::Error e;
0157   e(0, 0) = m_pvErr_x * m_pvErr_x;
0158   e(1, 1) = m_pvErr_y * m_pvErr_y;
0159   e(2, 2) = m_pvErr_z * m_pvErr_z;
0160   reco::Vertex::Point p(beamSpot->x0(), beamSpot->y0(), beamSpot->z0());
0161   reco::Vertex thePV(p, e, 0, 0, 0);
0162   auto pOut2 = std::make_unique<reco::VertexCollection>();
0163   pOut2->push_back(thePV);
0164   iEvent.put(std::move(pOut2));
0165 
0166   if (m_doFilter)
0167     return result;
0168   else
0169     return true;
0170 }
0171 
0172 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0173 void JetVertexChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0174   edm::ParameterSetDescription desc;
0175   desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"));
0176   desc.add<edm::InputTag>("jetTracks", edm::InputTag("hltFastPVJetTracksAssociator"));
0177   desc.add<double>("minPtRatio", 0.1);
0178   desc.add<double>("minPt", 0.0);
0179   desc.add<bool>("doFilter", false);
0180   desc.add<int>("maxNJetsToCheck", 2);
0181   desc.add<int>("maxNjetsOutput", 2);
0182   desc.add<double>("maxChi2", 20.0);
0183   desc.add<double>("maxTrackPt", 20.0);
0184   desc.add<bool>("newMethod", false);  // <---- newMethod
0185   desc.add<double>("maxETA", 2.4);
0186   desc.add<double>("pvErr_x", 0.0015);
0187   desc.add<double>("pvErr_y", 0.0015);
0188   desc.add<double>("pvErr_z", 1.5);
0189   descriptions.add("jetVertexChecker", desc);
0190 }
0191 //define this as a plug-in
0192 DEFINE_FWK_MODULE(JetVertexChecker);