-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_beta_ox.cpp
1770 lines (1519 loc) · 59.8 KB
/
calc_beta_ox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Title: "Automating the Calculation of Beta_OX"
*
* Copyright (C) 2020 David Fitzpatrick
*
* From: "Analyzing Optically-Dark Short Gamma Ray Bursts"
* (1) David Fitzpatrick, (2) Professor Alexander van der Horst, Ph.D.
* 1. Georgetown University, Department of Physics,
* 37 and O Streets NW, Washington D.C. 20057
* 2. The George Washington University, Department of Physics,
* 725 21 Street NW, Washington D.C. 20052
*
* I hereby grant to Georgetown University and its agents the non-exclusive, worldwide
* right to reproduce, distribute, display and transmit my thesis in such tangible and
* electronic formats as may be in existence now or developed in the future. I retain all
* ownership rights to the copyright of the thesis including the right to use it in whole
* or in part in future works. I agree to allow the Georgetown University Department of
* Physics to serve as the institutional repository of my thesis and to make it available
* to the Georgetown University community through its website. I certify that the version
* that I have submitted is the same version that was approved by my senior research
* advisor.
*
* Description: In an effort to automate the calculation of the optical to X-Ray spectral
* index (Beta_OX) of well-documented Gamma Ray Bursts (GRBs), this program loads in
* multiple files containing disparate GRB characteristics (in order: X-ray flux data,
* Beta_X data, optical flux data, and optical telescope filter data; fields correspond to
* Tables in Fong et al. 2015) and pairs burst measurements based on ID number and
* user-defined temporal separation between optical and X-Ray measurements. The fully-
* populated GRBs, with parameters which include a calculated value for Beta_OX, are then
* written to .csv files for further analysis.
*
**/
//declare necessary preprocessor directives
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <ctime>
//initialize and declare necessary global constants
//set allowed temporal separation [hr]
double DT_PERCENT_DIF;
//set wavelength for X-Rays in nm
//this is based off of an energy of 1 keV and the fact that
// \lambda = hv
const double FREQUENCY_XRAY = 2.415e+17;
//initialize global variable for number of successful pairs after optical
//data is loaded
double optical_pairs = 0;
//initialize variable for total number of possible pairings; that is, if
//there was 100% accuracy for pairing, this would be how many pairs
double total_possible_pairings = 0;
using namespace std;
/**********************************************************************
BEGIN CLASS DEFINITIONS
***********************************************************************/
class GRB {
public:
// A constructor that creates a GRB beginning with
// the GRB ID, X-Ray temporal separation, X-Ray
// exposure time, and X-Ray uncertainty
GRB(string, double, double, double, double);
// Prints attributes of particular GRB neatly. Items should
// print in the order listed for private data members below
void report();
// Returns the GRB ID of the GRB
string getGRB_ID();
// Accessor and Observers for each field of the X-Ray data.
double get_dt_XRay();
double get_ExpT_XRay();
double get_F_x();
double get_sigma_x();
string get_References_XRay();
void set_Beta_X(double);
double get_Beta_X();
void set_Beta_X_upper_sigma(double);
double get_Beta_X_upper_sigma();
void set_Beta_X_lower_sigma(double);
double get_Beta_X_lower_sigma();
// Accessor and Observers for each field of the Optical data
void set_dt_Opt(double);
double get_dt_Opt();
void set_telescope(string);
string get_telescope();
void set_instrument(string);
string get_instrument();
void set_filter(string);
string get_filter();
void set_Exp_Opt(double);
double get_Exp_Opt();
void set_F_o(double);
double get_F_o();
void set_sigma_o(double);
double get_sigma_o();
void set_References_Opt(string);
string get_References_Opt();
void set_frequency_XRay(double);
double get_frequency_XRay();
void set_frequency_Opt(double);
double get_frequency_Opt();
void set_Beta_OX(double);
double get_Beta_OX();
void set_sigma_OX_upper(double);
double get_sigma_OX_upper();
void set_sigma_OX_lower(double);
double get_sigma_OX_lower();
private:
//17 attributes of the GRB class
string GRB_ID;
double dt_XRay;
double ExpT_XRay;
double F_x;
double sigma_x;
double Beta_X;
double Beta_X_upper_sigma;
double Beta_X_lower_sigma;
string References_XRay;
double dt_Opt;
string telescope;
string instrument;
string filter;
double ExpT_Opt;
double F_o;
double sigma_o;
string References_Opt;
double frequency_XRay;
double frequency_Opt;
double Beta_OX;
double sigma_OX_upper;
double sigma_OX_lower;
};
GRB::GRB(string id, double dt_X, double ExpT_X, double Fx, double sig_x)
{
//create constructor by the following assignment statements
GRB_ID = id;
dt_XRay = dt_X;
ExpT_XRay = F_x;
F_x = Fx;
sigma_x = sig_x;
//initialize factors loaded after construction to 0 or NULL
Beta_X = 31415926535;
Beta_X_lower_sigma = 31415926535;
Beta_X_upper_sigma = 31415926535;
dt_Opt = 0;
telescope = "NULL";
instrument = "NULL";
filter = "NULL";
ExpT_Opt = 0;
F_o = 0;
sigma_o = 0;
References_Opt = "NULL";
References_XRay = "NULL";
frequency_XRay = FREQUENCY_XRAY;
Beta_OX = 0;
sigma_OX_lower = 0;
sigma_OX_upper = 0;
//initialize optical frequency to -1
//used to check for full population for the Trial print and write function
frequency_Opt = -1;
}
void GRB::report()
{
//set the numeric output formatting
cout << fixed << showpoint << setprecision( 2 );
//print out Subject's attributes from the first-loaded data file
cout << GRB_ID << " " << dt_XRay << " " << ExpT_XRay << " " << F_x << " "
<< sigma_x << " " << Beta_X << " " << Beta_X_upper_sigma << " "
<< Beta_X_lower_sigma << " " << dt_Opt << " " << telescope << " " << instrument
<< " " << filter << " " << ExpT_Opt << " " << F_o << " " << sigma_o
<< " " << " " << frequency_XRay << " " << " " << frequency_Opt << " " << Beta_OX
<< " " << sigma_OX_upper << " " << sigma_OX_lower <<endl;
}
string GRB::getGRB_ID()
{
//return GRB ID of GRB
return GRB_ID;
}
double GRB::get_dt_XRay()
{
//return X-Ray dt of GRB
return dt_XRay;
}
double GRB::get_ExpT_XRay()
{
//return X-Ray Exposure time
return ExpT_XRay;
}
double GRB::get_F_x()
{
//return the X-Ray flux density
return F_x;
}
double GRB::get_sigma_x()
{
//return the X-Ray sigma value
return sigma_x;
}
string GRB::get_References_XRay()
{
//return X-Ray references
return References_XRay;
}
void GRB::set_Beta_X(double b)
{
//set X-Ray spectral flux density
Beta_X = b;
}
double GRB::get_Beta_X()
{
//get X-Ray spectral flux density
return Beta_X;
}
void GRB::set_Beta_X_upper_sigma(double u)
{
//set upper bound of X-Ray spectral flux density
Beta_X_upper_sigma = u;
}
double GRB::get_Beta_X_upper_sigma()
{
//return upper bound of X-Ray spectral flux density
return Beta_X_upper_sigma;
}
void GRB::set_Beta_X_lower_sigma(double l)
{
//set lower bound of X-Ray spectral flux density
Beta_X_lower_sigma = l;
}
double GRB::get_Beta_X_lower_sigma()
{
//return lower bound of X-Ray spectral flux density
return Beta_X_lower_sigma;
}
void GRB::set_dt_Opt(double dt)
{
//set optical dt of GRB
dt_Opt= dt;
}
double GRB::get_dt_Opt()
{
//return optical dt of GRB
return dt_Opt;
}
void GRB::set_telescope(string tel)
{
//set optical telescope name
telescope = tel;
}
string GRB::get_telescope()
{
//return optical telescope name
return telescope;
}
void GRB::set_instrument(string i)
{
//set optical instrument name
instrument = i;
}
string GRB::get_instrument()
{
//return optical instrument name
return instrument;
}
void GRB::set_filter(string f)
{
//set filter name
filter = f;
}
string GRB::get_filter()
{
//get filter name
return filter;
}
void GRB::set_Exp_Opt(double e)
{
//set optical exposure time
ExpT_Opt = e;
}
double GRB::get_Exp_Opt()
{
//return optical exposure time
return ExpT_Opt;
}
void GRB::set_F_o(double f)
{
//set optical flux density
F_o = f;
}
double GRB::get_F_o()
{
//get optical flux density
return F_o;
}
void GRB::set_sigma_o(double s)
{
//set optical flux density standard deviation
sigma_o = s;
}
double GRB::get_sigma_o()
{
//get optical flux density standard deviation
return sigma_o;
}
void GRB::set_References_Opt(string r)
{
//set optical references
References_Opt = r;
}
string GRB::get_References_Opt()
{
//get optical references
return References_Opt;
}
void GRB::set_frequency_XRay(double f)
{
//set X-Ray frequency
frequency_XRay = f;
}
double GRB::get_frequency_XRay()
{
//get X-Ray frequency
return frequency_XRay;
}
void GRB::set_frequency_Opt(double wa)
{
//set optical frequency
frequency_Opt = wa;
}
double GRB::get_frequency_Opt()
{
//get optical frequency
return frequency_Opt;
}
void GRB::set_Beta_OX(double b)
{
//set Beta_OX
Beta_OX = b;
}
double GRB::get_Beta_OX()
{
//get Beta_OX
return Beta_OX;
}
void GRB::set_sigma_OX_upper(double s)
{
//set upper bound on Beta_OX uncertainty
sigma_OX_upper = s;
}
double GRB::get_sigma_OX_upper()
{
//get upper bound on Beta_OX uncertainty
return sigma_OX_upper;
}
void GRB::set_sigma_OX_lower(double s)
{
//set lower bound on Beta_OX uncertainty
sigma_OX_lower = s;
}
double GRB::get_sigma_OX_lower()
{
//get lower bound on Beta_OX uncertainty
return sigma_OX_lower;
}
// A class used for determining total number of possible outcomes
// between X-Ray and optical data
class Possibility {
public:
// A constructor consisting of the GRB ID number and its
// corresponding multiplicity
Possibility( string, int );
//Accessors and observers for the class
string get_ID();
void set_ID(string);
int get_multiplicity();
void set_multiplicity(int);
private:
//variable for GRB ID
string ID;
//variable for multiplicity
int multiplicity;
};
Possibility::Possibility( string id, int mult )
{
//create constructor by the following assignment statements
ID = id;
multiplicity = mult;
}
string Possibility::get_ID()
{
//return ID
return ID;
}
void Possibility::set_ID( string id )
{
//set ID
ID = id;
}
int Possibility::get_multiplicity()
{
//return multiplicity
return multiplicity;
}
void Possibility::set_multiplicity( int m )
{
//set multiplicity
multiplicity = m;
}
class Trial {
public:
// Simple constructor
Trial();
// Loads X-Ray data file into the vector of GRBs
int loadX_RayData(string);
// Loads Beta_X data file. Uses the GRB ID to locate the
// GRB ID in the vector, and then sets the GRB object to
// also contain the correct Beta_X values
int loadBeta_X(string);
// Loads optical data file. Uses the GRB ID to locate the
// GRB ID in the vector, and then sets the GRB object to
// also contain the correct optical data values
int loadOpticalData(string);
// Loads wavelength data file and pairs each GRB based on
// telescope and filter information appropriate wavelength
int loadWavelengthData(string);
// A function used to calculate the optical to X-Ray spectral index
// as well as the upper and lower bounds on the uncertainty
void calculate_Beta_OX();
// prints out the GRB vector by calling the report method
// of each GRB. Used for debugging.
void report();
//writes paired GRB data to file
void write_paired_data();
private:
// A private function used to return the location
// in the vector of GRBs of a GRB with a
// particular GRB ID used in the loadOpticalData
// to locate where a particular GRB is
int findGRB(string);
// A private function which is used to pair X-Ray data and
// optical data to a particular GRB based on a small temporal
// separation in measurement time
int matchGRB( string, double, int);
// A private function which is used to determine if for a given
// GRB ID in the optical data set, there exists at least one GRB
// with identical ID read in by the X-Ray Data set
int check_ID( string );
// A private function which is used to remove entities that haven't
// been paired with Beta_X data from vector XRay_entries
int clean_XRay_entries();
// A private function which is used to pair GRBs with their
// appropriate optical wavelength based on telescope, instrument,
// and filter information
int matchFrequency( string, string, string, double, double );
// A private function which is used to determine the total number of
// possible pairings between optical and X-Ray data by, in essence,
// conducting matrix multiplication between vectors XRay_entries and
// optical_entries
int find_total_possible_pairings();
//define a vector of GRBs
vector<GRB> GRBs;
//define a vector of GRBs filled with optical data
vector<GRB> GRBs_with_Opt;
//define a vector which has number of elements corresponding to the total number
//of different GRB IDs in the X-Ray file and elements corresponding to the
//total number of entries per individual GRB ID
//Ex: GRBs_with_Opt.size() = N; GRBs_With_Opt = {1,5,...,n}
//This would correspond to the X-Ray file having N different GRB IDs,
//and if the first two and last GRBs had IDs 050509B, 050709, and XXXXXX, then
//GRB 050509B would have 1 entry, GRB 050709 would have 5 entries, and GRB XXXXXX
//would have N entries
vector<Possibility> XRay_entries;
//define a vector identical to XRay_entries but for the optical file
vector<Possibility> optical_entries;
//define a vector of GRBs filled with IDs that exist in optical data but not in X-Ray
// data
vector<string> IDs_in_Opt_not_X;
};
Trial::Trial()
{
//constructor is empty because it does not need any attributes
}
int Trial::loadX_RayData( string filename )
{
//define variables for GRB attributes
//define variable for GRB ID Number
string ID;
//define variable for X-Ray dt in seconds
double dtX;
//define variable for X-Ray exposure time
double ExpX;
//define variable for optical flux density
double Fx;
//define variable for std dev of optical flux density
double sigmaX;
//initialize variable for number of GRBs loaded
int counter = 0;
//initialize string variable for old ID used in GRB ID multiplicity determination
string old_ID = "NULL";
//initialize counter used for determining number of data points for each unique ID
int entries_per_ID = 0;
//define ifstream variable for file
ifstream file;
//open file specified by user
file.open( filename.c_str() );
//test to see if file opens successfully
while ( !file )
{
//notify user of error and ask to input file name again
cout << "Could not open file: " << filename << "." << endl;
cout << "Please re-enter filename (or control-C to exit): ";
cin >> filename; //assign user input to variable fileName
file.open(filename.c_str()); //try again to open file specified by user
}
//display features
cout << endl << right << setw(65) << "************************ X-Ray GRB Data ********"
<< "****************" << endl << endl;
cout << right << setw(10) << "GRB ID" << right << setw(10) << "dt_X [s]"
<< right << setw(20) << "Exposure Time [s]" << right << setw(10)
<< "F_x [uJy]" << right << setw(15) << "sigma_X [uJy]" << endl << endl;
//read in data from file and assign them to corresponding variables
//read until file no longer has any more data
while ( file >> ID >> dtX >> ExpX >> Fx >> sigmaX)
{
//create a GRB g and construct it using variables read from file
GRB grb( ID, dtX, ExpX, Fx, sigmaX);
//initialize new_ID to be the GRB ID read in from file
string new_ID = ID;
//check if this is the first entry read from optical file
if ( counter == 0 )
{
//initialize old_ID to entry read from optical file if
//this is the first entry from optical file
old_ID = ID;
}
//check if new ID has been reached
if ( new_ID.compare(old_ID) == 0 )
{
//increment counter for number of entries per unique ID because
//a multiplicity of the same idea has been found OR it is the first trial
entries_per_ID++;
}
else
{
//construct Possibility object with corresponding data
Possibility new_Possibility( old_ID, entries_per_ID );
//add in new element to vector containing number of entires per unique
//GRB ID read from optical file
XRay_entries.push_back(new_Possibility);
//reset counter used for determining number of data points for each unique ID
//counter is reset to 1 because in order to reach this else clause, new_ID !=
//old_ID, meaning there is already a new entry
entries_per_ID = 1;
}
old_ID = ID;
//increment counter
counter++;
//put the GRB object in the vector of GRBs
GRBs.push_back( grb );
//display loaded features
cout << right << setw(10) << ID << right << setw(10) << dtX << right << setw(20)
<< ExpX << right << setw(10) << Fx << right << setw(15) << sigmaX <<endl;
}
//add last pair to vector of multiplicities
//construct Possibility object with corresponding data
Possibility new_Possibility( old_ID, entries_per_ID );
//add in new element to vector containing number of entires per unique
//GRB ID read from optical file
XRay_entries.push_back(new_Possibility);
cout << endl << "Number of GRBs loaded: " << counter;
//close file
file.close();
return counter;
}
int Trial::loadBeta_X(string filename)
{
//define variable for GRB ID
string ID;
//define variable for Beta_X
double Beta_X;
//define variable for Beta_X upper uncertainty
double Beta_X_upper_sigma;
//define variable for Beta_X lower uncertainty
double Beta_X_lower_sigma;
//define variable for total loaded Beta X elements
int total_loaded = 0;
//initialize variable for number of successful pairs after Beta_X
double Beta_X_pairs = 0;
//initialize variable for rate of successful pairings
double pairing_rate = 0;
//define ifstream variable for file
ifstream file;
//open file specified by user
file.open( filename.c_str() );
//test to see if file opens successfully
while ( !file )
{
//notify user of error and ask to input file name again
cout << "Could not open file: " << filename << "." << endl;
cout << "Please re-enter filename (or control-C to exit): ";
cin >> filename; //assign user input to variable fileName
file.open(filename.c_str()); //try again to open file specified by user
}
//display features
cout << endl << right << setw(60) << "************************Beta_X Data*************"
<< "*************"
<< endl << endl;
cout << right << setw(10) << "GRB ID" << right << setw(10) << "Beta_X"
<< right << setw(20) << "Upper Uncertainty" << right << setw(20)
<< "Lower Uncertainty"<< endl << endl;
//read in data from file and assign them to corresponding variables
//read until file no longer has any more data
while ( file >> ID >> Beta_X >> Beta_X_upper_sigma >> Beta_X_lower_sigma )
{
//display loaded features
cout << right << setw(10) << ID << right << setw(10) << Beta_X
<< right << setw(20) << Beta_X_upper_sigma << right << setw(20)
<< Beta_X_lower_sigma << endl;
//initialize success boolean to false
bool success = false;
//increment counter for successful load
total_loaded++;
// run through vector of GRBs
for ( int a = 0; a < GRBs.size(); a++ )
{
//match GRB IDs
if ( GRBs[a].getGRB_ID() == ID )
{
//assign attributes to appropriate GRB
GRBs[a].set_Beta_X(Beta_X);
GRBs[a].set_Beta_X_upper_sigma(Beta_X_upper_sigma);
GRBs[a].set_Beta_X_lower_sigma(Beta_X_lower_sigma);
//signify match
success = true;
//increment success counter for successful pairing
Beta_X_pairs++;
}
}
//check if no match was found
if ( success == false )
{
//notify user that no match was able to be found
cout << endl << "Unable to match GRB ID " << ID << " with Beta_X " << Beta_X
<< endl << endl;
}
}
//calculate percent of loaded GRBs that are paired
pairing_rate = (Beta_X_pairs / GRBs.size())*100;
//notify user of loading statistics
cout << endl << right << setw(58) << "Number of loaded GRBs from Beta_X file: "
<< right << setw(2) << total_loaded;
cout << endl << right << setw(57) << "Number of successful pairings with X-Ray Data: "
<< right << setw(3) << Beta_X_pairs;
cout << endl << right << setw(55) << fixed << showpoint << setprecision(1)
<< "Pairing Rate: " << right << setw(4) << pairing_rate << right << setw(1)
<< "%" << endl;
cout << endl << right << setw(60) << "...Cleaning up X-Ray Entries..." << endl;
clean_XRay_entries();
//close file
file.close();
return total_loaded;
}
int Trial::loadOpticalData( string filename )
{
//define variables for GRB attributes
//define variable for GRB ID Number
string ID;
//define variable for optical dt in hours
double dtO_hours;
//define variable for optical dt in seconds
double dtO_seconds;
//define variable for optical telescope name
string tel;
//define variable for instrument name
string inst;
//define variable for optical filter name
string fil;
//define variable for optical exposure time in seconds
double ExpO;
//define variable for optical flux density in uJy
double Fo;
//define variable for optical flux density std dev in uJy
double sigmaO;
//initialize variable for number of subjects loaded
double total_loaded = 0;
//initialize variable for rate of successful pairings
double pairing_rate = 0;
//initialize counter for no match found
int no_match_found_counter = 0;
//initialize string variable for old ID used in GRB ID multiplicity determination
string old_ID = "NULL";
//initialize counter used for determining number of data points for each unique ID
int entries_per_ID = 0;
//initialize variable for number of GRBs that are not in
//BOTH the X-Ray and optical files
int disjoint = 0;
//initialize variable for a check on the number of GRBs that are not in
//BOTH the X-Ray and optical files
int disjoint_confirm = 0;
//define ifstream variable for file
ifstream file;
//open file specified by user
file.open( filename.c_str() );
//test to see if file opens successfully
while ( !file )
{
//notify user of error and ask to input file name again
cout << "Could not open file: " << filename << "." << endl;
cout << "Please re-enter filename (or control-C to exit): ";
cin >> filename; //assign user input to variable fileName
file.open(filename.c_str()); //try again to open file specified by user
}
//display features
cout << endl << right << setw(110) << "**********************************************"
<<" Optical GRB Data **********************************************" << endl
<< endl;
cout << right << setw(10) << "GRB ID" << right << setw(15) << "dt_O [s]"
<< right << setw(15) << "Telescope" << right << setw(15)
<< "Instrument" << right << setw(10) << "Filter" << right << setw(20)
<< "Exposure Time [s]" << right << setw(10) << "F_o [uJy]" << right
<< setw(15) << "sigma_O [uJy]" << endl << endl;
//read in data from file and assign them to corresponding variables
//read until file no longer has any more data
while (file >> ID >> dtO_hours >> tel >> inst >> fil >> ExpO >> Fo >> sigmaO)
{
//transform optical dt measurement from hours into seconds
dtO_seconds = 3600 * dtO_hours;
//display loaded features
cout << right << setw(10) << ID << right << setw(15) << dtO_seconds
<< right << setw(15) << tel << right << setw(15)
<< inst << right << setw(10) << fil << right << setw(20)
<< ExpO << right << setw(10) << Fo << right
<< setw(15) << sigmaO << endl;
//initialize variable for location in GRB vector
int location = 0;
//initialize counter for checking if any pairings were made at all
int check = 0;
//initialize new_ID to be the GRB ID read in from file
string new_ID = ID;
//check if this is the first entry read from optical file
if ( total_loaded == 0 )
{
//initialize old_ID to entry read from optical file if
//this is the first entry from optical file
old_ID = ID;
}
//check if new ID has been reached
if ( new_ID == old_ID )
{
//increment counter for number of entries per unique ID because
//a multiplicity of the same idea has been found OR it is the first trial
entries_per_ID++;
}
else
{
//construct Possibility object with corresponding data
Possibility new_Possibility( old_ID, entries_per_ID );
//add in new element to vector containing number of entires per unique
//GRB ID read from optical file
optical_entries.push_back(new_Possibility);
//disjoint += check_ID(old_ID);
//reset counter used for determining number of data points for each unique ID
//counter is reset to 1 because in order to reach this else clause, new_ID !=
//old_ID, meaning there is already a new entry
entries_per_ID = 1;
}
old_ID = ID;
//increment counter for total loaded Optical elements
total_loaded++;
while ( location < GRBs.size() && location != -1)
{
location = matchGRB(ID, dtO_seconds, location);
check++;
//cout << "\nBeginning checks\n";
//cout << "Location is: " << location << endl;
//check if pairing is made
if( location != -1 )
{
//construct a GRB object that will be added
//into vector of GRBs with optical data
GRB copy_grb( GRBs[location].getGRB_ID(), GRBs[location].get_dt_XRay(),
GRBs[location].get_ExpT_XRay(), GRBs[location].get_F_x(),
GRBs[location].get_sigma_x());
//set corresponding GRB appropriate Beta_X parameters
copy_grb.set_Beta_X(GRBs[location].get_Beta_X());
copy_grb.set_Beta_X_lower_sigma(GRBs[location].get_Beta_X_lower_sigma());
copy_grb.set_Beta_X_upper_sigma(GRBs[location].get_Beta_X_upper_sigma());
//set corresponding GRB appropriate optical parameters
copy_grb.set_dt_Opt(dtO_seconds);
copy_grb.set_telescope(tel);
copy_grb.set_instrument(inst);
copy_grb.set_filter(fil);
copy_grb.set_Exp_Opt(ExpO);
copy_grb.set_F_o(Fo);
copy_grb.set_sigma_o(sigmaO);
//add newly-created GRB with optical data to
//vector of GRBs with optical data
GRBs_with_Opt.push_back(copy_grb);
//increment location
location ++;
//increment counter of successful pairing
optical_pairs++;
}
}
//check if no pairing was made
if ( check == 1)
{
// //notify user that no match was able to be found
// cout << "Unable to match GRB " << ID << " with optical dt " << dtO_hours
// << " [hr] = " << dtO_seconds << " [s]." << endl << endl;
//increment counter for no match made
no_match_found_counter++;
}
}
//add last pair to vector of multiplicities
//construct Possibility object with corresponding data
Possibility new_Possibility( old_ID, entries_per_ID );
//add in new element to vector containing number of entires per unique
//GRB ID read from optical file
optical_entries.push_back(new_Possibility);
total_possible_pairings = find_total_possible_pairings();
//calculate percent of loaded GRBs that are paired
pairing_rate = (optical_pairs / total_possible_pairings )*100;
//notify user of loading statistics
cout << endl << right << setw(57) << "Number of loaded GRBs from optical data file: "
<< right << setw(3) << int(total_loaded);
cout << endl << right << setw(57) << fixed << showpoint << setprecision(0)
<< "Number of possible pairs: " << right << setw(3)
<< int(total_possible_pairings);
cout << endl << right << setw(57) << fixed << showpoint << setprecision(0)
<< "Number of successful pairs: " << right << setw(3) << int(optical_pairs);
cout << endl << right << setw(55) << fixed << showpoint << setprecision(1)
<< "Pairing Rate: " << right << setw(5) << pairing_rate << "%";
//close file
file.close();
return total_loaded;
}
int Trial::loadWavelengthData(string filename)
{
//define variables for GRB attributes
//define variable for telescope name
string telName;
//define variable for instrument name
string instrumentName;