forked from ara-software/AraSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EarthModel.cc
2184 lines (1668 loc) · 78.3 KB
/
EarthModel.cc
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Constants.h"
//#include "Signal.h"
#include "signal.hh"
//#include "earthmodel.hh"
#include "EarthModel.h"
//#include "icemodel.hh"
#include "IceModel.h"
#include <cmath>
#include "Tools.h"
//#include "vector.hh"
#include "Vector.h"
//#include "position.hh"
#include "Position.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "signal.hh"
#include "Primaries.h"
#include "Settings.h"
#include "secondaries.hh"
ClassImp(EarthModel);
using std::cout;
using std::endl;
using std::ios;
using std::fstream;
const double EarthModel::COASTLINE(30.);
const double EarthModel::MAXTHETA(180.);
const int EarthModel::ILAT_MAX((int)((COASTLINE/MAXTHETA)*(double)NLAT+0.00001)); // corresponding latitude bin to "coastline"
const double EarthModel::GEOID_MAX(6.378137E6); // parameters of geoid model
const double EarthModel::GEOID_MIN(6.356752E6); // from Geodetic Reference System 1980, Bulletin Geodesique, Vol 54:395,1980. // The previous reference gave issue number 3 instead of page number 395
// test ClassDef works with static const double
const double EarthModel::R_EARTH(6.378140E6);
double EarthModel::GetCOASTLINE() {
return COASTLINE;
}
EarthModel::EarthModel(int model,int WEIGHTABSORPTION_SETTING) {
radii[0]=1.2e13;
radii[1]=(EarthModel::R_EARTH-4.0E4)*(EarthModel::R_EARTH-4.0E4);
radii[2]=(EarthModel::R_EARTH*EarthModel::R_EARTH); // average radii of boundaries between earth layers
// cout << "In EarthModel, model is " << model << "\n";
weightabsorption= WEIGHTABSORPTION_SETTING;
CONSTANTICETHICKNESS = (int) (model / 1000);
model -= CONSTANTICETHICKNESS * 1000;
CONSTANTCRUST = (int) (model / 100);
model -= CONSTANTCRUST * 100;
FIXEDELEVATION = (int) (model / 10);
model -= FIXEDELEVATION * 10;
EARTH_MODEL = model;
//cout<<"CONSTICETHK = "<<CONSTANTICETHICKNESS<<", CNSTCRST = "<<CONSTANTCRUST<<", FIXDELV = "<<FIXEDELEVATION<<", EARTH_MODEL = "<<EARTH_MODEL<<endl;
for (int i=0;i<NLON;i++) {
Tools::Zero(elevationarray[i],NLAT);
Tools::Zero(waterthkarray[i],NLAT);
Tools::Zero(icethkarray[i],NLAT);
Tools::Zero(softsedthkarray[i],NLAT);
Tools::Zero(hardsedthkarray[i],NLAT);
Tools::Zero(uppercrustthkarray[i],NLAT);
Tools::Zero(middlecrustthkarray[i],NLAT);
Tools::Zero(lowercrustthkarray[i],NLAT);
Tools::Zero(crustthkarray[i],NLAT);
Tools::Zero(surfacer[i],NLAT);
Tools::Zero(icer[i],NLAT);
Tools::Zero(waterr[i],NLAT);
Tools::Zero(softsedr[i],NLAT);
Tools::Zero(hardsedr[i],NLAT);
Tools::Zero(uppercrustr[i],NLAT);
Tools::Zero(middlecrustr[i],NLAT);
Tools::Zero(lowercrustr[i],NLAT);
Tools::Zero(waterdensityarray[i],NLAT);
Tools::Zero(icedensityarray[i],NLAT);
Tools::Zero(softseddensityarray[i],NLAT);
Tools::Zero(hardseddensityarray[i],NLAT);
Tools::Zero(uppercrustdensityarray[i],NLAT);
Tools::Zero(middlecrustdensityarray[i],NLAT);
Tools::Zero(lowercrustdensityarray[i],NLAT);
} //Zero Earth model arrays
// see monte carlo note #17
for (int i=0;i<NLAT;i++) {
geoid[i]=GEOID_MIN*GEOID_MAX/sqrt(pow(GEOID_MIN,2.)-(pow(GEOID_MIN,2.)-pow(GEOID_MAX,2.))*pow(cos(dGetTheta(i)),2.));
} //for
// Crust 2.0 is binned in 2deg x 2deg bins, area of bin depends on latitude.
// calculating surface area of bins
phistep=2*PI/(double)NLON;
thetastep=(MAXTHETA*RADDEG)/NLAT;
for (int i=0;i<NLAT;i++) {
area[i]=phistep*(cos(dGetTheta(i))-cos(dGetTheta(i+1)))*pow(geoid[i],2.);
} //for
if (EARTH_MODEL == 0)
ReadCrust(crust20_in);
else {
cout<<"Error! Unknown Earth model requested! Defaulting to Crust 2.0 model.\n";
ReadCrust(crust20_in);
} //else
} //EarthModel constructor (int mode)
EarthModel::~EarthModel() {} //EarthModel destructor - no dynamic variables, nothing to delete
double EarthModel::LongtoPhi_0isPrimeMeridian(double longitude) {
double phi;
// convert longitude (-180 to 180) to phi (0 to 2pi) wrt +x
// in radians
phi=(90-longitude);
if (phi<0.)
phi+=360.;
phi=phi*RADDEG;
return phi;
}
double EarthModel::LongtoPhi_0is180thMeridian(double longitude) {
double phi;
// convert longitude (0 to 360) to phi (0 to 2pi) wrt +x
phi=(270.-longitude);
if (phi<0.)
phi+=360.;
phi=phi*RADDEG;
// in radians
return phi;
}
double EarthModel::GetGeoid(double latitude) {
return (GEOID_MIN*GEOID_MAX/
sqrt(GEOID_MIN*GEOID_MIN-(GEOID_MIN*GEOID_MIN-GEOID_MAX*GEOID_MAX)*
cos(latitude*RADDEG)*cos(latitude*RADDEG)));
}
double EarthModel::Geoid(double latitude) const {
// latitude here is 0 at the south pole and 180 at the north pole
return (GEOID_MIN*GEOID_MAX/
sqrt(GEOID_MIN*GEOID_MIN-(GEOID_MIN*GEOID_MIN-GEOID_MAX*GEOID_MAX)*
cos(latitude*RADDEG)*cos(latitude*RADDEG)));
} //Geoid(lat)
double EarthModel::Geoid(const Position &pos) const {
return Geoid(pos.Lat());
} //Geoid(Position)
double EarthModel::IceThickness(double lon,double lat) const {
return icethkarray[(int)(lon/2)][(int)(lat/2)]*1000.;
} //IceThickness(lon,lat)
double EarthModel::IceThickness(const Position& pos) const {
return IceThickness(pos.Lon(),pos.Lat());
} //IceThickness(Position)
int EarthModel::InFirn(const Position& pos) const {
if (pos.Mag()-Surface(pos)<FIRNDEPTH)
return 0;
return 1;
} //InFirn(Position)
double EarthModel::SurfaceDeepIce(const Position& pos) const { // surface of the deep ice (where you reach the firn)
return surfacer[(int)(pos.Lon()/2)][(int)(pos.Lat()/2)] + geoid[(int)(pos.Lat()/2)] + FIRNDEPTH;
} //Surface(lon,lat)
double EarthModel::Surface(double lon,double lat) const {
return surfacer[(int)(lon/2)][(int)(lat/2)] + geoid[(int)(lat/2)];
} //Surface(lon,lat)
double EarthModel::Surface(const Position& pos) const {
return surfacer[(int)(pos.Lon()/2)][(int)(pos.Lat()/2)] + geoid[(int)(pos.Lat()/2)];
} //Surface(Position)
double EarthModel::RockSurface(double lon,double lat) const {
return (Surface(lon,lat) - IceThickness(lon,lat) - WaterDepth(lon,lat));
} //RockSurface(lon,lat)
double EarthModel::RockSurface(const Position& pos) const {
return RockSurface(pos.Lon(),pos.Lat());
} //RockSurface(lon,lat)
double EarthModel::SurfaceAboveGeoid(double lon,double lat) const {
return surfacer[(int)(lon/2)][(int)(lat/2)];
} //SurfaceAboveGeoid(lon,lat)
double EarthModel::SurfaceAboveGeoid(const Position& pos) const {
return surfacer[(int)(pos.Lon()/2)][(int)(pos.Lat()/2)];
} //SurfaceAboveGeoid(Position)
double EarthModel::WaterDepth(double lon,double lat) const {
return waterthkarray[(int)(lon/2)][(int)(lat/2)]*1000;
} //WaterDepth(lon,lat)
double EarthModel::WaterDepth(const Position& pos) const {
return WaterDepth(pos.Lon(),pos.Lat());
} //WaterDepth(Position)
double EarthModel::GetLat(double theta) const {
return theta*DEGRAD;
} //GetLat
double EarthModel::GetLon(double phi) const {
// input is phi in radians wrt +x
double phi_deg = phi*DEGRAD;
if (phi_deg > 270)
phi_deg = phi_deg - 360.; // this puts it from -90 to 270
return (360.*3./4. - phi_deg); // returns 0 to 360 degrees (going from -180 to 180 deg longitude like Crust 2.0 does)
} //GetLon
double EarthModel::GetDensity(double altitude, const Position earth_in, const Position posnu,
int& crust_entered, // 1 or 0
int& mantle_entered, // 1 or 0
int& core_entered){
Position where = earth_in;
//cout<<"where is "<<where<<"\n";
double x = 0; //where.Mag();
double lon = where.Lon();
double lat = where.Lat();
//cout <<"Lon and Lat are "<<lon<<","<<lat<<"\n";
int ilon = (int)(lon/2);
int ilat = (int)(lat/2);
double ddensity =0; //initilize ddensity
double surface_elevation = this->SurfaceAboveGeoid(lon,lat); // altitude of surface relative to geoid at earth entrance point
double local_icethickness = this->IceThickness(lon,lat);
double local_waterdepth = WaterDepth(lon,lat);
//altitude=altitude-Geoid(lat); // what is the altitude of the entrance point
if(altitude>surface_elevation+0.1){ // if it is above the surface, it's messed up
//cout << "neutrino entrance point is above the surface. Density0 \n";
// cout <<"altitude is "<<altitude<<"\n";
}
if(altitude>surface_elevation+0.1){
ddensity=1.25;
//cout <<"density is air! \n";
}
if (altitude<=surface_elevation+0.1 && altitude>(surface_elevation-local_icethickness)) // the 0.1 is just to take care of precision issues. It could have been 0.01 or 0.001.
ddensity=icedensityarray[ilon][ilat]*1000;
else if (altitude<=(surface_elevation-local_icethickness) && altitude>(surface_elevation-local_icethickness-local_waterdepth))
ddensity=waterdensityarray[ilon][ilat]*1000;
else if (altitude<=(surface_elevation-local_icethickness-local_waterdepth) && altitude>softsedr[ilon][ilat]) {
ddensity=softseddensityarray[ilon][ilat]*1000;
crust_entered=1; //Switch that lets us know we've penetrated into the crust
} //end if
else if (altitude<=softsedr[ilon][ilat] && altitude>hardsedr[ilon][ilat])
ddensity=hardseddensityarray[ilon][ilat]*1000;
else if (altitude<=hardsedr[ilon][ilat] && altitude>uppercrustr[ilon][ilat])
ddensity=uppercrustdensityarray[ilon][ilat]*1000;
else if (altitude<=uppercrustr[ilon][ilat] && altitude>middlecrustr[ilon][ilat])
ddensity=middlecrustdensityarray[ilon][ilat]*1000;
else if (altitude<=middlecrustr[ilon][ilat] && altitude>lowercrustr[ilon][ilat])
ddensity=lowercrustdensityarray[ilon][ilat]*1000;
else if (altitude<=lowercrustr[ilon][ilat])
ddensity=densities[1];
return ddensity;
}//Get Density
double EarthModel::GetDensity1(double altitude, const Position earth_in, const Position posnu,
int& crust_entered, // 1 or 0
int& mantle_entered, // 1 or 0
int& core_entered, double& abovesurface){
Position where = earth_in;
//cout<<"where is "<<where<<"\n";
double x = 0; //where.Mag();
double lon = where.Lon();
double lat = where.Lat();
//cout <<"Lon and Lat are "<<lon<<","<<lat<<"\n";
int ilon = (int)(lon/2);
int ilat = (int)(lat/2);
double ddensity =0; //initilize ddensity
double surface_elevation = this->SurfaceAboveGeoid(lon,lat); // altitude of surface relative to geoid at earth entrance point
double local_icethickness = this->IceThickness(lon,lat);
double local_waterdepth = WaterDepth(lon,lat);
//altitude=altitude-Geoid(lat); // what is the altitude of the entrance point
if(altitude>surface_elevation+0.1){ // if it is above the surface, it's messed up
//cout << "neutrino entrance point is above the surface density1.\n";
//cout <<"altitude is "<<altitude<<"\n";
abovesurface=1;
}
if(altitude>surface_elevation+0.1){
ddensity=1.25;
// cout<<"density is air. \n";
}
if (altitude<=surface_elevation+0.1 && altitude>(surface_elevation-local_icethickness)) // the 0.1 is just to take care of precision issues. It could have been 0.01 or 0.001.
ddensity=icedensityarray[ilon][ilat]*1000;
else if (altitude<=(surface_elevation-local_icethickness) && altitude>(surface_elevation-local_icethickness-local_waterdepth))
ddensity=waterdensityarray[ilon][ilat]*1000;
else if (altitude<=(surface_elevation-local_icethickness-local_waterdepth) && altitude>softsedr[ilon][ilat]) {
ddensity=softseddensityarray[ilon][ilat]*1000;
crust_entered=1; //Switch that lets us know we've penetrated into the crust
} //end if
else if (altitude<=softsedr[ilon][ilat] && altitude>hardsedr[ilon][ilat])
ddensity=hardseddensityarray[ilon][ilat]*1000;
else if (altitude<=hardsedr[ilon][ilat] && altitude>uppercrustr[ilon][ilat])
ddensity=uppercrustdensityarray[ilon][ilat]*1000;
else if (altitude<=uppercrustr[ilon][ilat] && altitude>middlecrustr[ilon][ilat])
ddensity=middlecrustdensityarray[ilon][ilat]*1000;
else if (altitude<=middlecrustr[ilon][ilat] && altitude>lowercrustr[ilon][ilat])
ddensity=lowercrustdensityarray[ilon][ilat]*1000;
else if (altitude<=lowercrustr[ilon][ilat])
ddensity=densities[1];
return ddensity;
}//Get Density
int EarthModel::Getchord(double len_int_kgm2,
const Position &earth_in, // place where neutrino entered the earth
const Position &posnu, // position of the interaction
int inu,
double& chord, // chord length
double& weight1, // weight
double& nearthlayers, // core, mantle, crust
double myair,
double& total_kgm2, // length in kg m^2
int& crust_entered, // 1 or 0
int& mantle_entered, // 1 or 0
int& core_entered) {
Vector chord3;
Vector nchord;
double x=0;
double lat,lon;
int ilon,ilat;
total_kgm2 = 0; //Initialize column density
nearthlayers=0; // this counts the number of earth layers the neutrino traverses.
crust_entered=0;
mantle_entered=0;
core_entered=0;
// Want to find probability that the neutrino survives its trip
// through the earth.
//Find the chord, its length and its unit vector.
chord3 = posnu - earth_in;
chord=chord3.Mag();
nchord = chord3 / chord;
if (chord<=1) {
cout << "short chord " << chord << "\n";
return 0;
}
if (chord>2.*R_EARTH+1000) {
cout << "bad chord" << " " << chord << ". Event is " << inu << "\n";
}
Position where=earth_in;
// the sin of the angle between the neutrino path and the
// radial vector to its earth entrance point determines
// if it will get to the next layer down.
double costh=(where*nchord)/where.Mag();
double sinth=sqrt(1-costh*costh);
double distance=0;
double halfchord=0;
if (getchord_method<1 || getchord_method>3)
cout << "Bogus method!\n";
// we are really focusing on method 2 - method 1 has not been maintenanced in a long time!!
// use at your own risk.
if (getchord_method==1) {
double L=0;
weight1=0;
if (sinth>sqrt(radii[1]/radii[2])) {
nearthlayers++;
// these only skim the first layer.
L=len_int_kgm2/densities[2];
weight1=exp(-posnu.Distance(where)/L);
}
else {
nearthlayers++;
// these get to the second layer down.
L=len_int_kgm2/densities[2];
// compute distance before it gets to the next layer.
halfchord=sqrt(radii[1]-radii[2]*sinth*sinth);
distance=sqrt(radii[2])*costh-halfchord;
weight1=exp(-distance/L);
// get position where it enters the second layer.
where = earth_in + distance*nchord;
// determine if it enters the core or not.
costh=(where*nchord)/where.Mag();
sinth=sqrt(1-costh*costh);
if (sinth>sqrt(radii[0]/radii[1])) {
halfchord=sqrt(radii[1])*costh;
nearthlayers++;
// these do not enter the core.
L=len_int_kgm2/densities[1];
weight1 *= exp(-2*halfchord/L);
L=len_int_kgm2/densities[2];
// this is where it exits the second layer and enters the crust again.
where = where + 2*halfchord*nchord;
weight1*=exp(-where.Distance(posnu)/L);
}
else {
nearthlayers++;
// these enter the core.
L=len_int_kgm2/densities[1];
// compute distance before entering the core.
halfchord=sqrt(radii[0]-radii[1]*sinth*sinth);
distance=sqrt(radii[1])*costh-halfchord;
weight1*=exp(-distance/L);
// go through the core.
L=len_int_kgm2/densities[0];
weight1*=exp(-2*halfchord/L);
// go through 2nd layer again.
L=len_int_kgm2/densities[1];
weight1*=exp(-distance/L);
// through the crust and end up at posnu.
L=len_int_kgm2/densities[2];
where = where + (2*distance+2*halfchord)*nchord;
weight1*=exp(-where.Distance(posnu)/L);
} //else
} //else
} //if getchord_method==1
if (getchord_method==2) {
x=0; // x is the distance you move as you step through the earth.
lon = where.Lon();
lat = where.Lat();
ilon = (int)(lon/2);
ilat = (int)(lat/2);
double surface_elevation = this->SurfaceAboveGeoid(lon,lat); // altitude of surface relative to geoid at earth entrance point
double local_icethickness = this->IceThickness(lon,lat);
double local_waterdepth = WaterDepth(lon,lat);
double altitude=0;
weight1=1;
double step=Tools::dMin(len_int_kgm2/densities[1]/10,500.); //how big is the step size
//double step=Tools::dMin(len_int_kgm2/densities[1]/10,5.); //how big is the step size
//--------------------------------------------------
// cout<<"len_int_kgm2 = "<<len_int_kgm2<<endl;
// cout<<"densities[1] = "<<densities[1]<<endl;
// cout<<"Getchord.step = "<<step<<endl;
//--------------------------------------------------
// either 1/10 of an interaction length in the mantle or 500 m, whichever is smaller.
// 500 m is approximately the feature size in Crust 2.0.
//------------------added on Dec 8------------------------
weight1*=exp(-myair/len_int_kgm2);//add atmosphere attenuation // fenfang's atten. due to atmosphere
//------------------added on Dec 8------------------------
total_kgm2+=myair;
double L=0;
double ddensity=Signal::RHOAIR;
nearthlayers=1;
if (where*nchord>0.) { // look at direction of neutrino where it enters the earth.
cout << "This one's trouble. Neutrino exit point looks more like an entrance point. Event is " << inu << "\n";
cout << "where is " << where[0] << " " << where[1] << " " << where[2] << "\n";
cout << "nchord is " << nchord[0] << " " << nchord[1] << " " << nchord[2] << "\n";
cout << "dot product is " << where*nchord/sqrt(where*where) << "\n";
cout << "posnu is " << posnu[0] << " " << posnu[1] << " " << posnu[2] << "\n";
cout << "Length of chord is : "<<chord<<endl;
} //end if
altitude=where.Mag()-Geoid(lat); // what is the altitude of the entrance point
if(altitude>surface_elevation+0.1) // if it is above the surface, it's messed up
cout << "neutrino entrance point is above the surface. Event is " << inu << "\n";
while(altitude>MIN_ALTITUDE_CRUST && x<posnu.Distance(earth_in)) { // starting at earth entrance point, step toward interaction position until you've reached the interaction or you are below the crust.
// while(altitude>MIN_ALTITUDE_CRUST && x<dDistance(enterice,earth_in)) {
// find the density of the earth at this altitude
ddensity=Signal::RHOAIR;
if (altitude<=surface_elevation+0.1 && altitude>(surface_elevation-local_icethickness)) // the 0.1 is just to take care of precision issues. It could have been 0.01 or 0.001.
ddensity=icedensityarray[ilon][ilat]*1000;
else if (altitude<=(surface_elevation-local_icethickness) && altitude>(surface_elevation-local_icethickness-local_waterdepth))
ddensity=waterdensityarray[ilon][ilat]*1000;
else if (altitude<=(surface_elevation-local_icethickness-local_waterdepth) && altitude>softsedr[ilon][ilat]) {
ddensity=softseddensityarray[ilon][ilat]*1000;
crust_entered=1; //Switch that lets us know we've penetrated into the crust
} //end if
else if (altitude<=softsedr[ilon][ilat] && altitude>hardsedr[ilon][ilat]) {
ddensity=hardseddensityarray[ilon][ilat]*1000;
crust_entered=1; //Switch that lets us know we've penetrated into the crust
} //end if
else if (altitude<=hardsedr[ilon][ilat] && altitude>uppercrustr[ilon][ilat]) {
ddensity=uppercrustdensityarray[ilon][ilat]*1000;
crust_entered=1; //Switch that lets us know we've penetrated into the crust
} //end if
else if (altitude<=uppercrustr[ilon][ilat] && altitude>middlecrustr[ilon][ilat]) {
ddensity=middlecrustdensityarray[ilon][ilat]*1000;
crust_entered=1; //Switch that lets us know we've penetrated into the crust
} //end if
else if (altitude<=middlecrustr[ilon][ilat] && altitude>lowercrustr[ilon][ilat]) {
ddensity=lowercrustdensityarray[ilon][ilat]*1000;
crust_entered=1; //Switch that lets us know we've penetrated into the crust
} //end if
else if (altitude<=lowercrustr[ilon][ilat]) {
ddensity=densities[1];
crust_entered=1; //Switch that lets us know we've penetrated into the crust
} //end if
// sometimes altitude will not satisfy any of these because it is above the surface.
// the neutrino is skimming the surface and will fly through the air for a while.
L=len_int_kgm2/ddensity; // get the interaction length for that density
weight1*=exp(-step/L); // adjust the weight accordingly
total_kgm2+=ddensity*step; //increase column density accordingly
if (exp(-step/L) > 1)
cout<<"Oops! len_int_kgm2, ddensity, factor : "<<len_int_kgm2<<" , "<<ddensity<<" , "<<exp(-step/L)<<endl;
x+=step; // distance you have stepped through the earth so far.
where += step*nchord;// find where you are now along the neutrino's path
lon = where.Lon();
lat = where.Lat();
ilon = (int)(lon/2);
ilat = (int)(lat/2);
altitude=where.Mag()-Geoid(lat); //what is the altitude
surface_elevation = this->SurfaceAboveGeoid(lon,lat); // altitude of surface relative to geoid at earth entrance point
local_icethickness = this->IceThickness(lon,lat);
local_waterdepth = WaterDepth(lon,lat);
} //end while
if (x>posnu.Distance(earth_in) && weightabsorption) // if you left the loop because you have already stepped the whole distance from the entrance point to the neutrino interaction position
return 1;
// if you left the loop because you're not in the crust anymore
if (altitude<=MIN_ALTITUDE_CRUST) {
mantle_entered=1; //Switch that lets us know we're into the mantle
// determine if it enters the core or not.
sinth=sin(where.Angle(nchord));
costh=sqrt(1-sinth*sinth);
if (sinth>sqrt(radii[0]/radii[1])) { // it does not enter the core, just the mantle
nearthlayers++; // count the mantle as a layer traversed.
L=len_int_kgm2/densities[1]; // interaction length in the mantle
halfchord=sqrt(radii[1])*costh; // 1/2 chord the neutrino goes through in the mantle
weight1 *= exp(-2*halfchord/L); // adjust the weight for path through mantle
total_kgm2+= 2*halfchord*densities[1]; //add column density for path through mantle
where += (2*halfchord)*nchord; // neutrino's new position once it reaches the crust again
} //end if (not entering core)
// these enter the core
else {
core_entered=1; //Switch that lets us know we've entered the core
nearthlayers+=2; // count the mantle and core as a layer traversed.
L=len_int_kgm2/densities[1]; // interaction length in mantle
// compute distance before entering the core.
halfchord=sqrt(radii[0]-radii[1]*sinth*sinth); // find distance it travels in the mantle
distance=sqrt(radii[1])*costh-halfchord;
weight1*=exp(-distance/L); // adjust the weight
total_kgm2 += 2*distance*densities[1]; //Add column density for trip through mantle
// go through the core.
L=len_int_kgm2/densities[0]; // interaction length in core
weight1*=exp(-2*halfchord/L); // adjust the weight
total_kgm2 += 2*halfchord*densities[0]; //Add column density for trip through core
// go through 2nd layer again.
L=len_int_kgm2/densities[1];
weight1*=exp(-distance/L);
if (exp(-distance/L) > 1)
cout<<"Oops2! len_int_kgm2, ddensity, distance, factor : "<<len_int_kgm2<<" , "<<ddensity<<" , "<<distance<<" , "<<exp(-distance/L)<<endl;
where += (2*distance+2*halfchord)*nchord; // neutrino's new position once it reaches the crust again
} //end else(enter core)
} //end if(left crust)
lon = where.Lon();
lat = where.Lat();
ilon = (int)(lon/2);
ilat = (int)(lat/2);
altitude=where.Mag()-Geoid(lat); //what is the altitude
surface_elevation = this->SurfaceAboveGeoid(lon,lat); // altitude of surface relative to geoid at earth entrance point
local_icethickness = this->IceThickness(lon,lat);
local_waterdepth = WaterDepth(lon,lat);
double distance_remaining=where.Distance(posnu); // how much farther you need to travel before you reach the neutrino interaction point
x=0; // this keeps track of how far you've stepped along the neutrino path, starting at the crust entrance.
while(x<=distance_remaining) { // keep going until you have reached the interaction position
double ddensity=Signal::RHOAIR;
// which layer does it go through
if (altitude<=surface_elevation && altitude>(surface_elevation-local_icethickness))
ddensity=icedensityarray[ilon][ilat]*1000;
if (altitude<=(surface_elevation-local_icethickness) && altitude>(surface_elevation-local_icethickness-local_waterdepth))
ddensity=waterdensityarray[ilon][ilat]*1000;
if (altitude<=(surface_elevation-local_icethickness-local_waterdepth) && altitude>softsedr[ilon][ilat])
ddensity=softseddensityarray[ilon][ilat]*1000;
if (altitude<=softsedr[ilon][ilat] && altitude>hardsedr[ilon][ilat])
ddensity=hardseddensityarray[ilon][ilat]*1000;
if (altitude<=hardsedr[ilon][ilat] && altitude>uppercrustr[ilon][ilat])
ddensity=uppercrustdensityarray[ilon][ilat]*1000;
if (altitude<=uppercrustr[ilon][ilat] && altitude>middlecrustr[ilon][ilat])
ddensity=middlecrustdensityarray[ilon][ilat]*1000;
if (altitude<=middlecrustr[ilon][ilat] && altitude>lowercrustr[ilon][ilat])
ddensity=lowercrustdensityarray[ilon][ilat]*1000;
if (altitude<=lowercrustr[ilon][ilat])
ddensity=3.4*1000;
L=len_int_kgm2/ddensity; // get the interaction length for that density
weight1*=exp(-step/L); // adjust the weight accordingly
total_kgm2 += step*ddensity;
if (exp(-step/L) > 1)
cout<<"Oops3! len_int_kgm2, ddensity, step, factor : "<<len_int_kgm2<<" , "<<ddensity<<" , "<<step<<" , "<<exp(-step/L)<<endl;
x+=step; // increment how far you've stepped through crust
// possible for a neutrino to go through the air but not likely because they aren't the most extreme skimmers (they went through the mantle)
where += step*nchord; // where you are now along neutrino's path
lon = where.Lon();
lat = where.Lat();
ilon = (int)(lon/2);
ilat = (int)(lat/2);
altitude=where.Mag()-Geoid(lat); //what is the altitude
surface_elevation = this->SurfaceAboveGeoid(lon,lat); // altitude of surface relative to geoid at earth entrance point
local_icethickness = this->IceThickness(lon,lat);
local_waterdepth = WaterDepth(lon,lat);
} //while
} //if (getchord_method == 2)
if (weightabsorption==0) {
if (Rand3.Rndm()>weight1) {
weight1=0.;
return 0;
}
else {
weight1=1.;
return 1;
}
}
else
return 1;
cout << "made it this far.\n";
return 1;
} //end Getchord
// new Getchord from icemc (org version)
// new tau weight calculation, probability to interact inside the ice
int EarthModel::Getchord(Primaries *primary1, Settings *settings1,IceModel *antarctica1, Secondaries *sec1,
double len_int_kgm2,
const Position &earth_in, // place where neutrino entered the earth
const Position &r_enterice,
const Position &nuexitice,
const Position &posnu, // position of the interaction
int inu,
double& chord, // chord length
double& probability_tmp, // weight
double& weight1_tmp,
double& nearthlayers, // core, mantle, crust
double myair,
double& total_kgm2, // length in kg m^2
int& crust_entered, // 1 or 0
int& mantle_entered, // 1 or 0
int& core_entered,
string thisnuflavor,double pnu, double Etau_final,
int nu_nubar, int currentint,int taumodes1, double *myxarray, double *myEarray, double *myyweightarray,
double *mytausurvarray, double& tauweight, double& tauchord, double *avgdensityarray, double *densityarray) {
Vector chord3;
Vector nchord;
double x=0;
double lat,lon;
int ilon,ilat;
total_kgm2 = 0; //Initialize column density
nearthlayers=0; // this counts the number of earth layers the neutrino traverses.
// Want to find probability that the neutrino survives its trip
// through the earth.
//Find the chord, its length and its unit vector.
chord3 = posnu - earth_in;
chord=chord3.Mag();
nchord = chord3 / chord;
if (chord<=1) {
cout << "short chord " << chord << "\n";
return 0;
}
if (chord>2.*R_EARTH+1000) {
cout << "bad chord" << " " << chord << ". Event is " << inu << "\n";
}
Position where=earth_in;
//cout <<"where(1) is "<<where;
// the sin of the angle between the neutrino path and the
// radial vector to its earth entrance point determines
// if it will get to the next layer down.
double costh=(where*nchord)/where.Mag();
double sinth=sqrt(1-costh*costh);
double distance=0;
double halfchord=0;
double taumodes = settings1->taumodes;
if (getchord_method<1 || getchord_method>3)
cout << "Bogus method!\n";
if (thisnuflavor =="nutau" && taumodes1==1 ){
// cout <<"nuflavor is nutau, \n";
sec1->GetTauWeight(primary1, settings1,antarctica1,pnu, nu_nubar,currentint,Etau_final,posnu, earth_in,
crust_entered, mantle_entered, core_entered, myxarray, myEarray, myyweightarray,
mytausurvarray,tauchord,avgdensityarray,densityarray,inu,weight1_tmp,probability_tmp);
weight1_tmp *=2; //only going to get half the normal number, so multiply by 2 to compensate.
tauweight = weight1_tmp;
//cout <<"weight1_tmp(tau) is "<<weight1_tmp<<".\n";
return 1;
}//thisnuflavor
//cout <<"nuflavor is not nutau. \n";
// we are really focusing on method 2 - method 1 has not been maintenanced in a long time!!
// use at your own risk.
if (getchord_method==1) {
double L=0;
weight1_tmp=0;
if (sinth>sqrt(radii[1]/radii[2])) {
nearthlayers++;
// these only skim the first layer.
L=len_int_kgm2/densities[2];
weight1_tmp=exp(-posnu.Distance(where)/L);
}
else {
nearthlayers++;
// these get to the second layer down.
L=len_int_kgm2/densities[2];
// compute distance before it gets to the next layer.
halfchord=sqrt(radii[1]-radii[2]*sinth*sinth);
distance=sqrt(radii[2])*costh-halfchord;
weight1_tmp=exp(-distance/L);
// get position where it enters the second layer.
where = earth_in + distance*nchord;
// determine if it enters the core or not.
costh=(where*nchord)/where.Mag();
sinth=sqrt(1-costh*costh);
if (sinth>sqrt(radii[0]/radii[1])) {
halfchord=sqrt(radii[1])*costh;
nearthlayers++;
// these do not enter the core.
L=len_int_kgm2/densities[1];
weight1_tmp *= exp(-2*halfchord/L);
L=len_int_kgm2/densities[2];
// this is where it exits the second layer and enters the crust again.
where = where + 2*halfchord*nchord;
weight1_tmp*=exp(-where.Distance(posnu)/L);
}
else {
nearthlayers++;
// these enter the core.
L=len_int_kgm2/densities[1];
// compute distance before entering the core.
halfchord=sqrt(radii[0]-radii[1]*sinth*sinth);
distance=sqrt(radii[1])*costh-halfchord;
weight1_tmp*=exp(-distance/L);
// go through the core.
L=len_int_kgm2/densities[0];
weight1_tmp*=exp(-2*halfchord/L);
// go through 2nd layer again.
L=len_int_kgm2/densities[1];
weight1_tmp*=exp(-distance/L);
// through the crust and end up at posnu.
L=len_int_kgm2/densities[2];
where = where + (2*distance+2*halfchord)*nchord;
weight1_tmp*=exp(-where.Distance(posnu)/L);
} //else
} //else
} //if getchord_method==1
if (getchord_method==2) {
x=0; // x is the distance you move as you step through the earth.
lon = where.Lon();
lat = where.Lat();
ilon = (int)(lon/2);
ilat = (int)(lat/2);
double surface_elevation = this->SurfaceAboveGeoid(lon,lat); // altitude of surface relative to geoid at earth entrance point
double local_icethickness = this->IceThickness(lon,lat);
double local_waterdepth = WaterDepth(lon,lat);
double altitude=0;
weight1_tmp=1;
probability_tmp=1;
double step=Tools::dMin(len_int_kgm2/densities[1]/10,500.); //how big is the step size
// either 1/10 of an interaction length in the mantle or 500 m, whichever is smaller.
// 500 m is approximately the feature size in Crust 2.0.
//------------------added on Dec 8------------------------
weight1_tmp*=exp(-myair/len_int_kgm2);//add atmosphere attenuation // fenfang's atten. due to atmosphere
//------------------added on Dec 8------------------------
total_kgm2+=myair;
double L_ice=len_int_kgm2/Signal::RHOICE;
if (settings1->UNBIASED_SELECTION)
probability_tmp*=1.-exp(-1.*(r_enterice.Distance(nuexitice)/L_ice)); // probability it interacts in ice along its path
double L=0;
double ddensity=Signal::RHOAIR;
nearthlayers=1;
if (where*nchord>0.) { // look at direction of neutrino where it enters the earth.
cout << "This one's trouble. Neutrino exit point looks more like an entrance point. Event is " << inu << "\n";
cout << "where is " << where[0] << " " << where[1] << " " << where[2] << "\n";
cout << "nchord is " << nchord[0] << " " << nchord[1] << " " << nchord[2] << "\n";
cout << "dot product is " << where*nchord/sqrt(where*where) << "\n";
cout << "posnu is " << posnu[0] << " " << posnu[1] << " " << posnu[2] << "\n";
cout << "Length of chord is : "<<chord<<endl;
} //end if
altitude=where.Mag()-Geoid(lat); // what is the altitude of the entrance point
if(altitude>surface_elevation+0.1) // if it is above the surface, it's messed up
cout << "neutrino entrance point is above the surface. Event is " << inu << "\n";
//cout <<"altitude is "<<altitude<<"\n";
while(altitude>MIN_ALTITUDE_CRUST && x<posnu.Distance(earth_in)) { // starting at earth entrance point, step toward interaction position until you've reached the interaction or you are below the crust.
// while(altitude>MIN_ALTITUDE_CRUST && x<dDistance(enterice,earth_in)) {
double abovesurface =0;
ddensity = this->GetDensity(altitude,where,posnu,crust_entered,mantle_entered,core_entered);
// if (abovesurface==1)
// cout <<"altitude is "<<altitude<<"\n";
// sometimes altitude will not satisfy any of these because it is above the surface.
// the neutrino is skimming the surface and will fly through the air for a while.
L=len_int_kgm2/ddensity; // get the interaction length for that density
weight1_tmp*=exp(-step/L); // adjust the weight accordingly
total_kgm2+=ddensity*step; //increase column density accordingly
if (exp(-step/L) > 1)
cout<<"Oops! len_int_kgm2, ddensity, factor : "<<len_int_kgm2<<" , "<<ddensity<<" , "<<exp(-step/L)<<endl;
x+=step; // distance you have stepped through the earth so far.
where += step*nchord;// find where you are now along the neutrino's path
lon = where.Lon();
lat = where.Lat();
ilon = (int)(lon/2);
ilat = (int)(lat/2);
altitude=where.Mag()-Geoid(lat); //what is the altitude
surface_elevation = this->SurfaceAboveGeoid(lon,lat); // altitude of surface relative to geoid at earth entrance point
local_icethickness = this->IceThickness(lon,lat);
local_waterdepth = WaterDepth(lon,lat);
} //end while
if (x>posnu.Distance(earth_in) && weightabsorption) { // if you left the loop because you have already stepped the whole distance from the entrance point to the neutrino interaction position
if (taumodes1==1 && thisnuflavor =="nutau")
weight1_tmp *=2; //factor of two for only having half the regular neutrinos.
probability_tmp*=weight1_tmp;
return 1;
}
// if you left the loop because you're not in the crust anymore
if (altitude<=MIN_ALTITUDE_CRUST) {
mantle_entered=1; //Switch that lets us know we're into the mantle
// determine if it enters the core or not.
sinth=sin(where.Angle(nchord));
costh=sqrt(1-sinth*sinth);
if (sinth>sqrt(radii[0]/radii[1])) { // it does not enter the core, just the mantle
nearthlayers++; // count the mantle as a layer traversed.
L=len_int_kgm2/densities[1]; // interaction length in the mantle
halfchord=sqrt(radii[1])*costh; // 1/2 chord the neutrino goes through in the mantle
weight1_tmp *= exp(-2*halfchord/L); // adjust the weight for path through mantle
total_kgm2+= 2*halfchord*densities[1]; //add column density for path through mantle
where += (2*halfchord)*nchord; // neutrino's new position once it reaches the crust again
} //end if (not entering core)
// these enter the core
else {
core_entered=1; //Switch that lets us know we've entered the core
nearthlayers+=2; // count the mantle and core as a layer traversed.
L=len_int_kgm2/densities[1]; // interaction length in mantle
// compute distance before entering the core.
halfchord=sqrt(radii[0]-radii[1]*sinth*sinth); // find distance it travels in the mantle
distance=sqrt(radii[1])*costh-halfchord;
weight1_tmp*=exp(-distance/L); // adjust the weight
total_kgm2 += 2*distance*densities[1]; //Add column density for trip through mantle
// go through the core.
L=len_int_kgm2/densities[0]; // interaction length in core
weight1_tmp*=exp(-2*halfchord/L); // adjust the weight
total_kgm2 += 2*halfchord*densities[0]; //Add column density for trip through core
// go through 2nd layer again.
L=len_int_kgm2/densities[1];