CMS 3D CMS Logo

L1TPhysicalEtAdder.cc
Go to the documentation of this file.
3 
7 
10 
13 
15 #include <cassert>
16 #include <vector>
17 
18 namespace {
19 
20  int getRegionEta(int gtEta, bool forward) {
21  // backwards conversion is
22  // unsigned rctEta = (iEta<11 ? 10-iEta : iEta-11);
23  // return (((rctEta % 7) & 0x7) | (iEta<11 ? 0x8 : 0));
24  int centralGtEta[] = {11, 12, 13, 14, 15, 16, 17, -100, 10, 9, 8, 7, 6, 5, 4};
25  int forwardGtEta[] = {18, 19, 20, 21, -100, -100, -100, -100, 3, 2, 1, 0};
26 
27  //printf("%i, %i\n",gtEta,forward);
28 
29  int regionEta;
30 
31  if (!forward) {
32  regionEta = centralGtEta[gtEta];
33  } else
34  regionEta = forwardGtEta[gtEta];
35 
36  if (regionEta == -100)
37  edm::LogError("EtaIndexError") << "Bad eta index passed to L1TPhysicalEtAdder::getRegionEta, " << gtEta
38  << std::endl;
39 
40  return regionEta;
41  }
42 
43  // adapted these from the UCT2015 codebase.
44  double getPhysicalEta(int gtEta, bool forward = false) {
45  int etaIndex = getRegionEta(gtEta, forward);
46 
47  const double rgnEtaValues[11] = {0.174, // HB and inner HE bins are 0.348 wide
48  0.522,
49  0.870,
50  1.218,
51  1.566,
52  1.956, // Last two HE bins are 0.432 and 0.828 wide
53  2.586,
54  3.250, // HF bins are 0.5 wide
55  3.750,
56  4.250,
57  4.750};
58  if (0 <= etaIndex && etaIndex < 11) {
59  return -rgnEtaValues[-(etaIndex - 10)]; // 0-10 are negative eta values
60  } else if (etaIndex < 22) {
61  return rgnEtaValues[etaIndex - 11]; // 11-21 are positive eta values
62  }
63  return -9;
64  }
65 
66  double getPhysicalPhi(int phiIndex) {
67  if (phiIndex < 10)
68  return 2. * M_PI * phiIndex / 18.;
69  if (phiIndex < 18)
70  return -M_PI + 2. * M_PI * (phiIndex - 9) / 18.;
71  return -9;
72  }
73 
74 } // namespace
75 
76 using namespace l1t;
77 
79  produces<EGammaBxCollection>();
80  produces<TauBxCollection>("rlxTaus");
81  produces<TauBxCollection>("isoTaus");
82  produces<JetBxCollection>();
83  produces<JetBxCollection>("preGtJets");
84  produces<EtSumBxCollection>();
85  produces<CaloSpareBxCollection>("HFRingSums");
86  produces<CaloSpareBxCollection>("HFBitCounts");
87 
88  EGammaToken_ = consumes<EGammaBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
89  RlxTauToken_ = consumes<TauBxCollection>(ps.getParameter<edm::InputTag>("InputRlxTauCollection"));
90  IsoTauToken_ = consumes<TauBxCollection>(ps.getParameter<edm::InputTag>("InputIsoTauCollection"));
91  JetToken_ = consumes<JetBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
92  preGtJetToken_ = consumes<JetBxCollection>(ps.getParameter<edm::InputTag>("InputPreGtJetCollection"));
93  EtSumToken_ = consumes<EtSumBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
94  HfSumsToken_ = consumes<CaloSpareBxCollection>(ps.getParameter<edm::InputTag>("InputHFSumsCollection"));
95  HfCountsToken_ = consumes<CaloSpareBxCollection>(ps.getParameter<edm::InputTag>("InputHFCountsCollection"));
96  emScaleToken_ = esConsumes<L1CaloEtScale, L1EmEtScaleRcd>();
97  jetScaleToken_ = esConsumes<L1CaloEtScale, L1JetEtScaleRcd>();
98  htMissScaleToken_ = esConsumes<L1CaloEtScale, L1HtMissScaleRcd>();
99 }
100 
102 
103 // ------------ method called to produce the data ------------
105  // store new collections which include physical quantities
106  std::unique_ptr<EGammaBxCollection> new_egammas(new EGammaBxCollection);
107  std::unique_ptr<TauBxCollection> new_rlxtaus(new TauBxCollection);
108  std::unique_ptr<TauBxCollection> new_isotaus(new TauBxCollection);
109  std::unique_ptr<JetBxCollection> new_jets(new JetBxCollection);
110  std::unique_ptr<JetBxCollection> new_preGtJets(new JetBxCollection);
111  std::unique_ptr<EtSumBxCollection> new_etsums(new EtSumBxCollection);
112  std::unique_ptr<CaloSpareBxCollection> new_hfsums(new CaloSpareBxCollection);
113  std::unique_ptr<CaloSpareBxCollection> new_hfcounts(new CaloSpareBxCollection);
114 
116  edm::Handle<TauBxCollection> old_rlxtaus;
117  edm::Handle<TauBxCollection> old_isotaus;
119  edm::Handle<JetBxCollection> old_preGtJets;
123 
124  iEvent.getByToken(EGammaToken_, old_egammas);
125  iEvent.getByToken(RlxTauToken_, old_rlxtaus);
126  iEvent.getByToken(IsoTauToken_, old_isotaus);
127  iEvent.getByToken(JetToken_, old_jets);
128  iEvent.getByToken(preGtJetToken_, old_preGtJets);
129  iEvent.getByToken(EtSumToken_, old_etsums);
130  iEvent.getByToken(HfSumsToken_, old_hfsums);
131  iEvent.getByToken(HfCountsToken_, old_hfcounts);
132 
133  //get the proper scales for conversion to physical et
134  edm::ESHandle<L1CaloEtScale> emScale = iSetup.getHandle(emScaleToken_);
135 
136  edm::ESHandle<L1CaloEtScale> jetScale = iSetup.getHandle(jetScaleToken_);
137 
138  edm::ESHandle<L1CaloEtScale> htMissScale = iSetup.getHandle(htMissScaleToken_);
139 
140  int firstBX = old_egammas->getFirstBX();
141  int lastBX = old_egammas->getLastBX();
142 
143  new_egammas->setBXRange(firstBX, lastBX);
144  new_rlxtaus->setBXRange(firstBX, lastBX);
145  new_isotaus->setBXRange(firstBX, lastBX);
146  new_jets->setBXRange(firstBX, lastBX);
147  new_preGtJets->setBXRange(firstBX, lastBX);
148  new_etsums->setBXRange(firstBX, lastBX);
149  new_hfsums->setBXRange(firstBX, lastBX);
150  new_hfcounts->setBXRange(firstBX, lastBX);
151 
152  for (int bx = firstBX; bx <= lastBX; ++bx) {
153  for (EGammaBxCollection::const_iterator itEGamma = old_egammas->begin(bx); itEGamma != old_egammas->end(bx);
154  ++itEGamma) {
155  //const double pt = itEGamma->hwPt() * emScale->linearLsb();
156  const double et = emScale->et(itEGamma->hwPt());
157  const double eta = getPhysicalEta(itEGamma->hwEta());
158  const double phi = getPhysicalPhi(itEGamma->hwPhi());
159  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
160 
161  EGamma eg(*&p4, itEGamma->hwPt(), itEGamma->hwEta(), itEGamma->hwPhi(), itEGamma->hwQual(), itEGamma->hwIso());
162  new_egammas->push_back(bx, *&eg);
163  }
164 
165  for (TauBxCollection::const_iterator itTau = old_rlxtaus->begin(bx); itTau != old_rlxtaus->end(bx); ++itTau) {
166  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
167  //const uint16_t rankPt = jetScale->rank((uint16_t)itTau->hwPt());
168  //const double et = jetScale->et( rankPt ) ;
169 
170  // or use the emScale to get finer-grained et
171  //const double et = itTau->hwPt() * emScale->linearLsb();
172 
173  // we are now already in the rankPt
174  const double et = jetScale->et(itTau->hwPt());
175 
176  const double eta = getPhysicalEta(itTau->hwEta());
177  const double phi = getPhysicalPhi(itTau->hwPhi());
178  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
179 
180  Tau tau(*&p4, itTau->hwPt(), itTau->hwEta(), itTau->hwPhi(), itTau->hwQual(), itTau->hwIso());
181  new_rlxtaus->push_back(bx, *&tau);
182  }
183 
184  for (TauBxCollection::const_iterator itTau = old_isotaus->begin(bx); itTau != old_isotaus->end(bx); ++itTau) {
185  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
186  //const uint16_t rankPt = jetScale->rank((uint16_t)itTau->hwPt());
187  //const double et = jetScale->et( rankPt ) ;
188 
189  // or use the emScale to get finer-grained et
190  //const double et = itTau->hwPt() * emScale->linearLsb();
191 
192  // we are now already in the rankPt
193  const double et = jetScale->et(itTau->hwPt());
194 
195  const double eta = getPhysicalEta(itTau->hwEta());
196  const double phi = getPhysicalPhi(itTau->hwPhi());
197  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
198 
199  Tau tau(*&p4, itTau->hwPt(), itTau->hwEta(), itTau->hwPhi(), itTau->hwQual(), itTau->hwIso());
200  new_isotaus->push_back(bx, *&tau);
201  }
202 
203  for (JetBxCollection::const_iterator itJet = old_jets->begin(bx); itJet != old_jets->end(bx); ++itJet) {
204  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
205  //const uint16_t rankPt = jetScale->rank((uint16_t)itJet->hwPt());
206  //const double et = jetScale->et( rankPt ) ;
207 
208  // or use the emScale to get finer-grained et
209  //const double et = itJet->hwPt() * emScale->linearLsb();
210 
211  // we are now already in the rankPt
212  const double et = jetScale->et(itJet->hwPt());
213 
214  const bool forward = ((itJet->hwQual() & 0x2) != 0);
215  const double eta = getPhysicalEta(itJet->hwEta(), forward);
216  const double phi = getPhysicalPhi(itJet->hwPhi());
217  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
218 
219  Jet jet(*&p4, itJet->hwPt(), itJet->hwEta(), itJet->hwPhi(), itJet->hwQual());
220  new_jets->push_back(bx, *&jet);
221  }
222 
223  for (JetBxCollection::const_iterator itJet = old_preGtJets->begin(bx); itJet != old_preGtJets->end(bx); ++itJet) {
224  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
225  //const uint16_t rankPt = jetScale->rank((uint16_t)itJet->hwPt());
226  //const double et = jetScale->et( rankPt ) ;
227 
228  // or use the emScale to get finer-grained et
229  const double et = itJet->hwPt() * emScale->linearLsb();
230 
231  // we are now already in the rankPt
232  //const double et = jetScale->et( itJet->hwPt() );
233 
234  const bool forward = ((itJet->hwQual() & 0x2) != 0);
235  const double eta = getPhysicalEta(itJet->hwEta(), forward);
236  const double phi = getPhysicalPhi(itJet->hwPhi());
237  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
238 
239  Jet jet(*&p4, itJet->hwPt(), itJet->hwEta(), itJet->hwPhi(), itJet->hwQual());
240  new_preGtJets->push_back(bx, *&jet);
241  }
242 
243  for (EtSumBxCollection::const_iterator itEtSum = old_etsums->begin(bx); itEtSum != old_etsums->end(bx); ++itEtSum) {
244  double et = itEtSum->hwPt() * emScale->linearLsb();
245  //hack while we figure out the right scales
246  //double et = emScale->et( itEtSum->hwPt() );
247  const EtSum::EtSumType sumType = itEtSum->getType();
248 
249  const double eta = getPhysicalEta(itEtSum->hwEta());
250  double phi = getPhysicalPhi(itEtSum->hwPhi());
251  if (sumType == EtSum::EtSumType::kMissingHt) {
252  et = htMissScale->et(itEtSum->hwPt());
253  double regionPhiWidth = 2. * 3.1415927 / L1CaloRegionDetId::N_PHI;
254  phi = phi + (regionPhiWidth / 2.); // add the region half-width to match L1Extra MHT phi
255  }
256 
257  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
258 
259  EtSum eg(*&p4, sumType, itEtSum->hwPt(), itEtSum->hwEta(), itEtSum->hwPhi(), itEtSum->hwQual());
260  new_etsums->push_back(bx, *&eg);
261  }
262 
263  for (CaloSpareBxCollection::const_iterator itCaloSpare = old_hfsums->begin(bx); itCaloSpare != old_hfsums->end(bx);
264  ++itCaloSpare) {
265  //just pass through for now
266  //a different scale is needed depending on the type
267  new_hfsums->push_back(bx, *itCaloSpare);
268  }
269 
270  for (CaloSpareBxCollection::const_iterator itCaloSpare = old_hfcounts->begin(bx);
271  itCaloSpare != old_hfcounts->end(bx);
272  ++itCaloSpare) {
273  //just pass through for now
274  //a different scale is needed depending on the type
275  new_hfcounts->push_back(bx, *itCaloSpare);
276  }
277  }
278 
279  iEvent.put(std::move(new_egammas));
280  iEvent.put(std::move(new_rlxtaus), "rlxTaus");
281  iEvent.put(std::move(new_isotaus), "isoTaus");
282  iEvent.put(std::move(new_jets));
283  iEvent.put(std::move(new_preGtJets), "preGtJets");
284  iEvent.put(std::move(new_etsums));
285  iEvent.put(std::move(new_hfsums), "HFRingSums");
286  iEvent.put(std::move(new_hfcounts), "HFBitCounts");
287 }
288 
289 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
291  //The following says we do not know what parameters are allowed so do no validation
292  // Please change this to state exactly what you do use, even if it is no parameters
294  desc.setUnknown();
295  descriptions.addDefault(desc);
296 }
297 
298 //define this as a plug-in
int getLastBX() const
int getFirstBX() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const unsigned int gtEta(const unsigned int iEta)
delete x;
Definition: CaloConfig.h:22
Log< level::Error, false > LogError
L1TPhysicalEtAdder(const edm::ParameterSet &ps)
const_iterator begin(int bx) const
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
double et(const uint16_t rank) const
convert from rank to physically meaningful quantity
Definition: Jet.py:1
double linearLsb() const
get LSB of linear input scale
Definition: L1CaloEtScale.h:54
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
#define M_PI
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: Tau.py:1
const_iterator end(int bx) const
static const unsigned N_PHI
EtSumType
Definition: EtSum.h:27
def move(src, dest)
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)