CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalListOfFEDSProducer.cc
Go to the documentation of this file.
4 
7 
8 // Ecal Mapping
11 
12 // Level 1 Trigger
15 
16 // EgammaCoreTools
19 
20 // Muon stuff
22 
23 #include <vector>
24 
25 using namespace l1extra;
26 
28 
29  debug_ = pset.getUntrackedParameter<bool>("debug");
30 
31  Pi0ListToIgnore_ = pset.getParameter<edm::InputTag>("Pi0ListToIgnore");
32 
33  EGamma_ = pset.getUntrackedParameter<bool>("EGamma",false);
34  Muon_ = pset.getUntrackedParameter<bool>("Muon",false);
35  Jets_ = pset.getUntrackedParameter<bool>("Jets",false);
36 
37  if (EGamma_ && Muon_) {
38  throw cms::Exception("EcalListOfFEDSProducer") <<
39  " Wrong configuration : EGamma and Muon should not be true at the same time." ;
40  }
41 
42 
43  if (EGamma_) {
44 
45  EMl1TagIsolated_ = consumes<L1EmParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("EM_l1TagIsolated"));
46  EMl1TagNonIsolated_ = consumes<L1EmParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("EM_l1TagNonIsolated"));
47  EMdoIsolated_ = pset.getUntrackedParameter<bool>("EM_doIsolated", true);
48  EMdoNonIsolated_ = pset.getUntrackedParameter<bool>("EM_doNonIsolated",true);
49  EMregionEtaMargin_ = pset.getUntrackedParameter<double>("EM_regionEtaMargin", 0.25);
50  EMregionPhiMargin_ = pset.getUntrackedParameter<double>("EM_regionPhiMargin", 0.40);
51  Ptmin_iso_ = pset.getUntrackedParameter<double>("Ptmin_iso", 0.);
52  Ptmin_noniso_ = pset.getUntrackedParameter<double>("Ptmin_noniso", 0.);
53  }
54 
55  if (Muon_) {
56  MUregionEtaMargin_ = pset.getUntrackedParameter<double>("MU_regionEtaMargin", 1.0);
57  MUregionPhiMargin_ = pset.getUntrackedParameter<double>("MU_regionPhiMargin", 1.0);
58  Ptmin_muon_ = pset.getUntrackedParameter<double>("Ptmin_muon", 0.);
59  MuonSource_ = consumes<L1MuonParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("MuonSource"));
60  }
61 
62  if (Jets_) {
63  JETSregionEtaMargin_ = pset.getUntrackedParameter<double>("JETS_regionEtaMargin", 1.0);
64  JETSregionPhiMargin_ = pset.getUntrackedParameter<double>("JETS_regionPhiMargin", 1.0);
65  Ptmin_jets_ = pset.getUntrackedParameter<double>("Ptmin_jets", 0.);
66  CentralSource_ = consumes<L1JetParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("CentralSource"));
67  ForwardSource_ = consumes<L1JetParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("ForwardSource"));
68  TauSource_ = consumes<L1JetParticleCollection>(pset.getUntrackedParameter<edm::InputTag>("TauSource"));
69  JETSdoCentral_ = pset.getUntrackedParameter<bool>("JETS_doCentral", true);
70  JETSdoForward_ = pset.getUntrackedParameter<bool>("JETS_doForward", true);
71  JETSdoTau_ = pset.getUntrackedParameter<bool>("JETS_doTau", true);
72  }
73 
74  OutputLabel_ = pset.getUntrackedParameter<std::string>("OutputLabel");
75 
76  TheMapping = new EcalElectronicsMapping();
77  first_ = true;
78 
79  consumesMany<EcalListOfFEDS>();
80  produces<EcalListOfFEDS>(OutputLabel_);
81 }
82 
84  delete TheMapping;
85 }
86 
88 
90  desc.add<bool>("debug", false);
91  desc.add<edm::InputTag>("Pi0ListToIgnore", edm::InputTag(""));
92  desc.add<bool>("EGamma",false);
93  desc.add<bool>("Muon",false);
94  desc.add<bool>("Jets",false);
95  desc.add<edm::InputTag>("EM_l1TagIsolated", edm::InputTag(""));
96  desc.add<edm::InputTag>("EM_l1TagNonIsolated", edm::InputTag(""));
97  desc.add<bool>("EM_doIsolated",true);
98  desc.add<bool>("EM_doNonIsolated",true);
99  desc.add<double>("EM_regionEtaMargin",0.25);
100  desc.add<double>("EM_regionPhiMargin",0.40);
101  desc.add<double>("Ptmin_iso",0.);
102  desc.add<double>("Ptmin_noniso",0.);
103  desc.add<double>("MU_regionEtaMargin",1.0);
104  desc.add<double>("MU_regionPhiMargin",1.0);
105  desc.add<double>("Ptmin_muon",0.);
106  desc.add<edm::InputTag>("MuonSource", edm::InputTag(""));
107  desc.add<double>("JETS_regionEtaMargin",1.0);
108  desc.add<double>("JETS_regionPhiMargin",1.0);
109  desc.add<double>("Ptmin_jets",0.);
110  desc.add<edm::InputTag>("CentralSource", edm::InputTag(""));
111  desc.add<edm::InputTag>("ForwardSource", edm::InputTag(""));
112 desc.add<edm::InputTag>("TauSource", edm::InputTag(""));
113  desc.add<bool>("JETS_doCentral",true);
114  desc.add<bool>("JETS_doForward",true);
115  desc.add<bool>("JETS_doTau",true);
116 desc.add<std::string>("OutputLabel", "");
117  descriptions.add(("hltEcalListOfFEDSProducer"), desc);
118 }
119 
121 {}
122 
124 {}
125 
127 
128  if (first_) {
130  iSetup.get< EcalMappingRcd >().get(ecalmapping);
131  const EcalElectronicsMapping* TheMapping_ = ecalmapping.product();
132  *TheMapping = *TheMapping_;
133  first_ = false;
134  }
135 
136  auto productAddress = std::make_unique<EcalListOfFEDS>();
137 
138  std::vector<int> feds; // the list of FEDS produced by this module
139 
140 
141  // ---- First, get the list of ECAL FEDs which have already been unpacked
142 
143  std::vector< edm::Handle<EcalListOfFEDS> > FEDs_Done;
144  std::vector<int> Done;
145  e.getManyByType(FEDs_Done);
146  unsigned int nDone = FEDs_Done.size();
147  if (debug_) std::cout << " ECAL unpacking module has already run " << nDone << " times. " << std::endl;
148  for (unsigned int id=0; id < nDone; id++) {
149  // ignore the FEDs coming from unpacking in pi0 paths
150  if( Pi0ListToIgnore_.label() == FEDs_Done[id].provenance()->moduleLabel() ){continue;}
151  std::vector<int> done = FEDs_Done[id]-> GetList();
152  for (int jd=0; jd < (int)done.size(); jd++) {
153  Done.push_back(done[jd] - FEDNumbering::MINECALFEDID);
154  }
155  }
156  if (debug_) std::cout << " For this event, " << Done.size() << " ECAL FEDs have already been unpacked." << std::endl;
157 
158 
159  if (EGamma_) {
160  // feds = Egamma(e, iSetup, Done);
161  Egamma(e, iSetup, Done, feds);
162  }
163 
164  if (Muon_) {
165  // feds = Muon(e, iSetup, Done);
166  Muon(e, iSetup, Done, feds);
167  }
168 
169  if (Jets_) {
170  // feds = Jets(e, iSetup, Done);
171  Jets(e, iSetup, Done, feds);
172  }
173 
174  if ( !EGamma_ && !Muon_ && ! Jets_) {
175  for (int i=1; i <= 54; i++) {
176  if ( std::find(Done.begin(), Done.end(), i) == Done.end())
177  feds.push_back(i);
178  }
179  }
180 
181  int nf = (int)feds.size();
182  for (int i=0; i <nf; i++) {
183  feds[i] += FEDNumbering::MINECALFEDID;
184  if (debug_) std::cout << "Will unpack FED " << feds[i] << std::endl;
185  }
186 
187  if (debug_ && nf < 1 )
188  std::cout << " Warning : no ECAL FED to unpack for Run " << e.id().run() << " Event " << e.id().event() << std::endl;
189 
190  productAddress.get() -> SetList(feds);
191  e.put(std::move(productAddress),OutputLabel_);
192 }
193 
194 void EcalListOfFEDSProducer::Egamma(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs ) {
195 
196  // std::vector<int> FEDs;
197 
198  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Egamma" << std::endl;
199 
200  //Get the L1 EM Particle Collection
201  //Get the L1 EM Particle Collection
203  if(EMdoIsolated_)
204  e.getByToken(EMl1TagIsolated_, emIsolColl);
205  //Get the L1 EM Particle Collection
207  if (EMdoNonIsolated_)
208  e.getByToken(EMl1TagNonIsolated_, emNonIsolColl);
209 
210  // Get the CaloGeometry
211  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
212  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
213 
214  if(EMdoIsolated_) {
215 
216  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin();
217  emItr != emIsolColl->end() ;++emItr ){
218 
219  float pt = emItr -> pt();
220  if (pt < Ptmin_iso_ ) continue;
221  if (debug_) std::cout << " Here is an L1 isoEM candidate of pt " << pt << std::endl;
222  // Access the GCT hardware object corresponding to the L1Extra EM object.
223  int etaIndex = emItr->gctEmCand()->etaIndex() ;
224  int phiIndex = emItr->gctEmCand()->phiIndex() ;
225  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
226  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
227  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
228  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
229  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
230 
231  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
232  for (int i=0; i < (int)feds.size(); i++) {
233  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
234  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
235  }
236  } // end loop on L1EmParticleCollection
237  } // endif doIsolated_
238 
239  if (EMdoNonIsolated_) {
240 
241  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin();
242  emItr != emNonIsolColl->end() ;++emItr ){
243 
244  float pt = emItr -> pt();
245  if (debug_) std::cout << " Here is an L1 nonisoEM candidate of pt " << pt << std::endl;
246  if (pt < Ptmin_noniso_ ) continue;
247  // Access the GCT hardware object corresponding to the L1Extra EM object.
248  int etaIndex = emItr->gctEmCand()->etaIndex() ;
249  int phiIndex = emItr->gctEmCand()->phiIndex() ;
250  // std::cout << " etaIndex phiIndex " << etaIndex << " " << phiIndex << std::endl;
251  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
252  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
253  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
254  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
255  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
256 
257  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
258  for (int i=0; i < (int)feds.size(); i++) {
259  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
260  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
261 
262  }
263 
264  } // end loop on L1EmParticleCollection
265  }
266 
267  // std::cout << "end of get list of feds " << std::endl;
268 
269  if (debug_) {
270  std::cout << std::endl;
271  for (int i=0; i < (int)FEDs.size(); i++) {
272  std::cout << "Egamma: unpack FED " << FEDs[i] << std::endl;
273  }
274  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
275  }
276 
277  // return FEDs;
278 
279 }
280 
281 void EcalListOfFEDSProducer::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
282 
283  // std::vector<int> FEDs;
284 
285  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Muon" << std::endl;
286 
288  e.getByToken(MuonSource_, muColl);
289 
290  double epsilon = 0.01;
291 
292  for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
293  const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
294  double pt = (*it).pt();
295  double eta = (*it).eta();
296  double phi = (*it).phi();
297 
298  if (debug_) std::cout << " here is a L1 muon Seed with (eta,phi) = " <<
299  eta << " " << phi << " and pt " << pt << std::endl;
300  if (pt < Ptmin_muon_ ) continue;
301 
302  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, MUregionEtaMargin_, MUregionPhiMargin_);
303 
304  for (int i=0; i < (int)feds.size(); i++) {
305  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
306  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
307  }
308  }
309 
310  if (debug_) {
311  std::cout << std::endl;
312  for (int i=0; i < (int)FEDs.size(); i++) {
313  std::cout << "Muons: unpack FED " << FEDs[i] << std::endl;
314  }
315  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
316  }
317 
318  // return FEDs;
319 
320 }
321 
322 void EcalListOfFEDSProducer::Jets(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
323 
324  // std::vector<int> FEDs;
325 
326  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Jets" << std::endl;
327  double epsilon = 0.01;
328 
329  if (JETSdoCentral_) {
331  e.getByToken(CentralSource_,jetColl);
332 
333  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
334 
335  double pt = it -> pt();
336  double eta = it -> eta();
337  double phi = it -> phi();
338 
339  if (debug_) std::cout << " here is a L1 CentralJet Seed with (eta,phi) = " <<
340  eta << " " << phi << " and pt " << pt << std::endl;
341 
342  if (pt < Ptmin_jets_ ) continue;
343 
344  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
345 
346  for (int i=0; i < (int)feds.size(); i++) {
347  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
348  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
349  }
350  }
351  }
352 
353  if (JETSdoForward_) {
355  e.getByToken(ForwardSource_,jetColl);
356 
357  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
358 
359  double pt = it -> pt();
360  double eta = it -> eta();
361  double phi = it -> phi();
362 
363  if (debug_) std::cout << " here is a L1 ForwardJet Seed with (eta,phi) = " <<
364  eta << " " << phi << " and pt " << pt << std::endl;
365  if (pt < Ptmin_jets_ ) continue;
366 
367  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
368 
369  for (int i=0; i < (int)feds.size(); i++) {
370  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
371  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
372  }
373  }
374  }
375 
376  if (JETSdoTau_) {
378  e.getByToken(TauSource_,jetColl);
379 
380  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
381 
382  double pt = it -> pt();
383  double eta = it -> eta();
384  double phi = it -> phi();
385 
386  if (debug_) std::cout << " here is a L1 TauJet Seed with (eta,phi) = " <<
387  eta << " " << phi << " and pt " << pt << std::endl;
388  if (pt < Ptmin_jets_ ) continue;
389 
390  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
391 
392  for (int i=0; i < (int)feds.size(); i++) {
393  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
394  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
395  }
396  }
397  }
398 
399 
400 
401  if (debug_) {
402  std::cout << std::endl;
403  for (int i=0; i < (int)FEDs.size(); i++) {
404  std::cout << "Jets: unpack FED " << FEDs[i] << std::endl;
405  }
406  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
407  }
408  // return FEDs;
409 }
410 
411 
412 std::vector<int> EcalListOfFEDSProducer::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
413  double phiHigh, double etamargin, double phimargin) {
414 
415  std::vector<int> FEDs;
416 
417  if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
418 
419 
420  if (debug_) std::cout << " etaLow etaHigh phiLow phiHigh " << etaLow << " " <<
421  etaHigh << " " << phiLow << " " << phiHigh << std::endl;
422 
423  etaLow -= etamargin;
424  etaHigh += etamargin;
425  double phiMinus = phiLow - phimargin;
426  double phiPlus = phiHigh + phimargin;
427 
428  bool all = false;
429  double dd = fabs(phiPlus-phiMinus);
430  if (debug_) std::cout << " dd = " << dd << std::endl;
431  if (dd > 2.*Geom::pi() ) all = true;
432 
433  while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
434  while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
435  if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
436 
437  double dphi = phiPlus - phiMinus;
438  if (dphi < 0) dphi += 2.*Geom::pi() ;
439  if (debug_) std::cout << "dphi = " << dphi << std::endl;
440  if (dphi > Geom::pi()) {
441  int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
442  int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
443  if (debug_) std::cout << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2 << std::endl;
444  if (fed_low1 == fed_low2) all = true;
445  int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
446  int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
447  if (debug_) std::cout << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2 << std::endl;
448  if (fed_hi1 == fed_hi2) all = true;
449  }
450 
451 
452  if (all) {
453  if (debug_) std::cout << " unpack everything in phi ! " << std::endl;
454  phiMinus = -20 * Geom::pi() / 180.; // -20 deg
455  phiPlus = -40 * Geom::pi() / 180.; // -20 deg
456  }
457 
458  if (debug_) std::cout << " with margins : " << etaLow << " " << etaHigh << " " <<
459  phiMinus << " " << phiPlus << std::endl;
460 
461 
462  const EcalEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
463 
464  FEDs = TheMapping -> GetListofFEDs(ecalregion);
465  return FEDs;
466 }
467 
468 
469 
470 
RunNumber_t run() const
Definition: EventID.h:39
void getManyByType(std::vector< Handle< PROD > > &results) const
Definition: Event.h:447
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
void Muon(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void Egamma(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
void produce(edm::Event &e, const edm::EventSetup &c) override
tuple Jets
Definition: METSkim_cff.py:17
def move
Definition: eostools.py:510
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void Jets(edm::Event &e, const edm::EventSetup &es, std::vector< int > &done, std::vector< int > &FEDs)
EcalListOfFEDSProducer(const edm::ParameterSet &pset)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< int > ListOfFEDS(double etaLow, double etaHigh, double phiLow, double phiHigh, double etamargin, double phimargin)
Geom::Phi< T > phi() const
edm::EventID id() const
Definition: EventBase.h:58
tuple cout
Definition: gather_cfg.py:145
constexpr double pi()
Definition: Pi.h:31