23#ifndef REST_TRestDataSetGainMap
24#define REST_TRestDataSetGainMap
31#include <TRestStringOutput.h>
37#include "TRestDataSet.h"
38#include "TRestMetadata.h"
80 Int_t GetNumberOfPlanes()
const {
return GetPlaneIDs().size(); }
81 Int_t GetNumberOfModules()
const {
87 std::string GetCalibrationFileName()
const {
return fCalibFileName; }
89 std::string GetObservable()
const {
return fObservable; }
96 Module*
GetModule(
const size_t index = 0);
97 Module*
GetModule(
const int planeID,
const int moduleID);
98 double GetSlopeParameter(
const int planeID,
const int moduleID,
const double x,
const double y);
103 void SetCalibrationFileName(
const std::string& fileName) {
fCalibFileName = fileName; }
104 void SetOutputFileName(
const std::string& fileName) {
fOutputFileName = fileName; }
106 void SetObservable(
const std::string& observable) {
fObservable = observable; }
107 void SetSpatialObservableX(
const std::string& spatialObservableX) {
110 void SetSpatialObservableY(
const std::string& spatialObservableY) {
115 void Import(
const std::string& fileName);
116 void Export(
const std::string& fileName =
"");
123 void CalibrateDataSet(
const std::string& dataSetFileName, std::string outputFileName =
"",
124 std::vector<std::string> excludeColumns = {});
137 std::pair<double, double> FitPeaks(TH1F* hSeg, TGraph* gr);
138 std::pair<double, double> UpdateCalibrationFits(TH1F* hSeg, TGraph* gr);
147 Int_t fModuleId = -1;
184 std::vector<std::vector<double>>
fSlope = {};
215 void AddPeak(
const double& energyPeak,
const TVector2& rangePeak = TVector2(0, 0)) {
223 std::pair<int, int>
GetIndexMatrix(
const double x,
const double y)
const;
224 double GetSlope(
const double x,
const double y)
const;
225 double GetIntercept(
const double x,
const double y)
const;
226 double GetSlopeFullSpc()
const {
return fFullSlope; };
229 Int_t GetPlaneId()
const {
return fPlaneId; }
230 Int_t GetModuleId()
const {
return fModuleId; }
231 std::string GetObservable()
const {
return p->
fObservable; }
236 inline std::string GetModuleDefinitionCut()
const {
return fDefinitionCut; }
240 std::set<double> GetSplitX()
const {
return fSplitX; }
241 std::set<double> GetSplitY()
const {
return fSplitY; }
245 void DrawSpectrum(
const bool drawFits =
true,
const int color = -1, TCanvas* c =
nullptr);
246 void DrawSpectrum(
const TVector2& position,
bool drawFits =
true,
int color = -1,
247 TCanvas* c =
nullptr);
248 void DrawSpectrum(
const int index_x,
const int index_y,
bool drawFits =
true,
int color = -1,
249 TCanvas* c =
nullptr);
250 void DrawFullSpectrum(
const bool drawFits =
true,
const int color = -1, TCanvas* c =
nullptr);
252 void DrawLinearFit(TCanvas* c =
nullptr);
253 void DrawLinearFit(
const TVector2& position, TCanvas* c =
nullptr);
254 void DrawLinearFit(
const int index_x,
const int index_y, TCanvas* c =
nullptr);
256 void DrawGainMap(
const int peakNumber = 0,
const bool fullModuleAsRef =
true,
257 const bool showText =
true);
259 void Refit(
const TVector2& position,
const double energy,
const TVector2& range);
260 void Refit(
const size_t x,
const size_t y,
const size_t peakNumber,
const TVector2& range);
261 void RefitFullSpc(
const double energy,
const TVector2& range);
262 void RefitFullSpc(
const size_t peakNumber,
const TVector2& range);
263 void UpdateCalibrationFits(
const size_t x,
const size_t y);
266 void SetPlaneId(
const Int_t& planeId) {
fPlaneId = planeId; }
267 void SetModuleId(
const Int_t& moduleId) { fModuleId = moduleId; }
268 void SetModuleDefinitionCut(
const std::string& moduleDefinitionCut) {
271 void SetCalibrationRange(
const TVector2& calibrationRange) {
fCalibRange = calibrationRange; }
272 void SetNBins(
const Int_t& nBins) {
fNBins = nBins; }
275 void SetSplitX(
const std::set<double>& splitX);
276 void SetSplitY(
const std::set<double>& splitY);
278 void SetSplits(
const std::set<double>& splitXandY) {
283 void SetNumberOfSegmentsX(
const Int_t& numberOfSegmentsX) {
fNumberOfSegmentsX = numberOfSegmentsX; }
284 void SetNumberOfSegmentsY(
const Int_t& numberOfSegmentsY) {
fNumberOfSegmentsY = numberOfSegmentsY; }
286 void SetDataSetFileName(
const std::string& dataSetFileName) {
fDataSetFileName = dataSetFileName; }
287 void SetReadoutRange(
const TVector2& readoutRange) {
fReadoutRange = readoutRange; }
288 void SetZeroPoint(
const bool& ZeroPoint) {
fZeroPoint = ZeroPoint; }
289 void SetAutoRangePeaks(
const bool& autoRangePeaks) {
fAutoRangePeaks = autoRangePeaks; }
298 Module(
const TRestDataSetGainMap& parent,
const Int_t planeId,
const Int_t moduleId) :
p(&parent) {
300 SetModuleId(moduleId);
A class to help on cuts definitions. To be used with TRestAnalysisTree.
double fFullIntercept
Intercept of the calibration linear fit of whole module.
std::vector< std::vector< double > > fIntercept
Array containing the intercept of the linear fit for each segment.
Int_t fNumberOfSegmentsY
Number of segments in the y direction.
void SetSplitY()
Function to set the class members for segmentation of the detector plane along the Y axis.
std::vector< std::vector< TGraph * > > fSegLinearFit
Array containing the calibration linear fit for each segment.
void SetSplits()
Function to set the class members for segmentation of the detector plane along the X and Y axis.
void SetSplitX()
Function to set the class members for segmentation of the detector plane along the X axis.
std::vector< std::vector< TH1F * > > fSegSpectra
Array containing the observable spectrum for each segment.
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 LoadConfigFromTiXmlElement(const TiXmlElement *module)
Function to read the parameters from the RML element (TiXmlElement) and set those class members.
void GenerateGainMap()
Function that calculates the calibration parameters for each segment defined at fSplitX and fSplitY a...
double fFullSlope
Slope of the calibration linear fit of whole module.
void DrawGainMap(const int peakNumber=0, const bool fullModuleAsRef=true, const bool showText=true)
Function to draw the relative gain map for a given energy peak of the module.
double GetSlope(const double x, const double y) const
Function to get the calibration parameter slope for a given x and y position on the detector plane.
std::set< double > fSplitX
Split points in the x direction.
void Print() const
Prints on screen the information about the members of Module.
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::string fDataSetFileName
std::set< double > fSplitY
Split points in the y direction.
void RefitFullSpc(const double energy, const TVector2 &range)
Function to fit again manually a peak for the whole module spectrum. The calibration curve is updated...
std::vector< TVector2 > fRangePeaks
Range of the peaks to be used for the calibration. If empty it will be automatically calculated.
const TRestDataSetGainMap * p
Pointer to the parent class.
void UpdateCalibrationFitsFullSpc()
Function to update the calibration curve for the whole module. The calibration curve is cleared and t...
std::vector< std::vector< double > > fSlope
Array containing the slope of the linear fit for each segment.
Int_t fNumberOfSegmentsX
Number of segments in the x direction.
Int_t fNBins
Number of bins for the spectrum histograms.
TVector2 fCalibRange
Calibration range. If fCalibRange.X()>=fCalibRange.Y() the range will be automatically calculated.
std::string fDefinitionCut
Cut that defines which events are from this module. Default is "1" (all events).
TGraph * fFullLinearFit
Calibration linear fit for the whole module.
TH1F * fFullSpectrum
Spectrum of the observable for the whole module.
bool fAutoRangePeaks
Automatic range for the peaks fitting. See GenerateGainMap() for more information of the logic.
double GetIntercept(const double x, const double y) const
Function to get the calibration parameter intercept for a given x and y position on the detector plan...
TVector2 fReadoutRange
Readout dimensions.
std::pair< int, int > GetIndexMatrix(const double x, const double y) const
Function to get the index of the matrix of calibration parameters for a given x and y position on the...
std::vector< double > fEnergyPeaks
Energy of the peaks to be used for the calibration.
Metadata class to calculate,store and apply the gain corrected calibration of a group of detectors.
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 ...
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,...
std::string fObservable
Observable that will be used to calculate the gain map.
double GetInterceptParameterFullSpc(const int planeID, const int moduleID)
Function to get the intercept parameter of the whole module with planeID and moduleID.
void CalibrateDataSet(const std::string &dataSetFileName, std::string outputFileName="", std::vector< std::string > excludeColumns={})
Function to calibrate a dataset with this gain map.
~TRestDataSetGainMap()
Default destructor.
void GenerateGainMap()
Function to calculate the calibration parameters of all modules.
std::string fSpatialObservableXSecondary
Secondary observable that will be used to segmentize the gain map in the x direction (if needed)
TRestDataSetGainMap()
Default constructor.
void Initialize() override
Making default settings.
std::vector< Module > fModulesCal
List of modules.
void SetModule(const Module &moduleCal)
Function to set a module calibration. If the module calibration already exists (same planeId and modu...
void InitFromConfigFile() override
Initialization of TRestDataSetGainMap members through a RML file.
double GetSlopeParameterFullSpc(const int planeID, const int moduleID)
Function to get the slope parameter of the whole module with planeID and moduleID.
void Export(const std::string &fileName="")
Function to export the calibration to the file fileName.
void PrintMetadata() override
Prints on screen the information about the metadata members.
std::map< int, std::set< int > > GetModuleIDs() const
Function to get the map of the module IDs for each plane ID.
std::string fSpatialObservableY
Observable that will be used to segmentize the gain map in the y direction.
std::string fCalibFileName
Name of the file that contains the calibration data.
TRestCut * fCut
Cut to be applied to the calibration data.
std::string fOutputFileName
Name of the file where the gain map was (or will be) exported.
std::string fSpatialObservableYSecondary
Secondary observable that will be used to segmentize the gain map in the y direction (if needed)
std::set< int > GetPlaneIDs() const
Function to get a list (set) of the plane IDs.
std::string fSpatialObservableX
Observable that will be used to segmentize the gain map in the x direction.
Module * GetModule(const size_t index=0)
Function to retrieve the module calibration by index. Default is 0.
void Import(const std::string &fileName)
Function to import the calibration parameters from the root file fileName.