File indexing completed on 2023-10-25 10:03:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/global/EDProducer.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 "FWCore/Utilities/interface/InputTag.h"
0031 #include "DataFormats/TrackReco/interface/Track.h"
0032 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0033 #include "TrackingTools/PatternTools/interface/TrackConstraintAssociation.h"
0034 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0035 #include "DataFormats/VertexReco/interface/Vertex.h"
0036 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0037
0038
0039
0040
0041
0042 class VertexConstraintProducer : public edm::global::EDProducer<> {
0043 public:
0044 explicit VertexConstraintProducer(const edm::ParameterSet&);
0045 ~VertexConstraintProducer() override = default;
0046
0047 private:
0048 void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
0049
0050
0051 const edm::InputTag srcTrkTag_;
0052 edm::EDGetTokenT<reco::TrackCollection> trkToken_;
0053
0054 const edm::InputTag srcVtxTag_;
0055 edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 VertexConstraintProducer::VertexConstraintProducer(const edm::ParameterSet& iConfig)
0070 : srcTrkTag_(iConfig.getParameter<edm::InputTag>("srcTrk")),
0071 srcVtxTag_(iConfig.getParameter<edm::InputTag>("srcVtx")) {
0072
0073 trkToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTrkTag_));
0074 vtxToken_ = consumes<reco::VertexCollection>(edm::InputTag(srcVtxTag_));
0075
0076
0077 produces<std::vector<VertexConstraint> >();
0078 produces<TrackVtxConstraintAssociationCollection>();
0079
0080
0081 }
0082
0083
0084
0085
0086
0087
0088 void VertexConstraintProducer::produce(edm::StreamID streamid,
0089 edm::Event& iEvent,
0090 const edm::EventSetup& iSetup) const {
0091 using namespace edm;
0092
0093 Handle<reco::TrackCollection> theTCollection;
0094 iEvent.getByToken(trkToken_, theTCollection);
0095
0096 Handle<reco::VertexCollection> theVertexHandle;
0097 iEvent.getByToken(vtxToken_, theVertexHandle);
0098
0099 edm::RefProd<std::vector<VertexConstraint> > rPairs = iEvent.getRefBeforePut<std::vector<VertexConstraint> >();
0100 std::unique_ptr<std::vector<VertexConstraint> > pairs(new std::vector<VertexConstraint>);
0101 std::unique_ptr<TrackVtxConstraintAssociationCollection> output(
0102 new TrackVtxConstraintAssociationCollection(theTCollection, rPairs));
0103
0104 int index = 0;
0105
0106
0107
0108 if (!theVertexHandle->empty()) {
0109 const reco::Vertex& pv = theVertexHandle->front();
0110 for (reco::TrackCollection::const_iterator i = theTCollection->begin(); i != theTCollection->end(); i++) {
0111 VertexConstraint tmp(GlobalPoint(pv.x(), pv.y(), pv.z()),
0112 GlobalError(pv.covariance(0, 0),
0113 pv.covariance(1, 0),
0114 pv.covariance(1, 1),
0115 pv.covariance(2, 0),
0116 pv.covariance(2, 1),
0117 pv.covariance(2, 2)));
0118 pairs->push_back(tmp);
0119 output->insert(reco::TrackRef(theTCollection, index), edm::Ref<std::vector<VertexConstraint> >(rPairs, index));
0120 index++;
0121 }
0122 }
0123
0124 iEvent.put(std::move(pairs));
0125 iEvent.put(std::move(output));
0126 }
0127
0128
0129 DEFINE_FWK_MODULE(VertexConstraintProducer);