Base class for calculating weight from spline.
More...
#include <Splines/SplineBase.h>
|
| | SplineBase (const bool Use_GPU=true) |
| | Constructor. More...
|
| |
| virtual | ~SplineBase () |
| | Destructor. More...
|
| |
| virtual void | Evaluate ()=0 |
| | CW: This Eval should be used when using two separate x,{y,a,b,c,d} arrays to store the weights; probably the best one here! Same thing but pass parameter spline segments instead of variations. More...
|
| |
| virtual std::string | GetName () const |
| | Get class name. More...
|
| |
| short int | GetNParams () const |
| | Get number of spline parameters. More...
|
| |
| virtual void | PrepareSplineFile (std::string FileName)=0 |
| | KS: Prepare spline file that can be used for fast loading. More...
|
| |
| virtual void | LoadSplineFile (std::string FileName)=0 |
| | KS: Load preprocessed spline file. More...
|
| |
| void | SynchroniseMemTransfer () const |
| | KS: After calculations are done on GPU we copy memory to CPU. This operation is asynchronous meaning while memory is being copied some operations are being carried. Memory must be copied before actual reweight. This function make sure all has been copied. More...
|
| |
Base class for calculating weight from spline.
- Author
- Dan Barrow
-
Kamil Skwarczynski
Definition at line 30 of file SplineBase.h.
◆ SplineBase()
| SplineBase::SplineBase |
( |
const bool |
Use_GPU = true | ) |
|
Constructor.
Definition at line 11 of file SplineBase.cpp.
SplineMonolithGPU * gpu_monolith
KS: Store info about Spline monolith, this allow to obtain better step time. As all necessary informa...
unsigned int NSplines_valid
Number of valid splines.
short int nParams
Number of parameters that have splines.
virtual std::string GetName() const
Get class name.
short int _max_knots
Max knots for production.
short int * SplineSegments
float * ParamValues
Store parameter values they are not in FastSplineInfo as in case of GPU we need to copy paste it to G...
bool useGPU
Whether to use GPU or not.
◆ ~SplineBase()
| SplineBase::~SplineBase |
( |
| ) |
|
|
virtual |
◆ CalcSplineWeights()
| virtual void SplineBase::CalcSplineWeights |
( |
| ) |
|
|
protectedpure virtual |
CPU based code which eval weight for each spline.
Splines are stored using a flat monolithic structure. The monolith is organised as follows:
Spline 0
Segment 0: [ Y | B | C | D ]
Segment 1: [ Y | B | C | D ]
Segment 2: [ Y | B | C | D ]
Spline 1
Segment 0: [ Y | B | C | D ]
Segment 1: [ Y | B | C | D ]
Segment 2: [ Y | B | C | D ]
Spline 2
Segment 0: [ Y | B | C | D ]
Segment 1: [ Y | B | C | D ]
Segment 2: [ Y | B | C | D ]
...
Once coefficient are grabbed we calculate weight using:
weight = Y + B*dx + C*dx^2 + D*dx^3;
Implemented in PySplineBase, UnbinnedSplineHandler, and BinnedSplineHandler.
◆ CheckSegmentValidity()
Validates that the spline segment is correct for the given variation.
- Parameters
-
| i | Index of the spline in SplineInfoArray. |
| segment | The segment index to validate. |
| xvar | The variation value being checked. |
| xPts | The array of x-values for the spline. |
Definition at line 35 of file SplineBase.cpp.
40 if (xPts[segment] > xvar && segment != 0) {
42 MACH3LOG_ERROR(
"IT SHOULD ALWAYS BE BELOW! (except when segment 0)");
47 for (
size_t j = 0; j < xPts.size(); ++j) {
Custom exception class used throughout MaCh3.
◆ Evaluate()
| virtual void SplineBase::Evaluate |
( |
| ) |
|
|
pure virtual |
CW: This Eval should be used when using two separate x,{y,a,b,c,d} arrays to store the weights; probably the best one here! Same thing but pass parameter spline segments instead of variations.
Implemented in PySplineBase, UnbinnedSplineHandler, and BinnedSplineHandler.
◆ FindSplineSegment()
| void SplineBase::FindSplineSegment |
( |
| ) |
|
|
protected |
CW:Code used in step by step reweighting, Find Spline Segment for each param.
Definition at line 58 of file SplineBase.cpp.
74 if(xArray.size() == 0)
continue;
83 if (xvar <= xArray[0]) {
86 }
else if (xvar >= xArray[nPoints-1]) {
90 }
else if( xArray[PreviousSegment+1] > xvar && xvar >= xArray[PreviousSegment] ) {
91 segment = PreviousSegment;
98 while (kHigh - segment > 1) {
102 if (xvar > xArray[kHalf]) {
111 if (segment >= nPoints-1 && nPoints > 1) segment = nPoints-2;
void CheckSegmentValidity(const M3::int_t i, const M3::int_t segment, const M3::float_t xvar, const std::vector< M3::float_t > &xPts) const
Validates that the spline segment is correct for the given variation.
std::vector< FastSplineInfo > SplineInfoArray
◆ GetName()
| virtual std::string SplineBase::GetName |
( |
| ) |
const |
|
inlinevirtual |
◆ GetNParams()
| short int SplineBase::GetNParams |
( |
| ) |
const |
|
inline |
Get number of spline parameters.
Definition at line 44 of file SplineBase.h.
◆ GetTF1Coeff()
| void SplineBase::GetTF1Coeff |
( |
TF1_red *& |
spl, |
|
|
int & |
nPoints, |
|
|
float *& |
coeffs |
|
) |
| const |
|
protected |
CW: Gets the polynomial coefficients for TF1.
- Parameters
-
| spl | pointer to TF1_red that will be checked |
| nPoints | number of knots |
| coeffs | Array holding coefficients for each knot |
Definition at line 129 of file SplineBase.cpp.
146 for (
int i = 0; i < nPoints; i++) {
constexpr int _nTF1Coeff_
KS: For TF1 we store at most 5 coefficients, we could make it more flexible but for now define it her...
double GetParameter(M3::int_t Parameter) const
Get a parameter value.
int GetSize() const
Get the size.
◆ LoadFastSplineInfoDir()
| void SplineBase::LoadFastSplineInfoDir |
( |
std::unique_ptr< TFile > & |
SplineFile | ) |
|
|
protected |
KS: Load preprocessed FastSplineInfo.
- Parameters
-
| File | File from which we load new tree |
Definition at line 181 of file SplineBase.cpp.
183 TTree *FastSplineInfoTree = SplineFile->Get<TTree>(
"FastSplineInfoTree");
186 FastSplineInfoTree->SetBranchAddress(
"nPts", &nPoints);
187 FastSplineInfoTree->SetBranchAddress(
"xPts", &xtemp);
194 FastSplineInfoTree->GetEntry(i);
198 if(nPoints == -999)
continue;
◆ LoadSplineFile()
| virtual void SplineBase::LoadSplineFile |
( |
std::string |
FileName | ) |
|
|
pure virtual |
◆ PrepareFastSplineInfoDir()
| void SplineBase::PrepareFastSplineInfoDir |
( |
std::unique_ptr< TFile > & |
SplineFile | ) |
const |
|
protected |
KS: Prepare Fast Spline Info within SplineFile.
- Parameters
-
| File | File to which we add new tree |
Definition at line 153 of file SplineBase.cpp.
155 TTree *FastSplineInfoTree =
new TTree(
"FastSplineInfoTree",
"FastSplineInfoTree");
159 FastSplineInfoTree->Branch(
"nPts", &nPoints,
"nPts/I");
160 FastSplineInfoTree->Branch(
"xPts", xtemp,
"xPts[nPts]/F");
170 FastSplineInfoTree->Fill();
174 FastSplineInfoTree->Write();
176 delete FastSplineInfoTree;
◆ PrepareSplineFile()
| virtual void SplineBase::PrepareSplineFile |
( |
std::string |
FileName | ) |
|
|
pure virtual |
◆ SetupSegments()
| void SplineBase::SetupSegments |
( |
| ) |
|
|
protected |
Since we find segment before actual reweight and sometimes we want to copy it to GPU we have different functionality depending if GPU or CPU.
Definition at line 208 of file SplineBase.cpp.
__host__ void InitGPU_Vals(float **vals)
Allocate memory for spline segments.
__host__ void InitGPU_Segments(short int **segment)
Allocate memory for spline segments.
◆ SynchroniseMemTransfer()
| void SplineBase::SynchroniseMemTransfer |
( |
| ) |
const |
KS: After calculations are done on GPU we copy memory to CPU. This operation is asynchronous meaning while memory is being copied some operations are being carried. Memory must be copied before actual reweight. This function make sure all has been copied.
Definition at line 231 of file SplineBase.cpp.
__host__ void SynchroniseSplines()
Make sure all Cuda threads finished execution.
◆ _max_knots
| short int SplineBase::_max_knots |
|
protected |
◆ gpu_monolith
KS: Store info about Spline monolith, this allow to obtain better step time. As all necessary information for spline weight calculation are here meaning better cache hits.
Definition at line 120 of file SplineBase.h.
◆ nParams
| short int SplineBase::nParams |
|
protected |
Number of parameters that have splines.
Definition at line 113 of file SplineBase.h.
◆ NSplines_valid
| unsigned int SplineBase::NSplines_valid |
|
protected |
◆ ParamValues
| float* SplineBase::ParamValues |
|
protected |
Store parameter values they are not in FastSplineInfo as in case of GPU we need to copy paste it to GPU.
Definition at line 111 of file SplineBase.h.
◆ SplineInfoArray
Array of FastSplineInfo structs: keeps information on each spline for fast evaluation Method identical to TSpline3::Eval(double) but faster because less operations
Definition at line 106 of file SplineBase.h.
◆ SplineSegments
| short int* SplineBase::SplineSegments |
|
protected |
Store currently found segment they are not in FastSplineInfo as in case of GPU we need to copy paste it to GPU
- Warning
- this is being used sometimes by GPU, therefore must be raw pointer!
Definition at line 109 of file SplineBase.h.
◆ useGPU
The documentation for this class was generated from the following files: