CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESListOfFEDSProducer.cc
Go to the documentation of this file.
1 
2 //#include <FWCore/Framework/interface/Handle.h>
6 
10 
12 
13 // Ecal Mapping
16 
19 
20 
21 // Level 1 Trigger
26 
27 // EgammaCoreTools
30 
31 // Muon stuff
35 
36 // Jets stuff
39 #include <vector>
40 
41 
42 using namespace l1extra;
43 
44 
46 
47  debug_ = pset.getUntrackedParameter<bool>("debug");
48 
49 
50  // Pi0ListToIgnore_ = pset.getParameter<edm::InputTag>("Pi0ListToIgnore");
51 
52  EGamma_ = pset.getUntrackedParameter<bool>("EGamma",false);
53  Muon_ = pset.getUntrackedParameter<bool>("Muon",false);
54  Jets_ = pset.getUntrackedParameter<bool>("Jets",false);
55 
56  if (EGamma_ && Muon_) {
57  throw cms::Exception("ESListOfFEDSProducer") <<
58  " Wrong configuration : EGamma and Muon should not be true at the same time." ;
59  }
60 
61 
62  if (EGamma_) {
63 
64  EMl1TagIsolated_ = pset.getUntrackedParameter<edm::InputTag>("EM_l1TagIsolated");
65  EMl1TagNonIsolated_ = pset.getUntrackedParameter<edm::InputTag>("EM_l1TagNonIsolated");
66  EMdoIsolated_ = pset.getUntrackedParameter<bool>("EM_doIsolated",true);
67  EMdoNonIsolated_ = pset.getUntrackedParameter<bool>("EM_doNonIsolated",true);
68  EMregionEtaMargin_ = pset.getUntrackedParameter<double>("EM_regionEtaMargin",0.25);
69  EMregionPhiMargin_ = pset.getUntrackedParameter<double>("EM_regionPhiMargin",0.40);
70  Ptmin_iso_ = pset.getUntrackedParameter<double>("Ptmin_iso",0.);
71  Ptmin_noniso_ = pset.getUntrackedParameter<double>("Ptmin_noniso",0.);
72  }
73 
74  if (Muon_) {
75  MUregionEtaMargin_ = pset.getUntrackedParameter<double>("MU_regionEtaMargin",1.0);
76  MUregionPhiMargin_ = pset.getUntrackedParameter<double>("MU_regionPhiMargin",1.0);
77  Ptmin_muon_ = pset.getUntrackedParameter<double>("Ptmin_muon",0.);
78  MuonSource_ = pset.getUntrackedParameter<edm::InputTag>("MuonSource");
79  }
80 
81  if (Jets_) {
82  JETSregionEtaMargin_ = pset.getUntrackedParameter<double>("JETS_regionEtaMargin",1.0);
83  JETSregionPhiMargin_ = pset.getUntrackedParameter<double>("JETS_regionPhiMargin",1.0);
84  Ptmin_jets_ = pset.getUntrackedParameter<double>("Ptmin_jets",0.);
85  CentralSource_ = pset.getUntrackedParameter<edm::InputTag>("CentralSource");
86  ForwardSource_ = pset.getUntrackedParameter<edm::InputTag>("ForwardSource");
87  TauSource_ = pset.getUntrackedParameter<edm::InputTag>("TauSource");
88  JETSdoCentral_ = pset.getUntrackedParameter<bool>("JETS_doCentral",true);
89  JETSdoForward_ = pset.getUntrackedParameter<bool>("JETS_doForward",true);
90  JETSdoTau_ = pset.getUntrackedParameter<bool>("JETS_doTau",true);
91  }
92 
93 
94  OutputLabel_ = pset.getUntrackedParameter<std::string>("OutputLabel");
95 
96  TheMapping = new EcalElectronicsMapping();
97  first_ = true;
98 
99  TheESMapping = new ESElectronicsMapper(pset);
100 
101  produces<ESListOfFEDS>(OutputLabel_);
102 
103 
104 
105 }
106 
107 
108 
110  delete TheMapping;
111 }
112 
113 
115 }
116 
118 }
119 
121 
122  if (first_) {
124  iSetup.get< EcalMappingRcd >().get(ecalmapping);
125  const EcalElectronicsMapping* TheMapping_ = ecalmapping.product();
126  *TheMapping = *TheMapping_;
127  first_ = false;
128 
129  }
130 
131  std::auto_ptr<ESListOfFEDS> productAddress(new ESListOfFEDS);
132 
133  std::vector<int> feds; // the list of Ecal FEDS produced
134 
135 
137  std::vector<int> Done;
138  if (EGamma_) {
139  // feds = Egamma(e, iSetup, Done);
140  Egamma(e, iSetup, Done, feds);
141  }
142 
143  if (Muon_) {
145  // feds = Muon(e, iSetup, Done);
146  // Muon(e, iSetup, Done, feds);
147  }
148 
149  if (Jets_) {
150  // feds = Jets(e, iSetup, Done);
151  //Jets(e, iSetup, Done, feds);
152  }
153 
154  if ( !EGamma_ && !Muon_ && ! Jets_) {
155  for (int i=1; i <= 54; i++) {
156  if ( std::find(Done.begin(), Done.end(), i) == Done.end())
157  feds.push_back(i);
158  }
159  }
160 
161 
162  int nf = (int)feds.size();
163  for (int i=0; i <nf; i++) {
164  feds[i] += FEDNumbering::MINECALFEDID;
165  if (debug_) std::cout << "Will unpack FED " << feds[i] << std::endl;
166  }
167 
168  if (debug_ && nf < 1 )
169  std::cout << " Warning : no ECAL FED to unpack for Run " << e.id().run() << " Event " << e.id().event() << std::endl;
170 
172  std::vector<int> es_feds = TheESMapping->GetListofFEDs(feds);
173 
174  //check ES List if some of them already done
175  std::vector< edm::Handle<ESListOfFEDS> > esFEDs_Done;
176  e.getManyByType(esFEDs_Done);
177  unsigned int esnDone = esFEDs_Done.size();
178 
179  if(debug_){
180  std::cout<<int(es_feds.size())<<" feds requested, and ESunpacking have already been done "<<esnDone<<" times."<<std::endl;
181  }
182 
183  for(int i=0; i<int(esFEDs_Done.size());i++){
184  std::vector<int> done = esFEDs_Done[i]-> GetList();
185  for(int n=0; n<int(done.size());n++){
186  for(int j=0; j<int(es_feds.size());j++){
187  std::vector<int>::iterator it = find(es_feds.begin(),es_feds.end(),done[n]);
188  if( it != es_feds.end()){
189  es_feds.erase(it);
190  j--;
191  }
192  }
193  }
194  }
195 
196  if (debug_ ){
197  std::cout<<"ESListofFEDSProducer: new ES_list will be put into event: total "<<int(es_feds.size())<<std::endl;
198  for(int j=0; j<int(es_feds.size());j++){
199  std::cout<<es_feds[j]<<" ";
200  }
201  std::cout<<std::endl;
202  }
203 
204 
206  productAddress.get() -> SetList(es_feds);
207  e.put(productAddress,OutputLabel_);
208 
209 }
210 
211 
212 // std::vector<int> EcalListOfFEDSProducer::Egamma(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done) {
213 void ESListOfFEDSProducer::Egamma(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs ) {
214 
215  // std::vector<int> FEDs;
216 
217  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Egamma" << std::endl;
218 
219  //Get the L1 EM Particle Collection
220  //Get the L1 EM Particle Collection
222  if(EMdoIsolated_)
223  e.getByLabel(EMl1TagIsolated_, emIsolColl);
224  //Get the L1 EM Particle Collection
226  if (EMdoNonIsolated_)
227  e.getByLabel(EMl1TagNonIsolated_, emNonIsolColl);
228 
229  // Get the CaloGeometry
230  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
231  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
232 
233  if(EMdoIsolated_) {
234 
235  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin();
236  emItr != emIsolColl->end() ;++emItr ){
237 
238  float pt = emItr -> pt();
239  if (pt < Ptmin_iso_ ) continue;
240  if (debug_) std::cout << " Here is an L1 isoEM candidate of pt " << pt << std::endl;
241  // Access the GCT hardware object corresponding to the L1Extra EM object.
242  int etaIndex = emItr->gctEmCand()->etaIndex() ;
243  int phiIndex = emItr->gctEmCand()->phiIndex() ;
244  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
245  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
246  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
247  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
248  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
249 
250  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
251  for (int i=0; i < (int)feds.size(); i++) {
252  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
253  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
254  }
255 
256  } // end loop on L1EmParticleCollection
257 
258  } // endif doIsolated_
259 
260 
261  if (EMdoNonIsolated_) {
262 
263  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin();
264  emItr != emNonIsolColl->end() ;++emItr ){
265 
266  float pt = emItr -> pt();
267  if (debug_) std::cout << " Here is an L1 nonisoEM candidate of pt " << pt << std::endl;
268  if (pt < Ptmin_noniso_ ) continue;
269  // Access the GCT hardware object corresponding to the L1Extra EM object.
270  int etaIndex = emItr->gctEmCand()->etaIndex() ;
271  int phiIndex = emItr->gctEmCand()->phiIndex() ;
272  // std::cout << " etaIndex phiIndex " << etaIndex << " " << phiIndex << std::endl;
273  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
274  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
275  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
276  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
277  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
278 
279  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
280  for (int i=0; i < (int)feds.size(); i++) {
281  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
282  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
283 
284  }
285 
286  } // end loop on L1EmParticleCollection
287  }
288 
289  // std::cout << "end of get list of feds " << std::endl;
290 
291  if (debug_) {
292  std::cout << std::endl;
293  for (int i=0; i < (int)FEDs.size(); i++) {
294  std::cout << "Egamma: unpack FED " << FEDs[i] << std::endl;
295  }
296  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
297  }
298 
299  // return FEDs;
300 
301 }
302 
303 
304 // std::vector<int> EcalListOfFEDSProducer::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done) {
305 void ESListOfFEDSProducer::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
306 
307  // std::vector<int> FEDs;
308 
309  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Muon" << std::endl;
310 
312  e.getByLabel(MuonSource_, muColl);
313 
314 
315  double epsilon = 0.01;
316 
317  for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
318 
319  const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
320  double pt = (*it).pt();
321  double eta = (*it).eta();
322  double phi = (*it).phi();
323 
324  if (debug_) std::cout << " here is a L1 muon Seed with (eta,phi) = " <<
325  eta << " " << phi << " and pt " << pt << std::endl;
326  if (pt < Ptmin_muon_ ) continue;
327 
328  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, MUregionEtaMargin_, MUregionPhiMargin_);
329 
330  for (int i=0; i < (int)feds.size(); i++) {
331  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
332  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
333  }
334  }
335 
336  if (debug_) {
337  std::cout << std::endl;
338  for (int i=0; i < (int)FEDs.size(); i++) {
339  std::cout << "Muons: unpack FED " << FEDs[i] << std::endl;
340  }
341  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
342  }
343 
344 
345  // return FEDs;
346 
347 }
348 
349 
350 
351 // std::vector<int> EcalListOfFEDSProducer::Jets(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done) {
352 void ESListOfFEDSProducer::Jets(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
353 
354  // std::vector<int> FEDs;
355 
356  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Jets" << std::endl;
357  double epsilon = 0.01;
358 
359  // Get the CaloGeometry
360  // edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
361  // es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
362 
363  if (JETSdoCentral_) {
364 
366  e.getByLabel(CentralSource_,jetColl);
367 
368  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
369 
370  double pt = it -> pt();
371  double eta = it -> eta();
372  double phi = it -> phi();
373 
374  if (debug_) std::cout << " here is a L1 CentralJet Seed with (eta,phi) = " <<
375  eta << " " << phi << " and pt " << pt << std::endl;
376  // int etaIndex = it->gctJetCand()->etaIndex() ;
377  // int phiIndex = it->gctJetCand()->phiIndex() ;
378  // double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
379  // double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
380  // double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
381  // double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
382  // if (debug_) std::cout << " etaLow .. " << etaLow << " " << etaHigh << " " << phiLow << " " << phiHigh << std::endl;
383 
384  if (pt < Ptmin_jets_ ) continue;
385 
386  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
387 
388  for (int i=0; i < (int)feds.size(); i++) {
389  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
390  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
391  }
392  }
393  }
394 
395  if (JETSdoForward_) {
396 
398  e.getByLabel(ForwardSource_,jetColl);
399 
400  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
401 
402  double pt = it -> pt();
403  double eta = it -> eta();
404  double phi = it -> phi();
405 
406  if (debug_) std::cout << " here is a L1 ForwardJet Seed with (eta,phi) = " <<
407  eta << " " << phi << " and pt " << pt << std::endl;
408  if (pt < Ptmin_jets_ ) continue;
409 
410  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
411 
412  for (int i=0; i < (int)feds.size(); i++) {
413  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
414  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
415  }
416  }
417  }
418 
419  if (JETSdoTau_) {
420 
422  e.getByLabel(TauSource_,jetColl);
423 
424  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
425 
426  double pt = it -> pt();
427  double eta = it -> eta();
428  double phi = it -> phi();
429 
430  if (debug_) std::cout << " here is a L1 TauJet Seed with (eta,phi) = " <<
431  eta << " " << phi << " and pt " << pt << std::endl;
432  if (pt < Ptmin_jets_ ) continue;
433 
434  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
435 
436  for (int i=0; i < (int)feds.size(); i++) {
437  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
438  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
439  }
440  }
441  }
442 
443 
444 
445  if (debug_) {
446  std::cout << std::endl;
447  for (int i=0; i < (int)FEDs.size(); i++) {
448  std::cout << "Jets: unpack FED " << FEDs[i] << std::endl;
449  }
450  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
451  }
452 
453 
454  // return FEDs;
455 
456 }
457 
458 
459 std::vector<int> ESListOfFEDSProducer::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
460  double phiHigh, double etamargin, double phimargin)
461 {
462 
463  std::vector<int> FEDs;
464 
465  if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
466 
467 
468  if (debug_) std::cout << " etaLow etaHigh phiLow phiHigh " << etaLow << " " <<
469  etaHigh << " " << phiLow << " " << phiHigh << std::endl;
470 
471  etaLow -= etamargin;
472  etaHigh += etamargin;
473  double phiMinus = phiLow - phimargin;
474  double phiPlus = phiHigh + phimargin;
475 
476  bool all = false;
477  double dd = fabs(phiPlus-phiMinus);
478  if (debug_) std::cout << " dd = " << dd << std::endl;
479  if (dd > 2.*Geom::pi() ) all = true;
480 
481  while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
482  while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
483  if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
484 
485  double dphi = phiPlus - phiMinus;
486  if (dphi < 0) dphi += 2.*Geom::pi() ;
487  if (debug_) std::cout << "dphi = " << dphi << std::endl;
488  if (dphi > Geom::pi()) {
489  int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
490  int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
491  if (debug_) std::cout << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2 << std::endl;
492  if (fed_low1 == fed_low2) all = true;
493  int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
494  int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
495  if (debug_) std::cout << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2 << std::endl;
496  if (fed_hi1 == fed_hi2) all = true;
497  }
498 
499 
500  if (all) {
501  if (debug_) std::cout << " unpack everything in phi ! " << std::endl;
502  phiMinus = -20 * Geom::pi() / 180.; // -20 deg
503  phiPlus = -40 * Geom::pi() / 180.; // -20 deg
504  }
505 
506  if (debug_) std::cout << " with margins : " << etaLow << " " << etaHigh << " " <<
507  phiMinus << " " << phiPlus << std::endl;
508 
509 
510  const EcalEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
511 
512  FEDs = TheMapping -> GetListofFEDs(ecalregion);
513 
514 /*
515  if (debug_) {
516  int nn = (int)FEDs.size();
517  for (int ii=0; ii < nn; ii++) {
518  std::cout << "unpack fed " << FEDs[ii] << std::endl;
519  }
520  }
521 */
522 
523  return FEDs;
524 
525 }
526 
527 
528 
529 /*
530 bool EcalListOfFEDSProducer::PhiInbetween(double phiPlus,double phiMinus,double phiLow) {
531 
532  bool all = false;
533  // first, everything back between 0 and 2pi
534 
535  if (phiPlus < 0) phiPlus += 2.*Geom::pi();
536  if (phiMinus < 0) phiMinus += 2.*Geom::pi();
537  if (phiLow < 0) phiLow += 2.*Geom::pi();
538 
539  if (phiMinus <= phiPlus && phiPlus <= phiLow) all = true;
540  return all;
541 
542 }
543 */
544 
545 
546 
547 
548 
549 
550 
RunNumber_t run() const
Definition: EventID.h:42
void getManyByType(std::vector< Handle< PROD > > &results) const
Definition: Event.h:395
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void Muon(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
T eta() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
ESListOfFEDSProducer(const edm::ParameterSet &pset)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::vector< int > ListOfFEDS(double etaLow, double etaHigh, double phiLow, double phiHigh, double etamargin, double phimargin)
int j
Definition: DBlmapReader.cc:9
void Jets(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
void Egamma(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
void produce(edm::Event &e, const edm::EventSetup &c)
edm::EventID id() const
Definition: EventBase.h:56
double pi()
Definition: Pi.h:31
tuple cout
Definition: gather_cfg.py:121
const double epsilon
Definition: DDAxes.h:10