CMS 3D CMS Logo

SeedingTracksConverter.cc
Go to the documentation of this file.
3 
6 
9 
11 
16 
18 
20 
21 namespace btagbtvdeep {
22 
23  void seedingTracksToFeatures(const std::vector<reco::TransientTrack>& selectedTracks,
24  const std::vector<float>& masses,
25  const reco::Jet& jet,
26  const reco::Vertex& pv,
27  HistogramProbabilityEstimator* probabilityEstimator,
29  std::vector<btagbtvdeep::SeedingTrackFeatures>& seedingT_features_vector)
30 
31  {
32  GlobalVector jetdirection(jet.px(), jet.py(), jet.pz());
33  GlobalPoint pvp(pv.x(), pv.y(), pv.z());
34 
35  std::multimap<double, std::pair<btagbtvdeep::SeedingTrackInfoBuilder, std::vector<btagbtvdeep::TrackPairFeatures>>>
36  sortedSeedsMap;
37  std::multimap<double, btagbtvdeep::TrackPairInfoBuilder> sortedNeighboursMap;
38 
39  std::vector<btagbtvdeep::TrackPairFeatures> tp_features_vector;
40 
41  sortedSeedsMap.clear();
42  seedingT_features_vector.clear();
43 
44  std::vector<std::pair<bool, Measurement1D>> absIP3D(selectedTracks.size());
45  std::vector<std::pair<bool, Measurement1D>> absIP2D(selectedTracks.size());
46  std::vector<bool> absIP3D_filled(selectedTracks.size(), false);
47  std::vector<bool> absIP2D_filled(selectedTracks.size(), false);
48 
49  unsigned int selTrackCount = 0;
50 
51  for (auto const& it : selectedTracks) {
52  selTrackCount += 1;
53  sortedNeighboursMap.clear();
54  tp_features_vector.clear();
55 
56  if (reco::deltaR(it.track(), jet) > 0.4)
57  continue;
58 
59  std::pair<bool, Measurement1D> ip = IPTools::absoluteImpactParameter3D(it, pv);
60 
61  absIP3D[selTrackCount - 1] = ip;
62  absIP3D_filled[selTrackCount - 1] = true;
63 
64  std::pair<double, Measurement1D> jet_dist = IPTools::jetTrackDistance(it, jetdirection, pv);
66  IPTools::closestApproachToJet(it.impactPointState(), pv, jetdirection, it.field());
67  float length = 999;
68  if (closest.isValid())
69  length = (closest.globalPosition() - pvp).mag();
70 
71  if (!(ip.first && ip.second.value() >= 0.0 && ip.second.significance() >= 1.0 && ip.second.value() <= 9999. &&
72  ip.second.significance() <= 9999. && it.track().normalizedChi2() < 5. &&
73  std::fabs(it.track().dxy(pv.position())) < 2 && std::fabs(it.track().dz(pv.position())) < 17 &&
74  jet_dist.second.value() < 0.07 && length < 5.))
75  continue;
76 
77  std::pair<bool, Measurement1D> ip2d = IPTools::absoluteTransverseImpactParameter(it, pv);
78 
79  absIP2D[selTrackCount - 1] = ip2d;
80  absIP2D_filled[selTrackCount - 1] = true;
81 
83  seedInfo.buildSeedingTrackInfo(&(it),
84  pv,
85  jet,
86  masses[selTrackCount - 1],
87  ip,
88  ip2d,
89  jet_dist.second.value(),
90  length,
91  probabilityEstimator,
93 
94  unsigned int neighbourTrackCount = 0;
95 
96  for (auto const& tt : selectedTracks) {
97  neighbourTrackCount += 1;
98 
99  if (neighbourTrackCount == selTrackCount)
100  continue;
101  if (std::fabs(pv.z() - tt.track().vz()) > 0.1)
102  continue;
103 
104  //avoid calling IPs twice
105  if (!absIP2D_filled[neighbourTrackCount - 1]) {
106  absIP2D[neighbourTrackCount - 1] = IPTools::absoluteTransverseImpactParameter(tt, pv);
107  absIP2D_filled[neighbourTrackCount - 1] = true;
108  }
109 
110  if (!absIP3D_filled[neighbourTrackCount - 1]) {
111  absIP3D[neighbourTrackCount - 1] = IPTools::absoluteImpactParameter3D(tt, pv);
112  absIP3D_filled[neighbourTrackCount - 1] = true;
113  }
114 
115  std::pair<bool, Measurement1D> t_ip = absIP3D[neighbourTrackCount - 1];
116  std::pair<bool, Measurement1D> t_ip2d = absIP2D[neighbourTrackCount - 1];
117 
118  btagbtvdeep::TrackPairInfoBuilder trackPairInfo;
119  trackPairInfo.buildTrackPairInfo(&(it), &(tt), pv, masses[neighbourTrackCount - 1], jetdirection, t_ip, t_ip2d);
120  sortedNeighboursMap.insert(std::make_pair(trackPairInfo.pca_distance(), trackPairInfo));
121  }
122 
123  int max_counter = 0;
124 
125  for (auto const& im : sortedNeighboursMap) {
126  if (max_counter >= 20)
127  break;
128  btagbtvdeep::TrackPairFeatures tp_features;
129 
130  auto const& tp = im.second;
131 
132  tp_features.pt = (tp.track_pt() == 0) ? 0 : 1.0 / tp.track_pt();
133  tp_features.eta = tp.track_eta();
134  tp_features.phi = tp.track_phi();
135  tp_features.mass = tp.track_candMass();
136  tp_features.dz = logWithOffset(tp.track_dz());
137  tp_features.dxy = logWithOffset(tp.track_dxy());
138  tp_features.ip3D = log(tp.track_ip3d());
139  tp_features.sip3D = log(tp.track_ip3dSig());
140  tp_features.ip2D = log(tp.track_ip2d());
141  tp_features.sip2D = log(tp.track_ip2dSig());
142  tp_features.distPCA = log(tp.pca_distance());
143  tp_features.dsigPCA = log(tp.pca_significance());
144  tp_features.x_PCAonSeed = tp.pcaSeed_x();
145  tp_features.y_PCAonSeed = tp.pcaSeed_y();
146  tp_features.z_PCAonSeed = tp.pcaSeed_z();
147  tp_features.xerr_PCAonSeed = tp.pcaSeed_xerr();
148  tp_features.yerr_PCAonSeed = tp.pcaSeed_yerr();
149  tp_features.zerr_PCAonSeed = tp.pcaSeed_zerr();
150  tp_features.x_PCAonTrack = tp.pcaTrack_x();
151  tp_features.y_PCAonTrack = tp.pcaTrack_y();
152  tp_features.z_PCAonTrack = tp.pcaTrack_z();
153  tp_features.xerr_PCAonTrack = tp.pcaTrack_xerr();
154  tp_features.yerr_PCAonTrack = tp.pcaTrack_yerr();
155  tp_features.zerr_PCAonTrack = tp.pcaTrack_zerr();
156  tp_features.dotprodTrack = tp.dotprodTrack();
157  tp_features.dotprodSeed = tp.dotprodSeed();
158  tp_features.dotprodTrackSeed2D = tp.dotprodTrackSeed2D();
159  tp_features.dotprodTrackSeed3D = tp.dotprodTrackSeed3D();
160  tp_features.dotprodTrackSeedVectors2D = tp.dotprodTrackSeed2DV();
161  tp_features.dotprodTrackSeedVectors3D = tp.dotprodTrackSeed3DV();
162  tp_features.pvd_PCAonSeed = log(tp.pcaSeed_dist());
163  tp_features.pvd_PCAonTrack = log(tp.pcaTrack_dist());
164  tp_features.dist_PCAjetAxis = log(tp.pca_jetAxis_dist());
165  tp_features.dotprod_PCAjetMomenta = tp.pca_jetAxis_dotprod();
166  tp_features.deta_PCAjetDirs = log(tp.pca_jetAxis_dEta());
167  tp_features.dphi_PCAjetDirs = tp.pca_jetAxis_dPhi();
168 
169  max_counter = max_counter + 1;
170  tp_features_vector.push_back(tp_features);
171  }
172 
173  sortedSeedsMap.insert(std::make_pair(-seedInfo.sip3d_Signed(), std::make_pair(seedInfo, tp_features_vector)));
174  }
175 
176  int max_counter_seed = 0;
177 
178  for (auto const& im : sortedSeedsMap) {
179  if (max_counter_seed >= 10)
180  break;
181 
182  btagbtvdeep::SeedingTrackFeatures seed_features;
183 
184  auto const& seed = im.second.first;
185 
186  seed_features.nearTracks = im.second.second;
187  seed_features.pt = (seed.pt() == 0) ? 0 : 1.0 / seed.pt();
188  seed_features.eta = seed.eta();
189  seed_features.phi = seed.phi();
190  seed_features.mass = seed.mass();
191  seed_features.dz = logWithOffset(seed.dz());
192  seed_features.dxy = logWithOffset(seed.dxy());
193  seed_features.ip3D = log(seed.ip3d());
194  seed_features.sip3D = log(seed.sip3d());
195  seed_features.ip2D = log(seed.ip2d());
196  seed_features.sip2D = log(seed.sip2d());
197  seed_features.signedIp3D = logWithOffset(seed.ip3d_Signed());
198  seed_features.signedSip3D = logWithOffset(seed.sip3d_Signed());
199  seed_features.signedIp2D = logWithOffset(seed.ip2d_Signed());
200  seed_features.signedSip2D = logWithOffset(seed.sip2d_Signed());
201  seed_features.trackProbability3D = seed.trackProbability3D();
202  seed_features.trackProbability2D = seed.trackProbability2D();
203  seed_features.chi2reduced = seed.chi2reduced();
204  seed_features.nPixelHits = seed.nPixelHits();
205  seed_features.nHits = seed.nHits();
206  seed_features.jetAxisDistance = log(seed.jetAxisDistance());
207  seed_features.jetAxisDlength = log(seed.jetAxisDlength());
208 
209  max_counter_seed = max_counter_seed + 1;
210  seedingT_features_vector.push_back(seed_features);
211  }
212 
213  if (sortedSeedsMap.size() < 10) {
214  for (unsigned int i = sortedSeedsMap.size(); i < 10; i++) {
215  std::vector<btagbtvdeep::TrackPairFeatures> tp_features_zeropad(20);
216  btagbtvdeep::SeedingTrackFeatures seed_features_zeropad;
217  seed_features_zeropad.nearTracks = tp_features_zeropad;
218  seedingT_features_vector.push_back(seed_features_zeropad);
219  }
220  }
221  }
222 
223 } // namespace btagbtvdeep
Base class for all types of Jets.
Definition: Jet.h:20
int closest(std::vector< int > const &vec, int value)
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:38
TrajectoryStateOnSurface closestApproachToJet(const TrajectoryStateOnSurface &state, const reco::Vertex &vertex, const GlobalVector &aJetDirection, const MagneticField *field)
Definition: IPTools.cc:182
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:206
Definition: TTTypes.h:54
def pv(vc)
Definition: MetAnalyzer.py:7
std::vector< btagbtvdeep::TrackPairFeatures > nearTracks
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
void buildTrackPairInfo(const reco::TransientTrack *it, const reco::TransientTrack *tt, const reco::Vertex &pv, float mass, GlobalVector jetdirection, const std::pair< bool, Measurement1D > &t_ip, const std::pair< bool, Measurement1D > &t_ip2d)
void buildSeedingTrackInfo(const reco::TransientTrack *it, const reco::Vertex &pv, const reco::Jet &jet, float mass, const std::pair< bool, Measurement1D > &ip, const std::pair< bool, Measurement1D > &ip2d, float jet_distance, float jaxis_dlength, HistogramProbabilityEstimator *m_probabilityEstimator, bool m_computeProbabilities)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
void seedingTracksToFeatures(const std::vector< reco::TransientTrack > &selectedTracks, const std::vector< float > &masses, const reco::Jet &jet, const reco::Vertex &pv, HistogramProbabilityEstimator *probabilityEstimator, bool computeProbabilities, std::vector< btagbtvdeep::SeedingTrackFeatures > &seedingT_features_vector)
std::pair< bool, Measurement1D > absoluteTransverseImpactParameter(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:47
float logWithOffset(float v, float logOffset=0)