14 for (
unsigned int i = 0;
i < pfcands->size(); ++
i) {
25 const size_t tau_index = 0;
31 static const std::map<unsigned, unsigned> nparticles{{0, 60}, {1, 36}};
36 static const std::map<unsigned, unsigned> nfeatures{{0, 47}, {1, 51}};
45 desc.
add<
std::string>(
"graph_file",
"RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v0_quantized.pb");
46 desc.
add<
unsigned>(
"version", 0);
47 desc.
add<
bool>(
"mem_mapped",
false);
60 descriptions.
add(
"DPFTau2016v0", desc);
65 const auto& shape =
cache_->
getGraph().node(0).attr().at(
"shape").shape();
68 throw cms::Exception(
"DPFIsolation") <<
"unknown version of the graph file.";
73 <<
"number of inputs does not match the expected inputs for the given version";
86 tensorflow::Tensor tensor(
90 tensorflow::Tensor predictions(tensorflow::DT_FLOAT, {static_cast<int>(
taus->size()), 1});
92 std::vector<tensorflow::Tensor>
outputs_;
94 float pfCandPt, pfCandPz, pfCandPtRel, pfCandPzRel, pfCandDr, pfCandDEta, pfCandDPhi, pfCandEta, pfCandDz,
95 pfCandDzErr, pfCandD0, pfCandD0D0, pfCandD0Dz, pfCandD0Dphi, pfCandPuppiWeight, pfCandPixHits, pfCandHits,
96 pfCandLostInnerHits, pfCandPdgID, pfCandCharge, pfCandFromPV, pfCandVtxQuality, pfCandHighPurityTrk,
97 pfCandTauIndMatch, pfCandDzSig, pfCandD0Sig, pfCandD0Err, pfCandPtRelPtRel, pfCandDzDz, pfCandDVx_1,
98 pfCandDVy_1, pfCandDVz_1, pfCandD_1;
99 float pvx = !
vertices->empty() ? (*vertices)[0].x() : -1;
100 float pvy = !
vertices->empty() ? (*vertices)[0].y() : -1;
101 float pvz = !
vertices->empty() ? (*vertices)[0].z() : -1;
106 static constexpr
float pfCandPt_max = 500.f;
107 static constexpr
float pfCandPz_max = 1000.f;
108 static constexpr
float pfCandPtRel_max = 1.f;
109 static constexpr
float pfCandPzRel_max = 100.f;
110 static constexpr
float pfCandPtRelPtRel_max = 1.f;
111 static constexpr
float pfCandD0_max = 5.f;
112 static constexpr
float pfCandDz_max = 5.f;
113 static constexpr
float pfCandDVx_y_z_1_max = 0.05f;
114 static constexpr
float pfCandD_1_max = 0.1f;
115 static constexpr
float pfCandD0_z_Err_max = 1.f;
116 static constexpr
float pfCandDzSig_max = 3.f;
117 static constexpr
float pfCandD0Sig_max = 1.f;
118 static constexpr
float pfCandDr_max = 0.5f;
119 static constexpr
float pfCandEta_max = 2.75f;
120 static constexpr
float pfCandDEta_max = 0.5f;
121 static constexpr
float pfCandDPhi_max = 0.5f;
122 static constexpr
float pfCandPixHits_max = 7.f;
123 static constexpr
float pfCandHits_max = 30.f;
125 for (
size_t tau_index = 0; tau_index <
taus->size(); tau_index++) {
127 bool isGoodTau =
false;
128 const float lepRecoPt =
tau.pt();
130 const float lepRecoEta =
tau.eta();
131 const float lepRecoPhi =
tau.phi();
133 if (lepRecoPt >= 30 &&
std::abs(lepRecoEta) < 2.3 &&
tau.isTauIDAvailable(
"againstMuonLoose3") &&
134 tau.isTauIDAvailable(
"againstElectronVLooseMVA6")) {
135 isGoodTau = (
tau.tauID(
"againstElectronVLooseMVA6") &&
tau.tauID(
"againstMuonLoose3"));
139 predictions.matrix<
float>()(tau_index, 0) = -1;
143 std::vector<unsigned int> signalCandidateInds;
145 for (
const auto c :
tau.signalCands())
146 signalCandidateInds.push_back(getPFCandidateIndex(pfcands,
c));
151 for (
unsigned input_idx = 0; input_idx < n_inputs; ++input_idx)
152 tensor.flat<
float>()(input_idx) = 0;
154 unsigned int iPF = 0;
157 std::vector<unsigned int> sorted_inds(pfcands->size());
162 return pfcands->at(
i1).pt() > pfcands->at(
i2).pt();
165 for (
size_t pf_index = 0; pf_index < pfcands->size() && iPF < max_iPF; pf_index++) {
167 float deltaR_tau_p =
deltaR(
p.p4(),
tau.p4());
171 if (deltaR_tau_p > 0.5)
173 if (
p.fromPV() < 1 &&
p.charge() != 0)
176 pfCandPtRel =
p.pt() / lepRecoPt;
178 pfCandDr = deltaR_tau_p;
179 pfCandDEta =
std::abs(lepRecoEta -
p.eta());
182 pfCandIsBarrel = (
std::abs(pfCandEta) < 1.4);
183 pfCandPz =
std::abs(std::sinh(pfCandEta) * pfCandPt);
184 pfCandPzRel = pfCandPz / lepRecoPz;
186 pfCandCharge =
p.charge();
187 pfCandDVx_1 =
p.vx() - pvx;
188 pfCandDVy_1 =
p.vy() - pvy;
189 pfCandDVz_1 =
p.vz() - pvz;
191 pfCandD_1 =
std::sqrt(pfCandDVx_1 * pfCandDVx_1 + pfCandDVy_1 * pfCandDVy_1 + pfCandDVz_1 * pfCandDVz_1);
193 if (pfCandCharge != 0 and
p.hasTrackDetails()) {
195 pfCandDzErr =
p.dzError();
196 pfCandDzSig = (
std::abs(
p.dz()) + 0.000001) / (
p.dzError() + 0.00001);
198 pfCandD0Err =
p.dxyError();
199 pfCandD0Sig = (
std::abs(
p.dxy()) + 0.000001) / (
p.dxyError() + 0.00001);
200 pfCandPixHits =
p.numberOfPixelHits();
201 pfCandHits =
p.numberOfHits();
202 pfCandLostInnerHits =
p.lostInnerHits();
205 int psudorand =
p.pt() * 1000000;
206 if (psudorand % 2 == 0)
216 pfCandLostInnerHits = 2.;
223 pfCandPuppiWeight =
p.puppiWeight();
224 pfCandFromPV =
p.fromPV();
225 pfCandVtxQuality =
p.pvAssociationQuality();
226 pfCandHighPurityTrk =
p.trackHighPurity();
227 float pfCandTauIndMatch_temp = 0;
229 for (
auto i : signalCandidateInds) {
230 if (
i == sorted_inds.at(pf_index))
231 pfCandTauIndMatch_temp = 1;
234 pfCandTauIndMatch = pfCandTauIndMatch_temp;
235 pfCandPtRelPtRel = pfCandPtRel * pfCandPtRel;
236 pfCandPt =
std::min(pfCandPt, pfCandPt_max);
237 pfCandPt = pfCandPt / pfCandPt_max;
239 pfCandPz =
std::min(pfCandPz, pfCandPz_max);
240 pfCandPz = pfCandPz / pfCandPz_max;
242 pfCandPtRel =
std::min(pfCandPtRel, pfCandPtRel_max);
243 pfCandPzRel =
std::min(pfCandPzRel, pfCandPzRel_max);
244 pfCandPzRel = pfCandPzRel / pfCandPzRel_max;
245 pfCandDr = pfCandDr / pfCandDr_max;
246 pfCandEta = pfCandEta / pfCandEta_max;
247 pfCandDEta = pfCandDEta / pfCandDEta_max;
248 pfCandDPhi = pfCandDPhi / pfCandDPhi_max;
249 pfCandPixHits = pfCandPixHits / pfCandPixHits_max;
250 pfCandHits = pfCandHits / pfCandHits_max;
252 pfCandPtRelPtRel =
std::min(pfCandPtRelPtRel, pfCandPtRelPtRel_max);
254 pfCandD0 = std::clamp(pfCandD0, -pfCandD0_max, pfCandD0_max);
255 pfCandD0 = pfCandD0 / pfCandD0_max;
257 pfCandDz = std::clamp(pfCandDz, -pfCandDz_max, pfCandDz_max);
258 pfCandDz = pfCandDz / pfCandDz_max;
260 pfCandD0Err =
std::min(pfCandD0Err, pfCandD0_z_Err_max);
261 pfCandDzErr =
std::min(pfCandDzErr, pfCandD0_z_Err_max);
262 pfCandDzSig =
std::min(pfCandDzSig, pfCandDzSig_max);
263 pfCandDzSig = pfCandDzSig / pfCandDzSig_max;
265 pfCandD0Sig =
std::min(pfCandD0Sig, pfCandD0Sig_max);
266 pfCandD0D0 = pfCandD0 * pfCandD0;
267 pfCandDzDz = pfCandDz * pfCandDz;
268 pfCandD0Dz = pfCandD0 * pfCandDz;
269 pfCandD0Dphi = pfCandD0 * pfCandDPhi;
271 pfCandDVx_1 = std::clamp(pfCandDVx_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
272 pfCandDVx_1 = pfCandDVx_1 / pfCandDVx_y_z_1_max;
274 pfCandDVy_1 = std::clamp(pfCandDVy_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
275 pfCandDVy_1 = pfCandDVy_1 / pfCandDVx_y_z_1_max;
277 pfCandDVz_1 = std::clamp(pfCandDVz_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
278 pfCandDVz_1 = pfCandDVz_1 / pfCandDVx_y_z_1_max;
280 pfCandD_1 = std::clamp(pfCandD_1, -pfCandD_1_max, pfCandD_1_max);
281 pfCandD_1 = pfCandD_1 / pfCandD_1_max;
284 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 0) = pfCandPt;
285 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 1) = pfCandPz;
286 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 2) = pfCandPtRel;
287 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 3) = pfCandPzRel;
288 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 4) = pfCandDr;
289 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 5) = pfCandDEta;
290 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 6) = pfCandDPhi;
291 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 7) = pfCandEta;
292 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 8) = pfCandDz;
293 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 9) = pfCandDzSig;
294 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 10) = pfCandD0;
295 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 11) = pfCandD0Sig;
296 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 12) = pfCandDzErr;
297 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 13) = pfCandD0Err;
298 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 14) = pfCandD0D0;
299 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 15) = pfCandCharge == 0;
300 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 16) = pfCandCharge == 1;
301 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 17) = pfCandCharge == -1;
302 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 18) = pfCandPdgID > 22;
303 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 19) = pfCandPdgID == 22;
304 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 20) = pfCandDzDz;
305 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 21) = pfCandD0Dz;
306 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 22) = pfCandD0Dphi;
307 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 23) = pfCandPtRelPtRel;
308 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 24) = pfCandPixHits;
309 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 25) = pfCandHits;
310 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 26) = pfCandLostInnerHits == -1;
311 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 27) = pfCandLostInnerHits == 0;
312 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 28) = pfCandLostInnerHits == 1;
313 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 29) = pfCandLostInnerHits == 2;
314 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 30) = pfCandPuppiWeight;
315 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 31) = (pfCandVtxQuality == 1);
316 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 32) = (pfCandVtxQuality == 5);
317 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 33) = (pfCandVtxQuality == 6);
318 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 34) = (pfCandVtxQuality == 7);
319 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 35) = (pfCandFromPV == 1);
320 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 36) = (pfCandFromPV == 2);
321 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 37) = (pfCandFromPV == 3);
322 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 38) = pfCandIsBarrel;
323 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 39) = pfCandHighPurityTrk;
324 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 40) = pfCandPdgID == 1;
325 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 41) = pfCandPdgID == 2;
326 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 42) = pfCandPdgID == 11;
327 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 43) = pfCandPdgID == 13;
328 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 44) = pfCandPdgID == 130;
329 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 45) = pfCandPdgID == 211;
330 tensor.tensor<
float, 3>()(0, 60 - 1 - iPF, 46) = pfCandTauIndMatch;
334 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 0) = pfCandPt;
335 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 1) = pfCandPz;
336 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 2) = pfCandPtRel;
337 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 3) = pfCandPzRel;
338 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 4) = pfCandDr;
339 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 5) = pfCandDEta;
340 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 6) = pfCandDPhi;
341 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 7) = pfCandEta;
342 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 8) = pfCandDz;
343 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 9) = pfCandDzSig;
344 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 10) = pfCandD0;
345 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 11) = pfCandD0Sig;
346 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 12) = pfCandDzErr;
347 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 13) = pfCandD0Err;
348 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 14) = pfCandD0D0;
349 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 15) = pfCandCharge == 0;
350 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 16) = pfCandCharge == 1;
351 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 17) = pfCandCharge == -1;
352 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 18) = pfCandPdgID > 22;
353 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 19) = pfCandPdgID == 22;
354 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 20) = pfCandDVx_1;
355 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 21) = pfCandDVy_1;
356 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 22) = pfCandDVz_1;
357 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 23) = pfCandD_1;
358 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 24) = pfCandDzDz;
359 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 25) = pfCandD0Dz;
360 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 26) = pfCandD0Dphi;
361 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 27) = pfCandPtRelPtRel;
362 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 28) = pfCandPixHits;
363 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 29) = pfCandHits;
364 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 30) = pfCandLostInnerHits == -1;
365 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 31) = pfCandLostInnerHits == 0;
366 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 32) = pfCandLostInnerHits == 1;
367 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 33) = pfCandLostInnerHits == 2;
368 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 34) = pfCandPuppiWeight;
369 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 35) = (pfCandVtxQuality == 1);
370 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 36) = (pfCandVtxQuality == 5);
371 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 37) = (pfCandVtxQuality == 6);
372 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 38) = (pfCandVtxQuality == 7);
373 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 39) = (pfCandFromPV == 1);
374 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 40) = (pfCandFromPV == 2);
375 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 41) = (pfCandFromPV == 3);
376 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 42) = pfCandIsBarrel;
377 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 43) = pfCandHighPurityTrk;
378 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 44) = pfCandPdgID == 1;
379 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 45) = pfCandPdgID == 2;
380 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 46) = pfCandPdgID == 11;
381 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 47) = pfCandPdgID == 13;
382 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 48) = pfCandPdgID == 130;
383 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 49) = pfCandPdgID == 211;
384 tensor.tensor<
float, 3>()(0, 36 - 1 - iPF, 50) = pfCandTauIndMatch;
389 predictions.matrix<
float>()(tau_index, 0) =
outputs_[0].flat<
float>()(0);