Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    MomentumConstraintProducer
0004 // Class:      MomentumConstraintProducer
0005 //
0006 /**\class MomentumConstraintProducer MomentumConstraintProducer.cc RecoTracker/ConstraintProducerTest/src/MomentumConstraintProducer.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 "DataFormats/TrackReco/interface/Track.h"
0024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0025 
0026 #include "FWCore/Framework/interface/ConsumesCollector.h"
0027 #include "FWCore/Framework/interface/global/EDProducer.h"
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/InputTag.h"
0033 
0034 #include "TrackingTools/PatternTools/interface/TrackConstraintAssociation.h"
0035 
0036 //
0037 // class declaration
0038 //
0039 
0040 class MomentumConstraintProducer : public edm::global::EDProducer<> {
0041 public:
0042   explicit MomentumConstraintProducer(const edm::ParameterSet&);
0043   ~MomentumConstraintProducer() override = default;
0044 
0045 private:
0046   void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
0047 
0048   // ----------member data ---------------------------
0049   const edm::InputTag srcTag_;
0050   const double fixedmom_;
0051   const double fixedmomerr_;
0052   edm::EDGetTokenT<reco::TrackCollection> srcToken_;
0053 };
0054 
0055 //
0056 // constants, enums and typedefs
0057 //
0058 
0059 //
0060 // static data member definitions
0061 //
0062 
0063 //
0064 // constructors and destructor
0065 //
0066 MomentumConstraintProducer::MomentumConstraintProducer(const edm::ParameterSet& iConfig)
0067     : srcTag_(iConfig.getParameter<edm::InputTag>("src")),
0068       fixedmom_(iConfig.getParameter<double>("fixedMomentum")),
0069       fixedmomerr_(iConfig.getParameter<double>("fixedMomentumError"))
0070 
0071 {
0072   //register your products
0073   produces<std::vector<MomentumConstraint>>();
0074   produces<TrackMomConstraintAssociationCollection>();
0075 
0076   //now do what ever other initialization is needed
0077   edm::ConsumesCollector&& iC = consumesCollector();
0078   srcToken_ = iC.consumes<reco::TrackCollection>(srcTag_);
0079 }
0080 
0081 //
0082 // member functions
0083 //
0084 
0085 // ------------ method called to produce the data  ------------
0086 void MomentumConstraintProducer::produce(edm::StreamID streamid,
0087                                          edm::Event& iEvent,
0088                                          const edm::EventSetup& iSetup) const {
0089   using namespace edm;
0090 
0091   Handle<reco::TrackCollection> theTCollection;
0092   iEvent.getByToken(srcToken_, theTCollection);
0093 
0094   edm::RefProd<std::vector<MomentumConstraint>> rPairs = iEvent.getRefBeforePut<std::vector<MomentumConstraint>>();
0095 
0096   std::unique_ptr<std::vector<MomentumConstraint>> pairs(new std::vector<MomentumConstraint>);
0097   std::unique_ptr<TrackMomConstraintAssociationCollection> output(
0098       new TrackMomConstraintAssociationCollection(theTCollection, rPairs));
0099 
0100   int index = 0;
0101   for (reco::TrackCollection::const_iterator i = theTCollection->begin(); i != theTCollection->end(); i++) {
0102     //    MomentumConstraint tmp(10.,0.01) ;
0103 
0104     MomentumConstraint tmp(fixedmom_, fixedmomerr_);
0105     if (fixedmom_ < 0.0) {
0106       tmp = MomentumConstraint(i->p(), fixedmomerr_);
0107     }
0108     pairs->push_back(tmp);
0109     output->insert(reco::TrackRef(theTCollection, index), edm::Ref<std::vector<MomentumConstraint>>(rPairs, index));
0110     index++;
0111   }
0112 
0113   iEvent.put(std::move(pairs));
0114   iEvent.put(std::move(output));
0115 }
0116 
0117 //define this as a plug-in
0118 DEFINE_FWK_MODULE(MomentumConstraintProducer);