CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauVertexAssociator.cc
Go to the documentation of this file.
2 
3 #include <functional>
4 #include <boost/foreach.hpp>
5 
13 
14 namespace reco { namespace tau {
15 
16 namespace {
17 
18 // Get the highest pt track in a jet.
19 // Get the KF track if it exists. Otherwise, see if it has a GSF track.
20 const reco::TrackBaseRef getLeadTrack(const PFJet& jet) {
21  std::vector<PFCandidatePtr> tracks = pfChargedCands(jet, true);
22  if (!tracks.size())
23  return reco::TrackBaseRef();
24  PFCandidatePtr cand = tracks[0];
25  if (cand->trackRef().isNonnull())
26  return reco::TrackBaseRef(cand->trackRef());
27  else if (cand->gsfTrackRef().isNonnull()) {
28  return reco::TrackBaseRef(cand->gsfTrackRef());
29  }
30  return reco::TrackBaseRef();
31 }
32 
33 // Define functors which extract the relevant information from a collection of
34 // vertices.
35 class DZtoTrack : public std::unary_function<double, reco::VertexRef> {
36  public:
37  DZtoTrack(const reco::TrackBaseRef& trk):trk_(trk){}
38  double operator()(const reco::VertexRef& vtx) const {
39  if (!trk_ || !vtx) {
41  }
42  return std::abs(trk_->dz(vtx->position()));
43  }
44  private:
46 };
47 
48 class TrackWeightInVertex : public std::unary_function<double, reco::VertexRef>
49 {
50  public:
51  TrackWeightInVertex(const reco::TrackBaseRef& trk):trk_(trk){}
52  double operator()(const reco::VertexRef& vtx) const {
53  if (!trk_ || !vtx) {
54  return 0.0;
55  }
56  return vtx->trackWeight(trk_);
57  }
58  private:
60 };
61 
62 }
63 
65  const edm::ParameterSet& pset) {
66 
67  vertexTag_ = edm::InputTag("offlinePrimaryVertices", "");
68  std::string algorithm = "highestPtInEvent";
69 
70  // Sanity check, will remove once HLT module configs are updated.
71  if (!pset.exists("primaryVertexSrc") || !pset.exists("pvFindingAlgo")) {
72  edm::LogWarning("NoVertexFindingMethodSpecified")
73  << "The PSet passed to the RecoTauVertexAssociator was"
74  << " incorrectly configured. The vertex will be taken as the "
75  << "highest Pt vertex from the offlinePrimaryVertices collection."
76  << std::endl;
77  } else {
78  vertexTag_ = pset.getParameter<edm::InputTag>("primaryVertexSrc");
79  algorithm = pset.getParameter<std::string>("pvFindingAlgo");
80  }
81 
82  if (algorithm == "highestPtInEvent") {
84  } else if (algorithm == "closestInDeltaZ") {
86  } else if (algorithm == "highestWeightForLeadTrack") {
88  } else {
89  throw cms::Exception("BadVertexAssociatorConfig")
90  << "The algorithm specified for tau-vertex association "
91  << algorithm << " is invalid. Options are: " << std::endl
92  << "highestPtInEvent,"
93  << "closestInDeltaZ,"
94  << "or highestWeightForLeadTrack." << std::endl;
95  }
96 }
97 
100  evt.getByLabel(vertexTag_, verticesH_);
101  vertices_.clear();
102  vertices_.reserve(verticesH_->size());
103  for(size_t i = 0; i < verticesH_->size(); ++i) {
104  vertices_.push_back(reco::VertexRef(verticesH_, i));
105  }
106 }
107 
110  reco::PFJetRef jetRef = tau.jetRef();
111 
112  // FIXME workaround for HLT which does not use updated data format
113  if (jetRef.isNull())
114  jetRef = tau.pfTauTagInfoRef()->pfjetRef();
115 
116  return associatedVertex(*jetRef);
117 }
118 
122  if (algo_ == kHighestPtInEvent) {
123  return output;
124  } else if (algo_ == kClosestDeltaZ) {
125  double closestDistance = std::numeric_limits<double>::infinity();
126  DZtoTrack dzComputer(getLeadTrack(jet));
127  // Find the vertex that has the lowest DZ to the lead track
128  BOOST_FOREACH(const reco::VertexRef& vtx, vertices_) {
129  double dz = dzComputer(vtx);
130  if (dz < closestDistance) {
131  closestDistance = dz;
132  output = vtx;
133  }
134  }
135  } else if (algo_ == kHighestWeigtForLeadTrack) {
136  double largestWeight = 0.;
137  // Find the vertex that gives the lead track the highest weight.
138  TrackWeightInVertex weightComputer(getLeadTrack(jet));
139  // Find the vertex that has the lowest DZ to the lead track
140  BOOST_FOREACH(const reco::VertexRef& vtx, vertices_) {
141  double weight = weightComputer(vtx);
142  if (weight > largestWeight) {
143  largestWeight = weight;
144  output = vtx;
145  }
146  }
147  }
148  return output;
149 }
150 
151 }}
T getParameter(std::string const &) const
reco::VertexRef associatedVertex(const PFJet &tau) const
int i
Definition: DBlmapReader.cc:9
< trclass="colgroup">< tdclass="colgroup"colspan=5 > Ecal cluster collections</td ></tr >< tr >< td >< ahref="classreco_1_1BasicCluster.html"> reco::BasicCluster</a ></td >< td >< ahref="DataFormats_EgammaReco.html"> reco::BasicClusterCollection</a ></td >< td >< ahref="#"> hybridSuperClusters</a ></td >< tdclass="description"> Basic clusters reconstructed with hybrid algorithm(barrel only)</td >< td >S.Rahatlou</td ></tr >< tr >< td >< a href
const PFJetRef & jetRef() const
Definition: PFTau.cc:50
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define abs(x)
Definition: mlp_lapack.h:159
void setEvent(const edm::Event &evt)
Load the vertices from the event.
Jets made from PFObjects.
Definition: PFJet.h:22
RecoTauVertexAssociator(const edm::ParameterSet &pset)
bool isNull() const
Checks for null.
Definition: Ref.h:247
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:22
const double infinity
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:127
const PFTauTagInfoRef & pfTauTagInfoRef() const
Definition: PFTau.cc:53
tuple tracks
Definition: testEve_cfg.py:39
std::vector< reco::VertexRef > vertices_
std::vector< PFCandidatePtr > pfChargedCands(const PFJet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
const reco::TrackBaseRef trk_
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate