CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Stage1Layer2TauAlgorithmImpPP.cc
Go to the documentation of this file.
1 
11 
19 
20 using namespace std;
21 using namespace l1t;
22 
23 
24 Stage1Layer2TauAlgorithmImpPP::Stage1Layer2TauAlgorithmImpPP(CaloParamsHelper* params) : params_(params)
25 {
26 }
27 
29 
30 
31 
32 
33 void l1t::Stage1Layer2TauAlgorithmImpPP::processEvent(const std::vector<l1t::CaloEmCand> & EMCands,
34  const std::vector<l1t::CaloRegion> & regions,
35  std::vector<l1t::Tau> * isoTaus,
36  std::vector<l1t::Tau> * taus) {
37 
38  double towerLsb = params_->towerLsbSum();
39 
40  int tauSeedThreshold= floor( params_->tauSeedThreshold()/towerLsb + 0.5); // convert GeV to HW units
41  int tauNeighbourThreshold= floor( params_->tauNeighbourThreshold()/towerLsb + 0.5); // convert GeV to HW units
42  int jetSeedThreshold= floor( params_->jetSeedThreshold()/towerLsb + 0.5); // convert GeV to HW units
43  int tauMaxPtTauVeto = floor( params_->tauMaxPtTauVeto()/towerLsb + 0.5);
44  int tauMinPtJetIsolationB = floor( params_->tauMinPtJetIsolationB()/towerLsb + 0.5);
45  int isoTauEtaMin = params_->isoTauEtaMin();
46  int isoTauEtaMax = params_->isoTauEtaMax();
47  double tauMaxJetIsolationB = params_->tauMaxJetIsolationB();
48  double tauMaxJetIsolationA = params_->tauMaxJetIsolationA();
49 
50  std::vector<l1t::CaloRegion> *subRegions = new std::vector<l1t::CaloRegion>();
51 
52 
53  //Region Correction will return uncorrected subregions if
54  //regionPUSType is set to None in the config
55  RegionCorrection(regions, subRegions, params_);
56 
57 
58 
59  // ----- need to cluster jets in order to compute jet isolation ----
60  std::vector<l1t::Jet> *unCorrJets = new std::vector<l1t::Jet>();
61  //slidingWindowJetFinder(jetSeedThreshold, subRegions, unCorrJets);
62  TwelveByTwelveFinder(jetSeedThreshold, subRegions, unCorrJets);
63 
64  std::vector<l1t::Tau> *preGtTaus = new std::vector<l1t::Tau>();
65  std::vector<l1t::Tau> *preSortTaus = new std::vector<l1t::Tau>();
66  std::vector<l1t::Tau> *sortedTaus = new std::vector<l1t::Tau>();
67  std::vector<l1t::Tau> *preGtIsoTaus = new std::vector<l1t::Tau>();
68  std::vector<l1t::Tau> *preSortIsoTaus = new std::vector<l1t::Tau>();
69  std::vector<l1t::Tau> *sortedIsoTaus = new std::vector<l1t::Tau>();
70 
71  for(CaloRegionBxCollection::const_iterator region = subRegions->begin();
72  region != subRegions->end(); region++) {
73 
74  int regionEt = region->hwPt();
75  if(regionEt < tauSeedThreshold) continue;
76 
77  int regionEta = region->hwEta();
78  if(regionEta < 4 || regionEta > 17)
79  continue; // Taus cannot come from HF
80  int regionPhi = region->hwPhi();
81 
82  //int associatedSecondRegionEt =
83  // AssociatedSecondRegionEt(region->hwEta(), region->hwPhi(),
84  // *subRegions);
85 
86  int tauEt=regionEt;
87  int isoFlag=0; // is 1 if it passes the relative jet iso requirement
88  int quality = 1; //doesn't really mean anything and isn't used
89 
90  int highestNeighborEt=0;
91  int highestNeighborEta=999;
92  int highestNeighborPhi=999;
93  int highestNeighborTauVeto=999;
94 
95  // if (regionEt>0) std::cout << "CCLA Prod: TauVeto: " << region->hwQual() << "\tET: " << regionEt << "\tETA: " << regionEta << "\tPhi: " << regionPhi << std::endl;
96 
97  //Find neighbor with highest Et
98  for(CaloRegionBxCollection::const_iterator neighbor = subRegions->begin();
99  neighbor != subRegions->end(); neighbor++) {
100 
101  int neighborPhi = neighbor->hwPhi();
102  int neighborEta = neighbor->hwEta();
103  if(neighborEta < 4 || neighborEta > 17)
104  continue; // Taus cannot come from HF
105 
106  int deltaPhi = regionPhi - neighborPhi;
107  if (std::abs(deltaPhi) == L1CaloRegionDetId::N_PHI-1)
108  deltaPhi = -deltaPhi/std::abs(deltaPhi); //18 regions in phi
109 
110  deltaPhi = std::abs(deltaPhi);
111  int deltaEta = std::abs(regionEta - neighborEta);
112 
113  if (deltaPhi + deltaEta > 0 && deltaPhi + deltaEta < 2) { //nondiagonal neighbors
114  if (neighbor->hwPt() > highestNeighborEt) {
115  highestNeighborEt = neighbor->hwPt();
116  highestNeighborEta = neighbor->hwEta();
117  highestNeighborPhi = neighbor->hwPhi();
118  int neighborTauVeto = neighbor->hwQual() & 0x1; // tauVeto should be the first bit of quality integer
119  highestNeighborTauVeto = neighborTauVeto;
120  }
121  }
122  }
123 
124 
125  string NESW = findNESW(regionEta, regionPhi, highestNeighborEta, highestNeighborPhi);
126 
127  //std::cout << "tau et, neighbor et " << tauEt << " " << highestNeighborEt << std::endl;
128  if((tauEt > highestNeighborEt && (NESW=="isEast" || NESW=="isNorth"))
129  || (tauEt >= highestNeighborEt && (NESW=="isSouth" || NESW=="isWest"))
130  || highestNeighborEt == 0 ) {
131 
132  if (highestNeighborEt >= tauNeighbourThreshold) tauEt += highestNeighborEt;
133 
134  int regionTauVeto = region->hwQual() & 0x1; // tauVeto should be the first bit of quality integer
135  //std::cout<< "regiontauveto, neighbor " << regionTauVeto << " " << highestNeighborTauVeto << std::endl;
136 
137  // compute relative jet isolation
138  if (region->hwEta() >= isoTauEtaMin && region->hwEta() <= isoTauEtaMax ){
139  if ((highestNeighborTauVeto == 0 && regionTauVeto == 0) || tauEt > tauMaxPtTauVeto) {
140  bool useIsolLut=true;
141  if (useIsolLut){
142  int jetEt=AssociatedJetPt(region->hwEta(), region->hwPhi(),unCorrJets);
143  if (jetEt>0){
144  unsigned int MAX_LUT_ADDRESS = params_->tauIsolationLUT()->maxSize()-1;
145  unsigned int lutAddress = isoLutIndex(tauEt,jetEt);
146  if (tauEt >0){
147  if (lutAddress > MAX_LUT_ADDRESS) lutAddress = MAX_LUT_ADDRESS;
148  isoFlag= params_->tauIsolationLUT()->data(lutAddress);
149  }
150  }else{ // no associated jet
151  isoFlag=1;
152  }
153  }else{
154  double jetIsolation = JetIsolation(tauEt, region->hwEta(), region->hwPhi(), *unCorrJets);
155  if (jetIsolation < tauMaxJetIsolationA || (tauEt >= tauMinPtJetIsolationB && jetIsolation < tauMaxJetIsolationB)
156  || (std::abs(jetIsolation - 999.) < 0.1) ) isoFlag=1;
157  }
158  }
159  }
160 
161 
162  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > tauLorentz(0,0,0,0);
163 
164  l1t::Tau theTau(*&tauLorentz, tauEt, region->hwEta(), region->hwPhi(), quality, isoFlag);
165 
166  preGtTaus->push_back(theTau);
167  if(isoFlag)
168  preGtIsoTaus->push_back(theTau);
169  }
170  }
171  TauToGtPtScales(params_, preGtTaus, preSortTaus);
172  TauToGtPtScales(params_, preGtIsoTaus, preSortIsoTaus);
173 
174  SortTaus(preSortTaus, sortedTaus);
175  SortTaus(preSortIsoTaus, sortedIsoTaus);
176 
177  TauToGtEtaScales(params_, sortedTaus, taus);
178  TauToGtEtaScales(params_, sortedIsoTaus, isoTaus);
179 
180  delete subRegions;
181  delete unCorrJets;
182  delete preGtTaus;
183  delete preSortTaus;
184  delete sortedTaus;
185  delete preGtIsoTaus;
186  delete preSortIsoTaus;
187  delete sortedIsoTaus;
188 }
189 
190 
191 
192 
193 
194 // Compute jet isolation.
195 double l1t::Stage1Layer2TauAlgorithmImpPP::JetIsolation(int et, int ieta, int iphi,
196  const std::vector<l1t::Jet> & jets) const {
197 
198  for(JetBxCollection::const_iterator jet = jets.begin();
199  jet != jets.end(); jet++) {
200 
201  if (ieta==jet->hwEta() && iphi==jet->hwPhi()){
202 
203  double isolation = (double) (jet->hwPt() - et);
204  return isolation/et;
205  }
206  }
207 
208  // set output
209  return 999.;
210 }
211 
212 
213 // Find if the neighbor with the highest Et is N, E, S, or W
214 string l1t::Stage1Layer2TauAlgorithmImpPP::findNESW(int ieta, int iphi, int neta, int nphi) const {
215 
216  int deltaPhi = iphi - nphi;
217  if (std::abs(deltaPhi) == L1CaloRegionDetId::N_PHI-1)
218  deltaPhi = -deltaPhi/std::abs(deltaPhi); //18 regions in phi
219 
220  int deltaEta = ieta - neta;
221 
222  if ((std::abs(deltaPhi) + std::abs(deltaEta)) < 2) {
223  if (deltaEta==-1) {
224  return "isEast";
225  }
226  else if (deltaEta==0) {
227  if (deltaPhi==-1) {
228  return "isNorth";
229  }
230  if (deltaPhi==1) {
231  return "isSouth";
232  }
233  }
234  else {
235  return "isWest";
236  }
237  }
238 
239  return "999";
240 
241 }
242 
244  const std::vector<l1t::Jet> * jets) const {
245 
246  bool Debug=false;
247 
248  if (Debug) cout << "Number of jets: " << jets->size() << endl;
249  int pt = -1;
250 
251 
252  for(JetBxCollection::const_iterator itJet = jets->begin();
253  itJet != jets->end(); ++itJet){
254 
255  int jetEta = itJet->hwEta();
256  int jetPhi = itJet->hwPhi();
257  if (Debug) cout << "Matching ETA: " << ieta << " " << jetEta << endl;
258  if (Debug) cout << "Matching PHI: " << iphi << " " << jetPhi << endl;
259  if ((jetEta == ieta) && (jetPhi == iphi)){
260  pt = itJet->hwPt();
261  break;
262  }
263  }
264 
265  // set output
266  return pt;
267 }
268 
269 unsigned l1t::Stage1Layer2TauAlgorithmImpPP::isoLutIndex(unsigned int tauPt,unsigned int jetPt) const
270 {
271  //const unsigned int nbitsTau=9; // number of bits used for et in LUT file (needed for left shift operation)
272  //const unsigned int nbitsJet=9;
273 
274  const unsigned int nbitsTau=8; // number of bits used for et in LUT file (needed for left shift operation)
275  const unsigned int nbitsJet=8;
276 
277  const unsigned int maxJet = pow(2,nbitsJet)-1;
278  const unsigned int maxTau = pow(2,nbitsTau)-1;
279 
280  if (nbitsTau < 9)
281  {
282  if (nbitsTau == 6)
283  {
284  tauPt=tauPt>>3;
285  }
286  else if (nbitsTau == 7)
287  {
288  tauPt=tauPt>>2;
289  }
290  else if (nbitsTau == 8)
291  {
292  tauPt=tauPt>>1;
293  }
294  }
295 
296  if (nbitsJet < 9)// no need to do shift if nbits>=9
297  {
298  if (nbitsJet == 6)
299  {
300  jetPt=jetPt>>3;
301  }
302  else if (nbitsJet == 7)
303  {
304  jetPt=jetPt>>2;
305  }
306  else if (nbitsJet == 8)
307  {
308  jetPt=jetPt>>1;
309  }
310  }
311 
312  if (jetPt>maxJet) jetPt=maxJet;
313  if (tauPt>maxTau) tauPt=maxTau;
314 
315  unsigned int address= (jetPt << nbitsTau) + tauPt;
316  // std::cout << address << "\t## " << tauPt << " " << jetPt << std::endl;
317  return address;
318 }
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 TauToGtEtaScales(CaloParamsHelper *params, const std::vector< l1t::Tau > *input, std::vector< l1t::Tau > *output)
int AssociatedJetPt(int ieta, int iphi, const std::vector< l1t::Jet > *jets) const
Definition: Tau.h:13
virtual void processEvent(const std::vector< l1t::CaloEmCand > &EMCands, const std::vector< l1t::CaloRegion > &regions, std::vector< l1t::Tau > *isoTaus, std::vector< l1t::Tau > *taus)
void TwelveByTwelveFinder(const int, const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
void SortTaus(std::vector< l1t::Tau > *input, std::vector< l1t::Tau > *output)
string findNESW(int ieta, int iphi, int neta, int nphi) const
vector< PseudoJet > jets
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned isoLutIndex(unsigned int tauPt, unsigned int jetPt) const
double JetIsolation(int et, int ieta, int iphi, const std::vector< l1t::Jet > &jets) const
tuple cout
Definition: gather_cfg.py:121
static const unsigned N_PHI
void TauToGtPtScales(CaloParamsHelper *params, const std::vector< l1t::Tau > *input, std::vector< l1t::Tau > *output)
const bool Debug
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::vector< CaloRegion >::const_iterator const_iterator
Definition: BXVector.h:16