CMS 3D CMS Logo

TrackVertexArbitration.h
Go to the documentation of this file.
1 #ifndef TrackVertexArbitration_H
2 #define TrackVertexArbitration_H
3 #include <memory>
4 #include <set>
5 #include <unordered_map>
6 
12 
18 
25 
31 
40 
42 
44 //#include "DataFormats/Math/interface/deltaR.h"
45 
46 //#define VTXDEBUG
47 
48 namespace svhelper {
49  inline double cov33(const reco::Vertex &sv) { return sv.covariance(3, 3); }
50  inline double cov33(const reco::VertexCompositePtrCandidate &sv) { return sv.vertexCovariance(3, 3); }
51 } // namespace svhelper
52 
53 template <class VTX>
55 public:
57 
59  const reco::Vertex &pv,
60  std::vector<reco::TransientTrack> &selectedTracks,
61  std::vector<VTX> &secondaryVertices);
62 
63 private:
65 
70  double dRCut;
71  double distCut;
72  double sigCut;
73  double dLenFraction;
74  double fitterSigmacut; // = 3.0;
75  double fitterTini; // = 256.;
76  double fitterRatio; // = 0.25;
78  double trackMinPt;
81  double sign;
82 };
83 
85 template <class VTX>
87  : primaryVertexCollection(params.getParameter<edm::InputTag>("primaryVertices")),
88  secondaryVertexCollection(params.getParameter<edm::InputTag>("secondaryVertices")),
89  trackCollection(params.getParameter<edm::InputTag>("tracks")),
90  beamSpotCollection(params.getParameter<edm::InputTag>("beamSpot")),
91  dRCut(params.getParameter<double>("dRCut")),
92  distCut(params.getParameter<double>("distCut")),
93  sigCut(params.getParameter<double>("sigCut")),
94  dLenFraction(params.getParameter<double>("dLenFraction")),
95  fitterSigmacut(params.getParameter<double>("fitterSigmacut")),
96  fitterTini(params.getParameter<double>("fitterTini")),
97  fitterRatio(params.getParameter<double>("fitterRatio")),
98  trackMinLayers(params.getParameter<int32_t>("trackMinLayers")),
99  trackMinPt(params.getParameter<double>("trackMinPt")),
100  trackMinPixels(params.getParameter<int32_t>("trackMinPixels")),
101  maxTimeSignificance(params.getParameter<double>("maxTimeSignificance")) {
102  sign = 1.0;
103  if (dRCut < 0) {
104  sign = -1.0;
105  }
106  dRCut *= dRCut;
107 }
108 template <class VTX>
110  if (!track.isValid())
111  return false;
112  if (track.track().hitPattern().trackerLayersWithMeasurement() < trackMinLayers)
113  return false;
114  if (track.track().pt() < trackMinPt)
115  return false;
116  if (track.track().hitPattern().numberOfValidPixelHits() < trackMinPixels)
117  return false;
118 
119  return true;
120 }
121 
123  return sv.trackWeight(track.trackBaseRef());
124 }
127  dynamic_cast<const reco::CandidatePtrTransientTrack *>(tt.basicTransientTrack());
128  if (cptt == nullptr)
129  edm::LogError("DynamicCastingFailed") << "Casting of TransientTrack to CandidatePtrTransientTrack failed!";
130  else {
131  const reco::CandidatePtr &c = cptt->candidate();
132  if (std::find(sv.daughterPtrVector().begin(), sv.daughterPtrVector().end(), c) != sv.daughterPtrVector().end())
133  return 1.0;
134  else
135  return 0;
136  }
137  return 0;
138 }
139 
140 template <class VTX>
142  const reco::Vertex &pv,
143  std::vector<reco::TransientTrack> &selectedTracks,
144  std::vector<VTX> &secondaryVertices) {
145  using namespace reco;
146 
147  //std::cout << "PV: " << pv.position() << std::endl;
148  VertexDistance3D dist;
154 
155  std::vector<VTX> recoVertices;
156  VertexDistance3D vdist;
157  GlobalPoint ppv(pv.position().x(), pv.position().y(), pv.position().z());
158 
159  std::unordered_map<unsigned int, Measurement1D> cachedIP;
160  for (typename std::vector<VTX>::const_iterator sv = secondaryVertices.begin(); sv != secondaryVertices.end(); ++sv) {
161  const double svTime(sv->t()), svTimeCov(svhelper::cov33(*sv));
162  const bool svHasTime = svTimeCov > 0.;
163 
164  GlobalPoint ssv(sv->position().x(), sv->position().y(), sv->position().z());
165  GlobalVector flightDir = ssv - ppv;
166  // std::cout << "Vertex : " << sv-secondaryVertices->begin() << " " << sv->position() << std::endl;
167  Measurement1D dlen =
169  std::vector<reco::TransientTrack> selTracks;
170  for (unsigned int itrack = 0; itrack < selectedTracks.size(); itrack++) {
171  TransientTrack &tt = (selectedTracks)[itrack];
172  if (!trackFilterArbitrator(tt))
173  continue;
174  tt.setBeamSpot(*beamSpot);
175  float w = trackWeight(*sv, tt);
176  Measurement1D ipv;
177  if (cachedIP.count(itrack)) {
178  ipv = cachedIP[itrack];
179  } else {
180  std::pair<bool, Measurement1D> ipvp = IPTools::absoluteImpactParameter3D(tt, pv);
181  cachedIP[itrack] = ipvp.second;
182  ipv = ipvp.second;
183  }
184 
185  AnalyticalImpactPointExtrapolator extrapolator(tt.field());
187  extrapolator.extrapolate(tt.impactPointState(), RecoVertex::convertPos(sv->position()));
188  if (!tsos.isValid())
189  continue;
190  GlobalPoint refPoint = tsos.globalPosition();
191  GlobalError refPointErr = tsos.cartesianError().position();
192  Measurement1D isv =
194  VertexState(refPoint, refPointErr));
195 
196  float dR = Geom::deltaR2(((sign > 0) ? flightDir : -flightDir),
197  tt.track()); //.eta(), flightDir.phi(), tt.track().eta(), tt.track().phi());
198 
199  double timeSig = 0.;
200  if (svHasTime && edm::isFinite(tt.timeExt())) {
201  double tError = std::sqrt(std::pow(tt.dtErrorExt(), 2) + svTimeCov);
202  timeSig = std::abs(tt.timeExt() - svTime) / tError;
203  }
204 
205  if (w > 0 || (isv.significance() < sigCut && isv.value() < distCut && isv.value() < dlen.value() * dLenFraction &&
206  timeSig < maxTimeSignificance)) {
207  if ((isv.value() < ipv.value()) && isv.value() < distCut && isv.value() < dlen.value() * dLenFraction &&
208  dR < dRCut && timeSig < maxTimeSignificance) {
209 #ifdef VTXDEBUG
210  if (w > 0.5)
211  std::cout << " = ";
212  else
213  std::cout << " + ";
214 #endif
215  selTracks.push_back(tt);
216  } else {
217 #ifdef VTXDEBUG
218  if (w > 0.5 && isv.value() > ipv.value())
219  std::cout << " - ";
220  else
221  std::cout << " ";
222 #endif
223  //add also the tracks used in previous fitting that are still closer to Sv than Pv
224  if (w > 0.5 && isv.value() <= ipv.value() && dR < dRCut && timeSig < maxTimeSignificance) {
225  selTracks.push_back(tt);
226 #ifdef VTXDEBUG
227  std::cout << " = ";
228 #endif
229  }
230  if (w > 0.5 && isv.value() <= ipv.value() && dR >= dRCut) {
231 #ifdef VTXDEBUG
232  std::cout << " - ";
233 #endif
234  }
235  }
236 #ifdef VTXDEBUG
237 
238  std::cout << "t : " << itrack << " ref " << ref.key() << " w: " << w << " svip: " << isv.significance() << " "
239  << isv.value() << " pvip: " << ipv.significance() << " " << ipv.value() << " res "
240  << tt.track().residualX(0) << "," << tt.track().residualY(0)
241 // << " tpvip: " << itpv.second.significance() << " " << itpv.second.value() << " dr: " << dR << std::endl;
242 #endif
243 
244  } else {
245 #ifdef VTXDEBUG
246 
247  std::cout << " . t : " << itrack << " ref " << ref.key() << " w: " << w
248  << " svip: " << isv.second.significance() << " " << isv.second.value()
249  << " pvip: " << ipv.significance() << " " << ipv.value() << " dr: " << dR << std::endl;
250 #endif
251  }
252  }
253 
254  if (selTracks.size() >= 2) {
255  TransientVertex singleFitVertex;
256  singleFitVertex = theAdaptiveFitter.vertex(selTracks, ssv);
257 
258  if (singleFitVertex.isValid()) {
259  if (pv.covariance(3, 3) > 0.)
260  svhelper::updateVertexTime(singleFitVertex);
261  recoVertices.push_back(VTX(singleFitVertex));
262 
263 #ifdef VTXDEBUG
264  const VTX &extVertex = recoVertices.back();
265  GlobalVector vtxDir = GlobalVector(extVertex.p4().X(), extVertex.p4().Y(), extVertex.p4().Z());
266 
267  std::cout << " pointing : " << Geom::deltaR(extVertex.position() - pv.position(), vtxDir) << std::endl;
268 #endif
269  }
270  }
271  }
272  return recoVertices;
273 }
274 
275 #endif
Vector3DBase
Definition: Vector3DBase.h:8
AdaptiveVertexFitter
Definition: AdaptiveVertexFitter.h:29
HLT_FULL_cff.dLenFraction
dLenFraction
Definition: HLT_FULL_cff.py:52036
TrackVertexArbitration::secondaryVertexCollection
edm::InputTag secondaryVertexCollection
Definition: TrackVertexArbitration.h:67
Handle.h
KalmanVertexUpdator< 5 >
Measurement1D
Definition: Measurement1D.h:11
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
AnalyticalImpactPointExtrapolator.h
HLT_FULL_cff.trackMinPixels
trackMinPixels
Definition: HLT_FULL_cff.py:52037
EDProducer.h
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
TrackVertexArbitration::sigCut
double sigCut
Definition: TrackVertexArbitration.h:72
KalmanVertexTrackCompatibilityEstimator.h
TransientVertex::isValid
bool isValid() const
Definition: TransientVertex.h:195
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
SVTimeHelpers.h
VectorUtil.h
TrackVertexArbitration
Definition: TrackVertexArbitration.h:54
edm
HLT enums.
Definition: AlignableModifier.h:19
Measurement1D::value
double value() const
Definition: Measurement1D.h:25
TrackVertexArbitration::primaryVertexCollection
edm::InputTag primaryVertexCollection
Definition: TrackVertexArbitration.h:66
IPTools::absoluteImpactParameter3D
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:38
VertexDistance3D::distance
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
Definition: VertexDistance3D.cc:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
TrackVertexArbitration::trackVertexArbitrator
std::vector< VTX > trackVertexArbitrator(edm::Handle< reco::BeamSpot > &beamSpot, const reco::Vertex &pv, std::vector< reco::TransientTrack > &selectedTracks, std::vector< VTX > &secondaryVertices)
Definition: TrackVertexArbitration.h:141
svhelper
Definition: SVTimeHelpers.h:9
TrackVertexArbitration::maxTimeSignificance
double maxTimeSignificance
Definition: TrackVertexArbitration.h:80
TrackVertexArbitration::dLenFraction
double dLenFraction
Definition: TrackVertexArbitration.h:73
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
reco::CandidatePtrTransientTrack
Definition: CandidatePtrTransientTrack.h:19
ConvertToFromReco.h
VertexDistance3D.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
TrackVertexArbitration::trackFilterArbitrator
bool trackFilterArbitrator(const reco::TransientTrack &track) const
Definition: TrackVertexArbitration.h:109
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
TransientTrack.h
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
AdaptiveVertexFitter::vertex
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
Definition: AdaptiveVertexFitter.cc:158
edm::Handle< reco::BeamSpot >
HLT_FULL_cff.dRCut
dRCut
Definition: HLT_FULL_cff.py:52039
TrackVertexArbitration::TrackVertexArbitration
TrackVertexArbitration(const edm::ParameterSet &params)
Definition: TrackVertexArbitration.h:86
reco::VertexCompositePtrCandidate
Definition: VertexCompositePtrCandidate.h:16
HLT_FULL_cff.trackMinPt
trackMinPt
Definition: HLT_FULL_cff.py:52033
L1TEGammaOffline_cfi.beamSpotCollection
beamSpotCollection
Definition: L1TEGammaOffline_cfi.py:35
CandidateFwd.h
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
Track.h
TrackFwd.h
BeamSpot.h
HLT_FULL_cff.maxTimeSignificance
maxTimeSignificance
Definition: HLT_FULL_cff.py:52038
w
const double w
Definition: UKUtility.cc:23
KalmanVertexTrackCompatibilityEstimator
Definition: KalmanVertexTrackCompatibilityEstimator.h:24
TrackVertexArbitration::beamSpotCollection
edm::InputTag beamSpotCollection
Definition: TrackVertexArbitration.h:69
TrackVertexArbitration::trackCollection
edm::InputTag trackCollection
Definition: TrackVertexArbitration.h:68
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
TrackVertexArbitration::sign
double sign
Definition: TrackVertexArbitration.h:81
TrackVertexArbitration::fitterRatio
double fitterRatio
Definition: TrackVertexArbitration.h:76
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
TrackVertexArbitration::trackMinLayers
int trackMinLayers
Definition: TrackVertexArbitration.h:77
svhelper::updateVertexTime
void updateVertexTime(TransientVertex &vtx)
Definition: SVTimeHelpers.h:11
VertexDistance3D
Definition: VertexDistance3D.h:13
Point3DBase< float, GlobalTag >
KalmanVertexSmoother
Definition: KalmanVertexSmoother.h:6
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
Vertex.h
Measurement1D::significance
double significance() const
Definition: Measurement1D.h:29
TransientTrackBuilder.h
edm::ParameterSet
Definition: ParameterSet.h:47
AnalyticalImpactPointExtrapolator
Definition: AnalyticalImpactPointExtrapolator.h:26
RecoVertex::convertError
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
duplicaterechits_cfi.trackCollection
trackCollection
Definition: duplicaterechits_cfi.py:4
Event.h
TrackVertexArbitration::fitterTini
double fitterTini
Definition: TrackVertexArbitration.h:75
HLT_FULL_cff.trackMinLayers
trackMinLayers
Definition: HLT_FULL_cff.py:52028
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
GeometricAnnealing
Definition: GeometricAnnealing.h:7
HLT_FULL_cff.sigCut
sigCut
Definition: HLT_FULL_cff.py:52031
TrackVertexArbitration::dRCut
double dRCut
Definition: TrackVertexArbitration.h:70
KalmanVertexUpdator.h
GlobalErrorBase< double, ErrorMatrixTag >
TrackVertexArbitration::trackMinPixels
int trackMinPixels
Definition: TrackVertexArbitration.h:79
KalmanVertexSmoother.h
HLT_FULL_cff.secondaryVertices
secondaryVertices
Definition: HLT_FULL_cff.py:52021
TransientVertex
Definition: TransientVertex.h:18
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
TransientTrackRecord.h
DefaultLinearizationPointFinder
Definition: DefaultLinearizationPointFinder.h:13
InputTag.h
edm::Ptr< Candidate >
HLT_FULL_cff.fitterTini
fitterTini
Definition: HLT_FULL_cff.py:51993
VertexFwd.h
CandidatePtrTransientTrack.h
IPTools.h
reco::TransientTrack
Definition: TransientTrack.h:19
isFinite.h
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
VertexState
Definition: VertexState.h:13
MaterialEffects_cfi.distCut
distCut
Definition: MaterialEffects_cfi.py:128
TrackVertexArbitration::trackMinPt
double trackMinPt
Definition: TrackVertexArbitration.h:78
TrackVertexArbitration::distCut
double distCut
Definition: TrackVertexArbitration.h:71
trackWeight
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)
Definition: TrackVertexArbitration.h:122
RecoVertex::convertPos
reco::Vertex::Point convertPos(const GlobalPoint &p)
Definition: ConvertToFromReco.h:7
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::isFinite
constexpr bool isFinite(T x)
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
ParameterSet.h
AdaptiveVertexFitter.h
edm::InputTag
Definition: InputTag.h:15
HLT_FULL_cff.fitterRatio
fitterRatio
Definition: HLT_FULL_cff.py:51994
reco::Vertex
Definition: Vertex.h:35
TrackCollections2monitor_cff.selectedTracks
selectedTracks
Definition: TrackCollections2monitor_cff.py:32
svhelper::cov33
double cov33(const reco::Vertex &sv)
Definition: TrackVertexArbitration.h:49
reco::CandidatePtrTransientTrack::candidate
CandidatePtr candidate() const override
Definition: CandidatePtrTransientTrack.h:79
HLT_FULL_cff.fitterSigmacut
fitterSigmacut
Definition: HLT_FULL_cff.py:51986
TrackVertexArbitration::fitterSigmacut
double fitterSigmacut
Definition: TrackVertexArbitration.h:74