test
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 
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 
127 {}
128 
130 
131  if (first_) {
133  iSetup.get< EcalMappingRcd >().get(ecalmapping);
134  const EcalElectronicsMapping* TheMapping_ = ecalmapping.product();
135  *TheMapping = *TheMapping_;
136  first_ = false;
137  }
138 
139  std::auto_ptr<ESListOfFEDS> productAddress(new ESListOfFEDS);
140  std::vector<int> feds; // the list of Ecal FEDS produced
141 
143  std::vector<int> Done;
144  if (EGamma_) {
145  // feds = Egamma(e, iSetup, Done);
146  Egamma(e, iSetup, Done, feds);
147  }
148 
149  if (Muon_) {
151  // feds = Muon(e, iSetup, Done);
152  // Muon(e, iSetup, Done, feds);
153  }
154 
155  if (Jets_) {
156  // feds = Jets(e, iSetup, Done);
157  //Jets(e, iSetup, Done, feds);
158  }
159 
160  if ( !EGamma_ && !Muon_ && ! Jets_) {
161  for (int i=1; i <= 54; i++) {
162  if ( std::find(Done.begin(), Done.end(), i) == Done.end())
163  feds.push_back(i);
164  }
165  }
166 
167 
168  int nf = (int)feds.size();
169  for (int i=0; i <nf; i++) {
170  feds[i] += FEDNumbering::MINECALFEDID;
171  if (debug_) std::cout << "Will unpack FED " << feds[i] << std::endl;
172  }
173 
174  if (debug_ && nf < 1 )
175  std::cout << " Warning : no ECAL FED to unpack for Run " << e.id().run() << " Event " << e.id().event() << std::endl;
176 
178  std::vector<int> es_feds = TheESMapping->GetListofFEDs(feds);
179 
180  //check ES List if some of them already done
181  std::vector< edm::Handle<ESListOfFEDS> > esFEDs_Done;
182  e.getManyByType(esFEDs_Done);
183  unsigned int esnDone = esFEDs_Done.size();
184 
185  if(debug_){
186  std::cout<<int(es_feds.size())<<" feds requested, and ESunpacking have already been done "<<esnDone<<" times."<<std::endl;
187  }
188 
189  for(int i=0; i<int(esFEDs_Done.size());i++){
190  std::vector<int> done = esFEDs_Done[i]-> GetList();
191  for(int n=0; n<int(done.size());n++){
192  for(int j=0; j<int(es_feds.size());j++){
193  std::vector<int>::iterator it = find(es_feds.begin(),es_feds.end(),done[n]);
194  if( it != es_feds.end()){
195  es_feds.erase(it);
196  j--;
197  }
198  }
199  }
200  }
201 
202  if (debug_ ){
203  std::cout<<"ESListofFEDSProducer: new ES_list will be put into event: total "<<int(es_feds.size())<<std::endl;
204  for(int j=0; j<int(es_feds.size());j++){
205  std::cout<<es_feds[j]<<" ";
206  }
207  std::cout<<std::endl;
208  }
209 
210 
212  productAddress.get() -> SetList(es_feds);
213  e.put(productAddress,OutputLabel_);
214 
215 }
216 
217 void ESListOfFEDSProducer::Egamma(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs ) {
218 
219  // std::vector<int> FEDs;
220 
221  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Egamma" << std::endl;
222 
223  //Get the L1 EM Particle Collection
225  if(EMdoIsolated_)
226  e.getByToken(EMl1TagIsolated_, emIsolColl);
227  //Get the L1 EM Particle Collection
229  if (EMdoNonIsolated_)
230  e.getByToken(EMl1TagNonIsolated_, emNonIsolColl);
231 
232  // Get the CaloGeometry
233  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
234  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
235 
236  if(EMdoIsolated_) {
237 
238  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin();
239  emItr != emIsolColl->end() ;++emItr ){
240 
241  float pt = emItr -> pt();
242  if (pt < Ptmin_iso_ ) continue;
243  if (debug_) std::cout << " Here is an L1 isoEM candidate of pt " << pt << std::endl;
244  // Access the GCT hardware object corresponding to the L1Extra EM object.
245  int etaIndex = emItr->gctEmCand()->etaIndex() ;
246  int phiIndex = emItr->gctEmCand()->phiIndex() ;
247  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
248  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
249  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
250  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
251  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
252 
253  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
254  for (int i=0; i < (int)feds.size(); i++) {
255  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
256  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
257  }
258  } // end loop on L1EmParticleCollection
259  } // endif doIsolated_
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  } // end loop on L1EmParticleCollection
286  }
287 
288  if (debug_) {
289  std::cout << std::endl;
290  for (int i=0; i < (int)FEDs.size(); i++) {
291  std::cout << "Egamma: unpack FED " << FEDs[i] << std::endl;
292  }
293  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
294  }
295 
296  // return FEDs;
297 
298 }
299 
300 void ESListOfFEDSProducer::Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
301 
302  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Muon" << std::endl;
304  e.getByToken(MuonSource_, muColl);
305 
306  double epsilon = 0.01;
307 
308  for (L1MuonParticleCollection::const_iterator it=muColl->begin(); it != muColl->end(); it++) {
309 
310  const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
311  double pt = (*it).pt();
312  double eta = (*it).eta();
313  double phi = (*it).phi();
314 
315  if (debug_) std::cout << " here is a L1 muon Seed with (eta,phi) = " <<
316  eta << " " << phi << " and pt " << pt << std::endl;
317  if (pt < Ptmin_muon_ ) continue;
318 
319  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, MUregionEtaMargin_, MUregionPhiMargin_);
320 
321  for (int i=0; i < (int)feds.size(); i++) {
322  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
323  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
324  }
325  }
326 
327  if (debug_) {
328  std::cout << std::endl;
329  for (int i=0; i < (int)FEDs.size(); i++) {
330  std::cout << "Muons: unpack FED " << FEDs[i] << std::endl;
331  }
332  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
333  }
334 
335  // return FEDs;
336 
337 }
338 
339 void ESListOfFEDSProducer::Jets(edm::Event& e, const edm::EventSetup& es, std::vector<int>& done, std::vector<int>& FEDs) {
340 
341  // std::vector<int> FEDs;
342 
343  if (debug_) std::cout << std::endl << std::endl << " enter in EcalListOfFEDSProducer::Jets" << std::endl;
344  double epsilon = 0.01;
345 
346  if (JETSdoCentral_) {
347 
349  e.getByToken(CentralSource_,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 CentralJet 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 (JETSdoForward_) {
371 
373  e.getByToken(ForwardSource_,jetColl);
374 
375  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
376 
377  double pt = it -> pt();
378  double eta = it -> eta();
379  double phi = it -> phi();
380 
381  if (debug_) std::cout << " here is a L1 ForwardJet Seed with (eta,phi) = " <<
382  eta << " " << phi << " and pt " << pt << std::endl;
383  if (pt < Ptmin_jets_ ) continue;
384 
385  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
386 
387  for (int i=0; i < (int)feds.size(); i++) {
388  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
389  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
390  }
391  }
392  }
393 
394  if (JETSdoTau_) {
395 
397  e.getByToken(TauSource_,jetColl);
398 
399  for (L1JetParticleCollection::const_iterator it=jetColl->begin(); it != jetColl->end(); it++) {
400 
401  double pt = it -> pt();
402  double eta = it -> eta();
403  double phi = it -> phi();
404 
405  if (debug_) std::cout << " here is a L1 TauJet Seed with (eta,phi) = " <<
406  eta << " " << phi << " and pt " << pt << std::endl;
407  if (pt < Ptmin_jets_ ) continue;
408 
409  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
410 
411  for (int i=0; i < (int)feds.size(); i++) {
412  if ( std::find(FEDs.begin(), FEDs.end(), feds[i]) == FEDs.end() &&
413  std::find(done.begin(), done.end(), feds[i]) == done.end() ) FEDs.push_back(feds[i]);
414  }
415  }
416  }
417 
418  if (debug_) {
419  std::cout << std::endl;
420  for (int i=0; i < (int)FEDs.size(); i++) {
421  std::cout << "Jets: unpack FED " << FEDs[i] << std::endl;
422  }
423  std::cout << "Number of FEDS is " << FEDs.size() << std::endl;
424  }
425 
426  // return FEDs;
427 }
428 
429 
430 std::vector<int> ESListOfFEDSProducer::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
431  double phiHigh, double etamargin, double phimargin)
432 {
433 
434  std::vector<int> FEDs;
435 
436  if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
437 
438 
439  if (debug_) std::cout << " etaLow etaHigh phiLow phiHigh " << etaLow << " " <<
440  etaHigh << " " << phiLow << " " << phiHigh << std::endl;
441 
442  etaLow -= etamargin;
443  etaHigh += etamargin;
444  double phiMinus = phiLow - phimargin;
445  double phiPlus = phiHigh + phimargin;
446 
447  bool all = false;
448  double dd = fabs(phiPlus-phiMinus);
449  if (debug_) std::cout << " dd = " << dd << std::endl;
450  if (dd > 2.*Geom::pi() ) all = true;
451 
452  while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
453  while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
454  if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
455 
456  double dphi = phiPlus - phiMinus;
457  if (dphi < 0) dphi += 2.*Geom::pi() ;
458  if (debug_) std::cout << "dphi = " << dphi << std::endl;
459  if (dphi > Geom::pi()) {
460  int fed_low1 = TheMapping -> GetFED(etaLow,phiMinus*180./Geom::pi());
461  int fed_low2 = TheMapping -> GetFED(etaLow,phiPlus*180./Geom::pi());
462  if (debug_) std::cout << "fed_low1 fed_low2 " << fed_low1 << " " << fed_low2 << std::endl;
463  if (fed_low1 == fed_low2) all = true;
464  int fed_hi1 = TheMapping -> GetFED(etaHigh,phiMinus*180./Geom::pi());
465  int fed_hi2 = TheMapping -> GetFED(etaHigh,phiPlus*180./Geom::pi());
466  if (debug_) std::cout << "fed_hi1 fed_hi2 " << fed_hi1 << " " << fed_hi2 << std::endl;
467  if (fed_hi1 == fed_hi2) all = true;
468  }
469 
470 
471  if (all) {
472  if (debug_) std::cout << " unpack everything in phi ! " << std::endl;
473  phiMinus = -20 * Geom::pi() / 180.; // -20 deg
474  phiPlus = -40 * Geom::pi() / 180.; // -20 deg
475  }
476 
477  if (debug_) std::cout << " with margins : " << etaLow << " " << etaHigh << " " <<
478  phiMinus << " " << phiPlus << std::endl;
479 
480 
481  const EcalEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
482 
483  FEDs = TheMapping -> GetListofFEDs(ecalregion);
484 
485  return FEDs;
486 }
RunNumber_t run() const
Definition: EventID.h:39
void getManyByType(std::vector< Handle< PROD > > &results) const
Definition: Event.h:452
EventNumber_t event() const
Definition: EventID.h:41
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)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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:121
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)
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)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void produce(edm::Event &e, const edm::EventSetup &c)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Geom::Phi< T > phi() const
edm::EventID id() const
Definition: EventBase.h:59
tuple cout
Definition: gather_cfg.py:145
constexpr double pi()
Definition: Pi.h:31