Skip to content

Commit

Permalink
TRestComponentDataSet::DrawComponent adding method to visualize densi…
Browse files Browse the repository at this point in the history
…ty distributions
  • Loading branch information
jgalan committed Nov 28, 2023
1 parent aaf068f commit c66016e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
4 changes: 4 additions & 0 deletions source/framework/sensitivity/inc/TRestComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define REST_TRestComponent

#include <THn.h>
#include <TCanvas.h>

#include "TRestDataSet.h"
#include "TRestMetadata.h"
Expand All @@ -49,6 +50,9 @@ class TRestComponent : public TRestMetadata {
/// It is used to define the node that will be accessed for rate retrieval
Int_t fActiveNode = -1; //<

/// A canvas for drawing the active node component
TCanvas* fCanvas = nullptr; //!

/// It returns true if any nodes have been defined.
Bool_t HasNodes() { return !fParameterizationNodes.empty(); }

Expand Down
3 changes: 3 additions & 0 deletions source/framework/sensitivity/inc/TRestComponentDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class TRestComponentDataSet : public TRestComponent {
Double_t GetRate(std::vector<Double_t> point) override;
Double_t GetTotalRate() override;

TCanvas* DrawComponent(std::vector<std::string> drawVariables, std::vector<std::string> scanVariables,
Int_t reduction = 1);

THnD* GetDensityForNode(Double_t value);
THnD* GetDensityForActiveNode();
THnD* GetDensity() { return GetDensityForActiveNode(); }
Expand Down
67 changes: 65 additions & 2 deletions source/framework/sensitivity/src/TRestComponentDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,76 @@ Double_t TRestComponentDataSet::GetTotalRate() {
return integral;
}

///////////////////////////////////////////////
/// \brief
///
TCanvas* TRestComponentDataSet::DrawComponent(std::vector<std::string> drawVariables,
std::vector<std::string> scanVariables, Int_t reduction) {
if (drawVariables.size() > 2) {
RESTError << "TRestComponentDataSet::DrawComponent. The number of variables that can be drawn cannot "
"be more than 2!" << RESTendl;
return fCanvas;
}

if (scanVariables.size() > 2) {
RESTError << "TRestComponentDataSet::DrawComponent. The number of variables that can be scanned "
"cannot be more than 2!" << RESTendl;
return fCanvas;
}

if (scanVariables.size() == 0) {
RESTError << "TRestComponentDataSet::DrawComponent. Needs at least one scan variable!" << RESTendl;
return fCanvas;
}

if (drawVariables.size() == 0) {
RESTError << "TRestComponentDataSet::DrawComponent. Needs at least one variable to be drawn!"
<< RESTendl;
return fCanvas;
}

// Initializing canvas window
if (fCanvas != nullptr) {
delete fCanvas;
fCanvas = nullptr;
}

std::vector<int> scanIndexes;
for (const auto& x : scanVariables) scanIndexes.push_back(GetVariableIndex(x));

std::vector<int> variableIndexes;
for (const auto& x : drawVariables) variableIndexes.push_back(GetVariableIndex(x));

if (scanIndexes.size() == 1) {
std::vector<int> canvasDivisions = TRestTools::CanvasDivisions(fNbins[scanIndexes[0]]);

std::cout << "- " <<
} else if (scanIndexes.size() == 2) {
}

fCanvas = new TCanvas(this->GetName(), this->GetName(), 0, 0, 640, 480);
/*
fCanvas->Divide((Int_t)fCanvasDivisions.X(), (Int_t)fCanvasDivisions.Y(),
fCanvasDivisionMargins.X(), fCanvasDivisionMargins.Y());
*/
return fCanvas;
}

/////////////////////////////////////////////
/// \brief Prints on screen the information about the metadata members of TRestAxionSolarFlux
///
void TRestComponentDataSet::PrintMetadata() {
TRestComponent::PrintMetadata();

if (!fDataSetFileNames.empty()) {
RESTMetadata << " " << RESTendl;
RESTMetadata << " == Dataset filenames ==" << RESTendl;

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

RESTMetadata << " " << RESTendl;
}

if (!fParameter.empty() && fParameterizationNodes.empty()) {
RESTMetadata << "This component has no nodes!" << RESTendl;
RESTMetadata << " Use: LoadDataSets() to initialize the nodes" << RESTendl;
Expand Down Expand Up @@ -456,8 +520,7 @@ std::vector<Int_t> TRestComponentDataSet::ExtractNodeStatistics() {
Bool_t TRestComponentDataSet::LoadDataSets() {
if (fDataSetFileNames.empty()) {
RESTWarning << "Dataset filename was not defined. You may still use "
"TRestComponentDataSet::LoadDataSet( filename );"
<< RESTendl;
"TRestComponentDataSet::LoadDataSet( filename );" << RESTendl;
fDataSetLoaded = false;
return fDataSetLoaded;
}
Expand Down

0 comments on commit c66016e

Please sign in to comment.