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);
65  TrajectoryStateOnSurface closest =
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
Vector3DBase
Definition: Vector3DBase.h:8
btagbtvdeep
Definition: BoostedDoubleSVTagInfoFeatures.h:4
btagbtvdeep::SeedingTrackFeatures
Definition: SeedingTrackFeatures.h:9
btagbtvdeep::TrackPairInfoBuilder::pca_distance
const float pca_distance() const
Definition: TrackPairInfoBuilder.h:28
btagbtvdeep::TrackPairFeatures::dotprodTrack
float dotprodTrack
Definition: TrackPairFeatures.h:32
btagbtvdeep::TrackPairFeatures::dotprod_PCAjetMomenta
float dotprod_PCAjetMomenta
Definition: TrackPairFeatures.h:41
mps_fire.i
i
Definition: mps_fire.py:428
reco::Jet
Base class for all types of Jets.
Definition: Jet.h:20
btagbtvdeep::SeedingTrackInfoBuilder
Definition: SeedingTrackInfoBuilder.h:10
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
PFCandidate.h
btagbtvdeep::TrackPairFeatures::z_PCAonTrack
float z_PCAonTrack
Definition: TrackPairFeatures.h:28
btagbtvdeep::SeedingTrackFeatures::sip3D
float sip3D
Definition: SeedingTrackFeatures.h:18
IPTools::absoluteImpactParameter3D
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:38
btagbtvdeep::TrackPairFeatures::ip2D
float ip2D
Definition: TrackPairFeatures.h:16
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
btagbtvdeep::SeedingTrackFeatures::signedIp3D
float signedIp3D
Definition: SeedingTrackFeatures.h:21
btagbtvdeep::TrackPairFeatures::pt
float pt
Definition: TrackPairFeatures.h:8
btagbtvdeep::SeedingTrackFeatures::signedIp2D
float signedIp2D
Definition: SeedingTrackFeatures.h:23
IPTools::closestApproachToJet
TrajectoryStateOnSurface closestApproachToJet(const TrajectoryStateOnSurface &state, const reco::Vertex &vertex, const GlobalVector &aJetDirection, const MagneticField *field)
Definition: IPTools.cc:182
btagbtvdeep::TrackPairFeatures::y_PCAonSeed
float y_PCAonSeed
Definition: TrackPairFeatures.h:21
TrackPairFeatures.h
SeedingTrackFeatures.h
btagbtvdeep::TrackPairFeatures::dotprodTrackSeed2D
float dotprodTrackSeed2D
Definition: TrackPairFeatures.h:34
VertexDistance3D.h
btagbtvdeep::SeedingTrackFeatures::ip3D
float ip3D
Definition: SeedingTrackFeatures.h:17
btagbtvdeep::TrackPairFeatures
Definition: TrackPairFeatures.h:6
btagbtvdeep::SeedingTrackFeatures::phi
float phi
Definition: SeedingTrackFeatures.h:13
btagbtvdeep::TrackPairFeatures::z_PCAonSeed
float z_PCAonSeed
Definition: TrackPairFeatures.h:22
btagbtvdeep::TrackPairFeatures::mass
float mass
Definition: TrackPairFeatures.h:11
HLT_FULL_cff.computeProbabilities
computeProbabilities
Definition: HLT_FULL_cff.py:51915
btagbtvdeep::SeedingTrackFeatures::jetAxisDistance
float jetAxisDistance
Definition: SeedingTrackFeatures.h:30
btagbtvdeep::TrackPairFeatures::y_PCAonTrack
float y_PCAonTrack
Definition: TrackPairFeatures.h:27
fileCollector.seed
seed
Definition: fileCollector.py:127
btagbtvdeep::TrackPairFeatures::pvd_PCAonSeed
float pvd_PCAonSeed
Definition: TrackPairFeatures.h:38
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
btagbtvdeep::TrackPairFeatures::zerr_PCAonTrack
float zerr_PCAonTrack
Definition: TrackPairFeatures.h:31
SeedingTrackInfoBuilder.h
btagbtvdeep::TrackPairFeatures::xerr_PCAonTrack
float xerr_PCAonTrack
Definition: TrackPairFeatures.h:29
btagbtvdeep::TrackPairFeatures::eta
float eta
Definition: TrackPairFeatures.h:9
btagbtvdeep::SeedingTrackInfoBuilder::buildSeedingTrackInfo
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)
Definition: SeedingTrackInfoBuilder.cc:34
btagbtvdeep::TrackPairInfoBuilder
Definition: TrackPairInfoBuilder.h:11
HistogramProbabilityEstimator.h
btagbtvdeep::TrackPairFeatures::sip2D
float sip2D
Definition: TrackPairFeatures.h:17
Point3DBase< float, GlobalTag >
btagbtvdeep::TrackPairFeatures::x_PCAonTrack
float x_PCAonTrack
Definition: TrackPairFeatures.h:26
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
btagbtvdeep::TrackPairFeatures::dotprodTrackSeed3D
float dotprodTrackSeed3D
Definition: TrackPairFeatures.h:35
btagbtvdeep::TrackPairFeatures::phi
float phi
Definition: TrackPairFeatures.h:10
IPTools::jetTrackDistance
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:206
btagbtvdeep::TrackPairFeatures::dphi_PCAjetDirs
float dphi_PCAjetDirs
Definition: TrackPairFeatures.h:43
btagbtvdeep::TrackPairFeatures::dotprodSeed
float dotprodSeed
Definition: TrackPairFeatures.h:33
btagbtvdeep::SeedingTrackFeatures::nearTracks
std::vector< btagbtvdeep::TrackPairFeatures > nearTracks
Definition: SeedingTrackFeatures.h:33
btagbtvdeep::TrackPairFeatures::xerr_PCAonSeed
float xerr_PCAonSeed
Definition: TrackPairFeatures.h:23
TransientTrackBuilder.h
btagbtvdeep::SeedingTrackFeatures::trackProbability2D
float trackProbability2D
Definition: SeedingTrackFeatures.h:26
PackedCandidate.h
btagbtvdeep::SeedingTrackFeatures::chi2reduced
float chi2reduced
Definition: SeedingTrackFeatures.h:27
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
btagbtvdeep::TrackPairFeatures::dotprodTrackSeedVectors2D
float dotprodTrackSeedVectors2D
Definition: TrackPairFeatures.h:36
btagbtvdeep::TrackPairFeatures::dxy
float dxy
Definition: TrackPairFeatures.h:13
HistogramProbabilityEstimator
Definition: HistogramProbabilityEstimator.h:18
btagbtvdeep::TrackPairFeatures::x_PCAonSeed
float x_PCAonSeed
Definition: TrackPairFeatures.h:20
btagbtvdeep::SeedingTrackFeatures::trackProbability3D
float trackProbability3D
Definition: SeedingTrackFeatures.h:25
btagbtvdeep::logWithOffset
float logWithOffset(float v, float logOffset=0)
Definition: SeedingTracksConverter.h:32
TransientTrackRecord.h
Jet.h
btagbtvdeep::TrackPairFeatures::sip3D
float sip3D
Definition: TrackPairFeatures.h:15
btagbtvdeep::SeedingTrackFeatures::ip2D
float ip2D
Definition: SeedingTrackFeatures.h:19
particleFlowDisplacedVertex_cfi.masses
masses
Definition: particleFlowDisplacedVertex_cfi.py:80
btagbtvdeep::TrackPairFeatures::dz
float dz
Definition: TrackPairFeatures.h:12
btagbtvdeep::SeedingTrackFeatures::signedSip2D
float signedSip2D
Definition: SeedingTrackFeatures.h:24
btagbtvdeep::TrackPairFeatures::dotprodTrackSeedVectors3D
float dotprodTrackSeedVectors3D
Definition: TrackPairFeatures.h:37
btagbtvdeep::TrackPairFeatures::pvd_PCAonTrack
float pvd_PCAonTrack
Definition: TrackPairFeatures.h:39
btagbtvdeep::TrackPairFeatures::distPCA
float distPCA
Definition: TrackPairFeatures.h:18
btagbtvdeep::SeedingTrackFeatures::pt
float pt
Definition: SeedingTrackFeatures.h:11
btagbtvdeep::SeedingTrackFeatures::jetAxisDlength
float jetAxisDlength
Definition: SeedingTrackFeatures.h:31
btagbtvdeep::SeedingTrackFeatures::signedSip3D
float signedSip3D
Definition: SeedingTrackFeatures.h:22
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
btagbtvdeep::TrackPairFeatures::dist_PCAjetAxis
float dist_PCAjetAxis
Definition: TrackPairFeatures.h:40
IPTools.h
btagbtvdeep::TrackPairFeatures::dsigPCA
float dsigPCA
Definition: TrackPairFeatures.h:19
btagbtvdeep::SeedingTrackFeatures::dz
float dz
Definition: SeedingTrackFeatures.h:15
btagbtvdeep::TrackPairFeatures::yerr_PCAonTrack
float yerr_PCAonTrack
Definition: TrackPairFeatures.h:30
metsig::jet
Definition: SignAlgoResolutions.h:47
btagbtvdeep::SeedingTrackFeatures::mass
float mass
Definition: SeedingTrackFeatures.h:14
btagbtvdeep::SeedingTrackFeatures::eta
float eta
Definition: SeedingTrackFeatures.h:12
btagbtvdeep::SeedingTrackFeatures::dxy
float dxy
Definition: SeedingTrackFeatures.h:16
btagbtvdeep::SeedingTrackFeatures::nPixelHits
float nPixelHits
Definition: SeedingTrackFeatures.h:28
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
btagbtvdeep::seedingTracksToFeatures
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)
Definition: SeedingTracksConverter.cc:23
SeedingTracksConverter.h
btagbtvdeep::TrackPairInfoBuilder::buildTrackPairInfo
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)
Definition: TrackPairInfoBuilder.cc:57
btagbtvdeep::SeedingTrackFeatures::nHits
float nHits
Definition: SeedingTrackFeatures.h:29
btagbtvdeep::TrackPairFeatures::zerr_PCAonSeed
float zerr_PCAonSeed
Definition: TrackPairFeatures.h:25
btagbtvdeep::SeedingTrackInfoBuilder::sip3d_Signed
const float sip3d_Signed() const
Definition: SeedingTrackInfoBuilder.h:36
IPTools::absoluteTransverseImpactParameter
std::pair< bool, Measurement1D > absoluteTransverseImpactParameter(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:47
btagbtvdeep::SeedingTrackFeatures::sip2D
float sip2D
Definition: SeedingTrackFeatures.h:20
btagbtvdeep::TrackPairFeatures::ip3D
float ip3D
Definition: TrackPairFeatures.h:14
btagbtvdeep::TrackPairFeatures::deta_PCAjetDirs
float deta_PCAjetDirs
Definition: TrackPairFeatures.h:42
reco::Vertex
Definition: Vertex.h:35
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
TrackPairInfoBuilder.h
btagbtvdeep::TrackPairFeatures::yerr_PCAonSeed
float yerr_PCAonSeed
Definition: TrackPairFeatures.h:24
TrackCollections2monitor_cff.selectedTracks
selectedTracks
Definition: TrackCollections2monitor_cff.py:32