ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
RandomSample::AtSample Class Referenceabstract

Interface for randomly sampling AtHits. More...

#include <AtSample.h>

Inheritance diagram for RandomSample::AtSample:
Inheritance graph
[legend]
Collaboration diagram for RandomSample::AtSample:
Collaboration graph
[legend]

Public Member Functions

virtual ~AtSample ()=default
 
virtual std::vector< AtHitSampleHits (int N)
 Sample hits (AtHit) from fHits. More...
 
std::vector< ROOT::Math::XYZPointSamplePoints (int N)
 Sample spacial locations (XYZPoints) from fHits. More...
 
virtual void SetHitsToSample (const std::vector< const AtHit * > &hits)=0
 
void SetHitsToSample (const std::vector< HitPtr > &hits)
 
void SetHitsToSample (const std::vector< AtHit > &hits)
 
void SetSampleWithReplacement (bool val)
 

Protected Types

using HitPtr = std::unique_ptr< AtHit >
 

Protected Member Functions

virtual std::vector< double > PDF (const AtHit &hit)=0
 
void FillCDF ()
 
std::vector< int > sampleIndicesFromCDF (int N, std::vector< int > vetoed={})
 
int getIndexFromCDF (double r, double rmCFD, std::vector< int > vetoed)
 Get the index i where CDF[i] >= r and CDF[i-1] < r. More...
 
double getPDFfromCDF (int index)
 

Static Protected Member Functions

template<typename T >
static bool isInVector (T val, std::vector< T > vec)
 

Protected Attributes

const std::vector< const AtHit * > * fHits
 
std::vector< double > fCDF
 
bool fWithReplacement {false}
 

Detailed Description

Interface for randomly sampling AtHits.

Samples according to the cumulitive distribution function fCDF.

Definition at line 35 of file AtSample.h.

Member Typedef Documentation

◆ HitPtr

using RandomSample::AtSample::HitPtr = std::unique_ptr<AtHit>
protected

Definition at line 37 of file AtSample.h.

Constructor & Destructor Documentation

◆ ~AtSample()

virtual RandomSample::AtSample::~AtSample ( )
virtualdefault

Member Function Documentation

◆ FillCDF()

void AtSample::FillCDF ( )
protected

Fill the cumulitive distribution function to sample using the marginal PDFs returned by the function PDF(const AtHit &hit) from every entry in the vector fHits.

Each marginal PDF is normalized to construct the final CDF. Assumes the marginal PDFs are independent (i.e. the joint PDF is just the product of all marginal PDFs)

Definition at line 115 of file AtSample.cxx.

◆ getIndexFromCDF()

int AtSample::getIndexFromCDF ( double  r,
double  rmCFD,
std::vector< int >  vetoed 
)
protected

Get the index i where CDF[i] >= r and CDF[i-1] < r.

Loop through fCDF, skipping any index in vetoed, for the index that corresponds to r So need to track what indices are not allowed (vetoed) and the amount of the CDF that has been removed (i.e. sum of PDFs for all removed indices). (rmCDF) The new CDF is then oldCDF/(1-rmCDF) We then need to loop through CDF and look for index where CDF[i] >= r

Parameters
[in]rRandom number between [0,1) to compare to fCDF
[in]vetoedIndices to ignore while searching fCDF

Definition at line 54 of file AtSample.cxx.

◆ getPDFfromCDF()

double AtSample::getPDFfromCDF ( int  index)
protected

Definition at line 104 of file AtSample.cxx.

◆ isInVector()

template<typename T >
static bool RandomSample::AtSample::isInVector ( val,
std::vector< T >  vec 
)
inlinestaticprotected

Definition at line 72 of file AtSample.h.

◆ PDF()

virtual std::vector<double> RandomSample::AtSample::PDF ( const AtHit hit)
protectedpure virtual

Computes the unnormalized marginal PDFs at the hit.

For example, a charge-weighted and spacial gaussian would looke like return {charge, gaussian_pdf(distance, sigma)};

Returns
vector where each element is a different maginal pdf

Implemented in RandomSample::AtIndependentSample, RandomSample::AtWeightedGaussian, RandomSample::AtY, RandomSample::AtGaussian, RandomSample::AtUniform, RandomSample::AtWeightedGaussianTrunc, and RandomSample::AtChargeWeighted.

◆ SampleHits()

std::vector< AtHit > AtSample::SampleHits ( int  N)
virtual

Sample hits (AtHit) from fHits.

Assumes fCDF is already setup and we are just using it.

Reimplemented in RandomSample::AtY, RandomSample::AtSampleFromReference, RandomSample::AtWeightedY, RandomSample::AtUniform, and RandomSample::AtWeightedGaussianTrunc.

Definition at line 20 of file AtSample.cxx.

◆ sampleIndicesFromCDF()

std::vector< int > AtSample::sampleIndicesFromCDF ( int  N,
std::vector< int >  vetoed = {} 
)
protected

Get a list of indices aampled according to the constructed fCDF (assumes FillCDF() has been called already)

Parameters
[in]Nnumber of pcoints to sample. If sampling without replacement this should be small compared to the total number of hits in the hit array.
[in]vetoedIndices to not sample (even if sampling with replacement).

Definition at line 77 of file AtSample.cxx.

◆ SamplePoints()

std::vector< ROOT::Math::XYZPoint > AtSample::SamplePoints ( int  N)

Sample spacial locations (XYZPoints) from fHits.

Calls SampleHits(int N).

Definition at line 34 of file AtSample.cxx.

◆ SetHitsToSample() [1/3]

void AtSample::SetHitsToSample ( const std::vector< AtHit > &  hits)

Definition at line 151 of file AtSample.cxx.

◆ SetHitsToSample() [2/3]

virtual void RandomSample::AtSample::SetHitsToSample ( const std::vector< const AtHit * > &  hits)
pure virtual

◆ SetHitsToSample() [3/3]

void AtSample::SetHitsToSample ( const std::vector< HitPtr > &  hits)

Definition at line 146 of file AtSample.cxx.

◆ SetSampleWithReplacement()

void RandomSample::AtSample::SetSampleWithReplacement ( bool  val)
inline

Definition at line 52 of file AtSample.h.

Member Data Documentation

◆ fCDF

std::vector<double> RandomSample::AtSample::fCDF
protected

Definition at line 39 of file AtSample.h.

◆ fHits

const std::vector<const AtHit *>* RandomSample::AtSample::fHits
protected

Definition at line 38 of file AtSample.h.

◆ fWithReplacement

bool RandomSample::AtSample::fWithReplacement {false}
protected

Definition at line 40 of file AtSample.h.


The documentation for this class was generated from the following files: