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<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
373bool 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
409std::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
426FPGATrackSimRoad 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
490std::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
524float 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
531std::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
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
552static 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
566static 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
572static 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
585static 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
591void 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
608void 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",
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
624void 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(std::move(d0shift));
662 if (d0step>m_d0spread) break;
663 ++steps;
664 }
665 ATH_MSG_DEBUG("d0 Shifts Found = " << m_d0shifts.size());
666}
667
668std::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
682std::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]=std::move(drops);
710
711 }
712
713}
714
715
716static 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}
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)
virtual StatusCode getRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, std::vector< std::shared_ptr< const FPGATrackSimRoad > > &roads) override
std::vector< boost::dynamic_bitset<> > makeHitMasks(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits)
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