All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Interaction.cxx
Go to the documentation of this file.
1 #include <cmath>
2 #include <TVector3.h>
3 #include "Interaction.hh"
4 
5 namespace util {
6 
7 double ECCQE(const TVector3& l_momentum, double l_energy) {
8  // Based on D. Kaleko, LowEnergyExcess LArLite module ECCQECalculator
9  double M_n = 0.939565; // GeV/c^2
10  double M_p = 0.938272; // GeV/c^2
11  double M_e = 0.000511; // GeV/c^2
12  double bindingE = 0.0300; // GeV
13 
14  double mp2 = M_p * M_p;
15  double me2 = M_e * M_e;
16  double mnb = M_n - bindingE;
17 
18  TVector3 v(l_momentum);
19  double l_mom = sqrt(l_energy * l_energy - me2);
20  double l_theta = \
21  acos(v.Pz() / sqrt(v.Px()*v.Px() + v.Py()*v.Py() + v.Pz()*v.Pz()));
22  double enu_top = mp2 - mnb*mnb - me2 + 2.0 * mnb * l_energy;
23  double enu_bot = 2.0 * (mnb - l_energy + l_mom * cos(l_theta));
24 
25  return enu_top / enu_bot;
26 }
27 
28 double ContainedLength(const TVector3 &v0, const TVector3 &v1,
29  const std::vector<geo::BoxBoundedGeo> &boxes) {
30  // if points are the same, return 0
31  if ((v0 - v1).Mag() < 1e-6) return 0;
32 
33  double length = 0;
34 
35  // total contained length is sum of lengths in all boxes
36  // assuming they are non-overlapping
37  for (auto const &box: boxes) {
38  int n_contained = box.ContainsPosition(v0) + box.ContainsPosition(v1);
39  // both points contained -- length is total length (also can break out of loop)
40  if (n_contained == 2) {
41  length = (v1 - v0).Mag();
42  break;
43  }
44  // one contained -- have to find intersection point (which must exist)
45  else if (n_contained == 1) {
46  std::vector<TVector3> intersections = box.GetIntersections(v0, v1);
47  assert(intersections.size() == 1); // should only have one intersection point
48  // get the length
49  length += ( box.ContainsPosition(v0) ? (v0 - intersections[0]).Mag() : (v1 - intersections[0]).Mag() );
50  }
51  else if (n_contained == 0) {
52  std::vector<TVector3> intersections = box.GetIntersections(v0, v1);
53  // should have 0 or 2
54  if (intersections.size() == 2) {
55  length += (intersections[0] - intersections[1]).Mag();
56  }
57  else assert(intersections.size() == 0);
58  }
59  else assert(false); // bad
60  }
61 
62  return length;
63 }
64 
65 double MCParticleLength(const simb::MCParticle &particle) {
66  double length = 0;
67  TVector3 last = particle.Position().Vect();
68  for (int i = 1; i < particle.NumberTrajectoryPoints(); i++) {
69  TVector3 current = particle.Position(i).Vect();
70  length += (current - last).Mag();
71  last = current;
72  }
73 
74  return length;
75 }
76 
77 double MCParticleContainedLength(const simb::MCParticle &particle, const std::vector<geo::BoxBoundedGeo> &active_volumes) {
78  double contained_length = 0;
79  bool outside_AV = true;
80  TVector3 start = particle.Position().Vect();
81 
82  // keep track of the containment position
83  int volume_index = -1;
84  // now check the active volumes
85  for (int i = 0; i < active_volumes.size(); i++) {
86  if (outside_AV && active_volumes[i].ContainsPosition(start)) {
87  outside_AV = false;
88  volume_index = i;
89  break;
90  }
91  }
92 
93  // if outside AV, set length to 0
94  if (outside_AV) return 0.;
95 
96  // keep track of the containment volume
97  std::vector<geo::BoxBoundedGeo> volume { active_volumes.at(volume_index) };
98 
99  TVector3 last = start;
100  for (int i = 1; i < particle.NumberTrajectoryPoints(); i++) {
101  TVector3 current = particle.Position(i).Vect();
102  if (!volume[0].ContainsPosition(current)) {
103  break;
104  }
105  contained_length += ContainedLength(last, current, volume);
106  last = current;
107  }
108 
109  return contained_length;
110 }
111 
112 
113 } // namespace util
114 
double ContainedLength(const TVector3 &v0, const TVector3 &v1, const std::vector< geo::BoxBoundedGeo > &boxes)
Definition: Interaction.cxx:28
double MCParticleLength(const simb::MCParticle &particle)
Definition: Interaction.cxx:65
double ECCQE(const TVector3 &l_momentum, double l_energy)
Definition: Interaction.cxx:7
double MCParticleContainedLength(const simb::MCParticle &particle, const std::vector< geo::BoxBoundedGeo > &active_volumes)
Definition: Interaction.cxx:77
do i e