Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:45

0001 
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/global/EDFilter.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DataFormats/Common/interface/View.h"
0008 #include "DataFormats/TrackReco/interface/Track.h"
0009 #include "DataFormats/VertexReco/interface/Vertex.h"
0010 #include "DataFormats/JetReco/interface/Jet.h"
0011 
0012 class TrackingFailureFilter : public edm::global::EDFilter<> {
0013 public:
0014   explicit TrackingFailureFilter(const edm::ParameterSet& iConfig);
0015   ~TrackingFailureFilter() override {}
0016 
0017 private:
0018   bool filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0019 
0020   edm::EDGetTokenT<edm::View<reco::Jet> > jetSrcToken_;
0021   edm::EDGetTokenT<std::vector<reco::Track> > trackSrcToken_;
0022   edm::EDGetTokenT<std::vector<reco::Vertex> > vertexSrcToken_;
0023   const double dzTrVtxMax_, dxyTrVtxMax_, minSumPtOverHT_;
0024 
0025   const bool taggingMode_, debug_;
0026 };
0027 
0028 TrackingFailureFilter::TrackingFailureFilter(const edm::ParameterSet& iConfig)
0029     : jetSrcToken_(consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("JetSource"))),
0030       trackSrcToken_(consumes<std::vector<reco::Track> >(iConfig.getParameter<edm::InputTag>("TrackSource"))),
0031       vertexSrcToken_(consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("VertexSource"))),
0032       dzTrVtxMax_(iConfig.getParameter<double>("DzTrVtxMax")),
0033       dxyTrVtxMax_(iConfig.getParameter<double>("DxyTrVtxMax")),
0034       minSumPtOverHT_(iConfig.getParameter<double>("MinSumPtOverHT")),
0035       taggingMode_(iConfig.getParameter<bool>("taggingMode")),
0036       debug_(iConfig.getParameter<bool>("debug")) {
0037   produces<bool>();
0038 }
0039 
0040 bool TrackingFailureFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0041   edm::Handle<edm::View<reco::Jet> > jets;
0042   iEvent.getByToken(jetSrcToken_, jets);
0043   edm::Handle<std::vector<reco::Track> > tracks;
0044   iEvent.getByToken(trackSrcToken_, tracks);
0045   edm::Handle<std::vector<reco::Vertex> > vtxs;
0046   iEvent.getByToken(vertexSrcToken_, vtxs);
0047 
0048   double ht = 0;
0049   for (edm::View<reco::Jet>::const_iterator j = jets->begin(); j != jets->end(); ++j) {
0050     ht += j->pt();
0051   }
0052   double sumpt = 0;
0053   if (!vtxs->empty()) {
0054     //    const reco::Vertex * vtx = &((*vtxs)[0]);
0055     for (std::vector<reco::Track>::const_iterator tr = tracks->begin(); tr != tracks->end(); ++tr) {
0056       bool associateToPV = false;
0057       for (int iv = 0; iv < (int)vtxs->size(); iv++) {
0058         const reco::Vertex* pervtx = &((*vtxs)[iv]);
0059         if (fabs(tr->dz(pervtx->position())) <= dzTrVtxMax_ && fabs(tr->dxy(pervtx->position())) <= dxyTrVtxMax_) {
0060           associateToPV = true;
0061         }
0062       }
0063       //      if (fabs(tr->dz(vtx->position())) > dzTrVtxMax_) continue;
0064       //      if (fabs(tr->dxy(vtx->position())) > dxyTrVtxMax_) continue;
0065       if (!associateToPV)
0066         continue;
0067       sumpt += tr->pt();
0068     }
0069   }
0070   const bool pass = (sumpt / ht) > minSumPtOverHT_;
0071 
0072   if (!pass && debug_)
0073     edm::LogInfo("TrackingFailureFilter")
0074         << "TRACKING FAILURE: " << iEvent.id().run() << " : " << iEvent.id().luminosityBlock() << " : "
0075         << iEvent.id().event() << " HT=" << ht << " SumPt=" << sumpt;
0076 
0077   iEvent.put(std::make_unique<bool>(pass));
0078 
0079   return taggingMode_ || pass;  // return false if filtering and not enough tracks in event
0080 }
0081 
0082 #include "FWCore/Framework/interface/MakerMacros.h"
0083 
0084 DEFINE_FWK_MODULE(TrackingFailureFilter);