9#include <svd/modules/svdPerformance/SVDVariablesToStorageModule.h>
10#include <reconstruction/persistenceManager/PersistenceManagerFactory.h>
12#include <framework/datastore/StoreArray.h>
13#include <framework/core/ModuleParam.templateDetails.h>
14#include <tracking/dataobjects/RecoTrack.h>
15#include <mdst/dataobjects/Track.h>
16#include <mdst/dataobjects/TrackFitResult.h>
17#include <analysis/dataobjects/ParticleList.h>
18#include <mdst/dataobjects/HitPatternVXD.h>
19#include <analysis/VariableManager/Manager.h>
21 namespace VPM = Belle2::VariablePersistenceManager;
23 std::string getIndexedVariableName(
const std::string& variableName,
unsigned int iCluster)
25 return variableName +
"(" + std::to_string(iCluster) +
")";
28 VPM::Variables createVariablesToStore(
const std::vector<std::string>& variablesToNtuple)
30 VPM::Variables variables;
31 for (
const auto& variableName : variablesToNtuple) {
34 variables.push_back(VPM::TypedVariable(variableName, variableDataType));
39 VPM::Variables createVariablesToStore(
const std::vector<std::tuple<std::string, int, float, float>>& variablesToHistogram)
41 VPM::Variables variables;
42 for (
const auto& [varName, nbins, minVal, maxVal] : variablesToHistogram) {
43 variables.push_back(VPM::BinnedVariable(varName, nbins, minVal, maxVal));
48 std::vector<std::string> extractVariableNames(
const std::vector<std::tuple<std::string, int, float, float>>& variablesToHistogram)
50 std::vector<std::string> variableNames;
51 std::transform(variablesToHistogram.begin(), variablesToHistogram.end(), std::back_inserter(variableNames),
52 [](
const auto & variable) {
53 return std::get<0>(variable);
61 namespace VPM = Belle2::VariablePersistenceManager;
77 VPM::Variables variablesToStore;
79 B2FATAL(
"Cannot have both variablesToNtuple and variablesToHistogram set.");
95 const auto ncandidates = particlelist->getListSize();
96 for (
unsigned int iPart = 0; iPart < ncandidates; iPart++) {
97 const Particle* particle = particlelist->getParticle(iPart);
99 const auto trackFitResult = particle->getTrackFitResult();
101 if (!trackFitResult) {
105 const auto nSVDClusters = trackFitResult->getHitPatternVXD().getNSVDHits();
107 for (
unsigned int iCluster = 0; iCluster < nSVDClusters; iCluster++) {
109 VPM::EvaluatedVariables evaluatedVariables{};
111 const std::string indexedVariableName = getIndexedVariableName(variableName, iCluster);
113 const auto value = var->function(particle);
114 evaluatedVariables[variableName] = value;
Class to store reconstructed particles.
std::string m_particleListName
The name of the particle list to use for analysis (if applicable).
std::vector< std::tuple< std::string, int, float, float > > m_variablesToHistogram
List of (variableName, nBins, lowBin, highBin) defining histograms.
virtual void initialize() override
Initializes the module.
std::vector< std::string > m_variableNames
List of variable names for reference.
std::unique_ptr< VPM::PersistenceManager > persistenceManager
Manages the persistence of data (e.g., writing to file).
virtual void event() override
Processes each event in the main event loop.
virtual void terminate() override
Performs finalization steps after all events have been processed.
std::string m_containerName
The name of the container storing SVD data (e.g., clusters).
std::string m_fileName
The output file name for storing results (e.g., root file).
std::vector< std::string > m_variablesToNtuple
List of variables to store in an ntuple.
SVDVariablesToStorageModule()
Constructs the SVDVariablesToStorageModule and sets default parameter values.
Type-safe access to single objects in the data store.
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Namespace to encapsulate code needed for simulation and reconstrucion of the SVD.
VariableDataType variabletype
data type of variable
A variable returning a floating-point value for a given Particle.