Skip to content

Commit

Permalink
TRestComponentDataSet. Final version with Nsim normalization and weights
Browse files Browse the repository at this point in the history
  • Loading branch information
jgalan committed Nov 27, 2023
1 parent d9e4bee commit 3164d77
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
4 changes: 2 additions & 2 deletions source/framework/sensitivity/inc/TRestComponentDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class TRestComponentDataSet : public TRestComponent {
/// A list with the dataset columns used to weight the distribution density and define rate
std::vector<std::string> fWeights; //<

/// It defines the statistics of each parameterization node (Initialized by the dataset)
std::vector<Int_t> fNodeStatistics; //<
/// It defines the number of entries for each parameterization node (Initialized by the dataset)
std::vector<Int_t> fNSimPerNode; //<

/// The filename of the dataset used
std::vector<std::string> fDataSetFileNames; //<
Expand Down
6 changes: 4 additions & 2 deletions source/framework/sensitivity/src/TRestComponent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ void TRestComponent::PrintMetadata() {
RESTWarning << "The number of variables does not match with the number of defined ranges!"
<< RESTendl;

else if (!fVariables.empty()) {
else if (fVariables.size() != fNbins.size())
RESTWarning << "The number of variables does not match with the number of defined bins!" << RESTendl;
else {
int n = 0;
RESTMetadata << " === Variables === " << RESTendl;
for (const auto& varName : fVariables) {
RESTMetadata << " - Name: " << varName << " Range: (" << fRanges[n].X() << ", " << fRanges[n].Y()
<< ")" << RESTendl;
<< ") bins: " << fNbins[n] << RESTendl;
n++;
}
}
Expand Down
59 changes: 25 additions & 34 deletions source/framework/sensitivity/src/TRestComponentDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,20 @@ Double_t TRestComponentDataSet::GetTotalRate() {
void TRestComponentDataSet::PrintMetadata() {
TRestComponent::PrintMetadata();

if (fVariables.size() != fRanges.size())
RESTWarning << "The number of variables does not match with the number of defined ranges!"
<< RESTendl;

else if (fVariables.size() != fNbins.size())
RESTWarning << "The number of variables does not match with the number of defined bins!" << RESTendl;
else {
int n = 0;
RESTMetadata << " === Variables === " << RESTendl;
for (const auto& varName : fVariables) {
RESTMetadata << " - Name: " << varName << " Range: (" << fRanges[n].X() << ", " << fRanges[n].Y()
<< ") bins: " << fNbins[n] << RESTendl;
n++;
}
}

RESTMetadata << "----" << RESTendl;

if (!fParameter.empty() && fParameterizationNodes.empty()) {
RESTMetadata << "This component has no nodes!" << RESTendl;
RESTMetadata << " Use: LoadDataSets() to initialize the nodes" << RESTendl;
}

if (!fWeights.empty()) {
RESTMetadata << " " << RESTendl;
RESTMetadata << " == Weights ==" << RESTendl;

for (const auto& x : fWeights) RESTMetadata << "- " << x << RESTendl;

RESTMetadata << " " << RESTendl;
}

RESTMetadata << " Use : PrintStatistics() to check node statistics" << RESTendl;
RESTMetadata << "----" << RESTendl;
}
Expand All @@ -186,7 +178,7 @@ void TRestComponentDataSet::PrintMetadata() {
/// \brief It prints out the statistics available for each parametric node
///
void TRestComponentDataSet::PrintStatistics() {
if (fNodeStatistics.empty() && IsDataSetLoaded()) fNodeStatistics = ExtractNodeStatistics();
if (fNSimPerNode.empty() && IsDataSetLoaded()) fNSimPerNode = ExtractNodeStatistics();

if (!HasNodes() && !IsDataSetLoaded()) {
RESTWarning << "TRestComponentDataSet::PrintStatistics. Empty nodes and no dataset loaded!"
Expand All @@ -195,14 +187,14 @@ void TRestComponentDataSet::PrintStatistics() {
return;
}

auto result = std::accumulate(fNodeStatistics.begin(), fNodeStatistics.end(), 0);
auto result = std::accumulate(fNSimPerNode.begin(), fNSimPerNode.end(), 0);
std::cout << "Total counts : " << result << std::endl;
std::cout << std::endl;

std::cout << " Parameter node statistics (" << fParameter << ")" << std::endl;
int n = 0;
for (const auto& p : fParameterizationNodes) {
std::cout << " - Value : " << p << " Counts: " << fNodeStatistics[n] << std::endl;
std::cout << " - Value : " << p << " Counts: " << fNSimPerNode[n] << std::endl;
n++;
}
}
Expand All @@ -225,7 +217,7 @@ void TRestComponentDataSet::InitFromConfigFile() {
/// variables and the weights for each of the parameter nodes.
///
void TRestComponentDataSet::FillHistograms() {
fNodeStatistics = ExtractNodeStatistics();
fNSimPerNode = ExtractNodeStatistics();

if (!IsDataSetLoaded()) {
RESTError << "TRestComponentDataSet::FillHistograms. Dataset has not been initialized!" << RESTendl;
Expand Down Expand Up @@ -270,21 +262,20 @@ void TRestComponentDataSet::FillHistograms() {

std::vector<std::string> varsAndWeight = fVariables;

/*
if (!fWeights.empty()) {
std::string weightsStr = "";
for (size_t n = 0; n < fWeights.size(); n++) {
if (n > 0) weightsStr += "*";
weightsStr += fWeights[n];
}
df = df.Define("componentWeight", weightsStr);
varsAndWeight.push_back("componentWeight");
std::string weightsStr = "";
for (size_t n = 0; n < fWeights.size(); n++) {
if (n > 0) weightsStr += "*";

weightsStr += fWeights[n];
}
df = df.Define("componentWeight", weightsStr);
varsAndWeight.push_back("componentWeight");
}
*/

auto hn = df.HistoND({hName, hName, (int)fNbins.size(), bins, xmin, xmax}, varsAndWeight);
THnD* hNd = new THnD(*hn);
hNd->Scale(1. / fNSimPerNode[nIndex]);

fNodeDensity.push_back(hNd);
fActiveNode = nIndex;
Expand Down Expand Up @@ -434,11 +425,11 @@ std::vector<Double_t> TRestComponentDataSet::ExtractParameterizationNodes() {
/// \brief It returns a vector with the number of entries found for each
/// parameterization node.
///
/// If fNodeStatistics has already been initialized it will
/// If fNSimPerNode has already been initialized it will
/// directly return its value.
///
std::vector<Int_t> TRestComponentDataSet::ExtractNodeStatistics() {
if (!fNodeStatistics.empty()) return fNodeStatistics;
if (!fNSimPerNode.empty()) return fNSimPerNode;

std::vector<Int_t> stats;
if (!IsDataSetLoaded()) {
Expand Down

0 comments on commit 3164d77

Please sign in to comment.