ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimEtaPatternFilterTool Class Reference

#include <FPGATrackSimEtaPatternFilterTool.h>

Inheritance diagram for FPGATrackSimEtaPatternFilterTool:
Collaboration diagram for FPGATrackSimEtaPatternFilterTool:

Classes

struct  ModuleId
struct  ModulesToPattern

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual StatusCode filterRoads (std::vector< std::shared_ptr< const FPGATrackSimRoad > > &prefilter_roads, std::vector< std::shared_ptr< const FPGATrackSimRoad > > &postfilter_roads) override

Private Types

typedef std::vector< ModuleIdEtaPattern

Private Member Functions

void readPatterns (std::string const &filepath)
void buildMap ()
void resetCounters ()
void addHitsToMap (const std::shared_ptr< const FPGATrackSimRoad > &r)
void addRedundantPatterns (std::set< EtaPattern > &usedPatterns, EtaPattern const &currPatt, unsigned nExtra)
FPGATrackSimRoad buildRoad (std::pair< EtaPattern, layer_bitmask_t > const &patt, std::shared_ptr< const FPGATrackSimRoad > origr, int etaPatternID) const
std::string to_string (const EtaPattern &patt) const
std::string to_string (const FPGATrackSimRoad &road) const
std::string to_string (const std::vector< unsigned > &v) const

Private Attributes

ServiceHandle< IFPGATrackSimMappingSvcm_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"}
ServiceHandle< IFPGATrackSimBankSvcm_FPGATrackSimBankSvc {this, "FPGATrackSimBankSvc", "FPGATrackSimBankSvc"}
Gaudi::Property< std::string > m_pattern_file_path {this, "EtaPatterns", "", "path to pattern file"}
Gaudi::Property< unsigned > m_threshold {this, "threshold", 0, "Minimum number of hit layers to fire a road"}
Gaudi::Property< bool > m_isSecondStage {this, "isSecondStage", false, "Whether or not his this a second stage HT"}
Gaudi::Property< bool > m_doEtaPatternConsts {this, "doEtaPatternConsts", false, "Use eta pattern IDs as part of sector definition"}
Gaudi::Property< bool > m_dynamicThreshold { this, "dynamicThreshold", false, "Stop lowering the threshold once matches have been found"}
std::vector< FPGATrackSimRoadm_postfilter_roads
unsigned m_nLayers {}
std::map< EtaPattern, layer_bitmask_tm_patternmap
std::vector< std::map< ModuleId, ModulesToPattern > > m_moduleHits

Friends

bool operator< (const ModuleId &lhs, const ModuleId &rhs)

Detailed Description

Definition at line 35 of file FPGATrackSimEtaPatternFilterTool.h.

Member Typedef Documentation

◆ EtaPattern

Definition at line 75 of file FPGATrackSimEtaPatternFilterTool.h.

Member Function Documentation

◆ addHitsToMap()

void FPGATrackSimEtaPatternFilterTool::addHitsToMap ( const std::shared_ptr< const FPGATrackSimRoad > & r)
private

Definition at line 204 of file FPGATrackSimEtaPatternFilterTool.cxx.

205{
206 for (unsigned lyr = 0; lyr < m_nLayers; lyr++)
207 for (auto & hit : r->getHits(lyr))
208 if (hit->getHitType() != HitType::wildcard)
209 {
210 ModuleId mod = { hit->getDetType(), hit->getDetectorZone(), (int)(hit->getEtaModule()) };
211 auto itr = m_moduleHits[lyr].find(mod);
212 if (itr != m_moduleHits[lyr].end()) {
213 ATH_MSG_VERBOSE("Adding hit to map");
214 itr->second.addHit(hit);
215 } else {
216 // If this is an outermost spacepoint this is, technically, okay, provided
217 // we're only out of bounds byt a single etamod-- could check that.
218 if (!((hit->getHitType() == HitType::spacepoint) && (hit->getSide() == 1))) {
219 ATH_MSG_ERROR("Module not in map: " << hit->getDetType() << " " << hit->getDetectorZone() << " " << static_cast<int>(hit->getEtaModule()) << " type: " << hit->getHitType() << " layer: " << lyr);
220 for (auto & itr2 : m_moduleHits[lyr])
221 {
222 ATH_MSG_ERROR(" " << itr2.first.siTech << " " << itr2.first.zone << " " << itr2.first.etaModule);
223 }
224 }
225 }
226 }
227}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
std::vector< std::map< ModuleId, ModulesToPattern > > m_moduleHits
int r
Definition globals.cxx:22

◆ addRedundantPatterns()

void FPGATrackSimEtaPatternFilterTool::addRedundantPatterns ( std::set< EtaPattern > & usedPatterns,
EtaPattern const & currPatt,
unsigned nExtra )
private

Definition at line 231 of file FPGATrackSimEtaPatternFilterTool.cxx.

232{
233 usedPatterns.insert(currPatt);
234
235 std::vector<unsigned> allowmissing(nExtra, 0);
236 bool done = false;
237 while (!done)
238 {
239 EtaPattern subpatt(currPatt);
240 for (auto h : allowmissing)
241 subpatt[h] = {};
242 usedPatterns.insert(std::move(subpatt));
243
244 // increment allowmissing with rollover
245 done = (nExtra == 0);
246 for (unsigned i = 0; i < nExtra; i++)
247 {
248 allowmissing[i]++;
249 if (allowmissing[i] == m_nLayers)
250 {
251 allowmissing[i] = 0;
252 done = (i==nExtra-1); // incremented last counter so were done
253 }
254 else
255 {
256 break;
257 }
258 }
259 }
260}

◆ buildMap()

void FPGATrackSimEtaPatternFilterTool::buildMap ( )
private

Definition at line 103 of file FPGATrackSimEtaPatternFilterTool.cxx.

104{
105 ATH_MSG_DEBUG("Building Map ");
106 m_moduleHits.resize(m_nLayers);
107
108 for (auto & entry : m_patternmap)
109 {
110 EtaPattern const & patt = entry.first;
111 layer_bitmask_t & counter = entry.second;
112 for (unsigned lyr = 0; lyr < m_nLayers; lyr++)
113 m_moduleHits[lyr][patt[lyr]].addPattern(&counter);
114 }
115
116 ATH_MSG_DEBUG("Done Building Map ");
117}
#define ATH_MSG_DEBUG(x)
uint32_t layer_bitmask_t
std::map< EtaPattern, layer_bitmask_t > m_patternmap

◆ buildRoad()

FPGATrackSimRoad FPGATrackSimEtaPatternFilterTool::buildRoad ( std::pair< EtaPattern, layer_bitmask_t > const & patt,
std::shared_ptr< const FPGATrackSimRoad > origr,
int etaPatternID ) const
private

Definition at line 262 of file FPGATrackSimEtaPatternFilterTool.cxx.

263{
264 // All roads are now Hough roads.
265 FPGATrackSimRoad r(*origr);
266
267 r.setHitLayers(patt.second);
268 r.setEtaPatternID(etaPatternID);
269 for (unsigned lyr = 0; lyr < m_nLayers; lyr++) {
270 r.setHits(lyr,
271 //copy vector
272 std::vector<std::shared_ptr<const FPGATrackSimHit> >(
273 m_moduleHits[lyr].find(patt.first[lyr])->second.getHits()));
274 if (r.getNHits_layer().at(lyr) == 0) {
275 std::shared_ptr<FPGATrackSimHit> wcHit = std::make_shared<FPGATrackSimHit>();
276 wcHit->setHitType(HitType::wildcard);
277 wcHit->setDetType(m_FPGATrackSimMapping->PlaneMap_1st(0)->getDetType(lyr));
278 wcHit->setLayer(lyr);
279 r.setHits(lyr, std::vector<std::shared_ptr<const FPGATrackSimHit>>{wcHit});
280 }
281 }
282
283 // Here, if told to do so, we'll reset the road's sector using the eta pattern ID.
284 // Perhaps this should also be AND'ed with the "match ideal geometry" setting?
285 // This code is adapted from FPGATrackSimHoughTransformTool::matchIdealGeoSectors, which perhaps
286 // calls for moving this into the road class itself.
288 int sectorbin = fpgatracksim::ETA_SECTOR_OFFSET*etaPatternID + r.getSectorBin();
289 r.setSectorBin(sectorbin);
290 std::vector<module_t> modules;
291 for (unsigned int il = 0; il < r.getNLayers(); il++) {
292 if (r.getNHits_layer()[il] == 0) {
293 modules.push_back(-1);
294 } else {
295 modules.push_back(sectorbin);
296 }
297 }
298 const FPGATrackSimSectorBank* sectorbank = !m_isSecondStage ? m_FPGATrackSimBankSvc->SectorBank_1st() : m_FPGATrackSimBankSvc->SectorBank_2nd();
299 r.setSector(sectorbank->findSector(modules));
300 }
301 return r;
302}
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
sector_t findSector(std::vector< module_t > const &modules) const
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
constexpr int ETA_SECTOR_OFFSET

◆ filterRoads()

StatusCode FPGATrackSimEtaPatternFilterTool::filterRoads ( std::vector< std::shared_ptr< const FPGATrackSimRoad > > & prefilter_roads,
std::vector< std::shared_ptr< const FPGATrackSimRoad > > & postfilter_roads )
overridevirtual

Definition at line 129 of file FPGATrackSimEtaPatternFilterTool.cxx.

130{
131 m_postfilter_roads.clear();
132 postfilter_roads.clear();
133 for (const auto & road : prefilter_roads)
134 {
135 // reset all maps
137
138
139 // put hits in module objects
140 addHitsToMap(road);
141
142 // keep track of used patterns, don't reuse
143 std::set<EtaPattern> usedPatterns;
144
145 // Count the number of matches from each individual road. This allows a dynamic threshold
146 // during constant generation (where we don't want to discard training tracks).
147 // At least, where we *might* not want to discard training tracks?
148 int numMatches = 0;
149 // check what is above threshold, moving down from 8/8 hits
150 for (unsigned working_threshold = m_nLayers; working_threshold >= m_threshold; working_threshold--)
151 {
152 for (auto & patt_bitmask : m_patternmap)
153 {
154 unsigned nLayers = std::popcount(patt_bitmask.second);
155 if (nLayers >= working_threshold)
156 {
157 // create subpattern from layers that actually have hits
158 EtaPattern subpatt(patt_bitmask.first);
159 for (unsigned lyr = 0; lyr < m_nLayers; lyr++)
160 if (!(patt_bitmask.second & (1 << lyr)))
161 subpatt[lyr] = {}; // defaults to undefined enums = missed
162
163 // check if this pattern was used already
164 if (usedPatterns.count(subpatt) > 0) continue;
165 addRedundantPatterns(usedPatterns, subpatt, nLayers - m_threshold);
166
167 // Get an "ID" for the pattern. This is a crude hack but it sort of works
168 // since the keys aren't being changed after the map is created. And provided the
169 // map is created in a consistent order this SHOULD be driven by insertion order.
170 // but this assumption may be fragile.
171 int index = std::distance(m_patternmap.begin(), m_patternmap.find(patt_bitmask.first));
172 if ((uint)index == m_patternmap.size() || index < 0) {
173 ATH_MSG_ERROR("Invalid pattern ID: " << index);
174 }
175 numMatches += 1;
176
177 // make the road
178 m_postfilter_roads.push_back(buildRoad(patt_bitmask, road, index));
179 }
180 }
181 // If using a "dynamic" threshold-- once matches have been found at a given level, exit.
182 if (numMatches > 0 && m_dynamicThreshold) {
183 break;
184 }
185 }
186 }
187 // copy roads to outputs
188 postfilter_roads.reserve(m_postfilter_roads.size());
189 for (FPGATrackSimRoad & r : m_postfilter_roads)
190 postfilter_roads.emplace_back(std::make_shared<const FPGATrackSimRoad>(r));
191 return StatusCode::SUCCESS;
192}
unsigned int uint
std::vector< FPGATrackSimRoad > m_postfilter_roads
void addHitsToMap(const std::shared_ptr< const FPGATrackSimRoad > &r)
void addRedundantPatterns(std::set< EtaPattern > &usedPatterns, EtaPattern const &currPatt, unsigned nExtra)
FPGATrackSimRoad buildRoad(std::pair< EtaPattern, layer_bitmask_t > const &patt, std::shared_ptr< const FPGATrackSimRoad > origr, int etaPatternID) const
str index
Definition DeMoScan.py:362

◆ finalize()

StatusCode FPGATrackSimEtaPatternFilterTool::finalize ( )
overridevirtual

Definition at line 120 of file FPGATrackSimEtaPatternFilterTool.cxx.

121{
122 return StatusCode::SUCCESS;
123}

◆ initialize()

StatusCode FPGATrackSimEtaPatternFilterTool::initialize ( )
overridevirtual

Definition at line 35 of file FPGATrackSimEtaPatternFilterTool.cxx.

36{
37 // Retrieve info
40 m_nLayers = m_FPGATrackSimMapping->PlaneMap_1st(0)->getNLogiLayers();
41
42 // Check inputs
43 if (m_pattern_file_path.empty())
44 {
45 ATH_MSG_FATAL("No File Specified");
46 return StatusCode::FAILURE;
47 }
48
49 // Read pattern file, populate m_patternmap keys
51
52 // Create inverse map from module to pattern counter, m_moduleHits
53 buildMap();
54
55 return StatusCode::SUCCESS;
56}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
Gaudi::Property< std::string > m_pattern_file_path
void readPatterns(std::string const &filepath)

◆ readPatterns()

void FPGATrackSimEtaPatternFilterTool::readPatterns ( std::string const & filepath)
private

Definition at line 59 of file FPGATrackSimEtaPatternFilterTool.cxx.

60{
61
62 // Open the file
63 std::ifstream fin(PathResolverFindCalibFile(filepath));
64 if (!fin.is_open())
65 {
66 ATH_MSG_FATAL("Couldn't open " << filepath);
67 throw ("FPGATrackSimEtaPatternFilterTool couldn't open " + filepath);
68 }
69
70 // Parse the file
71 bool ok = true;
72 std::string line;
73 while (getline(fin, line))
74 {
75 if (line.empty() || line[0] == '#') continue;
76 std::istringstream sline(line);
77
78 // Read Pattern
80 pattern.resize(m_nLayers);
81 int tech, zone, mod;
82 for (unsigned layer = 0; layer < m_nLayers; layer++)
83 {
84 ok = ok && (sline >> tech >> zone >> mod);
85 if (!ok) break;
86 pattern[layer] = { static_cast<SiliconTech>(tech), static_cast<DetectorZone>(zone), mod };
87 }
88 if (!ok) break;
89
90 m_patternmap.emplace(pattern, 0);
91 }
92
93 if (!ok)
94 {
95 ATH_MSG_FATAL("Found error reading file at line: " << line);
96 throw "FPGATrackSimEtaPatternFilterTool read error";
97 }
98
99 ATH_MSG_INFO("Read " << m_patternmap.size() << " patterns from " << filepath);
100}
#define ATH_MSG_INFO(x)
SiliconTech
DetectorZone
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
@ layer
Definition HitInfo.h:79

◆ resetCounters()

void FPGATrackSimEtaPatternFilterTool::resetCounters ( )
private

Definition at line 194 of file FPGATrackSimEtaPatternFilterTool.cxx.

195{
196 for (auto & entry : m_patternmap)
197 entry.second = 0;
198
199 for (unsigned lyr = 0; lyr < m_nLayers; lyr++)
200 for (auto & entry : m_moduleHits[lyr])
201 entry.second.reset();
202}

◆ to_string() [1/3]

std::string FPGATrackSimEtaPatternFilterTool::to_string ( const EtaPattern & patt) const
private

Definition at line 321 of file FPGATrackSimEtaPatternFilterTool.cxx.

322{
323 std::ostringstream oss;
324 oss << "[";
325 for (auto mod : patt) {
326 oss << "[";
327 oss << mod.siTech << ", " << mod.zone << ", " << mod.etaModule;
328 oss << "],";
329 }
330 oss << "]";
331 return oss.str();
332}

◆ to_string() [2/3]

std::string FPGATrackSimEtaPatternFilterTool::to_string ( const FPGATrackSimRoad & road) const
private

Definition at line 334 of file FPGATrackSimEtaPatternFilterTool.cxx.

335{
336 std::ostringstream oss;
337 oss << road.getNHits() << " : [";
338 for (unsigned layer = 0; layer < m_nLayers; layer++) {
339 oss << road.getNHits_layer()[layer] << ",";
340 }
341 oss << "]";
342 return oss.str();
343}
size_t getNHits() const
std::vector< size_t > getNHits_layer() const

◆ to_string() [3/3]

std::string FPGATrackSimEtaPatternFilterTool::to_string ( const std::vector< unsigned > & v) const
private

Definition at line 308 of file FPGATrackSimEtaPatternFilterTool.cxx.

309{
310 std::ostringstream oss;
311 oss << "[";
312 if (!v.empty())
313 {
314 std::copy(v.begin(), v.end()-1, std::ostream_iterator<unsigned>(oss, ", "));
315 oss << v.back();
316 }
317 oss << "]";
318 return oss.str();
319}

◆ operator<

bool operator< ( const ModuleId & lhs,
const ModuleId & rhs )
friend

Definition at line 27 of file FPGATrackSimEtaPatternFilterTool.cxx.

28{
29 if (lhs.siTech != rhs.siTech) return lhs.siTech < rhs.siTech;
30 if (lhs.zone != rhs.zone) return lhs.zone < rhs.zone;
31 return lhs.etaModule < rhs.etaModule;
32}

Member Data Documentation

◆ m_doEtaPatternConsts

Gaudi::Property<bool> FPGATrackSimEtaPatternFilterTool::m_doEtaPatternConsts {this, "doEtaPatternConsts", false, "Use eta pattern IDs as part of sector definition"}
private

Definition at line 62 of file FPGATrackSimEtaPatternFilterTool.h.

62{this, "doEtaPatternConsts", false, "Use eta pattern IDs as part of sector definition"};

◆ m_dynamicThreshold

Gaudi::Property<bool> FPGATrackSimEtaPatternFilterTool::m_dynamicThreshold { this, "dynamicThreshold", false, "Stop lowering the threshold once matches have been found"}
private

Definition at line 63 of file FPGATrackSimEtaPatternFilterTool.h.

63{ this, "dynamicThreshold", false, "Stop lowering the threshold once matches have been found"};

◆ m_FPGATrackSimBankSvc

ServiceHandle<IFPGATrackSimBankSvc> FPGATrackSimEtaPatternFilterTool::m_FPGATrackSimBankSvc {this, "FPGATrackSimBankSvc", "FPGATrackSimBankSvc"}
private

Definition at line 54 of file FPGATrackSimEtaPatternFilterTool.h.

54{this, "FPGATrackSimBankSvc", "FPGATrackSimBankSvc"};

◆ m_FPGATrackSimMapping

ServiceHandle<IFPGATrackSimMappingSvc> FPGATrackSimEtaPatternFilterTool::m_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"}
private

Definition at line 53 of file FPGATrackSimEtaPatternFilterTool.h.

53{this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};

◆ m_isSecondStage

Gaudi::Property<bool> FPGATrackSimEtaPatternFilterTool::m_isSecondStage {this, "isSecondStage", false, "Whether or not his this a second stage HT"}
private

Definition at line 61 of file FPGATrackSimEtaPatternFilterTool.h.

61{this, "isSecondStage", false, "Whether or not his this a second stage HT"};

◆ m_moduleHits

std::vector<std::map<ModuleId, ModulesToPattern> > FPGATrackSimEtaPatternFilterTool::m_moduleHits
private

Definition at line 115 of file FPGATrackSimEtaPatternFilterTool.h.

◆ m_nLayers

unsigned FPGATrackSimEtaPatternFilterTool::m_nLayers {}
private

Definition at line 108 of file FPGATrackSimEtaPatternFilterTool.h.

108{}; // alias to m_FPGATrackSimMapping->PlaneMap1stStage()->getNLogiLayers();

◆ m_pattern_file_path

Gaudi::Property<std::string> FPGATrackSimEtaPatternFilterTool::m_pattern_file_path {this, "EtaPatterns", "", "path to pattern file"}
private

Definition at line 59 of file FPGATrackSimEtaPatternFilterTool.h.

59{this, "EtaPatterns", "", "path to pattern file"};

◆ m_patternmap

std::map<EtaPattern, layer_bitmask_t> FPGATrackSimEtaPatternFilterTool::m_patternmap
private

Definition at line 112 of file FPGATrackSimEtaPatternFilterTool.h.

◆ m_postfilter_roads

std::vector<FPGATrackSimRoad> FPGATrackSimEtaPatternFilterTool::m_postfilter_roads
private

Definition at line 103 of file FPGATrackSimEtaPatternFilterTool.h.

◆ m_threshold

Gaudi::Property<unsigned> FPGATrackSimEtaPatternFilterTool::m_threshold {this, "threshold", 0, "Minimum number of hit layers to fire a road"}
private

Definition at line 60 of file FPGATrackSimEtaPatternFilterTool.h.

60{this, "threshold", 0, "Minimum number of hit layers to fire a road"};

The documentation for this class was generated from the following files: