CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Phase1L1TJetSumsProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1CaloTrigger
4 // Class: Phase1L1TJetSumsProducer
5 //
23 //
24 // Original Simone Bologna
25 //
26 
40 
41 #include <cmath>
42 
43 class Phase1L1TJetSumsProducer : public edm::one::EDProducer<edm::one::SharedResources> {
44 public:
46  ~Phase1L1TJetSumsProducer() override;
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
51  void produce(edm::Event&, const edm::EventSetup&) override;
52 
53  // computes ht, adds jet pt to ht only if the pt of the jet is above the ht calculation threshold
54  l1t::EtSum computeHT(const edm::Handle<std::vector<reco::CaloJet> > inputJets) const;
55 
56  // computes MHT
57  // adds jet pt to mht only if the pt of the jet is above the mht calculation threshold
58  // performs some calculations with digitised/integer quantities to ensure agreement with firmware
59  l1t::EtSum computeMHT(const edm::Handle<std::vector<reco::CaloJet> > inputJets) const;
60 
62 
63  // holds the sin and cos for HLs LUT emulation
64  std::vector<double> sinPhi_;
65  std::vector<double> cosPhi_;
66  unsigned int nBinsPhi_;
67 
68  // lower phi value
69  double phiLow_;
70  // higher phi value
71  double phiUp_;
72  // size of a phi bin
73  double phiStep_;
74  // threshold for ht calculation
76  // threshold for ht calculation
78  // jet eta cut for ht calculation
79  double htAbsEtaCut_;
80  // jet eta cut for mht calculation
81  double mhtAbsEtaCut_;
82  // LSB of pt quantity
83  double ptlsb_;
84  // label of sums
86 };
87 
88 // initialises plugin configuration and prepares ROOT file for saving the sums
90  : inputJetCollectionTag_{consumes<std::vector<reco::CaloJet> >(
91  iConfig.getParameter<edm::InputTag>("inputJetCollectionTag"))},
92  sinPhi_(iConfig.getParameter<std::vector<double> >("sinPhi")),
93  cosPhi_(iConfig.getParameter<std::vector<double> >("cosPhi")),
94  nBinsPhi_(iConfig.getParameter<unsigned int>("nBinsPhi")),
95  phiLow_(iConfig.getParameter<double>("phiLow")),
96  phiUp_(iConfig.getParameter<double>("phiUp")),
97  htPtThreshold_(iConfig.getParameter<double>("htPtThreshold")),
98  mhtPtThreshold_(iConfig.getParameter<double>("mhtPtThreshold")),
99  htAbsEtaCut_(iConfig.getParameter<double>("htAbsEtaCut")),
100  mhtAbsEtaCut_(iConfig.getParameter<double>("mhtAbsEtaCut")),
101  ptlsb_(iConfig.getParameter<double>("ptlsb")),
102  outputCollectionName_(iConfig.getParameter<std::string>("outputCollectionName")) {
103  phiStep_ = (phiUp_ - phiLow_) / nBinsPhi_;
104  produces<std::vector<l1t::EtSum> >(outputCollectionName_).setBranchAlias(outputCollectionName_);
105 }
106 
108 
110  edm::Handle<std::vector<reco::CaloJet> > jetCollectionHandle;
111  iEvent.getByToken(inputJetCollectionTag_, jetCollectionHandle);
112 
113  // computing sums and storing them in sum object
114  l1t::EtSum lHT = computeHT(jetCollectionHandle);
115  l1t::EtSum lMHT = computeMHT(jetCollectionHandle);
116 
117  //packing sums in vector for event saving
118  std::unique_ptr<std::vector<l1t::EtSum> > lSumVectorPtr(new std::vector<l1t::EtSum>(0));
119  lSumVectorPtr->push_back(lHT);
120  lSumVectorPtr->push_back(lMHT);
121  iEvent.put(std::move(lSumVectorPtr), outputCollectionName_);
122 
123  return;
124 }
125 
126 l1t::EtSum Phase1L1TJetSumsProducer::computeHT(const edm::Handle<std::vector<reco::CaloJet> > inputJets) const {
127  double lHT = 0;
128  for (const auto& jet : *inputJets) {
129  double lJetPt = jet.pt();
130  double lJetPhi = jet.phi();
131  double lJetEta = jet.eta();
132  if ((lJetPhi < phiLow_) || (lJetPhi >= phiUp_))
133  continue;
134 
135  lHT += (lJetPt >= htPtThreshold_ && std::fabs(lJetEta) < htAbsEtaCut_) ? lJetPt : 0;
136  }
137 
139  lHTVector.SetPt(lHT);
140  lHTVector.SetEta(0);
141  lHTVector.SetPhi(0);
142  l1t::EtSum lHTSum(lHTVector, l1t::EtSum::EtSumType::kTotalHt, 0, 0, 0, 0);
143  return lHTSum;
144 }
145 
146 l1t::EtSum Phase1L1TJetSumsProducer::computeMHT(const edm::Handle<std::vector<reco::CaloJet> > inputJets) const {
147  int lTotalJetPx = 0;
148  int lTotalJetPy = 0;
149 
150  std::vector<unsigned int> jetPtInPhiBins(nBinsPhi_, 0);
151 
152  for (const auto& jet : *inputJets) {
153  double lJetPhi = jet.phi();
154 
155  if ((lJetPhi < phiLow_) || (lJetPhi >= phiUp_))
156  continue;
157 
158  unsigned int iPhi = (lJetPhi - phiLow_) / phiStep_;
159 
160  if (jet.pt() >= mhtPtThreshold_ && std::fabs(jet.eta()) < mhtAbsEtaCut_) {
161  unsigned int digiJetPt = floor(jet.pt() / ptlsb_);
162  jetPtInPhiBins[iPhi] += digiJetPt;
163  }
164  }
165 
166  for (unsigned int iPhi = 0; iPhi < jetPtInPhiBins.size(); ++iPhi) {
167  unsigned int digiJetPtSum = jetPtInPhiBins[iPhi];
168 
169  // retrieving sin cos from LUT emulator
170  double lSinPhi = sinPhi_[iPhi];
171  double lCosPhi = cosPhi_[iPhi];
172 
173  // checking if above threshold
174  lTotalJetPx += trunc(digiJetPtSum * lCosPhi);
175  lTotalJetPy += trunc(digiJetPtSum * lSinPhi);
176  }
177 
178  double lMHT = floor(sqrt(lTotalJetPx * lTotalJetPx + lTotalJetPy * lTotalJetPy)) * ptlsb_;
179  math::PtEtaPhiMLorentzVector lMHTVector(lMHT, 0, acos(lTotalJetPx / (lMHT / ptlsb_)), 0);
180  l1t::EtSum lMHTSum(lMHTVector, l1t::EtSum::EtSumType::kMissingHt, 0, 0, 0, 0);
181 
182  return lMHTSum;
183 }
184 
187  desc.add<edm::InputTag>("inputJetCollectionTag",
188  edm::InputTag("Phase1L1TJetCalibrator", "Phase1L1TJetFromPfCandidates"));
189  desc.add<std::vector<double> >("sinPhi");
190  desc.add<std::vector<double> >("cosPhi");
191  desc.add<unsigned int>("nBinsPhi", 72);
192  desc.add<double>("phiLow", -M_PI);
193  desc.add<double>("phiUp", M_PI);
194  desc.add<double>("htPtThreshold", 30);
195  desc.add<double>("mhtPtThreshold", 30);
196  desc.add<double>("htAbsEtaCut", 3);
197  desc.add<double>("mhtAbsEtaCut", 3);
198  desc.add<double>("ptlsb", 0.25), desc.add<string>("outputCollectionName", "Sums");
199  descriptions.add("Phase1L1TJetSumsProducer", desc);
200 }
201 
202 // creates the plugin for later use in python
l1t::EtSum computeMHT(const edm::Handle< std::vector< reco::CaloJet > > inputJets) const
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
def move
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Phase1L1TJetSumsProducer(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define M_PI
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
l1t::EtSum computeHT(const edm::Handle< std::vector< reco::CaloJet > > inputJets) const
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< std::vector< reco::CaloJet > > inputJetCollectionTag_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38