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>();
50 int etSumEtaMinEt = params_->etSumEtaMin(0);
51 int etSumEtaMaxEt = params_->etSumEtaMax(0);
53 int etSumEtThresholdEt = (int) (params_->etSumEtThreshold(0) / jetLsb);
55 int etSumEtaMinHt = params_->etSumEtaMin(1);
56 int etSumEtaMaxHt = params_->etSumEtaMax(1);
58 int etSumEtThresholdHt = (int) (params_->etSumEtThreshold(1) / jetLsb);
62 std::vector<SimpleRegion> regionEtVect;
63 std::vector<SimpleRegion> regionHtVect;
66 bool regionOverflowEt(
false);
67 bool regionOverflowHt(
false);
68 for (
auto&
region : regions) {
69 if(
region.hwEta() >= etSumEtaMinEt &&
region.hwEta() <= etSumEtaMaxEt)
73 regionOverflowEt =
true;
76 if (
region.hwEta() >= etSumEtaMinHt &&
region.hwEta() <= etSumEtaMaxHt)
80 regionOverflowHt =
true;
90 for (
auto&
region : regions) {
91 if (
region.hwEta() >= etSumEtaMinEt &&
region.hwEta() <= etSumEtaMaxEt)
93 if(
region.hwPt() >= etSumEtThresholdEt)
99 regionEtVect.push_back(r);
102 if (
region.hwEta() >= etSumEtaMinHt &&
region.hwEta() <= etSumEtaMaxHt)
104 if(
region.hwPt() >= etSumEtThresholdHt)
110 regionHtVect.push_back(r);
115 int sumET,
MET, iPhiET;
116 std::tie(sumET, MET, iPhiET) = doSumAndMET(regionEtVect, ETSumType::kEmSum);
118 int sumHT, MHT, iPhiHT;
119 std::tie(sumHT, MHT, iPhiHT) = doSumAndMET(regionHtVect, ETSumType::kHadronicSum);
126 if(MET >= 0xfff || regionOverflowEt)
128 if(MHT >= 0x7f || regionOverflowHt)
130 if(sumET >= 0xfff || regionOverflowEt)
132 if(sumHT >= 0xfff || regionOverflowHt)
137 uint16_t MHToHT=MHToverHT(MHT,sumHT);
141 iPhiHT = DiJetPhi(jets);
144 const ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > etLorentz(0,0,0,0);
145 l1t::EtSum etMiss(*&etLorentz,EtSum::EtSumType::kMissingEt,MET&0xfff,0,iPhiET,METqual);
146 l1t::EtSum htMiss(*&etLorentz,EtSum::EtSumType::kMissingHt,MHToHT&0x7f,0,iPhiHT,MHTqual);
147 l1t::EtSum etTot (*&etLorentz,EtSum::EtSumType::kTotalEt,sumET&0xfff,0,0,ETTqual);
148 l1t::EtSum htTot (*&etLorentz,EtSum::EtSumType::kTotalHt,sumHT&0xfff,0,0,HTTqual);
150 std::vector<l1t::EtSum> *preGtEtSums =
new std::vector<l1t::EtSum>();
152 preGtEtSums->push_back(etMiss);
153 preGtEtSums->push_back(htMiss);
154 preGtEtSums->push_back(etTot);
155 preGtEtSums->push_back(htTot);
166 for(std::vector<l1t::EtSum>::const_iterator itetsum = etsums->begin();
167 itetsum != etsums->end(); ++itetsum){
168 if(EtSum::EtSumType::kMissingEt == itetsum->getType())
170 cout <<
"Missing Et" << endl;
171 cout << bitset<7>(itetsum->hwPhi()).
to_string() << bitset<1>(itetsum->hwQual()).
to_string() << bitset<12>(itetsum->hwPt()).
to_string() << endl;
173 if(EtSum::EtSumType::kMissingHt == itetsum->getType())
175 cout <<
"Missing Ht" << endl;
176 cout << bitset<1>(itetsum->hwQual()).
to_string() << bitset<7>(itetsum->hwPt()).
to_string() << bitset<5>(itetsum->hwPhi()).
to_string() << endl;
178 if(EtSum::EtSumType::kTotalEt == itetsum->getType())
180 cout <<
"Total Et" << endl;
181 cout << bitset<1>(itetsum->hwQual()).
to_string() << bitset<12>(itetsum->hwPt()).
to_string() << endl;
183 if(EtSum::EtSumType::kTotalHt == itetsum->getType())
185 cout <<
"Total Ht" << endl;
186 cout << bitset<1>(itetsum->hwQual()).
to_string() << bitset<12>(itetsum->hwPt()).
to_string() << endl;
192 std::tuple<int, int, int>
195 std::array<int, 18> sumEtaPos{};
196 std::array<int, 18> sumEtaNeg{};
197 for (
const auto&
r : regionEt)
200 sumEtaNeg[
r.iphi] +=
r.et;
202 sumEtaPos[
r.iphi] +=
r.et;
205 std::array<int, 18> sumEta{};
207 for(
size_t i=0;
i<sumEta.size(); ++
i)
209 assert(sumEtaPos[
i] >= 0 && sumEtaNeg[
i] >= 0);
210 sumEta[
i] = sumEtaPos[
i] + sumEtaNeg[
i];
215 std::array<int, 5> sumsForCos{};
216 std::array<int, 5> sumsForSin{};
217 for(
size_t iphi=0; iphi<sumEta.size(); ++iphi)
221 sumsForCos[iphi] += sumEta[iphi];
222 sumsForSin[iphi] += sumEta[iphi];
226 sumsForCos[9-iphi] -= sumEta[iphi];
227 sumsForSin[9-iphi] += sumEta[iphi];
229 else if ( iphi < 14 )
231 sumsForCos[iphi-9] -= sumEta[iphi];
232 sumsForSin[iphi-9] -= sumEta[iphi];
236 sumsForCos[18-iphi] += sumEta[iphi];
237 sumsForSin[18-iphi] -= sumEta[iphi];
243 for(
int i=0;
i<5; ++
i)
245 sumX += sumsForCos[
i]*cosines[
i];
246 sumY += sumsForSin[
i]*sines[
i];
249 int cordicX = sumX>>25;
250 int cordicY = sumY>>25;
252 uint32_t cordicMag(0);
254 cordic(cordicX, cordicY, cordicPhase, cordicMag);
258 if ( sumType == ETSumType::kHadronicSum )
260 met = (cordicMag % (1<<7)) | ((cordicMag >= (1<<7)) ? (1<<7):0);
261 metPhi = cordicToMETPhi(cordicPhase) >> 2;
262 assert(metPhi >=0 && metPhi < 18);
266 met = (cordicMag % (1<<12)) | ((cordicMag >= (1<<12)) ? (1<<12):0);
267 metPhi = cordicToMETPhi(cordicPhase);
268 assert(metPhi >=0 && metPhi < 72);
271 return std::make_tuple(sumEt, met, metPhi);
280 for(
size_t i=0;
i<cordicPhiValues.size()-1; ++
i)
281 if ( phase >= cordicPhiValues[
i] && phase < cordicPhiValues[
i+1] )
292 if (jets->size()<2)
return dphi;
293 if ((*jets).at(0).hwPt() == 0)
return dphi;
294 if ((*jets).at(1).hwPt() == 0)
return dphi;
297 int iphi1 = (*jets).at(0).hwPhi();
298 int iphi2 = (*jets).at(1).hwPhi();
300 int difference=
abs(iphi1-iphi2);
317 result = result & 0x7f;
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)
Sin< T >::type sin(const T &t)
std::array< long, 5 > sines
virtual ~Stage1Layer2EtSumAlgorithmImpHI()
void EtSumToGtScales(CaloParamsHelper *params, const std::vector< l1t::EtSum > *input, std::vector< l1t::EtSum > *output)
std::tuple< int, int, int > doSumAndMET(const std::vector< SimpleRegion > ®ionEt, ETSumType sumType)
Stage1Layer2EtSumAlgorithmImpHI(CaloParamsHelper *params)
std::string to_string(const T &t)
int DiJetPhi(const std::vector< l1t::Jet > *jets) const
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
int cordicToMETPhi(int phase)
std::array< long, 5 > cosines
uint16_t MHToverHT(uint16_t, uint16_t) const
static const unsigned N_PHI
Power< A, B >::type pow(const A &a, const B &b)
std::array< int, 73 > cordicPhiValues