From 85a87e64e790ccbd8955190a04538540e6648f0e Mon Sep 17 00:00:00 2001 From: juanan Date: Mon, 27 Mar 2023 20:34:23 +0200 Subject: [PATCH 01/11] New metadata class TRestCalibration meant to perform the calibration over a TRestDataSet --- .../framework/analysis/inc/TRestCalibration.h | 81 +++++ .../analysis/src/TRestCalibration.cxx | 299 ++++++++++++++++++ 2 files changed, 380 insertions(+) create mode 100644 source/framework/analysis/inc/TRestCalibration.h create mode 100644 source/framework/analysis/src/TRestCalibration.cxx diff --git a/source/framework/analysis/inc/TRestCalibration.h b/source/framework/analysis/inc/TRestCalibration.h new file mode 100644 index 000000000..ce8a0e006 --- /dev/null +++ b/source/framework/analysis/inc/TRestCalibration.h @@ -0,0 +1,81 @@ +/************************************************************************* + * This file is part of the REST software framework. * + * * + * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) * + * For more information see https://gifna.unizar.es/trex * + * * + * REST is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * REST is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have a copy of the GNU General Public License along with * + * REST in $REST_PATH/LICENSE. * + * If not, see https://www.gnu.org/licenses/. * + * For the list of contributors see $REST_PATH/CREDITS. * + *************************************************************************/ + +#ifndef REST_TRestCalibration +#define REST_TRestCalibration + +#include "TRestMetadata.h" + +/// This class is meant to perform the calibration of different runs +class TRestCalibration : public TRestMetadata { +private: + + // Name of the output file + std::string fOutputFileName = ""; + // Name of the dataSet inside the config file + std::string fDataSetName = ""; + // Vector containing expected energy peaks in keV must be sorted + std::vector< double > fEnergyPeaks; + // Vector containing calibrated peaks in ADCs + std::vector< double > fCalibPeaks; + // Vector containing calibrated sigma in ADCs + std::vector< double > fCalibFWHM; + // Name of the calibration file to be used + std::string fCalibFile = ""; + // Calibration variable to be used + std::string fCalObservable = ""; + // Range to be calibrated + TVector2 fCalibRange; + // Number of bins used in the calibration + Int_t fNBins; + // Slope from the calibration fit + Double_t fSlope = 0; + // Intercept of the calibration fit + Double_t fIntercept = 0; + + void Initialize() override; + void InitFromConfigFile() override; + +public: + void PrintMetadata() override; + + void Calibrate( ); + + inline void SetDataSetName (const std::string &dSName) {fDataSetName = dSName;} + inline void SetOutputFileName (const std::string &outName) {fOutputFileName = outName;} + inline void SetCalibrationFile (const std::string &calibFile) {fCalibFile = calibFile;} + + inline auto GetCalibPeaks() const {return fCalibPeaks;} + inline auto GetCalibFWHM() const {return fCalibFWHM;} + + inline double GetSlope() const {return fSlope;} + inline double GetIntercept() const {return fIntercept;} + inline std::string GetCalObservable() const {return fCalObservable;} + + TRestCalibration(); + TRestCalibration(const char* configFilename, std::string name = ""); + ~TRestCalibration(); + + ClassDefOverride(TRestCalibration, 1); + +}; +#endif diff --git a/source/framework/analysis/src/TRestCalibration.cxx b/source/framework/analysis/src/TRestCalibration.cxx new file mode 100644 index 000000000..67736a745 --- /dev/null +++ b/source/framework/analysis/src/TRestCalibration.cxx @@ -0,0 +1,299 @@ +/************************************************************************* + * This file is part of the REST software framework. * + * * + * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) * + * For more information see https://gifna.unizar.es/trex * + * * + * REST is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * REST is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have a copy of the GNU General Public License along with * + * REST in $REST_PATH/LICENSE. * + * If not, see https://www.gnu.org/licenses/. * + * For the list of contributors see $REST_PATH/CREDITS. * + *************************************************************************/ + +///////////////////////////////////////////////////////////////////////// +/// TRestCalibration performs the calibration of a TRestDataSet, the +/// calibration is performed over different peaks provided in the config +/// file, in which the first peak should corresponds to the maximum in the +/// spectrum histogram. +/// +/// A summary of the basic parameters is described below: +/// * **calObservable**: Name of the observable to be calibrated +/// * **nBins**: Number of bins for the calibration spectra +/// * **calibRange**: Calibration range inside calObservable that +/// will be used for the spectrum +/// * **dataSetName**: Name of the dataSet to be calibrated +/// * **calibFile**: Name of the calibration file to be used for +/// the calibration parameters, if empty it performs the calibration +/// over the dataSet provided. +/// +/// The energy peaks to calibrate are given using peak metadata: +/// * **energy**: Energy of the peak(s) to be calibrated in keV, +/// note that the first peak should correspond to the maximum +/// +/// The following metadata members are used as output after the fit: +/// * **calibPeaks**: Position of the mean value of the peak after +/// the fit using the same order as the energy peaks +/// * **fCalibFWHM**: FWHM in percentage for the different peaks, +/// using the same order as the energy peaks. +/// +/// If an output file name is provided a new dataset will be generated +/// with the corresponding metadata and calibration constants, while +/// adding a new observable, calib_energy. In addition, the spectrum +/// and the fit results will be stored in the output file. +/// +/// +/// ### Examples +/// RML example to calibrate a dataset with a peak at 5.89 keV +/// \code +/// +/// +/// +/// +/// +/// +/// +/// \endcode +/// +/// Example to perform calibration over a calibration dataSet using restRoot: +/// \code +/// [0] TRestCalibration cal ("calibration.rml"); +/// [1] cal.SetDataSetName("myDataSet.root"); +/// [2] cal.SetOutputFileName("myCalibratedDataSet.root"); +/// [3] cal.Calibrate(); +/// \endcode +/// +/// Example to perform calibration over a background dataSet using restRoot: +/// \code +/// [0] TRestCalibration cal ("calibration.rml"); +/// [1] cal.SetDataSetName("myBackgroundDataSet.root"); +/// [2] cal.SetOutputFileName("myBackgroundCalibratedDataSet.root"); +/// [3] cal.SetCalibrationFile("myCalibratedDataSet.root"); +/// [4] cal.Calibrate(); +/// \endcode +/// +///---------------------------------------------------------------------- +/// +/// REST-for-Physics - Software for Rare Event Searches Toolkit +/// +/// History of developments: +/// +/// 2023-03: First implementation of TRestCalibration +/// JuanAn Garcia +/// +/// \class TRestCalibration +/// \author: JuanAn Garcia e-mail: juanangp@unizar.es +/// +///
+/// + +#include "TRestCalibration.h" +#include "TRestDataSet.h" + +ClassImp(TRestCalibration); + +/////////////////////////////////////////////// +/// \brief Default constructor +/// +TRestCalibration::TRestCalibration() { + Initialize(); +} + +///////////////////////////////////////////// +/// \brief Constructor loading data from a config file +/// +/// If no configuration path is defined using TRestMetadata::SetConfigFilePath +/// the path to the config file must be specified using full path, absolute or +/// relative. +/// +/// The default behaviour is that the config file must be specified with +/// full path, absolute or relative. +/// +/// \param configFilename A const char* that defines the RML filename. +/// \param name The name of the metadata section. It will be used to find the +/// corresponding TRestCalibration section inside the RML. +/// +TRestCalibration::TRestCalibration(const char* configFilename, std::string name) : TRestMetadata(configFilename) { + LoadConfigFromFile(fConfigFileName, name); + Initialize(); + + if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) PrintMetadata(); +} + +/////////////////////////////////////////////// +/// \brief Default destructor +/// +TRestCalibration::~TRestCalibration() { +} + +/////////////////////////////////////////////// +/// \brief Function to initialize input/output event members and define +/// the section name +/// +void TRestCalibration::Initialize() { + SetSectionName(this->ClassName()); +} + +/////////////////////////////////////////////// +/// \brief Function to initialize some variables from +/// configfile, in case that the variable is not found +/// in the rml it checks the input file pattern. +/// +void TRestCalibration::InitFromConfigFile() { + + Initialize(); + TRestMetadata::InitFromConfigFile(); + + TiXmlElement* peakDefinition = GetElement("peak"); + while (peakDefinition != nullptr) { + std::string energy = GetFieldValue("energy", peakDefinition); + if (energy.empty() || energy == "Not defined") { + RESTError << "< peak variable key does not contain energy!" << RESTendl; + exit(1); + } else { + fEnergyPeaks.push_back(StringToDouble( energy ) ); + } + + peakDefinition = GetNextElement(peakDefinition); + } + + if(fEnergyPeaks.empty()){ + RESTError << "Energy peaks not provided, exiting..." << RESTendl; + exit(1); + } + + if(fOutputFileName == "")fOutputFileName = GetParameter("outputFileName",""); + +} + +///////////////////////////////////////////// +/// \brief Performs the calibration of a given dataSet. If +/// no calibration file is provided, it performs the gaussian +/// fit to the different parameters provided in the config file. +/// Otherwise, it takes the calibration constants from the +/// provided calibration file. +/// +void TRestCalibration::Calibrate(){ + + PrintMetadata(); + + TRestDataSet dataSet; + dataSet.Import(fDataSetName); + + dataSet.PrintMetadata(); + + std::unique_ptr spectrum; + std::unique_ptr gr; + std::unique_ptr linearFit; + + if(fCalibFile.empty()){ + + auto histo = dataSet.GetDataFrame().Histo1D( +{"spectrum","spectrum",fNBins,fCalibRange.X(),fCalibRange.X()}, fCalObservable); + spectrum = std::unique_ptr (static_cast(histo->DrawClone()) ); + + // Get position of the maximum + const double max = spectrum->GetBinCenter(spectrum->GetMaximumBin()); + // Get ratio between maximum and energy peak + const double ratio = max/fEnergyPeaks.front(); + + RESTDebug << "Max peak position " << max << RESTendl; + + std::vector gauss; + gr = std::unique_ptr(new TGraph()); + gr->SetName ("grFit"); + + int c=0; + for(const auto & energy : fEnergyPeaks){ + std::string fName = "g"+ std::to_string(c); + double pos = energy * ratio; + double start = pos * 0.85; + double end = pos * 1.15; + TF1 *g = new TF1(fName.c_str(), "gaus", start, end); + RESTDebug << "Fitting gaussian " << pos << " " << start <<" " << end << RESTendl; + spectrum->Fit(g,"R+"); + gauss.emplace_back(g); + gr->SetPoint(c, g->GetParameter(1), energy); + fCalibPeaks.push_back(g->GetParameter(1)); + fCalibFWHM.push_back(g->GetParameter(2)*235./g->GetParameter(1)); + c++; + } + + if(GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)GetChar(); + + gr->SetPoint(c,0,0); + + gr->Draw("AP"); + linearFit = std::unique_ptr (new TF1("linearFit", "pol1")); + gr->Fit("linearFit","S"); + } else { + TFile *f = TFile::Open(fCalibFile.c_str()); + if(f==nullptr){ + RESTError << "Cannot open calibration file "<< fCalibFile << RESTendl; + exit(1); + } + RESTInfo << "Opening "<< fCalibFile << RESTendl; + gr = std::unique_ptr(f->Get("grFit")); + linearFit = std::unique_ptr (f->Get("linearFit") ); + } + + fSlope = linearFit->GetParameter(1); + fIntercept = linearFit->GetParameter(0); + + RESTDebug<<"Slope "<GetParameter(1)*val + linearFit->GetParameter(0); + }; + df = df.Define("calib_Energy", calibrate, {fCalObservable}); + + dataSet.SetDataSet(df); + + if(!fOutputFileName.empty()){ + if(TRestTools::GetFileNameExtension(fOutputFileName) == "root"){ + dataSet.Export(fOutputFileName); + TFile* f = TFile::Open(fOutputFileName.c_str(), "UPDATE"); + this->Write(); + if(gr)gr->Write(); + if(linearFit)linearFit->Write(); + //if(lFit)lFit->Write(); + //spectrumFit->Write(); + if(spectrum)spectrum->Write(); + f->Close(); + } + } +} + +///////////////////////////////////////////// +/// \brief Prints on screen the information about the metadata members of TRestCalibration +/// +void TRestCalibration::PrintMetadata() { + TRestMetadata::PrintMetadata(); + + RESTMetadata << " Energy peaks to calibrate: "; + for (const auto& peak : fEnergyPeaks)RESTMetadata << peak <<" keV; "; + RESTMetadata << RESTendl; + RESTMetadata << " Calibrated peak position: "; + for (const auto& peak : fCalibPeaks)RESTMetadata << peak <<" ADC; "; + RESTMetadata << RESTendl; + RESTMetadata << " Calibrated FWHM: "; + for (const auto& fwhm : fCalibFWHM)RESTMetadata << fwhm <<" %; "; + RESTMetadata << RESTendl; + RESTMetadata << "Observable to calibrate: " << fCalObservable << RESTendl; + RESTMetadata << "Calibration range: ("<< fCalibRange.X() <<", "<< fCalibRange.Y() <<")" << RESTendl; + RESTMetadata << "Number of bins: " << fNBins << RESTendl; + RESTMetadata << "Slope: " << fSlope << " keV/ADC" << RESTendl; + RESTMetadata << "Intercept: " < Date: Mon, 27 Mar 2023 20:35:56 +0200 Subject: [PATCH 02/11] New metadata class TRestOdds to perform the log odds computation over a TRestDataSet --- source/framework/analysis/inc/TRestOdds.h | 72 +++++ source/framework/analysis/src/TRestOdds.cxx | 287 ++++++++++++++++++++ 2 files changed, 359 insertions(+) create mode 100644 source/framework/analysis/inc/TRestOdds.h create mode 100644 source/framework/analysis/src/TRestOdds.cxx diff --git a/source/framework/analysis/inc/TRestOdds.h b/source/framework/analysis/inc/TRestOdds.h new file mode 100644 index 000000000..db7acf963 --- /dev/null +++ b/source/framework/analysis/inc/TRestOdds.h @@ -0,0 +1,72 @@ +/************************************************************************* + * This file is part of the REST software framework. * + * * + * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) * + * For more information see https://gifna.unizar.es/trex * + * * + * REST is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * REST is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have a copy of the GNU General Public License along with * + * REST in $REST_PATH/LICENSE. * + * If not, see https://www.gnu.org/licenses/. * + * For the list of contributors see $REST_PATH/CREDITS. * + *************************************************************************/ + +#ifndef REST_TRestOdds +#define REST_TRestOdds + +#include "TRestMetadata.h" +#include "TRestCut.h" +#include "TH1F.h" + +/// This class is meant to compute the log odds for different datasets +class TRestOdds : public TRestMetadata { +private: + + // Name of the output file + std::string fOutputFileName = ""; + // Name of the dataSet inside the config file + std::string fDataSetName = ""; + // Vector containing different obserbable names + std::vector fObsName; + // Vector containing different obserbable ranges + std::vector fObsRange; + // Vector containing number of bins for the different observables + std::vector fObsNbins; + // Name of the odds file to be used to get the PDF + std::string fOddsFile = ""; + + /// Cuts over the dataset for PDF selection + TRestCut *fCut = nullptr; + + // Map containing the PDF of the different observables + std::map fHistos; //! + + void Initialize() override; + void InitFromConfigFile() override; + +public: + void PrintMetadata() override; + + void ComputeLogOdds(); + + inline void SetDataSetName (const std::string &dSName) {fDataSetName = dSName;} + inline void SetOutputFileName (const std::string &outName) {fOutputFileName = outName;} + inline void SetOddsFile (const std::string &oddsFile) {fOddsFile = oddsFile;} + + TRestOdds(); + TRestOdds(const char* configFilename, std::string name = ""); + ~TRestOdds(); + + ClassDefOverride(TRestOdds, 1); + +}; +#endif diff --git a/source/framework/analysis/src/TRestOdds.cxx b/source/framework/analysis/src/TRestOdds.cxx new file mode 100644 index 000000000..d9129ad08 --- /dev/null +++ b/source/framework/analysis/src/TRestOdds.cxx @@ -0,0 +1,287 @@ +/************************************************************************* + * This file is part of the REST software framework. * + * * + * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) * + * For more information see https://gifna.unizar.es/trex * + * * + * REST is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * REST is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have a copy of the GNU General Public License along with * + * REST in $REST_PATH/LICENSE. * + * If not, see https://www.gnu.org/licenses/. * + * For the list of contributors see $REST_PATH/CREDITS. * + *************************************************************************/ + +///////////////////////////////////////////////////////////////////////// +/// Write the class description Here +/// TRestOdds performs the log odds of the different observables given +/// in the config file and for a particular dataSet. To perform the log odds +/// first the probability density funcion (PDF) is obtained for a set of +/// observables in the desired range. Later on, the log odds is computed as +/// 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. +/// If an input odds file is provided, the different PDFs are retrieved from the input +/// file. +/// +/// A summary of the basic parameters is described below: +/// * **dataSetName**: Name of the dataSet to be computed +/// * **oddsFile**: Name of the input odds file to be used for the definition of the +/// different PDFs. +/// +/// The different obserbables, range and nBins are added as follow: +/// \code +/// +/// \endcode +/// * **name**: Name of the observable PDF to be computed +/// * **range**: Range of the observable PDF to be used +/// * **nBins**: Number of bins for the observable PDF +/// +/// In addition a TRestCut is used as input for the generation of PDFs, check TRestCut +/// class for more info. +/// +/// ### Examples +/// Example of RML config file: +/// \code +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// \endcode +/// +/// Example to compute the the odds over a dataSet using restRoot: +/// \code +/// [0] TRestOdds odds ("odds.rml"); +/// [1] odds.SetDataSetName("myDataSet.root"); +/// [2] odds.SetOutputFileName("myComputedOddsDataSet.root"); +/// [3] odds.ComputeLogOdds(); +/// \endcode +/// +/// Example to compute the the odds over a dataSet with input odds file using restRoot: +/// \code +/// [0] TRestOdds odds ("odds.rml"); +/// [1] odds.SetDataSetName("myDataSet.root"); +/// [2] odds.SetOutputFileName("myComputedOddsDataSet.root"); +/// [3] odds.odds.SetOddsFile("myOddsDataSet.root"); +/// [4] odds.ComputeLogOdds(); +/// \endcode +/// +///---------------------------------------------------------------------- +/// +/// REST-for-Physics - Software for Rare Event Searches Toolkit +/// +/// History of developments: +/// +/// 2023-03: First implementation of TRestOdds +/// JuanAn Garcia +/// +/// \class TRestOdds +/// \author: JuanAn Garcia e-mail: juanangp@unizar.es +/// +///
+/// + +#include "TRestOdds.h" +#include "TRestDataSet.h" + +ClassImp(TRestOdds); + +/////////////////////////////////////////////// +/// \brief Default constructor +/// +TRestOdds::TRestOdds() { + Initialize(); +} + +///////////////////////////////////////////// +/// \brief Constructor loading data from a config file +/// +/// If no configuration path is defined using TRestMetadata::SetConfigFilePath +/// the path to the config file must be specified using full path, absolute or +/// relative. +/// +/// The default behaviour is that the config file must be specified with +/// full path, absolute or relative. +/// +/// \param configFilename A const char* that defines the RML filename. +/// \param name The name of the metadata section. It will be used to find the +/// corresponding TRestOdds section inside the RML. +/// +TRestOdds::TRestOdds(const char* configFilename, std::string name) : TRestMetadata(configFilename) { + LoadConfigFromFile(fConfigFileName, name); + Initialize(); + + if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) PrintMetadata(); +} + +/////////////////////////////////////////////// +/// \brief Default destructor +/// +TRestOdds::~TRestOdds() { +} + +/////////////////////////////////////////////// +/// \brief Function to initialize input/output event members and define +/// the section name +/// +void TRestOdds::Initialize() { + SetSectionName(this->ClassName()); +} + +/////////////////////////////////////////////// +/// \brief Function to initialize some variables from +/// configfile +/// +void TRestOdds::InitFromConfigFile() { + + Initialize(); + TRestMetadata::InitFromConfigFile(); + + TiXmlElement* obsDefinition = GetElement("observable"); + while (obsDefinition != nullptr) { + std::string obsName = GetFieldValue("name", obsDefinition); + if (obsName.empty() || obsName == "Not defined") { + RESTError << "< observable variable key does not contain a name!" << RESTendl; + exit(1); + } else { + fObsName.push_back(obsName); + } + + std::string range = GetFieldValue("range", obsDefinition); + if (range.empty() || range == "Not defined") { + RESTError << "< observable key does not contain a range value!" << RESTendl; + exit(1); + } else { + TVector2 roi = StringTo2DVector(range); + fObsRange.push_back(roi); + } + + std::string nBins = GetFieldValue("nBins", obsDefinition); + if (nBins.empty() || nBins == "Not defined") { + RESTError << "< observable key does not contain a nBins value!" << RESTendl; + exit(1); + } else { + fObsNbins.push_back(StringToInteger(nBins)); + } + + obsDefinition = GetNextElement(obsDefinition); + } + + if(fObsName.empty() || fObsRange.empty () ){ + RESTError << "No observables provided, exiting..." << RESTendl; + exit(1); + } + + if(fOutputFileName == "")fOutputFileName = GetParameter("outputFileName",""); + + fCut = (TRestCut*)InstantiateChildMetadata("TRestCut"); + +} + +///////////////////////////////////////////// +/// \brief This function computes the log odds for +/// a given dataSet. If no calibration odds file is +/// provided it computes the PDF for the given +/// 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. +/// +void TRestOdds::ComputeLogOdds( ){ + + PrintMetadata(); + + TRestDataSet dataSet; + dataSet.Import(fDataSetName); + + if(fOddsFile.empty()){ + auto DF = dataSet.MakeCut(fCut); + for(size_t i=0; i(histo->DrawClone()); + h->Scale(1./h->Integral()); + fHistos[obsName] = h; + } + } else { + TFile *f = TFile::Open(fOddsFile.c_str()); + if(f==nullptr){ + RESTError << "Cannot open calibration odds file " << fOddsFile << RESTendl; + exit(1); + } + std::cout<<"Opening "<< fOddsFile <Get(histName.c_str()); + fHistos[obsName] = h; + } + } + + auto df = dataSet.GetDataFrame(); + std::string totName = ""; + for(const auto &[obsName, histo] : fHistos){ + const std::string oddsName = "odds_" + obsName; + auto GetLogOdds = [&histo] (double val) { + double odds = histo->GetBinContent (histo->GetXaxis()->FindBin(val)); + if(odds == 0 )return 1000.; + return log(1. - odds) - log(odds); + }; + df = df.Define(oddsName, GetLogOdds, {obsName} ); + auto h = df.Histo1D(oddsName); + + if(!totName.empty()) totName += "+"; + totName += oddsName; + } + + df = df.Define("odds_total", totName); + + dataSet.SetDataSet(df); + + if(!fOutputFileName.empty()){ + if(TRestTools::GetFileNameExtension(fOutputFileName) == "root"){ + dataSet.Export(fOutputFileName); + TFile* f = TFile::Open(fOutputFileName.c_str(), "UPDATE"); + this->Write(); + for(const auto &[obsName, histo] : fHistos)histo->Write(); + f->Close(); + } + } +} + +///////////////////////////////////////////// +/// \brief Prints on screen the information about the metadata members of TRestOdds +/// +void TRestOdds::PrintMetadata() { + TRestMetadata::PrintMetadata(); + + RESTMetadata << " Observables to compute: " << RESTendl; + for(size_t i=0; i Date: Mon, 27 Mar 2023 18:43:51 +0000 Subject: [PATCH 03/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../framework/analysis/inc/TRestCalibration.h | 32 ++- source/framework/analysis/inc/TRestOdds.h | 26 +- .../analysis/src/TRestCalibration.cxx | 237 +++++++++--------- source/framework/analysis/src/TRestOdds.cxx | 198 +++++++-------- 4 files changed, 238 insertions(+), 255 deletions(-) diff --git a/source/framework/analysis/inc/TRestCalibration.h b/source/framework/analysis/inc/TRestCalibration.h index ce8a0e006..9721e94cf 100644 --- a/source/framework/analysis/inc/TRestCalibration.h +++ b/source/framework/analysis/inc/TRestCalibration.h @@ -27,18 +27,17 @@ /// This class is meant to perform the calibration of different runs class TRestCalibration : public TRestMetadata { -private: - + private: // Name of the output file std::string fOutputFileName = ""; // Name of the dataSet inside the config file std::string fDataSetName = ""; - // Vector containing expected energy peaks in keV must be sorted - std::vector< double > fEnergyPeaks; + // Vector containing expected energy peaks in keV must be sorted + std::vector fEnergyPeaks; // Vector containing calibrated peaks in ADCs - std::vector< double > fCalibPeaks; + std::vector fCalibPeaks; // Vector containing calibrated sigma in ADCs - std::vector< double > fCalibFWHM; + std::vector fCalibFWHM; // Name of the calibration file to be used std::string fCalibFile = ""; // Calibration variable to be used @@ -55,27 +54,26 @@ class TRestCalibration : public TRestMetadata { void Initialize() override; void InitFromConfigFile() override; -public: + public: void PrintMetadata() override; - void Calibrate( ); + void Calibrate(); - inline void SetDataSetName (const std::string &dSName) {fDataSetName = dSName;} - inline void SetOutputFileName (const std::string &outName) {fOutputFileName = outName;} - inline void SetCalibrationFile (const std::string &calibFile) {fCalibFile = calibFile;} + inline void SetDataSetName(const std::string& dSName) { fDataSetName = dSName; } + inline void SetOutputFileName(const std::string& outName) { fOutputFileName = outName; } + inline void SetCalibrationFile(const std::string& calibFile) { fCalibFile = calibFile; } - inline auto GetCalibPeaks() const {return fCalibPeaks;} - inline auto GetCalibFWHM() const {return fCalibFWHM;} + inline auto GetCalibPeaks() const { return fCalibPeaks; } + inline auto GetCalibFWHM() const { return fCalibFWHM; } - inline double GetSlope() const {return fSlope;} - inline double GetIntercept() const {return fIntercept;} - inline std::string GetCalObservable() const {return fCalObservable;} + inline double GetSlope() const { return fSlope; } + inline double GetIntercept() const { return fIntercept; } + inline std::string GetCalObservable() const { return fCalObservable; } TRestCalibration(); TRestCalibration(const char* configFilename, std::string name = ""); ~TRestCalibration(); ClassDefOverride(TRestCalibration, 1); - }; #endif diff --git a/source/framework/analysis/inc/TRestOdds.h b/source/framework/analysis/inc/TRestOdds.h index db7acf963..970f8e2d4 100644 --- a/source/framework/analysis/inc/TRestOdds.h +++ b/source/framework/analysis/inc/TRestOdds.h @@ -23,50 +23,48 @@ #ifndef REST_TRestOdds #define REST_TRestOdds -#include "TRestMetadata.h" -#include "TRestCut.h" #include "TH1F.h" +#include "TRestCut.h" +#include "TRestMetadata.h" /// This class is meant to compute the log odds for different datasets class TRestOdds : public TRestMetadata { -private: - + private: // Name of the output file std::string fOutputFileName = ""; // Name of the dataSet inside the config file std::string fDataSetName = ""; // Vector containing different obserbable names - std::vector fObsName; + std::vector fObsName; // Vector containing different obserbable ranges - std::vector fObsRange; + std::vector fObsRange; // Vector containing number of bins for the different observables - std::vector fObsNbins; + std::vector fObsNbins; // Name of the odds file to be used to get the PDF std::string fOddsFile = ""; /// Cuts over the dataset for PDF selection - TRestCut *fCut = nullptr; + TRestCut* fCut = nullptr; // Map containing the PDF of the different observables - std::map fHistos; //! + std::map fHistos; //! void Initialize() override; void InitFromConfigFile() override; -public: + public: void PrintMetadata() override; void ComputeLogOdds(); - inline void SetDataSetName (const std::string &dSName) {fDataSetName = dSName;} - inline void SetOutputFileName (const std::string &outName) {fOutputFileName = outName;} - inline void SetOddsFile (const std::string &oddsFile) {fOddsFile = oddsFile;} + inline void SetDataSetName(const std::string& dSName) { fDataSetName = dSName; } + inline void SetOutputFileName(const std::string& outName) { fOutputFileName = outName; } + inline void SetOddsFile(const std::string& oddsFile) { fOddsFile = oddsFile; } TRestOdds(); TRestOdds(const char* configFilename, std::string name = ""); ~TRestOdds(); ClassDefOverride(TRestOdds, 1); - }; #endif diff --git a/source/framework/analysis/src/TRestCalibration.cxx b/source/framework/analysis/src/TRestCalibration.cxx index 67736a745..e6883977a 100644 --- a/source/framework/analysis/src/TRestCalibration.cxx +++ b/source/framework/analysis/src/TRestCalibration.cxx @@ -21,11 +21,11 @@ *************************************************************************/ ///////////////////////////////////////////////////////////////////////// -/// TRestCalibration performs the calibration of a TRestDataSet, the +/// TRestCalibration performs the calibration of a TRestDataSet, the /// calibration is performed over different peaks provided in the config /// file, in which the first peak should corresponds to the maximum in the /// spectrum histogram. -/// +/// /// A summary of the basic parameters is described below: /// * **calObservable**: Name of the observable to be calibrated /// * **nBins**: Number of bins for the calibration spectra @@ -35,25 +35,25 @@ /// * **calibFile**: Name of the calibration file to be used for /// the calibration parameters, if empty it performs the calibration /// over the dataSet provided. -/// +/// /// The energy peaks to calibrate are given using peak metadata: /// * **energy**: Energy of the peak(s) to be calibrated in keV, /// note that the first peak should correspond to the maximum /// /// The following metadata members are used as output after the fit: -/// * **calibPeaks**: Position of the mean value of the peak after +/// * **calibPeaks**: Position of the mean value of the peak after /// the fit using the same order as the energy peaks /// * **fCalibFWHM**: FWHM in percentage for the different peaks, /// using the same order as the energy peaks. -/// +/// /// If an output file name is provided a new dataset will be generated /// with the corresponding metadata and calibration constants, while /// adding a new observable, calib_energy. In addition, the spectrum /// and the fit results will be stored in the output file. -/// +/// /// /// ### Examples -/// RML example to calibrate a dataset with a peak at 5.89 keV +/// RML example to calibrate a dataset with a peak at 5.89 keV /// \code /// /// @@ -63,7 +63,7 @@ /// /// /// \endcode -/// +/// /// Example to perform calibration over a calibration dataSet using restRoot: /// \code /// [0] TRestCalibration cal ("calibration.rml"); @@ -71,7 +71,7 @@ /// [2] cal.SetOutputFileName("myCalibratedDataSet.root"); /// [3] cal.Calibrate(); /// \endcode -/// +/// /// Example to perform calibration over a background dataSet using restRoot: /// \code /// [0] TRestCalibration cal ("calibration.rml"); @@ -80,33 +80,32 @@ /// [3] cal.SetCalibrationFile("myCalibratedDataSet.root"); /// [4] cal.Calibrate(); /// \endcode -/// +/// ///---------------------------------------------------------------------- -/// -/// REST-for-Physics - Software for Rare Event Searches Toolkit -/// -/// History of developments: -/// +/// +/// REST-for-Physics - Software for Rare Event Searches Toolkit +/// +/// History of developments: +/// /// 2023-03: First implementation of TRestCalibration -/// JuanAn Garcia -/// -/// \class TRestCalibration +/// JuanAn Garcia +/// +/// \class TRestCalibration /// \author: JuanAn Garcia e-mail: juanangp@unizar.es -/// -///
-/// +/// +///
+/// #include "TRestCalibration.h" + #include "TRestDataSet.h" ClassImp(TRestCalibration); -/////////////////////////////////////////////// -/// \brief Default constructor -/// -TRestCalibration::TRestCalibration() { - Initialize(); -} +/////////////////////////////////////////////// +/// \brief Default constructor +/// +TRestCalibration::TRestCalibration() { Initialize(); } ///////////////////////////////////////////// /// \brief Constructor loading data from a config file @@ -122,57 +121,53 @@ TRestCalibration::TRestCalibration() { /// \param name The name of the metadata section. It will be used to find the /// corresponding TRestCalibration section inside the RML. /// -TRestCalibration::TRestCalibration(const char* configFilename, std::string name) : TRestMetadata(configFilename) { +TRestCalibration::TRestCalibration(const char* configFilename, std::string name) + : TRestMetadata(configFilename) { LoadConfigFromFile(fConfigFileName, name); Initialize(); if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) PrintMetadata(); } -/////////////////////////////////////////////// -/// \brief Default destructor -/// -TRestCalibration::~TRestCalibration() { -} +/////////////////////////////////////////////// +/// \brief Default destructor +/// +TRestCalibration::~TRestCalibration() {} -/////////////////////////////////////////////// -/// \brief Function to initialize input/output event members and define -/// the section name -/// -void TRestCalibration::Initialize() { - SetSectionName(this->ClassName()); -} +/////////////////////////////////////////////// +/// \brief Function to initialize input/output event members and define +/// the section name +/// +void TRestCalibration::Initialize() { SetSectionName(this->ClassName()); } -/////////////////////////////////////////////// +/////////////////////////////////////////////// /// \brief Function to initialize some variables from /// configfile, in case that the variable is not found -/// in the rml it checks the input file pattern. -/// +/// in the rml it checks the input file pattern. +/// void TRestCalibration::InitFromConfigFile() { - Initialize(); TRestMetadata::InitFromConfigFile(); TiXmlElement* peakDefinition = GetElement("peak"); while (peakDefinition != nullptr) { std::string energy = GetFieldValue("energy", peakDefinition); - if (energy.empty() || energy == "Not defined") { + if (energy.empty() || energy == "Not defined") { RESTError << "< peak variable key does not contain energy!" << RESTendl; exit(1); - } else { - fEnergyPeaks.push_back(StringToDouble( energy ) ); - } + } else { + fEnergyPeaks.push_back(StringToDouble(energy)); + } - peakDefinition = GetNextElement(peakDefinition); + peakDefinition = GetNextElement(peakDefinition); } - if(fEnergyPeaks.empty()){ + if (fEnergyPeaks.empty()) { RESTError << "Energy peaks not provided, exiting..." << RESTendl; exit(1); } - if(fOutputFileName == "")fOutputFileName = GetParameter("outputFileName",""); - + if (fOutputFileName == "") fOutputFileName = GetParameter("outputFileName", ""); } ///////////////////////////////////////////// @@ -182,8 +177,7 @@ void TRestCalibration::InitFromConfigFile() { /// Otherwise, it takes the calibration constants from the /// provided calibration file. /// -void TRestCalibration::Calibrate(){ - +void TRestCalibration::Calibrate() { PrintMetadata(); TRestDataSet dataSet; @@ -195,83 +189,82 @@ void TRestCalibration::Calibrate(){ std::unique_ptr gr; std::unique_ptr linearFit; - if(fCalibFile.empty()){ - - auto histo = dataSet.GetDataFrame().Histo1D( -{"spectrum","spectrum",fNBins,fCalibRange.X(),fCalibRange.X()}, fCalObservable); - spectrum = std::unique_ptr (static_cast(histo->DrawClone()) ); - - // Get position of the maximum - const double max = spectrum->GetBinCenter(spectrum->GetMaximumBin()); - // Get ratio between maximum and energy peak - const double ratio = max/fEnergyPeaks.front(); - - RESTDebug << "Max peak position " << max << RESTendl; - - std::vector gauss; - gr = std::unique_ptr(new TGraph()); - gr->SetName ("grFit"); - - int c=0; - for(const auto & energy : fEnergyPeaks){ - std::string fName = "g"+ std::to_string(c); - double pos = energy * ratio; - double start = pos * 0.85; - double end = pos * 1.15; - TF1 *g = new TF1(fName.c_str(), "gaus", start, end); - RESTDebug << "Fitting gaussian " << pos << " " << start <<" " << end << RESTendl; - spectrum->Fit(g,"R+"); - gauss.emplace_back(g); - gr->SetPoint(c, g->GetParameter(1), energy); - fCalibPeaks.push_back(g->GetParameter(1)); - fCalibFWHM.push_back(g->GetParameter(2)*235./g->GetParameter(1)); - c++; - } - - if(GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)GetChar(); - - gr->SetPoint(c,0,0); - - gr->Draw("AP"); - linearFit = std::unique_ptr (new TF1("linearFit", "pol1")); - gr->Fit("linearFit","S"); + if (fCalibFile.empty()) { + auto histo = dataSet.GetDataFrame().Histo1D( + {"spectrum", "spectrum", fNBins, fCalibRange.X(), fCalibRange.X()}, fCalObservable); + spectrum = std::unique_ptr(static_cast(histo->DrawClone())); + + // Get position of the maximum + const double max = spectrum->GetBinCenter(spectrum->GetMaximumBin()); + // Get ratio between maximum and energy peak + const double ratio = max / fEnergyPeaks.front(); + + RESTDebug << "Max peak position " << max << RESTendl; + + std::vector gauss; + gr = std::unique_ptr(new TGraph()); + gr->SetName("grFit"); + + int c = 0; + for (const auto& energy : fEnergyPeaks) { + std::string fName = "g" + std::to_string(c); + double pos = energy * ratio; + double start = pos * 0.85; + double end = pos * 1.15; + TF1* g = new TF1(fName.c_str(), "gaus", start, end); + RESTDebug << "Fitting gaussian " << pos << " " << start << " " << end << RESTendl; + spectrum->Fit(g, "R+"); + gauss.emplace_back(g); + gr->SetPoint(c, g->GetParameter(1), energy); + fCalibPeaks.push_back(g->GetParameter(1)); + fCalibFWHM.push_back(g->GetParameter(2) * 235. / g->GetParameter(1)); + c++; + } + + if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) GetChar(); + + gr->SetPoint(c, 0, 0); + + gr->Draw("AP"); + linearFit = std::unique_ptr(new TF1("linearFit", "pol1")); + gr->Fit("linearFit", "S"); } else { - TFile *f = TFile::Open(fCalibFile.c_str()); - if(f==nullptr){ - RESTError << "Cannot open calibration file "<< fCalibFile << RESTendl; - exit(1); + TFile* f = TFile::Open(fCalibFile.c_str()); + if (f == nullptr) { + RESTError << "Cannot open calibration file " << fCalibFile << RESTendl; + exit(1); } - RESTInfo << "Opening "<< fCalibFile << RESTendl; - gr = std::unique_ptr(f->Get("grFit")); - linearFit = std::unique_ptr (f->Get("linearFit") ); + RESTInfo << "Opening " << fCalibFile << RESTendl; + gr = std::unique_ptr(f->Get("grFit")); + linearFit = std::unique_ptr(f->Get("linearFit")); } fSlope = linearFit->GetParameter(1); fIntercept = linearFit->GetParameter(0); - RESTDebug<<"Slope "<GetParameter(1)*val + linearFit->GetParameter(0); + auto calibrate = [&linearFit](double val) { + return linearFit->GetParameter(1) * val + linearFit->GetParameter(0); }; - df = df.Define("calib_Energy", calibrate, {fCalObservable}); + df = df.Define("calib_Energy", calibrate, {fCalObservable}); dataSet.SetDataSet(df); - if(!fOutputFileName.empty()){ - if(TRestTools::GetFileNameExtension(fOutputFileName) == "root"){ - dataSet.Export(fOutputFileName); - TFile* f = TFile::Open(fOutputFileName.c_str(), "UPDATE"); - this->Write(); - if(gr)gr->Write(); - if(linearFit)linearFit->Write(); - //if(lFit)lFit->Write(); - //spectrumFit->Write(); - if(spectrum)spectrum->Write(); - f->Close(); - } + if (!fOutputFileName.empty()) { + if (TRestTools::GetFileNameExtension(fOutputFileName) == "root") { + dataSet.Export(fOutputFileName); + TFile* f = TFile::Open(fOutputFileName.c_str(), "UPDATE"); + this->Write(); + if (gr) gr->Write(); + if (linearFit) linearFit->Write(); + // if(lFit)lFit->Write(); + // spectrumFit->Write(); + if (spectrum) spectrum->Write(); + f->Close(); + } } } @@ -282,18 +275,18 @@ void TRestCalibration::PrintMetadata() { TRestMetadata::PrintMetadata(); RESTMetadata << " Energy peaks to calibrate: "; - for (const auto& peak : fEnergyPeaks)RESTMetadata << peak <<" keV; "; + for (const auto& peak : fEnergyPeaks) RESTMetadata << peak << " keV; "; RESTMetadata << RESTendl; RESTMetadata << " Calibrated peak position: "; - for (const auto& peak : fCalibPeaks)RESTMetadata << peak <<" ADC; "; + for (const auto& peak : fCalibPeaks) RESTMetadata << peak << " ADC; "; RESTMetadata << RESTendl; RESTMetadata << " Calibrated FWHM: "; - for (const auto& fwhm : fCalibFWHM)RESTMetadata << fwhm <<" %; "; + for (const auto& fwhm : fCalibFWHM) RESTMetadata << fwhm << " %; "; RESTMetadata << RESTendl; RESTMetadata << "Observable to calibrate: " << fCalObservable << RESTendl; - RESTMetadata << "Calibration range: ("<< fCalibRange.X() <<", "<< fCalibRange.Y() <<")" << RESTendl; + RESTMetadata << "Calibration range: (" << fCalibRange.X() << ", " << fCalibRange.Y() << ")" << RESTendl; RESTMetadata << "Number of bins: " << fNBins << RESTendl; RESTMetadata << "Slope: " << fSlope << " keV/ADC" << RESTendl; - RESTMetadata << "Intercept: " < @@ -48,9 +48,9 @@ /// /// In addition a TRestCut is used as input for the generation of PDFs, check TRestCut /// class for more info. -/// +/// /// ### Examples -/// Example of RML config file: +/// Example of RML config file: /// \code /// /// @@ -68,7 +68,7 @@ /// /// /// \endcode -/// +/// /// Example to compute the the odds over a dataSet using restRoot: /// \code /// [0] TRestOdds odds ("odds.rml"); @@ -84,34 +84,33 @@ /// [2] odds.SetOutputFileName("myComputedOddsDataSet.root"); /// [3] odds.odds.SetOddsFile("myOddsDataSet.root"); /// [4] odds.ComputeLogOdds(); -/// \endcode -/// +/// \endcode +/// ///---------------------------------------------------------------------- -/// -/// REST-for-Physics - Software for Rare Event Searches Toolkit -/// -/// History of developments: -/// +/// +/// REST-for-Physics - Software for Rare Event Searches Toolkit +/// +/// History of developments: +/// /// 2023-03: First implementation of TRestOdds -/// JuanAn Garcia -/// -/// \class TRestOdds +/// JuanAn Garcia +/// +/// \class TRestOdds /// \author: JuanAn Garcia e-mail: juanangp@unizar.es -/// -///
-/// +/// +///
+/// #include "TRestOdds.h" + #include "TRestDataSet.h" ClassImp(TRestOdds); -/////////////////////////////////////////////// -/// \brief Default constructor -/// -TRestOdds::TRestOdds() { - Initialize(); -} +/////////////////////////////////////////////// +/// \brief Default constructor +/// +TRestOdds::TRestOdds() { Initialize(); } ///////////////////////////////////////////// /// \brief Constructor loading data from a config file @@ -134,68 +133,63 @@ TRestOdds::TRestOdds(const char* configFilename, std::string name) : TRestMetada if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) PrintMetadata(); } -/////////////////////////////////////////////// -/// \brief Default destructor -/// -TRestOdds::~TRestOdds() { -} +/////////////////////////////////////////////// +/// \brief Default destructor +/// +TRestOdds::~TRestOdds() {} -/////////////////////////////////////////////// -/// \brief Function to initialize input/output event members and define -/// the section name -/// -void TRestOdds::Initialize() { - SetSectionName(this->ClassName()); -} +/////////////////////////////////////////////// +/// \brief Function to initialize input/output event members and define +/// the section name +/// +void TRestOdds::Initialize() { SetSectionName(this->ClassName()); } -/////////////////////////////////////////////// +/////////////////////////////////////////////// /// \brief Function to initialize some variables from -/// configfile -/// +/// configfile +/// void TRestOdds::InitFromConfigFile() { - Initialize(); TRestMetadata::InitFromConfigFile(); TiXmlElement* obsDefinition = GetElement("observable"); while (obsDefinition != nullptr) { std::string obsName = GetFieldValue("name", obsDefinition); - if (obsName.empty() || obsName == "Not defined") { + if (obsName.empty() || obsName == "Not defined") { RESTError << "< observable variable key does not contain a name!" << RESTendl; exit(1); - } else { + } else { fObsName.push_back(obsName); - } + } std::string range = GetFieldValue("range", obsDefinition); - if (range.empty() || range == "Not defined") { + if (range.empty() || range == "Not defined") { RESTError << "< observable key does not contain a range value!" << RESTendl; exit(1); } else { - TVector2 roi = StringTo2DVector(range); - fObsRange.push_back(roi); + TVector2 roi = StringTo2DVector(range); + fObsRange.push_back(roi); } std::string nBins = GetFieldValue("nBins", obsDefinition); - if (nBins.empty() || nBins == "Not defined") { + if (nBins.empty() || nBins == "Not defined") { RESTError << "< observable key does not contain a nBins value!" << RESTendl; exit(1); } else { - fObsNbins.push_back(StringToInteger(nBins)); + fObsNbins.push_back(StringToInteger(nBins)); } obsDefinition = GetNextElement(obsDefinition); } - if(fObsName.empty() || fObsRange.empty () ){ + if (fObsName.empty() || fObsRange.empty()) { RESTError << "No observables provided, exiting..." << RESTendl; exit(1); } - if(fOutputFileName == "")fOutputFileName = GetParameter("outputFileName",""); + if (fOutputFileName == "") fOutputFileName = GetParameter("outputFileName", ""); fCut = (TRestCut*)InstantiateChildMetadata("TRestCut"); - } ///////////////////////////////////////////// @@ -207,69 +201,68 @@ void TRestOdds::InitFromConfigFile() { /// odds_obsName and the addition of all of them for a further /// processing, which is stored in odds_total observable. /// -void TRestOdds::ComputeLogOdds( ){ - +void TRestOdds::ComputeLogOdds() { PrintMetadata(); TRestDataSet dataSet; dataSet.Import(fDataSetName); - if(fOddsFile.empty()){ - auto DF = dataSet.MakeCut(fCut); - for(size_t i=0; i(histo->DrawClone()); - h->Scale(1./h->Integral()); - fHistos[obsName] = h; + if (fOddsFile.empty()) { + auto DF = dataSet.MakeCut(fCut); + 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 int nBins = fObsNbins[i]; + auto histo = + DF.Histo1D({histName.c_str(), histName.c_str(), nBins, range.X(), range.Y()}, obsName); + TH1F* h = static_cast(histo->DrawClone()); + h->Scale(1. / h->Integral()); + fHistos[obsName] = h; } - } else { - TFile *f = TFile::Open(fOddsFile.c_str()); - if(f==nullptr){ - RESTError << "Cannot open calibration odds file " << fOddsFile << RESTendl; - exit(1); + } else { + TFile* f = TFile::Open(fOddsFile.c_str()); + if (f == nullptr) { + RESTError << "Cannot open calibration odds file " << fOddsFile << RESTendl; + exit(1); } - std::cout<<"Opening "<< fOddsFile <Get(histName.c_str()); - fHistos[obsName] = h; + std::cout << "Opening " << fOddsFile << std::endl; + for (size_t i = 0; i < fObsName.size(); i++) { + const std::string obsName = fObsName[i]; + const std::string histName = "h" + obsName; + TH1F* h = (TH1F*)f->Get(histName.c_str()); + fHistos[obsName] = h; } - } + } auto df = dataSet.GetDataFrame(); std::string totName = ""; - for(const auto &[obsName, histo] : fHistos){ - const std::string oddsName = "odds_" + obsName; - auto GetLogOdds = [&histo] (double val) { - double odds = histo->GetBinContent (histo->GetXaxis()->FindBin(val)); - if(odds == 0 )return 1000.; - return log(1. - odds) - log(odds); - }; - df = df.Define(oddsName, GetLogOdds, {obsName} ); - auto h = df.Histo1D(oddsName); + for (const auto& [obsName, histo] : fHistos) { + const std::string oddsName = "odds_" + obsName; + auto GetLogOdds = [&histo](double val) { + double odds = histo->GetBinContent(histo->GetXaxis()->FindBin(val)); + if (odds == 0) return 1000.; + return log(1. - odds) - log(odds); + }; + df = df.Define(oddsName, GetLogOdds, {obsName}); + auto h = df.Histo1D(oddsName); - if(!totName.empty()) totName += "+"; - totName += oddsName; - } + if (!totName.empty()) totName += "+"; + totName += oddsName; + } df = df.Define("odds_total", totName); dataSet.SetDataSet(df); - if(!fOutputFileName.empty()){ - if(TRestTools::GetFileNameExtension(fOutputFileName) == "root"){ - dataSet.Export(fOutputFileName); - TFile* f = TFile::Open(fOutputFileName.c_str(), "UPDATE"); - this->Write(); - for(const auto &[obsName, histo] : fHistos)histo->Write(); - f->Close(); - } + if (!fOutputFileName.empty()) { + if (TRestTools::GetFileNameExtension(fOutputFileName) == "root") { + dataSet.Export(fOutputFileName); + TFile* f = TFile::Open(fOutputFileName.c_str(), "UPDATE"); + this->Write(); + for (const auto& [obsName, histo] : fHistos) histo->Write(); + f->Close(); + } } } @@ -280,8 +273,9 @@ void TRestOdds::PrintMetadata() { TRestMetadata::PrintMetadata(); RESTMetadata << " Observables to compute: " << RESTendl; - for(size_t i=0; i Date: Tue, 28 Mar 2023 09:40:22 +0200 Subject: [PATCH 04/11] Addresssing typo Co-authored-by: Javier Galan --- source/framework/analysis/src/TRestOdds.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/framework/analysis/src/TRestOdds.cxx b/source/framework/analysis/src/TRestOdds.cxx index a7aaf0772..a2ec735c1 100644 --- a/source/framework/analysis/src/TRestOdds.cxx +++ b/source/framework/analysis/src/TRestOdds.cxx @@ -38,7 +38,7 @@ /// * **oddsFile**: Name of the input odds file to be used for the definition of the /// different PDFs. /// -/// The different obserbables, range and nBins are added as follow: +/// The different observables, range and nBins are added as follow: /// \code /// /// \endcode From c01f386629aacfab5b63aa8693938828a7e26569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Tue, 28 Mar 2023 09:42:31 +0200 Subject: [PATCH 05/11] Removing unnecessary comment Co-authored-by: Javier Galan --- source/framework/analysis/src/TRestOdds.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/source/framework/analysis/src/TRestOdds.cxx b/source/framework/analysis/src/TRestOdds.cxx index a2ec735c1..e6a442328 100644 --- a/source/framework/analysis/src/TRestOdds.cxx +++ b/source/framework/analysis/src/TRestOdds.cxx @@ -21,7 +21,6 @@ *************************************************************************/ ///////////////////////////////////////////////////////////////////////// -/// Write the class description Here /// TRestOdds performs the log odds of the different observables given /// in the config file and for a particular dataSet. To perform the log odds /// first the probability density funcion (PDF) is obtained for a set of From 8fcea7180d6f186eada3af6ce41b4a8456a7b345 Mon Sep 17 00:00:00 2001 From: juanan Date: Tue, 28 Mar 2023 09:46:50 +0200 Subject: [PATCH 06/11] Addressing PR comments --- .../framework/analysis/inc/TRestCalibration.h | 33 ++++++++++++------- source/framework/analysis/inc/TRestOdds.h | 20 +++++++---- .../analysis/src/TRestCalibration.cxx | 5 +-- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/source/framework/analysis/inc/TRestCalibration.h b/source/framework/analysis/inc/TRestCalibration.h index 9721e94cf..bbaa518f9 100644 --- a/source/framework/analysis/inc/TRestCalibration.h +++ b/source/framework/analysis/inc/TRestCalibration.h @@ -28,27 +28,38 @@ /// This class is meant to perform the calibration of different runs class TRestCalibration : public TRestMetadata { private: - // Name of the output file + + /// Name of the output file std::string fOutputFileName = ""; - // Name of the dataSet inside the config file + + /// Name of the dataSet inside the config file std::string fDataSetName = ""; - // Vector containing expected energy peaks in keV must be sorted + + /// Vector containing expected energy peaks in keV must be sorted std::vector fEnergyPeaks; - // Vector containing calibrated peaks in ADCs + + /// Vector containing calibrated peaks in ADCs std::vector fCalibPeaks; - // Vector containing calibrated sigma in ADCs + + /// Vector containing calibrated sigma in ADCs std::vector fCalibFWHM; - // Name of the calibration file to be used + + /// Name of the calibration file to be used std::string fCalibFile = ""; - // Calibration variable to be used + + /// Calibration variable to be used std::string fCalObservable = ""; - // Range to be calibrated + + /// Range to be calibrated TVector2 fCalibRange; - // Number of bins used in the calibration + + /// Number of bins used in the calibration Int_t fNBins; - // Slope from the calibration fit + + /// Slope from the calibration fit Double_t fSlope = 0; - // Intercept of the calibration fit + + /// Intercept of the calibration fit Double_t fIntercept = 0; void Initialize() override; diff --git a/source/framework/analysis/inc/TRestOdds.h b/source/framework/analysis/inc/TRestOdds.h index 970f8e2d4..e50378319 100644 --- a/source/framework/analysis/inc/TRestOdds.h +++ b/source/framework/analysis/inc/TRestOdds.h @@ -30,23 +30,29 @@ /// This class is meant to compute the log odds for different datasets class TRestOdds : public TRestMetadata { private: - // Name of the output file + + /// Name of the output file std::string fOutputFileName = ""; - // Name of the dataSet inside the config file + + /// Name of the dataSet inside the config file std::string fDataSetName = ""; - // Vector containing different obserbable names + + /// Vector containing different obserbable names std::vector fObsName; - // Vector containing different obserbable ranges + + /// Vector containing different obserbable ranges std::vector fObsRange; - // Vector containing number of bins for the different observables + + /// Vector containing number of bins for the different observables std::vector fObsNbins; - // Name of the odds file to be used to get the PDF + + /// Name of the odds file to be used to get the PDF std::string fOddsFile = ""; /// Cuts over the dataset for PDF selection TRestCut* fCut = nullptr; - // Map containing the PDF of the different observables + /// Map containing the PDF of the different observables std::map fHistos; //! void Initialize() override; diff --git a/source/framework/analysis/src/TRestCalibration.cxx b/source/framework/analysis/src/TRestCalibration.cxx index e6883977a..227143f2b 100644 --- a/source/framework/analysis/src/TRestCalibration.cxx +++ b/source/framework/analysis/src/TRestCalibration.cxx @@ -23,8 +23,9 @@ ///////////////////////////////////////////////////////////////////////// /// TRestCalibration performs the calibration of a TRestDataSet, the /// calibration is performed over different peaks provided in the config -/// file, in which the first peak should corresponds to the maximum in the -/// spectrum histogram. +/// file. The first peak provided in the config file should correspond +/// to the maximum in the spectra. The expected position of the rest +/// of the peaks are estimated with respect to the maximum. /// /// A summary of the basic parameters is described below: /// * **calObservable**: Name of the observable to be calibrated From 70e45238dcb7b01f1c2bbd321a9877d023a46fb7 Mon Sep 17 00:00:00 2001 From: juanan Date: Tue, 28 Mar 2023 09:48:42 +0200 Subject: [PATCH 07/11] Renaming TRestCalibration to TRestDataSetCalibration --- .../inc/{TRestCalibration.h => TRestDataSetCalibration.h} | 0 .../src/{TRestCalibration.cxx => TRestDataSetCalibration.cxx} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename source/framework/analysis/inc/{TRestCalibration.h => TRestDataSetCalibration.h} (100%) rename source/framework/analysis/src/{TRestCalibration.cxx => TRestDataSetCalibration.cxx} (100%) diff --git a/source/framework/analysis/inc/TRestCalibration.h b/source/framework/analysis/inc/TRestDataSetCalibration.h similarity index 100% rename from source/framework/analysis/inc/TRestCalibration.h rename to source/framework/analysis/inc/TRestDataSetCalibration.h diff --git a/source/framework/analysis/src/TRestCalibration.cxx b/source/framework/analysis/src/TRestDataSetCalibration.cxx similarity index 100% rename from source/framework/analysis/src/TRestCalibration.cxx rename to source/framework/analysis/src/TRestDataSetCalibration.cxx From 92a7d6691e0da9a0e37caf514949576a92979712 Mon Sep 17 00:00:00 2001 From: juanan Date: Tue, 28 Mar 2023 09:49:57 +0200 Subject: [PATCH 08/11] Renaming TRestOdds to TRestDataSetOdds --- source/framework/analysis/inc/{TRestOdds.h => TRestDataSetOdds.h} | 0 .../analysis/src/{TRestOdds.cxx => TRestDataSetOdss.cxx} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename source/framework/analysis/inc/{TRestOdds.h => TRestDataSetOdds.h} (100%) rename source/framework/analysis/src/{TRestOdds.cxx => TRestDataSetOdss.cxx} (100%) diff --git a/source/framework/analysis/inc/TRestOdds.h b/source/framework/analysis/inc/TRestDataSetOdds.h similarity index 100% rename from source/framework/analysis/inc/TRestOdds.h rename to source/framework/analysis/inc/TRestDataSetOdds.h diff --git a/source/framework/analysis/src/TRestOdds.cxx b/source/framework/analysis/src/TRestDataSetOdss.cxx similarity index 100% rename from source/framework/analysis/src/TRestOdds.cxx rename to source/framework/analysis/src/TRestDataSetOdss.cxx From 4e9db6c3cebd5b7d16d05f84e6dcca302bfa02f7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 Mar 2023 07:51:37 +0000 Subject: [PATCH 09/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/framework/analysis/inc/TRestDataSetCalibration.h | 1 - source/framework/analysis/inc/TRestDataSetOdds.h | 1 - source/framework/analysis/src/TRestDataSetCalibration.cxx | 5 ++--- source/framework/analysis/src/TRestDataSetOdss.cxx | 3 +-- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/source/framework/analysis/inc/TRestDataSetCalibration.h b/source/framework/analysis/inc/TRestDataSetCalibration.h index bbaa518f9..f8633dc32 100644 --- a/source/framework/analysis/inc/TRestDataSetCalibration.h +++ b/source/framework/analysis/inc/TRestDataSetCalibration.h @@ -28,7 +28,6 @@ /// This class is meant to perform the calibration of different runs class TRestCalibration : public TRestMetadata { private: - /// Name of the output file std::string fOutputFileName = ""; diff --git a/source/framework/analysis/inc/TRestDataSetOdds.h b/source/framework/analysis/inc/TRestDataSetOdds.h index e50378319..800db1dbc 100644 --- a/source/framework/analysis/inc/TRestDataSetOdds.h +++ b/source/framework/analysis/inc/TRestDataSetOdds.h @@ -30,7 +30,6 @@ /// This class is meant to compute the log odds for different datasets class TRestOdds : public TRestMetadata { private: - /// Name of the output file std::string fOutputFileName = ""; diff --git a/source/framework/analysis/src/TRestDataSetCalibration.cxx b/source/framework/analysis/src/TRestDataSetCalibration.cxx index 227143f2b..321a63ddb 100644 --- a/source/framework/analysis/src/TRestDataSetCalibration.cxx +++ b/source/framework/analysis/src/TRestDataSetCalibration.cxx @@ -23,8 +23,8 @@ ///////////////////////////////////////////////////////////////////////// /// TRestCalibration performs the calibration of a TRestDataSet, the /// calibration is performed over different peaks provided in the config -/// file. The first peak provided in the config file should correspond -/// to the maximum in the spectra. The expected position of the rest +/// file. The first peak provided in the config file should correspond +/// to the maximum in the spectra. The expected position of the rest /// of the peaks are estimated with respect to the maximum. /// /// A summary of the basic parameters is described below: @@ -98,7 +98,6 @@ /// #include "TRestCalibration.h" - #include "TRestDataSet.h" ClassImp(TRestCalibration); diff --git a/source/framework/analysis/src/TRestDataSetOdss.cxx b/source/framework/analysis/src/TRestDataSetOdss.cxx index e6a442328..1183b2866 100644 --- a/source/framework/analysis/src/TRestDataSetOdss.cxx +++ b/source/framework/analysis/src/TRestDataSetOdss.cxx @@ -100,9 +100,8 @@ ///
/// -#include "TRestOdds.h" - #include "TRestDataSet.h" +#include "TRestOdds.h" ClassImp(TRestOdds); From 7d8d6db6a22d982d5c0ed7e5a937ba2f281fa34f Mon Sep 17 00:00:00 2001 From: juanan Date: Tue, 28 Mar 2023 10:05:19 +0200 Subject: [PATCH 10/11] Addressing compilation issues after renaming --- .../analysis/inc/TRestDataSetCalibration.h | 14 ++++---- .../framework/analysis/inc/TRestDataSetOdds.h | 14 ++++---- .../analysis/src/TRestDataSetCalibration.cxx | 36 +++++++++---------- ...stDataSetOdss.cxx => TRestDataSetOdds.cxx} | 36 +++++++++---------- 4 files changed, 50 insertions(+), 50 deletions(-) rename source/framework/analysis/src/{TRestDataSetOdss.cxx => TRestDataSetOdds.cxx} (92%) diff --git a/source/framework/analysis/inc/TRestDataSetCalibration.h b/source/framework/analysis/inc/TRestDataSetCalibration.h index bbaa518f9..67434a89a 100644 --- a/source/framework/analysis/inc/TRestDataSetCalibration.h +++ b/source/framework/analysis/inc/TRestDataSetCalibration.h @@ -20,13 +20,13 @@ * For the list of contributors see $REST_PATH/CREDITS. * *************************************************************************/ -#ifndef REST_TRestCalibration -#define REST_TRestCalibration +#ifndef REST_TRestDataSetCalibration +#define REST_TRestDataSetCalibration #include "TRestMetadata.h" /// This class is meant to perform the calibration of different runs -class TRestCalibration : public TRestMetadata { +class TRestDataSetCalibration : public TRestMetadata { private: /// Name of the output file @@ -81,10 +81,10 @@ class TRestCalibration : public TRestMetadata { inline double GetIntercept() const { return fIntercept; } inline std::string GetCalObservable() const { return fCalObservable; } - TRestCalibration(); - TRestCalibration(const char* configFilename, std::string name = ""); - ~TRestCalibration(); + TRestDataSetCalibration(); + TRestDataSetCalibration(const char* configFilename, std::string name = ""); + ~TRestDataSetCalibration(); - ClassDefOverride(TRestCalibration, 1); + ClassDefOverride(TRestDataSetCalibration, 1); }; #endif diff --git a/source/framework/analysis/inc/TRestDataSetOdds.h b/source/framework/analysis/inc/TRestDataSetOdds.h index e50378319..35b0e0102 100644 --- a/source/framework/analysis/inc/TRestDataSetOdds.h +++ b/source/framework/analysis/inc/TRestDataSetOdds.h @@ -20,15 +20,15 @@ * For the list of contributors see $REST_PATH/CREDITS. * *************************************************************************/ -#ifndef REST_TRestOdds -#define REST_TRestOdds +#ifndef REST_TRestDataSetOdds +#define REST_TRestDataSetOdds #include "TH1F.h" #include "TRestCut.h" #include "TRestMetadata.h" /// This class is meant to compute the log odds for different datasets -class TRestOdds : public TRestMetadata { +class TRestDataSetOdds : public TRestMetadata { private: /// Name of the output file @@ -67,10 +67,10 @@ class TRestOdds : public TRestMetadata { inline void SetOutputFileName(const std::string& outName) { fOutputFileName = outName; } inline void SetOddsFile(const std::string& oddsFile) { fOddsFile = oddsFile; } - TRestOdds(); - TRestOdds(const char* configFilename, std::string name = ""); - ~TRestOdds(); + TRestDataSetOdds(); + TRestDataSetOdds(const char* configFilename, std::string name = ""); + ~TRestDataSetOdds(); - ClassDefOverride(TRestOdds, 1); + ClassDefOverride(TRestDataSetOdds, 1); }; #endif diff --git a/source/framework/analysis/src/TRestDataSetCalibration.cxx b/source/framework/analysis/src/TRestDataSetCalibration.cxx index 227143f2b..d9ecad2d6 100644 --- a/source/framework/analysis/src/TRestDataSetCalibration.cxx +++ b/source/framework/analysis/src/TRestDataSetCalibration.cxx @@ -21,7 +21,7 @@ *************************************************************************/ ///////////////////////////////////////////////////////////////////////// -/// TRestCalibration performs the calibration of a TRestDataSet, the +/// TRestDataSetCalibration performs the calibration of a TRestDataSet, the /// calibration is performed over different peaks provided in the config /// file. The first peak provided in the config file should correspond /// to the maximum in the spectra. The expected position of the rest @@ -56,18 +56,18 @@ /// ### Examples /// RML example to calibrate a dataset with a peak at 5.89 keV /// \code -/// +/// /// /// /// /// /// -/// +/// /// \endcode /// /// Example to perform calibration over a calibration dataSet using restRoot: /// \code -/// [0] TRestCalibration cal ("calibration.rml"); +/// [0] TRestDataSetCalibration cal ("calibration.rml"); /// [1] cal.SetDataSetName("myDataSet.root"); /// [2] cal.SetOutputFileName("myCalibratedDataSet.root"); /// [3] cal.Calibrate(); @@ -75,7 +75,7 @@ /// /// Example to perform calibration over a background dataSet using restRoot: /// \code -/// [0] TRestCalibration cal ("calibration.rml"); +/// [0] TRestDataSetCalibration cal ("calibration.rml"); /// [1] cal.SetDataSetName("myBackgroundDataSet.root"); /// [2] cal.SetOutputFileName("myBackgroundCalibratedDataSet.root"); /// [3] cal.SetCalibrationFile("myCalibratedDataSet.root"); @@ -88,25 +88,25 @@ /// /// History of developments: /// -/// 2023-03: First implementation of TRestCalibration +/// 2023-03: First implementation of TRestDataSetCalibration /// JuanAn Garcia /// -/// \class TRestCalibration +/// \class TRestDataSetCalibration /// \author: JuanAn Garcia e-mail: juanangp@unizar.es /// ///
/// -#include "TRestCalibration.h" +#include "TRestDataSetCalibration.h" #include "TRestDataSet.h" -ClassImp(TRestCalibration); +ClassImp(TRestDataSetCalibration); /////////////////////////////////////////////// /// \brief Default constructor /// -TRestCalibration::TRestCalibration() { Initialize(); } +TRestDataSetCalibration::TRestDataSetCalibration() { Initialize(); } ///////////////////////////////////////////// /// \brief Constructor loading data from a config file @@ -120,9 +120,9 @@ TRestCalibration::TRestCalibration() { Initialize(); } /// /// \param configFilename A const char* that defines the RML filename. /// \param name The name of the metadata section. It will be used to find the -/// corresponding TRestCalibration section inside the RML. +/// corresponding TRestDataSetCalibration section inside the RML. /// -TRestCalibration::TRestCalibration(const char* configFilename, std::string name) +TRestDataSetCalibration::TRestDataSetCalibration(const char* configFilename, std::string name) : TRestMetadata(configFilename) { LoadConfigFromFile(fConfigFileName, name); Initialize(); @@ -133,20 +133,20 @@ TRestCalibration::TRestCalibration(const char* configFilename, std::string name) /////////////////////////////////////////////// /// \brief Default destructor /// -TRestCalibration::~TRestCalibration() {} +TRestDataSetCalibration::~TRestDataSetCalibration() {} /////////////////////////////////////////////// /// \brief Function to initialize input/output event members and define /// the section name /// -void TRestCalibration::Initialize() { SetSectionName(this->ClassName()); } +void TRestDataSetCalibration::Initialize() { SetSectionName(this->ClassName()); } /////////////////////////////////////////////// /// \brief Function to initialize some variables from /// configfile, in case that the variable is not found /// in the rml it checks the input file pattern. /// -void TRestCalibration::InitFromConfigFile() { +void TRestDataSetCalibration::InitFromConfigFile() { Initialize(); TRestMetadata::InitFromConfigFile(); @@ -178,7 +178,7 @@ void TRestCalibration::InitFromConfigFile() { /// Otherwise, it takes the calibration constants from the /// provided calibration file. /// -void TRestCalibration::Calibrate() { +void TRestDataSetCalibration::Calibrate() { PrintMetadata(); TRestDataSet dataSet; @@ -270,9 +270,9 @@ void TRestCalibration::Calibrate() { } ///////////////////////////////////////////// -/// \brief Prints on screen the information about the metadata members of TRestCalibration +/// \brief Prints on screen the information about the metadata members of TRestDataSetCalibration /// -void TRestCalibration::PrintMetadata() { +void TRestDataSetCalibration::PrintMetadata() { TRestMetadata::PrintMetadata(); RESTMetadata << " Energy peaks to calibrate: "; diff --git a/source/framework/analysis/src/TRestDataSetOdss.cxx b/source/framework/analysis/src/TRestDataSetOdds.cxx similarity index 92% rename from source/framework/analysis/src/TRestDataSetOdss.cxx rename to source/framework/analysis/src/TRestDataSetOdds.cxx index e6a442328..1fae33afb 100644 --- a/source/framework/analysis/src/TRestDataSetOdss.cxx +++ b/source/framework/analysis/src/TRestDataSetOdds.cxx @@ -21,7 +21,7 @@ *************************************************************************/ ///////////////////////////////////////////////////////////////////////// -/// TRestOdds performs the log odds of the different observables given +/// TRestDataSetOdds performs the log odds of the different observables given /// in the config file and for a particular dataSet. To perform the log odds /// first the probability density funcion (PDF) is obtained for a set of /// observables in the desired range. Later on, the log odds is computed as @@ -51,7 +51,7 @@ /// ### Examples /// Example of RML config file: /// \code -/// +/// /// /// /// @@ -65,12 +65,12 @@ /// /// /// -/// +/// /// \endcode /// /// Example to compute the the odds over a dataSet using restRoot: /// \code -/// [0] TRestOdds odds ("odds.rml"); +/// [0] TRestDataSetOdds odds ("odds.rml"); /// [1] odds.SetDataSetName("myDataSet.root"); /// [2] odds.SetOutputFileName("myComputedOddsDataSet.root"); /// [3] odds.ComputeLogOdds(); @@ -78,7 +78,7 @@ /// /// Example to compute the the odds over a dataSet with input odds file using restRoot: /// \code -/// [0] TRestOdds odds ("odds.rml"); +/// [0] TRestDataSetOdds odds ("odds.rml"); /// [1] odds.SetDataSetName("myDataSet.root"); /// [2] odds.SetOutputFileName("myComputedOddsDataSet.root"); /// [3] odds.odds.SetOddsFile("myOddsDataSet.root"); @@ -91,25 +91,25 @@ /// /// History of developments: /// -/// 2023-03: First implementation of TRestOdds +/// 2023-03: First implementation of TRestDataSetOdds /// JuanAn Garcia /// -/// \class TRestOdds +/// \class TRestDataSetOdds /// \author: JuanAn Garcia e-mail: juanangp@unizar.es /// ///
/// -#include "TRestOdds.h" +#include "TRestDataSetOdds.h" #include "TRestDataSet.h" -ClassImp(TRestOdds); +ClassImp(TRestDataSetOdds); /////////////////////////////////////////////// /// \brief Default constructor /// -TRestOdds::TRestOdds() { Initialize(); } +TRestDataSetOdds::TRestDataSetOdds() { Initialize(); } ///////////////////////////////////////////// /// \brief Constructor loading data from a config file @@ -123,9 +123,9 @@ TRestOdds::TRestOdds() { Initialize(); } /// /// \param configFilename A const char* that defines the RML filename. /// \param name The name of the metadata section. It will be used to find the -/// corresponding TRestOdds section inside the RML. +/// corresponding TRestDataSetOdds section inside the RML. /// -TRestOdds::TRestOdds(const char* configFilename, std::string name) : TRestMetadata(configFilename) { +TRestDataSetOdds::TRestDataSetOdds(const char* configFilename, std::string name) : TRestMetadata(configFilename) { LoadConfigFromFile(fConfigFileName, name); Initialize(); @@ -135,19 +135,19 @@ TRestOdds::TRestOdds(const char* configFilename, std::string name) : TRestMetada /////////////////////////////////////////////// /// \brief Default destructor /// -TRestOdds::~TRestOdds() {} +TRestDataSetOdds::~TRestDataSetOdds() {} /////////////////////////////////////////////// /// \brief Function to initialize input/output event members and define /// the section name /// -void TRestOdds::Initialize() { SetSectionName(this->ClassName()); } +void TRestDataSetOdds::Initialize() { SetSectionName(this->ClassName()); } /////////////////////////////////////////////// /// \brief Function to initialize some variables from /// configfile /// -void TRestOdds::InitFromConfigFile() { +void TRestDataSetOdds::InitFromConfigFile() { Initialize(); TRestMetadata::InitFromConfigFile(); @@ -200,7 +200,7 @@ void TRestOdds::InitFromConfigFile() { /// odds_obsName and the addition of all of them for a further /// processing, which is stored in odds_total observable. /// -void TRestOdds::ComputeLogOdds() { +void TRestDataSetOdds::ComputeLogOdds() { PrintMetadata(); TRestDataSet dataSet; @@ -266,9 +266,9 @@ void TRestOdds::ComputeLogOdds() { } ///////////////////////////////////////////// -/// \brief Prints on screen the information about the metadata members of TRestOdds +/// \brief Prints on screen the information about the metadata members of TRestDataSetOdds /// -void TRestOdds::PrintMetadata() { +void TRestDataSetOdds::PrintMetadata() { TRestMetadata::PrintMetadata(); RESTMetadata << " Observables to compute: " << RESTendl; From e47252bd4d08f219e7359c253df3ea801647a060 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 Mar 2023 08:08:30 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/framework/analysis/src/TRestDataSetCalibration.cxx | 1 + source/framework/analysis/src/TRestDataSetOdds.cxx | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/framework/analysis/src/TRestDataSetCalibration.cxx b/source/framework/analysis/src/TRestDataSetCalibration.cxx index c40ad09d6..4f441c73f 100644 --- a/source/framework/analysis/src/TRestDataSetCalibration.cxx +++ b/source/framework/analysis/src/TRestDataSetCalibration.cxx @@ -98,6 +98,7 @@ /// #include "TRestDataSetCalibration.h" + #include "TRestDataSet.h" ClassImp(TRestDataSetCalibration); diff --git a/source/framework/analysis/src/TRestDataSetOdds.cxx b/source/framework/analysis/src/TRestDataSetOdds.cxx index a0c82ffc0..2aa4d18c8 100644 --- a/source/framework/analysis/src/TRestDataSetOdds.cxx +++ b/source/framework/analysis/src/TRestDataSetOdds.cxx @@ -101,6 +101,7 @@ /// #include "TRestDataSetOdds.h" + #include "TRestDataSet.h" ClassImp(TRestDataSetOdds); @@ -124,7 +125,8 @@ TRestDataSetOdds::TRestDataSetOdds() { Initialize(); } /// \param name The name of the metadata section. It will be used to find the /// corresponding TRestDataSetOdds section inside the RML. /// -TRestDataSetOdds::TRestDataSetOdds(const char* configFilename, std::string name) : TRestMetadata(configFilename) { +TRestDataSetOdds::TRestDataSetOdds(const char* configFilename, std::string name) + : TRestMetadata(configFilename) { LoadConfigFromFile(fConfigFileName, name); Initialize();