Belle II Software prerelease-11-00-00a
ClusterInfoExtractor Class Reference

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

#include <ClusterInfoExtractor.h>

Inheritance diagram for ClusterInfoExtractor:
Collaboration diagram for ClusterInfoExtractor:

Public Member Functions

 ClusterInfoExtractor (std::vector< TrackingUtilities::Named< float * > > &variableSet, bool useTimingInfo, const std::string &prefix="")
 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< TrackingUtilities::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< TrackingUtilities::Named< float * > > &variables)
 add a variable to the variable set
 

Protected Attributes

bool m_UseTimingInfo
 whether to use timing info from cluster
 
std::string m_prefix
 prefix that will be added before the variable names
 
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< TrackingUtilities::Named< float * > > & variableSet,
bool useTimingInfo,
const std::string & prefix = "" )
inline

Constructor fills variableSet with variables to be extracted.

Parameters
variableSetset of variable to be filled
useTimingInfowhether to use the timing info in clusters
prefixprefix that will be added before the variable names

Definition at line 30 of file ClusterInfoExtractor.h.

31 :
32 VariableExtractor(), m_UseTimingInfo(useTimingInfo), m_prefix(prefix)
33 {
34 initializeStats(m_prefix + "charge", variableSet);
35 initializeStats(m_prefix + "seedCharge", variableSet);
36 initializeStats(m_prefix + "size", variableSet);
37 initializeStats(m_prefix + "energyLoss", variableSet);
38 if (m_UseTimingInfo) {
39 initializeStats(m_prefix + "time", variableSet);
40 initializeStats(m_prefix + "timeSigma", variableSet);
41 }
42
43 }

Member Function Documentation

◆ addVariable()

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

add a variable to the variable set

Definition at line 30 of file VariableExtractor.h.

31 {
32 //todo: verify if it is faster to check explicitly or not
33 auto value = m_variables.emplace(identifier, NAN).first;
34 variables.emplace_back(identifier, &(value->second));
35 }

◆ extractVariables()

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

extract variables from SpacePoints

Definition at line 46 of file ClusterInfoExtractor.h.

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

◆ initializeStats()

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

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

Definition at line 104 of file ClusterInfoExtractor.h.

105 {
106 addVariable(identifier + "_max", variables);
107 addVariable(identifier + "_min", variables);
108 addVariable(identifier + "_mean", variables);
109 addVariable(identifier + "_std", variables);
110 addVariable(identifier + "_sum", variables);
111 }

◆ setStats()

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

calculated statistics and saves them in variable set

Definition at line 114 of file ClusterInfoExtractor.h.

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

Member Data Documentation

◆ m_prefix

std::string m_prefix
protected

prefix that will be added before the variable names

Definition at line 101 of file ClusterInfoExtractor.h.

◆ m_UseTimingInfo

bool m_UseTimingInfo
protected

whether to use timing info from cluster

Definition at line 99 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 38 of file VariableExtractor.h.


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