ElasticArms.h
Go to the documentation of this file.
1 #ifndef EARMS_ELASTICARMS_H
2 #define EARMS_ELASTICARMS_H
3 #include <vector>
4 
5 namespace earms {
6  ///
7  /// Fit a vertex and prongs to a collection of hits using the
8  /// "elastic arms" method
9  ///
10  class ElasticArms {
11  public:
12  ///
13  /// Construct an elastic arms fitter
14  ///
15  /// \param n - number of hits
16  /// \param m - number of prongs
17  /// \param lambda - noise penalty
18  /// \param lambdav - distance scale from vertex to first hit
19  ///
20  ElasticArms(unsigned int n, unsigned int m, double lambda, double lambdav);
21 
22  ///
23  /// Add a hit to the fit
24  ///
25  /// \param i - hit index [0...N)
26  /// \param z - z location of hit (cm)
27  /// \param xory - x or y location of hit (cm)
28  /// \param sigma - hit location uncertainty (cm)
29  /// \param view - X view or Y view?
30  ///
31  void SetHit(unsigned int i, double z, double xory, double sigma, int view);
32 
33  ///
34  /// The the annealing temperature.
35  ///
36  /// \param t - the temperature t is in units of chi^2
37  ///
38  void SetT(double t);
39 
40  ///
41  /// The the noise penalty
42  ///
43  /// \param lam - the noise penalty in units of chi^2
44  ///
45  void SetLambda(double lam);
46 
47  ///
48  /// Update the matrix of associations
49  ///
50  void UpdateVia();
51 
52  ///
53  /// Update the vector of arm-vertex distances
54  ///
55  void UpdateDaa();
56 
57  ///
58  /// Set the vertex parameters
59  ///
60  /// \param x - x position in cm
61  /// \param y - y position in cm
62  /// \param z - z position in cm
63  ///
64  void SetVertex(double x, double y, double z);
65 
66  void GetVertex(double& x, double& y, double& z) const;
67 
68  ///
69  /// Set the arm direction parameters
70  ///
71  /// \param theta - zenith angle in radians
72  /// \param phi - azimuthal angle in radians
73  ///
74  void SetArm(unsigned int i, double theta, double phi);
75 
76  ///
77  /// Compute the distances^2 from hit i to track a
78  ///
79  void UpdateMia();
80 
81  ///
82  /// Return the "energy" function, a chi^2-like goodness of fit
83  ///
84  double E();
85 
86  ///
87  /// Calculation the total weight of an arm a. Roughly speaking
88  /// this is the number of hits on the arm.
89  ///
90  double SumVi(unsigned int a) const;
91 
92  ///
93  /// Find the leading arm. The with the highest weight
94  ///
95  unsigned int LeadingArm() const;
96 
97  private:
98  int fProngFit; ///< 1 - treat arms as prongs in fit, 0 - treat as lines
99  double fT; ///< A measure of the "temperature" in units of sigma^2
100  double fBeta; ///< 1/T in units of 1/sigma^2
101  bool fBetaUnchanged; ///< Whether fBeta is the same since last call to UpdateMia
102  double fLambda; ///< Noise penalty term in units of sigma^2
103  double fExpBetaLambda; ///< exp(-fBeta*fLambda) - computed once used many
104  double fLambdaV; ///< Distance scale for hits to appear on (cm)
105 
106  public:
107  /// Data to fit
108  unsigned int fN; ///< Number of hits
109  std::vector<double> fXorY; ///< Transverse hit positions (cm)
110  std::vector<int> fView; ///< Which view is the hit in?
111  std::vector<double> fZ; ///< Z locations of hits (cm)
112  std::vector<double> fWsqr; ///< Combined weight for hit 1/(sigmaH^2 + sigmaMS^2)
113  std::vector<double> fDhi; ///< From hit to vertex location^2 [cm^2]
114  std::vector<double> fDaa; ///< Distance from vertex to prong [cm]
115 
116  typedef std::vector< std::vector<double> > matrix;
117  matrix fMia; ///< Distance^2 hit i to track a (sigma^2)
118  std::vector< std::vector<bool> > fMiaUnchanged; ///< Is fMia changed in UpdateMia?
119  std::vector<bool> fMiaRowUnchanged; ///< Is a row of fMia changed in UpdateMia?
120  std::vector<bool> fMiaColUnchanged; ///< Is a column of fMia changed in UpdateMia?
121  matrix fExpBetaMia; ///< exp(-fBeta*Mia) - compute once used many time
122  matrix fVia; ///< Strength of association hit i to track a
123 
124  public:
125  /// Model parameters
126  double fX0; ///< Vertex x location (cm)
127  double fY0; ///< Vertex y location (cm)
128  double fZ0; ///< Vertex z location (cm)
129  unsigned int fM; ///< Number of arms
130  std::vector<double> fdXds; ///< Track dx/ds
131  std::vector<double> fdYds; ///< Track dy/ds
132  std::vector<double> fdZds; ///< Track dz/ds
133  };
134 }
135 
136 #endif
137 ////////////////////////////////////////////////////////////////////////
double fBeta
1/T in units of 1/sigma^2
Definition: ElasticArms.h:100
double fLambda
Noise penalty term in units of sigma^2.
Definition: ElasticArms.h:102
unsigned int LeadingArm() const
std::vector< double > fWsqr
Combined weight for hit 1/(sigmaH^2 + sigmaMS^2)
Definition: ElasticArms.h:112
void SetLambda(double lam)
double fY0
Vertex y location (cm)
Definition: ElasticArms.h:127
std::vector< bool > fMiaColUnchanged
Is a column of fMia changed in UpdateMia?
Definition: ElasticArms.h:120
std::vector< double > fDhi
From hit to vertex location^2 [cm^2].
Definition: ElasticArms.h:113
double fZ0
Vertex z location (cm)
Definition: ElasticArms.h:128
double fLambdaV
Distance scale for hits to appear on (cm)
Definition: ElasticArms.h:104
Elastic Arms vertex finding algorithm.
unsigned int fM
Number of arms.
Definition: ElasticArms.h:129
bool fBetaUnchanged
Whether fBeta is the same since last call to UpdateMia.
Definition: ElasticArms.h:101
std::vector< double > fXorY
Transverse hit positions (cm)
Definition: ElasticArms.h:109
void SetHit(unsigned int i, double z, double xory, double sigma, int view)
Definition: ElasticArms.cxx:75
std::vector< double > fdZds
Track dz/ds.
Definition: ElasticArms.h:132
double SumVi(unsigned int a) const
std::vector< std::vector< double > > matrix
Definition: ElasticArms.h:116
const double a
void SetT(double t)
Definition: ElasticArms.cxx:90
void GetVertex(double &x, double &y, double &z) const
unsigned int fN
Data to fit.
Definition: ElasticArms.h:108
std::vector< double > fDaa
Distance from vertex to prong [cm].
Definition: ElasticArms.h:114
z
Definition: test.py:28
double sigma(TH1F *hist, double percentile)
int fProngFit
1 - treat arms as prongs in fit, 0 - treat as lines
Definition: ElasticArms.h:98
std::vector< double > fZ
Z locations of hits (cm)
Definition: ElasticArms.h:111
double fX0
Model parameters.
Definition: ElasticArms.h:126
void SetArm(unsigned int i, double theta, double phi)
std::vector< bool > fMiaRowUnchanged
Is a row of fMia changed in UpdateMia?
Definition: ElasticArms.h:119
std::vector< double > fdXds
Track dx/ds.
Definition: ElasticArms.h:130
matrix fVia
Strength of association hit i to track a.
Definition: ElasticArms.h:122
std::vector< std::vector< bool > > fMiaUnchanged
Is fMia changed in UpdateMia?
Definition: ElasticArms.h:118
ElasticArms(unsigned int n, unsigned int m, double lambda, double lambdav)
Definition: ElasticArms.cxx:33
std::vector< int > fView
Which view is the hit in?
Definition: ElasticArms.h:110
matrix fExpBetaMia
exp(-fBeta*Mia) - compute once used many time
Definition: ElasticArms.h:121
double fExpBetaLambda
exp(-fBeta*fLambda) - computed once used many
Definition: ElasticArms.h:103
std::vector< double > fdYds
Track dy/ds.
Definition: ElasticArms.h:131
double fT
A measure of the "temperature" in units of sigma^2.
Definition: ElasticArms.h:99
void SetVertex(double x, double y, double z)
matrix fMia
Distance^2 hit i to track a (sigma^2)
Definition: ElasticArms.h:117