Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions include/MGUIExpoDepthCalibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <TRootEmbeddedCanvas.h>
#include <TH1.h>
#include <TH2.h>
#include <TLegend.h>
#include <TGNumberEntry.h>
#include <TGComboBox.h>

// MEGAlib libs:
#include "MGlobal.h"
Expand Down Expand Up @@ -83,21 +86,44 @@ class MGUIExpoDepthCalibration : public MGUIExpo
//! 0 1 2 3
//! 4 5 6 7
//! 8 9 10 11
void AddDepth(unsigned int DetID, double Depth);
void AddDepth(unsigned int DetID, int LVStrip, int HVStrip, double Depth);
void AddRawDepth(unsigned int DetID, int LVStrip, int HVStrip, double Depth);
void OnStripSelectionChanged();
void RebuildDisplayHistograms();
virtual bool ProcessMessage(long Message, long Parameter1, long Parameter2);


// protected methods:
protected:

// protected members:
protected:
std::map<int, TH1D*> m_RawDepthPerStrip;
std::map<int, TH1D*> m_DepthPerStrip;

TGComboBox* m_SideSelector;
TGNumberEntry* m_StripMinEntry;
TGNumberEntry* m_StripMaxEntry;

// protected members:
protected:
int m_SelectedSide; // 0=LV, 1=HV
int m_StripMin;
int m_StripMax;

int GetStripKey(int DetID, int Side, int StripID) { return DetID * 1000 + Side * 100 + StripID; }

// private members:
private:
TLegend* m_Legend = nullptr;
TGTextButton* m_UpdateSelectionButton;

static const int c_UpdateSelection = 1001;


//! Depth canvas
unordered_map<unsigned int, TRootEmbeddedCanvas*> m_DepthCanvases;
//! Depth vs detector ID histogram
unordered_map<unsigned int, TH1D*> m_DepthHistograms;
unordered_map<unsigned int, TH1D*> m_RawDepthHistograms;

//! Detectors in x direction
unsigned int m_NColumns;
Expand Down
88 changes: 88 additions & 0 deletions include/MGUIExpoPlotTacDiff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef __MGUIExpoPlotTacDiff__
#define __MGUIExpoPlotTacDiff__

#include <map>
#include <vector>

#include <TH2D.h>
#include <TGComboBox.h>
#include <TRootEmbeddedCanvas.h>
#include <TGFrame.h>
#include <TGLabel.h>
#include <TGLayout.h>
#include <TGNumberEntry.h>

#include "MGUIExpo.h"
#include "MModule.h"

class MGUIExpoPlotTacDiff : public MGUIExpo
{
public:
MGUIExpoPlotTacDiff(MModule* Module);
virtual ~MGUIExpoPlotTacDiff();

virtual void Reset();
virtual void Create();
virtual void Update();
virtual void Export(const MString& FileName);

void SetHistogramParameters(unsigned int DetID, unsigned int NBinsDepth, double DepthMin, double DepthMax,
unsigned int NBinsDtac, double DtacMin, double DtacMax,
unsigned int NBinsFrac, double FracMin, double FracMax);
void AddData(int StripPairCode, double Depth, double dTac, double Fraction, double dTacAlt,double Energy);

//void OnDetectorSelected(Int_t DetID);
//void OnSideSelected(Int_t Side);
//void OnStripSelected();
//void OnEnergyRangeChanged();
virtual bool ProcessMessage(long Message, long Parameter1, long Parameter2);
void OnUpdateSelection();


protected:
void RedrawPlots();

int m_SelectedDetector;
int m_SelectedSide;
int m_SelectedStrip;
int m_SelectedStripPairCode;

TGComboBox* m_DetectorSelector;
TGComboBox* m_SideSelector;
TGNumberEntry* m_StripEntry;
TGNumberEntry* m_EnergyMinEntry;
TGNumberEntry* m_EnergyMaxEntry;
double m_EnergyMin;
double m_EnergyMax;

TRootEmbeddedCanvas* m_DtacVsDepthCanvas;
TRootEmbeddedCanvas* m_DtacVsFracCanvas;
TRootEmbeddedCanvas* m_DtacVsDtacCanvas;

// Key: StripPairCode = 10000*DetID + 100*LVStripID (for LV) or 10000*DetID + HVStripID (for HV)
std::map<int, TH2D*> m_DtacVsDepthHistograms;
std::map<int, TH2D*> m_DtacVsFracHistograms;
std::map<int, TH2D*> m_DtacVsDtacHistograms;

std::map<unsigned int, unsigned int> m_NBinsDepth;
std::map<unsigned int, double> m_DepthMin;
std::map<unsigned int, double> m_DepthMax;
std::map<unsigned int, unsigned int> m_NBinsDtac;
std::map<unsigned int, double> m_DtacMin;
std::map<unsigned int, double> m_DtacMax;
std::map<unsigned int, unsigned int> m_NBinsFrac;
std::map<unsigned int, double> m_FracMin;
std::map<unsigned int, double> m_FracMax;

std::vector<unsigned int> m_DetIDs;
private:
static const int c_UpdateSelection = 1001;
TGTextButton* m_UpdateSelectionButton;

#ifdef ___CLING___
public:
ClassDef(MGUIExpoPlotTacDiff, 0)
#endif
};

#endif
3 changes: 3 additions & 0 deletions include/MGUIOptionsDepthCalibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class MGUIOptionsDepthCalibration : public MGUIOptions
//! Select which coefficients file (stretching factors and offsets) to load
MGUIEFileSelector* m_CoeffsFileSelector;

//! Select which coefficients file (charge sharing correction) to load
MGUIEFileSelector* m_ChargeSharingConfigFileSelector;

//! Select spline file to load, splines will convert CTD->Depth
MGUIEFileSelector* m_SplinesFileSelector;

Expand Down
87 changes: 80 additions & 7 deletions include/MModuleDepthCalibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>
#include <numeric>
#include <cmath>
#include <tuple>

// ROOT libs:

Expand All @@ -31,6 +32,7 @@
#include "MDStrip3D.h"
#include "MDShapeBRIK.h"
#include "MGUIExpoDepthCalibration.h"
#include "MGUIExpoPlotTacDiff.h"

// Forward declarations:

Expand Down Expand Up @@ -62,7 +64,12 @@ class MModuleDepthCalibration : public MModule
//! Show the options GUI
virtual void ShowOptionsGUI();

//! Set filename for coefficients file
//! Set filename for charge sharing coefficients file
void SetChargeSharingConfigFileName( const MString& FileName) { m_ChargeSharingConfigFileName = FileName; }
//! Get filename for coefficients file
MString GetChargeSharingConfigFileName() const { return m_ChargeSharingConfigFileName; }

//! Set filename for ctd-z calibration coefficients file
void SetCoeffsFileName( const MString& FileName) { m_CoeffsFileName = FileName; }
//! Get filename for coefficients file
MString GetCoeffsFileName() const { return m_CoeffsFileName; }
Expand Down Expand Up @@ -91,11 +98,43 @@ class MModuleDepthCalibration : public MModule
//! Load the detector and strip dimensions from the geometry object
bool LoadDetectorDimensions(MDGeometryQuest* Geometry);

//! Load in the specified coefficients file
//! Load in the specified charge sharing calibration coefficients file
bool LoadChargeSharingConfigFile(MString FName);

//! Load in the specified ctd-z coefficients file
bool LoadCoeffsFile(MString FName);

//! Set the vector of z values for each detector (which depths are in the config for the charge sharing correction for each detector)
void SetChargeSharingDepths( unordered_map<int, vector<double>> ChargeSharingDepths) {m_ChargeSharingDepths = ChargeSharingDepths;}

//! Set the charge sharing correction depth calibration coefficient, one vector per strip-pair (map-int) per depth (the vector)
void SetChargeSharingCoeffs( unordered_map<int, vector<vector<double>>> ChargeSharingCoeffs ) { m_ChargeSharingCoeffs = ChargeSharingCoeffs; }

//! Set the coefficients of the polynomial describing the charge sharing correction depth calibration coefficient, one vector per detector (map-int) per depth (the vector)
void SetChargeSharingPolyCoeffsHV( unordered_map<int, vector<vector<double>>> ChargeSharingPolyCoeffsHV ) { m_ChargeSharingPolyCoeffsHV = ChargeSharingPolyCoeffsHV; }
void SetChargeSharingPolyCoeffsLV( unordered_map<int, vector<vector<double>>> ChargeSharingPolyCoeffsLV ) { m_ChargeSharingPolyCoeffsLV = ChargeSharingPolyCoeffsLV; }

//! Set the coefficients of the polynomial describing the charge sharing correction, one vector per detector (map-int) per depth (the vector)
void SetChargeSharingCorrectionCoeffsHV( unordered_map<int, vector<vector<double>>> ChargeSharingCorrectionCoeffsHV ) { m_ChargeSharingCorrectionCoeffsHV = ChargeSharingCorrectionCoeffsHV; }
void SetChargeSharingCorrectionCoeffsLV( unordered_map<int, vector<vector<double>>> ChargeSharingCorrectionCoeffsLV ) { m_ChargeSharingCorrectionCoeffsLV = ChargeSharingCorrectionCoeffsLV; }

//! Set the depth calibration coefficients
void SetCoeffs( unordered_map<int, vector<double>> Coeffs ) { m_Coeffs = Coeffs; }

//! Get the depths for the charge sharing correction calibration coefficients for a detector
unordered_map<int, vector<double>> GetChargeSharingDepths() { return m_ChargeSharingDepths; }

//! Get the charge sharing correction calibration coefficients
unordered_map<int, vector<vector<double>>> GetChargeSharingCoeffs() { return m_ChargeSharingCoeffs; }

//! Get the coefficients of the polynomial for the ccharge sharing expectation / bump calibration
unordered_map<int, vector<vector<double>>> GetChargeSharingPolyCoeffsHV() { return m_ChargeSharingPolyCoeffsHV; }
unordered_map<int, vector<vector<double>>> GetChargeSharingPolyCoeffsLV() { return m_ChargeSharingPolyCoeffsLV; }

//! Get the coefficients of the polynomial for the charge sharing correction calibration
unordered_map<int, vector<vector<double>>> GetChargeSharingCorrectionCoeffsHV() { return m_ChargeSharingCorrectionCoeffsHV; }
unordered_map<int, vector<vector<double>>> GetChargeSharingCorrectionCoeffsLV() { return m_ChargeSharingCorrectionCoeffsLV; }

//! Get the depth calibration coefficients
unordered_map<int, vector<double>> GetCoeffs() { return m_Coeffs; }

Expand Down Expand Up @@ -124,6 +163,13 @@ class MModuleDepthCalibration : public MModule

// protected methods:
protected:

//! Returns the z as a function of ctd, given some ctd and some detector
std::tuple<double, double> CalculateZfromCTD(double CTDvalue, double noise, int DetID,int Grade, bool sean_weighting);

//! Returns the strip with the specified strip ID
MStripHit* GetStrip(std::vector<MStripHit*>& Strips, int StripID);

//! Returns the strip with most energy from vector Strips, also gives back the energy fraction
MStripHit* GetDominantStrip(std::vector<MStripHit*>& Strips, double& EnergyFraction);

Expand All @@ -144,7 +190,18 @@ class MModuleDepthCalibration : public MModule
//! Determine the Grade (geometry of charge sharing) of the Hit
int GetHitGrade(MHit* H);

//! Return the coefficients for a pixel
//! Return the coefficients of the charge sharing correction polynomial for a detector at a depth
vector<double> GetChargeSharingCorrectionCoeffsHV(int DetID,double z);
vector<double> GetChargeSharingCorrectionCoeffsLV(int DetID,double z);

//! Return the coefficients of the dTac polynomial for a detector at a depth
vector<double> GetChargeSharingPolyCoeffsHV(int DetID,double z);
vector<double> GetChargeSharingPolyCoeffsLV(int DetID,double z);

//! Return the charge-sharing stretch/offset coefficients for a strip-pair at a depth
vector<double> GetChargeSharingCoeffs(int StripPairCode,double z);

//! Return the ctd-z stretch/offset coefficients for a pixel
vector<double>* GetPixelCoeffs(int PixelCode);

//! Load the metrology mask file
Expand All @@ -153,6 +210,7 @@ class MModuleDepthCalibration : public MModule
//! Get the x, y position of the intersection of two strips based on the Metrology Mask
vector<double> GetStripIntersection(MReadOutElementDoubleStrip LVStrip, MReadOutElementDoubleStrip HVStrip);

// TODO this should require strip energy, not hit energy...
//! Get the timing FWHM noise for the specified pixel and Energy
double GetTimingNoiseFWHM(int PixelCode, double Energy);

Expand All @@ -162,10 +220,17 @@ class MModuleDepthCalibration : public MModule


// protected members:
protected:

unordered_map<int, vector<double>> m_Coeffs;
protected:

unordered_map<int, vector<double>> m_ChargeSharingDepths; // maps DetID to the depths for which the charge sharing polynomial correction and charge sharing coefficients per-strip-pair were calculated
unordered_map<int, vector<vector<double>>> m_ChargeSharingCoeffs; // maps StripPairID to a vector of coefficients, for a vector of depths (needs interpolation)
unordered_map<int, vector<vector<double>>> m_ChargeSharingCorrectionCoeffsLV; // maps DetID to the LV coefficients for dTAC vs CS map and charge sharing correction vs CS map, for a vector of depths
unordered_map<int, vector<vector<double>>> m_ChargeSharingCorrectionCoeffsHV; // maps DetID to the HV coefficients for dTAC vs CS map and charge sharing correction vs CS map, for a given depth
unordered_map<int, vector<vector<double>>> m_ChargeSharingPolyCoeffsLV; // maps DetID to the LV coefficients for dTAC vs CS map and charge sharing correction vs CS map, for a vector of depths
unordered_map<int, vector<vector<double>>> m_ChargeSharingPolyCoeffsHV; // maps DetID to the HV coefficients for dTAC vs CS map and charge sharing correction vs CS map, for a given depth
unordered_map<int, vector<double>> m_Coeffs; // maps pix id to a vector of coefficients...
double m_Coeffs_Energy;
MString m_ChargeSharingConfigFileName;
MString m_CoeffsFileName;
MString m_SplinesFile;
unordered_map<int, double> m_Thicknesses;
Expand All @@ -183,17 +248,23 @@ class MModuleDepthCalibration : public MModule
uint64_t m_ErrorSH;
uint64_t m_ErrorNullSH;
uint64_t m_ErrorNoE;
uint64_t m_ZombieBump;
uint64_t m_ChargeSharingLV;
uint64_t m_ChargeSharingHV;
unordered_map<int, MDDetector*> m_Detectors;
vector<unsigned int> m_DetectorIDs;
MModuleEnergyCalibration* m_EnergyCalibration;
MGUIExpoDepthCalibration* m_ExpoDepthCalibration;
MGUIExpoPlotTacDiff* m_ExpoPlotTacDiff;


// The CTD Map maps each detector (int) to a 2D array of CTD values.
unordered_map<int, vector<vector<double>>> m_CTDMap;
unordered_map<int, vector<double>> m_DepthGrid;
unordered_map<int, vector<TSpline3*>> m_SplineMap;
bool m_SplinesFileIsLoaded;
bool m_CoeffsFileIsLoaded;
bool m_ChargeSharingConfigFileIsLoaded;

//! The Mask Metrology file name
MString m_MaskMetrologyFileName;
Expand All @@ -208,7 +279,9 @@ class MModuleDepthCalibration : public MModule
// boolean for use with the card cage at UCSD since it tags all events as detector 11
bool m_UCSDOverride;


// variable to describe the fraction of charge sharing that we define as a single strip
// TODO -- should this be a variable in the config?
double m_SingleStripChargeSharing = 0.9;

// private members:
private:
Expand Down
Loading
Loading