CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastL1Region.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FastL1CaloSim
4 // Class: FastL1Region
5 //
13 //
14 // Original Author: Chi Nhan Nguyen
15 // Created: Mon Feb 19 13:25:24 CST 2007
16 // $Id: FastL1Region.cc,v 1.7 2009/02/09 17:01:38 chinhan Exp $
17 //
18 
19 
21 
23 {
25 
26  jetE = 0.;
27  jetEt = 0.;
28 
29  id = 999;
30  ieta = 999;
31  iphi = 999;
32 
33  tauBit = false;
34  quietBit = false;
35  mipBit = false;
36  for(int i=0;i<16;i++) {
37  hcfgBit[i] = false;
38  fgBit[i] = false;
39  hOeBit[i] = false;
40  for (int j=0;j<25;j++) {
41  EMCrystalEnergy[i][j] = 0. ; // 16x25 Crystals
42  }
43  }
44 
45  // default values
47  Config.EMActiveLevel = 3.;
49  Config.noTauVetoLevel = 10000.;
50  Config.hOeThreshold = 0.05;
51  Config.FGEBThreshold = 0.8;
52  Config.noFGThreshold = 50.;
53  Config.FGEEThreshold = 0.8;
55  Config.EMNoiseLevel = 2.;
56  Config.HadNoiseLevel = 2.;
61 
62  Config.TowerEMLSB = 1.;
63  Config.TowerHadLSB = 1.;
64  Config.EMLSB = 1.;
65  Config.JetLSB = 1.;
66 
68  Config.TowerEEThreshold = 0.45;
71 
72  Config.TowerEBScale = 1.0;
73  Config.TowerEEScale = 1.0;
74  Config.TowerHBScale = 1.0;
75  Config.TowerHEScale = 1.0;
76 
77 
78  //Config.EmInputs;
79  //Config.xTowerInput;
80 
81 }
82 
83 
85 {
86 }
87 
88 
89 void
91 {
92  Config = iconfig;
93 }
94 
95 void
97 {
98  sumE = CalcSumE();
99  sumEt = CalcSumEt();
100 }
101 
102 void
104 {
105  SetTauBit(e);
106  SetQuietBit();
107  SetMIPBit();
108 }
109 
110 void
112 {
113  SetFGBit();
114  SetHOEBit();
115 }
116 
117 //
118 void
120  const CaloTopology* calotopo,
121  const CaloGeometry* cGeom,
122  const EcalRecHitCollection* ec0,
123  const EcalRecHitCollection* ec1,
124  FastL1RegionMap* m_RMap)
125 {
126  //std::vector< std::pair <std::string,std::string> > la;
127  //la.resize(2);
129  //la[0].first = "ecalRecHit";
130  //la[0].second = "EcalRecHitsEB";
132  //la[1].first = "ecalRecHit";
133  //la[1].second = "EcalRecHitsEE";
134 
135 
136 
137  // EB
138  //e.getByLabel(la[0].first,la[0].second,ec);
139  //e.getByLabel(Config.EmInputs.at(0),ec);
140 
141  double ethres = Config.CrystalEBThreshold;
142  for(EcalRecHitCollection::const_iterator ecItr = ec0->begin();
143  ecItr != ec0->end(); ++ecItr) {
144  //CaloRecHit recHit = (CaloRecHit)(*ecItr);
145  if (ecItr->energy()<ethres) continue;
146 
147  EBDetId detId = ecItr->detid();
148 
149  //int hiphi = detId.tower_iphi();
150  int hieta = detId.tower_ieta();
151  int eieta = detId.ieta();
152  int eiphi = detId.iphi();
153  int crIeta = 999;
154  if (hieta>0)
155  crIeta = (eieta-1)%5;
156  else
157  crIeta = 4 + (eieta+1)%5;
158  int crIphi = (eiphi - 1)%5;
159 
160  //const GlobalPoint gP = cGeom->getPosition(detId);
161 
162  //CaloTowerDetId towerDetId = theTowerConstituentsMap->towerOf(detId);
163  // loop over towers
164  for(int i=0;i<16;i++) {
165  //int hiphi = m_RMap->convertFromECal_to_HCal_iphi(detId.tower_iphi());
166  //int hiphi = m_RMap->convertFromHCal_to_ECal_iphi(detId.tower_iphi());
167  int hiphi = detId.tower_iphi();
168  if (!(Towers[i].id().iphi() == hiphi) || !(Towers[i].id().ieta() == hieta)) continue;
169  EMCrystalEnergy[i][crIeta + 5*crIphi] = ecItr->energy();
170  }
171  }
172 
173  // After having filled crsystal info set all veto bits
174  SetTowerBits();
175 
176  // EE FG bits are filled here!!!
177  //e.getByLabel(la[1].first,la[1].second,ec);
178 
179  if (GetiEta()==4 || GetiEta()==5 || GetiEta()==6 ||
180  GetiEta()==15 || GetiEta()==16 || GetiEta()==17 ) {
181 
182  //e.getByLabel(Config.EmInputs.at(1),ec);
183  ethres = Config.CrystalEEThreshold;
184  double towerEnergy[16];
185  // loop over towers
186  for(int i=0;i<16;i++) {
187  fgBit[i] = false; // re-iniate
188 
189  //if (Towers[i].hadEt()>Config.HadNoiseLevel && Towers[i].emEt()>Config.EMNoiseLevel ) {
190  if (Towers[i].emEt()>=Config.EMNoiseLevel ) {
191  //if (Towers[i].emEnergy()>Config.EMNoiseLevel ) {
192  //towerEnergy[i] = Towers[i].hadEt() + Towers[i].emEt();
193  towerEnergy[i] = Towers[i].hadEnergy() + Towers[i].emEnergy();
194  } else {
195  fgBit[i] = false;
196  continue;
197  }
198 
199  // EB/EE transition area: unset fg bits
200  // if (std::abs(Towers[i].id().ieta())==16 || std::abs(Towers[i].id().ieta())==17) {
201  // fgBit[i] = false;
202  // continue;
203  // }
204  if (Towers[i].emEt()>Config.noFGThreshold) {
205  fgBit[i] = false;
206  continue;
207  }
208 
209  //CaloRecHit maxRecHit;
210  //CaloRecHit maxRecHit2;
211  double maxRecHit=-1.;
212  double maxRecHit2=-1.;
213  DetId maxDetId;
214 
215  double max2En = 0.;
216 
217  for(EcalRecHitCollection::const_iterator ecItr = ec1->begin();
218  ecItr != ec1->end(); ++ecItr) {
219  //CaloRecHit recHit = (CaloRecHit)(*ecItr);
220  if (ecItr->energy()<ethres) continue;
221 
222  EEDetId detId = ecItr->detid();
223 
224  CaloTowerDetId towerDetId = theTowerConstituentsMap->towerOf(detId);
225  //int hiphi = m_RMap->convertFromECal_to_HCal_iphi(towerDetId.iphi());
226  int hiphi = towerDetId.iphi();
227  if (Towers[i].id().iphi()==hiphi &&
228  Towers[i].id().ieta()==towerDetId.ieta() ) {
229  if (maxRecHit<ecItr->energy()) {
230  maxRecHit = ecItr->energy();
231  maxDetId = detId;
232  }
233  }
234  }
235 
236  std::vector<DetId> westV = calotopo->west(maxDetId);
237  std::vector<DetId> eastV = calotopo->east(maxDetId);
238  std::vector<DetId> southV = calotopo->south(maxDetId);
239  std::vector<DetId> northV = calotopo->north(maxDetId);
240  for(EcalRecHitCollection::const_iterator ecItr = ec1->begin();
241  ecItr != ec1->end(); ++ecItr) {
242  //CaloRecHit recHit = (CaloRecHit)(*ecItr);
243  if (ecItr->energy()<ethres) continue;
244 
245  EEDetId detId = ecItr->detid();
246 
247  CaloTowerDetId towerDetId = theTowerConstituentsMap->towerOf(detId);
248  //int hiphi = m_RMap->convertFromECal_to_HCal_iphi(towerDetId.iphi());
249  int hiphi = towerDetId.iphi();
250  if (Towers[i].id().iphi()==hiphi &&
251  Towers[i].id().ieta()==towerDetId.ieta() ) {
252  if (
253  (!westV.empty() && detId==westV[0]) ||
254  (!eastV.empty() && detId==eastV[0]) ||
255  (!northV.empty() && detId==northV[0]) ||
256  (!southV.empty() && detId==southV[0])
257  ) {
258  if (maxRecHit2<ecItr->energy()) {
259  maxRecHit2 = ecItr->energy();
260  }
261  max2En += ecItr->energy();
262  }
263  }
264  }
265 
266  double eeThres = Config.FGEEThreshold;
267  //double totE = maxRecHit.energy() + max2En;
268  double totE = maxRecHit + maxRecHit2;
269  if (towerEnergy[i]>(Config.TowerEEThreshold)) {
270  //double totE = maxRecHit.energy() + maxRecHit2.energy();
271  //if (totE/towerEnergy[i]<Config.FGEBThreshold) fgBit[i] = true;
272  if (totE/towerEnergy[i]<eeThres) fgBit[i] = true;
273  }
274 
275  }
276  }
277 
278 
279 }
280 
281 //
282 void
284 {
285  Towers[tid] = CaloTower(t);
286  //std::cout<<"--- "<<Towers[tid].emEt()<<" "<<Towers[tid].hadEt()<<std::endl;
287 }
288 
289 void
291 {
292  double EThres = 0.;
293  double HThres = 0.;
294  double EBthres = Config.TowerEBThreshold;
295  double HBthres = Config.TowerHBThreshold;
296  double EEthres = Config.TowerEEThreshold;
297  double HEthres = Config.TowerHEThreshold;
298 
299  if(std::abs(t.eta())<2.322) {
300  EThres = EBthres;
301  } else {
302  EThres = EEthres;
303  }
304  if(std::abs(t.eta())<2.322) {
305  HThres = HBthres;
306  } else {
307  HThres = HEthres;
308  }
309 
310  double upperThres = 1024.;
311  double emet = RCTEnergyTrunc(t.emEt(),Config.TowerEMLSB,upperThres);
312  double hadet = RCTEnergyTrunc(t.hadEt(),Config.TowerHadLSB,upperThres);
313  //double eme = RCTEnergyTrunc(t.emEnergy(),Config.TowerEMLSB,upperThres);
314  //double hade = RCTEnergyTrunc(t.hadEnergy(),Config.TowerHadLSB,upperThres);
315 
316  if ( emet<EThres) emet = 0.;
317  if ( hadet<HThres) hadet = 0.;
318  //if ( eme<EThres) emet = 0.;
319  //if ( hade<HThres) hadet = 0.;
320 
321  GlobalPoint gP = cGeom->getPosition(t.id());
322  math::XYZTLorentzVector lvec(t.px(),t.py(),t.px(),t.energy());
323  //Towers[tid] = CaloTower(t);
324  //Towers[tid] = CaloTower(t.id(),t.momentum(),emet,hadet,t.outerEt(),0,0);
325  Towers[tid] = CaloTower(t.id(),emet,hadet,t.outerEt(),0,0,lvec,gP,gP);
326 }
327 
328 
329 //
330 void
331 FastL1Region::FillTower_Scaled(const CaloTower& t, int& tid, bool doRCTTrunc,edm::ESHandle<CaloGeometry> &cGeom)
332 {
333 
334  double EThres = 0.;
335  double HThres = 0.;
336  double EBthres = Config.TowerEBThreshold;
337  double HBthres = Config.TowerHBThreshold;
338  double EEthres = Config.TowerEEThreshold;
339  double HEthres = Config.TowerHEThreshold;
340 
341  if(std::abs(t.eta())<2.322) {
342  EThres = EBthres;
343  } else {
344  EThres = EEthres;
345  }
346  if(std::abs(t.eta())<2.322) {
347  HThres = HBthres;
348  } else {
349  HThres = HEthres;
350  }
351 
352  double emScale = 1.0;
353  double hadScale = 1.0;
354  //double outerScale = 1.0;
355 
356  if ((std::abs(t.eta()) > 1.3050) && (std::abs(t.eta()) < 3.0)) {
357  hadScale = Config.TowerHEScale;
358  emScale = Config.TowerEEScale;
359  }
360  if (std::abs(t.eta()) < 1.3050) {
361  hadScale = Config.TowerHBScale;
362  emScale = Config.TowerEBScale;
363  }
364 
365  double emet = emScale * t.emEt();
366  double hadet = hadScale * t.hadEt();
367 
368  if (doRCTTrunc) {
369  double upperThres = 1024.;
370  emet = RCTEnergyTrunc(emet,Config.TowerEMLSB,upperThres);
371  hadet = RCTEnergyTrunc(hadet,Config.TowerHadLSB,upperThres);
372  }
373  if ( emet<EThres) emet = 0.;
374  if ( hadet<HThres) hadet = 0.;
375  //if ( eme<EThres) emet = 0.;
376  //if ( hade<HThres) hadet = 0.;
377 
378  /*
379  if (t.emEt()>0. || t.hadEt()>0.) {
380  std::cout<<"+++ "
381  <<t.emEt()<<" "<<t.hadEt()<<" "
382  <<t.eta()<<" "<<t.phi()<<" "
383  <<std::endl;
384  }
385  */
386 
387  //Towers[tid] = CaloTower(t);
388  //Towers[tid] = CaloTower(t.id(),t.momentum(),emet,hadet,0.,0,0);
389  //edm::ESHandle<CaloGeometry> cGeom;
390  //c.get<CaloGeometryRecord>().get(cGeom);
391  GlobalPoint gP = cGeom->getPosition(t.id());
392  math::XYZTLorentzVector lvec(t.px(),t.py(),t.px(),t.energy());
393  //Towers[tid] = CaloTower(t);
394  //Towers[tid] = CaloTower(t.id(),t.momentum(),emet,hadet,t.outerEt(),0,0);
395  Towers[tid] = CaloTower(t.id(),emet,hadet,t.outerEt(),0,0,lvec,gP,gP);
396 
397  //std::cout<<tid<<" "<<Towers[tid].emEt()<< " " <<Towers[tid].hadEt()<< std::endl;
398 
399 }
400 
401 void
403 {
404  double fracThres = Config.hOeThreshold;
405 
406  for (int i=0; i<16; i++) {
407  //if (Towers[i].hadEt()>Config.HadNoiseLevel && Towers[i].emEt()>Config.EMNoiseLevel ) {
408  if (Towers[i].hadEnergy()>Config.HadNoiseLevel && Towers[i].emEnergy()>Config.EMNoiseLevel ) {
409  if((Towers[i].hadEt()/Towers[i].emEt()) > fracThres) {
410  hOeBit[i] = true;
411  }
412  }
413  }
414 }
415 
416 void
418 {
420  quietBit = true;
421 }
422 
423 void
425 {
426  if (quietBit) {
427  for (unsigned int i = 0U; i < 16; i++) {
428  if (hcfgBit[i]) {
429  mipBit = true;
430  return;
431  }
432  }
433  }
434 }
435 
436 void
437 FastL1Region::SetFGBit(int twrid,bool FGBIT)
438 {
439  fgBit[twrid] = FGBIT;
440 }
441 
442 void
443 FastL1Region::SetHOEBit(int twrid,bool FGBIT)
444 {
445  hOeBit[twrid] = FGBIT;
446 }
447 
448 void
450 {
451  double ratioCut = Config.FGEBThreshold;
452 
453  double stripEnergy[16][5];
454  double duostripEnergy[16][4];
455  double towerEnergy[16];
456 
457  if (GetiEta()>=7 && GetiEta()<=14) {
458  //Barrel
459  for (int i=0; i<16; i++) {
460  //if (Towers[i].hadEt()>Config.HadNoiseLevel && Towers[i].emEt()>Config.EMNoiseLevel ) {
461  if (Towers[i].emEt()>Config.EMNoiseLevel ) {
462  //towerEnergy[i] = Towers[i].hadEt() + Towers[i].emEt();
463  towerEnergy[i] = Towers[i].hadEnergy() + Towers[i].emEnergy();
464  } else {
465  fgBit[i] = false;
466  continue;
467  }
468 
469  // EB/EE transition area: unset fg bits
470  //if (std::abs(Towers[i].id().ieta())==16 || std::abs(Towers[i].id().ieta())==17) {
471  //fgBit[i] = false;
472  //continue;
473  //}
474  if (Towers[i].emEt()>Config.noFGThreshold) {
475  fgBit[i] = false;
476  continue;
477  }
478 
479  bool fgflag = false;
480  for (int j=0; j<5; j++) {
481  stripEnergy[i][j] = EMCrystalEnergy[i][j] + EMCrystalEnergy[i][j+5] + EMCrystalEnergy[i][j+10] +
482  EMCrystalEnergy[i][j+15] + EMCrystalEnergy[i][j+20];
483  }
484  for (int j=0; j<4; j++) {
485  duostripEnergy[i][j] = stripEnergy[i][j] + stripEnergy[i][j+1];
486  if (towerEnergy[i]>(Config.TowerEBThreshold)) {
487  //std::cout<<duostripEnergy[i][j]<<" |"<<towerEnergy[i]<<" |"<<duostripEnergy[i][j]/towerEnergy[i]<<std::endl;
488  if ( (duostripEnergy[i][j] / towerEnergy[i]) > ratioCut) {
489  fgflag = true;
490  }
491  //std::cout<<duostripEnergy[i][j]<<" | "<<towerEnergy[i]<<": "<<duostripEnergy[i][j]/towerEnergy[i]<<std::endl;
492  }
493  }
494 
495  if (fgflag) {
496  fgBit[i] = false;
497  } else {
498  fgBit[i] = true;
499  }
500  //std::cout<<GetiEta()<<" | "<<i<<": "<<fgBit[i]<<std::endl;
501  //std::cout<<"********************************************"<<std::endl;
502  }
503  } else {
504  // Endcap FG bit is already filled in fillEMCrystals()!!!
505  }
506 
507 }
508 
509 // Patterns with two or less contiguous bits set are passed
510  // rest are vetoed; 5=0101;7=0111;9=1001;10=1010;11=1011;13=1101;14=1110;15=1111
511  // --- Alternate patterns
512  // --- 9=1001;15=1111
513 static const std::vector<unsigned> vetoPatterns = { 5, 7, 9, 10,11,13,14,15};
514 
515 void
517 {
518  float emThres = Config.EMActiveLevel;
519  float hadThres = Config.HadActiveLevel;
520 
521  if (doBitInfo) BitInfo.setIsolationVeto(false);
522  if (doBitInfo) BitInfo.setTauVeto(false);
523  if (doBitInfo) BitInfo.setEmTauVeto(false);
524  if (doBitInfo) BitInfo.setHadTauVeto(false);
525 
526  // init pattern containers
527  unsigned emEtaPat = 0;
528  unsigned emPhiPat = 0;
529  unsigned hadEtaPat = 0;
530  unsigned hadPhiPat = 0;
531  unsigned one = 1;
532 
533 
534  // fill hits as bit pattern
535  for (int i=0; i<16; i++) {
536  if(Towers[i].emEt() > emThres) {
537  emEtaPat |= (one << (unsigned)(i%4));
538  emPhiPat |= (one << (unsigned)(i/4));
539  }
540 
541  if( Towers[i].hadEt() > hadThres) {
542  hadEtaPat |= (one << (unsigned)(i%4));
543  hadPhiPat |= (one << (unsigned)(i/4));
544  }
545 
546  }
547 
548  for(std::vector<unsigned>::const_iterator i = vetoPatterns.begin();
549  i != vetoPatterns.end(); i++) {
550  unsigned etaPattern = emEtaPat | hadEtaPat;
551  unsigned phiPattern = emPhiPat | hadPhiPat;
552 
553  // em pattern
554  if(emEtaPat == *i || emPhiPat == *i) {
555  if (doBitInfo) BitInfo.setEmTauVeto(true);
556  }
557  // had pattern
558  if(hadEtaPat == *i || hadPhiPat == *i) {
559  if (doBitInfo) BitInfo.setHadTauVeto(true);
560  }
561 
562  if(etaPattern == *i || phiPattern == *i) // combined pattern
563  //if(emEtaPat == *i || emPhiPat == *i || hadEtaPat == *i || hadPhiPat == *i)
564  {
565  tauBit = true;
566  if (doBitInfo) BitInfo.setTauVeto(true);
567  return;
568  }
569  }
570 
571  tauBit = false;
572 
573 }
574 
575 
576 int
578 {
579  int hid = -1;
580  double tmpet=0.;
581  for (int i=0; i<16; i++) {
582  if ( (Towers[i].emEt()+Towers[i].hadEt()) > tmpet) {
583  tmpet = (Towers[i].emEt()+Towers[i].hadEt());
584  hid = i;
585  }
586  }
587 
589 
590  return hid;
591 }
592 
593 int
595 {
596  int hid = -1;
597  double tmpet=0.;
598  for (int i=0; i<16; i++) {
599  if ( (Towers[i].emEt()) > tmpet) {
600  tmpet = (Towers[i].emEt());
601  hid = i;
602  }
603  }
604 
606  return hid;
607 }
608 
609 int
611 {
612  int hid = -1;
613  double tmpet=0.;
614  for (int i=0; i<16; i++) {
615  if ( (Towers[i].hadEt()) > tmpet) {
616  tmpet = (Towers[i].hadEt());
617  hid = i;
618  }
619  }
620 
622  return hid;
623 }
624 
625 double
627 {
628  double sumet=0;
629  for (int i=0; i<16; i++) {
630  sumet += Towers[i].emEt();
631  sumet += Towers[i].hadEt();
632  }
633 
634  return sumet;
635 }
636 
637 double
639 {
640  double sumet=0;
641  for (int i=0; i<16; i++) {
642  sumet += Towers[i].emEt();
643  }
644 
645  return sumet;
646 }
647 
648 double
650 {
651  double sumet=0;
652  for (int i=0; i<16; i++) {
653  sumet += Towers[i].hadEt();
654  }
655 
656  return sumet;
657 }
658 
659 double
661 {
662  double sume=0;
663  for (int i=0; i<16; i++) {
664  sume += Towers[i].emEnergy();
665  sume += Towers[i].hadEnergy();
666 
667  }
668  return sume;
669 }
670 
671 double
673 {
674  double sume=0;
675  for (int i=0; i<16; i++) {
676  sume += Towers[i].emEnergy();
677  }
678  return sume;
679 }
680 
681 double
683 {
684  double sume=0;
685  for (int i=0; i<16; i++) {
686  sume += Towers[i].hadEnergy();
687  }
688  return sume;
689 }
690 
691 
692 std::pair<double, double>
694 {
696  //c.get<IdealGeometryRecord>().get(cGeom);
697  c.get<CaloGeometryRecord>().get(cGeom);
698 
699  const GlobalPoint gP1 = cGeom->getPosition(Towers[5].id());
700  //const GlobalPoint gP2 = cGeom->getPosition(Towers[6].id());
701  //const GlobalPoint gP3 = cGeom->getPosition(Towers[10].id());
702 
703  double eta = gP1.eta();
704  double phi = gP1.phi();
705 
706  return std::pair<double, double>(eta, phi);
707 }
708 
709 
710 // test filling of FastL1Region
711 void
713 {
714 
715  // test tower filling:
716  /*
717  CaloTowerCollection::const_iterator t;
718  int count = 0;
719  for (t=Towers.begin(); t!=Towers.end(); t++) {
720  std::cout << count << ") " << t->energy() << " | " << t->eta() << " | " << t->phi() << std::endl;
721  count++;
722  }
723  std::cout << std::endl;
724  */
725 
726  // test region neighbours:
727  std::cout << this->GetNWId() << " " << this->GetNorthId() << " " << this->GetNEId() << std::endl;
728  std::cout << this->GetWestId() << " " << this->GetId() << " " << this->GetEastId() << std::endl;
729  std::cout << this->GetSWId() << " " << this->GetSouthId() << " " << this->GetSEId() << std::endl;
730  std::cout << std::endl;
731 
732 }
733 
734 int
736 { if (iphi != 17) return ((iphi+1)*22 + ieta); else return ieta; }
737 
738 
739 int
741 { if (iphi != 0) return ((iphi-1)*22 + ieta); else return (17*22 + ieta); }
742 
743 int
745 { if (ieta != 0) return (iphi*22 + ieta-1); else return 999; }
746 
747 int
749 { if (ieta != 21) return (iphi*22 + ieta+1); else return 999; }
750 
751 int
753 {
754  if (ieta != 0) {
755  if (iphi != 17)
756  return ((iphi+1)*22 + ieta-1);
757  else
758  return (ieta-1);
759  } else {
760  return 999;
761  }
762 }
763 
764 int
766 {
767  if (ieta != 0) {
768  if (iphi != 0)
769  return ((iphi-1)*22 + ieta-1);
770  else
771  return (17*22 + ieta-1);
772  } else {
773  return 999;
774  }
775 }
776 
778 {
779  if (ieta != 21) {
780  if (iphi != 17)
781  return ((iphi+1)*22 + ieta+1);
782  else
783  return (ieta+1);
784  } else {
785  return 999;
786  }
787 }
788 
789 int
791 {
792  if (ieta != 21) {
793  if (iphi != 0)
794  return ((iphi-1)*22 + ieta+1);
795  else
796  return (17*22 + ieta+1);
797  } else {
798  return 999;
799  }
800 }
801 
802 double
803 corrJetEt(double et, double eta)
804 {
805  return corrJetEt1(et,eta);
806  //return corrJetEt2(et,eta);
807 }
808 
809 
810 // Jet Calibration from CMSSW_1_3_0
811 double
812 corrJetEt2(double et, double eta)
813 {
814  const int NUMBER_ETA_VALUES = 11;
815  std::vector< std::vector<float> > m_calibFunc;
816 
817  m_calibFunc.resize(NUMBER_ETA_VALUES);
818 
819  // still fill manually
820  m_calibFunc.at(0).push_back(1);
821  m_calibFunc.at(0).push_back(1);
822  m_calibFunc.at(0).push_back(2);
823 
824  m_calibFunc.at(1).push_back(1);
825  m_calibFunc.at(1).push_back(2);
826  m_calibFunc.at(1).push_back(2);
827 
828  m_calibFunc.at(2).push_back(2);
829  m_calibFunc.at(2).push_back(2);
830  m_calibFunc.at(2).push_back(2);
831  m_calibFunc.at(2).push_back(2);
832  m_calibFunc.at(2).push_back(3);
833  m_calibFunc.at(2).push_back(3);
834 
835  m_calibFunc.at(3).push_back(1);
836  m_calibFunc.at(3).push_back(1);
837  m_calibFunc.at(3).push_back(3);
838 
839  m_calibFunc.at(4).push_back(1);
840  m_calibFunc.at(4).push_back(3);
841  m_calibFunc.at(4).push_back(3);
842  m_calibFunc.at(4).push_back(6);
843  m_calibFunc.at(4).push_back(6);
844  m_calibFunc.at(4).push_back(6);
845  m_calibFunc.at(4).push_back(6);
846  m_calibFunc.at(4).push_back(6);
847 
848  m_calibFunc.at(5).push_back(3);
849  m_calibFunc.at(5).push_back(3);
850  m_calibFunc.at(5).push_back(3);
851 
852  m_calibFunc.at(6).push_back(1);
853  m_calibFunc.at(6).push_back(1);
854  m_calibFunc.at(6).push_back(4);
855 
856  m_calibFunc.at(7).push_back(1);
857  m_calibFunc.at(7).push_back(4);
858  m_calibFunc.at(7).push_back(4);
859 
860  m_calibFunc.at(8).push_back(4);
861  m_calibFunc.at(8).push_back(4);
862  m_calibFunc.at(8).push_back(4);
863  m_calibFunc.at(8).push_back(1);
864  m_calibFunc.at(8).push_back(1);
865  m_calibFunc.at(8).push_back(1);
866 
867  m_calibFunc.at(9).push_back(1);
868  m_calibFunc.at(9).push_back(1);
869  m_calibFunc.at(9).push_back(5);
870 
871  m_calibFunc.at(10).push_back(1);
872  m_calibFunc.at(10).push_back(5);
873  m_calibFunc.at(10).push_back(5);
874 
875 
876  double etabin[12] = { 0.0, 0.348, 0.696, 1.044, 1.392, 1.74, 2.172, 3.0,
877  3.33, 3.839, 4.439, 5.115};
878  int BinID = 0;
879  for(int i = 0; i < 11; i++){
880  if(std::abs(eta) >= etabin[i] && eta < etabin[i+1])
881  BinID = i;
882  }
883 
884  double corrEt = 0;
885  for (unsigned i=0; i<m_calibFunc.at(BinID).size();i++){
886  corrEt += m_calibFunc.at(BinID).at(i)*pow(et,(int)i);
887  }
888 
889  uint16_t jetEtOut = (uint16_t)corrEt;
890 
891  if(jetEtOut < 1024) {
892  return (double)jetEtOut;
893  }
894  return (double)1023;
895 
896 }
897 
898 // Jet Calibration from Frederick(Helsinki), Monika/Creighton (Wisconsin)
899 double
900 corrJetEt1(double et, double eta)
901 {
902  double etabin[23] = {-5.115, -4.439, -3.839, -3.33,
903  -3.0, -2.172, -1.74, -1.392, -1.044, -0.696, -0.348,
904  0.0, 0.348, 0.696, 1.044, 1.392, 1.74, 2.172, 3.0,
905  3.33, 3.839, 4.439, 5.115};
906 
907  int BinID = 0;
908 
909  double domainbin_L[22] = {6.52223337753073373e+00,6.64347505748981959e+00,6.78054870174118296e+00,6.75191887554567405e+00,
910  6.60891660595437802e+00,6.57813476381055473e+00,6.96764764481347232e+00,6.77192746888150943e+00,
911  7.16209661824076260e+00,7.09640803784948027e+00,7.29886808171882517e+00,7.29883431473330546e+00,
912  7.24561741344293875e+00,7.05381822724987995e+00,6.52340799679028827e+00,6.96091042775473401e+00,
913  6.69803071767842262e+00,7.79138848427964259e+00,6.78565437835616603e+00,6.71201461174192904e+00,
914  6.60832257380386334e+00,6.54875448717649267e+00};
915 
916  double domainbin_U[22] = {8.90225568813317558e+00,1.24483653543590922e+01,1.32037091554958987e+01,1.70036104608977681e+01,
917  3.54325008263432011e+01,4.28758696753095450e+01,4.73079850563588025e+01,4.74182802251108981e+01,
918  4.62509826468679748e+01,5.02198002212212913e+01,4.69817029938948352e+01,4.77263481299233732e+01,
919  4.86083837976362076e+01,4.80105593452927337e+01,5.11550616006504200e+01,4.90703092811585861e+01,
920  4.11879629179572788e+01,3.21820720507165845e+01,1.71844078553560529e+01,1.33158534849654764e+01,
921  1.43586396719878149e+01,1.08629843894704248e+01};
922 
923  double A[22] = {2.03682,-4.36824,-4.45258,-6.76524,-22.5984,-24.5289,-24.0313,-22.1896,-21.7818,-22.9882,-20.3321,
924  -21.0595,-22.1007,-22.658,-23.6898,-24.8888,-23.3246,-21.5343,-6.41221,-4.58952,-3.17222,0.637666};
925 
926  double B[22] = {0.226303,0.683099,0.704578,0.704623,0.825928,0.80086,0.766475,0.726059,0.760964,0.792227,0.789188,0.795219,
927  0.781097,0.768022,0.740101,0.774782,0.788106,0.814502,0.686877,0.709556,0.628581,0.317453};
928 
929  double C[22] = {0.00409083,0.000235995,8.22958e-05,2.47567e-05,0.000127995,0.000132914,0.000133342,0.000133035,0.000125993,
930  8.25968e-05,9.94442e-05,9.11652e-05,0.000109351,0.000115883,0.00011112,0.000122559,0.00015868,0.000152601,
931  0.000112927,6.29999e-05,0.000741798,0.00274605};
932 
933  double D[22] = {8.24022,7.55916,7.16448,6.31577,5.96339,5.31203,5.35456,4.95243,5.34809,4.93339,5.05723,5.08575,5.18643,5.15202,
934  4.48249,5.2734,5.51785,8.00182,6.21742,6.96692,7.22975,8.12257};
935 
936  double E[22] = {-0.343598,-0.294067,-0.22529,-0.0718625,0.004164,0.081987,0.124964,0.15006,0.145201,0.182151,0.187525,0.184763,
937  0.170689,0.155268,0.174603,0.133432,0.0719798,-0.0921457,-0.0525274,-0.208415,-0.253542,-0.318476};
938 
939  double F[22] = {0.0171799,0.0202499,0.0186897,0.0115477,0.00603883,0.00446235,0.00363449,0.00318894,0.00361997,0.00341508,
940  0.00366392,0.0036545,0.00352303,0.00349116,0.00294891,0.00353187,0.00460384,0.00711028,0.0109351,0.0182924,
941  0.01914,0.0161094};
942 
943  for(int i = 0; i < 22; i++){
944  if(eta > etabin[i] && eta <= etabin[i+1])
945  BinID = i;
946  }
947 
948  if(et >= domainbin_U[BinID]){
949  return 2*(et-A[BinID])/(B[BinID]+sqrt(B[BinID]*B[BinID]-4*A[BinID]*C[BinID]+4*et*C[BinID]));
950  }
951  else if(et > domainbin_L[BinID]){
952  return 2*(et-D[BinID])/(E[BinID]+sqrt(E[BinID]*E[BinID]-4*D[BinID]*F[BinID]+4*et*F[BinID]));
953  }
954  else return et;
955 }
956 
957 
958 // EM correction from ORCA for cmsim 133
959 double
960 //corrEmEt(double et, double eta) {
961 corrEmEt(double et, int eta) {
962 
963 
964  const int nscales = 32;
965  /*
966  const int nscales = 27;
967  double etalimit[nscales] = { 0.0,0.087,0.174,0.261,0.348,0.435,0.522,0.609,0.696,0.783,0.870,0.957,
968  1.044,1.131,1.218,1.305,1.392,1.479,1.566,1.653,1.740,1.830,1.930,
969  2.043,2.172,2.322,2.500};
970  */
971 
972  double scfactor[nscales] = {
973  1.00,1.01,1.02,1.02,1.02,1.06,1.04,1.04,1.05,1.09,1.10,1.10,1.15,
974  1.20,1.27,1.29,1.32,1.52,1.52,1.48,1.40,1.32,1.26,1.21,1.17,1.15,
975  1.15,1.15,1.15,1.15,1.15,1.15};
976 
977  /*
978  double scale=1.;
979  for (int i=0;i<nscales;i++) {
980  if (std::abs(eta)<etalimit[i]) {
981  scale = scfactor[i];
982  }
983  }
984  return (scale*et);
985  */
986 
987  if (eta>=0 && eta <=28)
988  return (scfactor[eta]*et);
989  else
990  return et;
991 }
992 
993 
994 // Rounding the Et info for simulating the regional Et resolution
995 double
996 RCTEnergyTrunc(double et, double LSB, double thres) {
997 
998  //return et;
999  if (et>=thres) return thres;
1000 
1001  //et += LSB/2.;
1002  //double ret = (int)(et / LSB) * LSB + LSB;
1003  int iEt = (int)(et / LSB);
1004  double ret = (double)iEt * LSB;
1005 
1006  return ret;
1007 }
1008 
1009 
1010 double
1011 GCTEnergyTrunc(double et, double LSB, bool doEM) {
1012 
1013  //return et;
1014 
1015  //double L1CaloEmEtScaleLSB = LSB;
1016  //double L1CaloRegionEtScaleLSB = LSB;
1017 
1018  //if (et>0.) et += LSB/2.; // round up
1019 
1020  double L1CaloEmThresholds[64] = {
1021  0., 1., 2., 3., 4., 5., 6., 7., 8., 9.,
1022  10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
1023  20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
1024  30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
1025  40., 41., 42., 43., 44., 45., 46., 47., 48., 49.,
1026  50., 51., 52., 53., 54., 55., 56., 57., 58., 59.,
1027  60., 61., 62., 63.
1028  };
1029 
1030  double L1CaloJetThresholds[64] = {
1031  0., 10., 12., 14., 15., 18., 20., 22., 24., 25.,
1032  28., 30., 32., 35., 37., 40., 45., 50., 55., 60.,
1033  65., 70., 75., 80., 85., 90., 100., 110., 120., 125.,
1034  130., 140., 150., 160., 170., 175., 180., 190., 200., 215.,
1035  225., 235., 250., 275., 300., 325., 350., 375., 400., 425.,
1036  450., 475., 500., 525., 550., 575., 600., 625., 650., 675.,
1037  700., 725., 750., 775.
1038  };
1039 
1040 
1041 
1042  double L1CaloThresholds[64];
1043  if (doEM) {
1044  for (int i=0;i<64;i++)
1045  L1CaloThresholds[i] = L1CaloEmThresholds[i];
1046  } else {
1047  for (int i=0;i<64;i++)
1048  L1CaloThresholds[i] = L1CaloJetThresholds[i];
1049  }
1050 
1051 
1052  double ret = 0.;
1053  for (int i=63;i>0;i--) {
1054  if (et>=(L1CaloThresholds[i])) {
1055  if (i==63) {
1056  ret = L1CaloThresholds[63];
1057  } else {
1058  /*
1059  double minL = std::abs(et - L1CaloThresholds[i]);
1060  double minU = std::abs(et - L1CaloThresholds[i+1]);
1061  if (minL<minU)
1062  ret = L1CaloThresholds[i];
1063  else
1064  ret = L1CaloThresholds[i+1];
1065  */
1066  /*
1067  if (doEM) {
1068  ret = L1CaloThresholds[i];
1069  } else {
1070  ret = L1CaloThresholds[i+1];
1071  }
1072  */
1073  ret = L1CaloThresholds[i];
1074  }
1075  break;
1076  }
1077  }
1078  return ret;
1079 }
1080 
1081 
1082 
double FGEBThreshold
Definition: FastL1Region.h:67
double FGEEThreshold
Definition: FastL1Region.h:68
int i
Definition: DBlmapReader.cc:9
double corrJetEt(double et, double eta)
void SetRegionBits(edm::Event const &e)
double TowerEEScale
Definition: FastL1Region.h:86
std::pair< double, double > getRegionCenterEtaPhi(const edm::EventSetup &c)
void setTauVeto(bool tauVeto)
Definition: FastL1BitInfo.h:24
double HadActiveLevel
Definition: FastL1Region.h:61
double SumEt()
Definition: FastL1Region.h:161
double corrJetEt2(double et, double eta)
double noTauVetoLevel
Definition: FastL1Region.h:65
double QuietRegionThreshold
Definition: FastL1Region.h:70
double hOeThreshold
Definition: FastL1Region.h:66
double hadEt() const
Definition: CaloTower.h:100
int tower_ieta() const
get the HCAL/trigger ieta of this crystal
Definition: EBDetId.h:55
int tower_iphi() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.cc:114
double CalcSumHadE()
double outerEt() const
Definition: CaloTower.h:101
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
void SetTowerBits()
std::vector< EcalRecHit >::const_iterator const_iterator
void setHighestEtTowerID(int id)
Definition: FastL1BitInfo.h:35
double CalcSumEmE()
double EMActiveLevel
Definition: FastL1Region.h:60
bool hOeBit[16]
Definition: FastL1Region.h:234
double TowerEBScale
Definition: FastL1Region.h:85
double TowerHEThreshold
Definition: FastL1Region.h:83
T eta() const
bool fgBit[16]
Definition: FastL1Region.h:233
double HadNoiseLevel
Definition: FastL1Region.h:63
int HighestEmEtTowerID()
void FillEMCrystals(const CaloTowerConstituentsMap *theTowerConstituentsMap, const CaloTopology *calotopo, const CaloGeometry *cGeom, const EcalRecHitCollection *ec0, const EcalRecHitCollection *ec1, FastL1RegionMap *m_RMap)
void SetQuietBit()
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
double TowerHEScale
Definition: FastL1Region.h:88
double CalcSumHadEt()
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
virtual double energy() const
energy
int iEvent
Definition: GenABIO.cc:230
void setHadTauVeto(bool hadTauVeto)
Definition: FastL1BitInfo.h:26
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
double TowerHBThreshold
Definition: FastL1Region.h:82
double CalcSumEt()
double CrystalEBThreshold
Definition: FastL1Region.h:72
virtual float eta() const
momentum pseudorapidity
T sqrt(T t)
Definition: SSEVec.h:48
double JetSeedEtThreshold
Definition: FastL1Region.h:57
double CalcSumEmEt()
int iphi() const
get the tower iphi
double noFGThreshold
Definition: FastL1Region.h:69
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
std::vector< DetId > east(const DetId &id) const
Get the neighbors of the given cell in east direction.
Definition: CaloTopology.cc:38
double GCTEnergyTrunc(double et, double LSB=1., bool doEM=false)
void SetHOEBit()
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
void FillTowerZero(const CaloTower &t, int &tid)
std::vector< DetId > north(const DetId &id) const
Get the neighbors of the given cell in north direction.
Definition: CaloTopology.cc:48
double TowerEEThreshold
Definition: FastL1Region.h:81
const_iterator end() const
double EMNoiseLevel
Definition: FastL1Region.h:62
double corrEmEt(double et, int eta)
Definition: DetId.h:18
CaloTowerDetId id() const
Definition: CaloTower.h:87
void setIsolationVeto(bool isolationVeto)
Definition: FastL1BitInfo.h:27
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
CaloTowerCollection Towers
Definition: FastL1Region.h:214
std::vector< DetId > west(const DetId &id) const
Get the neighbors of the given cell in west direction.
Definition: CaloTopology.cc:43
virtual double px() const
x coordinate of momentum vector
int HighestEtTowerID()
void setEmTauVeto(bool emTauVeto)
Definition: FastL1BitInfo.h:25
const T & get() const
Definition: EventSetup.h:55
double EMCrystalEnergy[16][25]
Definition: FastL1Region.h:216
void setHighestHadEtTowerID(int id)
Definition: FastL1BitInfo.h:37
double TowerHadLSB
Definition: FastL1Region.h:76
T eta() const
Definition: PV3DBase.h:76
double corrJetEt1(double et, double eta)
double EMLSB
Definition: FastL1Region.h:77
edm::SortedCollection< CaloTower > CaloTowerCollection
Definition: CaloTowerFwd.h:15
double JetLSB
Definition: FastL1Region.h:78
double CrystalEEThreshold
Definition: FastL1Region.h:73
void SetRegionEnergy()
Definition: FastL1Region.cc:96
double MuonNoiseLevel
Definition: FastL1Region.h:71
tuple cout
Definition: gather_cfg.py:121
void SetTauBit(edm::Event const &e)
double RCTEnergyTrunc(double et, double Resol=1., double thres=1024.)
FastL1BitInfo BitInfo
Definition: FastL1Region.h:196
L1Config Config
Definition: FastL1Region.h:240
void FillTower(const CaloTower &t, int &tid, edm::ESHandle< CaloGeometry > &cGeom)
double EMSeedEnThreshold
Definition: FastL1Region.h:58
int ieta() const
get the tower ieta
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
void SetMIPBit()
bool hcfgBit[16]
Definition: FastL1Region.h:235
void FillTower_Scaled(const CaloTower &t, int &tid, bool doRCTTrunc, edm::ESHandle< CaloGeometry > &cGeom)
double TowerEBThreshold
Definition: FastL1Region.h:80
int HighestHadEtTowerID()
static const std::vector< unsigned > vetoPatterns
double emEt() const
Definition: CaloTower.h:99
virtual double py() const
y coordinate of momentum vector
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void SetParameters(const L1Config &)
Definition: FastL1Region.cc:90
std::vector< DetId > south(const DetId &id) const
Get the neighbors of the given cell in south direction.
Definition: CaloTopology.cc:53
void setHighestEmEtTowerID(int id)
Definition: FastL1BitInfo.h:36
const_iterator begin() const
double CalcSumE()
Definition: DDAxes.h:10