Belle II Software development
ClusterInfoExtractor Class Reference

class to extract info from individual clusters and combine for SPTC More...

#include <ClusterInfoExtractor.h>

Inheritance diagram for ClusterInfoExtractor:
VariableExtractor

Public Member Functions

 ClusterInfoExtractor (std::vector< Named< float * > > &variableSet, bool useTimingInfo)
 Constructor fills variableSet with variables to be extracted.
 
void extractVariables (std::vector< SpacePoint const * > const &spacePoints)
 extract variables from SpacePoints
 

Protected Member Functions

void initializeStats (const std::string &identifier, std::vector< Named< float * > > &variables)
 initialize statistics subsets of variables from clusters that get combined for SPTC
 
void setStats (const std::string &identifier, std::vector< float > &values)
 calculated statistics and saves them in variable set
 
void addVariable (const std::string &identifier, std::vector< Named< float * > > &variables)
 add a variable to the variable set
 

Protected Attributes

bool m_UseTimingInfo
 whether to use timing info from cluster
 
std::unordered_map< std::string, float > m_variables
 unordered_map to associate float value with a string name
 

Detailed Description

class to extract info from individual clusters and combine for SPTC

Definition at line 23 of file ClusterInfoExtractor.h.

Constructor & Destructor Documentation

◆ ClusterInfoExtractor()

ClusterInfoExtractor ( std::vector< Named< float * > > &  variableSet,
bool  useTimingInfo 
)
inline

Constructor fills variableSet with variables to be extracted.

Parameters
variableSetset of variable to be filled
useTimingInfowhether to use the timing info in clusters

Definition at line 29 of file ClusterInfoExtractor.h.

29 :
30 VariableExtractor(), m_UseTimingInfo(useTimingInfo)
31 {
32 initializeStats("charge", variableSet);
33 initializeStats("seedCharge", variableSet);
34 initializeStats("size", variableSet);
35 initializeStats("energyLoss", variableSet);
36 if (m_UseTimingInfo) {
37 initializeStats("time", variableSet);
38 initializeStats("timeSigma", variableSet);
39 }
40
41 }
void initializeStats(const std::string &identifier, std::vector< Named< float * > > &variables)
initialize statistics subsets of variables from clusters that get combined for SPTC
bool m_UseTimingInfo
whether to use timing info from cluster

Member Function Documentation

◆ addVariable()

void addVariable ( const std::string &  identifier,
std::vector< Named< float * > > &  variables 
)
inlineprotectedinherited

add a variable to the variable set

Definition at line 27 of file VariableExtractor.h.

28 {
29 //todo: verify if it is faster to check explicitly or not
30 auto value = m_variables.emplace(identifier, NAN).first;
31 variables.emplace_back(identifier, &(value->second));
32 }
std::unordered_map< std::string, float > m_variables
unordered_map to associate float value with a string name

◆ extractVariables()

void extractVariables ( std::vector< SpacePoint const * > const &  spacePoints)
inline

extract variables from SpacePoints

Definition at line 44 of file ClusterInfoExtractor.h.

45 {
46 std::vector<SVDCluster const*> clusters;
47 clusters.reserve(spacePoints.size() * 2);
48
49 for (SpacePoint const* sp : spacePoints) {
50 RelationVector<SVDCluster> relatedClusters = sp->getRelationsTo<SVDCluster>("");
51 for (const SVDCluster& cluster : relatedClusters) {
52 clusters.push_back(&cluster);
53 }
54 }
55
56 // this is fine as it is pointing to the `relatedClusters`, which are in the datastore..
57 // cppcheck-suppress invalidLifetime
58 std::vector<float> values(clusters.size());
59 for (unsigned int i = 0; i < clusters.size(); ++i) {
60 values[i] = clusters[i]->getCharge();
61 }
62 setStats("charge", values);
63
64 for (unsigned int i = 0; i < clusters.size(); ++i) {
65 values[i] = clusters[i]->getSeedCharge();
66 }
67 setStats("seedCharge", values);
68
69
70 for (unsigned int i = 0; i < clusters.size(); ++i) {
71 values[i] = clusters[i]->getSize();
72 }
73 setStats("size", values);
74
75
76 for (unsigned int i = 0; i < clusters.size(); ++i) {
77 values[i] = clusters[i]->getCharge() / clusters[i]->getSize();
78 }
79 setStats("energyLoss", values);
80
81 if (m_UseTimingInfo) {
82 for (unsigned int i = 0; i < clusters.size(); ++i) {
83 values[i] = clusters[i]->getClsTime();
84 }
85 setStats("time", values);
86
87 for (unsigned int i = 0; i < clusters.size(); ++i) {
88 values[i] = clusters[i]->getClsTimeSigma();
89 }
90 setStats("timeSigma", values);
91 }
92
93 }
void setStats(const std::string &identifier, std::vector< float > &values)
calculated statistics and saves them in variable set

◆ initializeStats()

void initializeStats ( const std::string &  identifier,
std::vector< Named< float * > > &  variables 
)
inlineprotected

initialize statistics subsets of variables from clusters that get combined for SPTC

Definition at line 100 of file ClusterInfoExtractor.h.

101 {
102 addVariable(identifier + "_max", variables);
103 addVariable(identifier + "_min", variables);
104 addVariable(identifier + "_mean", variables);
105 addVariable(identifier + "_std", variables);
106 addVariable(identifier + "_sum", variables);
107 }
void addVariable(const std::string &identifier, std::vector< Named< float * > > &variables)
add a variable to the variable set

◆ setStats()

void setStats ( const std::string &  identifier,
std::vector< float > &  values 
)
inlineprotected

calculated statistics and saves them in variable set

Definition at line 110 of file ClusterInfoExtractor.h.

111 {
112 short size = values.size();
113 if (values.size() == 0) {
114 m_variables.at(identifier + "_max") = NAN;
115 m_variables.at(identifier + "_min") = NAN;
116 m_variables.at(identifier + "_mean") = NAN;
117 m_variables.at(identifier + "_std") = NAN;
118 m_variables.at(identifier + "_sum") = NAN;
119 return;
120 }
121 // mean
122 float sum = std::accumulate(values.begin(), values.end(), 0.0);
123 m_variables.at(identifier + "_sum") = sum;
124 float mean = sum / size;
125 m_variables.at(identifier + "_mean") = mean;
126 // variance and standard deviation
127 float variance = std::accumulate(values.begin(), values.end(), 0.0,
128 [mean, size](float x, float y) {return x + ((y - mean) * (y - mean)) / (size - 1);});
129 float stddev = std::sqrt(variance);
130 m_variables.at(identifier + "_std") = stddev;
131 //min and max
132 float min = *(std::min_element(values.begin(), values.end()));
133 float max = *(std::max_element(values.begin(), values.end()));
134 m_variables.at(identifier + "_min") = min;
135 m_variables.at(identifier + "_max") = max;
136 }

Member Data Documentation

◆ m_UseTimingInfo

bool m_UseTimingInfo
protected

whether to use timing info from cluster

Definition at line 97 of file ClusterInfoExtractor.h.

◆ m_variables

std::unordered_map<std::string, float> m_variables
protectedinherited

unordered_map to associate float value with a string name

Definition at line 35 of file VariableExtractor.h.


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