31 typedef ap_ufixed<14, 12, AP_RND, AP_WRAP>
pt_t;
33 const float ptLSB_ = 0.25;
34 const float phiLSB_ =
M_PI / 720;
37 typedef ap_fixed<pt_t::width + 1, pt_t::iwidth + 1, AP_RND, AP_SAT>
pxy_t;
38 typedef ap_fixed<2 * pt_t::width, 2 * pt_t::iwidth, AP_RND, AP_SAT>
pt2_t;
40 const float maxPt_ = ((1 << pt_t::width) - 1) * ptLSB_;
42 const phi_t hwPiOverTwo_ = round(
M_PI / (2 * phiLSB_));
44 typedef ap_ufixed<pt_t::width, 0>
inv_t;
47 const int dropBits_ = 2;
48 const int dropFactor_ = (1 << dropBits_);
49 const int invTableBits_ = 10;
50 const int invTableSize_ = (1 << invTableBits_);
55 void CalcMetHLS(
const std::vector<float>&
pt,
56 const std::vector<float>& phi,
62 maxCands_(cfg.getParameter<int>(
"maxCands")) {
63 produces<std::vector<l1t::EtSum>>();
70 std::vector<float>
pt;
71 std::vector<float>
phi;
74 const auto& l1PFCand = l1PFCandidates->at(
i);
75 pt.push_back(l1PFCand.pt());
76 phi.push_back(l1PFCand.phi());
85 std::unique_ptr<std::vector<l1t::EtSum>>
metCollection(
new std::vector<l1t::EtSum>(0));
86 metCollection->push_back(theMET);
91 const std::vector<float>&
phi,
98 for (
uint i = 0;
i < pt.size();
i++) {
100 phi_t hw_phi = float(TVector2::Phi_mpi_pi(phi[i]) /
phiLSB_);
102 Project(hw_pt, hw_phi, hw_px,
true);
103 Project(hw_pt, hw_phi, hw_py,
false);
105 hw_sumx = hw_sumx - hw_px;
106 hw_sumy = hw_sumy - hw_py;
110 hw_met =
sqrt(
int(hw_met));
112 phi_t hw_met_phi = 0;
115 metVector.SetPt(hw_met.to_double());
116 metVector.SetPhi(hw_met_phi.to_double() *
phiLSB_);
134 phiQ1 =
hwPi_ - phiQ1;
139 }
else if (phiQ1 < 0) {
144 typedef ap_ufixed<14, 12, AP_RND, AP_WRAP>
pt_t;
158 if (px == 0 && py == 0) {
175 pt_t
a = x < y ? x :
y;
176 pt_t
b = x < y ? y :
x;
185 inv_t a_over_b = a * inv_b;
188 LogDebug(
"L1METPFProducer") <<
" a, b = \n " << a.to_double() <<
" , " << b.to_double()
189 <<
"; index, inv = " << index <<
", " << inv_b.to_double()
190 <<
"; ratio= " << a_over_b.to_double() <<
" \n"
192 LogDebug(
"L1METPFProducer") <<
"bcheck, 1/bc = " << bcheck <<
", " << 1. / bcheck <<
" -- " <<
invTableSize_ <<
" "
197 const int atanTableBits_ = 7;
198 const int atanTableSize_ = (1 << atanTableBits_);
199 index = round(a_over_b.to_double() * atanTableSize_);
200 phi = atan(
float(index) / atanTableSize_) /
phiLSB_;
203 LogDebug(
"L1METPFProducer") <<
" atan index, phi = " << index <<
", " << phi.to_double() <<
" ("
204 << phi.to_double() * (
M_PI /
hwPi_.to_double())
205 <<
" rad) real atan(a/b)= " << atan(a.to_double() / b.to_double()) <<
" \n"
213 if (px < 0 && py > 0)
215 if (px > 0 && py < 0)
217 if (px < 0 && py < 0)
221 LogDebug(
"L1METPFProducer") <<
" phi hw, float, real = " << phi.to_double() <<
", "
222 << phi.to_double() * (
M_PI /
hwPi_.to_double()) <<
" ("
223 << atan2(py.to_double(), px.to_double()) <<
" rad from x,y = " << px.to_double() <<
", "
224 << py.to_double() <<
") \n"
231 desc.
add<
int>(
"maxCandidates", 128);
233 descriptions.
add(
"L1METPFProducer", desc);
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
~L1METPFProducer() override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
Sin< T >::type sin(const T &t)
ap_ufixed< pt_t::width, 0 > inv_t
Cos< T >::type cos(const T &t)
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
edm::EDGetTokenT< vector< l1t::PFCandidate > > _l1PFToken
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ap_ufixed< 14, 12, AP_RND, AP_WRAP > pt_t
void CalcMetHLS(const std::vector< float > &pt, const std::vector< float > &phi, reco::Candidate::PolarLorentzVector &metVector) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void Project(pt_t pt, phi_t phi, pxy_t &pxy, bool isX, bool debug=false) const
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
ap_fixed< pt_t::width+1, pt_t::iwidth+1, AP_RND, AP_SAT > pxy_t
Log< level::Warning, false > LogWarning
L1METPFProducer(const edm::ParameterSet &)
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.