testInputAfterAntenna.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 double eventsfound_beforetrigger=0.;
111 double eventsfound_crust=0; //number of events that only traverse the crust
112 double eventsfound_weightgt01=0; // summing weights > 0.1
113 double eventsfound_belowhorizon=0; // how many are below horizon
114 double eventsfound=0; // how many events found
115 double eventsfound_prob=0; // how many events found, probabilities
116 double sum[3]; // sum of weight for events found for 3 flavors
117 // These numbers are from Feldman and Cousins wonderful paper: physics/9711021
118 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};
119 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.};
120 const int NBINS=10; // keep track of the number of events found, binned
121 // by weights
122 double MIN_LOGWEIGHT=-3;
123 double MAX_LOGWEIGHT=-1;
124 int index_weights=0; // which bin the weight falls into
125 double eventsfound_binned[NBINS];
126 double eventsfound_binned_e[NBINS];
127 double eventsfound_binned_mu[NBINS];
128 double eventsfound_binned_tau[NBINS];
129 double km3sr = 0; // total km3sr
130 double km3sr_e=0; // to calculate km3sr for electrons
131 double km3sr_mu=0; // to calculate km3sr for muons
132 double km3sr_tau=0; // to calculate km3sr for taus
133 double error_plus=0; // keeping track of asymmetric error bars
134 double error_e_plus=0;
135 double error_mu_plus=0;
136 double error_tau_plus=0;
137 double error_minus=0;
138 double error_e_minus=0;
139 double error_mu_minus=0;
140 double error_tau_minus=0;
141 int ierr=0; // integer for returning error from functions.
142 double gain_dipole=2.15; // antenna gain (nominal value for dipole is 2.15)
143 double changle_deg=0; // same, in degrees.
144 // inputs
145 int NNU; // number of neutrinos
146 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)
147 double RANDOMISEPOL=0.;
148 /************MOVED FROM shared.hh and shared.cc*****************/
149 
150 
151 double volume_thishorizon; // for plotting volume within the horizon of the balloon
152 int realtime_this; // for plotting real unix time
153 double longitude_this; // for plotting longitude
154 double latitude_this; // for plotting latitude
155 double altitude_this; // for plotting altitude
156 double heading_this=0.;// for plotting heading
157 double gps_offset=0;
158 
159 // inputs
160 
161 double pnu=pow(10., 20);
162 
163 double MEANX=0;
164 double MEANY=0.;
165 
166 double SIGNALRADIUS=2.; // in degrees
167 
168 
169 double bwslice_vnoise_thislayer[4];// for filling tree6b, noise for each bandwidth on each layer
170 int passes_thisevent=0; // this event passes
171 int unmasked_thisevent=0; // this event is unmasked
172 
173 int discones_passing; // number of discones that pass
174 int NDISCONES=8;
175 double heff_discone=0; // effective height of a discone antenna
176 double polarfactor_discone=0.;// factor to account for antenna beam pattern.
177 double thislambda=0;// for finding wavelength at each frequency
178 double volts_discone=0.;// for finding voltage at each discone
179 double vnoise_discone=0.; // noise on each discone
180 
181 
182 double BW_DISCONES=300.E6-120.E6; // bandwidth of the discones
183 
184 // ray tracing
185 double fresnel1=0;
186 double fresnel1_eachboresight[Anita::NLAYERS_MAX][Anita::NPHI_MAX]; // for slac simulation
187 double fresnel2=0;
188 double mag1=0; // magnification factor on field at ice-firn interface
189 double mag1_eachboresight[Anita::NLAYERS_MAX][Anita::NPHI_MAX];// for slac simulation
190 double mag2=0; // magnification factor on field in firn-air
191 double t_coeff_pokey, t_coeff_slappy;
192 double rflength=0; // distance from interaction to ice-air exit point
193 
194 double e_comp_max1=0;
195 double h_comp_max1=0;
196 double e_comp_max2=0;
197 double h_comp_max2=0;
198 double e_comp_max3=0;
199 double h_comp_max3=0;
200 
201 double diffexit=0; // checking exit point between_MAX interations
202 double diff_3tries=0;
203 double diffnorm=0; // checking angle of surf normal between iterations
204 double diffrefr=0; // checking angle of refr between iterations
205 double costheta_inc=0; // cos angle of incidence wrt surface normal
206 double costheta_exit=0; // theta of exit point wrt earth (costheta=1 at south pole)
207 double theta_rf_atbn; // polar angle of the signal as seen by perfect eyes at the balloon.
208 double theta_rf_atbn_measured; //polar angle of the signal as measured at the balloon (just the above variable smeared by 0.5 degrees)
209 
210 double costhetanu=-1000; // costheta of neutrino direction wrt earth (costheta=1 at south pole)
211 
212 // neutrino path
213 double theta_in=0; // theta where neutrino enters earth (radians, south pole=0)
214 double lat_in=0; // latitude where neutrino enters earth (degrees, south pole=-90)
215 double nearthlayers=0; // how many layers (core, mantle, crust) does nnu traverse
216 double weight_prob=0.;//event weight, including probability it interacts somewhere in ice along its path
217 double weight1=0; // event weight, just based on absorption in earth, see note
218 double weight=0.; // total event weight (product of the previous 2)
219 double logweight=0.;// log of the previous number
220 double len_int=0;// interaction length in m
221 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.
222 
223 double CUTONWEIGHTS=1.E-10; // cut out events with small enough weight that they don't matter, to save time
224 
225 // counting variables
226 int count_inthisloop1=0; // for debugging
227 int count_inthisloop2=0;
228 int count_inthisloop3=0;
229 double averaging_thetas1=0; // for debugging
230 double averaging_thetas2=0;
231 double averaging_thetas3=0;
232 int count_total=0; // number of neutrinos looped over. should always equal inu
233 
234 // i.e., is theoretically visible by balloon
235 
236 int count_asktrigger=0;
237 int count_asktrigger_nfb=0;
238 int count_pass=0; // how many total trigger channels pass (4 bandwidth slices*2 pol * nrx)
239 
240 double count_passestrigger_w=0; // same as above, but sum weights
241 int passestrigger=0; // 1=this event passes trigger, 0=does not
242 // so that we know to increment count_passestrigger_w at the end of the event
243 int allcuts[2]={0, 0}; // index is which ray (upward or downward)
244 // 1=this ray for this event passes all cuts, 0=does not
245 double allcuts_weighted[2]={0, 0}; // same as above but weighted
246 double allcuts_weighted_polarization[3]={0, 0, 0}; // same as above but divided into [0] vpol, [1] hpol, [2] both vpol and hpol
247 
248 
249 //signal has a chance to pass after accounting for 1/r
250 int count_chanceofsurviving=0; // based on neutrino direction, has a chance of making it through earth.
251 
252 int count_chanceinhell0=0; // based on 1/r, and best case attenuation
253 // (after 2nd guess at rf exit point)
254 // signal has a chance of passing
255 
256 double count_chanceinhell2_w=0; //same as above, but sum weights
257 int chanceinhell2=0; // 1=this event has chance to pass, 0=does not-
258 // so that we know to increment count_chanceinhell2_w by weight1 at the end.
259 
260 int count_chordgoodlength=0; // Incremented if neutrino path through earth is more than 1m
261 int count_d2goodlength=0; // neutrino path through ice is more than 1m
262 int count_rx=0; // counting antennas we loop through them
263 
264 double sum_frac[3]; // fraction of passing events that are e, mu, tau adding weights
265 double sum_frac_db[3]; // same for double bangs
266 
267 const int NBINS_DISTANCE=28; // keep track of number that pass as a function of distance to make Peter's plot
268 double eventsfound_binned_distance[NBINS_DISTANCE] = {0.}; // binning cumulative events found vs. distance
269 int index_distance=0; // index for filling array above
270 double km3sr_distance[NBINS_DISTANCE] = {0.}; // result of conversion of events to sensitivity
271 double error_distance_plus[NBINS_DISTANCE] = {0.}; // errors on above
272 double error_distance_minus[NBINS_DISTANCE] = {0.};
273 int eventsfound_binned_distance_forerror[NBINS_DISTANCE][NBINS] = {{0}}; // for propagation of errors
274 
275 //taus
276 double km3sr_db = 0;
277 double km3sr_nfb=0;
278 double ptau=0;
279 int count_passestrigger_nfb=0;
280 double percent_increase_db=0;
281 double percent_increase_nfb=0;
282 double percent_increase_total=0;
283 double error_nfb=0;
284 double error_km3sr_nfb=0;
285 double error_percent_increase_nfb=0;
286 
287 Vector n_exit2bn_db[5];
288 Vector nrf_iceside_db[5]; // direction of rf [tries][3d]
289 double n_exit_phi; //phi angle of the ray from the surface to the balloon
290 int count_dbexitsice=0;
291 
292 // int count_interacts_in_earth=0;
293 double eventsfound_nfb_binned[NBINS]; // counting events without first bang
294 
295 // rf parameters
296 double heff_max=0.62639; // maximum value of the effective height based on antenna specs
297 
298 // event geometry
299 double scalefactor_distance=0; // 1/r scalefactor
300 double scalefactor_attenuation=0; //scalefactor due to attenuation in ice
301 double MAX_ATTENLENGTH=1671;
302 double maxtaper=0; // this is just for plotting - maximum you are ever off cerenkov cone while
303 //an event is detectable
304 double dviewangle_deg=0;
305 
306 double forseckel[NVIEWANGLE][Anita::NFREQ];// Per Seckel's request, get strength of signal across frequencies for different viewing angles.
307 double viewangles[NVIEWANGLE];
308 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
309 
310 //Input files
311 int err=0; // errors from GetDirection function
312 
313 double djunk; // junk variable
314 
315 //For verification plots - added by Stephen
316 int max_antenna0 = -1; //antenna with the peak voltage, top layer
317 int max_antenna1 = -1; //antenna with the peak voltage, middle layer
318 int max_antenna2 = -1; //antenna with the peak voltage, bottom layer
319 double max_antenna_volts0 = 0; //Voltage on the antenna with maximum signal, top layer
320 double max_antenna_volts0_em = 0; //Component of voltage from em shower on the antenna with maximum signal, top layer
321 
322 double max_antenna_volts1 = 0; //Voltage on the antenna with maximum signal, middle layer
323 double max_antenna_volts2 = 0; //Voltage on the antenna with maximum signal, bottom layer
324 
325 double rx0_signal_eachband[2][5];
326 double rx0_threshold_eachband[2][5];
327 double rx0_noise_eachband[2][5];
328 int rx0_passes_eachband[2][5];
329 
330 double voltagearray[Anita::NLAYERS_MAX*Anita::NPHI_MAX]; //Records max voltages on each antenna for one neutrino
331 
332 Vector ant_max_normal0; //Vector normal to the face of the antenna with the maximum signal for a single neutrino, top layer
333 Vector ant_max_normal1; //Vector normal to the face of the antenna with the maximum signal for a single neutrino, middle layer
334 Vector ant_max_normal2; //Vector normal to the face of the antenna with the maximum signal for a single neutrino, bottom layer
335 double vmmhz1m_visible = 0; //Actual V/m/Mhz at 1m
336 int freq_bins = Anita::NFREQ; //Because the compiler objected to using the const directly
337 double total_kgm2 = 0; // output of Getchord
338 double nnu_array[3];
339 double r_in_array[3];
340 double nsurf_rfexit_array[3];
341 double nsurf_rfexit_db_array[3];
342 double r_bn_array[3];
343 double n_bn_array[3];
344 double posnu_array[3];
345 double nrf_iceside_array[5][3];
346 double nrf_iceside_db_array[5][3];
347 double ant_max_normal0_array[3];
348 double ant_max_normal1_array[3];
349 double ant_max_normal2_array[3];
350 double n_pol_array[3];
351 double n_exit2bn_array[5][3];
352 double r_enterice_array[3];
353 double n_exit2bn_db_array[5][3];
354 double rfexit_array[5][3];
355 double rfexit_db_array[5][3];
356 
357 int times_crust_entered_det=0; //Counter for total times each Earth layer is entered for detected neutrinos only
358 int times_mantle_entered_det=0;
359 int times_core_entered_det=0;
360 int crust_entered=0;
361 int mantle_entered=0;
362 int core_entered=0;
363 int neutrinos_passing_all_cuts=0;
364 double sum_weights=0;
365 //End verification plot block
366 
367 double justNoise_trig[2][48][512];
368 double justSignal_trig[2][48][512];
369 double justNoise_dig[2][48][512];
370 double justSignal_dig[2][48][512];
371 
372 
373 // functions
374 
375 // set up array of viewing angles for making plots for seckel
376 void SetupViewangles(Signal *sig1);
377 
378 void GetAir(double *col1); // get air column as a function of theta- only important for black hole studies
379 double GetThisAirColumn(Settings*, Position r_in, Vector nnu, Position posnu, double *col1, double& cosalpha, double& mytheta, double& cosbeta0, double& mybeta);
380 
381 double ScaleVmMHz(double vmmhz1m_max, const Position &posnu, const Position &r_bn);
382 
383 
384 double IsItDoubleBang(double exitlength, double plepton);
385 
386 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);
387 void GetCurrent(string& current);
388 
389 
390 double GetAverageVoltageFromAntennasHit(Settings *settings1, int *nchannels_perrx_triggered, double *voltagearray, double& volts_rx_sum);
391 
392 
393 Vector GetPolarization(const Vector &nnu, const Vector &nrf2_iceside);
394 
395 void Attenuate(IceModel *antartica1, Settings *settings1, double& vmmhz_max, double rflength, const Position &posnu);
396 
397 void Attenuate_down(IceModel *antarctica1, Settings *settings1, double& vmmhz_max, const Position &rfexit2, const Position &posnu, const Position &posnu_down);
398 
399 void IsAbsorbed(double chord_kgm2, double len_int_kgm2, double& weight);
400 
401 
402 int GetRayIceSide(const Vector &n_exit2rx, const Vector &nsurf_rfexit, double nexit, double nenter, Vector &nrf2_iceside);
403 
404 double GetViewAngle(const Vector &nrf2_iceside, const Vector &nnu);
405 int TIR(const Vector &n_surf, const Vector &nrf2_iceside, double N_IN, double N_OUT);
406 
407 void IntegrateBands(Anita *anita1, int k, Screen *panel1, double *freq, double scalefactor, double *sumsignal);
408 
409 void Integrate(Anita *anita1, int j, int k, double *vmmhz, double *freq, double scalefactor, double sumsignal);
410 
411 void interrupt_signal_handler(int); // This catches the Control-C interrupt, SIGINT
412 
413 bool ABORT_EARLY = false; // This flag is set to true when interrupt_signal_handler() is called
414 
415 void WriteNeutrinoInfo(Position&, Vector&, Position&, double, string, string, double, ofstream &nu_out);
416 
417 void CloseTFile(TFile *hfile);
418 
419 int Getmine(double*, double*, double*, double*);
420 
421 void Getearth(double*, double*, double*, double*);
422 
423 
424 #ifdef ANITA_UTIL_EXISTS
425 int GetIceMCAntfromUsefulEventAnt(Settings *settings1, int UsefulEventAnt);
426 #ifdef R_EARTH
427 #undef R_EARTH
428 #endif
429 #endif
430 
431 
432 double thresholdsAnt[48][2][5];
433 double thresholdsAntPass[48][2][5];
434 
435 
436 //do a threshold scan
437 double threshold_start=-1.;
438 double threshold_end=-6.;
439 const int NTHRESHOLDS=20;
440 double threshold_step=(threshold_end-threshold_start)/(double)NTHRESHOLDS;
441 
442 double npass_v_thresh[NTHRESHOLDS]={0.};
443 double denom_v_thresh[NTHRESHOLDS]={0.};
444 double npass_h_thresh[NTHRESHOLDS]={0.};
445 double denom_h_thresh[NTHRESHOLDS]={0.};
446 double thresholds[NTHRESHOLDS];
447 
448 int main(int argc, char **argv) {
449  //--------------------------------------------------------------
450  // MC Anita
451  //
452  // 12/01/03
453  //
454  //--------------------------------------------------------------
455 
456 
457  // // for comparing with peter
458  // double sumsignal[5]={0.};
459 
460  string stemp;
461 
462  Settings* settings1 = new Settings();
463 
464  string input= ICEMC_SRC_DIR + "/inputs.conf";
465  string run_num;//current run number as string
466  int run_no = 0;//current run number as integer
467  TString outputdir;
468 
469  if( (argc%3!=1)&&(argc%2!=1)) {
470  cout << "Syntax for options: -i inputfile -o outputdir -r run_number\n";
471  return 0;
472  }
473  int nnu_tmp=0;
474  double exp_tmp=0;
475  double trig_thresh=0.;
476  char clswitch; // command line switch
477  if (argc>1) {
478  while ((clswitch = getopt(argc, argv, "t:i:o:r:n:e:")) != EOF) {
479  switch(clswitch) {
480  case 'n':
481  nnu_tmp=atoi(optarg);
482  cout << "Changed number of simulated neutrinos to " << nnu_tmp << endl;
483  break;
484  case 't':
485  trig_thresh=atof(optarg);
486  break;
487  case 'i':
488  input=optarg;
489  cout << "Changed input file to: " << input << endl;
490  break;
491  case 'o':
492  outputdir=optarg;
493  cout << "Changed output directory to: " << string(outputdir.Data()) << endl;
494  stemp="mkdir -p " + string(outputdir.Data());
495  system(stemp.c_str());
496  break;
497  case 'e':
498  exp_tmp=atof(optarg);
499  cout << "Changed neutrino energy exponent to " << exp_tmp << endl;
500  break;
501  case 'r':
502  run_num=optarg;
503  stringstream convert(run_num);
504  convert>>run_no;
505  break;
506  } // end switch
507  } // end while
508  } // end if arg>1
509 
510 
511  settings1->SEED=settings1->SEED +run_no;
512  cout <<"seed is " << settings1->SEED << endl;
513 
514  setSeed(settings1->SEED);
515 
516  stemp=string(outputdir.Data())+"/nu_position"+run_num+".txt";
517  ofstream nu_out(stemp.c_str(), ios::app); //Positions, direction of momentum, and neutrino type for Ryan.
518 
519  stemp=string(outputdir.Data())+"/veff"+run_num+".txt";
520  ofstream veff_out(stemp.c_str(), ios::app);//to output only energy and effective volume to veff.txt
521 
522  stemp=string(outputdir.Data())+"/distance"+run_num+".txt";
523  ofstream distanceout(stemp.c_str());
524 
525  stemp=string(outputdir.Data())+"/debug"+run_num+".txt";
526  fstream outfile(stemp.c_str(), ios::out);
527 
528  stemp=string(outputdir.Data())+"/forbrian"+run_num+".txt";
529  fstream forbrian(stemp.c_str(), ios::out);
530 
531  stemp=string(outputdir.Data())+"/al_voltages_direct"+run_num+".dat";
532  fstream al_voltages_direct(stemp.c_str(), ios::out); //added djg ------provide anita-lite voltages and noise from MC for anita-lite analysis
533 
534  stemp=string(outputdir.Data())+"/events"+run_num+".txt";
535  ofstream eventsthatpassfile(stemp.c_str());
536 
537  stemp=string(outputdir.Data())+"/numbers"+run_num+".txt";
538  ofstream fnumbers(stemp.c_str()); // debugging
539 
540  stemp=string(outputdir.Data())+"/output"+run_num+".txt";
541  ofstream foutput(stemp.c_str(), ios::app);
542 
543  stemp=string(outputdir.Data())+"/slacviewangles"+run_num+".dat";
544  ofstream fslac_viewangles(stemp.c_str()); // this outputs numbers that we need for analyzing slac data
545 
546  stemp=string(outputdir.Data())+"/slac_hitangles"+run_num+".dat";
547  ofstream fslac_hitangles(stemp.c_str()); // this outputs numbers that we need for analyzing slac data
548 
549  Balloon *bn1=new Balloon(); // instance of the balloon
550  Anita *anita1=new Anita();// right now this constructor gets banding info
551  Secondaries *sec1=new Secondaries();
552  Signal *sig1=new Signal();
553  Ray *ray1=new Ray(); // create new instance of the ray class
554  Counting *count1=new Counting();
555  GlobalTrigger *globaltrig1;
556 
557  // input parameters
558  settings1->ReadInputs(input.c_str(), foutput, NNU, RANDOMISEPOL);
559  settings1->ApplyInputs(anita1, sec1, sig1, bn1, ray1);
560  sig1->Initialize();
561 
562  settings1->SEED=settings1->SEED + run_no;
563  setSeed(settings1->SEED);
564 
565  bn1->InitializeBalloon();
566  anita1->Initialize(settings1, foutput, inu, outputdir);
567 
568  if (nnu_tmp!=0)
569  NNU=nnu_tmp;
570  if (exp_tmp!=0)
571  settings1->EXPONENT=exp_tmp;
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  //added djg ////////////////////////////////////////////////////////
592  al_voltages_direct<<"antenna #"<<" "<<"volts chan 1"<<" "<<"volts chan 2"<<" "<<"volts chan 3"<<" "<<"volts chan 4"<<" "<<"noise chan 1"<<" "<<"noise chan 2"<<" "<<"noise chan 3"<<" "<<"noise chan 4"<<" "<<"weight"<<endl;
594 
595  // ray tracing
596  double viewangle=0;
597  double offaxis=0; // viewangle-changle, for plotting
598 
599  int beyondhorizon = 0; //Switch tells if neutrino interacts beyond the balloon's horizon. (0: inside horizon, 1: outside horizon)
600 
601  // frequency binning
602  double vmmhz1m_max=0; // maximum V/m/MHz at 1m from Jaime (highest frequency)
603  double vmmhz_lowfreq=0.; // V/m/MHz after 1/r, attenuation at the lowest freq.
604  double vmmhz[Anita::NFREQ]; // V/m/MHz at balloon (after all steps)
605 
606  // given the angle you are off the Cerenkov cone, the fraction of the observed e field that comes from the em shower
607  double vmmhz_em[Anita::NFREQ];
608  double vmmhz_min_thatpasses=1000;
609  double vmmhz_min=0; // minimum of the above array
610  double vmmhz_max=0; // maximum of the above array
611  double deltheta_em_max, deltheta_had_max; // maximum value of above array angular distribution
612 
613  // shower properties
614  double emfrac, hadfrac, sumfrac; // em and had fractions
615 
616  string taudecay; // tau decay type: e, m, h
617 
618  double elast_y=0; // inelasticity
619  double volts_rx_max=0; // max voltage seen on an antenna - just for debugging purposes
620  double volts_rx_ave=0; // ave voltage seen on an antenna, among hit antennas
621  double volts_rx_sum=0; // ave voltage seen on an antenna, among hit antennas
622 
623  double volts_rx_max_highband; // max voltage seen on an antenna - just for debugging purposes
624  double volts_rx_max_lowband; // max voltage seen on an antenna - just for debugging purposes
625  double volts_rx_rfcm_lab_e_all[48][512];
626  double volts_rx_rfcm_lab_h_all[48][512];
627 
628  // variable declarations for functions GetEcompHcompEvector and GetEcompHcompkvector - oindree
629  double e_component[Anita::NANTENNAS_MAX]={0}; // E comp along polarization
630  double h_component[Anita::NANTENNAS_MAX]={0}; // H comp along polarization
631  double n_component[Anita::NANTENNAS_MAX]={0}; // normal comp along polarization
632 
633  double e_component_kvector[Anita::NANTENNAS_MAX]={0}; // component of e-field along the rx e-plane
634  double h_component_kvector[Anita::NANTENNAS_MAX]={0}; // component of the e-field along the rx h-plane
635  double n_component_kvector[Anita::NANTENNAS_MAX]={0}; // component of the e-field along the normal
636 
637 
638  // Vector n_eplane = const_z;
639  // Vector n_hplane = -const_y;
640  // Vector n_normal = const_x;
641 
642  Vector ant_normal; //Vector normal to the face of the antenna
643 
644  // double hitangle_e, hitangle_h; // angle the ray hits the antenna wrt e-plane, h-plane
645  double hitangle_e_all[Anita::NANTENNAS_MAX]; // hit angles rel. to e plane stored for each antenna
646  double hitangle_h_all[Anita::NANTENNAS_MAX]; // hit angles rel. to h plane stored for each antenna
647 
648  double eventsfound_db=0; // same, for double bang
649  double eventsfound_nfb=0; // for taus
650 
651  // positions in earth frame
652  double horizcoord=0; // x component of interaction position
653  double vertcoord=0; // y component of interaction position
654 
655  double dist_int_bn_2d=0; // 2-d (surface) distance between interaction and balloon
656 
657  double cosalpha; // angle between nu momentum and surface normal at earth entrance point
658  double mytheta;
659  double cosbeta0; // angle between nu momentum and surface normal at interaction point.
660  double mybeta;
661  double nuexitice=0;
662  double theta_pol_measured; // theta of the polarization as measured at the payload (for now we don't correct for the 10 degree cant)
663 
664  double ptaui=0;
665  double ptauf =0;
666 
667 
668  double sourceLon;
669  double sourceAlt;
670  double sourceLat;
671  double sourceMag;
672 
673  Vector n_nutraject_ontheground; //direction of the neutrino from the person standing on the ground just below the balloon.
674  Vector n_pol; // direction of polarization
675  // Vector n_pol_eachboresight[Anita::NLAYERS_MAX][Anita::NPHI_MAX]; // direction of polarization of signal seen at each antenna
676  Vector n_pol_db; // same, double bangs
677 
678  int l3trig[Anita::NPOL]; // 16 bit number which says which phi sectors pass L3 V-POL
679  // For each trigger layer, which "clumps" pass L2. 16 bit, 16 bit and 8 bit for layers 1 & 2 and nadirs
680  int l2trig[Anita::NPOL][Anita::NTRIGGERLAYERS_MAX];
681  //For each trigger layer, which antennas pass L1. 16 bit, 16 bit and 8 bit and layers 1, 2 and nadirs
682  int l1trig[Anita::NPOL][Anita::NTRIGGERLAYERS_MAX];
683 
684  // these are declared here so that they can be stuck into trees
685  int loctrig[Anita::NPOL][Anita::NLAYERS_MAX][Anita::NPHI_MAX]; //counting how many pass trigger requirement
686 
687  int loctrig_nadironly[Anita::NPOL][Anita::NPHI_MAX]; //counting how many pass trigger requirement
688 
689  int nchannels_triggered = 0; // total number of channels triggered
690  int nchannels_perrx_triggered[48]; // total number of channels triggered
691 
692  eventsfound=0.; // sums weights for events that pass
693 
694  Tools::Zero(count1->npass, 2); // sums events that pass, without weights
695  Tools::Zero(sum, 3);
696  eventsfound_db=0;
697  eventsfound_nfb=0;
698 
699  Tools::Zero(eventsfound_binned, NBINS);
700  Tools::Zero(eventsfound_binned_e, NBINS);
701  Tools::Zero(eventsfound_binned_mu, NBINS);
702  Tools::Zero(eventsfound_binned_tau, NBINS);
703  Tools::Zero(eventsfound_nfb_binned, NBINS);
704 
705  //we pick both the interaction point and its corresponding mirror point
706 
707 
708 
709  //to determine where the cut should be.
710  stemp=string(outputdir.Data())+"/icefinal"+run_num+".root";
711  TFile *hfile = new TFile(stemp.c_str(), "RECREATE", "ice");
712 
713 
714  TTree *finaltree = new TTree("passing_events", "passing_events"); // finaltree filled for all events that pass
715  finaltree->Branch("inu", &inu, "inu/I");
716  finaltree->Branch("vmmhz_min", &vmmhz_min, "vmmhz_min/D");
717  finaltree->Branch("vmmhz_max", &vmmhz_max, "vmmhz_max/D");
718  finaltree->Branch("thresholdsAnt", &thresholdsAnt, "thresholdsAnt[48][2][5]/D");
719  finaltree->Branch("thresholdsAntPass", &thresholdsAntPass, "thresholdsAntPass[48][2][5]/D");
720  finaltree->Branch("deadTime", &anita1->deadTime, "deadTime/D");
721  finaltree->Branch("horizcoord", &horizcoord, "horizcoord/D");
722  finaltree->Branch("vertcoord", &vertcoord, "vertcoord/D");
723  finaltree->Branch("horizcoord_bn", &bn1->horizcoord_bn, "horizcoord_bn/D");
724  finaltree->Branch("vertcoord_bn", &bn1->vertcoord_bn, "vertcoord_bn/D");
725  finaltree->Branch("r_bn", &r_bn_array, "r_bn_array[3]/D");
726  finaltree->Branch("n_bn", &n_bn_array, "n_bn_array[3]/D");
727  finaltree->Branch("longitude_bn", &longitude_this, "longitude_bn/D");
728  finaltree->Branch("heading_bn", &heading_this, "heading_bn/D");
729  finaltree->Branch("gps_offset", &gps_offset, "gps_offset/D");
730  // this one is just weight due to earth absorption
731  finaltree->Branch("weight1", &weight1, "weight1/D");
732  // this is the total weight - the one you want to use!
733  finaltree->Branch("weight", &weight, "weight/D");
734  finaltree->Branch("logweight", &logweight, "logweight/D");
735  finaltree->Branch("posnu", &posnu_array, "posnu_array[3]/D");
736  finaltree->Branch("nnu", &nnu_array, "nnu_array[3]/D");
737  finaltree->Branch("n_exit2bn", &n_exit2bn_array, "n_exit2bn_array[5][3]/D");
738  finaltree->Branch("n_exit_phi", &n_exit_phi, "n_exit_phi/D");
739  finaltree->Branch("rfexit", &rfexit_array, "rfexit_array[5][3]/D");
740 
741  finaltree->Branch("pnu", &pnu, "pnu/D");
742  finaltree->Branch("elast_y", &elast_y, "elast_y/D");
743  finaltree->Branch("emfrac", &emfrac, "emfrac/D");
744  finaltree->Branch("hadfrac", &hadfrac, "hadfrac/D");
745  finaltree->Branch("sumfrac", &sumfrac, "sumfrac/D");
746  finaltree->Branch("nuexitice", &nuexitice, "nuexitice/D");
747  finaltree->Branch("l3trig", &l3trig, "l3trig[2]/I");
748  finaltree->Branch("l2trig", &l2trig, "l2trig[2][3]/I");
749  finaltree->Branch("l1trig", &l1trig, "l1trig[2][3]/I");
750  finaltree->Branch("phiTrigMask", &anita1->phiTrigMask, "phiTrigMask/s");
751  finaltree->Branch("phiTrigMaskH", &anita1->phiTrigMaskH, "phiTrigMaskH/s");
752  finaltree->Branch("l1TrigMask", &anita1->l1TrigMask, "l1TrigMask/s");
753  finaltree->Branch("l1TrigMaskH", &anita1->l1TrigMaskH, "l1TrigMaskH/s");
754  finaltree->Branch("max_antenna0", &max_antenna0, "max_antenna0/I");
755  finaltree->Branch("max_antenna1", &max_antenna1, "max_antenna1/I");
756  finaltree->Branch("max_antenna2", &max_antenna2, "max_antenna2/I");
757 
758  finaltree->Branch("viewangle", &viewangle, "viewangle/D");
759  finaltree->Branch("offaxis", &offaxis, "offaxis/D");
760  finaltree->Branch("rx0_signal_eachband", &rx0_signal_eachband, "rx0_signal_eachband[2][5]/D");
761  finaltree->Branch("rx0_threshold_eachband", &rx0_threshold_eachband, "rx0_threshold_eachband[2][5]/D");
762  finaltree->Branch("rx0_noise_eachband", &rx0_noise_eachband, "rx0_noise_eachband[2][5]/D");
763  finaltree->Branch("rx0_passes_eachband", &rx0_passes_eachband, "rx0_passes_eachband[2][5]/I");
764  finaltree->Branch("e_component", &e_component, "e_component[48]/D");
765  finaltree->Branch("h_component", &h_component, "h_component[48]/D");
766  finaltree->Branch("dist_int_bn_2d", &dist_int_bn_2d, "dist_int_bn_2d/D");
767 
768  finaltree->Branch("cosalpha", &cosalpha, "cosalpha/D");
769  finaltree->Branch("mytheta", &mytheta, "mytheta/D");
770  finaltree->Branch("cosbeta0", &cosbeta0, "cosbeta0/D");
771  finaltree->Branch("mybeta", &mybeta, "mybeta/D");
772 
773  //Begin block added by Stephen for verification plots
774  finaltree->Branch("fresnel1", &fresnel1, "fresnel1/D");
775  finaltree->Branch("fresnel2", &fresnel2, "fresnel2/D");
776  finaltree->Branch("mag1", &mag1, "mag1/D");
777  finaltree->Branch("mag2", &mag2, "mag2/D");
778  finaltree->Branch("t_coeff_pokey", &t_coeff_pokey, "t_coeff_pokey/D");
779  finaltree->Branch("t_coeff_slappy", &t_coeff_slappy, "t_coeff_slappy/D");
780 
781  finaltree->Branch("hitangle_e_all", &hitangle_e_all, "hitangle_e_all[48]/D");
782  finaltree->Branch("hitangle_h_all", &hitangle_h_all, "hitangle_h_all[48]/D");
783 
784  finaltree->Branch("e_comp_max1", &e_comp_max1, "e_comp_max1/D");
785  finaltree->Branch("h_comp_max1", &h_comp_max1, "h_comp_max1/D");
786  finaltree->Branch("e_comp_max2", &e_comp_max2, "e_comp_max2/D");
787  finaltree->Branch("h_comp_max2", &h_comp_max2, "h_comp_max2/D");
788  finaltree->Branch("e_comp_max3", &e_comp_max3, "e_comp_max3/D");
789  finaltree->Branch("h_comp_max3", &h_comp_max3, "h_comp_max3/D");
790  finaltree->Branch("max_antenna_volts0", &max_antenna_volts0, "max_antenna_volts0/D");
791  finaltree->Branch("max_antenna_volts0_em", &max_antenna_volts0_em, "max_antenna_volts0_em/D");
792  finaltree->Branch("max_antenna_volts1", &max_antenna_volts1, "max_antenna_volts1/D");
793  finaltree->Branch("max_antenna_volts2", &max_antenna_volts2, "max_antenna_volts2/D");
794  finaltree->Branch("triggers", &nchannels_perrx_triggered, "nchannels_perrx_triggered[48]/I");
795  finaltree->Branch("nchannels_triggered", &nchannels_triggered, "nchannels_triggered/I");
796  finaltree->Branch("volts_rx_max", &volts_rx_max, "volts_rx_max/D");
797  finaltree->Branch("volts_rx_ave", &volts_rx_ave, "volts_rx_ave/D");
798  finaltree->Branch("volts_rx_sum", &volts_rx_sum, "volts_rx_sum/D");
799 
800  finaltree->Branch("volts_rx_max_highband", &volts_rx_max_highband, "volts_rx_max_highband/D");
801  finaltree->Branch("volts_rx_max_lowband", &volts_rx_max_lowband, "volts_rx_max_lowband/D");
802  finaltree->Branch("theta_pol_measured", &theta_pol_measured, "theta_pol_measured/D");
803  finaltree->Branch("theta_rf_atbn", &theta_rf_atbn, "theta_rf_atbn/D");
804  finaltree->Branch("theta_rf_atbn_measured", &theta_rf_atbn_measured, "theta_rf_atbn_measured/D");
805  finaltree->Branch("voltage", &voltagearray, "voltagearray[48]/D");
806  finaltree->Branch("vmmhz1m_max", &vmmhz1m_max, "vmmhz1m_max/D");
807  finaltree->Branch("vmmhz_lowfreq", &vmmhz_lowfreq, "vmmhz_lowfreq/D");
808 
809  finaltree->Branch("deltheta_em_max", &deltheta_em_max, "deltheta_em_max/D");
810  finaltree->Branch("deltheta_had_max", &deltheta_had_max, "deltheta_had_max/D");
811  finaltree->Branch("r_enterice", &r_enterice_array, "r_enterice_array[3]/D");
812  finaltree->Branch("n_exit2bn_db", &n_exit2bn_db_array, "n_exit2bn_db_array[5][3]/D");
813 
814  finaltree->Branch("rfexit_db", &rfexit_db_array, "rfexit_db_array[5][3]/D");
815  finaltree->Branch("r_in", &r_in_array, "r_in_array[3]/D");
816  finaltree->Branch("nsurf_rfexit", &nsurf_rfexit_array, "nsurf_rfexit_array[3]/D");
817  finaltree->Branch("nsurf_rfexit_db", &nsurf_rfexit_db_array, "nsurf_rfexit_db_array[3]/D");
818 
819  finaltree->Branch("ant_normal0", &ant_max_normal0_array, "ant_max_normal0_array[3]/D");
820  finaltree->Branch("ant_normal1", &ant_max_normal1_array, "ant_max_normal1_array[3]/D");
821  finaltree->Branch("ant_normal2", &ant_max_normal2_array, "ant_max_normal2_array[3]/D");
822  finaltree->Branch("vmmhz1m_visible", &vmmhz1m_visible, "vmmhz1m_visible/D");
823  finaltree->Branch("freq_bins", &freq_bins, "freq_bins/I");
824  finaltree->Branch("vmmhz", &vmmhz, "vmmhz[freq_bins]/D");
825 
826  finaltree->Branch("n_pol", &n_pol_array, "n_pol_array[3]/D");
827  finaltree->Branch("vmmhz_min_thatpasses", &vmmhz_min_thatpasses, "vmmhz_min_thatpasses/D");
828 
829  finaltree->Branch("anita1->PHI_OFFSET", &anita1->PHI_OFFSET, "anita1->PHI_OFFSET/D");
830  finaltree->Branch("igps", &bn1->igps, "igyps/I");
831  finaltree->Branch("volts_rx_rfcm_lab_e_all", &volts_rx_rfcm_lab_e_all, "volts_rx_rfcm_lab_e_all[48][512]/D");
832  finaltree->Branch("volts_rx_rfcm_lab_h_all", &volts_rx_rfcm_lab_h_all, "volts_rx_rfcm_lab_h_all[48][512]/D");
833  finaltree->Branch("ptaui", &ptaui, "ptaui/D");
834  finaltree->Branch("ptauf", &ptauf, "ptauf/D");
835  finaltree->Branch("sourceLon", &sourceLon, "sourceLon/D");
836  finaltree->Branch("sourceLat", &sourceLat, "sourceLat/D");
837  finaltree->Branch("sourceAlt", &sourceAlt, "sourceAlt/D");
838  finaltree->Branch("sourceMag", &sourceMag, "sourceMag/D");
839 
840  double rms_rfcm_e;
841  double rms_rfcm_h;
842  double rms_lab_e;
843  double rms_lab_h;
844 
845  double avgfreq_rfcm[Anita::NFREQ];
846  double avgfreq_rfcm_lab[Anita::NFREQ];
847  double freq[Anita::NFREQ];
848 
849  int pdgcode=-999;
850  UInt_t eventNumber;
851 
852 #ifdef ANITA_UTIL_EXISTS
853 
854  string outputAnitaFile =string(outputdir.Data())+"/SimulatedAnitaEventFile"+run_num+".root";
855  TFile *anitafileEvent = new TFile(outputAnitaFile.c_str(), "RECREATE");
856 
857  TTree *eventTree = new TTree("eventTree", "eventTree");
858  eventTree->Branch("event", &realEvPtr );
859  eventTree->Branch("run", &run_no, "run/I" );
860  eventTree->Branch("weight", &weight, "weight/D");
861 
862  outputAnitaFile =string(outputdir.Data())+"/SimulatedAnitaHeadFile"+run_num+".root";
863  TFile *anitafileHead = new TFile(outputAnitaFile.c_str(), "RECREATE");
864 
865  TTree *headTree = new TTree("headTree", "headTree");
866  headTree->Branch("header", &rawHeaderPtr );
867  headTree->Branch("weight", &weight, "weight/D");
868 
869  outputAnitaFile =string(outputdir.Data())+"/SimulatedAnitaGpsFile"+run_num+".root";
870  TFile *anitafileGps = new TFile(outputAnitaFile.c_str(), "RECREATE");
871 
872  TTree *adu5PatTree = new TTree("adu5PatTree", "adu5PatTree");
873  adu5PatTree->Branch("pat", &Adu5PatPtr );
874  adu5PatTree->Branch("eventNumber", &eventNumber, "eventNumber/I");
875  adu5PatTree->Branch("weight", &weight, "weight/D" );
876 
877 #ifdef ANITA3_EVENTREADER
878 
879  // Set AnitaVersion so that the right payload geometry is used
880  AnitaVersion::set(settings1->ANITAVERSION);
881 
882  outputAnitaFile =string(outputdir.Data())+"/SimulatedAnitaTruthFile"+run_num+".root";
883  TFile *anitafileTruth = new TFile(outputAnitaFile.c_str(), "RECREATE");
884 
885  TString icemcgitversion = TString::Format("%s", EnvironmentVariable::ICEMC_VERSION(outputdir));
886  printf("ICEMC GIT Repository Version: %s\n", icemcgitversion.Data());
887  unsigned int timenow = time(NULL);
888 
889  TTree *configAnitaTree = new TTree("configIcemcTree", "Config file and settings information");
890  configAnitaTree->Branch("gitversion", &icemcgitversion );
891  configAnitaTree->Branch("startTime", &timenow );
892  // configAnitaTree->Branch("settings", &settings1 );
893  configAnitaTree->Fill();
894 
895  TTree *triggerSettingsTree = new TTree("triggerSettingsTree", "Trigger settings");
896  triggerSettingsTree->Branch("dioderms", anita1->bwslice_dioderms_fullband_allchan, "dioderms[2][48][7]/D");
897  triggerSettingsTree->Branch("diodemean", anita1->bwslice_diodemean_fullband_allchan, "diodemean[2][48][7/D");
898  triggerSettingsTree->Fill();
899 
900  TTree *truthAnitaTree = new TTree("truthAnitaTree", "Truth Anita Tree");
901  truthAnitaTree->Branch("truth", &truthEvPtr );
902 #endif
903 
904  AnitaGeomTool *AnitaGeom1 = AnitaGeomTool::Instance();
905 
906 #endif
907 
908 
909  IceModel *antarctica = new IceModel(settings1->ICE_MODEL + settings1->NOFZ*10, settings1->CONSTANTICETHICKNESS * 1000 + settings1->CONSTANTCRUST * 100 + settings1->FIXEDELEVATION * 10 + 0, settings1->WEIGHTABSORPTION);
910  cout << "area of the earth's surface covered by antarctic ice is " << antarctica->ice_area << "\n";
911 
912  // fills arrays according to antenna specs
913  anita1->GetBeamWidths(settings1); // this is used if GAINS set to 0
914  // Antenna measured gain vs. frequency
915  anita1->ReadGains(); // this is used if GAINS set to 1
916  anita1->Set_gain_angle(settings1, sig1->NMEDIUM_RECEIVER);
917  if(settings1->WHICH == 2 || settings1->WHICH == 6) anita1->SetDiffraction(); // for the upper ring
918 
919 
920  // sets position of balloon and related quantities
921  // these are all passed as pointers
922  // theta, phi, altitude of balloon
923  // position of balloon, altitude and position of surface of earth (relative to the center of the earth) under balloon
924  bn1->SetDefaultBalloonPosition(antarctica);
925 
926  anita1->SetNoise(settings1, bn1, antarctica);
927  //pathtree->Fill(); //Added by Stephen for verification of path
928 
929  // find the maximum distance the interaction could be from the balloon and still be within the horizon.
930  antarctica->GetMAXHORIZON(bn1);
931 
932  // calculate the volume of ice seen by the balloon for all balloon positions
933  antarctica->CreateHorizons(settings1, bn1, bn1->theta_bn, bn1->phi_bn, bn1->altitude_bn, foutput);
934  cout << "Done with CreateHorizons.\n";
935 
936  // builds payload based on read inputs
937  anita1->GetPayload(settings1, bn1);
938 
939  if (settings1->TRIGGERSCHEME == 3 || settings1->TRIGGERSCHEME == 4 || settings1->TRIGGERSCHEME==5) {
940  Vector plusz(0., 0., 1.);
941  bn1->PickBalloonPosition(plusz, antarctica, settings1, anita1);
942  anita1->calculate_all_offsets();
943  double angle_theta=16.;
944  double angle_phi=0.;
945  Vector x = Vector(cos(angle_theta * RADDEG) * cos((angle_phi+11.25) * RADDEG),
946  cos(angle_theta * RADDEG) * sin((angle_phi+11.25) * RADDEG),
947  sin(angle_theta * RADDEG));
948  anita1->GetArrivalTimes(x,bn1,settings1);
949  cout << "end of getarrivaltimes\n";
950  }
951 
952  time_t raw_loop_start_time = time(NULL);
953  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;
954 
955 
956  // for averaging balloon altitude and distance from center of earth
957  // for comparing with Peter
958  double average_altitude=0.;
959  double average_rbn=0.;
960 
961  signal(SIGINT, interrupt_signal_handler); // This function call allows icemc to gracefully abort and write files as usual rather than stopping abruptly.
962 
963  // Setting gps offset for plotting direction wrt north
964  if (settings1->WHICH==7){
965  gps_offset=atan2(-0.7042,0.71)*DEGRAD;
966  } else if(settings1->WHICH==8){
967  gps_offset=atan2(-0.7085,0.7056)*DEGRAD;
968  } else if (settings1->WHICH==9 || settings1->WHICH==10){
969  gps_offset=45;
970  } else gps_offset=0;
971 
972  int antNum;
973 
974  // begin looping over NNU neutrinos doing the things
975  for (inu = 0; inu < NNU; inu++) {
976 
977  if (NNU >= 100) {
978  if (inu % (NNU / 100) == 0)
979  cout << inu << " neutrinos. " << (double(inu)/double(NNU)) * 100 << "% complete.\n";
980  }
981  else
982  cout << inu << " neutrinos. " << (double(inu) / double(NNU)) * 100 << "% complete.\n";
983 
984  eventNumber=(UInt_t)(run_no)*NNU+inu;
985  anita1->inu = inu;
986 
987  // Set seed of all random number generators to be dependent on eventNumber
988  setSeed(eventNumber);
989  anita1->passglobtrig[0]=0;
990  anita1->passglobtrig[1]=0;
991  passes_thisevent=0;
992  unmasked_thisevent=1;
993  vmmhz_min_thatpasses=1000; // initializing. want to find the minumum voltage that passes a
994 
995 
996  count_pass=0;
997  passestrigger=0;
998  chanceinhell2=0;
999  sec1->secondbang=false;
1000  count_total++;
1001  // initializing the voltage seen by each polarization of each antenna
1002  bn1->dtryingposition=0;
1003  for (int i=0; i<Anita::NFREQ;i++) {
1004  vmmhz[i] = 0.; // the full signal with all factors accounted for (1/r, atten. etc.)
1005  vmmhz_em[i]=0.; // for keeping track of just the em component of the shower
1006  } //Zero the vmmhz array - helpful for banana plots, shouldn't affect anything else - Stephen
1007 
1008  // Picks the balloon position and at the same time sets the masks and thresholds
1009  bn1->PickBalloonPosition(antarctica, settings1, inu, anita1, getRNG(RNG_BALLOON_POSITION)->Rndm());
1010 
1011  // find average balloon altitude and distance from center of earth for
1012  // making comparisons with Peter
1013  average_altitude+=bn1->altitude_bn/(double)NNU;
1014  average_rbn+=bn1->r_bn.Mag()/(double)NNU;
1015 
1016  realtime_this=bn1->realTime_flightdata;
1017  longitude_this=bn1->longitude;
1018  latitude_this=bn1->latitude;
1019  altitude_this=bn1->altitude;
1020  heading_this=bn1->heading;
1021 
1022 
1023  // pick random point in ice.
1024  // also get initial guess shower exit position
1025  // unit vector from shower exit to balloon.
1026  // get both positions of interaction point and its mirror point.
1027  //-------------------------------------------------------
1028  beyondhorizon = 0;
1029 
1030  // make a global trigger object (but don't touch the electric fences)
1031  globaltrig1 = new GlobalTrigger(settings1, anita1);
1032 
1033  Tools::Zero(anita1->arrival_times[0], Anita::NLAYERS_MAX*Anita::NPHI_MAX);
1034  Tools::Zero(anita1->arrival_times[1], Anita::NLAYERS_MAX*Anita::NPHI_MAX);
1035 
1036  anita1->calculateDelaysForEfficiencyScan();
1037 
1038  globaltrig1->volts_rx_rfcm_trigger.assign(16, vector <vector <double> >(3, vector <double>(0)));
1039  anita1->rms_rfcm_e_single_event = 0;
1040 
1041 
1042  for (int ilayer=0; ilayer < settings1->NLAYERS; ilayer++) { // loop over layers on the payload
1043  for (int ifold=0;ifold<anita1->NRX_PHI[ilayer];ifold++) { // ifold loops over phi
1044 
1045  antNum = anita1->GetRxTriggerNumbering(ilayer, ifold);
1046 
1047  ChanTrigger *chantrig1 = new ChanTrigger();
1048  chantrig1->InitializeEachBand(anita1);
1049 
1050 
1051 #ifdef ANITA_UTIL_EXISTS
1052  if (settings1->SIGNAL_FLUCT && (settings1->NOISEFROMFLIGHTDIGITIZER || settings1->NOISEFROMFLIGHTTRIGGER) )
1053  chantrig1->getNoiseFromFlight(settings1, anita1, antNum);
1054 
1055  if(!settings1->APPLYIMPULSERESPONSETRIGGER) chantrig1->injectImpulseAfterAntenna(anita1, antNum);
1056 #endif
1057 
1058 
1059  memset(chantrig1->volts_rx_forfft, 0, sizeof(chantrig1->volts_rx_forfft));
1060 
1061  chantrig1->TriggerPath(settings1, anita1, antNum, bn1);
1062 
1063  chantrig1->DigitizerPath(settings1, anita1, antNum, bn1);
1064 
1065  chantrig1->WhichBandsPass(settings1, anita1, globaltrig1, bn1, ilayer, ifold, viewangle-sig1->changle, emfrac, hadfrac, thresholdsAnt[antNum]);
1066 
1067  chantrig1->TimeShiftAndSignalFluct(settings1, anita1, ilayer, ifold, volts_rx_rfcm_lab_e_all, volts_rx_rfcm_lab_h_all);
1068 
1069  chantrig1->saveTriggerWaveforms(anita1, justSignal_trig[0][antNum], justSignal_trig[1][antNum], justNoise_trig[0][antNum], justNoise_trig[1][antNum]);
1070  chantrig1->saveDigitizerWaveforms(anita1, justSignal_dig[0][antNum], justSignal_dig[1][antNum], justNoise_dig[0][antNum], justNoise_dig[1][antNum]);
1071 
1072  // cout << inu << " " << ilayer << " " << ifold << endl;
1073  delete chantrig1;
1074 
1075  } //loop through the phi-fold antennas
1076  } //loop through the layers of antennas
1077 
1078  anita1->rms_rfcm_e_single_event = sqrt(anita1->rms_rfcm_e_single_event / (anita1->HALFNFOUR * settings1->NANTENNAS));
1079 
1080 
1081  for (int irx=0;irx<settings1->NANTENNAS;irx++) {
1082  nchannels_perrx_triggered[irx]=globaltrig1->nchannels_perrx_triggered[irx];
1083  }
1084 
1085  nchannels_triggered=Tools::iSum(globaltrig1->nchannels_perrx_triggered, settings1->NANTENNAS); // find total number of antennas that were triggered.
1086  volts_rx_ave=GetAverageVoltageFromAntennasHit(settings1, globaltrig1->nchannels_perrx_triggered, voltagearray, volts_rx_sum);
1087 
1088 
1090  // EVALUATE GLOBAL TRIGGER //
1091  // FOR VPOL AND HPOL //
1093 
1094  int thispasses[Anita::NPOL]={0,0};
1095 
1096  globaltrig1->PassesTrigger(settings1, anita1, discones_passing, 2, l3trig, l2trig, l1trig, settings1->antennaclump, loctrig, loctrig_nadironly, inu,
1097  thispasses);
1098 
1099  for (int i=0;i<2;i++) {
1100  for (int j=0;j<16;j++) {
1101  for (int k=0;k<anita1->HALFNFOUR;k++) {
1102  count1->nl1triggers[i][whichray]+=anita1->l1trig_anita3and4_inanita[i][j][k];
1103  }
1104  }
1105  }
1106 
1108  // Require that it passes //
1109  // global trigger //
1111  // for Anita-lite, Anita Hill, just L1 requirement on 2 antennas. This option is currently disabled
1112  // Save events that generate an RF trigger or that are part of the min bias sample
1113  // Minimum bias sample: save all events that we could see at the payload
1114  // Independentely from the fact that they generated an RF trigger
1115 
1116  if ( (thispasses[0]==1 && anita1->pol_allowed[0]==1)
1117  || (thispasses[1]==1 && anita1->pol_allowed[1]==1)
1118  || (settings1->TRIGTYPE==0 && count_pass>=settings1->NFOLD)
1119  || (settings1->MINBIAS==1)) {
1120  if (bn1->WHICHPATH==4)
1121  cout << "This event passes.\n";
1122 
1123  // cout << inu << endl;
1124 
1125  anita1->passglobtrig[0]=thispasses[0];
1126  anita1->passglobtrig[1]=thispasses[1];
1127 
1128  //calculate the phi angle wrt +x axis of the ray from exit to balloon
1129  n_exit_phi = Tools::AbbyPhiCalc(ray1->n_exit2bn[2][0], ray1->n_exit2bn[2][1]);
1130 
1131  // tags this event as passing
1132  passestrigger=1;
1133 
1134  crust_entered=0; //These are switches that let us tell how far a given neutrino penetrated. Clear them before entering Getchord.
1135  mantle_entered=0;
1136  core_entered=0;
1137 
1138 
1139  finaltree->Fill();
1140 
1141 #ifdef ANITA_UTIL_EXISTS
1142  realEvPtr = new UsefulAnitaEvent();
1143  rawHeaderPtr = new RawAnitaHeader();
1144  Adu5PatPtr = new Adu5Pat();
1145 
1146  Adu5PatPtr->latitude= bn1->latitude;
1147  Adu5PatPtr->longitude=bn1->longitude;
1148  Adu5PatPtr->altitude=bn1->altitude;
1149  Adu5PatPtr->realTime=bn1->realTime_flightdata;
1150  Adu5PatPtr->heading = bn1->heading;
1151  Adu5PatPtr->pitch = bn1->pitch;
1152  Adu5PatPtr->roll = bn1->roll;
1153  Adu5PatPtr->run = run_no;
1154 
1155  memset(realEvPtr->fNumPoints, 0, sizeof(realEvPtr->fNumPoints) );
1156  memset(realEvPtr->fVolts, 0, sizeof(realEvPtr->fVolts) );
1157  memset(realEvPtr->fTimes, 0, sizeof(realEvPtr->fTimes) );
1158 
1159  int fNumPoints = 260;
1160 
1161  for (int iant = 0; iant < settings1->NANTENNAS; iant++){
1162  //int IceMCAnt = GetIceMCAntfromUsefulEventAnt(anita1, AnitaGeom1, iant);
1163  int IceMCAnt = GetIceMCAntfromUsefulEventAnt(settings1, iant);
1164  int UsefulChanIndexH = AnitaGeom1->getChanIndexFromAntPol(iant, AnitaPol::kHorizontal);
1165  int UsefulChanIndexV = AnitaGeom1->getChanIndexFromAntPol(iant, AnitaPol::kVertical);
1166  realEvPtr->fNumPoints[UsefulChanIndexV] = fNumPoints;
1167  realEvPtr->fNumPoints[UsefulChanIndexH] = fNumPoints;
1168  realEvPtr->chanId[UsefulChanIndexV] = UsefulChanIndexV;
1169  realEvPtr->chanId[UsefulChanIndexH] = UsefulChanIndexH;
1170 
1171  for (int j = 0; j < fNumPoints; j++) {
1172  // convert seconds to nanoseconds
1173  realEvPtr->fTimes[UsefulChanIndexV][j] = j * anita1->TIMESTEP * 1.0E9;
1174  realEvPtr->fTimes[UsefulChanIndexH][j] = j * anita1->TIMESTEP * 1.0E9;
1175  // convert volts to millivolts
1176  realEvPtr->fVolts[UsefulChanIndexH][j] = volts_rx_rfcm_lab_h_all[IceMCAnt][j+64]*1000;
1177  realEvPtr->fVolts[UsefulChanIndexV][j] = volts_rx_rfcm_lab_e_all[IceMCAnt][j+64]*1000;
1178  realEvPtr->fCapacitorNum[UsefulChanIndexH][j] = 0;
1179  realEvPtr->fCapacitorNum[UsefulChanIndexV][j] = 0;
1180  }//end int j
1181  }// end int iant
1182 
1183  realEvPtr->eventNumber = eventNumber;
1184 
1185  rawHeaderPtr->eventNumber = eventNumber;
1186  rawHeaderPtr->surfSlipFlag = 0;
1187  rawHeaderPtr->errorFlag = 0;
1188 
1189  if (settings1->MINBIAS==1)
1190  rawHeaderPtr->trigType = 8; // soft-trigger
1191  else
1192  rawHeaderPtr->trigType = 1; // RF trigger
1193 
1194  rawHeaderPtr->run = run_no;
1195  // put the vpol only as a placeholder - these are only used in Anita-2 anyway
1196  rawHeaderPtr->upperL1TrigPattern = l1trig[0][0];
1197  rawHeaderPtr->lowerL1TrigPattern = l1trig[0][1];
1198  rawHeaderPtr->nadirL1TrigPattern = l1trig[0][2];
1199 
1200  rawHeaderPtr->upperL2TrigPattern = l2trig[0][0];
1201  rawHeaderPtr->lowerL2TrigPattern = l2trig[0][1];
1202  rawHeaderPtr->nadirL2TrigPattern = l2trig[0][2];
1203 
1204  if (settings1->WHICH<9){
1205  rawHeaderPtr->phiTrigMask = (short) anita1->phiTrigMask;
1206  rawHeaderPtr->l3TrigPattern = (short) l3trig[0];
1207  }
1208 
1209  rawHeaderPtr->calibStatus = 31;
1210  rawHeaderPtr->realTime = bn1->realTime_flightdata;
1211  rawHeaderPtr->triggerTime = bn1->realTime_flightdata;
1212  Adu5PatPtr->latitude= bn1->latitude;
1213  Adu5PatPtr->longitude=bn1->longitude;
1214  Adu5PatPtr->altitude=bn1->altitude;
1215  Adu5PatPtr->realTime=bn1->realTime_flightdata;
1216  Adu5PatPtr->heading = bn1->heading;
1217  Adu5PatPtr->pitch = bn1->pitch;
1218  Adu5PatPtr->roll = bn1->roll;
1219  Adu5PatPtr->run = run_no;
1220 
1221 #ifdef ANITA3_EVENTREADER
1222  if (settings1->WHICH==9 || settings1->WHICH==10) {
1223  rawHeaderPtr->setTrigPattern((short) l3trig[0], AnitaPol::kVertical);
1224  rawHeaderPtr->setTrigPattern((short) l3trig[1], AnitaPol::kHorizontal);
1225  rawHeaderPtr->setMask( (short) anita1->l1TrigMask, (short) anita1->phiTrigMask, AnitaPol::kVertical);
1226  rawHeaderPtr->setMask( (short) anita1->l1TrigMaskH, (short) anita1->phiTrigMaskH, AnitaPol::kHorizontal);
1227  }
1228 
1229  truthEvPtr = new TruthAnitaEvent();
1230  truthEvPtr->eventNumber = eventNumber;
1231  truthEvPtr->realTime = bn1->realTime_flightdata;
1232  truthEvPtr->run = run_no;
1233  truthEvPtr->nuMom = pnu;
1234  truthEvPtr->nu_pdg = pdgcode;
1235  memcpy(truthEvPtr->e_component, e_component, sizeof(e_component));
1236  memcpy(truthEvPtr->h_component, h_component, sizeof(h_component));
1237  memcpy(truthEvPtr->n_component, n_component, sizeof(n_component));
1238  memcpy(truthEvPtr->e_component_k ,e_component_kvector, sizeof(e_component_kvector));
1239  memcpy(truthEvPtr->h_component_k ,h_component_kvector, sizeof(h_component_kvector));
1240  memcpy(truthEvPtr->n_component_k ,n_component_kvector, sizeof(n_component_kvector));
1241 
1242  truthEvPtr->sourceLon = sourceLon;
1243  truthEvPtr->sourceLat = sourceLat;
1244  truthEvPtr->sourceAlt = sourceAlt;
1245  truthEvPtr->weight = weight;
1246  for (int i=0;i<3;i++){
1247  truthEvPtr->balloonPos[i] = -999;
1248  truthEvPtr->balloonDir[i] = -999;
1249  truthEvPtr->nuPos[i] = -999;
1250  truthEvPtr->nuDir[i] = -999;
1251  }
1252  for (int i=0;i<5;i++){
1253  for (int j=0;j<3;j++){
1254  truthEvPtr->rfExitNor[i][j] = ray1->n_exit2bn[i][j];
1255  truthEvPtr->rfExitPos[i][j] = ray1->rfexit[i][j];
1256  }
1257  }
1258  for (int i=0;i<48;i++){
1259  truthEvPtr->hitangle_e[i] = hitangle_e_all[i];
1260  truthEvPtr->hitangle_h[i] = hitangle_h_all[i];
1261  }
1262  if(settings1->ROUGHNESS){
1263  for (int i=0;i<Anita::NFREQ;i++)
1264  truthEvPtr->vmmhz[i] = -999;
1265  }
1266 
1267  memset(truthEvPtr->SNRAtTrigger, 0, sizeof(truthEvPtr->SNRAtTrigger) );
1268  memset(truthEvPtr->fSignalAtTrigger, 0, sizeof(truthEvPtr->fSignalAtTrigger) );
1269  memset(truthEvPtr->fNoiseAtTrigger, 0, sizeof(truthEvPtr->fNoiseAtTrigger) );
1270  memset(truthEvPtr->SNRAtDigitizer, 0, sizeof(truthEvPtr->SNRAtDigitizer) );
1271  memset(truthEvPtr->thresholds, 0, sizeof(truthEvPtr->thresholds) );
1272  memset(truthEvPtr->fDiodeOutput, 0, sizeof(truthEvPtr->fDiodeOutput) );
1273 
1274  truthEvPtr->maxSNRAtTriggerV=0;
1275  truthEvPtr->maxSNRAtTriggerH=0;
1276  truthEvPtr->maxSNRAtDigitizerV=0;
1277  truthEvPtr->maxSNRAtDigitizerH=0;
1278 
1279  for (int iant = 0; iant < settings1->NANTENNAS; iant++){
1280  int UsefulChanIndexH = AnitaGeom1->getChanIndexFromAntPol(iant, AnitaPol::kHorizontal);
1281  int UsefulChanIndexV = AnitaGeom1->getChanIndexFromAntPol(iant, AnitaPol::kVertical);
1282 
1283  truthEvPtr->SNRAtTrigger[UsefulChanIndexV] = Tools::calculateSNR(justSignal_trig[0][iant], justNoise_trig[0][iant]);
1284  truthEvPtr->SNRAtTrigger[UsefulChanIndexH] = Tools::calculateSNR(justSignal_trig[1][iant], justNoise_trig[1][iant]);
1285 
1286  if (truthEvPtr->SNRAtTrigger[UsefulChanIndexV]>truthEvPtr->maxSNRAtTriggerV) truthEvPtr->maxSNRAtTriggerV=truthEvPtr->SNRAtTrigger[UsefulChanIndexV];
1287  if (truthEvPtr->SNRAtTrigger[UsefulChanIndexH]>truthEvPtr->maxSNRAtTriggerH) truthEvPtr->maxSNRAtTriggerH=truthEvPtr->SNRAtTrigger[UsefulChanIndexH];
1288 
1289  truthEvPtr->SNRAtDigitizer[UsefulChanIndexV] = Tools::calculateSNR(justSignal_dig[0][iant], justNoise_dig[0][iant]);
1290  truthEvPtr->SNRAtDigitizer[UsefulChanIndexH] = Tools::calculateSNR(justSignal_dig[1][iant], justNoise_dig[1][iant]);
1291 
1292  if (truthEvPtr->SNRAtDigitizer[UsefulChanIndexV]>truthEvPtr->maxSNRAtDigitizerV) truthEvPtr->maxSNRAtDigitizerV=truthEvPtr->SNRAtDigitizer[UsefulChanIndexV];
1293  if (truthEvPtr->SNRAtDigitizer[UsefulChanIndexH]>truthEvPtr->maxSNRAtDigitizerH) truthEvPtr->maxSNRAtDigitizerH=truthEvPtr->SNRAtDigitizer[UsefulChanIndexH];
1294 
1295 
1296  truthEvPtr->thresholds[UsefulChanIndexV] = thresholdsAnt[iant][0][4];
1297  truthEvPtr->thresholds[UsefulChanIndexH] = thresholdsAnt[iant][1][4];
1298  int irx = iant;
1299  if (iant<16){
1300  if (iant%2) irx = iant/2;
1301  else irx = iant/2 + 1;
1302  }
1303 
1304  for (int j = 0; j < fNumPoints; j++) {
1305  truthEvPtr->fTimes[UsefulChanIndexV][j] = j * anita1->TIMESTEP * 1.0E9;
1306  truthEvPtr->fTimes[UsefulChanIndexH][j] = j * anita1->TIMESTEP * 1.0E9;
1307 
1308  truthEvPtr->fSignalAtTrigger[UsefulChanIndexV][j] = justSignal_trig[0][iant][j]*1000;
1309  truthEvPtr->fSignalAtTrigger[UsefulChanIndexH][j] = justSignal_trig[1][iant][j]*1000;
1310  truthEvPtr->fNoiseAtTrigger[UsefulChanIndexV][j] = justNoise_trig[0][iant][j]*1000;
1311  truthEvPtr->fNoiseAtTrigger[UsefulChanIndexH][j] = justNoise_trig[1][iant][j]*1000;
1312  truthEvPtr->fSignalAtDigitizer[UsefulChanIndexV][j] = justSignal_dig[0][iant][j]*1000;
1313  truthEvPtr->fSignalAtDigitizer[UsefulChanIndexH][j] = justSignal_dig[1][iant][j]*1000;
1314  truthEvPtr->fNoiseAtDigitizer[UsefulChanIndexV][j] = justNoise_dig[0][iant][j]*1000;
1315  truthEvPtr->fNoiseAtDigitizer[UsefulChanIndexH][j] = justNoise_dig[1][iant][j]*1000;
1316 
1317  truthEvPtr->fDiodeOutput[UsefulChanIndexV][j] = anita1->timedomain_output_allantennas[0][irx][j];
1318  truthEvPtr->fDiodeOutput[UsefulChanIndexH][j] = anita1->timedomain_output_allantennas[1][irx][j];
1319  }//end int j
1320 
1321  }// end int iant
1322 
1323 
1324  truthAnitaTree->Fill();
1325  delete truthEvPtr;
1326 #endif
1327 
1328  headTree->Fill();
1329  eventTree->Fill();
1330  adu5PatTree->Fill();
1331 
1332  delete realEvPtr;
1333  delete rawHeaderPtr;
1334  delete Adu5PatPtr;
1335 #endif
1336 
1337  sum_weights+=weight;
1338  neutrinos_passing_all_cuts++;
1339  anita1->tdata->Fill();
1340  } // end if passing global trigger conditions
1341  else {
1342  passes_thisevent=0; // flag this event as not passing
1343  }// end else event does not pass trigger
1344 
1345  delete globaltrig1;
1346 
1347  if (ABORT_EARLY){
1348  std::cout << "\n***********************************************************";
1349  std::cout << "\n* SIGINT received, aborting loop over events early.";
1350  std::cout << "\n* Stopped after event " << inu << " instead of " << NNU;
1351  std::cout << "\n* Any output which relied on NNU should be corrected for.";
1352  std::cout << "\n***********************************************************\n";
1353  foutput << "\n***********************************************************";
1354  foutput << "\n* SIGINT received, aborting loop over events early.";
1355  foutput << "\n* Stopped after event " << inu << " instead of " << NNU;
1356  foutput << "\n* Any output which relied on NNU should be corrected for.";
1357  foutput << "\n***********************************************************\n";
1358  break;
1359  }
1360  }//end NNU neutrino loop
1361 
1362 
1363 
1364 
1365 #ifdef ANITA_UTIL_EXISTS
1366 
1367  anitafileEvent->cd();
1368  eventTree->Write("eventTree");
1369  anitafileEvent->Close();
1370  delete anitafileEvent;
1371 
1372  anitafileHead->cd();
1373  headTree->Write("headTree");
1374  anitafileHead->Close();
1375  delete anitafileHead;
1376 
1377  anitafileGps->cd();
1378  adu5PatTree->Write("adu5PatTree");
1379  anitafileGps->Close();
1380  delete anitafileGps;
1381 
1382 #ifdef ANITA3_EVENTREADER
1383  anitafileTruth->cd();
1384  configAnitaTree->Write("configAnitaTree");
1385  truthAnitaTree->Write("truthAnitaTree");
1386  triggerSettingsTree->Write("triggerSettingsTree");
1387  anitafileTruth->Close();
1388  delete anitafileTruth;
1389 #endif
1390 
1391 #endif
1392 
1393 
1394  anita1->rms_rfcm[0] = sqrt(anita1->rms_rfcm[0] / (double)anita1->count_getnoisewaveforms)*1000.;
1395  anita1->rms_rfcm[1] = sqrt(anita1->rms_rfcm[1] / (double)anita1->count_getnoisewaveforms)*1000.;
1396  anita1->rms_lab[0] = sqrt(anita1->rms_lab[0] / (double)anita1->count_getnoisewaveforms)*1000.;
1397  anita1->rms_lab[1] = sqrt(anita1->rms_lab[1] / (double)anita1->count_getnoisewaveforms)*1000.;
1398 
1399  cout << "RMS noise in rfcm e-pol is " << anita1->rms_rfcm[0] << " mV.\n";
1400  cout << "RMS noise in rfcm h-pol is " << anita1->rms_rfcm[1] << " mV.\n";
1401  cout << "RMS noise in lab e-pol is " << anita1->rms_lab[0] << "mV.\n";
1402  cout << "RMS noise in lab h-pol is " << anita1->rms_lab[1] << "mV.\n";
1403  for (int i=0;i<Anita::NFREQ;i++) {
1404  anita1->avgfreq_rfcm[i]/=(double)anita1->count_getnoisewaveforms;
1405  anita1->avgfreq_rfcm_lab[i]/=(double)anita1->count_getnoisewaveforms;
1406  }
1407 
1408  rms_rfcm_e=anita1->rms_rfcm[0];
1409  rms_rfcm_h=anita1->rms_rfcm[1];
1410  rms_lab_e=anita1->rms_lab[0];
1411  rms_lab_h=anita1->rms_lab[1];
1412  for (int i=0;i<Anita::NFREQ;i++) {
1413  avgfreq_rfcm[i]=anita1->avgfreq_rfcm[i];
1414  avgfreq_rfcm_lab[i]=anita1->avgfreq_rfcm_lab[i];
1415  freq[i]=anita1->freq[i];
1416  }
1417 
1418 
1419  // for each neutrino flavor, fraction each contributes to sensitivity.
1420  sum_frac[0]=sum[0]/eventsfound;
1421  sum_frac[1]=sum[1]/eventsfound;
1422  sum_frac[2]=sum[2]/eventsfound;
1423 
1424  // for taus.
1425  sum_frac_db[0]=sum[0]/(eventsfound+eventsfound_db+eventsfound_nfb);
1426  sum_frac_db[1]=sum[1]/(eventsfound+eventsfound_db+eventsfound_nfb);
1427  sum_frac_db[2]=(sum[2]+eventsfound_db+eventsfound_nfb)/(eventsfound+eventsfound_db+eventsfound_nfb);
1428  //if (tree17->GetEntries()<settings1->HIST_MAX_ENTRIES && !settings1->ONLYFINAL && HIST==1)
1429  //tree17->Fill();
1430 
1431 
1432  cout << "closing file.\n";
1433  CloseTFile(hfile);
1434 
1435  time_t raw_end_time = time(NULL);
1436  struct tm * end_time = localtime(&raw_end_time);
1437  cout << "Date and time at end of run are: " << asctime (end_time) << "\n";
1438  cout<<"Total time elapsed is "<<(int)((raw_end_time - raw_start_time)/60)<<":"<< ((raw_end_time - raw_start_time)%60)<<endl;
1439 
1440  foutput << "\nTotal time elapsed in run is " <<(int)((raw_end_time - raw_start_time)/60)<<":"<< ((raw_end_time - raw_start_time)%60)<<endl;
1441  anita1->fdata->Write();
1442  anita1->fdata->Close();
1443 
1444  delete anita1;
1445  return 0;
1446 
1447 } //END MAIN PROGRAM
1448 
1449 
1450 
1451 
1452 
1453 
1454 
1455 
1456 
1457 //
1458 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1459 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1460 //
1461 //
1462 // Auxiliary functions
1463 //
1464 //
1465 //
1466 
1467 void IntegrateBands(Anita *anita1, int k, Screen *panel1, double *freq, double scalefactor, double *sumsignal) {
1468  for (int j=0;j<5;j++) {
1469  // if this frequency is in this bandwidth slice
1470  for (int jpt=0; jpt<panel1->GetNvalidPoints(); jpt++){
1471  if (anita1->bwslice_min[j]<=freq[k] && anita1->bwslice_max[j]>freq[k])
1472  sumsignal[j]+=panel1->GetVmmhz_freq(jpt*Anita::NFREQ + k)*(freq[k+1]-freq[k])*scalefactor;
1473  }
1474  }
1475 }
1476 //end IntegrateBands()
1477 
1478 
1479 void Integrate(Anita *anita1, int j, int k, double *vmmhz, double *freq, double scalefactor, double sumsignal) {
1480  // if this frequency is in this bandwidth slice
1481  if (anita1->bwslice_min[j]<=freq[k] && anita1->bwslice_max[j]>freq[k])
1482  sumsignal+=vmmhz[k]*(freq[k+1]-freq[k])*scalefactor;
1483 }
1484 //end Integrate()
1485 
1486 
1487 void WriteNeutrinoInfo(Position &posnu, Vector &nnu, Position &r_bn, double altitude_int, string nuflavor, string current, double elast_y, ofstream &nu_out) {
1488  nu_out << "\n" << inu << "\t" << posnu[0] << " " << posnu[1] << " " << posnu[2] << "\t" << altitude_int << "\t" << nnu[0] << " " << nnu[1] << " " << nnu[2] << "\t" << r_bn[0] << " " << r_bn[1] << " " << r_bn[2] << "\t" << nuflavor << "\t" << current << "\t" << elast_y << "\n\n";
1489 }
1490 //end WriteNeutrinoInfo()
1491 
1492 
1493 
1494 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
1495  return EarthModel::R_EARTH*acos((altitude_bn+EarthModel::R_EARTH)/EarthModel::R_EARTH*(1-sin(beta)*sin(beta))+1/EarthModel::R_EARTH*sin(beta)*sqrt((altitude_bn+EarthModel::R_EARTH)*(altitude_bn+EarthModel::R_EARTH)*sin(beta)*sin(beta)-2*EarthModel::R_EARTH*altitude_bn-altitude_bn*altitude_bn));
1496 }
1497 //end GetAirDistance()
1498 
1499 
1500 double GetAverageVoltageFromAntennasHit(Settings *settings1, int *nchannels_perrx_triggered, double *voltagearray, double& volts_rx_sum) {
1501  double sum=0;
1502  int count_hitantennas=0;
1503  for (int i=0;i<settings1->NANTENNAS;i++) {
1504  if (nchannels_perrx_triggered[i]>=3) {
1505  sum+=voltagearray[i];
1506  count_hitantennas++;
1507  } //if
1508  } //for
1509  volts_rx_sum = sum;
1510  sum = sum/(double)count_hitantennas;
1511  return sum;
1512 }
1513 //end GetAverageVoltageFromAntennasHit()
1514 
1515 
1516 Vector GetPolarization(const Vector &nnu, const Vector &nrf2_iceside) {
1517  // Want to find a unit vector in the same plane as nnu and n_refr,
1518  // but perpendicular to n_refr, pointing away from nnu.
1519 
1520  // cross nnu with n_refr to get the direction of the B field.
1521  Vector n_bfield = nnu.Cross(nrf2_iceside);
1522  // cross b-field with nrf2_iceside to get the polarization vector.
1523  Vector n_pol = n_bfield.Cross(nrf2_iceside);
1524  n_pol = n_pol.Unit();
1525  // check and make sure E-field is pointing in the right direction.
1526  if (nnu*nrf2_iceside>0 && n_pol*nnu>0){
1527  cout << "error in GetPolarization. Event is " << inu << "\n";
1528  }
1529  return n_pol;
1530 }
1531 //end GetPolarization()
1532 
1533 
1534 void CloseTFile(TFile *hfile) {
1535  hfile->cd();
1536  hfile->Write();
1537  hfile->Close();
1538 }
1539 //end CloseTFile()
1540 
1541 
1542 double IsItDoubleBang(double exitlength, double plepton) {
1543  double gamma=plepton/MTAU;
1544  return 1-exp(-1*exitlength/(TAUDECAY_TIME*CLIGHT*gamma));
1545 }
1546 //end IsItDoubleBang()
1547 
1548 
1549 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) {
1550  double rnd1=0;
1551  double rnd2=2;
1552  double gamma=pnu/MTAU;
1553 
1554  if (exp(-1*nuexitlength/(TAUDECAY_TIME*CLIGHT*gamma))>0.999){
1555  rnd1=getRNG(RNG_SECOND_BANG)->Rndm()*nuexitlength;
1556  }
1557  else {
1558  while (rnd2>1-exp(-1*rnd1/(TAUDECAY_TIME*CLIGHT*gamma))) {
1559  rnd1=getRNG(RNG_SECOND_BANG)->Rndm()*nuexitlength;
1560  rnd2=getRNG(RNG_SECOND_BANG)->Rndm();
1561  } //while
1562  } //else
1563  posnu2 = posnu + rnd1*nnu;
1564  rfexit_db = antarctica1->Surface(posnu2)*posnu2.Unit();
1565 
1566  // unit vector pointing to antenna from exit point.
1567  n_exit2bn_db = (r_bn - rfexit_db) / r_bn.Distance(rfexit_db);
1568 
1569  double cosangle=(n_exit2bn_db * posnu2) / posnu2.Mag();
1570  if (cosangle<0){
1571  return 0;
1572  }
1573  return 1;
1574 }
1575 //end WhereIsSecondBang()
1576 
1577 
1578 //the following is a new function only for reflected case.
1579 void Attenuate_down(IceModel *antarctica1, Settings *settings1, double& vmmhz_max, const Position &rfexit2, const Position &posnu, const Position &posnu_down) {
1580  double ATTENLENGTH=700;
1581  if(!settings1->VARIABLE_ATTEN){
1582  ATTENLENGTH=antarctica1->EffectiveAttenuationLength(settings1, posnu, 1);
1583  }
1584 
1585  int position_in_iceshelves=antarctica1->IceOnWater(posnu);
1586  int position_in_rossexcept=antarctica1->RossExcept(posnu);
1587  // int position_in_ross = antarctica->RossIceShelf(posnu);
1588  // int position_in_ronne = antarctica->RonneIceShelf(posnu);
1589  double dtemp=posnu_down.Distance(rfexit2)/ATTENLENGTH;
1590 
1591  if (dtemp<20) {
1592  // if(position_in_ross || position_in_ronne) {
1593  if(position_in_iceshelves && (!position_in_rossexcept)){
1594  // scalefactor_attenuation=0.310227766*exp(-dtemp);
1595  // vmmhz_max=vmmhz_max*exp(-dtemp)*0.310227766;//10% of power reflected
1596  scalefactor_attenuation=0.71*exp(-dtemp);
1597  vmmhz_max=vmmhz_max*0.71*exp(-dtemp);//50% of power reflected. -3dB
1598  } //end if
1599  else if(position_in_rossexcept){
1600  scalefactor_attenuation=0.1*exp(-dtemp);
1601  vmmhz_max=0.1*vmmhz_max*exp(-dtemp);//1% of power reflected. -20dB
1602  }//end else if
1603  else {
1604  scalefactor_attenuation=sqrt(0.001)*exp(-dtemp);
1605  vmmhz_max=sqrt(0.001)*vmmhz_max*exp(-dtemp);//0.1% of power reflected.-30dB
1606  } //else
1607  } //if
1608  else {
1609  scalefactor_attenuation=0;
1610  vmmhz_max=0;
1611  } //else
1612 }
1613 //end Attenuate_down()
1614 
1615 
1616 void Attenuate(IceModel *antarctica1, Settings *settings1, double& vmmhz_max, double rflength, const Position &posnu) {
1617  double ATTENLENGTH=700; // constant attenuation length for now.
1618  if (!settings1->VARIABLE_ATTEN){
1619  ATTENLENGTH = antarctica1->EffectiveAttenuationLength(settings1, posnu, 0);
1620  }
1621 
1622  double dtemp=(rflength/ATTENLENGTH);
1623  if(!settings1->ROUGHNESS){
1624  if (dtemp<20) {
1625  scalefactor_attenuation=exp(-dtemp);
1626  vmmhz_max=vmmhz_max*exp(-dtemp);
1627  } //if
1628  else {
1629  scalefactor_attenuation=0;
1630  vmmhz_max=0;
1631  } //else
1632  }
1633  else{ // use a larger allowable value in case of roughness
1634  if (dtemp<10000) {
1635  scalefactor_attenuation=exp(-dtemp);
1636  vmmhz_max=vmmhz_max*exp(-dtemp);
1637  } //if
1638  else {
1639  scalefactor_attenuation=0;
1640  vmmhz_max=0;
1641  } //else
1642  }
1643 }
1644 //end Attenuate()
1645 
1646 
1647 void IsAbsorbed(double chord_kgm2, double len_int_kgm2, double &weight1) {
1648  // see if neutrino is absorbed
1649  // weighting works, but not to much purpose since nu's always
1650  // interact at these energies.
1651  double rtemp;
1652 
1653  rtemp=chord_kgm2/len_int_kgm2;
1654  if (rtemp<=20)
1655  weight1=exp(-rtemp);
1656  else
1657  weight1=0;
1658 }
1659 //end IsAbsorbed()
1660 
1661 
1662 void GetSmearedIncidentAngle(Vector &specular, Vector &nrf_iceside, Vector &n_exit2bn, double SMEARINCIDENTANGLE){
1663  // void GetSmearedIncidentAngle(Vector &specular, Vector &nsurf_rfexit, Vector &nrf_iceside, Vector &n_exit2bn, double SMEARINCIDENTANGLE, double theta_inc_smeared) {
1664  // Smear the incident angle for roughness studies
1665  specular+=nrf_iceside; // specular is the ray that we got from Snell's law
1666  Vector parallel_to_surface; // find vector parallel to surface to rotate the vector around
1667  parallel_to_surface+=n_exit2bn; // want to cross specular with n_exit2bn
1668  parallel_to_surface.Cross(specular);
1669  nrf_iceside.Rotate(SMEARINCIDENTANGLE*(2*getRNG(RNG_SMEARED_INCIDENT_ANGLE)->Rndm()-1.), parallel_to_surface); // smear the incident ray
1670  // theta_inc_smeared=acos(nrf_iceside.Dot(nsurf_rfexit));
1671 }
1672 //end GetSmearedIncidentAngle()
1673 
1674 
1675 int GetRayIceSide(const Vector &n_exit2rx, const Vector &nsurf_rfexit, double nexit, double nenter, Vector &nrf2_iceside) {
1676  // this function performs snell's law in three dimensions
1677  double costh=0;
1678  double NRATIO=nexit/nenter;
1679  costh=(n_exit2rx*nsurf_rfexit)/(n_exit2rx.Mag() * nsurf_rfexit.Mag()); // cos(theta) of the transmission angle
1680 
1681  if (costh<0) {
1682  //cout << "returning 0. inu is " << inu << "\n";
1683  return 0;
1684  }
1685  double sinth=sqrt(1 - costh*costh);
1686  double factor=NRATIO*costh-sqrt(1-(NRATIO*sinth*NRATIO*sinth));
1687  nrf2_iceside = -factor*nsurf_rfexit + NRATIO*n_exit2rx;
1688  nrf2_iceside = nrf2_iceside.Unit(); // normalize
1689  return 1;
1690 }
1691 //end GetRayIceSide()
1692 
1693 
1694 
1695 double ScaleVmMHz(double vmmhz1m_max, const Position &posnu1, const Position &r_bn) {
1696  double dtemp= r_bn.Distance(posnu1);
1697  vmmhz1m_max= vmmhz1m_max/dtemp;
1698  scalefactor_distance=1/dtemp;
1699  //cout << "dtemp is " << dtemp << "\n";
1700  return vmmhz1m_max;
1701 }
1702 //end ScaleVmMHz()
1703 
1704 
1705 void SetupViewangles(Signal *sig1) {
1706  double viewangle_max=90.*RADDEG;
1707  double viewangle_min=30.*RADDEG;
1708  for (int i=0;i<NVIEWANGLE-2;i++) {
1709  viewangles[i]=viewangle_max-(viewangle_max-viewangle_min)/(double)(NVIEWANGLE-2)*(double)i;
1710  }
1711  viewangles[NVIEWANGLE-2]=acos(1/sig1->N_DEPTH);
1712  viewangles[NVIEWANGLE-1]=90.*RADDEG;
1713 }
1714 //end SetupViewAngles()
1715 
1716 
1717 double GetThisAirColumn(Settings* settings1, Position r_in, Vector nnu, Position posnu, double *col1, double& cosalpha, double& mytheta, double& cosbeta0, double& mybeta) {
1718  double myair=0; // this is the output
1719  // it is the column of air in kg/m^2
1720  cosalpha=(r_in * nnu) / r_in.Mag(); // cosangle that the neutrino enters the earth wrt surface normal at its entrry point
1721  mytheta=(double)(acos(cosalpha)*DEGRAD)-90.; // turn this into an angle
1722 
1723  //------------------added on Dec 8------------------------
1724  if (settings1->ATMOSPHERE) {
1725  int index11=int(mytheta*10.); // which index this theta corresponds to
1726  int index12=index11+1;
1727  // find column of air at this theta
1728  myair=(col1[index11]+(col1[index12]-col1[index11])*(mytheta*10.-double(index11)))*10.;//unit is kg/m^2
1729  }
1730  else
1731  myair=0.;//don't include effect of atmosphere
1732 
1733  //cout<<"mytheta="<<mytheta<<"; myair="<<myair<<endl;
1734  //------------------added on Dec 8------------------------
1735  cosbeta0= (posnu * nnu) / posnu.Mag(); // cos angle of neutrino wrt person standing over the interaction point
1736  mybeta=(double)(acos(cosbeta0)*DEGRAD)-90.; // turn that into a theta
1737  return myair;
1738 }
1739 //end GetThisAirColumn()
1740 
1741 
1742 void GetAir(double *col1) {
1743  double nothing;
1744  ifstream air1(ICEMC_SRC_DIR+"/data/atmosphere.dat"); // length of chord in air vs. theta (deg)
1745  //where theta is respect to "up"
1746  // binned in 0.1 degrees
1747  for(int iii=0;iii<900;iii++) {
1748  air1>>nothing>>col1[iii];
1749  } // read in chord lengths
1750 }
1751 //end GetAir()
1752 
1753 
1754 int TIR(const Vector &n_surf, const Vector &nrf2_iceside, double N_IN, double N_OUT) {
1755  double test=sin(nrf2_iceside.Angle(n_surf))*N_IN/N_OUT;
1756  if(test>=1)
1757  return 1;
1758  else
1759  return 0;
1760 
1761  return 0;
1762 }
1763 //end TIR()
1764 
1765 
1766 double GetViewAngle(const Vector &nrf2_iceside, const Vector &nnu) {
1767  // get viewing angle of shower
1768  double dtemp=nrf2_iceside*nnu;
1769  if (dtemp>=1 && dtemp<1.02)
1770  dtemp=0.999999;
1771  if (dtemp<=-1 && dtemp>-1.02)
1772  dtemp=-0.9999999;
1773 
1774  return acos(dtemp);
1775 }
1776 //end ())etViewAngle
1777 
1778 
1779 TStyle* RootStyle() {
1780  TStyle *RootStyle = new TStyle("Root-Style", "The Perfect Style for Plots ;-)");
1781 
1782 #ifdef __CINT__
1783  TStyle *GloStyle;
1784  GloStyle = gStyle; // save the global style reference
1785  gStyle = RootStyle;
1786 #endif
1787  // otherwise you need to call TROOT::SetStyle("Root-Style")
1788 
1789  // Paper size
1790  RootStyle->SetPaperSize(TStyle::kUSLetter);
1791 
1792  // Canvas
1793  RootStyle->SetCanvasColor (0);
1794  RootStyle->SetCanvasBorderSize(10);
1795  RootStyle->SetCanvasBorderMode(0);
1796  RootStyle->SetCanvasDefH (600);
1797  RootStyle->SetCanvasDefW (600);
1798  RootStyle->SetCanvasDefX (10);
1799  RootStyle->SetCanvasDefY (10);
1800 
1801  // Pads
1802  RootStyle->SetPadColor (0);
1803  RootStyle->SetPadBorderSize (10);
1804  RootStyle->SetPadBorderMode (0);
1805  // RootStyle->SetPadBottomMargin(0.13);
1806  RootStyle->SetPadBottomMargin(0.16);
1807  RootStyle->SetPadTopMargin (0.08);
1808  RootStyle->SetPadLeftMargin (0.18);
1809  RootStyle->SetPadRightMargin (0.05);
1810  RootStyle->SetPadGridX (0);
1811  RootStyle->SetPadGridY (0);
1812  RootStyle->SetPadTickX (1);
1813  RootStyle->SetPadTickY (1);
1814 
1815  // Frames
1816  RootStyle->SetFrameFillStyle ( 0);
1817  RootStyle->SetFrameFillColor ( 0);
1818  RootStyle->SetFrameLineColor ( 1);
1819  RootStyle->SetFrameLineStyle ( 0);
1820  RootStyle->SetFrameLineWidth ( 2);
1821  RootStyle->SetFrameBorderSize(10);
1822  RootStyle->SetFrameBorderMode( 0);
1823 
1824 
1825  // Histograms
1826  RootStyle->SetHistFillColor(0);
1827  RootStyle->SetHistFillStyle(1);
1828  RootStyle->SetHistLineColor(1);
1829  RootStyle->SetHistLineStyle(0);
1830  RootStyle->SetHistLineWidth(2);
1831 
1832  // Functions
1833  RootStyle->SetFuncColor(1);
1834  RootStyle->SetFuncStyle(0);
1835  RootStyle->SetFuncWidth(1);
1836 
1837  //Legends
1838  RootStyle->SetStatBorderSize(2);
1839  RootStyle->SetStatFont (42);
1840  // RootStyle->SetOptStat (111111);
1841  RootStyle->SetOptStat (0);
1842  RootStyle->SetStatColor (0);
1843  RootStyle->SetStatX (0.93);
1844  RootStyle->SetStatY (0.90);
1845  RootStyle->SetStatFontSize (0.07);
1846  // RootStyle->SetStatW (0.2);
1847  // RootStyle->SetStatH (0.15);
1848 
1849  // Labels, Ticks, and Titles
1850  RootStyle->SetTickLength ( 0.015, "X");
1851  RootStyle->SetTitleSize ( 0.10, "X");
1852  RootStyle->SetTitleOffset( 1.20, "X");
1853  RootStyle->SetTitleBorderSize(0);
1854  // RootStyle->SetTitleFontSize((double)3.);
1855  RootStyle->SetLabelOffset( 0.015, "X");
1856  RootStyle->SetLabelSize ( 0.050, "X");
1857  RootStyle->SetLabelFont ( 42 , "X");
1858  RootStyle->SetTickLength ( 0.015, "Y");
1859  RootStyle->SetTitleSize ( 0.10, "Y");
1860  RootStyle->SetTitleOffset( 0.600, "Y");
1861  RootStyle->SetLabelOffset( 0.015, "Y");
1862  RootStyle->SetLabelSize ( 0.050, "Y");
1863  RootStyle->SetLabelFont ( 42 , "Y");
1864  RootStyle->SetTitleFont (42, "XY");
1865  RootStyle->SetTitleColor (1);
1866 
1867  // Options
1868  RootStyle->SetOptFit (0);
1869  RootStyle->SetMarkerStyle(20);
1870  RootStyle->SetMarkerSize(0.4);
1871 
1872  // cout << ">> Style initialized with the Root Style!" << endl;
1873  // cout << ">> " << modified << endl << endl;
1874  return RootStyle;
1875 }
1876 //end RootStyle()
1877 
1878 
1879 
1880 
1881 void interrupt_signal_handler(int sig){
1882  signal(sig, SIG_IGN);
1883  ABORT_EARLY = true;
1884  return;
1885 }
1886 //end interrupt_signal_handler()
1887 
1888 
1889 #ifdef ANITA_UTIL_EXISTS
1890 //int GetIceMCAntfromUsefulEventAnt(Anita *anita1, AnitaGeomTool *AnitaGeom1, int UsefulEventAnt){
1891 int GetIceMCAntfromUsefulEventAnt(Settings *settings1, int UsefulEventAnt){
1892  //int layer_temp = IceMCLayerPosition[UsefulEventIndex][0];
1893  //int position_temp = IceMCLayerPosition[UsefulEventIndex][1];
1894  //int IceMCIndex = anita1->GetRx(layer_temp, position_temp);
1895  int IceMCAnt = UsefulEventAnt;
1896  if ((settings1->WHICH==9 || settings1->WHICH==10) && UsefulEventAnt<16) {
1897  IceMCAnt = (UsefulEventAnt%2==0)*UsefulEventAnt/2 + (UsefulEventAnt%2==1)*(UsefulEventAnt/2+8);
1898  }
1899 
1900  return IceMCAnt;
1901 }
1902 //end GetIceMCAntfromUsefulEventAnt()
1903 
1904 
1905 #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.
Double_t rfExitPos[5][3]
Position where the RF exits the ice- 5 iterations, 3 dimensions each.
Double_t fNoiseAtDigitizer[12 *9][260]
Array of noise at digitizer.
UChar_t errorFlag
Error Flag.
void PassesTrigger(Settings *settings1, Anita *anita1, int discones_passing, int mode, int *l3trig, int l2trig[Anita::NPOL][Anita::NTRIGGERLAYERS_MAX], int l1trig[Anita::NPOL][Anita::NTRIGGERLAYERS_MAX], int antennaclump, int loctrig[Anita::NPOL][Anita::NLAYERS_MAX][Anita::NPHI_MAX], int loctrig_nadironly[Anita::NPOL][Anita::NPHI_MAX], int inu, int *thispasses, bool noiseOnly=false)
Evaluate the full trigger simulation for a given payload configuration.
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
Global Trigger.
Definition: GlobalTrigger.h:12
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
double Distance(const Position &second) const
Returns chord distance (direct distance between two vectors)
Definition: position.cc:37
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.
Double_t fDiodeOutput[12 *9][260]
Array of tunnel diode output.
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_t thresholds[12 *9]
Channel thresholds used in icemc.
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.
Double_t SNRAtDigitizer[12 *9]
Array of SNR at digitizer.
Class that handles the channel trigger.
Definition: ChanTrigger.h:18
Reads in and stores input settings for the run.
Definition: Settings.h:37
Double_t fSignalAtTrigger[12 *9][260]
Array of signal at trigger.
Int_t run
Run number, assigned on ground.
Double_t maxSNRAtTriggerV
Max SNR at trigger V-POL.
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
Double_t rfExitNor[5][3]
Normal vector in direction of exit point to balloon - 5 iterations.
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.
Double_t fSignalAtDigitizer[12 *9][260]
Array of signal at digitizer.
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 fNoiseAtTrigger[12 *9][260]
Array of noise at trigger.
Double_t nuDir[3]
Neutrino direction.
void WhichBandsPass(Settings *settings1, Anita *anita1, GlobalTrigger *globaltrig1, Balloon *bn1, int ilayer, int ifold, double dangle, double emfrac, double hadfrac, double thresholds[2][5])
Which bands passes the trigger.
Definition: ChanTrigger.cc:54
Vertical Polarisation.
Double_t e_component_k[48]
Component of e-field along the rx e-plane.
Double_t maxSNRAtDigitizerV
Max SNR at digitizer V-POL.
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
void injectImpulseAfterAntenna(Anita *anita1, int ant)
Inject pulse after the antenna (used for trigger efficiency scans)
Double_t maxSNRAtTriggerH
Max SNR at trigger H-POL.
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 fTimes[12 *9][260]
Array of unwrapped (unless kNoCalib) times for each channel.
Double_t hitangle_e[48]
Hit angles rel. to e plane stored for each antenna.
Int_t run
Run number.
Double_t SNRAtTrigger[12 *9]
Array of SNR at trigger.
Double_t maxSNRAtDigitizerH
Max SNR at digitizer H-POL.
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