CMS 3D CMS Logo

ESListOfFEDSProducer.cc
Go to the documentation of this file.
1 
3 
7 
8 // Ecal Mapping
11 
12 
13 // Level 1 Trigger
16 
17 // EgammaCoreTools
20 
21 // Muon stuff
23 
26 
27 #include <vector>
28 
29 using namespace l1extra;
30 
32 
33  debug_ = pset.getUntrackedParameter<bool>("debug");
34 
35  // Pi0ListToIgnore_ = pset.getParameter<edm::InputTag>("Pi0ListToIgnore");
36  EGamma_ = pset.getUntrackedParameter<bool>("EGamma",false);
37  Muon_ = pset.getUntrackedParameter<bool>("Muon",false);
38  Jets_ = pset.getUntrackedParameter<bool>("Jets",false);
39 
40  if (EGamma_ && Muon_) {
41  throw cms::Exception("ESListOfFEDSProducer") <<
42  " Wrong configuration : EGamma and Muon should not be true at the same time." ;
43  }
44 
45  if (EGamma_) {
46  EMl1TagIsolated_ = consumes<l1extra::L1EmParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("EM_l1TagIsolated"));
47  EMl1TagNonIsolated_ = consumes<l1extra::L1EmParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("EM_l1TagNonIsolated"));
48  EMdoIsolated_ = pset.getUntrackedParameter<bool>("EM_doIsolated",true);
49  EMdoNonIsolated_ = pset.getUntrackedParameter<bool>("EM_doNonIsolated",true);
50  EMregionEtaMargin_ = pset.getUntrackedParameter<double>("EM_regionEtaMargin",0.25);
51  EMregionPhiMargin_ = pset.getUntrackedParameter<double>("EM_regionPhiMargin",0.40);
52  Ptmin_iso_ = pset.getUntrackedParameter<double>("Ptmin_iso",0.);
53  Ptmin_noniso_ = pset.getUntrackedParameter<double>("Ptmin_noniso",0.);
54  }
55 
56  if (Muon_) {
57  MUregionEtaMargin_ = pset.getUntrackedParameter<double>("MU_regionEtaMargin",1.0);
58  MUregionPhiMargin_ = pset.getUntrackedParameter<double>("MU_regionPhiMargin",1.0);
59  Ptmin_muon_ = pset.getUntrackedParameter<double>("Ptmin_muon",0.);
60  MuonSource_ = consumes<l1extra::L1MuonParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("MuonSource"));
61  }
62 
63  if (Jets_) {
64  JETSregionEtaMargin_ = pset.getUntrackedParameter<double>("JETS_regionEtaMargin",1.0);
65  JETSregionPhiMargin_ = pset.getUntrackedParameter<double>("JETS_regionPhiMargin",1.0);
66  Ptmin_jets_ = pset.getUntrackedParameter<double>("Ptmin_jets",0.);
67  CentralSource_ = consumes<l1extra::L1JetParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("CentralSource"));
68  ForwardSource_ = consumes<l1extra::L1JetParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("ForwardSource"));
69  TauSource_ = consumes<l1extra::L1JetParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("TauSource"));
70  JETSdoCentral_ = pset.getUntrackedParameter<bool>("JETS_doCentral",true);
71  JETSdoForward_ = pset.getUntrackedParameter<bool>("JETS_doForward",true);
72  JETSdoTau_ = pset.getUntrackedParameter<bool>("JETS_doTau",true);
73  }
74 
75  OutputLabel_ = pset.getUntrackedParameter<std::string>("OutputLabel");
76 
77  TheMapping = new EcalElectronicsMapping();
78  first_ = true;
79 
80  TheESMapping = new ESElectronicsMapper(pset);
81 
82  consumesMany<ESListOfFEDS>();
83  produces<ESListOfFEDS>(OutputLabel_);
84 }
85 
87  delete TheMapping;
88 }
89 
91 
93  desc.add<bool>("debug", false);
94  desc.add<bool>("EGamma", true);
95  desc.add<bool>("Muon", false);
96  desc.add<bool>("Jets", false);
97  desc.add<edm::InputTag>("EM_l1TagIsolated", edm::InputTag("l1extraParticles","Isolated"));
98  desc.add<edm::InputTag>("EM_l1TagNonIsolated", edm::InputTag("l1extraParticles","NonIsolated"));
99  desc.add<bool>("EM_doIsolated", true);
100  desc.add<bool>("EM_doNonIsolated", true);
101  desc.add<double>("EM_regionEtaMargin", 0.25);
102  desc.add<double>("EM_regionPhiMargin", 0.40);
103  desc.add<double>("Ptmin_iso", 5.0);
104  desc.add<double>("Ptmin_noniso", 5.0);
105  desc.add<double>("MU_regionEtaMargin", 1.0);
106  desc.add<double>("MU_regionPhiMargin", 1.0);
107  desc.add<double>("Ptmin_muon", 0.);
108  desc.add<edm::InputTag>("MuonSource", edm::InputTag("l1extraParticles"));
109  desc.add<double>("JETS_regionEtaMargin", 1.0);
110  desc.add<double>("JETS_regionPhiMargin", 1.0);
111  desc.add<double>("Ptmin_jets", 50.);
112  desc.add<edm::InputTag>("CentralSource", edm::InputTag("l1extraParticles","Central"));
113  desc.add<edm::InputTag>("ForwardSource", edm::InputTag("l1extraParticles","Forward"));
114  desc.add<edm::InputTag>("TauSource", edm::InputTag("l1extraParticles","Tau"));
115  desc.add<bool>("JETS_doCentral", true);
116  desc.add<bool>("JETS_doForward", true);
117  desc.add<bool>("JETS_doTau", true);
118  desc.add<std::string>("OutputLabel", "");
119  descriptions.add(("hltESListOfFEDSProducer"), desc);
120 }
121 
122 
124 
125  if (first_) {
127  iSetup.get< EcalMappingRcd >().get(ecalmapping);
128  const EcalElectronicsMapping* TheMapping_ = ecalmapping.product();
129  *TheMapping = *TheMapping_;
130  first_ = false;
131  }
132 
133  auto productAddress = std::make_unique<ESListOfFEDS>();
134  std::vector<int> feds; // the list of Ecal FEDS produced
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(std::move(productAddress),OutputLabel_);
208 
209 }
210 
211 void ESListOfFEDSProducer::Egamma(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs ) {
212 
213  // std::vector<int> FEDs;
214 
215  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Egamma" << std::endl;
216 
217  //Get the L1 EM Particle Collection
219  if(EMdoIsolated_)
220  e.getByToken(EMl1TagIsolated_, emIsolColl);
221  //Get the L1 EM Particle Collection
223  if (EMdoNonIsolated_)
224  e.getByToken(EMl1TagNonIsolated_, emNonIsolColl);
225 
226  // Get the CaloGeometry
227  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
228  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
229 
230  if(EMdoIsolated_) {
231 
232  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin();
233  emItr != emIsolColl->end() ;++emItr ){
234 
235  float pt = emItr -> pt();
236  if (pt < Ptmin_iso_ ) continue;
237  if (debug_) std::cout << " Here is an L1 isoEM candidate of pt " << pt << std::endl;
238  // Access the GCT hardware object corresponding to the L1Extra EM object.
239  int etaIndex = emItr->gctEmCand()->etaIndex() ;
240  int phiIndex = emItr->gctEmCand()->phiIndex() ;
241  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
242  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
243  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
244  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
245  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
246 
247  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
248  for (int i=0; i < (int)feds.size(); i++) {
249  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
250  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
251  }
252  } // end loop on L1EmParticleCollection
253  } // endif doIsolated_
254 
255  if (EMdoNonIsolated_) {
256 
257  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin();
258  emItr != emNonIsolColl->end() ;++emItr ){
259 
260  float pt = emItr -> pt();
261  if (debug_) std::cout << " Here is an L1 nonisoEM candidate of pt " << pt << std::endl;
262  if (pt < Ptmin_noniso_ ) continue;
263  // Access the GCT hardware object corresponding to the L1Extra EM object.
264  int etaIndex = emItr->gctEmCand()->etaIndex() ;
265  int phiIndex = emItr->gctEmCand()->phiIndex() ;
266  // std::cout << " etaIndex phiIndex " << etaIndex << " " << phiIndex << std::endl;
267  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
268  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
269  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
270  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
271  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
272 
273  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
274  for (int i=0; i < (int)feds.size(); i++) {
275  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
276  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
277 
278  }
279  } // end loop on L1EmParticleCollection
280  }
281 
282  if (debug_) {
283  std::cout << std::endl;
284  for (int i=0; i < (int)FEDs.size(); i++) {
285  std::cout << "Egamma: unpack FED " << FEDs[i] << std::endl;
286  }
287  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
288  }
289 
290  // return FEDs;
291 
292 }
293 
294 void ESListOfFEDSProducer::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
295 
296  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Muon" << std::endl;
298  e.getByToken(MuonSource_, muColl);
299 
300  double epsilon = 0.01;
301 
302  for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
303 
304  const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
305  double pt = (*it).pt();
306  double eta = (*it).eta();
307  double phi = (*it).phi();
308 
309  if (debug_) std::cout << " here is a L1 muon Seed with (eta,phi) = " <<
310  eta << " " << phi << " and pt " << pt << std::endl;
311  if (pt < Ptmin_muon_ ) continue;
312 
313  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, MUregionEtaMargin_, MUregionPhiMargin_);
314 
315  for (int i=0; i < (int)feds.size(); i++) {
316  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
317  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
318  }
319  }
320 
321  if (debug_) {
322  std::cout << std::endl;
323  for (int i=0; i < (int)FEDs.size(); i++) {
324  std::cout << "Muons: unpack FED " << FEDs[i] << std::endl;
325  }
326  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
327  }
328 
329  // return FEDs;
330 
331 }
332 
333 void ESListOfFEDSProducer::Jets(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
334 
335  // std::vector<int> FEDs;
336 
337  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Jets" << std::endl;
338  double epsilon = 0.01;
339 
340  if (JETSdoCentral_) {
341 
343  e.getByToken(CentralSource_,jetColl);
344 
345  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
346 
347  double pt = it -> pt();
348  double eta = it -> eta();
349  double phi = it -> phi();
350 
351  if (debug_) std::cout << " here is a L1 CentralJet Seed with (eta,phi) = " <<
352  eta << " " << phi << " and pt " << pt << std::endl;
353  if (pt < Ptmin_jets_ ) continue;
354 
355  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
356 
357  for (int i=0; i < (int)feds.size(); i++) {
358  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
359  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
360  }
361  }
362  }
363 
364  if (JETSdoForward_) {
365 
367  e.getByToken(ForwardSource_,jetColl);
368 
369  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
370 
371  double pt = it -> pt();
372  double eta = it -> eta();
373  double phi = it -> phi();
374 
375  if (debug_) std::cout << " here is a L1 ForwardJet Seed with (eta,phi) = " <<
376  eta << " " << phi << " and pt " << pt << std::endl;
377  if (pt < Ptmin_jets_ ) continue;
378 
379  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
380 
381  for (int i=0; i < (int)feds.size(); i++) {
382  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
383  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
384  }
385  }
386  }
387 
388  if (JETSdoTau_) {
389 
391  e.getByToken(TauSource_,jetColl);
392 
393  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
394 
395  double pt = it -> pt();
396  double eta = it -> eta();
397  double phi = it -> phi();
398 
399  if (debug_) std::cout << " here is a L1 TauJet Seed with (eta,phi) = " <<
400  eta << " " << phi << " and pt " << pt << std::endl;
401  if (pt < Ptmin_jets_ ) continue;
402 
403  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
404 
405  for (int i=0; i < (int)feds.size(); i++) {
406  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
407  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
408  }
409  }
410  }
411 
412  if (debug_) {
413  std::cout << std::endl;
414  for (int i=0; i < (int)FEDs.size(); i++) {
415  std::cout << "Jets: unpack FED " << FEDs[i] << std::endl;
416  }
417  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
418  }
419 
420  // return FEDs;
421 }
422 
423 
424 std::vector<int> ESListOfFEDSProducer::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
425  double phiHigh, double etamargin, double phimargin)
426 {
427 
428  std::vector<int> FEDs;
429 
430  if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
431 
432 
433  if (debug_) std::cout << " etaLow etaHigh phiLow phiHigh " << etaLow << " " <<
434  etaHigh << " " << phiLow << " " << phiHigh << std::endl;
435 
436  etaLow -= etamargin;
437  etaHigh += etamargin;
438  double phiMinus = phiLow - phimargin;
439  double phiPlus = phiHigh + phimargin;
440 
441  bool all = false;
442  double dd = fabs(phiPlus-phiMinus);
443  if (debug_) std::cout << " dd = " << dd << std::endl;
444  if (dd > 2.*Geom::pi() ) all = true;
445 
446  while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
447  while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
448  if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
449 
450  double dphi = phiPlus - phiMinus;
451  if (dphi < 0) dphi += 2.*Geom::pi() ;
452  if (debug_) std::cout << "dphi = " << dphi << std::endl;
453  if (dphi > Geom::pi()) {
454  int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
455  int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
456  if (debug_) std::cout << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2 << std::endl;
457  if (fed_low1 == fed_low2) all = true;
458  int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
459  int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
460  if (debug_) std::cout << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2 << std::endl;
461  if (fed_hi1 == fed_hi2) all = true;
462  }
463 
464 
465  if (all) {
466  if (debug_) std::cout << " unpack everything in phi ! " << std::endl;
467  phiMinus = -20 * Geom::pi() / 180.; // -20 deg
468  phiPlus = -40 * Geom::pi() / 180.; // -20 deg
469  }
470 
471  if (debug_) std::cout << " with margins : " << etaLow << " " << etaHigh << " " <<
472  phiMinus << " " << phiPlus << std::endl;
473 
474 
475  const RectangularEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
476 
477  FEDs = TheMapping -> GetListofFEDs(ecalregion);
478 
479  return FEDs;
480 }
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
double etaBinHighEdge(unsigned int etaIndex, bool central=true) const
void Muon(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
double etaBinLowEdge(unsigned int etaIndex, bool central=true) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: Event.h:508
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
ESListOfFEDSProducer(const edm::ParameterSet &pset)
std::vector< int > ListOfFEDS(double etaLow, double etaHigh, double phiLow, double phiHigh, double etamargin, double phimargin)
void Jets(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void Egamma(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:59
T get() const
Definition: EventSetup.h:71
constexpr double pi()
Definition: Pi.h:31
double emJetPhiBinLowEdge(unsigned int phiIndex) const
T const * product() const
Definition: ESHandle.h:86
void produce(edm::Event &e, const edm::EventSetup &c) override
def move(src, dest)
Definition: eostools.py:511
double emJetPhiBinHighEdge(unsigned int phiIndex) const