forked from joaoabcoelho/OscProb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NuPath.cxx
107 lines (82 loc) · 2.78 KB
/
NuPath.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
////////////////////////////////////////////////////////////////////////
//
// Implements functions to average neutrino paths
//
////////////////////////////////////////////////////////////////////////
#include "NuPath.h"
using namespace std;
using namespace OscProb;
//......................................................................
///
/// Get the merged average of two paths
///
/// This method will merge two paths and take their average density
/// weighted by Z/A and path length.
///
/// The Z/A will be the average weighted by path length
///
/// @param p1 - The first path to merge
/// @param p2 - The second path to merge
/// @return The merged path
///
NuPath OscProb::AvgPath(NuPath& p1, NuPath& p2){
// Start with the first path
NuPath mergedPath = p1;
// Add the second length
mergedPath.length += p2.length;
// Compute weighted average of Z/A
mergedPath.zoa = (p1.zoa*p1.length + p2.zoa*p2.length) / (p1.length + p2.length);
// Compute weighted average of density
mergedPath.density = (p1.density*p1.zoa*p1.length + p2.density*p2.zoa*p2.length) / (p1.zoa*p1.length + p2.zoa*p2.length);
// return merged path
return mergedPath;
}
//......................................................................
///
/// Get the merged average of a vector of paths
///
/// This method will merge a set of paths and take their average density
/// weighted by Z/A and path length.
///
/// The Z/A will be the average weighted by path length
///
/// @param pv - vector of paths to merge
/// @return The merged path
///
OscProb::NuPath OscProb::AvgPath(std::vector<OscProb::NuPath>& pv){
// Get size of vector
int np = pv.size();
// Start with the first path
NuPath mergedPath;
// If vector is not empty, start on first path
if(np>0) mergedPath = pv[0];
else return mergedPath;
// Merge each of the following paths
for(int i=1; i<np; i++){
mergedPath = AvgPath(mergedPath, pv[i]);
}
// return merged path
return mergedPath;
}
//......................................................................
///
/// Merge two specific paths by their indices in a path vector
///
/// @param inputPath - The original vector of paths to merge
/// @param j,k - The indices of the two paths to merge
/// @return The merged vector of paths
///
std::vector<OscProb::NuPath> OscProb::MergePaths(std::vector<OscProb::NuPath>& inputPath, int j, int k){
// Output vector
vector<NuPath> mergedPath;
// Loop over input paths
for(int i=0; i<inputPath.size(); i++){
// If first index, merge the paths j and k
if(i==j) mergedPath.push_back(AvgPath(inputPath[j], inputPath[k]));
// If not second index add the path as is
else if(i!=k) mergedPath.push_back(inputPath[i]);
}// End of loop
// return merged vector
return mergedPath;
}