CMS 3D CMS Logo

tensor_fillers.cc
Go to the documentation of this file.
2 
3 namespace btagbtvdeep {
4 
5  // Note on setting tensor values:
6  // Instead of using the more convenient tensor.matrix (etc) methods,
7  // we can exploit that in the following methods values are set along
8  // the innermost (= last) axis. Those values are stored contiguously in
9  // the memory, so it is most performant to get the pointer to the first
10  // value and use pointer arithmetic to iterate through the next pointers.
11 
12  void jet_tensor_filler(tensorflow::Tensor & tensor,
13  std::size_t jet_n,
14  const btagbtvdeep::DeepFlavourFeatures & features) {
15 
16  float* ptr = &tensor.matrix<float>()(jet_n, 0);
17 
18  // jet variables
19  const auto & jet_features = features.jet_features;
20  *ptr = jet_features.pt;
21  *(++ptr) = jet_features.eta;
22  // number of elements in different collections
23  *(++ptr) = features.c_pf_features.size();
24  *(++ptr) = features.n_pf_features.size();
25  *(++ptr) = features.sv_features.size();
26  *(++ptr) = features.npv;
27  // variables from ShallowTagInfo
28  const auto & tag_info_features = features.tag_info_features;
29  *(++ptr) = tag_info_features.trackSumJetEtRatio;
30  *(++ptr) = tag_info_features.trackSumJetDeltaR;
31  *(++ptr) = tag_info_features.vertexCategory;
32  *(++ptr) = tag_info_features.trackSip2dValAboveCharm;
33  *(++ptr) = tag_info_features.trackSip2dSigAboveCharm;
34  *(++ptr) = tag_info_features.trackSip3dValAboveCharm;
35  *(++ptr) = tag_info_features.trackSip3dSigAboveCharm;
36  *(++ptr) = tag_info_features.jetNSelectedTracks;
37  *(++ptr) = tag_info_features.jetNTracksEtaRel;
38 
39  }
40 
41  void db_tensor_filler(tensorflow::Tensor & tensor,
42  std::size_t jet_n,
43  const btagbtvdeep::DeepDoubleXFeatures & features) {
44 
45  float* ptr = &tensor.tensor<float, 3>()(jet_n, 0, 0);
46 
47  // variables from BoostedDoubleSVTagInfo
48  const auto & tag_info_features = features.tag_info_features;
49  *ptr = tag_info_features.jetNTracks;
50  *(++ptr) = tag_info_features.jetNSecondaryVertices;
51  *(++ptr) = tag_info_features.tau1_trackEtaRel_0;
52  *(++ptr) = tag_info_features.tau1_trackEtaRel_1;
53  *(++ptr) = tag_info_features.tau1_trackEtaRel_2;
54  *(++ptr) = tag_info_features.tau2_trackEtaRel_0;
55  *(++ptr) = tag_info_features.tau2_trackEtaRel_1;
56  *(++ptr) = tag_info_features.tau2_trackEtaRel_2;
57  *(++ptr) = tag_info_features.tau1_flightDistance2dSig;
58  *(++ptr) = tag_info_features.tau2_flightDistance2dSig;
59  *(++ptr) = tag_info_features.tau1_vertexDeltaR;
60  // Note: this variable is not used in the 27-input BDT
61  // *(++ptr) = tag_info_features.tau2_vertexDeltaR;
62  *(++ptr) = tag_info_features.tau1_vertexEnergyRatio;
63  *(++ptr) = tag_info_features.tau2_vertexEnergyRatio;
64  *(++ptr) = tag_info_features.tau1_vertexMass;
65  *(++ptr) = tag_info_features.tau2_vertexMass;
66  *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_0;
67  *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_1;
68  *(++ptr) = tag_info_features.trackSip2dSigAboveCharm;
69  *(++ptr) = tag_info_features.trackSip3dSig_0;
70  *(++ptr) = tag_info_features.tau1_trackSip3dSig_0;
71  *(++ptr) = tag_info_features.tau1_trackSip3dSig_1;
72  *(++ptr) = tag_info_features.trackSip3dSig_1;
73  *(++ptr) = tag_info_features.tau2_trackSip3dSig_0;
74  *(++ptr) = tag_info_features.tau2_trackSip3dSig_1;
75  *(++ptr) = tag_info_features.trackSip3dSig_2;
76  *(++ptr) = tag_info_features.trackSip3dSig_3;
77  *(++ptr) = tag_info_features.z_ratio;
78  }
79 
80  void c_pf_tensor_filler(tensorflow::Tensor & tensor,
81  std::size_t jet_n,
82  std::size_t c_pf_n,
83  const btagbtvdeep::ChargedCandidateFeatures & c_pf_features) {
84 
85  float* ptr = &tensor.tensor<float, 3>()(jet_n, c_pf_n, 0);
86 
87  *ptr = c_pf_features.btagPf_trackEtaRel;
88  *(++ptr) = c_pf_features.btagPf_trackPtRel;
89  *(++ptr) = c_pf_features.btagPf_trackPPar;
90  *(++ptr) = c_pf_features.btagPf_trackDeltaR;
91  *(++ptr) = c_pf_features.btagPf_trackPParRatio;
92  *(++ptr) = c_pf_features.btagPf_trackSip2dVal;
93  *(++ptr) = c_pf_features.btagPf_trackSip2dSig;
94  *(++ptr) = c_pf_features.btagPf_trackSip3dVal;
95  *(++ptr) = c_pf_features.btagPf_trackSip3dSig;
96  *(++ptr) = c_pf_features.btagPf_trackJetDistVal;
97  *(++ptr) = c_pf_features.ptrel;
98  *(++ptr) = c_pf_features.drminsv;
99  *(++ptr) = c_pf_features.vtx_ass;
100  *(++ptr) = c_pf_features.puppiw;
101  *(++ptr) = c_pf_features.chi2;
102  *(++ptr) = c_pf_features.quality;
103 
104  }
105 
106  void c_pf_reduced_tensor_filler(tensorflow::Tensor & tensor,
107  std::size_t jet_n,
108  std::size_t c_pf_n,
109  const btagbtvdeep::ChargedCandidateFeatures & c_pf_features) {
110 
111  float* ptr = &tensor.tensor<float, 3>()(jet_n, c_pf_n, 0);
112 
113  *ptr = c_pf_features.btagPf_trackEtaRel;
114  *(++ptr) = c_pf_features.btagPf_trackPtRatio;
115  *(++ptr) = c_pf_features.btagPf_trackPParRatio;
116  *(++ptr) = c_pf_features.btagPf_trackSip2dVal;
117  *(++ptr) = c_pf_features.btagPf_trackSip2dSig;
118  *(++ptr) = c_pf_features.btagPf_trackSip3dVal;
119  *(++ptr) = c_pf_features.btagPf_trackSip3dSig;
120  *(++ptr) = c_pf_features.btagPf_trackJetDistVal;
121 
122  }
123 
124 
125  void n_pf_tensor_filler(tensorflow::Tensor & tensor,
126  std::size_t jet_n,
127  std::size_t n_pf_n,
128  const btagbtvdeep::NeutralCandidateFeatures & n_pf_features) {
129 
130  float* ptr = &tensor.tensor<float, 3>()(jet_n, n_pf_n, 0);
131 
132  *ptr = n_pf_features.ptrel;
133  *(++ptr) = n_pf_features.deltaR;
134  *(++ptr) = n_pf_features.isGamma;
135  *(++ptr) = n_pf_features.hadFrac;
136  *(++ptr) = n_pf_features.drminsv;
137  *(++ptr) = n_pf_features.puppiw;
138 
139  }
140 
141 
142  void sv_tensor_filler(tensorflow::Tensor & tensor,
143  std::size_t jet_n,
144  std::size_t sv_n,
145  const btagbtvdeep::SecondaryVertexFeatures & sv_features) {
146 
147  float* ptr = &tensor.tensor<float, 3>()(jet_n, sv_n, 0);
148 
149  *ptr = sv_features.pt;
150  *(++ptr) = sv_features.deltaR;
151  *(++ptr) = sv_features.mass;
152  *(++ptr) = sv_features.ntracks;
153  *(++ptr) = sv_features.chi2;
154  *(++ptr) = sv_features.normchi2;
155  *(++ptr) = sv_features.dxy;
156  *(++ptr) = sv_features.dxysig;
157  *(++ptr) = sv_features.d3d;
158  *(++ptr) = sv_features.d3dsig;
159  *(++ptr) = sv_features.costhetasvpv;
160  *(++ptr) = sv_features.enratio;
161 
162  }
163 
164 
165  void sv_reduced_tensor_filler(tensorflow::Tensor & tensor,
166  std::size_t jet_n,
167  std::size_t sv_n,
168  const btagbtvdeep::SecondaryVertexFeatures & sv_features) {
169 
170  float* ptr = &tensor.tensor<float, 3>()(jet_n, sv_n, 0);
171 
172  *ptr = sv_features.d3d;
173  *(++ptr) = sv_features.d3dsig;
174 
175  }
176 
177 }
178 
ShallowTagInfoFeatures tag_info_features
std::vector< NeutralCandidateFeatures > n_pf_features
void c_pf_tensor_filler(tensorflow::Tensor &tensor, std::size_t jet_n, std::size_t c_pf_n, const btagbtvdeep::ChargedCandidateFeatures &c_pf_features)
std::vector< SecondaryVertexFeatures > sv_features
void db_tensor_filler(tensorflow::Tensor &tensor, std::size_t jet_n, const btagbtvdeep::DeepDoubleXFeatures &features)
std::vector< ChargedCandidateFeatures > c_pf_features
void n_pf_tensor_filler(tensorflow::Tensor &tensor, std::size_t jet_n, std::size_t n_pf_n, const btagbtvdeep::NeutralCandidateFeatures &n_pf_features)
void jet_tensor_filler(tensorflow::Tensor &tensor, std::size_t jet_n, const btagbtvdeep::DeepFlavourFeatures &features)
BoostedDoubleSVTagInfoFeatures tag_info_features
void c_pf_reduced_tensor_filler(tensorflow::Tensor &tensor, std::size_t jet_n, std::size_t c_pf_n, const btagbtvdeep::ChargedCandidateFeatures &c_pf_features)
void sv_tensor_filler(tensorflow::Tensor &tensor, std::size_t jet_n, std::size_t sv_n, const btagbtvdeep::SecondaryVertexFeatures &sv_features)
void sv_reduced_tensor_filler(tensorflow::Tensor &tensor, std::size_t jet_n, std::size_t sv_n, const btagbtvdeep::SecondaryVertexFeatures &sv_features)