Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-05 23:51:09

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 "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0017 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0018 #include "CommonTools/ParticleFlow/interface/PFCandidateSelectorDefinition.h"
0019 #include "DataFormats/VertexReco/interface/Vertex.h"
0020 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0021 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0022 
0023 namespace pf2pat {
0024 
0025   struct IPCutPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition {
0026     IPCutPFCandidateSelectorDefinition(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
0027         : verticesToken_(iC.consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("vertices"))),
0028           d0Cut_(cfg.getParameter<double>("d0Cut")),
0029           dzCut_(cfg.getParameter<double>("dzCut")),
0030           dtCut_(cfg.getParameter<double>("dtCut")),
0031           d0SigCut_(cfg.getParameter<double>("d0SigCut")),
0032           dzSigCut_(cfg.getParameter<double>("dzSigCut")),
0033           dtSigCut_(cfg.getParameter<double>("dtSigCut")) {}
0034 
0035     static void fillPSetDescription(edm::ParameterSetDescription &desc) {
0036       desc.add<edm::InputTag>("vertices", edm::InputTag(""));
0037       desc.add<double>("d0Cut", 0.2)->setComment("transverse IP");
0038       desc.add<double>("dzCut", 0.5)->setComment("longitudingal IP");
0039       desc.add<double>("dtCut", -1.0)->setComment("time");
0040       desc.add<double>("d0SigCut", 99.)->setComment("transverse IP significance");
0041       desc.add<double>("dzSigCut", 99.)->setComment("longitudingal IP significance");
0042       desc.add<double>("dtSigCut", -1.0)->setComment("time significance");
0043     }
0044 
0045     void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s) {
0046       selected_.clear();
0047 
0048       edm::Handle<reco::VertexCollection> vertices;
0049       e.getByToken(verticesToken_, vertices);
0050       if (vertices->empty())
0051         return;
0052       const reco::Vertex &vtx = (*vertices)[0];
0053       double vt = vtx.t();
0054       double vte = vtx.tError();
0055 
0056       unsigned key = 0;
0057       for (collection::const_iterator pfc = hc->begin(); pfc != hc->end(); ++pfc, ++key) {
0058         bool passing = true;
0059         const reco::Track *tk = nullptr;
0060         if (pfc->gsfTrackRef().isNonnull())
0061           tk = pfc->gsfTrackRef().get();
0062         else if (pfc->trackRef().isNonnull())
0063           tk = pfc->trackRef().get();
0064 
0065         if (tk != nullptr) {
0066           double d0 = fabs(tk->dxy(vtx.position()));
0067           double dz = fabs(tk->dz(vtx.position()));
0068           double d0e = hypot(tk->dxyError(), hypot(vtx.xError(), vtx.yError()));
0069           double dze = hypot(tk->dzError(), vtx.zError());
0070           if (d0Cut_ > 0 && d0 > d0Cut_)
0071             passing = false;
0072           if (dzCut_ > 0 && dz > dzCut_)
0073             passing = false;
0074           if (d0SigCut_ > 0 && d0e > 0 && d0 / d0e > d0SigCut_)
0075             passing = false;
0076           if (dzSigCut_ > 0 && dze > 0 && dz / dze > dzSigCut_)
0077             passing = false;
0078         }
0079         double pfct = pfc->time();
0080         double pfcte = pfc->timeError();
0081         double dt = fabs(pfct - vt);
0082         double dte = std::sqrt(pfcte * pfcte + vte * vte);
0083         if (dtCut_ > 0 && pfcte > 0 && vte > 0 && dt > dtCut_)
0084           passing = false;
0085         if (dtSigCut_ > 0 && pfcte > 0 && vte > 0 && dt / dte > dtSigCut_)
0086           passing = false;
0087 
0088         if (passing) {
0089           selected_.push_back(reco::PFCandidate(*pfc));
0090           reco::PFCandidatePtr ptrToMother(hc, key);
0091 
0092           if (pfc->numberOfSourceCandidatePtrs() > 0) {
0093             selected_.back().setSourceCandidatePtr(edm::Ptr<reco::PFCandidate>(pfc->sourceCandidatePtr(0)));
0094           } else {
0095             selected_.back().setSourceCandidatePtr(ptrToMother);
0096           }
0097         }
0098       }
0099     }
0100 
0101   private:
0102     edm::EDGetTokenT<reco::VertexCollection> verticesToken_;
0103     double d0Cut_;
0104     double dzCut_;
0105     double dtCut_;
0106     double d0SigCut_;
0107     double dzSigCut_;
0108     double dtSigCut_;
0109   };
0110 }  // namespace pf2pat
0111 
0112 #endif