Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:05

0001 #ifndef CommonTools_ParticleFlow_IPCutPFCandidateSelectorDefinition
0002 #define CommonTools_ParticleFlow_IPCutPFCandidateSelectorDefinition
0003 
0004 /**
0005    \class    pf2pat::IPCutPFCandidateSelectorDefinition IPCutPFCandidateSelectorDefinition.h "CommonTools/ParticleFlow/interface/IPCutPFCandidateSelectorDefinition.h"
0006    \brief    Selects PFCandidates basing on their compatibility with vertex
0007 
0008    \author   Giovanni Petrucciani
0009    \version  $Id: IPCutPFCandidateSelectorDefinition.h,v 1.2 2011/04/06 12:12:38 rwolf Exp $
0010 */
0011 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/ConsumesCollector.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0016 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0017 #include "CommonTools/ParticleFlow/interface/PFCandidateSelectorDefinition.h"
0018 #include "DataFormats/VertexReco/interface/Vertex.h"
0019 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0020 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0021 
0022 namespace pf2pat {
0023 
0024   struct IPCutPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition {
0025     IPCutPFCandidateSelectorDefinition(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
0026         : verticesToken_(iC.consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("vertices"))),
0027           d0Cut_(cfg.getParameter<double>("d0Cut")),
0028           dzCut_(cfg.getParameter<double>("dzCut")),
0029           dtCut_(cfg.getParameter<double>("dtCut")),
0030           d0SigCut_(cfg.getParameter<double>("d0SigCut")),
0031           dzSigCut_(cfg.getParameter<double>("dzSigCut")),
0032           dtSigCut_(cfg.getParameter<double>("dtSigCut")) {}
0033 
0034     void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s) {
0035       selected_.clear();
0036 
0037       edm::Handle<reco::VertexCollection> vertices;
0038       e.getByToken(verticesToken_, vertices);
0039       if (vertices->empty())
0040         return;
0041       const reco::Vertex &vtx = (*vertices)[0];
0042       double vt = vtx.t();
0043       double vte = vtx.tError();
0044 
0045       unsigned key = 0;
0046       for (collection::const_iterator pfc = hc->begin(); pfc != hc->end(); ++pfc, ++key) {
0047         bool passing = true;
0048         const reco::Track *tk = nullptr;
0049         if (pfc->gsfTrackRef().isNonnull())
0050           tk = pfc->gsfTrackRef().get();
0051         else if (pfc->trackRef().isNonnull())
0052           tk = pfc->trackRef().get();
0053 
0054         if (tk != nullptr) {
0055           double d0 = fabs(tk->dxy(vtx.position()));
0056           double dz = fabs(tk->dz(vtx.position()));
0057           double d0e = hypot(tk->dxyError(), hypot(vtx.xError(), vtx.yError()));
0058           double dze = hypot(tk->dzError(), vtx.zError());
0059           if (d0Cut_ > 0 && d0 > d0Cut_)
0060             passing = false;
0061           if (dzCut_ > 0 && dz > dzCut_)
0062             passing = false;
0063           if (d0SigCut_ > 0 && d0e > 0 && d0 / d0e > d0SigCut_)
0064             passing = false;
0065           if (dzSigCut_ > 0 && dze > 0 && dz / dze > dzSigCut_)
0066             passing = false;
0067         }
0068         double pfct = pfc->time();
0069         double pfcte = pfc->timeError();
0070         double dt = fabs(pfct - vt);
0071         double dte = std::sqrt(pfcte * pfcte + vte * vte);
0072         if (dtCut_ > 0 && pfcte > 0 && vte > 0 && dt > dtCut_)
0073           passing = false;
0074         if (dtSigCut_ > 0 && pfcte > 0 && vte > 0 && dt / dte > dtSigCut_)
0075           passing = false;
0076 
0077         if (passing) {
0078           selected_.push_back(reco::PFCandidate(*pfc));
0079           reco::PFCandidatePtr ptrToMother(hc, key);
0080 
0081           if (pfc->numberOfSourceCandidatePtrs() > 0) {
0082             selected_.back().setSourceCandidatePtr(edm::Ptr<reco::PFCandidate>(pfc->sourceCandidatePtr(0)));
0083           } else {
0084             selected_.back().setSourceCandidatePtr(ptrToMother);
0085           }
0086         }
0087       }
0088     }
0089 
0090   private:
0091     edm::EDGetTokenT<reco::VertexCollection> verticesToken_;
0092     double d0Cut_;
0093     double dzCut_;
0094     double dtCut_;
0095     double d0SigCut_;
0096     double dzSigCut_;
0097     double dtSigCut_;
0098   };
0099 }  // namespace pf2pat
0100 
0101 #endif