105 tensorflow::Tensor tensor(tensorflow::DT_FLOAT, {1,
108 tensorflow::Tensor predictions(tensorflow::DT_FLOAT, {
static_cast<int>(taus->size()), 1});
110 std::vector<tensorflow::Tensor>
outputs_;
112 float pfCandPt, pfCandPz, pfCandPtRel, pfCandPzRel, pfCandDr, pfCandDEta, pfCandDPhi, pfCandEta, pfCandDz,
113 pfCandDzErr, pfCandD0, pfCandD0D0, pfCandD0Dz, pfCandD0Dphi, pfCandPuppiWeight,
114 pfCandPixHits, pfCandHits, pfCandLostInnerHits, pfCandPdgID, pfCandCharge, pfCandFromPV,
115 pfCandVtxQuality, pfCandHighPurityTrk, pfCandTauIndMatch, pfCandDzSig, pfCandD0Sig, pfCandD0Err,
116 pfCandPtRelPtRel, pfCandDzDz, pfCandDVx_1, pfCandDVy_1, pfCandDVz_1, pfCandD_1;
117 float pvx = !vertices->empty() ? (*vertices)[0].x() : -1;
118 float pvy = !vertices->empty() ? (*vertices)[0].y() : -1;
119 float pvz = !vertices->empty() ? (*vertices)[0].z() : -1;
124 static constexpr float pfCandPt_max = 500.f;
125 static constexpr float pfCandPz_max = 1000.f;
126 static constexpr float pfCandPtRel_max = 1.f;
127 static constexpr float pfCandPzRel_max = 100.f;
128 static constexpr float pfCandPtRelPtRel_max = 1.f;
129 static constexpr float pfCandD0_max = 5.f;
130 static constexpr float pfCandDz_max = 5.f;
131 static constexpr float pfCandDVx_y_z_1_max = 0.05f;
132 static constexpr float pfCandD_1_max = 0.1f;
133 static constexpr float pfCandD0_z_Err_max = 1.f;
134 static constexpr float pfCandDzSig_max = 3.f;
135 static constexpr float pfCandD0Sig_max = 1.f;
136 static constexpr float pfCandDr_max = 0.5f;
137 static constexpr float pfCandEta_max = 2.75f;
138 static constexpr float pfCandDEta_max = 0.5f;
139 static constexpr float pfCandDPhi_max = 0.5f;
140 static constexpr float pfCandPixHits_max = 7.f;
141 static constexpr float pfCandHits_max = 30.f;
143 for(
size_t tau_index = 0; tau_index < taus->size(); tau_index++) {
145 bool isGoodTau =
false;
146 const float lepRecoPt = tau.
pt();
148 const float lepRecoEta = tau.
eta();
149 const float lepRecoPhi = tau.
phi();
153 isGoodTau = (tau.
tauID(
"againstElectronVLooseMVA6") && tau.
tauID(
"againstMuonLoose3") );
157 predictions.matrix<
float>()(tau_index, 0) = -1;
161 std::vector<unsigned int> signalCandidateInds;
164 signalCandidateInds.push_back(getPFCandidateIndex(pfcands,
c));
169 for(
unsigned input_idx = 0; input_idx < n_inputs; ++input_idx)
170 tensor.flat<
float>()(input_idx) = 0;
172 unsigned int iPF = 0;
175 std::vector<unsigned int> sorted_inds(pfcands->size());
180 [&](
int i1,
int i2) {
return pfcands->at(i1).pt() > pfcands->at(i2).pt(); } );
182 for(
size_t pf_index = 0; pf_index < pfcands->size() && iPF < max_iPF; pf_index++) {
186 if (p.
pt() < 0.5)
continue;
187 if (p.
fromPV() < 0)
continue;
188 if (deltaR_tau_p > 0.5)
continue;
191 pfCandPtRel = p.
pt()/lepRecoPt;
193 pfCandDr = deltaR_tau_p;
197 pfCandIsBarrel = (
std::abs(pfCandEta) < 1.4);
198 pfCandPz =
std::abs(std::sinh(pfCandEta)*pfCandPt);
199 pfCandPzRel = pfCandPz/lepRecoPz;
201 pfCandCharge = p.
charge();
202 pfCandDVx_1 = p.
vx() - pvx;
203 pfCandDVy_1 = p.
vy() - pvy;
204 pfCandDVz_1 = p.
vz() - pvz;
206 pfCandD_1 =
std::sqrt(pfCandDVx_1*pfCandDVx_1 + pfCandDVy_1*pfCandDVy_1 + pfCandDVz_1*pfCandDVz_1);
220 int psudorand = p.
pt()*1000000;
221 if (psudorand%2 == 0) disp = -1;
230 pfCandLostInnerHits = 2.;
238 pfCandFromPV = p.
fromPV();
241 float pfCandTauIndMatch_temp = 0;
243 for (
auto i : signalCandidateInds) {
244 if (
i == sorted_inds.at(pf_index)) pfCandTauIndMatch_temp = 1;
247 pfCandTauIndMatch = pfCandTauIndMatch_temp;
248 pfCandPtRelPtRel = pfCandPtRel*pfCandPtRel;
249 pfCandPt =
std::min(pfCandPt, pfCandPt_max);
250 pfCandPt = pfCandPt/pfCandPt_max;
252 pfCandPz =
std::min(pfCandPz, pfCandPz_max);
253 pfCandPz = pfCandPz/pfCandPz_max;
255 pfCandPtRel =
std::min(pfCandPtRel, pfCandPtRel_max);
256 pfCandPzRel =
std::min(pfCandPzRel, pfCandPzRel_max);
257 pfCandPzRel = pfCandPzRel/pfCandPzRel_max;
258 pfCandDr = pfCandDr/pfCandDr_max;
259 pfCandEta = pfCandEta/pfCandEta_max;
260 pfCandDEta = pfCandDEta/pfCandDEta_max;
261 pfCandDPhi = pfCandDPhi/pfCandDPhi_max;
262 pfCandPixHits = pfCandPixHits/pfCandPixHits_max;
263 pfCandHits = pfCandHits/pfCandHits_max;
265 pfCandPtRelPtRel =
std::min(pfCandPtRelPtRel, pfCandPtRelPtRel_max);
267 pfCandD0 =
std::clamp(pfCandD0, -pfCandD0_max, pfCandD0_max);
268 pfCandD0 = pfCandD0/pfCandD0_max;
270 pfCandDz =
std::clamp(pfCandDz, -pfCandDz_max, pfCandDz_max);
271 pfCandDz = pfCandDz/pfCandDz_max;
273 pfCandD0Err =
std::min(pfCandD0Err, pfCandD0_z_Err_max);
274 pfCandDzErr =
std::min(pfCandDzErr, pfCandD0_z_Err_max);
275 pfCandDzSig =
std::min(pfCandDzSig, pfCandDzSig_max);
276 pfCandDzSig = pfCandDzSig/pfCandDzSig_max;
278 pfCandD0Sig =
std::min(pfCandD0Sig, pfCandD0Sig_max);
279 pfCandD0D0 = pfCandD0*pfCandD0;
280 pfCandDzDz = pfCandDz*pfCandDz;
281 pfCandD0Dz = pfCandD0*pfCandDz;
282 pfCandD0Dphi = pfCandD0*pfCandDPhi;
284 pfCandDVx_1 =
std::clamp(pfCandDVx_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
285 pfCandDVx_1 = pfCandDVx_1/pfCandDVx_y_z_1_max;
287 pfCandDVy_1 =
std::clamp(pfCandDVy_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
288 pfCandDVy_1 = pfCandDVy_1/pfCandDVx_y_z_1_max;
290 pfCandDVz_1 =
std::clamp(pfCandDVz_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
291 pfCandDVz_1 = pfCandDVz_1/pfCandDVx_y_z_1_max;
293 pfCandD_1 =
std::clamp(pfCandD_1, -pfCandD_1_max, pfCandD_1_max);
294 pfCandD_1 = pfCandD_1/ pfCandD_1_max;
297 tensor.tensor<
float,3>()( 0, 60-1-iPF, 0) = pfCandPt;
298 tensor.tensor<
float,3>()( 0, 60-1-iPF, 1) = pfCandPz;
299 tensor.tensor<
float,3>()( 0, 60-1-iPF, 2) = pfCandPtRel;
300 tensor.tensor<
float,3>()( 0, 60-1-iPF, 3) = pfCandPzRel;
301 tensor.tensor<
float,3>()( 0, 60-1-iPF, 4) = pfCandDr;
302 tensor.tensor<
float,3>()( 0, 60-1-iPF, 5) = pfCandDEta;
303 tensor.tensor<
float,3>()( 0, 60-1-iPF, 6) = pfCandDPhi;
304 tensor.tensor<
float,3>()( 0, 60-1-iPF, 7) = pfCandEta;
305 tensor.tensor<
float,3>()( 0, 60-1-iPF, 8) = pfCandDz;
306 tensor.tensor<
float,3>()( 0, 60-1-iPF, 9) = pfCandDzSig;
307 tensor.tensor<
float,3>()( 0, 60-1-iPF, 10) = pfCandD0;
308 tensor.tensor<
float,3>()( 0, 60-1-iPF, 11) = pfCandD0Sig;
309 tensor.tensor<
float,3>()( 0, 60-1-iPF, 12) = pfCandDzErr;
310 tensor.tensor<
float,3>()( 0, 60-1-iPF, 13) = pfCandD0Err;
311 tensor.tensor<
float,3>()( 0, 60-1-iPF, 14) = pfCandD0D0;
312 tensor.tensor<
float,3>()( 0, 60-1-iPF, 15) = pfCandCharge==0;
313 tensor.tensor<
float,3>()( 0, 60-1-iPF, 16) = pfCandCharge==1;
314 tensor.tensor<
float,3>()( 0, 60-1-iPF, 17) = pfCandCharge==-1;
315 tensor.tensor<
float,3>()( 0, 60-1-iPF, 18) = pfCandPdgID>22;
316 tensor.tensor<
float,3>()( 0, 60-1-iPF, 19) = pfCandPdgID==22;
317 tensor.tensor<
float,3>()( 0, 60-1-iPF, 20) = pfCandDzDz;
318 tensor.tensor<
float,3>()( 0, 60-1-iPF, 21) = pfCandD0Dz;
319 tensor.tensor<
float,3>()( 0, 60-1-iPF, 22) = pfCandD0Dphi;
320 tensor.tensor<
float,3>()( 0, 60-1-iPF, 23) = pfCandPtRelPtRel;
321 tensor.tensor<
float,3>()( 0, 60-1-iPF, 24) = pfCandPixHits;
322 tensor.tensor<
float,3>()( 0, 60-1-iPF, 25) = pfCandHits;
323 tensor.tensor<
float,3>()( 0, 60-1-iPF, 26) = pfCandLostInnerHits==-1;
324 tensor.tensor<
float,3>()( 0, 60-1-iPF, 27) = pfCandLostInnerHits==0;
325 tensor.tensor<
float,3>()( 0, 60-1-iPF, 28) = pfCandLostInnerHits==1;
326 tensor.tensor<
float,3>()( 0, 60-1-iPF, 29) = pfCandLostInnerHits==2;
327 tensor.tensor<
float,3>()( 0, 60-1-iPF, 30) = pfCandPuppiWeight;
328 tensor.tensor<
float,3>()( 0, 60-1-iPF, 31) = (pfCandVtxQuality == 1);
329 tensor.tensor<
float,3>()( 0, 60-1-iPF, 32) = (pfCandVtxQuality == 5);
330 tensor.tensor<
float,3>()( 0, 60-1-iPF, 33) = (pfCandVtxQuality == 6);
331 tensor.tensor<
float,3>()( 0, 60-1-iPF, 34) = (pfCandVtxQuality == 7);
332 tensor.tensor<
float,3>()( 0, 60-1-iPF, 35) = (pfCandFromPV == 1);
333 tensor.tensor<
float,3>()( 0, 60-1-iPF, 36) = (pfCandFromPV == 2);
334 tensor.tensor<
float,3>()( 0, 60-1-iPF, 37) = (pfCandFromPV == 3);
335 tensor.tensor<
float,3>()( 0, 60-1-iPF, 38) = pfCandIsBarrel;
336 tensor.tensor<
float,3>()( 0, 60-1-iPF, 39) = pfCandHighPurityTrk;
337 tensor.tensor<
float,3>()( 0, 60-1-iPF, 40) = pfCandPdgID==1;
338 tensor.tensor<
float,3>()( 0, 60-1-iPF, 41) = pfCandPdgID==2;
339 tensor.tensor<
float,3>()( 0, 60-1-iPF, 42) = pfCandPdgID==11;
340 tensor.tensor<
float,3>()( 0, 60-1-iPF, 43) = pfCandPdgID==13;
341 tensor.tensor<
float,3>()( 0, 60-1-iPF, 44) = pfCandPdgID==130;
342 tensor.tensor<
float,3>()( 0, 60-1-iPF, 45) = pfCandPdgID==211;
343 tensor.tensor<
float,3>()( 0, 60-1-iPF, 46) = pfCandTauIndMatch;
347 tensor.tensor<
float,3>()( 0, 36-1-iPF, 0) = pfCandPt;
348 tensor.tensor<
float,3>()( 0, 36-1-iPF, 1) = pfCandPz;
349 tensor.tensor<
float,3>()( 0, 36-1-iPF, 2) = pfCandPtRel;
350 tensor.tensor<
float,3>()( 0, 36-1-iPF, 3) = pfCandPzRel;
351 tensor.tensor<
float,3>()( 0, 36-1-iPF, 4) = pfCandDr;
352 tensor.tensor<
float,3>()( 0, 36-1-iPF, 5) = pfCandDEta;
353 tensor.tensor<
float,3>()( 0, 36-1-iPF, 6) = pfCandDPhi;
354 tensor.tensor<
float,3>()( 0, 36-1-iPF, 7) = pfCandEta;
355 tensor.tensor<
float,3>()( 0, 36-1-iPF, 8) = pfCandDz;
356 tensor.tensor<
float,3>()( 0, 36-1-iPF, 9) = pfCandDzSig;
357 tensor.tensor<
float,3>()( 0, 36-1-iPF, 10) = pfCandD0;
358 tensor.tensor<
float,3>()( 0, 36-1-iPF, 11) = pfCandD0Sig;
359 tensor.tensor<
float,3>()( 0, 36-1-iPF, 12) = pfCandDzErr;
360 tensor.tensor<
float,3>()( 0, 36-1-iPF, 13) = pfCandD0Err;
361 tensor.tensor<
float,3>()( 0, 36-1-iPF, 14) = pfCandD0D0;
362 tensor.tensor<
float,3>()( 0, 36-1-iPF, 15) = pfCandCharge==0;
363 tensor.tensor<
float,3>()( 0, 36-1-iPF, 16) = pfCandCharge==1;
364 tensor.tensor<
float,3>()( 0, 36-1-iPF, 17) = pfCandCharge==-1;
365 tensor.tensor<
float,3>()( 0, 36-1-iPF, 18) = pfCandPdgID>22;
366 tensor.tensor<
float,3>()( 0, 36-1-iPF, 19) = pfCandPdgID==22;
367 tensor.tensor<
float,3>()( 0, 36-1-iPF, 20) = pfCandDVx_1;
368 tensor.tensor<
float,3>()( 0, 36-1-iPF, 21) = pfCandDVy_1;
369 tensor.tensor<
float,3>()( 0, 36-1-iPF, 22) = pfCandDVz_1;
370 tensor.tensor<
float,3>()( 0, 36-1-iPF, 23) = pfCandD_1;
371 tensor.tensor<
float,3>()( 0, 36-1-iPF, 24) = pfCandDzDz;
372 tensor.tensor<
float,3>()( 0, 36-1-iPF, 25) = pfCandD0Dz;
373 tensor.tensor<
float,3>()( 0, 36-1-iPF, 26) = pfCandD0Dphi;
374 tensor.tensor<
float,3>()( 0, 36-1-iPF, 27) = pfCandPtRelPtRel;
375 tensor.tensor<
float,3>()( 0, 36-1-iPF, 28) = pfCandPixHits;
376 tensor.tensor<
float,3>()( 0, 36-1-iPF, 29) = pfCandHits;
377 tensor.tensor<
float,3>()( 0, 36-1-iPF, 30) = pfCandLostInnerHits==-1;
378 tensor.tensor<
float,3>()( 0, 36-1-iPF, 31) = pfCandLostInnerHits==0;
379 tensor.tensor<
float,3>()( 0, 36-1-iPF, 32) = pfCandLostInnerHits==1;
380 tensor.tensor<
float,3>()( 0, 36-1-iPF, 33) = pfCandLostInnerHits==2;
381 tensor.tensor<
float,3>()( 0, 36-1-iPF, 34) = pfCandPuppiWeight;
382 tensor.tensor<
float,3>()( 0, 36-1-iPF, 35) = (pfCandVtxQuality == 1);
383 tensor.tensor<
float,3>()( 0, 36-1-iPF, 36) = (pfCandVtxQuality == 5);
384 tensor.tensor<
float,3>()( 0, 36-1-iPF, 37) = (pfCandVtxQuality == 6);
385 tensor.tensor<
float,3>()( 0, 36-1-iPF, 38) = (pfCandVtxQuality == 7);
386 tensor.tensor<
float,3>()( 0, 36-1-iPF, 39) = (pfCandFromPV == 1);
387 tensor.tensor<
float,3>()( 0, 36-1-iPF, 40) = (pfCandFromPV == 2);
388 tensor.tensor<
float,3>()( 0, 36-1-iPF, 41) = (pfCandFromPV == 3);
389 tensor.tensor<
float,3>()( 0, 36-1-iPF, 42) = pfCandIsBarrel;
390 tensor.tensor<
float,3>()( 0, 36-1-iPF, 43) = pfCandHighPurityTrk;
391 tensor.tensor<
float,3>()( 0, 36-1-iPF, 44) = pfCandPdgID==1;
392 tensor.tensor<
float,3>()( 0, 36-1-iPF, 45) = pfCandPdgID==2;
393 tensor.tensor<
float,3>()( 0, 36-1-iPF, 46) = pfCandPdgID==11;
394 tensor.tensor<
float,3>()( 0, 36-1-iPF, 47) = pfCandPdgID==13;
395 tensor.tensor<
float,3>()( 0, 36-1-iPF, 48) = pfCandPdgID==130;
396 tensor.tensor<
float,3>()( 0, 36-1-iPF, 49) = pfCandPdgID==211;
397 tensor.tensor<
float,3>()( 0, 36-1-iPF, 50) = pfCandTauIndMatch;
402 predictions.matrix<
float>()(tau_index, 0) = outputs_[0].flat<
float>()(0);
float puppiWeight() const
Set both weights at once (with option for only full PUPPI)
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
edm::EDGetTokenT< pat::PackedCandidateCollection > pfcand_token
float dxyError() const override
uncertainty on dxy
double eta() const final
momentum pseudorapidity
int pdgId() const override
PDG identifier.
static unsigned getNumberOfParticles(unsigned graphVersion)
tensorflow::Session & getSession() const
const DeepTauCache * cache_
const LorentzVector & p4() const override
four-momentum Lorentz vecto r
float dzError() const override
uncertainty on dz
double pt() const final
transverse momentum
float tauID(const std::string &name) const
reco::CandidatePtrVector signalCands() const
double vz() const override
z coordinate of vertex position
def generate(map_blobs=False, class_name=None)
OutputCollection outputs_
int charge() const override
electric charge
double vy() const override
y coordinate of vertex position
static unsigned GetNumberOfFeatures(unsigned graphVersion)
const PVAssociationQuality pvAssociationQuality() const
double pz() const final
z coordinate of momentum vector
const PVAssoc fromPV(size_t ipv=0) const
bool trackHighPurity() const
true if the track had the highPurity quality bit
LostInnerHits lostInnerHits() const
Abs< T >::type abs(const T &t)
const LorentzVector & p4() const final
four-momentum Lorentz vector
double pt() const override
transverse momentum
int numberOfPixelHits() const
Analysis-level tau class.
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
double deltaR(double eta1, double eta2, double phi1, double phi2)
bool isTauIDAvailable(const std::string &name) const
Returns true if a specific ID is available in this pat::Tau.
double eta() const override
momentum pseudorapidity
double phi() const override
momentum azimuthal angle
edm::EDGetTokenT< reco::VertexCollection > vtx_token
const T & clamp(const T &v, const T &lo, const T &hi)
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, const std::vector< std::string > &targetNodes, std::vector< Tensor > *outputs)
virtual float dxy() const
dxy with respect to the PV ref
double phi() const final
momentum azimuthal angle
double vx() const override
x coordinate of vertex position