CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | 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 final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const 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
 
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)
 
 ~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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > 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
 
bool registeredToConsumeMany (TypeID const &, 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::ESRecordsToProxyIndices 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_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
 

Private Member Functions

void CalcMetHLS (const std::vector< float > &pt, const std::vector< float > &phi, reco::Candidate::PolarLorentzVector &metVector) 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 int dropBits_ = 2
 
const int dropFactor_ = (1 << dropBits_)
 
const phi_t hwPi_ = round(M_PI / phiLSB_)
 
const phi_t hwPiOverTwo_ = round(M_PI / (2 * phiLSB_))
 
const int invTableBits_ = 10
 
const int invTableSize_ = (1 << invTableBits_)
 
int maxCands_ = 128
 
const float maxPt_ = ((1 << pt_t::width) - 1) * ptLSB_
 
const float phiLSB_ = M_PI / 720
 
const float ptLSB_ = 0.25
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
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
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< B > consumes (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 ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
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 () noexcept
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
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 17 of file L1METPFProducer.cc.

Member Typedef Documentation

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

Definition at line 44 of file L1METPFProducer.cc.

typedef ap_int<12> L1METPFProducer::phi_t
private

Definition at line 32 of file L1METPFProducer.cc.

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

Definition at line 38 of file L1METPFProducer.cc.

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

Definition at line 31 of file L1METPFProducer.cc.

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

Definition at line 37 of file L1METPFProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 60 of file L1METPFProducer.cc.

61  : _l1PFToken(consumes<std::vector<l1t::PFCandidate>>(cfg.getParameter<edm::InputTag>("L1PFObjects"))),
62  maxCands_(cfg.getParameter<int>("maxCands")) {
63  produces<std::vector<l1t::EtSum>>();
64 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< vector< l1t::PFCandidate > > _l1PFToken
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1METPFProducer::~L1METPFProducer ( )
override

Definition at line 236 of file L1METPFProducer.cc.

236 {}

Member Function Documentation

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

Definition at line 90 of file L1METPFProducer.cc.

References mps_fire::i, maxPt_, min(), PhiFromXY(), phiLSB_, Project(), mathSSE::sqrt(), and parallelization::uint().

Referenced by produce().

92  {
93  pxy_t hw_px = 0;
94  pxy_t hw_py = 0;
95  pxy_t hw_sumx = 0;
96  pxy_t hw_sumy = 0;
97 
98  for (uint i = 0; i < pt.size(); i++) {
99  pt_t hw_pt = min(pt[i], maxPt_);
100  phi_t hw_phi = float(TVector2::Phi_mpi_pi(phi[i]) / phiLSB_);
101 
102  Project(hw_pt, hw_phi, hw_px, true);
103  Project(hw_pt, hw_phi, hw_py, false);
104 
105  hw_sumx = hw_sumx - hw_px;
106  hw_sumy = hw_sumy - hw_py;
107  }
108 
109  pt2_t hw_met = pt2_t(hw_sumx) * pt2_t(hw_sumx) + pt2_t(hw_sumy) * pt2_t(hw_sumy);
110  hw_met = sqrt(int(hw_met)); // stand-in for HLS::sqrt
111 
112  phi_t hw_met_phi = 0;
113  PhiFromXY(hw_sumx, hw_sumy, hw_met_phi);
114 
115  metVector.SetPt(hw_met.to_double());
116  metVector.SetPhi(hw_met_phi.to_double() * phiLSB_);
117  metVector.SetEta(0);
118 }
T sqrt(T t)
Definition: SSEVec.h:19
const float maxPt_
ap_fixed< 2 *pt_t::width, 2 *pt_t::iwidth, AP_RND, AP_SAT > pt2_t
T min(T a, T b)
Definition: MathUtil.h:58
void PhiFromXY(pxy_t px, pxy_t py, phi_t &phi, bool debug=false) const
void Project(pt_t pt, phi_t phi, pxy_t &pxy, bool isX, bool debug=false) const
ap_int< 16 > pt_t
Definition: data.h:6
ap_fixed< pt_t::width+1, pt_t::iwidth+1, AP_RND, AP_SAT > pxy_t
ap_int< 12 > phi_t
const float phiLSB_
void L1METPFProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 229 of file L1METPFProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), submitPVResolutionJobs::desc, and HLT_FULL_cff::InputTag.

229  {
231  desc.add<int>("maxCandidates", 128);
232  desc.add<edm::InputTag>("L1PFObjects", edm::InputTag("L1PFProducer", "l1pfCandidates"));
233  descriptions.add("L1METPFProducer", desc);
234 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void L1METPFProducer::PhiFromXY ( pxy_t  px,
pxy_t  py,
phi_t phi,
bool  debug = false 
) const
private

Definition at line 157 of file L1METPFProducer.cc.

References a, b, dropFactor_, hwPi_, hwPiOverTwo_, invTableSize_, LogDebug, M_PI, maxPt_, phi, phiLSB_, x, and y.

Referenced by CalcMetHLS().

157  {
158  if (px == 0 && py == 0) {
159  phi = 0;
160  return;
161  }
162  if (px == 0) {
163  phi = py > 0 ? hwPiOverTwo_ : phi_t(-hwPiOverTwo_);
164  return;
165  }
166  if (py == 0) {
167  phi = px > 0 ? phi_t(0) : phi_t(-hwPi_);
168  return;
169  }
170 
171  // get q1 coordinates
172  pt_t x = px > 0 ? pt_t(px) : pt_t(-px); //px>=0 ? px : -px;
173  pt_t y = py > 0 ? pt_t(py) : pt_t(-py); //px>=0 ? px : -px;
174  // transform so a<b
175  pt_t a = x < y ? x : y;
176  pt_t b = x < y ? y : x;
177 
178  if (b.to_double() > maxPt_ / dropFactor_)
179  b = maxPt_ / dropFactor_;
180  // map [0,max/4) to inv table size
181  int index = round((b.to_double() / (maxPt_ / dropFactor_)) * invTableSize_);
182  float bcheck = (float(index) / invTableSize_) * (maxPt_ / dropFactor_);
183  inv_t inv_b = 1. / ((float(index) / invTableSize_) * (maxPt_ / dropFactor_));
184 
185  inv_t a_over_b = a * inv_b;
186 
187  if (debug) {
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"
191  << std::endl;
192  LogDebug("L1METPFProducer") << "bcheck, 1/bc = " << bcheck << ", " << 1. / bcheck << " -- " << invTableSize_ << " "
193  << maxPt_ << " " << dropFactor_ << " \n"
194  << std::endl;
195  }
196 
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_;
201 
202  if (debug) {
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"
206  << std::endl;
207  }
208 
209  // rotate from (0,pi/4) to full quad1
210  if (y > x)
211  phi = hwPiOverTwo_ - phi; //phi = pi/2 - phi
212  // other quadrants
213  if (px < 0 && py > 0)
214  phi = hwPi_ - phi; // Q2 phi = pi - phi
215  if (px > 0 && py < 0)
216  phi = -phi; // Q4 phi = -phi
217  if (px < 0 && py < 0)
218  phi = -(hwPi_ - phi); // Q3 composition of both
219 
220  if (debug) {
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"
225  << std::endl;
226  }
227 }
const phi_t hwPi_
const int dropFactor_
ap_ufixed< pt_t::width, 0 > inv_t
const float maxPt_
const phi_t hwPiOverTwo_
#define M_PI
#define debug
Definition: HDRShower.cc:19
ap_ufixed< 14, 12, AP_RND, AP_WRAP > pt_t
const int invTableSize_
double b
Definition: hdecay.h:118
ap_int< 16 > pt_t
Definition: data.h:6
double a
Definition: hdecay.h:119
ap_int< 12 > phi_t
const float phiLSB_
#define LogDebug(id)
void L1METPFProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 66 of file L1METPFProducer.cc.

References _l1PFToken, CalcMetHLS(), edm::Event::getByToken(), mps_fire::i, L1Analysis::kTotalHt, maxCands_, HLT_FULL_cff::metCollection, eostools::move(), phi, DiDispStaMuonMonitor_cfi::pt, and edm::Event::put().

66  {
68  iEvent.getByToken(_l1PFToken, l1PFCandidates);
69 
70  std::vector<float> pt;
71  std::vector<float> phi;
72 
73  for (int i = 0; i < int(l1PFCandidates->size()) && (i < maxCands_ || maxCands_ < 0); i++) {
74  const auto& l1PFCand = l1PFCandidates->at(i);
75  pt.push_back(l1PFCand.pt());
76  phi.push_back(l1PFCand.phi());
77  }
78 
80 
81  CalcMetHLS(pt, phi, metVector);
82 
83  l1t::EtSum theMET(metVector, l1t::EtSum::EtSumType::kTotalHt, 0, 0, 0, 0);
84 
85  std::unique_ptr<std::vector<l1t::EtSum>> metCollection(new std::vector<l1t::EtSum>(0));
86  metCollection->push_back(theMET);
87  iEvent.put(std::move(metCollection));
88 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
def move
Definition: eostools.py:511
edm::EDGetTokenT< vector< l1t::PFCandidate > > _l1PFToken
void CalcMetHLS(const std::vector< float > &pt, const std::vector< float > &phi, reco::Candidate::PolarLorentzVector &metVector) const
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38
void L1METPFProducer::Project ( pt_t  pt,
phi_t  phi,
pxy_t pxy,
bool  isX,
bool  debug = false 
) const
private

Definition at line 120 of file L1METPFProducer.cc.

References funct::cos(), Phase1L1TJetProducer_cfi::cosPhi, hwPi_, hwPiOverTwo_, M_PI, objects.METAnalyzer::pxy, funct::sin(), and Phase1L1TJetProducer_cfi::sinPhi.

Referenced by CalcMetHLS().

120  {
121  /*
122  Convert pt and phi to px (py)
123  1) Map phi to the first quadrant to reduce LUT size
124  2) Lookup sin(phiQ1), where the result is in [0,maxPt]
125  which is used to encode [0,1].
126  3) Multiply pt by sin(phiQ1) to get px. Result will be px*maxPt, but
127  wrapping multiplication is 'mod maxPt' so the correct value is returned.
128  4) Check px=-|px|.
129  */
130 
131  // set phi to first quadrant
132  phi_t phiQ1 = (phi > 0) ? phi : phi_t(-phi); // Q1/Q4
133  if (phiQ1 >= hwPiOverTwo_)
134  phiQ1 = hwPi_ - phiQ1;
135 
136  if (phiQ1 > hwPiOverTwo_) {
137  edm::LogWarning("L1METPFProducer") << "unexpected phi (high)";
138  phiQ1 = hwPiOverTwo_;
139  } else if (phiQ1 < 0) {
140  edm::LogWarning("L1METPFProducer") << "unexpected phi (low)";
141  phiQ1 = 0;
142  }
143  if (isX) {
144  typedef ap_ufixed<14, 12, AP_RND, AP_WRAP> pt_t; // LSB is 0.25 and max is 4 TeV
145  ap_ufixed<pt_t::width, 0> cosPhi = cos(phiQ1.to_double() / hwPiOverTwo_.to_double() * M_PI / 2);
146  pxy = pt * cosPhi;
147  if (phi > hwPiOverTwo_ || phi < -hwPiOverTwo_)
148  pxy = -pxy;
149  } else {
150  ap_ufixed<pt_t::width, 0> sinPhi = sin(phiQ1.to_double() / hwPiOverTwo_.to_double() * M_PI / 2);
151  pxy = pt * sinPhi;
152  if (phi < 0)
153  pxy = -pxy;
154  }
155 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const phi_t hwPi_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const phi_t hwPiOverTwo_
#define M_PI
ap_ufixed< 14, 12, AP_RND, AP_WRAP > pt_t
ap_int< 12 > phi_t
Log< level::Warning, false > LogWarning

Member Data Documentation

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

Definition at line 26 of file L1METPFProducer.cc.

Referenced by produce().

const int L1METPFProducer::dropBits_ = 2
private

Definition at line 47 of file L1METPFProducer.cc.

const int L1METPFProducer::dropFactor_ = (1 << dropBits_)
private

Definition at line 48 of file L1METPFProducer.cc.

Referenced by PhiFromXY().

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

Definition at line 41 of file L1METPFProducer.cc.

Referenced by PhiFromXY(), and Project().

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

Definition at line 42 of file L1METPFProducer.cc.

Referenced by PhiFromXY(), and Project().

const int L1METPFProducer::invTableBits_ = 10
private

Definition at line 49 of file L1METPFProducer.cc.

const int L1METPFProducer::invTableSize_ = (1 << invTableBits_)
private

Definition at line 50 of file L1METPFProducer.cc.

Referenced by PhiFromXY().

int L1METPFProducer::maxCands_ = 128
private

Definition at line 28 of file L1METPFProducer.cc.

Referenced by produce().

const float L1METPFProducer::maxPt_ = ((1 << pt_t::width) - 1) * ptLSB_
private

Definition at line 40 of file L1METPFProducer.cc.

Referenced by CalcMetHLS(), and PhiFromXY().

const float L1METPFProducer::phiLSB_ = M_PI / 720
private

Definition at line 34 of file L1METPFProducer.cc.

Referenced by CalcMetHLS(), and PhiFromXY().

const float L1METPFProducer::ptLSB_ = 0.25
private

Definition at line 33 of file L1METPFProducer.cc.