25 for(
size_t i=0;
i<
sines.size(); ++
i) {
38 const std::vector<l1t::CaloEmCand> & EMCands,
39 const std::vector<l1t::Jet> *
jets,
40 std::vector<l1t::EtSum> * etsums) {
42 std::vector<l1t::CaloRegion> *subRegions =
new std::vector<l1t::CaloRegion>();
47 double jetLsb=params_->jetLsb();
49 int etSumEtaMinEt = params_->etSumEtaMin(0);
50 int etSumEtaMaxEt = params_->etSumEtaMax(0);
52 int etSumEtThresholdEt = (int) (params_->etSumEtThreshold(0) / jetLsb);
54 int etSumEtaMinHt = params_->etSumEtaMin(1);
55 int etSumEtaMaxHt = params_->etSumEtaMax(1);
57 int etSumEtThresholdHt = (int) (params_->etSumEtThreshold(1) / jetLsb);
61 std::vector<SimpleRegion> regionEtVect;
62 std::vector<SimpleRegion> regionHtVect;
65 bool regionOverflowEt(
false);
66 bool regionOverflowHt(
false);
67 for (
auto&
region : regions) {
68 if(
region.hwEta() >= etSumEtaMinEt &&
region.hwEta() <= etSumEtaMaxEt)
72 regionOverflowEt =
true;
75 if (
region.hwEta() >= etSumEtaMinHt &&
region.hwEta() <= etSumEtaMaxHt)
79 regionOverflowHt =
true;
88 for (
auto&
region : *subRegions) {
89 if (
region.hwEta() >= etSumEtaMinEt &&
region.hwEta() <= etSumEtaMaxEt)
91 if(
region.hwPt() >= etSumEtThresholdEt)
97 regionEtVect.push_back(r);
100 if (
region.hwEta() >= etSumEtaMinHt &&
region.hwEta() <= etSumEtaMaxHt)
102 if(
region.hwPt() >= etSumEtThresholdHt)
108 regionHtVect.push_back(r);
113 int sumET,
MET, iPhiET;
114 std::tie(sumET, MET, iPhiET) = doSumAndMET(regionEtVect, ETSumType::kEmSum);
116 int sumHT, MHT, iPhiHT;
117 std::tie(sumHT, MHT, iPhiHT) = doSumAndMET(regionHtVect, ETSumType::kHadronicSum);
124 if(MET > 0xfff || regionOverflowEt)
126 if(MHT > 0x7f || regionOverflowHt)
128 if(sumET > 0xfff || regionOverflowEt)
130 if(sumHT > 0xfff || regionOverflowHt)
135 uint16_t MHToHT=MHToverHT(MHT,sumHT);
137 iPhiHT = DiJetPhi(jets);
139 const ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > etLorentz(0,0,0,0);
140 l1t::EtSum etMiss(*&etLorentz,EtSum::EtSumType::kMissingEt,MET&0xfff,0,iPhiET,METqual);
141 l1t::EtSum htMiss(*&etLorentz,EtSum::EtSumType::kMissingHt,MHToHT&0x7f,0,iPhiHT,MHTqual);
142 l1t::EtSum etTot (*&etLorentz,EtSum::EtSumType::kTotalEt,sumET&0xfff,0,0,ETTqual);
143 l1t::EtSum htTot (*&etLorentz,EtSum::EtSumType::kTotalHt,sumHT&0xfff,0,0,HTTqual);
145 std::vector<l1t::EtSum> *preGtEtSums =
new std::vector<l1t::EtSum>();
147 preGtEtSums->push_back(etMiss);
148 preGtEtSums->push_back(htMiss);
149 preGtEtSums->push_back(etTot);
150 preGtEtSums->push_back(htTot);
161 for(std::vector<l1t::EtSum>::const_iterator itetsum = etsums->begin();
162 itetsum != etsums->end(); ++itetsum){
163 if(EtSum::EtSumType::kMissingEt == itetsum->getType())
165 cout <<
"Missing Et" << endl;
166 cout << bitset<7>(itetsum->hwPhi()).
to_string() << bitset<1>(itetsum->hwQual()).
to_string() << bitset<12>(itetsum->hwPt()).
to_string() << endl;
168 if(EtSum::EtSumType::kMissingHt == itetsum->getType())
170 cout <<
"Missing Ht" << endl;
171 cout << bitset<1>(itetsum->hwQual()).
to_string() << bitset<7>(itetsum->hwPt()).
to_string() << bitset<5>(itetsum->hwPhi()).
to_string() << endl;
173 if(EtSum::EtSumType::kTotalEt == itetsum->getType())
175 cout <<
"Total Et" << endl;
176 cout << bitset<1>(itetsum->hwQual()).
to_string() << bitset<12>(itetsum->hwPt()).
to_string() << endl;
178 if(EtSum::EtSumType::kTotalHt == itetsum->getType())
180 cout <<
"Total Ht" << endl;
181 cout << bitset<1>(itetsum->hwQual()).
to_string() << bitset<12>(itetsum->hwPt()).
to_string() << endl;
187 std::tuple<int, int, int>
190 std::array<int, 18> sumEtaPos{};
191 std::array<int, 18> sumEtaNeg{};
192 for (
const auto&
r : regionEt)
195 sumEtaNeg[
r.iphi] +=
r.et;
197 sumEtaPos[
r.iphi] +=
r.et;
200 std::array<int, 18> sumEta{};
202 for(
size_t i=0;
i<sumEta.size(); ++
i)
204 assert(sumEtaPos[
i] >= 0 && sumEtaNeg[
i] >= 0);
205 sumEta[
i] = sumEtaPos[
i] + sumEtaNeg[
i];
210 std::array<int, 5> sumsForCos{};
211 std::array<int, 5> sumsForSin{};
212 for(
size_t iphi=0; iphi<sumEta.size(); ++iphi)
216 sumsForCos[iphi] += sumEta[iphi];
217 sumsForSin[iphi] += sumEta[iphi];
221 sumsForCos[9-iphi] -= sumEta[iphi];
222 sumsForSin[9-iphi] += sumEta[iphi];
224 else if ( iphi < 14 )
226 sumsForCos[iphi-9] -= sumEta[iphi];
227 sumsForSin[iphi-9] -= sumEta[iphi];
231 sumsForCos[18-iphi] += sumEta[iphi];
232 sumsForSin[18-iphi] -= sumEta[iphi];
238 for(
int i=0;
i<5; ++
i)
240 sumX += sumsForCos[
i]*cosines[
i];
241 sumY += sumsForSin[
i]*sines[
i];
244 int cordicX = sumX>>25;
245 int cordicY = sumY>>25;
247 uint32_t cordicMag(0);
249 cordic(cordicX, cordicY, cordicPhase, cordicMag);
253 if ( sumType == ETSumType::kHadronicSum )
255 met = (cordicMag % (1<<7)) | ((cordicMag >= (1<<7)) ? (1<<7):0);
256 metPhi = cordicToMETPhi(cordicPhase) >> 2;
257 assert(metPhi >=0 && metPhi < 18);
261 met = (cordicMag % (1<<12)) | ((cordicMag >= (1<<12)) ? (1<<12):0);
262 metPhi = cordicToMETPhi(cordicPhase);
263 assert(metPhi >=0 && metPhi < 72);
266 return std::make_tuple(sumEt, met, metPhi);
275 for(
size_t i=0;
i<cordicPhiValues.size()-1; ++
i)
276 if ( phase >= cordicPhiValues[
i] && phase < cordicPhiValues[
i+1] )
287 if (jets->size()<2)
return dphi;
288 if ((*jets).at(0).hwPt() == 0)
return dphi;
289 if ((*jets).at(1).hwPt() == 0)
return dphi;
292 int iphi1 = (*jets).at(0).hwPhi();
293 int iphi2 = (*jets).at(1).hwPhi();
295 int difference=
abs(iphi1-iphi2);
312 result = result & 0x7f;
std::tuple< int, int, int > doSumAndMET(const std::vector< SimpleRegion > ®ionEt, ETSumType sumType)
std::array< int, 73 > cordicPhiValues
void RegionCorrection(const std::vector< l1t::CaloRegion > ®ions, std::vector< l1t::CaloRegion > *subRegions, CaloParamsHelper *params)
------— New region correction (PUsub, no response correction at the moment) --------— ...
Sin< T >::type sin(const T &t)
int DiJetPhi(const std::vector< l1t::Jet > *jets) const
std::array< long, 5 > cosines
void EtSumToGtScales(CaloParamsHelper *params, const std::vector< l1t::EtSum > *input, std::vector< l1t::EtSum > *output)
std::string to_string(const T &t)
Stage1Layer2EtSumAlgorithmImpHW(CaloParamsHelper *params)
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
virtual ~Stage1Layer2EtSumAlgorithmImpHW()
uint16_t MHToverHT(uint16_t, uint16_t) const
virtual void processEvent(const std::vector< l1t::CaloRegion > ®ions, const std::vector< l1t::CaloEmCand > &EMCands, const std::vector< l1t::Jet > *jets, std::vector< l1t::EtSum > *sums)
static const unsigned N_PHI
int cordicToMETPhi(int phase)
std::array< long, 5 > sines
Power< A, B >::type pow(const A &a, const B &b)