Imperial Analysis
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ICSecondaryVertexProducer.cc
Go to the documentation of this file.
2 #include <memory>
3 #include <string>
4 #include <vector>
5 #include "FWCore/Framework/interface/Event.h"
6 #include "FWCore/Framework/interface/EventSetup.h"
7 #include "FWCore/Framework/interface/MakerMacros.h"
8 #include "FWCore/ParameterSet/interface/ParameterSet.h"
9 #include "FWCore/Utilities/interface/InputTag.h"
10 #include "DataFormats/Common/interface/Handle.h"
11 #include "DataFormats/Common/interface/View.h"
12 #include "DataFormats/VertexReco/interface/Vertex.h"
13 #include "DataFormats/VertexReco/interface/VertexFwd.h"
14 #include "DataFormats/BTauReco/interface/SecondaryVertexTagInfo.h"
20 
22  const edm::ParameterSet& config)
23  : input_(config.getParameter<edm::InputTag>("input")),
24  branch_(config.getParameter<std::string>("branch")),
25  track_pt_threshold_(config.getParameter<double>("trackPtThreshold")),
26  request_trks_(config.getParameter<bool>("requestTracks")) {
27  consumes<edm::View<reco::SecondaryVertexTagInfo>>(input_);
28  vertices_ = new std::vector<ic::SecondaryVertex>();
29  if (request_trks_) {
30  produces<reco::TrackRefVector>("requestedTracks");
31  }
32  PrintHeaderWithProduces(config, input_, branch_);
33  PrintOptional(1, request_trks_, "requestTracks");
34 }
35 
37 
38 void ICSecondaryVertexProducer::produce(edm::Event& event,
39  const edm::EventSetup& setup) {
40  edm::Handle<edm::View<reco::SecondaryVertexTagInfo> > vtxs_handle;
41  event.getByLabel(input_, vtxs_handle);
42 
43  std::auto_ptr<reco::TrackRefVector> trk_requests(new reco::TrackRefVector());
44 
45  vertices_->clear();
46 
47  for (unsigned i = 0; i < vtxs_handle->size(); ++i) {
48  reco::SecondaryVertexTagInfo const& sv_src = vtxs_handle->at(i);
49  for (unsigned j = 0; j < sv_src.nVertices(); ++j) {
50  reco::Vertex const& src = sv_src.secondaryVertex(j);
51  vertices_->push_back(ic::SecondaryVertex());
52  ic::SecondaryVertex & dest = vertices_->back();
53  dest.set_id(vertex_hasher_(&src));
54  dest.set_vx(src.x());
55  dest.set_vy(src.y());
56  dest.set_vz(src.z());
57  dest.set_chi2(src.chi2());
58  dest.set_ndof(src.ndof());
59  dest.set_distance_3d(sv_src.flightDistance(j, true).value());
60  dest.set_distance_err_3d(sv_src.flightDistance(j, true).error());
61  for (reco::Vertex::trackRef_iterator trk_iter = src.tracks_begin();
62  trk_iter != src.tracks_end(); ++trk_iter) {
63  float weight = src.trackWeight(*trk_iter);
64  reco::TrackRef trk_ref = trk_iter->castTo<reco::TrackRef>();
65  if (trk_ref->pt() < track_pt_threshold_) continue;
66  dest.AddTrack(track_hasher_(&(*trk_ref)), weight);
67  trk_requests->push_back(trk_ref);
68  }
69  }
70  }
71  event.put(trk_requests, "requestedTracks");
72 }
73 
74 void ICSecondaryVertexProducer::beginJob() {
75  ic::StaticTree::tree_->Branch(branch_.c_str(), &vertices_);
76 }
77 
78 void ICSecondaryVertexProducer::endJob() {}
79 
80 // define this as a plug-in
void set_vz(float const &z)
Vertex z-coordinate.
Definition: Vertex.hh:71
void set_vx(float const &x)
Vertex x-coordinate.
Definition: Vertex.hh:65
void set_ndof(float const &ndof)
The number-of-degrees-of-freedom in the vertex fit.
Definition: Vertex.hh:77
A class deriving from ic::Vertex and adding information on the 3D flight distance.
static TTree * tree_
Definition: StaticTree.hh:13
void set_id(std::size_t const &id)
Unique identifier.
Definition: Vertex.hh:62
void set_chi2(float const &chi2)
The of the vertex fit.
Definition: Vertex.hh:74
DEFINE_FWK_MODULE(ICSecondaryVertexProducer)
void AddTrack(std::size_t id, float weight)
Add an ic::Track::id with a vertex fit weight.
Definition: Vertex.hh:86
ICSecondaryVertexProducer(const edm::ParameterSet &)
void set_distance_err_3d(double const &distance_err_3d)
3D flight-distance uncertainty, in centimetres
void PrintOptional(unsigned depth, bool value, std::string text)
Definition: Consumes.h:19
void set_vy(float const &y)
Vertex y-coordinate.
Definition: Vertex.hh:68
void set_distance_3d(double const &distance_3d)
3D flight-distance, in centimetres, from the primary to the secondary vertex
void PrintHeaderWithProduces(edm::ParameterSet const &config, edm::InputTag const &in, std::string branch)