CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TStage2Layer1Producer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/skeleton
4 // Class: skeleton
5 //
13 //
14 // Original Author: James Brooke
15 // Created: Thu, 05 Dec 2013 17:39:27 GMT
16 //
17 //
18 
19 
20 // system include files
21 #include <boost/shared_ptr.hpp>
22 
23 // user include files
24 
35 
38 
41 
46 
47 
50 
52 
54 
55 //
56 // class declaration
57 //
58 
59 using namespace l1t;
60 
61 
63  public:
64  explicit L1TStage2Layer1Producer(const edm::ParameterSet& ps);
66 
67  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions)
68  ;
69 
70  private:
71  virtual void beginJob() override;
72  virtual void produce(edm::Event&, const edm::EventSetup&) override;
73  virtual void endJob() override;
74 
75  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
76  virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
77  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
78  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
79 
80  // ----------member data ---------------------------
81 
83 
84  int bxFirst_, bxLast_; // bx range to process
85  int ietaMin_, ietaMax_, iphiMin_, iphiMax_;
86 
87  std::vector<edm::EDGetToken> ecalToken_; // this is a crazy way to store multi-BX info
88  std::vector<edm::EDGetToken> hcalToken_; // should be replaced with a BXVector< > or similar
89 
90  // parameters
91  unsigned long long paramsCacheId_;
92  unsigned fwv_;
94 
95  // the processor
97  boost::shared_ptr<Stage2PreProcessor> processor_;
98 
99  };
100 
101 
102 
104  verbosity_(ps.getParameter<int>("verbosity")),
105  bxFirst_(ps.getParameter<int>("bxFirst")),
106  bxLast_(ps.getParameter<int>("bxLast")),
107  ietaMin_(-32),
108  ietaMax_(32),
109  iphiMin_(1),
110  iphiMax_(72),
111  ecalToken_(bxLast_+1-bxFirst_),
112  hcalToken_(bxLast_+1-bxFirst_),
113  paramsCacheId_(0),
114  params_(0)
115 {
116 
117  // register what you produce
118  produces<CaloTowerBxCollection> ();
119 
120  // register what you consume and keep token for later access:
121  for (int ibx=0; ibx<bxLast_+1-bxFirst_; ibx++) {
122  ecalToken_[ibx] = consumes<EcalTrigPrimDigiCollection>(ps.getParameter<edm::InputTag>("ecalToken"));
123  hcalToken_[ibx] = consumes<HcalTrigPrimDigiCollection>(ps.getParameter<edm::InputTag>("hcalToken"));
124  }
125 
126  // placeholder for the parameters
128 
129  // set firmware version from python config for now
130  fwv_ = ps.getParameter<int>("firmware");
131 
132 }
133 
135 
136  delete params_;
137 
138 }
139 
140 // ------------ method called to produce the data ------------
141 void
143 {
144 
145  LogDebug("l1t|stage 2") << "L1TStage2Layer1Producer::produce function called..." << std::endl;
146 
147  // do event setup
148  // get RCT input scale objects
150  iSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
151  // const L1CaloEcalScale* e = ecalScale.product();
152 
154  iSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
155  // const L1CaloHcalScale* h = hcalScale.product();
156 
157  LogDebug("L1TDebug") << "First BX=" << bxFirst_ << ", last BX=" << bxLast_ << ", LSB(E)=" << params_->towerLsbE() << ", LSB(H)=" << params_->towerLsbH() << std::endl;
158 
159 
160  // output collection
161  std::auto_ptr<CaloTowerBxCollection> towersColl (new CaloTowerBxCollection);
162 
163 
164  // loop over crossings
165  for (int bx = bxFirst_; bx < bxLast_+1; ++bx) {
166 
167  int ibx = bx-bxFirst_;
168 
171 
172  iEvent.getByToken(hcalToken_[ibx], hcalTPs);
173  iEvent.getByToken(ecalToken_[ibx], ecalTPs);
174 
175  // create input and output tower vectors for this BX
176  std::auto_ptr< std::vector<CaloTower> > localInTowers (new std::vector<CaloTower>(CaloTools::caloTowerHashMax()));
177  std::auto_ptr< std::vector<CaloTower> > localOutTowers (new std::vector<CaloTower>()); //this is later filled to the same size as localInTowers
178 
179  // loop over ECAL TPs
181  int nEcal=0;
182  for (ecalItr=ecalTPs->begin(); ecalItr!=ecalTPs->end(); ++ecalItr, ++nEcal) {
183 
184  int ieta = ecalItr->id().ieta();
185  int iphi = ecalItr->id().iphi();
186 
187  int ietIn = ecalItr->compressedEt();
188  bool ifg = ecalItr->fineGrain();
189 
190  // decompress
191  double et = ecalScale->et( ietIn, abs(ieta), (ieta>0) );
192  int ietOut = floor( et / params_->towerLsbE() );
193  // int ietOutMask = (int) pow(2,params_->towerNBitsE())-1;
194 
195  if (ietIn>0)
196  LogDebug("L1TDebug") << " ECAL TP : " << ieta << ", " << iphi << ", " << ietIn << ", " << et << ", " << ietOut << std::endl;
197 
198  int itow = CaloTools::caloTowerHash(ieta, iphi);
199  localInTowers->at(itow).setHwEtEm(ietOut);// & ietOutMask);
200  localInTowers->at(itow).setHwQual( localInTowers->at(itow).hwQual() | (ifg ? 0x4 : 0x0) );
201 
202  }
203 
204  // loop over HCAL TPs
206  int nHcal=0;
207  for (hcalItr=hcalTPs->begin(); hcalItr!=hcalTPs->end(); ++hcalItr, ++nHcal) {
208 
209  int ieta = hcalItr->id().ieta();
210  int iphi = hcalItr->id().iphi();
211 
212  int ietIn = hcalItr->SOI_compressedEt();
213  //int ifg = hcalItr->SOI_fineGrain();
214 
215  // decompress
216  double et = hcalScale->et( ietIn, abs(ieta), (ieta>0) );
217  int ietOut = floor( et / params_->towerLsbH() );
218  // int ietOutMask = (int) pow(2,params_->towerNBitsH() )-1;
219 
220  if (ietIn>0)
221  LogDebug("L1TDebug") << " HCAL TP : " << ieta << ", " << iphi << ", " << ietIn << ", " << et << ", " << ietOut << std::endl;
222 
223  int itow = CaloTools::caloTowerHash(ieta, iphi);
224  localInTowers->at(itow).setHwEtHad(ietOut);// & ietOutMask);
225  // towers.at(itow).setHwFGHad(ifg);
226 
227  }
228 
229  // now calculate remaining tower quantities
230  for (int ieta=ietaMin_; ieta<ietaMax_+1; ieta++) {
231 
232  for (int iphi=iphiMin_; iphi<iphiMax_+1; iphi++) {
233 
234  if(!CaloTools::isValidIEtaIPhi(ieta,iphi)) continue;
235 
236  int itow = CaloTools::caloTowerHash(ieta, iphi);
237 
238  // get ECAL/HCAL raw numbers
239  int ietEcal = localInTowers->at(itow).hwEtEm();
240  int ietHcal = localInTowers->at(itow).hwEtHad();
241 
242  // const LorentzVector& p4;
243  int iet = ietEcal + ietHcal; // this is nonsense, temp solution!
244 
245  //LogDebug("L1TDebug") << " Tower : " << ieta << ", " << iphi << ", " << iet << ", " << ietEcal << ", " << ietHcal << std::endl;
246 
247  localInTowers->at(itow).setHwPt(iet);
248  localInTowers->at(itow).setHwEta(ieta);
249  localInTowers->at(itow).setHwPhi(iphi);
250 
251  }
252  }
253 
254  // do the decompression
255  processor_->processEvent(*localInTowers, *localOutTowers);
256 
257  // copy towers to output collection
258  for(std::vector<CaloTower>::const_iterator tower = localOutTowers->begin();
259  tower != localOutTowers->end();
260  ++tower)
261  towersColl->push_back(ibx, *tower);
262 
263  LogDebug("L1TDebug") << "BX=" << ibx << ", N(Tower in)=" << localInTowers->size() << ", N(Tower out)=" << localOutTowers->size() << std::endl;
264 
265  }
266 
267  iEvent.put(towersColl);
268 
269 }
270 
271 // ------------ method called once each job just before starting event loop ------------
272 void
274 {
275 }
276 
277 // ------------ method called once each job just after ending the event loop ------------
278 void
280 }
281 
282 // ------------ method called when starting to processes a run ------------
283 void
285 {
286 
287  // update parameters and algorithms at run start, if they have changed
288  // update params first because the firmware factory relies on pointer to params
289 
290  // parameters
291 
292  unsigned long long id = iSetup.get<L1TCaloParamsRcd>().cacheIdentifier();
293 
294  if (id != paramsCacheId_) {
295 
296  paramsCacheId_ = id;
297 
298  edm::ESHandle<CaloParams> paramsHandle;
299  iSetup.get<L1TCaloParamsRcd>().get(paramsHandle);
300 
301  // replace our local copy of the parameters with a new one using placement new
303  params_ = new (params_) CaloParamsHelper(*paramsHandle.product());
304 
305  LogDebug("L1TDebug") << *params_ << std::endl;
306 
307  if (! params_){
308  edm::LogError("l1t|caloStage2") << "Could not retrieve params from Event Setup" << std::endl;
309  }
310 
311  }
312 
313  // firmware
314 
315  if ( !processor_ ) { // in future, also check if the firmware cache ID has changed !
316 
317  // m_fwv = ; // get new firmware version in future
318 
319  // Set the current algorithm version based on DB pars from database:
321 
322  LogDebug("L1TDebug") << "Processor object : " << (processor_?1:0) << std::endl;
323 
324  if (! processor_) {
325  // we complain here once per run
326  edm::LogError("l1t|caloStage2") << "Layer 1 firmware could not be configured.\n";
327  }
328 
329  }
330 
331 
332 }
333 
334 
335 // ------------ method called when ending the processing of a run ------------
336 void
338 {
339 }
340 
341 // ------------ method called when starting to processes a luminosity block ------------
342 /*
343 void
344 L1TStage2Layer1Producer::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup cons
345 t&)
346 {
347 }
348 */
349 
350 // ------------ method called when ending the processing of a luminosity block ------------
351 /*
352 void
353 L1TStage2Layer1Producer::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&
354 )
355 {
356 }
357 */
358 
359 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
360 void
362  //The following says we do not know what parameters are allowed so do no validation
363  // Please change this to state exactly what you do use, even if it is no parameters
365  desc.setUnknown();
366  descriptions.addDefault(desc);
367 }
368 
369 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
boost::shared_ptr< Stage2PreProcessor > processor_
std::vector< edm::EDGetToken > ecalToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void beginJob() override
std::vector< EcalTriggerPrimitiveDigi >::const_iterator const_iterator
void beginJob()
Definition: Breakpoints.cc:15
L1TStage2Layer1Producer(const edm::ParameterSet &ps)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
Stage2Layer1FirmwareFactory factory_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ReturnType create(unsigned fwv, CaloParamsHelper *params)
std::vector< edm::EDGetToken > hcalToken_
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
double towerLsbE() const
virtual void produce(edm::Event &, const edm::EventSetup &) override
virtual void endJob() override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:43
double towerLsbH() const