Skip to content

Commit c34a318

Browse files
authored
Merge pull request #41492 from Duchstf/Tau_L1_2023_cmssw
Retrained L1 Tau Trigger Integration
2 parents 8ea0010 + 70ee234 commit c34a318

File tree

17 files changed

+614
-427
lines changed

17 files changed

+614
-427
lines changed

DataFormats/L1TParticleFlow/interface/PFTau.h

+17-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
#include <algorithm>
55
#include <vector>
66
#include "DataFormats/L1Trigger/interface/L1Candidate.h"
7+
#include "DataFormats/L1TParticleFlow/interface/taus.h"
8+
#include "DataFormats/L1TParticleFlow/interface/gt_datatypes.h"
79

810
namespace l1t {
911

1012
static constexpr float PFTAU_NN_OFFSET = 0.1;
1113
static constexpr float PFTAU_NN_SLOPE = 0.2;
1214
static constexpr float PFTAU_NN_OVERALL_SCALE = 1. / 20.1;
1315

14-
static constexpr float PFTAU_NN_LOOSE_CUT = 0.05;
16+
static constexpr float PFTAU_NN_LOOSE_CUT = 0.28;
1517
static constexpr float PFTAU_NN_TIGHT_CUT = 0.25;
1618

1719
static constexpr float PFTAU_PF_LOOSE_CUT = 10.0;
@@ -26,14 +28,16 @@ namespace l1t {
2628
PFTau() {}
2729
enum { unidentified = 0, oneprong = 1, oneprongpi0 = 2, threeprong = 3 };
2830
PFTau(const LorentzVector& p,
31+
float iVector[80],
2932
float iso = -1,
3033
float fulliso = -1,
3134
int id = 0,
3235
int hwpt = 0,
3336
int hweta = 0,
3437
int hwphi = 0)
35-
: PFTau(PolarLorentzVector(p), iso, id, hwpt, hweta, hwphi) {}
38+
: PFTau(PolarLorentzVector(p), iVector, iso, id, hwpt, hweta, hwphi) {}
3639
PFTau(const PolarLorentzVector& p,
40+
float iVector[80],
3741
float iso = -1,
3842
float fulliso = -1,
3943
int id = 0,
@@ -49,12 +53,10 @@ namespace l1t {
4953

5054
float z0() const { return vz(); }
5155
float dxy() const { return dxy_; }
56+
const float* NNValues() const { return NNValues_; }
5257

5358
bool passMass() const { return (mass() < 2 + pt() / PTSCALING_MASSCUT); }
54-
bool passLooseNN() const {
55-
return iso_ * (PFTAU_NN_OFFSET + PFTAU_NN_SLOPE * (min(pt(), PFTAU_NN_PT_CUTOFF))) * PFTAU_NN_OVERALL_SCALE >
56-
PFTAU_NN_LOOSE_CUT;
57-
}
59+
bool passLooseNN() const { return iso_ > PFTAU_NN_LOOSE_CUT; }
5860
bool passLooseNNMass() const {
5961
if (!passMass())
6062
return false;
@@ -72,11 +74,20 @@ namespace l1t {
7274
}
7375
bool passTightPF() const { return fullIso_ < PFTAU_PF_TIGHT_CUT; }
7476

77+
//Tau encoding for GT
78+
void set_encodedTau(l1gt::PackedTau encodedTau) { encodedTau_ = encodedTau; }
79+
l1gt::PackedTau encodedTau() const { return encodedTau_; } //Can be unpacked using l1gt::Tau::unpack()
80+
81+
//Return the l1gt Tau object from the encoded objects
82+
l1gt::Tau getHWTauGT() const { return l1gt::Tau::unpack(encodedTau_); }
83+
7584
private:
85+
float NNValues_[80]; // Values for each of the 80 NN inputs
7686
float iso_;
7787
float fullIso_;
7888
int id_;
7989
float dxy_;
90+
l1gt::PackedTau encodedTau_;
8091
};
8192

8293
typedef std::vector<l1t::PFTau> PFTauCollection;

DataFormats/L1TParticleFlow/interface/gt_datatypes.h

+42-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace l1gt {
3333

3434
// tau fields
3535
typedef ap_ufixed<10, 8> tauseed_pt_t;
36+
typedef ap_uint<10> tau_rawid_t;
37+
typedef std::array<uint64_t, 2> PackedTau;
3638

3739
namespace Scales {
3840
const int INTPHI_PI = 1 << (phi_t::width - 1);
@@ -183,12 +185,12 @@ namespace l1gt {
183185
z0_t seed_z0;
184186
ap_uint<1> charge;
185187
ap_uint<2> type;
186-
iso_t isolation;
188+
tau_rawid_t isolation;
187189
ap_uint<2> id0;
188190
ap_uint<2> id1;
189191

190192
static const int BITWIDTH = 128;
191-
inline ap_uint<BITWIDTH> pack() const {
193+
inline ap_uint<BITWIDTH> pack_ap() const {
192194
ap_uint<BITWIDTH> ret;
193195
unsigned int start = 0;
194196
pack_into_bits(ret, start, valid);
@@ -202,6 +204,44 @@ namespace l1gt {
202204
pack_into_bits(ret, start, id1);
203205
return ret;
204206
}
207+
208+
inline PackedTau pack() const {
209+
PackedTau packed;
210+
ap_uint<BITWIDTH> bits = this->pack_ap();
211+
packed[0] = bits(63, 0);
212+
packed[1] = bits(127, 64);
213+
return packed;
214+
}
215+
216+
inline static Tau unpack_ap(const ap_uint<BITWIDTH> &src) {
217+
Tau ret;
218+
ret.initFromBits(src);
219+
return ret;
220+
}
221+
222+
inline static Tau unpack(const PackedTau &src) {
223+
ap_uint<BITWIDTH> bits;
224+
bits(63, 0) = src[0];
225+
bits(127, 64) = src[1];
226+
227+
return unpack_ap(bits);
228+
}
229+
230+
inline void initFromBits(const ap_uint<BITWIDTH> &src) {
231+
unsigned int start = 0;
232+
unpack_from_bits(src, start, valid);
233+
unpack_from_bits(src, start, v3.pt);
234+
unpack_from_bits(src, start, v3.phi);
235+
unpack_from_bits(src, start, v3.eta);
236+
unpack_from_bits(src, start, seed_pt);
237+
unpack_from_bits(src, start, seed_z0);
238+
unpack_from_bits(src, start, charge);
239+
unpack_from_bits(src, start, type);
240+
unpack_from_bits(src, start, isolation);
241+
unpack_from_bits(src, start, id0);
242+
unpack_from_bits(src, start, id1);
243+
}
244+
205245
}; // struct Tau
206246

207247
struct Electron {

DataFormats/L1TParticleFlow/interface/taus.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "DataFormats/L1TParticleFlow/interface/datatypes.h"
55
#include "DataFormats/L1TParticleFlow/interface/bit_encoding.h"
6+
#include "DataFormats/L1TParticleFlow/interface/gt_datatypes.h"
67

78
namespace l1ct {
89

@@ -46,7 +47,7 @@ namespace l1ct {
4647
hwPhi = 0;
4748
hwSeedPt = 0;
4849
hwSeedZ0 = 0;
49-
hwCharge = 0;
50+
hwCharge = false;
5051
hwType = 0;
5152
hwIsoOrMVA = 0;
5253
hwIdVsMu = 0;
@@ -87,6 +88,7 @@ namespace l1ct {
8788
pack_into_bits(ret, start, hwIsoOrMVA);
8889
return ret;
8990
}
91+
9092
inline static Tau unpack(const ap_uint<BITWIDTH> &src) {
9193
Tau ret;
9294
unsigned int start = 0;
@@ -102,6 +104,23 @@ namespace l1ct {
102104
unpack_from_bits(src, start, ret.hwIsoOrMVA);
103105
return ret;
104106
}
107+
108+
l1gt::Tau toGT() const {
109+
l1gt::Tau t;
110+
t.valid = hwPt != 0;
111+
112+
t.v3.pt = CTtoGT_pt(hwPt);
113+
t.v3.phi = CTtoGT_phi(hwPhi);
114+
t.v3.eta = CTtoGT_eta(hwEta);
115+
116+
t.seed_pt = hwSeedPt;
117+
t.seed_z0 = hwSeedZ0;
118+
t.charge = hwCharge;
119+
120+
t.type = hwType;
121+
t.isolation = hwRawId;
122+
return t;
123+
}
105124
};
106125

107126
inline void clear(Tau &c) { c.clear(); }
+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#include "DataFormats/L1TParticleFlow/interface/PFTau.h"
22

3-
l1t::PFTau::PFTau(const PolarLorentzVector& p, float iso, float fulliso, int id, int hwpt, int hweta, int hwphi)
4-
: L1Candidate(p, hwpt, hweta, hwphi, /*hwQuality=*/int(0)), iso_(iso), fullIso_(fulliso), id_(id) {}
3+
l1t::PFTau::PFTau(
4+
const PolarLorentzVector& p, float NNValues[80], float iso, float fulliso, int id, int hwpt, int hweta, int hwphi)
5+
: L1Candidate(p, hwpt, hweta, hwphi, /*hwQuality=*/int(0)), iso_(iso), fullIso_(fulliso), id_(id) {
6+
for (int i0 = 0; i0 < 80; i0++)
7+
NNValues_[i0] = NNValues[i0]; // copy the array of NN inputs
8+
}

DataFormats/L1TParticleFlow/src/classes_def.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
<class name="edm::RefVector<l1t::PFJetCollection>" />
4848
<class name="std::vector<edm::Ref<std::vector<l1t::PFJet>,l1t::PFJet,edm::refhelper::FindUsingAdvance<std::vector<l1t::PFJet>,l1t::PFJet> > >" />
4949

50-
<class name="l1t::PFTau" ClassVersion="4">
50+
<class name="l1t::PFTau" ClassVersion="5">
51+
<version ClassVersion="5" checksum="549313204"/>
5152
<version ClassVersion="4" checksum="2045755946"/>
5253
<version ClassVersion="3" checksum="1410157160"/>
5354
</class>

L1Trigger/Phase2L1ParticleFlow/interface/TauNNId.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TauNNId {
1515

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

2021
private:

L1Trigger/Phase2L1ParticleFlow/interface/taus/TauNNIdHW.h

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class TauNNIdHW {
147147

148148
void initialize(const std::string &iName, int iNParticles);
149149
void SetNNVectorVar();
150+
input_t *NNVectorVar() { return NNvectorVar_.data(); }
150151
result_t EvaluateNN();
151152
result_t compute(const l1t::PFCandidate &iSeed, std::vector<l1t::PFCandidate> &iParts);
152153
//void print();
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
//Numpy array shape [25]
2-
//Min -1.101188778877
3-
//Max 1.014160394669
4-
//Number of zeros 2
2+
//Min -0.734825849533
3+
//Max 1.288661003113
4+
//Number of zeros 0
55

66
#ifndef B1_H_
77
#define B1_H_
88

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

1514
#endif
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
//Numpy array shape [10]
2-
//Min -0.819882214069
3-
//Max 0.973487198353
2+
//Min -0.380347400904
3+
//Max 0.551839828491
44
//Number of zeros 0
55

66
#ifndef B2_H_
77
#define B2_H_
88

9-
weight_default_t b2[10] = {-0.8198822141,
10-
0.7516837120,
11-
0.6504452229,
12-
-0.0292063691,
13-
-0.0308178961,
14-
0.9734871984,
15-
0.1587447226,
16-
-0.3352679014,
17-
-0.0403082110,
18-
0.9563522935};
9+
weight_default_t b2[10] = {0.55183983,
10+
0.36323273,
11+
-0.13108490,
12+
-0.38034740,
13+
0.08559006,
14+
0.01700789,
15+
0.13562575,
16+
-0.32752651,
17+
0.48282012,
18+
-0.15096320};
1919

2020
#endif
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
//Numpy array shape [10]
2-
//Min -0.128828719258
3-
//Max 1.138555169106
2+
//Min -0.936354994774
3+
//Max 0.407682240009
44
//Number of zeros 0
55

66
#ifndef B3_H_
77
#define B3_H_
88

9-
weight_default_t b3[10] = {1.0009469986,
10-
-0.0118703200,
11-
0.5378767252,
12-
0.6056469083,
13-
-0.0177963823,
14-
0.3281430006,
15-
-0.0163392760,
16-
1.1385551691,
17-
-0.1288287193,
18-
0.5457931757};
9+
weight_default_t b3[10] = {-0.58549309,
10+
-0.06117089,
11+
-0.24173595,
12+
0.17925857,
13+
-0.93635499,
14+
0.18813914,
15+
0.13134949,
16+
0.04132507,
17+
0.40768224,
18+
0.29987794};
1919

2020
#endif
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//Numpy array shape [1]
2-
//Min -0.572278082371
3-
//Max -0.572278082371
2+
//Min 0.023343238980
3+
//Max 0.023343238980
44
//Number of zeros 0
55

66
#ifndef B4_H_
77
#define B4_H_
88

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

1111
#endif

0 commit comments

Comments
 (0)