REST-for-Physics
v2.3
Rare Event Searches ToolKit for Physics
|
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()"
Also, the peak position provides a gain map that can be plotted with the function TRestDataSetGainMap::Module::DrawGainMap(peakNumber)
The result is a better energy resolution with the gain corrected calibration (red) than the plain calibration (blue).
A example of RML definition of this class can be found inside the file REST_PATH/examples/calibrationCorrection.rml
. This have the following structure:
Example to calculate the calibration parameters over a calibration dataSet using restRoot:
Example to calibrate a dataSet with the previously calculated calibration parameters and draw the result (using restRoot):
Example to refit manually the peaks of the gain map if any of them is not well fitted (using restRoot):
REST-for-Physics - Software for Rare Event Searches Toolkit
History of developments:
2023-September: First implementation of TRestDataSetGainMap Álvaro Ezquerro
Definition at line 41 of file TRestDataSetGainMap.h.
#include <TRestDataSetGainMap.h>
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. | |
std::string | GetCalibrationFileName () const |
TRestCut * | GetCut () 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) | |
double | GetInterceptParameterFullSpc (const int planeID, const int moduleID) |
Function to get the intercept parameter of the whole module with planeID and moduleID. | |
Module * | GetModule (const int planeID, const int moduleID) |
Function to retrieve the module calibration with planeID and moduleID. | |
Module * | GetModule (const size_t index=0) |
Function to retrieve the module calibration by index. Default is 0. | |
std::map< int, std::set< int > > | GetModuleIDs () const |
Function to get the map of the module IDs for each plane ID. | |
std::set< int > | GetModuleIDs (const int planeId) const |
Function to get a list (set) of the module IDs of the plane with planeID. | |
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. | |
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) | |
double | GetSlopeParameterFullSpc (const int planeID, const int moduleID) |
Function to get the slope parameter of the whole module with planeID and moduleID. | |
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. | |
TRestDataSetGainMap & | operator= (TRestDataSetGainMap &src) |
void | PrintMetadata () override |
Prints on screen the information about the metadata members. | |
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. | |
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. | |
TRestDataSetGainMap (const char *configFilename, std::string name="") | |
Constructor loading data from a config file. More... | |
~TRestDataSetGainMap () | |
Default destructor. | |
Public Member Functions inherited from TRestMetadata | |
void | AddLog (std::string log="", bool print=true) |
Add logs to messageBuffer. | |
void | DoNotStore () |
If this method is called the metadata information will not be stored in disk. | |
TVector2 | Get2DVectorParameterWithUnits (std::string parName, TVector2 defaultValue=TVector2(-1, -1)) |
TVector3 | Get3DVectorParameterWithUnits (std::string parName, TVector3 defaultValue=TVector3(-1, -1, -1)) |
TString | GetCommit () |
Returns the REST commit value stored in fCommit. | |
std::string | GetConfigBuffer () |
Returns the config section of this class. | |
std::string | GetDataMemberValue (std::string memberName) |
Get the value of data member as string. More... | |
std::vector< std::string > | GetDataMemberValues (std::string memberName, Int_t precision=0) |
Get the value of datamember as a vector of strings. More... | |
TString | GetDataPath () |
Returns a std::string with the path used for data storage. | |
Double_t | GetDblParameterWithUnits (std::string parName, Double_t defaultValue=PARAMETER_NOT_FOUND_DBL) |
Gets the value of the parameter name parName, after applying unit conversion. More... | |
Bool_t | GetError () const |
It returns true if an error was identified by a derived metadata class. | |
TString | GetErrorMessage () |
Returns a std::string containing the error message. | |
TString | GetLibraryVersion () |
Returns the REST libraty version stored in fLibraryVersion. | |
TString | GetMainDataPath () |
Gets a std::string with the path used for data storage. | |
Int_t | GetNumberOfErrors () const |
Int_t | GetNumberOfWarnings () const |
std::string | GetParameter (std::string parName, TString defaultValue=PARAMETER_NOT_FOUND_STR) |
Returns corresponding REST Metadata parameter from multiple sources. More... | |
std::string | GetSectionName () |
Returns the section name of this class, defined at the beginning of fSectionName. | |
TRestStringOutput::REST_Verbose_Level | GetVerboseLevel () |
returns the verboselevel in type of REST_Verbose_Level enumerator | |
TString | GetVerboseLevelString () |
returns the verbose level in type of TString More... | |
TString | GetVersion () |
Returns the REST version stored in fVersion. | |
Int_t | GetVersionCode () |
UInt_t | GetVersionMajor () const |
UInt_t | GetVersionMinor () const |
UInt_t | GetVersionPatch () const |
Bool_t | GetWarning () const |
It returns true if an error was identified by a derived metadata class. | |
TString | GetWarningMessage () |
Returns a std::string containing the warning message. | |
TRestMetadata * | InstantiateChildMetadata (int index, std::string pattern="") |
This method will retrieve a new TRestMetadata instance of a child element of the present TRestMetadata instance based on the index given by argument, which defines the element order to be retrieved, 0 for first element found, 1 for the second element found, etc. More... | |
TRestMetadata * | InstantiateChildMetadata (std::string pattern="", std::string name="") |
This method will retrieve a new TRestMetadata instance of a child element of the present TRestMetadata instance based on the name given by argument. More... | |
Bool_t | isCleanState () const |
Bool_t | isOfficialRelease () const |
Int_t | LoadConfigFromBuffer () |
Initialize data from a string element buffer. More... | |
Int_t | LoadConfigFromElement (TiXmlElement *eSectional, TiXmlElement *eGlobal, std::map< std::string, std::string > envs={}) |
Main starter method. More... | |
Int_t | LoadConfigFromFile (const std::string &configFilename, const std::string §ionName="") |
Give the file name, find out the corresponding section. Then call the main starter. | |
virtual void | Merge (const TRestMetadata &) |
TRestMetadata & | operator= (const TRestMetadata &) |
void | Print () |
Implementing TObject::Print() method. | |
void | PrintConfigBuffer () |
Print the config xml section stored in the class. More... | |
void | PrintMessageBuffer () |
Print the buffered message. | |
void | PrintTimeStamp (Double_t timeStamp) |
Print the current time on local machine. More... | |
void | SetConfigFile (std::string configFilename) |
set config file path from external | |
void | SetError (std::string message="", bool print=true, int maxPrint=5) |
A metadata class may use this method to signal that something went wrong. | |
void | SetHostmgr (TRestManager *m) |
Set the host manager for this class. | |
void | SetSectionName (std::string sName) |
set the section name, clear the section content | |
void | SetVerboseLevel (TRestStringOutput::REST_Verbose_Level v) |
sets the verbose level | |
void | SetWarning (std::string message="", bool print=true, int maxPrint=5) |
A metadata class may use this method to signal that something went wrong. | |
void | Store () |
If this method is called the metadata information will be stored in disk. | |
TRestMetadata (const TRestMetadata &) | |
virtual void | UpdateMetadataMembers () |
Method to allow implementation of specific metadata members updates at inherited classes. | |
virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) |
overwriting the write() method with fStore considered | |
void | WriteConfigBuffer (std::string fName) |
Writes the config buffer to a file in append mode. | |
~TRestMetadata () | |
TRestMetadata default destructor. | |
Private Member Functions | |
void | InitFromConfigFile () override |
Initialization of TRestDataSetGainMap members through a RML file. | |
void | Initialize () override |
Making default settings. | |
Private Attributes | |
std::string | fCalibFileName = "" |
Name of the file that contains the calibration data. | |
TRestCut * | fCut = nullptr |
Cut to be applied to the calibration data. | |
std::vector< Module > | fModulesCal = {} |
List of modules. | |
std::string | fObservable = "" |
Observable that will be used to calculate the gain map. | |
std::string | fOutputFileName = "" |
Name of the file where the gain map was (or will be) exported. | |
std::string | fSpatialObservableX = "" |
Observable that will be used to segmentize the gain map in the x direction. | |
std::string | fSpatialObservableY = "" |
Observable that will be used to segmentize the gain map in the y direction. | |
Additional Inherited Members | |
Protected Member Functions inherited from TRestMetadata | |
std::string | ElementToString (TiXmlElement *ele) |
Convert an TiXmlElement object to string. More... | |
TVector2 | Get2DVectorParameterWithUnits (std::string parName, TiXmlElement *e, TVector2 defaultValue=TVector2(-1, -1)) |
TVector3 | Get3DVectorParameterWithUnits (std::string parName, TiXmlElement *e, TVector3 defaultValue=TVector3(-1, -1, -1)) |
Double_t | GetDblParameterWithUnits (std::string parName, TiXmlElement *e, Double_t defaultVal=PARAMETER_NOT_FOUND_DBL) |
TiXmlElement * | GetElement (std::string eleDeclare, TiXmlElement *e=nullptr) |
Get an xml element from a given parent element, according to its declaration. | |
TiXmlElement * | GetElementFromFile (std::string configFilename, std::string NameOrDecalre="") |
Open an xml encoded file and find its element. More... | |
TiXmlElement * | GetElementWithName (std::string eleDeclare, std::string eleName) |
Get an xml element from the default location, according to its declaration and its field "name". | |
TiXmlElement * | GetElementWithName (std::string eleDeclare, std::string eleName, TiXmlElement *e) |
Get an xml element from a given parent element, according to its declaration and its field "name". | |
std::string | GetFieldValue (std::string fieldName, std::string definition, size_t fromPosition=0) |
Gets field value in an xml element string by parsing it as TiXmlElement. | |
std::string | GetFieldValue (std::string parName, TiXmlElement *e) |
Returns the field value of an xml element which has the specified name. More... | |
std::string | GetKEYDefinition (std::string keyName) |
Gets the first key definition for keyName found inside buffer starting at fromPosition. More... | |
std::string | GetKEYDefinition (std::string keyName, size_t &Position) |
std::string | GetKEYDefinition (std::string keyName, size_t &Position, std::string buffer) |
std::string | GetKEYDefinition (std::string keyName, std::string buffer) |
std::string | GetKEYStructure (std::string keyName) |
Gets the first key structure for keyName found inside buffer after fromPosition. More... | |
std::string | GetKEYStructure (std::string keyName, size_t &Position) |
std::string | GetKEYStructure (std::string keyName, size_t &Position, std::string buffer) |
std::string | GetKEYStructure (std::string keyName, size_t &Position, TiXmlElement *ele) |
std::string | GetKEYStructure (std::string keyName, std::string buffer) |
TiXmlElement * | GetNextElement (TiXmlElement *e) |
Get the next sibling xml element of this element, with same eleDeclare. | |
std::string | GetParameter (std::string parName, size_t &pos, std::string inputString) |
Returns the value for the parameter name parName found in inputString. More... | |
std::string | GetParameter (std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR) |
Returns the value for the parameter named parName in the given section. More... | |
std::pair< std::string, std::string > | GetParameterAndUnits (std::string parname, TiXmlElement *e=nullptr) |
Returns the unit string of the given parameter of the given xml section. More... | |
std::map< std::string, std::string > | GetParametersList () |
It retrieves a map of all parameter:value found in the metadata class. | |
TString | GetSearchPath () |
virtual void | InitFromRootFile () |
Method called after the object is retrieved from root file. | |
virtual Int_t | LoadSectionMetadata () |
This method does some preparation of xml section. More... | |
void | ReadAllParameters () |
Reflection methods, Set value of a datamember in class according to TRestMetadata::fElement. More... | |
void | ReadParametersList (std::map< std::string, std::string > &list) |
It reads a parameter list and associates it to its corresponding metadata member. par0 --> fPar0. | |
std::string | ReplaceConstants (const std::string buffer) |
Identifies "constants" in the input buffer, and replace them with corresponding value. More... | |
std::string | ReplaceVariables (const std::string buffer) |
Identifies environmental variable replacing marks in the input buffer, and replace them with corresponding value. More... | |
void | ReSetVersion () |
Resets the version of TRestRun to REST_RELEASE. Only TRestRun is allowed to update version. | |
std::string | SearchFile (std::string filename) |
Search files in current directory and directories specified in "searchPath" section. More... | |
void | SetLibraryVersion (TString version) |
Set the library version of this metadata class. | |
TiXmlElement * | StringToElement (std::string definition) |
Parsing a string into TiXmlElement object. More... | |
TRestMetadata () | |
TRestMetadata default constructor. | |
TRestMetadata (const char *configFilename) | |
constructor | |
void | UnSetVersion () |
Resets the version of TRestRun to -1, in case the file is old REST file. Only TRestRun is allowed to update version. | |
Protected Attributes inherited from TRestMetadata | |
std::string | configBuffer |
The buffer where the corresponding metadata section is stored. Filled only during Write() | |
std::string | fConfigFileName |
Full name of the rml file. More... | |
std::map< std::string, std::string > | fConstants |
Saving a list of rml constants. name-value std::pair. Constants are temporary for this class only. | |
TiXmlElement * | fElement |
Saving the sectional element together with global element. | |
TiXmlElement * | fElementGlobal |
Saving the global element, to be passed to the resident class, if necessary. | |
Bool_t | fError = false |
It can be used as a way to identify that something went wrong using SetError method. | |
TString | fErrorMessage = "" |
A std::string to store an optional error message through method SetError. | |
TRestManager * | fHostmgr |
All metadata classes can be initialized and managed by TRestManager. | |
Int_t | fNErrors = 0 |
It counts the number of errors notified. | |
Int_t | fNWarnings = 0 |
It counts the number of warnings notified. | |
std::string | fSectionName |
Section name given in the constructor of the derived metadata class. | |
Bool_t | fStore |
This variable is used to determine if the metadata structure should be stored in the ROOT file. | |
std::map< std::string, std::string > | fVariables |
Saving a list of rml variables. name-value std::pair. | |
TRestStringOutput::REST_Verbose_Level | fVerboseLevel |
Verbose level used to print debug info. | |
Bool_t | fWarning = false |
It can be used as a way to identify that something went wrong using SetWarning method. | |
TString | fWarningMessage = "" |
It can be used as a way to identify that something went wrong using SetWarning method. | |
std::string | messageBuffer |
The buffer to store the output message through TRestStringOutput in this class. | |
endl_t | RESTendl |
Termination flag object for TRestStringOutput. | |
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.
configFilename | A const char* that defines the RML filename. |
name | The 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.
void TRestDataSetGainMap::CalibrateDataSet | ( | const std::string & | dataSetFileName, |
std::string | outputFileName = "" , |
||
std::vector< std::string > | excludeColumns = {} |
||
) |
Function to calibrate a dataset with this gain map.
dataSetFileName | the name of the root file where the TRestDataSet to be calibrated is stored. |
outputFileName | the 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". |
excludeColumns | a 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.
void TRestDataSetGainMap::Export | ( | const std::string & | fileName = "" | ) |
Function to export the calibration to the file fileName.
fileName | The name of the output file. If empty, the output file will be the fOutputFileName class member. |
Definition at line 493 of file TRestDataSetGainMap.cxx.