CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VertexConstraintProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: VertexConstraintProducer
4 // Class: VertexConstraintProducer
5 //
13 //
14 // Original Author: Giuseppe Cerati
15 // Created: Tue Jul 10 15:05:02 CEST 2007
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
37 
38 //
39 // class decleration
40 //
41 
43 public:
45  ~VertexConstraintProducer() override = default;
46 
47 private:
48  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
49 
50  // ----------member data ---------------------------
53 
56 };
57 
58 //
59 // constants, enums and typedefs
60 //
61 
62 //
63 // static data member definitions
64 //
65 
66 //
67 // constructors and destructor
68 //
70  : srcTrkTag_(iConfig.getParameter<edm::InputTag>("srcTrk")),
71  srcVtxTag_(iConfig.getParameter<edm::InputTag>("srcVtx")) {
72  //declare the consumes
73  trkToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTrkTag_));
74  vtxToken_ = consumes<reco::VertexCollection>(edm::InputTag(srcVtxTag_));
75 
76  //register your products
77  produces<std::vector<VertexConstraint> >();
78  produces<TrackVtxConstraintAssociationCollection>();
79 
80  //now do what ever other initialization is needed
81 }
82 
83 //
84 // member functions
85 //
86 
87 // ------------ method called to produce the data ------------
90  const edm::EventSetup& iSetup) const {
91  using namespace edm;
92 
93  Handle<reco::TrackCollection> theTCollection;
94  iEvent.getByToken(trkToken_, theTCollection);
95 
96  Handle<reco::VertexCollection> theVertexHandle;
97  iEvent.getByToken(vtxToken_, theVertexHandle);
98 
99  edm::RefProd<std::vector<VertexConstraint> > rPairs = iEvent.getRefBeforePut<std::vector<VertexConstraint> >();
100  std::unique_ptr<std::vector<VertexConstraint> > pairs(new std::vector<VertexConstraint>);
101  std::unique_ptr<TrackVtxConstraintAssociationCollection> output(
102  new TrackVtxConstraintAssociationCollection(theTCollection, rPairs));
103 
104  int index = 0;
105 
106  //primary vertex extraction
107 
108  if (!theVertexHandle->empty()) {
109  const reco::Vertex& pv = theVertexHandle->front();
110  for (reco::TrackCollection::const_iterator i = theTCollection->begin(); i != theTCollection->end(); i++) {
111  VertexConstraint tmp(GlobalPoint(pv.x(), pv.y(), pv.z()),
112  GlobalError(pv.covariance(0, 0),
113  pv.covariance(1, 0),
114  pv.covariance(1, 1),
115  pv.covariance(2, 0),
116  pv.covariance(2, 1),
117  pv.covariance(2, 2)));
118  pairs->push_back(tmp);
119  output->insert(reco::TrackRef(theTCollection, index), edm::Ref<std::vector<VertexConstraint> >(rPairs, index));
120  index++;
121  }
122  }
123 
124  iEvent.put(std::move(pairs));
125  iEvent.put(std::move(output));
126 }
127 
128 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double y() const
y coordinate
Definition: Vertex.h:131
~VertexConstraintProducer() override=default
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:148
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, std::vector< VertexConstraint > > > TrackVtxConstraintAssociationCollection
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
double z() const
z coordinate
Definition: Vertex.h:133
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
RefProd< PROD > getRefBeforePut()
Definition: Event.h:158
double x() const
x coordinate
Definition: Vertex.h:129
edm::EDGetTokenT< reco::TrackCollection > trkToken_
std::pair< GlobalPoint, GlobalError > VertexConstraint
tmp
align.sh
Definition: createJobs.py:716
VertexConstraintProducer(const edm::ParameterSet &)