File indexing completed on 2023-03-17 11:16:11
0001 #ifndef PhysicsTools_PatAlgos_interface_VertexingHelper_h
0002 #define PhysicsTools_PatAlgos_interface_VertexingHelper_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "DataFormats/PatCandidates/interface/Vertexing.h"
0015 #include "DataFormats/Common/interface/ValueMap.h"
0016 #include "PhysicsTools/PatUtils/interface/VertexAssociationSelector.h"
0017
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/ConsumesCollector.h"
0021
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/ESHandle.h"
0024 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0025 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
0026
0027 #include "PhysicsTools/UtilAlgos/interface/ParameterAdapter.h"
0028 namespace reco {
0029 namespace modules {
0030
0031 template <>
0032 struct ParameterAdapter<pat::VertexAssociationSelector> {
0033 static pat::VertexAssociationSelector make(const edm::ParameterSet &iConfig) {
0034 pat::VertexAssociationSelector::Config assoconf;
0035 if (iConfig.existsAs<double>("deltaZ"))
0036 assoconf.dZ = iConfig.getParameter<double>("deltaZ");
0037 if (iConfig.existsAs<double>("deltaR"))
0038 assoconf.dR = iConfig.getParameter<double>("deltaR");
0039 if (iConfig.existsAs<double>("sigmasZ"))
0040 assoconf.sigmasZ = iConfig.getParameter<double>("sigmasZ");
0041 if (iConfig.existsAs<double>("sigmasR"))
0042 assoconf.sigmasR = iConfig.getParameter<double>("sigmasR");
0043 return pat::VertexAssociationSelector(assoconf);
0044 }
0045 };
0046 }
0047 }
0048
0049 namespace pat {
0050 namespace helper {
0051 class VertexingHelper {
0052 public:
0053 VertexingHelper() : enabled_(false) {}
0054 VertexingHelper(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC);
0055
0056
0057 bool enabled() const { return enabled_; }
0058
0059
0060 void newEvent(const edm::Event &event);
0061
0062
0063
0064 void newEvent(const edm::Event &event, const edm::EventSetup &setup);
0065
0066
0067
0068 template <typename AnyCandRef>
0069 pat::VertexAssociation operator()(const AnyCandRef &) const;
0070
0071 private:
0072
0073 bool enabled_;
0074
0075
0076 bool playback_;
0077
0078
0079 pat::VertexAssociationSelector assoSelector_;
0080
0081
0082 edm::EDGetTokenT<reco::VertexCollection> verticesToken_;
0083 edm::Handle<reco::VertexCollection> vertexHandle_;
0084
0085 bool useTracks_;
0086 edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> ttToken_;
0087 edm::ESHandle<TransientTrackBuilder> ttBuilder_;
0088
0089
0090 edm::EDGetTokenT<edm::ValueMap<pat::VertexAssociation> > vertexAssociationsToken_;
0091 edm::Handle<edm::ValueMap<pat::VertexAssociation> > vertexAssoMap_;
0092
0093
0094 reco::TrackBaseRef getTrack_(const reco::Candidate &c) const;
0095
0096
0097
0098 pat::VertexAssociation associate(const reco::Candidate &) const;
0099
0100 };
0101
0102 template <typename AnyCandRef>
0103 pat::VertexAssociation pat::helper::VertexingHelper::operator()(const AnyCandRef &cand) const {
0104 if (playback_) {
0105 const pat::VertexAssociation &assoc = (*vertexAssoMap_)[cand];
0106 return assoSelector_(assoc) ? assoc : pat::VertexAssociation();
0107 } else {
0108 return associate(*cand);
0109 }
0110 }
0111
0112 }
0113 }
0114
0115 #endif