Public Member Functions | Public Attributes | List of all members
earms::GridSearch Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-28/ElasticArms/art/GridSearch.h"

Public Member Functions

 GridSearch (double xmn, double xmx, double ymn, double ymx, double zmn, double zmx, double colinear, unsigned int nseeddir)
 
void AddVertex (double x, double y, double z)
 
void AddVtxPoints (const ElasticArms &arms, const std::vector< double > &mx, const std::vector< double > &bx, const std::vector< double > &my, const std::vector< double > &by, const std::vector< double > &f)
 
void AddHoughIntersections (const rb::HoughResult &hrx, const rb::HoughResult &hry, unsigned int nmx, unsigned int nmh, bool flipped=false)
 
void AddDirection (double theta, double phi)
 
void SetStandardDirections ()
 
double ChooseBestProngDir (ElasticArms &arms, unsigned int i)
 
double FindBestVtx (ElasticArms &arms)
 

Public Attributes

double fXmin
 Only consider vertex locations inside a box [cm]. More...
 
double fXmax
 Only consider vertex locations inside a box [cm]. More...
 
double fYmin
 Only consider vertex locations inside a box [cm]. More...
 
double fYmax
 Only consider vertex locations inside a box [cm]. More...
 
double fZmin
 Only consider vertex locations inside a box [cm]. More...
 
double fZmax
 Only consider vertex locations inside a box [cm]. More...
 
double fColinear
 |dot product|>fColinear means lines are colinear More...
 
unsigned int fNseedDir
 How many default seed directoins to check. More...
 
std::vector< double > fX
 List of vertex x coordinates. More...
 
std::vector< double > fY
 List of vertex y coordinates. More...
 
std::vector< double > fZ
 List of vertex z coorfinates. More...
 
std::vector< double > fTheta
 List of prong directions. More...
 
std::vector< double > fPhi
 List of prong directions. More...
 

Detailed Description

Implement a grid search over a specified range of verticies and directions

Definition at line 21 of file GridSearch.h.

Constructor & Destructor Documentation

earms::GridSearch::GridSearch ( double  xmn,
double  xmx,
double  ymn,
double  ymx,
double  zmn,
double  zmx,
double  colinear,
unsigned int  nseeddir 
)

Construct an object to search for a good elastic arms seed

Parameters
xmn- Lower edge of vertex box [cm]
xmx- Upper edge of vertex box [cm]
ymn- Lower edge of vertex box [cm]
ymx- Upper edge of vertex box [cm]
zmn- Lower edge of vertex box [cm]
zmx- Upper edge of vertex box [cm]
colinear- Cut on dot product to determin colinearity
nseeddir- How many seed directions to check

Definition at line 20 of file GridSearch.cxx.

24  :
25  fXmin(xmn),
26  fXmax(xmx),
27  fYmin(ymn),
28  fYmax(ymx),
29  fZmin(zmn),
30  fZmax(zmx),
31  fColinear(colinear),
32  fNseedDir(nseeddir)
33  { }
double fYmin
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:108
double fColinear
|dot product|>fColinear means lines are colinear
Definition: GridSearch.h:112
unsigned int fNseedDir
How many default seed directoins to check.
Definition: GridSearch.h:113
double fZmax
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:111
double fXmax
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:107
double fXmin
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:106
double fYmax
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:109
double fZmin
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:110

Member Function Documentation

void earms::GridSearch::AddDirection ( double  theta,
double  phi 
)

Add a direction in spherical coordinates to the list of arm directions to be considered.

Parameters
theta,phi- spherical coordinates of arm direction

Definition at line 131 of file GridSearch.cxx.

References fPhi, fTheta, and push_back().

Referenced by earms::ElasticArmsHS::FindSeed().

132  {
133  fTheta.push_back(theta);
134  fPhi. push_back(phi);
135  }
std::vector< double > fPhi
List of prong directions.
Definition: GridSearch.h:119
std::vector< double > fTheta
List of prong directions.
Definition: GridSearch.h:118
base_types push_back(int_type())
void earms::GridSearch::AddHoughIntersections ( const rb::HoughResult hrx,
const rb::HoughResult hry,
unsigned int  nmx,
unsigned int  nmh,
bool  flipped = false 
)

Produce a list of vertex seed locations from the hough analysis

Parameters
hrx- Hough results for the x view
hry- Hough results for the y view
nmx- Maximum number of hough results to use
nmh- Number of hough lines to match in other view
flipped- Used internally when hrx <-> hry

Definition at line 139 of file GridSearch.cxx.

References AddVertex(), stan::math::dot(), stan::math::fabs(), fColinear, rb::HoughResult::fPeak, MECModelEnuComparisons::i, calib::j, rb::HoughResult::SlopeIcept(), std::sqrt(), submit_syst::x, submit_syst::y, and test::z.

Referenced by earms::ElasticArmsHS::FindSeed().

144  {
145  //
146  // For there to be any intersections we need at minimum of two lines
147  // in x and one in y
148  //
149  if ((hrx.fPeak.size()<2) && (hry.fPeak.size()<1)){
150  //try flipping before we exit
151  if (flipped==false) {
152  this->AddHoughIntersections(hry,hrx,nmx,nmatch,true);
153  }
154  return;
155  }
156 
157  //
158  // Only use the top set of results
159  //
160  unsigned int nx = hrx.fPeak.size();
161  if (nx>nmx) nx = nmx;
162 
163  unsigned int i, j, k;
164  //
165  // Loop over all the intersections in the x view. Grab y location
166  // from the dominant line in that view.
167  //
168  double x, y, z;
169  double my, by;
170  double dot;
171 
172  unsigned int ny = nmatch;
173  if (hry.fPeak.size()<ny) ny = hry.fPeak.size();
174 
175  for (i=0; i<nx; ++i) {
176  double mi, bi;
177  hrx.SlopeIcept(i, &mi, &bi);
178  for (j=i+1; j<nx; ++j) {
179  double mj, bj;
180  hrx.SlopeIcept(j, &mj, &bj);
181 
182  // Skip lines paired with themselves
183  if (mi==mj) continue;
184 
185  // Also skip lines that are nearly colinear
186  dot = fabs((mi*mj+1.0)/sqrt(mi*mi+1.0)/sqrt(mj*mj+1.0));
187  if (dot>fColinear) continue;
188 
189  z = (bj-bi)/(mi-mj);
190  x = 0.5*((mi+mj)*z+(bi+bj));
191 
192 
193  //
194  // What y value to assign to this x-z pair? Check the top
195  // nmatch hough lines in the other view.
196  //
197  for (k=0; k<ny; ++k) {
198  hry.SlopeIcept(k, &my, &by);
199 
200  y = my*z + by;
201 
202 
203  if (flipped) this->AddVertex(y,x,z);
204  else this->AddVertex(x,y,z);
205  }
206 
207  } // loop on j hough lines in x view
208  } // loop on i hough lines x view
209 
210  //
211  // Repeat exchanging the meaning of x and y
212  //
213  if (flipped==false) {
214  this->AddHoughIntersections(hry,hrx,nmx,nmatch,true);
215  }
216  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
std::vector< HoughPeak > fPeak
List of peaks found in Hough space.
Definition: HoughResult.h:61
double fColinear
|dot product|>fColinear means lines are colinear
Definition: GridSearch.h:112
T sqrt(T number)
Definition: d0nt_math.hpp:156
void AddHoughIntersections(const rb::HoughResult &hrx, const rb::HoughResult &hry, unsigned int nmx, unsigned int nmh, bool flipped=false)
Definition: GridSearch.cxx:139
void SlopeIcept(unsigned int i, double *m, double *b) const
Slope and intercepts of Hough lines.
Definition: HoughResult.cxx:62
const double j
Definition: BetheBloch.cxx:29
z
Definition: test.py:28
void AddVertex(double x, double y, double z)
Definition: GridSearch.cxx:37
double dot(const std::vector< double > &x, const std::vector< double > &y)
Definition: dot.hpp:10
void earms::GridSearch::AddVertex ( double  x,
double  y,
double  z 
)

Add a vertex point to the list to be considered

Parameters
x,y,z- vertex location (cm)

Definition at line 37 of file GridSearch.cxx.

References fX, fXmax, fXmin, fY, fYmax, fYmin, fZ, fZmax, and fZmin.

Referenced by AddHoughIntersections(), and AddVtxPoints().

38  {
39  if (x<fXmin) return;
40  if (y<fYmin) return;
41  if (z<fZmin) return;
42  if (x>fXmax) return;
43  if (y>fYmax) return;
44  if (z>fZmax) return;
45  fX.push_back(x);
46  fY.push_back(y);
47  fZ.push_back(z);
48  }
double fYmin
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:108
std::vector< double > fZ
List of vertex z coorfinates.
Definition: GridSearch.h:117
double fZmax
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:111
std::vector< double > fY
List of vertex y coordinates.
Definition: GridSearch.h:116
double fXmax
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:107
z
Definition: test.py:28
double fXmin
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:106
double fYmax
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:109
std::vector< double > fX
List of vertex x coordinates.
Definition: GridSearch.h:115
double fZmin
Only consider vertex locations inside a box [cm].
Definition: GridSearch.h:110
void earms::GridSearch::AddVtxPoints ( const ElasticArms arms,
const std::vector< double > &  mx,
const std::vector< double > &  bx,
const std::vector< double > &  my,
const std::vector< double > &  by,
const std::vector< double > &  f 
)

Add a collection of vertex seeds near the hit locations specified by f

Parameters
f- a list of percentages marking hits to choose

Definition at line 52 of file GridSearch.cxx.

References AddVertex(), stan::math::fabs(), earms::ElasticArms::fN, earms::ElasticArms::fView, earms::ElasticArms::fXorY, earms::ElasticArms::fZ, MECModelEnuComparisons::i, and calib::j.

Referenced by earms::ElasticArmsHS::FindSeed().

58  {
59  unsigned int i, j;
60  std::vector< std::pair<double, double> > xz;
61  std::vector< std::pair<double, double> > yz;
62 
63  //
64  // Sort the xz and yz hits by z
65  //
66  for (i=0; i<arms.fN; ++i) {
67  if (arms.fView[i]==0) {
68  xz.push_back(std::pair<double,double>(arms.fZ[i], arms.fXorY[i]));
69  }
70  else if (arms.fView[i]==1) {
71  yz.push_back(std::pair<double,double>(arms.fZ[i], arms.fXorY[i]));
72  }
73  else abort();
74  }
75  sort(xz.begin(), xz.end());
76  sort(yz.begin(), yz.end());
77 
78  //
79  // Grab points from the specified locations in the hit lists
80  //
81  unsigned int ix;
82  unsigned int iy;
83  double xseed, zxseed;
84  double yseed, zyseed;
85  for (i=0; i<f.size(); ++i) {
86  ix = fabs(f[i])*xz.size()/100;
87  iy = fabs(f[i])*yz.size()/100;
88 
89 
90  //
91  // In forward direction, pick the hits
92  //
93  if (f[i]>0.0) {
94  zxseed = xz[ix].first;
95  xseed = xz[ix].second;
96  zyseed = yz[iy].first;
97  yseed = yz[iy].second;
98  }
99  else {
100  //
101  // In backward direction, pick mirror images of the hits
102  // reflected across the boundary of the first hit
103  //
104  zxseed = 2.0*xz[0].first -xz[ix].first;
105  xseed = 2.0*xz[0].second-xz[ix].second;
106  zyseed = 2.0*yz[0].first -yz[iy].first;
107  yseed = 2.0*yz[0].second-yz[iy].second;
108  }
109 
110  //
111  // A point on the line in the yz view
112  //
113  for (j=0; j<my.size(); ++j) {
114  this->AddVertex(xseed, my[j]*zxseed+by[j], zxseed);
115  }
116  //
117  // A point on the line in the xz view
118  //
119  for (j=0; j<mx.size(); ++j) {
120  this->AddVertex(mx[j]*zyseed+bx[j], yseed, zyseed);
121  }
122  //
123  // A point that takes information just from the hits
124  //
125  this->AddVertex(xseed, yseed, 0.5*(zxseed+zyseed));
126  }
127  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
const double j
Definition: BetheBloch.cxx:29
void AddVertex(double x, double y, double z)
Definition: GridSearch.cxx:37
double earms::GridSearch::ChooseBestProngDir ( ElasticArms arms,
unsigned int  i 
)

Choose the direction of prong i which gives the least energy

Returns
The best energy found in selecting this arm. Leaves arms in best state found.

Definition at line 248 of file GridSearch.cxx.

References a, b, stan::math::dot(), E, earms::ElasticArms::E(), fColinear, earms::ElasticArms::fdXds, earms::ElasticArms::fdYds, earms::ElasticArms::fdZds, fPhi, fTheta, calib::j, earms::ElasticArms::SetArm(), earms::ElasticArms::UpdateMia(), and earms::ElasticArms::UpdateVia().

Referenced by FindBestVtx().

249  {
250  unsigned int b;
251  unsigned int j, jbest=0;
252  double E = 99E99;
253  double Ebest = 99E99;
254 
255  //
256  // Loop over all directions in the table
257  //
258  for (j=0; j<fTheta.size(); ++j) {
259  arms.SetArm(a, fTheta[j], fPhi[j]);
260  //
261  // Check this direction against arms which have already been set.
262  // If it's too close to an existing arm, skip it.
263  //
264  double dot;
265  double maxdot = -1.0;
266  double mindot = 1.0;
267  for (b=0; b<a; ++b) {
268  dot =
269  arms.fdXds[a]*arms.fdXds[b]+
270  arms.fdYds[a]*arms.fdYds[b]+
271  arms.fdZds[a]*arms.fdZds[b];
272  if (dot>maxdot) maxdot = dot;
273  if (dot<mindot) mindot = dot;
274  }
275  if (maxdot> fColinear) continue;
276  if (mindot<-fColinear) continue;
277 
278  //
279  // Test the goodness of this prong. Remember it if its the best so
280  // far.
281  //
282  arms.UpdateMia();
283  arms.UpdateVia();
284  E = arms.E();
285  if (E<Ebest) {
286  jbest = j;
287  Ebest = E;
288  }
289  }
290  arms.SetArm(a, fTheta[jbest], fPhi[jbest]);
291  return Ebest;
292  }
std::vector< double > fPhi
List of prong directions.
Definition: GridSearch.h:119
double fColinear
|dot product|>fColinear means lines are colinear
Definition: GridSearch.h:112
std::vector< double > fTheta
List of prong directions.
Definition: GridSearch.h:118
Float_t E
Definition: plot.C:20
const double a
const double j
Definition: BetheBloch.cxx:29
double dot(const std::vector< double > &x, const std::vector< double > &y)
Definition: dot.hpp:10
const hit & b
Definition: hits.cxx:21
double earms::GridSearch::FindBestVtx ( ElasticArms arms)

Loop over vertex and direction seeds looking for the best choice.

Returns
The best energy found. Leaves 'arms' in the best state found

Definition at line 296 of file GridSearch.cxx.

References ChooseBestProngDir(), E, earms::ElasticArms::fM, fX, fY, fZ, MECModelEnuComparisons::i, calib::j, M_PI, earms::ElasticArms::SetArm(), and earms::ElasticArms::SetVertex().

Referenced by earms::ElasticArmsHS::FindSeed().

297  {
298  unsigned int i, j;
299  double E = 99E99;
300  double Ebest = 99E99;
301  double xbest=0;
302  double ybest=0;
303  double zbest=0;
304  for (i=0; i<fX.size(); ++i) {
305  arms.SetVertex(fX[i], fY[i], fZ[i]);
306  for (j=0; j<arms.fM; ++j) {
307  arms.SetArm(j, 0.5*M_PI, 2.0*M_PI*(float)j/(float)arms.fM);
308  }
309  for (j=0; j<arms.fM; ++j){
310  E = this->ChooseBestProngDir(arms, j);
311  }
312  if (E<Ebest) {
313  Ebest = E;
314  xbest = fX[i];
315  ybest = fY[i];
316  zbest = fZ[i];
317  }
318  }
319  //
320  // Leave the vertex and arm directions in their best configuration
321  //
322  arms.SetVertex(xbest, ybest, zbest);
323  for (j=0; j<arms.fM; ++j) {
324  arms.SetArm(j, 0.5*M_PI, 2.0*M_PI*(float)j/(float)arms.fM);
325  }
326  for (j=0; j<arms.fM; ++j) E = this->ChooseBestProngDir(arms, j);
327  return E;
328  }
std::vector< double > fZ
List of vertex z coorfinates.
Definition: GridSearch.h:117
#define M_PI
Definition: SbMath.h:34
std::vector< double > fY
List of vertex y coordinates.
Definition: GridSearch.h:116
Float_t E
Definition: plot.C:20
const double j
Definition: BetheBloch.cxx:29
double ChooseBestProngDir(ElasticArms &arms, unsigned int i)
Definition: GridSearch.cxx:248
std::vector< double > fX
List of vertex x coordinates.
Definition: GridSearch.h:115
void earms::GridSearch::SetStandardDirections ( )

Make a list of some standard direction vectors

Set a standard set of directions uniformly distributed on a sphere using the "Golden Section spiral" (http://www.xsi-blog.com/archives/115)

Definition at line 225 of file GridSearch.cxx.

References std::acos(), std::atan2(), std::cos(), fNseedDir, fPhi, fTheta, MECModelEnuComparisons::i, M_PI, nd, push_back(), r(), std::sin(), std::sqrt(), submit_syst::x, submit_syst::y, and test::z.

Referenced by earms::ElasticArmsHS::FindSeed().

226  {
227  static const double nd = fNseedDir;
228  static const double inc = M_PI*(3.0-sqrt(5.0));
229  static const double off = 2.0/nd;
230 
231  unsigned int i;
232  double x, y, z;
233  double r, phi;
234  for (i=0; i<fNseedDir; ++i) {
235  y = (i+0.5)*off-1.0;
236  r = sqrt(1.0-y*y);
237  phi = i*inc;
238  x = r*cos(phi);
239  z = r*sin(phi);
240 
241  fTheta.push_back(acos(z/sqrt(x*x+y*y+z*z)));
242  fPhi. push_back(atan2(y,x));
243  }
244  }
std::vector< double > fPhi
List of prong directions.
Definition: GridSearch.h:119
T sqrt(T number)
Definition: d0nt_math.hpp:156
std::vector< double > fTheta
List of prong directions.
Definition: GridSearch.h:118
T acos(T number)
Definition: d0nt_math.hpp:54
#define M_PI
Definition: SbMath.h:34
unsigned int fNseedDir
How many default seed directoins to check.
Definition: GridSearch.h:113
base_types push_back(int_type())
z
Definition: test.py:28
T sin(T number)
Definition: d0nt_math.hpp:132
T cos(T number)
Definition: d0nt_math.hpp:78
TRandom3 r(0)
T atan2(T number)
Definition: d0nt_math.hpp:72

Member Data Documentation

double earms::GridSearch::fColinear

|dot product|>fColinear means lines are colinear

Definition at line 112 of file GridSearch.h.

Referenced by AddHoughIntersections(), and ChooseBestProngDir().

unsigned int earms::GridSearch::fNseedDir

How many default seed directoins to check.

Definition at line 113 of file GridSearch.h.

Referenced by SetStandardDirections().

std::vector<double> earms::GridSearch::fPhi

List of prong directions.

Definition at line 119 of file GridSearch.h.

Referenced by AddDirection(), ChooseBestProngDir(), and SetStandardDirections().

std::vector<double> earms::GridSearch::fTheta

List of prong directions.

Definition at line 118 of file GridSearch.h.

Referenced by AddDirection(), ChooseBestProngDir(), and SetStandardDirections().

std::vector<double> earms::GridSearch::fX

List of vertex x coordinates.

Definition at line 115 of file GridSearch.h.

Referenced by AddVertex(), and FindBestVtx().

double earms::GridSearch::fXmax

Only consider vertex locations inside a box [cm].

Definition at line 107 of file GridSearch.h.

Referenced by AddVertex().

double earms::GridSearch::fXmin

Only consider vertex locations inside a box [cm].

Definition at line 106 of file GridSearch.h.

Referenced by AddVertex().

std::vector<double> earms::GridSearch::fY

List of vertex y coordinates.

Definition at line 116 of file GridSearch.h.

Referenced by AddVertex(), and FindBestVtx().

double earms::GridSearch::fYmax

Only consider vertex locations inside a box [cm].

Definition at line 109 of file GridSearch.h.

Referenced by AddVertex().

double earms::GridSearch::fYmin

Only consider vertex locations inside a box [cm].

Definition at line 108 of file GridSearch.h.

Referenced by AddVertex().

std::vector<double> earms::GridSearch::fZ

List of vertex z coorfinates.

Definition at line 117 of file GridSearch.h.

Referenced by AddVertex(), and FindBestVtx().

double earms::GridSearch::fZmax

Only consider vertex locations inside a box [cm].

Definition at line 111 of file GridSearch.h.

Referenced by AddVertex().

double earms::GridSearch::fZmin

Only consider vertex locations inside a box [cm].

Definition at line 110 of file GridSearch.h.

Referenced by AddVertex().


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