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  float dzE=sqrt(track->dzError()*track->dzError()+vertices[vtxIdMinDz].covariance(2,2));
45  if(vtxIdMinDz>=0 and (dzmin < maxDzForPrimaryAssignment_ and dzmin/dzE < maxDzSigForPrimaryAssignment_ and track->dzError()<maxDzErrorForPrimaryAssignment_))
46  {
47  iVertex=vtxIdMinDz;
48  }
49  if(iVertex >= 0 ) return std::pair<int,PrimaryVertexAssignment::Quality>(iVertex,PrimaryVertexAssignment::PrimaryDz);
50 
51  // if track not assigned yet, it could be a b-decay secondary , use jet axis dist criterion
52  // first find the closest jet within maxJetDeltaR_
53  int jetIdx = -1;
54  double minDeltaR = maxJetDeltaR_;
55  for(edm::View<reco::Candidate>::const_iterator ij=jets.begin(); ij!=jets.end(); ++ij)
56  {
57  if( ij->pt() < minJetPt_ ) continue; // skip jets below the jet Pt threshold
58 
59  double deltaR = reco::deltaR( *ij, *track );
60  if( deltaR < minDeltaR and track->dzError()<maxDzErrorForPrimaryAssignment_ )
61  {
62  minDeltaR = deltaR;
63  jetIdx = std::distance(jets.begin(), ij);
64  }
65  }
66  // if jet found
67  if( jetIdx!=-1 )
68  {
69  reco::TransientTrack transientTrack = builder.build(*track);
70  GlobalVector direction(jets.at(jetIdx).px(), jets.at(jetIdx).py(), jets.at(jetIdx).pz());
71  // find the vertex with the smallest distanceToJetAxis that is still within maxDistaneToJetAxis_
72  int vtxIdx = -1;
73  double minDistanceToJetAxis = maxDistanceToJetAxis_;
74  for(IV iv=vertices.begin(); iv!=vertices.end(); ++iv)
75  {
76  // only check for vertices that are close enough in Z and for tracks that have not too high dXY
77  if(std::abs(track->dz(iv->position())) > maxDzForJetAxisAssigment_ || std::abs(track->dxy(iv->position())) > maxDxyForJetAxisAssigment_)
78  continue;
79 
80  double distanceToJetAxis = IPTools::jetTrackDistance(transientTrack, direction, *iv).second.value();
81  if( distanceToJetAxis < minDistanceToJetAxis )
82  {
83  minDistanceToJetAxis = distanceToJetAxis;
84  vtxIdx = std::distance(vertices.begin(), iv);
85  }
86  }
87  if( vtxIdx>=0 )
88  {
89  iVertex=vtxIdx;
90  }
91  }
92  if(iVertex >= 0 )
93  return std::pair<int,PrimaryVertexAssignment::Quality>(iVertex,PrimaryVertexAssignment::BTrack);
94 
95  // if the track is not compatible with other PVs but is compatible with the BeamSpot, we may simply have not reco'ed the PV!
96  // we still point it to the closest in Z, but flag it as possible orphan-primary
97  if(std::abs(track->dxy(vertices[0].position()))<maxDxyForNotReconstructedPrimary_ && std::abs(track->dxy(vertices[0].position())/track->dxyError())<maxDxySigForNotReconstructedPrimary_)
98  return std::pair<int,PrimaryVertexAssignment::Quality>(vtxIdMinDz,PrimaryVertexAssignment::NotReconstructedPrimary);
99 
100  //FIXME: here we could better handle V0s and NucInt
101 
102  // all other tracks could be non-B secondaries and we just attach them with closest Z
103  if(vtxIdMinDz>=0)
104  return std::pair<int,PrimaryVertexAssignment::Quality>(vtxIdMinDz,PrimaryVertexAssignment::OtherDz);
105  //If for some reason even the dz failed (when?) we consider the track not assigned
106  return std::pair<int,PrimaryVertexAssignment::Quality>(-1,PrimaryVertexAssignment::Unassigned);
107 }
108 
109 
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
T sqrt(T t)
Definition: SSEVec.h:18
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 dzError() const
error on dz
Definition: TrackBase.h:809
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