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