Skip to content

Commit

Permalink
Changing method name Calibrate and CalculateCalibrationParameters to …
Browse files Browse the repository at this point in the history
…GenerateGainMap. Adding file existance check.
  • Loading branch information
AlvaroEzq committed Oct 21, 2023
1 parent bcc8a38 commit e306346
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions source/framework/analysis/inc/TRestDataSetGainMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TRestDataSetGainMap : public TRestMetadata {
public:
void PrintMetadata() override;

void Calibrate();
void GenerateGainMap();
void CalibrateDataSet(const std::string& dataSetFileName, std::string outputFileName = "");

TRestDataSetGainMap();
Expand Down Expand Up @@ -201,7 +201,7 @@ class TRestDataSetGainMap : public TRestMetadata {

void Print() const;

void CalculateCalibrationParameters();
void GenerateGainMap();
void Initialize();

Module() {}
Expand Down
36 changes: 21 additions & 15 deletions source/framework/analysis/src/TRestDataSetGainMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
/// TRestDataSetGainMap cal ("calibrationCorrection.rml");
/// cal.SetCalibrationFileName("myDataSet.root"); //if not already defined in rml file
/// cal.SetOutputFileName("myCalibration.root"); //if not already defined in rml file
/// cal.Calibrate();
/// cal.GenerateGainMap();
/// cal.Export(); // cal.Export("anyOtherFileName.root")
/// \endcode
///
Expand Down Expand Up @@ -189,10 +189,10 @@ void TRestDataSetGainMap::InitFromConfigFile() {
/////////////////////////////////////////////
/// \brief Function to calculate the calibration parameters of all modules
///
void TRestDataSetGainMap::Calibrate() {
void TRestDataSetGainMap::GenerateGainMap() {
for (auto& mod : fModulesCal) {
RESTInfo << "Calibrating plane " << mod.GetPlaneId() << " module " << mod.GetModuleId() << RESTendl;
mod.CalculateCalibrationParameters();
mod.GenerateGainMap();
if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) {
mod.DrawSpectrum();
mod.DrawGainMap();
Expand Down Expand Up @@ -420,7 +420,7 @@ void TRestDataSetGainMap::Export(const std::string& fileName) {
///
void TRestDataSetGainMap::PrintMetadata() {
TRestMetadata::PrintMetadata();
RESTMetadata << " Calibration file: " << fCalibFileName << RESTendl;
RESTMetadata << " Calibration dataset: " << fCalibFileName << RESTendl;
RESTMetadata << " Output file: " << fOutputFileName << RESTendl;
RESTMetadata << " Number of planes: " << GetNumberOfPlanes() << RESTendl;
RESTMetadata << " Number of modules: " << GetNumberOfModules() << RESTendl;
Expand Down Expand Up @@ -550,33 +550,39 @@ void TRestDataSetGainMap::Module::SetSplitY() {
}

/////////////////////////////////////////////
/// \brief Function calculate the calibration parameters for each segment
/// defined at fSplitX and fSplitY.
/// \brief Function that calculates the calibration parameters for each segment
/// defined at fSplitX and fSplitY ang generate their spectra and gain map.
///
/// It uses the data of the observable fObservable from the TRestDataSet
/// at fDataSetFileName (or fCalibrationFileName if first is empty).
/// at fDataSetFileName (or fCalibFileName if first is empty).
/// The segmentation is given by the splits.
///
/// Fitting ranges logic is as follows:
/// Ranges for peak fitting follows this logic:
/// 1. If fRangePeaks is defined and fAutoRangePeaks is false: fRangePeaks is used.
/// 2. If fRangePeaks is defined and fAutoRangePeaks is true: the fitting range
/// is calculated by the peak position found by TSpectrum inside fRangePeaks.
/// 3. If fRangePeaks is not defined and fAutoRangePeaks is false: use the peak position found by TSpectrum
/// and the peak position of the next peak to define the range.
/// 4. If fRangePeaks is not defined and fAutoRangePeaks is true: same as 3.
///
void TRestDataSetGainMap::Module::CalculateCalibrationParameters() {
void TRestDataSetGainMap::Module::GenerateGainMap() {
//--- Initial checks and settings ---
if (fDataSetFileName.empty()) fDataSetFileName = p->GetCalibrationFileName();
if (fDataSetFileName.empty()) {
std::string dsFileName = fDataSetFileName;
if (dsFileName.empty()) dsFileName = p->GetCalibrationFileName();
if (dsFileName.empty()) {
RESTError << "No calibration file defined" << p->RESTendl;
return;
}

if (!TRestTools::isDataSet(fDataSetFileName))
RESTWarning << fDataSetFileName << " is not a dataset." << p->RESTendl;
if (!TRestTools::fileExists(dsFileName)) {
RESTError << "Calibration file " << dsFileName << " does not exist." << p->RESTendl;
return;
}
if (!TRestTools::isDataSet(dsFileName)) RESTWarning << dsFileName << " is not a dataset." << p->RESTendl;
TRestDataSet dataSet;
dataSet.Import(fDataSetFileName);
dataSet.Import(dsFileName);
fDataSetFileName = dsFileName;

SetSplits();

//--- Get the calibration range if not provided (default is 0,0) ---
Expand Down Expand Up @@ -1099,7 +1105,7 @@ void TRestDataSetGainMap::Module::Print() const {
RESTMetadata << " Definition cut: " << fDefinitionCut << p->RESTendl;
RESTMetadata << p->RESTendl;

RESTMetadata << " DataSet: " << fDataSetFileName << p->RESTendl;
RESTMetadata << " Calibration dataset: " << fDataSetFileName << p->RESTendl;
RESTMetadata << p->RESTendl;

RESTMetadata << " Energy peaks: ";
Expand Down

0 comments on commit e306346

Please sign in to comment.