ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimHough1DShiftTool.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
9
22#include "TH2.h"
23
24#include <sstream>
25#include <cmath>
26#include <algorithm>
27#include <boost/dynamic_bitset.hpp>
28#include <iostream>
29
30static inline std::string to_string(std::vector<size_t> v);
31static inline boost::dynamic_bitset<> lshift(boost::dynamic_bitset<> const & b, int n);
32static inline boost::dynamic_bitset<> rshift(boost::dynamic_bitset<> const & b, int n);
33static inline void updateBinHits(std::vector<boost::dynamic_bitset<>> & binHits, unsigned layer, boost::dynamic_bitset<> const & b);
34static 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
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
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
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
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(std::move(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/
181void 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(std::move(shifts));
280 m_dropable.push_back(std::move(drops));
281 m_phivals.push_back(std::move(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
307StatusCode FPGATrackSimHough1DShiftTool::getRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, std::vector<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 = std::move(m_roads);
363
364 if (roads.size()==0 && m_drawHitMasks) drawHitMasks(hitMasks, m_name + "_fail_e" + std::to_string(m_event));
365
366 m_event++;
367 return StatusCode::SUCCESS;
368}
369
370
371
372bool FPGATrackSimHough1DShiftTool::passThreshold(std::vector<boost::dynamic_bitset<>>& binHits, int bin ) const
373{
374 // Check the threshold
375 if (binHits[bin].count() < m_threshold) return false;
376
377 // Apply neighbor veto
378 if (m_neighborWindow>0) {
379 for (int i = -m_neighborWindow; i <= m_neighborWindow; i++) {
380 if ((bin+i < 0) or ((bin+i)>=int(m_phiBins))) continue; // ignore edges
381 if (binHits[bin+i].count()>binHits[bin].count()) {
382 // neighbor has more layers
383 return false;
384 }
385 if (i!=0 && (binHits[bin+i].count()==binHits[bin].count())) {
386 // favor lower phi bin
387 return false;
388 }
389 for (unsigned j = 0; j < m_vetolist.size(); j++) {
390 if (m_vetolist[j][bin+i]>binHits[bin].count()) {
391 // past neighbor has more layers
392 return false;
393 }
394 if ((m_vetolist[j][bin+i]==binHits[bin].count()) and (i<0)) {
395 // favor previous shift and lower phi bin
396 return false;
397 }
398 }
399 }
400 }
401
402 return true; // passed threshold, wasn't vetoed by neighbors
403
404}
405
406
407
408std::vector<boost::dynamic_bitset<>> FPGATrackSimHough1DShiftTool::makeHitMasks(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits)
409{
410 std::vector<boost::dynamic_bitset<>> hitMasks(m_nLayers, boost::dynamic_bitset<>(m_phiBins));
411 for (auto const &hit : hits)
412 {
413 if (m_subRegion >= 0 && !m_FPGATrackSimMapping->SubRegionMap()->isInRegion(m_subRegion, *hit)) continue;
414
415 auto bins = getBins(hit);
416
417 for (int i = std::max(bins.first, 0); i <= std::min(bins.second, (int)m_phiBins - 1); i++)
418 hitMasks[hit->getLayer()][i] = true;
419 }
420
421 return hitMasks;
422}
423
424
425FPGATrackSimRoad FPGATrackSimHough1DShiftTool::makeRoad(const std::vector<std::shared_ptr<const FPGATrackSimHit>>& hits, int bin_track, size_t iShift)
426{
427 std::vector<int> const & shifts = m_shifts[iShift];
428 float qpT = m_qpt[iShift];
429
430 std::vector<std::shared_ptr<const FPGATrackSimHit>> road_hits;
431 layer_bitmask_t hitLayers = 0;
432
433 for (const auto & hit : hits)
434 {
435 if (m_subRegion >= 0 && !m_FPGATrackSimMapping->SubRegionMap()->isInRegion(m_subRegion, *hit)) continue;
436
437 // Get the shifted bins of the hit
438 auto bins = getBins(hit);
439 bins.first += shifts[hit->getLayer()]; // note boost::dynamic_bitset stores [0] as the LSB, i.e. rightmost. So leftshift = +bin
440 bins.second += shifts[hit->getLayer()];
441
442 // Check if it's the same bin as the track
443 if (bin_track >= bins.first && bin_track <= bins.second)
444 {
445 road_hits.push_back(hit);
446 hitLayers |= 1 << hit->getLayer();
447 }
448 }
449
450 auto sorted_hits = ::sortByLayer(road_hits);
451 sorted_hits.resize(m_nLayers); // If no hits in last layer, return from sortByLayer will be too short
452 // Combination of last two addRoad() functions from FPGATrackSimHoughTransformTool.cxx are implemented above (up to here)
453 // Below want to look at first addRoad()/matchIdealGeoSector() function in FPGATrackSimHoughTransformTool.cxx
454
456 r.setHitLayers(hitLayers);
457 r.setHits(std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>>(std::move(sorted_hits)));
458 r.setSubRegion(m_subRegion);
459 if (m_fieldCorrection) {
460 int inner_bin = static_cast<int>(bin_track)-static_cast<int>(shifts[0]);
461 if ((inner_bin < 0) || (inner_bin >= static_cast<int>(m_phiBins))) {
462 r.setX(-100000);
463 } else {
464 r.setX(m_bins[inner_bin] + 0.5*m_phiStep + deltaPhi(m_r[0],qpT));
465 }
466 } else {
467 r.setX(phitrk(bin_track,shifts).first); // will be a large negative number if invalid
468 }
469 r.setY(qpT);
470
471 return r;
472 // TODO sector, wildcard layers?
473}
474
475
477// Helpers
478
479// Given a relative shift between iterLayer and layer 0, returns the corresponding qpt.
480// This does a linear approximation of the Hough transform equation.
482{
483 if (m_iterLayer == 0u) ATH_MSG_FATAL("getPtFromShiftDiff() iterLayer can't be 0");
484 return (shift * m_phiStep / fpgatracksim::A) / (m_r[m_iterLayer] - m_r[0]);
485}
486
487
488// Returns the range of bins (inclusive) given a phi and an extension in number of bins
489std::pair<int, int> FPGATrackSimHough1DShiftTool::getBins(const std::shared_ptr<const FPGATrackSimHit>& hit) const
490{
491 float phi = hit->getGPhi();
492 float bin_extend = m_hitExtend[hit->getLayer()];
493 float center = (phi - m_phiMin) / m_phiStep;
494
495 if (m_variableExtend){
496 float r = hit->getR();
497 float dphimax = deltaPhi(r,m_qptMax);
498 float maxshift = +1*((std::sin(dphimax)*(r-m_r[hit->getLayer()]))/r)/m_phiStep;
499 float dphimin = deltaPhi(r,m_qptMin);
500 float minshift = +1*((std::sin(dphimin)*(r-m_r[hit->getLayer()]))/r)/m_phiStep;
501
502 center += (maxshift+minshift)/2.0;
503 bin_extend += std::abs((maxshift-minshift)/2.0);
504
505 }
506
507 int low = std::max(static_cast<int>(center - bin_extend),0);
508 int high = std::min(static_cast<int>(center + bin_extend),static_cast<int>(m_phiBins-1));
509 return { low, high };
510}
511
513{
514 if (m_useDiff) {
515 float r1=m_r[0];
516 float r2=r;
517 float sign = deltaPhi>0 ? 1 : -1;
518 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)));
519 }
520 return std::sin(deltaPhi) / (fpgatracksim::A * r);
521}
522
523float FPGATrackSimHough1DShiftTool::phitrkDiff(float r1, float phi1, float r2, float phi2) const
524{
525 float phi_track = phi1+ std::atan2(r2-r1*std::cos(phi2-phi1),r1*std::sin(phi2-phi1)) - TMath::Pi()/2.0;
526 return phi_track;
527}
528
529
530std::pair<float, bool> FPGATrackSimHough1DShiftTool::phitrk(int bin, std::vector<int> const & shifts ) const
531{
532 int inner_bin = static_cast<int>(bin)-static_cast<int>(shifts[0]);
533 int outer_bin = static_cast<int>(bin)-static_cast<int>(shifts[m_nLayers-1]);
534 if ((inner_bin < 0) || (inner_bin >= static_cast<int>(m_phiBins))) return {-100000,false};
535 if ((outer_bin < 0) || (outer_bin >= static_cast<int>(m_phiBins))) return {-100000,false};
536 float phi1 = m_bins[inner_bin];
537 float phi2 = m_bins[outer_bin];
538 float phi_track = phitrkDiff(m_r[0],phi1,m_r[m_nLayers-1],phi2)+0.5*m_phiStep;
539 return {phi_track,true};
540}
541
542
544{
545 float dPhi = std::asin(fpgatracksim::A * r * qPt);
546 if (m_fieldCorrection) dPhi += fieldCorrection(m_EvtSel->getRegionID(), qPt, r);
547 return dPhi;
548}
549
550
551static inline std::string to_string(std::vector<size_t> v)
552{
553 std::ostringstream oss;
554 oss << "[";
555 if (!v.empty())
556 {
557 std::copy(v.begin(), v.end()-1, std::ostream_iterator<size_t>(oss, ", "));
558 oss << v.back();
559 }
560 oss << "]";
561 return oss.str();
562}
563
564
565static inline boost::dynamic_bitset<> lshift(boost::dynamic_bitset<> const & b, int n)
566{
567 if (n < 0) return rshift(b, -n);
568 return b << n;
569}
570
571static inline boost::dynamic_bitset<> rshift(boost::dynamic_bitset<> const & b, int n)
572{
573 if (n < 0) return lshift(b, -n);
574
575 boost::dynamic_bitset<> out(b >> n);
576
577 // Force 0-padding
578 for (int i = 0; i < n; i++)
579 out[out.size() - 1 - i] = false;
580
581 return out;
582}
583
584static inline void updateBinHits(std::vector<boost::dynamic_bitset<>> & binHits, unsigned layer, boost::dynamic_bitset<> const & b)
585{
586 for (size_t i = 0; i < b.size(); i++)
587 if (b[i]) binHits[i].set(layer);
588}
589
590void FPGATrackSimHough1DShiftTool::printHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks) const
591{
592 std::stringstream ss;
593 ss << "Hit Masks:\n";
594 for (auto const & b : hitMasks)
595 {
596 ss << "\t";
597 for (size_t i = 0; i < b.size(); i++)
598 {
599 if (b[i]) ss << 1;
600 else ss << ".";
601 }
602 ss << "\n";
603 }
604 ATH_MSG_DEBUG(ss.str() << "\n\n");
605}
606
607void FPGATrackSimHough1DShiftTool::drawHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks, std::string const & name)
608{
609 m_monitorFile.cd();
610
611 TH2F h(name.c_str(), "Hough 1D Shift;phi;layer",
614 );
615
616 for (size_t layer = 0; layer < m_nLayers; layer++)
617 for (size_t i = 0; i < m_phiBins; i++)
618 h.SetBinContent(i+1, layer+1, hitMasks[layer][i]); // +1 since root bins are 1-indexed
619
620 h.Write();
621}
622
623void FPGATrackSimHough1DShiftTool::drawHitMasks(std::vector<boost::dynamic_bitset<>> const & hitMasks, std::string const & name, std::vector<int> const & shifts)
624{
625 std::vector<boost::dynamic_bitset<>> shiftedMasks;
626 for (size_t layer = 0; layer < m_nLayers; layer++)
627 shiftedMasks.push_back(lshift(hitMasks[layer], shifts[layer]));
628
629 drawHitMasks(shiftedMasks, name);
630}
631
633{
634 std::stringstream ss;
635 ss << "Shifts:\n";
636 for (size_t i = 0; i < m_shifts.size(); i++)
637 {
638 float qpt = qPt(m_r[m_iterLayer], m_phiStep * m_shifts[i][m_iterLayer]); // q/pT represented by this shift
639 ss << "q/pT=" << qpt << "; ";
640 for (int shift : m_shifts[i]) ss << shift << " ";
641 if (!m_dropable.empty()) ss << m_dropable[i];
642 ss << "\n";
643 }
644 ATH_MSG_VERBOSE(ss.str());
645}
646
647
649{
650 int steps=1;
651 while (true) {
652 float d0step = steps*m_phiStep*m_r[0];
653 ATH_MSG_DEBUG("d0step = " << d0step);
654 std::vector<int> d0shift;
655 for (unsigned lyr = 0; lyr < m_nLayers; lyr++) {
656 float phi_for_d0step = d0step/m_r[lyr];
657 int shift = static_cast<int>(round(phi_for_d0step/ m_phiStep));
658 d0shift.push_back(shift);
659 }
660 m_d0shifts.push_back(std::move(d0shift));
661 if (d0step>m_d0spread) break;
662 ++steps;
663 }
664 ATH_MSG_DEBUG("d0 Shifts Found = " << m_d0shifts.size());
665}
666
667std::vector<int> FPGATrackSimHough1DShiftTool::applyVariation(const std::vector<int>& base, const std::vector<int>& var, int sign) const
668{
669 std::vector<int> retv;
670
671 if (base.size()!=var.size()) {
672 ATH_MSG_ERROR("Base and Var lengths must match " << base.size() << " " << var.size() );
673 }
674
675 for (unsigned i = 0; i < base.size(); i++) {
676 retv.push_back(base[i]+sign*var[i]);
677 }
678 return retv;
679}
680
681std::vector<int> FPGATrackSimHough1DShiftTool::shiftWithDrop(std::vector<int>& shift,unsigned droplayer) const
682{
683 std::vector<int> retv(m_nLayers-1);
684 for (unsigned lyr = 0; lyr < m_nLayers; lyr++) {
685 if (lyr !=droplayer) retv.push_back(shift[lyr]);
686 }
687 return retv;
688}
689
691{
692
693 // one set per layer with shift set
694 std::vector< std::set< std::vector<int> > > reducedShifts(m_nLayers);
695
696 m_dropable.resize(m_shifts.size());
697
698 for (size_t iShift = 0; iShift < m_shifts.size(); iShift++)
699 {
700 boost::dynamic_bitset<> drops(m_nLayers);
701 for (unsigned droplayer =0; droplayer < m_nLayers; droplayer++) {
702 if (reducedShifts[droplayer].insert(shiftWithDrop(m_shifts[iShift],droplayer)).second) {
703 // true if the is a new shift in the set
704 drops.set(droplayer);
705 }
706 }
707
708 m_dropable[iShift]=std::move(drops);
709
710 }
711
712}
713
714
715static inline int layersHit(FPGATrackSimRoad& r) {
716 int cnt =0;
717 for (unsigned i = 0; i < r.getNLayers(); i++) {
718 if (r.getHitLayers() & (1<<i)) cnt++;
719 }
720 return cnt;
721}
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double fieldCorrection(unsigned region, double qoverpt, double r)
static std::string to_string(const std::vector< T > &v)
: FPGATrackSim-specific class to represent an hit in the detector.
std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit > > > sortByLayer(Container const &hits)
static std::string to_string(std::vector< size_t > v)
static boost::dynamic_bitset lshift(boost::dynamic_bitset<> const &b, int n)
static boost::dynamic_bitset rshift(boost::dynamic_bitset<> const &b, int n)
static int layersHit(FPGATrackSimRoad &r)
static void updateBinHits(std::vector< boost::dynamic_bitset<> > &binHits, unsigned layer, boost::dynamic_bitset<> const &b)
Implements road finding using Elliot's simplified Hough transform.
Implements road finding using a Hough transform.
Maps physical layers to logical layers.
Maps ITK module indices to FPGATrackSim regions.
Stores slice definitions for FPGATrackSim regions.
This file declares a class that stores the module IDs of the sectors.
uint32_t layer_bitmask_t
static Double_t ss
static const std::vector< std::string > bins
int sign(int a)
Header file for AthHistogramAlgorithm.
std::vector< FPGATrackSimRoad > m_roads
std::vector< int > applyVariation(const std::vector< int > &base, const std::vector< int > &var, int sign) const
std::vector< std::vector< int > > m_d0shifts
std::deque< std::vector< unsigned > > m_vetolist
Gaudi::Property< unsigned > m_threshold
std::pair< int, int > getBins(const std::shared_ptr< const FPGATrackSimHit > &hit) const
FPGATrackSimRoad makeRoad(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, int bin_track, size_t iShift)
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
void readShifts(std::string const &filepath)
Gaudi::Property< std::vector< float > > m_hitExtendProperty
std::vector< boost::dynamic_bitset<> > m_dropable
Gaudi::Property< unsigned > m_historyWindow
void drawHitMasks(std::vector< boost::dynamic_bitset<> > const &hitMasks, std::string const &name)
std::vector< boost::dynamic_bitset<> > makeHitMasks(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits)
virtual StatusCode getRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, std::vector< FPGATrackSimRoad > &roads) override
std::vector< std::vector< float > > m_phivals
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
bool passThreshold(std::vector< boost::dynamic_bitset<> > &binHits, int bin) const
std::vector< int > shiftWithDrop(std::vector< int > &shift, unsigned droplayer) const
void printHitMasks(std::vector< boost::dynamic_bitset<> > const &hitMasks) const
std::pair< float, bool > phitrk(int bin, std::vector< int > const &shifts) const
virtual StatusCode initialize() override
Gaudi::Property< unsigned > m_iterLayer
std::vector< std::vector< int > > m_shifts
float deltaPhi(float r, float qPt) const
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
float phitrkDiff(float r1, float phi1, float r2, float phi2) const
float qPt(float r, float deltaPhi) const
Gaudi::Property< std::string > m_bitShift_path
int r
Definition globals.cxx:22
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
std::string base
Definition hcg.cxx:81
static constexpr double A