Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FPGATrackSimHough1DShiftTool.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
22 #include "TH2.h"
23 
24 #include <sstream>
25 #include <cmath>
26 #include <algorithm>
27 #include <boost/dynamic_bitset.hpp>
28 #include <iostream>
29 
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);
34 static inline int layersHit(FPGATrackSimRoad& r);
35 
36 
38 {
39  // Config printout
40  ATH_MSG_INFO("Phi range: (" << m_phiMin << "," << m_phiMax << "," << m_phiBins << ")");
41  if (m_useDiff) ATH_MSG_INFO("useDiff Set True");
42  if (m_variableExtend) ATH_MSG_INFO("variableExtend Set True");
43  ATH_MSG_INFO("enhancedHighPt " << m_enhanceHighPt.value());
44  ATH_MSG_INFO("applyDropable " << m_applyDropable.value());
45  ATH_MSG_INFO("threshold " << m_threshold.value());
46 
47  // Retrieve info
49  ATH_CHECK(m_FPGATrackSimMapping.retrieve());
50  m_nLayers = m_FPGATrackSimMapping->PlaneMap_1st(0)->getNLogiLayers();
51 
52  // Error checking
53  if (m_phiMin >= m_phiMax || m_phiBins == 0u) {
54  ATH_MSG_FATAL("initialize() Phi range invalid");
55  return StatusCode::FAILURE;
56  }
57 
58  // Fix inputs
59  if (!m_hitExtendProperty.value().empty()) {
60  if (m_hitExtendProperty.value().size() != m_nLayers) {
61  ATH_MSG_FATAL("initialize() Hit extend must have size == nLayers");
62  return StatusCode::FAILURE;
63  } else {
65  }
66  } else {
67  m_hitExtend.resize(m_nLayers,0); // all 0
68  }
69  if (m_iterStep == 0u) m_iterStep = m_hitExtend[m_iterLayer] * 2 + 1; // default 1
70 
71  // Copy correct r values from the region map.
72  m_r.resize(m_nLayers);
73  for (unsigned ilayer = 0; ilayer < m_nLayers; ilayer++) {
74  m_r[ilayer] = m_FPGATrackSimMapping->SubRegionMap()->getAvgRadius(m_subRegion, ilayer);
75  }
76 
77  // Warnings / corrections
78  if (m_idealGeoRoads)
79  {
80  if (m_useSectors)
81  {
82  ATH_MSG_WARNING("initialize() idealGeoRoads conflicts with useSectors, switching off FPGATrackSim sector matching");
83  m_useSectors = false;
84  }
85  if (!m_traceHits)
86  {
87  ATH_MSG_WARNING("initialize() idealGeoRoads requires tracing hits, turning on automatically");
88  m_traceHits = true;
89  }
90  }
91 
92  // Fill convenience variables
94  for (unsigned i = 0; i <= m_phiBins; i++)
95  m_bins.push_back(m_phiMin + m_phiStep * i);
96  m_regionMin = m_EvtSel->getRegions()->getMin(m_EvtSel->getRegionID());
97  m_regionMax = m_EvtSel->getRegions()->getMax(m_EvtSel->getRegionID());
98 
99  m_regionMin.phi = m_regionMin.phi - 0.01; // For phi boundary effect
100  m_regionMax.phi = m_regionMax.phi + 0.01; // For phi boundary effect
101 
102  m_currentcounts.resize(m_phiBins);
103 
104  // Calculate the shift amounts
105  if (m_bitShift_path.value().empty()) calculateShifts();
107  printShifts();
108 
109 
110  return StatusCode::SUCCESS;
111 }
112 
113 
114 // Fills m_shifts
116 {
117  // Calculated d0shift if selected
118  if (m_d0spread>0) calculated0Shifts();
119 
120 
121  // Iterate over a steps of m_iterStep bin shift in m_iterLayer
122  for (int sign = -1; sign<2; sign+=2) {
123 
124  // start at highest pT
125  float iterShift = (sign>0) ? 0.0 : -1.0; // don't double count zero
126 
127  while (true)
128  {
129  float qpt = qPt(m_r[m_iterLayer], m_phiStep * iterShift);
130  if (abs(qpt)>std::max(abs(m_qptMin),abs(m_qptMax))) break;
131 
132  if ((qpt <= m_qptMax ) && (qpt >= m_qptMin )) {
133 
134  std::vector<int> shifts; // Fill both +iterShift and -iterShift here
135  for (unsigned i = 0; i < m_nLayers; i++)
136  {
137  float dPhi = deltaPhi(m_r[i], qpt);
138  if (m_useDiff){
139  dPhi -= deltaPhi(m_r[0], qpt);
140  }
141 
142  int shift = static_cast<int>(round(dPhi / m_phiStep));
143  if (shift >= static_cast<int>(m_phiBins) || shift <= -(static_cast<int>(m_phiBins))) return;
144  shifts.push_back(shift);
145  }
146 
147  // if thre are d0shifts, apply them
148  for (const std::vector<int>& d0shift: m_d0shifts){
149  m_shifts.push_back(applyVariation(shifts,d0shift,1));
150  m_shifts.push_back(applyVariation(shifts,d0shift,-1));
151  }
152 
153  m_qpt.push_back(qpt);
154  m_shifts.push_back(shifts);
155 
156  }
157 
158  // smaller steps if in "enhanceHighPt" range
159  iterShift += ((std::abs(qpt)>m_enhanceHighPt) ? sign*float(m_iterStep): sign*float(m_iterStep)/2.0) ;
160  }
161  ATH_MSG_INFO("Ending shift, qpt("<< m_qptMin << ", " << m_qptMax <<") sign:" << sign << " shift:" << iterShift);
162 
163 
164  // figure out which patterns are the same after dropping a hit
166  }
167 
168 }
169 
170 
171 // Fills m_shifts
172 //
173 // This reads a bitshift pattern file, which is a simple space-separated text file
174 // where each row respresents one shift set / pattern. Each row contains
175 // (nLayers - 1) columns representing the shifts in layers [1, nLayers)
176 // (implicit 0 shift in layer 0), followed by a column that is a 'droplist'.
177 // The droplist is a string of 0s and 1s indicating which layers can be dropped
178 // for 4/5 matching, i.e (layer 0 is right-most bit).
179 //
180 // See /eos/atlas/atlascerngroupdisk/det-htt/sectors_constants/BitShiftHoughPatterns/2021-02-20/
181 void FPGATrackSimHough1DShiftTool::readShifts(std::string const & filepath)
182 {
183  // Open the file
184  std::ifstream fin(filepath);
185  if (!fin.is_open())
186  {
187  ATH_MSG_FATAL("Couldn't open " << filepath);
188  throw ("FPGATrackSimHough1DShiftTool::readShifts couldn't open " + filepath);
189  }
190 
191  // Variables to fill
192  std::string line;
193  bool ok = true;
194  int subregion = -1;
195  bool newsubr = false;
196  bool headerdone = false;
197  int nslices = 0;
198  int nphi=0;
199 
200 
201  // Parse the file
202  while (getline(fin, line))
203  {
204  newsubr|=(line.empty());
205  if (line.empty() || line[0] == '#') continue;
206  std::istringstream sline(line);
207  if (!headerdone) {
208  std::string towers, phi;
209  ok = ok && (sline >> towers);
210  if (towers!="towers") {
211  ATH_MSG_FATAL("Parse Error expected 'towers' got "<< towers);
212  throw ("FPGATrackSimHough1DShiftTool::readShifts couldn't parse " + filepath);
213  }
214  ok = ok && (sline >> nslices);
215  ATH_MSG_INFO("FPGATrackSimHough1DShiftTool::readShifts " << nslices << "slices in shift file");
216  ok = ok && (sline >> phi);
217  if (phi!="phi") {
218  ATH_MSG_FATAL("Parse Error expected 'phi' got "<< phi);
219  throw ("FPGATrackSimHough1DShiftTool::readShifts couldn't parse " + filepath);
220  }
221  ok = ok && (sline >> nphi);
222  headerdone=true;
223  continue;
224  }
225 
226  if (newsubr) {
227  ok = ok && (sline >> subregion);
228  ATH_MSG_INFO("FPGATrackSimHough1DShiftTool::readShifts " << subregion << " looking for " << m_subRegion);
229  newsubr=false;
230  continue;
231  }
232 
233  if (subregion==m_subRegion) {
234  ATH_MSG_INFO("FPGATrackSimHough1DShiftTool::readShifts found subregion " << m_subRegion);
235  // Shifts
236  std::vector<int> shifts;
237  shifts.push_back(0); // layer 0 is implicit 0 TODO
238  for (unsigned layer = 1; layer < m_nLayers; layer++)
239  {
240  int shift = 0;
241  ok = ok && (sline >> shift);
242  if (!ok) break;
243  shifts.push_back(shift);
244  }
245  if (!ok) break;
246  if (shifts[0]<-1000) {
247  ATH_MSG_INFO("FPGATrackSimHough1DShiftTool::readShifts skipping line with shift out of range: " << line);
248  continue;
249  }
250 
251  // Dropable
252  std::string droplist;
253  ok = ok && (sline >> droplist);
254  ok = ok && (droplist.size() == m_nLayers);
255  if (!ok) break;
256 
257  boost::dynamic_bitset<> drops(m_nLayers);
258  for (unsigned i = 0; i < m_nLayers; i++)
259  if (droplist[i] == '1')
260  drops[m_nLayers - i - 1] = true; // Droplist is printed with MSB on left
261 
262  // qpT
263  float qpt = 0;
264  ok = ok && (sline >> qpt);
265  if (!ok) break;
266  if ((qpt<m_qptMin) or (qpt>m_qptMax)) continue;
267 
268  // Phi Vals
269  std::vector<float> phivals;
270  for (unsigned layer = 0; layer < m_nLayers; layer++)
271  {
272  float phival = 0;
273  ok = ok && (sline >> phival);
274  if (!ok) break;
275  phivals.push_back(phival);
276  }
277 
278  m_qpt.push_back(qpt);
279  m_shifts.push_back(shifts);
280  m_dropable.push_back(drops);
281  m_phivals.push_back(phivals);
282 
283 
284  }
285  }
286 
287  if (!ok)
288  {
289  ATH_MSG_FATAL("Found error reading file at line: " << line);
290  throw "FPGATrackSimHough1DShiftTool::readShifts read error";
291  }
292 
293  if (m_shifts.size()==0) ATH_MSG_FATAL("FPGATrackSimHough1DShiftTool::readShifts no shifts read");
294  ATH_MSG_INFO("Read " << m_shifts.size() << " patterns from " << filepath);
295 }
296 
297 
299 {
300  return StatusCode::SUCCESS;
301 }
302 
303 
305 // Main Algorithm
306 
307 StatusCode FPGATrackSimHough1DShiftTool::getRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads)
308 {
309 
310  roads.clear();
311  m_roads.clear();
312 
313  ATH_MSG_DEBUG("Input Hits Size:" << hits.size() << "\n");
314 
315  // Get hit masks
316  std::vector<boost::dynamic_bitset<>> hitMasks(makeHitMasks(hits));
317  if (m_drawHitMasks) drawHitMasks(hitMasks, m_name + "_e" + std::to_string(m_event));
318 
319  // Iterate over shifts
320  for (size_t iShift = 0; iShift < m_shifts.size(); iShift++)
321  {
322  // Track hit layers in each bin
323  std::vector<boost::dynamic_bitset<>> binHits(m_phiBins, boost::dynamic_bitset<>(m_nLayers));
324 
325 
326  // Add the counts
327  for (unsigned i = 0; i < m_nLayers; i++)
328  updateBinHits(binHits, i, lshift(hitMasks[i], m_shifts[iShift][i]));
329 
330  // Check the threshold
331  for (unsigned bin = 0; bin < m_phiBins; bin++)
332  {
333  // First check we're not missing hits in not allowed layers
334  if (m_applyDropable && !m_dropable.empty() && (~(binHits[bin] | m_dropable[iShift])).any()) continue;
335 
336  m_currentcounts[bin]=binHits[bin].count();
337 
338  if (passThreshold(binHits,bin))
339  {
340  FPGATrackSimRoad r = makeRoad(hits, bin, iShift);
341 
342  if (m_phiRangeCut && (r.getX() > m_regionMax.phi || r.getX() < m_regionMin.phi)) continue;
343 
344  m_roads.push_back(r);
345 
346  ATH_MSG_DEBUG("New Road: "<< layersHit(r) <<" lyrs, " << r.getNHits() << " hits :"
347  << to_string(r.getNHits_layer()) << " reg=" << r.getSubRegion()
348  << " bin=" << bin << " shift=" << iShift << " phi=" << r.getX() << " pti=" << r.getY() << " " << m_qpt[iShift]);
349 
350 
351  }
352 
353  }
354 
355  // Add/Remove history
356  m_vetolist.push_front(m_currentcounts);
357  if (m_vetolist.size() > m_historyWindow) {
358  m_vetolist.pop_back();
359  }
360  }
361 
362  roads.reserve(m_roads.size());
363  for (FPGATrackSimRoad & r : m_roads) roads.emplace_back(std::make_shared<const FPGATrackSimRoad>(r));
364 
365  if (roads.size()==0 && m_drawHitMasks) drawHitMasks(hitMasks, m_name + "_fail_e" + std::to_string(m_event));
366 
367  m_event++;
368  return StatusCode::SUCCESS;
369 }
370 
371 
372 
373 bool FPGATrackSimHough1DShiftTool::passThreshold(std::vector<boost::dynamic_bitset<>>& binHits, int bin ) const
374 {
375  // Check the threshold
376  if (binHits[bin].count() < m_threshold) return false;
377 
378  // Apply neighbor veto
379  if (m_neighborWindow>0) {
380  for (int i = -m_neighborWindow; i <= m_neighborWindow; i++) {
381  if ((bin+i < 0) or ((bin+i)>=int(m_phiBins))) continue; // ignore edges
382  if (binHits[bin+i].count()>binHits[bin].count()) {
383  // neighbor has more layers
384  return false;
385  }
386  if (i!=0 && (binHits[bin+i].count()==binHits[bin].count())) {
387  // favor lower phi bin
388  return false;
389  }
390  for (unsigned j = 0; j < m_vetolist.size(); j++) {
391  if (m_vetolist[j][bin+i]>binHits[bin].count()) {
392  // past neighbor has more layers
393  return false;
394  }
395  if ((m_vetolist[j][bin+i]==binHits[bin].count()) and (i<0)) {
396  // favor previous shift and lower phi bin
397  return false;
398  }
399  }
400  }
401  }
402 
403  return true; // passed threshold, wasn't vetoed by neighbors
404 
405 }
406 
407 
408 
409 std::vector<boost::dynamic_bitset<>> FPGATrackSimHough1DShiftTool::makeHitMasks(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits)
410 {
411  std::vector<boost::dynamic_bitset<>> hitMasks(m_nLayers, boost::dynamic_bitset<>(m_phiBins));
412  for (auto const &hit : hits)
413  {
414  if (m_subRegion >= 0 && !m_FPGATrackSimMapping->SubRegionMap()->isInRegion(m_subRegion, *hit)) continue;
415 
416  auto bins = getBins(hit);
417 
418  for (int i = std::max(bins.first, 0); i <= std::min(bins.second, (int)m_phiBins - 1); i++)
419  hitMasks[hit->getLayer()][i] = true;
420  }
421 
422  return hitMasks;
423 }
424 
425 
426 FPGATrackSimRoad FPGATrackSimHough1DShiftTool::makeRoad(const std::vector<std::shared_ptr<const FPGATrackSimHit>>& hits, int bin_track, size_t iShift)
427 {
428  std::vector<int> const & shifts = m_shifts[iShift];
429  float qpT = m_qpt[iShift];
430 
431  std::vector<std::shared_ptr<const FPGATrackSimHit>> road_hits;
432  layer_bitmask_t hitLayers = 0;
433 
434  for (const auto & hit : hits)
435  {
436  if (m_subRegion >= 0 && !m_FPGATrackSimMapping->SubRegionMap()->isInRegion(m_subRegion, *hit)) continue;
437 
438  // Get the shifted bins of the hit
439  auto bins = getBins(hit);
440  bins.first += shifts[hit->getLayer()]; // note boost::dynamic_bitset stores [0] as the LSB, i.e. rightmost. So leftshift = +bin
441  bins.second += shifts[hit->getLayer()];
442 
443  // Check if it's the same bin as the track
444  if (bin_track >= bins.first && bin_track <= bins.second)
445  {
446  road_hits.push_back(hit);
447  hitLayers |= 1 << hit->getLayer();
448  }
449  }
450 
451  auto sorted_hits = ::sortByLayer(road_hits);
452  sorted_hits.resize(m_nLayers); // If no hits in last layer, return from sortByLayer will be too short
453  // Combination of last two addRoad() functions from FPGATrackSimHoughTransformTool.cxx are implemented above (up to here)
454  // Below want to look at first addRoad()/matchIdealGeoSector() function in FPGATrackSimHoughTransformTool.cxx
455 
457  r.setHitLayers(hitLayers);
458  r.setHits(std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>>(std::move(sorted_hits)));
459  r.setSubRegion(m_subRegion);
460  if (m_fieldCorrection) {
461  int inner_bin = static_cast<int>(bin_track)-static_cast<int>(shifts[0]);
462  if ((inner_bin < 0) || (inner_bin >= static_cast<int>(m_phiBins))) {
463  r.setX(-100000);
464  } else {
465  r.setX(m_bins[inner_bin] + 0.5*m_phiStep + deltaPhi(m_r[0],qpT));
466  }
467  } else {
468  r.setX(phitrk(bin_track,shifts).first); // will be a large negative number if invalid
469  }
470  r.setY(qpT);
471 
472  return r;
473  // TODO sector, wildcard layers?
474 }
475 
476 
478 // Helpers
479 
480 // Given a relative shift between iterLayer and layer 0, returns the corresponding qpt.
481 // This does a linear approximation of the Hough transform equation.
483 {
484  if (m_iterLayer == 0u) ATH_MSG_FATAL("getPtFromShiftDiff() iterLayer can't be 0");
485  return (shift * m_phiStep / fpgatracksim::A) / (m_r[m_iterLayer] - m_r[0]);
486 }
487 
488 
489 // Returns the range of bins (inclusive) given a phi and an extension in number of bins
490 std::pair<int, int> FPGATrackSimHough1DShiftTool::getBins(const std::shared_ptr<const FPGATrackSimHit>& hit) const
491 {
492  float phi = hit->getGPhi();
493  float bin_extend = m_hitExtend[hit->getLayer()];
494  float center = (phi - m_phiMin) / m_phiStep;
495 
496  if (m_variableExtend){
497  float r = hit->getR();
498  float dphimax = deltaPhi(r,m_qptMax);
499  float maxshift = +1*((std::sin(dphimax)*(r-m_r[hit->getLayer()]))/r)/m_phiStep;
500  float dphimin = deltaPhi(r,m_qptMin);
501  float minshift = +1*((std::sin(dphimin)*(r-m_r[hit->getLayer()]))/r)/m_phiStep;
502 
503  center += (maxshift+minshift)/2.0;
504  bin_extend += std::abs((maxshift-minshift)/2.0);
505 
506  }
507 
508  int low = std::max(static_cast<int>(center - bin_extend),0);
509  int high = std::min(static_cast<int>(center + bin_extend),static_cast<int>(m_phiBins-1));
510  return { low, high };
511 }
512 
514 {
515  if (m_useDiff) {
516  float r1=m_r[0];
517  float r2=r;
518  float sign = deltaPhi>0 ? 1 : -1;
519  return sign*1/(2*fpgatracksim::A) * std::sqrt((4*std::sin(deltaPhi)*std::sin(deltaPhi))/( r1*r1 + r2*r2 -2*r2*r1*std::cos(deltaPhi)));
520  }
521  return std::sin(deltaPhi) / (fpgatracksim::A * r);
522 }
523 
524 float FPGATrackSimHough1DShiftTool::phitrkDiff(float r1, float phi1, float r2, float phi2) const
525 {
526  float phi_track = phi1+ std::atan2(r2-r1*std::cos(phi2-phi1),r1*std::sin(phi2-phi1)) - TMath::Pi()/2.0;
527  return phi_track;
528 }
529 
530 
531 std::pair<float, bool> FPGATrackSimHough1DShiftTool::phitrk(int bin, std::vector<int> const & shifts ) const
532 {
533  int inner_bin = static_cast<int>(bin)-static_cast<int>(shifts[0]);
534  int outer_bin = static_cast<int>(bin)-static_cast<int>(shifts[m_nLayers-1]);
535  if ((inner_bin < 0) || (inner_bin >= static_cast<int>(m_phiBins))) return {-100000,false};
536  if ((outer_bin < 0) || (outer_bin >= static_cast<int>(m_phiBins))) return {-100000,false};
537  float phi1 = m_bins[inner_bin];
538  float phi2 = m_bins[outer_bin];
539  float phi_track = phitrkDiff(m_r[0],phi1,m_r[m_nLayers-1],phi2)+0.5*m_phiStep;
540  return {phi_track,true};
541 }
542 
543 
544 float FPGATrackSimHough1DShiftTool::deltaPhi(float r, float qPt) const
545 {
546  float dPhi = std::asin(fpgatracksim::A * r * qPt);
547  if (m_fieldCorrection) dPhi += fieldCorrection(m_EvtSel->getRegionID(), qPt, r);
548  return dPhi;
549 }
550 
551 
552 static inline std::string to_string(std::vector<size_t> v)
553 {
554  std::ostringstream oss;
555  oss << "[";
556  if (!v.empty())
557  {
558  std::copy(v.begin(), v.end()-1, std::ostream_iterator<size_t>(oss, ", "));
559  oss << v.back();
560  }
561  oss << "]";
562  return oss.str();
563 }
564 
565 
566 static inline boost::dynamic_bitset<> lshift(boost::dynamic_bitset<> const & b, int n)
567 {
568  if (n < 0) return rshift(b, -n);
569  return b << n;
570 }
571 
572 static inline boost::dynamic_bitset<> rshift(boost::dynamic_bitset<> const & b, int n)
573 {
574  if (n < 0) return lshift(b, -n);
575 
576  boost::dynamic_bitset<> out(b >> n);
577 
578  // Force 0-padding
579  for (int i = 0; i < n; i++)
580  out[out.size() - 1 - i] = false;
581 
582  return out;
583 }
584 
585 static inline void updateBinHits(std::vector<boost::dynamic_bitset<>> & binHits, unsigned layer, boost::dynamic_bitset<> const & b)
586 {
587  for (size_t i = 0; i < b.size(); i++)
588  if (b[i]) binHits[i].set(layer);
589 }
590 
591 void FPGATrackSimHough1DShiftTool::printHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks) const
592 {
593  std::stringstream ss;
594  ss << "Hit Masks:\n";
595  for (auto const & b : hitMasks)
596  {
597  ss << "\t";
598  for (size_t i = 0; i < b.size(); i++)
599  {
600  if (b[i]) ss << 1;
601  else ss << ".";
602  }
603  ss << "\n";
604  }
605  ATH_MSG_DEBUG(ss.str() << "\n\n");
606 }
607 
608 void FPGATrackSimHough1DShiftTool::drawHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks, std::string const & name)
609 {
610  m_monitorFile.cd();
611 
612  TH2F h(name.c_str(), "Hough 1D Shift;phi;layer",
614  m_nLayers, 0, m_nLayers
615  );
616 
617  for (size_t layer = 0; layer < m_nLayers; layer++)
618  for (size_t i = 0; i < m_phiBins; i++)
619  h.SetBinContent(i+1, layer+1, hitMasks[layer][i]); // +1 since root bins are 1-indexed
620 
621  h.Write();
622 }
623 
624 void FPGATrackSimHough1DShiftTool::drawHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks, std::string const & name, std::vector<int> const & shifts)
625 {
626  std::vector<boost::dynamic_bitset<>> shiftedMasks;
627  for (size_t layer = 0; layer < m_nLayers; layer++)
628  shiftedMasks.push_back(lshift(hitMasks[layer], shifts[layer]));
629 
630  drawHitMasks(shiftedMasks, name);
631 }
632 
634 {
635  std::stringstream ss;
636  ss << "Shifts:\n";
637  for (size_t i = 0; i < m_shifts.size(); i++)
638  {
639  float qpt = qPt(m_r[m_iterLayer], m_phiStep * m_shifts[i][m_iterLayer]); // q/pT represented by this shift
640  ss << "q/pT=" << qpt << "; ";
641  for (int shift : m_shifts[i]) ss << shift << " ";
642  if (!m_dropable.empty()) ss << m_dropable[i];
643  ss << "\n";
644  }
645  ATH_MSG_VERBOSE(ss.str());
646 }
647 
648 
650 {
651  int steps=1;
652  while (true) {
653  float d0step = steps*m_phiStep*m_r[0];
654  ATH_MSG_DEBUG("d0step = " << d0step);
655  std::vector<int> d0shift;
656  for (unsigned lyr = 0; lyr < m_nLayers; lyr++) {
657  float phi_for_d0step = d0step/m_r[lyr];
658  int shift = static_cast<int>(round(phi_for_d0step/ m_phiStep));
659  d0shift.push_back(shift);
660  }
661  m_d0shifts.push_back(d0shift);
662  if (d0step>m_d0spread) break;
663  ++steps;
664  }
665  ATH_MSG_DEBUG("d0 Shifts Found = " << m_d0shifts.size());
666 }
667 
668 std::vector<int> FPGATrackSimHough1DShiftTool::applyVariation(const std::vector<int>& base, const std::vector<int>& var, int sign) const
669 {
670  std::vector<int> retv;
671 
672  if (base.size()!=var.size()) {
673  ATH_MSG_ERROR("Base and Var lengths must match " << base.size() << " " << var.size() );
674  }
675 
676  for (unsigned i = 0; i < base.size(); i++) {
677  retv.push_back(base[i]+sign*var[i]);
678  }
679  return retv;
680 }
681 
682 std::vector<int> FPGATrackSimHough1DShiftTool::shiftWithDrop(std::vector<int>& shift,unsigned droplayer) const
683 {
684  std::vector<int> retv(m_nLayers-1);
685  for (unsigned lyr = 0; lyr < m_nLayers; lyr++) {
686  if (lyr !=droplayer) retv.push_back(shift[lyr]);
687  }
688  return retv;
689 }
690 
692 {
693 
694  // one set per layer with shift set
695  std::vector< std::set< std::vector<int> > > reducedShifts(m_nLayers);
696 
697  m_dropable.resize(m_shifts.size());
698 
699  for (size_t iShift = 0; iShift < m_shifts.size(); iShift++)
700  {
701  boost::dynamic_bitset<> drops(m_nLayers);
702  for (unsigned droplayer =0; droplayer < m_nLayers; droplayer++) {
703  if (reducedShifts[droplayer].insert(shiftWithDrop(m_shifts[iShift],droplayer)).second) {
704  // true if the is a new shift in the set
705  drops.set(droplayer);
706  }
707  }
708 
709  m_dropable[iShift]=drops;
710 
711  }
712 
713 }
714 
715 
716 static inline int layersHit(FPGATrackSimRoad& r) {
717  int cnt =0;
718  for (unsigned i = 0; i < r.getNLayers(); i++) {
719  if (r.getHitLayers() & (1<<i)) cnt++;
720  }
721  return cnt;
722 }
FPGATrackSimHough1DShiftTool::printHitMasks
void printHitMasks(std::vector< boost::dynamic_bitset<>> const &hitMasks) const
Definition: FPGATrackSimHough1DShiftTool.cxx:591
FPGATrackSimHough1DShiftTool::deltaPhi
float deltaPhi(float r, float qPt) const
Definition: FPGATrackSimHough1DShiftTool.cxx:544
base
std::string base
Definition: hcg.cxx:78
FPGATrackSimHough1DShiftTool::m_traceHits
Gaudi::Property< bool > m_traceHits
Definition: FPGATrackSimHough1DShiftTool.h:109
beamspotman.r
def r
Definition: beamspotman.py:676
FPGATrackSimHough1DShiftTool::calculated0Shifts
void calculated0Shifts()
Definition: FPGATrackSimHough1DShiftTool.cxx:649
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
FPGATrackSimHough1DShiftTool::m_fieldCorrection
Gaudi::Property< bool > m_fieldCorrection
Definition: FPGATrackSimHough1DShiftTool.h:139
FPGATrackSimHough1DShiftTool::makeRoad
FPGATrackSimRoad makeRoad(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, int bin_track, size_t iShift)
Definition: FPGATrackSimHough1DShiftTool.cxx:426
module_driven_slicing.nslices
nslices
Definition: module_driven_slicing.py:575
FPGATrackSimTrackPars::phi
double phi
Definition: FPGATrackSimTrackPars.h:24
FPGATrackSimRegionSlices.h
Stores slice definitions for FPGATrackSim regions.
FPGATrackSimHough1DShiftTool::m_regionMax
FPGATrackSimTrackPars m_regionMax
Definition: FPGATrackSimHough1DShiftTool.h:157
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
collListGuids.line
string line
Definition: collListGuids.py:77
FPGATrackSimPlaneMap.h
Maps physical layers to logical layers.
FPGATrackSimHough1DShiftTool::m_phiStep
float m_phiStep
Definition: FPGATrackSimHough1DShiftTool.h:151
FPGATrackSimHough1DShiftTool::calculateShifts
void calculateShifts()
Definition: FPGATrackSimHough1DShiftTool.cxx:115
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
FPGATrackSimHough1DShiftTool::m_threshold
Gaudi::Property< unsigned > m_threshold
Definition: FPGATrackSimHough1DShiftTool.h:125
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
FPGATrackSimHough1DShiftTool::phitrk
std::pair< float, bool > phitrk(int bin, std::vector< int > const &shifts) const
Definition: FPGATrackSimHough1DShiftTool.cxx:531
FPGATrackSimHough1DShiftTool::m_qpt
std::vector< float > m_qpt
Definition: FPGATrackSimHough1DShiftTool.h:163
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
IFPGATrackSimMappingSvc.h
FPGATrackSimHoughTransformTool.h
Implements road finding using a Hough transform.
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
FPGATrackSimHough1DShiftTool::m_regionMin
FPGATrackSimTrackPars m_regionMin
Definition: FPGATrackSimHough1DShiftTool.h:156
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
FPGATrackSimHough1DShiftTool::m_phiMax
Gaudi::Property< float > m_phiMax
Definition: FPGATrackSimHough1DShiftTool.h:120
bin
Definition: BinsDiffFromStripMedian.h:43
FPGATrackSimHough1DShiftTool::m_phiRangeCut
Gaudi::Property< bool > m_phiRangeCut
Definition: FPGATrackSimHough1DShiftTool.h:131
FPGATrackSimHough1DShiftTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimHough1DShiftTool.h:104
FPGATrackSimHit::getLayer
int getLayer() const
Definition: FPGATrackSimHit.cxx:87
FPGATrackSimHough1DShiftTool::m_vetolist
std::deque< std::vector< unsigned > > m_vetolist
Definition: FPGATrackSimHough1DShiftTool.h:167
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
FPGATrackSimHough1DShiftTool.h
Implements road finding using Elliot's simplified Hough transform.
FPGATrackSimHough1DShiftTool::m_subRegion
Gaudi::Property< int > m_subRegion
Definition: FPGATrackSimHough1DShiftTool.h:118
FPGATrackSimHough1DShiftTool::m_bins
std::vector< double > m_bins
Definition: FPGATrackSimHough1DShiftTool.h:152
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
FPGATrackSimHough1DShiftTool::m_applyDropable
Gaudi::Property< bool > m_applyDropable
Definition: FPGATrackSimHough1DShiftTool.h:136
FPGATrackSimConstants.h
FPGATrackSimHough1DShiftTool::m_currentcounts
std::vector< unsigned > m_currentcounts
Definition: FPGATrackSimHough1DShiftTool.h:166
FPGATrackSimHough1DShiftTool::shiftWithDrop
std::vector< int > shiftWithDrop(std::vector< int > &shift, unsigned droplayer) const
Definition: FPGATrackSimHough1DShiftTool.cxx:682
FPGATrackSimHough1DShiftTool::m_event
unsigned m_event
Definition: FPGATrackSimHough1DShiftTool.h:178
FPGATrackSimHough1DShiftTool::m_neighborWindow
Gaudi::Property< int > m_neighborWindow
Definition: FPGATrackSimHough1DShiftTool.h:137
FPGATrackSimHit::getGPhi
float getGPhi() const
Definition: FPGATrackSimHit.h:144
FPGATrackSimRegionMap.h
Maps ITK module indices to FPGATrackSim regions.
FPGATrackSimHough1DShiftTool::m_dropable
std::vector< boost::dynamic_bitset<> > m_dropable
Definition: FPGATrackSimHough1DShiftTool.h:160
FPGATrackSimHough1DShiftTool::drawHitMasks
void drawHitMasks(std::vector< boost::dynamic_bitset<>> const &hitMasks, std::string const &name)
Definition: FPGATrackSimHough1DShiftTool.cxx:608
FPGATrackSimHough1DShiftTool::finalize
virtual StatusCode finalize() override
Definition: FPGATrackSimHough1DShiftTool.cxx:298
beamspotman.steps
int steps
Definition: beamspotman.py:505
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FPGATrackSimHough1DShiftTool::m_variableExtend
Gaudi::Property< bool > m_variableExtend
Definition: FPGATrackSimHough1DShiftTool.h:130
FPGATrackSimHough1DShiftTool::m_shifts
std::vector< std::vector< int > > m_shifts
Definition: FPGATrackSimHough1DShiftTool.h:159
FPGATrackSimHough1DShiftTool::m_useSectors
Gaudi::Property< bool > m_useSectors
Definition: FPGATrackSimHough1DShiftTool.h:113
FPGATrackSimHough1DShiftTool::qPt
float qPt(float r, float deltaPhi) const
Definition: FPGATrackSimHough1DShiftTool.cxx:513
FPGATrackSimHough1DShiftTool::m_d0spread
Gaudi::Property< float > m_d0spread
Definition: FPGATrackSimHough1DShiftTool.h:133
lumiFormat.i
int i
Definition: lumiFormat.py:85
FPGATrackSimHough1DShiftTool::m_hitExtendProperty
Gaudi::Property< std::vector< float > > m_hitExtendProperty
Definition: FPGATrackSimHough1DShiftTool.h:134
beamspotman.n
n
Definition: beamspotman.py:731
FPGATrackSimHough1DShiftTool::m_historyWindow
Gaudi::Property< unsigned > m_historyWindow
Definition: FPGATrackSimHough1DShiftTool.h:138
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
extractSporadic.h
list h
Definition: extractSporadic.py:97
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:548
FPGATrackSimHough1DShiftTool::m_useDiff
Gaudi::Property< bool > m_useDiff
Definition: FPGATrackSimHough1DShiftTool.h:129
FPGATrackSimHough1DShiftTool::m_idealGeoRoads
Gaudi::Property< bool > m_idealGeoRoads
Definition: FPGATrackSimHough1DShiftTool.h:114
fieldCorrection
double fieldCorrection(unsigned region, double qpt, double r)
Definition: FPGATrackSimFunctions.cxx:163
FPGATrackSimHough1DShiftTool::m_qptMin
Gaudi::Property< float > m_qptMin
Definition: FPGATrackSimHough1DShiftTool.h:121
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:107
FPGATrackSimHough1DShiftTool::phitrkDiff
float phitrkDiff(float r1, float phi1, float r2, float phi2) const
Definition: FPGATrackSimHough1DShiftTool.cxx:524
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FPGATrackSimHough1DShiftTool::readShifts
void readShifts(std::string const &filepath)
Definition: FPGATrackSimHough1DShiftTool.cxx:181
FPGATrackSimHough1DShiftTool::m_qptMax
Gaudi::Property< float > m_qptMax
Definition: FPGATrackSimHough1DShiftTool.h:122
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
FPGATrackSimHough1DShiftTool::getRoads
virtual StatusCode getRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, std::vector< std::shared_ptr< const FPGATrackSimRoad >> &roads) override
Definition: FPGATrackSimHough1DShiftTool.cxx:307
FPGATrackSimHough1DShiftTool::m_bitShift_path
Gaudi::Property< std::string > m_bitShift_path
Definition: FPGATrackSimHough1DShiftTool.h:135
FPGATrackSimHough1DShiftTool::m_iterLayer
Gaudi::Property< unsigned > m_iterLayer
Definition: FPGATrackSimHough1DShiftTool.h:127
FPGATrackSimHough1DShiftTool::m_EvtSel
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
Definition: FPGATrackSimHough1DShiftTool.h:102
FPGATrackSimHough1DShiftTool::m_drawHitMasks
Gaudi::Property< bool > m_drawHitMasks
Definition: FPGATrackSimHough1DShiftTool.h:116
FPGATrackSimHough1DShiftTool::m_phivals
std::vector< std::vector< float > > m_phivals
Definition: FPGATrackSimHough1DShiftTool.h:164
FPGATrackSimHough1DShiftTool::m_monitorFile
TFile m_monitorFile
Definition: FPGATrackSimHough1DShiftTool.h:180
FPGATrackSimHough1DShiftTool::calculateDropable
void calculateDropable()
Definition: FPGATrackSimHough1DShiftTool.cxx:691
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
FPGATrackSimHit.h
: FPGATrackSim-specific class to represent an hit in the detector.
FPGATrackSimHough1DShiftTool::m_r
std::vector< float > m_r
Definition: FPGATrackSimHough1DShiftTool.h:144
FPGATrackSimHough1DShiftTool::getBins
std::pair< int, int > getBins(const std::shared_ptr< const FPGATrackSimHit > &hit) const
Definition: FPGATrackSimHough1DShiftTool.cxx:490
python.PyAthena.v
v
Definition: PyAthena.py:154
FPGATrackSimHough1DShiftTool::getPtFromShiftDiff
float getPtFromShiftDiff(int shift) const
Definition: FPGATrackSimHough1DShiftTool.cxx:482
FPGATrackSimHit::getR
float getR() const
Definition: FPGATrackSimHit.h:143
h
IFPGATrackSimEventSelectionSvc.h
RunTileMonitoring.towers
towers
Definition: RunTileMonitoring.py:133
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
FPGATrackSimHough1DShiftTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimHough1DShiftTool.cxx:37
layer_bitmask_t
uint32_t layer_bitmask_t
Definition: FPGATrackSimTypes.h:22
FPGATrackSimHough1DShiftTool::m_iterStep
Gaudi::Property< unsigned > m_iterStep
Definition: FPGATrackSimHough1DShiftTool.h:126
IFPGATrackSimBankSvc.h
FPGATrackSimHough1DShiftTool::m_roads
std::vector< FPGATrackSimRoad > m_roads
Definition: FPGATrackSimHough1DShiftTool.h:173
compute_lumi.fin
fin
Definition: compute_lumi.py:19
FPGATrackSimHough1DShiftTool::m_nLayers
unsigned m_nLayers
Definition: FPGATrackSimHough1DShiftTool.h:149
FPGATrackSimHough1DShiftTool::printShifts
void printShifts() const
Definition: FPGATrackSimHough1DShiftTool.cxx:633
FPGATrackSimHough1DShiftTool::m_phiBins
Gaudi::Property< unsigned > m_phiBins
Definition: FPGATrackSimHough1DShiftTool.h:124
calibdata.copy
bool copy
Definition: calibdata.py:27
FPGATrackSimHough1DShiftTool::applyVariation
std::vector< int > applyVariation(const std::vector< int > &base, const std::vector< int > &var, int sign) const
Definition: FPGATrackSimHough1DShiftTool.cxx:668
FPGATrackSimHough1DShiftTool::m_d0shifts
std::vector< std::vector< int > > m_d0shifts
Definition: FPGATrackSimHough1DShiftTool.h:165
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
FPGATrackSimHough1DShiftTool::passThreshold
bool passThreshold(std::vector< boost::dynamic_bitset<>> &binHits, int bin) const
Definition: FPGATrackSimHough1DShiftTool.cxx:373
FPGATrackSimTypes.h
FPGATrackSimHough1DShiftTool::m_phiMin
Gaudi::Property< float > m_phiMin
Definition: FPGATrackSimHough1DShiftTool.h:119
FPGATrackSimHough1DShiftTool::m_enhanceHighPt
Gaudi::Property< float > m_enhanceHighPt
Definition: FPGATrackSimHough1DShiftTool.h:140
FPGATrackSimHough1DShiftTool::m_hitExtend
std::vector< float > m_hitExtend
Definition: FPGATrackSimHough1DShiftTool.h:143
FPGATrackSimSectorBank.h
This file declares a class that stores the module IDs of the sectors.
FPGATrackSimRoad
Definition: FPGATrackSimRoad.h:31
FPGATrackSimHough1DShiftTool::makeHitMasks
std::vector< boost::dynamic_bitset<> > makeHitMasks(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits)
Definition: FPGATrackSimHough1DShiftTool.cxx:409
FPGATrackSimHough1DShiftTool::m_name
std::string m_name
Definition: FPGATrackSimHough1DShiftTool.h:179
FPGATrackSimHough1DShiftTool::m_FPGATrackSimBankSvc
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
Definition: FPGATrackSimHough1DShiftTool.h:103
sortByLayer
std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit > > > sortByLayer(Container const &hits)
Definition: FPGATrackSimHit.h:300
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65