CMS 3D CMS Logo

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