testThermalNoise.cc
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <math.h>
5 #include <ctype.h>
6 #include <string>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <vector>
10 #include <array>
11 #include <time.h>
12 #include "TTreeIndex.h"
13 #include "TChain.h"
14 #include "TH1.h"
15 #include "TF1.h"
16 #include "TF2.h"
17 #include "TFile.h"
18 #include "icemc_random.h"
19 #include "TTree.h"
20 #include "TLegend.h"
21 #include "TLine.h"
22 #include "TROOT.h"
23 #include "TPostScript.h"
24 #include "TCanvas.h"
25 #include "TH2F.h"
26 #include "TText.h"
27 #include "TProfile.h"
28 #include "TGraphErrors.h"
29 #include "TGraphAsymmErrors.h"
30 #include "TStyle.h"
31 #include "TMath.h"
32 #include <unistd.h>
33 #include "TVector3.h"
34 #include "TRotation.h"
35 #include "TSpline.h"
36 #include "Math/InterpolationTypes.h"
37 #include "Math/Interpolator.h"
38 #include "signal.h"
39 
40 //#include "rx.hpp"
41 #include "Constants.h"
42 #include "Settings.h"
43 #include "position.hh"
44 
45 #include "earthmodel.hh"
46 #include "Tools.h"
47 #include "vector.hh"
48 #include "roughness.hh"
49 #include "anita.hh"
50 #include "balloon.hh"
51 #include "icemodel.hh"
52 // #include "trigger.hh"
53 #include "Spectra.h"
54 #include "signal.hh"
55 #include "secondaries.hh"
56 #include "ray.hh"
57 #include "counting.hh"
58 #include "Primaries.h"
59 #include "Taumodel.hh"
60 #include "screen.hh"
61 #include "GlobalTrigger.h"
62 #include "ChanTrigger.h"
63 #include "SimulatedSignal.h"
64 #include "EnvironmentVariable.h"
65 
66 #include <string>
67 #include <sstream>
68 
69 #if __cplusplus > 199711L
70 #include <type_traits>
71 #endif
72 
73 #include <typeinfo>
74 
75 #ifdef ANITA_UTIL_EXISTS
76 #include "UsefulAnitaEvent.h"
77 #include "AnitaGeomTool.h"
78 #include "AnitaConventions.h"
79 #include "RawAnitaHeader.h"
80 #include "Adu5Pat.h"
81 #include "FFTtools.h"
82 UsefulAnitaEvent* realEvPtr = NULL;
83 RawAnitaHeader* rawHeaderPtr = NULL;
84 Adu5Pat* Adu5PatPtr = NULL;
85 #ifdef ANITA3_EVENTREADER
86 #include "TruthAnitaEvent.h"
87 TruthAnitaEvent* truthEvPtr = NULL;
88 #endif
89 #endif
90 
91 Taumodel* TauPtr = NULL;
92 
93 const string ICEMC_SRC_DIR = EnvironmentVariable::ICEMC_SRC_DIR();
94 
95 ClassImp(RX);
96 
97 using namespace std;
98 
99 class EarthModel;
100 class Position;
101 
102 /************MOVED FROM shared.hh and shared.cc*****************/
103 // These need to be moved elsewhere.
104 // They were all global variables inside of shared.hh.
105 // Most of these should not be global variables.
106 const int NVIEWANGLE=100; // number of viewing angles to look at the signal, on Seckel's request
107 // int irays; // counts rays (for roughness) // LC: commented out because not used
108 
109 int inu; // counts neutrinos as they are generated
110 UInt_t eventNumber;
111 double eventsfound_beforetrigger=0.;
112 double eventsfound_crust=0; //number of events that only traverse the crust
113 double eventsfound_weightgt01=0; // summing weights > 0.1
114 double eventsfound_belowhorizon=0; // how many are below horizon
115 double eventsfound=0; // how many events found
116 double eventsfound_prob=0; // how many events found, probabilities
117 double sum[3]; // sum of weight for events found for 3 flavors
118 // These numbers are from Feldman and Cousins wonderful paper: physics/9711021
119 double poissonerror_minus[21] = {0.-0.00, 1.-0.37, 2.-0.74, 3.-1.10, 4.-2.34, 5.-2.75, 6.-3.82, 7.-4.25, 8.-5.30, 9.-6.33, 10.-6.78, 11.-7.81, 12.-8.83, 13.-9.28, 14.-10.30, 15.-11.32, 16.-12.33, 17.-12.79, 18.-13.81, 19.-14.82, 20.-15.83};
120 double poissonerror_plus[21] = {1.29-0., 2.75-1., 4.25-2., 5.30-3., 6.78-4., 7.81-5., 9.28-6., 10.30-7., 11.32-8., 12.79-9., 13.81-10., 14.82-11., 16.29-12., 17.30-13., 18.32-14., 19.32-15., 20.80-16., 21.81-17., 22.82-18., 23.82-19., 25.30-20.};
121 const int NBINS=10; // keep track of the number of events found, binned
122 // by weights
123 double MIN_LOGWEIGHT=-3;
124 double MAX_LOGWEIGHT=-1;
125 int index_weights=0; // which bin the weight falls into
126 double eventsfound_binned[NBINS];
127 double eventsfound_binned_e[NBINS];
128 double eventsfound_binned_mu[NBINS];
129 double eventsfound_binned_tau[NBINS];
130 double km3sr = 0; // total km3sr
131 double km3sr_e=0; // to calculate km3sr for electrons
132 double km3sr_mu=0; // to calculate km3sr for muons
133 double km3sr_tau=0; // to calculate km3sr for taus
134 double error_plus=0; // keeping track of asymmetric error bars
135 double error_e_plus=0;
136 double error_mu_plus=0;
137 double error_tau_plus=0;
138 double error_minus=0;
139 double error_e_minus=0;
140 double error_mu_minus=0;
141 double error_tau_minus=0;
142 int ierr=0; // integer for returning error from functions.
143 double gain_dipole=2.15; // antenna gain (nominal value for dipole is 2.15)
144 double changle_deg=0; // same, in degrees.
145 // inputs
146 int NNU; // number of neutrinos
147 int whichray=0; // indexes the rays that we look at (actually just used for ice but we use it in GetNuFlavor so keep it here)
148 double RANDOMISEPOL=0.;
149 /************MOVED FROM shared.hh and shared.cc*****************/
150 
151 
152 double volume_thishorizon; // for plotting volume within the horizon of the balloon
153 int realtime_this; // for plotting real unix time
154 double longitude_this; // for plotting longitude
155 double latitude_this; // for plotting latitude
156 double altitude_this; // for plotting altitude
157 double heading_this=0.;// for plotting heading
158 double gps_offset=0;
159 
160 // inputs
161 
162 double pnu=pow(10., 20);
163 
164 double MEANX=0;
165 double MEANY=0.;
166 
167 double SIGNALRADIUS=2.; // in degrees
168 
169 
170 double bwslice_vnoise_thislayer[4];// for filling tree6b, noise for each bandwidth on each layer
171 int passes_thisevent=0; // this event passes
172 int unmasked_thisevent=0; // this event is unmasked
173 
174 int discones_passing; // number of discones that pass
175 int NDISCONES=8;
176 double heff_discone=0; // effective height of a discone antenna
177 double polarfactor_discone=0.;// factor to account for antenna beam pattern.
178 double thislambda=0;// for finding wavelength at each frequency
179 double volts_discone=0.;// for finding voltage at each discone
180 double vnoise_discone=0.; // noise on each discone
181 
182 
183 double BW_DISCONES=300.E6-120.E6; // bandwidth of the discones
184 
185 // ray tracing
186 double fresnel1=0;
187 double fresnel1_eachboresight[Anita::NLAYERS_MAX][Anita::NPHI_MAX]; // for slac simulation
188 double fresnel2=0;
189 double mag1=0; // magnification factor on field at ice-firn interface
190 double mag1_eachboresight[Anita::NLAYERS_MAX][Anita::NPHI_MAX];// for slac simulation
191 double mag2=0; // magnification factor on field in firn-air
192 double t_coeff_pokey, t_coeff_slappy;
193 double rflength=0; // distance from interaction to ice-air exit point
194 
195 double e_comp_max1=0;
196 double h_comp_max1=0;
197 double e_comp_max2=0;
198 double h_comp_max2=0;
199 double e_comp_max3=0;
200 double h_comp_max3=0;
201 
202 double diffexit=0; // checking exit point between_MAX interations
203 double diff_3tries=0;
204 double diffnorm=0; // checking angle of surf normal between iterations
205 double diffrefr=0; // checking angle of refr between iterations
206 double costheta_inc=0; // cos angle of incidence wrt surface normal
207 double costheta_exit=0; // theta of exit point wrt earth (costheta=1 at south pole)
208 double theta_rf_atbn; // polar angle of the signal as seen by perfect eyes at the balloon.
209 double theta_rf_atbn_measured; //polar angle of the signal as measured at the balloon (just the above variable smeared by 0.5 degrees)
210 
211 double costhetanu=-1000; // costheta of neutrino direction wrt earth (costheta=1 at south pole)
212 
213 // neutrino path
214 double theta_in=0; // theta where neutrino enters earth (radians, south pole=0)
215 double lat_in=0; // latitude where neutrino enters earth (degrees, south pole=-90)
216 double nearthlayers=0; // how many layers (core, mantle, crust) does nnu traverse
217 double weight_prob=0.;//event weight, including probability it interacts somewhere in ice along its path
218 double weight1=0; // event weight, just based on absorption in earth, see note
219 double weight=0.; // total event weight (product of the previous 2)
220 double logweight=0.;// log of the previous number
221 double len_int=0;// interaction length in m
222 double pieceofkm2sr=0; // Use this for making plots comparing different cross sections. The integral of a plot from a run will be the total Area*sr of the detector. That way it is proportional to the cross section and the integral is something meaningful to people.
223 
224 double CUTONWEIGHTS=1.E-10; // cut out events with small enough weight that they don't matter, to save time
225 
226 // counting variables
227 int count_inthisloop1=0; // for debugging
228 int count_inthisloop2=0;
229 int count_inthisloop3=0;
230 double averaging_thetas1=0; // for debugging
231 double averaging_thetas2=0;
232 double averaging_thetas3=0;
233 int count_total=0; // number of neutrinos looped over. should always equal inu
234 
235 // i.e., is theoretically visible by balloon
236 
237 int count_asktrigger=0;
238 int count_asktrigger_nfb=0;
239 int count_pass=0; // how many total trigger channels pass (4 bandwidth slices*2 pol * nrx)
240 
241 double count_passestrigger_w=0; // same as above, but sum weights
242 int passestrigger=0; // 1=this event passes trigger, 0=does not
243 // so that we know to increment count_passestrigger_w at the end of the event
244 int allcuts[2]={0, 0}; // index is which ray (upward or downward)
245 // 1=this ray for this event passes all cuts, 0=does not
246 double allcuts_weighted[2]={0, 0}; // same as above but weighted
247 double allcuts_weighted_polarization[3]={0, 0, 0}; // same as above but divided into [0] vpol, [1] hpol, [2] both vpol and hpol
248 
249 
250 //signal has a chance to pass after accounting for 1/r
251 int count_chanceofsurviving=0; // based on neutrino direction, has a chance of making it through earth.
252 
253 int count_chanceinhell0=0; // based on 1/r, and best case attenuation
254 // (after 2nd guess at rf exit point)
255 // signal has a chance of passing
256 
257 double count_chanceinhell2_w=0; //same as above, but sum weights
258 int chanceinhell2=0; // 1=this event has chance to pass, 0=does not-
259 // so that we know to increment count_chanceinhell2_w by weight1 at the end.
260 
261 int count_chordgoodlength=0; // Incremented if neutrino path through earth is more than 1m
262 int count_d2goodlength=0; // neutrino path through ice is more than 1m
263 int count_rx=0; // counting antennas we loop through them
264 
265 double sum_frac[3]; // fraction of passing events that are e, mu, tau adding weights
266 double sum_frac_db[3]; // same for double bangs
267 
268 const int NBINS_DISTANCE=28; // keep track of number that pass as a function of distance to make Peter's plot
269 double eventsfound_binned_distance[NBINS_DISTANCE] = {0.}; // binning cumulative events found vs. distance
270 int index_distance=0; // index for filling array above
271 double km3sr_distance[NBINS_DISTANCE] = {0.}; // result of conversion of events to sensitivity
272 double error_distance_plus[NBINS_DISTANCE] = {0.}; // errors on above
273 double error_distance_minus[NBINS_DISTANCE] = {0.};
274 int eventsfound_binned_distance_forerror[NBINS_DISTANCE][NBINS] = {{0}}; // for propagation of errors
275 
276 //taus
277 double km3sr_db = 0;
278 double km3sr_nfb=0;
279 double ptau=0;
280 int count_passestrigger_nfb=0;
281 double percent_increase_db=0;
282 double percent_increase_nfb=0;
283 double percent_increase_total=0;
284 double error_nfb=0;
285 double error_km3sr_nfb=0;
286 double error_percent_increase_nfb=0;
287 
288 Vector n_exit2bn_db[5];
289 Vector nrf_iceside_db[5]; // direction of rf [tries][3d]
290 double n_exit_phi; //phi angle of the ray from the surface to the balloon
291 int count_dbexitsice=0;
292 
293 // int count_interacts_in_earth=0;
294 double eventsfound_nfb_binned[NBINS]; // counting events without first bang
295 
296 // rf parameters
297 double heff_max=0.62639; // maximum value of the effective height based on antenna specs
298 
299 // event geometry
300 double scalefactor_distance=0; // 1/r scalefactor
301 double scalefactor_attenuation=0; //scalefactor due to attenuation in ice
302 double MAX_ATTENLENGTH=1671;
303 double maxtaper=0; // this is just for plotting - maximum you are ever off cerenkov cone while
304 //an event is detectable
305 double dviewangle_deg=0;
306 
307 double forseckel[NVIEWANGLE][Anita::NFREQ];// Per Seckel's request, get strength of signal across frequencies for different viewing angles.
308 double viewangles[NVIEWANGLE];
309 double GetAirDistance(double altitude_bn, double beta); // given beta=angle wrt horizontal that the ray hits the balloon, calculate distance that the ray traveled in air, including curvature of earth
310 
311 //Input files
312 int err=0; // errors from GetDirection function
313 
314 double djunk; // junk variable
315 
316 //For verification plots - added by Stephen
317 int max_antenna0 = -1; //antenna with the peak voltage, top layer
318 int max_antenna1 = -1; //antenna with the peak voltage, middle layer
319 int max_antenna2 = -1; //antenna with the peak voltage, bottom layer
320 double max_antenna_volts0 = 0; //Voltage on the antenna with maximum signal, top layer
321 double max_antenna_volts0_em = 0; //Component of voltage from em shower on the antenna with maximum signal, top layer
322 
323 double max_antenna_volts1 = 0; //Voltage on the antenna with maximum signal, middle layer
324 double max_antenna_volts2 = 0; //Voltage on the antenna with maximum signal, bottom layer
325 
326 double rx0_signal_eachband[2][5];
327 double rx0_threshold_eachband[2][5];
328 double rx0_noise_eachband[2][5];
329 int rx0_passes_eachband[2][5];
330 
331 double voltagearray[Anita::NLAYERS_MAX*Anita::NPHI_MAX]; //Records max voltages on each antenna for one neutrino
332 
333 Vector ant_max_normal0; //Vector normal to the face of the antenna with the maximum signal for a single neutrino, top layer
334 Vector ant_max_normal1; //Vector normal to the face of the antenna with the maximum signal for a single neutrino, middle layer
335 Vector ant_max_normal2; //Vector normal to the face of the antenna with the maximum signal for a single neutrino, bottom layer
336 double vmmhz1m_visible = 0; //Actual V/m/Mhz at 1m
337 int freq_bins = Anita::NFREQ; //Because the compiler objected to using the const directly
338 double total_kgm2 = 0; // output of Getchord
339 double nnu_array[3];
340 double r_in_array[3];
341 double nsurf_rfexit_array[3];
342 double nsurf_rfexit_db_array[3];
343 double r_bn_array[3];
344 double n_bn_array[3];
345 double posnu_array[3];
346 double nrf_iceside_array[5][3];
347 double nrf_iceside_db_array[5][3];
348 double ant_max_normal0_array[3];
349 double ant_max_normal1_array[3];
350 double ant_max_normal2_array[3];
351 double n_pol_array[3];
352 double n_exit2bn_array[5][3];
353 double r_enterice_array[3];
354 double n_exit2bn_db_array[5][3];
355 double rfexit_array[5][3];
356 double rfexit_db_array[5][3];
357 
358 int times_crust_entered_det=0; //Counter for total times each Earth layer is entered for detected neutrinos only
359 int times_mantle_entered_det=0;
360 int times_core_entered_det=0;
361 int crust_entered=0;
362 int mantle_entered=0;
363 int core_entered=0;
364 int neutrinos_passing_all_cuts=0;
365 double sum_weights=0;
366 //End verification plot block
367 
368 
369 
370 double justNoise_trig[2][48][512];
371 double justSignal_trig[2][48][512];
372 double justNoise_dig[2][48][512];
373 double justSignal_dig[2][48][512];
374 
375 // functions
376 
377 // set up array of viewing angles for making plots for seckel
378 void SetupViewangles(Signal *sig1);
379 
380 void GetAir(double *col1); // get air column as a function of theta- only important for black hole studies
381 double GetThisAirColumn(Settings*, Position r_in, Vector nnu, Position posnu, double *col1, double& cosalpha, double& mytheta, double& cosbeta0, double& mybeta);
382 
383 double ScaleVmMHz(double vmmhz1m_max, const Position &posnu, const Position &r_bn);
384 
385 
386 double IsItDoubleBang(double exitlength, double plepton);
387 
388 int WhereIsSecondBang(const Position& posnu, const Vector& nnu, double nuexitlength, double pnu, IceModel *antarctica1, const Position& r_bn, Position &posnu2, Position &rfexit_db, Vector &n_exit2bn_db);
389 void GetCurrent(string& current);
390 
391 
392 double GetAverageVoltageFromAntennasHit(Settings *settings1, int *nchannels_perrx_triggered, double *voltagearray, double& volts_rx_sum);
393 
394 
395 Vector GetPolarization(const Vector &nnu, const Vector &nrf2_iceside);
396 
397 void Attenuate(IceModel *antartica1, Settings *settings1, double& vmmhz_max, double rflength, const Position &posnu);
398 
399 void Attenuate_down(IceModel *antarctica1, Settings *settings1, double& vmmhz_max, const Position &rfexit2, const Position &posnu, const Position &posnu_down);
400 
401 void IsAbsorbed(double chord_kgm2, double len_int_kgm2, double& weight);
402 
403 
404 int GetRayIceSide(const Vector &n_exit2rx, const Vector &nsurf_rfexit, double nexit, double nenter, Vector &nrf2_iceside);
405 
406 double GetViewAngle(const Vector &nrf2_iceside, const Vector &nnu);
407 int TIR(const Vector &n_surf, const Vector &nrf2_iceside, double N_IN, double N_OUT);
408 
409 void IntegrateBands(Anita *anita1, int k, Screen *panel1, double *freq, double scalefactor, double *sumsignal);
410 
411 void Integrate(Anita *anita1, int j, int k, double *vmmhz, double *freq, double scalefactor, double sumsignal);
412 
413 void interrupt_signal_handler(int); // This catches the Control-C interrupt, SIGINT
414 
415 bool ABORT_EARLY = false; // This flag is set to true when interrupt_signal_handler() is called
416 
417 void WriteNeutrinoInfo(Position&, Vector&, Position&, double, string, string, double, ofstream &nu_out);
418 
419 void CloseTFile(TFile *hfile);
420 
421 int Getmine(double*, double*, double*, double*);
422 
423 void Getearth(double*, double*, double*, double*);
424 
425 
426 #ifdef ANITA_UTIL_EXISTS
427 int GetIceMCAntfromUsefulEventAnt(Settings *settings1, int UsefulEventAnt);
428 #ifdef R_EARTH
429 #undef R_EARTH
430 #endif
431 #endif
432 
433 
434 double thresholdsAnt[48][2][5];
435 double thresholdsAntPass[48][2][5];
436 
437 
438 //do a threshold scan
439 double threshold_start=-1.;
440 double threshold_end=-6.;
441 const int NTHRESHOLDS=20;
442 double threshold_step=(threshold_end-threshold_start)/(double)NTHRESHOLDS;
443 
444 double npass_v_thresh[NTHRESHOLDS]={0.};
445 double denom_v_thresh[NTHRESHOLDS]={0.};
446 double npass_h_thresh[NTHRESHOLDS]={0.};
447 double denom_h_thresh[NTHRESHOLDS]={0.};
448 double thresholds[NTHRESHOLDS];
449 
450 int main(int argc, char **argv) {
451  //--------------------------------------------------------------
452  // MC Anita
453  //
454  // 12/01/03
455  //
456  //--------------------------------------------------------------
457 
458 
459  // // for comparing with peter
460  // double sumsignal[5]={0.};
461 
462  string stemp;
463 
464  Settings* settings1 = new Settings();
465 
466  string input= ICEMC_SRC_DIR + "/inputs.conf";
467  string run_num;//current run number as string
468  int run_no = 0;//current run number as integer
469  TString outputdir;
470 
471  if( (argc%3!=1)&&(argc%2!=1)) {
472  cout << "Syntax for options: -i inputfile -o outputdir -r run_number\n";
473  return 0;
474  }
475  int nnu_tmp=0;
476  double exp_tmp=0;
477  double trig_thresh=0.;
478  char clswitch; // command line switch
479  if (argc>1) {
480  while ((clswitch = getopt(argc, argv, "t:i:o:r:n:e:")) != EOF) {
481  switch(clswitch) {
482  case 'n':
483  nnu_tmp=atoi(optarg);
484  cout << "Changed number of simulated neutrinos to " << nnu_tmp << endl;
485  break;
486  case 't':
487  trig_thresh=atof(optarg);
488  break;
489  case 'i':
490  input=optarg;
491  cout << "Changed input file to: " << input << endl;
492  break;
493  case 'o':
494  outputdir=optarg;
495  cout << "Changed output directory to: " << string(outputdir.Data()) << endl;
496  stemp="mkdir -p " + string(outputdir.Data());
497  system(stemp.c_str());
498  break;
499  case 'r':
500  run_num=optarg;
501  stringstream convert(run_num);
502  convert>>run_no;
503  break;
504  } // end switch
505  } // end while
506  } // end if arg>1
507 
508 
509  settings1->SEED=settings1->SEED +run_no;
510  cout <<"seed is " << settings1->SEED << endl;
511  setSeed(settings1->SEED);
512 
513 
514  stemp=string(outputdir.Data())+"/nu_position"+run_num+".txt";
515  ofstream nu_out(stemp.c_str(), ios::app); //Positions, direction of momentum, and neutrino type for Ryan.
516 
517  stemp=string(outputdir.Data())+"/veff"+run_num+".txt";
518  ofstream veff_out(stemp.c_str(), ios::app);//to output only energy and effective volume to veff.txt
519 
520  stemp=string(outputdir.Data())+"/distance"+run_num+".txt";
521  ofstream distanceout(stemp.c_str());
522 
523  stemp=string(outputdir.Data())+"/debug"+run_num+".txt";
524  fstream outfile(stemp.c_str(), ios::out);
525 
526  stemp=string(outputdir.Data())+"/forbrian"+run_num+".txt";
527  fstream forbrian(stemp.c_str(), ios::out);
528 
529  stemp=string(outputdir.Data())+"/al_voltages_direct"+run_num+".dat";
530  fstream al_voltages_direct(stemp.c_str(), ios::out); //added djg ------provide anita-lite voltages and noise from MC for anita-lite analysis
531 
532  stemp=string(outputdir.Data())+"/events"+run_num+".txt";
533  ofstream eventsthatpassfile(stemp.c_str());
534 
535  stemp=string(outputdir.Data())+"/numbers"+run_num+".txt";
536  ofstream fnumbers(stemp.c_str()); // debugging
537 
538  stemp=string(outputdir.Data())+"/output"+run_num+".txt";
539  ofstream foutput(stemp.c_str(), ios::app);
540 
541  stemp=string(outputdir.Data())+"/slacviewangles"+run_num+".dat";
542  ofstream fslac_viewangles(stemp.c_str()); // this outputs numbers that we need for analyzing slac data
543 
544  stemp=string(outputdir.Data())+"/slac_hitangles"+run_num+".dat";
545  ofstream fslac_hitangles(stemp.c_str()); // this outputs numbers that we need for analyzing slac data
546 
547  Balloon *bn1=new Balloon(); // instance of the balloon
548  Anita *anita1=new Anita();// right now this constructor gets banding info
549  Secondaries *sec1=new Secondaries();
550  Signal *sig1=new Signal();
551  Ray *ray1=new Ray(); // create new instance of the ray class
552  Counting *count1=new Counting();
553 
554  // input parameters
555  settings1->ReadInputs(input.c_str(), foutput, NNU, RANDOMISEPOL);
556  settings1->ApplyInputs(anita1, sec1, sig1, bn1, ray1);
557  sig1->Initialize();
558 
559  settings1->SEED=settings1->SEED + run_no;
560  setSeed(settings1->SEED);
561 
562  bn1->InitializeBalloon();
563  anita1->Initialize(settings1, foutput, inu, outputdir);
564 
565  if (nnu_tmp!=0)
566  NNU=nnu_tmp;
567  if (exp_tmp!=0)
568  settings1->EXPONENT=exp_tmp;
569 
570  settings1->SIGNAL_FLUCT=1;
571  settings1->ZEROSIGNAL=1;
572 
573  time_t raw_start_time = time(NULL);
574  struct tm * start_time = localtime(&raw_start_time);
575 
576  cout << "Date and time at start of run are: " << asctime (start_time) << "\n";
577 
578  // zeroing global variables.
579  Tools::Zero(sum_frac, 3);
580  Tools::Zero(sum_frac_db, 3);
581  Tools::Zero(anita1->NRX_PHI, Anita::NLAYERS_MAX);
582  for (int i=0;i<Anita::NLAYERS_MAX;i++) {
583  Tools::Zero(anita1->PHI_EACHLAYER[i], Anita::NPHI_MAX);
584  }
585  Tools::Zero(anita1->PHI_OFFSET, Anita::NLAYERS_MAX);
586  Tools::Zero(anita1->THETA_ZENITH, Anita::NLAYERS_MAX);
587  Tools::Zero(anita1->LAYER_VPOSITION, Anita::NLAYERS_MAX);
588  Tools::Zero(anita1->RRX, Anita::NLAYERS_MAX);
589 
590 
591  // frequency binning
592  double vmmhz[Anita::NFREQ]; // V/m/MHz at balloon (after all steps)
593 
594  // given the angle you are off the Cerenkov cone, the fraction of the observed e field that comes from the em shower
595  double vmmhz_em[Anita::NFREQ];
596  double vmmhz_min_thatpasses=1000;
597 
598 
599  string taudecay; // tau decay type: e, m, h
600 
601  double volts_rx_rfcm_lab_e_all[48][512];
602  double volts_rx_rfcm_lab_h_all[48][512];
603 
604  // variable declarations for functions GetEcompHcompEvector and GetEcompHcompkvector - oindree
605  double e_component[Anita::NANTENNAS_MAX]={0}; // E comp along polarization
606  double h_component[Anita::NANTENNAS_MAX]={0}; // H comp along polarization
607  double n_component[Anita::NANTENNAS_MAX]={0}; // normal comp along polarization
608 
609  double e_component_kvector[Anita::NANTENNAS_MAX]={0}; // component of e-field along the rx e-plane
610  double h_component_kvector[Anita::NANTENNAS_MAX]={0}; // component of the e-field along the rx h-plane
611  double n_component_kvector[Anita::NANTENNAS_MAX]={0}; // component of the e-field along the normal
612 
613 
614  // Vector n_eplane = const_z;
615  // Vector n_hplane = -const_y;
616  // Vector n_normal = const_x;
617 
618  Vector ant_normal; //Vector normal to the face of the antenna
619 
620  // double hitangle_e, hitangle_h; // angle the ray hits the antenna wrt e-plane, h-plane
621  double hitangle_e_all[Anita::NANTENNAS_MAX]; // hit angles rel. to e plane stored for each antenna
622  double hitangle_h_all[Anita::NANTENNAS_MAX]; // hit angles rel. to h plane stored for each antenna
623 
624  double eventsfound_db=0; // same, for double bang
625  double eventsfound_nfb=0; // for taus
626 
627 
628  double sourceLon=-999;
629  double sourceAlt=-999;
630  double sourceLat=-999;
631 
632  Vector n_nutraject_ontheground; //direction of the neutrino from the person standing on the ground just below the balloon.
633  Vector n_pol; // direction of polarization
634  // Vector n_pol_eachboresight[Anita::NLAYERS_MAX][Anita::NPHI_MAX]; // direction of polarization of signal seen at each antenna
635  Vector n_pol_db; // same, double bangs
636 
637  int l3trig[Anita::NPOL]; // 16 bit number which says which phi sectors pass L3 V-POL
638  // For each trigger layer, which "clumps" pass L2. 16 bit, 16 bit and 8 bit for layers 1 & 2 and nadirs
639  int l2trig[Anita::NPOL][Anita::NTRIGGERLAYERS_MAX];
640  //For each trigger layer, which antennas pass L1. 16 bit, 16 bit and 8 bit and layers 1, 2 and nadirs
641  int l1trig[Anita::NPOL][Anita::NTRIGGERLAYERS_MAX];
642 
643 
644 
645  eventsfound=0.; // sums weights for events that pass
646 
647  Tools::Zero(count1->npass, 2); // sums events that pass, without weights
648  Tools::Zero(sum, 3);
649  eventsfound_db=0;
650  eventsfound_nfb=0;
651 
652  Tools::Zero(eventsfound_binned, NBINS);
653  Tools::Zero(eventsfound_binned_e, NBINS);
654  Tools::Zero(eventsfound_binned_mu, NBINS);
655  Tools::Zero(eventsfound_binned_tau, NBINS);
656  Tools::Zero(eventsfound_nfb_binned, NBINS);
657 
658 
659  Tools::Zero(anita1->arrival_times[0], Anita::NLAYERS_MAX*Anita::NPHI_MAX);
660  Tools::Zero(anita1->arrival_times[1], Anita::NLAYERS_MAX*Anita::NPHI_MAX);
661 
662  //we pick both the interaction point and its corresponding mirror point
663 
664 
665  int pdgcode=-999;
666 
667 #ifdef ANITA_UTIL_EXISTS
668 
669  string outputAnitaFile =string(outputdir.Data())+"/SimulatedAnitaEventFile"+run_num+".root";
670  TFile *anitafileEvent = new TFile(outputAnitaFile.c_str(), "RECREATE");
671 
672  TTree *eventTree = new TTree("eventTree", "eventTree");
673  eventTree->Branch("event", &realEvPtr );
674  eventTree->Branch("run", &run_no, "run/I" );
675  eventTree->Branch("weight", &weight, "weight/D");
676 
677  outputAnitaFile =string(outputdir.Data())+"/SimulatedAnitaHeadFile"+run_num+".root";
678  TFile *anitafileHead = new TFile(outputAnitaFile.c_str(), "RECREATE");
679 
680  TTree *headTree = new TTree("headTree", "headTree");
681  headTree->Branch("header", &rawHeaderPtr );
682  headTree->Branch("weight", &weight, "weight/D");
683 
684  outputAnitaFile =string(outputdir.Data())+"/SimulatedAnitaGpsFile"+run_num+".root";
685  TFile *anitafileGps = new TFile(outputAnitaFile.c_str(), "RECREATE");
686 
687  TTree *adu5PatTree = new TTree("adu5PatTree", "adu5PatTree");
688  adu5PatTree->Branch("pat", &Adu5PatPtr );
689  adu5PatTree->Branch("eventNumber", &eventNumber, "eventNumber/I");
690  adu5PatTree->Branch("weight", &weight, "weight/D" );
691 
692 #ifdef ANITA3_EVENTREADER
693 
694  // Set AnitaVersion so that the right payload geometry is used
695  AnitaVersion::set(settings1->ANITAVERSION);
696 
697  outputAnitaFile =string(outputdir.Data())+"/SimulatedAnitaTruthFile"+run_num+".root";
698  TFile *anitafileTruth = new TFile(outputAnitaFile.c_str(), "RECREATE");
699 
700  TString icemcgitversion = TString::Format("%s", EnvironmentVariable::ICEMC_VERSION(outputdir));
701  printf("ICEMC GIT Repository Version: %s\n", icemcgitversion.Data());
702  unsigned int timenow = time(NULL);
703 
704  TTree *configAnitaTree = new TTree("configIcemcTree", "Config file and settings information");
705  configAnitaTree->Branch("gitversion", &icemcgitversion );
706  configAnitaTree->Branch("startTime", &timenow );
707  // configAnitaTree->Branch("settings", &settings1 );
708  configAnitaTree->Fill();
709 
710  TTree *truthAnitaTree = new TTree("truthAnitaTree", "Truth Anita Tree");
711  truthAnitaTree->Branch("truth", &truthEvPtr );
712 #endif
713 
714  AnitaGeomTool *AnitaGeom1 = AnitaGeomTool::Instance();
715 
716 #endif
717 
718 
719  IceModel *antarctica = new IceModel(settings1->ICE_MODEL + settings1->NOFZ*10, settings1->CONSTANTICETHICKNESS * 1000 + settings1->CONSTANTCRUST * 100 + settings1->FIXEDELEVATION * 10 + 0, settings1->WEIGHTABSORPTION);
720  cout << "area of the earth's surface covered by antarctic ice is " << antarctica->ice_area << "\n";
721 
722 
723  // sets position of balloon and related quantities
724  // these are all passed as pointers
725  // theta, phi, altitude of balloon
726  // position of balloon, altitude and position of surface of earth (relative to the center of the earth) under balloon
727  bn1->SetDefaultBalloonPosition(antarctica);
728 
729 
730  // builds payload based on read inputs
731  anita1->GetPayload(settings1, bn1);
732 
733  // if (settings1->TRIGGERSCHEME == 3 || settings1->TRIGGERSCHEME == 4 || settings1->TRIGGERSCHEME==5) {
734  Vector plusz(0., 0., 1.);
735  bn1->PickBalloonPosition(plusz, antarctica, settings1, anita1);
736 
737  time_t raw_loop_start_time = time(NULL);
738  cout<<"Starting loop over events. Time required for setup is "<<(int)((raw_loop_start_time - raw_start_time)/60)<<":"<< ((raw_loop_start_time - raw_start_time)%60)<<endl;
739 
740 
741  // for averaging balloon altitude and distance from center of earth
742  // for comparing with Peter
743  double average_altitude=0.;
744  double average_rbn=0.;
745 
746 
747  signal(SIGINT, interrupt_signal_handler); // This function call allows icemc to gracefully abort and write files as usual rather than stopping abruptly.
748 
749 
750  int antNum;
751 
752  // begin looping over NNU neutrinos doing the things
753  for (inu = 0; inu < NNU; inu++) {
754 
755  if (NNU >= 100) {
756  if (inu % (NNU / 100) == 0)
757  cout << inu << " neutrinos. " << (double(inu)/double(NNU)) * 100 << "% complete.\n";
758  }
759  else
760  cout << inu << " neutrinos. " << (double(inu) / double(NNU)) * 100 << "% complete.\n";
761 
762  eventNumber=(UInt_t)(run_no)*NNU+inu;
763 
764  // Set seed of all random number generators to be dependent on eventNumber
765  setSeed(eventNumber);
766 
767  anita1->passglobtrig[0]=0;
768  anita1->passglobtrig[1]=0;
769  passes_thisevent=0;
770  unmasked_thisevent=1;
771  vmmhz_min_thatpasses=1000; // initializing. want to find the minumum voltage that passes a
772 
773 
774  count_pass=0;
775  passestrigger=0;
776  chanceinhell2=0;
777  // sec1->secondbang=false;
778  count_total++;
779  // initializing the voltage seen by each polarization of each antenna
780  bn1->dtryingposition=-999;
781  for (int i=0; i<Anita::NFREQ;i++) {
782  vmmhz[i] = 0.; // the full signal with all factors accounted for (1/r, atten. etc.)
783  vmmhz_em[i]=0.; // for keeping track of just the em component of the shower
784  } //Zero the vmmhz array - helpful for banana plots, shouldn't affect anything else - Stephen
785 
786 
787  // Picks the balloon position and at the same time sets the masks and thresholds
788  bn1->PickBalloonPosition(antarctica, settings1, inu, anita1, getRNG(RNG_BALLOON_POSITION)->Rndm());
789 
790  // find average balloon altitude and distance from center of earth for
791  // making comparisons with Peter
792  average_altitude+=bn1->altitude_bn/(double)NNU;
793  average_rbn+=bn1->r_bn.Mag()/(double)NNU;
794 
795  realtime_this=bn1->realTime_flightdata;
796  longitude_this=bn1->longitude;
797  latitude_this=bn1->latitude;
798  altitude_this=bn1->altitude;
799  heading_this=bn1->heading;
800 
801 
802  for (int ilayer=0; ilayer < settings1->NLAYERS; ilayer++) { // loop over layers on the payload
803  for (int ifold=0;ifold<anita1->NRX_PHI[ilayer];ifold++) { // ifold loops over phi
804 
805  ChanTrigger *chantrig1 = new ChanTrigger();
806  chantrig1->InitializeEachBand(anita1);
807 
808  antNum = anita1->GetRxTriggerNumbering(ilayer, ifold);
809 
810 
811 
812 #ifdef ANITA_UTIL_EXISTS
813  if (settings1->SIGNAL_FLUCT && (settings1->NOISEFROMFLIGHTDIGITIZER || settings1->NOISEFROMFLIGHTTRIGGER) )
814  chantrig1->getNoiseFromFlight(settings1, anita1, antNum);
815 #endif
816  // chantrig1->ApplyAntennaGain(settings1, anita1, bn1, panel1, antNum, n_eplane, n_hplane, n_normal);
817 
818  // chantrig1->injectImpulseAfterAntenna(anita1, antNum);
819 
820 
821  memset(chantrig1->volts_rx_forfft, 0, sizeof(chantrig1->volts_rx_forfft));
822 
823  chantrig1->TriggerPath(settings1, anita1, antNum, bn1);
824 
825  chantrig1->DigitizerPath(settings1, anita1, antNum, bn1);
826 
827  chantrig1->TimeShiftAndSignalFluct(settings1, anita1, ilayer, ifold, volts_rx_rfcm_lab_e_all, volts_rx_rfcm_lab_h_all);
828 
829  chantrig1->saveTriggerWaveforms(anita1, justSignal_trig[0][antNum], justSignal_trig[1][antNum], justNoise_trig[0][antNum], justNoise_trig[1][antNum]);
830  chantrig1->saveDigitizerWaveforms(anita1, justSignal_dig[0][antNum], justSignal_dig[1][antNum], justNoise_dig[0][antNum], justNoise_dig[1][antNum]);
831 
832  // chantrig1->WhichBandsPass(settings1, anita1, globaltrig1, bn1, ilayer, ifold, viewangle-sig1->changle, emfrac, hadfrac, thresholdsAnt[antNum]);
833 
834  // cout << inu << " " << ilayer << " " << ifold << endl;
835  delete chantrig1;
836 
837  } //loop through the phi-fold antennas
838  } //loop through the layers of antennas
839 
840 
841  if ( true ) {
842 
843 
844 #ifdef ANITA_UTIL_EXISTS
845  realEvPtr = new UsefulAnitaEvent();
846  rawHeaderPtr = new RawAnitaHeader();
847  Adu5PatPtr = new Adu5Pat();
848 
849  Adu5PatPtr->latitude = bn1->latitude;
850  Adu5PatPtr->longitude = bn1->longitude;
851  Adu5PatPtr->altitude = bn1->altitude;
852  Adu5PatPtr->realTime = bn1->realTime_flightdata;
853  Adu5PatPtr->heading = bn1->heading;
854  Adu5PatPtr->pitch = bn1->pitch;
855  Adu5PatPtr->roll = bn1->roll;
856  Adu5PatPtr->run = run_no;
857 
858 
859  memset(realEvPtr->fNumPoints, 0, sizeof(realEvPtr->fNumPoints) );
860  memset(realEvPtr->fVolts, 0, sizeof(realEvPtr->fVolts) );
861  memset(realEvPtr->fTimes, 0, sizeof(realEvPtr->fTimes) );
862 
863  int fNumPoints = 260;
864 
865  for (int iant = 0; iant < settings1->NANTENNAS; iant++){
866  //int IceMCAnt = GetIceMCAntfromUsefulEventAnt(anita1, AnitaGeom1, iant);
867  int IceMCAnt = GetIceMCAntfromUsefulEventAnt(settings1, iant);
868  int UsefulChanIndexH = AnitaGeom1->getChanIndexFromAntPol(iant, AnitaPol::kHorizontal);
869  int UsefulChanIndexV = AnitaGeom1->getChanIndexFromAntPol(iant, AnitaPol::kVertical);
870  realEvPtr->fNumPoints[UsefulChanIndexV] = fNumPoints;
871  realEvPtr->fNumPoints[UsefulChanIndexH] = fNumPoints;
872  realEvPtr->chanId[UsefulChanIndexV] = UsefulChanIndexV;
873  realEvPtr->chanId[UsefulChanIndexH] = UsefulChanIndexH;
874 
875  for (int j = 0; j < fNumPoints; j++) {
876  // convert seconds to nanoseconds
877  realEvPtr->fTimes[UsefulChanIndexV][j] = j * anita1->TIMESTEP * 1.0E9;
878  realEvPtr->fTimes[UsefulChanIndexH][j] = j * anita1->TIMESTEP * 1.0E9;
879  // convert volts to millivolts
880  realEvPtr->fVolts[UsefulChanIndexH][j] = volts_rx_rfcm_lab_h_all[IceMCAnt][j+64]*1000;
881  realEvPtr->fVolts[UsefulChanIndexV][j] = volts_rx_rfcm_lab_e_all[IceMCAnt][j+64]*1000;
882  realEvPtr->fCapacitorNum[UsefulChanIndexH][j] = 0;
883  realEvPtr->fCapacitorNum[UsefulChanIndexV][j] = 0;
884  }//end int j
885  }// end int iant
886 
887  realEvPtr->eventNumber = eventNumber;
888 
889  rawHeaderPtr->eventNumber = eventNumber;
890  rawHeaderPtr->surfSlipFlag = 0;
891  rawHeaderPtr->errorFlag = 0;
892 
893  rawHeaderPtr->trigType = 8; // soft-trigger
894 
895  rawHeaderPtr->run = run_no;
896  // put the vpol only as a placeholder - these are only used in Anita-2 anyway
897  rawHeaderPtr->upperL1TrigPattern = l1trig[0][0];
898  rawHeaderPtr->lowerL1TrigPattern = l1trig[0][1];
899  rawHeaderPtr->nadirL1TrigPattern = l1trig[0][2];
900 
901  rawHeaderPtr->upperL2TrigPattern = l2trig[0][0];
902  rawHeaderPtr->lowerL2TrigPattern = l2trig[0][1];
903  rawHeaderPtr->nadirL2TrigPattern = l2trig[0][2];
904 
905  if (settings1->WHICH<9){
906  rawHeaderPtr->phiTrigMask = (short) anita1->phiTrigMask;
907  rawHeaderPtr->l3TrigPattern = (short) l3trig[0];
908  }
909 
910  rawHeaderPtr->calibStatus = 31;
911  rawHeaderPtr->realTime = bn1->realTime_flightdata;
912  rawHeaderPtr->triggerTime = bn1->realTime_flightdata;
913  Adu5PatPtr->latitude= bn1->latitude;
914  Adu5PatPtr->longitude=bn1->longitude;
915  Adu5PatPtr->altitude=bn1->altitude;
916  Adu5PatPtr->realTime=bn1->realTime_flightdata;
917  Adu5PatPtr->heading = bn1->heading;
918  Adu5PatPtr->pitch = bn1->pitch;
919  Adu5PatPtr->roll = bn1->roll;
920  Adu5PatPtr->run = run_no;
921 
922 #ifdef ANITA3_EVENTREADER
923  if (settings1->WHICH==9 || settings1->WHICH==10) {
924  rawHeaderPtr->setTrigPattern((short) l3trig[0], AnitaPol::kVertical);
925  rawHeaderPtr->setTrigPattern((short) l3trig[1], AnitaPol::kHorizontal);
926  rawHeaderPtr->setMask( (short) anita1->l1TrigMask, (short) anita1->phiTrigMask, AnitaPol::kVertical);
927  rawHeaderPtr->setMask( (short) anita1->l1TrigMaskH, (short) anita1->phiTrigMaskH, AnitaPol::kHorizontal);
928  }
929 
930  truthEvPtr = new TruthAnitaEvent();
931  truthEvPtr->eventNumber = eventNumber;
932  truthEvPtr->realTime = bn1->realTime_flightdata;
933  truthEvPtr->run = run_no;
934  truthEvPtr->nuMom = pnu;
935  truthEvPtr->nu_pdg = pdgcode;
936  memcpy(truthEvPtr->e_component, e_component, sizeof(e_component));
937  memcpy(truthEvPtr->h_component, h_component, sizeof(h_component));
938  memcpy(truthEvPtr->n_component, n_component, sizeof(n_component));
939  memcpy(truthEvPtr->e_component_k ,e_component_kvector, sizeof(e_component_kvector));
940  memcpy(truthEvPtr->h_component_k ,h_component_kvector, sizeof(h_component_kvector));
941  memcpy(truthEvPtr->n_component_k ,n_component_kvector, sizeof(n_component_kvector));
942  truthEvPtr->sourceLon = sourceLon;
943  truthEvPtr->sourceLat = sourceLat;
944  truthEvPtr->sourceAlt = sourceAlt;
945  truthEvPtr->weight = weight;
946  for (int i=0;i<3;i++){
947  truthEvPtr->balloonPos[i] = -999;
948  truthEvPtr->balloonDir[i] = -999;
949  truthEvPtr->nuPos[i] = -999;
950  truthEvPtr->nuDir[i] = -999;
951  }
952  // for (int i=0;i<5;i++){
953  // for (int j=0;j<3;j++){
954  // truthEvPtr->rfExitNor[i][j] = ray1->n_exit2bn[i][j];
955  // truthEvPtr->rfExitPos[i][j] = ray1->rfexit[i][j];
956  // }
957  // }
958  for (int i=0;i<48;i++){
959  truthEvPtr->hitangle_e[i] = hitangle_e_all[i];
960  truthEvPtr->hitangle_h[i] = hitangle_h_all[i];
961  }
962  if(settings1->ROUGHNESS){
963  for (int i=0;i<Anita::NFREQ;i++)
964  truthEvPtr->vmmhz[i] = -999;
965  }
966  truthAnitaTree->Fill();
967  delete truthEvPtr;
968 #endif
969 
970  headTree->Fill();
971  eventTree->Fill();
972  adu5PatTree->Fill();
973 
974  delete realEvPtr;
975  delete rawHeaderPtr;
976  delete Adu5PatPtr;
977 #endif
978 
979  sum_weights+=weight;
980  neutrinos_passing_all_cuts++;
981 
982  } // end if passing global trigger conditions
983  else {
984  passes_thisevent=0; // flag this event as not passing
985  }// end else event does not pass trigger
986 
987  // delete globaltrig1;
988 
989  if (ABORT_EARLY){
990  std::cout << "\n***********************************************************";
991  std::cout << "\n* SIGINT received, aborting loop over events early.";
992  std::cout << "\n* Stopped after event " << inu << " instead of " << NNU;
993  std::cout << "\n* Any output which relied on NNU should be corrected for.";
994  std::cout << "\n***********************************************************\n";
995  foutput << "\n***********************************************************";
996  foutput << "\n* SIGINT received, aborting loop over events early.";
997  foutput << "\n* Stopped after event " << inu << " instead of " << NNU;
998  foutput << "\n* Any output which relied on NNU should be corrected for.";
999  foutput << "\n***********************************************************\n";
1000  break;
1001  }
1002  }//end NNU neutrino loop
1003 
1004 
1005 
1006 
1007 #ifdef ANITA_UTIL_EXISTS
1008 
1009  anitafileEvent->cd();
1010  eventTree->Write("eventTree");
1011  anitafileEvent->Close();
1012  delete anitafileEvent;
1013 
1014  anitafileHead->cd();
1015  headTree->Write("headTree");
1016  anitafileHead->Close();
1017  delete anitafileHead;
1018 
1019  anitafileGps->cd();
1020  adu5PatTree->Write("adu5PatTree");
1021  anitafileGps->Close();
1022  delete anitafileGps;
1023 
1024 #ifdef ANITA3_EVENTREADER
1025  anitafileTruth->cd();
1026  truthAnitaTree->Write("truthAnitaTree");
1027  anitafileTruth->Close();
1028  delete anitafileTruth;
1029 #endif
1030 
1031 #endif
1032 
1033 
1034 
1035  time_t raw_end_time = time(NULL);
1036  struct tm * end_time = localtime(&raw_end_time);
1037  cout << "Date and time at end of run are: " << asctime (end_time) << "\n";
1038  cout<<"Total time elapsed is "<<(int)((raw_end_time - raw_start_time)/60)<<":"<< ((raw_end_time - raw_start_time)%60)<<endl;
1039 
1040  foutput << "\nTotal time elapsed in run is " <<(int)((raw_end_time - raw_start_time)/60)<<":"<< ((raw_end_time - raw_start_time)%60)<<endl;
1041 
1042  // delete anita1;
1043  return 0;
1044 
1045 } //END MAIN PROGRAM
1046 
1047 
1048 
1049 
1050 
1051 
1052 
1053 
1054 
1055 //
1056 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1057 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1058 //
1059 //
1060 // Auxiliary functions
1061 //
1062 //
1063 //
1064 
1065 
1066 
1067 void interrupt_signal_handler(int sig){
1068  signal(sig, SIG_IGN);
1069  ABORT_EARLY = true;
1070  return;
1071 }
1072 //end interrupt_signal_handler()
1073 
1074 
1075 #ifdef ANITA_UTIL_EXISTS
1076 //int GetIceMCAntfromUsefulEventAnt(Anita *anita1, AnitaGeomTool *AnitaGeom1, int UsefulEventAnt){
1077 int GetIceMCAntfromUsefulEventAnt(Settings *settings1, int UsefulEventAnt){
1078  //int layer_temp = IceMCLayerPosition[UsefulEventIndex][0];
1079  //int position_temp = IceMCLayerPosition[UsefulEventIndex][1];
1080  //int IceMCIndex = anita1->GetRx(layer_temp, position_temp);
1081  int IceMCAnt = UsefulEventAnt;
1082  if ((settings1->WHICH==9 || settings1->WHICH==10) && UsefulEventAnt<16) {
1083  IceMCAnt = (UsefulEventAnt%2==0)*UsefulEventAnt/2 + (UsefulEventAnt%2==1)*(UsefulEventAnt/2+8);
1084  }
1085 
1086  return IceMCAnt;
1087 }
1088 //end GetIceMCAntfromUsefulEventAnt()
1089 
1090 
1091 #endif
UInt_t eventNumber
Event number from software.
Definition: RawAnitaEvent.h:33
UShort_t lowerL2TrigPattern
Bit mask for lower ring l2 cluster triggers. eg. if the bit 1 (the lowest bit) is active it means the...
UChar_t surfSlipFlag
Sync Slip between SURF 2-9 and SURF 1.
Double_t h_component_k[48]
Component of the e-field along the rx h-plane.
UChar_t errorFlag
Error Flag.
Double_t weight
Weight assigned by icemc.
Int_t nu_pdg
Neutrino PDG code.
Double_t sourceLat
RF position when leaving the ice: Latitude (using icemc model)
double fVolts[12 *9][260]
Array of unwrapped (unless kNoCalib) voltages for each channel.
Float_t pitch
in degrees
Definition: Adu5Pat.h:46
void InitializeEachBand(Anita *anita1)
Initialize trigger bands.
Definition: ChanTrigger.cc:711
UShort_t upperL1TrigPattern
Bit mask for upper ring l1 antenna triggers. eg. if the bit 1 (the lowest bit) is active it means the...
UShort_t l3TrigPattern
Bit mask for l3 global triggers. eg. if the bit 1 (the lowest bit) is active it means that phi sector...
Adu5Pat – The ADU5 Position and Attitude Data.
Definition: Adu5Pat.h:26
void TriggerPath(Settings *settings1, Anita *anita1, int ant, Balloon *bn1)
Apply trigger path.
Definition: ChanTrigger.cc:871
static const int NPOL
number of polarizations
Definition: anita.hh:51
Double_t n_component_k[48]
Component of the e-field along the normal.
UShort_t calibStatus
Calib/Relay Status.
Float_t latitude
In degrees.
Definition: Adu5Pat.h:42
STL namespace.
static Int_t getChanIndexFromAntPol(Int_t ant, AnitaPol::AnitaPol_t pol)
Convert ant-pol to logical index.
Radiation from interaction.
Definition: signal.hh:13
double fTimes[12 *9][260]
Array of unwrapped (unless kNoCalib) times for each channel.
Double_t sourceLon
RF position when leaving the ice: Longitude (using icemc model)
Double_t sourceAlt
RF position when leaving the ice: Altitude (using icemc model)
void TimeShiftAndSignalFluct(Settings *settings1, Anita *anita1, int ilayer, int ifold, double volts_rx_rfcm_lab_e_all[48][512], double volts_rx_rfcm_lab_h_all[48][512])
Time shift and fluctuate signal.
Float_t longitude
In degrees.
Definition: Adu5Pat.h:43
double volts_rx_forfft[2][5][Anita::HALFNFOUR]
Array of time domain after the antenna gain. Indeces stand for [ipol][iband][itime].
Definition: ChanTrigger.h:415
UInt_t realTime
Time from the GPS unit.
Definition: Adu5Pat.h:37
const char * ICEMC_SRC_DIR()
Double_t n_component[48]
Normal comp along polarization.
Double_t balloonPos[3]
Balloon position.
UChar_t nadirL2TrigPattern
8-bit trigger mask for L2 nadir triggers. Nadir L2 triggers are for the even phi sectors and are just...
void saveTriggerWaveforms(Anita *anita1, double sig0[48], double sig1[48], double noise0[48], double noise1[48])
Save signal and noise waveforms at trigger.
Double_t vmmhz[128]
V/m/MHz at balloon (128 frequency bins)
RawAnitaHeader – The Raw ANITA Event Header.
Class that handles the channel trigger.
Definition: ChanTrigger.h:18
Reads in and stores input settings for the run.
Definition: Settings.h:37
Int_t run
Run number, assigned on ground.
This class is a 3-vector that represents a position on the Earth&#39;s surface.
Definition: position.hh:26
Secondary interactions.
Definition: secondaries.hh:28
void saveDigitizerWaveforms(Anita *anita1, double sig0[48], double sig1[48], double noise0[48], double noise1[48])
Save signal and noise waveforms at digitizer.
void getNoiseFromFlight(Settings *settings1, Anita *anita1, int ant, bool also_digi=true)
Add noise from ANITA-3 flight to the time domain waveforms.
Double_t h_component[48]
H comp along polarization.
UInt_t realTime
unixTime of readout
UsefulAnitaEvent – The Calibrated Useful Anita Event object.
Float_t altitude
In metres.
Definition: Adu5Pat.h:44
UShort_t phiTrigMask
16-bit phi mask (from TURF)
Double_t hitangle_h[48]
Hit angles rel. to h plane stored for each antenna.
void DigitizerPath(Settings *settings1, Anita *anita1, int ant, Balloon *bn1)
Apply digitizer path.
UChar_t chanId[12 *9]
Definition: RawAnitaEvent.h:39
TruthAnitaEvent – The Truth ANITA Event.
Double_t e_component[48]
E comp along polarization.
Shape of the earth, ice thicknesses, profiles of earth layers, densities, neutrino absorption...
Definition: earthmodel.hh:40
static const int NLAYERS_MAX
max number of layers (in smex design, it&#39;s 4)
Definition: anita.hh:59
UShort_t lowerL1TrigPattern
Bit mask for lower ring l1 antenna triggers. eg. if the bit 1 (the lowest bit) is active it means the...
int fCapacitorNum[12 *9][260]
Array of capacitor numbers.
Double_t nuDir[3]
Neutrino direction.
Vertical Polarisation.
Double_t e_component_k[48]
Component of e-field along the rx e-plane.
Double_t nuMom
Neutrino momentum.
int fNumPoints[12 *9]
Number of poins per channel.
Handles everything related to balloon positions, payload orientation over the course of a flight...
Definition: balloon.hh:30
This class represents a three-vector. Operators are overloaded to provide for the familiar operations...
Definition: vector.hh:27
UShort_t upperL2TrigPattern
Bit mask for upper ring l2 cluster triggers. eg. if the bit 1 (the lowest bit) is active it means the...
static const int NPHI_MAX
max number of antennas around in phi (in smex, 16)
Definition: anita.hh:61
Horizontal Polarisation.
Float_t heading
0 is facing north, 180 is facing south
Definition: Adu5Pat.h:45
Handles event counting as cuts are made.
Definition: counting.hh:10
UInt_t realTime
unixTime of readout
Definition: rx.hpp:23
UChar_t nadirL1TrigPattern
8-bit trigger mask for L1 nadir triggers. Here bit 1 is antenna 33 (phi 1), bit 2 is antenna 34 (phi ...
static AnitaGeomTool * Instance(int anita_version=0)
Instance generator. If version_number == 0, uses AnitaVersion::get();.
AnitaGeomTool – The ANITA Geometry Tool.
Definition: AnitaGeomTool.h:48
UInt_t eventNumber
Software event number.
Double_t nuPos[3]
Neutrino position.
Ray tracing.
Definition: ray.hh:20
Double_t hitangle_e[48]
Hit angles rel. to e plane stored for each antenna.
Int_t run
Run number.
UChar_t trigType
Bit 0 is RF, 1 is ADU5, 2 is G12, 3 is software/external.
UInt_t triggerTime
Trigger time from TURF converted to unixTime.
Double_t balloonDir[3]
Balloon direction.
Ice thicknesses and water depth.
Definition: icemodel.hh:103