CMS 3D CMS Logo

PrimaryVertexAssignment.cc
Go to the documentation of this file.
8 
9 
10 std::pair<int,PrimaryVertexAssignment::Quality>
12  const reco::TrackRef& trackRef,
13  const reco::Track* track,
14  float time,
15  float timeReso, // <0 if timing not available for this object
17  const TransientTrackBuilder& builder) const {
18 
19  typedef reco::VertexCollection::const_iterator IV;
21 
22  int iVertex = -1;
23  size_t index=0;
24  float bestweight=0;
25  for( auto const & vtx : vertices) {
26  float w = vtx.trackWeight(trackRef);
27  if (w > bestweight){
28  bestweight=w;
29  iVertex=index;
30  }
31  index++;
32  }
33 
34  bool useTime = useTiming_;
35  if (edm::isNotFinite(time) || timeReso<1e-6) {
36  useTime = false;
37  time = 0.;
38  timeReso = -1.;
39  }
40 
41  if (preferHighRanked_) {
42  for(IV iv=vertices.begin(); iv!=vertices.end(); ++iv) {
43  int ivtx = iv - vertices.begin();
44  if (iVertex == ivtx) return std::pair<int,PrimaryVertexAssignment::Quality>(ivtx,PrimaryVertexAssignment::UsedInFit);
45 
46  double dz = std::abs(track->dz(iv->position()));
47  double dt = std::abs(time-iv->t());
48 
49  bool useTimeVtx = useTime && iv->tError()>0.;
50 
51  if ((dz < maxDzForPrimaryAssignment_ or dz/track->dzError() < maxDzSigForPrimaryAssignment_ ) and (!useTimeVtx or dt/timeReso < maxDtSigForPrimaryAssignment_)) {
52  return std::pair<int,PrimaryVertexAssignment::Quality>(ivtx,PrimaryVertexAssignment::PrimaryDz);
53  }
54  }
55  }
56 
57 
58  if(iVertex >= 0 ) return std::pair<int,PrimaryVertexAssignment::Quality>(iVertex,PrimaryVertexAssignment::UsedInFit);
59 
60  double distmin = std::numeric_limits<double>::max();
61  double dzmin = std::numeric_limits<double>::max();
62  double dtmin = std::numeric_limits<double>::max();
63  int vtxIdMinSignif = -1;
64  for(IV iv=vertices.begin(); iv!=vertices.end(); ++iv) {
65  double dz = std::abs(track->dz(iv->position()));
66  double dt = std::abs(time-iv->t());
67 
68  double dzsig = dz/track->dzError();
69  double dist = dzsig*dzsig;
70 
71  bool useTimeVtx = useTime && iv->tError()>0.;
72  if (useTime && !useTimeVtx) {
73  dt = timeReso;
74  }
75 
76  if (useTime) {
77  double dtsig = dt/timeReso;
78 
79  dist += dtsig*dtsig;
80  }
81  if(dist<distmin) {
82  distmin = dist;
83  dzmin = dz;
84  dtmin = dt;
85  vtxIdMinSignif = iv-vertices.begin();
86  }
87  }
88 
89  // first use "closest in Z" with tight cuts (targetting primary particles)
90  const float add_cov = vtxIdMinSignif >= 0 ? vertices[vtxIdMinSignif].covariance(2,2) : 0.f;
91  const float dzE=sqrt(track->dzError()*track->dzError()+add_cov);
92  if(vtxIdMinSignif>=0 and
93  (dzmin < maxDzForPrimaryAssignment_ and dzmin/dzE < maxDzSigForPrimaryAssignment_ and track->dzError()<maxDzErrorForPrimaryAssignment_) and
94  (!useTime or dtmin/timeReso < maxDtSigForPrimaryAssignment_) )
95  {
96  iVertex=vtxIdMinSignif;
97  }
98 
99  if(iVertex >= 0 ) return std::pair<int,PrimaryVertexAssignment::Quality>(iVertex,PrimaryVertexAssignment::PrimaryDz);
100 
101 
102 
103  // if track not assigned yet, it could be a b-decay secondary , use jet axis dist criterion
104  // first find the closest jet within maxJetDeltaR_
105  int jetIdx = -1;
106  double minDeltaR = maxJetDeltaR_;
107  for(edm::View<reco::Candidate>::const_iterator ij=jets.begin(); ij!=jets.end(); ++ij)
108  {
109  if( ij->pt() < minJetPt_ ) continue; // skip jets below the jet Pt threshold
110 
111  double deltaR = reco::deltaR( *ij, *track );
112  if( deltaR < minDeltaR and track->dzError()<maxDzErrorForPrimaryAssignment_ )
113  {
114  minDeltaR = deltaR;
115  jetIdx = std::distance(jets.begin(), ij);
116  }
117  }
118  // if jet found
119  if( jetIdx!=-1 )
120  {
121  reco::TransientTrack transientTrack = builder.build(*track);
122  GlobalVector direction(jets.at(jetIdx).px(), jets.at(jetIdx).py(), jets.at(jetIdx).pz());
123  // find the vertex with the smallest distanceToJetAxis that is still within maxDistaneToJetAxis_
124  int vtxIdx = -1;
125  double minDistanceToJetAxis = maxDistanceToJetAxis_;
126  for(IV iv=vertices.begin(); iv!=vertices.end(); ++iv)
127  {
128  // only check for vertices that are close enough in Z and for tracks that have not too high dXY
129  if(std::abs(track->dz(iv->position())) > maxDzForJetAxisAssigment_ || std::abs(track->dxy(iv->position())) > maxDxyForJetAxisAssigment_)
130  continue;
131 
132  double distanceToJetAxis = IPTools::jetTrackDistance(transientTrack, direction, *iv).second.value();
133  if( distanceToJetAxis < minDistanceToJetAxis )
134  {
135  minDistanceToJetAxis = distanceToJetAxis;
136  vtxIdx = std::distance(vertices.begin(), iv);
137  }
138  }
139  if( vtxIdx>=0 )
140  {
141  iVertex=vtxIdx;
142  }
143  }
144  if(iVertex >= 0 )
145  return std::pair<int,PrimaryVertexAssignment::Quality>(iVertex,PrimaryVertexAssignment::BTrack);
146 
147  // if the track is not compatible with other PVs but is compatible with the BeamSpot, we may simply have not reco'ed the PV!
148  // we still point it to the closest in Z, but flag it as possible orphan-primary
149  if(!vertices.empty() && std::abs(track->dxy(vertices[0].position()))<maxDxyForNotReconstructedPrimary_ && std::abs(track->dxy(vertices[0].position())/track->dxyError())<maxDxySigForNotReconstructedPrimary_)
150  return std::pair<int,PrimaryVertexAssignment::Quality>(vtxIdMinSignif,PrimaryVertexAssignment::NotReconstructedPrimary);
151 
152  //FIXME: here we could better handle V0s and NucInt
153 
154  // all other tracks could be non-B secondaries and we just attach them with closest Z
155  if(vtxIdMinSignif>=0)
156  return std::pair<int,PrimaryVertexAssignment::Quality>(vtxIdMinSignif,PrimaryVertexAssignment::OtherDz);
157  //If for some reason even the dz failed (when?) we consider the track not assigned
158  return std::pair<int,PrimaryVertexAssignment::Quality>(-1,PrimaryVertexAssignment::Unassigned);
159 }
160 
161 
float dt
Definition: AMPTWrapper.h:126
const double w
Definition: UKUtility.cc:23
double dxyError() const
error on dxy
Definition: TrackBase.h:796
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
bool isNotFinite(T x)
Definition: isFinite.h:10
T sqrt(T t)
Definition: SSEVec.h:18
vector< PseudoJet > jets
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::pair< int, PrimaryVertexAssignment::Quality > chargedHadronVertex(const reco::VertexCollection &vertices, const reco::TrackRef &trackRef, const reco::Track *track, float trackTime, float trackTimeResolution, const edm::View< reco::Candidate > &jets, const TransientTrackBuilder &builder) const
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:609
double dzError() const
error on dz
Definition: TrackBase.h:814
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:591