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>>>(std::move(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);
506 float r = hit->
getR();
512 center += (maxshift+minshift)/2.0;
513 bin_extend += std::abs((maxshift-minshift)/2.0);
517 int low =
std::max(
static_cast<int>(center - bin_extend),0);
518 int high =
std::min(
static_cast<int>(center + bin_extend),
static_cast<int>(
m_phiBins-1));
519 return { low, high };
535 float phi_track = phi1+ std::atan2(r2-r1*
std::cos(phi2-phi1),r1*
std::sin(phi2-phi1)) - TMath::Pi()/2.0;
542 int inner_bin =
static_cast<int>(
bin)-
static_cast<int>(shifts[0]);
543 int outer_bin =
static_cast<int>(
bin)-
static_cast<int>(shifts[
m_nLayers-1]);
544 if ((inner_bin < 0) || (inner_bin >=
static_cast<int>(
m_phiBins)))
return {-100000,
false};
545 if ((outer_bin < 0) || (outer_bin >=
static_cast<int>(
m_phiBins)))
return {-100000,
false};
546 float phi1 =
m_bins[inner_bin];
547 float phi2 =
m_bins[outer_bin];
549 return {phi_track,
true};
555 float dPhi = std::asin(fpgatracksim::A *
r *
qPt);
561 static inline std::string to_string(std::vector<size_t>
v)
563 std::ostringstream oss;
567 std::copy(
v.begin(),
v.end()-1, std::ostream_iterator<size_t>(oss,
", "));
575 static inline boost::dynamic_bitset<> lshift(boost::dynamic_bitset<>
const &
b,
int n)
577 if (
n < 0)
return rshift(
b, -
n);
581 static inline boost::dynamic_bitset<> rshift(boost::dynamic_bitset<>
const &
b,
int n)
583 if (
n < 0)
return lshift(
b, -
n);
585 boost::dynamic_bitset<>
out(
b >>
n);
588 for (
int i = 0;
i <
n;
i++)
589 out[
out.size() - 1 -
i] =
false;
594 static inline void updateBinHits(std::vector<boost::dynamic_bitset<>> & binHits,
unsigned layer, boost::dynamic_bitset<>
const &
b)
596 for (
size_t i = 0;
i <
b.size();
i++)
602 std::stringstream
ss;
603 ss <<
"Hit Masks:\n";
604 for (
auto const &
b : hitMasks)
607 for (
size_t i = 0;
i <
b.size();
i++)
621 TH2F h(
name.c_str(),
"Hough 1D Shift;phi;layer",
635 std::vector<boost::dynamic_bitset<>> shiftedMasks;
637 shiftedMasks.push_back(lshift(hitMasks[
layer], shifts[
layer]));
644 std::stringstream
ss;
649 ss <<
"q/pT=" << qpt <<
"; ";
664 std::vector<int> d0shift;
665 for (
unsigned lyr = 0; lyr <
m_nLayers; lyr++) {
666 float phi_for_d0step = d0step/
m_r[lyr];
668 d0shift.push_back(shift);
679 std::vector<int> retv;
685 for (
unsigned i = 0;
i <
base.size();
i++) {
694 for (
unsigned lyr = 0; lyr <
m_nLayers; lyr++) {
695 if (lyr !=droplayer) retv.push_back(shift[lyr]);
704 std::vector< std::set< std::vector<int> > > reducedShifts(
m_nLayers);
708 for (
size_t iShift = 0; iShift <
m_shifts.size(); iShift++)
710 boost::dynamic_bitset<> drops(
m_nLayers);
711 for (
unsigned droplayer =0; droplayer <
m_nLayers; droplayer++) {
714 drops.set(droplayer);
727 for (
unsigned i = 0;
i <
r.getNLayers();
i++) {
728 if (
r.getHitLayers() & (1<<
i))
cnt++;