All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
helper_math.h
Go to the documentation of this file.
1 #ifndef SBNCODE_SINGLEPHOTONANALYSIS_HELPER_MATH_H
2 #define SBNCODE_SINGLEPHOTONANALYSIS_HELPER_MATH_H
3 
4 #include "art/Framework/Principal/Handle.h"
5 #include "art/Framework/Services/Registry/ServiceHandle.h"
6 
9 
10 #include "canvas/Utilities/ensurePointer.h"
11 
12 #include <numeric>
13 #include <vector>
14 
15 namespace single_photon
16 {
17  //templates
18  // sort indices in descending order
19  template <typename T>
20  std::vector<size_t> sort_indexes(const std::vector<T> &v){
21 
22  std::vector<size_t> idx(v.size());
23  std::iota(idx.begin(), idx.end(), 0);
24 
25  // sort indexes based on comparing values in v
26  std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) {return v[i1] > v[i2];});
27 
28  return idx;
29  }
30 
31  // sort indices such that elements in v are in ascending order
32  template <typename T>
33  std::vector<size_t> sort_indexes_rev(const std::vector<T> &v) {
34 
35  std::vector<size_t> idx(v.size());
36  std::iota(idx.begin(), idx.end(), 0);
37 
38  // sort indexes based on comparing values in v
39  std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) {return v[i1] < v[i2];});
40 
41  return idx;
42  }
43 
44  // check if two vectors have same elements (regardless of the order), and arrange their elements in order
45  template<typename T>
46  bool marks_compare_vec_nonsense(std::vector<T>& v1, std::vector<T>& v2)
47  {
48  std::sort(v1.begin(), v1.end());
49  std::sort(v2.begin(), v2.end());
50  return v1 == v2;
51  }
52 
53 //inline functions
54  inline double calcWire(double Y, double Z, int plane, int fTPC, int fCryostat, geo::GeometryCore const& geo ){
55  double wire = geo.WireCoordinate(Y, Z, plane, fTPC, fCryostat);
56  return wire;
57  }
58 
59 
60  /* dot product of wire_dir and shower direction vectors */
61  inline double getCoswrtWires(TVector3 shower_dir, TVector3 wire_dir){
62  return wire_dir.Dot(shower_dir);
63  }
64  inline double degToRad(double deg){ return deg * M_PI/180; }
65  inline double radToDeg(double rad){ return rad * 180/M_PI; }
66 
67 
68 
69  //-----------------HELPER FUNCTIONS -----------
70  ////line between x1 and x2, point x0;
71  double dist_line_point( std::vector<double>&X1, std::vector<double>& X2, std::vector<double>& point);
72 
73  double impact_paramater_shr(double x, double y, double z, art::Ptr<recob::Shower> & shr);
74 
75  // invariant mass of a particle that decays to two showers
76  double implied_invar_mass(double vx, double vy, double vz, art::Ptr<recob::Shower> & s1, double E1, art::Ptr<recob::Shower> &s2, double E2);
77 
78  // invariant mass of two showers, calculated directly from shower directions
79  double invar_mass(art::Ptr<recob::Shower> & s1, double E1, art::Ptr<recob::Shower> &s2, double E2);
80 
81  double getMedian(std::vector<double> thisvector);
82 
83  /* returns (generally) best median dEdx of all 3
84  * planes, usually plane 2 */
85  double getAmalgamateddEdx(
86  double angle_wrt_plane0,
87  double angle_wrt_plane1,
88  double angle_wrt_plane2,
89  double median_plane0,
90  double median_plane1,
91  double median_plane2,
92  int plane0_nhits,
93  int plane1_nhits,
94  int plane2_nhits);
95 
96  /* returns the number of hits on the plane picked by function getAmalgamateddEdx */
98  double amalgamateddEdx,
99  double median_plane0,
100  double median_plane1,
101  double median_plane2,
102  int plane0_nhits,
103  int plane1_nhits,
104  int plane2_nhits);
105 
106 
107  /**
108  *@brief Calculates the four corners of a rectangle of given length and width around a cluster given the start point and axis direction
109  *@param cluster_start - the start position of a cluster in CM
110  *@param cluster_axis - calculated from the cluster end minus the cluster start
111  *@param width - typically ~1cm
112  *@param length - typically a few cm
113  *
114  * */
115  std::vector<std::vector<double>> buildRectangle(std::vector<double> cluster_start, std::vector<double> cluster_axis, double width, double length);
116 
117 }
118 #endif // SBNCODE_SINGLEPHOTONANALYSIS_HELPER_MATH_H
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
process_name opflash particleana ie ie ie z
process_name opflash particleana ie x
int getAmalgamateddEdxNHits(double amalgamateddEdx, double median_plane0, double median_plane1, double median_plane2, int plane0_nhits, int plane1_nhits, int plane2_nhits)
std::vector< size_t > sort_indexes(const std::vector< T > &v)
Definition: helper_math.h:20
double degToRad(double deg)
Definition: helper_math.h:64
double dist_line_point(std::vector< double > &X1, std::vector< double > &X2, std::vector< double > &point)
Definition: helper_math.cxx:8
double calcWire(double Y, double Z, int plane, int fTPC, int fCryostat, geo::GeometryCore const &geo)
Definition: helper_math.h:54
double invar_mass(art::Ptr< recob::Shower > &s1, double E1, art::Ptr< recob::Shower > &s2, double E2)
Definition: helper_math.cxx:74
double implied_invar_mass(double vx, double vy, double vz, art::Ptr< recob::Shower > &s1, double E1, art::Ptr< recob::Shower > &s2, double E2)
Definition: helper_math.cxx:50
double radToDeg(double rad)
Definition: helper_math.h:65
process_name opflash particleana ie ie y
std::vector< std::vector< double > > buildRectangle(std::vector< double > cluster_start, std::vector< double > cluster_axis, double width, double length)
Calculates the four corners of a rectangle of given length and width around a cluster given the start...
Description of geometry of one entire detector.
double getAmalgamateddEdx(double angle_wrt_plane0, double angle_wrt_plane1, double angle_wrt_plane2, double median_plane0, double median_plane1, double median_plane2, int plane0_nhits, int plane1_nhits, int plane2_nhits)
double getCoswrtWires(TVector3 shower_dir, TVector3 wire_dir)
Definition: helper_math.h:61
double impact_paramater_shr(double x, double y, double z, art::Ptr< recob::Shower > &shr)
Definition: helper_math.cxx:39
double getMedian(std::vector< double > thisvector)
Definition: helper_math.cxx:88
std::vector< size_t > sort_indexes_rev(const std::vector< T > &v)
Definition: helper_math.h:33
art framework interface to geometry description
bool marks_compare_vec_nonsense(std::vector< T > &v1, std::vector< T > &v2)
Definition: helper_math.h:46