CMS 3D CMS Logo

PrimaryVertexAssignment.cc
Go to the documentation of this file.
7 
8 
9 
10 std::pair<int,PrimaryVertexAssignment::Quality>
12  const reco::TrackRef& trackRef,
13  const reco::Track* track,
15  const TransientTrackBuilder& builder) const {
16 
17  int iVertex = -1;
18  size_t index=0;
19  typedef reco::VertexCollection::const_iterator IV;
21  float bestweight=0;
22  for( auto const & vtx : vertices) {
23  float w = vtx.trackWeight(trackRef);
24  if (w > bestweight){
25  bestweight=w;
26  iVertex=index;
27  }
28  index++;
29  }
30 
31 
32  if(iVertex >= 0 ) return std::pair<int,PrimaryVertexAssignment::Quality>(iVertex,PrimaryVertexAssignment::UsedInFit);
33 
34  double dzmin = 1e99;
35  int vtxIdMinDz = -1;
36  for(IV iv=vertices.begin(); iv!=vertices.end(); ++iv) {
37  double dz = std::abs(track->dz(iv->position()));
38  if(dz<dzmin) {
39  dzmin = dz;
40  vtxIdMinDz = iv-vertices.begin();
41  }
42  }
43  // first use "closest in Z" with tight cuts (targetting primary particles)
44  if(vtxIdMinDz>=0 and (dzmin < maxDzForPrimaryAssignment_ or dzmin/track->dzError() < maxDzSigForPrimaryAssignment_ ))
45  {
46  iVertex=vtxIdMinDz;
47  }
48  if(iVertex >= 0 ) return std::pair<int,PrimaryVertexAssignment::Quality>(iVertex,PrimaryVertexAssignment::PrimaryDz);
49 
50  // if track not assigned yet, it could be a b-decay secondary , use jet axis dist criterion
51  // first find the closest jet within maxJetDeltaR_
52  int jetIdx = -1;
53  double minDeltaR = maxJetDeltaR_;
54  for(edm::View<reco::Candidate>::const_iterator ij=jets.begin(); ij!=jets.end(); ++ij)
55  {
56  if( ij->pt() < minJetPt_ ) continue; // skip jets below the jet Pt threshold
57 
58  double deltaR = reco::deltaR( *ij, *track );
59  if( deltaR < minDeltaR )
60  {
61  minDeltaR = deltaR;
62  jetIdx = std::distance(jets.begin(), ij);
63  }
64  }
65  // if jet found
66  if( jetIdx!=-1 )
67  {
68  reco::TransientTrack transientTrack = builder.build(*track);
69  GlobalVector direction(jets.at(jetIdx).px(), jets.at(jetIdx).py(), jets.at(jetIdx).pz());
70  // find the vertex with the smallest distanceToJetAxis that is still within maxDistaneToJetAxis_
71  int vtxIdx = -1;
72  double minDistanceToJetAxis = maxDistanceToJetAxis_;
73  for(IV iv=vertices.begin(); iv!=vertices.end(); ++iv)
74  {
75  // only check for vertices that are close enough in Z and for tracks that have not too high dXY
76  if(std::abs(track->dz(iv->position())) > maxDzForJetAxisAssigment_ || std::abs(track->dxy(iv->position())) > maxDxyForJetAxisAssigment_)
77  continue;
78 
79  double distanceToJetAxis = IPTools::jetTrackDistance(transientTrack, direction, *iv).second.value();
80  if( distanceToJetAxis < minDistanceToJetAxis )
81  {
82  minDistanceToJetAxis = distanceToJetAxis;
83  vtxIdx = std::distance(vertices.begin(), iv);
84  }
85  }
86  if( vtxIdx>=0 )
87  {
88  iVertex=vtxIdx;
89  }
90  }
91  if(iVertex >= 0 )
92  return std::pair<int,PrimaryVertexAssignment::Quality>(iVertex,PrimaryVertexAssignment::BTrack);
93 
94  // if the track is not compatible with other PVs but is compatible with the BeamSpot, we may simply have not reco'ed the PV!
95  // we still point it to the closest in Z, but flag it as possible orphan-primary
96  if(std::abs(track->dxy(vertices[0].position()))<maxDxyForNotReconstructedPrimary_ && std::abs(track->dxy(vertices[0].position())/track->dxyError())<maxDxySigForNotReconstructedPrimary_)
97  return std::pair<int,PrimaryVertexAssignment::Quality>(vtxIdMinDz,PrimaryVertexAssignment::NotReconstructedPrimary);
98 
99  //FIXME: here we could better handle V0s and NucInt
100 
101  // all other tracks could be non-B secondaries and we just attach them with closest Z
102  if(vtxIdMinDz>=0)
103  return std::pair<int,PrimaryVertexAssignment::Quality>(vtxIdMinDz,PrimaryVertexAssignment::OtherDz);
104  //If for some reason even the dz failed (when?) we consider the track not assigned
105  return std::pair<int,PrimaryVertexAssignment::Quality>(-1,PrimaryVertexAssignment::Unassigned);
106 }
107 
108 
const double w
Definition: UKUtility.cc:23
double dxyError() const
error on dxy
Definition: TrackBase.h:791
reco::TransientTrack build(const reco::Track *p) const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:200
const_iterator begin() const
vector< PseudoJet > jets
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
std::vector< LinkConnSpec >::const_iterator IT
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:604
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:37
const_reference at(size_type pos) const
const_iterator end() const
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:586
std::pair< int, PrimaryVertexAssignment::Quality > chargedHadronVertex(const reco::VertexCollection &vertices, const reco::TrackRef &trackRef, const reco::Track *track, const edm::View< reco::Candidate > &jets, const TransientTrackBuilder &builder) const