CMS 3D CMS Logo

Stage1Layer2EGammaAlgorithmImpPP.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 Stage1Layer2EGammaAlgorithmImpPP::Stage1Layer2EGammaAlgorithmImpPP(CaloParamsHelper const* params) : params_(params) {};
26 
27 
28 void l1t::Stage1Layer2EGammaAlgorithmImpPP::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  double egLsb=params_->egLsb();
32  double jetLsb=params_->jetLsb();
33  int egSeedThreshold= floor( params_->egSeedThreshold()/egLsb + 0.5);
34  int jetSeedThreshold= floor( params_->jetSeedThreshold()/jetLsb + 0.5);
35  int egMinPtJetIsolation = params_->egMinPtJetIsolation();
36  int egMaxPtJetIsolation = params_->egMaxPtJetIsolation();
37  int egMinPtHOverEIsolation = params_->egMinPtHOverEIsolation();
38  int egMaxPtHOverEIsolation = params_->egMaxPtHOverEIsolation();
39 
40  std::vector<l1t::CaloRegion> subRegions;
41  std::vector<l1t::EGamma> preSortEGammas;
42  std::vector<l1t::EGamma> preGtEGammas;
43 
44 
45  //Region Correction will return uncorrected subregions if
46  //regionPUSType is set to None in the config
47  RegionCorrection(regions, &subRegions, params_);
48 
49  // ----- need to cluster jets in order to compute jet isolation ----
50  std::vector<l1t::Jet> *unCorrJets = new std::vector<l1t::Jet>();
51  // slidingWindowJetFinder(jetSeedThreshold, subRegions, unCorrJets);
52  TwelveByTwelveFinder(jetSeedThreshold, &subRegions, unCorrJets);
53 
54 
55  for(CaloEmCandBxCollection::const_iterator egCand = EMCands.begin();
56  egCand != EMCands.end(); egCand++) {
57 
58  int eg_et = egCand->hwPt();
59  int eg_eta = egCand->hwEta();
60  int eg_phi = egCand->hwPhi();
61  int index = (egCand->hwIso()*4 + egCand->hwQual()) ;
62 
63  if(eg_et <= egSeedThreshold) continue;
64 
65  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > egLorentz(0,0,0,0);
66 
67  //int quality = 1;
68  int isoFlag = 0;
69  int isoFlagRct = 0;
70 
71  // 3x3 HoE, computed in 3x3
72  if(eg_et>=egMinPtHOverEIsolation && eg_et < egMaxPtHOverEIsolation ) {
73  if(egCand->hwIso()) isoFlagRct =1;
74  }
75  else {isoFlagRct =1;}
76 
77  int ijet_pt=AssociatedJetPt(eg_eta,eg_phi,unCorrJets);
78  // double jet_pt=ijet_pt*jetLsb;
79  bool isinBarrel = (eg_eta>=7 && eg_eta<=14);
80  if (ijet_pt>0 && eg_et>=egMinPtJetIsolation && eg_et<egMaxPtJetIsolation){
81 
82  // Combined Barrel/Endcap LUT uses upper bit to indicate Barrel / Endcap:
83  enum {MAX_LUT_ADDRESS = 0x7fff};
84  enum {LUT_BARREL_OFFSET = 0x0, LUT_ENDCAP_OFFSET = 0x8000};
85 
86  unsigned int lutAddress = isoLutIndex(eg_et,ijet_pt);
87 
88  if (eg_et >0){
89  if (lutAddress > MAX_LUT_ADDRESS) lutAddress = MAX_LUT_ADDRESS;
90  if (isinBarrel){
91  isoFlag= params_->egIsolationLUT()->data(LUT_BARREL_OFFSET + lutAddress);
92  } else{
93  isoFlag= params_->egIsolationLUT()->data(LUT_ENDCAP_OFFSET + lutAddress);
94  }
95  }
96 
97 
98  }else{ // no associated jet; assume it's an isolated eg
99  isoFlag=1;
100  }
101 
102  int fullIsoFlag=isoFlag*isoFlagRct;
103 
104  // ------- fill the EG candidate vector ---------
105  l1t::EGamma theEG(*&egLorentz, eg_et, eg_eta, eg_phi, index, fullIsoFlag);
106  //?? if( hoe < HoverECut) egammas->push_back(theEG);
107  preSortEGammas.push_back(theEG);
108  }
109 
110  SortEGammas(&preSortEGammas, &preGtEGammas);
111 
112  EGammaToGtScales(params_, &preGtEGammas, egammas);
113 
114 }
115 
116 
117 
118 
119 
122  const std::vector<l1t::CaloRegion> & regions) const {
123  double isolation = 0;
124 
125  for(CaloRegionBxCollection::const_iterator region = regions.begin();
126  region != regions.end(); region++) {
127 
128  int regionPhi = region->hwPhi();
129  int regionEta = region->hwEta();
131  int deltaPhi = iphi - regionPhi;
132  if (std::abs(deltaPhi) == L1CaloRegionDetId::N_PHI-1)
133  deltaPhi = -deltaPhi/std::abs(deltaPhi); //18 regions in phi
134 
135  unsigned int deltaEta = std::abs(ieta - regionEta);
136 
137  if ((deltaPhi + deltaEta) > 0 && deltaPhi < 2 && deltaEta < 2)
138  isolation += region->hwPt();
139  }
140 
141  // set output
142  return isolation;
143 }
144 
145 //ieta =-28, nrTowers 0 is 0, increases to ieta28, nrTowers=kNrTowersInSum
146 unsigned l1t::Stage1Layer2EGammaAlgorithmImpPP::isoLutIndex(unsigned int egPt,unsigned int jetPt) const
147 {
148  const unsigned int nbitsEG=6; // number of bits used for EG bins in LUT file (needed for left shift operation)
149  // const unsigned int nbitsJet=9; // not used but here for info number of bits used for Jet bins in LUT file
150 
151  unsigned int address= (jetPt << nbitsEG) + egPt;
152  return address;
153 }
154 
155 
156 
158  const std::vector<l1t::Jet> * jets) const {
159 
160  int pt = -1;
161 
162 
163  for(JetBxCollection::const_iterator itJet = jets->begin();
164  itJet != jets->end(); ++itJet){
165 
166  int jetEta = itJet->hwEta();
167  int jetPhi = itJet->hwPhi();
168  if ((jetEta == ieta) && (jetPhi == iphi)){
169  pt = itJet->hwPt();
170  break;
171  }
172  }
173 
174  // set output
175  return pt;
176 }
177 
178 
179 
181 double l1t::Stage1Layer2EGammaAlgorithmImpPP::HoverE(int et, int ieta, int iphi,
182  const std::vector<l1t::CaloRegion> & regions) const {
183  int hadronicET = 0;
184 
185  for(CaloRegionBxCollection::const_iterator region = regions.begin();
186  region != regions.end(); region++) {
187 
188  int regionET = region->hwPt();
189  int regionPhi = region->hwPhi();
190  int regionEta = region->hwEta();
191 
192  if(iphi == regionPhi && ieta == regionEta) {
193  hadronicET = regionET;
194  break;
195  }
196  }
197 
198  hadronicET -= et;
199 
200  double hoe = 0.0;
201 
202  if( hadronicET >0 && et > 0)
203  hoe = (double) hadronicET / (double) et;
204 
205  // set output
206  return hoe;
207 }
int egMinPtHOverEIsolation() const
double HoverE(int et, int ieta, int iphi, const std::vector< l1t::CaloRegion > &regions) const
--— Compute H/E -----------------—
int AssociatedJetPt(int ieta, int iphi, const std::vector< l1t::Jet > *jets) const
double Isolation(int ieta, int iphi, const std::vector< l1t::CaloRegion > &regions) const
–— Compute isolation sum --------------——
int egMinPtJetIsolation() const
delete x;
Definition: CaloConfig.h:22
void TwelveByTwelveFinder(const int, const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
int egMaxPtHOverEIsolation() const
static const double deltaEta
Definition: CaloConstants.h:8
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) --------— ...
double egSeedThreshold() const
double jetLsb() const
vector< PseudoJet > jets
void SortEGammas(std::vector< l1t::EGamma > *input, std::vector< l1t::EGamma > *output)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int egMaxPtJetIsolation() 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
et
define resolution functions of each parameter
unsigned isoLutIndex(unsigned int etaPt, unsigned int jetPt) const
int data(unsigned int address) const
Definition: LUT.h:46
static const unsigned N_PHI
double jetSeedThreshold() const
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