From 51d357d3868ff52b0e6382224a8868b24c6087c2 Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Tue, 8 Jul 2025 14:37:50 -0500 Subject: [PATCH 01/12] Bringing Detector.cc and Detector.h in pair with new AraSim --- Detector.cc | 151 +++++++++++++++++++++++++++++++--------------------- Detector.h | 24 +++++++-- 2 files changed, 112 insertions(+), 63 deletions(-) diff --git a/Detector.cc b/Detector.cc index 81ac7f59..528903d2 100644 --- a/Detector.cc +++ b/Detector.cc @@ -2252,10 +2252,15 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ std::string VgainFile; std::string VgainTopFile; std::string HgainFile; - std::string TxgainFile; + std::string TxgainFile; + std::string TxgainFileCross; + std::string VgainCrossFile; + std::string VgainTopCrossFile; + std::string HgainCrossFile; //Adding step to read Tx gain. Will hardcode to PVA gain for now. - TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; + TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; + TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; if (settings1->ANTENNA_MODE == 0){ // use the orignal Vpol/Hpol gains @@ -2305,6 +2310,11 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_TVpol_RealizedGainAndPhase_Copol_Custom.txt"; HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Copol_Custom.txt"; } + + // Add cross-pol gain files + VgainCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; + VgainTopCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; //Should be TV but it's not working due to a negative SWR (first SWR entry) -ASG 12/09/24 + HgainCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; // Check for ALL_ANT_V_ON, then set all antennas to VPol if true if (settings1->ALL_ANT_V_ON == 1) { @@ -2318,12 +2328,18 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ freq_width = -1; freq_init = -1; - //Read in antenna gain files. + //Read in antenna co-pol gain files. ReadAntennaGain(VgainFile, settings1, eVPol); ReadAntennaGain(VgainTopFile, settings1, eVPolTop); ReadAntennaGain(HgainFile, settings1, eHPol); ReadAntennaGain(TxgainFile, settings1, eTx); + // Read cross-pol Rx gain files + ReadAntennaGain(VgainCrossFile, settings1, eVPolCross); + ReadAntennaGain(VgainTopCrossFile, settings1, eVPolTopCross); + ReadAntennaGain(HgainCrossFile, settings1, eHPolCross); + ReadAntennaGain(TxgainFileCross, settings1, eTxCross); + // update parameters to reflect what was read-in params.freq_step = freq_step; params.ang_step = ang_step; @@ -2375,30 +2391,45 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt // make sure dummy variables point to the right variables switch(type) { - case(eVPol) : - freq = &Freq; + case(eVPol): gain = &Vgain; phase = &Vphase; transAnt_databin = &transV_databin; break; - case(eVPolTop) : - freq = &Freq; + case(eVPolTop): gain = &VgainTop; phase = &VphaseTop; transAnt_databin = &transVTop_databin; break; - case(eHPol) : - freq = &Freq; + case(eHPol): gain = &Hgain; phase = &Hphase; transAnt_databin = &transH_databin; break; - case(eTx) : - freq = &TxFreq; + case(eVPolCross): // Cross-pol VPol + gain = &VgainCross; + phase = &VphaseCross; + transAnt_databin = &transVCross_databin; + break; + case(eVPolTopCross): // Cross-pol VPol Top + gain = &VgainTopCross; + phase = &VphaseTopCross; + transAnt_databin = &transVTopCross_databin; + break; + case(eHPolCross): // Cross-pol HPol + gain = &HgainCross; + phase = &HphaseCross; + transAnt_databin = &transHCross_databin; + break; + case(eTx): gain = &Txgain; phase = &Txphase; break; - default : + case(eTxCross): + gain = &TxgainCross; + phase = &TxphaseCross; + break; + default: throw runtime_error("Unknown antenna type!"); } @@ -2984,7 +3015,7 @@ double Detector::GetAntPhase( double freq, double theta, double phi, int ant_m ) } -double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int ant_m, int string_number, int ant_number, bool useInTransmitterMode) { +double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int ant_m, int string_number, int ant_number, bool useInTransmitterMode, bool useCrossPol) { /* The purpose of this function is to interpolate the globally defined gain arrays (Vgain, VgainTop, Hgain, Txgain) @@ -2998,48 +3029,48 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int //Assign local pointer to gain array specified in the function argument //VPol Rx - if ( Detector_mode == 5 ){ // Phased Array mode - if ( useInTransmitterMode ) { - tempGain = &Txgain; // Transmitter mode - } - else if ( ant_m == 1 ) { - tempGain = &Hgain; // PA Hpols - } - else { - if ( string_number == 0 ) { - tempGain = &Vgain; // PA Vpols - } + if (Detector_mode == 5) { // Phased Array mode + if (useInTransmitterMode) { + tempGain = useCrossPol ? &TxgainCross : &Txgain; // Transmitter mode + } + else if (ant_m == 1) { + tempGain = useCrossPol ? &HgainCross : &Hgain; // HPol + } + else { // VPol + if (string_number == 0) { + tempGain = useCrossPol ? &VgainCross : &Vgain; + } else { - if ( ant_number == 1 ) { - tempGain = &VgainTop; // A5 Top VPols - } - else { - tempGain = &Vgain; // A5 Bottom Vpols + if (ant_number == 1) { + tempGain = useCrossPol ? &VgainTopCross : &VgainTop; // A5 Top VPols + } + else { + tempGain = useCrossPol ? &VgainCross : &Vgain; // A5 Bottom VPols } } } } else { // Traditional Station mode - //Tx - if (useInTransmitterMode) { - tempGain = &Txgain; - } - else if (ant_m == 0) { - if (ant_number == 0) { - tempGain = &Vgain; - } - else if (ant_number == 2) { - tempGain = &VgainTop; + if (!useInTransmitterMode) { + if (ant_m == 0) { // VPol + if (ant_number == 0) { + tempGain = useCrossPol ? &VgainCross : &Vgain; + } + else if (ant_number == 2) { + tempGain = useCrossPol ? &VgainTopCross : &VgainTop; + } + } + else if (ant_m == 1) { // HPol + tempGain = useCrossPol ? &HgainCross : &Hgain; } } - //HPol Rx - else if (ant_m == 1) { - tempGain = &Hgain; - } - else { - throw runtime_error("In GetGain_1D_OutZero: No appropriate gain model for this simulation setup."); + else { // Tx mode + tempGain = useCrossPol ? &TxgainCross : &Txgain; } } + if (!tempGain) { + throw runtime_error("In GetGain_1D_OutZero: No appropriate gain model for this simulation setup."); + } double thisFreq_init; double thisFreq_width; @@ -3149,27 +3180,27 @@ double Detector::GetImpedance( double freq, int ant_m, int ant_number, bool useI } -double Detector::GetAntPhase_1D( double freq, double theta, double phi, int ant_m, bool useInTransmitterMode ) { +double Detector::GetAntPhase_1D( double freq, double theta, double phi, int ant_m, bool useInTransmitterMode, bool useCrossPol ) { //Creating tempPhase array to make this function more dynamic for Rx and Tx mode. vector > *tempPhase = nullptr; vector * F; - //Tx - if (useInTransmitterMode) { - tempPhase = &Txphase; - } - //VPol Rx - else if (ant_m == 0) { - tempPhase = &Vphase; - } - //HPol Rx - else if (ant_m == 1) { - tempPhase = &Hphase; + // Assign tempPhase based on polarization type and cross-pol flag + if (!useInTransmitterMode) { + if (ant_m == 0) { // VPol + tempPhase = useCrossPol ? &VphaseCross : &Vphase; + } + else if (ant_m == 1) { // HPol + tempPhase = useCrossPol ? &HphaseCross : &Hphase; + } + } + else { // Transmitter mode + tempPhase = useCrossPol ? &TxphaseCross : &Txphase; } - else { - throw runtime_error("In GetAntPhase_1D: No appropriate gain model for this simulation setup."); - } + if (!tempPhase) { + throw runtime_error("In GetAntPhase_1D: No appropriate phase model for this simulation setup."); + } double thisFreq_init; double thisFreq_width; diff --git a/Detector.h b/Detector.h index 450efcc5..638488e6 100644 --- a/Detector.h +++ b/Detector.h @@ -217,7 +217,11 @@ enum EAntennaType { eVPol, // (bottom) Vpol eVPolTop, // top Vpol eHPol, // Hpol - eTx // transmitter + eTx, // transmitter + eTxCross, // transmitter + eVPolCross, // Cross-pol VPol + eVPolTopCross, // Cross-pol VPol Top + eHPolCross // Cross-pol HPol }; class Detector { @@ -234,6 +238,14 @@ class Detector { vector > Hgain; vector > Hphase; vector Freq; + + // Cross-pol vectors + vector > VgainCross; + vector > VphaseCross; + vector > VgainTopCross; + vector > VphaseTopCross; + vector > HgainCross; + vector > HphaseCross; //Define impedance and gain for receiving antenna vector impFreq; @@ -252,6 +264,8 @@ class Detector { vector TxFreq; vector > Txgain; vector > Txphase; + vector > TxgainCross; + vector > TxphaseCross; void ReadImpedance(string filename, double (*TempRealImpedance)[freq_step_max], double (*TempImagImpedance)[freq_step_max]); void ReadAllAntennaImpedance(Settings *settings1); @@ -347,6 +361,10 @@ class Detector { vector transVTop_databin; vector transH_databin; + // Cross-pol data bins + std::vector transVCross_databin; + std::vector transVTopCross_databin; + std::vector transHCross_databin; void ReadAmplifierNoiseFigure(Settings *settings1); vector< vector > amplifierNoiseFig_ch; @@ -383,7 +401,7 @@ class Detector { double GetGain(double freq, double theta, double phi, int ant_m, int ant_o); //read antenna gain at certain angle, certain type, and certain orientation double GetGain(double freq, double theta, double phi, int ant_m); //read antenna gain at certain angle, certain type. (orientation : default) - double GetGain_1D_OutZero(double freq, double theta, double phi, int ant_m, int string_number=0, int ant_number=0, bool useInTransmitterMode=false); //read antenna gain at certain angle, certain type. (orientation : default) and use 1-D interpolation to get gain, if freq bigger than freq range, return 0 gain + double GetGain_1D_OutZero(double freq, double theta, double phi, int ant_m, int string_number=0, int ant_number=0, bool useInTransmitterMode=false, bool useCrossPol=false); //read antenna gain at certain angle, certain type. (orientation : default) and use 1-D interpolation to get gain, if freq bigger than freq range, return 0 gain //Creating function to interpolate antenna impedance to frequency binning. double GetImpedance(double freq, int ant_m=0, int ant_number=0, bool useInTransmitterMode=false); @@ -393,7 +411,7 @@ class Detector { double GetAntPhase(double freq, double theta, double phi, int ant_m); // return antenna phase with 2-D interpolation - double GetAntPhase_1D(double freq, double theta, double phi, int ant_m, bool useInTransmitterMode=false); // return antenna phase with 1-D interpolation + double GetAntPhase_1D(double freq, double theta, double phi, int ant_m, bool useInTransmitterMode=false, bool useCrossPol=false); // return antenna phase with 1-D interpolation double GetFilterGain(int bin) { return FilterGain[bin]; } // same bin with Vgain, Hgain From 68aa4816521ac0b077243eb8e917824232342c1d Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Tue, 8 Jul 2025 16:02:46 -0500 Subject: [PATCH 02/12] Bringing Report.h, Settings.cc, Settings.h in pair with new AraSim --- Report.h | 30 ++++++------- Settings.cc | 125 ++++++++++++++++++++++++++-------------------------- Settings.h | 2 + 3 files changed, 79 insertions(+), 78 deletions(-) diff --git a/Report.h b/Report.h index 15da338c..938de100 100644 --- a/Report.h +++ b/Report.h @@ -78,6 +78,8 @@ class Antenna_r { vector < vector < vector > > vmmhz; //! // signal V/m/MHz for each freq bin vector < vector < vector > > Heff; //! // effective height for each freq bin + vector < vector > Heff_copol; // effective height for each freq bin + vector < vector > Heff_crosspol; // effective height for each freq bin vector < vector > Mag; //! // magnification factor vector < vector > Fresnel; //! // Fresnel factor vector < vector > Pol_factor; //! // Polarization factor @@ -330,25 +332,21 @@ class Report { double heff, Vector &n_trg_pokey, Vector &n_trg_slappy, Vector &Pol_vector, int ant_type, double &pol_factor, double &vmmhz, double antenna_theta, double antenna_phi ); - void ApplyAntFactors_Tdomain( - double AntPhase, double heff, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, double antenna_theta, double antenna_phi, - double freq, bool useInTransmitterMode=false, bool applyInverse=false + void ApplyAntFactors_Tdomain(double phase_copol, double phase_crosspol, double heff_copol, double heff_crosspol, Vector &Pol_vector, + int ant_type, double &pol_factor, double &vm_real, double &vm_img, + Settings *settings1, double antenna_theta, double antenna_phi, double freq, + bool useInTransmitterMode=false, bool applyInverse=false ); - void ApplyAntFactors_Tdomain_FirstTwo ( - double heff, double heff_lastbin, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, double antenna_theta, double antenna_phi, - double freq, bool useInTransmitterMode=false, bool applyInverse=false + void ApplyAntFactors_Tdomain_FirstTwo(double heff_copol, double heff_copol_lastbin, double heff_crosspol, double heff_crosspol_lastbin, + Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, + Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode=false, + bool applyInverse=false ); - void InvertAntFactors_Tdomain( - double AntPhase, double heff, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, double antenna_theta, double antenna_phi, - double freq, bool useInTransmitterMode=false + void InvertAntFactors_Tdomain(double AntPhase_copol, double AntPhase_crosspol, double heff_copol, double heff_crosspol, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, double antenna_theta, + double antenna_phi, double freq, bool useInTransmitterMode=false ); - void InvertAntFactors_Tdomain_FirstTwo ( - double heff, double heff_lastbin, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, double antenna_theta, double antenna_phi, - double freq, bool useInTransmitterMode=false + void InvertAntFactors_Tdomain_FirstTwo(double heff_copol, double heff_copol_lastbin, double heff_crosspol, double heff_crosspol_lastbin, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, Settings *settings1, + double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode=false ); void ApplyElect_Tdomain(double freq, Detector *detector, double &vm_real, double &vm_img, int gain_ch_no, Settings *settings1, bool applyInverse=false); diff --git a/Settings.cc b/Settings.cc index 60bc9661..c53a5b06 100644 --- a/Settings.cc +++ b/Settings.cc @@ -324,7 +324,8 @@ outputdir="outputs"; // directory where outputs go // This setting is only used if DETECTOR > 3 && NOISE == 1 && CUSTOM_ELECTRONICS == 0 CLOCK_ANGLE=0; //Default: 0 -- Angle of polarization "on the clock". Angle of zero is pure thetaPol, whereas 90ยบ is pure phiPol. - + CROSSPOL_RX=0; //Default: 0 -- don't use cross-pol responses on receiving antennas + CROSSPOL_TX=0; //Default: 0 -- don't use cross-pol responses on transmitting antennas @@ -365,12 +366,12 @@ void Settings::ReadFile(string setupfile) { else if (label == "NOFZ") { NOFZ = atof( line.substr(line.find_first_of("=") + 1).c_str() ); } - else if (label == "BIREFRINGENCE"){ - BIREFRINGENCE = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "BIAXIAL"){ - BIAXIAL = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - } + else if (label == "BIREFRINGENCE"){ + BIREFRINGENCE = atof( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "BIAXIAL"){ + BIAXIAL = atof( line.substr(line.find_first_of("=") + 1).c_str() ); + } else if (label == "CONSTANTCRUST") { CONSTANTCRUST = atof( line.substr(line.find_first_of("=") + 1).c_str() ); } @@ -397,11 +398,11 @@ void Settings::ReadFile(string setupfile) { } else if (label == "DETECTOR_STATION") { DETECTOR_STATION = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - DETECTOR_STATION_ARAROOT = DETECTOR_STATION; - if (DETECTOR_STATION == 100) { - DETECTOR_STATION = 1; - DETECTOR_STATION_ARAROOT = 100; - } + DETECTOR_STATION_ARAROOT = DETECTOR_STATION; + if (DETECTOR_STATION == 100) { + DETECTOR_STATION = 1; + DETECTOR_STATION_ARAROOT = 100; + } } else if (label == "DETECTOR_STATION_LIVETIME_CONFIG") { DETECTOR_STATION_LIVETIME_CONFIG = atof( line.substr(line.find_first_of("=") + 1).c_str() ); @@ -456,7 +457,7 @@ void Settings::ReadFile(string setupfile) { } else if(label == "TRIG_SCAN_MODE"){ TRIG_SCAN_MODE = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); - } + } else if (label == "POWERTHRESHOLD") { POWERTHRESHOLD = atof( line.substr(line.find_first_of("=") + 1).c_str() ); } @@ -688,42 +689,39 @@ void Settings::ReadFile(string setupfile) { else if (label == "AVZ_NORM_FACTOR_MODE") { AVZ_NORM_FACTOR_MODE = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); } - else if (label == "number_of_stations") { - number_of_stations = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "RAY_TRACE_ICE_MODEL_PARAMS") { - RAY_TRACE_ICE_MODEL_PARAMS = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "WAVEFORM_LENGTH") { - WAVEFORM_LENGTH = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "WAVEFORM_CENTER") { - WAVEFORM_CENTER = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "DEADTIME") { - DEADTIME = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "POSNU_R") { - POSNU_R = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "POSNU_THETA") { - POSNU_THETA = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "POSNU_PHI") { - POSNU_PHI = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "ARBITRARY_EVENT_ATTENUATION") { - ARBITRARY_EVENT_ATTENUATION = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - } - else if (label == "PICK_ABOVE_HEIGHT") { - PICK_ABOVE_HEIGHT = atof( line.substr(line.find_first_of("=") + 1).c_str() ); - } + else if (label == "number_of_stations") { + number_of_stations = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "RAY_TRACE_ICE_MODEL_PARAMS") { + RAY_TRACE_ICE_MODEL_PARAMS = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "WAVEFORM_LENGTH") { + WAVEFORM_LENGTH = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "WAVEFORM_CENTER") { + WAVEFORM_CENTER = atoi( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "DEADTIME") { + DEADTIME = atof( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "POSNU_R") { + POSNU_R = atof( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "POSNU_THETA") { + POSNU_THETA = atof( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "POSNU_PHI") { + POSNU_PHI = atof( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "ARBITRARY_EVENT_ATTENUATION") { + ARBITRARY_EVENT_ATTENUATION = atof( line.substr(line.find_first_of("=") + 1).c_str() ); + } + else if (label == "PICK_ABOVE_HEIGHT") { + PICK_ABOVE_HEIGHT = atof( line.substr(line.find_first_of("=") + 1).c_str() ); + } else if (label == "EVENT_GENERATION_MODE"){ EVENT_GENERATION_MODE = atoi(line.substr(line.find_first_of("=") + 1).c_str()); } - // else if (label == "EVENT_NUM"){ - // EVENT_NUM = atoi(line.substr(line.find_first_of("=") + 1).c_str()); - // } else if (label == "ANTENNA_MODE"){ ANTENNA_MODE = atoi(line.substr(line.find_first_of("=") + 1).c_str()); } @@ -748,22 +746,25 @@ void Settings::ReadFile(string setupfile) { else if (label == "ELECTRONICS_ANTENNA_CONSISTENCY"){ ELECTRONICS_ANTENNA_CONSISTENCY = atoi(line.substr(line.find_first_of("=") + 1).c_str()); } - else if (label == "CLOCK_ANGLE"){ - CLOCK_ANGLE = atof(line.substr(line.find_first_of("=") + 1).c_str()); - } - //Adding source easting, northing, and depth for INTERACTION_MODE=5. - else if (label == "SOURCE_LATITUDE"){ - SOURCE_LATITUDE = atof(line.substr(line.find_first_of("=") + 1).c_str()); - } - else if (label == "SOURCE_LONGITUDE"){ - SOURCE_LONGITUDE = atof(line.substr(line.find_first_of("=") + 1).c_str()); - } - else if (label == "SOURCE_DEPTH"){ - SOURCE_DEPTH = atof(line.substr(line.find_first_of("=") + 1).c_str()); - } - - - + else if (label == "CLOCK_ANGLE"){ + CLOCK_ANGLE = atof(line.substr(line.find_first_of("=") + 1).c_str()); + } + //Adding source easting, northing, and depth for INTERACTION_MODE=5. + else if (label == "SOURCE_LATITUDE"){ + SOURCE_LATITUDE = atof(line.substr(line.find_first_of("=") + 1).c_str()); + } + else if (label == "SOURCE_LONGITUDE"){ + SOURCE_LONGITUDE = atof(line.substr(line.find_first_of("=") + 1).c_str()); + } + else if (label == "SOURCE_DEPTH"){ + SOURCE_DEPTH = atof(line.substr(line.find_first_of("=") + 1).c_str()); + } + else if (label == "CROSSPOL_RX"){ + CROSSPOL_RX = atof(line.substr(line.find_first_of("=") + 1).c_str()); + } + else if (label == "CROSSPOL_TX"){ + CROSSPOL_TX = atof(line.substr(line.find_first_of("=") + 1).c_str()); + } } } diff --git a/Settings.h b/Settings.h index cf46fec5..cd952465 100644 --- a/Settings.h +++ b/Settings.h @@ -347,6 +347,8 @@ class Settings // This setting is only used if DETECTOR > 3 && NOISE == 1 && CUSTOM_ELECTRONICS == 0 double CLOCK_ANGLE; // default: 0; Angle of polarization "on the clock" for use in pulser events (EVENT_TYPE=11) + int CROSSPOL_RX=0; //Default: 0 -- don't use cross-pol responses on receiving antennas + int CROSSPOL_TX=0; //Default: 0 -- don't use cross-pol responses on transmitting antennas From 337449853275eadab21df85adae812a06ffd2efc Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Wed, 9 Jul 2025 11:22:00 -0500 Subject: [PATCH 03/12] Adding ApplyAnt.. and InvertApplyAnt... functions for cross pol, while keeping the original, via function oevrloading --- Report.cc | 2021 ++++++++++++++++++++++++++++------------------------- Report.h | 28 +- 2 files changed, 1104 insertions(+), 945 deletions(-) diff --git a/Report.cc b/Report.cc index b64af0a7..f44986cf 100644 --- a/Report.cc +++ b/Report.cc @@ -36,7 +36,7 @@ Report::Report(Detector *detector, Settings *settings1) { // Default constructor Initialize(detector, settings1); - + } @@ -65,7 +65,7 @@ void Report::delete_all() { } void Report::Initialize(Detector *detector, Settings *settings1) { - + // Clear information stored in this object (but there shouldn't be. just to make sure) delete_all(); @@ -85,61 +85,61 @@ void Report::Initialize(Detector *detector, Settings *settings1) { stations[i].strings.push_back(tmp_string); // vector antennas - for (int k=0; kstations[i].strings[j].antennas.size(); k++) + for (int k=0; kstations[i].strings[j].antennas.size(); k++) stations[i].strings[j].antennas.push_back(tmp_antenna); } - + // vector surface antennas - for (int j=0; jstations[i].surfaces.size(); j++) + for (int j=0; jstations[i].surfaces.size(); j++) stations[i].surfaces.push_back(tmp_surface); if(settings1->TRIG_SCAN_MODE>0){// scan Pthresh mode - int numChan=0; + int numChan=0; int numChanVpol=0; int numChanHpol=0; - + for(int j=0;jstations[i].strings.size(); j++){ - + for (int k=0;kstations[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) + + 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) + + 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;chTRIG_MODE==0) { - for(int ch=0;chTRIG_MODE==1) { - for(int ch=0;chTRIG_MODE==1) { + for(int ch=0;chTRIG_MODE==1) { - for(int ch=0;chDATA_SAVE_MODE >= 1) { - + // Clear EM signal and waveform data for each interaction and ray vmmhz.clear(); Heff.clear(); + Heff_copol.clear(); + Heff_crosspol.clear(); Vfft.clear(); Vfft_noise.clear(); V.clear(); @@ -296,143 +302,143 @@ void Antenna_r::clear_useless(Settings *settings1) { // Remove final waveform data and ray path data if (settings1->DATA_SAVE_MODE >= 2) { - + //! clear the ray step to reduce the size of output AraOut.root - ray_step.clear(); - + ray_step.clear(); + // clear global trigger waveform info also time.clear(); time_mimic.clear(); V_mimic.clear(); - + } return; } - + int CircularBuffer::add(double input_value){ changelog=0; temp_value=best_value; - - if(buffer[i]1) + if(mode>1) last_value=buffer[i]; // in mode 1 we don't care about the values, just about the addToNPass - + if(input_value1 && buffer[i]1 && buffer[i]1 && std::fabs(last_value-best_value)1 && std::fabs(last_value-best_value)1: return value is zero if no changes, + + return changelog; + // in mode>1: return value is zero if no changes, // and non-zero if there are changes to best_value (for mode==1 it's always zero); - -}// add + +}// add int CircularBuffer::fill(double input_value){// buffer is just filling, don't use last_value - + changelog=0; temp_value=best_value; - + if(input_value1&&buffer[i]DATA_SAVE_MODE != 0) { @@ -451,11 +457,11 @@ void Report::clear_useless(Settings *settings1) { void Report::CalculateSignals( - int debugmode, - Birefringence *birefringence, Detector *detector, Event *event, + int debugmode, + Birefringence *birefringence, Detector *detector, Event *event, IceModel *icemodel, RaySolver *raysolver, Settings *settings1, Signal *signal ){ - // For each each station, perform the ray tracing from each cascade to each antenna + // For each each station, perform the ray tracing from each cascade to each antenna // and determine the voltage readout in the antenna for each connected ray double RandomTshift = gRandom->Rndm(); // for t-domain signal, a factor for random init time shift @@ -473,7 +479,7 @@ void Report::CalculateSignals( // Loop over strings on this station for (int j = 0; j < detector->stations[i].strings.size(); j++) { - + // Create the array used for interpolation double init_T = settings1->TIMESTEP *-1.e9 *((double) settings1->NFOUR / 4 + RandomTshift); // locate zero time at the middle and give random time shift double T_forint[settings1->NFOUR / 2]; @@ -489,7 +495,7 @@ void Report::CalculateSignals( // Loop over interactions in this event for (int interaction_idx=0; interaction_idxNu_Interaction.size(); interaction_idx++) { - // Perform the ray tracing between this interaction (interaction_idx) + // Perform the ray tracing between this interaction (interaction_idx) // and the antenna (k) then calculate the voltage response in the antenna int ray_sol_cnt = 0; @@ -497,14 +503,14 @@ void Report::CalculateSignals( // Check that the event is in a valid location and close enough to the antenna before raytracing if ( event->Nu_Interaction[interaction_idx].pickposnu && // If the event location is in Antarctic Ice - event->Nu_Interaction[interaction_idx].posnu.Distance(detector->stations[i].strings[j].antennas[k]) <= settings1->RAYSOL_RANGE + event->Nu_Interaction[interaction_idx].posnu.Distance(detector->stations[i].strings[j].antennas[k]) <= settings1->RAYSOL_RANGE // If the event is closer to the antenna than the user-defined maximum distance for ray tracing (settings1->RAYSOL_RANGE) ) { // Clear and calculate all ray solutions between the cascade and antenna RayStep.clear(); raysolver->Solve_Ray( - event->Nu_Interaction[interaction_idx].posnu, detector->stations[i].strings[j].antennas[k], + event->Nu_Interaction[interaction_idx].posnu, detector->stations[i].strings[j].antennas[k], icemodel, ray_output, settings1, RayStep ); @@ -518,23 +524,23 @@ void Report::CalculateSignals( // attenuation factors, antenna viewing angles, polarization, etc ModelRay( ray_sol_cnt, ray_output, interaction_idx, T_forint, - &stations[i].strings[j].antennas[k], + &stations[i].strings[j].antennas[k], &detector->stations[i].strings[j].antennas[k], - i, j, k, debugmode, + i, j, k, debugmode, birefringence, detector, event, icemodel, settings1, signal ); // check max_PeakV if ( debugmode == 0){ - if (max_PeakV_tmp < stations[i].strings[j].antennas[k].PeakV[interaction_idx][ray_sol_cnt]) + if (max_PeakV_tmp < stations[i].strings[j].antennas[k].PeakV[interaction_idx][ray_sol_cnt]) max_PeakV_tmp = stations[i].strings[j].antennas[k].PeakV[interaction_idx][ray_sol_cnt]; } // check min_arrival_time - if (min_arrival_time_tmp > stations[i].strings[j].antennas[k].arrival_time[interaction_idx][ray_sol_cnt]) + if (min_arrival_time_tmp > stations[i].strings[j].antennas[k].arrival_time[interaction_idx][ray_sol_cnt]) min_arrival_time_tmp = stations[i].strings[j].antennas[k].arrival_time[interaction_idx][ray_sol_cnt]; // check max_arrival_time - if (max_arrival_time_tmp < stations[i].strings[j].antennas[k].arrival_time[interaction_idx][ray_sol_cnt]) + if (max_arrival_time_tmp < stations[i].strings[j].antennas[k].arrival_time[interaction_idx][ray_sol_cnt]) max_arrival_time_tmp = stations[i].strings[j].antennas[k].arrival_time[interaction_idx][ray_sol_cnt]; ray_sol_cnt++; @@ -566,7 +572,7 @@ void Report::CalculateSignals( stations[i].max_PeakV = max_PeakV_tmp; } // for number_of_stations - // If the simulation is not in debug mode, set ranking of signal between + // If the simulation is not in debug mode, set ranking of signal between // antennas after all values are stored in Report if (debugmode == 0){ SetRank(detector); @@ -576,7 +582,7 @@ void Report::CalculateSignals( } void Report::BuildAndTriggerOnWaveforms( - int debugmode, int station_index, int evt, int trig_search_init, + int debugmode, int station_index, int evt, int trig_search_init, Detector *detector, Event *event, Settings *settings1, Trigger *trigger ){ // Loop over all antennas to make DATA_BIN_SIZE array for signal + noise. (with time delay) @@ -587,19 +593,19 @@ void Report::BuildAndTriggerOnWaveforms( // Reinitialize it back to 0 stations[station_index].Global_Pass = 0; - // If we're looking to trigger on signal, check that there - // is enough signal that reached the station. + // If we're looking to trigger on signal, check that there + // is enough signal that reached the station. // Otherwise, don't worry about checking for a trigger int ants_with_nonzero_signal = 0; - if (settings1->TRIG_ANALYSIS_MODE == 2) { - // TRIG_ANALYSIS_MODE=2 is the noise-only mode, + if (settings1->TRIG_ANALYSIS_MODE == 2) { + // TRIG_ANALYSIS_MODE=2 is the noise-only mode, // say that all antennas have good signal - ants_with_nonzero_signal = 16; + ants_with_nonzero_signal = 16; } else { - // If rays connected to the station, count how many antennas + // If rays connected to the station, count how many antennas // have sufficient signal from the signal-only waveform - if (stations[station_index].Total_ray_sol) + if (stations[station_index].Total_ray_sol) ants_with_nonzero_signal = getNumOfSignalledAnts(stations[station_index]); } @@ -613,19 +619,19 @@ void Report::BuildAndTriggerOnWaveforms( // we define the size of a signal as BINSIZE = NFOUR/2 later in the code // there could be two ray solutions in an interaction. We add 2*BINSIZE = NFOUR for safety int max_total_bin = ( - (stations[station_index].max_arrival_time - stations[station_index].min_arrival_time) + (stations[station_index].max_arrival_time - stations[station_index].min_arrival_time) / settings1->TIMESTEP) + settings1->NFOUR; - + // Compute next power of two larger than max_total_bin max_total_bin = (int)std::pow(2, std::ceil(std::log2(max_total_bin))); - - //Analyze more bins for historically unspecified reasons. + + //Analyze more bins for historically unspecified reasons. //Could be to adjust for an offset in indexing and signals that come after the last event temporally //However AraSim may break without this extra padding, so adjust carefully //This offset is probably to account for offset between indices of V_convolved and V_signal in GetNoiseThenConvolve() max_total_bin += settings1->NFOUR *3 + trigger->maxt_diode_bin; - // Decide if new noise waveforms will be generated for every new event. + // Decide if new noise waveforms will be generated for every new event. // Otherwise, the same noise waveforms will be used for the entire simulation run. if (settings1->NOISE_WAVEFORM_GENERATE_MODE == 0) { // Generate brand new noise waveforms for each event @@ -635,9 +641,9 @@ void Report::BuildAndTriggerOnWaveforms( int DBS = 10; // Starting power of 2 while (true) { DATA_BIN_SIZE_tmp = (int) pow(2., (double) DBS); - if (DATA_BIN_SIZE_tmp > max_total_bin) + if (DATA_BIN_SIZE_tmp > max_total_bin) break; // Exit the loop if the size exceeds max_total_bin - + DBS++; // Increment DBS for the next power of 2 } settings1->DATA_BIN_SIZE = DATA_BIN_SIZE_tmp; @@ -672,8 +678,8 @@ void Report::BuildAndTriggerOnWaveforms( } - // If the simulation is not in debug mode, check if DATA_BIN_SIZE is large - // enough for the total time delay between antennas via this N_noise + // If the simulation is not in debug mode, check if DATA_BIN_SIZE is large + // enough for the total time delay between antennas via this N_noise // variable. It should evaluate to 1 in most cases. if (debugmode == 1) { N_noise = 1; @@ -685,9 +691,9 @@ void Report::BuildAndTriggerOnWaveforms( cout << "N_noise : " << N_noise << " max_total_bin : " << max_total_bin << " might cause error!!" << endl; } - // For all antennas on all strings, get the noise waveform and combine - // it with the signal waveforms from all connected rays then convolve the - // full waveform through the tunnel diode. + // For all antennas on all strings, get the noise waveform and combine + // it with the signal waveforms from all connected rays then convolve the + // full waveform through the tunnel diode. int ch_ID = 0; int ants_with_sufficient_SNR = 0; for (int j = 0; j < detector->stations[station_index].strings.size(); j++) @@ -701,12 +707,12 @@ void Report::BuildAndTriggerOnWaveforms( // Fill trigger->Full_window and trigger->Full_window_V with noise waveforms Prepare_Antenna_Noise(debugmode, ch_ID, station_index, j, k, settings1, trigger, detector); - // currently there is a initial spoiled bins (maxt_diode_bin) - // at the initial Full_window "AND" at the initial of connected noisewaveform + // currently there is a initial spoiled bins (maxt_diode_bin) + // at the initial Full_window "AND" at the initial of connected noisewaveform // (we can fix this by adding values but not accomplished yet) // If the simulation is not in debug mode, combine the voltage response - // from all rays into a single vector, add the noise waveform, + // from all rays into a single vector, add the noise waveform, // and convolve this complete waveform with the tunnel diode. if (debugmode == 0) { Convolve_Signals( @@ -724,8 +730,8 @@ void Report::BuildAndTriggerOnWaveforms( ant_SNR = 100.; else { - // Use the noise RMS from the trigger class and pass - // it as the noise WF to get_SNR() (since the RMS of an + // Use the noise RMS from the trigger class and pass + // it as the noise WF to get_SNR() (since the RMS of an // array with one element is the absolute value of that element) vector tmp_noise_RMS; int trigger_ch_ID = GetChNumFromArbChID(detector, ch_ID, station_index, settings1) - 1; @@ -733,14 +739,14 @@ void Report::BuildAndTriggerOnWaveforms( tmp_noise_RMS.push_back( ant_noise_voltage_RMS ); // Calculate the SNR in this antenna from the signal only - ant_SNR = get_SNR( - stations[station_index].strings[j].antennas[k].V_convolved, + ant_SNR = get_SNR( + stations[station_index].strings[j].antennas[k].V_convolved, tmp_noise_RMS); } // Log if this antenna has a decent signal-only SNR or not. - if ( ant_SNR > 0.01 ) + if ( ant_SNR > 0.01 ) ants_with_sufficient_SNR++; // Apply gain factors @@ -755,16 +761,16 @@ void Report::BuildAndTriggerOnWaveforms( // Check for a trigger on this event // Do only if it's not in debugmode and if at least 1 antenna has sufficient signal - // Previously, events with very low neutrino signals were triggering on + // Previously, events with very low neutrino signals were triggering on // noise and inflating effective volume calculations. By skipping // events with insufficient signal in all antennas, we reduce - // contributions from noise-only triggered events in our effective - // volume calculations which require a pure sample of signal-only - // triggered events. + // contributions from noise-only triggered events in our effective + // volume calculations which require a pure sample of signal-only + // triggered events. if ( (debugmode == 0) && (ants_with_sufficient_SNR) ) { // coincidence window bin for trigger - int trig_window_bin = (int)(settings1->TRIG_WINDOW / settings1->TIMESTEP); + int trig_window_bin = (int)(settings1->TRIG_WINDOW / settings1->TIMESTEP); // save trig search bin info default (if no global trig, this value saved) stations[station_index].total_trig_search_bin = max_total_bin - trig_search_init; @@ -772,7 +778,7 @@ void Report::BuildAndTriggerOnWaveforms( if (settings1->TRIG_SCAN_MODE==5) { // Trigger mode for phased array checkPATrigger( - station_index, detector, event, evt, trigger, settings1, + station_index, detector, event, evt, trigger, settings1, trig_search_init, max_total_bin ); } @@ -784,19 +790,19 @@ void Report::BuildAndTriggerOnWaveforms( ); } else if (settings1->TRIG_SCAN_MODE > 0) { - // Newer trigger check loops that use the Circular Buffer and - // save some extra information. More information in log.txt. + // Newer trigger check loops that use the Circular Buffer and + // save some extra information. More information in log.txt. triggerCheckLoop( - settings1, detector, event, trigger, - station_index, trig_search_init, max_total_bin, trig_window_bin, + settings1, detector, event, trigger, + station_index, trig_search_init, max_total_bin, trig_window_bin, settings1->TRIG_SCAN_MODE ); } } // if it's not debugmode - // delete noise waveforms - if (settings1->NOISE_WAVEFORM_GENERATE_MODE == 0) + // delete noise waveforms + if (settings1->NOISE_WAVEFORM_GENERATE_MODE == 0) // noise waveforms will be generated for each evts // remove noise waveforms for next evt trigger->ClearNoiseWaveforms(); @@ -815,15 +821,15 @@ void Report::BuildAndTriggerOnWaveforms( // Calculate the next bin that could be checked for a trigger based on this antenna's trigger bin int this_next_trig_search_init = ( stations[station_index].Global_Pass // trigger bin in V_convolved - + (settings1->WAVEFORM_LENGTH - stations[station_index].strings[string].antennas[antenna].global_trig_bin) - // number of bins between trigger bin and end of readout window. + + (settings1->WAVEFORM_LENGTH - stations[station_index].strings[string].antennas[antenna].global_trig_bin) + // number of bins between trigger bin and end of readout window. // Sometimes includes channel-specific delays + settings1->DEADTIME/settings1->TIMESTEP // deadtime in units of bins - ); + ); - // Save this antenna's "next initial trigger bin" as the whole station's - // "next initial trigger bin" if it's larger than what was previously saved - if (this_next_trig_search_init > stations[station_index].next_trig_search_init) + // Save this antenna's "next initial trigger bin" as the whole station's + // "next initial trigger bin" if it's larger than what was previously saved + if (this_next_trig_search_init > stations[station_index].next_trig_search_init) stations[station_index].next_trig_search_init = this_next_trig_search_init; } } @@ -832,7 +838,7 @@ void Report::BuildAndTriggerOnWaveforms( for (int antenna=0; antenna-1; bin--) { @@ -842,7 +848,7 @@ void Report::BuildAndTriggerOnWaveforms( } } - // If there is signal that exists later than what would be the next trig_search_init, + // If there is signal that exists later than what would be the next trig_search_init, // indicate that we need to analyze more signal. if ( last_nonzero_bin > stations[station_index].next_trig_search_init ) analyze_more_waveform = true; @@ -852,7 +858,7 @@ void Report::BuildAndTriggerOnWaveforms( // If we have no waveform left to analyze, reset the `next_trig_search_init` to `-1` // to indicate that there's nothing to trigger check after reading out this event so far. - if ( !analyze_more_waveform ) + if ( !analyze_more_waveform ) stations[station_index].next_trig_search_init = -1; } @@ -860,7 +866,7 @@ void Report::BuildAndTriggerOnWaveforms( } void Antenna_r::Find_Likely_Sol(){ - // Estimate which interaction and which ray from said interaction triggered + // Estimate which interaction and which ray from said interaction triggered // the detector based on the timing between the bin that triggered and the // SignalBin of each ray from each simulated cascade. @@ -889,11 +895,11 @@ void Antenna_r::Find_Likely_Sol(){ void Antenna_r::Get_Brightest_Interaction(int (*brightest_event)[2]){ // Determine which interaction and which ray from that interaction yielded - // the highest voltage response in this antenna. - + // the highest voltage response in this antenna. + brightest_event[0][0] = -1; brightest_event[0][1] = -1; - double maxV = -1; + double maxV = -1; for (int interaction_idx=0; interaction_idx > ray_output, int interaction_idx, double *T_forint, - Antenna_r *antenna_r, Antenna *antenna_d, int i, int j, int k, - int debugmode, Birefringence *birefringence, Detector *detector, + int ray_idx, vector< vector< double > > ray_output, int interaction_idx, double *T_forint, + Antenna_r *antenna_r, Antenna *antenna_d, int i, int j, int k, + int debugmode, Birefringence *birefringence, Detector *detector, Event *event, IceModel *icemodel, Settings *settings, Signal *signal ){ // Get the voltage response in an antenna along one ray path from a cascade by // - Calculating the electric field signal at the cascade - // - Transforming that into the signal at the antenna by modifying the + // - Transforming that into the signal at the antenna by modifying the // field according to attenuation, fresnel, etc along the ray path - // - Convolving the signal at the antenna with the antenna's effective height, + // - Convolving the signal at the antenna with the antenna's effective height, // gain, and other parameters to obtain the voltage response to the cascade - // This (gain_ch_no) is used for per-channel gain implementation. + // This (gain_ch_no) is used for per-channel gain implementation. // It is used in all instances of ApplyElect_Tdomain() and ApplyElect_Tdomain_FirstTwo(), to indicate channel number - // Note that channel numbering is different for DETECTOR==4 than for the other modes (1-3). See that in the definition of GetChannelfromStringAntenna() + // Note that channel numbering is different for DETECTOR==4 than for the other modes (1-3). See that in the definition of GetChannelfromStringAntenna() int gain_ch_no; if (settings->DETECTOR==4 || settings->DETECTOR==5) { gain_ch_no = detector->GetChannelfromStringAntenna (i, j, k, settings)-1; @@ -934,13 +940,13 @@ void Report::ModelRay( } double time_diff_birefringence = birefringence->Time_Diff_TwoRays( - RayStep[ray_idx][0], RayStep[ray_idx][1], ray_output[3][ray_idx], + RayStep[ray_idx][0], RayStep[ray_idx][1], ray_output[3][ray_idx], event->Nu_Interaction[interaction_idx].posnu_from_antcen, settings - ); // calculate time differences for birefringence + ); // calculate time differences for birefringence antenna_r->arrival_time[interaction_idx].push_back(ray_output[4][ray_idx] + event->interactions_birth_time[interaction_idx]); - //! Save every ray steps between the vertex (source) and an antenna (target), unless DATA_SAVE_MODE is 2. + //! Save every ray steps between the vertex (source) and an antenna (target), unless DATA_SAVE_MODE is 2. //! These xz coordinates were calculated after we convert the earth coordinates to flat coordinates by the RaySolver::Earth_to_Flat_same_angle() antenna_r->ray_step[interaction_idx].resize(ray_idx + 1); ///< resize by number of ray solutions antenna_r->ray_step[interaction_idx][ray_idx].resize(2); ///< resize by xz values @@ -960,13 +966,13 @@ void Report::ModelRay( dz = RayStep[ray_idx][1][steps - 1] - RayStep[ray_idx][1][steps]; dl = sqrt((dx *dx) + (dz *dz)); - // Skipping attenuation calculation when the distance between two RaySteps is 0. + // Skipping attenuation calculation when the distance between two RaySteps is 0. // PrevenTing adds -nan into the IceAttenFactor. 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 + // use the midpoint of the array to calculate the attenuation length, instead of the end of the ray IceAttenFactor *= ( - exp(-dl / icemodel->GetARAIceAttenuLength(-RayStep[ray_idx][1][steps])) + + exp(-dl / icemodel->GetARAIceAttenuLength(-RayStep[ray_idx][1][steps])) + exp(-dl / icemodel->GetARAIceAttenuLength(-RayStep[ray_idx][1][steps - 1])) ) / 2; } @@ -990,9 +996,9 @@ void Report::ModelRay( antenna_r, antenna_d, event->Nu_Interaction[interaction_idx], interaction_idx, i, j, k, ray_idx, ray_output, &n_trg_pokey, &n_trg_slappy, &Pol_vector_src, - &launch_vector, &receive_vector, + &launch_vector, &receive_vector, icemodel, settings - ); + ); double viewangle = antenna_r->view_ang[interaction_idx][ray_idx]; double mag = antenna_r->Mag[interaction_idx][ray_idx]; @@ -1001,9 +1007,9 @@ void Report::ModelRay( double antenna_phi = antenna_r->phi_rec[interaction_idx][ray_idx] * 180 / PI; Vector Pol_vector = antenna_r->Pol_vector[interaction_idx][ray_idx]; - double vmmhz1m_tmp = 0; - double vmmhz1m_sum = 0; - double vmmhz1m_em = 0; + double vmmhz1m_tmp = 0; + double vmmhz1m_sum = 0; + double vmmhz1m_em = 0; // old freq domain signal mode (AVZ model) if (settings->SIMULATION_MODE == 0) { @@ -1015,8 +1021,8 @@ void Report::ModelRay( double Pol_factor = 0; - // In frequency space, modify the signal from the cascade according - // to the ice attenuation, the antennas effective height, + // In frequency space, modify the signal from the cascade according + // to the ice attenuation, the antennas effective height, // the antenna's Filter, the Preamplifiers, and the FOAM for (int l = 0; l < detector->GetFreqBin(); l++) { // for detector freq bin numbers @@ -1026,11 +1032,11 @@ void Report::ModelRay( else { vmmhz1m_tmp = event->Nu_Interaction[interaction_idx].vmmhz1m[l]; signal->TaperVmMHz( - viewangle, - event->Nu_Interaction[interaction_idx].d_theta_em[l], - event->Nu_Interaction[interaction_idx].d_theta_had[l], - event->Nu_Interaction[interaction_idx].emfrac, - event->Nu_Interaction[interaction_idx].hadfrac, + viewangle, + event->Nu_Interaction[interaction_idx].d_theta_em[l], + event->Nu_Interaction[interaction_idx].d_theta_had[l], + event->Nu_Interaction[interaction_idx].emfrac, + event->Nu_Interaction[interaction_idx].hadfrac, vmmhz1m_tmp, vmmhz1m_em); } @@ -1048,7 +1054,7 @@ void Report::ModelRay( dz = RayStep[ray_idx][1][steps - 1] - RayStep[ray_idx][1][steps]; dl = sqrt((dx *dx) + (dz *dz)); - // Skipping attenuation calculation when the distance between two RaySteps is 0. + // Skipping attenuation calculation when the distance between two RaySteps is 0. // Prevening adds -nan into the IceAttenFactor. if (dl > 0) { @@ -1058,7 +1064,7 @@ void Report::ModelRay( ) / 2.; // 1e9 to convert to GHz } } - + // assume whichray = 0, now vmmhz1m_tmp has all factors except for the detector properties (antenna gain, etc) vmmhz1m_tmp = vmmhz1m_tmp / ray_output[0][ray_idx] *IceAttenFactor *mag * fresnel; @@ -1073,11 +1079,11 @@ void Report::ModelRay( // Get ant gain with 2-D interpolation double heff = GaintoHeight( detector->GetGain_1D_OutZero( - freq_tmp *1.E-6, antenna_theta, antenna_phi, + freq_tmp *1.E-6, antenna_theta, antenna_phi, antenna_d->type, j, k), - freq_tmp, + freq_tmp, icemodel->GetN(*antenna_d), - detector->GetImpedance(freq_tmp*1.E-6, antenna_d->type, j, k)); + detector->GetImpedance(freq_tmp*1.E-6, antenna_d->type, j, k)); antenna_r->Heff[interaction_idx][ray_idx].push_back(heff); @@ -1096,14 +1102,14 @@ void Report::ModelRay( } ApplyAntFactors( - heff, n_trg_pokey, n_trg_slappy, Pol_vector, antenna_d->type, + heff, n_trg_pokey, n_trg_slappy, Pol_vector, antenna_d->type, Pol_factor, vmmhz1m_tmp, antenna_theta, antenna_phi); ApplyFilter_OutZero(freq_tmp, detector, vmmhz1m_tmp); ApplyPreamp_OutZero(freq_tmp, detector, vmmhz1m_tmp); ApplyFOAM_OutZero(freq_tmp, detector, vmmhz1m_tmp); vmmhz_filter[l] = vmmhz1m_tmp; - + } // end for freq bin antenna_r->Pol_factor[interaction_idx].push_back(Pol_factor); @@ -1140,7 +1146,7 @@ void Report::ModelRay( // if event is not calpulser if (event->IsCalpulser == 0) { - if (settings->EVENT_TYPE == 0) { + if (settings->EVENT_TYPE == 0) { // Get the signal from Neutrino events // see if integrated shower profile LQ is non-zero and near the cone viewangle @@ -1149,7 +1155,7 @@ void Report::ModelRay( double atten_factor = 0.; if (settings->USE_ARA_ICEATTENU == 1 || settings->USE_ARA_ICEATTENU == 0) { - atten_factor = 1. / ray_output[0][ray_idx] *IceAttenFactor *mag * fresnel; + atten_factor = 1. / ray_output[0][ray_idx] *IceAttenFactor *mag * fresnel; } else if (settings->USE_ARA_ICEATTENU == 2) { atten_factor = 1. / ray_output[0][ray_idx] *mag * fresnel; //apply freq dependent IceAttenFactor later @@ -1159,11 +1165,11 @@ void Report::ModelRay( double Tarray[outbin]; double Earray[outbin]; signal->GetVm_FarField_Tarray( - event, settings, viewangle, atten_factor, outbin, Tarray, Earray, + event, settings, viewangle, atten_factor, outbin, Tarray, Earray, antenna_r->skip_bins[ray_idx], interaction_idx); double dT_forfft = Tarray[1] - Tarray[0]; // step in ns - + // Determine the number of bins that will be used to build the waveform that will be fourier transformed DetermineWFBins(antenna_r, interaction_idx, ray_idx, dT_forfft, settings); @@ -1177,9 +1183,9 @@ void Report::ModelRay( Earray_vector.push_back( Earray[bin] ); } - PropagateSignal( + PropagateSignal( dT_forfft, outbin, Tarray_vector, Earray_vector, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); @@ -1205,7 +1211,7 @@ void Report::ModelRay( antenna_r->PeakV[interaction_idx].push_back(0.); } - + } // neutrino events else if (settings->EVENT_TYPE == 10) { // Get the signal from Arbitrary Events @@ -1228,7 +1234,7 @@ void Report::ModelRay( PropagateSignal( dT_forfft, waveform_bin, ArbitraryWaveform_T_vector, ArbitraryWaveform_V_vector, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); @@ -1247,13 +1253,13 @@ void Report::ModelRay( double psi = TMath::DegToRad()*settings->CLOCK_ANGLE; double theta = acos(launch_vector[2]); double phi = atan2(launch_vector[1],launch_vector[0]); - + //Justin's method double newPol_vectorX = -cos(psi)*cos(theta)*cos(phi) + sin(psi)*sin(phi); double newPol_vectorY = -cos(psi)*cos(theta)*sin(phi) - sin(psi)*cos(phi); double newPol_vectorZ = cos(psi)*sin(theta); Vector Pol_vector = Vector(newPol_vectorX, newPol_vectorY, newPol_vectorZ); - + icemodel->GetFresnel( ray_output[1][ray_idx], // launch_angle ray_output[2][ray_idx], // rec_angle @@ -1265,7 +1271,7 @@ void Report::ModelRay( fresnel, Pol_vector); // input src Pol and return Pol at trg icemodel->GetMag( - mag, + mag, ray_output[0][ray_idx], // ray path length ray_output[1][ray_idx], // zenith angle of ray at launch ray_output[2][ray_idx], // zenith angle of ray upon receipt @@ -1278,19 +1284,19 @@ void Report::ModelRay( PropagateSignal( dT_forfft, waveform_bin, signal->PulserWaveform_T, signal->PulserWaveform_V, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); } // Simple Pulser Simulation - - // PVA pulser simulation. Separate from previous pulser event type to avoid breaking things. + + // PVA pulser simulation. Separate from previous pulser event type to avoid breaking things. else if (settings->EVENT_TYPE == 12) { // Get the signal from PVA Pulser events // Import Voltage versus time fed into antenna (via data from Alisa in IDL2_InputVoltageVersusTime.txt) - + int waveform_bin = (int) signal->InputVoltage_V.size(); double dT_forfft = signal->InputVoltage_T[1] - signal->InputVoltage_T[0]; // step in ns @@ -1300,17 +1306,17 @@ void Report::ModelRay( //Defining polarization at the source (using launch_vector (a unit vector)) // double psi = TMath::DegToRad()*settings->CLOCK_ANGLE; double psi = 0; // In the absence of cross-pol, the polarization angle is nominally zero for - // an antenna in the ice that is azimuthally symmetric. + // an antenna in the ice that is azimuthally symmetric. // Cross pol psi is updated after emission from a Tx double theta = acos(launch_vector[2]); double phi = atan2(launch_vector[1],launch_vector[0]); - + //Justin's method double newPol_vectorX = -cos(psi)*cos(theta)*cos(phi) + sin(psi)*sin(phi); double newPol_vectorY = -cos(psi)*cos(theta)*sin(phi) - sin(psi)*cos(phi); double newPol_vectorZ = cos(psi)*sin(theta); Vector Pol_vector = Vector(newPol_vectorX, newPol_vectorY, newPol_vectorZ); - + //Apply Fresnel factors for magnification and 1/r dependence icemodel->GetFresnel( ray_output[1][ray_idx], // launch_angle @@ -1325,14 +1331,14 @@ void Report::ModelRay( PropagateSignal( dT_forfft, waveform_bin, signal->InputVoltage_T, signal->InputVoltage_V, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); - + } // PVA Pulser Events - + } // if not calpulser event // if calpulser event @@ -1348,7 +1354,7 @@ void Report::ModelRay( PropagateSignal( dT_forfft, CP_bin, detector->CalPulserWF_ns, detector->CalPulserWF_V, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); @@ -1362,17 +1368,17 @@ void Report::ModelRay( } void Report::GetRayParameters( - Antenna_r *antenna_r, Antenna *antenna_d, + Antenna_r *antenna_r, Antenna *antenna_d, Interaction interaction, int interaction_idx, - int i, int j, int k, + int i, int j, int k, int ray_idx, vector> ray_output, Vector *n_trg_pokey, Vector *n_trg_slappy, Vector *Pol_vector_src, - Position *launch_vector, Position *receive_vector, + Position *launch_vector, Position *receive_vector, IceModel *icemodel, Settings *settings1 ){ // For a given ray path connecting a cascade to an antenna, calculate and - // save parameters including the antenna's viewing angle of the ray, - // attenuation length, magnification factors, etc. + // save parameters including the antenna's viewing angle of the ray, + // attenuation length, magnification factors, etc. // Also initializes the objects that store electric field and voltage // signals from the cascade by resizing those objects to the number of rays. @@ -1396,6 +1402,8 @@ void Report::GetRayParameters( antenna_r->reflect_ang[interaction_idx].push_back(ray_output[3][ray_idx]); antenna_r->vmmhz[interaction_idx].resize(ray_idx + 1); antenna_r->Heff[interaction_idx].resize(ray_idx + 1); + antenna_r->Heff_copol[interaction_idx].resize(ray_idx + 1); + antenna_r->Heff_crosspol[interaction_idx].resize(ray_idx + 1); antenna_r->Vm_zoom[interaction_idx].resize(ray_idx + 1); antenna_r->Vm_zoom_T[interaction_idx].resize(ray_idx + 1); antenna_r->Vfft[interaction_idx].resize(ray_idx + 1); @@ -1405,7 +1413,7 @@ void Report::GetRayParameters( // calculate the polarization vector at the source Position Pol_vector = GetPolarization(interaction.nnu, *launch_vector); // polarization vector at the source - *Pol_vector_src = Pol_vector; //store the src Pol + *Pol_vector_src = Pol_vector; //store the src Pol double fresnel = 0; icemodel->GetFresnel( @@ -1420,7 +1428,7 @@ void Report::GetRayParameters( Pol_vector); // input src Pol and return Pol at trg double mag = 0; icemodel->GetMag( - mag, + mag, ray_output[0][ray_idx], // ray path length ray_output[1][ray_idx], // zenith angle of ray at launch ray_output[2][ray_idx], // zenith angle of ray upon receipt @@ -1461,8 +1469,8 @@ void Report::GetRayParameters( antenna_r->phi_rec[interaction_idx].push_back(antenna_phi *(PI / 180)); antenna_r->theta_rec[interaction_idx].push_back(antenna_theta *(PI / 180)); antenna_r->phi_launch[interaction_idx].push_back(launch_phi *(PI / 180)); - antenna_r->theta_launch[interaction_idx].push_back(launch_theta *(PI / 180)); - + antenna_r->theta_launch[interaction_idx].push_back(launch_theta *(PI / 180)); + } void Report::DetermineWFBins( @@ -1484,14 +1492,14 @@ void Report::DetermineWFBins( void Report::PropagateSignal( double dT_forfft, int efield_length, vector< double > efield_time, vector< double > efield, double *T_forint, - int interaction_idx, int ray_idx, vector > ray_output, Position launch_vector, double time_diff_birefringence, - Vector Pol_vector_src, Vector Pol_vector, Vector n_trg_slappy, Vector n_trg_pokey, + int interaction_idx, int ray_idx, vector > ray_output, Position launch_vector, double time_diff_birefringence, + Vector Pol_vector_src, Vector Pol_vector, Vector n_trg_slappy, Vector n_trg_pokey, Antenna_r *antenna_r, Antenna *antenna_d, int gain_ch_no, int j, int k, Birefringence *birefringence, Detector *detector, Event *event, IceModel *icemodel, Settings *settings ){ // For the provided `antenna_r`, interaction, and ray: - // take the EM signal at the source and calculate how it's read out - // as a voltage waveform by the antenna by applying all attenuation, + // take the EM signal at the source and calculate how it's read out + // as a voltage waveform by the antenna by applying all attenuation, // birefringence, antenna, and other factors. // now we have to make NFOUR/2 number of bins with random init time @@ -1541,7 +1549,7 @@ void Report::PropagateSignal( Pol_vector_src, bire_ray_cnt, ray_output[3][ray_idx], settings ); //split power factor for birefringence birefringence->Time_shift_and_power_split( - V_forfft, antenna_r->Nnew[ray_idx], + V_forfft, antenna_r->Nnew[ray_idx], T_shift_bire, split_factor_bire, bire_ray_cnt, max_bire_ray_cnt, settings ); // apply time differences and power split @@ -1559,18 +1567,18 @@ void Report::PropagateSignal( double freq_lastbin = freq_tmp; //For birefringence, modify the polarization at the antennas - birefringence->Principal_axes_polarization(Pol_vector, bire_ray_cnt, max_bire_ray_cnt, settings); + birefringence->Principal_axes_polarization(Pol_vector, bire_ray_cnt, max_bire_ray_cnt, settings); - // Get ant gain with 2-D interpolation + // Get ant gain with 2-D interpolation double heff_lastbin = GaintoHeight( detector->GetGain_1D_OutZero( - freq_tmp *1.E-6, antenna_theta, antenna_phi, + freq_tmp *1.E-6, antenna_theta, antenna_phi, antenna_d->type, j, k), - freq_tmp, + freq_tmp, icemodel->GetN(*antenna_d), detector->GetImpedance(freq_tmp*1.E-6, antenna_d->type, k)); - // Tx effective height for last bin. Currently locked to standard ARA Vpol and HPol antennas. + // Tx effective height for last bin. Currently locked to standard ARA Vpol and HPol antennas. // Need to add selection mode. // Only used in EVENT_MODE == 12 double Tx_theta = 0; @@ -1586,16 +1594,16 @@ void Report::PropagateSignal( double Tx_phi = phi*180/PI; double heff_Tx_lastbin = GaintoHeight( detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true), - freq_tmp, + freq_tmp, icemodel->GetN(*antenna_d), - detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true)); + detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true)); } else if (event->IsCalpulser > 0){ // Calibration Pulser simulations Tx_theta = ray_output[1][ray_idx] *DEGRAD; // from 0 to 180 heff_Tx_lastbin = GaintoHeight( detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, antenna_phi, antenna_d->type, j, k), - freq_tmp, icemodel->GetN(event->Nu_Interaction[interaction_idx].posnu)); - + freq_tmp, icemodel->GetN(event->Nu_Interaction[interaction_idx].posnu)); + if (event->IsCalpulser == 1) { Pol_vector = n_trg_slappy; } @@ -1616,12 +1624,12 @@ void Report::PropagateSignal( for (int n = 0; n < antenna_r->Nnew[ray_idx] / 2; n++) { // Loop over frequency bins freq_tmp = dF_Nnew *((double) n + 0.5); // in Hz 0.5 to place the middle of the bin and avoid zero freq - + double heff = GaintoHeight( detector->GetGain_1D_OutZero(freq_tmp *1.E-6, antenna_theta, antenna_phi, antenna_d->type, j, k), - freq_tmp, + freq_tmp, icemodel->GetN(*antenna_d), - detector->GetImpedance(freq_tmp*1.E-6, antenna_d->type, k)); + detector->GetImpedance(freq_tmp*1.E-6, antenna_d->type, k)); antenna_r->Heff[interaction_idx][ray_idx].push_back(heff); //apply freq dependent attenuation model if in neutrino mode @@ -1634,8 +1642,8 @@ void Report::PropagateSignal( dz = RayStep[ray_idx][1][steps - 1] - RayStep[ray_idx][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. + // Skipping attenuation calculation when the distance between two RaySteps is 0. + // Prevening adds -nan into the IceAttenFactor. if (dl > 0) { // use ray midpoint for attenuation calculation IceAttenFactor *= ( @@ -1645,7 +1653,7 @@ void Report::PropagateSignal( } } - + 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 @@ -1655,19 +1663,19 @@ void Report::PropagateSignal( if (settings->EVENT_TYPE == 12){ double heff_Tx = GaintoHeight( detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true), - freq_tmp, + freq_tmp, icemodel->GetN(*antenna_d), - detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true)); + detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true)); if (n > 0) { ApplyAntFactors_Tdomain( detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0), - heff_Tx, Pol_vector, 0, Pol_factor, V_forfft[2 *n], V_forfft[2 *n + 1], + heff_Tx, Pol_vector, 0, Pol_factor, V_forfft[2 *n], V_forfft[2 *n + 1], settings, Tx_theta, Tx_phi, freq_tmp, detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true), true); } else { ApplyAntFactors_Tdomain_FirstTwo( - heff_Tx, heff_Tx_lastbin, Pol_vector, 0, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], Tx_theta, Tx_phi, freq_tmp); + heff_Tx, heff_Tx_lastbin, Pol_vector, 0, Pol_factor, + V_forfft[2 *n], V_forfft[2 *n + 1], settings, Tx_theta, Tx_phi, freq_tmp); } } else if (event->IsCalpulser > 0){ @@ -1677,42 +1685,42 @@ void Report::PropagateSignal( freq_tmp *1.E-6, // to MHz Tx_theta, antenna_phi, antenna_d->type, j, k), freq_tmp, icemodel->GetN(event->Nu_Interaction[interaction_idx].posnu)); - + if (n > 0) { ApplyAntFactors_Tdomain( detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, antenna_phi, antenna_d->type), - heff, Pol_vector, antenna_d->type, Pol_factor, + heff, Pol_vector, antenna_d->type, Pol_factor, V_forfft[2 *n], V_forfft[2 *n + 1], settings, true, antenna_theta, antenna_phi, freq_tmp); } else { ApplyAntFactors_Tdomain_FirstTwo( - heff, heff_Tx_lastbin, Pol_vector, antenna_d->type, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], antenna_theta, antenna_phi, freq_tmp); + heff, heff_Tx_lastbin, Pol_vector, antenna_d->type, Pol_factor, + V_forfft[2 *n], V_forfft[2 *n + 1], settings, antenna_theta, antenna_phi, freq_tmp); } } // apply ant factors if (n > 0) { - ApplyAntFactors_Tdomain( + ApplyAntFactors_Tdomain( detector->GetAntPhase_1D(freq_tmp *1.e-6, antenna_theta, antenna_phi, antenna_d->type), - heff, Pol_vector, antenna_d->type, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], settings, antenna_theta, antenna_phi, freq_tmp); + heff, Pol_vector, antenna_d->type, Pol_factor, + V_forfft[2 *n], V_forfft[2 *n + 1], settings, antenna_theta, antenna_phi, freq_tmp); } else { ApplyAntFactors_Tdomain_FirstTwo( - heff, heff_lastbin, Pol_vector, antenna_d->type, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], antenna_theta, antenna_phi, freq_tmp); + heff, heff_lastbin, Pol_vector, antenna_d->type, Pol_factor, + V_forfft[2 *n], V_forfft[2 *n + 1], settings, antenna_theta, antenna_phi, freq_tmp); } // apply entire elect chain gain, phase if (n > 0) { ApplyElect_Tdomain( - freq_tmp *1.e-6, detector, + freq_tmp *1.e-6, detector, V_forfft[2 *n], V_forfft[2 *n + 1], gain_ch_no, settings); } else { ApplyElect_Tdomain_FirstTwo( - freq_tmp *1.e-6, freq_lastbin *1.e-6, detector, + freq_tmp *1.e-6, freq_lastbin *1.e-6, detector, V_forfft[2 *n], V_forfft[2 *n + 1], gain_ch_no, settings); } @@ -1725,7 +1733,7 @@ void Report::PropagateSignal( V_forfft, V_forfft_bire[bire_ray_cnt], antenna_r->Nnew[ray_idx] ); //Store waveforms from birefringence for interference - } // end for bire_ray_cnt + } // end for bire_ray_cnt birefringence->Two_rays_interference( V_forfft, V_forfft_bire[0], V_forfft_bire[1], antenna_r->Nnew[ray_idx], max_bire_ray_cnt, settings @@ -1758,7 +1766,7 @@ void Report::triggerCheck_ScanMode0( int n_scanned_channels, int station_index, Detector *detector, Event *event, Settings *settings1, Trigger *trigger ){ - // Check the tunnel diode for each antenna for sufficient signal to trigger + // Check the tunnel diode for each antenna for sufficient signal to trigger // then perform station-wide trigger check. Transforms waveforms into // the data-like V_mimic objects // Original AraSim trigger checking mode @@ -1786,7 +1794,7 @@ void Report::triggerCheck_ScanMode0( ARA_station *station_d = &detector->stations[station_index]; // Loop over global time bins and identify the first, if any, time bin - // with sufficient signal to trigger in the appropriate amount of antennas + // with sufficient signal to trigger in the appropriate amount of antennas while (this_bin < max_total_bin - trig_window_bin) { // loop over waveform bins int N_pass = 0; @@ -1803,15 +1811,15 @@ void Report::triggerCheck_ScanMode0( int channel_num = detector->GetChannelfromStringAntenna(station_index, string_i, antenna_i, settings1); // Channel numbering is different for DETECTOR=(1,2,3) than for - // DETECTOR = 4 and 5 in GetChannelfromStringAntenna(), it needs that shift + // DETECTOR = 4 and 5 in GetChannelfromStringAntenna(), it needs that shift if (!(settings1->DETECTOR==4 || settings1->DETECTOR==5)){ - channel_num = channel_num+1; + channel_num = channel_num+1; } // Antenna Masking (masked_ant=0 means this antenna should be ignored from trigger) - if( detector->GetTrigMasking(channel_num-1)==0){ + if( detector->GetTrigMasking(channel_num-1)==0){ antenna_counter++; - continue; + continue; } int offset = detector->GetTrigOffset(channel_num-1, settings1); @@ -1827,9 +1835,9 @@ void Report::triggerCheck_ScanMode0( double diode_noise_RMS = trigger->GetAntNoise_diodeRMS(channel_num-1, settings1); if ( - trigger->Full_window[antenna_counter][this_bin + trig_bin] < - ( detector->GetThres(station_index, channel_num - 1, settings1) - * diode_noise_RMS + trigger->Full_window[antenna_counter][this_bin + trig_bin] < + ( detector->GetThres(station_index, channel_num - 1, settings1) + * diode_noise_RMS * detector->GetThresOffset(station_index, channel_num - 1, settings1)) ) { // if this channel passed the trigger! @@ -1842,7 +1850,7 @@ void Report::triggerCheck_ScanMode0( if (station_d->strings[string_i].antennas[antenna_i].type == 1) { // Hpol N_pass_H++; } - if (last_trig_bin < this_bin + trig_bin) + if (last_trig_bin < this_bin + trig_bin) last_trig_bin = this_bin + trig_bin; // added for fixed V_mimic trig_bin = trig_window_bin; // if confirmed this channel passed the trigger, no need to do rest of bins Passed_chs.push_back(antenna_counter); @@ -1863,7 +1871,7 @@ void Report::triggerCheck_ScanMode0( if (antenna_i < 2) { // only antenna 0, 1 which are bottom 2 antennas - // set channel_num as new value (antenna 0, 1 are only + // set channel_num as new value (antenna 0, 1 are only // possible antennas for channel_num 1 - 8) int trig_bin = 0; @@ -1872,9 +1880,9 @@ void Report::triggerCheck_ScanMode0( double diode_noise_RMS = trigger->GetAntNoise_diodeRMS(channel_num-1, settings1); // with threshold offset by chs if ( - trigger->Full_window[antenna_counter][this_bin + trig_bin] < - ( detector->GetThres(station_index, channel_num - 1, settings1) - * diode_noise_RMS + trigger->Full_window[antenna_counter][this_bin + trig_bin] < + ( detector->GetThres(station_index, channel_num - 1, settings1) + * diode_noise_RMS * detector->GetThresOffset(station_index, channel_num - 1, settings1))) { // if this channel passed the trigger! @@ -1889,7 +1897,7 @@ void Report::triggerCheck_ScanMode0( // Hpol N_pass_H++; } - if (last_trig_bin < this_bin + trig_bin) + if (last_trig_bin < this_bin + trig_bin) last_trig_bin = this_bin + trig_bin; // added for fixed V_mimic trig_bin = trig_window_bin; // if confirmed this channel passed the trigger, no need to do rest of bins Passed_chs.push_back(antenna_counter); @@ -1903,17 +1911,17 @@ void Report::triggerCheck_ScanMode0( // other cases: use all possible chs for trigger analysis else { - + int trig_bin = 0; while (trig_bin < trig_window_bin) { double diode_noise_RMS = trigger->GetAntNoise_diodeRMS(channel_num-1, settings1); - if( this_bin+offset+trig_bin >= settings1->DATA_BIN_SIZE ) + if( this_bin+offset+trig_bin >= settings1->DATA_BIN_SIZE ) break; //if trigger window hits wf end, cannot scan this channel further with this this_bin if ( - trigger->Full_window[antenna_counter][this_bin + trig_bin + offset] < - ( detector->GetThres(station_index, channel_num - 1, settings1) - * diode_noise_RMS + trigger->Full_window[antenna_counter][this_bin + trig_bin + offset] < + ( detector->GetThres(station_index, channel_num - 1, settings1) + * diode_noise_RMS * detector->GetThresOffset(station_index, channel_num - 1, settings1)) ) { // if this channel passed the trigger! @@ -1926,7 +1934,7 @@ void Report::triggerCheck_ScanMode0( if (station_d->strings[string_i].antennas[antenna_i].type == 1) { // Hpol N_pass_H++; } - if (last_trig_bin < this_bin + trig_bin) + if (last_trig_bin < this_bin + trig_bin) last_trig_bin = this_bin + trig_bin + offset; // added for fixed V_mimic trig_bin = trig_window_bin; // if confirmed this channel passed the trigger, no need to do rest of bins Passed_chs.push_back(antenna_counter); @@ -1952,22 +1960,22 @@ void Report::triggerCheck_ScanMode0( this_bin = max_total_bin; // also if we know this station is trigged, don't need to check rest of time window // Loop over all antennas on the station and save the data-like waveform, V_mimic - for (int ch_loop = 0; ch_loop < n_scanned_channels; ch_loop++) { + for (int ch_loop = 0; ch_loop < n_scanned_channels; ch_loop++) { int string_i = detector->getStringfromArbAntID(station_index, ch_loop); int antenna_i = detector->getAntennafromArbAntID(station_index, ch_loop); int waveformLength = settings1->WAVEFORM_LENGTH; int waveformCenter = settings1->WAVEFORM_CENTER; - + station_r->strings[string_i].antennas[antenna_i].Likely_Sol[0] = -1; // no likely init station_r->strings[string_i].antennas[antenna_i].Likely_Sol[1] = -1; // no likely init - // If this channel was one that passed, also determine which + // If this channel was one that passed, also determine which // ray and interaction triggered the detector and print some info if (ch_loop == Passed_chs[check_ch] && check_ch < N_pass) { // `check_ch < N_Pass` present to circumvent a bug in vector Passed_chs.clear() - // Determine which ray and interaciton triggered triggered + // Determine which ray and interaciton triggered triggered // the station based on signal and trigger bins station_r->strings[string_i].antennas[antenna_i].Find_Likely_Sol(); int likely_int = station_r->strings[string_i].antennas[antenna_i].Likely_Sol[0]; @@ -1975,40 +1983,40 @@ void Report::triggerCheck_ScanMode0( if (settings1->TRIG_ONLY_LOW_CH_ON == 0) { - cout << endl + cout << endl << "trigger passed at bin " - << station_r->strings[string_i].antennas[antenna_i].Trig_Pass - << " passed ch : " << ch_loop - << " (" << station_d->strings[string_i].antennas[antenna_i].type - << "type) Direct dist btw posnu : " - << event->Nu_Interaction[0].posnu.Distance(station_d->strings[string_i].antennas[antenna_i]) + << station_r->strings[string_i].antennas[antenna_i].Trig_Pass + << " passed ch : " << ch_loop + << " (" << station_d->strings[string_i].antennas[antenna_i].type + << "type) Direct dist btw posnu : " + << event->Nu_Interaction[0].posnu.Distance(station_d->strings[string_i].antennas[antenna_i]) << " noiseID : " << station_r->strings[string_i].antennas[antenna_i].noise_ID[0]; if (station_r->strings[string_i].antennas[antenna_i].Likely_Sol[0] != -1) { - cout << " ViewAngle : " + cout << " ViewAngle : " << station_r->strings[string_i].antennas[antenna_i].view_ang[likely_int][likely_ray] *DEGRAD ; - cout << " LikelyTrigSignal : interaction " + cout << " LikelyTrigSignal : interaction " << station_r->strings[string_i].antennas[antenna_i].Likely_Sol[0]; - cout << ", ray " + cout << ", ray " << station_r->strings[string_i].antennas[antenna_i].Likely_Sol[1]; } } else if (settings1->TRIG_ONLY_LOW_CH_ON == 1) { - cout << endl - << "trigger passed at bin " - << station_r->strings[string_i].antennas[antenna_i].Trig_Pass - << " passed ant: str[" << string_i << "].ant[" << antenna_i << "] (" - << station_d->strings[string_i].antennas[antenna_i].type - << "type) Direct dist btw posnu : " - << event->Nu_Interaction[0].posnu.Distance(station_d->strings[string_i].antennas[antenna_i]) + cout << endl + << "trigger passed at bin " + << station_r->strings[string_i].antennas[antenna_i].Trig_Pass + << " passed ant: str[" << string_i << "].ant[" << antenna_i << "] (" + << station_d->strings[string_i].antennas[antenna_i].type + << "type) Direct dist btw posnu : " + << event->Nu_Interaction[0].posnu.Distance(station_d->strings[string_i].antennas[antenna_i]) << " noiseID : " << station_r->strings[string_i].antennas[antenna_i].noise_ID[0]; if (station_r->strings[string_i].antennas[antenna_i].Likely_Sol[0] != -1) { - cout << " ViewAngle : " + cout << " ViewAngle : " << station_r->strings[string_i].antennas[antenna_i].view_ang[likely_int][likely_ray] *DEGRAD ; - cout << " LikelyTrigSignal : interaction " + cout << " LikelyTrigSignal : interaction " << station_r->strings[string_i].antennas[antenna_i].Likely_Sol[0]; - cout << ", ray " + cout << ", ray " << station_r->strings[string_i].antennas[antenna_i].Likely_Sol[1]; } @@ -2031,9 +2039,9 @@ void Report::triggerCheck_ScanMode0( } else if (V_mimic_mode == 1) { // Global passed bin is the center of the window + delay to each chs from araGeom - const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[ch_loop] + const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin) + waveformCenter - waveformLength / 2 + mimicbin; - const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin) + const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin) + waveformCenter - waveformLength / 2 + mimicbin; station_r->strings[string_i].antennas[antenna_i].V_mimic.push_back((trigger->Full_window_V[ch_loop][thisBin]) *1.e3); // save in mV @@ -2042,12 +2050,12 @@ void Report::triggerCheck_ScanMode0( } else if (V_mimic_mode == 2) { // Global passed bin is the center of the window + delay to each chs from araGeom + fitted by eye - const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[ch_loop] - - detector->params.TestBed_BH_Mean_delay_bin - + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[ch_loop] + - detector->params.TestBed_BH_Mean_delay_bin + + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + waveformCenter - waveformLength / 2 + mimicbin; - const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin - + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin + + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + waveformCenter - waveformLength / 2 + mimicbin; station_r->strings[string_i].antennas[antenna_i].V_mimic.push_back((trigger->Full_window_V[ch_loop][thisBin]) *1.e3); // save in mV @@ -2057,9 +2065,9 @@ void Report::triggerCheck_ScanMode0( if (mimicbin == 0) { ///< calculates time of center of each rays signal based on readout window time config for (int interaction_idx=0; interaction_idxstrings[string_i].antennas[antenna_i].SignalBin.size(); interaction_idx++){ - for (int m = 0; m < station_r->strings[string_i].antennas[antenna_i].SignalBin[interaction_idx].size(); m++) { + for (int m = 0; m < station_r->strings[string_i].antennas[antenna_i].SignalBin[interaction_idx].size(); m++) { double signal_center_offset = (double)( - station_r->strings[string_i].antennas[antenna_i].SignalBin[interaction_idx][m] - + station_r->strings[string_i].antennas[antenna_i].SignalBin[interaction_idx][m] - station_r->strings[string_i].antennas[antenna_i].time[0] ) * settings1->TIMESTEP * 1.e9; double signal_center_time = signal_center_offset + station_r->strings[string_i].antennas[antenna_i].time_mimic[0]; @@ -2078,14 +2086,14 @@ void Report::triggerCheck_ScanMode0( } else if (V_mimic_mode == 1) { // Global passed bin is the center of the window + delay to each chs from araGeom - station_r->strings[string_i].antennas[antenna_i].global_trig_bin = (detector->params.TestBed_Ch_delay_bin[ch_loop] + station_r->strings[string_i].antennas[antenna_i].global_trig_bin = (detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin) - waveformCenter + waveformLength / 2; } else if (V_mimic_mode == 2) { // Global passed bin is the center of the window + delay to each chs from araGeom + fitted by eye - station_r->strings[string_i].antennas[antenna_i].global_trig_bin = (detector->params.TestBed_Ch_delay_bin[ch_loop] - - detector->params.TestBed_BH_Mean_delay_bin - + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + station_r->strings[string_i].antennas[antenna_i].global_trig_bin = (detector->params.TestBed_Ch_delay_bin[ch_loop] + - detector->params.TestBed_BH_Mean_delay_bin + + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) - waveformCenter + waveformLength / 2; } } @@ -2105,11 +2113,11 @@ void Report::triggerCheck_ScanMode0( } else if (V_mimic_mode == 1) { // Global passed bin is the center of the window + delay to each chs from araGeom - const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[ch_loop] - - detector->params.TestBed_BH_Mean_delay_bin) + const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[ch_loop] + - detector->params.TestBed_BH_Mean_delay_bin) + waveformCenter - waveformLength / 2 + mimicbin; - const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[ch_loop] - - detector->params.TestBed_BH_Mean_delay_bin) + const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[ch_loop] + - detector->params.TestBed_BH_Mean_delay_bin) + waveformCenter - waveformLength / 2 + mimicbin; station_r->strings[string_i].antennas[antenna_i].V_mimic.push_back((trigger->Full_window_V[ch_loop][thisBin]) *1.e3); // save in mV @@ -2118,15 +2126,15 @@ void Report::triggerCheck_ScanMode0( } if (V_mimic_mode == 2) { // Global passed bin is the center of the window + delay to each chs from araGeom + fitted delay - const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[ch_loop] - - detector->params.TestBed_BH_Mean_delay_bin - + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[ch_loop] + - detector->params.TestBed_BH_Mean_delay_bin + + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + waveformCenter - waveformLength / 2 + mimicbin; - const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[ch_loop] - - detector->params.TestBed_BH_Mean_delay_bin - + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[ch_loop] + - detector->params.TestBed_BH_Mean_delay_bin + + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + waveformCenter - waveformLength / 2 + mimicbin; - + station_r->strings[string_i].antennas[antenna_i].V_mimic.push_back((trigger->Full_window_V[ch_loop][thisBin]) *1.e3); // save in mV station_r->strings[string_i].antennas[antenna_i].time.push_back(thisBin); station_r->strings[string_i].antennas[antenna_i].time_mimic.push_back(thisTimeBin *settings1->TIMESTEP *1.e9 + detector->params.TestBed_WFtime_offset_ns); // save in ns @@ -2134,9 +2142,9 @@ void Report::triggerCheck_ScanMode0( if (mimicbin == 0) { ///< calculates time of center of each rays signal based on readout window time config for (int interaction_idx=0; interaction_idxstrings[string_i].antennas[antenna_i].SignalBin.size(); interaction_idx++){ - for (int m = 0; m < station_r->strings[string_i].antennas[antenna_i].SignalBin[interaction_idx].size(); m++) { + for (int m = 0; m < station_r->strings[string_i].antennas[antenna_i].SignalBin[interaction_idx].size(); m++) { double signal_center_offset = (double)( - station_r->strings[string_i].antennas[antenna_i].SignalBin[interaction_idx][m] - + station_r->strings[string_i].antennas[antenna_i].SignalBin[interaction_idx][m] - station_r->strings[string_i].antennas[antenna_i].time[0] ) * settings1->TIMESTEP * 1.e9; double signal_center_time = signal_center_offset + station_r->strings[string_i].antennas[antenna_i].time_mimic[0]; @@ -2156,19 +2164,19 @@ void Report::triggerCheck_ScanMode0( else if (V_mimic_mode == 1) { // Global passed bin is the center of the window + delay to each chs from araGeom station_r->strings[string_i].antennas[antenna_i].global_trig_bin = ( - (detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin) + (detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin) + waveformLength / 2 - waveformCenter); } else if (V_mimic_mode == 2) { // Global passed bin is the center of the window + delay to each chs from araGeom + fitted by eye station_r->strings[string_i].antennas[antenna_i].global_trig_bin = ( - (detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + (detector->params.TestBed_Ch_delay_bin[ch_loop] - detector->params.TestBed_BH_Mean_delay_bin + station_d->strings[string_i].antennas[antenna_i].manual_delay_bin) + waveformLength / 2 - waveformCenter); } // done V_mimic for non-triggered chs (done fixed V_mimic) } - + } // save trig search bin info @@ -2183,66 +2191,66 @@ void Report::triggerCheck_ScanMode0( } int Report::triggerCheckLoop( - Settings *settings1, Detector *detector, Event *event, Trigger *trigger, - int stationID, int trig_search_init, int max_total_bin, int trig_window_bin, int scan_mode + Settings *settings1, Detector *detector, Event *event, Trigger *trigger, + int stationID, int trig_search_init, int max_total_bin, int trig_window_bin, int scan_mode ){ - + int i=stationID; - + int numChan=stations[i].TDR_all.size(); int numChanVpol=stations[i].TDR_Vpol_sorted.size(); int numChanHpol=stations[i].TDR_Hpol_sorted.size(); - + double powerthreshold=settings1->POWERTHRESHOLD; - // this value is compared to POWERTHRESHOLD for local trigger. - + // this value is compared to POWERTHRESHOLD for local trigger. + int first_trigger=0; - + double Pthresh_value[numChan]; CircularBuffer **buffer=new CircularBuffer*[numChan]; for(int trig_j=0;trig_jgetStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); trig_window_bin = (int)(settings1->TRIG_WINDOW / settings1->TIMESTEP); // coincidence window bin for trigger - + Pthresh_value[trig_j]=0; buffer[trig_j]=new CircularBuffer( trig_window_bin, powerthreshold, scan_mode); - + stations[i].strings[string_i].antennas[antenna_i].SingleChannelTriggers=0; stations[i].strings[string_i].antennas[antenna_i].TotalBinsScannedPerChannel=0; - + }// for trig_j - + double *TDR_all_sorted_temp; double *TDR_Vpol_sorted_temp; double *TDR_Hpol_sorted_temp; - + if(scan_mode>1){ - + TDR_all_sorted_temp=new double[numChan]; TDR_Vpol_sorted_temp=new double[numChanVpol]; TDR_Hpol_sorted_temp=new double[numChanHpol]; - + // only need to initialize for scan_mode>1 - for(int trig_j=0;trig_j1 int global_pass_bit=0; // whether this event passes (in all windows) int check_TDR_configuration=0; // check if we need to reorder our TDR arrays - int SCTR_cluster_bit[numChan]; - - for(int trig_j=0;trig_jgetStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); trig_window_bin = (int)(settings1->TRIG_WINDOW / settings1->TIMESTEP); // coincidence window bin for trigger - + if (settings1->TRIG_ONLY_BH_ON==0 - || + || (settings1->TRIG_ONLY_BH_ON==1 && settings1->DETECTOR==3 && detector->stations[i].strings[string_i].antennas[antenna_i].DAQchan==0) || (settings1->TRIG_ONLY_LOW_CH_ON==1 && settings1->DETECTOR!=3 && antenna_i<2 ) ) { // channel filter: choose if to use lower/borehole channels or not - + int channel_num = detector->GetChannelfromStringAntenna ( i, string_i, antenna_i, settings1 ); - // assign Pthresh a value + // assign Pthresh a value double diode_noise_RMS = trigger->GetAntNoise_diodeRMS(channel_num-1, settings1); Pthresh_value[trig_j]=trigger->Full_window[trig_j][trig_i]/(diode_noise_RMS * detector->GetThresOffset( i, channel_num-1,settings1) ); - // this is to count how many local trigger clusters there are + // this is to count how many local trigger clusters there are if(Pthresh_value[trig_j]TRIG_SCAN_MODE>2){ - + if(settings1->TRIG_SCAN_MODE>2){ + if(SCTR_cluster_bit[trig_j]==0){// if first trigger in cluster - + stations[i].strings[string_i].antennas[antenna_i].SCT_threshold_pass.push_back(Pthresh_value[trig_j]); - - + + } else{// choose the highest trigger value (most negative) in cluster - - if(Pthresh_value[trig_j] 2 - + SCTR_cluster_bit[trig_j]=1; - + }// if local trigger - else + else SCTR_cluster_bit[trig_j]=0;// if no local trigger, set zero to start a new cluster at next local trigger - + // and how many bins scanned stations[i].strings[string_i].antennas[antenna_i].TotalBinsScannedPerChannel++; - - - + + + // fill the buffers (if any changes occur mark check_TDR_configuration as non-zero) - if(trig_ifill(Pthresh_value[trig_j]); - else + else check_TDR_configuration+=buffer[trig_j]->add(Pthresh_value[trig_j]); - + if(buffer[trig_j]->addToNPass>0){// if there is at least one value above threshold in the buffer, this is ++ - + N_pass++; - if(detector->stations[i].strings[string_i].antennas[antenna_i].type == 0) + if(detector->stations[i].strings[string_i].antennas[antenna_i].type == 0) N_pass_V++; - if(detector->stations[i].strings[string_i].antennas[antenna_i].type == 1) + if(detector->stations[i].strings[string_i].antennas[antenna_i].type == 1) N_pass_H++; - + }// if addToNPass>0 - + }// non-testbed case (i.e. use all channels) - + }// for trig_j (channel scan) // check if global trigger... - - if( (settings1->TRIG_MODE==0&&( N_pass >= settings1->N_TRIG )) || - (settings1->TRIG_MODE==1&&( N_pass_V >= settings1->N_TRIG_V || - N_pass_H >= settings1->N_TRIG_H ) ) + + if( (settings1->TRIG_MODE==0&&( N_pass >= settings1->N_TRIG )) || + (settings1->TRIG_MODE==1&&( N_pass_V >= settings1->N_TRIG_V || + N_pass_H >= settings1->N_TRIG_H ) ) ){ // if there's a trigger ! - - global_pass_bit=1; + + global_pass_bit=1; window_pass_bit=1; if(first_trigger==0){ // if this is the first trigger, mark this position and save event first_trigger=1; for(int trig_j=0;trig_jgetStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); - if(buffer[trig_j]->addToNPass>0) + if(buffer[trig_j]->addToNPass>0) stations[i].strings[string_i].antennas[antenna_i].Trig_Pass = trig_i-buffer[trig_j]->numBinsToOldestTrigger(); // mark the bin on which we triggered... - else + else stations[i].strings[string_i].antennas[antenna_i].Trig_Pass = 0.; - + }// for trig_j - + saveTriggeredEvent(settings1, detector, event, trigger, stationID, trig_search_init, max_total_bin, trig_window_bin, trig_i); - + }// first trigger - - if(scan_mode==1) + + if(scan_mode==1) return trig_i; // if we aren't going to scan all the Pthresh values, just return } - + // if there's a trigger and anything changes in the buffers, restock the TDR arrays if( scan_mode>1 && check_TDR_configuration && window_pass_bit ){ - - for(int trig_j=0;trig_jTRIG_MODE==0){ // for N out of all mode - + if(N_pass>=settings1->N_TRIG) for(int ii=0;iitemp_valuetemp_value; + + for(int trig_j=0;trig_jtemp_valuetemp_value; best_chan=trig_j; } - + buffer[best_chan]->temp_value=0; - + TDR_all_sorted_temp[ii]=best_thresh; - + }// for ii - - + + // debug output: if(TDR_all_sorted_temp[0]>TDR_all_sorted_temp[1]||TDR_all_sorted_temp[1]>TDR_all_sorted_temp[2]){ - + cout<<"\n"; for(int p=0;p<80;p++) cout<<"*"; cout<<"\n ordering problem: "<TRIG_MODE==1){ // for N out of either polarization @@ -2415,86 +2423,86 @@ int Report::triggerCheckLoop( double best_thresh=0; int best_chan=0; - + for(int trig_j=0;trig_jgetStringfromArbAntID( i, trig_j); - int antenna_i = detector->getAntennafromArbAntID( i, trig_j); + int antenna_i = detector->getAntennafromArbAntID( i, trig_j); + + if(detector->stations[i].strings[string_i].antennas[antenna_i].type == 0 && buffer[trig_j]->temp_valuestations[i].strings[string_i].antennas[antenna_i].type == 0 && buffer[trig_j]->temp_valuetemp_value; + best_thresh=buffer[trig_j]->temp_value; best_chan=trig_j; - + }// if best }// for trig_j buffer[best_chan]->temp_value=0; - + TDR_Vpol_sorted_temp[ii]=best_thresh; - + }// for ii - + // for Hpol only - if(N_pass_H>=settings1->N_TRIG_H) + if(N_pass_H>=settings1->N_TRIG_H) for(int ii=0;iigetStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); - - if(detector->stations[i].strings[string_i].antennas[antenna_i].type==1&&buffer[trig_j]->temp_valuetemp_value; + + if(detector->stations[i].strings[string_i].antennas[antenna_i].type==1&&buffer[trig_j]->temp_valuetemp_value; best_chan=trig_j; - + }// if best }// for trig_j - + buffer[best_chan]->temp_value=0; - + TDR_Hpol_sorted_temp[ii]=best_thresh; - + }// for ii - + }// if trig_mode==1 - + // check if temp TDR arrays improved, if so update TDR arrays: if(settings1->TRIG_MODE==0){ - + if(N_pass>=settings1->N_TRIG) for(int ii=0;iiTRIG_MODE==1){ - + if(N_pass_V>=settings1->N_TRIG_V) for(int ii=0;ii=settings1->N_TRIG_H) for(int ii=0;ii1&&global_pass_bit){ - + if(settings1->TRIG_MODE==0){ - + cout<<"\nPthresh best: "; for(int ii=0;ii<3;ii++) cout<<" "<stations[i].TDR_all_sorted[1]||stations[i].TDR_all_sorted[1]>stations[i].TDR_all_sorted[2]){ - + cout<<"\n"; - for(int p=0;p<80;p++) + for(int p=0;p<80;p++) cout<<"*"; cout<<"\n ordering problem: " <TRIG_MODE==1){ cout<<"\nPthresh best: "; - cout<<" Vpol: "; - for(int ii=0;iistations[i].TDR_Vpol_sorted[1] || stations[i].TDR_Vpol_sorted[1]>stations[i].TDR_Vpol_sorted[2]){ - + cout<<"\n"; for(int p=0;p<80;p++) cout<<"*"; cout<<"\n ordering problem (final) Vpol: " @@ -2535,55 +2543,55 @@ int Report::triggerCheckLoop( <<" "<stations[i].TDR_Hpol_sorted[1] || stations[i].TDR_Hpol_sorted[1]>stations[i].TDR_Hpol_sorted[2]){ - + cout<<"\n"; - for(int p=0;p<80;p++) + for(int p=0;p<80;p++) cout<<"*"; cout<<"\n ordering problem (final), Hpol: " <1 and global pass - + for(int trig_j=0;trig_j1){ - + delete [] TDR_all_sorted_temp; delete [] TDR_Vpol_sorted_temp; delete [] TDR_Hpol_sorted_temp; } - - + + return stations[i].Global_Pass; - + } int Report::saveTriggeredEvent( - Settings *settings1, Detector *detector, Event *event, Trigger *trigger, + Settings *settings1, Detector *detector, Event *event, Trigger *trigger, int stationID, int trig_search_init, int max_total_bin, int trig_window_bin, int last_trig_bin ) { - + int i=stationID; int numChan=stations[i].TDR_all.size(); cout<<"saving event"<getStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); - + if(stations[i].strings[string_i].antennas[antenna_i].Trig_Pass){// if this channel triggered - - // Determine which ray and interaciton triggered triggered + + // Determine which ray and interaciton triggered triggered // the station based on signal and trigger bins stations[i].strings[string_i].antennas[antenna_i].Find_Likely_Sol(); int likely_int = stations[i].strings[string_i].antennas[antenna_i].Likely_Sol[0]; int likely_ray = stations[i].strings[string_i].antennas[antenna_i].Likely_Sol[1]; - + if ( settings1->TRIG_ONLY_LOW_CH_ON==0 ) { cout << endl @@ -2619,81 +2627,81 @@ int Report::saveTriggeredEvent( << " noiseID : " << stations[i].strings[string_i].antennas[antenna_i].noise_ID[0]; if (stations[i].strings[string_i].antennas[antenna_i].Likely_Sol[0] != -1) { - cout << " ViewAngle : " + cout << " ViewAngle : " << stations[i].strings[string_i].antennas[antenna_i].view_ang[likely_int][likely_ray] *DEGRAD ; - cout << " LikelyTrigSignal : interaction " + cout << " LikelyTrigSignal : interaction " << stations[i].strings[string_i].antennas[antenna_i].Likely_Sol[0]; - cout << ", ray " + cout << ", ray " << stations[i].strings[string_i].antennas[antenna_i].Likely_Sol[1]; } } else if ( settings1->TRIG_ONLY_LOW_CH_ON==1 ) { - + cout << endl << "trigger passed at bin " << stations[i].strings[string_i].antennas[antenna_i].Trig_Pass - <<" passed ant: str[" << string_i << "].ant[" <stations[i].strings[string_i].antennas[antenna_i].type << "type) Direct dist btw posnu : " << event->Nu_Interaction[0].posnu.Distance( detector->stations[i].strings[string_i].antennas[antenna_i] ) - << " noiseID : " + << " noiseID : " << stations[i].strings[string_i].antennas[antenna_i].noise_ID[0]; if (stations[i].strings[string_i].antennas[antenna_i].Likely_Sol[0] != -1) { - cout << " ViewAngle : " + cout << " ViewAngle : " << stations[i].strings[string_i].antennas[antenna_i].view_ang[likely_int][likely_ray] *DEGRAD ; - cout << " LikelyTrigSignal : interaction " + cout << " LikelyTrigSignal : interaction " << stations[i].strings[string_i].antennas[antenna_i].Likely_Sol[0]; - cout << ", ray " + cout << ", ray " << stations[i].strings[string_i].antennas[antenna_i].Likely_Sol[1]; } - + } - + }// if Trig_Pass - + // now save the voltage waveform to V_mimic for (int mimicbin=0; mimicbin < waveformLength/2; mimicbin++) { // new DAQ waveform writing mechanism test if (settings1->V_MIMIC_MODE == 0) { // Global passed bin is the center of the window - + const int thisBin = last_trig_bin - waveformLength/2 + waveformCenter + mimicbin; - const int thisTimeBin = waveformLength/2 + waveformCenter + mimicbin; - + const int thisTimeBin = waveformLength/2 + waveformCenter + mimicbin; + stations[i].strings[string_i].antennas[antenna_i].V_mimic.push_back( ( trigger->Full_window_V[trig_j][thisBin] )*1.e3 );// save in mV stations[i].strings[string_i].antennas[antenna_i].time.push_back(thisBin); stations[i].strings[string_i].antennas[antenna_i].time_mimic.push_back( thisTimeBin * settings1->TIMESTEP*1.e9 );// save in ns } else if (settings1->V_MIMIC_MODE == 1) { // Global passed bin is the center of the window + delay to each chs from araGeom - + const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin) - waveformLength/2 + waveformCenter + mimicbin; const int thisTimeBin = -(detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin) - waveformLength/2 + waveformCenter + mimicbin; - + stations[i].strings[string_i].antennas[antenna_i].V_mimic.push_back( ( trigger->Full_window_V[trig_j][thisBin] )*1.e3 );// save in mV stations[i].strings[string_i].antennas[antenna_i].time.push_back(thisBin); stations[i].strings[string_i].antennas[antenna_i].time_mimic.push_back( thisTimeBin * settings1->TIMESTEP*1.e9 );// save in ns - + } - + else if (settings1->V_MIMIC_MODE == 2) { // Global passed bin is the center of the window + delay to each chs from araGeom + fitted by eye - const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin - + detector->stations[i].strings[string_i].antennas[antenna_i].manual_delay_bin) - waveformLength/2 + waveformCenter + mimicbin; - const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin + const int thisBin = last_trig_bin - (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin + + detector->stations[i].strings[string_i].antennas[antenna_i].manual_delay_bin) - waveformLength/2 + waveformCenter + mimicbin; + const int thisTimeBin = -1*(detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin + detector->stations[i].strings[string_i].antennas[antenna_i].manual_delay_bin) - waveformLength/2 + waveformCenter + mimicbin; - + stations[i].strings[string_i].antennas[antenna_i].V_mimic.push_back( ( trigger->Full_window_V[trig_j][thisBin] )*1.e3 );// save in mV stations[i].strings[string_i].antennas[antenna_i].time.push_back(thisBin); stations[i].strings[string_i].antennas[antenna_i].time_mimic.push_back( thisTimeBin * settings1->TIMESTEP*1.e9 + detector->params.TestBed_WFtime_offset_ns );// save in ns - + } if (mimicbin == 0) { ///< calculates time of center of each rays signal based on readout window time config for (int interaction_idx=0; interaction_idx < stations[i].strings[string_i].antennas[antenna_i].SignalBin.size(); interaction_idx++){ - for (int m = 0; m < stations[i].strings[string_i].antennas[antenna_i].SignalBin[interaction_idx].size(); m++) { + for (int m = 0; m < stations[i].strings[string_i].antennas[antenna_i].SignalBin[interaction_idx].size(); m++) { double signal_center_offset = (double)( - stations[i].strings[string_i].antennas[antenna_i].SignalBin[interaction_idx][m] - + stations[i].strings[string_i].antennas[antenna_i].SignalBin[interaction_idx][m] - stations[i].strings[string_i].antennas[antenna_i].time[0] ) * settings1->TIMESTEP * 1.e9; double signal_center_time = signal_center_offset + stations[i].strings[string_i].antennas[antenna_i].time_mimic[0]; @@ -2702,65 +2710,65 @@ int Report::saveTriggeredEvent( stations[i].strings[string_i].antennas[antenna_i].SignalBinTime[interaction_idx].push_back(signal_center_time); } } - } - + } + } - - + + // set global_trig_bin values if (settings1->V_MIMIC_MODE == 0) { // Global passed bin is the center of the window stations[i].strings[string_i].antennas[antenna_i].global_trig_bin = waveformLength/2 + waveformCenter ; } else if (settings1->V_MIMIC_MODE == 1) { // Global passed bin is the center of the window + delay to each chs from araGeom - stations[i].strings[string_i].antennas[antenna_i].global_trig_bin = (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin) + stations[i].strings[string_i].antennas[antenna_i].global_trig_bin = (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin) + waveformLength/2 + waveformCenter ; } else if (settings1->V_MIMIC_MODE == 2) { // Global passed bin is the center of the window + delay to each chs from araGeom + fitted by eye - stations[i].strings[string_i].antennas[antenna_i].global_trig_bin = (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin - + detector->stations[i].strings[string_i].antennas[antenna_i].manual_delay_bin) + stations[i].strings[string_i].antennas[antenna_i].global_trig_bin = (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin + + detector->stations[i].strings[string_i].antennas[antenna_i].manual_delay_bin) + waveformLength/2 + waveformCenter ; } - + stations[i].total_trig_search_bin = stations[i].Global_Pass + trig_window_bin - trig_search_init; - + }// for trig_j - - + + if(settings1->OUTPUT_TDR_GRAPH>0){ - + settings1->OUTPUT_TDR_GRAPH--; - + TGraph **gr=new TGraph*[numChan]; - + for(int trig_j=0;trig_jgetStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); int channel_num = detector->GetChannelfromStringAntenna ( i, string_i, antenna_i, settings1 ); double thresh_value=0; - - // assign Pthresh a value + + // assign Pthresh a value double diode_noise_RMS = trigger->GetAntNoise_diodeRMS(channel_num-1, settings1); thresh_value=detector->GetThres(i, channel_num-1, settings1) * diode_noise_RMS * detector->GetThresOffset( i, channel_num-1,settings1); - + gr[trig_j]=new TGraph(); - for(int trig_i=0;trig_iDATA_BIN_SIZE/2;trig_i++) + for(int trig_i=0;trig_iDATA_BIN_SIZE/2;trig_i++) gr[trig_j]->SetPoint(trig_i, (trig_search_init+trig_i), trigger->Full_window[trig_j][trig_i]); - - gr[trig_j]->SetNameTitle(Form("TDR_waveform%dC%02d", settings1->OUTPUT_TDR_GRAPH, trig_j), - Form("Tunnel diode response waveform %d, channel %02d, trig_pass= %d, P_{th}= %le; time bins; power after convolution with tunnel diode", + + gr[trig_j]->SetNameTitle(Form("TDR_waveform%dC%02d", settings1->OUTPUT_TDR_GRAPH, trig_j), + Form("Tunnel diode response waveform %d, channel %02d, trig_pass= %d, P_{th}= %le; time bins; power after convolution with tunnel diode", settings1->OUTPUT_TDR_GRAPH, trig_j, stations[i].strings[string_i].antennas[antenna_i].Trig_Pass, thresh_value)); gr[trig_j]->Write(); delete gr[trig_j]; } - + delete [] gr; - - + + } - + return 1; - + }// saveTriggeredEvent #ifdef ARA_UTIL_EXISTS @@ -2780,11 +2788,11 @@ void Report::MakeUsefulEvent(Detector *detector, Settings *settings1, Trigger *t int antenna_i = detector->getAntennafromArbAntID( stationIndex, ch_loop); int AraRootChannel = 0; AraRootChannel = detector->GetChannelfromStringAntenna (i, string_i, antenna_i, settings1); - + int UsefulEventBin; if ( settings1->NFOUR/2 < EFFECTIVE_LAB3_SAMPLES*2) UsefulEventBin = settings1->NFOUR/2; else UsefulEventBin = EFFECTIVE_LAB3_SAMPLES*2; - + for (int mimicbin=0; mimicbin 0){ theUsefulEvent->fVoltsRF[AraRootChannel-1][mimicbin] = stations[i].strings[string_i].antennas[antenna_i].V_mimic[mimicbin]; @@ -2806,11 +2814,11 @@ void Report::MakeUsefulEvent(Detector *detector, Settings *settings1, Trigger *t int i = stationID; int stationID_AraRoot = settings1->DETECTOR_STATION_ARAROOT; - cout << "StationID: " << stationID << endl; + cout << "StationID: " << stationID << endl; cout << "StationID_AraRoot: " << stationID_AraRoot << endl; theUsefulEvent->fNumChannels = 32; theUsefulEvent->stationId = stationID_AraRoot; - + int ch_limit; if (stationID == 0){ ch_limit = 14; @@ -2819,7 +2827,7 @@ void Report::MakeUsefulEvent(Detector *detector, Settings *settings1, Trigger *t } int maxElecChans = 32; - + for (int ch_loop=0; ch_loop < ch_limit; ch_loop++) { int elecChan = AraGeomTool::Instance()->getElecChanFromRFChan(ch_loop, stationID_AraRoot); int string_i = 0; @@ -2828,7 +2836,7 @@ void Report::MakeUsefulEvent(Detector *detector, Settings *settings1, Trigger *t int AraRootChannel = 0; AraRootChannel = detector->GetChannelfromStringAntenna (stationID, string_i, antenna_i, settings1); - + int UsefulEventBin; UsefulEventBin = settings1->WAVEFORM_LENGTH; @@ -2837,7 +2845,7 @@ void Report::MakeUsefulEvent(Detector *detector, Settings *settings1, Trigger *t volts.resize(UsefulEventBin); vector < double > times; times.resize(UsefulEventBin); - + for (int mimicbin=0; mimicbin 0){ volts[mimicbin] = stations[stationIndex].strings[string_i].antennas[antenna_i].V_mimic[mimicbin]; @@ -2850,7 +2858,7 @@ void Report::MakeUsefulEvent(Detector *detector, Settings *settings1, Trigger *t } theUsefulEvent->fVolts.insert( std::pair < int, std::vector < double > > (elecChan, volts )); theUsefulEvent->fTimes.insert( std::pair < int, std::vector < double > > (elecChan, times )); - + volts.clear(); times.clear(); @@ -2860,7 +2868,7 @@ void Report::MakeUsefulEvent(Detector *detector, Settings *settings1, Trigger *t void Report::ClearUselessfromConnect(Detector *detector, Settings *settings1, Trigger *trigger){ - + for (int i = 0; i< stations.size(); i++) { // now remove all information which are useless for (int c_j=0; c_j< detector->stations[i].strings.size(); c_j++) { @@ -2876,10 +2884,10 @@ void Report::ClearUselessfromConnect(Detector *detector, Settings *settings1, Tr void Report::Convolve_Signals( - Antenna_r *antenna, int channel_index, int station_number, + Antenna_r *antenna, int channel_index, int station_number, Event *event, Settings *settings1, Trigger *trigger, Detector *detector ){ - // For the provided antenna: + // For the provided antenna: // Calculate bin values for the signal and determine if how many rays fit in the readout window // Combine signals from rays and load noise waveforms // Pass the noise+signal waveform through the tunnel diode @@ -2897,8 +2905,8 @@ void Report::Convolve_Signals( for (int m = 0; m < antenna->arrival_time[interaction_idx].size(); m++) { // loop over raysol numbers // Store the bin where the signal is located signal_bin[interaction_idx].push_back( - (antenna->arrival_time[interaction_idx][m] - stations[station_number].min_arrival_time) / (settings1->TIMESTEP) - + settings1->NFOUR *2 + trigger->maxt_diode_bin); + (antenna->arrival_time[interaction_idx][m] - stations[station_number].min_arrival_time) / (settings1->TIMESTEP) + + settings1->NFOUR *2 + trigger->maxt_diode_bin); antenna->SignalBin[interaction_idx].push_back(signal_bin[interaction_idx][m]); } } @@ -2920,18 +2928,18 @@ void Report::Convolve_Signals( GetNoiseThenConvolve( antenna, V_signal, BINSIZE, BINSIZE/2, 0, // waveform_length, this_signalbin, n_connected_rays - channel_index, station_number, + channel_index, station_number, settings1, trigger, detector); - + } // Loop over ray solutions and get signals from each // Loop does not run if there are no ray solutions else { int this_signalbin = 0; - int n_connected_rays = antenna->ray_sol_cnt; + int n_connected_rays = antenna->ray_sol_cnt; vector V_signal; - + // Identify the indices of the last non-empty waveform (to apply final padding inside Combine_Waveforms) // Loop through all interaction indices int last_valid_interaction = -1; // Will store the index of the last interaction with data @@ -2951,7 +2959,7 @@ void Report::Convolve_Signals( for (int interaction_idx=0; interaction_idxV.size(); interaction_idx++){ for (int m = 0; m < signal_bin[interaction_idx].size(); ++m) { - + bool is_last = (interaction_idx == last_valid_interaction) && (m == last_valid_m); // reached the last waveform Combine_Waveforms( @@ -2965,7 +2973,7 @@ void Report::Convolve_Signals( throw runtime_error("Full waveform trace is longer than DATA_BIN_SIZE."); } - // If there are ray solutions, prepare signal wf array with 0s + // If there are ray solutions, prepare signal wf array with 0s // and save an array with the full noise-only waveform to the antenna // Initialize array_length = waveform length + (2*NFOUR + maxt_diode_bin) @@ -2980,8 +2988,8 @@ void Report::Convolve_Signals( GetNoiseThenConvolve( antenna, V_signal, - BINSIZE, this_signalbin, n_connected_rays, - channel_index, station_number, + BINSIZE, this_signalbin, n_connected_rays, + channel_index, station_number, settings1, trigger, detector); } @@ -3002,14 +3010,14 @@ int Antenna_r::Get_Max_SignalBin(){ void Report::Select_Wave_Convlv_Exchange( - vector &V, + vector &V, int BINSIZE, vector *V_signal ) { // Convolve a single signal into the signal array - + // Clear previous waveform data V_signal->clear(); - + // Save the signal voltage waveform for (int bin=0; binpush_back( V[bin] ); @@ -3019,15 +3027,15 @@ void Report::Select_Wave_Convlv_Exchange( void Report::Select_Wave_Convlv_Exchange( - int signalbin_1, int signalbin_2, - vector &V1, vector &V2, + int signalbin_1, int signalbin_2, + vector &V1, vector &V2, int BINSIZE, vector *V_signal ) { // Convolve 2 signals into one signal array - + // Clear previous waveform data V_signal->clear(); - + // Save the signal voltage waveform int signal_dbin = signalbin_2 - signalbin_1; for (int bin=0; bin &V0, vector &V1, vector &V2, + int signalbin_0, int signalbin_1, int signalbin_2, + vector &V0, vector &V1, vector &V2, int BINSIZE, vector *V_signal ) { // Convolve 3 signals into one signal array - - // Clear previous waveform data + + // Clear previous waveform data V_signal->clear(); - + // Save the signal voltage waveform int signal_dbin = signalbin_2 - signalbin_1; int signal_dbin0 = signalbin_1 - signalbin_0; @@ -3092,8 +3100,8 @@ void Report::Select_Wave_Convlv_Exchange( } -void Report::Combine_Waveforms(int signalbin_0, int signalbin_1, - vector V0, vector V1, +void Report::Combine_Waveforms(int signalbin_0, int signalbin_1, + vector V0, vector V1, int* signalbin_combined, vector* V_combined, bool pad_to_power_of_two ) { // adds waveforms V0 & V1 into combined vector V_combined @@ -3111,18 +3119,18 @@ void Report::Combine_Waveforms(int signalbin_0, int signalbin_1, if(V0.empty() && V1.empty()) throw runtime_error("Cannot combine two empty signal vectors!"); - // if one vector is empty, assign its signalbin to that of the other so nothing breaks + // if one vector is empty, assign its signalbin to that of the other so nothing breaks if(V0.empty()) signalbin_0 = signalbin_1; - else if(V1.empty()) + else if(V1.empty()) signalbin_1 = signalbin_0; - // resize to necessary length to combine vectors + // resize to necessary length to combine vectors signalbin = min(signalbin_0, signalbin_1); // starting index in terms of global index const int maxsignalbin = max(signalbin_0+V0.size()-1, signalbin_1+V1.size()-1); // last index in terms of global index const int len = maxsignalbin - signalbin + 1; // length needed to combine both signals V.resize(len, 0); - + // add in the zeroth vector for(unsigned int bin = 0; bin < V0.size(); ++bin) { const int combined_bin = bin + (signalbin_0- signalbin); @@ -3137,7 +3145,7 @@ void Report::Combine_Waveforms(int signalbin_0, int signalbin_1, // for the last added waveform if length is not a power of 2, zero pad if(pad_to_power_of_two && (V.size() & (V.size() - 1)) != 0) { - const int newLen = int(pow(2, ceil(log2(V.size())))); // get next power of 2 + const int newLen = int(pow(2, ceil(log2(V.size())))); // get next power of 2 V.resize(newLen, 0.); } @@ -3147,13 +3155,13 @@ void Report::Combine_Waveforms(int signalbin_0, int signalbin_1, void Report::GetNoiseThenConvolve( Antenna_r *antenna, vector V_signal, - int BINSIZE, int this_signalbin, int n_connected_rays, - int channel_index, int station_number, + int BINSIZE, int this_signalbin, int n_connected_rays, + int channel_index, int station_number, Settings *settings1, Trigger *trigger, Detector *detector ){ - // Get noise waveform, signal waveform, combine them, + // Get noise waveform, signal waveform, combine them, // convolve them through the tunnel diode, apply voltage saturation, - // then save the noise and signals to the + // then save the noise and signals to the // `Antenna_r` object and the `trigger` class // Extend the length of this waveform we're constructing if more than 1 ray connected int wf_length = 0; @@ -3187,7 +3195,7 @@ void Report::GetNoiseThenConvolve( // Get noise-only waveform vector V_noise; GetAntennaNoiseWF( - this_signalbin, wf_length, BINSIZE, channel_index, station_number, &V_noise, + this_signalbin, wf_length, BINSIZE, channel_index, station_number, &V_noise, settings1, trigger, detector); // Create noise+signal waveforms @@ -3217,13 +3225,13 @@ void Report::GetNoiseThenConvolve( trigger->Full_window_V[channel_index][bin] = -1.*settings1->V_SATURATION; } - } + } } void Report::GetAntennaNoiseWF( - int signalbin, + int signalbin, int wf_length, int BINSIZE, int channel_index, int StationIndex, vector *V_noise_only, Settings *settings1, Trigger *trigger, Detector *detector ){ @@ -3244,7 +3252,7 @@ void Report::GetAntennaNoiseWF( else if ( settings1->NOISE_CHANNEL_MODE==1) { noise_wf = &trigger->v_noise_timedomain_ch[ channel_number ]; } - // Only use channel-by-channel temperatures to generate noise for the first 8 channels. + // Only use channel-by-channel temperatures to generate noise for the first 8 channels. // Use the same temperature for the remaining 8. else if ( settings1->NOISE_CHANNEL_MODE==2) { // If this channel is one of the first 8, use channel specific noise @@ -3286,12 +3294,12 @@ void Report::Apply_Gain_Offset(Settings *settings1, Trigger *trigger, Detector * int channel_num = detector->GetChannelfromStringAntenna ( StationIndex, string_num, ant_num, settings1 ); for (int bin=0; binDATA_BIN_SIZE; bin++) { // test for full window - trigger->Full_window[ID][bin] = ( - trigger->Full_window[ID][bin] * detector->GetGainOffset( StationIndex, channel_num-1, settings1 ) - * detector->GetGainOffset( StationIndex, channel_num-1, settings1 ) + trigger->Full_window[ID][bin] = ( + trigger->Full_window[ID][bin] * detector->GetGainOffset( StationIndex, channel_num-1, settings1 ) + * detector->GetGainOffset( StationIndex, channel_num-1, settings1 ) ); // offset in voltage factor so we need power (V^2 factor to diode response) - trigger->Full_window_V[ID][bin] = ( - trigger->Full_window_V[ID][bin] * detector->GetGainOffset( StationIndex, channel_num-1, settings1 ) + trigger->Full_window_V[ID][bin] = ( + trigger->Full_window_V[ID][bin] * detector->GetGainOffset( StationIndex, channel_num-1, settings1 ) ); // gain in voltage factor } @@ -3319,33 +3327,33 @@ Vector Report::GetPolarization (Vector &nnu, Vector &launch_vector) { // Want to find a unit vector in the same plane as // nnu and launch_vector, but perpendicular to launch_vector, pointing away // from nnu. - + // cross nnu with launch_vector to get the direction of the B field. Vector n_bfield = nnu.Cross(launch_vector); - + // cross b-field with nrf2_iceside to get the polarization vector. Vector n_pol = n_bfield.Cross(launch_vector); - + n_pol = n_pol.Unit(); - + // check and make sure E-field is pointing in the right direction. if (nnu*launch_vector>0 && n_pol*nnu>0) cout << "error in GetPolarization. \n"; - + /* * BAC, AC, and JT 2020/11/3 - * + * * We confirmed that we think this calculation is correct up to a minus sign * e.g. outward or inward on the cone depending on whether * one is outside or inside of the cherenkov cone */ - + return n_pol; } //GetPolarization -void Report::GetParameters( - Position &src, Position &trg, Vector &nnu, double &viewangle, double receive_angle, +void Report::GetParameters( + Position &src, Position &trg, Vector &nnu, double &viewangle, double receive_angle, Vector &launch_vector, Vector &receive_vector, Vector &n_trg_slappy, Vector &n_trg_pokey ) { @@ -3354,10 +3362,10 @@ void Report::GetParameters( launch_vector = (trg.Cross( trg.Cross(src) )).Rotate(viewangle, trg.Cross(src)); launch_vector = launch_vector.Unit(); viewangle = launch_vector.Angle(nnu); - + /* * BAC, AC, and JT 2020/11/3 - * + * * n_trg_pokey points from the center of the earth to the antenna location * so for any antenna somewhere on the earth, this points to approximately * the center axis of the antenna @@ -3377,7 +3385,7 @@ void Report::GetParameters( double Report::GaintoHeight(double gain, double freq, double n_medium, double Z_A) { - + return sqrt((gain*CLIGHT*CLIGHT*Zr) / (4*PI*n_medium*freq*freq*Z0)); } @@ -3408,7 +3416,7 @@ double Report::calculatePolFactor(Vector &Pol_vector, int ant_type, double anten void Report::ApplyAntFactors( - double heff, Vector &n_trg_pokey, Vector &n_trg_slappy, Vector &Pol_vector, + double heff, Vector &n_trg_pokey, Vector &n_trg_slappy, Vector &Pol_vector, int ant_type, double &pol_factor, double &vmmhz, double antenna_theta, double antenna_phi ) { // vmmhz is input and output. output will have some antenna factors on it @@ -3418,7 +3426,7 @@ void Report::ApplyAntFactors( // now actually vmmhz is not V/m/MHz but V/m/Hz unit // sqrt(2) for 3dB spliter for TURF, SURF. 1/TIMESTEP moved to MakeArraysforFFT // 1/(1.E6) for V/MHz to V/Hz - vmmhz = vmmhz/sqrt(2.)/(1.E6); + vmmhz = vmmhz/sqrt(2.)/(1.E6); // apply antenna effective height and 0.5 (to calculate power with heff), and polarization factor // not vmmhz is actually V/Hz unit @@ -3428,16 +3436,34 @@ void Report::ApplyAntFactors( } +void Report::ApplyAntFactors_Tdomain( + double AntPhase, double heff, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_real, double &vm_img, + Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode, bool applyInverse +) { + double heff_copol = heff; + double heff_crosspol = 0.0; + double phase_copol = AntPhase; + double phase_crosspol = 0.0; + + ApplyAntFactors_Tdomain( + phase_copol, phase_crosspol, + heff_copol, heff_crosspol, + Pol_vector, ant_type, + pol_factor, vm_real, vm_img, + settings1, antenna_theta, antenna_phi, + freq, useInTransmitterMode, applyInverse); +} + -void Report::ApplyAntFactors_Tdomain ( - double AntPhase, double heff, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, double antenna_theta, double antenna_phi, - double freq, bool useInTransmitterMode, bool applyInverse -) { +void Report::ApplyAntFactors_Tdomain(double phase_copol, double phase_crosspol, double heff_copol, double heff_crosspol, + Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_real, double &vm_img, + Settings *settings1, double antenna_theta, double antenna_phi, double freq, + bool useInTransmitterMode, bool applyInverse +) { /* Report::ApplyAntFactors_Tdomain() - Purpose: + Purpose: Multiply (or divide) voltage in Fourier space by the antenna gain and phase. - + Inputs: AntPhase: Phase of the antenna, usually calculated with Detector::GetAntPhase_1D() heff: Effective height of the antenna, usually calculated with Report::GainToHeight @@ -3452,11 +3478,11 @@ void Report::ApplyAntFactors_Tdomain ( freq: Frequency of the current frequency bin. useInTransmitterMode: Boolean that dictates whether this antenna is in Transmitter mode (Tx) or Receiver mode (Rx) applyInverse: Boolean that dictates if we're applying the antenna factors (projecting E-field onto h to get voltage) or inverting the factors (dividing h out of voltage to get E-field). - + Outputs: New values of the following via pass-by-reference: pol_factor, vm_real, vm_img - + */ double phaseSign = 1.; double amplitudeSign = 1.; @@ -3466,7 +3492,21 @@ void Report::ApplyAntFactors_Tdomain ( if(applyInverse==true){ phaseSign*=-1.; amplitudeSign*=-1;}; //Calculate the polarization factor, which is essentially the vector component of the Electric field that is projected onto the antenna. - pol_factor = calculatePolFactor(Pol_vector, ant_type, antenna_theta, antenna_phi); + //Do both co-pol and cross-pol polarization factors + double pol_factor_copol = calculatePolFactor(Pol_vector, ant_type, antenna_theta, antenna_phi); + double pol_factor_crosspol = calculatePolFactor(Pol_vector, 1 - ant_type, antenna_theta, antenna_phi); + + // Calculate amplitude amplifications from co-pol and cross-pol + double v_amplification_copol = heff_copol * pol_factor_copol; + double v_amplification_crosspol = 0.0; + + //turn on cross-pol for receiver + if (settings1->CROSSPOL_RX){ + v_amplification_crosspol = heff_crosspol * pol_factor_crosspol; + } + + // Add the contributions linearly for Rx + double v_amplification = v_amplification_copol + v_amplification_crosspol; if ( settings1->PHASE_SKIP_MODE != 1 ) { double phase_current; if ( vm_real != 0. ) { @@ -3483,37 +3523,77 @@ void Report::ApplyAntFactors_Tdomain ( else phase_current = 0.; } //Calculate amplitude via the real and imaginary components. - double v_amp = sqrt(vm_real*vm_real + vm_img*vm_img); - //Apply effective height and polarization factors to ampltitude. - v_amp *= pow(heff*pol_factor, amplitudeSign); + double v_amp_in = sqrt(vm_real*vm_real + vm_img*vm_img); + double v_amp = v_amp_in; //save the incomming voltage + // Apply amplitude sign for inversion if necessary + v_amp *= pow(v_amplification, amplitudeSign); //If in transmitter mode, we must apply additional frequency and impedance terms to the amplitude. - if (useInTransmitterMode==true){ + if (useInTransmitterMode==true){ phase_current += PI/2; - // The factors of two in this line are still under consideration, see GitHub Issue #175 - v_amp *= pow(freq/CLIGHT*(Z0/Zr)/4/sqrt(2.), amplitudeSign); + double psi = settings1->CLOCK_ANGLE; + double delta_psi = TMath::ATan(heff_crosspol / heff_copol); // Tx cross-pol tilt + double theta = antenna_theta*PI/180; + double phi = antenna_phi*PI/180; + + //turn on cross-pol Tx + if (settings1->CROSSPOL_TX != 1){ + heff_crosspol = 0.0; //need to be turned off for the calculation of amplitude v_amp + delta_psi = 0.0; // turn off cross-pol tx tilt + } + + //Adjust polarization vector + double newPol_vectorX = -cos(psi+delta_psi)*cos(theta)*cos(phi) + sin(psi+delta_psi)*sin(phi); + double newPol_vectorY = -cos(psi+delta_psi)*cos(theta)*sin(phi) - sin(psi+delta_psi)*cos(phi); + double newPol_vectorZ = cos(psi+delta_psi)*sin(theta); + + Pol_vector = Vector(newPol_vectorX, newPol_vectorY, newPol_vectorZ); + + //copol and cross-pol add quadratically in E-field + v_amp *= pow(freq/CLIGHT*(Z0/Zr)/4/sqrt(2.)*(1/v_amplification)*(sqrt(heff_crosspol* heff_crosspol + heff_copol*heff_copol )), amplitudeSign); } - //Calculate the real and imaginary terms using the new ampltitude and phase. - vm_real = v_amp * cos( phase_current + (phaseSign * AntPhase*RADDEG) ); - vm_img = v_amp * sin( phase_current + (phaseSign * AntPhase*RADDEG) ); + // Calculate the combined real and imaginary terms from co-pol and cross-pol + double vm_real_copol = v_amp_in * (v_amplification_copol * cos(phase_current + (phaseSign * phase_copol * RADDEG))); + double vm_img_copol = v_amp_in * (v_amplification_copol * sin(phase_current + (phaseSign * phase_copol * RADDEG))); + + double vm_real_crosspol = v_amp_in * (v_amplification_crosspol * cos(phase_current + (phaseSign * phase_crosspol * RADDEG))); + double vm_img_crosspol = v_amp_in * (v_amplification_crosspol * sin(phase_current + (phaseSign * phase_crosspol * RADDEG))); + + // Combine co-pol and cross-pol real and imaginary parts + vm_real = vm_real_copol + vm_real_crosspol; + vm_img = vm_img_copol + vm_img_crosspol; } + else { // Amplitude-only mode - else { // only amplitude - vm_real *= pow(heff * pol_factor, amplitudeSign); - vm_img *= pow(heff * pol_factor, amplitudeSign); + vm_real *= pow(v_amplification, amplitudeSign); + vm_img *= pow(v_amplification, amplitudeSign); } } +void Report::ApplyAntFactors_Tdomain_FirstTwo( + double heff, double heff_lastbin, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, + Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode, bool applyInverse +) { + // Default to no cross-pol + double heff_crosspol = 0.0; + double heff_crosspol_lastbin = 0.0; + + ApplyAntFactors_Tdomain_FirstTwo( + heff, heff_lastbin, heff_crosspol, heff_crosspol_lastbin, + Pol_vector, ant_type, pol_factor, vm_bin0, vm_bin1, + settings1, antenna_theta, antenna_phi, freq, useInTransmitterMode, applyInverse); +} -void Report::ApplyAntFactors_Tdomain_FirstTwo ( - double heff, double heff_lastbin, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, double antenna_theta, double antenna_phi, - double freq, bool useInTransmitterMode, bool applyInverse +void Report::ApplyAntFactors_Tdomain_FirstTwo(double heff_copol, double heff_copol_lastbin, double heff_crosspol, + double heff_crosspol_lastbin, Vector &Pol_vector, int ant_type, + double &pol_factor, double &vm_bin0, double &vm_bin1, Settings *settings1, + double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode, + bool applyInverse ) { /* Report::ApplyAntFactors_Tdomain_FirstTwo() - Purpose: + Purpose: Multiply (or divide) first and last bin of voltage in Fourier space by the antenna gain and phase. - + For a more verbose explanation, see Report::ApplyAntFactors_Tdomain. This simply applies the operation to the first and last bin, which much be done separately as a consequence of FFT's. Does not calculate phase. */ @@ -3524,45 +3604,107 @@ void Report::ApplyAntFactors_Tdomain_FirstTwo ( //double pol_factor; pol_factor = calculatePolFactor(Pol_vector, ant_type, antenna_theta, antenna_phi); - //First step in the voltage calculation. Both Tx and Rx mode use this. - vm_bin0 *= pow(heff * pol_factor, amplitudeSign); - vm_bin1 *= pow(heff_lastbin * pol_factor, amplitudeSign); - - if (useInTransmitterMode) { - // The factors of two in these two lines are currently up for debate, see GitHub Issue #175 - vm_bin0 *= pow(freq/CLIGHT*(Z0/(Zr))/4/sqrt(2.), amplitudeSign); - vm_bin1 *= pow(freq/CLIGHT*(Z0/(Zr))/4/sqrt(2.), amplitudeSign); + // Initialize cross-pol amplification factors + double pol_factor_crosspol = 0.0; + double v_amplification_copol_bin0 = heff_copol * pol_factor; + double v_amplification_copol_bin1 = heff_copol_lastbin * pol_factor; + double v_amplification_crosspol_bin0 = 0.0; + double v_amplification_crosspol_bin1 = 0.0; + + // Handle cross-pol factors for receiver mode + if (!useInTransmitterMode && settings1->CROSSPOL_RX) { + pol_factor_crosspol = calculatePolFactor(Pol_vector, 1 - ant_type, antenna_theta, antenna_phi); + v_amplification_crosspol_bin0 = heff_crosspol * pol_factor_crosspol; + v_amplification_crosspol_bin1 = heff_crosspol_lastbin * pol_factor_crosspol; } - else { - vm_bin0 *= pow(heff * pol_factor, amplitudeSign); - vm_bin1 *= pow(heff_lastbin * pol_factor, amplitudeSign); + + // Combine co-pol and cross-pol amplifications + double v_amplification_bin0 = v_amplification_copol_bin0 + v_amplification_crosspol_bin0; + double v_amplification_bin1 = v_amplification_copol_bin1 + v_amplification_crosspol_bin1; + + // Apply amplification for receiver mode + vm_bin0 *= pow(v_amplification_bin0, amplitudeSign); + vm_bin1 *= pow(v_amplification_bin1, amplitudeSign); + + if (useInTransmitterMode) { + // Handle cross-pol factors for transmitter mode + if (settings1->CROSSPOL_TX) { + pol_factor_crosspol = calculatePolFactor(Pol_vector, 1 - ant_type, antenna_theta, antenna_phi); + v_amplification_crosspol_bin0 = heff_crosspol * pol_factor_crosspol; + v_amplification_crosspol_bin1 = heff_crosspol_lastbin * pol_factor_crosspol; + } + + // Co-pol and cross-pol add quadratically in E-field + double tx_amplification_bin0 = freq / CLIGHT * (Z0 / Zr) / 4 / sqrt(2.0) * (1/v_amplification_bin0) * + (sqrt(heff_crosspol * heff_crosspol + heff_copol * heff_copol)); + double tx_amplification_bin1 = freq / CLIGHT * (Z0 / Zr) / 4 / sqrt(2.0) * (1/v_amplification_bin1) * + (sqrt(heff_crosspol_lastbin * heff_crosspol_lastbin + heff_copol_lastbin * heff_copol_lastbin)); + + vm_bin0 *= pow(tx_amplification_bin0, amplitudeSign); + vm_bin1 *= pow(tx_amplification_bin1, amplitudeSign); } + // I don't understand why we had it twice in the original function -ASG 12/09/24 + // else { + // vm_bin0 *= pow(heff * pol_factor, amplitudeSign); + // vm_bin1 *= pow(heff_lastbin * pol_factor, amplitudeSign); + // } + } -void Report::InvertAntFactors_Tdomain ( - double AntPhase, double heff, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, double antenna_theta, double antenna_phi, - double freq, bool useInTransmitterMode -) { - /* Report::InvertAntFactors_Tdomain() - Purpose: Inverts the antenna factors in a convenient way by simply calling ApplyAntFactors with the boolean applyInverse enabled. +void Report::InvertAntFactors_Tdomain( + double AntPhase, double heff, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, + double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode +) { + ApplyAntFactors_Tdomain( + AntPhase, heff, Pol_vector, ant_type, + pol_factor, vm_real, vm_img, + settings1, antenna_theta, antenna_phi, + freq, useInTransmitterMode, true); // applyInverse = true +} + +void Report::InvertAntFactors_Tdomain(double AntPhase_copol, double AntPhase_crosspol, + double heff_copol, double heff_crosspol, + Vector &Pol_vector, int ant_type, + double &pol_factor, double &vm_real, double &vm_img, + Settings *settings1, double antenna_theta, + double antenna_phi, double freq, + bool useInTransmitterMode) { + /* Report::InvertAntFactors_Tdomain_new() + Purpose: Inverts the antenna factors for both co-polarization and cross-polarization + by simply calling ApplyAntFactors_Tdomain_new with the boolean applyInverse enabled. */ - ApplyAntFactors_Tdomain (AntPhase, heff, Pol_vector, ant_type, pol_factor, vm_real, vm_img, settings1, antenna_theta, antenna_phi, freq, useInTransmitterMode, true); + ApplyAntFactors_Tdomain(AntPhase_copol, AntPhase_crosspol, heff_copol, heff_crosspol, + Pol_vector, ant_type, pol_factor, vm_real, vm_img, + settings1, antenna_theta, antenna_phi, freq, useInTransmitterMode, true); } +void Report::InvertAntFactors_Tdomain_FirstTwo( + double heff, double heff_lastbin, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, + double &vm_bin1, Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode +) { + ApplyAntFactors_Tdomain_FirstTwo( + heff, heff_lastbin, + Pol_vector, ant_type, pol_factor, vm_bin0, vm_bin1, + settings1, antenna_theta, antenna_phi, freq, + useInTransmitterMode, true); +} -void Report::InvertAntFactors_Tdomain_FirstTwo ( - double heff, double heff_lastbin, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, double antenna_theta, double antenna_phi, - double freq, bool useInTransmitterMode -) { - /* Report::InvertAntFactors_Tdomain_FirstTwo() - Purpose: Inverts the antenna factors in a convenient way by simply calling ApplyAntFactors with the boolean applyInverse enabled. +void Report::InvertAntFactors_Tdomain_FirstTwo(double heff_copol, double heff_copol_lastbin, + double heff_crosspol, double heff_crosspol_lastbin, + Vector &Pol_vector, int ant_type, + double &pol_factor, double &vm_bin0, double &vm_bin1, + Settings *settings1, double antenna_theta, double antenna_phi, double freq, + bool useInTransmitterMode) { + /* Report::InvertAntFactors_Tdomain_FirstTwo_new() + Purpose: Inverts the antenna factors for both co-polarization and cross-polarization + by simply calling ApplyAntFactors_Tdomain_FirstTwo_new with the boolean applyInverse enabled. */ - ApplyAntFactors_Tdomain_FirstTwo (heff, heff_lastbin, Pol_vector, ant_type, pol_factor, vm_bin0, vm_bin1, antenna_theta, antenna_phi, freq, useInTransmitterMode, true); + ApplyAntFactors_Tdomain_FirstTwo(heff_copol, heff_copol_lastbin, heff_crosspol, heff_crosspol_lastbin, + Pol_vector, ant_type, pol_factor, vm_bin0, vm_bin1, + settings1, antenna_theta, antenna_phi, freq, useInTransmitterMode, true); } @@ -3602,11 +3744,11 @@ void Report::ApplyFilter_OutZero (double freq, Detector *detector, double &vmmhz } -void Report::ApplyElect_Tdomain(double freq, Detector *detector, double &vm_real, double &vm_img, int gain_ch_no, Settings *settings1, bool applyInverse) { +void Report::ApplyElect_Tdomain(double freq, Detector *detector, double &vm_real, double &vm_img, int gain_ch_no, Settings *settings1, bool applyInverse) { /* Report::ApplyElect_Tdomain() - Purpose: + Purpose: Multiply (or divide) voltage in Fourier space by the electronics gain and phase. - + Inputs: freq: Frequency of the current frequency bin. detector: ARA detector object, which contains the config and antenna info to look up the gain and phase. @@ -3615,16 +3757,16 @@ void Report::ApplyElect_Tdomain(double freq, Detector *detector, double &vm_real gain_ch_no: Integer that represents the RF channel of the antenna, so that it can look up the gain and phase info. settings1: The ARA settings object containing the setup of the simulation or detector. applyInverse: Boolean that dictates if we're applying the electronics factors or inverting the factors. - + Outputs: New values of the following via pass-by-reference: vm_real, vm_img - + */ double phaseSign = 1.; double amplitudeSign = 1.; - // If using this function to invert the electronics response, we apply a minus sign the phase in order to undo the - // phase applied by the electronics. We also divide the amplitude by the factor rather than multiply. + // If using this function to invert the electronics response, we apply a minus sign the phase in order to undo the + // phase applied by the electronics. We also divide the amplitude by the factor rather than multiply. // To do this, we simply apply a -1 to the power of the factor applied to the amplitude so that it is divided out. if(applyInverse==true){ phaseSign*=-1.; amplitudeSign*=-1;}; @@ -3650,7 +3792,7 @@ void Report::ApplyElect_Tdomain(double freq, Detector *detector, double &vm_real } // V amplitude, apply gain (unitless) to amplitude - double v_amp = sqrt(vm_real*vm_real + vm_img*vm_img) * pow(detector->GetElectGain_1D_OutZero( freq, gain_ch_no ),amplitudeSign); + double v_amp = sqrt(vm_real*vm_real + vm_img*vm_img) * pow(detector->GetElectGain_1D_OutZero( freq, gain_ch_no ),amplitudeSign); vm_real = v_amp * cos( phase_current - phaseSign*detector->GetElectPhase_1D(freq, gain_ch_no) ); vm_img = v_amp * sin( phase_current - phaseSign*detector->GetElectPhase_1D(freq, gain_ch_no ) ); @@ -3662,7 +3804,7 @@ void Report::ApplyElect_Tdomain(double freq, Detector *detector, double &vm_real vm_img = vm_img * pow(detector->GetElectGain_1D_OutZero( freq, gain_ch_no),amplitudeSign); // only amplitude } - + //Apply power splitter/attenuator based on station. ApplySplitterFactor(vm_real, vm_img, detector, settings1, applyInverse); @@ -3677,16 +3819,16 @@ void Report::ApplyElect_Tdomain_FirstTwo( ) { // read elect chain gain (unitless), phase (rad) and apply to V/m /* Report::ApplyElect_Tdomain_FirstTwo() - Purpose: + Purpose: Multiply (or divide) first two bins of voltage in Fourier space by the electronics gain and phase. - - For a more verbose explanation, see Report::ApplyElect_Tdomain. - This simply applies the operation to the first and last bin, which much be done separately as a consequence of FFT's. + + For a more verbose explanation, see Report::ApplyElect_Tdomain. + This simply applies the operation to the first and last bin, which much be done separately as a consequence of FFT's. Does not calculate phase. */ double amplitudeSign = 1.; - // If using this function to invert the electronics response, we apply a minus sign the phase in order to undo the - // phase applied by the electronics. We also divide the amplitude by the factor rather than multiply. + // If using this function to invert the electronics response, we apply a minus sign the phase in order to undo the + // phase applied by the electronics. We also divide the amplitude by the factor rather than multiply. // To do this, we simply apply a -1 to the power of the factor applied to the amplitude so that it is divided out. if(applyInverse==true){amplitudeSign*=-1;}; @@ -3699,12 +3841,12 @@ void Report::ApplyElect_Tdomain_FirstTwo( void Report::ApplySplitterFactor(double &vm_real, double &vm_img, Detector* detector, Settings *settings1, bool applyInverse) { // Apply splitter/attenuation factor in the digitizer path based on station. - + // If we wish to invert the splitter factor, we must divide the factor out rather than multiply. To accomplish this, // we simply raise the factor to the -1 power in the multiplication step. double amplitudeSign=1; - if (applyInverse==true){amplitudeSign*=-1;}; - + if (applyInverse==true){amplitudeSign*=-1;}; + const double factor = detector->GetSplitterFactor(settings1); vm_real *= pow(factor, amplitudeSign); @@ -3721,7 +3863,7 @@ void Report::InvertElect_Tdomain( Purpose: Inverts the electronics factors in a convenient way by simply calling ApplyElecFactors with the boolean applyInverse enabled. */ ApplyElect_Tdomain(freq, detector, vm_real, vm_img, gain_ch_no, settings1, true); - + } void Report::InvertElect_Tdomain_FirstTwo( @@ -3732,7 +3874,7 @@ void Report::InvertElect_Tdomain_FirstTwo( Purpose: Inverts the electronics factors in a convenient way by simply calling ApplyElecFactors with the boolean applyInverse enabled. */ ApplyElect_Tdomain_FirstTwo(freq0, freq1, detector, vm_bin0, vm_bin1, gain_ch_no, settings1, true); - + } @@ -3805,33 +3947,33 @@ void Report::ApplyRFCM_OutZero(int ch, double freq, Detector *detector, double & } void Report::ApplyNoiseFig_databin(int ch, int bin_n, Detector *detector, double &vmmhz, Settings *settings1) { // read noise figure and apply unitless gain to vmmhz - + double tempNoise = vmmhz*vmmhz; if(detector->GetNoiseFig_databin(ch,bin_n)>1.0){ - vmmhz = TMath::Sqrt( tempNoise*(detector->GetTransm_databin(ch, bin_n)) + tempNoise/(settings1->NOISE_TEMP)*220.0*(detector->GetNoiseFig_databin(ch,bin_n) - 1.0) ) ; + vmmhz = TMath::Sqrt( tempNoise*(detector->GetTransm_databin(ch, bin_n)) + tempNoise/(settings1->NOISE_TEMP)*220.0*(detector->GetNoiseFig_databin(ch,bin_n) - 1.0) ) ; } else{ vmmhz = vmmhz; } - return; + return; } void Report::ApplyNoiseFig_OutZero(int ch, double freq, Detector *detector, double &vmmhz, Settings *settings1) { // read noise figure and apply unitless gain to vmmhz double tempNoise = vmmhz*vmmhz; - + if(detector->GetNoiseFig_OutZero(ch, freq)>1.0){ - vmmhz = TMath::Sqrt( tempNoise*(detector->GetTransm_OutZero(ch, freq)) + tempNoise/(settings1->NOISE_TEMP)*220.0*(detector->GetNoiseFig_OutZero(ch, freq) - 1.0) ) ; + vmmhz = TMath::Sqrt( tempNoise*(detector->GetTransm_OutZero(ch, freq)) + tempNoise/(settings1->NOISE_TEMP)*220.0*(detector->GetNoiseFig_OutZero(ch, freq) - 1.0) ) ; } else{ vmmhz = vmmhz; } - + return; } -void Report::GetAngleAnt(Vector &rec_vector, Position &antenna, double &ant_theta, double &ant_phi) { //ant_theta and ant_phi is in degree +void Report::GetAngleAnt(Vector &rec_vector, Position &antenna, double &ant_theta, double &ant_phi) { //ant_theta and ant_phi is in degree /* * 2020-12-07 BAC @@ -3851,16 +3993,16 @@ void Report::GetAngleAnt(Vector &rec_vector, Position &antenna, double &ant_thet } void Report::GetAngleLaunch(Vector &launch_vector, double &launch_theta, double &launch_phi) { - + /* - Takes the launch vector of the signal and calculates the theta and phi of the launch vector in the + Takes the launch vector of the signal and calculates the theta and phi of the launch vector in the station-centric coordinates and returns them in degrees; where theta=0 is along the upward vertical axis, theta=90 is along the horizon, and theta=180 is along the downward vertical axis. - - This is necessary because for source reconstruction, we need the launch vector of the RF signal in + + This is necessary because for source reconstruction, we need the launch vector of the RF signal in conjunction with the polarization to find the neutrino trajectory. */ - + launch_theta = launch_vector.Theta() * TMath::RadToDeg(); launch_phi = launch_vector.Phi() * TMath::RadToDeg(); @@ -3965,7 +4107,7 @@ void Report::GetNoiseWaveforms_ch(Settings * settings1, Detector * detector, dou if (settings1 -> APPLY_NOISE_FIGURE == 1) { ApplyNoiseFig_OutZero(ch % 16, freq, detector, V_tmp, settings1); } - } + } else if (settings1 -> USE_TESTBED_RFCM_ON == 1) { const double dfreq = 1./(settings1->DATA_BIN_SIZE * settings1->TIMESTEP * (1.E6)); // from Hz to MHz; const double freq = k*dfreq; @@ -4000,7 +4142,7 @@ void Report::GetNoiseWaveforms_ch(Settings * settings1, Detector * detector, dou Vfft_noise_after.clear(); // remove previous Vfft_noise values Vfft_noise_before.clear(); // remove previous Vfft_noise values - + Vfft_noise_after.resize(settings1->DATA_BIN_SIZE); Vfft_noise_before.resize(settings1->DATA_BIN_SIZE/2); @@ -4027,7 +4169,7 @@ void Report::GetNoiseWaveforms_ch(Settings * settings1, Detector * detector, dou V_tmp = detector -> GetRayleighFit_databin(ch, k) * sqrt((double) settings1 -> DATA_BIN_SIZE / (double)(settings1 -> NFOUR / 2.)); // use real value array value, extra 1/1.177 to make total power same with "before random_rician". - Tools::get_random_rician(0., 0., V_tmp, current_amplitude, current_phase); + Tools::get_random_rician(0., 0., V_tmp, current_amplitude, current_phase); } else { @@ -4052,7 +4194,7 @@ void Report::GetNoiseWaveforms_ch(Settings * settings1, Detector * detector, dou current_phase = noise_phase[k]; // use real value array value, extra 1/1.177 to make total power same with "before random_rician". - Tools::get_random_rician(0., 0., sqrt(2. / M_PI) / 1.177 * V_tmp, current_amplitude, current_phase); + Tools::get_random_rician(0., 0., sqrt(2. / M_PI) / 1.177 * V_tmp, current_amplitude, current_phase); } @@ -4101,7 +4243,7 @@ void Report::GetNoiseWaveforms_ch(Settings * settings1, Detector * detector, dou V_tmp *= sqrt(this_delta_f); // draw a random number from the distribution with this rayleigh fit parameter - Tools::get_random_rician(0., 0., V_tmp, current_amplitude, current_phase); + Tools::get_random_rician(0., 0., V_tmp, current_amplitude, current_phase); // set the real and imaginary components of the FFT vnoise[2 * k] = (current_amplitude) * cos(noise_phase[k]); @@ -4117,7 +4259,7 @@ void Report::GetNoiseWaveforms_ch(Settings * settings1, Detector * detector, dou } - // real FT back to get vnoise in time domain waveform; + // real FT back to get vnoise in time domain waveform; Tools::realft(vnoise, -1, settings1 -> DATA_BIN_SIZE); } @@ -4147,18 +4289,18 @@ void Report::GetNoiseWaveforms_ch(Settings * settings1, Detector * detector, dou Vfft_noise_before[k] = fits_for_this_station[ch][k]; current_phase = noise_phase[k]; V_tmp = fits_for_this_station[ch][k]; - + // the right normalization factor is N * sqrt(deltaF) V_tmp *= double(settings1->DATA_BIN_SIZE); V_tmp *= sqrt(this_delta_f); // draw a random number from the distribution with this rayleigh fit parameter - Tools::get_random_rician(0., 0., V_tmp, current_amplitude, current_phase); + Tools::get_random_rician(0., 0., V_tmp, current_amplitude, current_phase); // set the real and imaginary components of the FFT vnoise[2 * k] = (current_amplitude) * cos(noise_phase[k]); vnoise[2 * k + 1] = (current_amplitude) * sin(noise_phase[k]); - + // stash those values Vfft_noise_after[2*k] = vnoise[2 * k]; Vfft_noise_after[2*k + 1] = vnoise[2 * k + 1]; @@ -4169,7 +4311,7 @@ void Report::GetNoiseWaveforms_ch(Settings * settings1, Detector * detector, dou } - // real FT back to get vnoise in time domain waveform; + // real FT back to get vnoise in time domain waveform; Tools::realft(vnoise, -1, settings1 -> DATA_BIN_SIZE); } @@ -4191,19 +4333,19 @@ void Report::GetNoisePhase(Settings *settings1) { for (int i=0; iDATA_BIN_SIZE/2; i++) { // noise with DATA_BIN_SIZE bin array noise_phase[i] = 2*PI*gRandom->Rndm(); // get random phase for flat thermal noise } - + } void Report::Prepare_Antenna_Noise( - int debugmode, int channel_index, + int debugmode, int channel_index, int station_number, int string_number, int antenna_number, Settings *settings1, Trigger *trigger, Detector *detector ){ // Determine which noise waveforms from the trigger class we'd like to use // for each antenna then export said waveforms into trigger->Full_window - // and trigger->Full_window_V + // and trigger->Full_window_V for (int l = 0; l < N_noise; l++) { @@ -4247,7 +4389,7 @@ void Report::Prepare_Antenna_Noise( k_sub==1 // 2nd antenna that doesn't exist but this block of code expects it to ) { continue; - } + } // check only first one for now;;; if (noise_ID[l] == stations[station_number].strings[j_sub].antennas[k_sub].noise_ID[0]) @@ -4340,7 +4482,7 @@ void Report::Prepare_Antenna_Noise( ][ noise_ID[l] ][ bin ] ); } } - + } // end NOISE_CHANNEL_MODE 1 // Export noise generated where first 8 channels have their own temperatures and the remaining 8 share one temperature @@ -4410,7 +4552,7 @@ void Report::Prepare_Antenna_Noise( } } - } + } } // end consideration for all other NOISE_CHANNEL_MODE options @@ -4437,39 +4579,39 @@ void Report::MakeArraysforFFT(Settings *settings1, Detector *detector, int Stati int iprevious=0; int ifirstnonzero=-1; int ilastnonzero=2000; - + for (int i=0;iGetFreqBin();i++) { - + // freq_forfft has NFOUR/2 elements because it is meant to cover real and imaginary values // but there are only NFOUR/4 different values // it's the index among the NFOUR/4 that we're interested in int ifour=Tools::Getifreq(detector->GetFreq(i),detector->freq_forfft[0],detector->freq_forfft[NFOUR/2-1],NFOUR/4); - + if (ifour!=-1 && 2*ifour+1AVZ_NORM_FACTOR_MODE == 1) { // use new (fixed) normalization factors - + double dF = 1. / ((double)(NFOUR/2) * TIMESTEP); // in Hz - + double dF_org = detector->GetFreq(1) - detector->GetFreq(0); // in Hz - + double dF_factor = 1.; - + int Norg = detector->GetFreqBin(); - + double FreqOrg[Norg+1]; double VmMHzOrg[Norg+1]; - + double FreqNFOUR[NFOUR/4+1]; // one more bin double VmMHzNFOUR[NFOUR/4+1]; // one more bin - + for (int i=0;iGetFreq(i-1); } - + } - + for (int ifour=0;ifourPHASE*PI/180.); vsignal_forfft[2*ifour+1]*=sin(settings1->PHASE*PI/180.); } - + // first and last freq bin read values to 0, 1 bin vsignal_forfft[0] = VmMHzNFOUR[0] * 2/((double)NFOUR/2) * dF_factor / TIMESTEP; vsignal_forfft[1] = VmMHzNFOUR[NFOUR/4] * 2/((double)NFOUR/2) * dF_factor / TIMESTEP; } - + } @@ -4556,44 +4698,44 @@ void Report::MakeArraysforFFT(Settings *settings1, Detector *detector, int Stati if (settings1->AVZ_NORM_FACTOR_MODE == 0) { // use previous normalization factors - + double previous_value_e_even=0.; double previous_value_e_odd=0.; int count_nonzero=0; int iprevious=0; int ifirstnonzero=-1; int ilastnonzero=2000; - + for (int i=0;iGetFreqBin();i++) { - + // freq_forfft has NFOUR/2 elements because it is meant to cover real and imaginary values // but there are only NFOUR/4 different values // it's the index among the NFOUR/4 that we're interested in int ifour=Tools::Getifreq(detector->GetFreq(i),detector->freq_forfft[0],detector->freq_forfft[NFOUR/2-1],NFOUR/4); - + if (ifour!=-1 && 2*ifour+1AVZ_NORM_FACTOR_MODE == 1) { // use new (fixed) normalization factors - + double dF = 1. / ((double)(NFOUR/2) * TIMESTEP); // in Hz - + double dF_org = detector->GetFreq(1) - detector->GetFreq(0); // in Hz - + double dF_factor = 1.; - + int Norg = detector->GetFreqBin(); - + double FreqOrg[Norg+1]; double VmMHzOrg[Norg+1]; - + double FreqNFOUR[NFOUR/4+1]; // one more bin double VmMHzNFOUR[NFOUR/4+1]; // one more bin - + for (int i=0;iGetFreq(i-1); } - + } - + for (int ifour=0;ifourPHASE*PI/180.); vsignal_forfft[2*ifour+1]*=sin(settings1->PHASE*PI/180.); } - + // first and last freq bin read values to 0, 1 bin vsignal_forfft[0] = VmMHzNFOUR[0] * 2/((double)NFOUR/2) * dF_factor / TIMESTEP; vsignal_forfft[1] = VmMHzNFOUR[NFOUR/4] * 2/((double)NFOUR/2) * dF_factor / TIMESTEP; @@ -4680,7 +4822,7 @@ void Report::MakeArraysforFFT_noise(Settings *settings1, Detector *detector, int double TIMESTEP = settings1->TIMESTEP; Tools::Zero(vsignal_forfft,NFOUR/2); - + double previous_value_e_even=0.; double previous_value_e_odd=0.; int count_nonzero=0; @@ -4689,37 +4831,37 @@ void Report::MakeArraysforFFT_noise(Settings *settings1, Detector *detector, int int ilastnonzero=2000; for (int i=0;iGetFreqBin();i++) { - + // freq_forfft has NFOUR/2 elements because it is meant to cover real and imaginary values // but there are only NFOUR/4 different values // it's the index among the NFOUR/4 that we're interested in int ifour=Tools::Getifreq(detector->GetFreq(i),detector->freq_forfft[0],detector->freq_forfft[NFOUR/2-1],NFOUR/4); - + if (ifour!=-1 && 2*ifour+1 0 && stations[i].strings[j].antennas[k].PeakV[n][0] != 0. ) { @@ -4898,121 +5040,121 @@ int Report::GetChannelNum8_LowAnt(int string_num, int antenna_num) { TGraph *Report::getWaveform(Detector *detector, int ch, int station_i, int event_num, int run_num){ - + int string_i = detector->getStringfromArbAntID( station_i, ch); int antenna_i = detector->getAntennafromArbAntID( station_i, ch); - + TGraph *gr=new TGraph(); - + int N=stations[station_i].strings[string_i].antennas[antenna_i].V_mimic.size(); - + for(int i=0;iSetPoint(i,stations[station_i].strings[string_i].antennas[antenna_i].time_mimic[i], stations[station_i].strings[string_i].antennas[antenna_i].V_mimic[i]); - + }// for i - + gr->SetNameTitle(Form("WF%dS%02dC%02d", event_num, station_i, ch), Form("Simulated waveform %d, station %d, channel %d;time (ns); voltage (mV)", event_num, station_i, ch)); - + return gr; - + } vector Report::getWaveformVector(Detector *detector, int station_i, int event_num, int run_num){ vector waveforms; - + for(int ch=0;chstations[station_i].number_of_antennas; ch++){ - + int string_i = detector->getStringfromArbAntID( station_i, ch); int antenna_i = detector->getAntennafromArbAntID( station_i, ch); - + TGraph *gr=new TGraph(); - + int N=stations[station_i].strings[string_i].antennas[antenna_i].V_mimic.size(); - + for(int i=0;iSetPoint(i,stations[station_i].strings[string_i].antennas[antenna_i].time_mimic[i], stations[station_i].strings[string_i].antennas[antenna_i].V_mimic[i]); - + }// for i - + gr->SetNameTitle(Form("WF%dS%02dC%02d", event_num, station_i, ch), Form("Simulated waveform %d, station %d, channel %d;time (ns); voltage (mV)", event_num, station_i, ch)); - + waveforms.push_back(gr); - + }// for ch - + return waveforms; - + } vector Report::getWaveformVectorVpol(Detector *detector, int station_i, int event_num, int run_num){ - + vector waveforms; - + for(int ch=0;chstations[station_i].number_of_antennas; ch++){ - + int string_i = detector->getStringfromArbAntID( station_i, ch); int antenna_i = detector->getAntennafromArbAntID( station_i, ch); - + if(detector->stations[station_i].strings[string_i].antennas[antenna_i].type!=0) continue; // jump to next channel if this isn't Vpol - + TGraph *gr=new TGraph(); - + int N=stations[station_i].strings[string_i].antennas[antenna_i].V_mimic.size(); - + for(int i=0;iSetPoint(i,stations[station_i].strings[string_i].antennas[antenna_i].time_mimic[i], stations[station_i].strings[string_i].antennas[antenna_i].V_mimic[i]); - + }// for i - + gr->SetNameTitle(Form("WF%dS%02dC%02d", event_num, station_i, ch), Form("Simulated waveform %d, station %d, channel %d;time (ns); voltage (mV)", event_num, station_i, ch)); - + waveforms.push_back(gr); - + }// for ch - + return waveforms; - + } vector Report::getWaveformVectorHpol(Detector *detector, int station_i, int event_num, int run_num){ - + vector waveforms; - + for(int ch=0;chstations[station_i].number_of_antennas; ch++){ - + int string_i = detector->getStringfromArbAntID( station_i, ch); int antenna_i = detector->getAntennafromArbAntID( station_i, ch); - + if(detector->stations[station_i].strings[string_i].antennas[antenna_i].type!=1) continue; // jump to next channel if this isn't Hpol - + TGraph *gr=new TGraph(); - + int N=stations[station_i].strings[string_i].antennas[antenna_i].V_mimic.size(); - + for(int i=0;iSetPoint(i,stations[station_i].strings[string_i].antennas[antenna_i].time_mimic[i], stations[station_i].strings[string_i].antennas[antenna_i].V_mimic[i]); - + }// for i - + gr->SetNameTitle(Form("WF%dS%02dC%02d", event_num, station_i, ch), Form("Simulated waveform %d, station %d, channel %d;time (ns); voltage (mV)", event_num, station_i, ch)); - + waveforms.push_back(gr); - + }// for ch - + return waveforms; - + } int Report::getNumOfSignalledAnts(Station_r station){ - // Count and return the number of antennas in the provided station that + // Count and return the number of antennas in the provided station that // have waveforms, from signal only, that exceed 0.0 int ants_with_good_signal = 0; @@ -5020,24 +5162,24 @@ int Report::getNumOfSignalledAnts(Station_r station){ for ( // loop over each string in the station int s = 0; s < station.strings.size(); s++ - ) { + ) { for ( // loop over each antenna on the string int a = 0; a < station.strings[s].antennas.size(); a++ - ) { + ) { - double max_signal = 0.0; + double max_signal = 0.0; - // If there are ray solutions to this antenna, get the max + // If there are ray solutions to this antenna, get the max // (of the absolute) value of their signal-only waveforms if ( station.strings[s].antennas[a].ray_sol_cnt > 0 ){ - for (int n=0; n 0.0){ + if ( max_signal > 0.0){ ants_with_good_signal++; summary.push_back(max_signal); } @@ -5063,7 +5205,7 @@ int Report::getNumOfSignalledAnts(Station_r station){ } // end loop over strings on the antenna return ants_with_good_signal; - + } double Report::get_SNR(vector signal_array, vector noise_array){ @@ -5098,13 +5240,13 @@ double Report::get_SNR(vector signal_array, vector noise_array){ rms = sqrt( rms / noise_array.size() ); // Catch potential errors - if ( (p2p==-20000000.) || (p2p!=p2p) ){ + if ( (p2p==-20000000.) || (p2p!=p2p) ){ // if p2p is original value or nan cerr<<"In Report::get_SNR, peak-to-peak not calculated correctly. "; cerr<<"Will set peak-to-peak to 0."<TRIG_ANALYSIS_MODE == 2) { // Noise only triggers - avgSnr = pa_force_trigger_snr; + avgSnr = pa_force_trigger_snr; } - else { + else { // Estimate average SNR in topmost vpol if( waveform.size() > 0 ) { - // it as the noise WF to get_SNR() (since the RMS of an + // it as the noise WF to get_SNR() (since the RMS of an // array with one element is the absolute value of that element) vector tmp_noise_RMS; double ant_noise_voltage_RMS = trigger->GetAntNoise_voltageRMS(ch_ID, settings); tmp_noise_RMS.push_back( ant_noise_voltage_RMS ); - // Calculate SNR in this antenna using trace w/o noise since - // this SNR is used with a signal-only SNR efficiency curve + // Calculate SNR in this antenna using trace w/o noise since + // this SNR is used with a signal-only SNR efficiency curve // to estimate trigger likelihood - avgSnr = get_SNR( + avgSnr = get_SNR( waveform, tmp_noise_RMS); } @@ -5162,7 +5304,7 @@ bool Report::isTrigger( trigger->snr_PA, trigger->eff_PA, // x and y coordinates of curve to interpolate avgSnr, // x value to interpolate y value for (*(&trigger->snr_PA+1) - trigger->snr_PA) - 1 // len(snr_PA) - 1 - ); + ); if (avgSnr > 0.5){ if (eff >= 1.0){ @@ -5184,7 +5326,7 @@ int Report::get_PA_trigger_bin( int ch_ID, Antenna_r *antenna, vector waveform, double randNum, Settings *settings, Trigger *trigger ){ - // From the given waveform, find and return the starting index of the + // From the given waveform, find and return the starting index of the // first 10.7 ns time window with an SNR that triggers the PA. // Return -1 if no 10.7 ns time window triggers the PA @@ -5204,14 +5346,14 @@ int Report::get_PA_trigger_bin( // Get this 10.7ns snapshot of waveform and find the bin with greatest absolute value vector waveform_window(waveform.begin()+bin, waveform.begin()+bin+trigger_window_bins); - int bin_max_value = + int bin_max_value = (TMath::MaxElement(trigger_window_bins, &waveform_window[0]) > -1* TMath::MinElement(trigger_window_bins, &waveform_window[0]))? - TMath::LocMax(trigger_window_bins, &waveform_window[0]) + TMath::LocMax(trigger_window_bins, &waveform_window[0]) : TMath::LocMin(trigger_window_bins, &waveform_window[0]); // Bin (in waveform_window) with the greatest absolute value - // Identify the ray solution that arrived closest to bin with the + // Identify the ray solution that arrived closest to bin with the // greatest absolute value in this 10.7ns window. - int Likely_Sol[2] = {0, 0}; // Initialize to direct ray + int Likely_Sol[2] = {0, 0}; // Initialize to direct ray int mindBin = 1.e9; // Minimum difference between this bin and a ray solutions signal_bin. // Initialized unphysically large. int dBin = 0; // Difference between this bin and some ray solution's signal bin. @@ -5220,30 +5362,30 @@ int Report::get_PA_trigger_bin( if ( antenna->SignalExt[n][m] ) { dBin = abs( antenna->SignalBin[n][m] - bin_max_value ); if ( dBin < mindBin ) { - Likely_Sol[0] = n; - Likely_Sol[1] = m; - mindBin = dBin; + Likely_Sol[0] = n; + Likely_Sol[1] = m; + mindBin = dBin; } - } - } - } + } + } + } // Scale SNR according to full phased array angular response double avgSnr = 0.; if(settings->TRIG_ANALYSIS_MODE == 2) { // Noise only triggers - avgSnr = pa_force_trigger_snr; + avgSnr = pa_force_trigger_snr; } - else { + else { // Estimate average SNR in topmost vpol if( waveform.size() > 0 ) { - // it as the noise WF to get_SNR() (since the RMS of an + // it as the noise WF to get_SNR() (since the RMS of an // array with one element is the absolute value of that element) vector tmp_noise_RMS; double ant_noise_voltage_RMS = trigger->GetAntNoise_voltageRMS(ch_ID, settings); tmp_noise_RMS.push_back( ant_noise_voltage_RMS ); - - // Calculate SNR in this antenna using trace w/o noise since - // this SNR is used with a signal-only SNR efficiency curve + + // Calculate SNR in this antenna using trace w/o noise since + // this SNR is used with a signal-only SNR efficiency curve // to estimate trigger likelihood avgSnr = get_SNR(waveform_window, tmp_noise_RMS); } @@ -5251,7 +5393,7 @@ int Report::get_PA_trigger_bin( avgSnr = 0.0; } } - + // Scale SNR with respect to the antenna's viewing angle of the signal const double viewangle = antenna->theta_rec[Likely_Sol[0]][Likely_Sol[1]] * 180.0/PI - 90.0 ; double snr_50 = interpolate( @@ -5260,13 +5402,13 @@ int Report::get_PA_trigger_bin( (*(&trigger->angle_PA+1) - trigger->angle_PA) - 1 // len(ang_data) - 1 ); avgSnr = avgSnr*2.0/snr_50; - + // Estimate the PA signal efficiency of for this SNR from curve of efficiency vs data double eff = interpolate( trigger->snr_PA, trigger->eff_PA, // x and y coordinates of curve to interpolate avgSnr, // x value to interpolate y value for (*(&trigger->snr_PA+1) - trigger->snr_PA) - 1 // len(snr_PA) - 1 - ); + ); // If the PA triggers on this SNR, return the starting bin of this window if (avgSnr > 0.5){ @@ -5288,12 +5430,12 @@ int Report::get_PA_trigger_bin( } void Report::checkPATrigger( - int i, Detector *detector, Event *event, int evt, Trigger *trigger, Settings *settings1, + int i, Detector *detector, Event *event, int evt, Trigger *trigger, Settings *settings1, int trig_search_init, int max_total_bin ){ - // Calculates max SNR in topmost PA Vpol - // and multplies it by viewing angle factors. - // Then determines signal efficiency by interpolating oberved SNR from + // Calculates max SNR in topmost PA Vpol + // and multplies it by viewing angle factors. + // Then determines signal efficiency by interpolating oberved SNR from // efficiency vs SNR data. // Triggers if signal efficiency is above certain treshold. // If triggered, saves relevant information. @@ -5304,18 +5446,18 @@ void Report::checkPATrigger( int trigger_antenna_number = 8; Antenna_r *trigger_antenna = &stations[i].strings[trigger_antenna_string_i].antennas[trigger_antenna_i]; int trigger_ch_ID = GetChNumFromArbChID(detector, trigger_antenna_number, i, settings1) - 1; - - // If the antenna we use to trigger the PA doesn't have any ray solutions, + + // If the antenna we use to trigger the PA doesn't have any ray solutions, // do not perform the trigger check. if (trigger_antenna->ray_sol_cnt == 0){ return; } - // For phased array, waveform length is 680 ns, but + // For phased array, waveform length is 680 ns, but // for PA trigger check only 20 ns around the signal bin. // This is to avoid getting the second ray // KAH and ARB are not sure where the 1200 number comes from - // !!!HEY IF YOU ARE FIXING THIS!!! please update the corresponding check in Settings::CheckCompatibilitiesSettings + // !!!HEY IF YOU ARE FIXING THIS!!! please update the corresponding check in Settings::CheckCompatibilitiesSettings int BINSIZE = 1200/(settings1->TIMESTEP*1.e9); // Number of bins (aka datapoints) of data to save int waveformLength = settings1->WAVEFORM_LENGTH; @@ -5327,19 +5469,19 @@ void Report::checkPATrigger( vector trigger_waveform(V_convolved->begin(), V_convolved->begin()+convolved_len-1); // Find and log the event and ray with the most signal - int brightest_event[2]; + int brightest_event[2]; trigger_antenna->Get_Brightest_Interaction(&brightest_event); // Create an object to save the random number generated in isTrigger() - // for use in get_PA_trigger_bin(). + // for use in get_PA_trigger_bin(). double random_number = 1.01; if( isTrigger( trigger_waveform, brightest_event, random_number, trigger_antenna, trigger_ch_ID, settings1, trigger - )){ + )){ cout<Full_window_V[ant][bin_value]) > peakvalue) { peakvalue = TMath::Abs(trigger->Full_window_V[my_ch_id][bin_value]); } - + }//end bin my_ch_id ++; }//end ant @@ -5385,7 +5527,7 @@ void Report::checkPATrigger( double *TDR_all_sorted_temp; double *TDR_Vpol_sorted_temp; double *TDR_Hpol_sorted_temp; - + if(settings1->TRIG_SCAN_MODE>1){ // prepare TDR storage arrays and initialize all values to 0 TDR_all_sorted_temp=new double[numChan]; TDR_Vpol_sorted_temp=new double[numChanVpol]; @@ -5397,7 +5539,7 @@ void Report::checkPATrigger( TDR_Vpol_sorted_temp[trig_j]=0; } for(int trig_j=0; trig_j1 @@ -5415,68 +5557,68 @@ void Report::checkPATrigger( stations[i].strings[string_i].antennas[antenna_i].SingleChannelTriggers=0; stations[i].strings[string_i].antennas[antenna_i].TotalBinsScannedPerChannel=0; - } // end channel loop + } // end channel loop // Loop over window bins, get PThresh and decide if we need to update sorted arrays int N_pass_V = 0; int window_pass_bit = 0; // Whether this trig_i window passes - int bin_to_save_on = -1; + int bin_to_save_on = -1; for(int trig_i = trig_search_init; trig_i < max_total_bin; trig_i++) { // scan the different window positions - + // FOR EACH CHANNEL for (int trig_j=0; trig_jgetStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); int channel_num = detector->GetChannelfromStringAntenna( 5, string_i, antenna_i, settings1 ); - // assign Pthresh a value + // assign Pthresh a value double diode_noise_RMS = trigger->GetAntNoise_diodeRMS(channel_num-1, settings1); Pthresh_value[trig_j] = ( - trigger->Full_window[trig_j][trig_i] / + trigger->Full_window[trig_j][trig_i] / ( diode_noise_RMS * detector->GetThresOffset(i, channel_num-1,settings1) ) ); - // this is to count how many local trigger clusters there are + // this is to count how many local trigger clusters there are if(Pthresh_value[trig_j]TRIG_SCAN_MODE>2){ // save PThresh to ant SCT_threshold_pass if its the best or first if(SCTR_cluster_bit[trig_j]==0){// if first trigger in cluster stations[i].strings[string_i].antennas[antenna_i].SCT_threshold_pass.push_back(Pthresh_value[trig_j]); } else{// choose the highest trigger value (most negative) in cluster - if(Pthresh_value[trig_j] 2 - + SCTR_cluster_bit[trig_j]=1; - + }// if local trigger else SCTR_cluster_bit[trig_j]=0;// if no local trigger, set zero to start a new cluster at next local trigger - + // and how many bins scanned stations[i].strings[string_i].antennas[antenna_i].TotalBinsScannedPerChannel++; // fill the buffers (if any changes occur mark check_TDR_configuration as non-zero) - if(trig_ifill(Pthresh_value[trig_j]); - else + else check_TDR_configuration += buffer[trig_j]->add(Pthresh_value[trig_j]); // if there is at least one value above threshold in the buffer, this is ++ - if ( - buffer[trig_j]->addToNPass>0 && - string_i == 0 && + if ( + buffer[trig_j]->addToNPass>0 && + string_i == 0 && detector->stations[i].strings[string_i].antennas[antenna_i].type == 0 ) { N_pass_V++; } - + }// end iteration over channels to calculate PThresh // Add in PThresh calculators inspired by triggerCheckLoop() @@ -5485,7 +5627,7 @@ void Report::checkPATrigger( window_pass_bit=1; // if this is the first trigger, mark this position and save event - if(first_trigger==0){ + if(first_trigger==0){ first_trigger=1; // FOR EACH CHANNEL for(int trig_j=0;trig_jgetAntennafromArbAntID( i, trig_j); // mark the bin on which we triggered... - if(buffer[trig_j]->addToNPass>0) - stations[i].strings[string_i].antennas[antenna_i].Trig_Pass = trig_i-buffer[trig_j]->numBinsToOldestTrigger(); - else + if(buffer[trig_j]->addToNPass>0) + stations[i].strings[string_i].antennas[antenna_i].Trig_Pass = trig_i-buffer[trig_j]->numBinsToOldestTrigger(); + else stations[i].strings[string_i].antennas[antenna_i].Trig_Pass = 0.; }// for trig_j @@ -5506,12 +5648,12 @@ void Report::checkPATrigger( // if there's a trigger and anything changes in the buffers, restock the TDR arrays if(settings1->TRIG_SCAN_MODE>1&&check_TDR_configuration&&window_pass_bit){ - - for(int trig_j=0;trig_jgetStringfromArbAntID( i, trig_j); - int antenna_i = detector->getAntennafromArbAntID( i, trig_j); - if(detector->stations[i].strings[string_i].antennas[antenna_i].type == 0 + int antenna_i = detector->getAntennafromArbAntID( i, trig_j); + if(detector->stations[i].strings[string_i].antennas[antenna_i].type == 0 && buffer[trig_j]->temp_valuetemp_value; + { + best_thresh=buffer[trig_j]->temp_value; best_chan=trig_j; }// if best }// for trig_j buffer[best_chan]->temp_value=0; TDR_Vpol_sorted_temp[ii]=best_thresh; - + }// end sort Vpol tdr values - + // Changes TDR sorting and buffer[best_chan] for Hpol only for(int ii=0;iigetStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); - if(detector->stations[i].strings[string_i].antennas[antenna_i].type==1 + if(detector->stations[i].strings[string_i].antennas[antenna_i].type==1 && buffer[trig_j]->temp_valuetemp_value; + { + best_thresh=buffer[trig_j]->temp_value; best_chan=trig_j; }// if best }// for trig_j - + buffer[best_chan]->temp_value=0; TDR_Hpol_sorted_temp[ii]=best_thresh; - + }// end sort Hpol tdr values // Update TDR arrays (no matter what) @@ -5566,52 +5708,52 @@ void Report::checkPATrigger( for(int ii=0;iiTRIG_MODE==1){ for(int ii=0;iiSignalBin[brightest_event[0]][brightest_event[1]]; - + // Do what saveTriggeredEvent() does for(int trig_j=0; trig_jgetStringfromArbAntID( i, trig_j); int antenna_i = detector->getAntennafromArbAntID( i, trig_j); - - // Determine which ray and interaciton triggered triggered + + // Determine which ray and interaciton triggered triggered // the station based on signal and trigger bins stations[i].strings[string_i].antennas[antenna_i].Find_Likely_Sol(); // no likely init - + // set global_trig_bin values if (settings1->V_MIMIC_MODE == 0) { // Global passed bin is the center of the window stations[i].strings[string_i].antennas[antenna_i].global_trig_bin = waveformLength/2 + waveformCenter ; } else if (settings1->V_MIMIC_MODE == 1) { // Global passed bin is the center of the window + delay to each chs from araGeom stations[i].strings[string_i].antennas[antenna_i].global_trig_bin = ( - (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin) + (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin) + waveformLength/2 + waveformCenter ); } else if (settings1->V_MIMIC_MODE == 2) { // Global passed bin is the center of the window + delay to each chs from araGeom + fitted by eye stations[i].strings[string_i].antennas[antenna_i].global_trig_bin = ( (detector->params.TestBed_Ch_delay_bin[trig_j] - detector->params.TestBed_BH_Mean_delay_bin - + detector->stations[i].strings[string_i].antennas[antenna_i].manual_delay_bin) + + detector->stations[i].strings[string_i].antennas[antenna_i].manual_delay_bin) + waveformLength/2 + waveformCenter ); } - + stations[i].total_trig_search_bin = stations[i].Global_Pass + trig_window_bin - trig_search_init; } // end for trig_j in numchans @@ -5648,6 +5790,3 @@ double Report::interpolate(double *xdata,double *ydata, double xi, int numData) } //Adding function for padding waveforms to take FFT - - - diff --git a/Report.h b/Report.h index 938de100..87ecce29 100644 --- a/Report.h +++ b/Report.h @@ -332,19 +332,39 @@ class Report { double heff, Vector &n_trg_pokey, Vector &n_trg_slappy, Vector &Pol_vector, int ant_type, double &pol_factor, double &vmmhz, double antenna_theta, double antenna_phi ); - void ApplyAntFactors_Tdomain(double phase_copol, double phase_crosspol, double heff_copol, double heff_crosspol, Vector &Pol_vector, - int ant_type, double &pol_factor, double &vm_real, double &vm_img, - Settings *settings1, double antenna_theta, double antenna_phi, double freq, - bool useInTransmitterMode=false, bool applyInverse=false + + void ApplyAntFactors_Tdomain( + double AntPhase, double heff, Vector &Pol_vector, + int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, double antenna_theta, double antenna_phi, + double freq, bool useInTransmitterMode=false, bool applyInverse=false + ); + + void ApplyAntFactors_Tdomain( + double phase_copol, double phase_crosspol, double heff_copol, double heff_crosspol, + Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_real, double &vm_img, + Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode=false, bool applyInverse=false); + + void ApplyAntFactors_Tdomain_FirstTwo ( + double heff, double heff_lastbin, Vector &Pol_vector, + int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, Settings *settings1, double antenna_theta, double antenna_phi, + double freq, bool useInTransmitterMode=false, bool applyInverse=false ); void ApplyAntFactors_Tdomain_FirstTwo(double heff_copol, double heff_copol_lastbin, double heff_crosspol, double heff_crosspol_lastbin, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode=false, bool applyInverse=false ); + + void InvertAntFactors_Tdomain(double AntPhase, double heff, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode=false); + + void InvertAntFactors_Tdomain(double AntPhase_copol, double AntPhase_crosspol, double heff_copol, double heff_crosspol, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_real, double &vm_img, Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode=false ); + + + void InvertAntFactors_Tdomain_FirstTwo ( double heff, double heff_lastbin, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode=false); + void InvertAntFactors_Tdomain_FirstTwo(double heff_copol, double heff_copol_lastbin, double heff_crosspol, double heff_crosspol_lastbin, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode=false ); From 01b9940627f8dfe363659964d11c7b62de024bcd Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Wed, 9 Jul 2025 12:26:15 -0500 Subject: [PATCH 04/12] Fixes on reading files --- Detector.cc | 80 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/Detector.cc b/Detector.cc index 528903d2..0bde7ac8 100644 --- a/Detector.cc +++ b/Detector.cc @@ -2257,11 +2257,12 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ std::string VgainCrossFile; std::string VgainTopCrossFile; std::string HgainCrossFile; - +cout << "NEW ASG 1" << endl; //Adding step to read Tx gain. Will hardcode to PVA gain for now. TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; - TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; - + TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; +cout << "NEW ASG 2" << endl; + if (settings1->ANTENNA_MODE == 0){ // use the orignal Vpol/Hpol gains VgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_bicone6in_output.txt"; @@ -2310,11 +2311,18 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_TVpol_RealizedGainAndPhase_Copol_Custom.txt"; HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Copol_Custom.txt"; } +cout << "NEW ASG 3" << endl; // Add cross-pol gain files VgainCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; +cout << "NEW ASG 4" << endl; + VgainTopCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; //Should be TV but it's not working due to a negative SWR (first SWR entry) -ASG 12/09/24 +cout << "NEW ASG 5" << endl; + HgainCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; +cout << "NEW ASG 6" << endl; + // Check for ALL_ANT_V_ON, then set all antennas to VPol if true if (settings1->ALL_ANT_V_ON == 1) { @@ -2329,16 +2337,30 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ freq_init = -1; //Read in antenna co-pol gain files. + cout << "ASG 1" << endl; ReadAntennaGain(VgainFile, settings1, eVPol); + cout << "ASG 2" << endl; ReadAntennaGain(VgainTopFile, settings1, eVPolTop); + cout << "ASG 3" << endl; + ReadAntennaGain(HgainFile, settings1, eHPol); + cout << "ASG 4" << endl; + ReadAntennaGain(TxgainFile, settings1, eTx); + cout << "ASG 5" << endl; // Read cross-pol Rx gain files ReadAntennaGain(VgainCrossFile, settings1, eVPolCross); + cout << "ASG 6" << endl; + ReadAntennaGain(VgainTopCrossFile, settings1, eVPolTopCross); + cout << "ASG 7" << endl; + ReadAntennaGain(HgainCrossFile, settings1, eHPolCross); + cout << "ASG 8" << endl; + ReadAntennaGain(TxgainFileCross, settings1, eTxCross); + cout << "ASG 9" << endl; // update parameters to reflect what was read-in params.freq_step = freq_step; @@ -2381,72 +2403,79 @@ inline double Detector::SWRtoTransCoeff(double swr){ } inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAntennaType type) { - // define some dummy variables that will point to the real variables // where values are stored vector * freq; vector< vector > * gain; vector< vector > * phase; vector* transAnt_databin; - // make sure dummy variables point to the right variables switch(type) { case(eVPol): + freq = &Freq; gain = &Vgain; phase = &Vphase; transAnt_databin = &transV_databin; break; case(eVPolTop): + freq = &Freq; gain = &VgainTop; phase = &VphaseTop; transAnt_databin = &transVTop_databin; break; case(eHPol): + freq = &Freq; gain = &Hgain; phase = &Hphase; transAnt_databin = &transH_databin; break; case(eVPolCross): // Cross-pol VPol + freq = &Freq; gain = &VgainCross; phase = &VphaseCross; transAnt_databin = &transVCross_databin; break; case(eVPolTopCross): // Cross-pol VPol Top + freq = &Freq; gain = &VgainTopCross; phase = &VphaseTopCross; transAnt_databin = &transVTopCross_databin; break; case(eHPolCross): // Cross-pol HPol + freq = &Freq; gain = &HgainCross; phase = &HphaseCross; transAnt_databin = &transHCross_databin; break; case(eTx): + freq = &Freq; gain = &Txgain; phase = &Txphase; break; case(eTxCross): + freq = &Freq; gain = &TxgainCross; phase = &TxphaseCross; break; default: throw runtime_error("Unknown antenna type!"); } - // open the requested file ifstream NecOut( filename.c_str() ); // initialize some variables used for read-in vector Transm; string line; - + // clear vector in case there's any lingering data gain->clear(); - phase->clear(); + phase->clear(); + if(freq_step == -1 || type == eTx) { // only reset if it hasn't been read-in yet + cout << "freq ptr = " << freq << endl; freq->clear(); } - + // check the file opened successfully if (! NecOut.is_open() ) { throw runtime_error("Antenna gain file could not be opened: "+filename); @@ -2574,22 +2603,25 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt freq_init = freq->at(0); } - // check things look sensible - if(Transm.size() != freq_step) { - throw runtime_error("Transm has an unexpected length! "+filename); - } - if(gain->size() != freq_step) { - throw runtime_error("gain has an unexpected length! "+filename); - } - if(phase->size() != freq_step) { - throw runtime_error("phase has an unexpected length! "+filename); - } - for(int i = 0; i < freq_step; ++i) { - if(gain->at(i).size() != ang_step) { - throw runtime_error("gain vectors have inconsistent length! "+filename); + // Only enforce check for non-Tx and non-crosspol antennas + if(type != eTx && type != eTxCross && type != eVPolCross && type != eVPolTopCross && type != eHPolCross) { + // check things look sensible + if(freq_step != -1 && Transm.size() != freq_step) { + throw runtime_error("Transm has an unexpected length! "+filename); + } + if(freq_step != -1 && gain->size() != freq_step) { + throw runtime_error("gain has an unexpected length! "+filename); } - if(phase->at(i).size() != ang_step) { - throw runtime_error("gain vectors have inconsistent length! "+filename); + if(freq_step != -1 && phase->size() != freq_step) { + throw runtime_error("phase has an unexpected length! "+filename); + } + for(int i = 0; i < freq_step; ++i) { + if(gain->at(i).size() != ang_step) { + throw runtime_error("gain vectors have inconsistent length! "+filename); + } + if(phase->at(i).size() != ang_step) { + throw runtime_error("gain vectors have inconsistent length! "+filename); + } } } From e0d8b542b4a3c95bb7f198abb086571136c1ac94 Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Wed, 9 Jul 2025 15:32:43 -0500 Subject: [PATCH 05/12] Rearranged propagate signals to work with EVENT_TYPE=11 --- Detector.cc | 45 +++++++++++---------------------------------- Detector.h | 6 +++--- Report.cc | 11 +++++------ 3 files changed, 19 insertions(+), 43 deletions(-) diff --git a/Detector.cc b/Detector.cc index 0bde7ac8..95dbaf23 100644 --- a/Detector.cc +++ b/Detector.cc @@ -2257,11 +2257,9 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ std::string VgainCrossFile; std::string VgainTopCrossFile; std::string HgainCrossFile; -cout << "NEW ASG 1" << endl; //Adding step to read Tx gain. Will hardcode to PVA gain for now. TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; - TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; -cout << "NEW ASG 2" << endl; + TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; if (settings1->ANTENNA_MODE == 0){ // use the orignal Vpol/Hpol gains @@ -2311,17 +2309,11 @@ cout << "NEW ASG 2" << endl; VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_TVpol_RealizedGainAndPhase_Copol_Custom.txt"; HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Copol_Custom.txt"; } -cout << "NEW ASG 3" << endl; // Add cross-pol gain files VgainCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; -cout << "NEW ASG 4" << endl; - - VgainTopCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; //Should be TV but it's not working due to a negative SWR (first SWR entry) -ASG 12/09/24 -cout << "NEW ASG 5" << endl; - + //VgainTopCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; //Should be TV but it's not working due to a negative SWR (first SWR entry) -ASG 12/09/24 HgainCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; -cout << "NEW ASG 6" << endl; // Check for ALL_ANT_V_ON, then set all antennas to VPol if true @@ -2337,30 +2329,16 @@ cout << "NEW ASG 6" << endl; freq_init = -1; //Read in antenna co-pol gain files. - cout << "ASG 1" << endl; ReadAntennaGain(VgainFile, settings1, eVPol); - cout << "ASG 2" << endl; ReadAntennaGain(VgainTopFile, settings1, eVPolTop); - cout << "ASG 3" << endl; - ReadAntennaGain(HgainFile, settings1, eHPol); - cout << "ASG 4" << endl; - ReadAntennaGain(TxgainFile, settings1, eTx); - cout << "ASG 5" << endl; // Read cross-pol Rx gain files ReadAntennaGain(VgainCrossFile, settings1, eVPolCross); - cout << "ASG 6" << endl; - ReadAntennaGain(VgainTopCrossFile, settings1, eVPolTopCross); - cout << "ASG 7" << endl; - ReadAntennaGain(HgainCrossFile, settings1, eHPolCross); - cout << "ASG 8" << endl; - ReadAntennaGain(TxgainFileCross, settings1, eTxCross); - cout << "ASG 9" << endl; // update parameters to reflect what was read-in params.freq_step = freq_step; @@ -2472,7 +2450,6 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt phase->clear(); if(freq_step == -1 || type == eTx) { // only reset if it hasn't been read-in yet - cout << "freq ptr = " << freq << endl; freq->clear(); } @@ -2595,24 +2572,24 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt return; } - // set parameter values if this is the first read-in - if(freq_step == -1) { - freq_step = (int)freq->size(); + int this_freq_step = (int)freq->size(); + // set parameter values for the smallest freq_step + if(freq_step == -1 || this_freq_step < freq_step) { + freq_step = this_freq_step; ang_step = (int)gain->back().size(); freq_width = freq->at(1)-freq->at(0); freq_init = freq->at(0); } - // Only enforce check for non-Tx and non-crosspol antennas if(type != eTx && type != eTxCross && type != eVPolCross && type != eVPolTopCross && type != eHPolCross) { // check things look sensible - if(freq_step != -1 && Transm.size() != freq_step) { + if(Transm.size() != freq_step) { throw runtime_error("Transm has an unexpected length! "+filename); } - if(freq_step != -1 && gain->size() != freq_step) { + if(gain->size() != freq_step) { throw runtime_error("gain has an unexpected length! "+filename); } - if(freq_step != -1 && phase->size() != freq_step) { + if(phase->size() != freq_step) { throw runtime_error("phase has an unexpected length! "+filename); } for(int i = 0; i < freq_step; ++i) { @@ -3048,7 +3025,6 @@ double Detector::GetAntPhase( double freq, double theta, double phi, int ant_m ) double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int ant_m, int string_number, int ant_number, bool useInTransmitterMode, bool useCrossPol) { - /* The purpose of this function is to interpolate the globally defined gain arrays (Vgain, VgainTop, Hgain, Txgain) to match the frequency binning dictated by NFOUR in the setup file. @@ -3134,6 +3110,7 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int int bin = (int)( (freq - thisFreq_init) / thisFreq_width )+1; + //Interpolation of tempGain slope_1 = ((*tempGain)[1][angle_bin] - (*tempGain)[0][angle_bin]) / (F->at(1) - F->at(0)); @@ -3148,7 +3125,7 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int else { Gout = (*tempGain)[bin-1][angle_bin] + (freq-F->at(bin-1))*((*tempGain)[bin][angle_bin]-(*tempGain)[bin-1][angle_bin])/(F->at(bin)-F->at(bin-1)); } - + if ( Gout < 0. ) { // gain can not go below 0 Gout = 0.; } diff --git a/Detector.h b/Detector.h index 638488e6..531d9ee6 100644 --- a/Detector.h +++ b/Detector.h @@ -362,9 +362,9 @@ class Detector { vector transH_databin; // Cross-pol data bins - std::vector transVCross_databin; - std::vector transVTopCross_databin; - std::vector transHCross_databin; + vector transVCross_databin; + vector transVTopCross_databin; + vector transHCross_databin; void ReadAmplifierNoiseFigure(Settings *settings1); vector< vector > amplifierNoiseFig_ch; diff --git a/Report.cc b/Report.cc index f44986cf..27a6b338 100644 --- a/Report.cc +++ b/Report.cc @@ -463,7 +463,6 @@ void Report::CalculateSignals( ){ // For each each station, perform the ray tracing from each cascade to each antenna // and determine the voltage readout in the antenna for each connected ray - double RandomTshift = gRandom->Rndm(); // for t-domain signal, a factor for random init time shift // Loop over stations @@ -1281,7 +1280,6 @@ void Report::ModelRay( -0.01, // 1cm antenna shift, inspired from NuRadioMC icemodel, settings ); - PropagateSignal( dT_forfft, waveform_bin, signal->PulserWaveform_T, signal->PulserWaveform_V, T_forint, interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, @@ -1584,14 +1582,15 @@ void Report::PropagateSignal( double Tx_theta = 0; double Tx_phi = 0; double heff_Tx_lastbin = 0; - if (settings->EVENT_TYPE == 11 || settings->EVENT_TYPE == 12){ // Pulser simulations + if (settings->EVENT_TYPE == 12){ // Pulser simulations - //Defining polarization at the source (using launch_vector (a unit vector)) + //Defining transmission angle at the source (using launch_vector (a unit vector)) double theta = acos(launch_vector[2]); double phi = atan2(launch_vector[1],launch_vector[0]); double Tx_theta = theta*180/PI; double Tx_phi = phi*180/PI; + double heff_Tx_lastbin = GaintoHeight( detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true), freq_tmp, @@ -1670,12 +1669,12 @@ void Report::PropagateSignal( ApplyAntFactors_Tdomain( detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0), heff_Tx, Pol_vector, 0, Pol_factor, V_forfft[2 *n], V_forfft[2 *n + 1], - settings, Tx_theta, Tx_phi, freq_tmp, detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true), true); + settings, Tx_theta, Tx_phi, freq_tmp, true); } else { ApplyAntFactors_Tdomain_FirstTwo( heff_Tx, heff_Tx_lastbin, Pol_vector, 0, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], settings, Tx_theta, Tx_phi, freq_tmp); + V_forfft[2 *n], V_forfft[2 *n + 1], settings, Tx_theta, Tx_phi, freq_tmp, true); } } else if (event->IsCalpulser > 0){ From d7d7d0972978b41f1d370892ee5b8a46221a3704 Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Wed, 9 Jul 2025 19:49:38 -0500 Subject: [PATCH 06/12] Extra fixes, but I need this as a checkpoint --- Detector.cc | 2257 ++++++++++++++++++++++++++------------------------- Detector.h | 124 +-- Report.cc | 4 +- 3 files changed, 1214 insertions(+), 1171 deletions(-) diff --git a/Detector.cc b/Detector.cc index 95dbaf23..0d334317 100644 --- a/Detector.cc +++ b/Detector.cc @@ -78,10 +78,10 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile //end initialize //Parameters to use if using Arianna_WIPLD_hpol.dat - if (settings1 -> ANTENNA_MODE == 2) { + if (settings1 -> ANTENNA_MODE == 2) { params.DeployedStations = 4; } - + //copy freq_width, freq_init in params to Detector freq_width, freq_init freq_step = params.freq_step; ang_step = params.ang_step; @@ -118,25 +118,25 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile strings.push_back(temp); } cout << "read numner_of_strings" << endl; - } + } else if (label == "antenna_string") { string_id++; antenna_id = 0; cout << "read antenna_string" << endl; - } + } else if (label == "x") { strings[string_id].SetX(atof(line.substr(line.find_first_of("=") + 1).c_str())); cout << "read x : " << (double) strings[string_id].GetX() << " string_id : " << string_id << endl; - } + } else if (label == "y") { strings[string_id].SetY(atof(line.substr(line.find_first_of("=") + 1).c_str())); cout << "read y : " << (double) strings[string_id].GetY() << " string_id : " << string_id << endl; - } + } else if (label == "z") { strings[string_id].antennas.push_back(temp_antenna); strings[string_id].antennas[antenna_id].SetZ(atof(line.substr(line.find_first_of("=") + 1, line.find_first_of(",")).c_str())); strings[string_id].antennas[antenna_id].type = atoi(line.substr(line.find_first_of(",") + 1).c_str()); - cout << "read z : " << (double) strings[string_id].antennas[antenna_id].GetZ() << " string_id : " << string_id << " antenna_id : " + cout << "read z : " << (double) strings[string_id].antennas[antenna_id].GetZ() << " string_id : " << string_id << " antenna_id : " << antenna_id << " type : " << (int) strings[string_id].antennas[antenna_id].type << endl; antenna_id++; params.number_of_antennas++; @@ -145,12 +145,12 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } } testbed.close(); - } + } else { cout << "Unable to open antenna array file !" << endl; } - // testbed version of FlattoEarth_ARA + // testbed version of FlattoEarth_ARA // strings and antennas on the strings use geoid surface! double Dist = 0.; //for sqrt(x^2 + y^2) double R1 = icesurface -> Surface(0., 0.); // from core of earth to surface at theta, phi = 0. @@ -164,7 +164,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile theta_tmp = Dist / R1; // assume R1 is constant (which is not) phi_tmp = atan2(strings[i].GetY(), strings[i].GetX()); - if (phi_tmp < 0.) { + if (phi_tmp < 0.) { phi_tmp += 2. * PI; } @@ -176,13 +176,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile cout << "R, Theta, Phi : " << strings[i].R() << " " << strings[i].Theta() << " " << strings[i].Phi() << endl; // set antennas r, theta, phi - for (int j = 0; j < antenna_id; j++) { + for (int j = 0; j < antenna_id; j++) { strings[i].antennas[j].SetRThetaPhi(strings[i].R() + strings[i].antennas[j].GetZ(), strings[i].Theta(), strings[i].Phi()); } } - } // if mode == 0 - + } // if mode == 0 + ///////////////////////////////////////////////////////////////////////////// else if (mode == 1) { ifstream ARA_N(ARA_N_file.c_str()); @@ -202,19 +202,19 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile double z_btw_array[6]; // assume there will be less than 6 bore hole antennas at each string // these z_btw array will be used when settings->BH_ANT_SEP_DIST_ON=1 case for (int i = 0; i < 6; i++) { - if (i == 0) { + if (i == 0) { z_btw_array[i] = 0.; } - else if (i == 1) { + else if (i == 1) { z_btw_array[i] = 2.; } - else if (i == 2) { + else if (i == 2) { z_btw_array[i] = 15.; } else if (i == 3) { z_btw_array[i] = 2.; } - else { + else { z_btw_array[i] = z_btw; } } @@ -236,63 +236,63 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile if (label == "core_x") { params.core_x = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read core_x" << endl; - } + } else if (label == "core_y") { params.core_y = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read core_y" << endl; - } + } else if (label == "R_string") { R_string = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read R_string" << endl; - } + } else if (label == "R_surface") { R_surface = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read R_surface" << endl; - } + } else if (label == "z_max") { z_max = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_max" << endl; - } + } else if (label == "z_btw") { z_btw = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw" << endl; - } + } else if (label == "z_btw01") { z_btw_array[1] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant0 and ant1" << endl; - } + } else if (label == "z_btw12") { z_btw_array[2] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant1 and ant2" << endl; - } + } else if (label == "z_btw23") { z_btw_array[3] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant2 and ant3" << endl; - } + } else if (label == "z_btw34") { z_btw_array[4] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant3 and ant4" << endl; - } + } else if (label == "z_btw45") { z_btw_array[5] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant4 and ant5" << endl; - } + } else if (label == "number_of_stations") { params.number_of_stations = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read stations_per_side" << endl; - } + } else if (label == "station_spacing") { params.station_spacing = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read station_spacting" << endl; - } + } else if (label == "antenna_orientation") { params.antenna_orientation = atoi(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read antenna_orientation" << endl; - } + } else if (label == "number_of_strings_station") { params.number_of_strings_station = atoi(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read number of strings" << endl; - } + } else if (label == "number_of_antennas_string") { params.number_of_antennas_string = atoi(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read number of antennas per string" << endl; @@ -306,30 +306,30 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile // set number of antennas in a string if (params.bore_hole_antenna_layout == 0) { // VHVH layout params.number_of_antennas_string = 4; - } + } else if (params.bore_hole_antenna_layout == 1) { // VHV layout params.number_of_antennas_string = 3; - } + } else if (params.bore_hole_antenna_layout == 2) { // VHVV layout params.number_of_antennas_string = 4; - } + } else if (params.bore_hole_antenna_layout == 3) { // VHHH layout params.number_of_antennas_string = 4; - } + } else if (params.bore_hole_antenna_layout == 4) { // VHH layout params.number_of_antennas_string = 3; - } + } else if (params.bore_hole_antenna_layout == 5) { // VVVV layout params.number_of_antennas_string = 4; - } + } else if (params.bore_hole_antenna_layout == 6) { // VV layout params.number_of_antennas_string = 2; - } + } else if (params.bore_hole_antenna_layout == 7) { // V layout params.number_of_antennas_string = 1; } - // calculate number of stations, strings, antennas + // calculate number of stations, strings, antennas params.number_of_strings = params.number_of_stations * params.number_of_strings_station; params.number_of_antennas = params.number_of_strings * params.number_of_antennas_string; @@ -337,14 +337,14 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile for (int i = 0; i < params.number_of_stations; i++) { stations.push_back(temp_station); - for (int j = 0; j < params.number_of_surfaces_station; j++) { + for (int j = 0; j < params.number_of_surfaces_station; j++) { stations[i].surfaces.push_back(temp_surface); } for (int k = 0; k < params.number_of_strings_station; k++) { stations[i].strings.push_back(temp_string); - for (int l = 0; l < params.number_of_antennas_string; l++) { + for (int l = 0; l < params.number_of_antennas_string; l++) { stations[i].strings[k].antennas.push_back(temp_antenna); } } @@ -366,7 +366,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile if (station_count < 6) { // first layer stations[station_count].SetX(params.core_x + (double) params.station_spacing * cos((PI / 3.) * (double) station_count)); stations[station_count].SetY(params.core_y + (double) params.station_spacing * sin((PI / 3.) * (double) station_count)); - } + } else if (station_count < 18) { // second layer // if the first outter layer station @@ -381,7 +381,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[station_count].SetX(stations[station_count - 1].GetX() + (double) params.station_spacing * cos(next_dir)); stations[station_count].SetY(stations[station_count - 1].GetY() + (double) params.station_spacing * sin(next_dir)); side_step--; - } + } else { side_step = 1; next_dir += PI / 3.; // rotate @@ -389,7 +389,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[station_count].SetY(stations[station_count - 1].GetY() + (double) params.station_spacing * sin(next_dir)); } } - } + } else if (station_count < 36) { // third layer // if the first outter layer station @@ -404,7 +404,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[station_count].SetX(stations[station_count - 1].GetX() + (double) params.station_spacing * cos(next_dir)); stations[station_count].SetY(stations[station_count - 1].GetY() + (double) params.station_spacing * sin(next_dir)); side_step--; - } + } else { side_step = 2; next_dir += PI / 3.; // rotate @@ -416,12 +416,12 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } station_count++; - } + } else if (station_count < (int) stations.size()) { stations[station_count].SetX(params.core_x); stations[station_count].SetY(params.core_y); station_count++; - } + } else { cout << "\n\tError, too many stations !" << endl; } @@ -431,7 +431,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile if (station_count != (int) params.number_of_stations) { cout << "\n\tError, the number of stations initialized doesn't match the number requested!" << endl; } - + // set antenna values from parameters // set station positions if (settings1 -> READGEOM == 0) { // use idealized geometry @@ -463,9 +463,9 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (settings1 -> BH_ANT_SEP_DIST_ON == 1) { z_btw_total = 0.; - for (int l = 0; l < k + 1; l++) + for (int l = 0; l < k + 1; l++) z_btw_total += z_btw_array[l]; - + stations[i].strings[j].antennas[k].SetZ(-z_max + z_btw_total); } @@ -481,18 +481,18 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (params.antenna_orientation == 1) { // borehole antennas one next facing different way if (j == 0 || j == 3) { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 0; } - else { + else { stations[i].strings[j].antennas[k].orient = 1; } } else { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; } - else { + else { stations[i].strings[j].antennas[k].orient = 0; } } @@ -512,9 +512,9 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (settings1 -> BH_ANT_SEP_DIST_ON == 1) { z_btw_total = 0.; - for (int l = 0; l < k + 1; l++) + for (int l = 0; l < k + 1; l++) z_btw_total += z_btw_array[l]; - + stations[i].strings[j].antennas[k].SetZ(-z_max + z_btw_total); } @@ -533,15 +533,15 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 0; } - else { + else { stations[i].strings[j].antennas[k].orient = 1; } - } + } else { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; } - else { + else { stations[i].strings[j].antennas[k].orient = 0; } } @@ -561,10 +561,10 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (settings1 -> BH_ANT_SEP_DIST_ON == 1) { z_btw_total = 0.; - for (int l = 0; l < k + 1; l++) { + for (int l = 0; l < k + 1; l++) { z_btw_total += z_btw_array[l]; } - + stations[i].strings[j].antennas[k].SetZ(-z_max + z_btw_total); } @@ -580,18 +580,18 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (params.antenna_orientation == 1) { // borehole antennas one next facing different way if (j == 0 || j == 3) { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 0; } else { stations[i].strings[j].antennas[k].orient = 1; } - } + } else { if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; } - else { + else { stations[i].strings[j].antennas[k].orient = 0; } } @@ -603,7 +603,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } // end if bore hole antenna layout = 3 (where VHHH way) else if (params.bore_hole_antenna_layout == 5 || params.bore_hole_antenna_layout == 6 || - params.bore_hole_antenna_layout == 7) + params.bore_hole_antenna_layout == 7) { // it's V-V-V-V or V-V or V for (int j = 0; j < stations[i].strings.size(); j++) { @@ -615,29 +615,29 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile else if (settings1 -> BH_ANT_SEP_DIST_ON == 1) { z_btw_total = 0.; - for (int l = 0; l < k + 1; l++) { + for (int l = 0; l < k + 1; l++) { z_btw_total += z_btw_array[l]; } - + stations[i].strings[j].antennas[k].SetZ(-z_max + z_btw_total); } - stations[i].strings[j].antennas[k].type = 0; // all antennas v-pol + stations[i].strings[j].antennas[k].type = 0; // all antennas v-pol if (params.antenna_orientation == 0) { // all borehole antennas facing same x stations[i].strings[j].antennas[k].orient = 0; } else if (params.antenna_orientation == 1) { // borehole antennas one next facing different way if (j == 0 || j == 3) { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 0; } else { stations[i].strings[j].antennas[k].orient = 1; } - } + } else { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; } else { @@ -691,14 +691,14 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[i].strings[j].antennas[k].SetX(stations[i].GetX() + araGeom -> getStationInfo(i + 1, settings1->DETECTOR_YEAR) -> fAntInfo[chan - 1].antLocation[0]); stations[i].strings[j].antennas[k].SetY(stations[i].GetY() + araGeom -> getStationInfo(i + 1, settings1->DETECTOR_YEAR) -> fAntInfo[chan - 1].antLocation[1]); stations[i].strings[j].antennas[k].SetZ(araGeom -> getStationInfo(i + 1, settings1->DETECTOR_YEAR) -> fAntInfo[chan - 1].antLocation[2]); - cout << "DetectorStation:string:antenna:X:Y:Z:: " - << i << " : " - << j << " : " + cout << "DetectorStation:string:antenna:X:Y:Z:: " + << i << " : " + << j << " : " << k << " : " - << stations[i].strings[j].antennas[k].GetX() << " : " - << stations[i].strings[j].antennas[k].GetY() << " : " - << stations[i].strings[j].antennas[k].GetZ() << " : " - << chan << " : " + << stations[i].strings[j].antennas[k].GetX() << " : " + << stations[i].strings[j].antennas[k].GetY() << " : " + << stations[i].strings[j].antennas[k].GetZ() << " : " + << chan << " : " << endl; } @@ -719,7 +719,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile for (int j = 0; j < stations[i].strings.size(); j++) { for (int k = 0; k < stations[i].strings[j].antennas.size(); k++) { - if (k % 2 == 0) { + if (k % 2 == 0) { stations[i].strings[j].antennas[k].type = 0; // v-pol } else { @@ -731,13 +731,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (params.antenna_orientation == 1) { // borehole antennas one next facing different way if (j == 0 || j == 3) { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 0; } - else { + else { stations[i].strings[j].antennas[k].orient = 1; } - } + } else { if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; @@ -775,7 +775,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile else { stations[i].strings[j].antennas[k].orient = 1; } - } + } else { if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; @@ -813,12 +813,12 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile else { stations[i].strings[j].antennas[k].orient = 1; } - } + } else { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; } - else { + else { stations[i].strings[j].antennas[k].orient = 0; } } @@ -851,13 +851,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile antenna_count = 0; for (int j = 0; j < (int)(stations[i].strings.size()); j++) { - for (int k = 0; k < (int)(stations[i].strings[j].antennas.size()); k++) { + for (int k = 0; k < (int)(stations[i].strings[j].antennas.size()); k++) { antenna_count++; } } stations[i].number_of_antennas = antenna_count; - if (max_number_of_antennas_station < antenna_count) { + if (max_number_of_antennas_station < antenna_count) { max_number_of_antennas_station = antenna_count; } } @@ -882,10 +882,10 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile ReadThresOffset_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/threshold_offset.csv", settings1); // only TestBed for now // read threshold values for chs file ReadThres_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/thresholds_TB.csv", settings1); // only TestBed for now - + // read system temperature for chs file!! cout << "check read testbed temp1" << endl; - if (settings1 -> NOISE_CHANNEL_MODE != 0) { + if (settings1 -> NOISE_CHANNEL_MODE != 0) { ReadTemp_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/system_temperature.csv", settings1); // only TestBed for now } @@ -909,7 +909,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } // if mode == 1 - ///////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////// else if (mode == 2) { cout << "\n\tDector mode 2 : Pentagon" << endl; cout << "\n\tBy default, ARA-37 is set" << endl; @@ -932,19 +932,19 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile double z_btw_array[6]; // assume there will be less than 6 bore hole antennas at each string // these z_btw array will be used when settings->BH_ANT_SEP_DIST_ON=1 case for (int i = 0; i < 6; i++) { - if (i == 0) { + if (i == 0) { z_btw_array[i] = 0.; } - else if (i == 1) { + else if (i == 1) { z_btw_array[i] = 2.; } - else if (i == 2) { + else if (i == 2) { z_btw_array[i] = 15.; } - else if (i == 3) { + else if (i == 3) { z_btw_array[i] = 2.; } - else { + else { z_btw_array[i] = z_btw; } } @@ -966,55 +966,55 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile if (label == "core_x") { params.core_x = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read core_x" << endl; - } + } else if (label == "core_y") { params.core_y = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read core_y" << endl; - } + } else if (label == "R_string") { R_string = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read R_string" << endl; - } + } else if (label == "R_surface") { R_surface = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read R_surface" << endl; - } + } else if (label == "z_max") { z_max = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_max" << endl; - } + } else if (label == "z_btw") { z_btw = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw" << endl; - } + } else if (label == "z_btw01") { z_btw_array[1] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant0 and ant1" << endl; - } + } else if (label == "z_btw12") { z_btw_array[2] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant1 and ant2" << endl; - } + } else if (label == "z_btw23") { z_btw_array[3] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant2 and ant3" << endl; - } + } else if (label == "z_btw34") { z_btw_array[4] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant3 and ant4" << endl; - } + } else if (label == "z_btw45") { z_btw_array[5] = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw bh ant4 and ant5" << endl; - } + } else if (label == "stations_per_side") { params.stations_per_side = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read stations_per_side" << endl; - } + } else if (label == "station_spacing") { params.station_spacing = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read station_spacting" << endl; - } + } else if (label == "antenna_orientation") { params.antenna_orientation = atoi(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read antenna_orientation" << endl; @@ -1042,7 +1042,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile params.number_of_antennas_string = 3; } - // caculate number of stations, strings, antennas + // caculate number of stations, strings, antennas params.number_of_stations = 1 + (3 * params.stations_per_side) * (params.stations_per_side - 1); params.number_of_strings = params.number_of_stations * params.number_of_strings_station; @@ -1052,14 +1052,14 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile for (int i = 0; i < params.number_of_stations; i++) { stations.push_back(temp_station); - for (int j = 0; j < params.number_of_surfaces_station; j++) { + for (int j = 0; j < params.number_of_surfaces_station; j++) { stations[i].surfaces.push_back(temp_surface); } for (int k = 0; k < params.number_of_strings_station; k++) { stations[i].strings.push_back(temp_string); - for (int l = 0; l < params.number_of_antennas_string; l++) { + for (int l = 0; l < params.number_of_antennas_string; l++) { stations[i].strings[k].antennas.push_back(temp_antenna); } } @@ -1082,7 +1082,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[station_count].SetY(current_y); stations[station_count].SetX((double) params.station_spacing * ((double) istation - ((double) stations_this_row - 1.) / 2.) + params.core_x); station_count++; - } + } else { cout << "\n\tError, too many stations !" << endl; } @@ -1091,7 +1091,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile // finished setting all stations' position cout << "total station_count : " << station_count << endl; - if (station_count != (int) params.number_of_stations) { + if (station_count != (int) params.number_of_stations) { cout << "\n\tError, the number of stations initialized doesn't match the number requested!" << endl; } @@ -1126,7 +1126,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile for (int l = 0; l < k + 1; l++) { z_btw_total += z_btw_array[l]; } - + stations[i].strings[j].antennas[k].SetZ(-z_max + z_btw_total); } @@ -1142,18 +1142,18 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (params.antenna_orientation == 1) { // borehole antennas one next facing different way if (j == 0 || j == 3) { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 0; } - else { + else { stations[i].strings[j].antennas[k].orient = 1; } } else { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; } - else { + else { stations[i].strings[j].antennas[k].orient = 0; } } @@ -1171,9 +1171,9 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (settings1 -> BH_ANT_SEP_DIST_ON == 1) { z_btw_total = 0.; - for (int l = 0; l < k + 1; l++) + for (int l = 0; l < k + 1; l++) z_btw_total += z_btw_array[l]; - + stations[i].strings[j].antennas[k].SetZ(-z_max + z_btw_total); } @@ -1189,7 +1189,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (params.antenna_orientation == 1) { // borehole antennas one next facing different way if (j == 0 || j == 3) { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 0; } else { @@ -1197,7 +1197,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } } else { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; } else { @@ -1218,10 +1218,10 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (settings1 -> BH_ANT_SEP_DIST_ON == 1) { z_btw_total = 0.; - for (int l = 0; l < k + 1; l++) { + for (int l = 0; l < k + 1; l++) { z_btw_total += z_btw_array[l]; } - + stations[i].strings[j].antennas[k].SetZ(-z_max + z_btw_total); } @@ -1237,18 +1237,18 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } else if (params.antenna_orientation == 1) { // borehole antennas one next facing different way if (j == 0 || j == 3) { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 0; } - else { + else { stations[i].strings[j].antennas[k].orient = 1; } - } + } else { - if (k == 0 || k == 1) { + if (k == 0 || k == 1) { stations[i].strings[j].antennas[k].orient = 1; } - else { + else { stations[i].strings[j].antennas[k].orient = 0; } } @@ -1319,7 +1319,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } // if mode == 2 - ///////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////// else if (mode == 3) { // initialize info @@ -1357,35 +1357,35 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile if (label == "core_x") { params.core_x = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read core_x" << endl; - } + } else if (label == "core_y") { params.core_y = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read core_y" << endl; - } + } else if (label == "R_string") { R_string = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read R_string" << endl; - } + } else if (label == "R_surface") { R_surface = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read R_surface" << endl; - } + } else if (label == "z_max") { z_max = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_max" << endl; - } + } else if (label == "z_btw") { z_btw = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw" << endl; - } + } else if (label == "number_of_stations") { params.number_of_stations = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read stations_per_side" << endl; - } + } else if (label == "station_spacing") { params.station_spacing = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read station_spacting" << endl; - } + } else if (label == "antenna_orientation") { params.antenna_orientation = atoi(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read antenna_orientation" << endl; @@ -1410,18 +1410,18 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[station_count].SetX(params.core_x + (double) params.station_spacing * cos((PI / 3.) * (double) station_count)); stations[station_count].SetY(params.core_y + (double) params.station_spacing * sin((PI / 3.) * (double) station_count)); station_count++; - } + } else if (station_count < (int) params.number_of_stations) { stations[station_count].SetX(params.core_x); stations[station_count].SetY(params.core_y); station_count++; - } - else + } + else cout << "\n\tError, too many stations !" << endl; } // finished setting all stations' position - if (station_count != (int) params.number_of_stations) { + if (station_count != (int) params.number_of_stations) { cout << "\n\tError, station number not match !" << endl; } @@ -1432,13 +1432,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile #endif for (int i = 0; i < stations.size(); i++) { stations[i].StationID = i; - + if (settings1 -> USE_INSTALLED_TRIGGER_SETTINGS == 0) { stations[i].NFOUR = 1024; stations[i].TIMESTEP = 1. / 2.6 * 1.E-9; stations[i].TRIG_WINDOW = 2.5E-7; stations[i].DATA_BIN_SIZE = settings1 -> DATA_BIN_SIZE; - } + } else if (settings1 -> USE_INSTALLED_TRIGGER_SETTINGS == 1) { if (stations[i].StationID == 0) { stations[i].NFOUR = 1024; @@ -1462,13 +1462,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile for (int j = 0; j < stations[0].strings.size(); j++) { for (int k = 0; k < stations[0].strings[j].antennas.size(); k++) { - cout << "DetectorStation2:string:antenna:X:Y:Z:chno :: " - << j << " : " - << k << " : " - << stations[0].strings[j].antennas[k].GetX() << " : " - << stations[0].strings[j].antennas[k].GetY() << " : " - << stations[0].strings[j].antennas[k].GetZ() << " : \t" - << GetChannelfromStringAntenna(0, j, k, settings1) + cout << "DetectorStation2:string:antenna:X:Y:Z:chno :: " + << j << " : " + << k << " : " + << stations[0].strings[j].antennas[k].GetX() << " : " + << stations[0].strings[j].antennas[k].GetY() << " : " + << stations[0].strings[j].antennas[k].GetZ() << " : \t" + << GetChannelfromStringAntenna(0, j, k, settings1) << endl; params.number_of_antennas++; @@ -1479,17 +1479,17 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile for (int j = 0; j < stations[0].strings.size(); j++) { for (int k = 0; k < stations[0].strings[j].antennas.size(); k++) { - cout << "Detector:station:string:antenna:X:Y:Z:R:Theta:Phi:: " - << "0" << " : " - << j << " : " - << k << " : " - << stations[0].strings[j].antennas[k].GetX() << " : " - << stations[0].strings[j].antennas[k].GetY() << " : " - << stations[0].strings[j].antennas[k].GetZ() << " : " - << stations[0].strings[j].antennas[k].R() << " : " - << stations[0].strings[j].antennas[k].Theta() << " : " - << stations[0].strings[j].antennas[k].Phi() << " : " - << icesurface -> Surface(stations[0].strings[j].antennas[k].Lon(), stations[0].strings[j].antennas[k].Lat()) << " : " + cout << "Detector:station:string:antenna:X:Y:Z:R:Theta:Phi:: " + << "0" << " : " + << j << " : " + << k << " : " + << stations[0].strings[j].antennas[k].GetX() << " : " + << stations[0].strings[j].antennas[k].GetY() << " : " + << stations[0].strings[j].antennas[k].GetZ() << " : " + << stations[0].strings[j].antennas[k].R() << " : " + << stations[0].strings[j].antennas[k].Theta() << " : " + << stations[0].strings[j].antennas[k].Phi() << " : " + << icesurface -> Surface(stations[0].strings[j].antennas[k].Lon(), stations[0].strings[j].antennas[k].Lat()) << " : " << endl; } } @@ -1501,13 +1501,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile antenna_count = 0; for (int j = 0; j < (int)(stations[i].strings.size()); j++) { - for (int k = 0; k < (int)(stations[i].strings[j].antennas.size()); k++) { + for (int k = 0; k < (int)(stations[i].strings[j].antennas.size()); k++) { antenna_count++; } } stations[i].number_of_antennas = antenna_count; - if (max_number_of_antennas_station < antenna_count) { + if (max_number_of_antennas_station < antenna_count) { max_number_of_antennas_station = antenna_count; } } @@ -1525,7 +1525,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile ReadFOAM(string(getenv("ARA_SIM_DIR"))+"/data/FOAM.csv", settings1); // read Rayleigh fit for freq range, bh channels - if (settings1 -> NOISE == 1) { + if (settings1 -> NOISE == 1) { ReadRayleighFit_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/RayleighFit_TB.csv", settings1); // read and save RFCM gain } @@ -1555,10 +1555,10 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile ReadThresOffset_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/threshold_offset.csv", settings1); // only TestBed for now // read threshold values for chs file ReadThres_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/thresholds_TB.csv", settings1); // only TestBed for now - + // read system temperature for chs file!! cout << "check read temp testbed 3" << endl; - if (settings1 -> NOISE_CHANNEL_MODE != 0) { + if (settings1 -> NOISE_CHANNEL_MODE != 0) { ReadTemp_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/system_temperature.csv", settings1); // only TestBed for now } @@ -1578,7 +1578,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile cout << "done read elect chain" << endl; // if calpulser case - if (settings1 -> CALPULSER_ON > 0) { + if (settings1 -> CALPULSER_ON > 0) { // read TestBed Calpulser waveform measured (before pulser) ReadCalPulserWF(string(getenv("ARA_SIM_DIR"))+"/data/CalPulserWF.txt", settings1); } @@ -1587,7 +1587,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile ReadTrig_Delays_Masking(string(getenv("ARA_SIM_DIR"))+"/data/trigger/delays_masking_custom.csv", settings1); } // if mode == 3 - + else if (mode == 4) { // initialize info @@ -1621,35 +1621,35 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile if (label == "core_x") { params.core_x = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read core_x" << endl; - } + } else if (label == "core_y") { params.core_y = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read core_y" << endl; - } + } else if (label == "R_string") { R_string = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read R_string" << endl; - } + } else if (label == "R_surface") { R_surface = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read R_surface" << endl; - } + } else if (label == "z_max") { z_max = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_max" << endl; - } + } else if (label == "z_btw") { z_btw = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read z_btw" << endl; - } + } else if (label == "number_of_stations") { params.number_of_stations = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read stations_per_side" << endl; - } + } else if (label == "station_spacing") { params.station_spacing = atof(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read station_spacting" << endl; - } + } else if (label == "antenna_orientation") { params.antenna_orientation = atoi(line.substr(line.find_first_of("=") + 1).c_str()); cout << "read antenna_orientation" << endl; @@ -1669,7 +1669,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[0].SetX(params.core_x); stations[0].SetY(params.core_y); - if (station_count != (int) params.number_of_stations) { + if (station_count != (int) params.number_of_stations) { cout << "\n\tError, station number not match !" << endl; } @@ -1690,7 +1690,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[i].TIMESTEP = 1. / 2.6 * 1.E-9; stations[i].TRIG_WINDOW = 2.5E-7; stations[i].DATA_BIN_SIZE = settings1 -> DATA_BIN_SIZE; - } + } else if (settings1 -> USE_INSTALLED_TRIGGER_SETTINGS == 1) { if (stations[i].StationID == 0) { stations[i].NFOUR = 1024; @@ -1714,13 +1714,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile for (int j = 0; j < stations[0].strings.size(); j++) { for (int k = 0; k < stations[0].strings[j].antennas.size(); k++) { - cout << "DetectorStation2:string:antenna:X:Y:Z:chno :: " - << j << " : " - << k << " : " - << stations[0].strings[j].antennas[k].GetX() << " : " - << stations[0].strings[j].antennas[k].GetY() << " : " - << stations[0].strings[j].antennas[k].GetZ() << " : \t" - << GetChannelfromStringAntenna(0, j, k, settings1) + cout << "DetectorStation2:string:antenna:X:Y:Z:chno :: " + << j << " : " + << k << " : " + << stations[0].strings[j].antennas[k].GetX() << " : " + << stations[0].strings[j].antennas[k].GetY() << " : " + << stations[0].strings[j].antennas[k].GetZ() << " : \t" + << GetChannelfromStringAntenna(0, j, k, settings1) << endl; params.number_of_antennas++; @@ -1731,17 +1731,17 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile for (int j = 0; j < stations[0].strings.size(); j++) { for (int k = 0; k < stations[0].strings[j].antennas.size(); k++) { - cout << "Detector:station:string:antenna:X:Y:Z:R:Theta:Phi:: " - << "0" << " : " - << j << " : " - << k << " : " - << stations[0].strings[j].antennas[k].GetX() << " : " - << stations[0].strings[j].antennas[k].GetY() << " : " - << stations[0].strings[j].antennas[k].GetZ() << " : " - << stations[0].strings[j].antennas[k].R() << " : " - << stations[0].strings[j].antennas[k].Theta() << " : " - << stations[0].strings[j].antennas[k].Phi() << " : " - << icesurface -> Surface(stations[0].strings[j].antennas[k].Lon(), stations[0].strings[j].antennas[k].Lat()) << " : " + cout << "Detector:station:string:antenna:X:Y:Z:R:Theta:Phi:: " + << "0" << " : " + << j << " : " + << k << " : " + << stations[0].strings[j].antennas[k].GetX() << " : " + << stations[0].strings[j].antennas[k].GetY() << " : " + << stations[0].strings[j].antennas[k].GetZ() << " : " + << stations[0].strings[j].antennas[k].R() << " : " + << stations[0].strings[j].antennas[k].Theta() << " : " + << stations[0].strings[j].antennas[k].Phi() << " : " + << icesurface -> Surface(stations[0].strings[j].antennas[k].Lon(), stations[0].strings[j].antennas[k].Lat()) << " : " << endl; } } @@ -1753,13 +1753,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile antenna_count = 0; for (int j = 0; j < (int)(stations[i].strings.size()); j++) { - for (int k = 0; k < (int)(stations[i].strings[j].antennas.size()); k++) { + for (int k = 0; k < (int)(stations[i].strings[j].antennas.size()); k++) { antenna_count++; } } stations[i].number_of_antennas = antenna_count; - if (max_number_of_antennas_station < antenna_count) { + if (max_number_of_antennas_station < antenna_count) { max_number_of_antennas_station = antenna_count; } } @@ -1777,12 +1777,12 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile // read FOAM gain file!! ReadFOAM(string(getenv("ARA_SIM_DIR"))+"/data/FOAM.csv", settings1); - if (settings1 -> NOISE_CHANNEL_MODE != 0) + if (settings1 -> NOISE_CHANNEL_MODE != 0) ReadTemp_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/system_temperature.csv", settings1); // only TestBed for now if (settings1 -> DETECTOR_STATION == 0) { // read Rayleigh fit for freq range, bh channels - if (settings1 -> NOISE == 1) { + if (settings1 -> NOISE == 1) { ReadRayleighFit_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/RayleighFit_TB.csv", settings1); // read and save RFCM gain } @@ -1815,7 +1815,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile // read system temperature for chs file!! cout << "check read temp testbed 4" << endl; - if (settings1 -> NOISE_CHANNEL_MODE != 0) { + if (settings1 -> NOISE_CHANNEL_MODE != 0) { ReadTemp_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/system_temperature.csv", settings1); // only TestBed for now } } @@ -1827,7 +1827,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile if(settings1->NOISE==1){ cout <<"Reading in situ ARA noise for this station and configuration from file: " <DETECTOR_STATION, settings1->DETECTOR_STATION_LIVETIME_CONFIG); cout << the_rayleigh_filename << endl; ReadRayleighFit_DeepStation(std::string(the_rayleigh_filename), settings1); @@ -1846,12 +1846,12 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile cout << the_gain_filename <DETECTOR_STATION, settings1->DETECTOR_STATION_LIVETIME_CONFIG); cout << the_gain_filename << endl; - } - + } + ReadElectChain(std::string(the_gain_filename), settings1); if(settings1->ELECTRONICS_ANTENNA_CONSISTENCY==1) { if(settings1->NOISE==1) { @@ -1862,7 +1862,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile else { cerr << "WARNING - Antenna model used to calculate in situ gain model may not match that used in this simulation!" << endl; cerr << "\t To ensure consistency load an in-situ noise model with NOISE = 1." << endl; - } + } } } else{ // testbed only @@ -1878,7 +1878,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile cout << "done read elect chain" << endl; // if calpulser case - if (settings1 -> CALPULSER_ON > 0) { + if (settings1 -> CALPULSER_ON > 0) { // read TestBed Calpulser waveform measured (before pulser) ReadCalPulserWF(string(getenv("ARA_SIM_DIR"))+"/data/CalPulserWF.txt", settings1); } @@ -1896,7 +1896,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile cout<<" Reading standard trigger formation values"<DETECTOR_STATION_ARAROOT==1) { cout << "\n A1 is being simulated as an ICRR" << endl; @@ -1910,13 +1910,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile ///////////////////////////////////////////////////////////////////////////// else if (mode == 5){ // Simulates ARA05 + PA station(s) - // Detector setup according to the real station's configuration + // Detector setup according to the real station's configuration // over time specified by DETECTOR_STATION settings parameter - // Options available: + // Options available: // 1: Jan 2018 - Dec 2018 (PA channels only) // 2: October 2019 - Jan 2020 (All PA channels and 1 A5 channel) // 3: Jan 2020 - present (PA + 7 VPols from A5) - + cout << "Simulating realistic ARA05 and Phased Array." << endl; @@ -1927,12 +1927,12 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile // Distances are in meters params.antenna_orientation = 0; // all antennas facing x params.bore_hole_antenna_layout = settings1->BORE_HOLE_ANTENNA_LAYOUT; - params.core_x = 10000.; - params.core_y = 10000.; - params.number_of_surfaces_station = 0; - params.stations_per_side = 1; + params.core_x = 10000.; + params.core_y = 10000.; + params.number_of_surfaces_station = 0; + params.stations_per_side = 1; params.station_spacing = 2000.; - double R_string = 10.; + double R_string = 10.; double R_surface = 60.; // Initialize parameters that have changed over time @@ -1957,13 +1957,13 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } - // Build Station/String/Antenna Vectors + // Build Station/String/Antenna Vectors for (int i=0; iDETECTOR_STATION == 2){ // 1 Vanilla VPol from 1 string attached to PA DAQ stations[i].strings.push_back(temp_string); - stations[i].strings[1].antennas.push_back(temp_antenna); // A5E 24, A5RF 7, PA 5 + stations[i].strings[1].antennas.push_back(temp_antenna); // A5E 24, A5RF 7, PA 5 } else if (settings1->DETECTOR_STATION == 3){ // 7 Vanilla VPols from 4 strings attached to PA DAQ stations[i].strings.push_back(temp_string); @@ -1993,7 +1993,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile int station_count = 0; int side_step; double next_dir = PI*2./3; - for (int istation = 0; istation < (int)params.number_of_stations; istation++) + for (int istation = 0; istation < (int)params.number_of_stations; istation++) { if (station_count < (int)params.number_of_stations - 1) { @@ -2010,7 +2010,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[station_count].SetY( params.core_y ); } // after first station - else { + else { if ( side_step > 0 ) { stations[station_count].SetX( stations[station_count-1].GetX() + (double)params.station_spacing * cos(next_dir) ); stations[station_count].SetY( stations[station_count-1].GetY() + (double)params.station_spacing * sin(next_dir) ); @@ -2033,7 +2033,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile stations[station_count].SetY( params.core_y ); } // after first station - else { + else { if ( side_step > 0 ) { stations[station_count].SetX( stations[station_count-1].GetX() + (double)params.station_spacing * cos(next_dir) ); stations[station_count].SetY( stations[station_count-1].GetY() + (double)params.station_spacing * sin(next_dir) ); @@ -2081,15 +2081,15 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile // Set ARA5 string locations // DETECTOR_STATION == 1 has no ARA5 strings attached to PA DAQ if (settings1->DETECTOR_STATION == 2){ - stations[i].strings[1].SetX( stations[i].GetX() + 12.33); // A5E 24 - stations[i].strings[1].SetY( stations[i].GetY() - 31.89); + stations[i].strings[1].SetX( stations[i].GetX() + 12.33); // A5E 24 + stations[i].strings[1].SetY( stations[i].GetY() - 31.89); } else if (settings1->DETECTOR_STATION == 3){ stations[i].strings[1].SetX( stations[i].GetX() + 29.63); // A5E 0 & 1 stations[i].strings[1].SetY( stations[i].GetY() - 3.30); stations[i].strings[2].SetX( stations[i].GetX() - 12.96); // A5E 16 stations[i].strings[2].SetY( stations[i].GetY() - 8.65); - stations[i].strings[3].SetX( stations[i].GetX() + 12.33); // A5E 24 & 25 + stations[i].strings[3].SetX( stations[i].GetX() + 12.33); // A5E 24 & 25 stations[i].strings[3].SetY( stations[i].GetY() - 31.89); stations[i].strings[4].SetX( stations[i].GetX() + 1.55); // A5E 8 & 9 stations[i].strings[4].SetY( stations[i].GetY() + 15.66); @@ -2116,25 +2116,25 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile // Set all antennas to VPOL (1 for HPOL) stations[i].strings[0].antennas[0].type = 1; // PA Hpol - stations[i].strings[0].antennas[1].type = 1; // PA Hpol + stations[i].strings[0].antennas[1].type = 1; // PA Hpol for (int l=2; l<9; l++) { // PA Vpols stations[i].strings[0].antennas[l].type = 0; } - + if (settings1->DETECTOR_STATION > 1){ // Set all vanilla antennas to VPol for (int k=1; kNOISE_CHANNEL_MODE!=0) { + if (settings1->NOISE_CHANNEL_MODE!=0) { ReadTemp_TestBed(string(getenv("ARA_SIM_DIR"))+"/data/system_temperature.csv", settings1);// only TestBed for now } @@ -2188,14 +2188,14 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile //read the standard ARA electronics char the_gain_filename[500]; if(settings1->DETECTOR_STATION_LIVETIME_CONFIG == -1 || settings1->ELECTRONICS_ANTENNA_CONSISTENCY==1) { - sprintf(the_gain_filename, "%s/data/gain/PA_Electronics_TotalGainPhase.csv", getenv("ARA_SIM_DIR")); + sprintf(the_gain_filename, "%s/data/gain/PA_Electronics_TotalGainPhase.csv", getenv("ARA_SIM_DIR")); cout << " Reading standard PA electronics response from file:" << endl; cout << the_gain_filename <DETECTOR_STATION_LIVETIME_CONFIG); - cout <<" Reading in situ ARA electronics response for the PA and this configuration from file:"< CUSTOM_ELECTRONICS == 1) { //read a custom user defined electronics gain cout << " Reading custom PA electronics response" << endl; @@ -2234,7 +2234,7 @@ Detector::Detector(Settings * settings1, IceModel * icesurface, string setupfile } // if mode == 5 - ///////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////// // add additional depth if it's on AddAdditional_Depth(settings1); @@ -2256,16 +2256,17 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ std::string TxgainFileCross; std::string VgainCrossFile; std::string VgainTopCrossFile; - std::string HgainCrossFile; + std::string HgainCrossFile; + //Adding step to read Tx gain. Will hardcode to PVA gain for now. - TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; - TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; + TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; + TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; if (settings1->ANTENNA_MODE == 0){ // use the orignal Vpol/Hpol gains VgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_bicone6in_output.txt"; VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_bicone6in_output.txt"; - HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_dipoletest1_output.txt"; + HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_dipoletest1_output.txt"; } else if (settings1->ANTENNA_MODE == 1) { // use the gains as Thomas had them circa 2016 @@ -2277,57 +2278,57 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ // and then SWR = (1+reflection_coefficient)/(1-reflection_coefficient). VgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_bicone6in_output_updated2020.txt"; VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_VPresult_topTrec_updated2020.txt"; - HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_dipoletest1_output_updated2020.txt"; + HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_dipoletest1_output_updated2020.txt"; } else if (settings1->ANTENNA_MODE == 2){ // pull a "trick" and substitue the ARIANNA LPDAs for the antennas VgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/Arianna_WIPLD_hpol.dat"; VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/Arianna_WIPLD_hpol.dat"; - HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/Arianna_WIPLD_hpol.dat"; + HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/Arianna_WIPLD_hpol.dat"; } else if(settings1->ANTENNA_MODE == 3){ // load the Chiba XFDTD models // same gain for top and bottom VgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/Vpol_original_CrossFeed_150mmHole_Ice_ARASim.txt"; VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/Vpol_original_CrossFeed_150mmHole_Ice_ARASim.txt"; - HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/Hpol_original_150mmHole_Ice_ARASim.txt"; + HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/Hpol_original_150mmHole_Ice_ARASim.txt"; } else if (settings1->ANTENNA_MODE == 4){ // load the Chiba in-situ models // same gain for top and bottom VgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/In_situ_VPol_Model.txt"; VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/In_situ_VPol_Model.txt"; - HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/In_situ_HPol_Model.txt"; + HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/In_situ_HPol_Model.txt"; } else if (settings1->ANTENNA_MODE == 5) { //Adding antenna mode for Kansas lab measurements. VgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Copol_Kansas2024.txt"; VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_TVpol_RealizedGainAndPhase_Copol_Kansas2024.txt"; - HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Copol_Kansas2024.txt"; + HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Copol_Kansas2024.txt"; } else if (settings1->ANTENNA_MODE == 6) { //Adding antenna mode for custom gains. VgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Copol_Custom.txt"; VgainTopFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_TVpol_RealizedGainAndPhase_Copol_Custom.txt"; - HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Copol_Custom.txt"; + HgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Copol_Custom.txt"; } // Add cross-pol gain files VgainCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; - //VgainTopCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; //Should be TV but it's not working due to a negative SWR (first SWR entry) -ASG 12/09/24 + VgainTopCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_BVpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; //Should be TV but it's not working due to a negative SWR (first SWR entry) -ASG 12/09/24 HgainCrossFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_Hpol_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; - + // Check for ALL_ANT_V_ON, then set all antennas to VPol if true if (settings1->ALL_ANT_V_ON == 1) { HgainFile = VgainFile; VgainTopFile = VgainFile; } - + // set parameters to "unset" values freq_step = -1; ang_step = -1; freq_width = -1; - freq_init = -1; - + freq_init = -1; + //Read in antenna co-pol gain files. ReadAntennaGain(VgainFile, settings1, eVPol); ReadAntennaGain(VgainTopFile, settings1, eVPolTop); @@ -2345,12 +2346,12 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ params.ang_step = ang_step; params.freq_width = freq_width; params.freq_init = freq_init; - + return; } //Defining function that reads in TX antenna impedances inline void Detector::ReadAllAntennaImpedance(Settings *settings1) { - + //Initialize array of impedance filepaths, where the indices correspond to the IMPEDANCE_<> flag in the setup file. std::string impedanceFileArray[9] = {string(getenv("ARA_SIM_DIR"))+"/data/antennas/impedance/ARA_Impedance_SimpleApproximation.txt", string(getenv("ARA_SIM_DIR"))+"/data/antennas/impedance/ARA_BVpol_MohammadData_2024.txt", @@ -2365,12 +2366,12 @@ inline void Detector::ReadAllAntennaImpedance(Settings *settings1) { //Vpol ReadImpedance(impedanceFileArray[settings1->IMPEDANCE_RX_VPOL], &RealImpedanceV, &ImagImpedanceV); //Vpol Top - ReadImpedance(impedanceFileArray[settings1->IMPEDANCE_RX_VPOL_TOP], &RealImpedanceVTop, &ImagImpedanceVTop); + ReadImpedance(impedanceFileArray[settings1->IMPEDANCE_RX_VPOL_TOP], &RealImpedanceVTop, &ImagImpedanceVTop); //Hpol ReadImpedance(impedanceFileArray[settings1->IMPEDANCE_RX_HPOL], &RealImpedanceH, &ImagImpedanceH); //Tx - ReadImpedance(impedanceFileArray[settings1->IMPEDANCE_TX], &RealImpedanceTx, &ImagImpedanceTx); - + ReadImpedance(impedanceFileArray[settings1->IMPEDANCE_TX], &RealImpedanceTx, &ImagImpedanceTx); + }//ReadAllAntennaImpedance // convert the swr into a transmission coefficient @@ -2387,7 +2388,7 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt vector< vector > * gain; vector< vector > * phase; vector* transAnt_databin; - // make sure dummy variables point to the right variables + // make sure dummy variables point to the right variables switch(type) { case(eVPol): freq = &Freq; @@ -2426,12 +2427,12 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt transAnt_databin = &transHCross_databin; break; case(eTx): - freq = &Freq; + freq = &TxFreq; gain = &Txgain; phase = &Txphase; break; case(eTxCross): - freq = &Freq; + freq = &TxFreq; gain = &TxgainCross; phase = &TxphaseCross; break; @@ -2440,7 +2441,7 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt } // open the requested file ifstream NecOut( filename.c_str() ); - + // initialize some variables used for read-in vector Transm; string line; @@ -2448,22 +2449,22 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt // clear vector in case there's any lingering data gain->clear(); phase->clear(); - + if(freq_step == -1 || type == eTx) { // only reset if it hasn't been read-in yet - freq->clear(); + freq->clear(); } // check the file opened successfully - if (! NecOut.is_open() ) { + if (! NecOut.is_open() ) { throw runtime_error("Antenna gain file could not be opened: "+filename); } - + // read the first line getline (NecOut, line); - - // start reading the file + + // start reading the file while (NecOut.good() ) { - + //put line into a string stream stringstream ss(line); @@ -2473,7 +2474,7 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt while(ss >> buff) { // >> skips whitespace and just goes to the next word words.push_back(buff); } - + // check if this is the start of a new frequency section if (words.size() > 0 && words[0] == "freq") { @@ -2497,7 +2498,7 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt if(abs(freq->at(i)-thisFreq) > 0.1 ) { // ensure they match to at least 0.1 MHz throw runtime_error("Frequency bins of antenna models do not match! "+filename); } - } + } // read SWR info line getline (NecOut, line); @@ -2526,11 +2527,11 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt // read in next line but we won't do anything with it getline (NecOut, line); //read names (ie column names) - + // add new vector to gain and phase gain->push_back(vector()); phase->push_back(vector()); - + } // end frequency/header read in // otherwise we are reading in theta/phi values for a specific frequency @@ -2540,7 +2541,7 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt if(words.size() != 5) { throw runtime_error("Antenna gain file data line not properly formatted! "+filename); } - + // save dB gain and phase and check they are sensible double thisdBGain = stof(words[2]); double thisPhase = stof(words[4]); @@ -2555,30 +2556,30 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt gain->back().push_back(pow(10, thisdBGain/10)); //Importing gain in dB, then converting to linear gain phase->back().push_back(thisPhase); - } // end theta/phi read in - + } // end theta/phi read in + // read the next line getline (NecOut, line); - + }// end while NecOut.good NecOut.close(); - // skip this for the transmitter case for now since it may not match other models + // skip this for the transmitter case for now since it may not match other models if(type == eTx) { Tx_freq_width = freq->at(1)-freq->at(0); Tx_freq_init = freq->at(0); - + return; } int this_freq_step = (int)freq->size(); // set parameter values for the smallest freq_step - if(freq_step == -1 || this_freq_step < freq_step) { + if(freq_step == -1 || this_freq_step < freq_step) { freq_step = this_freq_step; ang_step = (int)gain->back().size(); freq_width = freq->at(1)-freq->at(0); - freq_init = freq->at(0); + freq_init = freq->at(0); } // Only enforce check for non-Tx and non-crosspol antennas if(type != eTx && type != eTxCross && type != eVPolCross && type != eVPolTopCross && type != eHPolCross) { @@ -2589,7 +2590,7 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt if(gain->size() != freq_step) { throw runtime_error("gain has an unexpected length! "+filename); } - if(phase->size() != freq_step) { + if(phase->size() != freq_step) { throw runtime_error("phase has an unexpected length! "+filename); } for(int i = 0; i < freq_step; ++i) { @@ -2601,13 +2602,13 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt } } } - - // skip this for the transmitter case + + // skip this for the transmitter case if(type == eTx) { return; } - - const int N = freq_step; + + const int N = freq_step; double xfreq[N]; if(freq_step > settings1->DATA_BIN_SIZE/2) { @@ -2616,20 +2617,20 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt vector xfreq_databin(settings1->DATA_BIN_SIZE/2); // array for FFT freq bin double trans_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); - + // now below are values that shared in all channels for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE xfreq_databin[i] = (double)i * df_fft / (1.E6); // from Hz to MHz - } + } // store the frequency bins used (should be okay to overwrite since all antenna types have same binning since it's defined here) - trans_freq = xfreq_databin; - + trans_freq = xfreq_databin; + Tools::SimpleLinearInterpolation( freq_step-1, xfreq, &Transm[0], settings1->DATA_BIN_SIZE/2, &xfreq_databin[0], trans_databin ); for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE if(!std::isfinite(trans_databin[i])) { @@ -2639,14 +2640,14 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt } return; -} +} // linearly interpolate the transmittance for a channel at a particular frequency (OutZero == extrapolation is fixed to return 0) double Detector::GetTransm_OutZero(int ch, double freq) { ch = ch%16; // to match the convention of Detector::GetTransm_databin - vector* transm; + vector* transm; if(ch < 4) transm = &transVTop_databin; else if(ch < 8) @@ -2655,52 +2656,52 @@ double Detector::GetTransm_OutZero(int ch, double freq) { transm = &transH_databin; const int nFreq = (int)trans_freq.size(); - const double dfreq = trans_freq[1] - trans_freq[0]; + const double dfreq = trans_freq[1] - trans_freq[0]; const int bin = (int)( (freq - trans_freq[0]) / dfreq )+1; if(freq == trans_freq[0]) return transm->front(); - + if(freq == trans_freq.back()) return transm->back(); - + if(bin <= 0 || bin >= nFreq) return 0; const double m = (transm->at(bin) - transm->at(bin-1))/(trans_freq[bin] - trans_freq[bin-1]); - const double b = transm->at(bin-1); - - return m*(freq - trans_freq[bin-1]) + b; + const double b = transm->at(bin-1); + + return m*(freq - trans_freq[bin-1]) + b; } double Detector::GetGain(double freq, double theta, double phi, int ant_m, int ant_o) { // using Interpolation on multidimentions! - + // change antenna facing orientation if (ant_o == 0) { // no change... } else if (ant_o == 1) { - if (phi - 90. >= 0.) { + if (phi - 90. >= 0.) { phi = phi - 90.; } - else { + else { phi = 360. + phi - 90.; } } else if (ant_o == 2) { - if (phi - 180. >= 0.) { + if (phi - 180. >= 0.) { phi = phi - 180.; } - else { + else { phi = 360. + phi - 180.; } } else if (ant_o == 3) { - if (phi - 270. >= 0.) { + if (phi - 270. >= 0.) { phi = phi - 270.; } - else { + else { phi = 360. + phi - 270.; } } @@ -2709,36 +2710,36 @@ double Detector::GetGain(double freq, double theta, double phi, int ant_m, int a cout<<"ant_o will be replaced from "< (freq_init + freq_width*((double)freq_step-1.) ) ) { + else if ( freq > (freq_init + freq_width*((double)freq_step-1.) ) ) { //cout<<"Frequency value is bigger than frequency range with Gain."< (freq_init + freq_width*((double)freq_step - 1.) ) ) { + else if ( freq > (freq_init + freq_width*((double)freq_step - 1.) ) ) { //cout<<"Frequency value is bigger than frequency range with Gain."< (freq_init + freq_width*((double)freq_step - 1.) ) ) { + else if ( freq > (freq_init + freq_width*((double)freq_step - 1.) ) ) { //cout<<"Frequency value is bigger than frequency range with phase."< > *tempGain = nullptr; - vector * F; - + vector * F; + //Assign local pointer to gain array specified in the function argument //VPol Rx if (Detector_mode == 5) { // Phased Array mode if (useInTransmitterMode) { tempGain = useCrossPol ? &TxgainCross : &Txgain; // Transmitter mode - } + } else if (ant_m == 1) { tempGain = useCrossPol ? &HgainCross : &Hgain; // HPol - } + } else { // VPol if (string_number == 0) { tempGain = useCrossPol ? &VgainCross : &Vgain; - } + } else { if (ant_number == 1) { tempGain = useCrossPol ? &VgainTopCross : &VgainTop; // A5 Top VPols - } + } else { tempGain = useCrossPol ? &VgainCross : &Vgain; // A5 Bottom VPols } @@ -3063,11 +3064,11 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int if (ant_m == 0) { // VPol if (ant_number == 0) { tempGain = useCrossPol ? &VgainCross : &Vgain; - } + } else if (ant_number == 2) { tempGain = useCrossPol ? &VgainTopCross : &VgainTop; } - } + } else if (ant_m == 1) { // HPol tempGain = useCrossPol ? &HgainCross : &Hgain; } @@ -3091,13 +3092,13 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int F = &Freq; thisFreq_init = freq_init; thisFreq_width = freq_width; - } - + } + // check if angles range actually theta 0-180, phi 0-360 int i = (int)( (theta+2.5)/5. ); int j = (int)( (phi+2.5)/5. ); - if ( j == 72 ) { + if ( j == 72 ) { j = 0; } @@ -3109,27 +3110,72 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int double Gout; int bin = (int)( (freq - thisFreq_init) / thisFreq_width )+1; + cout << "thisFreq_init: " << thisFreq_init << endl; + cout << "thisFreq_width: " << thisFreq_width << endl; + + + // ========== Begin Debug Block ========== + cout << "[DEBUG] tempGain size: " << tempGain->size() << endl; + if(tempGain->size() < 2) { + cerr << "[ERROR] tempGain has size " << tempGain->size() << ", need at least 2 for interpolation.\n"; + throw std::out_of_range("tempGain too small in GetGain1D()"); + } + cout << "[DEBUG] tempGain[0] size: " << (*tempGain)[0].size() << ", tempGain[1] size: " << (*tempGain)[1].size() << endl; + cout << "[DEBUG] angle_bin: " << angle_bin << endl; + + if(angle_bin >= (*tempGain)[0].size() || angle_bin >= (*tempGain)[1].size()) { + cerr << "[ERROR] angle_bin " << angle_bin << " is out of range for gain vectors.\n"; + throw std::out_of_range("angle_bin out of range in GetGain1D()"); + } + + if(F->size() < 2) { + cerr << "[ERROR] F vector has only " << F->size() << " entries. Cannot interpolate.\n"; + throw std::out_of_range("F vector too small in GetGain1D()"); + } + + cout << "[DEBUG] F[0]: " << F->at(0) << ", F[1]: " << F->at(1) << endl; + // ========== End Debug Block ========== //Interpolation of tempGain slope_1 = ((*tempGain)[1][angle_bin] - (*tempGain)[0][angle_bin]) / (F->at(1) - F->at(0)); + cout << "ASG 2" << endl; + cout << "freq" << freq << endl; + // if freq is lower than freq_init - if ( freq < thisFreq_init ) { + if ( freq < thisFreq_init ) { + cout << "Here 1" << endl; Gout = slope_1 * (freq - F->at(0)) + (*tempGain)[0][angle_bin]; + cout << "Here 1" << endl; } // if freq is higher than last freq - else if ( freq > F->back() ) { - Gout = 0.; + else if ( freq > F->back() ) { + cout << "Here 2" << endl; + + Gout = 0.; + cout << "Here 2" << endl; + } - else { + else { + cout << "Here 3" << endl; +cout << "[DEBUG] bin = " << bin + << ", F.size = " << F->size() + << ", F->back()" << F->back() + << ", freq = " << freq << endl; Gout = (*tempGain)[bin-1][angle_bin] + (freq-F->at(bin-1))*((*tempGain)[bin][angle_bin]-(*tempGain)[bin-1][angle_bin])/(F->at(bin)-F->at(bin-1)); - } + cout << "Here 3" << endl; - if ( Gout < 0. ) { // gain can not go below 0 - Gout = 0.; } + if ( Gout < 0. ) { // gain can not go below 0 + cout << "Here 4" << endl; + + Gout = 0.; + cout << "Here 4" << endl; + + } +cout << "ASG 3" << endl; return Gout; } @@ -3139,26 +3185,26 @@ double Detector::GetImpedance( double freq, int ant_m, int ant_number, bool useI //Initialize pointer to dynamically point to the impedance for the chosen antenna. double (*tempImpedance)[freq_step_max] = nullptr; //Tx - if (useInTransmitterMode) { + if (useInTransmitterMode) { tempImpedance = &RealImpedanceTx; } //VPol Rx - else if (ant_m == 0) { + else if (ant_m == 0) { tempImpedance = &RealImpedanceV; } //HPol Rx - else if (ant_m == 1) { + else if (ant_m == 1) { tempImpedance = &RealImpedanceH; } - else { + else { throw runtime_error("In GetImpedance: No appropriate impedance model for this simulation setup."); - } - - vector * F = &impFreq; + } + + vector * F = &impFreq; double thisFreq_init = F->at(0); double thisFreq_width = F->at(1) - F->at(0); int thisFreq_step = (int)F->size(); - + //The following is a simplified form of the interpolation used in GetGain_1D_OutZero, where we only interpolate over freuqnecy bins and ignore angle bins. double slope_1; // slope of init part @@ -3170,16 +3216,16 @@ double Detector::GetImpedance( double freq, int ant_m, int ant_number, bool useI slope_1 = ((*tempImpedance)[1] - (*tempImpedance)[0]) / (F->at(1) - F->at(0)); // if freq is lower than freq_init - if ( freq < thisFreq_init ) { + if ( freq < thisFreq_init ) { ZOut = slope_1 * (freq - F->at(0)) + (*tempImpedance)[0]; } // if freq is higher than last freq - else if ( freq > F->back() ) { + else if ( freq > F->back() ) { ZOut = 0.; } - else { + else { ZOut = (*tempImpedance)[bin-1] + (freq - F->at(bin-1))*((*tempImpedance)[bin]-(*tempImpedance)[bin-1])/(F->at(bin) - F->at(bin-1)); - } + } if ( ZOut < 0. ) { // impedance can not go below 0 ZOut = 0.; @@ -3190,26 +3236,26 @@ double Detector::GetImpedance( double freq, int ant_m, int ant_number, bool useI double Detector::GetAntPhase_1D( double freq, double theta, double phi, int ant_m, bool useInTransmitterMode, bool useCrossPol ) { - + //Creating tempPhase array to make this function more dynamic for Rx and Tx mode. vector > *tempPhase = nullptr; - vector * F; - + vector * F; + // Assign tempPhase based on polarization type and cross-pol flag if (!useInTransmitterMode) { if (ant_m == 0) { // VPol tempPhase = useCrossPol ? &VphaseCross : &Vphase; - } + } else if (ant_m == 1) { // HPol tempPhase = useCrossPol ? &HphaseCross : &Hphase; } - } + } else { // Transmitter mode tempPhase = useCrossPol ? &TxphaseCross : &Txphase; } if (!tempPhase) { throw runtime_error("In GetAntPhase_1D: No appropriate phase model for this simulation setup."); - } + } double thisFreq_init; double thisFreq_width; @@ -3224,13 +3270,13 @@ double Detector::GetAntPhase_1D( double freq, double theta, double phi, int ant_ thisFreq_init = freq_init; thisFreq_width = freq_width; } - thisFreq_step = (int)F->size(); + thisFreq_step = (int)F->size(); // check if angles range actually theta 0-180, phi 0-360 int i = (int)( (theta+2.5)/5. ); int j = (int)( (phi+2.5)/5. ); - if ( j == 72 ) { + if ( j == 72 ) { j = 0; } @@ -3256,12 +3302,12 @@ double Detector::GetAntPhase_1D( double freq, double theta, double phi, int ant_ phase = slope_1 * (freq - F->at(0)) + (*tempPhase)[0][angle_bin]; if ( phase > 180. ) { - while ( phase > 180. ) { + while ( phase > 180. ) { phase = phase - 360.; } } else if ( phase < -180. ) { - while ( phase < -180. ) { + while ( phase < -180. ) { phase = phase + 360.; } } @@ -3272,12 +3318,12 @@ double Detector::GetAntPhase_1D( double freq, double theta, double phi, int ant_ phase = slope_2 * (freq - F->back()) + (*tempPhase)[thisFreq_step-1][angle_bin]; if ( phase > 180. ) { - while ( phase > 180. ) { + while ( phase > 180. ) { phase = phase - 360.; } } else if ( phase < -180. ) { - while ( phase < -180. ) { + while ( phase < -180. ) { phase = phase + 360.; } } @@ -3292,43 +3338,43 @@ double Detector::GetAntPhase_1D( double freq, double theta, double phi, int ant_ slope_t2 = ((*tempPhase)[bin+1][angle_bin] - (*tempPhase)[bin][angle_bin]) / (F->at(bin+1) - F->at(bin)); // down going case - if ( slope_t1 * slope_t2 > 0. && (*tempPhase)[bin][angle_bin] - (*tempPhase)[bin-1][angle_bin] > 180. ) { + if ( slope_t1 * slope_t2 > 0. && (*tempPhase)[bin][angle_bin] - (*tempPhase)[bin-1][angle_bin] > 180. ) { phase = (*tempPhase)[bin-1][angle_bin] + (freq - F->at(bin-1))*((*tempPhase)[bin][angle_bin]-360.-(*tempPhase)[bin-1][angle_bin])/(F->at(bin) - F->at(bin-1)); } // up going case - else if ( slope_t1 * slope_t2 > 0. && (*tempPhase)[bin][angle_bin] - (*tempPhase)[bin-1][angle_bin] < -180. ) { + else if ( slope_t1 * slope_t2 > 0. && (*tempPhase)[bin][angle_bin] - (*tempPhase)[bin-1][angle_bin] < -180. ) { phase = (*tempPhase)[bin-1][angle_bin] + (freq - F->at(bin-1))*((*tempPhase)[bin][angle_bin]+360.-(*tempPhase)[bin-1][angle_bin])/(F->at(bin) - F->at(bin-1)); } // neither case - else { + else { phase = (*tempPhase)[bin-1][angle_bin] + (freq - F->at(bin-1))*((*tempPhase)[bin][angle_bin]-(*tempPhase)[bin-1][angle_bin])/(F->at(bin) - F->at(bin-1)); - } + } // if outside the range, put inside if ( phase > 180. ) { - while ( phase > 180. ) { + while ( phase > 180. ) { phase = phase - 360.; } } else if ( phase < -180. ) { - while ( phase < -180. ) { + while ( phase < -180. ) { phase = phase + 360.; } } }// not first two bins - else { + else { phase = (*tempPhase)[bin-1][angle_bin] + (freq - F->at(bin-1))*((*tempPhase)[bin][angle_bin]-(*tempPhase)[bin-1][angle_bin])/(F->at(bin) - F->at(bin-1)); } - + // if outside the range, put inside if ( phase > 180. ) { - while ( phase > 180. ) { + while ( phase > 180. ) { phase = phase - 360.; } } else if ( phase < -180. ) { - while ( phase < -180. ) { + while ( phase < -180. ) { phase = phase + 360.; } } @@ -3349,17 +3395,17 @@ double Detector::GetFilterGain_1D_OutZero( double freq ) { slope_1 = (FilterGain[1] - FilterGain[0]) / (Freq[1] - Freq[0]); // if freq is lower than freq_init - if ( freq < freq_init ) { + if ( freq < freq_init ) { Gout = slope_1 * (freq - Freq[0]) + FilterGain[0]; } // if freq is higher than last freq - else if ( freq > Freq[freq_step-1] ) { + else if ( freq > Freq[freq_step-1] ) { Gout = 0.; } - else { + else { Gout = FilterGain[bin-1] + (freq-Freq[bin-1])*(FilterGain[bin]-FilterGain[bin-1])/(Freq[bin]-Freq[bin-1]); - } - + } + return Gout; } @@ -3376,14 +3422,14 @@ double Detector::GetPreampGain_1D_OutZero( double freq ) { // if freq is lower than freq_init - if ( freq < freq_init ) { + if ( freq < freq_init ) { Gout = slope_1 * (freq - Freq[0]) + PreampGain[0]; } // if freq is higher than last freq - else if ( freq > Freq[freq_step-1] ) { + else if ( freq > Freq[freq_step-1] ) { Gout = 0.; } - else { + else { Gout = PreampGain[bin-1] + (freq-Freq[bin-1])*(PreampGain[bin]-PreampGain[bin-1])/(Freq[bin]-Freq[bin-1]); } @@ -3401,14 +3447,14 @@ double Detector::GetFOAMGain_1D_OutZero( double freq ) { slope_1 = (FOAMGain[1] - FOAMGain[0]) / (Freq[1] - Freq[0]); // if freq is lower than freq_init - if ( freq < freq_init ) { + if ( freq < freq_init ) { Gout = slope_1 * (freq - Freq[0]) + FOAMGain[0]; } // if freq is higher than last freq - else if ( freq > Freq[freq_step-1] ) { + else if ( freq > Freq[freq_step-1] ) { Gout = 0.; } - else { + else { Gout = FOAMGain[bin-1] + (freq-Freq[bin-1])*(FOAMGain[bin]-FOAMGain[bin-1])/(Freq[bin]-Freq[bin-1]); } @@ -3417,7 +3463,7 @@ double Detector::GetFOAMGain_1D_OutZero( double freq ) { // set outside value as 0 double Detector::GetElectGain_1D_OutZero( double freq, int gain_ch_no) { - + double slope_1; // slope of init part double Gout; @@ -3427,17 +3473,17 @@ double Detector::GetElectGain_1D_OutZero( double freq, int gain_ch_no) { // if freq is lower than freq_init - if ( bin < 1) { + if ( bin < 1) { Gout = 0.; } // if freq is higher than last freq else if ( bin > freq_step -1 ) { Gout = 0.; } - else { + else { Gout = ElectGain[gain_ch_no][bin-1] + (freq-Freq[bin-1])*(ElectGain[gain_ch_no][bin]-ElectGain[gain_ch_no][bin-1])/(Freq[bin]-Freq[bin-1]); - } - + } + return Gout; } @@ -3462,12 +3508,12 @@ double Detector::GetElectPhase_1D( double freq, int gain_ch_no ) { phase = slope_1 * (freq - Freq[0]) + ElectPhase[gain_ch_no][0]; if ( phase > PI ) { - while ( phase > PI ) { + while ( phase > PI ) { phase = phase - 2*PI; } } else if ( phase < -PI ) { - while ( phase < -PI ) { + while ( phase < -PI ) { phase = phase + 2*PI; } } @@ -3478,12 +3524,12 @@ double Detector::GetElectPhase_1D( double freq, int gain_ch_no ) { phase = slope_2 * (freq - Freq[freq_step-1]) + ElectPhase[gain_ch_no][freq_step-1]; if ( phase > PI ) { - while ( phase > PI ) { + while ( phase > PI ) { phase = phase - 2*PI; } } else if ( phase < -PI ) { - while ( phase < -PI ) { + while ( phase < -PI ) { phase = phase + 2*PI; } } @@ -3497,26 +3543,26 @@ double Detector::GetElectPhase_1D( double freq, int gain_ch_no ) { slope_t2 = (ElectPhase[gain_ch_no][bin+1] - ElectPhase[gain_ch_no][bin]) / (Freq[bin+1] - Freq[bin]); // down going case - if ( slope_t1 * slope_t2 > 0. && ElectPhase[gain_ch_no][bin] - ElectPhase[gain_ch_no][bin-1] > PI ) { + if ( slope_t1 * slope_t2 > 0. && ElectPhase[gain_ch_no][bin] - ElectPhase[gain_ch_no][bin-1] > PI ) { phase = ElectPhase[gain_ch_no][bin-1] + (freq-Freq[bin-1])*(ElectPhase[gain_ch_no][bin]-2*PI-ElectPhase[gain_ch_no][bin-1])/(Freq[bin]-Freq[bin-1]); } // up going case - else if ( slope_t1 * slope_t2 > 0. && ElectPhase[gain_ch_no][bin] - ElectPhase[gain_ch_no][bin-1] < -PI ) { + else if ( slope_t1 * slope_t2 > 0. && ElectPhase[gain_ch_no][bin] - ElectPhase[gain_ch_no][bin-1] < -PI ) { phase = ElectPhase[gain_ch_no][bin-1] + (freq-Freq[bin-1])*(ElectPhase[gain_ch_no][bin]+2*PI-ElectPhase[gain_ch_no][bin-1])/(Freq[bin]-Freq[bin-1]); } // neither case - else { + else { phase = ElectPhase[gain_ch_no][bin-1] + (freq-Freq[bin-1])*(ElectPhase[gain_ch_no][bin]-ElectPhase[gain_ch_no][bin-1])/(Freq[bin]-Freq[bin-1]); } // if outside the range, put inside if ( phase > PI ) { - while ( phase > PI ) { + while ( phase > PI ) { phase = phase - 2*PI; } } else if ( phase < -PI ) { - while ( phase < -PI ) { + while ( phase < -PI ) { phase = phase + 2*PI; } } @@ -3528,12 +3574,12 @@ double Detector::GetElectPhase_1D( double freq, int gain_ch_no ) { // if outside the range, put inside if ( phase > PI ) { - while ( phase > PI ) { + while ( phase > PI ) { phase = phase - 2*PI; } } else if ( phase < -PI ) { - while ( phase < -PI ) { + while ( phase < -PI ) { phase = phase + 2*PI; } } @@ -3544,175 +3590,175 @@ double Detector::GetElectPhase_1D( double freq, int gain_ch_no ) { } double Antenna::GetG(Detector *D, double freq, double theta, double phi) { - + return D->GetGain(freq, theta, phi, type, orient); } double Surface_antenna::GetG(Detector *D, double freq, double theta, double phi) { - + return D->GetGain(freq, theta, phi, type, orient); } inline void Detector::FlattoEarth_ARA(IceModel *icesurface) { - + double Dist = 0.; //for sqrt(x^2 + y^2) double R1 = icesurface->Surface(0.,0.); // from core of earth to surface at theta, phi = 0. double theta_tmp; double phi_tmp; - + // stations // stations, strings, and borehole antennas use geoid surface !! for (int i=0; i < stations.size(); i++) { - + Dist = sqrt( pow(stations[i].GetX(),2) + pow(stations[i].GetY(),2) ); theta_tmp = Dist/R1; phi_tmp = atan2(stations[i].GetY(),stations[i].GetX()); - - if (phi_tmp<0.) { + + if (phi_tmp<0.) { phi_tmp += 2.*PI; } - + // set theta, phi for stations. stations[i].SetThetaPhi(theta_tmp, phi_tmp); //set R for stations. stations[i].SetR( icesurface->Surface( stations[i].Lon(), stations[i].Lat()) ); - - + + // strings for (int j=0; j < stations[i].strings.size(); j++) { Dist = sqrt( pow(stations[i].strings[j].GetX(),2) + pow(stations[i].strings[j].GetY(),2) ); theta_tmp = Dist/R1; phi_tmp = atan2(stations[i].strings[j].GetY(),stations[i].strings[j].GetX()); - - if (phi_tmp<0.) { + + if (phi_tmp<0.) { phi_tmp += 2.*PI; } - + stations[i].strings[j].SetThetaPhi(theta_tmp, phi_tmp); // string Vector points the position where string meets the ice surface! stations[i].strings[j].SetR( icesurface->Surface( stations[i].strings[j].Lon(), stations[i].strings[j].Lat()) ); - + // borehole antennas - for (int k=0; kSurface( stations[i].surfaces[l].Lon(), stations[i].surfaces[l].Lat()) ); } } - - return; + + return; } inline void Detector::FlattoEarth_ARA_sharesurface(IceModel *icesurface) { // each station share the lowest surface - + double Dist = 0.; //for sqrt(x^2 + y^2) double R1 = icesurface->Surface(0.,0.); // from core of earth to surface at theta, phi = 0. double theta_tmp; double phi_tmp; - + double lowest_surface; // lowest surface of the string among the station - + // stations // stations, strings, and borehole antennas use geoid surface !! for (int i=0; iSurface( stations[i].Lon(), stations[i].Lat()) ); - + lowest_surface = 1.E7; // much bigger than the surface (approx radius of earth 6.E6) - + // strings for (int j=0; jSurface( stations[i].strings[j].Lon(), stations[i].strings[j].Lat()) ); - + // find the lowest surface among strings in a station - if ( lowest_surface > stations[i].strings[j].R() ) { + if ( lowest_surface > stations[i].strings[j].R() ) { lowest_surface = stations[i].strings[j].R(); } } - + // string loop again for borehole antennas for (int j=0; jSurface( stations[i].surfaces[l].Lon(), stations[i].surfaces[l].Lat()) ); } - + } // end loop over stations - + for (int i = 0; i < int(stations.size()); i++){ for (int j = 0; j < int(stations[i].strings.size()); j++){ for (int k = 0; k < int(stations[i].strings[j].antennas.size()); k++){ - cout << "Sharesurface: " - << i << " : " - << j << " : " - << k << " : " - << stations[i].strings[j].antennas[k].GetX() << " : " - << stations[i].strings[j].antennas[k].GetY() << " : " - << stations[i].strings[j].antennas[k].GetZ() << " : " + cout << "Sharesurface: " + << i << " : " + << j << " : " + << k << " : " + << stations[i].strings[j].antennas[k].GetX() << " : " + << stations[i].strings[j].antennas[k].GetY() << " : " + << stations[i].strings[j].antennas[k].GetZ() << " : " << endl; } } } - - return; + + return; } inline void Detector::AddAdditional_Depth(Settings *settings1) { // each station share the lowest surface - + if (settings1->ADDITIONAL_DEPTH_ON == 1) { // stations for (int i=0; i xfreq_tmp; vector ygain_tmp; - + if ( Filter.is_open() ) { while (Filter.good() ) { - + getline (Filter, line); xfreq_tmp.push_back( atof( line.substr(0, line.find_first_of(",")).c_str() ) ); ygain_tmp.push_back( atof( line.substr(line.find_first_of(",") + 1).c_str() ) ); - + N++; } Filter.close(); } else { cout<<"Filter file can not opened!!"<DATA_BIN_SIZE/2]; // array for FFT freq bin double ygain_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); - + for (int i=0;iDATA_BIN_SIZE/2;i++) { // this one is for DATA_BIN_SIZE xfreq_databin[i] = (double)i * df_fft / (1.E6); // from Hz to MHz - } + } // Tools::SimpleLinearInterpolation will return Filter array (in dB) Tools::SimpleLinearInterpolation( N, xfreq, ygain, freq_step, &Freq[0], FilterGain ); - + Tools::SimpleLinearInterpolation( N, xfreq, ygain, settings1->DATA_BIN_SIZE/2, xfreq_databin, ygain_databin ); - - for (int i=0; iDATA_BIN_SIZE/2; i++) { + + for (int i=0; iDATA_BIN_SIZE/2; i++) { FilterGain_databin.push_back( ygain_databin[i] ); } - + // for NFOUR/2 t domain array double xfreq_NFOUR[settings1->NFOUR/4+1]; // array for FFT freq bin double ygain_NFOUR[settings1->NFOUR/4+1]; // array for gain in FFT bin - + df_fft = 1./ ( (double)(settings1->NFOUR/2) * settings1->TIMESTEP ); for (int i=0;iNFOUR/4+1;i++) { // this one is for DATA_BIN_SIZE @@ -3792,12 +3838,12 @@ inline void Detector::ReadFilter(string filename, Settings *settings1) { // w } Tools::SimpleLinearInterpolation( N, xfreq, ygain, settings1->NFOUR/4+1, xfreq_NFOUR, ygain_NFOUR ); - - for (int i=0;iNFOUR/4+1;i++) { + + for (int i=0;iNFOUR/4+1;i++) { FilterGain_NFOUR.push_back( ygain_NFOUR[i] ); } - - return; + + return; } @@ -3810,7 +3856,7 @@ void Detector::ReadFilter_New(Settings *settings1) { // will return gain (dB) std::vector xfreq_databin(n_bins); // vector for FFT freq bin std::vector ygain_databin(n_bins); // vector for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE @@ -3818,10 +3864,10 @@ void Detector::ReadFilter_New(Settings *settings1) { // will return gain (dB) } Tools::SimpleLinearInterpolation( freq_step, &Freq[0], FilterGain, settings1->DATA_BIN_SIZE/2, xfreq_databin.data(), ygain_databin.data() ); - + FilterGain_databin.clear(); - - for (int i=0;iDATA_BIN_SIZE/2;i++) { + + for (int i=0;iDATA_BIN_SIZE/2;i++) { FilterGain_databin.push_back( ygain_databin[i] ); } @@ -3830,60 +3876,60 @@ void Detector::ReadFilter_New(Settings *settings1) { // will return gain (dB) inline void Detector::ReadPreamp(string filename, Settings *settings1) { // will return gain (dB) with same freq bin with antenna gain - + ifstream Preampgain( filename.c_str() ); - + string line; - + int N=-1; - + vector xfreq_tmp; vector ygain_tmp; - + if ( Preampgain.is_open() ) { while (Preampgain.good() ) { - + getline (Preampgain, line); xfreq_tmp.push_back( atof( line.substr(0, line.find_first_of(",")).c_str() ) ); ygain_tmp.push_back( atof( line.substr(line.find_first_of(",") + 1).c_str() ) ); - + N++; } Preampgain.close(); } - else { + else { cout<<"Preamgain file can not opened!!"<DATA_BIN_SIZE/2]; // array for FFT freq bin double ygain_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); - + for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE xfreq_databin[i] = (double)i * df_fft / (1.E6); // from Hz to MHz - } + } // Tools::SimpleLinearInterpolation will return Preampgain array (in dB) Tools::SimpleLinearInterpolation( N, xfreq, ygain, freq_step, &Freq[0], PreampGain ); - + Tools::SimpleLinearInterpolation( N, xfreq, ygain, settings1->DATA_BIN_SIZE/2, xfreq_databin, ygain_databin ); - - for (int i=0; iDATA_BIN_SIZE/2; i++) { + + for (int i=0; iDATA_BIN_SIZE/2; i++) { PreampGain_databin.push_back( ygain_databin[i] ); } - + // for NFOUR/2 t domain array double xfreq_NFOUR[settings1->NFOUR/4+1]; // array for FFT freq bin double ygain_NFOUR[settings1->NFOUR/4+1]; // array for gain in FFT bin - + df_fft = 1./ ( (double)(settings1->NFOUR/2) * settings1->TIMESTEP ); for (int i=0; iNFOUR/4+1; i++) { // this one is for DATA_BIN_SIZE @@ -3891,12 +3937,12 @@ inline void Detector::ReadPreamp(string filename, Settings *settings1) { // w } Tools::SimpleLinearInterpolation( N, xfreq, ygain, settings1->NFOUR/4+1, xfreq_NFOUR, ygain_NFOUR ); - - for (int i=0; iNFOUR/4+1; i++) { + + for (int i=0; iNFOUR/4+1; i++) { PreampGain_NFOUR.push_back( ygain_NFOUR[i] ); } - - return; + + return; } void Detector::ReadPreamp_New(Settings *settings1) { // will return gain (dB) with same freq bin with antenna gain @@ -3909,7 +3955,7 @@ void Detector::ReadPreamp_New(Settings *settings1) { // will return gain (dB) std::vector xfreq_databin(n_bins); // vector for FFT freq bin std::vector ygain_databin(n_bins); // vector for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE @@ -3917,10 +3963,10 @@ void Detector::ReadPreamp_New(Settings *settings1) { // will return gain (dB) } Tools::SimpleLinearInterpolation( freq_step, &Freq[0], PreampGain, settings1->DATA_BIN_SIZE/2, xfreq_databin.data(), ygain_databin.data() ); - + PreampGain_databin.clear(); - - for (int i=0; iDATA_BIN_SIZE/2; i++) { + + for (int i=0; iDATA_BIN_SIZE/2; i++) { PreampGain_databin.push_back( ygain_databin[i] ); } @@ -3928,60 +3974,60 @@ void Detector::ReadPreamp_New(Settings *settings1) { // will return gain (dB) } inline void Detector::ReadFOAM(string filename, Settings *settings1) { // will return gain (dB) with same freq bin with antenna gain - + ifstream FOAMgain( filename.c_str() ); - + string line; - + int N=-1; - + vector xfreq_tmp; vector ygain_tmp; - + if ( FOAMgain.is_open() ) { while (FOAMgain.good() ) { - + getline (FOAMgain, line); xfreq_tmp.push_back( atof( line.substr(0, line.find_first_of(",")).c_str() ) ); ygain_tmp.push_back( atof( line.substr(line.find_first_of(",") + 1).c_str() ) ); - + N++; } FOAMgain.close(); } - else { + else { cout<<"Preamgain file can not opened!!"<DATA_BIN_SIZE/2]; // array for FFT freq bin double ygain_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); - + for (int i=0;iDATA_BIN_SIZE/2;i++) { // this one is for DATA_BIN_SIZE xfreq_databin[i] = (double)i * df_fft / (1.E6); // from Hz to MHz - } - + } + // Tools::SimpleLinearInterpolation will return FOAMgain array (in dB) Tools::SimpleLinearInterpolation( N, xfreq, ygain, freq_step, &Freq[0], FOAMGain ); - + Tools::SimpleLinearInterpolation( N, xfreq, ygain, settings1->DATA_BIN_SIZE/2, xfreq_databin, ygain_databin ); - - for (int i=0; iDATA_BIN_SIZE/2; i++) { + + for (int i=0; iDATA_BIN_SIZE/2; i++) { FOAMGain_databin.push_back( ygain_databin[i] ); } // for NFOUR/2 t domain array double xfreq_NFOUR[settings1->NFOUR/4+1]; // array for FFT freq bin double ygain_NFOUR[settings1->NFOUR/4+1]; // array for gain in FFT bin - + df_fft = 1./ ( (double)(settings1->NFOUR/2) * settings1->TIMESTEP ); for (int i=0; iNFOUR/4+1; i++) { // this one is for DATA_BIN_SIZE @@ -3989,8 +4035,8 @@ inline void Detector::ReadFOAM(string filename, Settings *settings1) { // wil } Tools::SimpleLinearInterpolation( N, xfreq, ygain, settings1->NFOUR/4+1, xfreq_NFOUR, ygain_NFOUR ); - - for (int i=0; iNFOUR/4+1; i++) { + + for (int i=0; iNFOUR/4+1; i++) { FOAMGain_NFOUR.push_back( ygain_NFOUR[i] ); } @@ -4000,16 +4046,16 @@ inline void Detector::ReadFOAM(string filename, Settings *settings1) { // wil void Detector::ReadNoiseFigure(string filename, Settings *settings1) { ifstream nfFile( filename.c_str() ); - + string line; int N=0; vector< vector > all_chNF; vector xfreq_tmp; vector yNF_tmp; - + if ( nfFile.is_open() ) { while (nfFile.good() ) { - + getline (nfFile, line); istringstream iss(line); @@ -4023,14 +4069,14 @@ void Detector::ReadNoiseFigure(string filename, Settings *settings1) all_chNF.push_back( yNF_tmp ); yNF_tmp.clear(); - + N++; } nfFile.close(); } - else { + else { cout<<"Noise Figure file can not be opened!!"< xfreq_databin(settings1->DATA_BIN_SIZE/2); // array for FFT freq bin double NoiseFig_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); - cout<<"DATA_BIN_SIZE: "<DATA_BIN_SIZE<<" TIMESTEP: "<TIMESTEP<<" df_fft: "<DATA_BIN_SIZE<<" TIMESTEP: "<TIMESTEP<<" df_fft: "<DATA_BIN_SIZE/2<DATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE xfreq_databin[i] = (double)i * df_fft / (1.E6); // from Hz to MHz - } + } // set vector array size to number of chs NoiseFig_databin_ch.resize(ch_no); - + // save frequency values we interpolate onto NoiseFig_freq = xfreq_databin; @@ -4064,15 +4110,15 @@ void Detector::ReadNoiseFigure(string filename, Settings *settings1) for (int ch=0; chDATA_BIN_SIZE/2, &xfreq_databin[0], NoiseFig_databin ); - - for (int i=0; iDATA_BIN_SIZE/2; i++) { + + for (int i=0; iDATA_BIN_SIZE/2; i++) { NoiseFig_databin_ch[ch].push_back( NoiseFig_databin[i] ); } } @@ -4086,24 +4132,24 @@ double Detector::GetNoiseFig_OutZero(int ch, double freq) { ch = ch%16; // to match the convention of Detector::GetNoiseFig_databin const int nFreq = (int)NoiseFig_freq.size(); - const double dfreq = NoiseFig_freq[1] - NoiseFig_freq[0]; + const double dfreq = NoiseFig_freq[1] - NoiseFig_freq[0]; const int bin = (int)( (freq - NoiseFig_freq[0]) / dfreq )+1; if(freq == NoiseFig_freq[0]) return NoiseFig_databin_ch[ch].front(); - + if(freq == NoiseFig_freq.back()) return NoiseFig_databin_ch[ch].back(); - + if(bin <= 0 || bin >= nFreq) return 0; vector* noiseFig = &NoiseFig_databin_ch[ch]; const double m = (noiseFig->at(bin) - noiseFig->at(bin-1))/(NoiseFig_freq[bin] - NoiseFig_freq[bin-1]); - const double b = noiseFig->at(bin-1); - - return m*(freq - NoiseFig_freq[bin-1]) + b; + const double b = noiseFig->at(bin-1); + + return m*(freq - NoiseFig_freq[bin-1]) + b; } @@ -4136,7 +4182,7 @@ void Detector::ReadAmplifierNoiseFigure(Settings *settings) { } else { throw runtime_error("Unsupported station for amplifier noise figure!"); - } + } } else if(detector == 5) { // PA case @@ -4159,7 +4205,7 @@ void Detector::ReadAmplifierNoiseFigure(Settings *settings) { string line; while(getline(noiseFigFile, line)) { - + stringstream ss(line); if(line[0] == '#') { // comment, skip line continue; @@ -4179,40 +4225,40 @@ void Detector::ReadAmplifierNoiseFigure(Settings *settings) { if(words.size() != 17) { throw runtime_error("Amplifier noise figure file not properly formatted!"); } - + // actually put data into data arrays rawFreqs.push_back(words[0]); // expected to be in MHz for(int chan = 0; chan < 16; ++chan) { rawNf[chan].push_back(words[chan+1]); // expected to be in linear units - } + } } noiseFigFile.close(); - } - - // annoying but we need to give special treatment to A5 channels merged into the PA + } + + // annoying but we need to give special treatment to A5 channels merged into the PA if(detector == 5) { - + // define PA channels to be replaced vector chans = {5, 10, 11, 12, 13, 14, 15}; - // define corresponding A5 RF channels + // define corresponding A5 RF channels vector srcChans = {7, 6, 3, 4, 0, 5, 1}; - + if(chans.size() != srcChans.size()) { - throw runtime_error("Mismatch in A5-PA channel mapping for amplifier noise!"); + throw runtime_error("Mismatch in A5-PA channel mapping for amplifier noise!"); } - // read in the data - filename = string(getenv("ARA_SIM_DIR"))+"/data/amplifierNoiseFigures/amplifierNoiseFigure_A5.csv"; + // read in the data + filename = string(getenv("ARA_SIM_DIR"))+"/data/amplifierNoiseFigures/amplifierNoiseFigure_A5.csv"; ifstream noiseFigFile(filename); if(!noiseFigFile.is_open()) { throw runtime_error("Amplifier noise figure file cannot be opened: "+filename); } - int idx = 0; + int idx = 0; string line; while(getline(noiseFigFile, line)) { - + stringstream ss(line); if(line[0] == '#') { // comment, skip line continue; @@ -4237,14 +4283,14 @@ void Detector::ReadAmplifierNoiseFigure(Settings *settings) { // but let's save that for another day... if(words[0] != rawFreqs[idx]) { throw runtime_error("A5 and PA amplifier noise figures are not aligned properly!"); - } + } // actually put data into data arrays - for(unsigned int i = 0; i < chans.size(); ++i) { - + for(unsigned int i = 0; i < chans.size(); ++i) { + const int paChan = chans[i]; - const int a5Chan = srcChans[i]; - + const int a5Chan = srcChans[i]; + rawNf[paChan][idx] = words[a5Chan+1]; // replace PA noise figure by corresponding A5 noise figure } @@ -4256,8 +4302,8 @@ void Detector::ReadAmplifierNoiseFigure(Settings *settings) { } - // set up the output frequency spacing for this event's specific DATA_BIN_SIZE - const double dt = settings->TIMESTEP; // seconds + // set up the output frequency spacing for this event's specific DATA_BIN_SIZE + const double dt = settings->TIMESTEP; // seconds const double df_fft = 1./ ( (double)(settings->DATA_BIN_SIZE) * dt ); // the frequency step const int nFreqs = settings->DATA_BIN_SIZE/2.; double interp_frequencies_databin[nFreqs]; // array for interpolated FFT frequencies @@ -4266,16 +4312,16 @@ void Detector::ReadAmplifierNoiseFigure(Settings *settings) { interp_frequencies_databin[i] = (double)i * df_fft / (1.E6); // from Hz to MHz } - // interpolate raw values onto the frequency spacing in use here + // interpolate raw values onto the frequency spacing in use here for(int chan = 0; chan < 16; ++chan) { const int nFreqsRaw = rawFreqs.size(); - amplifierNoiseFig_ch[chan].resize(nFreqs); + amplifierNoiseFig_ch[chan].resize(nFreqs); - // interpolate onto requested frequencies - Tools::SimpleLinearInterpolation(nFreqsRaw, (double*)&rawFreqs[0], (double*)&rawNf[chan][0], - nFreqs, interp_frequencies_databin, (double*)&lifierNoiseFig_ch[chan][0]); + // interpolate onto requested frequencies + Tools::SimpleLinearInterpolation(nFreqsRaw, (double*)&rawFreqs[0], (double*)&rawNf[chan][0], + nFreqs, interp_frequencies_databin, (double*)&lifierNoiseFig_ch[chan][0]); } @@ -4293,7 +4339,7 @@ void Detector::ReadFOAM_New(Settings *settings1) { // will return gain (dB) w std::vector xfreq_databin(n_bins); // vector for FFT freq bin std::vector ygain_databin(n_bins); // vector for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE @@ -4301,10 +4347,10 @@ void Detector::ReadFOAM_New(Settings *settings1) { // will return gain (dB) w } Tools::SimpleLinearInterpolation( freq_step, &Freq[0], FOAMGain, settings1->DATA_BIN_SIZE/2, xfreq_databin.data(), ygain_databin.data() ); - + FOAMGain_databin.clear(); - - for (int i=0; iDATA_BIN_SIZE/2; i++) { + + for (int i=0; iDATA_BIN_SIZE/2; i++) { FOAMGain_databin.push_back( ygain_databin[i] ); } @@ -4312,16 +4358,16 @@ void Detector::ReadFOAM_New(Settings *settings1) { // will return gain (dB) w } inline void Detector::ReadCalPulserWF(string filename, Settings *settings1 ) { // will store calpulser waveform array - + ifstream CalPulWF( filename.c_str() ); - + string line; - + int N=-1; - + CalPulserWF_ns.clear(); CalPulserWF_V.clear(); - + int firstread = 1; if ( CalPulWF.is_open() ) { @@ -4333,41 +4379,41 @@ inline void Detector::ReadCalPulserWF(string filename, Settings *settings1 ) { getline (CalPulWF, line); firstread++; } - + getline (CalPulWF, line); CalPulserWF_ns.push_back( atof( line.substr(0, line.find_first_of(",")).c_str() ) ); CalPulserWF_V.push_back( atof( line.substr(line.find_first_of(",") + 1).c_str() ) * settings1->CALPUL_AMP ); - + N++; } CalPulWF.close(); } - - else + + else cout<<"CalPulserWF file can not opened!!"< > gains; @@ -4515,10 +4561,10 @@ inline void Detector::ReadElectChain(string filename, Settings *settings1) { getline(gainFile, line, ','); double temp_freq_val = atof(line.c_str()); // the frequency in MHz if(std::isnan(temp_freq_val) || temp_freq_val < 0 || temp_freq_val > 1200){ - sprintf(errorMessage, - "The frequency value (freq bin %d) is a nan or negative or very large (%e). Stop!", + sprintf(errorMessage, + "The frequency value (freq bin %d) is a nan or negative or very large (%e). Stop!", theFreqBin, temp_freq_val); - cout << "The gain filename is: " << filename << endl; + cout << "The gain filename is: " << filename << endl; throw std::runtime_error(errorMessage); } @@ -4534,16 +4580,16 @@ inline void Detector::ReadElectChain(string filename, Settings *settings1) { int numColsPair = 0; while(numColsPair < gain_ch-1){ //numColsPair is the number of column pairs e.g. columns //2 and 3 correspond to gain and phase of channel 0. - + //get and store the gain values getline(gainFile, line, ','); double temp_gain_val = atof(line.c_str()); if(std::isnan(temp_gain_val) || temp_gain_val < 0 || temp_gain_val > 1E6){ - sprintf(errorMessage, - "A gain value (freq bin %d, ch %d) is a nan or negative or very large (%e). Stop!", + sprintf(errorMessage, + "A gain value (freq bin %d, ch %d) is a nan or negative or very large (%e). Stop!", theFreqBin, numColsPair, temp_gain_val); - cout << "The gain filename is: " << filename << endl; + cout << "The gain filename is: " << filename << endl; throw std::runtime_error(errorMessage); } @@ -4551,13 +4597,13 @@ inline void Detector::ReadElectChain(string filename, Settings *settings1) { //get and store the phase values getline(gainFile, line, ','); - double temp_phase_val = atof(line.c_str()); + double temp_phase_val = atof(line.c_str()); if(std::isnan(temp_phase_val)){ - sprintf(errorMessage, - "A phase value (freq bin %d, ch %d) is a nan. Stop!", + sprintf(errorMessage, + "A phase value (freq bin %d, ch %d) is a nan. Stop!", theFreqBin, numColsPair); - cout << "The gain filename is: " << filename << endl; + cout << "The gain filename is: " << filename << endl; throw std::runtime_error(errorMessage); } @@ -4566,17 +4612,17 @@ inline void Detector::ReadElectChain(string filename, Settings *settings1) { numColsPair++; // advance number of column pair } - + // once more to get the final channel, this time we need to detect the newline character after getting the last gain // NB: at this point, numColsPair == final channel number, so we can just use it // (no need to increment numColsPair again) - + getline(gainFile, line, ','); //getting last gain double temp_gain_val = atof(line.c_str()); gains[numColsPair][theFreqBin] = temp_gain_val; - + getline(gainFile, line, '\n'); //getting last phase double temp_phase_val = atof(line.c_str()); @@ -4590,7 +4636,7 @@ inline void Detector::ReadElectChain(string filename, Settings *settings1) { } } gainFile.close(); - + //This is the end of PART 1. Done getting data from the gain-phase file @@ -4598,7 +4644,7 @@ inline void Detector::ReadElectChain(string filename, Settings *settings1) { // the content of the vectors needs to be stuffed into arrays for the interpolator // so, copy over the vector of frequencies into an array - + double frequencies_asarray[numFreqBins]; std::copy(frequencies.begin(), frequencies.end(), frequencies_asarray); @@ -4607,78 +4653,78 @@ inline void Detector::ReadElectChain(string filename, Settings *settings1) { // loop over channel, and do the interpolation for(int iCh=0; iChDETECTOR; const int station = settings->DETECTOR_STATION; - + // set up the output frequency spacing for this event's specific DATA_BIN_SIZE -- matches frequency binning of Hmeas below - const double dt = settings->TIMESTEP; // seconds + const double dt = settings->TIMESTEP; // seconds const double df_fft = 1./ ( (double)(settings->DATA_BIN_SIZE) * dt ); // the frequency step const int nFreqs = settings->DATA_BIN_SIZE/2.; double interp_frequencies_databin[nFreqs]; // array for interpolated FFT frequencies - + // set the frequencies for(int i=0; i < nFreqs; i++) { interp_frequencies_databin[i] = (double)i * df_fft / (1.E6); // from Hz to MHz - } + } - // get thermal noise level from data for this station & livetime config + // get thermal noise level from data for this station & livetime config std::vector< std::vector > Hmeas = GetRayleighFitVector_databin(station, settings); // calculate theoretical expectation for thermal noise const double splitterFactor = GetSplitterFactor(settings); - + std::vector< std::vector > Htot(16, std::vector(nFreqs, 0)); const double Z0 = 50; // ohms - characteristic impedance const double Tamp = 220; // K - amplifier temp const double Tice = 247; // K - ice temp - + // get correct bandwidth for ARA vs PA DAQs const double bandWidth = (detector < 5)? 850e6-150e6 : 720e6-130e6; // Hz for(int rfChan = 0; rfChan < 16; ++rfChan) { - + std::vector Ttot(nFreqs, 0); - + // get appropriate trasmittances (antenna-type specific) { // choose correct antenna type for this channel @@ -4687,17 +4733,17 @@ inline void Detector::CalculateElectChain(Settings *settings) { if(rfChan < 4) { type = eVPolTop; - } + } else if(rfChan < 8) { type = eVPol; } else { type = eHPol; } - + } else if(detector == 5) { // PA case - + if(rfChan < 8) { // even channel 5 is a bottom Vpol type = eVPol; } @@ -4715,7 +4761,7 @@ inline void Detector::CalculateElectChain(Settings *settings) { throw runtime_error("Detector type unsupported for automated data-driven gain model calculation!"); } - // calculate ice contribution to Ttot at each frequency for this channel + // calculate ice contribution to Ttot at each frequency for this channel // uses loaded antenna model for transmittance for(int i = 0; i < nFreqs; ++i) { @@ -4731,14 +4777,14 @@ inline void Detector::CalculateElectChain(Settings *settings) { } else { throw runtime_error("Unsupported antenna type, transmittance unknown!"); - } - } + } + } } - - // get appropriate noise figure of LNA (station-specific) + + // get appropriate noise figure of LNA (station-specific) { - // calculate amplifier contribution to Ttot at each frequency for this channel - for(int i = 0; i < nFreqs; ++i) { + // calculate amplifier contribution to Ttot at each frequency for this channel + for(int i = 0; i < nFreqs; ++i) { const double thisNF = amplifierNoiseFig_ch[rfChan][i]; Ttot[i] += (thisNF-1)*Tamp; } @@ -4746,7 +4792,7 @@ inline void Detector::CalculateElectChain(Settings *settings) { // calculate Htot { - for(int i = 0; i < nFreqs; ++i) { + for(int i = 0; i < nFreqs; ++i) { // theoretical expectation Htot[rfChan][i] = sqrt(KBOLTZ * Ttot[i] * Z0 * bandWidth * dt); @@ -4755,29 +4801,29 @@ inline void Detector::CalculateElectChain(Settings *settings) { } } } - + // finally calculate the gain and replace previous gain values (retain phase values) - ElectGain.clear(); // clear previous values + ElectGain.clear(); // clear previous values ElectGain.resize(16, vector(freq_step, 0)); // parameters for bandpass [MHz] const int loFreq = (detector < 5)? 150 : 130; const int hiFreq = (detector < 5)? 850 : 720; const int width = 10; - + for(int rfChan = 0; rfChan < 16; ++rfChan) { vector buffGain(nFreqs, 0); - for(int i = 0; i < nFreqs; ++i) { + for(int i = 0; i < nFreqs; ++i) { buffGain[i] = Hmeas[rfChan][i]/Htot[rfChan][i]; - // apply basic bandpass to make sure we don't get any surprises out of band + // apply basic bandpass to make sure we don't get any surprises out of band // (this is equivalent to the quality control done for the tabulated models) const double thisFreq = interp_frequencies_databin[i]; buffGain[i] *= (tanh((thisFreq - loFreq)/width) + 1)/2.; buffGain[i] *= (tanh((hiFreq - thisFreq)/width) + 1)/2.; } - + // interpolate back onto the original frequency binning for the gain Tools::SimpleLinearInterpolation(nFreqs, interp_frequencies_databin, (double*)&buffGain[0], freq_step, &Freq[0], (double*)&ElectGain[rfChan][0]); @@ -4790,7 +4836,7 @@ inline void Detector::CalculateElectChain(Settings *settings) { inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *settings1) { //will return trigger delays and channels masked from trigger logic //First, let's check that the file exists and the format is correct - + // check if the file with delays + masking exists char errorMessage[400]; struct stat buffer; @@ -4809,7 +4855,7 @@ inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *setting string line; // a dummy variable we can stream over // if the trigger formation file exists, then make sure our user has formatted the file correctly - // in particular, it means we really need to see the word "Channel No." as the first word in the header file + // in particular, it means we really need to see the word "Channel No." as the first word in the header file string expected_first_column_header = "Channel"; if(trigFile.is_open()){ @@ -4837,7 +4883,7 @@ inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *setting trigFile.seekg(0, ios::beg); - // Figure out how many columns we have, to check we get the four expected columns + // Figure out how many columns we have, to check we get the four expected columns int numCommas = 0; int theLineNo = 0; if(trigFile.is_open()){ @@ -4858,7 +4904,7 @@ inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *setting trigFile.clear(); // back to the beginning of the file again trigFile.seekg(0, ios::beg); - + //Second, let us extract the data from the file // Figure out how many channels there are @@ -4872,16 +4918,16 @@ inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *setting trigFile.clear(); // back to the beginning of the file again trigFile.seekg(0, ios::beg); - int numChannels = lineCount - 1; // one row is dedicated to headers; number of channels is therefore # rows - 1 - + int numChannels = lineCount - 1; // one row is dedicated to headers; number of channels is therefore # rows - 1 + //Set up containers to stream the csv file into. - + //vector of delays triggerDelay.resize(numChannels); // resize to account for the number of channels - + //vector of trigger masking triggerMask.resize(numChannels); // resize to account for the number of channels - + //vector for active delays activeDelay.resize(numChannels); // resize to account for the number of channels @@ -4895,12 +4941,12 @@ inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *setting theLineNo++; } else{ - /* + /* from the second line forward, read in the values the first column is the channel number the second has the trigger delay values, the third determines if the channel is in trigger (masking), - the fourth determines if the channel has active delays + the fourth determines if the channel has active delays */ // first, peel off the channel no. @@ -4914,18 +4960,18 @@ inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *setting cout << "The trigger formation filename is: " << filename << endl; throw std::runtime_error(errorMessage); } - + /* then loop over the columns, splitting most on the comma "," Because the "separating" character for the very last column is a newline (\n), we need to change to the newline character for the final column (see below). */ - + //get and store the trigger delay values getline(trigFile, line, ','); - double temp_delay_val = atof(line.c_str()); - + double temp_delay_val = atof(line.c_str()); + if(std::isnan(temp_delay_val) || temp_delay_val < 0 || temp_delay_val > 1E6){ sprintf(errorMessage, "A delay value (ch %d) is a nan or negative or very large (%e). Stop!", @@ -4948,10 +4994,10 @@ inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *setting throw std::runtime_error(errorMessage); } - triggerMask[chBin] = temp_mask_val; + triggerMask[chBin] = temp_mask_val; - // once more to get the final column, this time we need to detect the newline character + // once more to get the final column, this time we need to detect the newline character //get and store the value to activate delay getline(trigFile, line, '\n'); @@ -4969,7 +5015,7 @@ inline void Detector::ReadTrig_Delays_Masking(string filename, Settings *setting // now we're done! theLineNo++; //advance the line number - } + } } } trigFile.close(); @@ -4985,17 +5031,17 @@ inline void Detector::ReadGainOffset_TestBed(string filename, Settings *settings if (settings1->USE_CH_GAINOFFSET == 1) { ifstream GainOffset( filename.c_str() ); - + string line; int N=0; - + if ( GainOffset.is_open() ) { while (GainOffset.good() ) { getline (GainOffset, line); - + GainOffset_TB_ch.push_back( atof( line.c_str() ) ); cout<<"GainOffset ch"<USE_MANUAL_GAINOFFSET == 0) { - for (int i=0; iTRIG_THRES_MODE == 1){ ifstream Thres( filename.c_str() ); - + string line; - + int N=0; - + if ( Thres.is_open() ) { while (Thres.good() ) { getline (Thres, line); - + Thres_TB_ch.push_back( atof( line.c_str() ) ); cout<<"Thres ch" << N << " : " << Thres_TB_ch[N] << endl; - + N++; } Thres.close(); @@ -5079,18 +5125,18 @@ inline void Detector::ReadThresOffset_TestBed(string filename, Settings *setting inline void Detector::ReadTemp_TestBed(string filename, Settings *settings1) { // will return gain offset (unit in voltage) for different chs ifstream Temp( filename.c_str() ); - + string line; - + int N=0; - + if ( Temp.is_open() ) { while (Temp.good() ) { getline (Temp, line); - + Temp_TB_ch.push_back( atof( line.c_str() ) ); cout<<"System temp ch"< xfreq_tmp; vector ygain_tmp; - + if ( RFCM.is_open() ) { while (RFCM.good() ) { getline (RFCM, line); xfreq_tmp.push_back( atof( line.substr(0, line.find_first_of(",")).c_str() )*1.e-6 ); // from Hz to MHz - + ygain_tmp.push_back( atof( line.substr(line.find_first_of(",") + 1).c_str() ) ); - + N++; } RFCM.close(); } - + else { cout<<"RFCM file can not opened!!"< xfreq_databin(settings1->DATA_BIN_SIZE/2); // array for FFT freq bin double ygain_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); - + for (int i=0; iDATA_BIN_SIZE/2, &xfreq_databin[0], ygain_databin ); // store frequency bins (should be okay if this is overwritten since it's defined in this function, so should be the same) @@ -5155,35 +5201,35 @@ inline void Detector::ReadRFCM_TestBed(string filename, Settings *settings1) { // set vector array size to number of chs RFCM_TB_databin_ch.resize(ch_no+1); - - for (int i=0;iDATA_BIN_SIZE/2;i++) { + + for (int i=0;iDATA_BIN_SIZE/2;i++) { RFCM_TB_databin_ch[ch_no].push_back( ygain_databin[i] ); } - - return; + + return; } double Detector::GetRFCMGain_OutZero(int ch, double freq) { const int nFreq = (int)RFCM_TB_freq.size(); - const double dfreq = RFCM_TB_freq[1] - RFCM_TB_freq[0]; + const double dfreq = RFCM_TB_freq[1] - RFCM_TB_freq[0]; const int bin = (int)( (freq - RFCM_TB_freq[0]) / dfreq )+1; vector* RFCM_TB = &RFCM_TB_databin_ch[ch]; if(freq == RFCM_TB_freq[0]) return RFCM_TB->front(); - + if(freq == NoiseFig_freq.back()) return RFCM_TB->back(); - + if(bin <= 0 || bin >= nFreq) return 0; const double m = (RFCM_TB->at(bin) - RFCM_TB->at(bin-1))/(RFCM_TB_freq[bin] - RFCM_TB_freq[bin-1]); - const double b = RFCM_TB->at(bin-1); - - return m*(freq - RFCM_TB_freq[bin-1]) + b; + const double b = RFCM_TB->at(bin-1); + + return m*(freq - RFCM_TB_freq[bin-1]) + b; } @@ -5194,7 +5240,7 @@ void Detector::ReadRFCM_New(Settings *settings1) { // will return gain (dB) w double xfreq_databin[settings1->DATA_BIN_SIZE/2]; // array for FFT freq bin double ygain_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE @@ -5205,10 +5251,10 @@ void Detector::ReadRFCM_New(Settings *settings1) { // will return gain (dB) w for (int ch=0; chDATA_BIN_SIZE/2, xfreq_databin, ygain_databin ); - + RFCM_TB_databin_ch[ch].clear(); - - for (int i=0; iDATA_BIN_SIZE/2; i++) { + + for (int i=0; iDATA_BIN_SIZE/2; i++) { RFCM_TB_databin_ch[ch].push_back( ygain_databin[i] ); } } @@ -5219,12 +5265,12 @@ void Detector::ReadRFCM_New(Settings *settings1) { // will return gain (dB) w inline void Detector::ReadRayleighFit_TestBed(string filename, Settings *settings1) { // will read Rayleigh fit result from the file ifstream Rayleigh_file( filename.c_str() ); - + string line; - + int init = 1; int ch_loop = 0; - + vector xfreq_tmp; vector > fit_tmp; // 2d array for ch @@ -5238,7 +5284,7 @@ inline void Detector::ReadRayleighFit_TestBed(string filename, Settings *setting if ( Rayleigh_file.is_open() ) { while (Rayleigh_file.good() ) { - + if (init == 1) { // ok, skip first line getline (Rayleigh_file, line); init++; @@ -5252,22 +5298,22 @@ inline void Detector::ReadRayleighFit_TestBed(string filename, Settings *setting getline (Rayleigh_file, line, ','); fit_tmp_tmp = atof( line.c_str() ); // fit result - + fit_tmp[ch_tmp].push_back( fit_tmp_tmp ); // fit result - if (ch_tmp == 0) { + if (ch_tmp == 0) { xfreq_tmp.push_back( freq_tmp_tmp ); } getline (Rayleigh_file, line, '\n'); - + total_line++; } } Rayleigh_file.close(); } - + else { cout<<"Rayleigh file can not opened!!"<DATA_BIN_SIZE/2]; // array for FFT freq bin double Rayleigh_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); - + // now below are values that shared in all channels for (int i=0;iDATA_BIN_SIZE/2;i++) { // this one is for DATA_BIN_SIZE xfreq_databin[i] = (double)i * df_fft / (1.E6); // from Hz to MHz - } - + } + // set vector array size to number of chs Rayleigh_TB_databin_ch.resize(ch_no); - + // now loop over channels and do interpolation for (int ch=0; chDATA_BIN_SIZE/2, xfreq_databin, Rayleigh_databin ); - for (int i=0;iDATA_BIN_SIZE/2;i++) { + for (int i=0;iDATA_BIN_SIZE/2;i++) { Rayleigh_TB_databin_ch[ch].push_back( Rayleigh_databin[i] ); } } - - return; - + + return; + } //! A function to load the deep station rayleigh fits @@ -5365,8 +5411,8 @@ void Detector::ReadRayleighFit_DeepStation(string filename, Settings *settings){ getline(rayleighFile, line, ','); string first_header_entry = line.c_str(); if (! (first_header_entry == expected_first_column_header)){ - sprintf(errorMessage, - "The first word of the header line is '%s'. It was expected to be '%s'. Please double check file format!!", + sprintf(errorMessage, + "The first word of the header line is '%s'. It was expected to be '%s'. Please double check file format!!", first_header_entry.c_str(), expected_first_column_header.c_str()); throw std::runtime_error(errorMessage); @@ -5441,7 +5487,7 @@ void Detector::ReadRayleighFit_DeepStation(string filename, Settings *settings){ } rayleighFile.clear(); // back to the beginning of the file again rayleighFile.seekg(0, ios::beg); - RayleighFit_ch = numCommas; // also need to set this detector wide variable, + RayleighFit_ch = numCommas; // also need to set this detector wide variable, // which specifies how many channels for which we have rayleigh data /* @@ -5451,12 +5497,12 @@ void Detector::ReadRayleighFit_DeepStation(string filename, Settings *settings){ First, setup a vector of vectors to hold the fit values we stream in. The first dimension is for the number of channels (so this is "number of channels" long). The second dimension is for the number of frequency bins (so this is "number of frequency bins" long). - (which goes first and which goes second is arbitrary; + (which goes first and which goes second is arbitrary; the TestBed version does it in this order, so replicate here) */ - std::vector< std::vector > fits; + std::vector< std::vector > fits; fits.resize(RayleighFit_ch); // resize to account for number of channels - for(int iCh=0; iCh 1200){ - sprintf(errorMessage, - "A rayleigh frequency value (freq bin %d) is a nan or negative or very large (%e). Stop!", + sprintf(errorMessage, + "A rayleigh frequency value (freq bin %d) is a nan or negative or very large (%e). Stop!", theFreqBin, temp_freq_val); throw std::runtime_error(errorMessage); } @@ -5510,8 +5556,8 @@ void Detector::ReadRayleighFit_DeepStation(string filename, Settings *settings){ getline(rayleighFile, line, ','); double temp_fit_val = atof(line.c_str()); if(std::isnan(temp_fit_val) || temp_fit_val < 0 || temp_fit_val > 1E-5){ - sprintf(errorMessage, - "A rayleigh fit value (freq bin %d, ch %d) is a nan or negative or very large (%e). Stop!", + sprintf(errorMessage, + "A rayleigh fit value (freq bin %d, ch %d) is a nan or negative or very large (%e). Stop!", theFreqBin, numCols, temp_fit_val); throw std::runtime_error(errorMessage); } @@ -5583,7 +5629,7 @@ std::vector< std::vector< double> > Detector::GetRayleighFitVector_databin(int s // this stores the response vector interpolated for THIS SPECIFIC DATA_BIN_SIZE std::vector< std::vector< double > > rayleighFits_DeepStation_values_databin; rayleighFits_DeepStation_values_databin.resize(this_station_original_fits.size(), vector(settings->DATA_BIN_SIZE/2)); // resize to match channel count - + // set up the output frequency spacing for this event's specific DATA_BIN_SIZE int n_bins = settings->DATA_BIN_SIZE / 2; double df_fft = 1./ ( (double)(settings->DATA_BIN_SIZE) * settings->TIMESTEP ); // the frequency step @@ -5628,7 +5674,7 @@ void Detector::ReadNoiseFig_New(Settings *settings1) { // will return gain (d double xfreq_databin[settings1->DATA_BIN_SIZE/2]; // array for FFT freq bin double NoiseFig_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE @@ -5641,11 +5687,11 @@ void Detector::ReadNoiseFig_New(Settings *settings1) { // will return gain (d for (int ch=0; chDATA_BIN_SIZE/2, xfreq_databin, NoiseFig_databin ); - + NoiseFig_databin_ch[ch].clear(); - + for (int i=0;iDATA_BIN_SIZE/2;i++) { - if(i%100==0) { + if(i%100==0) { cout<<"NoiseFig_databin: "<DATA_BIN_SIZE/2]; // array for FFT freq bin double Rayleigh_databin[settings1->DATA_BIN_SIZE/2]; // array for gain in FFT bin double df_fft; - + df_fft = 1./ ( (double)(settings1->DATA_BIN_SIZE) * settings1->TIMESTEP ); for (int i=0; iDATA_BIN_SIZE/2; i++) { // this one is for DATA_BIN_SIZE @@ -5684,10 +5730,10 @@ void Detector::ReadRayleigh_New(Settings *settings1) { // will return gain (d for (int ch=0; chDATA_BIN_SIZE/2, xfreq_databin, Rayleigh_databin ); - + Rayleigh_TB_databin_ch[ch].clear(); - - for (int i=0; iDATA_BIN_SIZE/2; i++) { + + for (int i=0; iDATA_BIN_SIZE/2; i++) { Rayleigh_TB_databin_ch[ch].push_back( Rayleigh_databin[i] ); } } @@ -5699,21 +5745,21 @@ int Detector::GetTrigOffset( int ch, Settings *settings1 ){ double mostDelay; int offset; - - if(activeDelay[ch]==0){ //value of 0 means the DAQ didn't record cable delays in data and must be added in simulations + + if(activeDelay[ch]==0){ //value of 0 means the DAQ didn't record cable delays in data and must be added in simulations mostDelay = *max_element(triggerDelay.begin(), triggerDelay.end()); offset = int((mostDelay - triggerDelay[ch]) / (settings1->TIMESTEP * 1e9)); } else { offset = 0; - } - + } + return offset; } -int Detector::GetTrigMasking( int ch){ +int Detector::GetTrigMasking( int ch){ - return triggerMask[ch]; + return triggerMask[ch]; } @@ -5725,7 +5771,7 @@ double Detector::GetGainOffset( int StationID, int ch, Settings *settings1 ) { / else if ( settings1->TRIG_ONLY_LOW_CH_ON==1 ) { // if only triggered by bottom chs with TB info return GainOffset_TB_ch[ch]; } - + return 1.;// other stations, just return 1. } @@ -5738,13 +5784,13 @@ double Detector::GetThresOffset( int StationID, int ch, Settings *settings1 ) { else if ( settings1->TRIG_ONLY_LOW_CH_ON==1 ) { // if only triggered by bottom chs with TB info return ThresOffset_TB_ch[ch]; } - + return 1.;// other stations, just return 1. } double Detector::GetThres( int StationID, int ch, Settings *settings1 ){ - - if ( (StationID == 0) && (settings1->DETECTOR==3) ) { + + if ( (StationID == 0) && (settings1->DETECTOR==3) ) { return Thres_TB_ch[ch]; } else if ( settings1->TRIG_ONLY_LOW_CH_ON==1 ) { // if only triggered by bottom chs with TB info @@ -5762,125 +5808,125 @@ double Detector::GetTemp( int StationID, int ch, Settings *settings1 ) { // ret else if ( settings1->TRIG_ONLY_LOW_CH_ON==1 ) { // if only triggered by bottom chs with TB info return Temp_TB_ch[ch]; } - + return settings1->NOISE_TEMP;// other stations, just return setup NOISE_TEMP } void Detector::getDiodeModel(Settings *settings1) { - + // this is our homegrown diode response function which is a downgoing gaussian followed by an upward step function TF1 *fdown1=new TF1("fl_down1","[3]+[0]*exp(-1.*(x-[1])*(x-[1])/(2*[2]*[2]))",-300.E-9,300.E-9); fdown1->SetParameter(0,-0.8); fdown1->SetParameter(1,15.E-9); fdown1->SetParameter(2,2.3E-9); fdown1->SetParameter(3,0.); - + TF1 *fdown2=new TF1("fl_down2","[3]+[0]*exp(-1.*(x-[1])*(x-[1])/(2*[2]*[2]))",-300.E-9,300.E-9); fdown2->SetParameter(0,-0.2); fdown2->SetParameter(1,15.E-9); fdown2->SetParameter(2,4.0E-9); fdown2->SetParameter(3,0.); - + maxt_diode= settings1->MAXT_DIODE; maxt_diode_bin = (int)( maxt_diode / TIMESTEP ); idelaybeforepeak= settings1->IDELAYBEFOREPEAK_DIODE; iwindow= settings1->IWINDOW_DIODE; ibinshift = NFOUR/4 - (int)( maxt_diode / TIMESTEP ); - + TF1 *f_up=new TF1("f_up","[0]*([3]*(x-[1]))^2*exp(-(x-[1])/[2])",-200.E-9,100.E-9); - + f_up->SetParameter(2,7.0E-9); f_up->SetParameter(0,1.); f_up->SetParameter(1,18.E-9); f_up->SetParameter(3,1.E9); - + double sum=0.; - + f_up->SetParameter(0,-1.*sqrt(2.*PI)*(fdown1->GetParameter(0)*fdown1->GetParameter(2)+fdown2->GetParameter(0)*fdown2->GetParameter(2))/(2.*pow(f_up->GetParameter(2),3.)*1.E18)); - + for (int i=0;iEval((double)i*TIMESTEP)+fdown2->Eval((double)i*TIMESTEP); if (i>(int)(f_up->GetParameter(1)/TIMESTEP)) { diode_real[i]+=f_up->Eval((double)i*TIMESTEP); } - + sum+=diode_real[i]; } } - + // now get f domain response with realft double diode_real_fft[settings1->DATA_BIN_SIZE*2]; // double sized array for myconvlv double diode_real_fft_half[NFOUR]; // double sized array for NFOUR/2 double diode_real_fft_double[NFOUR*2]; // test with NFOUR*2 array - - + + for (int i=0; iDATA_BIN_SIZE*2; i++) { // 512 bin added for zero padding - if ( i<(int)(maxt_diode/TIMESTEP) ) { + if ( i<(int)(maxt_diode/TIMESTEP) ) { diode_real_fft[i] = diode_real[i]; } - else { + else { diode_real_fft[i] = 0.; } } - + for (int i=0; iDATA_BIN_SIZE*2); - + // forward FFT for half size array Tools::realft(diode_real_fft_half,1,NFOUR); - + // forward FFT for double size array Tools::realft(diode_real_fft_double,1,NFOUR*2); - + fdiode_real_databin.clear(); fdiode_real.clear(); fdiode_real_double.clear(); - + // save f domain diode response in fdiode_real - for (int i=0; iDATA_BIN_SIZE*2; i++) { + for (int i=0; iDATA_BIN_SIZE*2; i++) { fdiode_real_databin.push_back( diode_real_fft[i] ); } - + // save f domain diode response in fdiode_real_half - for (int i=0; i Detector::getDiodeModel(const int len, Settings *settings1) { @@ -5899,42 +5945,42 @@ vector Detector::getDiodeModel(const int len, Settings *settings1) { fdown2->SetParameter(3,0.); maxt_diode= settings1->MAXT_DIODE; - + TF1 *f_up=new TF1("f_up","[0]*([3]*(x-[1]))^2*exp(-(x-[1])/[2])",-200.E-9,100.E-9); f_up->SetParameter(2,7.0E-9); f_up->SetParameter(0,1.); f_up->SetParameter(1,18.E-9); f_up->SetParameter(3,1.E9); - + double sum=0.; - + f_up->SetParameter(0,-1.*sqrt(2.*PI)*(fdown1->GetParameter(0)*fdown1->GetParameter(2)+fdown2->GetParameter(0)*fdown2->GetParameter(2))/(2.*pow(f_up->GetParameter(2),3.)*1.E18)); diode_real.clear(); for (int i=0;iEval((double)i*TIMESTEP)+fdown2->Eval((double)i*TIMESTEP); if (i>(int)(f_up->GetParameter(1)/TIMESTEP)) { diode_real[i]+=f_up->Eval((double)i*TIMESTEP); } - + sum+=diode_real[i]; } } - std::vector diode_real_fft(len, 0.0); + std::vector diode_real_fft(len, 0.0); - for (int i=0; i < len; i++) { - if ( i<(int)(maxt_diode/TIMESTEP) ) { + for (int i=0; i < len; i++) { + if ( i<(int)(maxt_diode/TIMESTEP) ) { diode_real_fft[i] = diode_real[i]; } - else { + else { diode_real_fft[i] = 0.; } } @@ -5942,17 +5988,17 @@ vector Detector::getDiodeModel(const int len, Settings *settings1) { // forward FFT Tools::realft(diode_real_fft.data(),1,len); - vector fdiode; + vector fdiode; // save f domain diode response in fdiode - for (int i=0; i < len; i++) { + for (int i=0; i < len; i++) { fdiode.push_back( diode_real_fft[i] ); } delete fdown1; delete fdown2; delete f_up; - + return fdiode; } @@ -5964,10 +6010,10 @@ void Detector::get_NewDiodeModel(Settings *settings1) { std::vector diode_real_fft(settings1->DATA_BIN_SIZE * 2); // double sized vector for myconvlv for (int i=0; iDATA_BIN_SIZE*2; i++) { // 512 bin added for zero padding - if ( i<(int)(maxt_diode/TIMESTEP) ) { + if ( i<(int)(maxt_diode/TIMESTEP) ) { diode_real_fft[i] = diode_real[i]; } - else { + else { diode_real_fft[i] = 0.; } } @@ -5979,7 +6025,7 @@ void Detector::get_NewDiodeModel(Settings *settings1) { fdiode_real_databin.clear(); // save f domain diode response in fdiode_real - for (int i=0; iDATA_BIN_SIZE*2; i++) { + for (int i=0; iDATA_BIN_SIZE*2; i++) { fdiode_real_databin.push_back( diode_real_fft[i] ); } @@ -5989,32 +6035,32 @@ void Detector::get_NewDiodeModel(Settings *settings1) { void Detector::PrepareVectorsInstalled(){ - + ARA_station temp_station; Antenna_string temp; Antenna_string temp_string; Antenna temp_antenna; Surface_antenna temp_surface; - + // prepare vectors for (int i=0; i 0) { // Testbed - // Make string 0 - Antennas.push_back(4); + // Make string 0 + Antennas.push_back(4); Antennas.push_back(1); InstalledStations[0].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 1 - Antennas.push_back(2); + Antennas.push_back(2); Antennas.push_back(7); - InstalledStations[0].VHChannel.push_back(Antennas); + InstalledStations[0].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 2 - Antennas.push_back(6); + Antennas.push_back(6); Antennas.push_back(3); - InstalledStations[0].VHChannel.push_back(Antennas); + InstalledStations[0].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 3 - Antennas.push_back(5); + Antennas.push_back(5); Antennas.push_back(8); - InstalledStations[0].VHChannel.push_back(Antennas); + InstalledStations[0].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 4 - Antennas.push_back(12); + Antennas.push_back(12); Antennas.push_back(9); - InstalledStations[0].VHChannel.push_back(Antennas); + InstalledStations[0].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 5 - Antennas.push_back(14); + Antennas.push_back(14); Antennas.push_back(13); - InstalledStations[0].VHChannel.push_back(Antennas); + InstalledStations[0].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 6 Antennas.push_back(10); - InstalledStations[0].VHChannel.push_back(Antennas); + InstalledStations[0].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 7 Antennas.push_back(11); - InstalledStations[0].VHChannel.push_back(Antennas); + InstalledStations[0].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[0].nStrings = InstalledStations[0].VHChannel.size(); @@ -6115,40 +6161,40 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { } - if (InstalledStations.size() > 1) { // Station 1 - + if (InstalledStations.size() > 1) { // Station 1 + if(settings1-> DETECTOR_STATION_ARAROOT==1){ //Build A1 as an ICRR // Make string 0 - Antennas.push_back(5); + Antennas.push_back(5); Antennas.push_back(9); - Antennas.push_back(1); + Antennas.push_back(1); Antennas.push_back(13); - InstalledStations[1].VHChannel.push_back(Antennas); + InstalledStations[1].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 1 - Antennas.push_back(6); + Antennas.push_back(6); Antennas.push_back(10); - Antennas.push_back(2); + Antennas.push_back(2); Antennas.push_back(14); - InstalledStations[1].VHChannel.push_back(Antennas); + InstalledStations[1].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 2 - Antennas.push_back(7); + Antennas.push_back(7); Antennas.push_back(11); - Antennas.push_back(3); + Antennas.push_back(3); Antennas.push_back(15); - InstalledStations[1].VHChannel.push_back(Antennas); + InstalledStations[1].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 3 - Antennas.push_back(4); + Antennas.push_back(4); Antennas.push_back(8); - Antennas.push_back(0); + Antennas.push_back(0); Antennas.push_back(12); - InstalledStations[1].VHChannel.push_back(Antennas); + InstalledStations[1].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[1].nStrings = InstalledStations[1].VHChannel.size(); @@ -6167,31 +6213,31 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { } else{ //Otherwise always build A1 as an ATRI - + // Make string 0 - Antennas.push_back(5); + Antennas.push_back(5); Antennas.push_back(13); Antennas.push_back(1); Antennas.push_back(9); - InstalledStations[1].VHChannel.push_back(Antennas); + InstalledStations[1].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 1 Antennas.push_back(6); Antennas.push_back(14); Antennas.push_back(2); Antennas.push_back(10); - InstalledStations[1].VHChannel.push_back(Antennas); + InstalledStations[1].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 2 Antennas.push_back(7); Antennas.push_back(15); Antennas.push_back(3); Antennas.push_back(11); - InstalledStations[1].VHChannel.push_back(Antennas); - Antennas.clear(); + InstalledStations[1].VHChannel.push_back(Antennas); + Antennas.clear(); // Make string 3 Antennas.push_back(4); Antennas.push_back(12); Antennas.push_back(0); Antennas.push_back(8); - InstalledStations[1].VHChannel.push_back(Antennas); + InstalledStations[1].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[1].nStrings = InstalledStations[1].VHChannel.size(); @@ -6214,25 +6260,25 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { // Make string 0 Antennas.push_back(5); Antennas.push_back(13); Antennas.push_back(1); Antennas.push_back(9); - InstalledStations[2].VHChannel.push_back(Antennas); + InstalledStations[2].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 1 Antennas.push_back(6); Antennas.push_back(14); Antennas.push_back(2); Antennas.push_back(10); - InstalledStations[2].VHChannel.push_back(Antennas); + InstalledStations[2].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 2 Antennas.push_back(7); Antennas.push_back(15); Antennas.push_back(3); Antennas.push_back(11); - InstalledStations[2].VHChannel.push_back(Antennas); + InstalledStations[2].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 3 Antennas.push_back(4); Antennas.push_back(12); Antennas.push_back(0); Antennas.push_back(8); - InstalledStations[2].VHChannel.push_back(Antennas); + InstalledStations[2].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[2].nStrings = InstalledStations[2].VHChannel.size(); @@ -6250,37 +6296,37 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { } if (InstalledStations.size() > 3) { // Station 3 - + // Make string 0 - Antennas.push_back(5); + Antennas.push_back(5); Antennas.push_back(13); - Antennas.push_back(1); + Antennas.push_back(1); Antennas.push_back(9); - InstalledStations[3].VHChannel.push_back(Antennas); + InstalledStations[3].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 1 - Antennas.push_back(6); + Antennas.push_back(6); Antennas.push_back(14); - Antennas.push_back(2); + Antennas.push_back(2); Antennas.push_back(10); InstalledStations[3].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 2 - Antennas.push_back(7); + Antennas.push_back(7); Antennas.push_back(15); - Antennas.push_back(3); + Antennas.push_back(3); Antennas.push_back(11); - InstalledStations[3].VHChannel.push_back(Antennas); + InstalledStations[3].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 3 - Antennas.push_back(4); + Antennas.push_back(4); Antennas.push_back(12); - Antennas.push_back(0); + Antennas.push_back(0); Antennas.push_back(8); - InstalledStations[3].VHChannel.push_back(Antennas); + InstalledStations[3].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[3].nStrings = InstalledStations[3].VHChannel.size(); @@ -6298,37 +6344,37 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { } if (InstalledStations.size() > 4) { // Station 4 - + // Make string 0 - Antennas.push_back(5); + Antennas.push_back(5); Antennas.push_back(13); - Antennas.push_back(1); + Antennas.push_back(1); Antennas.push_back(9); - InstalledStations[4].VHChannel.push_back(Antennas); + InstalledStations[4].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 1 - Antennas.push_back(6); + Antennas.push_back(6); Antennas.push_back(14); - Antennas.push_back(2); + Antennas.push_back(2); Antennas.push_back(10); InstalledStations[4].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 2 - Antennas.push_back(7); + Antennas.push_back(7); Antennas.push_back(15); - Antennas.push_back(3); + Antennas.push_back(3); Antennas.push_back(11); - InstalledStations[4].VHChannel.push_back(Antennas); + InstalledStations[4].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 3 - Antennas.push_back(4); + Antennas.push_back(4); Antennas.push_back(12); - Antennas.push_back(0); + Antennas.push_back(0); Antennas.push_back(8); - InstalledStations[4].VHChannel.push_back(Antennas); + InstalledStations[4].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[4].nStrings = InstalledStations[4].VHChannel.size(); @@ -6341,37 +6387,37 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { } if (InstalledStations.size() > 5) { // Station 5 - + // Make string 0 - Antennas.push_back(5); + Antennas.push_back(5); Antennas.push_back(13); - Antennas.push_back(1); + Antennas.push_back(1); Antennas.push_back(9); - InstalledStations[5].VHChannel.push_back(Antennas); + InstalledStations[5].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 1 - Antennas.push_back(6); + Antennas.push_back(6); Antennas.push_back(14); - Antennas.push_back(2); + Antennas.push_back(2); Antennas.push_back(10); - InstalledStations[5].VHChannel.push_back(Antennas); + InstalledStations[5].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 2 - Antennas.push_back(7); + Antennas.push_back(7); Antennas.push_back(15); - Antennas.push_back(3); + Antennas.push_back(3); Antennas.push_back(11); - InstalledStations[5].VHChannel.push_back(Antennas); + InstalledStations[5].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 3 - Antennas.push_back(4); + Antennas.push_back(4); Antennas.push_back(12); - Antennas.push_back(0); + Antennas.push_back(0); Antennas.push_back(8); - InstalledStations[5].VHChannel.push_back(Antennas); + InstalledStations[5].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[5].nStrings = InstalledStations[5].VHChannel.size(); @@ -6384,7 +6430,7 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { } if (InstalledStations.size() > 6) { // Phased Array - + // Make Phased Array Antennas.push_back(9); // PAHpol at Z=-184.8 Antennas.push_back(8); // PAHpol at Z=-182.8 @@ -6395,11 +6441,11 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { Antennas.push_back(2); // PAVpol at Z=-174.7 Antennas.push_back(1); // PAVpol at Z=-173.7 Antennas.push_back(0); // PAVpol at Z=-172.7 - InstalledStations[6].VHChannel.push_back(Antennas); + InstalledStations[6].VHChannel.push_back(Antennas); Antennas.clear(); if (settings1->DETECTOR_STATION==1) { - // No A5 Antennas on the PA DAQ + // No A5 Antennas on the PA DAQ InstalledStations[6].nChannels = 9; InstalledStations[6].nChannelsVH = 9; } @@ -6411,7 +6457,7 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { // Make string 3s Antennas.push_back(5);// Antennas.push_back(x); // Antennas.push_back(11);// Antennas.push_back(x); - InstalledStations[6].VHChannel.push_back(Antennas); + InstalledStations[6].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[6].nChannels = 10; @@ -6419,31 +6465,31 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { } else if (settings1->DETECTOR_STATION==3) { // ARA05 DAQ off, only 7 vpols available - // Note that numbering of VPol channels is different here from DETECTOR=4 + // Note that numbering of VPol channels is different here from DETECTOR=4 // since this is the PA DAQ - + // Make string 1 Antennas.push_back(12);// Antennas.push_back(x); Antennas.push_back(13);// Antennas.push_back(x); - InstalledStations[6].VHChannel.push_back(Antennas); + InstalledStations[6].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 2 Antennas.push_back(10);// Antennas.push_back(x); // Antennas.push_back(x);// Antennas.push_back(x); - InstalledStations[6].VHChannel.push_back(Antennas); + InstalledStations[6].VHChannel.push_back(Antennas); Antennas.clear(); - + // Make string 3 Antennas.push_back(5);// Antennas.push_back(x); Antennas.push_back(11);// Antennas.push_back(x); - InstalledStations[6].VHChannel.push_back(Antennas); + InstalledStations[6].VHChannel.push_back(Antennas); Antennas.clear(); // Make string 4 Antennas.push_back(14);// Antennas.push_back(x); Antennas.push_back(15);// Antennas.push_back(x); - InstalledStations[6].VHChannel.push_back(Antennas); + InstalledStations[6].VHChannel.push_back(Antennas); Antennas.clear(); InstalledStations[6].nChannels = 16; @@ -6458,9 +6504,9 @@ void Detector::SetupInstalledStations(Settings *settings1=nullptr) { return; } - + int Detector::GetChannelfromStringAntenna ( int stationNum, int stringnum, int antennanum){ - + int ChannelNum; if (stationNum < int(InstalledStations.size())){ if (stringnum < int(InstalledStations[stationNum].VHChannel.size())){ @@ -6478,7 +6524,7 @@ int Detector::GetChannelfromStringAntenna ( int stationNum, int stringnum, int a return -1; } } - + cerr << "Invalid request for station channel map: station number" << endl; cout << stationNum << " : " << int(InstalledStations.size()) << endl; return -1; @@ -6583,7 +6629,7 @@ int Detector::GetChannelfromStringAntenna ( int stationNum, int stringnum, int a } void Detector::GetSSAfromChannel ( int stationID, int channelNum, int * antennaNum, int * stringNum) { - + *stringNum = -1; *antennaNum = -1; for (int i = 0; i < int(InstalledStations[stationID].VHChannel.size()); i++){ @@ -6594,11 +6640,11 @@ void Detector::GetSSAfromChannel ( int stationID, int channelNum, int * antennaN } } } - + if (*stringNum == -1) { cerr << "No string/antenna matches the channel number" << endl; - } - + } + return; } @@ -6619,10 +6665,10 @@ void Detector::GetSSAfromChannel(int stationID, int channelNum, int * antennaNum } } - if ( * stringNum == -1) { + if ( * stringNum == -1) { cerr << "No string/antenna matches the channel number" << endl; } - } + } else if (settings1 -> DETECTOR == 4) { for (int i = 0; i < int(InstalledStations[stationID].VHChannel.size()); i++) { @@ -6634,10 +6680,10 @@ void Detector::GetSSAfromChannel(int stationID, int channelNum, int * antennaNum } } - if ( * stringNum == -1) + if ( * stringNum == -1) cerr << "No string/antenna matches the channel number" << endl; - } + } else if (settings1 -> DETECTOR == 5) { stationID=6; // Force the funciton to use phased array and not the provided stationID @@ -6650,7 +6696,7 @@ void Detector::GetSSAfromChannel(int stationID, int channelNum, int * antennaNum } } - if ( * stringNum == -1) { + if ( * stringNum == -1) { cerr << "No string/antenna matches the channel number" << endl; } } @@ -6678,57 +6724,57 @@ void Detector::GetSSAfromChannel(int stationID, int channelNum, int * antennaNum #ifdef ARA_UTIL_EXISTS void Detector::UseAntennaInfo(int stationNum, Settings *settings1){ - + AraGeomTool *araGeom = new AraGeomTool(); - if (stationNum == 0) { + if (stationNum == 0) { params.TestBed_BH_Mean_delay = 0.; - } + } for ( int chan = 1; chan < InstalledStations[stationNum].nChannels+1; chan++){ - + double avgX, avgY; - + int antennaNum, stringNum; GetSSAfromChannel(stationNum, chan, &antennaNum, &stringNum, settings1); - + if (araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].polType != AraAntPol::kSurface){ stations[stationNum].strings[stringNum].antennas[antennaNum].SetX(stations[stationNum].GetX()+araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].antLocation[0]); stations[stationNum].strings[stringNum].antennas[antennaNum].SetY(stations[stationNum].GetY()+araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].antLocation[1]); stations[stationNum].strings[stringNum].antennas[antennaNum].SetZ(araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].antLocation[2]); - + //set polarization to match the deployed information - stations[stationNum].strings[stringNum].antennas[antennaNum].type = int(araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].polType); - + stations[stationNum].strings[stringNum].antennas[antennaNum].type = int(araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].polType); + stations[stationNum].strings[stringNum].SetX(stations[stationNum].GetX()+araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].antLocation[0]); stations[stationNum].strings[stringNum].SetY(stations[stationNum].GetY()+araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].antLocation[1]); - + if ( params.antenna_orientation == 0 ) { // all borehole antennas facing same x stations[stationNum].strings[stringNum].antennas[antennaNum].orient = 0; } else if ( params.antenna_orientation == 1 ) { // borehole antennas one next facing different way if ( stringNum==0||stringNum==3 ) { - if ( antennaNum==0||antennaNum==1 ) { + if ( antennaNum==0||antennaNum==1 ) { stations[stationNum].strings[stringNum].antennas[antennaNum].orient = 0; } - else { + else { stations[stationNum].strings[stringNum].antennas[antennaNum].orient = 1; } } else { - if ( antennaNum==0||antennaNum==1 ) { + if ( antennaNum==0||antennaNum==1 ) { stations[stationNum].strings[stringNum].antennas[antennaNum].orient = 1; } - else { + else { stations[stationNum].strings[stringNum].antennas[antennaNum].orient = 0; } } - + } //end orientation selection - // put DAQ channel type + // put DAQ channel type if (araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].daqChanType == AraDaqChanType::kDisconeChan) { // BH chs stations[stationNum].strings[stringNum].antennas[antennaNum].DAQchan = 0; } @@ -6736,10 +6782,10 @@ void Detector::UseAntennaInfo(int stationNum, Settings *settings1){ stations[stationNum].strings[stringNum].antennas[antennaNum].DAQchan = 1; } - cout << "Borehole ch: " << chan << " station: " << stationNum << " string: " << stringNum - << " ant: " << antennaNum << " Type: " << stations[stationNum].strings[stringNum].antennas[antennaNum].type + cout << "Borehole ch: " << chan << " station: " << stationNum << " string: " << stringNum + << " ant: " << antennaNum << " Type: " << stations[stationNum].strings[stringNum].antennas[antennaNum].type << endl; - + if (stationNum == 0) { params.TestBed_Ch_delay[chan-1] = araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].debugTotalCableDelay; @@ -6747,52 +6793,52 @@ void Detector::UseAntennaInfo(int stationNum, Settings *settings1){ if (chan<9) { params.TestBed_BH_Mean_delay += params.TestBed_Ch_delay[chan-1]; } - + // give manual delay time for BH chs (for TestBed) if (chan == 2) { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = 50.; // additional delay in ns } - else if (chan == 3) { + else if (chan == 3) { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = -10.; // additional delay in ns } - else if (chan == 4) { + else if (chan == 4) { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = 20.; // additional delay in ns } - else if (chan == 5) { + else if (chan == 5) { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = 30.; // additional delay in ns } - else if (chan == 6) { + else if (chan == 6) { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = 20.; // additional delay in ns } - else if (chan == 7) { + else if (chan == 7) { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = -10.; // additional delay in ns } - else if (chan == 8) { + else if (chan == 8) { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = 10.; // additional delay in ns } - else { + else { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = 0.; } } else { stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay = 0.;// no manual delay for other stations (not known yet) } - + // set manual delay bin stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay_bin = stations[stationNum].strings[stringNum].antennas[antennaNum].manual_delay / (settings1->TIMESTEP * 1.e9); }// end polarization (antenna type) selection else { - + int antPolNum = araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].antPolNum; // set surface antenna postions - + stations[stationNum].surfaces[antPolNum].SetX( stations[stationNum].GetX()+araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].antLocation[0]); stations[stationNum].surfaces[antPolNum].SetY( stations[stationNum].GetY()+araGeom->getStationInfo(stationNum, settings1->DETECTOR_YEAR)->fAntInfo[chan-1].antLocation[1]); - + } } // end channel loop - + if (stationNum == 0) { params.TestBed_BH_Mean_delay /= 8.; params.TestBed_BH_Mean_delay_bin = params.TestBed_BH_Mean_delay/(settings1->TIMESTEP * 1.e9); // change TIMESTEP s to ns @@ -6800,36 +6846,36 @@ void Detector::UseAntennaInfo(int stationNum, Settings *settings1){ params.TestBed_WFtime_offset_ns = -20.; } - return; + return; } #endif #ifdef ARA_UTIL_EXISTS void Detector::ImportStationInfo(Settings *settings1, int StationIndex, int StationID){ - + AraGeomTool *araGeom = new AraGeomTool(); int StationID_AraRoot = settings1->DETECTOR_STATION_ARAROOT; - - if (StationID == 0) { + + if (StationID == 0) { params.TestBed_BH_Mean_delay = 0.; - } + } std::cout<<"InstalledStations[StationID].nChannels is "<getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].antLocation[2]); //set polarization to match the deployed information - stations[StationIndex].strings[stringNum].antennas[antennaNum].type = int(araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].polType); + stations[StationIndex].strings[stringNum].antennas[antennaNum].type = int(araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].polType); stations[StationIndex].strings[stringNum].SetX(stations[StationIndex].GetX()+araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].antLocation[0]); stations[StationIndex].strings[stringNum].SetY(stations[StationIndex].GetY()+araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].antLocation[1]); - + if ( params.antenna_orientation == 0 ) { // all borehole antennas facing same x stations[StationIndex].strings[stringNum].antennas[antennaNum].orient = 0; } else if ( params.antenna_orientation == 1 ) { // borehole antennas one next facing different way if ( stringNum==0||stringNum==3 ) { - if ( antennaNum==0||antennaNum==1 ) { + if ( antennaNum==0||antennaNum==1 ) { stations[StationIndex].strings[stringNum].antennas[antennaNum].orient = 0; } - else { + else { stations[StationIndex].strings[stringNum].antennas[antennaNum].orient = 1; } } else { - if ( antennaNum==0||antennaNum==1 ) { + if ( antennaNum==0||antennaNum==1 ) { stations[StationIndex].strings[stringNum].antennas[antennaNum].orient = 1; } else { stations[StationIndex].strings[stringNum].antennas[antennaNum].orient = 0; } } - + } //end orientation selection - // put DAQ channel type + // put DAQ channel type if (araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].daqChanType == AraDaqChanType::kDisconeChan) { // BH chs stations[StationIndex].strings[stringNum].antennas[antennaNum].DAQchan = 0; } @@ -6877,32 +6923,32 @@ void Detector::ImportStationInfo(Settings *settings1, int StationIndex, int Stat stations[StationIndex].strings[stringNum].antennas[antennaNum].DAQchan = 1; } - cout << "Borehole ch: " << chan << " inserted station: " << StationIndex << " station: " << StationID - << " string: " << stringNum << " ant: " << antennaNum << " Type: " << stations[StationIndex].strings[stringNum].antennas[antennaNum].type + cout << "Borehole ch: " << chan << " inserted station: " << StationIndex << " station: " << StationID + << " string: " << stringNum << " ant: " << antennaNum << " Type: " << stations[StationIndex].strings[stringNum].antennas[antennaNum].type << endl; if (StationID == 0) { params.TestBed_Ch_delay[chan] = araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].debugTotalCableDelay; params.TestBed_Ch_delay_bin[chan] = params.TestBed_Ch_delay[chan]/(settings1->TIMESTEP * 1.e9); // change TIMESTEP s to ns - if (chan<8) { + if (chan<8) { params.TestBed_BH_Mean_delay += params.TestBed_Ch_delay[chan]; } // give manual delay time for BH chs (for TestBed) - if (chan == 1) { + if (chan == 1) { stations[StationIndex].strings[stringNum].antennas[antennaNum].manual_delay = 50.; // additional delay in ns } - else if (chan == 2) { + else if (chan == 2) { stations[StationIndex].strings[stringNum].antennas[antennaNum].manual_delay = -10.; // additional delay in ns } - else if (chan == 3) { + else if (chan == 3) { stations[StationIndex].strings[stringNum].antennas[antennaNum].manual_delay = 20.; // additional delay in ns } - else if (chan == 4) { + else if (chan == 4) { stations[StationIndex].strings[stringNum].antennas[antennaNum].manual_delay = 30.; // additional delay in ns } - else if (chan == 5) { + else if (chan == 5) { stations[StationIndex].strings[stringNum].antennas[antennaNum].manual_delay = 20.; // additional delay in ns } else if (chan == 6) { @@ -6924,17 +6970,17 @@ void Detector::ImportStationInfo(Settings *settings1, int StationIndex, int Stat }// end polarization (antenna type) selection else { - + int antPolNum = araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].antPolNum; // set surface antenna postions - + stations[StationIndex].surfaces[antPolNum].SetX( stations[StationIndex].GetX()+araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].antLocation[0]); stations[StationIndex].surfaces[antPolNum].SetY( stations[StationIndex].GetY()+araGeom->getStationInfo(StationID_AraRoot, settings1->DETECTOR_YEAR)->fAntInfo[antId].antLocation[1]); - + } - + } // end channel loop - + if (StationID == 0) { params.TestBed_BH_Mean_delay /= 8.; params.TestBed_BH_Mean_delay_bin = params.TestBed_BH_Mean_delay/(settings1->TIMESTEP * 1.e9); // change TIMESTEP s to ns @@ -6949,16 +6995,16 @@ void Detector::ImportStationInfo(Settings *settings1, int StationIndex, int Stat void Detector::SetupIdealStations(){ - + IdealStations.resize(2); - + std::vector < int > Antennas; - + if (IdealStations.size() > 1){ // Station 1 int stationID = 1; IdealStations[stationID].nChannels = 20; IdealStations[stationID].nChannelsVH = 16; - + Antennas.push_back(5); Antennas.push_back(9); Antennas.push_back(1); @@ -6986,16 +7032,16 @@ void Detector::SetupIdealStations(){ Antennas.push_back(20); IdealStations[stationID].VHChannel.push_back(Antennas); // Make string 3 Antennas.clear(); - + IdealStations[stationID].nStrings = IdealStations[stationID].VHChannel.size(); IdealStations[stationID].surfaceChannels.push_back(13); IdealStations[stationID].surfaceChannels.push_back(14); IdealStations[stationID].surfaceChannels.push_back(15); IdealStations[stationID].surfaceChannels.push_back(16); - + IdealStations[stationID].nSurfaces = IdealStations[stationID].surfaceChannels.size(); - + Antennas.push_back(0); Antennas.push_back(1); Antennas.push_back(2); @@ -7009,26 +7055,26 @@ void Detector::SetupIdealStations(){ Antennas.push_back(7); IdealStations[stationID].VHID.push_back(Antennas); // Make string 1 Antennas.clear(); - + Antennas.push_back(8); Antennas.push_back(9); Antennas.push_back(10); Antennas.push_back(11); IdealStations[stationID].VHID.push_back(Antennas); // Make string 2 Antennas.clear(); - + Antennas.push_back(12); Antennas.push_back(13); Antennas.push_back(14); Antennas.push_back(15); IdealStations[stationID].VHID.push_back(Antennas); // Make string 3 Antennas.clear(); - + IdealStations[stationID].surfaceID.push_back(0); IdealStations[stationID].surfaceID.push_back(1); IdealStations[stationID].surfaceID.push_back(2); IdealStations[stationID].surfaceID.push_back(3); - + for (int BHAntID = 0; BHAntID < IdealStations[stationID].nChannelsVH; BHAntID++){ for (int i = 0; i < IdealStations[stationID].VHID.size(); i++){ for (int j = 0; j < IdealStations[stationID].VHID[i].size(); j++){ @@ -7046,7 +7092,7 @@ void Detector::SetupIdealStations(){ } } } - } + } return; } @@ -7054,7 +7100,7 @@ void Detector::SetupIdealStations(){ int Detector::getStringfromArbAntID( int stationID, int ant_ID){ for (int i = 0; i < stations[stationID].strings.size(); i++){ - if (ant_ID < stations[stationID].strings[i].antennas.size()) { + if (ant_ID < stations[stationID].strings[i].antennas.size()) { return i; } else { @@ -7062,40 +7108,40 @@ int Detector::getStringfromArbAntID( int stationID, int ant_ID){ } } - throw runtime_error("Detector::getStringfromArbAntID - you've reached a place where a return statement is missing. Can you fix it?"); + throw runtime_error("Detector::getStringfromArbAntID - you've reached a place where a return statement is missing. Can you fix it?"); } int Detector::getAntennafromArbAntID( int stationID, int ant_ID){ - + for (int i = 0; i < stations[stationID].strings.size(); i++){ - if (ant_ID < stations[stationID].strings[i].antennas.size()) { + if (ant_ID < stations[stationID].strings[i].antennas.size()) { return ant_ID; } else { ant_ID = ant_ID - stations[stationID].strings[i].antennas.size(); } } - - throw runtime_error("Detector:::getAntennafromArbAntID - you've reached a place where a return statement is missing. Can you fix it?"); + + throw runtime_error("Detector:::getAntennafromArbAntID - you've reached a place where a return statement is missing. Can you fix it?"); } //TODO: Need to retool the arguments of this to use the Settings parameters for Vpol, Vpol_top, HPol, and Tx. inline void Detector::ReadImpedance(string filename, double (*TempRealImpedance)[freq_step_max], double (*TempImagImpedance)[freq_step_max]) { // this is really dumb but were gonna assume all the impedances have the same frequency - // binning and just rewrite this every time a file is read-in. seems okay for now + // binning and just rewrite this every time a file is read-in. seems okay for now // and i just don't have the time, someone make this better one day -- MSM 2/18/25 impFreq.clear(); - + ifstream NecOut( filename.c_str() ); string line; - int idx = 0; + int idx = 0; if ( NecOut.is_open() ) { getline (NecOut, line); //gets first line to skip header - - getline (NecOut, line); //gets first line of data + + getline (NecOut, line); //gets first line of data while (NecOut.good() ) { - + //put line into a string stream stringstream ss(line); @@ -7107,20 +7153,20 @@ inline void Detector::ReadImpedance(string filename, double (*TempRealImpedance) } if(words.size() != 3) { - throw runtime_error("Impedance file not formatted properly! "+filename); + throw runtime_error("Impedance file not formatted properly! "+filename); } impFreq.push_back(stod(words[0])); (*TempRealImpedance)[idx] = stod(words[1]); (*TempImagImpedance)[idx] = stod(words[2]); - getline (NecOut, line); //Gets next line of data + getline (NecOut, line); //Gets next line of data idx++; - + }// end while NecOut.good NecOut.close(); - }// end if file open + }// end if file open }//ReadImpedance @@ -7130,22 +7176,22 @@ double Detector::GetSplitterFactor(Settings *settings) { // AraSim default had factor of 1/sqrt(2), whereas A1-3 have a 3.4 dB factor and A4-5 have a 1.4 dB factor. // See talk by Brian discussing splitter factors: https://aradocs.wipac.wisc.edu/cgi-bin/DocDB/ShowDocument?docid=2751 - double factor; - + double factor; + //Case for simulating real ARA Stations 0 (testbed), A1, A2, and A3. - if (settings->DETECTOR == 4 and settings->DETECTOR_STATION < 4) { + if (settings->DETECTOR == 4 and settings->DETECTOR_STATION < 4) { factor = 1/sqrt(pow(10,-0.34)); } //Case for simulating real ARA Stations A4 and A5 (non phased array). - else if (settings->DETECTOR == 4 and settings->DETECTOR_STATION >= 4) { + else if (settings->DETECTOR == 4 and settings->DETECTOR_STATION >= 4) { factor = 1/sqrt(pow(10,-0.14)); } - //Case for Phased Array implementation by Abby Bishop. - else if (settings->DETECTOR == 5) { + //Case for Phased Array implementation by Abby Bishop. + else if (settings->DETECTOR == 5) { factor = 1; } //Final case where if none of the above are satisfied, it defaults to the historical 1/sqrt(2) - else { + else { factor = 1/sqrt(2); } @@ -7155,6 +7201,3 @@ double Detector::GetSplitterFactor(Settings *settings) { Detector::~Detector() { } - - - diff --git a/Detector.h b/Detector.h index 531d9ee6..7d29d9c2 100644 --- a/Detector.h +++ b/Detector.h @@ -43,14 +43,14 @@ class Parameters { int number_of_antennas_string; //antennas per string int number_of_surfaces_station; //surface antennas per station int number_of_channels; // number of channels for each regular (non-TestBed) station - + int number_of_strings_station_TB; //number of strings in the TestBed int number_of_antennas_string_TB; //number of antennas in each string in the Testbed int number_of_surfaces_station_TB; //number of surface stations for the TestBed int number_of_channels_TB; // number of channels for the TestBed - + int num_of_channels[2]; - + int bore_hole_antenna_layout; // bore hole antenna layout, 0 : VHVH, 1 : VHV, 2 : VHVV int number_of_strings; @@ -58,10 +58,10 @@ class Parameters { double core_x; double core_y; - + int DeployedStations; - - + + // static const int freq_step = 60; // static const int ang_step = 2664; // static const double freq_width = 16.667; // this value could be changed when Nec2 condition changes! @@ -116,7 +116,7 @@ class Surface_antenna : public Position { }; - + //struct Antenna : public Position, public TObject { //class Antenna : public Position, public TObject { class Antenna : public Position { @@ -131,13 +131,13 @@ class Antenna : public Position { int manual_delay; // to fit the waveform to actual TestBed waveform, added manual delay time int manual_delay_bin; // to fit the waveform to actual TestBed waveform, added manual delay bin - + double GetG(Detector *D, double freq, double theta, double phi); // read gain value from Detector class, return 2-D interpolated value //ClassDef(Antenna,1); ClassDef(Antenna,3); - + }; @@ -167,7 +167,7 @@ class ARA_station : public Position { double DATA_BIN_SIZE; int number_of_antennas; // total number of antennas for each stations - + ClassDef(ARA_station,1); }; @@ -192,11 +192,11 @@ class InstalledStation { //class Detector : public TObject { - + class IdealStation{ - + public: - + int nSurfaces; int nStrings; vector < int > surfaceChannels; @@ -208,22 +208,22 @@ class IdealStation{ vector < int > IDSurface; vector < int > IDAntenna; vector < int > IDString; - + ClassDef(IdealStation, 1); - + }; enum EAntennaType { eVPol, // (bottom) Vpol eVPolTop, // top Vpol eHPol, // Hpol - eTx, // transmitter - eTxCross, // transmitter + eTx, // transmitter + eTxCross, // transmitter eVPolCross, // Cross-pol VPol eVPolTopCross, // Cross-pol VPol Top eHPolCross // Cross-pol HPol }; - + class Detector { private: static const int freq_step_max = 60; @@ -246,16 +246,16 @@ class Detector { vector > VphaseTopCross; vector > HgainCross; vector > HphaseCross; - + //Define impedance and gain for receiving antenna vector impFreq; double RealImpedanceV[freq_step_max]; - double ImagImpedanceV[freq_step_max]; + double ImagImpedanceV[freq_step_max]; double RealImpedanceVTop[freq_step_max]; - double ImagImpedanceVTop[freq_step_max]; + double ImagImpedanceVTop[freq_step_max]; double RealImpedanceH[freq_step_max]; - double ImagImpedanceH[freq_step_max]; - + double ImagImpedanceH[freq_step_max]; + //Define impedance and gain for transmitting antenna double RealImpedanceTx[freq_step_max]; double ImagImpedanceTx[freq_step_max]; @@ -270,7 +270,7 @@ class Detector { void ReadAllAntennaImpedance(Settings *settings1); - + void ReadFilter(string filename, Settings *settings1); double FilterGain[freq_step_max]; // Filter gain (dB) for Detector freq bin array @@ -298,7 +298,7 @@ class Detector { void CalculateElectChain(Settings *settings1); // calculate data-driven noise model int gain_ch; // Number of channels used for gain model array population in ReadElectChain() std::vector< std::vector > ElectGain; //Elect chain gain (unitless) for Detector freq bin array - std::vector< std::vector > ElectPhase; // Elect chain phase (rad) for Detector freq bin array + std::vector< std::vector > ElectPhase; // Elect chain phase (rad) for Detector freq bin array void ReadTrig_Delays_Masking(string filename, Settings *settings1); std::vector triggerDelay; //trigger delay for a given channel (seconds?) @@ -306,16 +306,16 @@ class Detector { std::vector activeDelay; //decision value to activate delay (either 0 or 1) void ReadGainOffset_TestBed(string filename, Settings *settings1); - vector GainOffset_TB_ch; // constant gain offset for the TestBed chs + vector GainOffset_TB_ch; // constant gain offset for the TestBed chs void ReadThresOffset_TestBed(string filename, Settings *settings1); - vector ThresOffset_TB_ch; // constant gain offset for the TestBed chs + vector ThresOffset_TB_ch; // constant gain offset for the TestBed chs void ReadThres_TestBed(string filename, Settings *settings1); - vector Thres_TB_ch; // Threshold values for the TestBed chs + vector Thres_TB_ch; // Threshold values for the TestBed chs void ReadTemp_TestBed(string filename, Settings *settings1); - //vector Temp_TB_ch; // constant gain offset for the TestBed chs + //vector Temp_TB_ch; // constant gain offset for the TestBed chs void ReadRFCM_TestBed(string filename, Settings *settings1); double RFCM_TB_ch[16][freq_step_max]; // Filter gain (dB) for Detector freq bin array @@ -337,7 +337,7 @@ class Detector { rayleighFits_DeepStation_values holds the Rayleigh sigma. The first dimension is for the number of channels (so this is "number of channels" long). The second dimension is for the number of frequency bins (so this is "number of frequency bins" long). - (which goes first and which goes second is arbitrary; + (which goes first and which goes second is arbitrary; the TestBed version does it in this order, so replicate here) rayleighFits_DeepStation_frequencies holds the Rayleigh frequencies. @@ -350,7 +350,7 @@ class Detector { void ReadRayleighFit_DeepStation(string filename, Settings *settings1); - void ReadNoiseFigure(string filename, Settings *settings1); + void ReadNoiseFigure(string filename, Settings *settings1); double NoiseFig_ch[16][freq_step_max]; vector NoiseFig_freq; vector < vector < double > > NoiseFig_databin_ch; @@ -365,7 +365,7 @@ class Detector { vector transVCross_databin; vector transVTopCross_databin; vector transHCross_databin; - + void ReadAmplifierNoiseFigure(Settings *settings1); vector< vector > amplifierNoiseFig_ch; @@ -405,7 +405,7 @@ class Detector { //Creating function to interpolate antenna impedance to frequency binning. double GetImpedance(double freq, int ant_m=0, int ant_number=0, bool useInTransmitterMode=false); - + int GetTrigOffset( int ch, Settings *settings1 ); int GetTrigMasking( int ch ); @@ -430,7 +430,7 @@ class Detector { double GetFOAMGain_NFOUR(int bin) { return FOAMGain_NFOUR[bin]; } // bin for FFT double GetFOAMGain_1D_OutZero(double freq); - + double GetElectGain(int bin, int gain_ch_no) { return ElectGain[gain_ch_no][bin]; } // same bin with Vgain, Hgain double GetElectGain_1D_OutZero(double freq, int gain_ch_no); double GetElectPhase_1D(double freq, int gain_ch_no); @@ -446,23 +446,23 @@ class Detector { std::vector< std::vector< double> > GetRayleighFitVector_databin(int station, Settings *settings); double GetNoiseFig_databin(int ch, int bin) { return NoiseFig_databin_ch[ch%16][bin]; } // bin for FFT - double GetNoiseFig_OutZero(int ch, double freq); - + double GetNoiseFig_OutZero(int ch, double freq); + double GetTransm_databin(int ch, int bin) { if(ch%16<4){return transVTop_databin[bin];} - else if(ch%16<8){return transV_databin[bin];} + else if(ch%16<8){return transV_databin[bin];} else{return transH_databin[bin];} } // bin for FFT double GetTransm_OutZero(int ch, double freq); void ReadNoiseFig_New(Settings *settings1); // get noise Figure array with new DATA_BIN_SIZE - + double GetGainOffset( int StationID, int ch, Settings *settings1 ); // returns voltage factor for specific channel gain off set double GetThresOffset( int StationID, int ch, Settings *settings1 ); // returns voltage factor for specific channel gain off set - double GetThres( int StationID, int ch, Settings *settings1 ); // returns voltage factor threshold for specific channel + double GetThres( int StationID, int ch, Settings *settings1 ); // returns voltage factor threshold for specific channel double GetTemp( int StationID, int ch, Settings *settings1 ); // returns voltage factor for specific channel gain off set - vector Temp_TB_ch; // constant gain offset for the TestBed chs + vector Temp_TB_ch; // constant gain offset for the TestBed chs double Getfreq_init() {return freq_init;} @@ -476,7 +476,7 @@ class Detector { vector fdiode_real_databin; // NFOUR array of f domain tunnel diode response (FFT of diode_real). also same with icemc -> anita -> fdiode_real but only full bandwidth array 4 vector fdiode_real; // NFOUR/2 array of f domain tunnel diode response (FFT of diode_real). also same with icemc -> anita -> fdiode_real but only full bandwidth array 4 vector fdiode_real_double; // NFOUR array of f domain tunnel diode response (FFT of diode_real). also same with icemc -> anita -> fdiode_real but only full bandwidth array 4 - + double TIMESTEP; // will copy TIMESTEP from Settings int NFOUR; // also will copy NFOUR from Settings @@ -498,23 +498,23 @@ class Detector { // for a best performance, we can just set a new reasonable DATA_BIN_SIZE and make new values for those void get_NewDiodeModel(Settings *settings1); - void ReadFilter_New(Settings *settings1); // get filter vector array with new DATA_BIN_SIZE + void ReadFilter_New(Settings *settings1); // get filter vector array with new DATA_BIN_SIZE - void ReadPreamp_New(Settings *settings1); // get filter vector array with new DATA_BIN_SIZE + void ReadPreamp_New(Settings *settings1); // get filter vector array with new DATA_BIN_SIZE - void ReadFOAM_New(Settings *settings1); // get filter vector array with new DATA_BIN_SIZE + void ReadFOAM_New(Settings *settings1); // get filter vector array with new DATA_BIN_SIZE - void ReadRFCM_New(Settings *settings1); // get filter vector array with new DATA_BIN_SIZE + void ReadRFCM_New(Settings *settings1); // get filter vector array with new DATA_BIN_SIZE void ReadRayleigh_New(Settings *settings1); // get Rayleigh fit array with new DATA_BIN_SIZE - + // vector < vector < vector < int > > > ChannelfromStringAntenna; // void SetChannelStringAntennaMap(); int GetChannelfromStringAntenna (int stationNum, int stringnum, int antennanum ); void GetSSAfromChannel ( int stationNum, int channelNum, int * antennaNum, int * stringNum ); - + #ifdef ARA_UTIL_EXISTS void UseAntennaInfo (int stationNum, Settings *settings1); void ImportStationInfo (Settings *settings1, int StationIndex, int StationID); @@ -523,8 +523,8 @@ class Detector { // more general used function void GetSSAfromChannel ( int stationID, int channelNum, int * antennaNum, int * stringNum, Settings *settings1); int GetChannelfromStringAntenna ( int stationID, int stringnum, int antennanum, Settings *settings1); - - + + /* struct InstalledStation { int nSurfaces; @@ -538,13 +538,13 @@ class Detector { }; */ - + vector < InstalledStation > InstalledStations; - + // class IdealStation{ -// +// // public: -// +// // int nSurfaces; // int nStrings; // vector < int > surfaceChannels; @@ -556,11 +556,11 @@ class Detector { // vector < int > IDSurface; // vector < int > IDAntenna; // vector < int > IDString; -// +// // }; - + vector < IdealStation > IdealStations; - + void SetupInstalledStations(Settings *settings1); void PrepareVectorsInstalled(); @@ -570,8 +570,8 @@ class Detector { int getAntennafromArbAntID( int stationID, int ant_ID); int getStringfromArbAntID( int stationID, int ant_ID); - - + + vector CalPulserWF_ns; vector CalPulserWF_V; @@ -579,10 +579,10 @@ class Detector { ~Detector(); //destructor ClassDef(Detector,2); - - - - + + + + }; diff --git a/Report.cc b/Report.cc index 27a6b338..8fe7b560 100644 --- a/Report.cc +++ b/Report.cc @@ -1590,7 +1590,7 @@ void Report::PropagateSignal( double Tx_theta = theta*180/PI; double Tx_phi = phi*180/PI; - + double heff_Tx_lastbin = GaintoHeight( detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true), freq_tmp, @@ -3680,7 +3680,7 @@ void Report::InvertAntFactors_Tdomain(double AntPhase_copol, double AntPhase_cro } void Report::InvertAntFactors_Tdomain_FirstTwo( - double heff, double heff_lastbin, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, + double heff, double heff_lastbin, Vector &Pol_vector, int ant_type, double &pol_factor, double &vm_bin0, double &vm_bin1, Settings *settings1, double antenna_theta, double antenna_phi, double freq, bool useInTransmitterMode ) { ApplyAntFactors_Tdomain_FirstTwo( From c4cb5fe3e2e657e34a421f950d8b81ab3e0c00c1 Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Wed, 9 Jul 2025 21:23:49 -0500 Subject: [PATCH 07/12] Now all event types work, but I need to input another Tx gain file --- Detector.cc | 45 ++------------------------------------------- Detector.h | 4 ++-- Report.cc | 6 +++--- 3 files changed, 7 insertions(+), 48 deletions(-) diff --git a/Detector.cc b/Detector.cc index 0d334317..7811de1d 100644 --- a/Detector.cc +++ b/Detector.cc @@ -2259,7 +2259,7 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ std::string HgainCrossFile; //Adding step to read Tx gain. Will hardcode to PVA gain for now. - TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; + TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_bicone6in_output.txt"; TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; if (settings1->ANTENNA_MODE == 0){ @@ -3110,72 +3110,31 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int double Gout; int bin = (int)( (freq - thisFreq_init) / thisFreq_width )+1; - cout << "thisFreq_init: " << thisFreq_init << endl; - cout << "thisFreq_width: " << thisFreq_width << endl; - - - // ========== Begin Debug Block ========== - cout << "[DEBUG] tempGain size: " << tempGain->size() << endl; - if(tempGain->size() < 2) { - cerr << "[ERROR] tempGain has size " << tempGain->size() << ", need at least 2 for interpolation.\n"; - throw std::out_of_range("tempGain too small in GetGain1D()"); - } - - cout << "[DEBUG] tempGain[0] size: " << (*tempGain)[0].size() << ", tempGain[1] size: " << (*tempGain)[1].size() << endl; - cout << "[DEBUG] angle_bin: " << angle_bin << endl; - - if(angle_bin >= (*tempGain)[0].size() || angle_bin >= (*tempGain)[1].size()) { - cerr << "[ERROR] angle_bin " << angle_bin << " is out of range for gain vectors.\n"; - throw std::out_of_range("angle_bin out of range in GetGain1D()"); - } - - if(F->size() < 2) { - cerr << "[ERROR] F vector has only " << F->size() << " entries. Cannot interpolate.\n"; - throw std::out_of_range("F vector too small in GetGain1D()"); - } - - cout << "[DEBUG] F[0]: " << F->at(0) << ", F[1]: " << F->at(1) << endl; - // ========== End Debug Block ========== //Interpolation of tempGain slope_1 = ((*tempGain)[1][angle_bin] - (*tempGain)[0][angle_bin]) / (F->at(1) - F->at(0)); - cout << "ASG 2" << endl; - cout << "freq" << freq << endl; - // if freq is lower than freq_init if ( freq < thisFreq_init ) { - cout << "Here 1" << endl; Gout = slope_1 * (freq - F->at(0)) + (*tempGain)[0][angle_bin]; - cout << "Here 1" << endl; } // if freq is higher than last freq else if ( freq > F->back() ) { - cout << "Here 2" << endl; Gout = 0.; - cout << "Here 2" << endl; } else { - cout << "Here 3" << endl; -cout << "[DEBUG] bin = " << bin - << ", F.size = " << F->size() - << ", F->back()" << F->back() - << ", freq = " << freq << endl; + Gout = (*tempGain)[bin-1][angle_bin] + (freq-F->at(bin-1))*((*tempGain)[bin][angle_bin]-(*tempGain)[bin-1][angle_bin])/(F->at(bin)-F->at(bin-1)); - cout << "Here 3" << endl; } if ( Gout < 0. ) { // gain can not go below 0 - cout << "Here 4" << endl; Gout = 0.; - cout << "Here 4" << endl; } -cout << "ASG 3" << endl; return Gout; } diff --git a/Detector.h b/Detector.h index 7d29d9c2..6a9c620b 100644 --- a/Detector.h +++ b/Detector.h @@ -259,8 +259,8 @@ class Detector { //Define impedance and gain for transmitting antenna double RealImpedanceTx[freq_step_max]; double ImagImpedanceTx[freq_step_max]; - int Tx_freq_init; - int Tx_freq_width; + double Tx_freq_init; + double Tx_freq_width; vector TxFreq; vector > Txgain; vector > Txphase; diff --git a/Report.cc b/Report.cc index 8fe7b560..26841d9c 100644 --- a/Report.cc +++ b/Report.cc @@ -1588,10 +1588,10 @@ void Report::PropagateSignal( double theta = acos(launch_vector[2]); double phi = atan2(launch_vector[1],launch_vector[0]); - double Tx_theta = theta*180/PI; - double Tx_phi = phi*180/PI; + Tx_theta = theta*180/PI; + Tx_phi = phi*180/PI; - double heff_Tx_lastbin = GaintoHeight( + heff_Tx_lastbin = GaintoHeight( detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true), freq_tmp, icemodel->GetN(*antenna_d), From 712aeb2824f3dda7f9f73ad6ae0ce74e61ad32fb Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Thu, 10 Jul 2025 13:19:14 -0500 Subject: [PATCH 08/12] Prevent negative Gout interpolations to be 0. Messes up FFTs. Instead make it be 1e-30 --- Detector.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Detector.cc b/Detector.cc index 7811de1d..7cdf7db0 100644 --- a/Detector.cc +++ b/Detector.cc @@ -2259,7 +2259,7 @@ inline void Detector::ReadAllAntennaGains(Settings *settings1){ std::string HgainCrossFile; //Adding step to read Tx gain. Will hardcode to PVA gain for now. - TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/ARA_bicone6in_output.txt"; + TxgainFile = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Copol_Kansas2024.txt"; TxgainFileCross = string(getenv("ARA_SIM_DIR"))+"/data/antennas/realizedGain/PVA_RealizedGainAndPhase_Crosspol_Kansas2024.txt"; if (settings1->ANTENNA_MODE == 0){ @@ -3121,7 +3121,7 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int // if freq is higher than last freq else if ( freq > F->back() ) { - Gout = 0.; + Gout = 1e-30; } else { @@ -3132,7 +3132,7 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int if ( Gout < 0. ) { // gain can not go below 0 - Gout = 0.; + Gout = 1e-30; } return Gout; From 37eff3cbcec4b9cc63ffd9d5dd4f9315f91c8172 Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Thu, 10 Jul 2025 14:19:07 -0500 Subject: [PATCH 09/12] Finishes applying functions in antenna factors --- Report.cc | 141 +++++++++++++++++++++++++++++++++++++----------------- Report.h | 4 +- 2 files changed, 100 insertions(+), 45 deletions(-) diff --git a/Report.cc b/Report.cc index 26841d9c..590e8805 100644 --- a/Report.cc +++ b/Report.cc @@ -1567,21 +1567,29 @@ void Report::PropagateSignal( //For birefringence, modify the polarization at the antennas birefringence->Principal_axes_polarization(Pol_vector, bire_ray_cnt, max_bire_ray_cnt, settings); - // Get ant gain with 2-D interpolation - double heff_lastbin = GaintoHeight( - detector->GetGain_1D_OutZero( - freq_tmp *1.E-6, antenna_theta, antenna_phi, - antenna_d->type, j, k), + // Co-pol effective height for the last bin + double heff_copol_lastbin = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp * 1.E-6, antenna_theta, antenna_phi, + antenna_d->type, j, k, false, false), freq_tmp, icemodel->GetN(*antenna_d), - detector->GetImpedance(freq_tmp*1.E-6, antenna_d->type, k)); + detector->GetImpedance(freq_tmp * 1.E-6, antenna_d->type, k)); + + // Cross-pol effective height for the last bin + double heff_crosspol_lastbin = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp * 1.E-6, antenna_theta, antenna_phi, + antenna_d->type, j, k, false, true), + freq_tmp, + icemodel->GetN(*antenna_d), + detector->GetImpedance(freq_tmp * 1.E-6, antenna_d->type, k)); // Tx effective height for last bin. Currently locked to standard ARA Vpol and HPol antennas. // Need to add selection mode. // Only used in EVENT_MODE == 12 double Tx_theta = 0; double Tx_phi = 0; - double heff_Tx_lastbin = 0; + double heff_Tx_copol_lastbin=0; + double heff_Tx_crosspol_lastbin=0; if (settings->EVENT_TYPE == 12){ // Pulser simulations //Defining transmission angle at the source (using launch_vector (a unit vector)) @@ -1590,18 +1598,33 @@ void Report::PropagateSignal( Tx_theta = theta*180/PI; Tx_phi = phi*180/PI; + + // Tx effective height for co-pol and cross-pol for the last bin + heff_Tx_copol_lastbin = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp * 1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true, false), + freq_tmp, + icemodel->GetN(*antenna_d), + detector->GetImpedance(freq_tmp * 1.E-6, 0, 0, true)); - heff_Tx_lastbin = GaintoHeight( - detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true), - freq_tmp, + heff_Tx_crosspol_lastbin = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp * 1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true, true), + freq_tmp, icemodel->GetN(*antenna_d), - detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true)); + detector->GetImpedance(freq_tmp * 1.E-6, 0, 0, true)); + // End Tx effective height for last bin } else if (event->IsCalpulser > 0){ // Calibration Pulser simulations Tx_theta = ray_output[1][ray_idx] *DEGRAD; // from 0 to 180 - heff_Tx_lastbin = GaintoHeight( - detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, antenna_phi, antenna_d->type, j, k), - freq_tmp, icemodel->GetN(event->Nu_Interaction[interaction_idx].posnu)); + + // Tx effective height for co-pol and cross-pol for the last bin + heff_Tx_copol_lastbin = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp * 1.E-6, Tx_theta, antenna_phi, antenna_d->type, j, k, true, false), + freq_tmp, icemodel->GetN(event->Nu_Interaction[interaction_idx].posnu)); + + heff_Tx_crosspol_lastbin = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp * 1.E-6, Tx_theta, antenna_phi, antenna_d->type, j, k, true, true), + freq_tmp, icemodel->GetN(event->Nu_Interaction[interaction_idx].posnu)); + // End Tx effective height for last bin if (event->IsCalpulser == 1) { Pol_vector = n_trg_slappy; @@ -1624,12 +1647,22 @@ void Report::PropagateSignal( freq_tmp = dF_Nnew *((double) n + 0.5); // in Hz 0.5 to place the middle of the bin and avoid zero freq - double heff = GaintoHeight( - detector->GetGain_1D_OutZero(freq_tmp *1.E-6, antenna_theta, antenna_phi, antenna_d->type, j, k), + // Co-pol effective height + double heff_copol = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp * 1.E-6, antenna_theta, antenna_phi, antenna_d->type, j, k, false, false), + freq_tmp, + icemodel->GetN(*antenna_d), + detector->GetImpedance(freq_tmp * 1.E-6, antenna_d->type, k)); + + // Cross-pol effective height + double heff_crosspol = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp * 1.E-6, antenna_theta, antenna_phi, antenna_d->type, j, k, false, true), freq_tmp, icemodel->GetN(*antenna_d), - detector->GetImpedance(freq_tmp*1.E-6, antenna_d->type, k)); - antenna_r->Heff[interaction_idx][ray_idx].push_back(heff); + detector->GetImpedance(freq_tmp * 1.E-6, antenna_d->type, k)); + + antenna_r->Heff_copol[interaction_idx][ray_idx].push_back(heff_copol); + antenna_r->Heff_crosspol[interaction_idx][ray_idx].push_back(heff_crosspol); //apply freq dependent attenuation model if in neutrino mode if (settings->EVENT_TYPE == 0 && settings->USE_ARA_ICEATTENU == 2) { @@ -1660,55 +1693,77 @@ void Report::PropagateSignal( // Apply transmitter effective height if in PVA Pulser mode if (settings->EVENT_TYPE == 12){ - double heff_Tx = GaintoHeight( - detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true), + // Co-pol effective height Tx + double heff_Tx_copol = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true, false), + freq_tmp, + icemodel->GetN(*antenna_d), + detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true)); + + // Cross-pol effective height Tx + double heff_Tx_crosspol = GaintoHeight( + detector->GetGain_1D_OutZero(freq_tmp *1.E-6, Tx_theta, Tx_phi, 0, 0, 0, true, true), freq_tmp, icemodel->GetN(*antenna_d), detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true)); + + // Retrieve co-pol and cross-pol phases + double phase_copol_tx = detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0, true, false); + double phase_crosspol_tx = detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0, true, true); + if (n > 0) { - ApplyAntFactors_Tdomain( - detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0), - heff_Tx, Pol_vector, 0, Pol_factor, V_forfft[2 *n], V_forfft[2 *n + 1], - settings, Tx_theta, Tx_phi, freq_tmp, true); + ApplyAntFactors_Tdomain(phase_copol_tx, phase_crosspol_tx, heff_Tx_copol, heff_Tx_crosspol, Pol_vector, 0, Pol_factor, + V_forfft[2 * n], V_forfft[2 * n + 1], settings, Tx_theta, Tx_phi, freq_tmp, true, false); } else { ApplyAntFactors_Tdomain_FirstTwo( - heff_Tx, heff_Tx_lastbin, Pol_vector, 0, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], settings, Tx_theta, Tx_phi, freq_tmp, true); + heff_Tx_copol, heff_Tx_copol_lastbin, heff_Tx_crosspol, heff_Tx_crosspol_lastbin, Pol_vector, 0, + Pol_factor, V_forfft[2 * n], V_forfft[2 * n + 1], settings, Tx_theta, Tx_phi, freq_tmp, true, false); } } else if (event->IsCalpulser > 0){ - // apply ant factors (transmitter ant) - heff = GaintoHeight( + + // Co-pol effective height + double heff_Tx_copol = GaintoHeight( detector->GetGain_1D_OutZero( - freq_tmp *1.E-6, // to MHz - Tx_theta, antenna_phi, antenna_d->type, j, k), + freq_tmp * 1.E-6, Tx_theta, antenna_phi, antenna_d->type, j, k, false, false), freq_tmp, icemodel->GetN(event->Nu_Interaction[interaction_idx].posnu)); + + // Cross-pol effective height + double heff_Tx_crosspol = GaintoHeight( + detector->GetGain_1D_OutZero( + freq_tmp * 1.E-6, + Tx_theta, antenna_phi, antenna_d->type, j, k, false, true), + freq_tmp, icemodel->GetN(event->Nu_Interaction[interaction_idx].posnu)); + + // Retrieve co-pol and cross-pol phases + double phase_copol_tx = detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, antenna_phi, antenna_d->type, true, false); + double phase_crosspol_tx = detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, antenna_phi, antenna_d->type, true, true); if (n > 0) { - ApplyAntFactors_Tdomain( - detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, antenna_phi, antenna_d->type), - heff, Pol_vector, antenna_d->type, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], settings, true, antenna_theta, antenna_phi, freq_tmp); + ApplyAntFactors_Tdomain(phase_copol_tx, phase_crosspol_tx, heff_Tx_copol, heff_Tx_crosspol, Pol_vector, antenna_d->type, Pol_factor, + V_forfft[2 * n], V_forfft[2 * n + 1], settings, Tx_theta, Tx_phi, freq_tmp, true, false); } else { ApplyAntFactors_Tdomain_FirstTwo( - heff, heff_Tx_lastbin, Pol_vector, antenna_d->type, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], settings, antenna_theta, antenna_phi, freq_tmp); + heff_Tx_copol, heff_Tx_copol_lastbin, heff_Tx_crosspol, heff_Tx_crosspol_lastbin, Pol_vector, antenna_d->type, Pol_factor, + V_forfft[2 * n], V_forfft[2 * n + 1], settings, Tx_theta, Tx_phi, freq_tmp, true, false); } } + double phase_copol = detector->GetAntPhase_1D(freq_tmp * 1.e-6, antenna_theta, antenna_phi, + antenna_d->type, false, false); + double phase_crosspol = detector->GetAntPhase_1D(freq_tmp * 1.e-6, antenna_theta, antenna_phi, + antenna_d->type, false, true); + // apply ant factors if (n > 0) { - ApplyAntFactors_Tdomain( - detector->GetAntPhase_1D(freq_tmp *1.e-6, antenna_theta, antenna_phi, antenna_d->type), - heff, Pol_vector, antenna_d->type, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], settings, antenna_theta, antenna_phi, freq_tmp); + ApplyAntFactors_Tdomain(phase_copol, phase_crosspol, heff_copol, heff_crosspol, Pol_vector, antenna_d->type, Pol_factor, + V_forfft[2 * n], V_forfft[2 * n + 1], settings, antenna_theta, antenna_phi, freq_tmp); } else { - ApplyAntFactors_Tdomain_FirstTwo( - heff, heff_lastbin, Pol_vector, antenna_d->type, Pol_factor, - V_forfft[2 *n], V_forfft[2 *n + 1], settings, antenna_theta, antenna_phi, freq_tmp); + ApplyAntFactors_Tdomain_FirstTwo(heff_copol, heff_copol_lastbin, heff_crosspol, heff_crosspol_lastbin, Pol_vector, antenna_d->type, Pol_factor, + V_forfft[2 * n], V_forfft[2 * n + 1], settings, antenna_theta, antenna_phi, freq_tmp); } // apply entire elect chain gain, phase diff --git a/Report.h b/Report.h index 87ecce29..2e64a94c 100644 --- a/Report.h +++ b/Report.h @@ -78,8 +78,8 @@ class Antenna_r { vector < vector < vector > > vmmhz; //! // signal V/m/MHz for each freq bin vector < vector < vector > > Heff; //! // effective height for each freq bin - vector < vector > Heff_copol; // effective height for each freq bin - vector < vector > Heff_crosspol; // effective height for each freq bin + vector < vector < vector > > Heff_copol; // effective height for each freq bin + vector < vector < vector > > Heff_crosspol; // effective height for each freq bin vector < vector > Mag; //! // magnification factor vector < vector > Fresnel; //! // Fresnel factor vector < vector > Pol_factor; //! // Polarization factor From c9b7be58733cdba89060deb0e6dd25c0d33b66de Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Thu, 10 Jul 2025 16:33:43 -0500 Subject: [PATCH 10/12] Now completely functional for all EVENT TYPES. I need to test crosspol only. --- Detector.cc | 36 ++++++++++++++++++------------------ Detector.h | 2 ++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Detector.cc b/Detector.cc index 7cdf7db0..70c1031b 100644 --- a/Detector.cc +++ b/Detector.cc @@ -2409,19 +2409,19 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt transAnt_databin = &transH_databin; break; case(eVPolCross): // Cross-pol VPol - freq = &Freq; + freq = &FreqCross; gain = &VgainCross; phase = &VphaseCross; transAnt_databin = &transVCross_databin; break; case(eVPolTopCross): // Cross-pol VPol Top - freq = &Freq; + freq = &FreqCross; gain = &VgainTopCross; phase = &VphaseTopCross; transAnt_databin = &transVTopCross_databin; break; case(eHPolCross): // Cross-pol HPol - freq = &Freq; + freq = &FreqCross; gain = &HgainCross; phase = &HphaseCross; transAnt_databin = &transHCross_databin; @@ -2432,7 +2432,7 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt phase = &Txphase; break; case(eTxCross): - freq = &TxFreq; + freq = &TxFreqCross; gain = &TxgainCross; phase = &TxphaseCross; break; @@ -2450,7 +2450,7 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt gain->clear(); phase->clear(); - if(freq_step == -1 || type == eTx) { // only reset if it hasn't been read-in yet + if(freq_step == -1 || type == eTx || type == eVPolCross || type == eVPolTopCross || type == eHPolCross || eTxCross) { // only reset if it hasn't been read-in yet freq->clear(); } @@ -2489,10 +2489,12 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt throw runtime_error("Non-finite frequency value found! "+filename); } - if(freq_step == -1 || type == eTx) { // add frequency if this is the first read-in + if(freq_step == -1 || type == eTx || type == eVPolCross || type == eVPolTopCross || type == eHPolCross || eTxCross ) { // add frequency if this is the first read-in freq->push_back(thisFreq); + } else { // otherwise make sure it matches the values already stored + int i = (int)Transm.size(); if(abs(freq->at(i)-thisFreq) > 0.1 ) { // ensure they match to at least 0.1 MHz @@ -2533,7 +2535,6 @@ inline void Detector::ReadAntennaGain(string filename, Settings *settings1, EAnt phase->push_back(vector()); } // end frequency/header read in - // otherwise we are reading in theta/phi values for a specific frequency else { @@ -3030,7 +3031,6 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int The purpose of this function is to interpolate the globally defined gain arrays (Vgain, VgainTop, Hgain, Txgain) to match the frequency binning dictated by NFOUR in the setup file. */ - //Initialize pointer to dynamically point to the gain for chosen antenna. The structure of this pointer matches that of the global gain arrays defined in Detector.h. vector > *tempGain = nullptr; @@ -3083,13 +3083,12 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int double thisFreq_init; double thisFreq_width; - if(useInTransmitterMode) { - F = &TxFreq; + if (useInTransmitterMode) { + F = useCrossPol ? &TxFreqCross : &TxFreq; thisFreq_init = Tx_freq_init; thisFreq_width = Tx_freq_width; - } - else { - F = &Freq; + } else { + F = useCrossPol ? &FreqCross : &Freq; thisFreq_init = freq_init; thisFreq_width = freq_width; } @@ -3116,7 +3115,9 @@ double Detector::GetGain_1D_OutZero( double freq, double theta, double phi, int // if freq is lower than freq_init if ( freq < thisFreq_init ) { + Gout = slope_1 * (freq - F->at(0)) + (*tempGain)[0][angle_bin]; + } // if freq is higher than last freq else if ( freq > F->back() ) { @@ -3219,13 +3220,12 @@ double Detector::GetAntPhase_1D( double freq, double theta, double phi, int ant_ double thisFreq_init; double thisFreq_width; int thisFreq_step; - if(useInTransmitterMode) { - F = &TxFreq; + if (useInTransmitterMode) { + F = useCrossPol ? &TxFreqCross : &TxFreq; thisFreq_init = Tx_freq_init; thisFreq_width = Tx_freq_width; - } - else { - F = &Freq; + } else { + F = useCrossPol ? &FreqCross : &Freq; thisFreq_init = freq_init; thisFreq_width = freq_width; } diff --git a/Detector.h b/Detector.h index 6a9c620b..ff71f02f 100644 --- a/Detector.h +++ b/Detector.h @@ -238,6 +238,7 @@ class Detector { vector > Hgain; vector > Hphase; vector Freq; + vector FreqCross; // Cross-pol vectors vector > VgainCross; @@ -262,6 +263,7 @@ class Detector { double Tx_freq_init; double Tx_freq_width; vector TxFreq; + vector TxFreqCross; vector > Txgain; vector > Txphase; vector > TxgainCross; From 3041863a301fe28073b1b23feca043da0f2656f7 Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Fri, 11 Jul 2025 14:08:55 -0500 Subject: [PATCH 11/12] Fixing waveform for EVENT_TYPE == 12 --- Report.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Report.cc b/Report.cc index 590e8805..0420dd03 100644 --- a/Report.cc +++ b/Report.cc @@ -1327,8 +1327,13 @@ void Report::ModelRay( fresnel, Pol_vector); // input src Pol and return Pol at trg + std::vector scaled_waveform; + scaled_waveform.reserve(signal->InputVoltage_V.size()); + for (const auto& v : signal->InputVoltage_V) + scaled_waveform.push_back(v * 1e-3); + PropagateSignal( - dT_forfft, waveform_bin, signal->InputVoltage_T, signal->InputVoltage_V, T_forint, + dT_forfft, waveform_bin, signal->InputVoltage_T, scaled_waveform, T_forint, interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, From 7a744b044b25b216df5eb98991b8611a1c6c7671 Mon Sep 17 00:00:00 2001 From: Alan Salcedo Gomez Date: Fri, 18 Jul 2025 21:14:34 -0400 Subject: [PATCH 12/12] Fix order for pulser propagation, and fixing amplitudes --- Report.cc | 62 +++++++++++++++++++++++++++++++++---------------------- Report.h | 4 ++-- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/Report.cc b/Report.cc index 0420dd03..c95518b8 100644 --- a/Report.cc +++ b/Report.cc @@ -1184,7 +1184,7 @@ void Report::ModelRay( PropagateSignal( dT_forfft, outbin, Tarray_vector, Earray_vector, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, receive_vector, fresnel, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); @@ -1233,7 +1233,7 @@ void Report::ModelRay( PropagateSignal( dT_forfft, waveform_bin, ArbitraryWaveform_T_vector, ArbitraryWaveform_V_vector, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, receive_vector, fresnel, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); @@ -1282,7 +1282,7 @@ void Report::ModelRay( ); PropagateSignal( dT_forfft, waveform_bin, signal->PulserWaveform_T, signal->PulserWaveform_V, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, receive_vector, fresnel, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); @@ -1315,18 +1315,6 @@ void Report::ModelRay( double newPol_vectorZ = cos(psi)*sin(theta); Vector Pol_vector = Vector(newPol_vectorX, newPol_vectorY, newPol_vectorZ); - //Apply Fresnel factors for magnification and 1/r dependence - icemodel->GetFresnel( - ray_output[1][ray_idx], // launch_angle - ray_output[2][ray_idx], // rec_angle - ray_output[3][ray_idx], // reflect_angle - event->Nu_Interaction[interaction_idx].posnu, - launch_vector, - receive_vector, - settings, - fresnel, - Pol_vector); // input src Pol and return Pol at trg - std::vector scaled_waveform; scaled_waveform.reserve(signal->InputVoltage_V.size()); for (const auto& v : signal->InputVoltage_V) @@ -1334,7 +1322,7 @@ void Report::ModelRay( PropagateSignal( dT_forfft, waveform_bin, signal->InputVoltage_T, scaled_waveform, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, receive_vector, fresnel, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); @@ -1357,7 +1345,7 @@ void Report::ModelRay( PropagateSignal( dT_forfft, CP_bin, detector->CalPulserWF_ns, detector->CalPulserWF_V, T_forint, - interaction_idx, ray_idx, ray_output, launch_vector, time_diff_birefringence, + interaction_idx, ray_idx, ray_output, launch_vector, receive_vector, fresnel, time_diff_birefringence, Pol_vector_src, Pol_vector, n_trg_slappy, n_trg_pokey, antenna_r, antenna_d, gain_ch_no, j, k, birefringence, detector, event, icemodel, settings); @@ -1495,8 +1483,8 @@ void Report::DetermineWFBins( void Report::PropagateSignal( double dT_forfft, int efield_length, vector< double > efield_time, vector< double > efield, double *T_forint, - int interaction_idx, int ray_idx, vector > ray_output, Position launch_vector, double time_diff_birefringence, - Vector Pol_vector_src, Vector Pol_vector, Vector n_trg_slappy, Vector n_trg_pokey, + int interaction_idx, int ray_idx, vector > ray_output, Position launch_vector, Position receive_vector, double fresnel, + double time_diff_birefringence, Vector Pol_vector_src, Vector Pol_vector, Vector n_trg_slappy, Vector n_trg_pokey, Antenna_r *antenna_r, Antenna *antenna_d, int gain_ch_no, int j, int k, Birefringence *birefringence, Detector *detector, Event *event, IceModel *icemodel, Settings *settings ){ @@ -1713,8 +1701,8 @@ void Report::PropagateSignal( detector->GetImpedance(freq_tmp*1.E-6, 0, 0, true)); // Retrieve co-pol and cross-pol phases - double phase_copol_tx = detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0, true, false); - double phase_crosspol_tx = detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0, true, true); + double phase_copol_tx = detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0, false, false); //ASG change when fixing phases + double phase_crosspol_tx = detector->GetAntPhase_1D(freq_tmp *1.e-6, Tx_theta, Tx_phi, 0, false, true); //ASG change when fixing phases if (n > 0) { ApplyAntFactors_Tdomain(phase_copol_tx, phase_crosspol_tx, heff_Tx_copol, heff_Tx_crosspol, Pol_vector, 0, Pol_factor, @@ -1725,6 +1713,18 @@ void Report::PropagateSignal( heff_Tx_copol, heff_Tx_copol_lastbin, heff_Tx_crosspol, heff_Tx_crosspol_lastbin, Pol_vector, 0, Pol_factor, V_forfft[2 * n], V_forfft[2 * n + 1], settings, Tx_theta, Tx_phi, freq_tmp, true, false); } + + //Apply Fresnel factors for magnification and 1/r dependence + icemodel->GetFresnel( + ray_output[1][ray_idx], // launch_angle + ray_output[2][ray_idx], // rec_angle + ray_output[3][ray_idx], // reflect_angle + event->Nu_Interaction[interaction_idx].posnu, + launch_vector, + receive_vector, + settings, + fresnel, + Pol_vector); // input src Pol and return Pol at trg } else if (event->IsCalpulser > 0){ @@ -1754,6 +1754,18 @@ void Report::PropagateSignal( heff_Tx_copol, heff_Tx_copol_lastbin, heff_Tx_crosspol, heff_Tx_crosspol_lastbin, Pol_vector, antenna_d->type, Pol_factor, V_forfft[2 * n], V_forfft[2 * n + 1], settings, Tx_theta, Tx_phi, freq_tmp, true, false); } + + //Apply Fresnel factors for magnification and 1/r dependence + icemodel->GetFresnel( + ray_output[1][ray_idx], // launch_angle + ray_output[2][ray_idx], // rec_angle + ray_output[3][ray_idx], // reflect_angle + event->Nu_Interaction[interaction_idx].posnu, + launch_vector, + receive_vector, + settings, + fresnel, + Pol_vector); // input src Pol and return Pol at trg } double phase_copol = detector->GetAntPhase_1D(freq_tmp * 1.e-6, antenna_theta, antenna_phi, @@ -3589,13 +3601,13 @@ void Report::ApplyAntFactors_Tdomain(double phase_copol, double phase_crosspol, //If in transmitter mode, we must apply additional frequency and impedance terms to the amplitude. if (useInTransmitterMode==true){ phase_current += PI/2; - double psi = settings1->CLOCK_ANGLE; + double psi = 0.0; double delta_psi = TMath::ATan(heff_crosspol / heff_copol); // Tx cross-pol tilt - double theta = antenna_theta*PI/180; - double phi = antenna_phi*PI/180; + double theta = antenna_theta*PI/180.0; + double phi = antenna_phi*PI/180.0; //turn on cross-pol Tx - if (settings1->CROSSPOL_TX != 1){ + if (settings1->CROSSPOL_TX == 0){ heff_crosspol = 0.0; //need to be turned off for the calculation of amplitude v_amp delta_psi = 0.0; // turn off cross-pol tx tilt } diff --git a/Report.h b/Report.h index 2e64a94c..713dc68f 100644 --- a/Report.h +++ b/Report.h @@ -259,8 +259,8 @@ class Report { IceModel *icemodel, Settings *settings1 ); void PropagateSignal( double dT_forfft, int efield_length, vector< double > efield_time, vector< double > efield, double *T_forint, - int interaction_idx, int ray_idx, vector > ray_output, Position launch_vector, double time_diff_birefringence, - Vector Pol_vector_src, Vector Pol_vector, Vector n_trg_slappy, Vector n_trg_pokey, + int interaction_idx, int ray_idx, vector > ray_output, Position launch_vector, Position receive_vector, double fresnel, + double time_diff_birefringence, Vector Pol_vector_src, Vector Pol_vector, Vector n_trg_slappy, Vector n_trg_pokey, Antenna_r *antenna_r, Antenna *antenna_d, int gain_ch_no, int j, int k, Birefringence *birefringence, Detector *detector, Event *event, IceModel *icemodel, Settings *settings);