CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BXVectorInputProducer.cc
Go to the documentation of this file.
1 
14 
15 // system include files
16 #include <boost/shared_ptr.hpp>
17 
18 // user include files
19 
30 
31 //#include <vector>
33 
39 
44 
45 #include "TMath.h"
46 
47 using namespace std;
48 using namespace edm;
49 
50 #ifndef M_PI
51 #define M_PI 3.14159265358979323846
52 #endif
53 
54 namespace l1t {
55 
56 //
57 // class declaration
58 //
59 
61  public:
62  explicit BXVectorInputProducer(const ParameterSet&);
64 
65  static void fillDescriptions(ConfigurationDescriptions& descriptions);
66 
67  private:
68  virtual void produce(Event&, EventSetup const&);
69  virtual void beginJob();
70  virtual void endJob();
71  virtual void beginRun(Run const&iR, EventSetup const&iE);
72  virtual void endRun(Run const& iR, EventSetup const& iE);
73 
74  int convertPhiToHW(double iphi, int steps);
75  int convertEtaToHW(double ieta, double minEta, double maxEta, int steps);
76  int convertPtToHW(double ipt, int maxPt, double step);
77 
78  // ----------member data ---------------------------
79  unsigned long long m_paramsCacheId; // Cache-ID from current parameters, to check if needs to be updated.
80  //boost::shared_ptr<const CaloParams> m_dbpars; // Database parameters for the trigger, to be updated as needed.
81  //boost::shared_ptr<const FirmwareVersion> m_fwv;
82  //boost::shared_ptr<FirmwareVersion> m_fwv; //not const during testing.
83 
84  // BX parameters
85  int bxFirst_;
86  int bxLast_;
87 
88  unsigned int maxNumMuCands_;
89  unsigned int maxNumJetCands_;
90  unsigned int maxNumEGCands_;
91  unsigned int maxNumTauCands_;
92 
97 
98  // Control how to end the job
102 
103  // Tokens for inputs from other parts of the L1 system
109 
110  int counter_;
111 
112  std::vector<l1t::Muon> muonVec_bxm2;
113  std::vector<l1t::Muon> muonVec_bxm1;
114  std::vector<l1t::Muon> muonVec_bx0;
115  std::vector<l1t::Muon> muonVec_bxp1;
116 
117  std::vector<l1t::EGamma> egammaVec_bxm2;
118  std::vector<l1t::EGamma> egammaVec_bxm1;
119  std::vector<l1t::EGamma> egammaVec_bx0;
120  std::vector<l1t::EGamma> egammaVec_bxp1;
121 
122  std::vector<l1t::Tau> tauVec_bxm2;
123  std::vector<l1t::Tau> tauVec_bxm1;
124  std::vector<l1t::Tau> tauVec_bx0;
125  std::vector<l1t::Tau> tauVec_bxp1;
126 
127  std::vector<l1t::Jet> jetVec_bxm2;
128  std::vector<l1t::Jet> jetVec_bxm1;
129  std::vector<l1t::Jet> jetVec_bx0;
130  std::vector<l1t::Jet> jetVec_bxp1;
131 
132  std::vector<l1t::EtSum> etsumVec_bxm2;
133  std::vector<l1t::EtSum> etsumVec_bxm1;
134  std::vector<l1t::EtSum> etsumVec_bx0;
135  std::vector<l1t::EtSum> etsumVec_bxp1;
136 
137  };
138 
139  //
140  // constructors and destructor
141  //
142  BXVectorInputProducer::BXVectorInputProducer(const ParameterSet& iConfig)
143  {
144 
145  egToken = consumes<BXVector<l1t::EGamma>>(iConfig.getParameter<InputTag>("egInputTag"));
146  muToken = consumes<BXVector<l1t::Muon>>(iConfig.getParameter<InputTag>("muInputTag"));
147  tauToken = consumes<BXVector<l1t::Tau>>(iConfig.getParameter<InputTag>("tauInputTag"));
148  jetToken = consumes<BXVector<l1t::Jet>>(iConfig.getParameter<InputTag>("jetInputTag"));
149  etsumToken = consumes<BXVector<l1t::EtSum>>(iConfig.getParameter<InputTag>("etsumInputTag"));
150 
151  // register what you produce
152  produces<BXVector<l1t::EGamma>>();
153  produces<BXVector<l1t::Muon>>();
154  produces<BXVector<l1t::Tau>>();
155  produces<BXVector<l1t::Jet>>();
156  produces<BXVector<l1t::EtSum>>();
157 
158  // Setup parameters
159  bxFirst_ = iConfig.getParameter<int>("bxFirst");
160  bxLast_ = iConfig.getParameter<int>("bxLast");
161 
162  maxNumMuCands_ = iConfig.getParameter<unsigned int>("maxMuCand");
163  maxNumJetCands_ = iConfig.getParameter<unsigned int>("maxJetCand");
164  maxNumEGCands_ = iConfig.getParameter<unsigned int>("maxEGCand");
165  maxNumTauCands_ = iConfig.getParameter<unsigned int>("maxTauCand");
166 
167  jetEtThreshold_ = iConfig.getParameter<double>("jetEtThreshold");
168  tauEtThreshold_ = iConfig.getParameter<double>("tauEtThreshold");
169  egEtThreshold_ = iConfig.getParameter<double>("egEtThreshold");
170  muEtThreshold_ = iConfig.getParameter<double>("muEtThreshold");
171 
172 
173  emptyBxTrailer_ = iConfig.getParameter<int>("emptyBxTrailer");
174  emptyBxEvt_ = iConfig.getParameter<int>("emptyBxEvt");
175 
176 
177  // set cache id to zero, will be set at first beginRun:
178  m_paramsCacheId = 0;
179  eventCnt_ = 0;
180  }
181 
182 
183  BXVectorInputProducer::~BXVectorInputProducer()
184  {
185  }
186 
187 
188 
189 //
190 // member functions
191 //
192 
193 // ------------ method called to produce the data ------------
194 void
195 BXVectorInputProducer::produce(Event& iEvent, const EventSetup& iSetup)
196 {
197 
198  eventCnt_++;
199 
200  LogDebug("l1t|Global") << "BXVectorInputProducer::produce function called...\n";
201 
202  // Setup vectors
203  std::vector<l1t::Muon> muonVec;
204  std::vector<l1t::EGamma> egammaVec;
205  std::vector<l1t::Tau> tauVec;
206  std::vector<l1t::Jet> jetVec;
207  std::vector<l1t::EtSum> etsumVec;
208 
209  // Set the range of BX....TO DO...move to Params or determine from param set.
210  int bxFirst = bxFirst_;
211  int bxLast = bxLast_;
212 
213  //outputs
214  std::auto_ptr<l1t::EGammaBxCollection> egammas (new l1t::EGammaBxCollection(0, bxFirst, bxLast));
215  std::auto_ptr<l1t::MuonBxCollection> muons (new l1t::MuonBxCollection(0, bxFirst, bxLast));
216  std::auto_ptr<l1t::TauBxCollection> taus (new l1t::TauBxCollection(0, bxFirst, bxLast));
217  std::auto_ptr<l1t::JetBxCollection> jets (new l1t::JetBxCollection(0, bxFirst, bxLast));
218  std::auto_ptr<l1t::EtSumBxCollection> etsums (new l1t::EtSumBxCollection(0, bxFirst, bxLast));
219 
220  std::vector<int> mu_cands_index;
221  std::vector<int> eg_cands_index;
222  std::vector<int> tau_cands_index;
223 
224 
225  // Bx to use...grab only bx=0 for now
226  int bx=0;
227 
228  // Make sure that you can get input EG
229  Handle<BXVector<l1t::EGamma>> inputEgammas;
230  if( iEvent.getByToken(egToken, inputEgammas) ){
231 
232  for(std::vector<l1t::EGamma>::const_iterator eg = inputEgammas->begin(bx); eg != inputEgammas->end(bx); ++eg) {
233 
234  if(eg->hwPt()>egEtThreshold_ && egammaVec.size() < maxNumEGCands_ ) {
235  egammaVec.push_back((*eg));
236  }
237 
238  }
239  }
240  else {
241  LogTrace("l1t|Global") << ">>> input EG collection not found!" << std::endl;
242  }
243 
244  // Make sure that you can get input Muons
245  Handle<BXVector<l1t::Muon>> inputMuons;
246  if( iEvent.getByToken(muToken,inputMuons) ){
247 
248  for(std::vector<l1t::Muon>::const_iterator mu = inputMuons->begin(bx); mu != inputMuons->end(bx); ++mu) {
249 
250  if(mu->hwPt()>muEtThreshold_ && muonVec.size() < maxNumMuCands_ ) {
251  muonVec.push_back((*mu));
252  }
253 
254  }
255  }
256  else {
257  LogTrace("l1t|Global") << ">>> input Mu collection not found!" << std::endl;
258  }
259 
260 
261  // Make sure that you can get input Tau
262  Handle<BXVector<l1t::Tau>> inputTaus;
263  if( iEvent.getByToken(tauToken, inputTaus) ){
264 
265  for(std::vector<l1t::Tau>::const_iterator tau = inputTaus->begin(bx); tau != inputTaus->end(bx); ++tau) {
266 
267  if(tau->hwPt()>tauEtThreshold_ && tauVec.size() < maxNumTauCands_ ) {
268  tauVec.push_back((*tau));
269  }
270 
271  }
272  }
273  else {
274  LogTrace("l1t|Global") << ">>> input tau collection not found!" << std::endl;
275  }
276 
277 
278  // Make sure that you can get input jet
280  if( iEvent.getByToken(jetToken, inputJets) ){
281 
282  for(std::vector<l1t::Jet>::const_iterator jet = inputJets->begin(bx); jet != inputJets->end(bx); ++jet) {
283 
284  if(jet->hwPt()>jetEtThreshold_ && jetVec.size() < maxNumJetCands_ ) {
285  jetVec.push_back((*jet));
286  }
287 
288  }
289  }
290  else {
291  LogTrace("l1t|Global") << ">>> input jet collection not found!" << std::endl;
292  }
293 
294 
295  // Make sure that you can get input etsum
296  Handle<BXVector<l1t::EtSum>> inputEtsums;
297  if( iEvent.getByToken(etsumToken, inputEtsums) ){
298 
299  for(std::vector<l1t::EtSum>::const_iterator etsum = inputEtsums->begin(bx); etsum != inputEtsums->end(bx); ++etsum) {
300 
301  etsumVec.push_back((*etsum));
302 
303  }
304  }
305  else {
306  LogTrace("l1t|Global") << ">>> input etsum collection not found!" << std::endl;
307  }
308 
309 
310  // Insert all the bx into the L1 Collections
311  LogTrace("l1t|Global") << "Event " << eventCnt_ << " EmptyBxEvt " << emptyBxEvt_ << " emptyBxTrailer " << emptyBxTrailer_ << " diff " << (emptyBxEvt_ - eventCnt_) << std::endl;
312 
313 
314  // Fill Muons
315  for( int iMu=0; iMu<int(muonVec_bxm2.size()); iMu++ ){
316  muons->push_back(-2, muonVec_bxm2[iMu]);
317  }
318  for( int iMu=0; iMu<int(muonVec_bxm1.size()); iMu++ ){
319  muons->push_back(-1, muonVec_bxm1[iMu]);
320  }
321  for( int iMu=0; iMu<int(muonVec_bx0.size()); iMu++ ){
322  muons->push_back(0, muonVec_bx0[iMu]);
323  }
324  for( int iMu=0; iMu<int(muonVec_bxp1.size()); iMu++ ){
325  muons->push_back(1, muonVec_bxp1[iMu]);
326  }
327  if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
328  for( int iMu=0; iMu<int(muonVec.size()); iMu++ ){
329  muons->push_back(2, muonVec[iMu]);
330  }
331  } else {
332  // this event is part of empty trailer...clear out data
333  muonVec.clear();
334  }
335 
336  // Fill Egammas
337  for( int iEG=0; iEG<int(egammaVec_bxm2.size()); iEG++ ){
338  egammas->push_back(-2, egammaVec_bxm2[iEG]);
339  }
340  for( int iEG=0; iEG<int(egammaVec_bxm1.size()); iEG++ ){
341  egammas->push_back(-1, egammaVec_bxm1[iEG]);
342  }
343  for( int iEG=0; iEG<int(egammaVec_bx0.size()); iEG++ ){
344  egammas->push_back(0, egammaVec_bx0[iEG]);
345  }
346  for( int iEG=0; iEG<int(egammaVec_bxp1.size()); iEG++ ){
347  egammas->push_back(1, egammaVec_bxp1[iEG]);
348  }
349  if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
350  for( int iEG=0; iEG<int(egammaVec.size()); iEG++ ){
351  egammas->push_back(2, egammaVec[iEG]);
352  }
353  } else {
354  // this event is part of empty trailer...clear out data
355  egammaVec.clear();
356  }
357 
358  // Fill Taus
359  for( int iTau=0; iTau<int(tauVec_bxm2.size()); iTau++ ){
360  taus->push_back(-2, tauVec_bxm2[iTau]);
361  }
362  for( int iTau=0; iTau<int(tauVec_bxm1.size()); iTau++ ){
363  taus->push_back(-1, tauVec_bxm1[iTau]);
364  }
365  for( int iTau=0; iTau<int(tauVec_bx0.size()); iTau++ ){
366  taus->push_back(0, tauVec_bx0[iTau]);
367  }
368  for( int iTau=0; iTau<int(tauVec_bxp1.size()); iTau++ ){
369  taus->push_back(1, tauVec_bxp1[iTau]);
370  }
371  if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
372  for( int iTau=0; iTau<int(tauVec.size()); iTau++ ){
373  taus->push_back(2, tauVec[iTau]);
374  }
375  } else {
376  // this event is part of empty trailer...clear out data
377  tauVec.clear();
378  }
379 
380  // Fill Jets
381  for( int iJet=0; iJet<int(jetVec_bxm2.size()); iJet++ ){
382  jets->push_back(-2, jetVec_bxm2[iJet]);
383  }
384  for( int iJet=0; iJet<int(jetVec_bxm1.size()); iJet++ ){
385  jets->push_back(-1, jetVec_bxm1[iJet]);
386  }
387  for( int iJet=0; iJet<int(jetVec_bx0.size()); iJet++ ){
388  jets->push_back(0, jetVec_bx0[iJet]);
389  }
390  for( int iJet=0; iJet<int(jetVec_bxp1.size()); iJet++ ){
391  jets->push_back(1, jetVec_bxp1[iJet]);
392  }
393  if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
394  for( int iJet=0; iJet<int(jetVec.size()); iJet++ ){
395  jets->push_back(2, jetVec[iJet]);
396  }
397  } else {
398  // this event is part of empty trailer...clear out data
399  jetVec.clear();
400  }
401 
402  // Fill Etsums
403  for( int iETsum=0; iETsum<int(etsumVec_bxm2.size()); iETsum++ ){
404  etsums->push_back(-2, etsumVec_bxm2[iETsum]);
405  }
406  for( int iETsum=0; iETsum<int(etsumVec_bxm1.size()); iETsum++ ){
407  etsums->push_back(-1, etsumVec_bxm1[iETsum]);
408  }
409  for( int iETsum=0; iETsum<int(etsumVec_bx0.size()); iETsum++ ){
410  etsums->push_back(0, etsumVec_bx0[iETsum]);
411  }
412  for( int iETsum=0; iETsum<int(etsumVec_bxp1.size()); iETsum++ ){
413  etsums->push_back(1, etsumVec_bxp1[iETsum]);
414  }
415  if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
416  for( int iETsum=0; iETsum<int(etsumVec.size()); iETsum++ ){
417  etsums->push_back(2, etsumVec[iETsum]);
418  }
419  } else {
420  // this event is part of empty trailer...clear out data
421  etsumVec.clear();
422  }
423 
424 
425  iEvent.put(egammas);
426  iEvent.put(muons);
427  iEvent.put(taus);
428  iEvent.put(jets);
429  iEvent.put(etsums);
430 
431  // Now shift the bx data by one to prepare for next event.
432  muonVec_bxm2 = muonVec_bxm1;
433  egammaVec_bxm2 = egammaVec_bxm1;
434  tauVec_bxm2 = tauVec_bxm1;
435  jetVec_bxm2 = jetVec_bxm1;
436  etsumVec_bxm2 = etsumVec_bxm1;
437 
438  muonVec_bxm1 = muonVec_bx0;
439  egammaVec_bxm1 = egammaVec_bx0;
440  tauVec_bxm1 = tauVec_bx0;
441  jetVec_bxm1 = jetVec_bx0;
442  etsumVec_bxm1 = etsumVec_bx0;
443 
444  muonVec_bx0 = muonVec_bxp1;
445  egammaVec_bx0 = egammaVec_bxp1;
446  tauVec_bx0 = tauVec_bxp1;
447  jetVec_bx0 = jetVec_bxp1;
448  etsumVec_bx0 = etsumVec_bxp1;
449 
450  muonVec_bxp1 = muonVec;
451  egammaVec_bxp1 = egammaVec;
452  tauVec_bxp1 = tauVec;
453  jetVec_bxp1 = jetVec;
454  etsumVec_bxp1 = etsumVec;
455 
456 }
457 
458 // ------------ method called once each job just before starting event loop ------------
459 void
461 {
462 }
463 
464 // ------------ method called once each job just after ending the event loop ------------
465 void
466 BXVectorInputProducer::endJob() {
467 }
468 
469 // ------------ method called when starting to processes a run ------------
470 
471 void BXVectorInputProducer::beginRun(Run const&iR, EventSetup const&iE){
472 
473  LogDebug("l1t|Global") << "BXVectorInputProducer::beginRun function called...\n";
474 
475  counter_ = 0;
476 }
477 
478 // ------------ method called when ending the processing of a run ------------
479 void BXVectorInputProducer::endRun(Run const& iR, EventSetup const& iE){
480 
481 }
482 
483 
484 // ------------ methods to convert from physical to HW values ------------
485 int BXVectorInputProducer::convertPhiToHW(double iphi, int steps){
486 
487  double phiMax = 2 * M_PI;
488  if( iphi < 0 ) iphi += 2*M_PI;
489  if( iphi > phiMax) iphi -= phiMax;
490 
491  int hwPhi = int( (iphi/phiMax)*steps + 0.00001 );
492  return hwPhi;
493 }
494 
495 int BXVectorInputProducer::convertEtaToHW(double ieta, double minEta, double maxEta, int steps){
496 
497  double binWidth = (maxEta - minEta)/steps;
498 
499  //if we are outside the limits, set error
500  if(ieta < minEta) return 99999;//ieta = minEta+binWidth/2.;
501  if(ieta > maxEta) return 99999;//ieta = maxEta-binWidth/2.;
502 
503  int binNum = (int)(ieta/binWidth);
504  if(ieta<0.) binNum--;
505 
506 // unsigned int hwEta = binNum & bitMask;
507 // Remove masking for BXVectors...only assume in raw data
508 
509  return binNum;
510 }
511 
512 int BXVectorInputProducer::convertPtToHW(double ipt, int maxPt, double step){
513 
514  int hwPt = int( ipt/step + 0.0001 );
515  // if above max Pt, set to largest value
516  if( hwPt > maxPt ) hwPt = maxPt;
517 
518  return hwPt;
519 }
520 
521 
522 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
523 void
524 BXVectorInputProducer::fillDescriptions(ConfigurationDescriptions& descriptions) {
525  //The following says we do not know what parameters are allowed so do no validation
526  // Please change this to state exactly what you do use, even if it is no parameters
528  desc.setUnknown();
529  descriptions.addDefault(desc);
530 }
531 
532 } // namespace
533 
534 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
std::vector< l1t::Jet > jetVec_bxp1
std::vector< l1t::Muon > muonVec_bx0
std::vector< l1t::EGamma > egammaVec_bxm1
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< l1t::EtSum > etsumVec_bxm2
std::vector< l1t::EGamma > egammaVec_bxp1
std::vector< l1t::Jet > jetVec_bx0
std::vector< l1t::EGamma > egammaVec_bxm2
std::vector< l1t::Jet > jetVec_bxm2
double maxEta
std::vector< l1t::Tau > tauVec_bxm2
std::vector< l1t::EtSum > etsumVec_bx0
void beginJob()
Definition: Breakpoints.cc:15
std::vector< l1t::Jet > jetVec_bxm1
int iEvent
Definition: GenABIO.cc:230
std::vector< l1t::Tau > tauVec_bxm1
std::vector< l1t::EtSum > etsumVec_bxm1
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< l1t::Muon > muonVec_bxp1
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
std::vector< l1t::Tau > tauVec_bx0
vector< PseudoJet > jets
std::vector< l1t::EGamma > egammaVec_bx0
const int mu
Definition: Constants.h:22
#define LogTrace(id)
#define M_PI
std::vector< l1t::EtSum > etsumVec_bxp1
std::vector< l1t::Muon > muonVec_bxm1
tuple muons
Definition: patZpeak.py:38
std::vector< l1t::Muon > muonVec_bxm2
std::vector< l1t::Tau > tauVec_bxp1
Definition: Run.h:43