CMS 3D CMS Logo

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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
38 
39 //
40 // class decleration
41 //
42 
44 public:
46  ~VertexConstraintProducer() override = default;
47 
48 private:
49  void produce(edm::StreamID streamid, edm::Event&, const edm::EventSetup&) const override;
50 
51  // ----------member data ---------------------------
54 
57 
58 };
59 
60 //
61 // constants, enums and typedefs
62 //
63 
64 //
65 // static data member definitions
66 //
67 
68 //
69 // constructors and destructor
70 //
72 srcTrkTag_(iConfig.getParameter<edm::InputTag>("srcTrk")),
73 srcVtxTag_(iConfig.getParameter<edm::InputTag>("srcVtx"))
74 {
75  //declare the consumes
76  trkToken_ = consumes<reco::TrackCollection>(edm::InputTag(srcTrkTag_));
77  vtxToken_ = consumes<reco::VertexCollection>(edm::InputTag(srcVtxTag_));
78 
79  //register your products
80  produces<std::vector<VertexConstraint> >();
81  produces<TrackVtxConstraintAssociationCollection>();
82 
83  //now do what ever other initialization is needed
84 }
85 
86 
87 //
88 // member functions
89 //
90 
91 // ------------ method called to produce the data ------------
93 {
94  using namespace edm;
95 
96  Handle<reco::TrackCollection> theTCollection;
97  iEvent.getByToken(trkToken_, theTCollection);
98 
99  Handle<reco::VertexCollection> theVertexHandle;
100  iEvent.getByToken(vtxToken_, theVertexHandle);
101 
102  edm::RefProd<std::vector<VertexConstraint> > rPairs = iEvent.getRefBeforePut<std::vector<VertexConstraint> >();
103  std::unique_ptr<std::vector<VertexConstraint> > pairs(new std::vector<VertexConstraint>);
104  std::unique_ptr<TrackVtxConstraintAssociationCollection> output(new TrackVtxConstraintAssociationCollection(theTCollection, rPairs));
105 
106  int index = 0;
107 
108  //primary vertex extraction
109 
110  if (!theVertexHandle->empty()){
111  const reco::Vertex& pv = theVertexHandle->front();
112  for (reco::TrackCollection::const_iterator i=theTCollection->begin(); i!=theTCollection->end();i++) {
114  GlobalPoint(pv.x(), pv.y(), pv.z()),
115  GlobalError(
116  pv.covariance(0, 0),
117  pv.covariance(1, 0), pv.covariance(1, 1),
118  pv.covariance(2, 0), pv.covariance(2, 1), pv.covariance(2, 2)
119  )
120  );
121  pairs->push_back(tmp);
122  output->insert(reco::TrackRef(theTCollection,index), edm::Ref<std::vector<VertexConstraint> >(rPairs,index) );
123  index++;
124  }
125  }
126 
127  iEvent.put(std::move(pairs));
128  iEvent.put(std::move(output));
129 }
130 
131 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, std::vector< VertexConstraint > > > TrackVtxConstraintAssociationCollection
void produce(edm::StreamID streamid, edm::Event &, const edm::EventSetup &) const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
double y() const
y coordinate
Definition: Vertex.h:113
~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:130
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::pair< GlobalPoint, GlobalError > VertexConstraint
def pv(vc)
Definition: MetAnalyzer.py:7
double z() const
z coordinate
Definition: Vertex.h:115
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
double x() const
x coordinate
Definition: Vertex.h:111
edm::EDGetTokenT< reco::TrackCollection > trkToken_
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
def move(src, dest)
Definition: eostools.py:511
VertexConstraintProducer(const edm::ParameterSet &)