26 static inline int quant(
double min,
double max,
unsigned nSteps,
double val);
27 static inline double unquant(
double min,
double max,
unsigned nSteps,
int step);
29 static inline std::string
to_string(
const std::vector<T> &
v);
47 ATH_MSG_INFO(
"Convolution: " << to_string(
const_cast<std::vector<int>&
>(
m_conv.value())));
59 ATH_MSG_FATAL(
"initialize() Image size must be greater than 0");
65 ATH_MSG_FATAL(
"initialize() Hit extentsion list must have size % nLayers");
67 ATH_MSG_FATAL(
"initialize() Combine layers list must have size = nLayers");
71 ATH_MSG_FATAL(
"initialize() Bin scale list must have size = nLayers");
72 else if (std::any_of(
m_binScale.begin(),
m_binScale.end(), [&](
unsigned i){ return m_imageSize_y % i != 0; }))
73 ATH_MSG_FATAL(
"initialize() The imagesize is not divisible by scale");
76 if (!ok)
return StatusCode::FAILURE;
81 ATH_MSG_WARNING(
"initialize() localMaxWindowSize requires tracing hits, turning on automatically");
88 ATH_MSG_WARNING(
"initialize() idealGeoRoads conflicts with useSectors, switching off FPGATrackSim sector matching");
93 ATH_MSG_WARNING(
"initialize() idealGeoRoads requires tracing hits, turning on automatically");
145 m_HT_sel =
static_cast<int>(DBinPhi0_clean / DBinQApt_clean);
147 return StatusCode::SUCCESS;
163 std::vector<std::pair<unsigned, unsigned>> roadListXY;
164 std::unordered_set<std::shared_ptr<const FPGATrackSimHit>> merged_image;
174 roadListXY.push_back({
x,
y});
182 for (
const auto & roadXY : roadListXY){
183 ATH_MSG_DEBUG(
"roadList x : " << roadXY.first <<
", y : " << roadXY.second);
188 ATH_MSG_DEBUG(
"Trace hits is disabled. Road merge doesn't work with this state at the moment.");
192 for (
const auto & roadXY : roadListXY){
193 unsigned x = roadXY.first;
194 unsigned y = roadXY.second;
198 if(!roadListXY.empty()){
199 std::vector<std::pair<unsigned, unsigned>> mergedRoadListXY;
200 size_t roadCounter = 0;
212 while(!roadListXY.empty()){
213 mergedRoadListXY.push_back(roadListXY[0]);
214 roadListXY.erase(roadListXY.begin());
215 for(
size_t i = 0;
i < mergedRoadListXY.size();
i++){
216 for(
int j = 0; j < std::ssize(roadListXY); j++){
217 if(std::abs(
static_cast<int>(roadListXY[j].
first) -
static_cast<int>(mergedRoadListXY[
i].
first)) < 2 &&
218 std::abs(
static_cast<int>(roadListXY[j].
second) -
static_cast<int>(mergedRoadListXY[
i].
second)) < 2){
219 mergedRoadListXY.push_back(roadListXY[j]);
220 roadListXY.erase(roadListXY.begin() + j);
226 if (!mergedRoadListXY.empty()){
227 ATH_MSG_DEBUG( mergedRoadListXY.size() -1 <<
" roads are merged to road(" << mergedRoadListXY[0].first <<
"," << mergedRoadListXY[0].second <<
")");
229 for (
const auto & roadXY : mergedRoadListXY){
230 unsigned x = roadXY.first;
231 unsigned y = roadXY.second;
235 mergedRoadListXY.clear();
236 merged_image.clear();
239 ATH_MSG_DEBUG(
"There is/are " << roadCounter <<
" roads after road merge");
246 return StatusCode::SUCCESS;
253 for (
const auto& hit :
hits) {
259 switch (hit->getLayer()){
280 ATH_MSG_FATAL(
"Debug: something wrong! layer: " << hit->getLayer());
283 int phi_L_bin =
m_h_rfix.at(LUT_layer)->FindBin(hit->getGPhi());
285 if(MSB >= 64) MSB = 63;
286 for(
const auto& LUT_i:
m_LUT.at(LUT_layer).at(MSB)){
287 if(LUT_i.input_begin <= phi_L_bin && phi_L_bin <= LUT_i.input_end){
288 for(
const auto&
pos: LUT_i.output){
295 double r = hit->getR();
297 int input_bins_vector_size = 0;
306 std::vector<std::vector<int>> hitLineQAPtPhi0(input_bins_vector_size);
309 for (
const std::vector<int>& it_base : hitLineQAPtPhi0) {
310 if (it_base[0] != -1 && it_base[1] != -1) {
311 image(it_base[0] , it_base[1]).first++;
313 image(it_base[0] , it_base[1]).second.insert(hit);
321 for (
unsigned y_ = 0; y_ < new_size_y; y_++) {
322 unsigned y_bin_min =
scale * y_;
323 unsigned y_bin_max =
scale * (y_ + 1);
329 for (
unsigned y = y_bin_min;
y < y_bin_max;
y++){
351 if (layerImage(
y,
x).
first > 0)
395 if (
i == 0 && j == 0)
continue;
414 static inline int quant(
double min,
double max,
unsigned nSteps,
double val)
420 static inline double unquant(
double min,
double max,
unsigned nSteps,
int step)
425 template <
typename T>
426 static inline std::string
to_string(
const std::vector<T> &
v)
428 std::ostringstream oss;
432 std::copy(
v.begin(),
v.end()-1, std::ostream_iterator<T>(oss,
", "));
445 double r = hit->
getR();
446 double phi_hit = hit->
getGPhi();
448 x = asin(
r * fpgatracksim::A *
y -
d0 /
r) + phi_hit;
454 ATH_MSG_ERROR(
"yToX() not defined for the current m_par selection");
480 std::vector<int64_t> bins_x_new;
481 std::vector<int64_t> bins_y_new;
494 std::vector<int64_t> qApt_ht_array;
495 std::vector<int64_t> phi0_ht_array;
496 std::vector<int>
zeros = {-1, -1};
498 std::vector<std::vector<int>> hitLineQAPtPhi0;
503 for (
unsigned i = 0;
i < bins_along_phi0_sector;
i++) {
504 qApt_ht_array.push_back(0);
506 for (
unsigned i = 0;
i < bins_along_qApt_sector;
i++) {
507 phi0_ht_array.push_back(0);
510 int64_t phi_conv_offseted = 0;
511 int64_t Delta_qApt_after_first_sector = 0;
512 int64_t qApt_ht = -1;
513 int64_t phi0_ht = -1;
514 int64_t qApt_ht_pre = -1;
515 int64_t phi0_ht_pre = -1;
516 int64_t qApt_ht_sector = 0;
517 int64_t phi0_ht_sector = 0;
518 int64_t Delta_phi0_after_first_sector = 0;
520 std::vector<double> d_qApt_ht_array;
521 std::vector<double> d_phi0_ht_array;
523 for (
unsigned i = 0;
i < bins_along_phi0_sector;
i++) {
524 d_qApt_ht_array.push_back(0.0);
526 for (
unsigned i = 0;
i < bins_along_qApt_sector;
i++) {
527 d_phi0_ht_array.push_back(0.0);
530 double d_phi_conv_offseted = 0.0;
531 double d_qApt_ht_sector = 0.0;
532 double d_phi0_ht_sector = 0.0;
533 double d_one_over_r_by_const = 0.0;
534 double d_phi_conv_over_DBinQApt = 0.0;
535 double d_Delta_phi0_after_first_sector = 0.0;
538 double r = hit->
getR();
539 double phi_hit = hit->
getGPhi();
544 hitLineQAPtPhi0.push_back(
zeros);
555 for (
unsigned j = start_phi0_bins_first_sector; j < end_phi0_bins_first_sector; j++) {
557 int64_t
c2 = (
static_cast<int64_t
>(d_c1) -
static_cast<int64_t
>(d_phi_conv_over_DBinQApt)) *
static_cast<int64_t
>(d_one_over_r_by_const) /
m_one_r_const_twoexp_post_conv;
558 int64_t
c3 = (
static_cast<int64_t
>(d_c1) -
static_cast<int64_t
>(d_phi_conv_over_DBinQApt)) *
static_cast<int64_t
>(d_one_over_r_by_const);
561 double d_c3 = (d_c1 - d_phi_conv_over_DBinQApt) * d_one_over_r_by_const;
564 if (
static_cast<int64_t
>(d_c1) <=
static_cast<int64_t
>(d_phi_conv_over_DBinQApt)) {
570 d_qApt_ht_sector = d_c3;
571 qApt_ht_array[j - start_phi0_bins_first_sector] = qApt_ht_sector;
572 d_qApt_ht_array[j - start_phi0_bins_first_sector] = d_qApt_ht_sector;
574 if (
static_cast<int64_t
>(d_c1) <=
static_cast<int64_t
>(d_phi_conv_over_DBinQApt) && (d_c2 -
m_qApt_min_post_conv - d_c4) >= 0) {
575 qApt_ht = qApt_ht_pre;
577 if (
static_cast<int64_t
>(d_c1) >
static_cast<int64_t
>(d_phi_conv_over_DBinQApt) && 1 + (d_c2 -
m_qApt_min_post_conv - d_c4) >= 0) {
578 qApt_ht = qApt_ht_pre;
582 hitLineQAPtPhi0[j] = {
static_cast<int>(qApt_ht),
static_cast<int>(j)};
591 Delta_phi0_after_first_sector = d_c6 *
static_cast<int64_t
>(d_one_over_r_by_const);
593 d_Delta_phi0_after_first_sector =
static_cast<double>(d_c6) * d_one_over_r_by_const;
594 for (
unsigned psi = start_phi0_bins_first_sector; psi < end_phi0_bins_first_sector; psi++) {
599 if (-qApt_ht_array[psi - start_phi0_bins_first_sector] < Delta_phi0_after_first_sector) {
607 if (qApt_ht >= 0 && qApt_ht <=
m_imageSize_y -1 && (1 + d_c7 - d_c9) >= 0 && (0 + d_c7 - d_c9) >= 0 ) {
618 hitLineQAPtPhi0.push_back(
zeros);
628 for (
unsigned n = start_qApt_bins_first_sector;
n < end_qApt_bins_first_sector;
n++) {
633 phi0_ht_sector = phi_conv_offseted + r_bit *
d2;
634 phi0_ht_array[
n - start_qApt_bins_first_sector] = phi0_ht_sector;
636 d_phi0_ht_sector = d_phi_conv_offseted + r_bit *
static_cast<double>(
d2);
637 d_phi0_ht_array[
n - start_qApt_bins_first_sector] = d_phi0_ht_sector;
639 if (phi0_ht_sector >= 0) {
646 phi0_ht = phi0_ht_pre;
649 phi0_ht = phi0_ht_pre;
652 if (phi0_ht <= m_imageSize_x - 1 && phi0_ht >= 0){
653 hitLineQAPtPhi0[
n] = {
static_cast<int>(
n),
static_cast<int>(phi0_ht)};
660 Delta_qApt_after_first_sector = r_bit * d3;
661 for (
unsigned tsi = start_qApt_bins_first_sector; tsi < end_qApt_bins_first_sector; tsi++) {
662 phi0_ht = (phi0_ht_array[tsi - start_qApt_bins_first_sector] + Delta_qApt_after_first_sector) /
m_bitwise_qApt_conv;
663 double d_phi0_ht = (d_phi0_ht_array[tsi - start_qApt_bins_first_sector] + Delta_qApt_after_first_sector) /
m_bitwise_qApt_conv;
675 ATH_MSG_ERROR(
"lineGenLay() not defined for the current m_par selection");
679 return hitLineQAPtPhi0;
689 if (x_min > x_max)
std::swap(x_min, x_max);
703 if (x_bin_min < 0) x_bin_min = 0;
706 return { x_bin_min, x_bin_max };
731 r.setHits( std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>>(
hits));
741 r.setHitLayers(hitLayers);
750 for (
auto const & hit :
hits)
751 hitLayers |= 1 << hit->getLayer();
763 std::vector<std::shared_ptr<const FPGATrackSimHit>> road_hits;
765 for (
const auto & hit :
hits)
769 unsigned int y_bin_max = y_bin_min +
m_binScale[hit->getLayer()];
775 road_hits.push_back(hit);
776 hitLayers |= 1 << hit->getLayer();
788 const std::string filepath =
m_requirements.value() +
"requirement-" +
tag +
".root";
789 TFile*
fin = TFile::Open(filepath.c_str());
792 TTree* requirement =
fin->Get<TTree>(
"requirement");
794 for(
int i=0;
i<5;
i++){
795 v_LUT.at(
i).resize(64);
796 TH1D*
h = (TH1D*)
fin->Get(Form(
"in%d",
i));
799 int nrequirement = requirement->GetEntries();
805 requirement->SetBranchAddress(
"input_begin", &in_min);
806 requirement->SetBranchAddress(
"input_end", &in_max);
807 requirement->SetBranchAddress(
"output_x", &xi);
808 requirement->SetBranchAddress(
"output_y", &yi);
809 requirement->SetBranchAddress(
"output_l", &ri);
810 for(
int i=0;
i<nrequirement;
i++){
811 requirement->GetEntry(
i);
814 bool toBeFilled =
true;
815 if(!v_LUT.at(ri).at(MSB).empty()){
816 for(
auto& LUT_i : v_LUT.at(ri).at(MSB)){
817 if(LUT_i.input_begin == in_min && LUT_i.input_end == in_max){
818 LUT_i.output.push_back({xi, yi, ri});
829 LUT_i.
output.push_back({xi, yi, ri});
830 v_LUT.at(ri).at(MSB).push_back(LUT_i);
837 if(!v_LUT.at(ri).at(MSB).empty()){
838 for(
auto& LUT_i : v_LUT.at(ri).at(MSB)){
839 if(LUT_i.input_begin == in_min && LUT_i.input_end == in_max){
840 LUT_i.output.push_back({xi, yi, ri});
851 LUT_i.
output.push_back({xi, yi, ri});
852 v_LUT.at(ri).at(MSB).push_back(LUT_i);
856 int LUTsize = v_LUT.size();
858 for(
int msb = 0; msb < 64; msb++){