CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhysicalEtAdder.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 
28 
29  produces<l1t::EGammaBxCollection>();
30  produces<l1t::TauBxCollection>();
31  produces<l1t::JetBxCollection>();
32  produces<l1t::EtSumBxCollection>();
33  produces<l1t::CaloSpareBxCollection>();
34 
35  EGammaToken_ = consumes<l1t::EGammaBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
36  TauToken_ = consumes<l1t::TauBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
37  JetToken_ = consumes<l1t::JetBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
38  EtSumToken_ = consumes<l1t::EtSumBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
39  CaloSpareToken_ = consumes<l1t::CaloSpareBxCollection>(ps.getParameter<edm::InputTag>("InputCollection"));
40 }
41 
43 
44 }
45 
46 // ------------ method called to produce the data ------------
47 void
49 {
50  // store new collections which include physical quantities
51  std::auto_ptr<l1t::EGammaBxCollection> new_egammas (new l1t::EGammaBxCollection);
52  std::auto_ptr<l1t::TauBxCollection> new_taus (new l1t::TauBxCollection);
53  std::auto_ptr<l1t::JetBxCollection> new_jets (new l1t::JetBxCollection);
54  std::auto_ptr<l1t::EtSumBxCollection> new_etsums (new l1t::EtSumBxCollection);
55  std::auto_ptr<l1t::CaloSpareBxCollection> new_calospares (new l1t::CaloSpareBxCollection);
56 
62 
63  iEvent.getByToken(EGammaToken_, old_egammas);
64  iEvent.getByToken(TauToken_, old_taus);
65  iEvent.getByToken(JetToken_, old_jets);
66  iEvent.getByToken(EtSumToken_, old_etsums);
67  iEvent.getByToken(CaloSpareToken_, old_calospares);
68 
69  //get the proper scales for conversion to physical et
71  iSetup.get< L1EmEtScaleRcd >().get( emScale ) ;
72 
74  iSetup.get< L1JetEtScaleRcd >().get( jetScale ) ;
75 
76  edm::ESHandle< L1CaloEtScale > htMissScale ;
77  iSetup.get< L1HtMissScaleRcd >().get( htMissScale ) ;
78 
79  int firstBX = old_egammas->getFirstBX();
80  int lastBX = old_egammas->getLastBX();
81 
82  new_egammas->setBXRange(firstBX, lastBX);
83  new_taus->setBXRange(firstBX, lastBX);
84  new_jets->setBXRange(firstBX, lastBX);
85  new_taus->setBXRange(firstBX, lastBX);
86  new_calospares->setBXRange(firstBX, lastBX);
87 
88  for(int bx = firstBX; bx <= lastBX; ++bx)
89  {
90  for(l1t::EGammaBxCollection::const_iterator itEGamma = old_egammas->begin(bx);
91  itEGamma != old_egammas->end(bx); ++itEGamma)
92  {
93  //const double pt = itEGamma->hwPt() * emScale->linearLsb();
94  const double et = emScale->et( itEGamma->hwPt() );
95  const double eta = getPhysicalEta(itEGamma->hwEta());
96  const double phi = getPhysicalPhi(itEGamma->hwPhi());
97  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
98 
99  l1t::EGamma eg(*&p4, itEGamma->hwPt(),
100  itEGamma->hwEta(), itEGamma->hwPhi(),
101  itEGamma->hwQual(), itEGamma->hwIso());
102  new_egammas->push_back(bx, *&eg);
103 
104 
105  }
106 
107  for(l1t::TauBxCollection::const_iterator itTau = old_taus->begin(bx);
108  itTau != old_taus->end(bx); ++itTau)
109  {
110  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
111  //const uint16_t rankPt = jetScale->rank((uint16_t)itTau->hwPt());
112  //const double et = jetScale->et( rankPt ) ;
113 
114  // or use the emScale to get finer-grained et
115  //const double et = itTau->hwPt() * emScale->linearLsb();
116 
117  // we are now already in the rankPt
118  const double et = jetScale->et( itTau->hwPt() );
119 
120  const double eta = getPhysicalEta(itTau->hwEta());
121  const double phi = getPhysicalPhi(itTau->hwPhi());
122  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
123 
124  l1t::Tau tau(*&p4, itTau->hwPt(),
125  itTau->hwEta(), itTau->hwPhi(),
126  itTau->hwQual(), itTau->hwIso());
127  new_taus->push_back(bx, *&tau);
128 
129  }
130 
131  for(l1t::JetBxCollection::const_iterator itJet = old_jets->begin(bx);
132  itJet != old_jets->end(bx); ++itJet)
133  {
134  // use the full-circle conversion to match l1extra, accounts for linearLsb and max value automatically
135  //const uint16_t rankPt = jetScale->rank((uint16_t)itJet->hwPt());
136  //const double et = jetScale->et( rankPt ) ;
137 
138  // or use the emScale to get finer-grained et
139  //const double et = itJet->hwPt() * emScale->linearLsb();
140 
141  // we are now already in the rankPt
142  const double et = jetScale->et( itJet->hwPt() );
143 
144  const bool forward = ((itJet->hwQual() & 0x2) != 0);
145  const double eta = getPhysicalEta(itJet->hwEta(), forward);
146  const double phi = getPhysicalPhi(itJet->hwPhi());
147  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
148 
149  l1t::Jet jet(*&p4, itJet->hwPt(),
150  itJet->hwEta(), itJet->hwPhi(),
151  itJet->hwQual());
152  new_jets->push_back(bx, *&jet);
153 
154  }
155 
156  for(l1t::EtSumBxCollection::const_iterator itEtSum = old_etsums->begin(bx);
157  itEtSum != old_etsums->end(bx); ++itEtSum)
158  {
159  double et = itEtSum->hwPt() * emScale->linearLsb();
160  //hack while we figure out the right scales
161  //double et = emScale->et( itEtSum->hwPt() );
162  const l1t::EtSum::EtSumType sumType = itEtSum->getType();
163  if(sumType == EtSum::EtSumType::kMissingHt)
164  et = htMissScale->et( itEtSum->hwPt() );
165 
166  const double eta = getPhysicalEta(itEtSum->hwEta());
167  const double phi = getPhysicalPhi(itEtSum->hwPhi());
168 
169  math::PtEtaPhiMLorentzVector p4(et, eta, phi, 0);
170 
171  l1t::EtSum eg(*&p4, sumType, itEtSum->hwPt(),
172  itEtSum->hwEta(), itEtSum->hwPhi(),
173  itEtSum->hwQual());
174  new_etsums->push_back(bx, *&eg);
175 
176 
177  }
178 
179  for(l1t::CaloSpareBxCollection::const_iterator itCaloSpare = old_calospares->begin(bx);
180  itCaloSpare != old_calospares->end(bx); ++itCaloSpare)
181  {
182  //just pass through for now
183  //a different scale is needed depending on the type
184  new_calospares->push_back(bx, *itCaloSpare);
185  }
186  }
187 
188  iEvent.put(new_egammas);
189  iEvent.put(new_taus);
190  iEvent.put(new_jets);
191  iEvent.put(new_etsums);
192  iEvent.put(new_calospares);
193 }
194 
195 // ------------ method called once each job just before starting event loop ------------
196 void
198 {
199 }
200 
201 // ------------ method called once each job just after ending the event loop ------------
202 void
204 }
205 
206 // ------------ method called when starting to processes a run ------------
207 /*
208  void
209  l1t::PhysicalEtAdder::beginRun(edm::Run const&, edm::EventSetup const&)
210  {
211  }
212 */
213 
214 // ------------ method called when ending the processing of a run ------------
215 /*
216  void
217  l1t::PhysicalEtAdder::endRun(edm::Run const&, edm::EventSetup const&)
218  {
219  }
220 */
221 
222 // ------------ method called when starting to processes a luminosity block ------------
223 /*
224  void
225  l1t::PhysicalEtAdder::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup cons
226  t&)
227  {
228  }
229 */
230 
231 // ------------ method called when ending the processing of a luminosity block ------------
232 /*
233  void
234  l1t::PhysicalEtAdder::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&
235  )
236  {
237  }
238 */
239 
240 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
241 void
243  //The following says we do not know what parameters are allowed so do no validation
244  // Please change this to state exactly what you do use, even if it is no parameters
246  desc.setUnknown();
247  descriptions.addDefault(desc);
248 }
249 
250 //define this as a plug-in
252 
253 int getRegionEta(int gtEta, bool forward)
254 {
255  // backwards conversion is
256  // unsigned rctEta = (iEta<11 ? 10-iEta : iEta-11);
257  // return (((rctEta % 7) & 0x7) | (iEta<11 ? 0x8 : 0));
258  int centralGtEta[] = {11, 12, 13, 14, 15, 16, 17, -100, 10, 9, 8, 7, 6, 5, 4};
259  int forwardGtEta[] = {18, 19, 20, 21, -100, -100, -100, -100, 3, 2, 1, 0};
260 
261  //printf("%i, %i\n",gtEta,forward);
262 
263  int regionEta;
264 
265  if(!forward)
266  {
267  regionEta = centralGtEta[gtEta];
268  } else
269  regionEta = forwardGtEta[gtEta];
270 
271  if(regionEta == -100)
272  edm::LogError("EtaIndexError")
273  << "Bad eta index passed to PhysicalEtAdder::getRegionEta, " << gtEta << std::endl;
274 
275  return regionEta;
276 }
277 
278 // adapted these from the UCT2015 codebase.
279 double getPhysicalEta(int gtEta, bool forward)
280 {
281  int etaIndex = getRegionEta(gtEta, forward);
282 
283  const double rgnEtaValues[11] = {
284  0.174, // HB and inner HE bins are 0.348 wide
285  0.522,
286  0.870,
287  1.218,
288  1.566,
289  1.956, // Last two HE bins are 0.432 and 0.828 wide
290  2.586,
291  3.250, // HF bins are 0.5 wide
292  3.750,
293  4.250,
294  4.750
295  };
296  if(etaIndex < 11) {
297  return -rgnEtaValues[-(etaIndex - 10)]; // 0-10 are negative eta values
298  }
299  else if (etaIndex < 22) {
300  return rgnEtaValues[etaIndex - 11]; // 11-21 are positive eta values
301  }
302  return -9;
303 }
304 
305 double getPhysicalPhi(int phiIndex)
306 {
307  if (phiIndex < 10)
308  return 2. * M_PI * phiIndex / 18.;
309  if (phiIndex < 18)
310  return -M_PI + 2. * M_PI * (phiIndex - 9) / 18.;
311  return -9;
312 }
T getParameter(std::string const &) const
edm::EDGetToken EtSumToken_
double getPhysicalEta(int etaIndex, bool forward=false)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetToken TauToken_
Definition: Tau.h:13
const unsigned int gtEta(const unsigned int iEta)
edm::EDGetToken CaloSpareToken_
T eta() const
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
Definition: Jet.h:13
PhysicalEtAdder(const edm::ParameterSet &ps)
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
double p4[4]
Definition: TauolaWrapper.h:92
virtual void endJob() override
#define M_PI
int getRegionEta(int gtEta, bool forward)
double getPhysicalPhi(int phiIndex)
const T & get() const
Definition: EventSetup.h:55
virtual void beginJob() override
edm::EDGetToken EGammaToken_
edm::EDGetToken JetToken_
virtual void produce(edm::Event &, const edm::EventSetup &) override
EtSumType
Definition: EtSum.h:17
std::vector< EGamma >::const_iterator const_iterator
Definition: BXVector.h:16
Definition: DDAxes.h:10