Skip to content

Commit

Permalink
Add Tau GT Format
Browse files Browse the repository at this point in the history
Add Tau GT Format
  • Loading branch information
Duchstf authored Apr 15, 2023
2 parents 4ecee8d + ff55c39 commit 741f236
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
18 changes: 18 additions & 0 deletions DataFormats/L1TParticleFlow/interface/PFTau.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#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 {

Expand Down Expand Up @@ -72,12 +74,28 @@ namespace l1t {
}
bool passTightPF() const { return fullIso_ < PFTAU_PF_TIGHT_CUT; }

void set_encodedTau(std::array<uint64_t, 2> encodedTau){
encodedTau_ = encodedTau;
}
std::array<uint64_t, 2> encodedTau() const {return encodedTau_; }

//l1gt::Tau getHWTauGT() const { return l1ct::Tau::unpack_gt(encodedTau_); }

//Return the l1gt Tau object for now
void set_TauGT(l1gt::Tau TauGT){
TauGT_ = TauGT;
}

l1gt::Tau getTauGT() const { return TauGT_; }

private:
float NNValues_[80];
float iso_;
float fullIso_;
int id_;
float dxy_;
std::array<uint64_t, 2> encodedTau_;
l1gt::Tau TauGT_;
};

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

// tau fields
typedef ap_ufixed<10, 8> tauseed_pt_t;
typedef ap_uint<10> tau_rawid_t;

namespace Scales {
const int INTPHI_PI = 1 << (phi_t::width - 1);
Expand Down Expand Up @@ -185,12 +186,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 @@ -204,6 +205,15 @@ namespace l1gt {
pack_into_bits(ret, start, id1);
return ret;
}

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

}; // struct Tau

struct Electron {
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/L1TParticleFlow/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<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="5">
<version ClassVersion="5" checksum="3999627045"/>
<version ClassVersion="5" checksum="2339758668"/>
<version ClassVersion="4" checksum="2045755946"/>
<version ClassVersion="3" checksum="1410157160"/>
</class>
Expand Down
25 changes: 22 additions & 3 deletions L1Trigger/Phase2L1ParticleFlow/plugins/L1NNTauProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class L1NNTauProducer : public edm::stream::EDProducer<edm::GlobalCache<TauNNTFC
const l1t::PFCandidateCollection& iParts,
std::unique_ptr<PFTauCollection>& outputTaus);

void printParts(std::vector<l1t::PFCandidate>& parts);

void printTau(uint32_t& iPt, uint32_t& iEta, uint32_t& iPhi, uint32_t& iNN);
double fSeedPt_;
double fConeSize_;
double fTauSize_;
Expand Down Expand Up @@ -273,10 +270,32 @@ void L1NNTauProducer::makeTau_HW(const l1t::PFCandidate& seed,
L1TauEmu::etaphi_t phi = etaphi_t(seed.phi() * L1TauEmu::etaphi_base);
math::PtEtaPhiMLorentzVector tempP4(
float(pt), float(eta) / L1TauEmu::etaphi_base, float(phi) / L1TauEmu::etaphi_base, float(mass));

//Make
l1t::PFTau l1PFTau(tempP4, pNNVec, NN, 0, lId);
l1PFTau.setZ0(float(z0) * 0.05); //L1TauEmu::z0_base);
l1PFTau.setDxy(float(dxy) * 0.05); //L1TauEmu::dxy_base);

//Firmware Tau
l1ct::Tau l1ctTau;
l1ctTau.hwPt = l1ct::pt_t(pt); //l1gt is <16,11> and currently <16,14>
l1ctTau.hwEta = l1ct::eta_t(seed.eta()/l1ct::Scales::ETAPHI_LSB);
l1ctTau.hwPhi = l1ct::phi_t(seed.phi()/l1ct::Scales::ETAPHI_LSB);

l1ctTau.hwSeedPt = seed.pt();
l1ctTau.hwSeedZ0 = seed.hwZ0();
l1ctTau.hwCharge = seed.charge();

l1ctTau.hwType = l1ct::Tau::type_t(lId);
l1ctTau.hwRawId = ap_uint<10>(NN*1024); //NN Output is ap_fixed<16, 8> so need to cast.

//Convert to GT format and pack to encodedTau of PFTau
l1gt::Tau l1gtTau = l1ctTau.toGT();
std::array<uint64_t, 2> packed_Tau = l1gtTau.pack();

l1PFTau.set_TauGT(l1gtTau);
l1PFTau.set_encodedTau(packed_Tau);

iTaus->push_back(l1PFTau);
}

Expand Down

0 comments on commit 741f236

Please sign in to comment.