CMS 3D CMS Logo

Stage1Layer2EGammaAlgorithmImpHW.cc
Go to the documentation of this file.
1 
18 
19 #include <bitset>
20 
21 using namespace std;
22 using namespace l1t;
23 
24 
25 Stage1Layer2EGammaAlgorithmImpHW::Stage1Layer2EGammaAlgorithmImpHW(CaloParamsHelper const* params) : params_(params) {};
26 
27 
28 void l1t::Stage1Layer2EGammaAlgorithmImpHW::processEvent(const std::vector<l1t::CaloEmCand> & EMCands, const std::vector<l1t::CaloRegion> & regions, const std::vector<l1t::Jet> * jets, std::vector<l1t::EGamma>* egammas) {
29 
30 
31  std::vector<l1t::CaloRegion> subRegions;
32  std::vector<l1t::EGamma> preSortEGammas;
33  std::vector<l1t::EGamma> preGtEGammas;
34 
35 
36  //Region Correction will return uncorrected subregions if
37  //regionPUSType is set to None in the config
38  RegionCorrection(regions, &subRegions, params_);
39 
40  // ----- need to cluster jets in order to compute jet isolation ----
41  std::vector<l1t::Jet> *unCorrJets = new std::vector<l1t::Jet>();
42  TwelveByTwelveFinder(0, &subRegions, unCorrJets);
43 
44 
45  for(CaloEmCandBxCollection::const_iterator egCand = EMCands.begin();
46  egCand != EMCands.end(); egCand++) {
47 
48  int eg_et = egCand->hwPt();
49  int eg_eta = egCand->hwEta();
50  int eg_phi = egCand->hwPhi();
51  int index = (egCand->hwIso()*4 + egCand->hwQual()) ;
52 
53  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > egLorentz(0,0,0,0);
54 
55  int isoFlag = 0;
56  int ijet_pt=AssociatedJetPt(eg_eta,eg_phi,unCorrJets);
57  bool isinBarrel = (eg_eta>=7 && eg_eta<=14);
58  unsigned int lutAddress = isoLutIndex(eg_et,ijet_pt);
59 
60  // Combined Barrel/Endcap LUT uses upper bit to indicate Barrel / Endcap:
61  enum {MAX_LUT_ADDRESS = 0x7fff};
62  enum {LUT_BARREL_OFFSET = 0x0, LUT_ENDCAP_OFFSET = 0x8000};
63  enum {LUT_RCT_OFFSET = 0x10000};
64 
65  unsigned int rct_offset=0;
66  if (egCand->hwIso()) rct_offset=LUT_RCT_OFFSET;
67 
68  if (eg_et >0){
69  if (lutAddress > MAX_LUT_ADDRESS) lutAddress = MAX_LUT_ADDRESS;
70 
71  if (isinBarrel){
72  isoFlag= params_->egIsolationLUT()->data(LUT_BARREL_OFFSET + rct_offset + lutAddress);
73  } else{
74  isoFlag= params_->egIsolationLUT()->data(LUT_ENDCAP_OFFSET + rct_offset + lutAddress);
75  }
76  }
77 
78  l1t::EGamma theEG(*&egLorentz, eg_et, eg_eta, eg_phi, index, isoFlag);
79  preSortEGammas.push_back(theEG);
80  }
81 
82  SortEGammas(&preSortEGammas, &preGtEGammas);
83 
84  EGammaToGtScales(params_, &preGtEGammas, egammas);
85 
86 }
87 
88 //ieta =-28, nrTowers 0 is 0, increases to ieta28, nrTowers=kNrTowersInSum
89 unsigned l1t::Stage1Layer2EGammaAlgorithmImpHW::isoLutIndex(unsigned int egPt,unsigned int jetPt) const
90 {
91  const unsigned int nbitsEG=6; // number of bits used for EG bins in LUT file (needed for left shift operation)
92  // const unsigned int nbitsJet=9; // not used but here for info number of bits used for Jet bins in LUT file
93 
94  //jetPt &= 511; // Take only the LSB 9 bits to match firmware.
95  if(jetPt > 511) jetPt = 511;
96  unsigned int address= (jetPt << nbitsEG) + egPt;
97  return address;
98 }
99 
101  const std::vector<l1t::Jet> * jets) const {
102 
103  int pt = 0;
104 
105 
106  for(JetBxCollection::const_iterator itJet = jets->begin();
107  itJet != jets->end(); ++itJet){
108 
109  int jetEta = itJet->hwEta();
110  int jetPhi = itJet->hwPhi();
111  if ((jetEta == ieta) && (jetPhi == iphi)){
112  pt = itJet->hwPt();
113  break;
114  }
115  }
116 
117  // set output
118  return pt;
119 }
delete x;
Definition: CaloConfig.h:22
void TwelveByTwelveFinder(const int, const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
l1t::LUT const * egIsolationLUT() const
void RegionCorrection(const std::vector< l1t::CaloRegion > &regions, std::vector< l1t::CaloRegion > *subRegions, CaloParamsHelper const *params)
------— New region correction (PUsub, no response correction at the moment) --------— ...
unsigned isoLutIndex(unsigned int etaPt, unsigned int jetPt) const
vector< PseudoJet > jets
void SortEGammas(std::vector< l1t::EGamma > *input, std::vector< l1t::EGamma > *output)
int AssociatedJetPt(int ieta, int iphi, const std::vector< l1t::Jet > *jets) const
void processEvent(const std::vector< l1t::CaloEmCand > &EMCands, const std::vector< l1t::CaloRegion > &regions, const std::vector< l1t::Jet > *jets, std::vector< l1t::EGamma > *egammas) override
int data(unsigned int address) const
Definition: LUT.h:46
void EGammaToGtScales(CaloParamsHelper const *params, const std::vector< l1t::EGamma > *input, std::vector< l1t::EGamma > *output)
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:20