23 #ifndef REST_TRestDataSetGainMap
24 #define REST_TRestDataSetGainMap
31 #include <TRestStringOutput.h>
32 #include <TSpectrum.h>
37 #include "TRestDataSet.h"
38 #include "TRestMetadata.h"
74 Int_t GetNumberOfPlanes()
const {
return GetPlaneIDs().size(); }
75 Int_t GetNumberOfModules()
const {
81 std::string GetCalibrationFileName()
const {
return fCalibFileName; }
83 std::string GetObservable()
const {
return fObservable; }
88 Module*
GetModule(
const size_t index = 0);
89 Module*
GetModule(
const int planeID,
const int moduleID);
90 double GetSlopeParameter(
const int planeID,
const int moduleID,
const double x,
const double y);
95 void SetCalibrationFileName(
const std::string& fileName) {
fCalibFileName = fileName; }
96 void SetOutputFileName(
const std::string& fileName) {
fOutputFileName = fileName; }
98 void SetObservable(
const std::string& observable) {
fObservable = observable; }
99 void SetSpatialObservableX(
const std::string& spatialObservableX) {
102 void SetSpatialObservableY(
const std::string& spatialObservableY) {
107 void Import(
const std::string& fileName);
108 void Export(
const std::string& fileName =
"");
115 void CalibrateDataSet(
const std::string& dataSetFileName, std::string outputFileName =
"",
116 std::vector<std::string> excludeColumns = {});
129 std::pair<double, double> FitPeaks(TH1F* hSeg, TGraph* gr);
130 std::pair<double, double> UpdateCalibrationFits(TH1F* hSeg, TGraph* gr);
139 Int_t fModuleId = -1;
176 std::vector<std::vector<double>>
fSlope = {};
207 void AddPeak(
const double& energyPeak,
const TVector2& rangePeak = TVector2(0, 0)) {
215 std::pair<int, int>
GetIndexMatrix(
const double x,
const double y)
const;
216 double GetSlope(
const double x,
const double y)
const;
217 double GetIntercept(
const double x,
const double y)
const;
218 double GetSlopeFullSpc()
const {
return fFullSlope; };
221 Int_t GetPlaneId()
const {
return fPlaneId; }
222 Int_t GetModuleId()
const {
return fModuleId; }
223 std::string GetObservable()
const {
return p->
fObservable; }
226 inline std::string GetModuleDefinitionCut()
const {
return fDefinitionCut; }
230 std::set<double> GetSplitX()
const {
return fSplitX; }
231 std::set<double> GetSplitY()
const {
return fSplitY; }
235 void DrawSpectrum(
const bool drawFits =
true,
const int color = -1, TCanvas* c =
nullptr);
236 void DrawSpectrum(
const TVector2& position,
bool drawFits =
true,
int color = -1,
237 TCanvas* c =
nullptr);
238 void DrawSpectrum(
const int index_x,
const int index_y,
bool drawFits =
true,
int color = -1,
239 TCanvas* c =
nullptr);
240 void DrawFullSpectrum(
const bool drawFits =
true,
const int color = -1, TCanvas* c =
nullptr);
242 void DrawLinearFit(TCanvas* c =
nullptr);
243 void DrawLinearFit(
const TVector2& position, TCanvas* c =
nullptr);
244 void DrawLinearFit(
const int index_x,
const int index_y, TCanvas* c =
nullptr);
246 void DrawGainMap(
const int peakNumber = 0,
const bool fullModuleAsRef =
true);
248 void Refit(
const TVector2& position,
const double energy,
const TVector2& range);
249 void Refit(
const size_t x,
const size_t y,
const size_t peakNumber,
const TVector2& range);
250 void RefitFullSpc(
const double energy,
const TVector2& range);
251 void RefitFullSpc(
const size_t peakNumber,
const TVector2& range);
252 void UpdateCalibrationFits(
const size_t x,
const size_t y);
255 void SetPlaneId(
const Int_t& planeId) {
fPlaneId = planeId; }
256 void SetModuleId(
const Int_t& moduleId) { fModuleId = moduleId; }
257 void SetModuleDefinitionCut(
const std::string& moduleDefinitionCut) {
260 void SetCalibrationRange(
const TVector2& calibrationRange) {
fCalibRange = calibrationRange; }
261 void SetNBins(
const Int_t& nBins) {
fNBins = nBins; }
264 void SetSplitX(
const std::set<double>& splitX);
265 void SetSplitY(
const std::set<double>& splitY);
267 void SetSplits(
const std::set<double>& splitXandY) {
272 void SetNumberOfSegmentsX(
const Int_t& numberOfSegmentsX) {
fNumberOfSegmentsX = numberOfSegmentsX; }
273 void SetNumberOfSegmentsY(
const Int_t& numberOfSegmentsY) {
fNumberOfSegmentsY = numberOfSegmentsY; }
275 void SetDataSetFileName(
const std::string& dataSetFileName) {
fDataSetFileName = dataSetFileName; }
276 void SetReadoutRange(
const TVector2& readoutRange) {
fReadoutRange = readoutRange; }
277 void SetZeroPoint(
const bool& ZeroPoint) {
fZeroPoint = ZeroPoint; }
278 void SetAutoRangePeaks(
const bool& autoRangePeaks) {
fAutoRangePeaks = autoRangePeaks; }
287 Module(
const TRestDataSetGainMap& parent,
const Int_t planeId,
const Int_t moduleId) :
p(&parent) {
289 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.
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.
void DrawGainMap(const int peakNumber=0, const bool fullModuleAsRef=true)
Function to draw the relative gain map for a given energy peak of the module.
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.
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.
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::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.