Skip to content

Commit

Permalink
Merge pull request #41492 from Duchstf/Tau_L1_2023_cmssw
Browse files Browse the repository at this point in the history
Retrained L1 Tau Trigger Integration
  • Loading branch information
cmsbuild authored Jun 22, 2023
2 parents 8ea0010 + 70ee234 commit c34a318
Show file tree
Hide file tree
Showing 17 changed files with 614 additions and 427 deletions.
23 changes: 17 additions & 6 deletions DataFormats/L1TParticleFlow/interface/PFTau.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include <algorithm>
#include <vector>
#include "DataFormats/L1Trigger/interface/L1Candidate.h"
#include "DataFormats/L1TParticleFlow/interface/taus.h"
#include "DataFormats/L1TParticleFlow/interface/gt_datatypes.h"

namespace l1t {

static constexpr float PFTAU_NN_OFFSET = 0.1;
static constexpr float PFTAU_NN_SLOPE = 0.2;
static constexpr float PFTAU_NN_OVERALL_SCALE = 1. / 20.1;

static constexpr float PFTAU_NN_LOOSE_CUT = 0.05;
static constexpr float PFTAU_NN_LOOSE_CUT = 0.28;
static constexpr float PFTAU_NN_TIGHT_CUT = 0.25;

static constexpr float PFTAU_PF_LOOSE_CUT = 10.0;
Expand All @@ -26,14 +28,16 @@ namespace l1t {
PFTau() {}
enum { unidentified = 0, oneprong = 1, oneprongpi0 = 2, threeprong = 3 };
PFTau(const LorentzVector& p,
float iVector[80],
float iso = -1,
float fulliso = -1,
int id = 0,
int hwpt = 0,
int hweta = 0,
int hwphi = 0)
: PFTau(PolarLorentzVector(p), iso, id, hwpt, hweta, hwphi) {}
: PFTau(PolarLorentzVector(p), iVector, iso, id, hwpt, hweta, hwphi) {}
PFTau(const PolarLorentzVector& p,
float iVector[80],
float iso = -1,
float fulliso = -1,
int id = 0,
Expand All @@ -49,12 +53,10 @@ namespace l1t {

float z0() const { return vz(); }
float dxy() const { return dxy_; }
const float* NNValues() const { return NNValues_; }

bool passMass() const { return (mass() < 2 + pt() / PTSCALING_MASSCUT); }
bool passLooseNN() const {
return iso_ * (PFTAU_NN_OFFSET + PFTAU_NN_SLOPE * (min(pt(), PFTAU_NN_PT_CUTOFF))) * PFTAU_NN_OVERALL_SCALE >
PFTAU_NN_LOOSE_CUT;
}
bool passLooseNN() const { return iso_ > PFTAU_NN_LOOSE_CUT; }
bool passLooseNNMass() const {
if (!passMass())
return false;
Expand All @@ -72,11 +74,20 @@ namespace l1t {
}
bool passTightPF() const { return fullIso_ < PFTAU_PF_TIGHT_CUT; }

//Tau encoding for GT
void set_encodedTau(l1gt::PackedTau encodedTau) { encodedTau_ = encodedTau; }
l1gt::PackedTau encodedTau() const { return encodedTau_; } //Can be unpacked using l1gt::Tau::unpack()

//Return the l1gt Tau object from the encoded objects
l1gt::Tau getHWTauGT() const { return l1gt::Tau::unpack(encodedTau_); }

private:
float NNValues_[80]; // Values for each of the 80 NN inputs
float iso_;
float fullIso_;
int id_;
float dxy_;
l1gt::PackedTau encodedTau_;
};

typedef std::vector<l1t::PFTau> PFTauCollection;
Expand Down
44 changes: 42 additions & 2 deletions DataFormats/L1TParticleFlow/interface/gt_datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace l1gt {

// tau fields
typedef ap_ufixed<10, 8> tauseed_pt_t;
typedef ap_uint<10> tau_rawid_t;
typedef std::array<uint64_t, 2> PackedTau;

namespace Scales {
const int INTPHI_PI = 1 << (phi_t::width - 1);
Expand Down Expand Up @@ -183,12 +185,12 @@ namespace l1gt {
z0_t seed_z0;
ap_uint<1> charge;
ap_uint<2> type;
iso_t isolation;
tau_rawid_t isolation;
ap_uint<2> id0;
ap_uint<2> id1;

static const int BITWIDTH = 128;
inline ap_uint<BITWIDTH> pack() const {
inline ap_uint<BITWIDTH> pack_ap() const {
ap_uint<BITWIDTH> ret;
unsigned int start = 0;
pack_into_bits(ret, start, valid);
Expand All @@ -202,6 +204,44 @@ namespace l1gt {
pack_into_bits(ret, start, id1);
return ret;
}

inline PackedTau pack() const {
PackedTau packed;
ap_uint<BITWIDTH> bits = this->pack_ap();
packed[0] = bits(63, 0);
packed[1] = bits(127, 64);
return packed;
}

inline static Tau unpack_ap(const ap_uint<BITWIDTH> &src) {
Tau ret;
ret.initFromBits(src);
return ret;
}

inline static Tau unpack(const PackedTau &src) {
ap_uint<BITWIDTH> bits;
bits(63, 0) = src[0];
bits(127, 64) = src[1];

return unpack_ap(bits);
}

inline void initFromBits(const ap_uint<BITWIDTH> &src) {
unsigned int start = 0;
unpack_from_bits(src, start, valid);
unpack_from_bits(src, start, v3.pt);
unpack_from_bits(src, start, v3.phi);
unpack_from_bits(src, start, v3.eta);
unpack_from_bits(src, start, seed_pt);
unpack_from_bits(src, start, seed_z0);
unpack_from_bits(src, start, charge);
unpack_from_bits(src, start, type);
unpack_from_bits(src, start, isolation);
unpack_from_bits(src, start, id0);
unpack_from_bits(src, start, id1);
}

}; // struct Tau

struct Electron {
Expand Down
21 changes: 20 additions & 1 deletion DataFormats/L1TParticleFlow/interface/taus.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "DataFormats/L1TParticleFlow/interface/datatypes.h"
#include "DataFormats/L1TParticleFlow/interface/bit_encoding.h"
#include "DataFormats/L1TParticleFlow/interface/gt_datatypes.h"

namespace l1ct {

Expand Down Expand Up @@ -46,7 +47,7 @@ namespace l1ct {
hwPhi = 0;
hwSeedPt = 0;
hwSeedZ0 = 0;
hwCharge = 0;
hwCharge = false;
hwType = 0;
hwIsoOrMVA = 0;
hwIdVsMu = 0;
Expand Down Expand Up @@ -87,6 +88,7 @@ namespace l1ct {
pack_into_bits(ret, start, hwIsoOrMVA);
return ret;
}

inline static Tau unpack(const ap_uint<BITWIDTH> &src) {
Tau ret;
unsigned int start = 0;
Expand All @@ -102,6 +104,23 @@ namespace l1ct {
unpack_from_bits(src, start, ret.hwIsoOrMVA);
return ret;
}

l1gt::Tau toGT() const {
l1gt::Tau t;
t.valid = hwPt != 0;

t.v3.pt = CTtoGT_pt(hwPt);
t.v3.phi = CTtoGT_phi(hwPhi);
t.v3.eta = CTtoGT_eta(hwEta);

t.seed_pt = hwSeedPt;
t.seed_z0 = hwSeedZ0;
t.charge = hwCharge;

t.type = hwType;
t.isolation = hwRawId;
return t;
}
};

inline void clear(Tau &c) { c.clear(); }
Expand Down
8 changes: 6 additions & 2 deletions DataFormats/L1TParticleFlow/src/PFTau.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "DataFormats/L1TParticleFlow/interface/PFTau.h"

l1t::PFTau::PFTau(const PolarLorentzVector& p, float iso, float fulliso, int id, int hwpt, int hweta, int hwphi)
: L1Candidate(p, hwpt, hweta, hwphi, /*hwQuality=*/int(0)), iso_(iso), fullIso_(fulliso), id_(id) {}
l1t::PFTau::PFTau(
const PolarLorentzVector& p, float NNValues[80], float iso, float fulliso, int id, int hwpt, int hweta, int hwphi)
: L1Candidate(p, hwpt, hweta, hwphi, /*hwQuality=*/int(0)), iso_(iso), fullIso_(fulliso), id_(id) {
for (int i0 = 0; i0 < 80; i0++)
NNValues_[i0] = NNValues[i0]; // copy the array of NN inputs
}
3 changes: 2 additions & 1 deletion DataFormats/L1TParticleFlow/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
<class name="edm::RefVector<l1t::PFJetCollection>" />
<class name="std::vector<edm::Ref<std::vector<l1t::PFJet>,l1t::PFJet,edm::refhelper::FindUsingAdvance<std::vector<l1t::PFJet>,l1t::PFJet> > >" />

<class name="l1t::PFTau" ClassVersion="4">
<class name="l1t::PFTau" ClassVersion="5">
<version ClassVersion="5" checksum="549313204"/>
<version ClassVersion="4" checksum="2045755946"/>
<version ClassVersion="3" checksum="1410157160"/>
</class>
Expand Down
1 change: 1 addition & 0 deletions L1Trigger/Phase2L1ParticleFlow/interface/TauNNId.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TauNNId {

void setNNVectorVar();
float EvaluateNN();
float *NNVectorVar() { return NNvectorVar_.data(); }
float compute(const l1t::PFCandidate &iSeed, l1t::PFCandidateCollection &iParts);

private:
Expand Down
1 change: 1 addition & 0 deletions L1Trigger/Phase2L1ParticleFlow/interface/taus/TauNNIdHW.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class TauNNIdHW {

void initialize(const std::string &iName, int iNParticles);
void SetNNVectorVar();
input_t *NNVectorVar() { return NNvectorVar_.data(); }
result_t EvaluateNN();
result_t compute(const l1t::PFCandidate &iSeed, std::vector<l1t::PFCandidate> &iParts);
//void print();
Expand Down
15 changes: 7 additions & 8 deletions L1Trigger/Phase2L1ParticleFlow/interface/taus/weights/b1.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//Numpy array shape [25]
//Min -1.101188778877
//Max 1.014160394669
//Number of zeros 2
//Min -0.734825849533
//Max 1.288661003113
//Number of zeros 0

#ifndef B1_H_
#define B1_H_

weight_default_t b1[25] = {0.8776568174, -0.0888396949, -0.1198173761, -0.0066847582, -0.0117284302,
-0.0283335019, 0.0000000000, -1.1011887789, -0.0135271018, -0.0323914811,
0.5437909961, -0.0175916012, 0.5357875228, -0.3656347692, 0.2423969060,
1.0141603947, 0.0000000000, -0.7741876245, 0.9614976048, 0.5918464661,
-0.3908625543, -0.2043008506, -0.3004969060, -0.1039064825, 0.5963121057};
weight_default_t b1[25] = {-0.12057505, -0.05409636, 0.27422485, 0.49775919, -0.73482585, 0.44995615, 0.52624124,
-0.71328187, -0.43596983, 0.10772870, -0.68372047, 0.22197038, -0.53673136, -0.00771000,
0.06140821, 1.28866100, -0.12453079, 0.16897179, 0.18858922, -0.17255782, -0.24242370,
-0.21922758, 0.40799412, 0.46138164, 0.85911417};

#endif
24 changes: 12 additions & 12 deletions L1Trigger/Phase2L1ParticleFlow/interface/taus/weights/b2.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//Numpy array shape [10]
//Min -0.819882214069
//Max 0.973487198353
//Min -0.380347400904
//Max 0.551839828491
//Number of zeros 0

#ifndef B2_H_
#define B2_H_

weight_default_t b2[10] = {-0.8198822141,
0.7516837120,
0.6504452229,
-0.0292063691,
-0.0308178961,
0.9734871984,
0.1587447226,
-0.3352679014,
-0.0403082110,
0.9563522935};
weight_default_t b2[10] = {0.55183983,
0.36323273,
-0.13108490,
-0.38034740,
0.08559006,
0.01700789,
0.13562575,
-0.32752651,
0.48282012,
-0.15096320};

#endif
24 changes: 12 additions & 12 deletions L1Trigger/Phase2L1ParticleFlow/interface/taus/weights/b3.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//Numpy array shape [10]
//Min -0.128828719258
//Max 1.138555169106
//Min -0.936354994774
//Max 0.407682240009
//Number of zeros 0

#ifndef B3_H_
#define B3_H_

weight_default_t b3[10] = {1.0009469986,
-0.0118703200,
0.5378767252,
0.6056469083,
-0.0177963823,
0.3281430006,
-0.0163392760,
1.1385551691,
-0.1288287193,
0.5457931757};
weight_default_t b3[10] = {-0.58549309,
-0.06117089,
-0.24173595,
0.17925857,
-0.93635499,
0.18813914,
0.13134949,
0.04132507,
0.40768224,
0.29987794};

#endif
6 changes: 3 additions & 3 deletions L1Trigger/Phase2L1ParticleFlow/interface/taus/weights/b4.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//Numpy array shape [1]
//Min -0.572278082371
//Max -0.572278082371
//Min 0.023343238980
//Max 0.023343238980
//Number of zeros 0

#ifndef B4_H_
#define B4_H_

weight_default_t b4[1] = {-0.5722780824};
weight_default_t b4[1] = {0.02334324};

#endif
Loading

0 comments on commit c34a318

Please sign in to comment.