2 #include <TLorentzVector.h> 28 static std::unique_ptr<tensorflow::SessionCache> initializeGlobalCache(
const edm::ParameterSet&);
41 std::unique_ptr<l1t::PFTauCollection>& iTaus);
45 std::unique_ptr<PFTauCollection>& outputTaus);
61 : fSeedPt_(
cfg.getParameter<double>(
"seedpt")),
62 fConeSize_(
cfg.getParameter<double>(
"conesize")),
63 fTauSize_(
cfg.getParameter<double>(
"tausize")),
64 fMaxTaus_(
cfg.getParameter<
int>(
"maxtaus")),
65 fNParticles_(
cfg.getParameter<
int>(
"nparticles")),
66 fHW(
cfg.getParameter<
bool>(
"HW")),
67 fEMSeed(
cfg.getParameter<
bool>(
"emseed")),
68 fDebug(
cfg.getParameter<
bool>(
"debug")),
75 fTauNNId_ = std::make_unique<TauNNId>(lNNFile.find(
"v0") == std::string::npos ?
"input_1:0" :
"dense_1_input:0",
80 produces<l1t::PFTauCollection>(
"L1PFTausNN");
85 return std::make_unique<tensorflow::SessionCache>(
graphPath);
91 auto lTaus = std::make_unique<l1t::PFTauCollection>();
103 std::unique_ptr<l1t::PFTauCollection>& iTaus) {
105 std::vector<unique_ptr<l1t::PFCandidate>> pfChargedHadrons_sort_v;
106 std::vector<unique_ptr<l1t::PFCandidate>> pfChargedHadrons_seeds_v;
107 for (
const auto& l1PFCand :
parts)
110 pfChargedHadrons_sort_v.push_back(std::make_unique<l1t::PFCandidate>(l1PFCand));
112 if (pfChargedHadrons_sort_v.empty())
115 pfChargedHadrons_sort_v.begin(),
116 pfChargedHadrons_sort_v.end(),
117 [](std::unique_ptr<l1t::PFCandidate>&
i, std::unique_ptr<l1t::PFCandidate>&
j) {
return (
i->pt() >
j->pt()); });
119 pfChargedHadrons_seeds_v.push_back(
std::move(pfChargedHadrons_sort_v[0]));
120 for (
unsigned int i0 = 1; i0 < pfChargedHadrons_sort_v.size(); i0++) {
122 for (
unsigned int i1 = 0;
i1 < pfChargedHadrons_seeds_v.size();
i1++) {
128 pfChargedHadrons_seeds_v.push_back(
std::move(pfChargedHadrons_sort_v[i0]));
129 if (
int(pfChargedHadrons_seeds_v.size()) >
fMaxTaus_ - 1)
132 for (
unsigned int i0 = 0; i0 < pfChargedHadrons_seeds_v.size(); i0++) {
133 addTau(*(pfChargedHadrons_seeds_v[i0]),
parts, iTaus);
140 std::unique_ptr<l1t::PFTauCollection>& outputTaus) {
147 for (
const auto& l1PFCand : iParts) {
159 dxy = l1PFCand.dxy();
162 pfTauCands.push_back(l1PFCand);
169 float* lNNVector =
fTauNNId_->NNVectorVar();
174 outputTaus->push_back(l1PFTau);
179 desc.add<
std::string>(
"NNFileName",
"L1Trigger/Phase2L1ParticleFlow/data/tau_3layer.pb");
180 desc.add<
double>(
"tausize", 0.1);
181 desc.add<
int>(
"maxtaus", 5);
182 desc.add<
int>(
"nparticles", 10);
183 desc.add<
double>(
"conesize", 0.4);
184 desc.add<
double>(
"seedpt", 20);
185 desc.add<
bool>(
"HW",
true);
186 desc.add<
bool>(
"emseed",
true);
187 desc.add<
bool>(
"debug",
false);
189 descriptions.
add(
"L1NNTauProducer",
desc);
194 std::unique_ptr<l1t::PFTauCollection>& iTaus) {
212 for (
unsigned i0 = 0; i0 <
parts.size(); i0++) {
221 input2_t d1r2 = d1eta * d1eta + d1phi * d1phi;
224 p1z_tot = p1z_tot + tmppt * (1 - d1r2 * half);
225 p1y_tot = p1y_tot + tmppt * d1phi;
226 p1x_tot = p1x_tot + tmppt * d1eta;
227 p1_tot = p1_tot + tmppt;
238 input2_t tmpmass1 = (p1_tot * p1_tot - p1x_tot * p1x_tot - p1y_tot * p1y_tot - p1z_tot * p1z_tot);
252 for (
unsigned i0 = 0; i0 < 80; i0++)
253 pNNVec[i0] =
float(lNNVector[i0]);
280 l1PFTau.
setZ0(
float(
z0) * 0.05);
285 iTaus->push_back(l1PFTau);
289 std::unique_ptr<l1t::PFTauCollection>& iTaus) {
292 std::vector<l1t::PFCandidate>
work;
299 std::vector<l1t::PFCandidate>
seeds;
305 part.id() == lSeed) &&
318 std::vector<l1t::PFCandidate> particlesInCone;
324 work.erase(std::remove_if(
void set_encodedTau(l1gt::PackedTau encodedTau)
glbeta_t makeGlbEta(float eta)
float floatPhi(phi_t phi)
float floatEta(eta_t eta)
static constexpr float track_trigger_eta_max
L1NNTauProducer(const edm::ParameterSet &, const tensorflow::SessionCache *)
static constexpr float etaphi_base
std::unique_ptr< TauNNIdHW > fTauNNIdHW_
std::vector< l1t::PFCandidate > PFCandidateCollection
ap_fixed< 24, 12 > input2_t
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
glbphi_t makeGlbPhi(float phi)
ap_fixed< 12, 6 > detaphi_t
void makeTau_HW(const l1t::PFCandidate &seed, l1t::PFCandidateCollection &parts, std::unique_ptr< l1t::PFTauCollection > &iTaus)
edm::EDGetTokenT< vector< l1t::PFCandidate > > fL1PFToken_
std::array< uint64_t, 2 > PackedTau
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
void addTau(const l1t::PFCandidate &iCand, const l1t::PFCandidateCollection &iParts, std::unique_ptr< PFTauCollection > &outputTaus)
std::unique_ptr< TauNNId > fTauNNId_
constexpr Matriplex::idx_t NN
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
~L1NNTauProducer() override
ap_fixed< 16, 10 > input_t
ap_ufixed< 14, 12, AP_TRN, AP_SAT > pt_t
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static std::unique_ptr< tensorflow::SessionCache > initializeGlobalCache(const edm::ParameterSet &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void process_HW(const l1t::PFCandidateCollection &parts, std::unique_ptr< l1t::PFTauCollection > &iTaus)
ap_ufixed< 14, 12, AP_TRN, AP_SAT > pt_t
const std::string & fullPath() const
bool inCone(l1t::PFCandidate seed, l1t::PFCandidate part, detaphi_t cone2)
static void globalEndJob(const tensorflow::SessionCache *)
result_t nn_pt_correction
void process_SW(const l1t::PFCandidateCollection &parts, std::unique_ptr< l1t::PFTauCollection > &iTaus)
constexpr float etaphi_base