Public Member Functions | Private Member Functions | List of all members
beamlinereco::ToFPositionFinder Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/TestBeam/ToFPositionFinder.h"

Public Member Functions

 ToFPositionFinder ()
 
virtual ~ToFPositionFinder ()=default
 
posn_t Get3CornerPosition (double tA, double tB, double tC, double s)
 
posn_t Get4CornerPosition (double tA, double tB, double tC, double tD, double s)
 
double Get4CornerSpread (double tA, double tB, double tC, double tD, double s)
 
TH2D GetSummaryHist (TString name, TString title, double tA, double tB, double tC, double tD, double s)
 
bool IsPhysical (posn_t p, double s)
 
bool RunTests ()
 
double GetDistanceToNearestCorner (posn_t p, double s)
 

Private Member Functions

posn_t PosnAvg (std::vector< posn_t > posns)
 
double PosnDist (posn_t a, posn_t b)
 
double GetSpread (std::vector< posn_t > posns)
 
posn_t Transform90posn (posn_t p, double s)
 
posn_t RotateCoords (posn_t p, double s, int n)
 
double GetClosestDist (posn_t p, std::vector< posn_t > others)
 
std::vector< posn_tGet4Posns (double tA, double tB, double tC, double tD, double s)
 
bool Run3CornerTest (testset_t ts)
 
bool Run3CornerTests ()
 
bool Run4CornerTest (testset_t ts)
 
bool Run4CornerTests ()
 

Detailed Description

Definition at line 20 of file ToFPositionFinder.h.

Constructor & Destructor Documentation

beamlinereco::ToFPositionFinder::ToFPositionFinder ( )

Definition at line 3 of file ToFPositionFinder.cxx.

3  {
4 
5 }
virtual beamlinereco::ToFPositionFinder::~ToFPositionFinder ( )
virtualdefault

Member Function Documentation

beamlinereco::posn_t beamlinereco::ToFPositionFinder::Get3CornerPosition ( double  tA,
double  tB,
double  tC,
double  s 
)

Definition at line 15 of file ToFPositionFinder.cxx.

References PandAna.Demos.demo0::loc, m, getGoodRuns4SAM::n, msf_helper::o, std::sqrt(), submit_syst::x, and submit_syst::y.

Referenced by Get4Posns(), and Run3CornerTest().

15  {
16 
17  //calculate the deltas
18  double dtA = tA - tB;
19  double dtC = tC - tB;
20 
21  //the solution to a quadratic...
22  double m = 4 * (dtA*dtA + dtC*dtC - s*s);
23  double n = 4 * (dtA*dtA*dtA + dtC*dtC*dtC - dtA*s*s - dtC*s*s);
24  double o = dtA*dtA*dtA*dtA + dtC*dtC*dtC*dtC + 2 * (s*s*s*s - s*s*dtA*dtA - s*s*dtC*dtC);
25  //...is the distance in ns from the middle corner
26  double B = ( -n - std::sqrt(n*n - 4*m*o) ) / ( 2*m );
27 
28  //once we know the absolute distance to one corner,
29  //we effectively know the absolute distance to any corner,
30  //so calculating x and y becomes trivial.
31  double x = ( B*B + s*s - (B+dtC)*(B+dtC) ) / (2*s);
32  double y = ( B*B + s*s - (B+dtA)*(B+dtA) ) / (2*s);
33 
34  posn_t loc = {x,y};
35  return loc;
36 }
T sqrt(T number)
Definition: d0nt_math.hpp:156
const XML_Char * s
Definition: expat.h:262
beamlinereco::posn_t beamlinereco::ToFPositionFinder::Get4CornerPosition ( double  tA,
double  tB,
double  tC,
double  tD,
double  s 
)

Definition at line 59 of file ToFPositionFinder.cxx.

References Get4Posns(), and PosnAvg().

Referenced by beamlinereco::ToFPositionRecoAnalysis::analyze(), and Run4CornerTest().

59  {
60  std::vector<posn_t> posns = Get4Posns(tA, tB, tC, tD, s);
61  posn_t avg = PosnAvg(posns);
62  return avg;
63 }
const XML_Char * s
Definition: expat.h:262
posn_t PosnAvg(std::vector< posn_t > posns)
std::vector< posn_t > Get4Posns(double tA, double tB, double tC, double tD, double s)
double beamlinereco::ToFPositionFinder::Get4CornerSpread ( double  tA,
double  tB,
double  tC,
double  tD,
double  s 
)

Definition at line 65 of file ToFPositionFinder.cxx.

References Get4Posns(), and GetSpread().

Referenced by beamlinereco::ToFPositionRecoAnalysis::analyze().

65  {
66  std::vector<posn_t> posns = Get4Posns(tA,tB,tC,tD,s);
67  double spread = GetSpread(posns);
68  return spread;
69 }
const XML_Char * s
Definition: expat.h:262
double GetSpread(std::vector< posn_t > posns)
std::vector< posn_t > Get4Posns(double tA, double tB, double tC, double tD, double s)
std::vector< beamlinereco::posn_t > beamlinereco::ToFPositionFinder::Get4Posns ( double  tA,
double  tB,
double  tC,
double  tD,
double  s 
)
private

Definition at line 42 of file ToFPositionFinder.cxx.

References Get3CornerPosition(), and RotateCoords().

Referenced by Get4CornerPosition(), Get4CornerSpread(), and GetSummaryHist().

42  {
43  //reconstruct from each corner
44  posn_t locB = Get3CornerPosition(tA, tB, tC, s);
45  posn_t locC = Get3CornerPosition(tB, tC, tD, s);
46  posn_t locD = Get3CornerPosition(tC, tD, tA, s);
47  posn_t locA = Get3CornerPosition(tD, tA, tB, s);
48 
49  //transform to coordinate system with B at origin
50  locB = RotateCoords(locB, s, 0);
51  locC = RotateCoords(locC, s, 1);
52  locD = RotateCoords(locD, s, 2);
53  locA = RotateCoords(locA, s, 3);
54 
55  return {locA,locB,locC,locD};
56 }
posn_t Get3CornerPosition(double tA, double tB, double tC, double s)
posn_t RotateCoords(posn_t p, double s, int n)
const XML_Char * s
Definition: expat.h:262
double beamlinereco::ToFPositionFinder::GetClosestDist ( posn_t  p,
std::vector< posn_t others 
)
private

Definition at line 191 of file ToFPositionFinder.cxx.

References fhicl::other, and PosnDist().

Referenced by GetDistanceToNearestCorner().

191  {
192  double mindist = 0;
193  for(posn_t other : others) {
194  double thisdist = PosnDist(p, other);
195  mindist = thisdist < mindist ? thisdist : mindist;
196  }
197  return mindist;
198 }
const char * p
Definition: xmltok.h:285
double PosnDist(posn_t a, posn_t b)
double beamlinereco::ToFPositionFinder::GetDistanceToNearestCorner ( posn_t  p,
double  s 
)

Definition at line 201 of file ToFPositionFinder.cxx.

References GetClosestDist().

201  {
202  return GetClosestDist( p, { {0,0}, {0,s}, {s,0}, {s,s} } );
203 }
double GetClosestDist(posn_t p, std::vector< posn_t > others)
const char * p
Definition: xmltok.h:285
const XML_Char * s
Definition: expat.h:262
double beamlinereco::ToFPositionFinder::GetSpread ( std::vector< posn_t posns)
private

Definition at line 175 of file ToFPositionFinder.cxx.

References PosnAvg(), and PosnDist().

Referenced by Get4CornerSpread().

175  {
176  posn_t center = PosnAvg(posns);
177  double avgDist = 0;
178  for(posn_t p : posns) {
179  avgDist += PosnDist(p,center);
180  }
181  avgDist /= posns.size();
182  return avgDist;
183 }
const char * p
Definition: xmltok.h:285
posn_t PosnAvg(std::vector< posn_t > posns)
double PosnDist(posn_t a, posn_t b)
TH2D beamlinereco::ToFPositionFinder::GetSummaryHist ( TString  name,
TString  title,
double  tA,
double  tB,
double  tC,
double  tD,
double  s 
)

Definition at line 206 of file ToFPositionFinder.cxx.

References Get4Posns(), analysePickle::hist, HIST_N_BINS, PosnAvg(), beamlinereco::posn_t::x, and beamlinereco::posn_t::y.

Referenced by beamlinereco::ToFPositionRecoAnalysis::analyze().

206  {
207  std::vector<posn_t> posns = Get4Posns(tA,tB,tC,tD,s);
208  posn_t avg = PosnAvg(posns);
209  TH2D hist = TH2D(name, title, HIST_N_BINS, -s, 2*s, HIST_N_BINS, -s, 2*s);
210  for(posn_t p : posns) {
211  hist.Fill(p.x,p.y);
212  hist.Fill(avg.x,avg.y);
213  }
214  hist.SetOption("colz");
215  return hist;
216 }
const XML_Char * name
Definition: expat.h:151
const char * p
Definition: xmltok.h:285
const XML_Char * s
Definition: expat.h:262
int HIST_N_BINS
posn_t PosnAvg(std::vector< posn_t > posns)
std::vector< posn_t > Get4Posns(double tA, double tB, double tC, double tD, double s)
bool beamlinereco::ToFPositionFinder::IsPhysical ( posn_t  p,
double  s 
)

Definition at line 186 of file ToFPositionFinder.cxx.

References beamlinereco::posn_t::x, and beamlinereco::posn_t::y.

Referenced by beamlinereco::ToFPositionRecoAnalysis::analyze().

186  {
187  return 0 < p.x && p.x < s && 0 < p.y && p.y < s;
188 }
const char * p
Definition: xmltok.h:285
const XML_Char * s
Definition: expat.h:262
beamlinereco::posn_t beamlinereco::ToFPositionFinder::PosnAvg ( std::vector< posn_t posns)
private

Definition at line 144 of file ToFPositionFinder.cxx.

References beamlinereco::posn_t::x.

Referenced by Get4CornerPosition(), GetSpread(), and GetSummaryHist().

144  {
145  double sumX = 0; double sumY = 0;
146  for(auto p : posns) { sumX += p.x; sumY += p.y; }
147  double avgX = sumX/posns.size();
148  double avgY = sumY/posns.size();
149  return { avgX, avgY};
150 }
const char * p
Definition: xmltok.h:285
double beamlinereco::ToFPositionFinder::PosnDist ( posn_t  a,
posn_t  b 
)
private

Definition at line 170 of file ToFPositionFinder.cxx.

References cet::pow(), std::sqrt(), beamlinereco::posn_t::x, and beamlinereco::posn_t::y.

Referenced by GetClosestDist(), and GetSpread().

170  {
171  return std::sqrt( std::pow(a.x-b.x, 2) + std::pow(a.y-b.y, 2) );
172 }
T sqrt(T number)
Definition: d0nt_math.hpp:156
constexpr T pow(T x)
Definition: pow.h:75
float y
Definition: structs.h:15
const double a
const hit & b
Definition: hits.cxx:21
float x
Definition: structs.h:14
beamlinereco::posn_t beamlinereco::ToFPositionFinder::RotateCoords ( posn_t  p,
double  s,
int  n 
)
private

Definition at line 162 of file ToFPositionFinder.cxx.

References MECModelEnuComparisons::i, getGoodRuns4SAM::n, and Transform90posn().

Referenced by Get4Posns().

162  {
163  for(int i = 0; i < n; i++) {
164  p = Transform90posn(p,s);
165  }
166  return p;
167 }
const char * p
Definition: xmltok.h:285
const XML_Char * s
Definition: expat.h:262
posn_t Transform90posn(posn_t p, double s)
bool beamlinereco::ToFPositionFinder::Run3CornerTest ( testset_t  ts)
private

Definition at line 102 of file ToFPositionFinder.cxx.

References std::abs(), om::cout, beamlinereco::EPSILON, beamlinereco::testset_t::expected, Get3CornerPosition(), beamlinereco::testset_t::s, beamlinereco::testset_t::tA, beamlinereco::testset_t::tB, beamlinereco::testset_t::tC, beamlinereco::posn_t::x, and beamlinereco::posn_t::y.

Referenced by Run3CornerTests().

102  {
103  std::cout << "Parameters A:" << ts.tA << " B:" << ts.tB << " C:" << ts.tC << " s:" << ts.s << "\n";
104  posn_t calculated = Get3CornerPosition(ts.tA, ts.tB, ts.tC, ts.s);
105  std::cout << "Calculated result: (" << calculated.x << "," << calculated.y;
106  std::cout << ") Expected result: (" << ts.expected.x << "," << ts.expected.y << ")\n\n";
107  return std::abs(ts.expected.x - calculated.x) < EPSILON
108  && std::abs(ts.expected.y - calculated.y) < EPSILON;
109 }
const double EPSILON
posn_t Get3CornerPosition(double tA, double tB, double tC, double s)
float abs(float number)
Definition: d0nt_math.hpp:39
OStream cout
Definition: OStream.cxx:6
bool beamlinereco::ToFPositionFinder::Run3CornerTests ( )
private

Definition at line 81 of file ToFPositionFinder.cxx.

References om::cout, Run3CornerTest(), and std::sqrt().

Referenced by RunTests().

81  {
82  std::cout << "***********RUNNING 3_CORNER TESTS**********\n";
83  bool allPassed = true;
84  std::vector<testset_t> testSets;
85  testSets = { { 100, 100, 100, 0, 1, {.5,.5} },
86  { 101, 100+std::sqrt(2), 101, 0, 1, {1,1} },
87  { 1+std::sqrt(10), 1+std::sqrt(18), 1+std::sqrt(10), 0, 4, {3,3} },
88  { 5+std::sqrt(26), 5+std::sqrt(26), 5+std::sqrt(106), 0, 10, {1,5} },
89  { 7+std::sqrt(20), 7+std::sqrt(53), 7+std::sqrt(130), 0, 11, {2,7} } };
90 
91  for(auto ts : testSets) {
92  bool thisPassed = Run3CornerTest(ts);
93  allPassed = allPassed && thisPassed;
94  }
95  std::cout << (allPassed ? "All 3-corner tests passed.\n" : "1+ 3-corner tests failed.\n");
96  std::cout << "***********DONE RUNNING 3_CORNER TESTS**********\n";
97 
98  return allPassed;
99 }
T sqrt(T number)
Definition: d0nt_math.hpp:156
OStream cout
Definition: OStream.cxx:6
bool beamlinereco::ToFPositionFinder::Run4CornerTest ( testset_t  ts)
private

Definition at line 131 of file ToFPositionFinder.cxx.

References std::abs(), om::cout, beamlinereco::EPSILON, beamlinereco::testset_t::expected, Get4CornerPosition(), beamlinereco::testset_t::s, beamlinereco::testset_t::tA, beamlinereco::testset_t::tB, beamlinereco::testset_t::tC, beamlinereco::testset_t::tD, beamlinereco::posn_t::x, and beamlinereco::posn_t::y.

Referenced by Run4CornerTests().

131  {
132  std::cout << "Parameters A:" << ts.tA << " B:" << ts.tB << " C:" << ts.tC << " D:" << ts.tD << " s:" << ts.s << "\n";
133  posn_t calculated = Get4CornerPosition(ts.tA, ts.tB, ts.tC, ts.tD, ts.s);
134  std::cout << "Calculated result: (" << calculated.x << "," << calculated.y;
135  std::cout << ") Expected result: (" << ts.expected.x << "," << ts.expected.y << ")\n\n";
136  return std::abs(ts.expected.x - calculated.x) < EPSILON
137  && std::abs(ts.expected.y - calculated.y) < EPSILON;
138 }
const double EPSILON
float abs(float number)
Definition: d0nt_math.hpp:39
OStream cout
Definition: OStream.cxx:6
posn_t Get4CornerPosition(double tA, double tB, double tC, double tD, double s)
bool beamlinereco::ToFPositionFinder::Run4CornerTests ( )
private

Definition at line 112 of file ToFPositionFinder.cxx.

References om::cout, Run4CornerTest(), and std::sqrt().

Referenced by RunTests().

112  {
113  std::cout << "***********RUNNING 4_CORNER TESTS**********\n";
114  bool allPassed = true;
115  std::vector<testset_t> testSets;
116  testSets = { { 100, 100, 100, 100, 1, {.5,.5} },
117  { 101, 100+std::sqrt(2), 101, 100, 1, {1,1} },
118  { 1+std::sqrt(10), 1+std::sqrt(18), 1+std::sqrt(10), 1+std::sqrt(2), 4, {3,3} },
119  { 5+std::sqrt(26), 5+std::sqrt(26), 5+std::sqrt(106), 5+std::sqrt(106), 10, {1,5} },
120  { 7+std::sqrt(20), 7+std::sqrt(53), 7+std::sqrt(130), 7+std::sqrt(97), 11, {2,7} } };
121 
122  for(auto ts : testSets) {
123  allPassed = Run4CornerTest(ts) && allPassed;
124  }
125  std::cout << (allPassed ? "All 4-corner tests passed.\n" : "1+ 4-corner tests failed.\n");
126  std::cout << "***********RUNNING 4_CORNER TESTS**********\n";
127  return allPassed;
128 }
T sqrt(T number)
Definition: d0nt_math.hpp:156
OStream cout
Definition: OStream.cxx:6
bool beamlinereco::ToFPositionFinder::RunTests ( )

Definition at line 72 of file ToFPositionFinder.cxx.

References om::cout, Run3CornerTests(), and Run4CornerTests().

72  {
73  std::cout << "*********************RUNNING TESTS*********************\n";
74  bool pass3 = Run3CornerTests();
75  bool pass4 = Run4CornerTests();
76  std::cout << "*******************DONE RUNNING TESTS******************\n";
77  return pass3 && pass4;
78 }
OStream cout
Definition: OStream.cxx:6
beamlinereco::posn_t beamlinereco::ToFPositionFinder::Transform90posn ( posn_t  p,
double  s 
)
private

Definition at line 157 of file ToFPositionFinder.cxx.

References beamlinereco::posn_t::x, and beamlinereco::posn_t::y.

Referenced by RotateCoords().

157  {
158  return { s - p.y, p.x };
159 }
const char * p
Definition: xmltok.h:285
const XML_Char * s
Definition: expat.h:262

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