Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/framework/analysis/inc/TRestDataSetOdds.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TRestDataSetOdds : public TRestMetadata {
std::string GetOddsFile() { return fOddsFile; }
std::string GetDataSetName() { return fDataSetName; }
std::string GetOutputFileName() { return fOutputFileName; }
const std::map<std::string, TH1F*>& GetHistos() const { return fHistos; }
TRestCut* GetCut() { return fCut; }

inline void SetDataSetName(const std::string& dSName) { fDataSetName = dSName; }
Expand All @@ -74,6 +75,7 @@ class TRestDataSetOdds : public TRestMetadata {
inline void SetCut(TRestCut* cut) { fCut = cut; }
void SetOddsObservables(const std::vector<std::tuple<std::string, TVector2, int>>& obs);
void AddOddsObservable(const std::string& name, const TVector2& range, int nbins);
void WriteHistograms(TFile* f) const;

TRestDataSetOdds();
TRestDataSetOdds(const char* configFilename, std::string name = "");
Expand Down
21 changes: 15 additions & 6 deletions source/framework/analysis/src/TRestDataSetOdds.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
/// log(1. - odds) - log(odds) obtaining a number which is proportional to
/// how likely is an event with respect the desired distribution; lower the number,
/// more likely is the event to the input distribution. New observables are created in
/// the output dataSet odds_obserbable and the addition of all of them in odds_total.
/// the output dataSet odds_obserbable and the addition of all of them in odds_total,
/// where odds represents the TRestDataSetOdds name.
/// If an input odds file is provided, the different PDFs are retrieved from the input
/// file.
///
Expand Down Expand Up @@ -199,7 +200,7 @@ void TRestDataSetOdds::InitFromConfigFile() {
/// observables. Otherwise, it takes the PDF from the
/// input file. This function generate different observables
/// odds_obsName and the addition of all of them for a further
/// processing, which is stored in odds_total observable.
/// processing, which is stored in odds_total observable, where odds is the TRestDataSetOdds name.
///
void TRestDataSetOdds::ComputeLogOdds() {
PrintMetadata();
Expand All @@ -213,7 +214,7 @@ void TRestDataSetOdds::ComputeLogOdds() {
for (size_t i = 0; i < fObsName.size(); i++) {
const std::string obsName = fObsName[i];
const TVector2 range = fObsRange[i];
const std::string histName = "h" + obsName;
const std::string histName = "h" + std::string(GetName()) + "_" + obsName;
const int nBins = fObsNbins[i];
RESTDebug << "\tGenerating PDF for " << obsName << " with range: (" << range.X() << ", "
<< range.Y() << ") and nBins: " << nBins << RESTendl;
Expand All @@ -233,7 +234,7 @@ void TRestDataSetOdds::ComputeLogOdds() {
RESTInfo << "Opening " << fOddsFile << " as oddsFile." << RESTendl;
for (size_t i = 0; i < fObsName.size(); i++) {
const std::string obsName = fObsName[i];
const std::string histName = "h" + obsName;
const std::string histName = "h" + std::string(GetName()) + "_" + obsName;
TH1F* h = (TH1F*)f->Get(histName.c_str());
fHistos[obsName] = h;
}
Expand All @@ -243,7 +244,7 @@ void TRestDataSetOdds::ComputeLogOdds() {
std::string totName = "";
RESTDebug << "Computing log odds from " << fDataSetName << RESTendl;
for (const auto& [obsName, histo] : fHistos) {
const std::string oddsName = "odds_" + obsName;
const std::string oddsName = std::string(GetName()) + "_" + obsName;
auto GetLogOdds = [&histo = histo](double val) {
double odds = histo->GetBinContent(histo->GetXaxis()->FindBin(val));
if (odds == 0) return 1000.;
Expand All @@ -264,7 +265,7 @@ void TRestDataSetOdds::ComputeLogOdds() {

RESTDebug << "Computing total log odds" << RESTendl;
RESTDebug << "\tTotal log odds = " << totName << RESTendl;
df = df.Define("odds_total", totName);
df = df.Define(std::string(GetName()) + "_total", totName);

dataSet.SetDataFrame(df);

Expand Down Expand Up @@ -306,6 +307,14 @@ void TRestDataSetOdds::SetOddsObservables(const std::vector<std::tuple<std::stri
for (const auto& [name, range, nbins] : obs) AddOddsObservable(name, range, nbins);
}

void TRestDataSetOdds::WriteHistograms(TFile* f) const {
if (!f) return;
f->cd();
for (const auto& [name, histo] : fHistos) {
if (histo) histo->Write();
}
}

/////////////////////////////////////////////
/// \brief Prints on screen the information about the metadata members of TRestDataSetOdds
///
Expand Down