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