CaMaterialMonitor.h 3.98 KiB
/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Sergey Gorbunov [committer] */
/// \file MaterialMonitor.h
/// \brief Class to collect statistics for ca::MaterialMap
#pragma once // include this header only once per compilation unit
#include "CaDefs.h"
#include "CaMaterialMap.h"
#include <string>
#include <vector>
namespace cbm::algo::ca
{
/// Class to collect statistics for ca::MaterialMap
///
class MaterialMonitor {
public:
/// default constructor
MaterialMonitor() : MaterialMonitor(nullptr) {}
/// constructor
/// \param materialMap Matareial map to be monitored
/// \param name Name of the material map
MaterialMonitor(const ca::MaterialMap* materialMap, std::string name = "") : fName(name)
{
SetMaterial(materialMap);
}
/// construction
/// \param materialMap Matareial map to be monitored
void SetMaterial(const ca::MaterialMap* materialMap);
/// construction
/// \param name Name of the material map
void SetName(std::string name) { fName = name; }
/// reset the map of active bins
void ResetActiveBins()
{
for (auto& v : fActiveBinMap) {
v = 0;
}
}
/// mark a bin as active
void MarkActiveBin(float x, float y);
/// update values of statistical variables with respect to the active map
void EvaluateStatistics();
/// print statistics to a string
std::string ToString();
/// get number of active bins in the map
int GetActiveNbins() const { return fActiveNbins; }
/// get minimal radiation thickness among all active bins
double GetActiveRadThickMin() const { return fPassiveRadThickMin; }
/// get maximal radiation thickness among all active bins
double GetActiveRadThickMax() const { return fPassiveRadThickMax; }
/// get average radiation thickness among all active bins
double GetActiveRadThickMean() const { return fPassiveRadThickMean; }
/// get number of passive bins in the map
int GetPassiveNbins() const { return fPassiveNbins; }
/// get minimal radiation thickness among all passive bins
double GetPassiveRadThickMin() const { return fPassiveRadThickMin; }
/// get maximal radiation thickness among all passive bins
double GetPassiveRadThickMax() const { return fPassiveRadThickMax; }
/// get average radiation thickness among all passive bins
double GetPassiveRadThickMean() const { return fPassiveRadThickMean; }
/// get the ration of hits that show up outside the material map
double GetRatioOfOutsideHits() const { return fNhitsOutside / (fNhitsTotal + 1.e-8); }
/// get the number of processed hits
double GetNhits() const { return fNhitsTotal; }
private:
const ca::MaterialMap* fMaterial{nullptr}; ///< Pointer to ca::MaterialMap
std::string fName{}; ///< Name of the material map
std::vector<char> fActiveBinMap{}; ///< Map of active bins in the material map (bins where hits appear)
int fActiveNbins{constants::Undef<int>}; ///< Active material: number of bins
double fActiveRadThickMin{constants::Undef<double>}; ///< Active material: minimal thickness
double fActiveRadThickMax{constants::Undef<double>}; ///< Active material: maximal thickness
double fActiveRadThickMean{constants::Undef<double>}; ///< Active material: average thickness
int fPassiveNbins{constants::Undef<int>}; ///< Passive material: number of bins
double fPassiveRadThickMin{constants::Undef<double>}; ///< Passive material: minimal thickness
double fPassiveRadThickMax{constants::Undef<double>}; ///< Passive material: maximal thickness
double fPassiveRadThickMean{constants::Undef<double>}; ///< Passive material: average thickness
unsigned long fNhitsTotal{0}; ///< number of hits in statistics
unsigned long fNhitsOutside{0}; ///< number of hits outside the material map
};
} // namespace cbm::algo::ca