ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtSample.h
Go to the documentation of this file.
1 #ifndef ATHITSAMPLER_H
2 #define ATHITSAMPLER_H
3 
4 #include <Math/Point3Dfwd.h> // for XYZPoint
5 
6 #include <algorithm>
7 #include <memory>
8 #include <vector>
9 
10 class AtHit;
11 
25 namespace RandomSample {
26 enum class SampleMethod;
27 
35 class AtSample {
36 protected:
37  using HitPtr = std::unique_ptr<AtHit>;
38  const std::vector<const AtHit *> *fHits; //< Hits to sample from
39  std::vector<double> fCDF; //< Cummulative distribution function for hits
40  bool fWithReplacement{false}; //< If we should sample with replacement
41 
42 public:
43  virtual ~AtSample() = default;
44 
45  virtual std::vector<AtHit> SampleHits(int N);
46  std::vector<ROOT::Math::XYZPoint> SamplePoints(int N);
47 
48  virtual void SetHitsToSample(const std::vector<const AtHit *> &hits) = 0;
49  [[deprecated]] void SetHitsToSample(const std::vector<HitPtr> &hits);
50  [[deprecated]] void SetHitsToSample(const std::vector<AtHit> &hits);
51 
52  void SetSampleWithReplacement(bool val) { fWithReplacement = val; }
53 
54 protected:
63  virtual std::vector<double> PDF(const AtHit &hit) = 0;
64  void FillCDF();
65 
66  std::vector<int> sampleIndicesFromCDF(int N, std::vector<int> vetoed = {});
67  int getIndexFromCDF(double r, double rmCFD, std::vector<int> vetoed);
68 
69  double getPDFfromCDF(int index);
70 
71  template <typename T>
72  static inline bool isInVector(T val, std::vector<T> vec)
73  {
74  if (vec.size() == 0)
75  return false;
76  return std::find(vec.begin(), vec.end(), val) != vec.end();
77  }
78 };
79 } // namespace RandomSample
80 
81 #endif //#ifndef ATHITSAMPLER_H
RandomSample::AtSample::SampleHits
virtual std::vector< AtHit > SampleHits(int N)
Sample hits (AtHit) from fHits.
Definition: AtSample.cxx:20
RandomSample::AtSample::SetHitsToSample
virtual void SetHitsToSample(const std::vector< const AtHit * > &hits)=0
RandomSample::AtSample::SetSampleWithReplacement
void SetSampleWithReplacement(bool val)
Definition: AtSample.h:52
RandomSample::AtSample::~AtSample
virtual ~AtSample()=default
RandomSample::SampleMethod
SampleMethod
. Methods of random sampling.
Definition: AtSampleMethods.h:22
RandomSample
Definition: AtSampleConsensus.h:26
RandomSample::AtSample::fWithReplacement
bool fWithReplacement
Definition: AtSample.h:40
RandomSample::AtSample::sampleIndicesFromCDF
std::vector< int > sampleIndicesFromCDF(int N, std::vector< int > vetoed={})
Definition: AtSample.cxx:77
RandomSample::AtSample::getPDFfromCDF
double getPDFfromCDF(int index)
Definition: AtSample.cxx:104
RandomSample::AtSample::HitPtr
std::unique_ptr< AtHit > HitPtr
Definition: AtSample.h:37
RandomSample::AtSample::getIndexFromCDF
int getIndexFromCDF(double r, double rmCFD, std::vector< int > vetoed)
Get the index i where CDF[i] >= r and CDF[i-1] < r.
Definition: AtSample.cxx:54
RandomSample::AtSample::fCDF
std::vector< double > fCDF
Definition: AtSample.h:39
RandomSample::AtSample::fHits
const std::vector< const AtHit * > * fHits
Definition: AtSample.h:38
RandomSample::AtSample::SamplePoints
std::vector< ROOT::Math::XYZPoint > SamplePoints(int N)
Sample spacial locations (XYZPoints) from fHits.
Definition: AtSample.cxx:34
RandomSample::AtSample::FillCDF
void FillCDF()
Definition: AtSample.cxx:115
RandomSample::AtSample::PDF
virtual std::vector< double > PDF(const AtHit &hit)=0
RandomSample::AtSample
Interface for randomly sampling AtHits.
Definition: AtSample.h:35
RandomSample::AtSample::isInVector
static bool isInVector(T val, std::vector< T > vec)
Definition: AtSample.h:72
AtHit
Point in space with charge.
Definition: AtHit.h:27