18#include <boost/property_tree/ptree.hpp>
19#include <boost/property_tree/xml_parser.hpp>
31using boost::property_tree::ptree;
37 auto inoct_sector = ((sector + 2) % 4);
38 auto mioct_number = ((sector + 2) / 4) % 8;
39 return std::make_pair(inoct_sector,mioct_number);
43 return ((30 + 4 * mioct) +
number) % 32;
47 auto inoct_sector = ((sector + 1) % 6);
48 auto mioct_number = ((sector + 1) / 6) % 8;
49 return std::make_pair(inoct_sector,mioct_number);
54 return ((47 + 6 * mioct) +
number) % 48;
57 auto inoct_sector = (sector % 3);
58 auto mioct_number = (sector / 3) % 8;
59 return std::make_pair(inoct_sector,mioct_number);
64 return ((0 + 3 * mioct) +
number) % 24;
74 std::array<std::map<std::string,std::vector<std::string>>,2>
lhs_index;
75 std::array<std::map<std::string,std::vector<std::string>>,2>
rhs_index;
77 std::string
make_key(std::string prefix,
int global_sec,
int roi){
78 prefix += std::to_string(global_sec) +
"_" + std::to_string(roi);
82 std::string
make_pair(
const std::string& lhs,
const std::string& rhs)
const {
83 return lhs +
":" + rhs;
89 for(
const auto& region : side_regions.second){
90 auto split = region.find(
':');
91 auto left = region.substr(0,
split);
92 auto right = region.substr(
split+1,std::string::npos);
93 lhs_index[side_regions.first][left].push_back(right);
94 rhs_index[side_regions.first][right].push_back(std::move(left));
99 std::vector<std::string>
get_lhs_keys(
const std::string& dettype,
int roi,
int sector)
const {
100 std::vector<std::string>
r;
101 r.push_back(dettype + std::to_string(sector) +
"_" + std::to_string(roi));
105 std::vector<std::string>
get_rhs_keys(
const std::string& dettype,
int roi,
int sector)
const {
106 std::vector<std::string>
r;
107 r.push_back(dettype + std::to_string(sector) +
"_" + std::to_string(roi));
111 std::vector<std::string>
relevant_regions(
int side,
const std::string& dettype,
int roi,
int sector)
const {
112 std::vector<std::string>
r;
113 for(
const auto& key :
get_lhs_keys(dettype,roi,sector)){
116 for(
const auto&
rr :
x->second){
121 for(
const auto& key :
get_rhs_keys(dettype,roi,sector)){
124 for(
const auto&
rr :
x->second){
135 read_xml(lutFile, inputTree);
137 boost::property_tree::ptree topEle = inputTree.get_child(
"MUCTPI_LUT");
140 for(
const boost::property_tree::ptree::value_type &
x: topEle) {
142 std::string topElementName =
x.first;
145 if (topElementName !=
"LUT")
continue;
147 std::string SectorId1 =
xmlHelper.getAttribute(lut,
"SectorId1");
148 std::string SectorId2 =
xmlHelper.getAttribute(lut,
"SectorId2");
150 unsigned left_mod = 32;
151 unsigned right_mod = 32;
152 if (SectorId1[0] ==
'E') left_mod = 48;
153 if (SectorId1[0] ==
'F') left_mod = 24;
154 if (SectorId2[0] ==
'E') right_mod = 48;
155 if (SectorId2[0] ==
'F') right_mod = 24;
157 std::string snum_left = std::string(1,SectorId1[1])+std::string(1,SectorId1[2]);
158 int sec_left = std::stoi(snum_left) % left_mod;
160 std::string snum_right = std::string(1,SectorId2[1])+std::string(1,SectorId2[2]);
161 int sec_right = std::stoi(snum_right) % right_mod;
163 std::string side =
xmlHelper.getAttribute(lut,
"Side");
164 int active_side = (side ==
"C") ? 0 : 1;
166 std::string System1 = SectorId1.substr(0,1);
167 std::string System2 = SectorId2.substr(0,1);
169 for(
const boost::property_tree::ptree::value_type &
z: lut) {
170 std::string menuElementName =
z.first;
171 if(menuElementName!=
"Element" && menuElementName!=
"BBElement")
continue;
173 auto roi1 =
xmlHelper.getIntAttribute(ele,
"RoI1");
174 auto roi2 =
xmlHelper.getIntAttribute(ele,
"RoI2");
175 auto lhs_key =
make_key(System1,sec_left,roi1);
176 auto rhs_key =
make_key(System2,sec_right,roi2);
177 auto region =
make_pair(lhs_key,rhs_key);
226 const auto & exMU = &
m_l1menu->thrExtraInfo().MU();
227 auto rpcPtValues = exMU->knownRpcPtValues();
228 auto tgcPtValues = exMU->knownTgcPtValues();
229 for (
unsigned i=0; i<rpcPtValues.size(); i++){
232 for (
unsigned i=0; i<tgcPtValues.size(); i++){
243 std::map<std::string,std::vector<std::pair<std::shared_ptr<LVL1MUONIF::Lvl1MuSectorLogicDataPhase1>,
unsigned> > > buckets;
252 for (
size_t isub=0;isub<2;isub++)
254 if (isub !=
size_t(
m_side))
continue;
257 std::shared_ptr<LVL1MUONIF::Lvl1MuSectorLogicDataPhase1> sectorData = inputs->getSectorLogicDataPtr(isys, isub, isec, bcid);
258 if (!sectorData)
continue;
263 std::string sectorName=
"";
264 if (isys == 0) sectorName=
"B";
265 else if (isys == 1) sectorName=
"E";
266 else if (isys == 2) sectorName=
"F";
268 int roiID = sectorData->roi(icand);
269 if (roiID < 0)
continue;
270 int ptword = sectorData->pt(icand);
271 if (ptword < 0)
continue;
274 sectorData->veto(icand,0);
279 if( std::count(
rr.begin(),
rr.end(),
'B') == 2 && isys == 0 && sectorData->ovl(icand) == 0 )
continue;
280 buckets[
rr].push_back(std::make_pair(sectorData, icand));
287 for(
auto candidate_vector : buckets){
290 unsigned i_notRemove = 0;
292 for (
unsigned i=0;i<candidate_vector.second.size();i++){
293 if( candidate_vector.second[i].first->veto(candidate_vector.second[i].second)==1 )
continue;
294 int pt = candidate_vector.second[i].first->pt(candidate_vector.second[i].second);
302 for (
unsigned i=0;i<candidate_vector.second.size();i++)
304 if( candidate_vector.second[i].first->veto(candidate_vector.second[i].second)==1 )
continue;
305 candidate_vector.second[i].first->veto(candidate_vector.second[i].second, (i==i_notRemove)?0:1 );
321 for (
unsigned short isub=0;isub<2;isub++)
323 if (isub != (
unsigned short)(
m_side))
continue;
324 std::shared_ptr<LVL1MUONIF::Lvl1MuSectorLogicDataPhase1> sectorData = inputs->getSectorLogicDataPtr(isys, isub, isec, bcid);
325 if (!sectorData)
continue;
328 std::stringstream sectorName;
329 if (isys == 0) sectorName<<
"B";
330 else if (isys == 1) sectorName<<
"E";
331 else if (isys == 2) sectorName<<
"F";
336 int sectorNumber=isec;
338 if (sectorNumber < 10) sectorName <<
"0";
339 sectorName << sectorNumber;
344 else sectorName <<
"C";
345 if (isec < 10) sectorName <<
"0";
353 int roiID = sectorData->roi(icand);
354 if (roiID < 0)
continue;
355 int ptword = sectorData->pt(icand);
356 if (ptword < 0)
continue;
365 std::stringstream err;
366 err <<
"Couldn't decode L1Topo coordinates: Side = " << isub <<
", subsystem = " << isys <<
", sector = " << isec <<
", roi = " << roiID;
375 if (last_enc !=
m_ptEncoding[isys].rend() && ptword > last_enc->first)
381 std::stringstream err;
382 err <<
"Pt threshold not found in L1Topo encoding. Thr: " << ptword <<
", subsys: " << isys;
386 else ptValue=enc->second;
390 std::stringstream err;
391 err <<
"Default value returned for pt encoding. Thr: " << ptword <<
", isys: " << isys;
399 unsigned int mioctID = 0;
400 unsigned int ptCode=0;
406 (
unsigned int)ptword,
408 (
unsigned int)ptValue,
421 if (isys == 0) cand.
setRPCFlags(sectorData->is2candidates(icand),
422 sectorData->ovl(icand));
424 sectorData->innercoin(icand),
425 sectorData->goodmf(icand),
426 sectorData->charge(icand));
const boost::regex rr(r_r)
boost::property_tree::ptree ptree
std::vector< std::map< int, int > > m_ptEncoding
bool configurePtEncoding()
void setMenu(const TrigConf::L1Menu *l1menu)
MuonSectorProcessor(bool side)
void runOverlapRemoval(LVL1MUONIF::Lvl1MuCTPIInputPhase1 *inputs, int bcid) const
std::string makeL1TopoData(LVL1MUONIF::Lvl1MuCTPIInputPhase1 *inputs, int bcid, LVL1::MuCTPIL1Topo &l1topoData) const
const L1TopoLUT * m_l1topoLUT
std::unique_ptr< OverlapHelper > m_overlapHelper
const TrigConf::L1Menu * m_l1menu
void configureOverlapRemoval(const std::string &lutFile)
std::vector< std::string > get_rhs_keys(const std::string &dettype, int roi, int sector) const
std::array< std::map< std::string, std::vector< std::string > >, 2 > rhs_index
std::array< std::map< std::string, std::vector< std::string > >, 2 > lhs_index
void configure(const std::string &lutFile)
MuctpiXMLHelper xmlHelper
std::string make_key(std::string prefix, int global_sec, int roi)
std::vector< std::string > relevant_regions(int side, const std::string &dettype, int roi, int sector) const
std::map< int, std::set< std::string > > global_pairs
std::string make_pair(const std::string &lhs, const std::string &rhs) const
std::vector< std::string > get_lhs_keys(const std::string &dettype, int roi, int sector) const
MuCTPI input class to the L1Topo simulation.
void setRPCFlags(bool is2cand, bool phiOvl)
void setTGCFlags(bool bw2or3, bool innerCoin, bool goodMF, int charge)
void setCandidateData(const std::string §orName, unsigned int roiID, unsigned int bcid, unsigned int ptThresholdID, unsigned int ptL1TopoCode, unsigned int ptValue, float eta, float phi, unsigned int etacode, unsigned int phicode, float etamin, float etamax, float phimin, float phimax, unsigned int mioctID, int ieta, int iphi)
MuCTPI input class to the L1Topo simulation.
void addCandidate(const MuCTPIL1TopoCandidate &candidate)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
static const size_t NCAND[3]
int endcap_local2global(int number, int mioct)
std::pair< int, int > barrel_global2local(int sector)
std::pair< int, int > endcap_global2local(int sector)
std::pair< int, int > forward_global2local(int sector)
int barrel_local2global(int number, int mioct)
int forward_local2global(int number, int mioct)
std::string number(const double &d, const std::string &s)