CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastL1GlobalAlgo.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1CaloTriggerProducer
4 // Class: FastL1GlobalAlgo
5 //
13 //
14 // Original Author: Chi Nhan Nguyen
15 // Created: Mon Feb 19 13:25:24 CST 2007
16 // $Id: FastL1GlobalAlgo.cc,v 1.42 2009/10/22 11:51:03 abdullin Exp $
17 //
18 
19 // No BitInfos for release versions
20 
22 #include <iostream>
23 #include <fstream>
24 
25 //
26 // constructors and destructor
27 //
29 {
31 
32  // Get L1 config
33  m_L1Config.DoEMCorr = iConfig.getParameter<bool>("DoEMCorr");
34  m_L1Config.DoJetCorr = iConfig.getParameter<bool>("DoJetCorr");
35  m_DoBitInfo = iConfig.getParameter<bool>("DoBitInfo");
36  m_GctIso = iConfig.getParameter<bool>("GctIso");
37  m_IsolationEt = iConfig.getParameter<double>("IsolationEt");
38 
39  // get uncompressed hcal et
40  m_L1Config.HcalLUT = iConfig.getParameter<edm::FileInPath>("HcalLUT");
41 
42  m_L1Config.EMSeedEnThreshold = iConfig.getParameter<double>("EMSeedEnThreshold");
43  m_L1Config.EMActiveLevel = iConfig.getParameter<double>("EMActiveLevel");
44  m_L1Config.HadActiveLevel = iConfig.getParameter<double>("HadActiveLevel");
45  m_L1Config.noTauVetoLevel = iConfig.getParameter<double>("noTauVetoLevel");
46  m_L1Config.hOeThreshold = iConfig.getParameter<double>("hOeThreshold");
47  m_L1Config.FGEBThreshold = iConfig.getParameter<double>("FGEBThreshold");
48  m_L1Config.FGEEThreshold = iConfig.getParameter<double>("FGEEThreshold");
49 
50  m_L1Config.MuonNoiseLevel = iConfig.getParameter<double>("MuonNoiseLevel");
51  m_L1Config.EMNoiseLevel = iConfig.getParameter<double>("EMNoiseLevel");
52  m_L1Config.HadNoiseLevel = iConfig.getParameter<double>("HadNoiseLevel");
53  m_L1Config.QuietRegionThreshold = iConfig.getParameter<double>("QuietRegionThreshold");
54  m_L1Config.JetSeedEtThreshold = iConfig.getParameter<double>("JetSeedEtThreshold");
55 
56  m_L1Config.TowerEMLSB = iConfig.getParameter<double>("TowerEMLSB");
57  m_L1Config.TowerHadLSB = iConfig.getParameter<double>("TowerHadLSB");
58  m_L1Config.EMLSB = iConfig.getParameter<double>("EMLSB");
59  m_L1Config.JetLSB = iConfig.getParameter<double>("JetLSB");
60 
61  m_L1Config.CrystalEBThreshold = iConfig.getParameter<double>("CrystalEBThreshold");
62  m_L1Config.CrystalEEThreshold = iConfig.getParameter<double>("CrystalEEThreshold");
63 
64  m_L1Config.TowerEBThreshold = iConfig.getParameter<double>("TowerEBThreshold");
65  m_L1Config.TowerEEThreshold = iConfig.getParameter<double>("TowerEEThreshold");
66  m_L1Config.TowerHBThreshold = iConfig.getParameter<double>("TowerHBThreshold");
67  m_L1Config.TowerHEThreshold = iConfig.getParameter<double>("TowerHEThreshold");
68 
69  m_L1Config.TowerEBScale = iConfig.getParameter<double>("TowerEBScale");
70  m_L1Config.TowerEEScale = iConfig.getParameter<double>("TowerEEScale");
71  m_L1Config.TowerHBScale = iConfig.getParameter<double>("TowerHBScale");
72  m_L1Config.TowerHEScale = iConfig.getParameter<double>("TowerHEScale");
73 
74  m_L1Config.noFGThreshold = iConfig.getParameter<double>("noFGThreshold");
75 
76  m_L1Config.EmInputs = iConfig.getParameter <std::vector<edm::InputTag> >("EmInputs");
77  m_L1Config.TowerInput = iConfig.getParameter<edm::InputTag>("TowerInput");
78 
79  m_L1Config.EcalTPInput = iConfig.getParameter<edm::InputTag>("EcalTPInput");
80  m_L1Config.HcalTPInput = iConfig.getParameter<edm::InputTag>("HcalTPInput");
81 
82 
83  //Load Hcal LUT file
84  std::ifstream userfile;
85  const std::string userfileName = m_L1Config.HcalLUT.fullPath();
86  userfile.open(userfileName.c_str());
87  static const int etabound = 32;
88  static const int tpgmax = 256;
89  for (int i=0; i<tpgmax; i++) {
90  for(int j = 1; j <=etabound; j++) {
91  userfile >> m_hcaluncomp[j][i];
92  }
93  }
94  userfile.close();
95 
96 
97  FastL1Region tr;
98  for (int i=0;i<396;i++)
99  m_Regions.push_back(tr);
100 
101 }
102 
104 {
105 }
106 
107 
108 
109 // ------------ Dump out CaloTower info ------------
110 void
112  /*
113  std::vector<edm::Handle<CaloTowerCollection> > prods;
114 
115  edm::LogInfo("FastL1GlobalAlgo::CaloTowersDump") << "Start!";
116  e.getManyByType(prods);
117 
118  std::vector<edm::Handle<CaloTowerCollection> >::iterator i;
119 
120  for (i=prods.begin(); i!=prods.end(); i++) {
121  const CaloTowerCollection& c=*(*i);
122 
123  for (CaloTowerCollection::const_iterator j=c.begin(); j!=c.end(); j++) {
124  edm::LogInfo("FastL1GlobalAlgo::CaloTowersDump") << *j;
125  }
126  }
127  edm::LogInfo("FastL1GlobalAlgo::CaloTowersDump") << "End!";
128  */
129 
130 
132 
133  edm::LogInfo("FastL1GlobalAlgo::CaloTowersDump") << "Start!";
135 
136  for (CaloTowerCollection::const_iterator j=input->begin(); j!=input->end(); j++) {
137  edm::LogInfo("FastL1GlobalAlgo::CaloTowersDump") << *j;
138  }
139 
140  edm::LogInfo("FastL1GlobalAlgo::CaloTowersDump") << "End!";
141 }
142 
143 
144 // ------------ For sort() ------------
145 namespace myspace {
146  bool
147  //FastL1GlobalAlgo::greaterEt( const reco::Candidate& a, const reco::Candidate& b ) {
149  return (a.et()>b.et());
150  }
151 }
152 
153 // ------------ Find Jets ------------
154 void
156 
157  m_TauJets.clear();
158  m_CenJets.clear();
159  m_ForJets.clear();
160 
161  for (int i=0; i<396; i++) {
162  // barrel/endcap part only:
163  //if ((i%22)>3 && (i%22)<18) {
164  std::pair<double, double> p = m_RMap->getRegionCenterEtaPhi(i);
165 
166  //if (m_Regions.at(i).SumEt()>0.)
167  // std::cout<<"******** TEST "<<i<<": "<<m_Regions.at(i).SumEt()<<std::endl;
168 
169  double eta = p.first;
170  double phi = p.second;
171  if (m_DoBitInfo){
172  m_Regions[i].BitInfo.setEta(eta);
173  m_Regions[i].BitInfo.setPhi(phi);
174  }
175 
176  if (m_Regions.at(i).SumEt()>m_L1Config.JetSeedEtThreshold) {
177  if (isMaxEtRgn_Window33(i)) {
178  if (m_GctIso == true) {
179  if (TauIsolation(i) && (i%22)>3 && (i%22)<18 ) {
180  addJet(i,true);
181  } else {
182  addJet(i,false);
183  }
184  } else {
185  if (isTauJet(i) && (i%22)>3 && (i%22)<18 ) {
186  addJet(i,true);
187  } else {
188  addJet(i,false);
189  }
190  }
191  if (m_DoBitInfo) m_Regions[i].BitInfo.setMaxEt(true);
192  }
193  else {
194  if (m_DoBitInfo) m_Regions[i].BitInfo.setMaxEt(false);
195  }
196  if (m_DoBitInfo) m_Regions[i].BitInfo.setSumEtBelowThres (false);
197  } else {
198  if (m_DoBitInfo) m_Regions[i].BitInfo.setSumEtBelowThres (true);
199  }
200  //}
201  }
202 
203 }
204 
205 
206 // ------------ Add a jet ------------
207 void
208 FastL1GlobalAlgo::addJet(int iRgn, bool taubit) {
209  std::pair<double, double> p = m_RMap->getRegionCenterEtaPhi(iRgn);
210 
211  //double e = m_Regions.at(iRgn).GetJetE();
212  //double et = GCTEnergyTrunc(m_Regions.at(iRgn).GetJetEt(), m_L1Config.JetLSB, false);
213  double et = m_Regions.at(iRgn).GetJetEt();
214 
215  double eta = p.first;
216  double phi = p.second;
217 
218  if (m_L1Config.DoJetCorr) {
219  et = GCTEnergyTrunc(corrJetEt(et,eta), m_L1Config.JetLSB, false);
220  } else {
221  et = GCTEnergyTrunc(et, m_L1Config.JetLSB, false);
222  }
223 
224  double theta = 2.*atan(exp(-eta));
225  double ex = et*cos(phi);
226  double ey = et*sin(phi);
227  //double ex = e*sin(theta)*cos(phi);
228  //double ey = e*sin(theta)*sin(phi);
229  double e = ex/sin(theta)/cos(phi);
230  double ez = e*cos(theta);
231 
232  if (m_DoBitInfo){
233  m_Regions[iRgn].BitInfo.setEt(et);
234  m_Regions[iRgn].BitInfo.setEnergy(e);
235  }
236 
237  reco::Particle::LorentzVector rp4(ex,ey,ez,e);
238  l1extra::L1JetParticle tjet(rp4);
239 
240  if (et>=5.) {
241  if (m_DoBitInfo) m_Regions[iRgn].BitInfo.setHard(true);
242  if (m_DoBitInfo) m_Regions[iRgn].BitInfo.setSoft(false);
243  if ((taubit || et>m_L1Config.noTauVetoLevel) && (std::abs(eta)<3.0) ) {
244  m_TauJets.push_back(tjet);
245  // sort by et
247  } else {
248  if (std::abs(eta)<3.0) {
249  m_CenJets.push_back(tjet);
251  } else {
252  m_ForJets.push_back(tjet);
254  }
255  }
256  }
257  else{
258  if (m_DoBitInfo) m_Regions[iRgn].BitInfo.setSoft(true);
259  if (m_DoBitInfo) m_Regions[iRgn].BitInfo.setHard(false);
260  }
261 }
262 
263 
264 // ------------ Fill Egammas for TP input------------
265 void
267  m_Egammas.clear();
268  m_isoEgammas.clear();
269 
271  //l1extra::L1EmParticle ph;
272  for (int i=0; i<396; i++) {
273  CaloTowerCollection towers = m_Regions[i].GetCaloTowers();
274 
275  for (CaloTowerCollection::const_iterator cnd=towers.begin(); cnd!=towers.end(); cnd++) {
276  if (cnd->emEt()<0.01 && cnd->hadEt()<0.01) continue;
277  //if (cnd->emEt()<0.01) continue;
278 
279  reco::Particle::LorentzVector rp4(0.,0.,0.,0.);
280  // l1extra::L1EmParticle* ph = new l1extra::L1EmParticle(rp4);
281  *ph = l1extra::L1EmParticle(rp4);
282 
283  CaloTowerDetId cid = cnd->id();
284 
285  int emTag = isEMCand(cid,ph,e);
286 
287  // 1 = non-iso EM, 2 = iso EM
288  if (emTag==1) {
289  m_Egammas.push_back(*ph);
290  } else if (emTag==2) {
291  m_isoEgammas.push_back(*ph);
292  }
293 
294  }
297  }
298  delete ph;
299 }
300 
301 
302 // ------------ Fill Egammas for Tower input ------------
303 void
305  m_Egammas.clear();
306  m_isoEgammas.clear();
307 
308  //std::vector< edm::Handle<CaloTowerCollection> > input;
309  //e.getManyByType(input);
312 
313  //std::vector< edm::Handle<CaloTowerCollection> >::iterator j;
314  //for (j=input.begin(); j!=input.end(); j++) {
315  // const CaloTowerCollection& c=*(*j);
316 
318  //l1extra::L1EmParticle ph;
319  //for (CaloTowerCollection::const_iterator cnd=c.begin(); cnd!=c.end(); cnd++) {
320  for (CaloTowerCollection::const_iterator cnd=input->begin(); cnd!=input->end(); cnd++) {
321  reco::Particle::LorentzVector rp4(0.,0.,0.,0.);
322  //l1extra::L1EmParticle* ph = new l1extra::L1EmParticle(rp4);
323  *ph = l1extra::L1EmParticle(rp4);
324 
325  CaloTowerDetId cid = cnd->id();
326 
327  int emTag = isEMCand(cid,ph,e);
328 
329  // 1 = non-iso EM, 2 = iso EM
330  if (emTag==1) {
331  m_Egammas.push_back(*ph);
332  } else if (emTag==2) {
333  m_isoEgammas.push_back(*ph);
334  }
335 
336  }
337  //}
338 
341 
342  delete ph;
343 }
344 
345 // ------------ Fill MET 1: loop over towers ------------
346 void
348  m_METs.clear();
349 
350  //std::vector< edm::Handle<CaloTowerCollection> > input;
351  //e.getManyByType(input);
354 
355  double sum_hade = 0.0;
356  double sum_hadet = 0.0;
357  double sum_hadex = 0.0;
358  double sum_hadey = 0.0;
359  double sum_hadez = 0.0;
360  double sum_e = 0.0;
361  double sum_et = 0.0;
362  double sum_ex = 0.0;
363  double sum_ey = 0.0;
364  double sum_ez = 0.0;
365 
366  //std::vector< edm::Handle<CaloTowerCollection> >::iterator i;
367 
368  //for (i=input.begin(); i!=input.end(); i++) {
369  // const CaloTowerCollection& c=*(*i);
370 
371  // for (CaloTowerCollection::const_iterator candidate=c.begin(); candidate!=c.end(); candidate++) {
372  for (CaloTowerCollection::const_iterator candidate=input->begin(); candidate!=input->end(); candidate++) {
373  //double eme = candidate->emEnergy();
374  //double hade = candidate->hadEnergy();
375  double eme = candidate->emEt();
376  double hade = candidate->hadEt();
377 
378  double EThres = 0.;
379  double HThres = 0.;
380  double EBthres = m_L1Config.TowerEBThreshold;
381  double HBthres = m_L1Config.TowerHBThreshold;
382  double EEthres = m_L1Config.TowerEBThreshold;
383  double HEthres = m_L1Config.TowerEEThreshold;
384 
385  //if(std::abs(candidate->eta())<1.479) {
386  if(std::abs(candidate->eta())<2.322) {
387  EThres = EBthres;
388  } else {
389  EThres = EEthres;
390  }
391  //if(std::abs(candidate->eta())<1.305) {
392  if(std::abs(candidate->eta())<2.322) {
393  HThres = HBthres;
394  } else {
395  HThres = HEthres;
396  }
397 
398  // rescale energies
399  double emScale = 1.0;
400  double hadScale = 1.0;
401  if (std::abs(candidate->eta()>1.3050) && std::abs(candidate->eta())<3.0) {
402  hadScale = m_L1Config.TowerHEScale;
403  emScale = m_L1Config.TowerEEScale;
404  }
405  if (std::abs(candidate->eta()<1.3050)) {
406  hadScale = m_L1Config.TowerHBScale;
407  emScale = m_L1Config.TowerEBScale;
408  }
409  eme *= emScale;
410  hade *= hadScale;
411 
412  if (eme>=EThres || hade>=HThres) {
413  double phi = candidate->phi();
414  double eta = candidate->eta();
415  //double et = candidate->et();
416  //double e = candidate->energy();
417  double theta = 2.*atan(exp(-eta));
418  double et = 0.;
419  double e = 0.;
420  double had_et = 0.;
421  double had_e = 0.;
422 
423  if (eme>=EThres) {
424  et += candidate->emEt();
425  e += candidate->emEnergy();
426  }
427  if (hade>=HThres) {
428  et += candidate->hadEt();
429  e += candidate->hadEnergy();
430  had_et += candidate->hadEt();
431  had_e += candidate->hadEnergy();
432  }
433 
434  //sum_et += et;
435  sum_et += RCTEnergyTrunc(et,1.0,1024);
436  sum_ex += et*cos(phi);
437  sum_ey += et*sin(phi);
438  //sum_ex += e*sin(theta)*cos(phi);
439  //sum_ey += e*sin(theta)*sin(phi);
440  //sum_e += e;
441  sum_e += et/sin(theta);
442  sum_ez += et*cos(theta)/sin(theta);
443 
444  sum_hadet += had_et;
445  sum_hadex += had_et*cos(phi);
446  sum_hadey += had_et*sin(phi);
447  //sum_hadex += had_e*sin(theta)*cos(phi);
448  //sum_hadey += had_e*sin(theta)*sin(phi);
449  //sum_hade += had_e;
450  sum_hade += had_et/sin(theta);
451  sum_hadez += had_et*cos(theta)/sin(theta);
452  }
453  }
454  //}
455 
456  reco::Particle::LorentzVector rp4(-sum_ex,-sum_ey,0.,std::sqrt(sum_ex*sum_ex + sum_ey*sum_ey));
457  //m_MET = l1extra::L1EtMissParticle(rp4,sum_et,0.);
459 }
460 
461 // ------------ Fill MET 2: loop over regions ------------
462 void
464  m_METs.clear();
465 
466  //double sum_e = 0.0;
467  double sum_et = 0.0;
468  double sum_ex = 0.0;
469  double sum_ey = 0.0;
470  //double sum_ez = 0.0;
471 
472  for (int i=0; i<396; i++) {
473  std::pair<double, double> etaphi = m_RMap->getRegionCenterEtaPhi(i);
474  double phi = etaphi.second;
475  //double eta = etaphi.first;
476  //double theta = 2.*atan(exp(-eta));
477 
478  double et = m_Regions[i].SumEt();
479  //double e = m_Regions[i].SumE();
480 
481  //sum_et += et;
482  //sum_et += RCTEnergyTrunc(et,0.5,2048);
483  //sum_et += et;
484  //sum_ex += RCTEnergyTrunc(et*cos(phi),0.5,2048);
485  //sum_ey += RCTEnergyTrunc(et*sin(phi),0.5,2048);
486  sum_ex += et*cos(phi);
487  sum_ey += et*sin(phi);
488  //sum_ex += e*sin(theta)*cos(phi);
489  //sum_ey += e*sin(theta)*sin(phi);
490  //sum_e += e;
491  //sum_e += RCTEnergyTrunc(et/sin(theta),0.5,2048);
492  //sum_ez += RCTEnergyTrunc(et*cos(theta)/sin(theta),0.5,2048);
493  //sum_e += et/sin(theta);
494  //sum_ez += et*cos(theta)/sin(theta);
495  //sum_ez += e*cos(theta);
496  //sum_et += e*sin(theta);
497  }
498 
499  //sum_et = RCTEnergyTrunc(std::sqrt(sum_ex*sum_ex + sum_ey*sum_ey),0.5,2048);
500  sum_et = std::sqrt(sum_ex*sum_ex + sum_ey*sum_ey);
501 
502  //reco::Particle::LorentzVector rp4(-sum_ex,-sum_ey,-sum_ez,sum_e);
503  reco::Particle::LorentzVector rp4(-sum_ex,-sum_ey,0.,std::sqrt(sum_ex*sum_ex + sum_ey*sum_ey));
504  //edm::LogInfo("********** FastL1GlobalAlgo::FillMET()")<<rp4.mass()<<std::endl;
505  //m_MET = l1extra::L1EtMissParticle(rp4,sum_et,0.);
507 
508 }
509 
510 void
512 {
513  m_Regions.clear();
514  m_Regions = std::vector<FastL1Region>(396); // ieta: 1-22, iphi: 1-18
515 
516  // init regions
517  for (int i=0; i<396; i++) {
518  m_Regions[i].SetParameters(m_L1Config);
519  m_Regions[i].SetDoBitInfo(m_DoBitInfo);
520  std::pair<int, int> p = m_RMap->getRegionEtaPhiIndex(i);
521  m_Regions[i].SetEtaPhiIndex(p.first,p.second,i);
522  CaloTower c;
523  for (int twrid=0; twrid<16; twrid++) {
524  m_Regions[i].FillTowerZero(c,twrid);
525  }
526  }
527 }
528 
529 // ------------ Fill L1 Regions on Trigger Primitives------------
530 void
532 {
533  //edm::ESHandle<CaloTowerConstituentsMap> cttopo;
534  //s.get<IdealGeometryRecord>().get(cttopo);
535  //const CaloTowerConstituentsMap* theTowerConstituentsMap = cttopo.product();
536 
537  InitL1Regions();
538 
540  //c.get<IdealGeometryRecord>().get(cGeom);
541  s.get<CaloGeometryRecord>().get(cGeom);
542 
544  e.getByLabel(m_L1Config.EcalTPInput,ETPinput);
545 
547  e.getByLabel(m_L1Config.HcalTPInput,HTPinput);
548 
549  //CaloTowerCollection towers;
550  int hEtV [396][16] = {{0}};
551  // int hFGV [396][16] = {{0}};
552  int hiEtaV[396][16] = {{0}};
553  int hiPhiV[396][16] = {{0}};
554  for (HcalTrigPrimDigiCollection::const_iterator hTP=HTPinput->begin();
555  hTP!=HTPinput->end(); hTP++) {
556 
557  int rgnid = 999;
558  int twrid = 999;
559 
560  int hiphi = hTP->id().iphi();
561  int hieta = hTP->id().ieta();
562 
563  /*
564  if(abs(hieta) > 20 && hiphi%2 == 0) hiphi--;
565  std::pair<int, int> prim_tower_feed; // prim tower indeces iEta +/- 1~32, iPhi (+) 1~72
566  prim_tower_feed.first = hieta;
567  prim_tower_feed.second = hiphi;
568  std::pair<int, int> rct_index = m_RMap-> getRegionEtaPhiIndex(prim_tower_feed); // convert prim tower indeces into RCT indeces ieta 0~21, iphi 0~17
569  rgnid = rct_index.second*22 + rct_index.first; // converting fastL1 obsolete RCT numbering
570  */
571 
572  rgnid = m_RMap->getRegionIndex(hieta,hiphi);
573  twrid = m_RMap->getRegionTowerIndex(hieta,hiphi);
574 
575  /*
576  if (std::abs(htwrid.ieta())>28) {
577  std::cout<<htwrid.ieta()<<" "<<htwrid.iphi()<<" "<<rgnid<<" "<<twrid<<" "<<std::endl;
578  }
579  */
580 
581  /*
582  if (hTP->SOI_compressedEt()>0) {
583  std::cout<<"hcalTP >>> "<<hTP->SOI_compressedEt()<<" "<<hTP->SOI_fineGrain()<<" "
584  <<rgnid<<" "<<twrid<<std::endl;
585  }
586  */
587  if(rgnid < 396 && twrid < 16){
588  hEtV[rgnid][twrid] = (int)hTP->SOI_compressedEt();
589  // hFGV[rgnid][twrid] = (int)hTP->SOI_fineGrain();
590  hiEtaV[rgnid][twrid] = hieta;
591  hiPhiV[rgnid][twrid] = hiphi;
592  }
593  }
594 
595 
596  int emEtV [396][16] = {{0}};
597  int emFGV [396][16] = {{0}};
598  int emiEtaV[396][16] = {{0}};
599  int emiPhiV[396][16] = {{0}};
600  //double emEtaV[396][16] = {0.};
601  for (EcalTrigPrimDigiCollection::const_iterator eTP=ETPinput->begin();
602  eTP!=ETPinput->end(); eTP++) {
603 
604  int eieta = eTP->id().ieta();
605 
606  if(abs(eieta)> 28) continue; // no crystal in HF
607  else{
608  int eiphi = eTP->id().iphi();
609  //int teiphi = eiphi;
610 
611  int rgnid = 999;
612  int twrid = 999;
613 
614  //if(abs(eieta) > 20 && eiphi%2 == 0) teiphi=eiphi-1;
615 
616  /*
617  if(abs(eieta) > 20 && eiphi%2 == 0) eiphi--;
618  std::pair<int, int> prim_tower_feed; // prim tower indeces iEta +/- 1~28, iPhi (+) 1~72
619  prim_tower_feed.first = eieta;
620  prim_tower_feed.second = eiphi;
621  std::pair<int, int> rct_index = m_RMap-> getRegionEtaPhiIndex(prim_tower_feed); // convert prim tower indeces into RCT indeces ieta 0~21, iphi 0~17
622  rgnid = rct_index.second*22 + rct_index.first; // converting fastL1 obsolete RCT numbering
623  */
624 
625  /*
626  rgnid = m_RMap->getRegionIndex(eieta,eiphi);
627  twrid = m_RMap->getRegionTowerIndex(eieta,eiphi);
628 
629  if (eTP->compressedEt()>0) {
630  std::cout<<"ecalTP *** "<<eTP->compressedEt()<<" "<<eTP->fineGrain()<<" "
631  <<rgnid<<" "<<twrid<<std::endl;
632  }
633  */
634  if(rgnid < 396 && twrid < 16){
635  emEtV[rgnid][twrid] = (int)eTP->compressedEt();
636  emFGV[rgnid][twrid] = (int)eTP->fineGrain();
637  emiEtaV[rgnid][twrid] = eieta;
638  emiPhiV[rgnid][twrid] = eiphi;
639 
640  //edm::ESHandle<CaloGeometry> cGeom;
641  //s.get<IdealGeometryRecord>().get(cGeom);
642 
643  //CaloTowerDetId towerDetId = CaloTowerDetId( eieta, teiphi);
644  //CaloTowerDetId towerDetId2 = CaloTowerDetId( eieta, eiphi);
645  //const GlobalPoint gP1 = cGeom->getPosition(towerDetId);
646  //const GlobalPoint gP12 = cGeom->getPosition(towerDetId2);
647  //double eta = gP1.eta();
648 
649  //if(abs(eieta) > 20)
650  //std::cout<<eiphi<<" "<<gP1.phi()<<" "<<eieta<<" "<<gP1.eta()<<" "<<std::endl;
651 
652  //double phi = gP1.phi();
653  //emEtaV[rgnid][twrid] = eta;
654  }
655  } // else
656  } // ecalTP
657 
658 
659  for (int i=0; i<396; i++) {
660  for (int j=0; j<16; j++) {
661  if (emEtV[i][j]>0 || hEtV[i][j]>0) {
662 
663 
664  std::pair<double, double> etaphi
666  double eta = etaphi.first;
667  double phi = etaphi.second;
668 
669 
670  double emEt = ((double) emEtV[i][j]) * m_L1Config.EMLSB;
671  //double hadEt = ((double )hEtV[i][j]) * m_L1Config.JetLSB * cos(2.*atan(exp(-hiEtaV[i][j])));
672  int iAbsTwrEta = std::abs(hiEtaV[i][j]);
673  //double hadEt = ((double )hcaletValue(iAbsTwrEta, hEtV[i][j])) * m_L1Config.JetLSB;
674  double hadEt = ((double )hcaletValue(iAbsTwrEta, hEtV[i][j]));
675  //double hadEt = hEtV[i][j] * m_L1Config.JetLSB;
676 
677  if (m_L1Config.DoEMCorr) {
678  //emEt = corrEmEt(emEt,emEtaV[i][j]);
679  emEt = corrEmEt(emEt,std::abs(emiEtaV[i][j]));
680  }
681 
682  double et = emEt + hadEt;
684  //s.get<IdealGeometryRecord>().get(cGeom);
685  s.get<CaloGeometryRecord>().get(cGeom);
686 
687 
688  //math::RhoEtaPhiVector lvec(et,eta,phi);
689  math::XYZTLorentzVector lvec(et,eta,phi,0.);
690  //math::PtEtaPhiMLorentzVector lvec(et,eta,phi,0.);
691 
692  CaloTowerDetId towerDetId;
693  if (emEtV[i][j]>0)
694  towerDetId = CaloTowerDetId(emiEtaV[i][j],emiPhiV[i][j]);
695  else
696  towerDetId = CaloTowerDetId(hiEtaV[i][j],hiPhiV[i][j]);
697 
698  GlobalPoint gP = cGeom->getPosition(towerDetId);
699  CaloTower t = CaloTower(towerDetId,
700  emEt, hadEt, 0.,
701  0, 0, lvec,
702  gP, gP);
703 
704  //m_Regions[i].FillTower_Scaled(t,j,false);
705  m_Regions[i].FillTower_Scaled(t,j,true,cGeom);
706 
707  /*
708  if (et>0) {
709  std::cout<<"+++ "<<emEt<<" "<<hadEt<<" "
710  <<i<<" "<<j<<" "
711  <<std::endl<<"-- "
712  <<t.emEt()<<" "<<t.hadEt()<<" "
713  <<t.eta()<<" "<<t.phi()<<" "
714  <<std::endl;
715  }
716  */
717 
718 
719  // Explicitely take care of integer boolean conversion
720  if (emEt > 3.0 && emEt < m_L1Config.noFGThreshold && (int)emFGV[i][j]!=0)
721  m_Regions[i].SetFGBit(j,true);
722  else
723  m_Regions[i].SetFGBit(j,false);
724 
725  if (emEt > 3.0){
726  if (emEt < 60. && hadEt/emEt > m_L1Config.hOeThreshold)
727  m_Regions[i].SetHOEBit(j,true);
728  else
729  m_Regions[i].SetHOEBit(j,false);
730  }
731  else
732  m_Regions[i].SetHOEBit(j,false);
733 
734  m_Regions[i].SetRegionBits(e);
735  }
736 
737 
738  }
739  }
740 
741 
742 
743 
744 
745 
746 }
747 
748 // ------------ Fill L1 Regions on Towers and RecHits------------
749 void
751 {
752  InitL1Regions();
753 
756 
758  c.get<IdealGeometryRecord>().get(cttopo);
759  const CaloTowerConstituentsMap* theTowerConstituentsMap = cttopo.product();
760 
762  c.get<CaloTopologyRecord>().get(calotopo);
763 
765  //c.get<IdealGeometryRecord>().get(cGeom);
766  c.get<CaloGeometryRecord>().get(cGeom);
767 
769  e.getByLabel(m_L1Config.EmInputs.at(1),ec1);
770 
772  e.getByLabel(m_L1Config.EmInputs.at(0),ec0);
773 
774  // ascii visualisation of mapping
775  //m_RMap->display();
776 
777 
778  // works for barrel/endcap region only right now!
779  //std::vector< edm::Handle<CaloTowerCollection> > input;
780  //e.getManyByType(input);
781  //edm::Handle<CaloTowerCollection> input;
782  //e.getByLabel(m_L1Config.TowerInput,input);
783 
784  //std::vector< edm::Handle<CaloTowerCollection> >::iterator j;
785  //for (j=input.begin(); j!=input.end(); j++) {
786  // const CaloTowerCollection& c=*(*j);
787 
788  // for (CaloTowerCollection::const_iterator cnd=c.begin(); cnd!=c.end(); cnd++) {
789  for (CaloTowerCollection::const_iterator cnd=input->begin(); cnd!=input->end(); cnd++) {
790 
791  CaloTowerDetId cid = cnd->id();
792  std::pair<int, int> pep = m_RMap->getRegionEtaPhiIndex(cid);
793 
794  int rgnid = 999;
795  int twrid = 999;
796 
797  if (std::abs(pep.first)<=22) {
798  rgnid = pep.second*22 + pep.first;
799  twrid = m_RMap->getRegionTowerIndex(cid);
800  //std::cout << rgnid << " " << twrid << std::endl;
801  //std::cout << cnd->emEt() << " " << cnd->hadEt() << std::endl;
802  }
803 
804  if (rgnid<396 && twrid<16) {
805  m_Regions[rgnid].FillTower_Scaled(*cnd,twrid,true,cGeom);
806  m_Regions[rgnid].SetRegionBits(e);
807  }
808 
809  }
810 
811  //}
812 
813  // Fill EM Crystals
814  for (int i=0; i<396; i++) {
815 
816  //m_Regions[i].FillEMCrystals(e,iConfig,m_RMap);
817  m_Regions[i].FillEMCrystals(theTowerConstituentsMap,
818  &(*calotopo),
819  &(*cGeom),
820  &(*ec0), &(*ec1),
821  m_RMap);
822 
823  }
824 
825  //checkMapping();
826 
827 }
828 
829 
830 // Fill Bitwords
831 void
833  if (m_DoBitInfo){
834  m_BitInfos.clear();
835  for (int i=0; i<396; i++) {
836  m_BitInfos.push_back(m_Regions[i].getBitInfo());
837  }
838  }
839 }
840 
841 // ------------ Check if jet is taujet ------------
842 bool
844 
845  // Barrel and Endcap only
846  if ((cRgn%22)<4 || (cRgn%22)>17)
847  return false;
848 
849  int shower_shape = 0;
850  int et_isolation = 0;
851 
852  if (m_Regions[cRgn].GetTauBit()) {
853  shower_shape = 1;
854  //if (m_DoBitInfo) m_Regions[cRgn].BitInfo.setTauVeto(true);
855  } else {
856  shower_shape = 0;
857  //if (m_DoBitInfo) m_Regions[cRgn].BitInfo.setTauVeto(false);
858  }
859 
860  int nwid = m_Regions[cRgn].GetNWId();
861  int nid = m_Regions[cRgn].GetNorthId();
862  int neid = m_Regions[cRgn].GetNEId();
863  int wid = m_Regions[cRgn].GetWestId();
864  int eid = m_Regions[cRgn].GetEastId();
865  int swid = m_Regions[cRgn].GetSWId();
866  int sid = m_Regions[cRgn].GetSouthId();
867  int seid = m_Regions[cRgn].GetSEId();
868 
869  //Use 3x2 window at eta borders!
870  // west border:
871  if ((cRgn%22)==4) {
872  if (m_Regions[nid].GetTauBit() ||
873  m_Regions[neid].GetTauBit() ||
874  m_Regions[eid].GetTauBit() ||
875  m_Regions[seid].GetTauBit() ||
876  m_Regions[sid].GetTauBit() ) {
877  et_isolation = 1;
878  }
879  }
880 
881  // east border:
882  if ((cRgn%22)==17) {
883  if (m_Regions[nid].GetTauBit() ||
884  m_Regions[nwid].GetTauBit() ||
885  m_Regions[wid].GetTauBit() ||
886  m_Regions[swid].GetTauBit() ||
887  m_Regions[sid].GetTauBit() ) {
888  et_isolation = 1;
889  }
890  }
891 
892  if ( (cRgn%22)>4 && (cRgn%22)<17){ // non-border
893  if (nwid==999 || neid==999 || nid==999 || swid==999 || seid==999 || sid==999 || wid==999 ||
894  eid==999 ) {
895  return false;
896  }
897 
898  if (m_Regions[nwid].GetTauBit() ||
899  m_Regions[nid].GetTauBit() ||
900  m_Regions[neid].GetTauBit() ||
901  m_Regions[wid].GetTauBit() ||
902  m_Regions[eid].GetTauBit() ||
903  m_Regions[swid].GetTauBit() ||
904  m_Regions[seid].GetTauBit() ||
905  m_Regions[sid].GetTauBit() ) {
906  et_isolation = 1;
907  }
908  } // non-border
909 
910  if (m_DoBitInfo) {
911  if (et_isolation == 1) {
912  //std::cout<<"*********************************"<<std::endl;
913  //std::cout<<"Rgn iso veto: "<<et_isolation<<std::endl;
914  m_Regions[cRgn].BitInfo.setIsolationVeto(true);
915  } else {
916  m_Regions[cRgn].BitInfo.setIsolationVeto(false);
917  }
918  // if (shower_shape == 1) {
919  //std::cout<<"###############################"<<std::endl;
920  //std::cout<<"Rgn shower veto: "<<shower_shape<<std::endl;
921  //}
922  }
923 
924  if (et_isolation == 1 || shower_shape == 1) return false;
925  else return true;
926 
927 }
928 
929 // ------------ Check if tower is emcand ------------
930 // returns 1 = non-iso EM, 2 = iso EM, 0 = no EM
931 int
933 
934  // center tower
935  int crgn = m_RMap->getRegionIndex(cid);
936  int ctwr = m_RMap->getRegionTowerIndex(cid);
937 
938  // crystals only in barrel/endcap part
939  if ((crgn%22)<4 || (crgn%22)>17) return 0;
940  if (crgn>395 || crgn < 0 || ctwr > 15 || ctwr < 0) return 0;
941 
942  CaloTowerCollection c = m_Regions.at(crgn).GetCaloTowers();
943  double cenEt = c[ctwr].et();
944  //double cenEt = RCTEnergyTrunc(c[ctwr].et(),0.5,64);
945  //double cenE = c[ctwr].emEnergy();
946 
947  // Using region position rather than tower position
948  std::pair<double, double> crpos = m_RMap->getRegionCenterEtaPhi(crgn);
949  //double cenEta = c[ctwr].eta();
950  //double cenPhi = c[ctwr].phi();
951  double cenEta = crpos.first;
952  double cenPhi = crpos.second;
953 
954  double cenFGbit = m_Regions.at(crgn).GetFGBit(ctwr);
955  double cenHOEbit = m_Regions.at(crgn).GetHOEBit(ctwr);
956 
957  if (cenEt<m_L1Config.TowerEBThreshold) return 0;
958 
959  // check fine grain bit
960  if (cenFGbit) return 0;
961 
962  // check H/E bit
963  if (cenHOEbit) return 0;
964 
965  // check neighbours
966  std::pair<int, int> no = m_RMap->GetTowerNorthEtaPhi(cid.ieta(),cid.iphi());
967  std::pair<int, int> so = m_RMap->GetTowerSouthEtaPhi(cid.ieta(),cid.iphi());
968  std::pair<int, int> we = m_RMap->GetTowerWestEtaPhi(cid.ieta(),cid.iphi());
969  std::pair<int, int> ea = m_RMap->GetTowerEastEtaPhi(cid.ieta(),cid.iphi());
970  std::pair<int, int> nw = m_RMap->GetTowerNWEtaPhi(cid.ieta(),cid.iphi());
971  std::pair<int, int> ne = m_RMap->GetTowerNEEtaPhi(cid.ieta(),cid.iphi());
972  std::pair<int, int> sw = m_RMap->GetTowerSWEtaPhi(cid.ieta(),cid.iphi());
973  std::pair<int, int> se = m_RMap->GetTowerSEEtaPhi(cid.ieta(),cid.iphi());
974  if (no.first>29 || no.first<-29 || no.second>72 || no.second<0) return 0;
975  if (so.first>29 || so.first<-29 || so.second>72 || so.second<0) return 0;
976  if (we.first>29 || we.first<-29 || we.second>72 || we.second<0) return 0;
977  if (ea.first>29 || ea.first<-29 || ea.second>72 || ea.second<0) return 0;
978  if (nw.first>29 || nw.first<-29 || nw.second>72 || nw.second<0) return 0;
979  if (ne.first>29 || ne.first<-29 || ne.second>72 || ne.second<0) return 0;
980  if (sw.first>29 || sw.first<-29 || sw.second>72 || sw.second<0) return 0;
981  if (se.first>29 || se.first<-29 || se.second>72 || se.second<0) return 0;
982 
983  int notwr = m_RMap->getRegionTowerIndex(no);
984  int norgn = m_RMap->getRegionIndex(no.first,no.second);
985  int sotwr = m_RMap->getRegionTowerIndex(so);
986  int sorgn = m_RMap->getRegionIndex(so.first,so.second);
987  int wetwr = m_RMap->getRegionTowerIndex(we);
988  int wergn = m_RMap->getRegionIndex(we.first,we.second);
989  int eatwr = m_RMap->getRegionTowerIndex(ea);
990  int eargn = m_RMap->getRegionIndex(ea.first,ea.second);
991  int setwr = m_RMap->getRegionTowerIndex(se);
992  int sergn = m_RMap->getRegionIndex(se.first,sw.second);
993  int swtwr = m_RMap->getRegionTowerIndex(sw);
994  int swrgn = m_RMap->getRegionIndex(sw.first,sw.second);
995  int netwr = m_RMap->getRegionTowerIndex(ne);
996  int nergn = m_RMap->getRegionIndex(ne.first,ne.second);
997  int nwtwr = m_RMap->getRegionTowerIndex(nw);
998  int nwrgn = m_RMap->getRegionIndex(nw.first,nw.second);
999 
1000  //
1001  if (norgn>395 || norgn < 0 || notwr > 15 || notwr < 0) return 0;
1002  c = m_Regions[norgn].GetCaloTowers();
1003  double noEt = c[notwr].et();
1004  //double noEt = RCTEnergyTrunc(c[notwr].et(),0.5,64);
1005  //double noE = c[notwr].emEnergy();
1006  // check fine grain bit
1007  bool noFGbit = m_Regions[norgn].GetFGBit(notwr);
1008  // check H/E bit
1009  bool noHOEbit = m_Regions[norgn].GetHOEBit(notwr);
1010 
1011  //
1012  if (sorgn>395 || sorgn < 0 || sotwr > 15 || sotwr < 0) return 0;
1013  c = m_Regions[sorgn].GetCaloTowers();
1014  double soEt = c[sotwr].et();
1015  //double soEt = RCTEnergyTrunc(c[sotwr].et(),0.5,64);
1016  //double soE = c[sotwr].emEnergy();
1017  // check fine grain bit
1018  bool soFGbit = m_Regions[sorgn].GetFGBit(sotwr);
1019  // check H/E bit
1020  bool soHOEbit = m_Regions[sorgn].GetHOEBit(sotwr);
1021 
1022  //
1023  if (wergn>395 || wergn < 0 || wetwr > 15 || wetwr < 0) return 0;
1024  c = m_Regions[wergn].GetCaloTowers();
1025  double weEt = c[wetwr].et();
1026  //double weEt = RCTEnergyTrunc(c[wetwr].et(),0.5,64);
1027  //double weE = c[wetwr].emEnergy();
1028  // check fine grain bit
1029  bool weFGbit = m_Regions[wergn].GetFGBit(wetwr);
1030  // check H/E bit
1031  bool weHOEbit = m_Regions[wergn].GetHOEBit(wetwr);
1032 
1033  //
1034  if (eargn>395 || eargn < 0 || eatwr > 15 || eatwr < 0) return 0;
1035  c = m_Regions[eargn].GetCaloTowers();
1036  double eaEt = c[eatwr].et();
1037  //double eaEt = RCTEnergyTrunc(c[eatwr].et(),0.5,64);
1038  //double eaE = c[eatwr].emEnergy();
1039  // check fine grain bit
1040  bool eaFGbit = m_Regions[eargn].GetFGBit(eatwr);
1041  // check H/E bit
1042  bool eaHOEbit = m_Regions[eargn].GetHOEBit(eatwr);
1043 
1044  //
1045  if (nwrgn>395 || nwrgn < 0 || nwtwr > 15 || nwtwr < 0) return 0;
1046  c = m_Regions[nwrgn].GetCaloTowers();
1047  double nwEt = c[nwtwr].et();
1048  //double nwEt = RCTEnergyTrunc(c[nwtwr].et(),0.5,64);
1049  //double nwE = c[nwtwr].emEnergy();
1050  // check fine grain bit
1051  bool nwFGbit = m_Regions[nwrgn].GetFGBit(nwtwr);
1052  // check H/E bit
1053  bool nwHOEbit = m_Regions[nwrgn].GetHOEBit(nwtwr);
1054 
1055  //
1056  if (nergn>395 || nergn < 0 || netwr > 15 || netwr < 0) return 0;
1057  c = m_Regions[nergn].GetCaloTowers();
1058  double neEt = c[netwr].et();
1059  //double neEt = RCTEnergyTrunc(c[netwr].et(),0.5,64);
1060  //double neE = c[netwr].emEnergy();
1061  // check fine grain bit
1062  bool neFGbit = m_Regions[nergn].GetFGBit(netwr);
1063  // check H/E bit
1064  bool neHOEbit = m_Regions[nergn].GetHOEBit(netwr);
1065 
1066  //
1067  if (swrgn>395 || swrgn < 0 || swtwr > 15 || swtwr < 0) return 0;
1068  c = m_Regions[swrgn].GetCaloTowers();
1069  double swEt = c[swtwr].et();
1070  //double swEt = RCTEnergyTrunc(c[swtwr].et(),0.5,64);
1071  //double swE = c[swtwr].emEnergy();
1072  // check fine grain bit
1073  bool swFGbit = m_Regions[swrgn].GetFGBit(swtwr);
1074  // check H/E bit
1075  bool swHOEbit = m_Regions[swrgn].GetHOEBit(swtwr);
1076 
1077  //
1078  if (sergn>395 || sergn < 0 || setwr > 15 || setwr < 0) return 0;
1079  c = m_Regions[sergn].GetCaloTowers();
1080  double seEt = c[setwr].et();
1081  //double seEt = RCTEnergyTrunc(c[setwr].et(),0.5,64);
1082  //double seE = c[setwr].emEnergy();
1083  // check fine grain bit
1084  bool seFGbit = m_Regions[sergn].GetFGBit(setwr);
1085  // check H/E bit
1086  bool seHOEbit = m_Regions[sergn].GetHOEBit(setwr);
1087 
1088 
1089  // check if highest et tower
1090  bool isHit = ( cenEt > noEt && cenEt >= soEt && cenEt > weEt &&
1091  cenEt >= eaEt && cenEt > nwEt && cenEt > neEt &&
1092  cenEt >= swEt && cenEt >= seEt );
1093  if (!isHit) return 0;
1094 
1095  // find highest neighbour
1096  double hitEt = cenEt;
1097  //double hitE = cenE;
1098  double maxEt = std::max(noEt,std::max(soEt,std::max(weEt,eaEt)));
1099  //double maxE = std::max(noE,std::max(soE,std::max(weE,eaE)));
1100 
1101  // check 2 tower Et
1102  float emEtThres = m_L1Config.EMSeedEnThreshold;
1103 
1104  // at this point candidate is at least non-iso Egamma
1105  //double eme = (hitE+maxE);
1106  //double eme = (hitE+maxE);
1107  double emet = (hitEt+maxEt);
1108 
1109  /*
1110  if (m_L1Config.DoEMCorr) {
1111  emet = GCTEnergyTrunc(corrEmEt(emet,cenEta),m_L1Config.EMLSB, true);
1112  //emet = GCTEnergyTrunc(emet,m_L1Config.EMLSB, true);
1113  } else {
1114  emet = GCTEnergyTrunc(emet,m_L1Config.EMLSB, true);
1115  }
1116  */
1117  emet = GCTEnergyTrunc(emet,m_L1Config.EMLSB, true);
1118 
1119  if ((emet)<emEtThres) return 0;
1120 
1121  double emtheta = 2.*atan(exp(-cenEta));
1122  //double emet = eme*sin(emtheta);
1123  double emex = emet*cos(cenPhi);
1124  double emey = emet*sin(cenPhi);
1125  //double emex = eme*sin(emtheta)*cos(cenPhi);
1126  //double emey = eme*sin(emtheta)*sin(cenPhi);
1127  double eme = emex/sin(emtheta)/cos(cenPhi);
1128  double emez = eme*cos(emtheta);
1129 
1130 
1131  reco::Particle::LorentzVector rp4(emex,emey,emez,eme);
1132  //reco::Particle::Point rp3(0.,0.,0.);
1133  //reco::Particle::Charge q(0);
1134  //*ph = reco::Photon(q,rp4,rp3);
1135  *ph = l1extra::L1EmParticle(rp4);
1136  //ph = l1extra::L1EmParticle(rp4);
1137 
1138  //std::cout<<"EM eme : "<<eme<<std::endl;
1139  //std::cout<<"EM rp4.et(): "<<rp4.Et()<<std::endl;
1140  //std::cout<<"EM ph->et() : "<<ph->et()<<std::endl;
1141 
1142  //if (emet>0.) {
1143  // std::cout << "em region et, eta, phi: "<< emet<<" "<< cenEta<<" "<< cenPhi<<" " << std::endl;
1144  // std::cout << "em lv et, eta, phi: "<< ph->et()<<" "<< ph->eta()<<" "<< ph->phi()<<" " << std::endl;
1145  //}
1146 
1147  // check isolation FG bits
1148  if (noFGbit || soFGbit || weFGbit || eaFGbit ||
1149  nwFGbit || neFGbit || swFGbit || seFGbit ||
1150  noHOEbit || soHOEbit || weHOEbit || eaHOEbit ||
1151  nwHOEbit || neHOEbit || swHOEbit || seHOEbit)
1152  return 1;
1153 
1154  // check isolation corners
1155  //double corThres = 0.4;
1156  //double quietThres = m_L1Config.EMNoiseLevel;
1157  double quietThres = m_L1Config.QuietRegionThreshold;
1158  bool isoVeto1 = false,isoVeto2 = false,isoVeto3 = false,isoVeto4 = false;
1159  if (swEt>quietThres || weEt>quietThres || nwEt>quietThres || noEt>quietThres || neEt>quietThres ) {
1160  //if ((swEt + weEt + nwEt + noEt + neEt)/cenEt > corThres)
1161  isoVeto1 = true;
1162  }
1163  if (neEt>quietThres || eaEt>quietThres || seEt>quietThres || soEt>quietThres || swEt>quietThres ) {
1164  //if ((neEt + eaEt + seEt + soEt + swEt)/cenEt > corThres)
1165  isoVeto2 = true;
1166  }
1167  if (nwEt>quietThres || noEt>quietThres || neEt>quietThres || eaEt>quietThres || seEt>quietThres ) {
1168  //if ((nwEt + noEt + neEt + eaEt + seEt)/cenEt > corThres)
1169  isoVeto3 = true;
1170  }
1171  if (seEt>quietThres || soEt>quietThres || swEt>quietThres || weEt>quietThres || nwEt>quietThres ) {
1172  //if ((seEt + soEt + swEt + weEt + nwEt)/cenEt > corThres)
1173  isoVeto4 = true;
1174  }
1175  if (isoVeto1 && isoVeto2 && isoVeto3 && isoVeto4)
1176  return 1;
1177 
1178  return 2;
1179 }
1180 
1181 
1182 // is central region the highest Et Region?
1183 bool
1185 
1186  int nwid = m_Regions.at(crgn).GetNWId();
1187  int nid = m_Regions.at(crgn).GetNorthId();
1188  int neid = m_Regions.at(crgn).GetNEId();
1189  int wid = m_Regions.at(crgn).GetWestId();
1190  int eid = m_Regions.at(crgn).GetEastId();
1191  int swid = m_Regions.at(crgn).GetSWId();
1192  int sid = m_Regions.at(crgn).GetSouthId();
1193  int seid = m_Regions.at(crgn).GetSEId();
1194 
1195 
1196  //Use 3x2 window at eta borders!
1197  // east border:
1198  if ((crgn%22)==21) {
1199 
1200  if (nwid==999 || nid==999 || swid==999 || sid==999 || wid==999 ) {
1201  return false;
1202  }
1203 
1204  double cenet = m_Regions.at(crgn).SumEt();
1205  double nwet = m_Regions[nwid].SumEt();
1206  double noet = m_Regions[nid].SumEt();
1207  double weet = m_Regions[wid].SumEt();
1208  double swet = m_Regions[swid].SumEt();
1209  double soet = m_Regions[sid].SumEt();
1210 
1211  if ( cenet > nwet && cenet > noet &&
1212  cenet >= weet && cenet >= soet &&
1213  cenet >= swet )
1214  {
1215 
1216  double cene = m_Regions.at(crgn).SumE();
1217  double nwe = m_Regions[nwid].SumE();
1218  double noe = m_Regions[nid].SumE();
1219  double wee = m_Regions[wid].SumE();
1220  double swe = m_Regions[swid].SumE();
1221  double soe = m_Regions[sid].SumE();
1222 
1223  // if region is central: jet energy is sum of 3x3 region
1224  // surrounding the central region
1225  double jE = cene + nwe + noe + wee + swe + soe;
1226  double jEt = cenet + nwet + noet + weet + swet + soet;
1227 
1228 
1229  m_Regions.at(crgn).SetJetE(jE);
1230  m_Regions.at(crgn).SetJetEt(jEt);
1231 
1232  m_Regions.at(crgn).SetJetE3x3(cene);
1233  m_Regions.at(crgn).SetJetEt3x3(cenet);
1234 
1235  return true;
1236  } else { return false; }
1237 
1238  }
1239 
1240 
1241  // west border:
1242  if ((crgn%22)==0) {
1243 
1244  if (neid==999 || nid==999 || seid==999 || sid==999 || eid==999 ) {
1245  return false;
1246  }
1247 
1248  double cenet = m_Regions.at(crgn).SumEt();
1249  double neet = m_Regions[neid].SumEt();
1250  double noet = m_Regions[nid].SumEt();
1251  double eaet = m_Regions[eid].SumEt();
1252  double seet = m_Regions[seid].SumEt();
1253  double soet = m_Regions[sid].SumEt();
1254 
1255  if ( cenet > neet && cenet > noet &&
1256  cenet >= eaet && cenet >= soet &&
1257  cenet >= seet )
1258  {
1259 
1260  double cene = m_Regions.at(crgn).SumE();
1261  double nee = m_Regions[neid].SumE();
1262  double noe = m_Regions[nid].SumE();
1263  double eae = m_Regions[eid].SumE();
1264  double see = m_Regions[seid].SumE();
1265  double soe = m_Regions[sid].SumE();
1266 
1267  // if region is central: jet energy is sum of 3x3 region
1268  // surrounding the central region
1269  double jE = cene + nee + noe + eae + see + soe;
1270  double jEt = cenet + neet + noet + eaet + seet + soet;
1271 
1272  m_Regions.at(crgn).SetJetE(jE);
1273  m_Regions.at(crgn).SetJetEt(jEt);
1274 
1275  m_Regions.at(crgn).SetJetE3x3(cene);
1276  m_Regions.at(crgn).SetJetEt3x3(cenet);
1277 
1278  return true;
1279  } else { return false; }
1280 
1281  }
1282 
1283 
1284  if (nwid==999 || neid==999 || nid==999 || swid==999 || seid==999 || sid==999 || wid==999 ||
1285  eid==999 ) {
1286  //std::cerr << "FastL1GlobalAlgo::isMaxEtRgn_Window33(): RegionId out of bounds: " << std::endl
1287  // << nwid << " " << nid << " " << neid << " " << std::endl
1288  // << wid << " " << crgn << " " << eid << " " << std::endl
1289  // << swid << " " << sid << " " << seid << " " << std::endl;
1290  return false;
1291  }
1292 
1293 
1294  double cenet = m_Regions.at(crgn).SumEt();
1295  double nwet = m_Regions[nwid].SumEt();
1296  double noet = m_Regions[nid].SumEt();
1297  double neet = m_Regions[neid].SumEt();
1298  double weet = m_Regions[wid].SumEt();
1299  double eaet = m_Regions[eid].SumEt();
1300  double swet = m_Regions[swid].SumEt();
1301  double soet = m_Regions[sid].SumEt();
1302  double seet = m_Regions[seid].SumEt();
1303 
1304  if ( cenet > nwet && cenet > noet &&
1305  cenet > neet && cenet >= eaet &&
1306  cenet > weet && cenet >= soet &&
1307  cenet >= swet && cenet >= seet )
1308  {
1309 
1310  double cene = m_Regions.at(crgn).SumE();
1311  double nwe = m_Regions[nwid].SumE();
1312  double noe = m_Regions[nid].SumE();
1313  double nee = m_Regions[neid].SumE();
1314  double wee = m_Regions[wid].SumE();
1315  double eae = m_Regions[eid].SumE();
1316  double swe = m_Regions[swid].SumE();
1317  double soe = m_Regions[sid].SumE();
1318  double see = m_Regions[seid].SumE();
1319 
1320  // if region is central: jet energy is sum of 3x3 region
1321  // surrounding the central region
1322  double jE = cene + nwe + noe + nee + wee + eae + swe + soe + see;
1323  double jEt = cenet + nwet + noet + neet + weet + eaet + swet + soet + seet;
1324 
1325 
1326  m_Regions.at(crgn).SetJetE(jE);
1327  m_Regions.at(crgn).SetJetEt(jEt);
1328 
1329  m_Regions.at(crgn).SetJetE3x3(cene);
1330  m_Regions.at(crgn).SetJetEt3x3(cenet);
1331 
1332  return true;
1333  } else { return false; }
1334 
1335 }
1336 
1337 
1338 void
1340 
1341  // loop over towers ieta,iphi
1342  for (int j=1;j<=72;j++) {
1343  for (int i=-28; i<=28; i++) {
1344  if (i==0) continue;
1345  int iRgn = m_RMap->getRegionIndex(i,j);
1346  std::pair<double, double> RgnEtaPhi = m_RMap->getRegionCenterEtaPhi(iRgn);
1347  //int iTwr = m_RMap->getRegionTowerIndex(i,j);
1348  std::pair<int, int> iRgnEtaPhi = m_RMap->getRegionEtaPhiIndex(iRgn);
1349  std::pair<int, int> iRgnEtaPhi2 = m_RMap->getRegionEtaPhiIndex(std::pair<int, int>(i,j));
1350 
1351  std::cout<<"---------------------------------------------------------------------------"<<std::endl;
1352  std::cout<<"Region: "<<iRgn<<" | "<<RgnEtaPhi.first<<", "<<RgnEtaPhi.second*180./3.141<<std::endl;
1353  std::cout<<" - "<<iRgnEtaPhi.first<<", "<<iRgnEtaPhi.second<<std::endl;
1354  std::cout<<" - "<<iRgnEtaPhi2.first<<", "<<iRgnEtaPhi2.second<<std::endl;
1355  std::cout<<" Tower: "<<i<<", "<<m_RMap->convertFromECal_to_HCal_iphi(j)<<std::endl;
1356  std::cout<<" TowerId: "<<m_RMap->getRegionTowerIndex(i,j)<<std::endl;
1357 
1358  }
1359  }
1360 
1361 }
1362 
1363 double
1364 FastL1GlobalAlgo::hcaletValue(const int ieta,const int compET) {
1365  double etvalue = m_hcaluncomp[ieta][compET];//*cos(eta_ave);
1366  return etvalue;
1367 }
1368 
1369 // Et Check
1370 bool
1372 
1373  if ((cRgn%22)<4 || (cRgn%22)>17) return false;
1374 
1375  double iso_threshold = m_IsolationEt; // arbitrarily set
1376  int shower_shape = 0;
1377  int et_isolation = 0;
1378  unsigned int iso_count = 0;
1379 
1380  int nwid = m_Regions[cRgn].GetNWId();
1381  int nid = m_Regions[cRgn].GetNorthId();
1382  int neid = m_Regions[cRgn].GetNEId();
1383  int wid = m_Regions[cRgn].GetWestId();
1384  int eid = m_Regions[cRgn].GetEastId();
1385  int swid = m_Regions[cRgn].GetSWId();
1386  int sid = m_Regions[cRgn].GetSouthId();
1387  int seid = m_Regions[cRgn].GetSEId();
1388 
1389  if (m_Regions[cRgn].GetTauBit()) { // check center
1390  shower_shape = 1;
1391  //if (m_DoBitInfo) m_Regions[cRgn].BitInfo.setTauVeto(true);
1392  }
1393 
1394  if((cRgn%22)==4 || (cRgn%22)==17 ) {
1395  // west border
1396  if ((cRgn%22)==4) {
1397  if( m_Regions[neid].SumEt() > iso_threshold){
1398  iso_count ++;
1399  if (m_Regions[neid].GetTauBit()) iso_count++;
1400  }
1401  if( m_Regions[nid].SumEt() > iso_threshold){
1402  iso_count ++;
1403  if (m_Regions[nid].GetTauBit()) iso_count++;
1404  }
1405  if( m_Regions[eid].SumEt() > iso_threshold){
1406  iso_count ++;
1407  if (m_Regions[eid].GetTauBit()) iso_count++;
1408  }
1409  if( m_Regions[seid].SumEt() > iso_threshold){
1410  iso_count ++;
1411  if (m_Regions[seid].GetTauBit()) iso_count++;
1412  }
1413  if( m_Regions[sid].SumEt() > iso_threshold){
1414  iso_count ++;
1415  if (m_Regions[sid].GetTauBit()) iso_count++;
1416  }
1417  } // west bd
1418 
1419  // east border:
1420  if ((cRgn%22)==17) {
1421  if( m_Regions[nwid].SumEt() > iso_threshold){
1422  iso_count ++;
1423  if (m_Regions[nwid].GetTauBit()) iso_count++;
1424  }
1425  if( m_Regions[nid].SumEt() > iso_threshold){
1426  iso_count ++;
1427  if (m_Regions[nid].GetTauBit()) iso_count++;
1428  }
1429  if( m_Regions[wid].SumEt() > iso_threshold){
1430  iso_count ++;
1431  if (m_Regions[wid].GetTauBit()) iso_count++;
1432  }
1433  if( m_Regions[swid].SumEt() > iso_threshold){
1434  iso_count ++;
1435  if (m_Regions[swid].GetTauBit()) iso_count++;
1436  }
1437  if( m_Regions[sid].SumEt() > iso_threshold){
1438  iso_count ++;
1439  if (m_Regions[sid].GetTauBit()) iso_count++;
1440  }
1441  } // east bd
1442 
1443  }
1444 
1445  if ( (cRgn%22)>4 && (cRgn%22)<17){ // non-border
1446  if (nwid==999 || neid==999 || nid==999 || swid==999 || seid==999 || sid==999 || wid==999 ||
1447  eid==999 ) {
1448  return false;
1449  }
1450 
1451  if( m_Regions[neid].SumEt() > iso_threshold){
1452  iso_count ++;
1453  if (m_Regions[neid].GetTauBit()) iso_count++;
1454  }
1455  if( m_Regions[nid].SumEt() > iso_threshold){
1456  iso_count ++;
1457  if (m_Regions[nid].GetTauBit()) iso_count++;
1458  }
1459  if( m_Regions[eid].SumEt() > iso_threshold){
1460  iso_count ++;
1461  if (m_Regions[eid].GetTauBit()) iso_count++;
1462  }
1463  if( m_Regions[seid].SumEt() > iso_threshold){
1464  iso_count ++;
1465  if (m_Regions[seid].GetTauBit()) iso_count++;
1466  }
1467  if( m_Regions[sid].SumEt() > iso_threshold){
1468  iso_count ++;
1469  if (m_Regions[sid].GetTauBit()) iso_count++;
1470  }
1471  if( m_Regions[nwid].SumEt() > iso_threshold){
1472  iso_count ++;
1473  if (m_Regions[nwid].GetTauBit()) iso_count++;
1474  }
1475  if( m_Regions[wid].SumEt() > iso_threshold){
1476  iso_count ++;
1477  if (m_Regions[wid].GetTauBit()) iso_count++;
1478  }
1479  if( m_Regions[swid].SumEt() > iso_threshold){
1480  iso_count ++;
1481  if (m_Regions[swid].GetTauBit()) iso_count++;
1482  }
1483  }// non-border
1484 
1485 
1486  if (iso_count >= 2 ){
1487  et_isolation = 1;
1488  }
1489  else {
1490  et_isolation = 0;
1491  }
1492 
1493  if (m_DoBitInfo){
1494  if (et_isolation == 1)
1495  m_Regions[cRgn].BitInfo.setIsolationVeto (true);
1496  else
1497  m_Regions[cRgn].BitInfo.setIsolationVeto (false);
1498  }
1499 
1500  if (et_isolation == 1 || shower_shape == 1) return false;
1501  else return true;
1502 
1503 }//
1504 
T getParameter(std::string const &) const
double FGEBThreshold
Definition: FastL1Region.h:67
double FGEEThreshold
Definition: FastL1Region.h:68
int i
Definition: DBlmapReader.cc:9
double corrJetEt(double et, double eta)
double TowerEEScale
Definition: FastL1Region.h:86
l1extra::L1JetParticleCollection m_TauJets
std::pair< int, int > GetTowerNEEtaPhi(int ieta, int iphi)
std::pair< int, int > GetTowerNWEtaPhi(int ieta, int iphi)
std::pair< int, int > GetTowerSEEtaPhi(int ieta, int iphi)
double HadActiveLevel
Definition: FastL1Region.h:61
double noTauVetoLevel
Definition: FastL1Region.h:65
FastL1BitInfoCollection m_BitInfos
FastL1GlobalAlgo(const edm::ParameterSet &)
virtual double et() const =0
transverse energy
double QuietRegionThreshold
Definition: FastL1Region.h:70
double hOeThreshold
Definition: FastL1Region.h:66
std::vector< edm::InputTag > EmInputs
Definition: FastL1Region.h:90
static FastL1RegionMap * getFastL1RegionMap()
int getRegionIndex(int ieta, int iphi)
std::pair< double, double > getRegionCenterEtaPhi(int iRgn)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< CaloTower >::const_iterator const_iterator
Geom::Theta< T > theta() const
std::vector< FastL1Region > m_Regions
int isEMCand(CaloTowerDetId cid, l1extra::L1EmParticle *p, const edm::Event &e)
int getRegionTowerIndex(std::pair< int, int > iEtaPhi)
double EMActiveLevel
Definition: FastL1Region.h:60
std::pair< int, int > GetTowerSWEtaPhi(int ieta, int iphi)
double TowerEBScale
Definition: FastL1Region.h:85
double TowerHEThreshold
Definition: FastL1Region.h:83
edm::InputTag TowerInput
Definition: FastL1Region.h:91
void FillEgammas(edm::Event const &)
T eta() const
l1extra::L1JetParticleCollection m_CenJets
std::pair< int, int > GetTowerWestEtaPhi(int ieta, int iphi)
double HadNoiseLevel
Definition: FastL1Region.h:63
bool isTauJet(int rgnid)
void FillEgammasTP(edm::Event const &)
static std::string const input
Definition: EdmProvDump.cc:44
void CaloTowersDump(edm::Event const &e)
double TowerHEScale
Definition: FastL1Region.h:88
std::pair< int, int > GetTowerSouthEtaPhi(int ieta, int iphi)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
double TowerHBScale
Definition: FastL1Region.h:87
double TowerEMLSB
Definition: FastL1Region.h:75
int iEvent
Definition: GenABIO.cc:230
double TowerHBThreshold
Definition: FastL1Region.h:82
double CrystalEBThreshold
Definition: FastL1Region.h:72
T sqrt(T t)
Definition: SSEVec.h:48
double JetSeedEtThreshold
Definition: FastL1Region.h:57
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
bool isMaxEtRgn_Window33(int rgnid)
int iphi() const
get the tower iphi
std::pair< T, T > etaphi(T x, T y, T z)
Definition: FastMath.h:128
double noFGThreshold
Definition: FastL1Region.h:69
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double m_hcaluncomp[33][256]
int j
Definition: DBlmapReader.cc:9
edm::InputTag HcalTPInput
Definition: FastL1Region.h:94
int convertFromECal_to_HCal_iphi(int iphi_ecal)
bool TauIsolation(int rgnid)
double GCTEnergyTrunc(double et, double LSB=1., bool doEM=false)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
edm::InputTag EcalTPInput
Definition: FastL1Region.h:93
l1extra::L1EtMissParticleCollection m_METs
double TowerEEThreshold
Definition: FastL1Region.h:81
bool greaterEt(const reco::Candidate &a, const reco::Candidate &b)
void FillL1RegionsTP(edm::Event const &e, const edm::EventSetup &c)
const_iterator end() const
double EMNoiseLevel
Definition: FastL1Region.h:62
double corrEmEt(double et, int eta)
void FillL1Regions(edm::Event const &e, const edm::EventSetup &c)
bool DoJetCorr
Definition: FastL1Region.h:54
double hcaletValue(const int ieta, const int compET)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
l1extra::L1EmParticleCollection m_isoEgammas
double b
Definition: hdecay.h:120
std::pair< int, int > GetTowerNorthEtaPhi(int ieta, int iphi)
double TowerHadLSB
Definition: FastL1Region.h:76
l1extra::L1EmParticleCollection m_Egammas
void addJet(int rgnId, bool taubit)
double EMLSB
Definition: FastL1Region.h:77
double a
Definition: hdecay.h:121
double JetLSB
Definition: FastL1Region.h:78
double CrystalEEThreshold
Definition: FastL1Region.h:73
l1extra::L1JetParticleCollection m_ForJets
double MuonNoiseLevel
Definition: FastL1Region.h:71
tuple cout
Definition: gather_cfg.py:121
double RCTEnergyTrunc(double et, double Resol=1., double thres=1024.)
double EMSeedEnThreshold
Definition: FastL1Region.h:58
std::pair< int, int > GetTowerEastEtaPhi(int ieta, int iphi)
FastL1RegionMap * m_RMap
std::string fullPath() const
Definition: FileInPath.cc:165
int ieta() const
get the tower ieta
double TowerEBThreshold
Definition: FastL1Region.h:80
edm::FileInPath HcalLUT
Definition: FastL1Region.h:96
bool DoEMCorr
Definition: FastL1Region.h:55
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:27
std::pair< int, int > getRegionEtaPhiIndex(std::pair< int, int > iEtaPhi)
const_iterator begin() const
Definition: DDAxes.h:10