CMS 3D CMS Logo

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  if (first_) {
124  iSetup.get< EcalMappingRcd >().get(ecalmapping);
125  const EcalElectronicsMapping* TheMapping_ = ecalmapping.product();
126  *TheMapping = *TheMapping_;
127  first_ = false;
128  }
129 
130  auto productAddress = std::make_unique<EcalListOfFEDS>();
131 
132  std::vector<int> feds; // the list of FEDS produced by this module
133 
134 
135  // ---- First, get the list of ECAL FEDs which have already been unpacked
136 
137  std::vector< edm::Handle<EcalListOfFEDS> > FEDs_Done;
138  std::vector<int> Done;
139  e.getManyByType(FEDs_Done);
140  unsigned int nDone = FEDs_Done.size();
141  if (debug_) std::cout << " ECAL unpacking module has already run " << nDone << " times. " << std::endl;
142  for (unsigned int id=0; id < nDone; id++) {
143  // ignore the FEDs coming from unpacking in pi0 paths
144  if( Pi0ListToIgnore_.label() == FEDs_Done[id].provenance()->moduleLabel() ){continue;}
145  std::vector<int> done = FEDs_Done[id]-> GetList();
146  for (int jd=0; jd < (int)done.size(); jd++) {
147  Done.push_back(done[jd] - FEDNumbering::MINECALFEDID);
148  }
149  }
150  if (debug_) std::cout << " For this event, " << Done.size() << " ECAL FEDs have already been unpacked." << std::endl;
151 
152 
153  if (EGamma_) {
154  // feds = Egamma(e, iSetup, Done);
155  Egamma(e, iSetup, Done, feds);
156  }
157 
158  if (Muon_) {
159  // feds = Muon(e, iSetup, Done);
160  Muon(e, iSetup, Done, feds);
161  }
162 
163  if (Jets_) {
164  // feds = Jets(e, iSetup, Done);
165  Jets(e, iSetup, Done, feds);
166  }
167 
168  if ( !EGamma_ && !Muon_ && ! Jets_) {
169  for (int i=1; i <= 54; i++) {
170  if ( std::find(Done.begin(), Done.end(), i) == Done.end())
171  feds.push_back(i);
172  }
173  }
174 
175  int nf = (int)feds.size();
176  for (int i=0; i <nf; i++) {
177  feds[i] += FEDNumbering::MINECALFEDID;
178  if (debug_) std::cout << "Will unpack FED " << feds[i] << std::endl;
179  }
180 
181  if (debug_ && nf < 1 )
182  std::cout << " Warning : no ECAL FED to unpack for Run " << e.id().run() << " Event " << e.id().event() << std::endl;
183 
184  productAddress.get() -> SetList(feds);
185  e.put(std::move(productAddress),OutputLabel_);
186 }
187 
188 void EcalListOfFEDSProducer::Egamma(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs ) {
189 
190  // std::vector<int> FEDs;
191 
192  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Egamma" << std::endl;
193 
194  //Get the L1 EM Particle Collection
195  //Get the L1 EM Particle Collection
197  if(EMdoIsolated_)
198  e.getByToken(EMl1TagIsolated_, emIsolColl);
199  //Get the L1 EM Particle Collection
201  if (EMdoNonIsolated_)
202  e.getByToken(EMl1TagNonIsolated_, emNonIsolColl);
203 
204  // Get the CaloGeometry
205  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
206  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
207 
208  if(EMdoIsolated_) {
209 
210  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin();
211  emItr != emIsolColl->end() ;++emItr ){
212 
213  float pt = emItr -> pt();
214  if (pt < Ptmin_iso_ ) continue;
215  if (debug_) std::cout << " Here is an L1 isoEM candidate of pt " << pt << std::endl;
216  // Access the GCT hardware object corresponding to the L1Extra EM object.
217  int etaIndex = emItr->gctEmCand()->etaIndex() ;
218  int phiIndex = emItr->gctEmCand()->phiIndex() ;
219  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
220  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
221  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
222  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
223  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
224 
225  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
226  for (int i=0; i < (int)feds.size(); i++) {
227  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
228  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
229  }
230  } // end loop on L1EmParticleCollection
231  } // endif doIsolated_
232 
233  if (EMdoNonIsolated_) {
234 
235  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin();
236  emItr != emNonIsolColl->end() ;++emItr ){
237 
238  float pt = emItr -> pt();
239  if (debug_) std::cout << " Here is an L1 nonisoEM candidate of pt " << pt << std::endl;
240  if (pt < Ptmin_noniso_ ) continue;
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  // std::cout << " etaIndex phiIndex " << etaIndex << " " << phiIndex << std::endl;
245  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
246  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
247  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
248  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
249  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
250 
251  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
252  for (int i=0; i < (int)feds.size(); i++) {
253  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
254  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
255 
256  }
257 
258  } // end loop on L1EmParticleCollection
259  }
260 
261  // std::cout << "end of get list of feds " << std::endl;
262 
263  if (debug_) {
264  std::cout << std::endl;
265  for (int i=0; i < (int)FEDs.size(); i++) {
266  std::cout << "Egamma: unpack FED " << FEDs[i] << std::endl;
267  }
268  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
269  }
270 
271  // return FEDs;
272 
273 }
274 
275 void EcalListOfFEDSProducer::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
276 
277  // std::vector<int> FEDs;
278 
279  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Muon" << std::endl;
280 
282  e.getByToken(MuonSource_, muColl);
283 
284  double epsilon = 0.01;
285 
286  for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
287  const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
288  double pt = (*it).pt();
289  double eta = (*it).eta();
290  double phi = (*it).phi();
291 
292  if (debug_) std::cout << " here is a L1 muon Seed with (eta,phi) = " <<
293  eta << " " << phi << " and pt " << pt << std::endl;
294  if (pt < Ptmin_muon_ ) continue;
295 
296  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, MUregionEtaMargin_, MUregionPhiMargin_);
297 
298  for (int i=0; i < (int)feds.size(); i++) {
299  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
300  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
301  }
302  }
303 
304  if (debug_) {
305  std::cout << std::endl;
306  for (int i=0; i < (int)FEDs.size(); i++) {
307  std::cout << "Muons: unpack FED " << FEDs[i] << std::endl;
308  }
309  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
310  }
311 
312  // return FEDs;
313 
314 }
315 
316 void EcalListOfFEDSProducer::Jets(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
317 
318  // std::vector<int> FEDs;
319 
320  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Jets" << std::endl;
321  double epsilon = 0.01;
322 
323  if (JETSdoCentral_) {
325  e.getByToken(CentralSource_,jetColl);
326 
327  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
328 
329  double pt = it -> pt();
330  double eta = it -> eta();
331  double phi = it -> phi();
332 
333  if (debug_) std::cout << " here is a L1 CentralJet Seed with (eta,phi) = " <<
334  eta << " " << phi << " and pt " << pt << std::endl;
335 
336  if (pt < Ptmin_jets_ ) continue;
337 
338  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
339 
340  for (int i=0; i < (int)feds.size(); i++) {
341  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
342  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
343  }
344  }
345  }
346 
347  if (JETSdoForward_) {
349  e.getByToken(ForwardSource_,jetColl);
350 
351  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
352 
353  double pt = it -> pt();
354  double eta = it -> eta();
355  double phi = it -> phi();
356 
357  if (debug_) std::cout << " here is a L1 ForwardJet Seed with (eta,phi) = " <<
358  eta << " " << phi << " and pt " << pt << std::endl;
359  if (pt < Ptmin_jets_ ) continue;
360 
361  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
362 
363  for (int i=0; i < (int)feds.size(); i++) {
364  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
365  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
366  }
367  }
368  }
369 
370  if (JETSdoTau_) {
372  e.getByToken(TauSource_,jetColl);
373 
374  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
375 
376  double pt = it -> pt();
377  double eta = it -> eta();
378  double phi = it -> phi();
379 
380  if (debug_) std::cout << " here is a L1 TauJet Seed with (eta,phi) = " <<
381  eta << " " << phi << " and pt " << pt << std::endl;
382  if (pt < Ptmin_jets_ ) continue;
383 
384  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
385 
386  for (int i=0; i < (int)feds.size(); i++) {
387  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
388  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
389  }
390  }
391  }
392 
393 
394 
395  if (debug_) {
396  std::cout << std::endl;
397  for (int i=0; i < (int)FEDs.size(); i++) {
398  std::cout << "Jets: unpack FED " << FEDs[i] << std::endl;
399  }
400  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
401  }
402  // return FEDs;
403 }
404 
405 
406 std::vector<int> EcalListOfFEDSProducer::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
407  double phiHigh, double etamargin, double phimargin) {
408 
409  std::vector<int> FEDs;
410 
411  if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
412 
413 
414  if (debug_) std::cout << " etaLow etaHigh phiLow phiHigh " << etaLow << " " <<
415  etaHigh << " " << phiLow << " " << phiHigh << std::endl;
416 
417  etaLow -= etamargin;
418  etaHigh += etamargin;
419  double phiMinus = phiLow - phimargin;
420  double phiPlus = phiHigh + phimargin;
421 
422  bool all = false;
423  double dd = fabs(phiPlus-phiMinus);
424  if (debug_) std::cout << " dd = " << dd << std::endl;
425  if (dd > 2.*Geom::pi() ) all = true;
426 
427  while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
428  while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
429  if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
430 
431  double dphi = phiPlus - phiMinus;
432  if (dphi < 0) dphi += 2.*Geom::pi() ;
433  if (debug_) std::cout << "dphi = " << dphi << std::endl;
434  if (dphi > Geom::pi()) {
435  int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
436  int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
437  if (debug_) std::cout << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2 << std::endl;
438  if (fed_low1 == fed_low2) all = true;
439  int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
440  int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
441  if (debug_) std::cout << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2 << std::endl;
442  if (fed_hi1 == fed_hi2) all = true;
443  }
444 
445 
446  if (all) {
447  if (debug_) std::cout << " unpack everything in phi ! " << std::endl;
448  phiMinus = -20 * Geom::pi() / 180.; // -20 deg
449  phiPlus = -40 * Geom::pi() / 180.; // -20 deg
450  }
451 
452  if (debug_) std::cout << " with margins : " << etaLow << " " << etaHigh << " " <<
453  phiMinus << " " << phiPlus << std::endl;
454 
455 
456  const RectangularEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
457 
458  FEDs = TheMapping -> GetListofFEDs(ecalregion);
459  return FEDs;
460 }
461 
462 
463 
464 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
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
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
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
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)
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)
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
def move(src, dest)
Definition: eostools.py:511
double emJetPhiBinHighEdge(unsigned int phiIndex) const