1 #ifndef _NSD_PHYSICS_CALCS_
2 #define _NSD_PHYSICS_CALCS_
12 constexpr
double MnMeV = 939.56542052;
24 double a_scatteringAngle);
29 double a_scatteringAngle);
35 double a_electronEnergyDep);
51 inline static double gT(
double a_L
56 inline static double Nen(
double a_L,
60 inline static double NTOF(
double a_L,
64 inline static std::vector<double>
GenEnBins(
double a_L,
117 inline static double cloverResol(
const std::vector<double>& a_coeffs,
123 inline static double polyEval(
const std::vector<double>& a_coeffs,
136 inline static std::vector<double>
getNormVector(std::vector<double> a_pntA,
137 std::vector<double> a_pntB,
138 std::vector<double> a_pntC
143 inline static std::vector<double>
getVector(
double a_x1,
149 inline static std::vector<double>
getVector(std::vector<double> a_v1,
150 std::vector<double> a_v2);
152 inline static double magnitude(std::vector<double> a_v);
157 inline static double calcAngle(std::vector<double> a_v1,
158 std::vector<double> a_v2);
161 inline static double calcAngle(
double a_x1,
188 double a_scatteringAngle)
191 A *= a_incidentEnergy;
201 double a_scatteringAngle)
215 double a_electronEnergyDep)
219 B *= ((a_incidentEnergy / (a_incidentEnergy - a_electronEnergyDep)) - 1);
222 double theta = acos(A) * (180. / M_PI);;
236 double gTime =
gT(a_L);
240 double gamma = 1.0/sqrt(1-beta);
241 return MnMeV*(gamma -1.0);
252 double numerator = a_L * (a_nEn+
MnMeV);
253 double denominator =
CcmPerNs * sqrt(a_nEn*a_nEn+2.0*
MnMeV*a_nEn);
254 return numerator/denominator;
263 std::vector<double> res;
264 for(
double t = a_maxT;t>a_minT;t-=a_dt)
266 res.push_back(
Nen(a_L,t));
268 res.push_back(
Nen(a_L,a_minT));
278 return a_Ex*(A+1)/A ;
285 return (a_coeffs[0]*a_val+a_coeffs[1])/(1+0.221*log(a_val)-1.07) \
286 + (0.221*log(a_val)-1.07)/(1+0.221*log(a_val)-1.07)*(a_coeffs[2]*a_val+2*a_coeffs[1]);
293 int a_coeffsSize = a_coeffs.size();
296 double result = a_coeffs[0];
298 for(
int a_i=1; a_i<a_coeffsSize; a_i++)
300 result = result*a_val + a_coeffs[a_i];
318 return a_A+a_B*sqrt(a_E)+a_C*a_E;
331 return std::exp(-1.0 * a_t / a_tau2) * (1. - std::exp(-1.0 * a_t / a_tau1)) /
332 a_tau2 / a_tau2 * (a_tau1 + a_tau2);
344 return std::exp(-1.0 * a_t / a_tau2) * std::erf(a_t / a_tau1);
361 return (a_lambda*std::exp(-1.0 * a_t / a_tau3)+std::exp(-1.0 * a_t / a_tau2)) *
362 (1. - std::exp(-1.0 * a_t / a_tau1)) *(a_tau2+a_tau3)*(a_tau1*a_tau2
363 + a_tau1*a_tau3 + a_tau2*a_tau3)/((a_tau2*a_tau3)*(a_tau2*a_tau3));
379 double erfDenom = a_sigma*sqrt(2);
380 double upperErfArg = (a_stop-a_mu)/erfDenom;
381 double lowerErfArg = (a_start-a_mu)/erfDenom;
382 return 0.5*(erf(upperErfArg)-erf(lowerErfArg));
391 std::vector<double> a_pntB,
392 std::vector<double> a_pntC
396 std::vector<double> vecAB;
397 vecAB.push_back(a_pntB[0]-a_pntA[0]);
398 vecAB.push_back(a_pntB[1]-a_pntA[1]);
399 vecAB.push_back(a_pntB[2]-a_pntA[2]);
400 std::vector<double> vecAC;
402 vecAC.push_back(a_pntC[0]-a_pntA[0]);
403 vecAC.push_back(a_pntC[1]-a_pntA[1]);
404 vecAC.push_back(a_pntC[2]-a_pntA[2]);
406 std::vector<double> orthVector;
407 orthVector.push_back(vecAB[1]*vecAC[2]-vecAB[2]*vecAC[1]);
408 orthVector.push_back(vecAB[2]*vecAC[0]-vecAB[0]*vecAC[2]);
409 orthVector.push_back(vecAB[0]*vecAC[1]-vecAB[1]*vecAC[0]);
410 double vecNorm = sqrt(orthVector[0]*orthVector[0]+
411 orthVector[1]*orthVector[1]+
412 orthVector[2]*orthVector[2]
414 orthVector[0]/=vecNorm;
415 orthVector[1]/=vecNorm;
416 orthVector[2]/=vecNorm;
427 double x = a_x2 - a_x1;
428 double y = a_y2 - a_y1;
429 double z = a_z2 - a_z1;
430 std::vector<double> rtnVec = {x , y, z};
435 std::vector<double> a_v2)
437 return getVector(a_v1[0], a_v1[1], a_v1[2], a_v2[0], a_v2[1], a_v2[2]);
443 return (std::sqrt(a_v[0]*a_v[0] + a_v[1]*a_v[1] + a_v[2]*a_v[2]));
447 std::vector<double> a_v2)
450 double numerator = std::inner_product(a_v1.begin(),
451 a_v1.end(), a_v2.begin(), 0.);
455 double cosTheta = numerator / denominator;
456 double theta = acos(cosTheta);
470 double dot = a_x1*a_x2+a_y1*a_y2+a_z1*a_z2;
471 double mag1 = sqrt(a_x1*a_x1+a_y1*a_y1+a_z1*a_z1);
472 double mag2 = sqrt(a_x2*a_x2+a_y2*a_y2+a_z2*a_z2);
473 return acos(dot/(mag1*mag2));
486 double area = a_norm*a_sig*sqrt(2.*M_PI)/a_binWidth;
489 double percDSig = a_dSig/a_sig;
490 double percDNorm = a_dNorm/a_norm;
491 *a_dArea = area * sqrt(percDNorm*percDNorm + percDSig*percDSig);
Definition: NSDPhysicsCalcs.h:19
static double recoilElectronEnergy(double a_incidentEnergy, double a_scatteringAngle)
Definition: NSDPhysicsCalcs.h:200
static double scatteringAngleFromED(double a_incidentEnergy, double a_electronEnergyDep)
Definition: NSDPhysicsCalcs.h:214
static double recoilGammaEnergy(double a_incidentEnergy, double a_scatteringAngle)
Definition: NSDPhysicsCalcs.h:187
McGuire, 2023.
Definition: NSDPhysicsCalcs.h:46
static double gT(double a_L)
Definition: NSDPhysicsCalcs.h:227
static double NTOF(double a_L, double a_nEn)
this function calculates the time of flight in ns for a neutron
Definition: NSDPhysicsCalcs.h:248
static std::vector< double > GenEnBins(double a_L, double a_maxT, double a_minT, double a_dt)
this function calculates the time of flight in ns for a neutron
Definition: NSDPhysicsCalcs.h:257
NTOFCalcs()
Definition: NSDPhysicsCalcs.cpp:4
static double Nen(double a_L, double a_t)
Definition: NSDPhysicsCalcs.h:231
Definition: NSDPhysicsCalcs.h:9
constexpr double CcmPerNs
Definition: NSDPhysicsCalcs.h:11
constexpr double electronRestEnergy
Definition: NSDPhysicsCalcs.h:13
constexpr double MnMeV
Definition: NSDPhysicsCalcs.h:12