REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Data Structures | Public Member Functions | Private Member Functions | Private Attributes
TRestDataSetGainMap Class Reference

Detailed Description

Metadata class to calculate,store and apply the gain corrected calibration of a group of detectors.

TRestDataSetGainMap calculates and stores the calibration parameters for a given detector with multiple (or just one) modules. The modules are defined using the Module class (defined internally). It performs a gain correction based on a spatial segmentation of the detector module. This is useful forbig modules such as the ones used in TREX-DM experiment. The input data files for this methods are TRestDataSet for both calculating the calibration parameters and performing the calibration of the desired events.

To correct the gain inhomogeneities, the module is divided in fNumberOfSegmentsX*fNumberOfSegmentsY segments. The energy peaks provided are fitted in each segment. The events are associated to each segment based on the observables fSpatialObservableX and fSpatialObservablesY. This results in the following plot that can be obtain with the function TRestDataSetGainMap::Module::DrawSpectrum()

TRestDataSetGainMap::Module::DrawSpectrum()" TRestDataSetGainMap::Module::DrawSpectrum()" TRestDataSetGainMap::Module::DrawSpectrum()" TRestDataSetGainMap::Module::DrawSpectrum()" TRestDataSetGainMap::Module::DrawSpectrum()" Also, the peak position provides a gain map that can be plotted with the function TRestDataSetGainMap::Module::DrawGainMap(peakNumber) @htmlonly <style>div.image img[src="drawGainMap.png"]{width:200px;}</style> \endhtmlonly @image{inline} html drawGainMap.png "Gain map. Plot obtain with TRestDataSetGainMap::Module::DrawGainMap()"

The result is a better energy resolution with the gain corrected calibration (red) than the plain calibration (blue).

Parameters

Examples

A example of RML definition of this class can be found inside the file REST_PATH/examples/calibrationCorrection.rml. This have the following structure:

<TRestDataSetGainMap name="calib">
...
<module>
...
</module>
<module>
...
</module>
Metadata class to calculate,store and apply the gain corrected calibration of a group of detectors.

Example to calculate the calibration parameters over a calibration dataSet using restRoot:

TRestDataSetGainMap gm ("calibrationCorrection.rml");
gm.SetCalibrationFileName("myDataSet.root"); //if not already defined in rml file
gm.SetOutputFileName("myCalibration.root"); //if not already defined in rml file
gm.GenerateGainMap();
gm.Export(); // gm.Export("anyOtherFileName.root")

Example to calibrate a dataSet with the previously calculated calibration parameters and draw the result (using restRoot):

gm.Import("myCalibration.root");
gm.CalibrateDataSet("dataSetToCalibrate.root", "calibratedDataSet.root");
ds.Import("calibratedDataSet.root");
auto h = ds.GetDataFrame().Histo1D({"hname", "",100,-1,40.}, "calib_ThresholdIntegral");
h->Draw();
void CalibrateDataSet(const std::string &dataSetFileName, std::string outputFileName="", std::vector< std::string > excludeColumns={})
Function to calibrate a dataset with this gain map.
void Import(const std::string &fileName)
Function to import the calibration parameters from the root file fileName.
It allows to group a number of runs that satisfy given metadata conditions.
Definition: TRestDataSet.h:34
void Import(const std::string &fileName)
This function imports metadata from a root file it import metadata info from the previous dataSet whi...
ROOT::RDF::RNode GetDataFrame() const
Gives access to the RDataFrame.
Definition: TRestDataSet.h:129

Example to refit manually the peaks of the gain map if any of them is not well fitted (using restRoot):

gm.Import("myCalibration.root");
// Draw all segmented spectra and check if any need a refit
for (auto pID : gm.GetPlaneIDs())
for (auto mID : gm.GetModuleIDs(pID))
gm.GetModule(pID,mID)->DrawSpectrum();
// Draw only the desired spectrum (segment 0,0 in this case)
gm.GetModule(0,0)->DrawSpectrum(0, 0);
// Refit the desired peak (peak with energy 22.5 in this case) with a new range
TVector2 range(100000, 200000); // Define here the new range for the fit as you wish
gm.GetModule(0,0)->Refit(TVector2(0,0), 22.5, range);
// Check the result
gm.GetModule(0,0)->DrawSpectrum(TVector2(0.0,0.0)); // using x,y physical coord is possible
// Export the new calibration
gm.Export(); // gm.Export("anyOtherFileName.root")
void DrawSpectrum(const bool drawFits=true, const int color=-1, TCanvas *c=nullptr)
Function to draw the spectrum for each segment of the module on the same canvas. The canvas is divide...
void Refit(const TVector2 &position, const double energy, const TVector2 &range)
Function to fit again manually a peak for a given segment of the module.
std::set< int > GetModuleIDs(const int planeId) const
Function to get a list (set) of the module IDs of the plane with planeID.
void Export(const std::string &fileName="")
Function to export the calibration to the file fileName.
std::set< int > GetPlaneIDs() const
Function to get a list (set) of the plane IDs.
Module * GetModule(const size_t index=0)
Function to retrieve the module calibration by index. Default is 0.

REST-for-Physics - Software for Rare Event Searches Toolkit

History of developments:

2023-September: First implementation of TRestDataSetGainMap Álvaro Ezquerro

Author
: Álvaro Ezquerro aezqu.nosp@m.erro.nosp@m.@uniz.nosp@m.ar.e.nosp@m.s

Definition at line 41 of file TRestDataSetGainMap.h.

#include <TRestDataSetGainMap.h>

Inheritance diagram for TRestDataSetGainMap:
TRestMetadata

Data Structures

class  Module
 

Public Member Functions

void CalibrateDataSet (const std::string &dataSetFileName, std::string outputFileName="", std::vector< std::string > excludeColumns={})
 Function to calibrate a dataset with this gain map. More...
 
 ClassDefOverride (TRestDataSetGainMap, 2)
 
void Export (const std::string &fileName="")
 Function to export the calibration to the file fileName. More...
 
void GenerateGainMap ()
 Function to calculate the calibration parameters of all modules. More...
 
std::string GetCalibrationFileName () const
 
TRestCutGetCut () const
 
double GetInterceptParameter (const int planeID, const int moduleID, const double x, const double y)
 Function to get the intercept parameter of the module with planeID and moduleID at physical position (x,y) More...
 
double GetInterceptParameterFullSpc (const int planeID, const int moduleID)
 Function to get the intercept parameter of the whole module with planeID and moduleID. More...
 
ModuleGetModule (const int planeID, const int moduleID)
 Function to retrieve the module calibration with planeID and moduleID. More...
 
ModuleGetModule (const size_t index=0)
 Function to retrieve the module calibration by index. Default is 0. More...
 
std::map< int, std::set< int > > GetModuleIDs () const
 Function to get the map of the module IDs for each plane ID. More...
 
std::set< int > GetModuleIDs (const int planeId) const
 Function to get a list (set) of the module IDs of the plane with planeID. More...
 
Int_t GetNumberOfModules () const
 
Int_t GetNumberOfPlanes () const
 
std::string GetObservable () const
 
std::string GetOutputFileName () const
 
std::set< int > GetPlaneIDs () const
 Function to get a list (set) of the plane IDs. More...
 
double GetSlopeParameter (const int planeID, const int moduleID, const double x, const double y)
 Function to get the slope parameter of the module with planeID and moduleID at physical position (x,y) More...
 
double GetSlopeParameterFullSpc (const int planeID, const int moduleID)
 Function to get the slope parameter of the whole module with planeID and moduleID. More...
 
std::string GetSpatialObservableX () const
 
std::string GetSpatialObservableY () const
 
void Import (const std::string &fileName)
 Function to import the calibration parameters from the root file fileName. More...
 
TRestDataSetGainMapoperator= (TRestDataSetGainMap &src)
 
void PrintMetadata () override
 Prints on screen the information about the metadata members. More...
 
void SetCalibrationFileName (const std::string &fileName)
 
void SetCut (TRestCut *cut)
 
void SetModule (const Module &moduleCal)
 Function to set a module calibration. If the module calibration already exists (same planeId and moduleId), it will be replaced. More...
 
void SetObservable (const std::string &observable)
 
void SetOutputFileName (const std::string &fileName)
 
void SetSpatialObservableX (const std::string &spatialObservableX)
 
void SetSpatialObservableY (const std::string &spatialObservableY)
 
 TRestDataSetGainMap ()
 Default constructor. More...
 
 TRestDataSetGainMap (const char *configFilename, std::string name="")
 Constructor loading data from a config file. More...
 
 ~TRestDataSetGainMap ()
 Default destructor. More...
 

Private Member Functions

void InitFromConfigFile () override
 Initialization of TRestDataSetGainMap members through a RML file. More...
 
void Initialize () override
 Making default settings. More...
 

Private Attributes

std::string fCalibFileName = ""
 Name of the file that contains the calibration data. More...
 
TRestCutfCut = nullptr
 Cut to be applied to the calibration data. More...
 
std::vector< ModulefModulesCal = {}
 List of modules. More...
 
std::string fObservable = ""
 Observable that will be used to calculate the gain map. More...
 
std::string fOutputFileName = ""
 Name of the file where the gain map was (or will be) exported. More...
 
std::string fSpatialObservableX = ""
 Observable that will be used to segmentize the gain map in the x direction. More...
 
std::string fSpatialObservableY = ""
 Observable that will be used to segmentize the gain map in the y direction. More...
 

Additional Inherited Members

Constructor & Destructor Documentation

◆ TRestDataSetGainMap() [1/2]

TRestDataSetGainMap::TRestDataSetGainMap ( )

Default constructor.

Definition at line 144 of file TRestDataSetGainMap.cxx.

◆ TRestDataSetGainMap() [2/2]

TRestDataSetGainMap::TRestDataSetGainMap ( const char *  configFilename,
std::string  name = "" 
)

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.

Parameters
configFilenameA const char* that defines the RML filename.
nameThe name of the metadata section. It will be used to find the corresponding TRestDataSetGainMap section inside the RML.

Definition at line 160 of file TRestDataSetGainMap.cxx.

◆ ~TRestDataSetGainMap()

TRestDataSetGainMap::~TRestDataSetGainMap ( )

Default destructor.

Definition at line 169 of file TRestDataSetGainMap.cxx.

Member Function Documentation

◆ CalibrateDataSet()

void TRestDataSetGainMap::CalibrateDataSet ( const std::string &  dataSetFileName,
std::string  outputFileName = "",
std::vector< std::string >  excludeColumns = {} 
)

Function to calibrate a dataset with this gain map.

Parameters
dataSetFileNamethe name of the root file where the TRestDataSet to be calibrated is stored.
outputFileNamethe name of the output (root) file where the calibrated TRestDataSet will be exported. If empty, the output file will be named as the input file plus the name of the TRestDataSetGainMap. E.g. "data/myDataSet.root" -> "data/myDataSet_<gmName>.root".
excludeColumnsa vector of strings with the names of the columns to be excluded from the output file. If empty, all columns will be included. If "all" is in the list, all columns will be excluded except the calibrated observable, the calibrated observable with no segmentation and the plane-module identifier (pmID).

Definition at line 222 of file TRestDataSetGainMap.cxx.

◆ Export()

void TRestDataSetGainMap::Export ( const std::string &  fileName = "")

Function to export the calibration to the file fileName.

Parameters
fileNameThe name of the output file. If empty, the output file will be the fOutputFileName class member.

Definition at line 493 of file TRestDataSetGainMap.cxx.

◆ GenerateGainMap()

void TRestDataSetGainMap::GenerateGainMap ( )

Function to calculate the calibration parameters of all modules.

Definition at line 197 of file TRestDataSetGainMap.cxx.

◆ GetCalibrationFileName()

std::string TRestDataSetGainMap::GetCalibrationFileName ( ) const
inline

Definition at line 81 of file TRestDataSetGainMap.h.

◆ GetCut()

TRestCut * TRestDataSetGainMap::GetCut ( ) const
inline

Definition at line 86 of file TRestDataSetGainMap.h.

◆ GetInterceptParameter()

double TRestDataSetGainMap::GetInterceptParameter ( const int  planeID,
const int  moduleID,
const double  x,
const double  y 
)

Function to get the intercept parameter of the module with planeID and moduleID at physical position (x,y)

Definition at line 376 of file TRestDataSetGainMap.cxx.

◆ GetInterceptParameterFullSpc()

double TRestDataSetGainMap::GetInterceptParameterFullSpc ( const int  planeID,
const int  moduleID 
)

Function to get the intercept parameter of the whole module with planeID and moduleID.

Definition at line 387 of file TRestDataSetGainMap.cxx.

◆ GetModule() [1/2]

TRestDataSetGainMap::Module * TRestDataSetGainMap::GetModule ( const int  planeID,
const int  moduleID 
)

Function to retrieve the module calibration with planeID and moduleID.

Definition at line 341 of file TRestDataSetGainMap.cxx.

◆ GetModule() [2/2]

TRestDataSetGainMap::Module * TRestDataSetGainMap::GetModule ( const size_t  index = 0)

Function to retrieve the module calibration by index. Default is 0.

Definition at line 326 of file TRestDataSetGainMap.cxx.

◆ GetModuleIDs() [1/2]

std::map< int, std::set< int > > TRestDataSetGainMap::GetModuleIDs ( ) const

Function to get the map of the module IDs for each plane ID.

Definition at line 417 of file TRestDataSetGainMap.cxx.

◆ GetModuleIDs() [2/2]

std::set< int > TRestDataSetGainMap::GetModuleIDs ( const int  planeId) const

Function to get a list (set) of the module IDs of the plane with planeID.

Definition at line 407 of file TRestDataSetGainMap.cxx.

◆ GetNumberOfModules()

Int_t TRestDataSetGainMap::GetNumberOfModules ( ) const
inline

Definition at line 75 of file TRestDataSetGainMap.h.

◆ GetNumberOfPlanes()

Int_t TRestDataSetGainMap::GetNumberOfPlanes ( ) const
inline

Definition at line 74 of file TRestDataSetGainMap.h.

◆ GetObservable()

std::string TRestDataSetGainMap::GetObservable ( ) const
inline

Definition at line 83 of file TRestDataSetGainMap.h.

◆ GetOutputFileName()

std::string TRestDataSetGainMap::GetOutputFileName ( ) const
inline

Definition at line 82 of file TRestDataSetGainMap.h.

◆ GetPlaneIDs()

std::set< int > TRestDataSetGainMap::GetPlaneIDs ( ) const

Function to get a list (set) of the plane IDs.

Definition at line 397 of file TRestDataSetGainMap.cxx.

◆ GetSlopeParameter()

double TRestDataSetGainMap::GetSlopeParameter ( const int  planeID,
const int  moduleID,
const double  x,
const double  y 
)

Function to get the slope parameter of the module with planeID and moduleID at physical position (x,y)

Definition at line 354 of file TRestDataSetGainMap.cxx.

◆ GetSlopeParameterFullSpc()

double TRestDataSetGainMap::GetSlopeParameterFullSpc ( const int  planeID,
const int  moduleID 
)

Function to get the slope parameter of the whole module with planeID and moduleID.

Definition at line 365 of file TRestDataSetGainMap.cxx.

◆ GetSpatialObservableX()

std::string TRestDataSetGainMap::GetSpatialObservableX ( ) const
inline

Definition at line 84 of file TRestDataSetGainMap.h.

◆ GetSpatialObservableY()

std::string TRestDataSetGainMap::GetSpatialObservableY ( ) const
inline

Definition at line 85 of file TRestDataSetGainMap.h.

◆ Import()

void TRestDataSetGainMap::Import ( const std::string &  fileName)

Function to import the calibration parameters from the root file fileName.

Definition at line 455 of file TRestDataSetGainMap.cxx.

◆ InitFromConfigFile()

void TRestDataSetGainMap::InitFromConfigFile ( )
overrideprivatevirtual

Initialization of TRestDataSetGainMap members through a RML file.

Reimplemented from TRestMetadata.

Definition at line 176 of file TRestDataSetGainMap.cxx.

◆ Initialize()

void TRestDataSetGainMap::Initialize ( )
overrideprivatevirtual

Making default settings.

Reimplemented from TRestMetadata.

Definition at line 171 of file TRestDataSetGainMap.cxx.

◆ operator=()

TRestDataSetGainMap & TRestDataSetGainMap::operator= ( TRestDataSetGainMap src)

Definition at line 424 of file TRestDataSetGainMap.cxx.

◆ PrintMetadata()

void TRestDataSetGainMap::PrintMetadata ( )
overridevirtual

Prints on screen the information about the metadata members.

Reimplemented from TRestMetadata.

Definition at line 513 of file TRestDataSetGainMap.cxx.

◆ SetCalibrationFileName()

void TRestDataSetGainMap::SetCalibrationFileName ( const std::string &  fileName)
inline

Definition at line 95 of file TRestDataSetGainMap.h.

◆ SetCut()

void TRestDataSetGainMap::SetCut ( TRestCut cut)
inline

Definition at line 105 of file TRestDataSetGainMap.h.

◆ SetModule()

void TRestDataSetGainMap::SetModule ( const Module moduleCal)

Function to set a module calibration. If the module calibration already exists (same planeId and moduleId), it will be replaced.

Definition at line 441 of file TRestDataSetGainMap.cxx.

◆ SetObservable()

void TRestDataSetGainMap::SetObservable ( const std::string &  observable)
inline

Definition at line 98 of file TRestDataSetGainMap.h.

◆ SetOutputFileName()

void TRestDataSetGainMap::SetOutputFileName ( const std::string &  fileName)
inline

Definition at line 96 of file TRestDataSetGainMap.h.

◆ SetSpatialObservableX()

void TRestDataSetGainMap::SetSpatialObservableX ( const std::string &  spatialObservableX)
inline

Definition at line 99 of file TRestDataSetGainMap.h.

◆ SetSpatialObservableY()

void TRestDataSetGainMap::SetSpatialObservableY ( const std::string &  spatialObservableY)
inline

Definition at line 102 of file TRestDataSetGainMap.h.

Field Documentation

◆ fCalibFileName

std::string TRestDataSetGainMap::fCalibFileName = ""
private

Name of the file that contains the calibration data.

Definition at line 59 of file TRestDataSetGainMap.h.

◆ fCut

TRestCut* TRestDataSetGainMap::fCut = nullptr
private

Cut to be applied to the calibration data.

Definition at line 65 of file TRestDataSetGainMap.h.

◆ fModulesCal

std::vector<Module> TRestDataSetGainMap::fModulesCal = {}
private

List of modules.

Definition at line 56 of file TRestDataSetGainMap.h.

◆ fObservable

std::string TRestDataSetGainMap::fObservable = ""
private

Observable that will be used to calculate the gain map.

Definition at line 47 of file TRestDataSetGainMap.h.

◆ fOutputFileName

std::string TRestDataSetGainMap::fOutputFileName = ""
private

Name of the file where the gain map was (or will be) exported.

Definition at line 62 of file TRestDataSetGainMap.h.

◆ fSpatialObservableX

std::string TRestDataSetGainMap::fSpatialObservableX = ""
private

Observable that will be used to segmentize the gain map in the x direction.

Definition at line 50 of file TRestDataSetGainMap.h.

◆ fSpatialObservableY

std::string TRestDataSetGainMap::fSpatialObservableY = ""
private

Observable that will be used to segmentize the gain map in the y direction.

Definition at line 53 of file TRestDataSetGainMap.h.


The documentation for this class was generated from the following files: