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 
15 namespace reco { namespace tau {
16 
18 
19 // Get the highest pt track in a jet.
20 // Get the KF track if it exists. Otherwise, see if it has a GSF track.
22  std::vector<PFCandidatePtr> allTracks = pfChargedCands(jet, true);
23  std::vector<PFCandidatePtr> tracks;
24  //PJ filtering of tracks
25  if (!allTracks.size()){
26  LogDebug("VxTrkAssocInfo") << " No tracks at this jet! Returning empty reference.";
27  return reco::TrackBaseRef();
28  }
29  if(vxTrkFiltering) tracks = qcuts_.filterRefs(allTracks);
30  else{
31  tracks = allTracks;
32  LogDebug("VxTrkAssocInfo") << " No quality cuts applied. All tracks passing.";
33  }
34  PFCandidatePtr cand;
35  if (!tracks.size()){
36  if(!recoverLeadingTrk){
37  LogDebug("VxTrkAssocInfo") << " All " << allTracks.size() << " tracks rejected!";
38  return reco::TrackBaseRef();
39  }else{
40  cand = allTracks[0];
41  LogDebug("VxTrkAssocInfo") << " All " << allTracks.size() << " tracks rejected but leading track was recovered!";
42  }
43  }else cand = tracks[0];
44 
45  if (cand->trackRef().isNonnull())
46  return reco::TrackBaseRef(cand->trackRef());
47  else if (cand->gsfTrackRef().isNonnull()) {
48  return reco::TrackBaseRef(cand->gsfTrackRef());
49  }
50  return reco::TrackBaseRef();
51  }
52  namespace {
53 // Define functors which extract the relevant information from a collection of
54 // vertices.
55 class DZtoTrack : public std::unary_function<double, reco::VertexRef> {
56  public:
57  DZtoTrack(const reco::TrackBaseRef& trk):trk_(trk){}
58  double operator()(const reco::VertexRef& vtx) const {
59  if (!trk_ || !vtx) {
61  }
62  return std::abs(trk_->dz(vtx->position()));
63  }
64  private:
66 };
67 
68 class TrackWeightInVertex : public std::unary_function<double, reco::VertexRef>
69 {
70  public:
71  TrackWeightInVertex(const reco::TrackBaseRef& trk):trk_(trk){}
72  double operator()(const reco::VertexRef& vtx) const {
73  if (!trk_ || !vtx) {
74  return 0.0;
75  }
76  return vtx->trackWeight(trk_);
77  }
78  private:
80 };
81 
82  }
83 
85  const edm::ParameterSet& pset): qcuts_(pset.exists("vxAssocQualityCuts") ? pset.getParameterSet("vxAssocQualityCuts") : pset.getParameterSet("signalQualityCuts"))
86 {
87  // qcuts_ = pset.exists("vxAssocQualityCuts") ? pset.getParameterSet("vxAssocQualityCuts") : pset.getParameterSet("signalQualityCuts");
88  vertexTag_ = edm::InputTag("offlinePrimaryVertices", "");
89  std::string algorithm = "highestPtInEvent";
90  // Sanity check, will remove once HLT module configs are updated.
91  if (!pset.exists("primaryVertexSrc") || !pset.exists("pvFindingAlgo")) {
92  edm::LogWarning("NoVertexFindingMethodSpecified")
93  << "The PSet passed to the RecoTauVertexAssociator was"
94  << " incorrectly configured. The vertex will be taken as the "
95  << "highest Pt vertex from the offlinePrimaryVertices collection."
96  << std::endl;
97  } else {
98  vertexTag_ = pset.getParameter<edm::InputTag>("primaryVertexSrc");
99  algorithm = pset.getParameter<std::string>("pvFindingAlgo");
100  }
101  vxTrkFiltering = false;
102  if(!pset.exists("vertexTrackFiltering") && pset.exists("vxAssocQualityCuts")){
103  edm::LogWarning("NoVertexTrackFilteringSpecified")
104  << "The PSet passed to the RecoTauVertexAssociator was"
105  << " incorrectly configured. Please define vertexTrackFiltering in config file."
106  << " No filtering of tracks to vertices will be applied"
107  << std::endl;
108  }else{
109  vxTrkFiltering = pset.exists("vertexTrackFiltering") ? pset.getParameter<bool>("vertexTrackFiltering") : false;
110  }
111 
112  LogDebug("TauVxAssociatorInfo") << " ----> Using " << algorithm << " algorithm to select vertex.";
113  if (algorithm == "highestPtInEvent") {
115  } else if (algorithm == "closestInDeltaZ") {
117  } else if (algorithm == "highestWeightForLeadTrack") {
119  } else if (algorithm == "combined"){
120  algo_ = kCombined;
121  } else {
122  throw cms::Exception("BadVertexAssociatorConfig")
123  << "The algorithm specified for tau-vertex association "
124  << algorithm << " is invalid. Options are: " << std::endl
125  << "highestPtInEvent, "
126  << "closestInDeltaZ, "
127  << "highestWeightForLeadTrack, "
128  << " or combined." << std::endl;
129  }
130  recoverLeadingTrk = pset.exists("recoverLeadingTrk") ? pset.getParameter<bool>("recoverLeadingTrk") : false;
131  // containers for holding vertices associated to jets
133  myEventNumber = -999;
134 
135  }
136 
137 
140  evt.getByLabel(vertexTag_, verticesH_);
141  vertices_.clear();
142  vertices_.reserve(verticesH_->size());
143  for(size_t i = 0; i < verticesH_->size(); ++i) {
144  vertices_.push_back(reco::VertexRef(verticesH_, i));
145  }
146  if(vertices_.size()>0 ) qcuts_.setPV(vertices_[0]);
147  int currentEvent = evt.id().event();
148  if(myEventNumber == -999 || myEventNumber!=currentEvent)
149  {
150  if(myEventNumber==-999) JetToVertexAssociation= new std::map<const reco::PFJet*,reco::VertexRef>;
151  else JetToVertexAssociation->clear();
152  myEventNumber = currentEvent;
153  }
154 }
155 
158  reco::PFJetRef jetRef = tau.jetRef();
159  // FIXME workaround for HLT which does not use updated data format
160  if (jetRef.isNull())
161  jetRef = tau.pfTauTagInfoRef()->pfjetRef();
162  return associatedVertex(*jetRef);
163 }
164 
168  PFJet const* my_jet_ptr = &jet;
169  LogDebug("VxTrkAssocInfo") << "There are " << vertices_.size() << " vertices in this event. The jet is " << jet;
170  LogTrace("VxTrkAssocInfo") << "The lenght of assoc map is "<< JetToVertexAssociation->size();
171 
172 
173  std::map<const reco::PFJet*,reco::VertexRef>::iterator it = JetToVertexAssociation->find(my_jet_ptr);
174  if(it!=JetToVertexAssociation->end())
175  {
176  LogTrace("VxTrkAssocInfo") << "I have seen this jet! Returning pointer to stored value.";
177  return it->second;
178  }
179  // Vx counters
181  if (algo_ == kHighestPtInEvent) {
182  return output;
183  } else if (algo_ == kClosestDeltaZ) {
184  leadTrack = getLeadTrack(jet);
185  if(!leadTrack){
186  LogTrace("VxTrkAssocInfo") << "No track to associate to! Returning vx no. 0.";
187  JetToVertexAssociation->insert(std::pair<const PFJet*, reco::VertexRef>(my_jet_ptr,output));
188  return output;
189  }
190  double closestDistance = std::numeric_limits<double>::infinity();
191  DZtoTrack dzComputer(leadTrack);
192  // Find the vertex that has the lowest DZ to the lead track
193  BOOST_FOREACH(const reco::VertexRef& vtx, vertices_) {
194  double dz = dzComputer(vtx);
195  if (dz < closestDistance) {
196  closestDistance = dz;
197  output = vtx;
198 
199  }
200  }
201  } else if (algo_ == kHighestWeigtForLeadTrack || algo_ == kCombined) {
202  leadTrack = getLeadTrack(jet);
203  if(!leadTrack){
204  LogTrace("VxTrkAssocInfo") << "No track to associate to! Returning vx no. 0.";
205  JetToVertexAssociation->insert(std::pair<const PFJet*, reco::VertexRef>(my_jet_ptr,output));
206  return output;
207  }
208  double largestWeight = 0.;
209  // Find the vertex that gives the lead track the highest weight.
210  TrackWeightInVertex weightComputer(leadTrack);
211  BOOST_FOREACH(const reco::VertexRef& vtx, vertices_) {
212  double weight = weightComputer(vtx);
213  if (weight > largestWeight) {
214  largestWeight = weight;
215  output = vtx;
216  }
217  }
218  // the weight was never larger than zero
219  if(algo_==kCombined && largestWeight < 1e-7){
220  LogTrace("VxTrkAssocInfo") << " No vertex had positive weight! Trying dZ instead... ";
221  DZtoTrack dzComputer(leadTrack);
222  double closestDistance = std::numeric_limits<double>::infinity();
223  BOOST_FOREACH(const reco::VertexRef& vtx, vertices_) {
224  double dz_i = dzComputer(vtx);
225  if (dz_i < closestDistance) {
226  closestDistance = dz_i;
227  output = vtx;
228  }
229  }
230  }
231  }
232 
233  JetToVertexAssociation->insert(std::pair<const PFJet*, reco::VertexRef>(my_jet_ptr,output));
234 
235  return output;
236 }
237 
238 
239 
240 }}
#define LogDebug(id)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
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
std::map< const reco::PFJet *, reco::VertexRef > * JetToVertexAssociation
Coll filterRefs(const Coll &refcoll, bool invert=false) const
Filter a ref vector of PFCandidates.
ParameterSet const & getParameterSet(ParameterSetID const &id)
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.
reco::TrackBaseRef getLeadTrack(const PFJet &jet) const
Jets made from PFObjects.
Definition: PFJet.h:22
RecoTauVertexAssociator(const edm::ParameterSet &pset)
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:152
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
void setPV(const reco::VertexRef &vtx) const
Update the primary vertex.
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:361
#define LogTrace(id)
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_
edm::EventID id() const
Definition: EventBase.h:56
std::vector< PFCandidatePtr > pfChargedCands(const PFJet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
int weight
Definition: histoStyle.py:50
const reco::TrackBaseRef trk_