13#include "prem_default.hpp"
19TrajConstants::TrajConstants(
double cosT,
double phi,
double DetLat,
20 double DetLon,
double rDet)
93 double den,
double z,
int n)
95 SetBin(r_out, r_in, lat, lon, den, z, n);
99 double den,
double z,
int n)
188 double latitude,
double longitude,
double density,
189 double zoa,
double index)
192 density, zoa, index));
218 double EarthRadius = 6371.0;
221 if (filename ==
"") { filename = PREM3D_DEFAULT; }
222 cout <<
"Loading Earth model table from " << filename <<
"..." << endl;
226 fin.open(filename.c_str());
228 cerr <<
"ERROR: File " << filename <<
" not found!" << endl;
233 float depth, latitude, longitude, density, zoa, index;
236 double radius_prev = 0;
237 double lat_prev = -90.0;
241 double radius_min = radius_prev;
247 while (fin >> longitude >> latitude >> depth >> density >> zoa >> index) {
248 double outer_radius = EarthRadius - depth;
252 if (outer_radius > radius_prev) {
253 radius_min = radius_prev;
258 else if (outer_radius <
260 cerr <<
"ERROR: Depths are not sorted in decreasing order in the model "
262 <<
"(or depth is greater than " << EarthRadius <<
" km)." << endl;
266 else if (longitude > lon_prev) {
271 else if (longitude < lon_prev) {
273 cerr <<
"ERROR: Longitudes are not sorted in increasing order (after "
274 "depths) in the model file."
279 else if (latitude < lat_prev) {
281 cerr <<
"ERROR: Latitudes are not sorted in increasing order (after "
282 "longitudes) in the model file."
289 AddBin(outer_radius, radius_min, latitude, longitude, density, zoa, index);
295 radius_prev = outer_radius;
297 lon_prev = longitude;
320 cerr <<
"ERROR: Latitude of 1st bin center (" <<
fEarthBins[0].latitude
321 <<
") is not in the middle of the first bin, whose size should be "
323 <<
fnLatBins <<
" latitude bins." << endl;
330 <<
" longitude)." << endl;
346 cerr <<
"WARNING: Index " << index <<
" does not exist in model "
348 <<
"Doing nothing." << endl;
356 for (
int i = 0; i < nbins; i++) {
375 cerr <<
"ERROR: Index " << index <<
" does not exist in model "
376 <<
"(max index = " <<
fmaxRegIndex <<
"). Returning 0" << endl;
382 for (
int i = 0; i < nbins; i++) {
391 cerr <<
"ERROR: Index " << index <<
" not found! Returning 0" << endl;
406 cerr <<
"WARNING: Index " << index <<
" does not exist in model "
408 <<
"Doing nothing." << endl;
416 for (
int i = 0; i < nbins; i++) {
420 fEarthBins[i].density = factor * density_init;
461 if (abs(NewLat) - 0.5 * M_PI > -1.0e-14) {
467 if (abs(NewLat) - 0.5 * M_PI > -1.0e-14)
472 double sinNewLat = sin(NewLat);
473 double NsinSqNewLat = -sinNewLat * sinNewLat;
477 if (radicand < 1.0e-14) {
483 sinNewLat = sin(NewLat);
484 NsinSqNewLat = -sinNewLat * sinNewLat;
486 if (radicand < 1.0e-14)
489 double denominator =
fC.
gammaSq + NsinSqNewLat;
493 if (denominator == 0) {
528 double twoPi = 2 * M_PI;
530 double lon = prev_lon + L.
dLon;
531 if (lon < 0 || lon >= twoPi) { lon -= floor(lon / twoPi) * twoPi; }
549 if (0 > lon - L.
min && L.
max - lon < 0)
return -1;
552 if (0 > lon - L.
min || L.
max - lon < 0)
return -1;
556 double cosNewLon = cos(lon);
557 double sinNewLon = sin(lon);
559 double denominator =
fC.
alpha * expression +
564 if (denominator == 0) {
566 L.
err_message.assign(
"Longitude along neutrino trajectory = " +
567 std::to_string(lon));
587 double& DetDist,
int& index,
600 double latitude_crossing =
661 if (londiff < 0 || londiff >= 2 * M_PI)
662 londiff -= floor(londiff / (2 * M_PI));
697 if (fabs(cosT) > 1)
return 0;
700 double Az = phi / 180.0 * M_PI;
704 double distEdgeToMin =
708 double baseline = distEdgeToMin -
fC.
rDetCosT;
726 double init_lon = atan2(
733 if (init_lon < 0) { init_lon += 2 * M_PI; }
744 latinfo.
bin = init_latBin;
745 loninfo.
bin = init_lonBin;
770 loninfo.
min = init_lon;
774 loninfo.
min = loninfo.
max;
775 loninfo.
max = init_lon;
777 loninfo.
max = init_lon;
816 double prev_DetDistance = baseline;
824 if (r_in < minRadius)
break;
827 double DetDistance = -
fC.
rDetCosT + sqrt(r_in * r_in - rDetSqSinSqT);
837 prev_DetDistance = DetDistance;
838 index -= binsPerDepth;
847 index2 += binsPerDepth) {
851 double DetDistance = -
fC.
rDetCosT - sqrt(r_out * r_out - rDetSqSinSqT);
861 prev_DetDistance = DetDistance;
875 if (loninfo.
error < 0) {
877 <<
"ERROR: Oops... It turns out that I was wrong about the denominator"
878 <<
" of the x(long) equation never being 0 apart from the cases where "
879 <<
"sin(Zenith) = 0, sin(Azimuthal) = 0, or cos(Detector Longitude) = "
881 <<
" Send the following message to rpestes@apc.in2p3.fr:" << endl
883 <<
"You were wrong about the denominator of x(long)... "
884 <<
"Here are the values of the variables that broke it:" << endl
885 <<
"\tDetector Coordinates (r,lat,lon) = (" <<
fDetRadius <<
", "
887 <<
"\tcos(Zenith Angle) = " << cosT << endl
888 <<
"\tAzimuthal Angle = " << phi <<
" deg" << endl
890 <<
"Please fix this ASAP!" << endl;
double fRadiusMax
Maximum radius in Earth model (in km)
double fDetLat
The latitude (in rad) where the detector sits.
double fDetLon
The longitude (in rad) where the detector sits.
virtual void SetRemoveSmallPaths(bool rp=true)
Set tag to remove small paths.
virtual void AddPathSegment(double length, double density, double zoa, int index)
Add a path segment to the sequence.
std::vector< NuPath > fNuPath
The current neutrino path sequence.
double fDetRadius
The radius where the detector sits (in km)
virtual void SetDetectorCoordinates(double rad, double lat, double lon)
virtual double GetRegionZoA(int index)
Get Z/A of all bins with specified region index.
virtual double DetDistForNextLonBin(double prev_lon, LonBinInfo &L)
std::vector< EarthBin > fEarthBins
The bins in the earth model.
virtual void ClearModel()
Clear the earth model information.
double fInvLonBinWidth
1/binwidth for each longitude bin
virtual void AddPath(double length, EarthBin bin)
Add a path segment to the sequence.
virtual ~EarthModelBinned()
Destructor.
int fnDepthBins
Total number of depth bins.
int FillPath(double cosT, double phi=0)
virtual std::vector< EarthBin > GetEarthBins()
virtual void LoadModel(std::string filename)
Load an earth model from a file.
EarthModelBinned(std::string filename="")
Constructor.
virtual void RecordLatLonBinCrossings(double detDist_nextDbin, double &DetDist, int &index, LatBinInfo &latI, LonBinInfo &lonI)
double fHalfLonBinWidth
Half-width of each longitude bin.
void SetDetPos(double rad, double lat=0, double lon=0)
virtual void SetRegionZoA(int index, double zoa)
Set Z/A of all bins with specified region index.
int fnLatBins
Total number of latitude bins.
virtual void AddBin(double radius_out, double radius_in, double latitude, double longitude, double density, double zoa, double layer)
Add a bin to the model (angles in degrees)
double fHalfLatBinWidth
Half-width of each latitude bin.
double fInvLatBinWidth
1/binwidth for each latitude bin
virtual int LonBinIndex(double longitude)
Find lon bin index containing longitude.
TrajConstants fC
Useful constants for the trajectory.
int fmaxRegIndex
Largest region index in model.
virtual void ScaleRegionDensity(int index, double scalingfactor)
virtual double DetDistForNextLatBin(int cur_index, LatBinInfo &L)
int fnLonBins
Total number of longitude bins.
Some useful general definitions.
double radius_in
The inner radius of the bin in km.
void SetBin(double r_out=0, double r_in=0, double lat=0, double lon=0, double den=0, double z=0.5, int n=0)
Set the properties of the bin.
double latitude
The latitude of the bin center in radians.
double longitude
The longitude of the bin center in radians.
double zoa
The effective Z/A value of the matter in the bin.
double radius_out
The outer radius of the bin in km.
EarthBin(double r_out=0, double r_in=0, double lat=0, double lon=0, double den=0, double z=0.5, int n=0)
Constructor.
double density
The density of the matter in the bin in g/cm^3.
A struct holding information about upcoming latitude bin crossings along the neutrino's trajectory.
int nextBin
Index of next latitude bin.
int bin
Index of current latitude bin.
A struct holding information about upcoming longitude bin crossings along the neutrino's trajectory.
int nextBin
Index of next longitude bin.
int bin
Index of current longitude bin.
double min
"Minimum" longitude
double max
"Maximum" longitude
std::string err_message
Part of error message specific to piece of path.
double cosTcosDetLat
cosT*cos(DetLat)
double sinTsinA
sin(T)*sin(phi)
double cosDetLon
cos(DetLon)
double beta
sin(T)*sin(DetLat)-cos(phi)*cosT*cos(DetLat)
double gammaSq
[sin(T)*cos(phi)*cos(DetLat)+cosT*sin(DetLat)]^2
double sinDetLat
sin(DetLat)
double rDetSinT
rDet*sin(T)
double sinTcosA
sin(T)*cos(phi)
double alpha
sin(T)*cos(phi)*sin(DetLat)-cosT*cos(DetLat)
double rDetGammaSinDetLat
rDet*sin(DetLat)*[sin(T)*cos(phi)*cos(DetLat)+cosT*sin(DetLat)]
double sinSqT
sin^2(T) = 1 - (cosT)^2
double sinDetLon
sin(DetLon)
double sinTsinAsinDetLon
sin(T)*sin(phi)*sin(DetLon)
void UpdateDetPos(double rDet, double DetLat, double DetLon)
double gamma
sin(T)*cos(phi)*cos(DetLat)+cosT*sin(DetLat)
double maxSinSqLat
1 - [sin(phi)*cos(DetLat)]^2
void UpdateNuAngles(double cosTheta, double phi)
double rDetSinDetLat
rDet*sin(DetLat)
double rDetCosDetLat
rDet*cos(DetLat)
double cosDetLat
cos(DetLat)
double sinT
sin(T) = sqrt(sinSqT)
double sinTsinAcosDetLon
sin(T)*sin(phi)*cos(DetLon)