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_.filterCandRefs(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, edm::ConsumesCollector && iC): 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  }
131  recoverLeadingTrk = pset.exists("recoverLeadingTrk") ? pset.getParameter<bool>("recoverLeadingTrk") : false;
132  // containers for holding vertices associated to jets
134  myEventNumber = -999;
135 
136  }
137 
138 
141  evt.getByToken(vx_token, verticesH_);
142  vertices_.clear();
143  vertices_.reserve(verticesH_->size());
144  for(size_t i = 0; i < verticesH_->size(); ++i) {
145  vertices_.push_back(reco::VertexRef(verticesH_, i));
146  }
147  if(vertices_.size()>0 ) qcuts_.setPV(vertices_[0]);
148  int currentEvent = evt.id().event();
149  if(myEventNumber == -999 || myEventNumber!=currentEvent)
150  {
151  if(myEventNumber==-999) JetToVertexAssociation= new std::map<const reco::PFJet*,reco::VertexRef>;
152  else JetToVertexAssociation->clear();
153  myEventNumber = currentEvent;
154  }
155 }
156 
159  reco::PFJetRef jetRef = tau.jetRef();
160  // FIXME workaround for HLT which does not use updated data format
161  if (jetRef.isNull())
162  jetRef = tau.pfTauTagInfoRef()->pfjetRef();
163  return associatedVertex(*jetRef);
164 }
165 
169  PFJet const* my_jet_ptr = &jet;
170  LogDebug("VxTrkAssocInfo") << "There are " << vertices_.size() << " vertices in this event. The jet is " << jet;
171  LogTrace("VxTrkAssocInfo") << "The lenght of assoc map is "<< JetToVertexAssociation->size();
172 
173 
174  std::map<const reco::PFJet*,reco::VertexRef>::iterator it = JetToVertexAssociation->find(my_jet_ptr);
175  if(it!=JetToVertexAssociation->end())
176  {
177  LogTrace("VxTrkAssocInfo") << "I have seen this jet! Returning pointer to stored value.";
178  return it->second;
179  }
180  // Vx counters
182  if (algo_ == kHighestPtInEvent) {
183  return output;
184  } else if (algo_ == kClosestDeltaZ) {
185  leadTrack = getLeadTrack(jet);
186  if(!leadTrack){
187  LogTrace("VxTrkAssocInfo") << "No track to associate to! Returning vx no. 0.";
188  JetToVertexAssociation->insert(std::pair<const PFJet*, reco::VertexRef>(my_jet_ptr,output));
189  return output;
190  }
191  double closestDistance = std::numeric_limits<double>::infinity();
192  DZtoTrack dzComputer(leadTrack);
193  // Find the vertex that has the lowest DZ to the lead track
194  BOOST_FOREACH(const reco::VertexRef& vtx, vertices_) {
195  double dz = dzComputer(vtx);
196  if (dz < closestDistance) {
197  closestDistance = dz;
198  output = vtx;
199 
200  }
201  }
202  } else if (algo_ == kHighestWeigtForLeadTrack || algo_ == kCombined) {
203  leadTrack = getLeadTrack(jet);
204  if(!leadTrack){
205  LogTrace("VxTrkAssocInfo") << "No track to associate to! Returning vx no. 0.";
206  JetToVertexAssociation->insert(std::pair<const PFJet*, reco::VertexRef>(my_jet_ptr,output));
207  return output;
208  }
209  double largestWeight = 0.;
210  // Find the vertex that gives the lead track the highest weight.
211  TrackWeightInVertex weightComputer(leadTrack);
212  BOOST_FOREACH(const reco::VertexRef& vtx, vertices_) {
213  double weight = weightComputer(vtx);
214  if (weight > largestWeight) {
215  largestWeight = weight;
216  output = vtx;
217  }
218  }
219  // the weight was never larger than zero
220  if(algo_==kCombined && largestWeight < 1e-7){
221  LogTrace("VxTrkAssocInfo") << " No vertex had positive weight! Trying dZ instead... ";
222  DZtoTrack dzComputer(leadTrack);
223  double closestDistance = std::numeric_limits<double>::infinity();
224  BOOST_FOREACH(const reco::VertexRef& vtx, vertices_) {
225  double dz_i = dzComputer(vtx);
226  if (dz_i < closestDistance) {
227  closestDistance = dz_i;
228  output = vtx;
229  }
230  }
231  }
232  }
233 
234  JetToVertexAssociation->insert(std::pair<const PFJet*, reco::VertexRef>(my_jet_ptr,output));
235 
236  return output;
237 }
238 
239 
240 
241 }}
#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:52
std::map< const reco::PFJet *, reco::VertexRef > * JetToVertexAssociation
Coll filterCandRefs(const Coll &refcoll, bool invert=false) const
Filter a ref vector of PFCandidates.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
ParameterSet const & getParameterSet(ParameterSetID const &id)
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
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:21
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
#define LogTrace(id)
RecoTauVertexAssociator(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
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:125
const PFTauTagInfoRef & pfTauTagInfoRef() const
Definition: PFTau.cc:55
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.
edm::EDGetTokenT< reco::VertexCollection > vx_token
int weight
Definition: histoStyle.py:50
const reco::TrackBaseRef trk_