27 #include <boost/dynamic_bitset.hpp>
30 static inline std::string
to_string(std::vector<size_t>
v);
31 static inline boost::dynamic_bitset<> lshift(boost::dynamic_bitset<>
const &
b,
int n);
32 static inline boost::dynamic_bitset<> rshift(boost::dynamic_bitset<>
const &
b,
int n);
33 static inline void updateBinHits(std::vector<boost::dynamic_bitset<>> & binHits,
unsigned layer, boost::dynamic_bitset<>
const &
b);
42 declareInterface<IFPGATrackSimRoadFinderTool>(
this);
64 return StatusCode::FAILURE;
70 ATH_MSG_FATAL(
"initialize() Hit extend must have size == nLayers");
71 return StatusCode::FAILURE;
82 for (
unsigned ilayer = 0; ilayer <
m_nLayers; ilayer++) {
91 ATH_MSG_WARNING(
"initialize() idealGeoRoads conflicts with useSectors, switching off FPGATrackSim sector matching");
96 ATH_MSG_WARNING(
"initialize() idealGeoRoads requires tracing hits, turning on automatically");
119 return StatusCode::SUCCESS;
134 float iterShift = (
sign>0) ? 0.0 : -1.0;
143 std::vector<int> shifts;
152 if (shift >=
static_cast<int>(
m_phiBins) || shift <= -(
static_cast<int>(
m_phiBins)))
return;
153 shifts.push_back(shift);
157 for (
const std::vector<int>& d0shift:
m_d0shifts){
162 m_qpt.push_back(qpt);
193 std::ifstream
fin(filepath);
197 throw (
"FPGATrackSimHough1DShiftTool::readShifts couldn't open " + filepath);
204 bool newsubr =
false;
205 bool headerdone =
false;
213 newsubr|=(
line.empty());
214 if (
line.empty() ||
line[0] ==
'#')
continue;
215 std::istringstream sline(
line);
218 ok = ok && (sline >>
towers);
221 throw (
"FPGATrackSimHough1DShiftTool::readShifts couldn't parse " + filepath);
224 ATH_MSG_INFO(
"FPGATrackSimHough1DShiftTool::readShifts " <<
nslices <<
"slices in shift file");
225 ok = ok && (sline >>
phi);
228 throw (
"FPGATrackSimHough1DShiftTool::readShifts couldn't parse " + filepath);
230 ok = ok && (sline >> nphi);
236 ok = ok && (sline >> subregion);
245 std::vector<int> shifts;
250 ok = ok && (sline >> shift);
252 shifts.push_back(shift);
255 if (shifts[0]<-1000) {
256 ATH_MSG_INFO(
"FPGATrackSimHough1DShiftTool::readShifts skipping line with shift out of range: " <<
line);
261 std::string droplist;
262 ok = ok && (sline >> droplist);
263 ok = ok && (droplist.size() ==
m_nLayers);
266 boost::dynamic_bitset<> drops(
m_nLayers);
268 if (droplist[
i] ==
'1')
273 ok = ok && (sline >> qpt);
278 std::vector<float> phivals;
282 ok = ok && (sline >> phival);
284 phivals.push_back(phival);
287 m_qpt.push_back(qpt);
299 throw "FPGATrackSimHough1DShiftTool::readShifts read error";
309 return StatusCode::SUCCESS;
329 for (
size_t iShift = 0; iShift <
m_shifts.size(); iShift++)
332 std::vector<boost::dynamic_bitset<>> binHits(
m_phiBins, boost::dynamic_bitset<>(
m_nLayers));
337 updateBinHits(binHits,
i, lshift(hitMasks[
i],
m_shifts[iShift][
i]));
355 ATH_MSG_DEBUG(
"New Road: "<< layersHit(
r) <<
" lyrs, " <<
r.getNHits() <<
" hits :"
356 << to_string(
r.getNHits_layer()) <<
" reg=" <<
r.getSubRegion()
357 <<
" bin=" <<
bin <<
" shift=" << iShift <<
" phi=" <<
r.getX() <<
" pti=" <<
r.getY() <<
" " <<
m_qpt[iShift]);
377 return StatusCode::SUCCESS;
399 for (
unsigned j = 0; j <
m_vetolist.size(); j++) {
420 std::vector<boost::dynamic_bitset<>> hitMasks(
m_nLayers, boost::dynamic_bitset<>(
m_phiBins));
421 for (
auto const &hit :
hits)
428 hitMasks[hit->getLayer()][
i] =
true;
437 std::vector<int>
const & shifts =
m_shifts[iShift];
438 float qpT =
m_qpt[iShift];
440 std::vector<std::shared_ptr<const FPGATrackSimHit>> road_hits;
443 for (
const auto & hit :
hits)
449 bins.first += shifts[hit->getLayer()];
450 bins.second += shifts[hit->getLayer()];
453 if (bin_track >=
bins.first && bin_track <=
bins.second)
455 road_hits.push_back(hit);
456 hitLayers |= 1 << hit->getLayer();
466 r.setHitLayers(hitLayers);
467 r.setHits(std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>>(sorted_hits));
470 int inner_bin =
static_cast<int>(bin_track)-
static_cast<int>(shifts[0]);
471 if ((inner_bin < 0) || (inner_bin >=
static_cast<int>(
m_phiBins))) {
477 r.setX(
phitrk(bin_track,shifts).first);
495 double qoverpt =
r.getY()*0.001;
497 qoverpt = std::abs(qoverpt);
504 auto bounds = std::equal_range(qoverpt_bins.begin(), qoverpt_bins.end(), qoverpt);
507 if (sectorbin < 0) sectorbin = 0;
508 if ((sectorbin / 10) >
static_cast<int>(qoverpt_bins.size() - 2))sectorbin = 10*(qoverpt_bins.size() - 2);
511 int subregion =
r.getSubRegion();
514 std::vector<module_t> modules;
515 for (
unsigned int il = 0;
il <
r.getNLayers();
il++) {
516 if (
r.getNHits_layer()[
il] == 0) {
517 modules.push_back(-1);
520 wc_layers |= (0x1 <<
il);
521 r.setWCLayers(wc_layers);
523 std::unique_ptr<FPGATrackSimHit> wcHit = std::make_unique<FPGATrackSimHit>();
527 std::vector<std::shared_ptr<const FPGATrackSimHit>> wcHits;
528 wcHits.push_back(std::move(wcHit));
529 r.setHits(
il,std::move(wcHits));
532 modules.push_back(sectorbin);
544 r.setSectorBin(sectorbin);
571 float r = hit->
getR();
577 center += (maxshift+minshift)/2.0;
578 bin_extend += std::abs((maxshift-minshift)/2.0);
582 int low =
std::max(
static_cast<int>(center - bin_extend),0);
583 int high =
std::min(
static_cast<int>(center + bin_extend),
static_cast<int>(
m_phiBins-1));
584 return { low, high };
600 float phi_track = phi1+ std::atan2(r2-r1*
std::cos(phi2-phi1),r1*
std::sin(phi2-phi1)) - TMath::Pi()/2.0;
607 int inner_bin =
static_cast<int>(
bin)-
static_cast<int>(shifts[0]);
608 int outer_bin =
static_cast<int>(
bin)-
static_cast<int>(shifts[
m_nLayers-1]);
609 if ((inner_bin < 0) || (inner_bin >=
static_cast<int>(
m_phiBins)))
return {-100000,
false};
610 if ((outer_bin < 0) || (outer_bin >=
static_cast<int>(
m_phiBins)))
return {-100000,
false};
611 float phi1 =
m_bins[inner_bin];
612 float phi2 =
m_bins[outer_bin];
614 return {phi_track,
true};
620 float dPhi = std::asin(fpgatracksim::A *
r *
qPt);
626 static inline std::string to_string(std::vector<size_t>
v)
628 std::ostringstream oss;
632 std::copy(
v.begin(),
v.end()-1, std::ostream_iterator<size_t>(oss,
", "));
640 static inline boost::dynamic_bitset<> lshift(boost::dynamic_bitset<>
const &
b,
int n)
642 if (
n < 0)
return rshift(
b, -
n);
646 static inline boost::dynamic_bitset<> rshift(boost::dynamic_bitset<>
const &
b,
int n)
648 if (
n < 0)
return lshift(
b, -
n);
650 boost::dynamic_bitset<>
out(
b >>
n);
653 for (
int i = 0;
i <
n;
i++)
654 out[
out.size() - 1 -
i] =
false;
659 static inline void updateBinHits(std::vector<boost::dynamic_bitset<>> & binHits,
unsigned layer, boost::dynamic_bitset<>
const &
b)
661 for (
size_t i = 0;
i <
b.size();
i++)
667 std::stringstream
ss;
668 ss <<
"Hit Masks:\n";
669 for (
auto const &
b : hitMasks)
672 for (
size_t i = 0;
i <
b.size();
i++)
686 TH2F h(
name.c_str(),
"Hough 1D Shift;phi;layer",
700 std::vector<boost::dynamic_bitset<>> shiftedMasks;
702 shiftedMasks.push_back(lshift(hitMasks[
layer], shifts[
layer]));
709 std::stringstream
ss;
714 ss <<
"q/pT=" << qpt <<
"; ";
729 std::vector<int> d0shift;
730 for (
unsigned lyr = 0; lyr <
m_nLayers; lyr++) {
731 float phi_for_d0step = d0step/
m_r[lyr];
733 d0shift.push_back(shift);
744 std::vector<int> retv;
750 for (
unsigned i = 0;
i <
base.size();
i++) {
759 for (
unsigned lyr = 0; lyr <
m_nLayers; lyr++) {
760 if (lyr !=droplayer) retv.push_back(shift[lyr]);
769 std::vector< std::set< std::vector<int> > > reducedShifts(
m_nLayers);
773 for (
size_t iShift = 0; iShift <
m_shifts.size(); iShift++)
775 boost::dynamic_bitset<> drops(
m_nLayers);
776 for (
unsigned droplayer =0; droplayer <
m_nLayers; droplayer++) {
779 drops.set(droplayer);
792 for (
unsigned i = 0;
i <
r.getNLayers();
i++) {
793 if (
r.getHitLayers() & (1<<
i))
cnt++;