CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
L1MetPfProducer Class Reference
Inheritance diagram for L1MetPfProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 L1MetPfProducer (const edm::ParameterSet &)
 
 ~L1MetPfProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Types

typedef ap_fixed< 32, 16 > input_t
 
typedef ap_ufixed< pt_t::width, 0 > inv_t
 
typedef ap_int< 12 > phi_t
 
typedef ap_fixed< 2 *pt_t::width, 2 *pt_t::iwidth, AP_RND, AP_SAT > pt2_t
 
typedef ap_ufixed< 14, 12, AP_RND, AP_WRAP > pt_t
 
typedef ap_fixed< pt_t::width+1, pt_t::iwidth+1, AP_RND, AP_SAT > pxy_t
 
typedef ap_fixed< 32, 16 > result_t
 

Private Member Functions

void CalcMetHLS (const std::vector< float > &pt, const std::vector< float > &phi, reco::Candidate::PolarLorentzVector &metVector) const
 
void CalcMlMet (const std::vector< float > &pt, const std::vector< float > &eta, const std::vector< float > &phi, const std::vector< float > &puppiWeight, const std::vector< int > &pdgId, const std::vector< int > &charge, reco::Candidate::PolarLorentzVector &metVector) const
 
int EncodePdgId (int pdgId) const
 
void PhiFromXY (pxy_t px, pxy_t py, phi_t &phi, bool debug=false) const
 
void produce (edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 
void Project (pt_t pt, phi_t phi, pxy_t &pxy, bool isX, bool debug=false) const
 

Private Attributes

edm::EDGetTokenT< vector< l1t::PFCandidate > > _l1PFToken
 
const phi_t hwPi_ = round(M_PI / phiLSB_)
 
const phi_t hwPiOverTwo_ = round(M_PI / (2 * phiLSB_))
 
int maxCands_ = 128
 
std::shared_ptr< hls4mlEmulator::Model > model
 
std::string modelVersion_
 
bool useMlModel_
 

Static Private Attributes

static constexpr int dropBits_ = 2
 
static constexpr int dropFactor_ = (1 << dropBits_)
 
static constexpr int invTableBits_ = 10
 
static constexpr int invTableSize_ = (1 << invTableBits_)
 
static constexpr float maxPt_ = ((1 << pt_t::width) - 1) * ptLSB_
 
static constexpr int numCatInputs_ = 2
 
static constexpr int numContInputs_ = 4
 
static constexpr int numInputs_ = numContInputs_ + numPxPyInputs_ + numCatInputs_
 
static constexpr int numPxPyInputs_ = 2
 
static constexpr float phiLSB_ = M_PI / 720
 
static constexpr float ptLSB_ = 0.25
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 21 of file L1MetPfProducer.cc.

Member Typedef Documentation

◆ input_t

typedef ap_fixed<32, 16> L1MetPfProducer::input_t
private

Definition at line 59 of file L1MetPfProducer.cc.

◆ inv_t

typedef ap_ufixed<pt_t::width, 0> L1MetPfProducer::inv_t
private

Definition at line 47 of file L1MetPfProducer.cc.

◆ phi_t

typedef ap_int<12> L1MetPfProducer::phi_t
private

Definition at line 35 of file L1MetPfProducer.cc.

◆ pt2_t

typedef ap_fixed<2 * pt_t::width, 2 * pt_t::iwidth, AP_RND, AP_SAT> L1MetPfProducer::pt2_t
private

Definition at line 41 of file L1MetPfProducer.cc.

◆ pt_t

typedef ap_ufixed<14, 12, AP_RND, AP_WRAP> L1MetPfProducer::pt_t
private

Definition at line 34 of file L1MetPfProducer.cc.

◆ pxy_t

typedef ap_fixed<pt_t::width + 1, pt_t::iwidth + 1, AP_RND, AP_SAT> L1MetPfProducer::pxy_t
private

Definition at line 40 of file L1MetPfProducer.cc.

◆ result_t

typedef ap_fixed<32, 16> L1MetPfProducer::result_t
private

Definition at line 60 of file L1MetPfProducer.cc.

Constructor & Destructor Documentation

◆ L1MetPfProducer()

L1MetPfProducer::L1MetPfProducer ( const edm::ParameterSet cfg)
explicit

Definition at line 83 of file L1MetPfProducer.cc.

References web.browse_db::loader, model, modelVersion_, and useMlModel_.

84  : _l1PFToken(consumes<std::vector<l1t::PFCandidate>>(cfg.getParameter<edm::InputTag>("L1PFObjects"))),
85  maxCands_(cfg.getParameter<int>("maxCands")),
86  modelVersion_(cfg.getParameter<std::string>("modelVersion")) {
87  produces<std::vector<l1t::EtSum>>();
88  useMlModel_ = (modelVersion_.length() > 0);
89  if (useMlModel_) {
90  hls4mlEmulator::ModelLoader loader(modelVersion_);
91  model = loader.load_model();
92  }
93 }
std::shared_ptr< hls4mlEmulator::Model > model
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::string modelVersion_
edm::EDGetTokenT< vector< l1t::PFCandidate > > _l1PFToken

◆ ~L1MetPfProducer()

L1MetPfProducer::~L1MetPfProducer ( )
override

Definition at line 340 of file L1MetPfProducer.cc.

340 {}

Member Function Documentation

◆ CalcMetHLS()

void L1MetPfProducer::CalcMetHLS ( const std::vector< float > &  pt,
const std::vector< float > &  phi,
reco::Candidate::PolarLorentzVector metVector 
) const
private

Definition at line 199 of file L1MetPfProducer.cc.

References nano_mu_digi_cff::float, mps_fire::i, maxPt_, SiStripPI::min, phi, PhiFromXY(), phiLSB_, Project(), DiDispStaMuonMonitor_cfi::pt, mathSSE::sqrt(), and parallelization::uint.

Referenced by produce().

201  {
202  pxy_t hw_px = 0;
203  pxy_t hw_py = 0;
204  pxy_t hw_sumx = 0;
205  pxy_t hw_sumy = 0;
206 
207  for (uint i = 0; i < pt.size(); i++) {
208  pt_t hw_pt = min(pt[i], maxPt_);
209  phi_t hw_phi = float(TVector2::Phi_mpi_pi(phi[i]) / phiLSB_);
210 
211  Project(hw_pt, hw_phi, hw_px, true);
212  Project(hw_pt, hw_phi, hw_py, false);
213 
214  hw_sumx = hw_sumx - hw_px;
215  hw_sumy = hw_sumy - hw_py;
216  }
217 
218  pt2_t hw_met = pt2_t(hw_sumx) * pt2_t(hw_sumx) + pt2_t(hw_sumy) * pt2_t(hw_sumy);
219  hw_met = sqrt(int(hw_met)); // stand-in for HLS::sqrt
220 
221  phi_t hw_met_phi = 0;
222  PhiFromXY(hw_sumx, hw_sumy, hw_met_phi);
223 
224  metVector.SetPt(hw_met.to_double());
225  metVector.SetPhi(hw_met_phi.to_double() * phiLSB_);
226  metVector.SetEta(0);
227 }
static constexpr float phiLSB_
static constexpr float maxPt_
void Project(pt_t pt, phi_t phi, pxy_t &pxy, bool isX, bool debug=false) const
ap_fixed< 2 *pt_t::width, 2 *pt_t::iwidth, AP_RND, AP_SAT > pt2_t
void PhiFromXY(pxy_t px, pxy_t py, phi_t &phi, bool debug=false) const
T sqrt(T t)
Definition: SSEVec.h:23
ap_int< 12 > phi_t
ap_ufixed< 16, 14 > pt_t
Definition: TauNNIdHW.h:13
ap_fixed< pt_t::width+1, pt_t::iwidth+1, AP_RND, AP_SAT > pxy_t

◆ CalcMlMet()

void L1MetPfProducer::CalcMlMet ( const std::vector< float > &  pt,
const std::vector< float > &  eta,
const std::vector< float > &  phi,
const std::vector< float > &  puppiWeight,
const std::vector< int > &  pdgId,
const std::vector< int > &  charge,
reco::Candidate::PolarLorentzVector metVector 
) const
private

Definition at line 156 of file L1MetPfProducer.cc.

References funct::abs(), ALCARECOTkAlJpsiMuMu_cff::charge, funct::cos(), EncodePdgId(), PVValHelper::eta, Matriplex::hypot(), mps_fire::i, input, maxCands_, model, numContInputs_, numInputs_, numPxPyInputs_, EgammaValidation_cff::pdgId, phi, DiDispStaMuonMonitor_cfi::pt, mps_fire::result, funct::sin(), and parallelization::uint.

Referenced by produce().

162  {
163  const int inputSize = maxCands_ * numInputs_;
164 
165  input_t input[800];
166  result_t result[2];
167 
168  // initialize with zeros (for padding)
169  for (int i = 0; i < inputSize; i++) {
170  input[i] = 0;
171  }
172 
173  for (uint i = 0; i < pt.size(); i++) {
174  // input_cont
175  input[i * numContInputs_] = pt[i];
176  input[i * numContInputs_ + 1] = eta[i];
177  input[i * numContInputs_ + 2] = phi[i];
178  input[i * numContInputs_ + 3] = puppiWeight[i];
179  // input_pxpy
181  input[(maxCands_ * numContInputs_) + (i * numPxPyInputs_) + 1] = pt[i] * sin(phi[i]);
182  // input_cat0
184  // input_cat1
185  input[maxCands_ * (numContInputs_ + numPxPyInputs_ + 1) + i] = (abs(charge[i]) <= 1) ? (charge[i] + 2) : 0;
186  }
187 
188  model->prepare_input(input);
189  model->predict();
190  model->read_result(result);
191 
192  double met_px = -result[0].to_double();
193  double met_py = -result[1].to_double();
194  metVector.SetPt(hypot(met_px, met_py));
195  metVector.SetPhi(atan2(met_py, met_px));
196  metVector.SetEta(0);
197 }
std::shared_ptr< hls4mlEmulator::Model > model
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
Definition: Matriplex.h:436
static constexpr int numPxPyInputs_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
static std::string const input
Definition: EdmProvDump.cc:50
ap_fixed< 16, 6 > result_t
Definition: defines.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int EncodePdgId(int pdgId) const
static constexpr int numInputs_
ap_fixed< 16, 10 > input_t
Definition: defines.h:27
static constexpr int numContInputs_

◆ EncodePdgId()

int L1MetPfProducer::EncodePdgId ( int  pdgId) const
private

Definition at line 139 of file L1MetPfProducer.cc.

References funct::abs(), and EgammaValidation_cff::pdgId.

Referenced by CalcMlMet().

139  {
140  switch (abs(pdgId)) {
141  case 211: // charged hadron (pion)
142  return 1;
143  case 130: // neutral hadron (kaon)
144  return 2;
145  case 22: // photon
146  return 3;
147  case 13: // muon
148  return 4;
149  case 11: // electron
150  return 5;
151  default:
152  return 0;
153  }
154 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ fillDescriptions()

void L1MetPfProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 95 of file L1MetPfProducer.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, ProducerED_cfi::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

95  {
97  desc.add<edm::InputTag>("L1PFObjects", edm::InputTag("L1PFProducer", "l1pfCandidates"));
98  desc.add<int>("maxCands", 128);
99  desc.add<std::string>("modelVersion", "");
100  descriptions.add("L1MetPfProducer", desc);
101 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ PhiFromXY()

void L1MetPfProducer::PhiFromXY ( pxy_t  px,
pxy_t  py,
phi_t phi,
bool  debug = false 
) const
private

Definition at line 266 of file L1MetPfProducer.cc.

References a, b, debug, dropFactor_, nano_mu_digi_cff::float, hwPi_, hwPiOverTwo_, invTableSize_, M_PI, maxPt_, phi, phiLSB_, multPhiCorr_741_25nsDY_cfi::px, multPhiCorr_741_25nsDY_cfi::py, x, and y.

Referenced by CalcMetHLS().

266  {
267  if (px == 0 && py == 0) {
268  phi = 0;
269  return;
270  }
271  if (px == 0) {
272  phi = py > 0 ? hwPiOverTwo_ : phi_t(-hwPiOverTwo_);
273  return;
274  }
275  if (py == 0) {
276  phi = px > 0 ? phi_t(0) : phi_t(-hwPi_);
277  return;
278  }
279 
280  // get q1 coordinates
281  pt_t x = px > 0 ? pt_t(px) : pt_t(-px); //px>=0 ? px : -px;
282  pt_t y = py > 0 ? pt_t(py) : pt_t(-py); //px>=0 ? px : -px;
283  // transform so a<b
284  pt_t a = x < y ? x : y;
285  pt_t b = x < y ? y : x;
286 
287  if (b.to_double() > maxPt_ / dropFactor_)
288  b = maxPt_ / dropFactor_;
289  // map [0,max/4) to inv table size
290  int index = round((b.to_double() / (maxPt_ / dropFactor_)) * invTableSize_);
291  float bcheck = (float(index) / invTableSize_) * (maxPt_ / dropFactor_);
292  inv_t inv_b = 1. / ((float(index) / invTableSize_) * (maxPt_ / dropFactor_));
293 
294  inv_t a_over_b = a * inv_b;
295 
296  if (debug) {
297  printf(" a, b = %f, %f; index, inv = %d, %f; ratio = %f \n",
298  a.to_double(),
299  b.to_double(),
300  index,
301  inv_b.to_double(),
302  a_over_b.to_double());
303  printf(" bcheck, 1/bc = %f, %f -- %d %f %d \n", bcheck, 1. / bcheck, invTableSize_, maxPt_, dropFactor_);
304  }
305 
306  int atanTableBits_ = 7;
307  int atanTableSize_ = (1 << atanTableBits_);
308  index = round(a_over_b.to_double() * atanTableSize_);
309  phi = atan(float(index) / atanTableSize_) / phiLSB_;
310 
311  if (debug) {
312  printf(" atan index, phi = %d, %f (%f rad) real atan(a/b)= %f \n",
313  index,
314  phi.to_double(),
315  phi.to_double() * (M_PI / hwPi_.to_double()),
316  atan(a.to_double() / b.to_double()));
317  }
318 
319  // rotate from (0,pi/4) to full quad1
320  if (y > x)
321  phi = hwPiOverTwo_ - phi; //phi = pi/2 - phi
322  // other quadrants
323  if (px < 0 && py > 0)
324  phi = hwPi_ - phi; // Q2 phi = pi - phi
325  if (px > 0 && py < 0)
326  phi = -phi; // Q4 phi = -phi
327  if (px < 0 && py < 0)
328  phi = -(hwPi_ - phi); // Q3 composition of both
329 
330  if (debug) {
331  printf(" phi hw, float, real = %f, %f (%f rad from x,y = %f, %f) \n",
332  phi.to_double(),
333  phi.to_double() * (M_PI / hwPi_.to_double()),
334  atan2(py.to_double(), px.to_double()),
335  px.to_double(),
336  py.to_double());
337  }
338 }
static constexpr float phiLSB_
static constexpr float maxPt_
ap_ufixed< 14, 12, AP_RND, AP_WRAP > pt_t
static constexpr int dropFactor_
const phi_t hwPi_
const phi_t hwPiOverTwo_
static constexpr int invTableSize_
ap_int< 12 > phi_t
#define M_PI
ap_ufixed< pt_t::width, 0 > inv_t
#define debug
Definition: HDRShower.cc:19
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
ap_ufixed< 16, 14 > pt_t
Definition: TauNNIdHW.h:13

◆ produce()

void L1MetPfProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 103 of file L1MetPfProducer.cc.

References _l1PFToken, CalcMetHLS(), CalcMlMet(), ALCARECOTkAlJpsiMuMu_cff::charge, PVValHelper::eta, mps_fire::i, iEvent, createfilelist::int, L1Analysis::kTotalHt, maxCands_, susyDQM_cfi::metCollection, eostools::move(), EgammaValidation_cff::pdgId, phi, DiDispStaMuonMonitor_cfi::pt, and useMlModel_.

103  {
105  iEvent.getByToken(_l1PFToken, l1PFCandidates);
106 
107  std::vector<float> pt;
108  std::vector<float> eta;
109  std::vector<float> phi;
110  std::vector<float> puppiWeight;
111  std::vector<int> pdgId;
112  std::vector<int> charge;
113 
114  for (int i = 0; i < int(l1PFCandidates->size()) && (i < maxCands_ || maxCands_ < 0); i++) {
115  const auto& l1PFCand = l1PFCandidates->at(i);
116  pt.push_back(l1PFCand.pt());
117  eta.push_back(l1PFCand.eta());
118  phi.push_back(l1PFCand.phi());
119  puppiWeight.push_back(l1PFCand.puppiWeight());
120  pdgId.push_back(l1PFCand.pdgId());
121  charge.push_back(l1PFCand.charge());
122  }
123 
125 
126  if (useMlModel_) {
127  CalcMlMet(pt, eta, phi, puppiWeight, pdgId, charge, metVector);
128  } else {
129  CalcMetHLS(pt, phi, metVector);
130  }
131 
132  l1t::EtSum theMET(metVector, l1t::EtSum::EtSumType::kTotalHt, 0, 0, 0, 0);
133 
134  auto metCollection = std::make_unique<std::vector<l1t::EtSum>>(0);
135  metCollection->push_back(theMET);
137 }
void CalcMetHLS(const std::vector< float > &pt, const std::vector< float > &phi, reco::Candidate::PolarLorentzVector &metVector) const
int iEvent
Definition: GenABIO.cc:224
void CalcMlMet(const std::vector< float > &pt, const std::vector< float > &eta, const std::vector< float > &phi, const std::vector< float > &puppiWeight, const std::vector< int > &pdgId, const std::vector< int > &charge, reco::Candidate::PolarLorentzVector &metVector) const
edm::EDGetTokenT< vector< l1t::PFCandidate > > _l1PFToken
def move(src, dest)
Definition: eostools.py:511
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38

◆ Project()

void L1MetPfProducer::Project ( pt_t  pt,
phi_t  phi,
pxy_t pxy,
bool  isX,
bool  debug = false 
) const
private

Definition at line 229 of file L1MetPfProducer.cc.

References funct::cos(), l1tPhase1JetProducer_cfi::cosPhi, hwPi_, hwPiOverTwo_, M_PI, phi, DiDispStaMuonMonitor_cfi::pt, objects.METAnalyzer::pxy, funct::sin(), and l1tPhase1JetProducer_cfi::sinPhi.

Referenced by CalcMetHLS().

229  {
230  /*
231  Convert pt and phi to px (py)
232  1) Map phi to the first quadrant to reduce LUT size
233  2) Lookup sin(phiQ1), where the result is in [0,maxPt]
234  which is used to encode [0,1].
235  3) Multiply pt by sin(phiQ1) to get px. Result will be px*maxPt, but
236  wrapping multiplication is 'mod maxPt' so the correct value is returned.
237  4) Check px=-|px|.
238  */
239 
240  // set phi to first quadrant
241  phi_t phiQ1 = (phi > 0) ? phi : phi_t(-phi); // Q1/Q4
242  if (phiQ1 >= hwPiOverTwo_)
243  phiQ1 = hwPi_ - phiQ1;
244 
245  if (phiQ1 > hwPiOverTwo_) {
246  edm::LogWarning("L1MetPfProducer") << "unexpected phi (high)";
247  phiQ1 = hwPiOverTwo_;
248  } else if (phiQ1 < 0) {
249  edm::LogWarning("L1MetPfProducer") << "unexpected phi (low)";
250  phiQ1 = 0;
251  }
252  if (isX) {
253  typedef ap_ufixed<14, 12, AP_RND, AP_WRAP> pt_t; // LSB is 0.25 and max is 4 TeV
254  ap_ufixed<pt_t::width, 0> cosPhi = cos(phiQ1.to_double() / hwPiOverTwo_.to_double() * M_PI / 2);
255  pxy = pt * cosPhi;
256  if (phi > hwPiOverTwo_ || phi < -hwPiOverTwo_)
257  pxy = -pxy;
258  } else {
259  ap_ufixed<pt_t::width, 0> sinPhi = sin(phiQ1.to_double() / hwPiOverTwo_.to_double() * M_PI / 2);
260  pxy = pt * sinPhi;
261  if (phi < 0)
262  pxy = -pxy;
263  }
264 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ap_ufixed< 14, 12, AP_RND, AP_WRAP > pt_t
const phi_t hwPi_
const phi_t hwPiOverTwo_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
ap_int< 12 > phi_t
#define M_PI
Log< level::Warning, false > LogWarning

Member Data Documentation

◆ _l1PFToken

edm::EDGetTokenT<vector<l1t::PFCandidate> > L1MetPfProducer::_l1PFToken
private

Definition at line 29 of file L1MetPfProducer.cc.

Referenced by produce().

◆ dropBits_

constexpr int L1MetPfProducer::dropBits_ = 2
staticprivate

Definition at line 50 of file L1MetPfProducer.cc.

◆ dropFactor_

constexpr int L1MetPfProducer::dropFactor_ = (1 << dropBits_)
staticprivate

Definition at line 51 of file L1MetPfProducer.cc.

Referenced by PhiFromXY().

◆ hwPi_

const phi_t L1MetPfProducer::hwPi_ = round(M_PI / phiLSB_)
private

Definition at line 44 of file L1MetPfProducer.cc.

Referenced by PhiFromXY(), and Project().

◆ hwPiOverTwo_

const phi_t L1MetPfProducer::hwPiOverTwo_ = round(M_PI / (2 * phiLSB_))
private

Definition at line 45 of file L1MetPfProducer.cc.

Referenced by PhiFromXY(), and Project().

◆ invTableBits_

constexpr int L1MetPfProducer::invTableBits_ = 10
staticprivate

Definition at line 52 of file L1MetPfProducer.cc.

◆ invTableSize_

constexpr int L1MetPfProducer::invTableSize_ = (1 << invTableBits_)
staticprivate

Definition at line 53 of file L1MetPfProducer.cc.

Referenced by PhiFromXY().

◆ maxCands_

int L1MetPfProducer::maxCands_ = 128
private

Definition at line 31 of file L1MetPfProducer.cc.

Referenced by CalcMlMet(), and produce().

◆ maxPt_

constexpr float L1MetPfProducer::maxPt_ = ((1 << pt_t::width) - 1) * ptLSB_
staticprivate

Definition at line 43 of file L1MetPfProducer.cc.

Referenced by CalcMetHLS(), and PhiFromXY().

◆ model

std::shared_ptr<hls4mlEmulator::Model> L1MetPfProducer::model
private

◆ modelVersion_

std::string L1MetPfProducer::modelVersion_
private

Definition at line 58 of file L1MetPfProducer.cc.

Referenced by L1MetPfProducer().

◆ numCatInputs_

constexpr int L1MetPfProducer::numCatInputs_ = 2
staticprivate

Definition at line 63 of file L1MetPfProducer.cc.

◆ numContInputs_

constexpr int L1MetPfProducer::numContInputs_ = 4
staticprivate

Definition at line 61 of file L1MetPfProducer.cc.

Referenced by CalcMlMet().

◆ numInputs_

constexpr int L1MetPfProducer::numInputs_ = numContInputs_ + numPxPyInputs_ + numCatInputs_
staticprivate

Definition at line 64 of file L1MetPfProducer.cc.

Referenced by CalcMlMet().

◆ numPxPyInputs_

constexpr int L1MetPfProducer::numPxPyInputs_ = 2
staticprivate

Definition at line 62 of file L1MetPfProducer.cc.

Referenced by CalcMlMet().

◆ phiLSB_

constexpr float L1MetPfProducer::phiLSB_ = M_PI / 720
staticprivate

Definition at line 37 of file L1MetPfProducer.cc.

Referenced by CalcMetHLS(), and PhiFromXY().

◆ ptLSB_

constexpr float L1MetPfProducer::ptLSB_ = 0.25
staticprivate

Definition at line 36 of file L1MetPfProducer.cc.

◆ useMlModel_

bool L1MetPfProducer::useMlModel_
private

Definition at line 56 of file L1MetPfProducer.cc.

Referenced by L1MetPfProducer(), and produce().