13 #include <framework/logging/Logger.h>
14 #include <tracking/trackFindingVXD/sectorMapTools/SubGraphID.h>
15 #include <tracking/trackFindingVXD/sectorMapTools/SubGraph.h>
19 #include <unordered_map>
30 template<
class FilterType>
class SectorGraph {
32 std::unordered_map<SubGraphID, SubGraph<FilterType>>
m_subgraphs;
39 {
if (
m_filterIDs.empty()) { B2FATAL(
"SectorGraph-constructor: passed filterIDs are empty, this is an illegal usage of this class!"); } }
42 using Iterator =
typename std::unordered_map<SubGraphID, SubGraph<FilterType>>::iterator;
59 unsigned long nFound = 0;
60 for (
auto& pack :
m_subgraphs) { nFound += pack.second.getFound(); }
68 { B2WARNING(
"SectorGraph::add: given ID " << newID.
print() <<
" is already in graph, not added again...");
return end(); }
70 B2DEBUG(1,
"SectorGraph::add: new subgraph added: " << pos.first->second.print());
75 std::string
print(
bool fullPrint =
true)
const
78 std::string out =
"graph has got " + std::to_string(nSubgraphs) +
" entries:\n";
79 out +=
"now printing " + (fullPrint ? std::string(
"full") : std::string(
"short version of the")) +
" graph:\n";
81 if (!fullPrint and nSubgraphs % 100 != 0)
continue;
82 out += entry.second.print() +
"\n";
91 if (rarenessCut < 0 or rarenessCut >= 1)
92 { B2WARNING(
"pruneGraph: rarenessCut is rubbish: " << rarenessCut <<
", stopping prune-process.");
return 0; }
93 if (rarenessCut == 0) { B2DEBUG(1,
"pruneGraph: nothing to be done, stopping prune-process.");
return 0; }
98 std::vector< std::pair<unsigned, std::vector<SubGraph<FilterType>*> >> trunks;
104 for (
auto& trunk : trunks) {
106 trunk.first += graph.getFound();
107 trunk.second.push_back(&graph);
113 trunks.push_back({graph.getFound(), {&graph} });
117 unsigned long nFoundB4 =
nFoundTotal(), nKilled = 0;
118 unsigned sizeb4 =
size();
119 B2DEBUG(1,
"pruneGraph - before pruning: graph of size " << sizeb4 <<
" has " << trunks.size() <<
" trunks with " << nFoundB4 <<
123 std::vector<SubGraph<FilterType>*> deadBranches;
124 for (
auto& trunk : trunks) {
125 double trunkCut = rarenessCut * double(trunk.first);
128 std::sort(trunk.second.begin(),
131 ->
bool { return a->getFound() < b->getFound(); });
134 auto pos = trunk.second.begin();
135 if (
double((**pos).getFound()) >= trunkCut)
continue;
138 while (pos != trunk.second.end()) {
140 deadBranches.push_back(*pos);
141 trunkCut -= double((**pos).getFound()) * rarenessCut;
144 if (
double((**pos).getFound()) >= trunkCut)
break;
149 if (deadBranches.empty()) { B2DEBUG(1,
"pruneGraph: no rare branches found - stopping pruning process.");
return 0; }
152 for (
auto* graph : deadBranches) {
153 nKilled += graph->getFound();
157 B2DEBUG(1,
"pruneGraph - after pruning graph with size (before/after " << sizeb4 <<
"/" <<
size() <<
158 ") and nFound (before/after/killed " << nFoundB4 <<
"/" <<
nFoundTotal() <<
"/" << nKilled);
169 unsigned nUpdated = 0,
174 std::vector<unsigned> idsFound;
175 std::string idsPrinted;
179 SubGraphID graphID = subGraphEntry.second.getID();
181 if (found.empty())
continue;
182 idsFound.insert(idsFound.end(), found.begin(), found.end());
185 B2DEBUG(1,
"updateSubLayerIDs: before unique of found ids, following IDs are recorded: \n" << idsPrinted);
186 nFound += idsFound.size();
187 std::sort(idsFound.begin(), idsFound.end());
188 idsFound.erase(std::unique(idsFound.begin(), idsFound.end()), idsFound.end());
189 nUpdated += idsFound.size();
192 for (
unsigned id : idsFound) { idsPrinted += FullSecID(
id).getFullSecString() +
" "; }
193 B2DEBUG(1,
"updateSubLayerIDs: before updating Subgraphs, following IDs have to be updated: \n" << idsPrinted);
198 SubGraph<FilterType>& graph = subGraphEntry.second;
199 unsigned nSecsUpdated = graph.idCheckAndUpdate(idsFound);
200 if (nSecsUpdated == 0) {
201 B2DEBUG(50,
"updateSubLayerIDs: was _not_ updated: " << graph.getID().print());
205 B2DEBUG(50,
"updateSubLayerIDs: was updated " << nSecsUpdated <<
" times: " << graph.getID().print());
208 B2DEBUG(1,
"updateSubLayerIDs: nSectors found/updated: " << nFound <<
"/" << nUpdated <<
", nSubgraphs updated: " <<
224 std::vector<FullSecID> foundIDs;
227 std::vector<FullSecID> sectorsFound = subGraph.second.getSectorsOfSensor(sensor);
228 if (sectorsFound.empty())
continue;
229 foundIDs.insert(foundIDs.end(), sectorsFound.begin(), sectorsFound.end());
231 B2DEBUG(1,
"getAllFullSecIDsOfSensor: VxdID " << sensor <<
" has " << foundIDs.size() <<
" sectors in this graph");