forked from ara-software/AraSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Report.cc
5617 lines (4247 loc) · 308 KB
/
Report.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 "Detector.h"
#include "Report.h"
#include "Event.h"
#include "RaySolver.h"
#include "signal.hh"
#include "IceModel.h"
#include "Settings.h"
#include "Vector.h"
#include "Tools.h"
#include "Trigger.h"
#include "Constants.h"
#include <iostream>
#include <sstream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include "TRandom3.h"
#include "TMath.h"
#include <cstdlib>
ClassImp(Report);
ClassImp(Antenna_r);
ClassImp(Surface_antenna_r);
ClassImp(String_r);
ClassImp(Station_r);
Report::Report() {
}
Report::Report(Detector *detector, Settings *settings1) {
// Default constructor
Initialize(detector, settings1);
}
Report::~Report() {
// default destructor
stations.clear();
strings.clear();
Passed_chs.clear();
Vfft_noise_after.clear();
Vfft_noise_before.clear();
//V_noise_timedomain.clear();
}
void Report::delete_all() {
stations.clear();
strings.clear();
Passed_chs.clear();
Vfft_noise_after.clear();
Vfft_noise_before.clear();
noise_phase.clear(); // random noise phase generated in GetNoisePhase()
signal_bin.clear(); // the center of bin where signal should locate
signal_dbin.clear(); // the bin difference between signal bins
connect_signals.clear(); // if ray_sol time delay is small enough to connect each other
Passed_chs.clear();
}
void Report::Initialize(Detector *detector, Settings *settings1) {
// clear information stored in (but there shouldn't be. just to make sure)
//
//stations.clear();
delete_all();
// tmp for push_back vector structure
Antenna_r tmp_antenna;
String_r tmp_string;
Station_r tmp_station;
Surface_antenna_r tmp_surface;
for (int i=0; i<detector->params.number_of_stations; i++) {
// vector stations
stations.push_back(tmp_station);
for (int j=0; j<detector->stations[i].strings.size(); j++) {
// vector strings
stations[i].strings.push_back(tmp_string);
for (int k=0; k<detector->stations[i].strings[j].antennas.size(); k++) {
// vector antennas
stations[i].strings[j].antennas.push_back(tmp_antenna);
}
}
for (int j=0; j<detector->stations[i].surfaces.size(); j++) {
// vector surface antennas
stations[i].surfaces.push_back(tmp_surface);
}
if(settings1->TRIG_SCAN_MODE>0){// scan Pthresh mode
int numChan=0;
int numChanVpol=0;
int numChanHpol=0;
for(int j=0;j<detector->stations[i].strings.size(); j++){
for (int k=0;k<detector->stations[i].strings[j].antennas.size();k++) {
int string_i = detector->getStringfromArbAntID( i, numChan);
int antenna_i = detector->getAntennafromArbAntID( i, numChan);
if (detector->stations[i].strings[string_i].antennas[antenna_i].type == 0) numChanVpol++;
if (detector->stations[i].strings[string_i].antennas[antenna_i].type == 1) numChanHpol++;
numChan++;
}// for k
}// for j
stations[i].TDR_all.clear();
for(int ch=0;ch<numChan; ch++ ) stations[i].TDR_all.push_back(0);
stations[i].TDR_all_sorted.clear();
if(settings1->TRIG_MODE==0) for(int ch=0;ch<numChan; ch++ ) stations[i].TDR_all_sorted.push_back(0);
stations[i].TDR_Vpol_sorted.clear();
if(settings1->TRIG_MODE==1) for(int ch=0;ch<numChanVpol; ch++) stations[i].TDR_Vpol_sorted.push_back(0);
stations[i].TDR_Hpol_sorted.clear();
if(settings1->TRIG_MODE==1) for(int ch=0;ch<numChanHpol; ch++ ) stations[i].TDR_Hpol_sorted.push_back(0);
}// if TRIG_SCAN_MODE
}// for i (number of stations)
}
void Antenna_r::clear() { // if any vector variable added in Antenna_r, need to be added here!
view_ang.clear();
launch_ang.clear();
rec_ang.clear();
reflect_ang.clear();
Dist.clear();
L_att.clear();
arrival_time.clear();
reflection.clear();
Pol_vector.clear();
vmmhz.clear();
Heff.clear();
Mag.clear();
Fresnel.clear();
Pol_factor.clear();
Pol_factorH.clear();
Pol_factorV.clear();
phi_rec.clear();
theta_rec.clear();
//VHz_antfactor.clear();
//VHz_filter.clear();
Vfft.clear();
Vfft_noise.clear();
ray_step.clear();
time.clear();
time_mimic.clear();
V_mimic.clear();
Ax.clear();
Ay.clear();
Az.clear();
V.clear();
noise_ID.clear();
PeakV.clear();
Rank.clear();
TooMuch_Tdelay.clear();
Trig_Pass = 0;
// additional for before ant waveform
//Vm_wo_antfactor.clear();
Vm_zoom.clear();
Vm_zoom_T.clear();
SignalBin.clear();
SignalExt.clear();
SCT_threshold_pass.clear();
}
void Antenna_r::clear_useless(Settings *settings1) { // to reduce the size of output AraOut.root, remove some information
if (settings1->DATA_SAVE_MODE == 1) {
Heff.clear();
//VHz_antfactor.clear();
//VHz_filter.clear();
Vfft.clear();
Vfft_noise.clear();
Ax.clear();
Ay.clear();
Az.clear();
V.clear();
//Trig_Pass.clear();
TooMuch_Tdelay.clear();
// need or not?
//Pol_vector.clear();
vmmhz.clear();
//Mag.clear();
//Fresnel.clear();
//Pol_factor.clear();
//
// additional for before ant waveform
//Vm_wo_antfactor.clear();
Vm_zoom.clear();
Vm_zoom_T.clear();
}
else if (settings1->DATA_SAVE_MODE == 2) {
//! clear the ray step to reduce the size of output AraOut.root
ray_step.clear();
Heff.clear();
//VHz_antfactor.clear();
//VHz_filter.clear();
Vfft.clear();
Vfft_noise.clear();
Ax.clear();
Ay.clear();
Az.clear();
V.clear();
//Trig_Pass.clear();
TooMuch_Tdelay.clear();
// need or not?
//Pol_vector.clear();
vmmhz.clear();
//Mag.clear();
//Fresnel.clear();
//Pol_factor.clear();
// clear global trigger waveform info also
time.clear();
time_mimic.clear();
V_mimic.clear();
// additional for before ant waveform
//Vm_wo_antfactor.clear();
Vm_zoom.clear();
Vm_zoom_T.clear();
}
}
void Report::clear_useless(Settings *settings1) { // to reduce the size of output AraOut.root, remove some information
if (settings1->DATA_SAVE_MODE != 0) {
// also clear all vector info to reduce output root file size
noise_phase.clear();
signal_bin.clear();
signal_dbin.clear();
connect_signals.clear();
Passed_chs.clear();
Vfft_noise_after.clear();
Vfft_noise_before.clear();
//V_noise_timedomain.clear();
// done clear vector info in report head
//
V_total_forconvlv.clear();
RayStep.clear();
}
}
void Report::Connect_Interaction_Detector_V2(Event *event, Detector *detector, RaySolver *raysolver, Signal *signal, IceModel *icemodel, Settings *settings1, Trigger *trigger, int evt)
{
int ray_sol_cnt;
double viewangle;
Position launch_vector; // direction of ray at the source
Position receive_vector; // direction of ray at the target antenna
Vector n_trg_pokey; // unit pokey vector at the target
Vector n_trg_slappy; // unit slappy vector at the target
vector<vector < double>> ray_output;
double vmmhz1m_tmp, vmmhz1m_sum, vmmhz1m_em; // currently not using vmmhz1m_em
Position Pol_vector; // polarization vector at the source
double mag; // magnification factor. it can vary in case of plane / spherical wave
double fresnel; // fresnel factor
double Pol_factor; // polarization factor
double tmp; // for non use return values
double Pol_factorV;
double Pol_factorH;
double phi_rec;
double theta_rec;
double freq_tmp, heff, antenna_theta, antenna_phi; // values needed for apply antenna gain factor and prepare fft, trigger
double volts_forfft[settings1->NFOUR / 2]; // array for fft
double dT_forfft;
double volts_forint[settings1->NFOUR / 2]; // array for interpolation
double T_forint[settings1->NFOUR / 2]; // array for interpolation
double dF_NFOUR = 1. / ((double)(settings1->NFOUR / 2) *settings1->TIMESTEP); // in Hz
int waveformLength = settings1->WAVEFORM_LENGTH;
int waveformCenter = settings1->WAVEFORM_CENTER;
double dF_Nnew;
double heff_lastbin;
double freq_lastbin;
int check_toomuch_Tdelay; // return value from MixSignalNoise_Tdelay
double min_arrival_time_tmp; // min arrival time between all antennas, raysolves
double max_arrival_time_tmp; // max arrival time between all antennas, raysolves
double max_PeakV_tmp; // max PeakV of all antennas in the station
int trig_window_bin = (int)(settings1->TRIG_WINDOW / settings1->TIMESTEP); // coincidence window bin for trigger
RandomTshift = gRandom->Rndm();
init_T = settings1->TIMESTEP *-1.e9 *((double) settings1->NFOUR / 4 + RandomTshift); // locate zero time at the middle and give random time shift
for (int n = 0; n < settings1->NFOUR / 2; n++)
{
T_forint[n] = init_T + (double) n *settings1->TIMESTEP *1.e9; // in ns
}
// decide whether debug mode or not
int debugmode = 0;
if (settings1->DEBUG_MODE_ON == 1 && evt < settings1->DEBUG_SKIP_EVT) debugmode = 1;
else if (settings1->DEBUG_MODE_ON == 1 && evt >= settings1->DEBUG_SKIP_EVT) cout << evt << " " << endl;
// skip most of computation intensive processes if debugmode == 1
int N_pass; // number of trigger passed channels (antennas)
int N_pass_V; // number of trigger passed channels (Vpol antennas)
int N_pass_H; // number of trigger passed channels (Hpol antennas)
for (int i = 0; i < detector->params.number_of_stations; i++)
{
min_arrival_time_tmp = 10.; // first min_arrival_time is unreasonably big value
max_arrival_time_tmp = 0.; // first max_arrival_time is unreasonably small value
max_PeakV_tmp = 0.; // first max_PeakV_tmp is 0.
stations[i].Total_ray_sol = 0; // initial Total_ray_sol value
for (int j = 0; j < detector->stations[i].strings.size(); j++)
{
for (int k = 0; k < detector->stations[i].strings[j].antennas.size(); k++)
{
// cout << i << " : " << j << " : " << k << endl;
stations[i].strings[j].antennas[k].clear(); // clear data in antenna which stored in previous event
// run ray solver, see if solution exist
// if not, skip (set something like Sol_No = 0;
// if solution exist, calculate view angle and calculate TaperVmMHz
// added one more condition to run raysolver (direct distance is less than 3km)
//
// cout << event->Nu_Interaction[0].posnu.GetX() << " : " << event->Nu_Interaction[0].posnu.GetY() << " : " << event->Nu_Interaction[0].posnu.GetZ() << endl;
// cout << event->Nu_Interaction[0].pickposnu << " : " << event->Nu_Interaction[0].posnu.Distance(detector->stations[i].strings[j].antennas[k]) << " : " << settings1->RAYSOL_RANGE << endl;
if (event->Nu_Interaction[0].pickposnu && event->Nu_Interaction[0].posnu.Distance(detector->stations[i].strings[j].antennas[k]) <= settings1->RAYSOL_RANGE)
{
// if posnu is selected inside the antarctic ice
// cout << i << " : " << j << " : " << k << endl;
RayStep.clear(); // remove previous values
raysolver->Solve_Ray(event->Nu_Interaction[0].posnu, detector->stations[i].strings[j].antennas[k], icemodel, ray_output, settings1, RayStep); // solve ray between source and antenna
ray_sol_cnt = 0;
if (raysolver->solution_toggle)
{
// if there are solution from raysolver
while (ray_sol_cnt < ray_output[0].size())
{
// for number of soultions (could be 1 or 2)
stations[i].strings[j].antennas[k].arrival_time.push_back(ray_output[4][ray_sol_cnt]);
//! Save every ray steps between the vertex (source) and an antenna (target), unless DATA_SAVE_MODE is 2. 02-12-2021 -MK-
//! These xz coordinates were calculated after we convert the earth coordinates to flat coordinates by the RaySolver::Earth_to_Flat_same_angle()
stations[i].strings[j].antennas[k].ray_step.resize(ray_sol_cnt + 1); ///< resize by number of ray solutions
stations[i].strings[j].antennas[k].ray_step[ray_sol_cnt].resize(2); ///< resize by xz values
for (int steps = 0; steps < (int) RayStep[ray_sol_cnt][0].size(); steps++)
{
///< push back each ray step coordinates
stations[i].strings[j].antennas[k].ray_step[ray_sol_cnt][0].push_back(RayStep[ray_sol_cnt][0][steps]);
stations[i].strings[j].antennas[k].ray_step[ray_sol_cnt][1].push_back(RayStep[ray_sol_cnt][1][steps]);
}
// get ice attenuation factor
double IceAttenFactor = 1.;
if (settings1->USE_ARA_ICEATTENU == 1)
{
// use new ARA measured ice attenuation values
double dx, dz, dl;
for (int steps = 1; steps < (int) RayStep[ray_sol_cnt][0].size(); steps++)
{
dx = RayStep[ray_sol_cnt][0][steps - 1] - RayStep[ray_sol_cnt][0][steps];
dz = RayStep[ray_sol_cnt][1][steps - 1] - RayStep[ray_sol_cnt][1][steps];
dl = sqrt((dx *dx) + (dz *dz));
// Skipping attenuation calculation when the distance between two RaySteps is 0. Prevening adds -nan into the IceAttenFactor. (MK 2021)
if (dl > 0)
{
// use new ice model
// use the midpoint of the array to calculate the attenuation length, instead of the end of the ray (BAC 2020)
IceAttenFactor *= (exp(-dl / icemodel->GetARAIceAttenuLength(-RayStep[ray_sol_cnt][1][steps])) + exp(-dl / icemodel->GetARAIceAttenuLength(-RayStep[ray_sol_cnt][1][steps - 1]))) / 2;
}
}
}
else if (settings1->USE_ARA_ICEATTENU == 0)
{
// use old method
IceAttenFactor = exp(-ray_output[0][ray_sol_cnt] / icemodel->EffectiveAttenuationLength(settings1, event->Nu_Interaction[0].posnu, 0));
}
if (debugmode == 0)
{
// set viewangle, launch_vector, receive vectors
viewangle = ray_output[1][ray_sol_cnt];
GetParameters(event->Nu_Interaction[0].posnu, // posnu
detector->stations[i].strings[j].antennas[k], // trg antenna
event->Nu_Interaction[0].nnu, // nnu
viewangle, // inputs launch_angle, returns viewangle
ray_output[2][ray_sol_cnt], // receive_angle
launch_vector, receive_vector,
n_trg_slappy, n_trg_pokey);
// check viewangle that if ray in near Cherenkov cone
if (viewangle * DEGRAD > 55. && viewangle * DEGRAD < 57.)
{
// if viewangle is 56 deg +- 1 deg
//cout<<"near cone! view angle : "<<viewangle * DEGRAD <<" station["<<i<<"].string["<<j<<"].antenna["<<k<<"] with ray_sol_cnt : "<<ray_sol_cnt<<endl;
}
// store information to report
stations[i].strings[j].antennas[k].view_ang.push_back(viewangle);
stations[i].strings[j].antennas[k].launch_ang.push_back(ray_output[1][ray_sol_cnt]);
stations[i].strings[j].antennas[k].rec_ang.push_back(ray_output[2][ray_sol_cnt]);
stations[i].strings[j].antennas[k].Dist.push_back(ray_output[0][ray_sol_cnt]);
stations[i].strings[j].antennas[k].L_att.push_back(icemodel->EffectiveAttenuationLength(settings1, event->Nu_Interaction[0].posnu, 0));
stations[i].strings[j].antennas[k].reflect_ang.push_back(ray_output[3][ray_sol_cnt]);
stations[i].strings[j].antennas[k].vmmhz.resize(ray_sol_cnt + 1);
stations[i].strings[j].antennas[k].Heff.resize(ray_sol_cnt + 1);
stations[i].strings[j].antennas[k].Vm_zoom.resize(ray_sol_cnt + 1);
stations[i].strings[j].antennas[k].Vm_zoom_T.resize(ray_sol_cnt + 1);
stations[i].strings[j].antennas[k].Vfft.resize(ray_sol_cnt + 1);
stations[i].strings[j].antennas[k].Vfft_noise.resize(ray_sol_cnt + 1);
stations[i].strings[j].antennas[k].V.resize(ray_sol_cnt + 1);
stations[i].strings[j].antennas[k].SignalExt.resize(ray_sol_cnt + 1);
// calculate the polarization vector at the source
Pol_vector = GetPolarization(event->Nu_Interaction[0].nnu, launch_vector);
icemodel->GetFresnel(ray_output[1][ray_sol_cnt], // launch_angle
ray_output[2][ray_sol_cnt], // rec_angle
ray_output[3][ray_sol_cnt], // reflect_angle
event->Nu_Interaction[0].posnu,
launch_vector,
receive_vector,
settings1,
fresnel,
mag,
Pol_vector); // input src Pol and return Pol at trg
if (ray_output[3][ray_sol_cnt] < PI / 2.)
{
// when not reflected at the surface, angle = 100
stations[i].strings[j].antennas[k].reflection.push_back(1); // say this is reflected ray
}
else
{
stations[i].strings[j].antennas[k].reflection.push_back(0); // say this is not reflected ray
}
stations[i].strings[j].antennas[k].Pol_vector.push_back(Pol_vector); // this Pol_vector is for the target antenna
stations[i].strings[j].antennas[k].Mag.push_back(mag); // magnification factor
stations[i].strings[j].antennas[k].Fresnel.push_back(fresnel); // Fresnel factor
vmmhz1m_sum = 0;
// get the arrival angle at the antenna, and store the relevant polarization factors
GetAngleAnt(receive_vector, detector->stations[i].strings[j].antennas[k], antenna_theta, antenna_phi); // get theta, phi for signal ray arrived at antenna
Vector thetaHat = Vector(cos(antenna_theta *(PI / 180)) *cos(antenna_phi *(PI / 180)),
cos(antenna_theta *(PI / 180)) *sin(antenna_phi *(PI / 180)),
-sin(antenna_theta *(PI / 180)));
Vector phiHat = Vector(-sin(antenna_phi *(PI / 180)),
cos(antenna_phi *(PI / 180)),
0);
stations[i].strings[j].antennas[k].Pol_factorH.push_back(abs(phiHat *Pol_vector));
stations[i].strings[j].antennas[k].Pol_factorV.push_back(abs(thetaHat *Pol_vector));
stations[i].strings[j].antennas[k].phi_rec.push_back(antenna_phi *(PI / 180));
stations[i].strings[j].antennas[k].theta_rec.push_back(antenna_theta *(PI / 180));
// old freq domain signal mode (AVZ model)
if (settings1->SIMULATION_MODE == 0)
{
// initially give raysol has actual signal
stations[i].strings[j].antennas[k].SignalExt[ray_sol_cnt] = 1;
double vmmhz_filter[(int)(detector->GetFreqBin())];
for (int l = 0; l < detector->GetFreqBin(); l++)
{
// for detector freq bin numbers
//cout<<"TaperVmMHz inputs VA:"<<viewangle<<" th_em:"<<event->Nu_Interaction[0].d_theta_em[l]<<" th_had:"<<event->Nu_Interaction[0].d_theta_had[l]<<" emfrac:"<<event->Nu_Interaction[0].emfrac<<" hadfrac:"<<event->Nu_Interaction[0].hadfrac<<" vmmhz1m:"<<event->Nu_Interaction[0].vmmhz1m[l]<<endl;
// switch (event->IsCalpulser){
// case 0:
if (event->IsCalpulser > 0)
{
vmmhz1m_tmp = event->Nu_Interaction[0].vmmhz1m[l] *settings1->CALPUL_AMP;
//vmmhz1m_tmp = event->Nu_Interaction[0].vmmhz1m[l];// calpulser -> let's use slight offset from cone
//signal->TaperVmMHz(settings1->CALPUL_OFFCONE_ANGLE*RADDEG, event->Nu_Interaction[0].d_theta_em[l], event->Nu_Interaction[0].d_theta_had[l], event->Nu_Interaction[0].emfrac, event->Nu_Interaction[0].hadfrac, vmmhz1m_tmp, vmmhz1m_em);
}
else
{
vmmhz1m_tmp = event->Nu_Interaction[0].vmmhz1m[l];
signal->TaperVmMHz(viewangle, event->Nu_Interaction[0].d_theta_em[l], event->Nu_Interaction[0].d_theta_had[l], event->Nu_Interaction[0].emfrac, event->Nu_Interaction[0].hadfrac, vmmhz1m_tmp, vmmhz1m_em);
}
// break;
// case 1:
// vmmhz1m_tmp = 0;
// break;
// case 2:
// vmmhz1m_tmp = 0;
// break;
// default:
// vmmhz1m_tmp = event->Nu_Interaction[0].vmmhz1m[l];
// break;
// }
// signal->TaperVmMHz(viewangle, event->Nu_Interaction[0].d_theta_em[l], event->Nu_Interaction[0].d_theta_had[l], event->Nu_Interaction[0].emfrac, event->Nu_Interaction[0].hadfrac, vmmhz1m_tmp, vmmhz1m_em);
//cout<<"TaperVmMHz (1m at view angle) at "<<l<<"th bin : "<<vmmhz1m_tmp<<endl;
// multiply all factors for traveling ice
//vmmhz1m_tmp = vmmhz1m_tmp / ray_output[0][ray_sol_cnt] *exp(-ray_output[0][ray_sol_cnt]/icemodel->EffectiveAttenuationLength(settings1, event->Nu_Interaction[0].posnu, 0)) *mag * fresnel; // assume whichray = 0, now vmmhz1m_tmp has all factors except for the detector properties (antenna gain, etc)
if (settings1->USE_ARA_ICEATTENU == 1 || settings1->USE_ARA_ICEATTENU == 0)
{
vmmhz1m_tmp = vmmhz1m_tmp / ray_output[0][ray_sol_cnt] *IceAttenFactor *mag * fresnel; // assume whichray = 0, now vmmhz1m_tmp has all factors except for the detector properties (antenna gain, etc)
}
else if (settings1->USE_ARA_ICEATTENU == 2)
{
double IceAttenFactor = 1.;
double dx, dz, dl;
for (int steps = 1; steps < (int) RayStep[ray_sol_cnt][0].size(); steps++)
{
dx = RayStep[ray_sol_cnt][0][steps - 1] - RayStep[ray_sol_cnt][0][steps];
dz = RayStep[ray_sol_cnt][1][steps - 1] - RayStep[ray_sol_cnt][1][steps];
dl = sqrt((dx *dx) + (dz *dz));
// Skipping attenuation calculation when the distance between two RaySteps is 0. Prevening adds -nan into the IceAttenFactor. (MK 2021)
if (dl > 0)
{
// IceAttenFactor *= exp(-dl / icemodel->GetFreqDepIceAttenuLength(-RayStep[ray_sol_cnt][1][steps], detector->GetFreq(l) / 1e9));
// use ray midpoint for attenuation calculation
IceAttenFactor *= (exp(-dl / icemodel->GetFreqDepIceAttenuLength(-RayStep[ray_sol_cnt][1][steps], detector->GetFreq(l) / 1e9)) +
exp(-dl / icemodel->GetFreqDepIceAttenuLength(-RayStep[ray_sol_cnt][1][steps - 1], detector->GetFreq(l) / 1e9))
) / 2.; // 1e9 to convert to GHz
}
}
vmmhz1m_tmp = vmmhz1m_tmp / ray_output[0][ray_sol_cnt] *IceAttenFactor *mag * fresnel; // assume whichray = 0, now vmmhz1m_tmp has all factors except for the detector properties (antenna gain, etc)
}
//cout<<"AttenLength : "<<icemodel->EffectiveAttenuationLength(settings1, event->Nu_Interaction[0].posnu, 0)<<endl;
vmmhz1m_sum += vmmhz1m_tmp;
stations[i].strings[j].antennas[k].vmmhz[ray_sol_cnt].push_back(vmmhz1m_tmp);
freq_tmp = detector->GetFreq(l); // freq in Hz
//cout << "Check 1" << endl;
/*
// Get ant gain with 2-D interpolation (may have bug?)
//
heff = GaintoHeight(detector->stations[i].strings[j].antennas[k].GetG(detector, freq_tmp*1.E-6, // to MHz
antenna_theta, antenna_phi),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
*/
if (settings1->ALL_ANT_V_ON == 0)
{
if (settings1->ANTENNA_MODE != 1)
{
heff = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, detector->stations[i].strings[j].antennas[k].type),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
if (settings1->ANTENNA_MODE == 1)
{
heff = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, detector->stations[i].strings[j].antennas[k].type, k),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
}
else if (settings1->ALL_ANT_V_ON == 1)
{
if (settings1->ANTENNA_MODE != 1)
{
heff = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, 0),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
if (settings1->ANTENNA_MODE == 1)
{
heff = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, 0, k),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
}
//cout<<"n_medium : "<<icemodel->GetN(detector->stations[i].strings[j].antennas[k])<<endl;
//cout<<"gain : "<<detector->stations[i].strings[j].antennas[k].GetG(detector, freq_tmp*1.E-6, antenna_theta, antenna_phi)<<endl;
//cout<<"heff : "<<heff<<endl;
stations[i].strings[j].antennas[k].Heff[ray_sol_cnt].push_back(heff);
// apply pol factor, heff
if (event->IsCalpulser == 1)
{
//cout<<"set signal pol as Hpol for Calpulser1 evts"<<endl;
Pol_vector = n_trg_slappy;
}
else if (event->IsCalpulser == 2)
{
//cout<<"set signal pol as Vpol for Calpulser2 evts"<<endl;
Pol_vector = n_trg_pokey;
}
else if (event->IsCalpulser == 3)
{
//cout<<"set signal pol as Hpol for Calpulser2 evts"<<endl;
Pol_vector = n_trg_slappy;
}
else if (event->IsCalpulser == 4)
{
//cout<<"set signal pol as Vpol + Hpol for Calpulser2 evts"<<endl;
Pol_vector = n_trg_slappy + n_trg_pokey;
}
ApplyAntFactors(heff, n_trg_pokey, n_trg_slappy, Pol_vector, detector->stations[i].strings[j].antennas[k].type, Pol_factor, vmmhz1m_tmp, antenna_theta, antenna_phi);
//cout << "Check 2" << endl;
//stations[i].strings[j].antennas[k].VHz_antfactor[ray_sol_cnt].push_back(vmmhz1m_tmp);
// apply filter
ApplyFilter(l, detector, vmmhz1m_tmp);
// apply Preamp gain
ApplyPreamp(l, detector, vmmhz1m_tmp);
// apply FOAM gain
ApplyFOAM(l, detector, vmmhz1m_tmp);
//stations[i].strings[j].antennas[k].VHz_filter[ray_sol_cnt].push_back(vmmhz1m_tmp);
vmmhz_filter[l] = vmmhz1m_tmp;
} // end for freq bin
stations[i].strings[j].antennas[k].Pol_factor.push_back(Pol_factor);
//cout<<"station["<<i<<"].strings["<<j<<"].antennas["<<k<<"].vmmhz1m["<<ray_sol_cnt<<"][0] : "<<stations[i].strings[j].antennas[k].vmmhz[ray_sol_cnt][0]<<endl;
//MakeArraysforFFT(settings1, detector, i, stations[i].strings[j].antennas[k].VHz_filter[ray_sol_cnt], volts_forfft);
MakeArraysforFFT(settings1, detector, i, vmmhz_filter, volts_forfft);
// save freq domain array which is prepaired for realft
for (int n = 0; n < settings1->NFOUR / 2; n++)
{
stations[i].strings[j].antennas[k].Vfft[ray_sol_cnt].push_back(volts_forfft[n]);
}
// now, after realft, volts_forfft is time domain signal at backend of antenna
Tools::realft(volts_forfft, -1, settings1->NFOUR / 2);
//Tools::realft(volts_forfft,1,settings1->NFOUR/2);
//cout<<"Finished getting V signal part!!"<<endl;
stations[i].strings[j].antennas[k].PeakV.push_back(FindPeak(volts_forfft, settings1->NFOUR / 2));
// Vfft_noise_org is in fft freq bin!!
// same unit with Vfft[V] but filter not applied
Tools::NormalTimeOrdering(settings1->NFOUR / 2, volts_forfft);
//cout<<"finished NormalTimeOrdering!!"<<endl;
for (int n = 0; n < settings1->NFOUR / 2; n++)
{
if (settings1->TRIG_ANALYSIS_MODE != 2)
{
// not pure noise mode (we need signal)
stations[i].strings[j].antennas[k].V[ray_sol_cnt].push_back(volts_forfft[n]);
}
else if (settings1->TRIG_ANALYSIS_MODE == 2)
{
// pure noise mode (set signal to 0)
stations[i].strings[j].antennas[k].V[ray_sol_cnt].push_back(0.);
}
//stations[i].strings[j].antennas[k].time[ray_sol_cnt].push_back(stations[i].strings[j].antennas[k].arrival_time[ray_sol_cnt] + (double)(n - settings1->NFOUR/4)*settings1->TIMESTEP); // time at 0 s is when ray started at the posnu
}
//cout<<"finished push_back V, V_noise V_total, and time!!"<<endl;
} // if SIMULATION_MODE = 0
else if (settings1->SIMULATION_MODE == 1)
{
// if event is not calpulser
if (event->IsCalpulser == 0)
{
if (settings1->EVENT_TYPE == 0)
{
// see if integrated shower profile LQ is non-zero
// and near the cone viewangle
if (event->Nu_Interaction[0].LQ > 0 && (fabs(viewangle - signal->CHANGLE_ICE) <= settings1->OFFCONE_LIMIT *RADDEG))
{
// initially give raysol has actual signal
stations[i].strings[j].antennas[k].SignalExt[ray_sol_cnt] = 1;
// let's make NFOUR/2 bin of time domain pure signal part for now
// later once we understand how to apply antenna phase, total electronics with phase, apply those
double atten_factor = 0.;
if (settings1->USE_ARA_ICEATTENU == 1 || settings1->USE_ARA_ICEATTENU == 0)
{
atten_factor = 1. / ray_output[0][ray_sol_cnt] *IceAttenFactor *mag * fresnel; // assume whichray = 0, now vmmhz1m_tmp has all factors except for the detector properties (antenna gain, etc)
}
else if (settings1->USE_ARA_ICEATTENU == 2)
{
atten_factor = 1. / ray_output[0][ray_sol_cnt] *mag * fresnel; //apply freq dependent IceAttenFactor later
}
// signal before the antenna (get signal at 1m and apply atten factor)
signal->GetVm_FarField_Tarray(event, settings1, viewangle, atten_factor, outbin, Tarray, Earray, stations[i].strings[j].antennas[k].skip_bins[ray_sol_cnt]);
dT_forfft = Tarray[1] - Tarray[0]; // step in ns
int Ntmp = settings1->TIMESTEP *1.e9 / dT_forfft;
stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] = 1;
while (Ntmp > 1)
{
Ntmp = Ntmp / 2;
stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] = stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] *2;
}
stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] = stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] *settings1->NFOUR / 2;
// now new NFOUR for zero padding
// now we have to make NFOUR/2 number of bins with random init time
//
// as a test, make first as it is and zero pad
double V_forfft[stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt]];
double T_forfft[stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt]];
for (int n = 0; n < stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt]; n++)
{
if (n < outbin)
{
stations[i].strings[j].antennas[k].Vm_zoom[ray_sol_cnt].push_back(Earray[n]);
stations[i].strings[j].antennas[k].Vm_zoom_T[ray_sol_cnt].push_back(Tarray[n]);
}
// make Tarray, Earray located at the center of Nnew array
T_forfft[n] = Tarray[outbin / 2] - (dT_forfft *(double)(stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] / 2 - n));
if ((n >= stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] / 2 - outbin / 2) &&
(n < stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] / 2 + outbin / 2))
{
V_forfft[n] = Earray[n - (stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] / 2 - outbin / 2)];
}
else
V_forfft[n] = 0.;
}
// just get peak from the array
stations[i].strings[j].antennas[k].PeakV.push_back(FindPeak(Earray, outbin));
// this forward fft volts_forfft is now in unit of V at each freq we can just apply each bin's gain factor to each freq bins
// without any phase consideration,
// apply same factor to both real, img parts
// get spectrum with zero padded WF
Tools::realft(V_forfft, 1, stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt]);
dF_Nnew = 1. / ((double)(stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt]) *(dT_forfft) *1.e-9); // in Hz
freq_tmp = dF_Nnew *((double) stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] / 2. + 0.5); // in Hz 0.5 to place the middle of the bin and avoid zero freq
freq_lastbin = freq_tmp;
/*
// Get ant gain with 2-D interpolation (may have bug?)
*/
if (settings1->ALL_ANT_V_ON == 0)
{
if (settings1->ANTENNA_MODE != 1)
{
heff_lastbin = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, detector->stations[i].strings[j].antennas[k].type),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
if (settings1->ANTENNA_MODE == 1)
{
heff_lastbin = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, detector->stations[i].strings[j].antennas[k].type, k),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
}
else if (settings1->ALL_ANT_V_ON == 1)
{
if (settings1->ANTENNA_MODE != 1)
{
heff_lastbin = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, 0),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
if (settings1->ANTENNA_MODE == 1)
{
heff_lastbin = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, 0, k),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
}
for (int n = 0; n < stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt] / 2; n++)
{
freq_tmp = dF_Nnew *((double) n + 0.5); // in Hz 0.5 to place the middle of the bin and avoid zero freq
if (settings1->ALL_ANT_V_ON == 0)
{
if (settings1->ANTENNA_MODE != 1)
{
heff = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, detector->stations[i].strings[j].antennas[k].type),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
if (settings1->ANTENNA_MODE == 1)
{
heff = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, detector->stations[i].strings[j].antennas[k].type, k),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
}
else if (settings1->ALL_ANT_V_ON == 1)
{
if (settings1->ANTENNA_MODE != 1)
{
heff = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, 0),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
if (settings1->ANTENNA_MODE == 1)
{
heff = GaintoHeight(detector->GetGain_1D_OutZero(freq_tmp *1.E-6, // to MHz
antenna_theta, antenna_phi, 0, k),
freq_tmp, icemodel->GetN(detector->stations[i].strings[j].antennas[k]));
}
}
stations[i].strings[j].antennas[k].Heff[ray_sol_cnt].push_back(heff);
//apply freq dependent attenuation model
if (settings1->USE_ARA_ICEATTENU == 2)
{
double IceAttenFactor = 1.;
double dx, dz, dl;
for (int steps = 1; steps < (int) RayStep[ray_sol_cnt][0].size(); steps++)
{
dx = RayStep[ray_sol_cnt][0][steps - 1] - RayStep[ray_sol_cnt][0][steps];
dz = RayStep[ray_sol_cnt][1][steps - 1] - RayStep[ray_sol_cnt][1][steps];
dl = sqrt((dx *dx) + (dz *dz));
// Skipping attenuation calculation when the distance between two RaySteps is 0. Prevening adds -nan into the IceAttenFactor. (MK 2021)
if (dl > 0)
{
// use ray midpoint for attenuation calculation
IceAttenFactor *= (exp(-dl / icemodel->GetFreqDepIceAttenuLength(-RayStep[ray_sol_cnt][1][steps], freq_tmp *1.E-9)) +
exp(-dl / icemodel->GetFreqDepIceAttenuLength(-RayStep[ray_sol_cnt][1][steps - 1], freq_tmp *1.E-9))
) / 2.; // 1e9 for conversion to GHz
}
}
//cout << "apply IceAttenFactor to the real part of fft. V_forfft[2 *n] = " << V_forfft[2 *n] << " *" << IceAttenFactor << endl;
V_forfft[2 *n] *= IceAttenFactor; // apply IceAttenFactor to the real part of fft
V_forfft[2 *n + 1] *= IceAttenFactor; // apply IceAttenFactor to the imag part of fft
}
// apply ant factors
if (n > 0)
{
if (settings1->ALL_ANT_V_ON == 0)
{
ApplyAntFactors_Tdomain(detector->GetAntPhase_1D(freq_tmp *1.e-6, antenna_theta, antenna_phi, detector->stations[i].strings[j].antennas[k].type),
heff, n_trg_pokey, n_trg_slappy, Pol_vector, detector->stations[i].strings[j].antennas[k].type, Pol_factor, V_forfft[2 *n], V_forfft[2 *n + 1], settings1, antenna_theta, antenna_phi);
}
else if (settings1->ALL_ANT_V_ON == 1)
{
ApplyAntFactors_Tdomain(detector->GetAntPhase_1D(freq_tmp *1.e-6, antenna_theta, antenna_phi, 0),
heff, n_trg_pokey, n_trg_slappy, Pol_vector, detector->stations[i].strings[j].antennas[k].type, Pol_factor, V_forfft[2 *n], V_forfft[2 *n + 1], settings1, antenna_theta, antenna_phi);
}
}
else
{
ApplyAntFactors_Tdomain_FirstTwo(heff, heff_lastbin, n_trg_pokey, n_trg_slappy, Pol_vector, detector->stations[i].strings[j].antennas[k].type, Pol_factor, V_forfft[2 *n], V_forfft[2 *n + 1], antenna_theta, antenna_phi);
}
// apply entire elect chain gain, phase
if (n > 0)
{
ApplyElect_Tdomain(freq_tmp *1.e-6, detector, V_forfft[2 *n], V_forfft[2 *n + 1], settings1);
}
else
{
ApplyElect_Tdomain_FirstTwo(freq_tmp *1.e-6, freq_lastbin *1.e-6, detector, V_forfft[2 *n], V_forfft[2 *n + 1]);
}
} // end for freq bin
// now get time domain waveform back by inv fft
Tools::realft(V_forfft, -1, stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt]);
// do linear interpolation
// changed to sinc interpolation Dec 2020 by BAC
Tools::SincInterpolation(stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt], T_forfft, V_forfft, settings1->NFOUR / 2, T_forint, volts_forint);
stations[i].strings[j].antennas[k].Pol_factor.push_back(Pol_factor);
for (int n = 0; n < settings1->NFOUR / 2; n++)
{
if (settings1->TRIG_ANALYSIS_MODE != 2)
{
// not pure noise mode (we need signal)
stations[i].strings[j].antennas[k].V[ray_sol_cnt].push_back(volts_forint[n] *2. / (double)(stations[i].strings[j].antennas[k].Nnew[ray_sol_cnt])); // 2/N for inverse FFT normalization factor
}
else if (settings1->TRIG_ANALYSIS_MODE == 2)
{
// pure noise mode (set signal to 0)
stations[i].strings[j].antennas[k].V[ray_sol_cnt].push_back(0.);
}
}
}
else
{
// no signal generating
// initially give raysol has actual signal
stations[i].strings[j].antennas[k].SignalExt[ray_sol_cnt] = 0;
// if no signal, push_back 0 values (otherwise the value inside will remain as old value)
for (int n = 0; n < settings1->NFOUR / 2; n++)
{