94 tensorflow::Tensor tensor(tensorflow::DT_FLOAT, {1,
97 tensorflow::Tensor predictions(tensorflow::DT_FLOAT, {
static_cast<int>(taus->size()), 1});
99 std::vector<tensorflow::Tensor>
outputs_;
101 float pfCandPt, pfCandPz, pfCandPtRel, pfCandPzRel, pfCandDr, pfCandDEta, pfCandDPhi, pfCandEta, pfCandDz,
102 pfCandDzErr, pfCandD0, pfCandD0D0, pfCandD0Dz, pfCandD0Dphi, pfCandPuppiWeight,
103 pfCandPixHits, pfCandHits, pfCandLostInnerHits, pfCandPdgID, pfCandCharge, pfCandFromPV,
104 pfCandVtxQuality, pfCandHighPurityTrk, pfCandTauIndMatch, pfCandDzSig, pfCandD0Sig, pfCandD0Err,
105 pfCandPtRelPtRel, pfCandDzDz, pfCandDVx_1, pfCandDVy_1, pfCandDVz_1, pfCandD_1;
106 float pvx = !vertices->empty() ? (*vertices)[0].x() : -1;
107 float pvy = !vertices->empty() ? (*vertices)[0].y() : -1;
108 float pvz = !vertices->empty() ? (*vertices)[0].z() : -1;
113 static constexpr float pfCandPt_max = 500.f;
114 static constexpr float pfCandPz_max = 1000.f;
115 static constexpr float pfCandPtRel_max = 1.f;
116 static constexpr float pfCandPzRel_max = 100.f;
117 static constexpr float pfCandPtRelPtRel_max = 1.f;
118 static constexpr float pfCandD0_max = 5.f;
119 static constexpr float pfCandDz_max = 5.f;
120 static constexpr float pfCandDVx_y_z_1_max = 0.05f;
121 static constexpr float pfCandD_1_max = 0.1f;
122 static constexpr float pfCandD0_z_Err_max = 1.f;
123 static constexpr float pfCandDzSig_max = 3.f;
124 static constexpr float pfCandD0Sig_max = 1.f;
125 static constexpr float pfCandDr_max = 0.5f;
126 static constexpr float pfCandEta_max = 2.75f;
127 static constexpr float pfCandDEta_max = 0.5f;
128 static constexpr float pfCandDPhi_max = 0.5f;
129 static constexpr float pfCandPixHits_max = 7.f;
130 static constexpr float pfCandHits_max = 30.f;
132 for(
size_t tau_index = 0; tau_index < taus->size(); tau_index++) {
134 bool isGoodTau =
false;
135 const float lepRecoPt = tau.
pt();
137 const float lepRecoEta = tau.
eta();
138 const float lepRecoPhi = tau.
phi();
142 isGoodTau = (tau.
tauID(
"againstElectronVLooseMVA6") && tau.
tauID(
"againstMuonLoose3") );
146 predictions.matrix<
float>()(tau_index, 0) = -1;
150 std::vector<unsigned int> signalCandidateInds;
153 signalCandidateInds.push_back(getPFCandidateIndex(pfcands,
c));
158 for(
unsigned input_idx = 0; input_idx < n_inputs; ++input_idx)
159 tensor.flat<
float>()(input_idx) = 0;
161 unsigned int iPF = 0;
164 std::vector<unsigned int> sorted_inds(pfcands->size());
169 [&](
int i1,
int i2) {
return pfcands->at(i1).pt() > pfcands->at(i2).pt(); } );
171 for(
size_t pf_index = 0; pf_index < pfcands->size() && iPF < max_iPF; pf_index++) {
175 if (p.
pt() < 0.5)
continue;
176 if (p.
fromPV() < 0)
continue;
177 if (deltaR_tau_p > 0.5)
continue;
180 pfCandPtRel = p.
pt()/lepRecoPt;
182 pfCandDr = deltaR_tau_p;
186 pfCandIsBarrel = (
std::abs(pfCandEta) < 1.4);
187 pfCandPz =
std::abs(std::sinh(pfCandEta)*pfCandPt);
188 pfCandPzRel = pfCandPz/lepRecoPz;
190 pfCandCharge = p.
charge();
191 pfCandDVx_1 = p.
vx() - pvx;
192 pfCandDVy_1 = p.
vy() - pvy;
193 pfCandDVz_1 = p.
vz() - pvz;
195 pfCandD_1 =
std::sqrt(pfCandDVx_1*pfCandDVx_1 + pfCandDVy_1*pfCandDVy_1 + pfCandDVz_1*pfCandDVz_1);
209 int psudorand = p.
pt()*1000000;
210 if (psudorand%2 == 0) disp = -1;
219 pfCandLostInnerHits = 2.;
227 pfCandFromPV = p.
fromPV();
230 float pfCandTauIndMatch_temp = 0;
232 for (
auto i : signalCandidateInds) {
233 if (
i == sorted_inds.at(pf_index)) pfCandTauIndMatch_temp = 1;
236 pfCandTauIndMatch = pfCandTauIndMatch_temp;
237 pfCandPtRelPtRel = pfCandPtRel*pfCandPtRel;
238 pfCandPt =
std::min(pfCandPt, pfCandPt_max);
239 pfCandPt = pfCandPt/pfCandPt_max;
241 pfCandPz =
std::min(pfCandPz, pfCandPz_max);
242 pfCandPz = pfCandPz/pfCandPz_max;
244 pfCandPtRel =
std::min(pfCandPtRel, pfCandPtRel_max);
245 pfCandPzRel =
std::min(pfCandPzRel, pfCandPzRel_max);
246 pfCandPzRel = pfCandPzRel/pfCandPzRel_max;
247 pfCandDr = pfCandDr/pfCandDr_max;
248 pfCandEta = pfCandEta/pfCandEta_max;
249 pfCandDEta = pfCandDEta/pfCandDEta_max;
250 pfCandDPhi = pfCandDPhi/pfCandDPhi_max;
251 pfCandPixHits = pfCandPixHits/pfCandPixHits_max;
252 pfCandHits = pfCandHits/pfCandHits_max;
254 pfCandPtRelPtRel =
std::min(pfCandPtRelPtRel, pfCandPtRelPtRel_max);
256 pfCandD0 = std::clamp(pfCandD0, -pfCandD0_max, pfCandD0_max);
257 pfCandD0 = pfCandD0/pfCandD0_max;
259 pfCandDz = std::clamp(pfCandDz, -pfCandDz_max, pfCandDz_max);
260 pfCandDz = pfCandDz/pfCandDz_max;
262 pfCandD0Err =
std::min(pfCandD0Err, pfCandD0_z_Err_max);
263 pfCandDzErr =
std::min(pfCandDzErr, pfCandD0_z_Err_max);
264 pfCandDzSig =
std::min(pfCandDzSig, pfCandDzSig_max);
265 pfCandDzSig = pfCandDzSig/pfCandDzSig_max;
267 pfCandD0Sig =
std::min(pfCandD0Sig, pfCandD0Sig_max);
268 pfCandD0D0 = pfCandD0*pfCandD0;
269 pfCandDzDz = pfCandDz*pfCandDz;
270 pfCandD0Dz = pfCandD0*pfCandDz;
271 pfCandD0Dphi = pfCandD0*pfCandDPhi;
273 pfCandDVx_1 = std::clamp(pfCandDVx_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
274 pfCandDVx_1 = pfCandDVx_1/pfCandDVx_y_z_1_max;
276 pfCandDVy_1 = std::clamp(pfCandDVy_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
277 pfCandDVy_1 = pfCandDVy_1/pfCandDVx_y_z_1_max;
279 pfCandDVz_1 = std::clamp(pfCandDVz_1, -pfCandDVx_y_z_1_max, pfCandDVx_y_z_1_max);
280 pfCandDVz_1 = pfCandDVz_1/pfCandDVx_y_z_1_max;
282 pfCandD_1 = std::clamp(pfCandD_1, -pfCandD_1_max, pfCandD_1_max);
283 pfCandD_1 = pfCandD_1/ pfCandD_1_max;
286 tensor.tensor<
float,3>()( 0, 60-1-iPF, 0) = pfCandPt;
287 tensor.tensor<
float,3>()( 0, 60-1-iPF, 1) = pfCandPz;
288 tensor.tensor<
float,3>()( 0, 60-1-iPF, 2) = pfCandPtRel;
289 tensor.tensor<
float,3>()( 0, 60-1-iPF, 3) = pfCandPzRel;
290 tensor.tensor<
float,3>()( 0, 60-1-iPF, 4) = pfCandDr;
291 tensor.tensor<
float,3>()( 0, 60-1-iPF, 5) = pfCandDEta;
292 tensor.tensor<
float,3>()( 0, 60-1-iPF, 6) = pfCandDPhi;
293 tensor.tensor<
float,3>()( 0, 60-1-iPF, 7) = pfCandEta;
294 tensor.tensor<
float,3>()( 0, 60-1-iPF, 8) = pfCandDz;
295 tensor.tensor<
float,3>()( 0, 60-1-iPF, 9) = pfCandDzSig;
296 tensor.tensor<
float,3>()( 0, 60-1-iPF, 10) = pfCandD0;
297 tensor.tensor<
float,3>()( 0, 60-1-iPF, 11) = pfCandD0Sig;
298 tensor.tensor<
float,3>()( 0, 60-1-iPF, 12) = pfCandDzErr;
299 tensor.tensor<
float,3>()( 0, 60-1-iPF, 13) = pfCandD0Err;
300 tensor.tensor<
float,3>()( 0, 60-1-iPF, 14) = pfCandD0D0;
301 tensor.tensor<
float,3>()( 0, 60-1-iPF, 15) = pfCandCharge==0;
302 tensor.tensor<
float,3>()( 0, 60-1-iPF, 16) = pfCandCharge==1;
303 tensor.tensor<
float,3>()( 0, 60-1-iPF, 17) = pfCandCharge==-1;
304 tensor.tensor<
float,3>()( 0, 60-1-iPF, 18) = pfCandPdgID>22;
305 tensor.tensor<
float,3>()( 0, 60-1-iPF, 19) = pfCandPdgID==22;
306 tensor.tensor<
float,3>()( 0, 60-1-iPF, 20) = pfCandDzDz;
307 tensor.tensor<
float,3>()( 0, 60-1-iPF, 21) = pfCandD0Dz;
308 tensor.tensor<
float,3>()( 0, 60-1-iPF, 22) = pfCandD0Dphi;
309 tensor.tensor<
float,3>()( 0, 60-1-iPF, 23) = pfCandPtRelPtRel;
310 tensor.tensor<
float,3>()( 0, 60-1-iPF, 24) = pfCandPixHits;
311 tensor.tensor<
float,3>()( 0, 60-1-iPF, 25) = pfCandHits;
312 tensor.tensor<
float,3>()( 0, 60-1-iPF, 26) = pfCandLostInnerHits==-1;
313 tensor.tensor<
float,3>()( 0, 60-1-iPF, 27) = pfCandLostInnerHits==0;
314 tensor.tensor<
float,3>()( 0, 60-1-iPF, 28) = pfCandLostInnerHits==1;
315 tensor.tensor<
float,3>()( 0, 60-1-iPF, 29) = pfCandLostInnerHits==2;
316 tensor.tensor<
float,3>()( 0, 60-1-iPF, 30) = pfCandPuppiWeight;
317 tensor.tensor<
float,3>()( 0, 60-1-iPF, 31) = (pfCandVtxQuality == 1);
318 tensor.tensor<
float,3>()( 0, 60-1-iPF, 32) = (pfCandVtxQuality == 5);
319 tensor.tensor<
float,3>()( 0, 60-1-iPF, 33) = (pfCandVtxQuality == 6);
320 tensor.tensor<
float,3>()( 0, 60-1-iPF, 34) = (pfCandVtxQuality == 7);
321 tensor.tensor<
float,3>()( 0, 60-1-iPF, 35) = (pfCandFromPV == 1);
322 tensor.tensor<
float,3>()( 0, 60-1-iPF, 36) = (pfCandFromPV == 2);
323 tensor.tensor<
float,3>()( 0, 60-1-iPF, 37) = (pfCandFromPV == 3);
324 tensor.tensor<
float,3>()( 0, 60-1-iPF, 38) = pfCandIsBarrel;
325 tensor.tensor<
float,3>()( 0, 60-1-iPF, 39) = pfCandHighPurityTrk;
326 tensor.tensor<
float,3>()( 0, 60-1-iPF, 40) = pfCandPdgID==1;
327 tensor.tensor<
float,3>()( 0, 60-1-iPF, 41) = pfCandPdgID==2;
328 tensor.tensor<
float,3>()( 0, 60-1-iPF, 42) = pfCandPdgID==11;
329 tensor.tensor<
float,3>()( 0, 60-1-iPF, 43) = pfCandPdgID==13;
330 tensor.tensor<
float,3>()( 0, 60-1-iPF, 44) = pfCandPdgID==130;
331 tensor.tensor<
float,3>()( 0, 60-1-iPF, 45) = pfCandPdgID==211;
332 tensor.tensor<
float,3>()( 0, 60-1-iPF, 46) = pfCandTauIndMatch;
336 tensor.tensor<
float,3>()( 0, 36-1-iPF, 0) = pfCandPt;
337 tensor.tensor<
float,3>()( 0, 36-1-iPF, 1) = pfCandPz;
338 tensor.tensor<
float,3>()( 0, 36-1-iPF, 2) = pfCandPtRel;
339 tensor.tensor<
float,3>()( 0, 36-1-iPF, 3) = pfCandPzRel;
340 tensor.tensor<
float,3>()( 0, 36-1-iPF, 4) = pfCandDr;
341 tensor.tensor<
float,3>()( 0, 36-1-iPF, 5) = pfCandDEta;
342 tensor.tensor<
float,3>()( 0, 36-1-iPF, 6) = pfCandDPhi;
343 tensor.tensor<
float,3>()( 0, 36-1-iPF, 7) = pfCandEta;
344 tensor.tensor<
float,3>()( 0, 36-1-iPF, 8) = pfCandDz;
345 tensor.tensor<
float,3>()( 0, 36-1-iPF, 9) = pfCandDzSig;
346 tensor.tensor<
float,3>()( 0, 36-1-iPF, 10) = pfCandD0;
347 tensor.tensor<
float,3>()( 0, 36-1-iPF, 11) = pfCandD0Sig;
348 tensor.tensor<
float,3>()( 0, 36-1-iPF, 12) = pfCandDzErr;
349 tensor.tensor<
float,3>()( 0, 36-1-iPF, 13) = pfCandD0Err;
350 tensor.tensor<
float,3>()( 0, 36-1-iPF, 14) = pfCandD0D0;
351 tensor.tensor<
float,3>()( 0, 36-1-iPF, 15) = pfCandCharge==0;
352 tensor.tensor<
float,3>()( 0, 36-1-iPF, 16) = pfCandCharge==1;
353 tensor.tensor<
float,3>()( 0, 36-1-iPF, 17) = pfCandCharge==-1;
354 tensor.tensor<
float,3>()( 0, 36-1-iPF, 18) = pfCandPdgID>22;
355 tensor.tensor<
float,3>()( 0, 36-1-iPF, 19) = pfCandPdgID==22;
356 tensor.tensor<
float,3>()( 0, 36-1-iPF, 20) = pfCandDVx_1;
357 tensor.tensor<
float,3>()( 0, 36-1-iPF, 21) = pfCandDVy_1;
358 tensor.tensor<
float,3>()( 0, 36-1-iPF, 22) = pfCandDVz_1;
359 tensor.tensor<
float,3>()( 0, 36-1-iPF, 23) = pfCandD_1;
360 tensor.tensor<
float,3>()( 0, 36-1-iPF, 24) = pfCandDzDz;
361 tensor.tensor<
float,3>()( 0, 36-1-iPF, 25) = pfCandD0Dz;
362 tensor.tensor<
float,3>()( 0, 36-1-iPF, 26) = pfCandD0Dphi;
363 tensor.tensor<
float,3>()( 0, 36-1-iPF, 27) = pfCandPtRelPtRel;
364 tensor.tensor<
float,3>()( 0, 36-1-iPF, 28) = pfCandPixHits;
365 tensor.tensor<
float,3>()( 0, 36-1-iPF, 29) = pfCandHits;
366 tensor.tensor<
float,3>()( 0, 36-1-iPF, 30) = pfCandLostInnerHits==-1;
367 tensor.tensor<
float,3>()( 0, 36-1-iPF, 31) = pfCandLostInnerHits==0;
368 tensor.tensor<
float,3>()( 0, 36-1-iPF, 32) = pfCandLostInnerHits==1;
369 tensor.tensor<
float,3>()( 0, 36-1-iPF, 33) = pfCandLostInnerHits==2;
370 tensor.tensor<
float,3>()( 0, 36-1-iPF, 34) = pfCandPuppiWeight;
371 tensor.tensor<
float,3>()( 0, 36-1-iPF, 35) = (pfCandVtxQuality == 1);
372 tensor.tensor<
float,3>()( 0, 36-1-iPF, 36) = (pfCandVtxQuality == 5);
373 tensor.tensor<
float,3>()( 0, 36-1-iPF, 37) = (pfCandVtxQuality == 6);
374 tensor.tensor<
float,3>()( 0, 36-1-iPF, 38) = (pfCandVtxQuality == 7);
375 tensor.tensor<
float,3>()( 0, 36-1-iPF, 39) = (pfCandFromPV == 1);
376 tensor.tensor<
float,3>()( 0, 36-1-iPF, 40) = (pfCandFromPV == 2);
377 tensor.tensor<
float,3>()( 0, 36-1-iPF, 41) = (pfCandFromPV == 3);
378 tensor.tensor<
float,3>()( 0, 36-1-iPF, 42) = pfCandIsBarrel;
379 tensor.tensor<
float,3>()( 0, 36-1-iPF, 43) = pfCandHighPurityTrk;
380 tensor.tensor<
float,3>()( 0, 36-1-iPF, 44) = pfCandPdgID==1;
381 tensor.tensor<
float,3>()( 0, 36-1-iPF, 45) = pfCandPdgID==2;
382 tensor.tensor<
float,3>()( 0, 36-1-iPF, 46) = pfCandPdgID==11;
383 tensor.tensor<
float,3>()( 0, 36-1-iPF, 47) = pfCandPdgID==13;
384 tensor.tensor<
float,3>()( 0, 36-1-iPF, 48) = pfCandPdgID==130;
385 tensor.tensor<
float,3>()( 0, 36-1-iPF, 49) = pfCandPdgID==211;
386 tensor.tensor<
float,3>()( 0, 36-1-iPF, 50) = pfCandTauIndMatch;
391 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
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