Skip to content

Commit

Permalink
Merge branch 'jgalan_sensitivity' of github.com:rest-for-physics/fram…
Browse files Browse the repository at this point in the history
…ework into jgalan_sensitivity
  • Loading branch information
jgalan committed Jan 29, 2024
2 parents d97347f + 3cdcf5f commit 9d1996d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 41 deletions.
3 changes: 1 addition & 2 deletions source/framework/sensitivity/inc/TRestComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
#ifndef REST_TRestComponent
#define REST_TRestComponent

#include <TRandom3.h>

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

#include <ROOT/RDataFrame.hxx>
#include <ROOT/RVec.hxx>
Expand Down
20 changes: 10 additions & 10 deletions source/framework/sensitivity/inc/TRestExperimentList.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ class TRestExperimentList : public TRestMetadata {
std::vector<std::vector<std::string> > fExperimentsTable; //<

/// A vector with a list of experiments includes the background components in this model
std::vector<TRestExperiment *> fExperiments; //<
std::vector<TRestExperiment*> fExperiments; //<

/// If not zero this will be the common exposure time in micro-seconds (standard REST units)
Double_t fExposureTime = 0;

/// If not null this will be the common signal used in each experiment
TRestComponent *fSignal = nullptr; //<
TRestComponent* fSignal = nullptr; //<

/// If not null this will be the common signal used in each experiment
TRestComponent *fBackground = nullptr; //<
TRestComponent* fBackground = nullptr; //<

protected:
TRestComponent *GetComponent(std::string compName);
TRestComponent* GetComponent(std::string compName);

void InitFromConfigFile() override;

public:
void Initialize() override;

void SetExposure(const Double_t &exposure) { fExposureTime = exposure; }
void SetSignal(TRestComponent *comp) { fSignal = comp; }
void SetBackground(TRestComponent *comp) { fBackground = comp; }
void SetExposure(const Double_t& exposure) { fExposureTime = exposure; }
void SetSignal(TRestComponent* comp) { fSignal = comp; }
void SetBackground(TRestComponent* comp) { fBackground = comp; }

std::vector<TRestExperiment *> GetExperiments() { return fExperiments; }
TRestExperiment *GetExperiment(const size_t &n) {
std::vector<TRestExperiment*> GetExperiments() { return fExperiments; }
TRestExperiment* GetExperiment(const size_t& n) {
if (n >= GetNumberOfExperiments())
return nullptr;
else
Expand All @@ -83,7 +83,7 @@ class TRestExperimentList : public TRestMetadata {

void PrintMetadata() override;

TRestExperimentList(const char *cfgFileName, const std::string &name);
TRestExperimentList(const char* cfgFileName, const std::string& name);

TRestExperimentList();
~TRestExperimentList();
Expand Down
8 changes: 4 additions & 4 deletions source/framework/sensitivity/inc/TRestSensitivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
class TRestSensitivity : public TRestMetadata {
private:
/// A list of experimental conditions included to get a final sensitivity plot
std::vector<TRestExperiment *> fExperiments; //<
std::vector<TRestExperiment*> fExperiments; //<

protected:
void InitFromConfigFile() override;

public:
void Initialize() override;

std::vector<TRestExperiment *> GetExperiments() { return fExperiments; }
TRestExperiment *GetExperiment(const size_t &n) {
std::vector<TRestExperiment*> GetExperiments() { return fExperiments; }
TRestExperiment* GetExperiment(const size_t& n) {
if (n >= GetNumberOfExperiments())
return nullptr;
else
Expand All @@ -49,7 +49,7 @@ class TRestSensitivity : public TRestMetadata {

void PrintMetadata() override;

TRestSensitivity(const char *cfgFileName, const std::string &name = "");
TRestSensitivity(const char* cfgFileName, const std::string& name = "");
TRestSensitivity();
~TRestSensitivity();

Expand Down
1 change: 0 additions & 1 deletion source/framework/sensitivity/src/TRestComponentDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ std::vector<Int_t> TRestComponentDataSet::ExtractNodeStatistics() {
RESTInfo << "Counting statistics for each node ..." << RESTendl;
RESTInfo << "Number of nodes : " << fParameterizationNodes.size() << RESTendl;
for (const auto& p : fParameterizationNodes) {

Double_t pUp = p * (1 + fPrecision / 2);
Double_t pDown = p * (1 - fPrecision / 2);
std::string filter =
Expand Down
32 changes: 16 additions & 16 deletions source/framework/sensitivity/src/TRestExperimentList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TRestExperimentList::~TRestExperimentList() {}
/// \param cfgFileName A const char* giving the path to an RML file.
/// \param name The name of the specific metadata.
///
TRestExperimentList::TRestExperimentList(const char *cfgFileName, const std::string &name)
TRestExperimentList::TRestExperimentList(const char* cfgFileName, const std::string& name)
: TRestMetadata(cfgFileName) {
LoadConfigFromFile(fConfigFileName, name);
}
Expand All @@ -85,8 +85,8 @@ void TRestExperimentList::InitFromConfigFile() {
if (!fExperimentsFile.empty() && fExperiments.empty()) {
TRestTools::ReadASCIITable(fExperimentsFile, fExperimentsTable);

for (auto &row : fExperimentsTable)
for (auto &el : row) el = REST_StringHelper::ReplaceMathematicalExpressions(el);
for (auto& row : fExperimentsTable)
for (auto& el : row) el = REST_StringHelper::ReplaceMathematicalExpressions(el);

if (fExperimentsTable.empty()) {
RESTError << "TRestExperimentList::InitFromConfigFile. The experiments table is empty!"
Expand All @@ -97,7 +97,7 @@ void TRestExperimentList::InitFromConfigFile() {
Int_t nTableColumns = fExperimentsTable[0].size();

int cont = 0;
TRestComponent *comp = (TRestComponent *)this->InstantiateChildMetadata(cont, "Component");
TRestComponent* comp = (TRestComponent*)this->InstantiateChildMetadata(cont, "Component");
while (comp != nullptr) {
if (ToLower(comp->GetNature()) == "background")
fBackground = comp;
Expand All @@ -107,7 +107,7 @@ void TRestExperimentList::InitFromConfigFile() {
RESTWarning << "TRestExperimentList::InitFromConfigFile. Unknown component!" << RESTendl;

cont++;
comp = (TRestComponent *)this->InstantiateChildMetadata(cont, "Component");
comp = (TRestComponent*)this->InstantiateChildMetadata(cont, "Component");
}

Int_t nExpectedColumns = 3;
Expand Down Expand Up @@ -144,11 +144,11 @@ void TRestExperimentList::InitFromConfigFile() {
fComponentFiles = TRestTools::GetFilesMatchingPattern(fComponentPattern);

Bool_t generateMockData = false;
for (const auto &experimentRow : fExperimentsTable) {
TRestExperiment *experiment = new TRestExperiment();
for (const auto& experimentRow : fExperimentsTable) {
TRestExperiment* experiment = new TRestExperiment();

std::string rowStr = "";
for (const auto &el : experimentRow) {
for (const auto& el : experimentRow) {
rowStr += el + " ";
}

Expand Down Expand Up @@ -181,15 +181,15 @@ void TRestExperimentList::InitFromConfigFile() {
}

if (!fSignal) {
TRestComponent *sgnl = (TRestComponent *)GetComponent(experimentRow[column])->Clone();
TRestComponent* sgnl = (TRestComponent*)GetComponent(experimentRow[column])->Clone();
experiment->SetSignal(sgnl);
column++;
} else {
experiment->SetSignal(fSignal);
}

if (!fBackground) {
TRestComponent *bck = (TRestComponent *)GetComponent(experimentRow[column])->Clone();
TRestComponent* bck = (TRestComponent*)GetComponent(experimentRow[column])->Clone();
experiment->SetBackground(bck);
} else {
experiment->SetBackground(fBackground);
Expand All @@ -205,16 +205,16 @@ void TRestExperimentList::InitFromConfigFile() {
}
}

TRestComponent *TRestExperimentList::GetComponent(std::string compName) {
TRestComponent *component = nullptr;
for (const auto &c : fComponentFiles) {
TFile *f = TFile::Open(c.c_str(), "READ");
TObject *obj = f->Get((TString)compName);
TRestComponent* TRestExperimentList::GetComponent(std::string compName) {
TRestComponent* component = nullptr;
for (const auto& c : fComponentFiles) {
TFile* f = TFile::Open(c.c_str(), "READ");
TObject* obj = f->Get((TString)compName);

if (!obj) continue;

if (obj->InheritsFrom("TRestComponent")) {
return (TRestComponent *)obj;
return (TRestComponent*)obj;
} else {
RESTError << "An object named : " << compName
<< " exists inside the file, but it does not inherit from TRestComponent" << RESTendl;
Expand Down
15 changes: 7 additions & 8 deletions source/framework/sensitivity/src/TRestSensitivity.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
///
/// <hr>
///
#include <TRestSensitivity.h>
#include <TRestExperimentList.h>
#include <TRestSensitivity.h>

ClassImp(TRestSensitivity);

Expand Down Expand Up @@ -67,7 +67,7 @@ TRestSensitivity::~TRestSensitivity() {}
/// \param name The name of the specific metadata. It will be used to find the
/// corresponding TRestAxionMagneticField section inside the RML.
///
TRestSensitivity::TRestSensitivity(const char *cfgFileName, const std::string &name)
TRestSensitivity::TRestSensitivity(const char* cfgFileName, const std::string& name)
: TRestMetadata(cfgFileName) {
LoadConfigFromFile(fConfigFileName, name);
}
Expand All @@ -85,19 +85,18 @@ void TRestSensitivity::InitFromConfigFile() {
TRestMetadata::InitFromConfigFile();

int cont = 0;
TRestMetadata *metadata = (TRestMetadata *)this->InstantiateChildMetadata(cont, "Experiment");
TRestMetadata* metadata = (TRestMetadata*)this->InstantiateChildMetadata(cont, "Experiment");
while (metadata != nullptr) {

cont++;
if (metadata->InheritsFrom("TRestExperimentList")) {
TRestExperimentList *experimentsList = (TRestExperimentList *)metadata;
std::vector<TRestExperiment *> exList = experimentsList->GetExperiments();
TRestExperimentList* experimentsList = (TRestExperimentList*)metadata;
std::vector<TRestExperiment*> exList = experimentsList->GetExperiments();
fExperiments.insert(fExperiments.end(), exList.begin(), exList.end());
} else if (metadata->InheritsFrom("TRestExperiment")) {
fExperiments.push_back((TRestExperiment *)metadata);
fExperiments.push_back((TRestExperiment*)metadata);
}

metadata = (TRestMetadata *)this->InstantiateChildMetadata(cont, "Experiment");
metadata = (TRestMetadata*)this->InstantiateChildMetadata(cont, "Experiment");
}

Initialize();
Expand Down

0 comments on commit 9d1996d

Please sign in to comment.