CMS 3D CMS Logo

Stage1Layer2EtSumAlgorithmImpPP.cc
Go to the documentation of this file.
1 
17 
19 {
20  //now do what ever initialization is needed
21  for(unsigned int i = 0; i < L1CaloRegionDetId::N_PHI; i++) {
22  sinPhi.push_back(sin(2. * 3.1415927 * i * 1.0 / L1CaloRegionDetId::N_PHI));
23  cosPhi.push_back(cos(2. * 3.1415927 * i * 1.0 / L1CaloRegionDetId::N_PHI));
24  }
25 }
26 
27 
28 //double l1t::Stage1Layer2EtSumAlgorithmImpPP::regionPhysicalEt(const l1t::CaloRegion& cand) const {
29 // return jetLsb*cand.hwPt();
30 //}
31 
32 void l1t::Stage1Layer2EtSumAlgorithmImpPP::processEvent(const std::vector<l1t::CaloRegion> & regions,
33  const std::vector<l1t::CaloEmCand> & EMCands,
34  const std::vector<l1t::Jet> * jets,
35  std::vector<l1t::EtSum> * etsums) {
36 
37  unsigned int sumET = 0;
38  double sumEx = 0;
39  double sumEy = 0;
40  unsigned int sumHT = 0;
41  double sumHx = 0;
42  double sumHy = 0;
43 
44  std::vector<l1t::CaloRegion> subRegions;
45 
46 
47  //Region Correction will return uncorrected subregions if
48  //regionPUSType is set to None in the config
49  double jetLsb=params_->jetLsb();
50 
51  int etSumEtaMinEt = params_->etSumEtaMin(0);
52  int etSumEtaMaxEt = params_->etSumEtaMax(0);
53  //double etSumEtThresholdEt = params_->etSumEtThreshold(0);
54  int etSumEtThresholdEt = (int) (params_->etSumEtThreshold(0) / jetLsb);
55 
56  int etSumEtaMinHt = params_->etSumEtaMin(1);
57  int etSumEtaMaxHt = params_->etSumEtaMax(1);
58  //double etSumEtThresholdHt = params_->etSumEtThreshold(1);
59  int etSumEtThresholdHt = (int) (params_->etSumEtThreshold(1) / jetLsb);
60 
61  RegionCorrection(regions, &subRegions, params_);
62 
63  double towerLsb = params_->towerLsbSum();
64  int jetSeedThreshold = floor( params_->jetSeedThreshold()/towerLsb + 0.5);
65  // ----- cluster jets for repurposing of MHT phi (use if for angle between leading jet)
66  std::vector<l1t::Jet> unCorrJets;
67  std::vector<l1t::Jet> unSortedJets;
68  std::vector<l1t::Jet> SortedJets;
69  slidingWindowJetFinder(jetSeedThreshold, &subRegions, &unCorrJets);
70 
71  //if jetCalibrationType is set to None in the config
72  std::string jetCalibrationType = params_->jetCalibrationType();
73  std::vector<double> jetCalibrationParams = params_->jetCalibrationParams();
74  JetCalibration(&unCorrJets, jetCalibrationParams, &unSortedJets, jetCalibrationType, towerLsb);
75 
76  SortJets(&unSortedJets, &SortedJets);
77  int dijet_phi=DiJetPhi(&SortedJets);
78 
79  for(std::vector<CaloRegion>::const_iterator region = subRegions.begin(); region != subRegions.end(); region++) {
80  if (region->hwEta() < etSumEtaMinEt || region->hwEta() > etSumEtaMaxEt) {
81  continue;
82  }
83 
84  //double regionET= regionPhysicalEt(*region);
85  int regionET = region->hwPt();
86 
87  if(regionET >= etSumEtThresholdEt){
88  sumET += regionET;
89  sumEx += (((double) regionET) * cosPhi[region->hwPhi()]);
90  sumEy += (((double) regionET) * sinPhi[region->hwPhi()]);
91  }
92  }
93 
94  for(std::vector<CaloRegion>::const_iterator region = subRegions.begin(); region != subRegions.end(); region++) {
95  if (region->hwEta() < etSumEtaMinHt || region->hwEta() > etSumEtaMaxHt) {
96  continue;
97  }
98 
99  //double regionET= regionPhysicalEt(*region);
100  int regionET = region->hwPt();
101 
102  if(regionET >= etSumEtThresholdHt) {
103  sumHT += regionET;
104  sumHx += (((double) regionET) * cosPhi[region->hwPhi()]);
105  sumHy += (((double) regionET) * sinPhi[region->hwPhi()]);
106  }
107  }
108 
109  unsigned int MET = ((unsigned int) sqrt(sumEx * sumEx + sumEy * sumEy));
110  unsigned int MHT = ((unsigned int) sqrt(sumHx * sumHx + sumHy * sumHy));
111 
112  double physicalPhi = atan2(sumEy, sumEx) + 3.1415927;
113  // Global Trigger expects MET phi to be 0-71 (e.g. tower granularity)
114  // Although we calculated it with regions, there is some benefit to interpolation.
115  unsigned int iPhiET = 4*L1CaloRegionDetId::N_PHI * physicalPhi / (2 * 3.1415927);
116 
117  double physicalPhiHT = atan2(sumHy, sumHx) + 3.1415927;
118  unsigned int iPhiHT = L1CaloRegionDetId::N_PHI * (physicalPhiHT) / (2 * 3.1415927);
119 
120  const ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > etLorentz(0,0,0,0);
121 
122  // Set quality (i.e. overflow) bits appropriately
123  int METqual = 0;
124  int MHTqual = 0;
125  int ETTqual = 0;
126  int HTTqual = 0;
127  if(MET >= 0xfff) // MET 12 bits
128  METqual = 1;
129  if(MHT >= 0x7f) // MHT 7 bits
130  MHTqual = 1;
131  if(sumET >= 0xfff)
132  ETTqual = 1;
133  if(sumHT >= 0xfff)
134  HTTqual = 1;
135 
136 
137 
138  // scale MHT by sumHT
139  // int mtmp = floor (((double) MHT / (double) sumHT)*100 + 0.5);
140  // double mtmp = ((double) MHT / (double) sumHT);
141  // int rank=params_->HtMissScale().rank(mtmp);
142  // MHT=rank;
143 
144  uint16_t MHToHT=MHToverHT(MHT,sumHT);
145  iPhiHT=dijet_phi;
146 
147  l1t::EtSum etMiss(*&etLorentz,EtSum::EtSumType::kMissingEt,MET,0,iPhiET,METqual);
148  l1t::EtSum htMiss(*&etLorentz,EtSum::EtSumType::kMissingHt,MHToHT&0x7f,0,iPhiHT,MHTqual);
149  l1t::EtSum etTot (*&etLorentz,EtSum::EtSumType::kTotalEt,sumET&0xfff,0,0,ETTqual);
150  l1t::EtSum htTot (*&etLorentz,EtSum::EtSumType::kTotalHt,sumHT&0xfff,0,0,HTTqual);
151 
152  std::vector<l1t::EtSum> preGtEtSums = {etMiss, htMiss, etTot, htTot};
153 
154  EtSumToGtScales(params_, &preGtEtSums, etsums);
155 }
156 
157 int l1t::Stage1Layer2EtSumAlgorithmImpPP::DiJetPhi(const std::vector<l1t::Jet> * jets) const {
158 
159  int dphi = 10; // initialize to negative physical dphi value
160  if (jets->size()<2) return dphi; // size() not really reliable as we pad the size to 8 (4cen+4for) in the sorter
161  if ((*jets).at(0).hwPt() == 0) return dphi;
162  if ((*jets).at(1).hwPt() == 0) return dphi;
163 
164 
165  int iphi1 = (*jets).at(0).hwPhi();
166  int iphi2 = (*jets).at(1).hwPhi();
167 
168  int difference=abs(iphi1-iphi2);
169 
170  if ( difference > 9 ) difference= L1CaloRegionDetId::N_PHI - difference ; // make Physical dphi always positive
171  return difference;
172 }
173 
174 uint16_t l1t::Stage1Layer2EtSumAlgorithmImpPP::MHToverHT(uint16_t num,uint16_t den) const {
175 
176  uint16_t result;
177  uint32_t numerator(num),denominator(den);
178 
179  if(numerator == denominator)
180  result = 0x7f;
181  else
182  {
183  numerator = numerator << 7;
184  result = numerator/denominator;
185  result = result & 0x7f;
186  }
187  return result;
188 }
void JetCalibration(std::vector< l1t::Jet > *uncalibjets, std::vector< double > jetCalibrationParams, std::vector< l1t::Jet > *jets, std::string jetCalibrationType, double jetLSB)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Stage1Layer2EtSumAlgorithmImpPP(CaloParamsHelper const *params)
double etSumEtThreshold(unsigned isum) const
std::string const & jetCalibrationType() const
int etSumEtaMax(unsigned isum) const
void SortJets(std::vector< l1t::Jet > *input, std::vector< l1t::Jet > *output)
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) --------— ...
std::vector< double > const & jetCalibrationParams() const
int etSumEtaMin(unsigned isum) const
void EtSumToGtScales(CaloParamsHelper const *params, const std::vector< l1t::EtSum > *input, std::vector< l1t::EtSum > *output)
T sqrt(T t)
Definition: SSEVec.h:18
double jetLsb() const
vector< PseudoJet > jets
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void processEvent(const std::vector< l1t::CaloRegion > &regions, const std::vector< l1t::CaloEmCand > &EMCands, const std::vector< l1t::Jet > *jets, std::vector< l1t::EtSum > *sums) override
uint16_t MHToverHT(uint16_t, uint16_t) const
void slidingWindowJetFinder(const int, const std::vector< l1t::CaloRegion > *regions, std::vector< l1t::Jet > *uncalibjets)
int DiJetPhi(const std::vector< l1t::Jet > *jets) const
double towerLsbSum() const
static const unsigned N_PHI
double jetSeedThreshold() const