CMS 3D CMS Logo

MomentumConstraintProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MomentumConstraintProducer
4 // Class: MomentumConstraintProducer
5 //
13 //
14 // Original Author: Giuseppe Cerati
15 // Created: Tue Jul 10 15:05:02 CEST 2007
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
34 
36 
37 //
38 // class declaration
39 //
40 
42 public:
44  ~MomentumConstraintProducer() override = default;
45 
46 private:
47  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
48 
49  // ----------member data ---------------------------
51  const double fixedmom_;
52  const double fixedmomerr_;
54 };
55 
56 //
57 // constants, enums and typedefs
58 //
59 
60 //
61 // static data member definitions
62 //
63 
64 //
65 // constructors and destructor
66 //
68  srcTag_(iConfig.getParameter<edm::InputTag>("src")),
69  fixedmom_(iConfig.getParameter<double>("fixedMomentum")),
70  fixedmomerr_(iConfig.getParameter<double>("fixedMomentumError"))
71 
72 {
73  //register your products
74  produces<std::vector<MomentumConstraint>>();
75  produces<TrackMomConstraintAssociationCollection>();
76 
77  //now do what ever other initialization is needed
79  srcToken_ = iC.consumes<reco::TrackCollection>(srcTag_);
80 }
81 
82 
83 //
84 // member functions
85 //
86 
87 // ------------ method called to produce the data ------------
89 {
90  using namespace edm;
91 
92  Handle<reco::TrackCollection> theTCollection;
93  iEvent.getByToken(srcToken_,theTCollection);
94 
95  edm::RefProd<std::vector<MomentumConstraint>> rPairs = iEvent.getRefBeforePut<std::vector<MomentumConstraint>>();
96 
97  std::unique_ptr<std::vector<MomentumConstraint>> pairs(new std::vector<MomentumConstraint>);
98  std::unique_ptr<TrackMomConstraintAssociationCollection> output(new TrackMomConstraintAssociationCollection(theTCollection, rPairs));
99 
100  int index = 0;
101  for (reco::TrackCollection::const_iterator i=theTCollection->begin(); i!=theTCollection->end();i++) {
102  // MomentumConstraint tmp(10.,0.01) ;
103 
105  if(fixedmom_< 0.0){
106  tmp= MomentumConstraint(i->p(),fixedmomerr_);
107  }
108  pairs->push_back(tmp);
109  output->insert(reco::TrackRef(theTCollection,index), edm::Ref<std::vector<MomentumConstraint>>(rPairs,index) );
110  index++;
111  }
112 
113  iEvent.put(std::move(pairs));
114  iEvent.put(std::move(output));
115 
116 }
117 
118 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
edm::EDGetTokenT< reco::TrackCollection > srcToken_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, std::vector< MomentumConstraint > > > TrackMomConstraintAssociationCollection
MomentumConstraintProducer(const edm::ParameterSet &)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
~MomentumConstraintProducer() override=default
def move(src, dest)
Definition: eostools.py:511