CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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* params) : params_(params) {};
26 
28 
29 
30 
31 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) {
32 
33 
34  std::vector<l1t::CaloRegion> *subRegions = new std::vector<l1t::CaloRegion>();
35  std::vector<l1t::EGamma> *preSortEGammas = new std::vector<l1t::EGamma>();
36  std::vector<l1t::EGamma> *preGtEGammas = new std::vector<l1t::EGamma>();
37 
38 
39  //Region Correction will return uncorrected subregions if
40  //regionPUSType is set to None in the config
41  RegionCorrection(regions, subRegions, params_);
42 
43  // ----- need to cluster jets in order to compute jet isolation ----
44  std::vector<l1t::Jet> *unCorrJets = new std::vector<l1t::Jet>();
45  TwelveByTwelveFinder(0, subRegions, unCorrJets);
46 
47 
48  //std::cout << "Begin egamma cand debug dump:" << std::endl;
49  //std::cout << "pt eta phi index assocJetPt lutAddress lutResult" << std::endl;
50  for(CaloEmCandBxCollection::const_iterator egCand = EMCands.begin();
51  egCand != EMCands.end(); egCand++) {
52 
53  int eg_et = egCand->hwPt();
54  int eg_eta = egCand->hwEta();
55  int eg_phi = egCand->hwPhi();
56  int index = (egCand->hwIso()*4 + egCand->hwQual()) ;
57 
58  //std::cout << "JetRankMax: " << params_->jetScale().rankScaleMax()<< " EmRankMax: " << params_->emScale().rankScaleMax()<< std::endl;
59  //std::cout << "JetLinMax: " << params_->jetScale().linScaleMax()<< " EmLinMax: " << params_->emScale().linScaleMax()<< std::endl;
60 
61  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > egLorentz(0,0,0,0);
62 
63  int isoFlag = 0;
64  int ijet_pt=AssociatedJetPt(eg_eta,eg_phi,unCorrJets);
65  bool isinBarrel = (eg_eta>=7 && eg_eta<=14);
66  unsigned int lutAddress = isoLutIndex(eg_et,ijet_pt);
67 
68  // Combined Barrel/Endcap LUT uses upper bit to indicate Barrel / Endcap:
69  enum {MAX_LUT_ADDRESS = 0x7fff};
70  enum {LUT_BARREL_OFFSET = 0x0, LUT_ENDCAP_OFFSET = 0x8000};
71  enum {LUT_RCT_OFFSET = 0x10000};
72 
73  unsigned int rct_offset=0;
74  if (egCand->hwIso()) rct_offset=LUT_RCT_OFFSET;
75 
76  if (eg_et >0){
77  if (lutAddress > MAX_LUT_ADDRESS) lutAddress = MAX_LUT_ADDRESS;
78 
79  if (isinBarrel){
80  isoFlag= params_->egIsolationLUT()->data(LUT_BARREL_OFFSET + rct_offset + lutAddress);
81  } else{
82  isoFlag= params_->egIsolationLUT()->data(LUT_ENDCAP_OFFSET + rct_offset + lutAddress);
83  }
84  }
85 
86  // std::cout << eg_et << " " << eg_eta << " " << eg_phi << " " << index << " "
87  // << ijet_pt << " " << lutAddress << " " << isoFlag << std::endl;
88  l1t::EGamma theEG(*&egLorentz, eg_et, eg_eta, eg_phi, index, isoFlag);
89  preSortEGammas->push_back(theEG);
90  }
91 
92  // printf("Pre-Sort\n");
93  // for(std::vector<l1t::EGamma>::const_iterator itEGamma = preSortEGammas->begin();
94  // itEGamma != preSortEGammas->end(); ++itEGamma){
95  // std::cout << itEGamma->hwPt() << " " << itEGamma->hwEta() << " " << itEGamma->hwPhi() << std::endl;
96  // }
97 
98  SortEGammas(preSortEGammas, preGtEGammas);
99 
100  EGammaToGtScales(params_, preGtEGammas, egammas);
101 
102  // printf("Post-Sort\n");
103  // for(std::vector<l1t::EGamma>::const_iterator itEGamma = egammas->begin();
104  // itEGamma != egammas->end(); ++itEGamma){
105  // std::cout << itEGamma->hwPt() << " " << itEGamma->hwEta() << " " << itEGamma->hwPhi() << std::endl;
106  // }
107 
108  const bool verbose = false;
109  if(verbose)
110  {
111  int cEGammas = 0;
112  int fEGammas = 0;
113  printf("EGammas Isolated\n");
114  for(std::vector<l1t::EGamma>::const_iterator itEGamma = egammas->begin();
115  itEGamma != egammas->end(); ++itEGamma){
116  if(itEGamma->hwIso() != 1) continue;
117  cEGammas++;
118  unsigned int packed = pack15bits(itEGamma->hwPt(), itEGamma->hwEta(), itEGamma->hwPhi());
119  cout << bitset<15>(packed).to_string() << endl;
120  if(cEGammas == 4) break;
121  }
122 
123  printf("EGammas Non-isolated\n");
124  for(std::vector<l1t::EGamma>::const_iterator itEGamma = egammas->begin();
125  itEGamma != egammas->end(); ++itEGamma){
126  if(itEGamma->hwIso() != 0) continue;
127  fEGammas++;
128  unsigned int packed = pack15bits(itEGamma->hwPt(), itEGamma->hwEta(), itEGamma->hwPhi());
129  cout << bitset<15>(packed).to_string() << endl;
130  if(fEGammas == 4) break;
131  }
132  }
133 
134  delete subRegions;
135  delete unCorrJets;
136  delete preSortEGammas;
137  delete preGtEGammas;
138 
139 }
140 
141 //ieta =-28, nrTowers 0 is 0, increases to ieta28, nrTowers=kNrTowersInSum
142 unsigned l1t::Stage1Layer2EGammaAlgorithmImpHW::isoLutIndex(unsigned int egPt,unsigned int jetPt) const
143 {
144  const unsigned int nbitsEG=6; // number of bits used for EG bins in LUT file (needed for left shift operation)
145  // const unsigned int nbitsJet=9; // not used but here for info number of bits used for Jet bins in LUT file
146 
147  //jetPt &= 511; // Take only the LSB 9 bits to match firmware.
148  if(jetPt > 511) jetPt = 511;
149  unsigned int address= (jetPt << nbitsEG) + egPt;
150  // std::cout << address << "\t## " << egPt << " " << jetPt << std::endl;
151  return address;
152 }
153 
155  const std::vector<l1t::Jet> * jets) const {
156 
157  bool Debug=false;
158 
159  if (Debug) cout << "Number of jets: " << jets->size() << endl;
160  int pt = 0;
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 (Debug) cout << "Matching ETA: " << ieta << " " << jetEta << endl;
169  if (Debug) cout << "Matching PHI: " << iphi << " " << jetPhi << endl;
170  if ((jetEta == ieta) && (jetPhi == iphi)){
171  pt = itJet->hwPt();
172  break;
173  }
174  }
175 
176  // set output
177  return pt;
178 }
void RegionCorrection(const std::vector< l1t::CaloRegion > &regions, std::vector< l1t::CaloRegion > *subRegions, CaloParamsHelper *params)
------— New region correction (PUsub, no response correction at the moment) --------— ...
void EGammaToGtScales(CaloParamsHelper *params, const std::vector< l1t::EGamma > *input, std::vector< l1t::EGamma > *output)
void TwelveByTwelveFinder(const int, const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
std::string to_string(const T &t)
Definition: Logger.cc:26
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
unsigned int pack15bits(int pt, int eta, int phi)
tuple cout
Definition: gather_cfg.py:121
virtual 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)
const bool Debug
std::vector< CaloEmCand >::const_iterator const_iterator
Definition: BXVector.h:16