Belle II Software development
SubGraph.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/logging/Logger.h>
12#include <tracking/trackFindingVXD/sectorMapTools/RawDataCollectedMinMax.h>
13#include <tracking/trackFindingVXD/sectorMapTools/MinMax.h>
14#include <tracking/trackFindingVXD/sectorMapTools/SubGraphID.h>
15#include <tracking/dataobjects/FullSecID.h>
16
17#include <string>
18#include <vector>
19#include <unordered_map>
20#include <utility>
21
22
23namespace Belle2 {
30 template<class FilterType> class SubGraph {
31 protected:
35 std::unordered_map<FilterType, MinMax> m_minMaxValues;
36
37 unsigned m_found;
39 std::unordered_map<FilterType, RawDataCollectedMinMax>* m_rawDataCollected;
42 void updateID(const SubGraphID& newID)
43 { m_id = newID; }
44 public:
45
47 bool operator==(const SubGraph<FilterType>& b) const
48 { return (m_id == b.m_id); }
49
51 using Iterator = typename std::unordered_map<FilterType, MinMax>::iterator;
52
54 SubGraph(SubGraphID& id, const std::vector<FilterType>& fIDs) : m_id(id), m_found(1), m_rawDataCollected(nullptr)
55 {
56 for (auto& iD : fIDs) {
57 m_minMaxValues.insert({iD, MinMax()});
58 }
59 }
60
62 ~SubGraph() { if (m_rawDataCollected != nullptr) delete m_rawDataCollected; }
63
65 bool checkAndReplaceIfMinMax(FilterType fID, double value)
66 {
67 Iterator pos = m_minMaxValues.find(fID);
68 if (pos == m_minMaxValues.end()) {
69 B2WARNING("FilterID " << fID << " not known to this subgraph " << m_id.print() << " - nothing added!");
70 return false;
71 }
72 return pos->second.checkAndReplaceIfMinMax(value);
73 }
74
75 void wasFound() { m_found++; }
77 unsigned getFound() const { return m_found; }
80 bool checkSharesTrunk(const SubGraph<FilterType>& b) const { return (m_id.checkSharesTrunk(b.m_id)); }
81
83 std::string print() const
84 {
85 std::string out = "id: " + m_id.print() + " was found " + std::to_string(m_found) + " times. Filters with values collected:\n";
86 for (const auto& entry : m_minMaxValues) {
87 out += entry.first + " " + entry.second.print() + " _||_ ";
88 }
89 return out;
90 }
91
93 const SubGraphID& getID() const { return m_id; }
94
96 void prepareDataCollection(std::pair<double, double> quantiles)
97 {
98 if (m_rawDataCollected != nullptr) delete m_rawDataCollected;
99 m_rawDataCollected = new std::unordered_map<FilterType, RawDataCollectedMinMax>();
100
101 for (const auto& entry : m_minMaxValues) {
102 m_rawDataCollected->insert({entry.first, RawDataCollectedMinMax(m_found, quantiles)});
103 }
104 }
105
107 void addValue(FilterType fID, double value)
108 {
109 if (m_rawDataCollected == nullptr) { B2FATAL("SubGraph::addValue: attempt to add data before prepareDataCollection(...) was executed! Aborting illegal procedure."); }
110 auto pos = m_rawDataCollected->find(fID);
111 if (pos == m_rawDataCollected->end()) {
112 B2WARNING("addValue: FilterID " << fID << " not known to this subgraph " << m_id.print() << " - nothing added!");
113 return;
114 }
115 pos->second.add(value);
116 return;
117 }
118
120 const std::unordered_map<FilterType, MinMax>& getFinalQuantileValues()
121 {
122 for (auto& entry : *m_rawDataCollected) {
123 std::pair<double, double> results = entry.second.getMinMax();
124 checkAndReplaceIfMinMax(entry.first, results.first);
125 checkAndReplaceIfMinMax(entry.first, results.second);
126 }
127
128 std::string out;
129 for (auto& entry : m_minMaxValues) {
130 out += entry.first + " " + entry.second.print() + " ";
131 }
132 B2DEBUG(20, "SubGraph::getFinalQuantileValues: minMaxFound:\n" << out);
133 return m_minMaxValues;
134 }
135
137 unsigned idCheckAndUpdate(const std::vector<unsigned>& ids)
138 {
139 unsigned nUpdated = 0;
140 for (unsigned id : ids) {
141
142 if (m_id.hasElement(id)) {
143 m_id.updateID(id);
144 nUpdated++;
145 }
146 }
147 return nUpdated;
148 }
149
151 std::vector<FullSecID> getSectorsOfSensor(const VxdID& sensor)
152 {
153 std::vector<FullSecID> foundIDs;
154
155 for (auto& sector : m_id) {
156 if (sensor != FullSecID(sector).getVxdID()) continue;
157 foundIDs.push_back(FullSecID(sector));
158 }
159 return foundIDs;
160 }
161 };
163}
164
Class to identify a sector inside of the VXD.
Definition: FullSecID.h:33
small class for storing min and max.
Definition: MinMax.h:23
takes care of collecting raw data and staying below RAM-threshold.
stores the ID of a subgraph, which is basically a chain of FullSecID coded as unsigned ints.
Definition: SubGraphID.h:24
bool hasElement(unsigned b) const
checks if given raw secID is part of this, ignores subLayerID.
Definition: SubGraphID.h:132
bool updateID(unsigned newID)
if newID is element of this (ignoring subLayerID), oldID will be replaced by newID....
Definition: SubGraphID.h:171
bool checkSharesTrunk(const SubGraphID &b) const
if both graphs have got the same IDs except the last one, they share a trunk.
Definition: SubGraphID.h:87
std::string print() const
returns string of entries.
Definition: SubGraphID.h:101
contains all relevant stuff needed for dealing with a subGraph.
Definition: SubGraph.h:30
std::unordered_map< FilterType, RawDataCollectedMinMax > * m_rawDataCollected
takes care of collecting the raw data.
Definition: SubGraph.h:39
const std::unordered_map< FilterType, MinMax > & getFinalQuantileValues()
this deletes the old min and max values stored and replaces them with the quantiles to be found.
Definition: SubGraph.h:120
bool checkSharesTrunk(const SubGraph< FilterType > &b) const
if both graphs have got the same IDs except the last one, they share a trunk.
Definition: SubGraph.h:80
unsigned getFound() const
returns found-counter.
Definition: SubGraph.h:77
const SubGraphID & getID() const
returns iD of this graph
Definition: SubGraph.h:93
void prepareDataCollection(std::pair< double, double > quantiles)
takes care of being able to use the data collector. please use for quantiles [min,...
Definition: SubGraph.h:96
SubGraphID m_id
contains the IDs in the correct order (from outer to inner) as a unique identifier for this graph.
Definition: SubGraph.h:32
void updateID(const SubGraphID &newID)
set newID for this subgraph.
Definition: SubGraph.h:42
bool operator==(const SubGraph< FilterType > &b) const
overloaded '=='-operator
Definition: SubGraph.h:47
bool checkAndReplaceIfMinMax(FilterType fID, double value)
add filter, if not added yet, checks value and replaces old ones if new one is better.
Definition: SubGraph.h:65
unsigned idCheckAndUpdate(const std::vector< unsigned > &ids)
for given vector of ids check if any of them is part of subGraphID. If yes, update their SubLayerID....
Definition: SubGraph.h:137
SubGraph(SubGraphID &id, const std::vector< FilterType > &fIDs)
constructor, mandatory iDChain musst at least contain one iD.
Definition: SubGraph.h:54
typename std::unordered_map< FilterType, MinMax >::iterator Iterator
for better readability.
Definition: SubGraph.h:51
std::unordered_map< FilterType, MinMax > m_minMaxValues
contains all min- and max-values found so far for all filters relevant for this Graph....
Definition: SubGraph.h:35
std::vector< FullSecID > getSectorsOfSensor(const VxdID &sensor)
returns vector containing all sectors for given sensor (if any) and empty vector if no sector of that...
Definition: SubGraph.h:151
~SubGraph()
destructor
Definition: SubGraph.h:62
void wasFound()
increases found-counter.
Definition: SubGraph.h:75
unsigned m_found
counts number of times this subgraph was found.
Definition: SubGraph.h:37
std::string print() const
"print" debugging information to a string
Definition: SubGraph.h:83
void addValue(FilterType fID, double value)
adds value to rawDataCollector
Definition: SubGraph.h:107
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Abstract base class for different kinds of events.