ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtWeightedGaussianTrunc.cxx
Go to the documentation of this file.
2 
3 #include "AtHit.h"
4 #include "AtSample.h" // for RandomSample
5 
6 #include <Math/Point3D.h> // for operator-
7 #include <Math/Vector3D.h> // for DisplacementVector3D
8 #include <TRandom.h>
9 
10 #include <algorithm>
11 #include <cmath> // for sqrt
12 using namespace RandomSample;
13 
14 std::vector<AtHit> AtWeightedGaussianTrunc::SampleHits(int N)
15 {
16  int p1, p2;
17  int pclouds = fHits->size();
18  int counter = 0;
19  double dist = 0;
20  double sigma = 30.0;
21  double y = 0;
22  double gauss = 0;
23  double w = 0;
24  double Tcharge = 0;
25  double avgCharge = 0;
26  std::vector<double> Proba;
27  std::vector<AtHit> retVec;
28 
29  for (int i = 0; i < pclouds; i++)
30  Tcharge += fHits->at(i)->GetCharge();
31 
32  if (Tcharge > 0)
33  for (int i = 0; i < pclouds; i++)
34  Proba.push_back(fHits->at(i)->GetCharge());
35 
36  avgCharge = Tcharge / (double)pclouds;
37  p1 = gRandom->Uniform() * pclouds;
38  retVec.push_back(*fHits->at(p1));
39 
40  do {
41  counter++;
42  p2 = gRandom->Uniform() * pclouds;
43  if (p2 == p1)
44  continue;
45  dist = std::sqrt((fHits->at(p1)->GetPosition() - fHits->at(p2)->GetPosition()).Mag2());
46  gauss = 1.0 * exp(-1.0 * pow(dist / sigma, 2));
47  y = gRandom->Uniform();
48  w = gRandom->Uniform() * 4. * avgCharge;
49  if (fHits->at(p2)->GetCharge() > w || y < gauss) {
50  retVec.push_back(*fHits->at(p2));
51  }
52  } while (retVec.size() < N && counter < pclouds && counter < 50);
53 
54  return retVec;
55 }
56 
57 std::vector<double> AtWeightedGaussianTrunc::PDF(const AtHit &hit)
58 {
59  return {};
60 }
RandomSample
Definition: AtSampleConsensus.h:26
RandomSample::AtSample::fHits
const std::vector< const AtHit * > * fHits
Definition: AtSample.h:38
AtHit.h
gauss
double gauss(double x, const double *p)
Definition: lmfit.cxx:21
y
const double * y
Definition: lmcurve.cxx:20
RandomSample::AtWeightedGaussianTrunc::SampleHits
virtual std::vector< AtHit > SampleHits(int N) override
Sample hits (AtHit) from fHits.
Definition: AtWeightedGaussianTrunc.cxx:14
RandomSample::AtWeightedGaussianTrunc::PDF
virtual std::vector< double > PDF(const AtHit &hit) override
Definition: AtWeightedGaussianTrunc.cxx:57
AtWeightedGaussianTrunc.h
AtSample.h
AtHit
Point in space with charge.
Definition: AtHit.h:27