CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TPhysicalEtAdder.cc
Go to the documentation of this file.
3 
8 
12 
15 
18 
20 #include <vector>
21 
22 #include <stdio.h>
23 
24 double getPhysicalEta(int etaIndex, bool forward = false);
25 double getPhysicalPhi(int phiIndex);
26 
27 using namespace l1t;
28 
30 
31  produces<EGammaBxCollection>();
32  produces<TauBxCollection>("rlxTaus");
33  produces<TauBxCollection>("isoTaus");
34  produces<JetBxCollection>();
35  produces<JetBxCollection>("preGtJets");
36  produces<EtSumBxCollection>();
37  produces<CaloSpareBxCollection>("HFRingSums");
38  produces<CaloSpareBxCollection>("HFBitCounts");
39 
40  EGammaToken_ = consumes<EGammaBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
41  RlxTauToken_ = consumes<TauBxCollection>(ps.getParameter<edm::InputTag>("InputRlxTauCollection"));
42  IsoTauToken_ = consumes<TauBxCollection>(ps.getParameter<edm::InputTag>("InputIsoTauCollection"));
43  JetToken_ = consumes<JetBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
44  preGtJetToken_ = consumes<JetBxCollection>(ps.getParameter<edm::InputTag>("InputPreGtJetCollection"));
45  EtSumToken_ = consumes<EtSumBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
46  HfSumsToken_ = consumes<CaloSpareBxCollection>(ps.getParameter<edm::InputTag>("InputHFSumsCollection"));
47  HfCountsToken_ = consumes<CaloSpareBxCollection>(ps.getParameter<edm::InputTag>("InputHFCountsCollection"));
48 }
49 
51 
52 }
53 
54 // ------------ method called to produce the data ------------
55 void
57 {
58  // store new collections which include physical quantities
59  std::auto_ptr<EGammaBxCollection> new_egammas (new EGammaBxCollection);
60  std::auto_ptr<TauBxCollection> new_rlxtaus (new TauBxCollection);
61  std::auto_ptr<TauBxCollection> new_isotaus (new TauBxCollection);
62  std::auto_ptr<JetBxCollection> new_jets (new JetBxCollection);
63  std::auto_ptr<JetBxCollection> new_preGtJets (new JetBxCollection);
64  std::auto_ptr<EtSumBxCollection> new_etsums (new EtSumBxCollection);
65  std::auto_ptr<CaloSpareBxCollection> new_hfsums (new CaloSpareBxCollection);
66  std::auto_ptr<CaloSpareBxCollection> new_hfcounts (new CaloSpareBxCollection);
67 
69  edm::Handle<TauBxCollection> old_rlxtaus;
70  edm::Handle<TauBxCollection> old_isotaus;
72  edm::Handle<JetBxCollection> old_preGtJets;
76 
77  iEvent.getByToken(EGammaToken_, old_egammas);
78  iEvent.getByToken(RlxTauToken_, old_rlxtaus);
79  iEvent.getByToken(IsoTauToken_, old_isotaus);
80  iEvent.getByToken(JetToken_, old_jets);
81  iEvent.getByToken(preGtJetToken_, old_preGtJets);
82  iEvent.getByToken(EtSumToken_, old_etsums);
83  iEvent.getByToken(HfSumsToken_, old_hfsums);
84  iEvent.getByToken(HfCountsToken_, old_hfcounts);
85 
86  //get the proper scales for conversion to physical et
88  iSetup.get< L1EmEtScaleRcd >().get( emScale ) ;
89 
91  iSetup.get< L1JetEtScaleRcd >().get( jetScale ) ;
92 
93  edm::ESHandle< L1CaloEtScale > htMissScale ;
94  iSetup.get< L1HtMissScaleRcd >().get( htMissScale ) ;
95 
96  int firstBX = old_egammas->getFirstBX();
97  int lastBX = old_egammas->getLastBX();
98 
99  new_egammas->setBXRange(firstBX, lastBX);
100  new_rlxtaus->setBXRange(firstBX, lastBX);
101  new_isotaus->setBXRange(firstBX, lastBX);
102  new_jets->setBXRange(firstBX, lastBX);
103  new_preGtJets->setBXRange(firstBX, lastBX);
104  new_etsums->setBXRange(firstBX, lastBX);
105  new_hfsums->setBXRange(firstBX, lastBX);
106  new_hfcounts->setBXRange(firstBX, lastBX);
107 
108  for(int bx = firstBX; bx <= lastBX; ++bx)
109  {
110  for(EGammaBxCollection::const_iterator itEGamma = old_egammas->begin(bx);
111  itEGamma != old_egammas->end(bx); ++itEGamma)
112  {
113  //const double pt = itEGamma->hwPt() * emScale->linearLsb();
114  const double et = emScale->et( itEGamma->hwPt() );
115  const double eta = getPhysicalEta(itEGamma->hwEta());
116  const double phi = getPhysicalPhi(itEGamma->hwPhi());
117  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
118 
119  EGamma eg(*&p4, itEGamma->hwPt(),
120  itEGamma->hwEta(), itEGamma->hwPhi(),
121  itEGamma->hwQual(), itEGamma->hwIso());
122  new_egammas->push_back(bx, *&eg);
123 
124 
125  }
126 
127  for(TauBxCollection::const_iterator itTau = old_rlxtaus->begin(bx);
128  itTau != old_rlxtaus->end(bx); ++itTau)
129  {
130  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
131  //const uint16_t rankPt = jetScale->rank((uint16_t)itTau->hwPt());
132  //const double et = jetScale->et( rankPt ) ;
133 
134  // or use the emScale to get finer-grained et
135  //const double et = itTau->hwPt() * emScale->linearLsb();
136 
137  // we are now already in the rankPt
138  const double et = jetScale->et( itTau->hwPt() );
139 
140  const double eta = getPhysicalEta(itTau->hwEta());
141  const double phi = getPhysicalPhi(itTau->hwPhi());
142  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
143 
144  Tau tau(*&p4, itTau->hwPt(),
145  itTau->hwEta(), itTau->hwPhi(),
146  itTau->hwQual(), itTau->hwIso());
147  new_rlxtaus->push_back(bx, *&tau);
148 
149  }
150 
151  for(TauBxCollection::const_iterator itTau = old_isotaus->begin(bx);
152  itTau != old_isotaus->end(bx); ++itTau)
153  {
154  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
155  //const uint16_t rankPt = jetScale->rank((uint16_t)itTau->hwPt());
156  //const double et = jetScale->et( rankPt ) ;
157 
158  // or use the emScale to get finer-grained et
159  //const double et = itTau->hwPt() * emScale->linearLsb();
160 
161  // we are now already in the rankPt
162  const double et = jetScale->et( itTau->hwPt() );
163 
164  const double eta = getPhysicalEta(itTau->hwEta());
165  const double phi = getPhysicalPhi(itTau->hwPhi());
166  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
167 
168  Tau tau(*&p4, itTau->hwPt(),
169  itTau->hwEta(), itTau->hwPhi(),
170  itTau->hwQual(), itTau->hwIso());
171  new_isotaus->push_back(bx, *&tau);
172 
173  }
174 
175  for(JetBxCollection::const_iterator itJet = old_jets->begin(bx);
176  itJet != old_jets->end(bx); ++itJet)
177  {
178  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
179  //const uint16_t rankPt = jetScale->rank((uint16_t)itJet->hwPt());
180  //const double et = jetScale->et( rankPt ) ;
181 
182  // or use the emScale to get finer-grained et
183  //const double et = itJet->hwPt() * emScale->linearLsb();
184 
185  // we are now already in the rankPt
186  const double et = jetScale->et( itJet->hwPt() );
187 
188  const bool forward = ((itJet->hwQual() & 0x2) != 0);
189  const double eta = getPhysicalEta(itJet->hwEta(), forward);
190  const double phi = getPhysicalPhi(itJet->hwPhi());
191  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
192 
193  Jet jet(*&p4, itJet->hwPt(),
194  itJet->hwEta(), itJet->hwPhi(),
195  itJet->hwQual());
196  new_jets->push_back(bx, *&jet);
197 
198  }
199 
200  for(JetBxCollection::const_iterator itJet = old_preGtJets->begin(bx);
201  itJet != old_preGtJets->end(bx); ++itJet)
202  {
203  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
204  //const uint16_t rankPt = jetScale->rank((uint16_t)itJet->hwPt());
205  //const double et = jetScale->et( rankPt ) ;
206 
207  // or use the emScale to get finer-grained et
208  const double et = itJet->hwPt() * emScale->linearLsb();
209 
210  // we are now already in the rankPt
211  //const double et = jetScale->et( itJet->hwPt() );
212 
213  const bool forward = ((itJet->hwQual() & 0x2) != 0);
214  const double eta = getPhysicalEta(itJet->hwEta(), forward);
215  const double phi = getPhysicalPhi(itJet->hwPhi());
216  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
217 
218  Jet jet(*&p4, itJet->hwPt(),
219  itJet->hwEta(), itJet->hwPhi(),
220  itJet->hwQual());
221  new_preGtJets->push_back(bx, *&jet);
222 
223  }
224 
225 
226  for(EtSumBxCollection::const_iterator itEtSum = old_etsums->begin(bx);
227  itEtSum != old_etsums->end(bx); ++itEtSum)
228  {
229  double et = itEtSum->hwPt() * emScale->linearLsb();
230  //hack while we figure out the right scales
231  //double et = emScale->et( itEtSum->hwPt() );
232  const EtSum::EtSumType sumType = itEtSum->getType();
233 
234  const double eta = getPhysicalEta(itEtSum->hwEta());
235  double phi = getPhysicalPhi(itEtSum->hwPhi());
236  if(sumType == EtSum::EtSumType::kMissingHt){
237  et = htMissScale->et( itEtSum->hwPt() );
238  double regionPhiWidth=2. * 3.1415927 / L1CaloRegionDetId::N_PHI;
239  phi=phi+(regionPhiWidth/2.); // add the region half-width to match L1Extra MHT phi
240  }
241 
242 
243  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
244 
245  EtSum eg(*&p4, sumType, itEtSum->hwPt(),
246  itEtSum->hwEta(), itEtSum->hwPhi(),
247  itEtSum->hwQual());
248  new_etsums->push_back(bx, *&eg);
249 
250 
251  }
252 
253  for(CaloSpareBxCollection::const_iterator itCaloSpare = old_hfsums->begin(bx);
254  itCaloSpare != old_hfsums->end(bx); ++itCaloSpare)
255  {
256  //just pass through for now
257  //a different scale is needed depending on the type
258  new_hfsums->push_back(bx, *itCaloSpare);
259  }
260 
261  for(CaloSpareBxCollection::const_iterator itCaloSpare = old_hfcounts->begin(bx);
262  itCaloSpare != old_hfcounts->end(bx); ++itCaloSpare)
263  {
264  //just pass through for now
265  //a different scale is needed depending on the type
266  new_hfcounts->push_back(bx, *itCaloSpare);
267  }
268 
269  }
270 
271  iEvent.put(new_egammas);
272  iEvent.put(new_rlxtaus,"rlxTaus");
273  iEvent.put(new_isotaus,"isoTaus");
274  iEvent.put(new_jets);
275  iEvent.put(new_preGtJets,"preGtJets");
276  iEvent.put(new_etsums);
277  iEvent.put(new_hfsums,"HFRingSums");
278  iEvent.put(new_hfcounts,"HFBitCounts");
279 }
280 
281 // ------------ method called once each job just before starting event loop ------------
282 void
284 {
285 }
286 
287 // ------------ method called once each job just after ending the event loop ------------
288 void
290 }
291 
292 // ------------ method called when starting to processes a run ------------
293 /*
294  void
295  L1TPhysicalEtAdder::beginRun(edm::Run const&, edm::EventSetup const&)
296  {
297  }
298 */
299 
300 // ------------ method called when ending the processing of a run ------------
301 /*
302  void
303  L1TPhysicalEtAdder::endRun(edm::Run const&, edm::EventSetup const&)
304  {
305  }
306 */
307 
308 // ------------ method called when starting to processes a luminosity block ------------
309 /*
310  void
311  L1TPhysicalEtAdder::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup cons
312  t&)
313  {
314  }
315 */
316 
317 // ------------ method called when ending the processing of a luminosity block ------------
318 /*
319  void
320  L1TPhysicalEtAdder::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&
321  )
322  {
323  }
324 */
325 
326 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
327 void
329  //The following says we do not know what parameters are allowed so do no validation
330  // Please change this to state exactly what you do use, even if it is no parameters
332  desc.setUnknown();
333  descriptions.addDefault(desc);
334 }
335 
336 //define this as a plug-in
338 
339 int getRegionEta(int gtEta, bool forward)
340 {
341  // backwards conversion is
342  // unsigned rctEta = (iEta<11 ? 10-iEta : iEta-11);
343  // return (((rctEta % 7) & 0x7) | (iEta<11 ? 0x8 : 0));
344  int centralGtEta[] = {11, 12, 13, 14, 15, 16, 17, -100, 10, 9, 8, 7, 6, 5, 4};
345  int forwardGtEta[] = {18, 19, 20, 21, -100, -100, -100, -100, 3, 2, 1, 0};
346 
347  //printf("%i, %i\n",gtEta,forward);
348 
349  int regionEta;
350 
351  if(!forward)
352  {
353  regionEta = centralGtEta[gtEta];
354  } else
355  regionEta = forwardGtEta[gtEta];
356 
357  if(regionEta == -100)
358  edm::LogError("EtaIndexError")
359  << "Bad eta index passed to L1TPhysicalEtAdder::getRegionEta, " << gtEta << std::endl;
360 
361  return regionEta;
362 }
363 
364 // adapted these from the UCT2015 codebase.
365 double getPhysicalEta(int gtEta, bool forward)
366 {
367  int etaIndex = getRegionEta(gtEta, forward);
368 
369  const double rgnEtaValues[11] = {
370  0.174, // HB and inner HE bins are 0.348 wide
371  0.522,
372  0.870,
373  1.218,
374  1.566,
375  1.956, // Last two HE bins are 0.432 and 0.828 wide
376  2.586,
377  3.250, // HF bins are 0.5 wide
378  3.750,
379  4.250,
380  4.750
381  };
382  if(etaIndex < 11) {
383  return -rgnEtaValues[-(etaIndex - 10)]; // 0-10 are negative eta values
384  }
385  else if (etaIndex < 22) {
386  return rgnEtaValues[etaIndex - 11]; // 11-21 are positive eta values
387  }
388  return -9;
389 }
390 
391 double getPhysicalPhi(int phiIndex)
392 {
393  if (phiIndex < 10)
394  return 2. * M_PI * phiIndex / 18.;
395  if (phiIndex < 18)
396  return -M_PI + 2. * M_PI * (phiIndex - 9) / 18.;
397  return -9;
398 }
T getParameter(std::string const &) const
virtual void produce(edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Definition: Tau.h:13
const unsigned int gtEta(const unsigned int iEta)
T eta() const
L1TPhysicalEtAdder(const edm::ParameterSet &ps)
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
Definition: Jet.h:13
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
int getRegionEta(int gtEta, bool forward)
double p4[4]
Definition: TauolaWrapper.h:92
virtual void beginJob() override
#define M_PI
double getPhysicalPhi(int phiIndex)
const T & get() const
Definition: EventSetup.h:55
virtual void endJob() override
double getPhysicalEta(int etaIndex, bool forward=false)
static const unsigned N_PHI
EtSumType
Definition: EtSum.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< EGamma >::const_iterator const_iterator
Definition: BXVector.h:16
Definition: DDAxes.h:10