Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:59

0001 // -*- C++ -*-
0002 //
0003 // Package:    VertexConstraintProducer
0004 // Class:      VertexConstraintProducer
0005 //
0006 /**\class VertexConstraintProducer VertexConstraintProducer.cc RecoTracker/ConstraintProducerTest/src/VertexConstraintProducer.cc
0007 
0008 Description: <one line class summary>
0009 
0010 Implementation:
0011 <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Giuseppe Cerati
0015 //         Created:  Tue Jul 10 15:05:02 CEST 2007
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
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 // class decleration
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   // ----------member data ---------------------------
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 // constants, enums and typedefs
0060 //
0061 
0062 //
0063 // static data member definitions
0064 //
0065 
0066 //
0067 // constructors and destructor
0068 //
0069 VertexConstraintProducer::VertexConstraintProducer(const edm::ParameterSet& iConfig)
0070     : srcTrkTag_(iConfig.getParameter<edm::InputTag>("srcTrk")),
0071       srcVtxTag_(iConfig.getParameter<edm::InputTag>("srcVtx")) {
0072   //declare the consumes
0073   trkToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTrkTag_));
0074   vtxToken_ = consumes<reco::VertexCollection>(edm::InputTag(srcVtxTag_));
0075 
0076   //register your products
0077   produces<std::vector<VertexConstraint> >();
0078   produces<TrackVtxConstraintAssociationCollection>();
0079 
0080   //now do what ever other initialization is needed
0081 }
0082 
0083 //
0084 // member functions
0085 //
0086 
0087 // ------------ method called to produce the data  ------------
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   //primary vertex extraction
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 //define this as a plug-in
0129 DEFINE_FWK_MODULE(VertexConstraintProducer);