-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalcData.java
More file actions
1904 lines (1460 loc) · 65.6 KB
/
CalcData.java
File metadata and controls
1904 lines (1460 loc) · 65.6 KB
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
package sbeam2;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JFrame;
import sbeam2.POEData;
import sbeam2.scale;
import sbeam2.gui.MessageDialog;
import sbeam2.POECalcData;
import sbeam2.TOFData;
public class CalcData {
public int CalcNumber;
public TOFData[] calculated_tofs;
public String title;
public int num_poes, num_total_poes;
public float ion_m_e;
public int num_beam_ang_segs, num_det_ang_segs, num_ionizer_segs;
public boolean is_ionizer_gaussian;
public float[] ionizer_prob_dist; // Normalized probability distribution
public float[] ionizer_distance; // Array of distances from the ionizer center (in cm)
public float[] beam_velocities; // In m/s
public float[] bm_vel_prob_dist, bm_vel_squared; // Boltzmann distrib or input data
public float[] lab_velocities, lab_vel_squared;
public float[] cos_theta_lab, sin_theta_lab, cos_polar_angle, sin_polar_angle;
public float[] depolar_major, depolar_minor;
public float alpha, speed_ratio;
public int num_beam_vel_segs;
public float min_lab_velocity, max_lab_velocity;
public float flight_length, beam_angular_width, detector_angular_width, ionizer_length;
public float starting_time, ending_time;
public int num_tof_points, num_lab_vel_segs, num_tofs;
public float[] tof_lab_angles, tof_polarization_angles, depolarization;
public boolean[] tof_is_polarized;
public double[] cos_theta_beam, sin_theta_beam;
public double[] cos_theta_detector, sin_theta_detector;
public float[][] cos_phi_beam, sin_phi_beam;
public float[][] cos_phi_detector, sin_phi_detector;
public float[][][][][] TOF_2cos_gamma; // YIKES!!!
public ArrayList<POECalcData> data_for_poes;
public float[][][][] min_u_squared_array, max_u_squared_array;
public boolean bm_angle_has_changed, det_angle_has_changed, is_number_density_calc;
public int old_num_tofs, old_num_theta_bm, old_num_theta_det;
public int[] included_tof_num_array;
public JFrame main_frame_window;
public MessageDialog message_dialog;
public SBApp sb;
public CalcData() {
// TODO Auto-generated constructor stub
}
public CalcData(int title_calc_number, int num_tot_poes, float ionizer_len, JFrame main_window, SBApp app)
{
int i;
sb = app;
main_frame_window = main_window;
message_dialog = new MessageDialog(main_window);
ionizer_length = ionizer_len;
// Set default calculation numbers
title = "";
String title_number;
CalcNumber = title_calc_number;
// Default title is just Convolution # XX
title = "Convolution #";
title_number = "" + title_calc_number;
title += title_number;
num_poes = 0;
num_tofs = 0;
num_total_poes = num_tot_poes;
ion_m_e = 1.0f;
num_beam_ang_segs = 4;
num_det_ang_segs = 4;
is_ionizer_gaussian = true;
alpha = 76;
speed_ratio = 13;
num_beam_vel_segs = 5;
starting_time = 0;
ending_time = 1000;
num_tof_points = 1001;
bm_angle_has_changed = true;
det_angle_has_changed = true;
is_number_density_calc = true;
cos_theta_beam = null;
sin_theta_beam = null;
depolar_major = null;
depolar_minor = null;
SetIonizerDist(3, ionizer_length, ionizer_prob_dist);
SetBmVelDistrib(5, 76, 13, null, null);
SetLabVelocityArrays(0, 5000, 400);
//SetNumBeamAngleSegs(DEFAULT_ANG_SEGS);
data_for_poes = new ArrayList<POECalcData>();
// Initialize all POE_calc_data structs
for(i = 0; i < num_total_poes; i++)
{
POECalcData poeData = new POECalcData();
// Give each one a single ion channel, but not contributing to calculation
poeData.beta_param = 0.0f;
poeData.num_channels = 1;
poeData.is_included = false;
poeData.mass_1 = new float[1];
poeData.mass_1[0] = 1.0f;
poeData.mass_2 = new float[1];
poeData.mass_2[0] = 1.0f;
poeData.rel_weight = new float[1];
poeData.rel_weight[0] = 1.0f;
poeData.mass_ratio = null;
poeData.poe = app.poes.get(i);
data_for_poes.add(poeData);
}
ReplacePOECalcData(false);
tof_lab_angles = null;
tof_polarization_angles = null;
old_num_tofs = 0;
old_num_theta_bm = 0;
old_num_theta_det = 0;
detector_angular_width = 0;
beam_angular_width = 0;
}
/* CALCULATION STUFF TAKEN FROM SBEAM1 */
public void SetNumBeamAngleSegs(int new_value){
// Sets number of segments and calculates
// Note: The division of the beam angle was devised such that each discrete
// angle theta is representative of 1/(num_beam_ang_segs - 1) of the beam. i.e. the
// theta angles are determined by splitting the beam up into theta segments such
// that the probability of finding a molecule at an angle in each specific segment
// is equal. This allows simplification in later calculations since the probability
// of each theta does not need to be stored. The probability of each discrete theta
// will simply be 1/(num_beam_ang_segs - 1). This can be done relatively easily since
// a cos^2 distribution is assumed for the beam angle between 0 and the full beam angle,
// which can be solved analytically, so a determination of which discrete thetas to
// choose is relatively straightforward.
// The division of the azimuthal angle, phi, is even more straightforward, since
// all possible phi are equally probable. Thus, the ith theta value is divided up
// into (3i + 1) discrete phi pieces, each of which carries equal probability.
// In the end, the total probability of having a velocity vector in some spherical
// shell in velocity space is simply the product of the P(v) from the speed distribution,
// and the P(theta) and P(phi) determined here, all of which can be normalized individually.
double cos_cubed, cos_full_bm_angle, normalization_factor, difference;
double temp_cos;
float temp_phi, phi_difference;
float[] temp_cos_phi_array, temp_sin_phi_array;
int i, j, num_phis;
if(((new_value <= 0) || (new_value == num_beam_ang_segs)) && (bm_angle_has_changed == false))
return; // Don't make any changes in this case!
// Delete any information which has already been stored
// Store new beam angle information
num_beam_ang_segs = new_value;
cos_theta_beam = new double[num_beam_ang_segs];
sin_theta_beam = new double[num_beam_ang_segs];
cos_phi_beam = new float[num_beam_ang_segs][];
sin_phi_beam = new float[num_beam_ang_segs][];
cos_full_bm_angle = Math.cos(Math.PI/180*(beam_angular_width));
normalization_factor = 1.0 - Math.pow(cos_full_bm_angle, 3);
if(num_beam_ang_segs == 1)
difference = 0.0;
else
difference = normalization_factor / (num_beam_ang_segs - 1);
// Iteratively get new cos_theta_beam from old one. The new theta is determined
// by finding a theta such that the probability of having an angle between the old
// theta and the new theta is equal to 1/(num_beam_ang_segs - 1).
for(i = 0; i < num_beam_ang_segs; i++)
{
cos_cubed = 1.0 - i * difference;
temp_cos = Math.pow(cos_cubed, (1.0/3.0));
cos_theta_beam[i] = temp_cos;
sin_theta_beam[i] = Math.sqrt(1.0 - temp_cos * temp_cos);
num_phis = 3*i + 1;
phi_difference = (float) ((2 * Math.PI)/num_phis); // Don't need num_phis - 1 since last
// phi is not 2*Pi!
cos_phi_beam[i] = new float[num_phis];
sin_phi_beam[i] = new float[num_phis];
// Use the following to save time lost by dereferencing in for loop over many j values
temp_cos_phi_array = cos_phi_beam[i];
temp_sin_phi_array = sin_phi_beam[i];
// Each of these will have equal probability, so the probabilities won't need to be stored
for(j = 0; j < num_phis; j++)
{
temp_phi = j * phi_difference;
temp_cos_phi_array[j] = (float) Math.cos(temp_phi);
temp_sin_phi_array[j] = (float) Math.sin(temp_phi);
}
} // End of loop over all possible i values from zero to num_bm_ang_segs - 1
bm_angle_has_changed = false;
}
// arrays of cos_theta_beam, sin_theta_beam,
// cos_phi_beam, and sin_phi_beam
public void SetNumDetAngleSegs(int new_value){
// Sets number of segments and calculates
// The angle of the detector relative to the center of the molecular beam at the
// interaction is divided up exactly analogously to the beam angle division.
// (See the description in the function Calc_data::SetNumBeamAngleSegs(int)).
// In this case, however, the beam is simply divided such that the integrated
// area between two theta values will be the same and equal to the total area of
// the detector over (num_det_ang_segs - 1). i.e. This is like the above division
// except the initial probability distribution is uniform rather than proportional
// to cos^2
// The detector theta angle is measured relative to the detector axis whereas the
// detector phi angle is the azimuthal angle which can take on any value from zero
// to 2*PI radians, again uniformly. The ith theta annulus is divided into 3i + 1
// phi pieces.
double cos_full_det_angle, normalization_factor, difference;
double temp_cos;
float temp_phi, phi_difference;
float[] temp_cos_phi_array, temp_sin_phi_array;
int i, j, num_phis;
if((new_value <= 0) || ((new_value == num_det_ang_segs) && (det_angle_has_changed == false)))
return; // Don't make any changes in this case!
// Delete any information which has already been stored
// Store new beam angle information
num_det_ang_segs = new_value;
cos_theta_detector = new double[num_det_ang_segs];
sin_theta_detector = new double[num_det_ang_segs];
cos_phi_detector = new float[num_det_ang_segs][];
sin_phi_detector = new float[num_det_ang_segs][];
cos_full_det_angle = Math.cos(Math.PI/180*(detector_angular_width));
normalization_factor = 1.0 - cos_full_det_angle;
if(num_det_ang_segs == 1)
difference = 0.0;
else
difference = normalization_factor / (num_det_ang_segs - 1);
// Iteratively get new cos_theta_detector from old one. The new theta is determined
// by finding a theta such that the probability of having an angle between the old
// theta and the new theta is equal to 1/(num_det_ang_segs - 1).
for(i = 0; i < num_det_ang_segs; i++)
{
temp_cos = 1.0 - i * difference;
cos_theta_detector[i] = temp_cos;
sin_theta_detector[i] = Math.sqrt(1.0 - temp_cos * temp_cos);
num_phis = 3*i + 1;
phi_difference = (float) ((2 * Math.PI)/num_phis); // Don't need num_phis - 1 since last
// phi is not 2*Pi!
cos_phi_detector[i] = new float[num_phis];
sin_phi_detector[i] = new float[num_phis];
// Use the following to save time lost by dereferencing in for loop over many j values
temp_cos_phi_array = cos_phi_detector[i];
temp_sin_phi_array = sin_phi_detector[i];
// Each of these will have equal probability, so the probabilities won't need to be stored
for(j = 0; j < num_phis; j++)
{
temp_phi = j * phi_difference;
temp_cos_phi_array[j] = (float) Math.cos(temp_phi);
temp_sin_phi_array[j] = (float) Math.sin(temp_phi);
}
} // End of loop over all possible i values from zero to num_bm_ang_segs - 1
det_angle_has_changed = false;
}
// arrays of cos_theta_detector, sin_theta_detector,
// cos_phi_detector, and sin_phi_detector
public void SetIonizerDist(int num_segments, float ionizer_len, float[] array){
// Note that normalization is not done at this point since, in the end, everything
// is scaled anyway, so the multiplicative constant doesn't matter
int i;
float ionizer_spacings, x_over_sigma, /*normalization_const,*/ exponent_value;
float ionizer_length_spacings;
ionizer_length = ionizer_len;
num_ionizer_segs = num_segments;
// If array = 0 (default), then assume a Gaussian distribution and calculate
// that distribution
if(array == null)
{
is_ionizer_gaussian = true;
// Initialize ionizer distribution (Gaussian)
ionizer_prob_dist = new float[num_ionizer_segs];
ionizer_distance = new float[num_ionizer_segs];
if(num_ionizer_segs == 1)
{
ionizer_prob_dist[0] = 1.0f;
ionizer_distance[0] = 0.0f;
return;
}
// The numbers 4.90 & 2.45 are used here since the Gaussian distribution is
// assumed to have a width such that the probability drops to ~exp(-3) at the
// outer edges of the ionizer. Thus, x^2/2*sigma^2 ~ 3, so x/sigma~2.45
ionizer_spacings = (float) (2 * 2.58 / (num_ionizer_segs - 1));
ionizer_length_spacings = ionizer_len / (num_ionizer_segs - 1);
//normalization_const = 0.0;
for(i = 0; i < num_ionizer_segs; i++)
{
x_over_sigma = (float) (- 2.58 + i * ionizer_spacings);
exponent_value = (float) Math.exp(-(x_over_sigma * x_over_sigma) / 2);
ionizer_prob_dist[i] = exponent_value;
ionizer_distance[i] = -(ionizer_len / 2) + i * ionizer_length_spacings;
//normalization_const += (ionizer_spacings * exponent_value);
}
// Normalize the distribution:
/*for(i = 0; i < num_ionizer_segs; i++)
{
ionizer_prob_dist[i] /= normalization_const;
} */
}
else
{
is_ionizer_gaussian = false;
ionizer_prob_dist = array;
}
}
public void SetIonizerLen(float ionizer_len){
// Used when ionizer length changes
// Used only by Document to change ionizer length without changing the probability
// distribution & # of points; thus, only need to put new info into ionizer_distance
// array.
// Note: may need to renormalize ionization distribution if necessary!!
int i;
float ionizer_length_spacings;
ionizer_length = ionizer_len;
ionizer_length_spacings = ionizer_len / (num_ionizer_segs - 1);
for(i = 0; i < num_ionizer_segs; i++)
{
ionizer_distance[i] = -(ionizer_len / 2) + i * ionizer_length_spacings;
}
}
public void SetBeamAng(float bm_angle_width){
// Used when angular width of beam changes
if(beam_angular_width == bm_angle_width)
return;
beam_angular_width = bm_angle_width;
bm_angle_has_changed = true;
SetNumBeamAngleSegs(num_beam_ang_segs);
}
public void SetDetectorAng(float detector_angle_width){
// Used when angular width of detector changes
if(detector_angular_width == detector_angle_width)
return;
detector_angular_width = detector_angle_width;
det_angle_has_changed = true;
SetNumDetAngleSegs(num_det_ang_segs);
}
public void SetBmVelDistrib(int num_segs, float alfa, float spd_ratio, float[] prob_array, float[] array){
// This function uses alpha, the speed_ratio, and the number of beam velocity
// segments to find the beam velocity probability distribution as a function
// of beam velocity. Is the user so desires, an input pair of arrays for the
// velocity and probability distribution are sent to this function directly.
// The function also normalizes the distribution. Although this is not explicitly
// required at this point due to the fact that the final TOF will be scaled arbitrarily,
// resulting in a lack of necessity for the multiplicative constant,
// the normalization helps to maintain reasonable orders of magnitude throughout the
// calculation. Finally, the square of the beam velocity is determined since this is
// used in later calculations involving the Law of Cosines.
int i;
float peak_vel, upper_lim, lower_lim, square_root_value;
float prob_pk_vel, prob_upper_lim, prob_vel, bm_vel_spacings;
float difference_over_alpha, step_size, velocity;
float alpha_multiplier;
float normalization_const;
if((prob_array != null) && (num_beam_vel_segs == num_segs) && (alpha == alfa) && (speed_ratio == spd_ratio))
return;
num_beam_vel_segs = num_segs;
bm_vel_squared = new float[num_beam_vel_segs];
if(prob_array == null)
{
beam_velocities = new float[num_beam_vel_segs];
bm_vel_prob_dist = new float[num_beam_vel_segs];
alpha = alfa;
speed_ratio = spd_ratio;
alpha_multiplier = 2.1f; // Initially start with 2.1
square_root_value = (float) (1 + (4.0 / (speed_ratio * speed_ratio)));
peak_vel = (float) ((alpha * speed_ratio * (1 + Math.sqrt(square_root_value))) / 2.0);
if(num_beam_vel_segs == 1)
{
beam_velocities[0] = peak_vel;
bm_vel_squared[0] = peak_vel * peak_vel;
bm_vel_prob_dist[0] = 1;
normalization_const = 1.0f;
}
else
{
difference_over_alpha = (peak_vel - speed_ratio * alpha) / alpha;
prob_pk_vel = (float) (peak_vel * peak_vel * Math.exp(-(difference_over_alpha * difference_over_alpha)));
// Find a good upper limit of beam velocity distribution. (i.e. one in which
// the probability of the upper limit is ~0.01 to 0.025 that of the peak probability)
upper_lim = peak_vel + (alpha_multiplier * alpha);
lower_lim = peak_vel;
difference_over_alpha = (upper_lim - speed_ratio * alpha) / alpha;
prob_upper_lim = (float) (upper_lim * upper_lim * Math.exp(-(difference_over_alpha * difference_over_alpha)));
while((prob_upper_lim/prob_pk_vel) <= 0.01 || (prob_upper_lim/prob_pk_vel) >= 0.025)
{
if((prob_upper_lim/prob_pk_vel) <= 0.01)
{
//i.e. too far out!
upper_lim = (upper_lim + lower_lim) / 2;
difference_over_alpha = (upper_lim - speed_ratio * alpha) / alpha;
prob_upper_lim = (float) (upper_lim * upper_lim * Math.exp(-(difference_over_alpha * difference_over_alpha)));
}
if((prob_upper_lim/prob_pk_vel) >= 0.025)
{
// not far enough!
step_size = upper_lim - lower_lim;
lower_lim += step_size;
upper_lim += step_size;
difference_over_alpha = (upper_lim - speed_ratio * alpha) / alpha;
prob_upper_lim = (float) (upper_lim * upper_lim * Math.exp(-(difference_over_alpha * difference_over_alpha)));
}
}
lower_lim = 2 * peak_vel - upper_lim;
if(lower_lim < 0)
lower_lim = 0;
bm_vel_spacings = (upper_lim - lower_lim) / (num_beam_vel_segs - 1);
normalization_const = 0.0f;
for(i = 0; i < num_beam_vel_segs; i++)
{
velocity = lower_lim + i * bm_vel_spacings;
beam_velocities[i] = velocity;
bm_vel_squared[i] = velocity * velocity;
difference_over_alpha = (velocity - speed_ratio * alpha) / alpha;
prob_vel = (float) (velocity * velocity * Math.exp(-(difference_over_alpha * difference_over_alpha)));
// Use Trapezoid rule to "integrate" the probabilities
if((i == 0) || (i == num_beam_vel_segs - 1))
{
normalization_const += 0.5 * prob_vel;
}
else
{
normalization_const += prob_vel;
}
bm_vel_prob_dist[i] = prob_vel;
}
//normalization_const *= bm_vel_spacings; // Not included since numbers get too small!
} // End of else for if(num_bm_vel_segs == 1)
}
else
{
beam_velocities = array;
bm_vel_prob_dist = prob_array;
if(num_beam_vel_segs == 1)
{
bm_vel_squared[0] = beam_velocities[0] * beam_velocities[0];
bm_vel_prob_dist[0] = 1;
normalization_const = 1.0f;
}
else
{
// Normalize probabilities
normalization_const = 0.0f;
bm_vel_spacings = beam_velocities[1] - beam_velocities[0];
for(i = 0; i < num_beam_vel_segs; i++)
{
bm_vel_squared[i] = beam_velocities[i] * beam_velocities[i];
// Use Trapezoid rule to "integrate" the probabilities
if((i == 0) || (i == num_beam_vel_segs - 1))
{
normalization_const += 0.5 * bm_vel_prob_dist[i];
}
else
{
normalization_const += bm_vel_prob_dist[i];
}
}
normalization_const *= bm_vel_spacings;
}// End of else for if(num_bm_vel_segs == 1)
}
// Divide everything in the array by the normalization constant
for(i = 0; i < num_beam_vel_segs; i++)
{
bm_vel_prob_dist[i] /= normalization_const;
}
}
public void SetLabVelocityArrays(float min_vel, float max_vel, int num_segs){
int i;
float difference, temp_velocity;
// Quick fixes for now; don't allow bad input to screw up calculations
if(num_segs > 0)
num_lab_vel_segs = num_segs;
if((min_vel < max_vel) && (min_vel >= 0))
{
min_lab_velocity = min_vel;
max_lab_velocity = max_vel;
}
difference = (max_lab_velocity - min_lab_velocity)/ (num_lab_vel_segs - 1);
lab_velocities = new float[num_lab_vel_segs];
lab_vel_squared = new float[num_lab_vel_segs];
for(i = 0; i < num_lab_vel_segs; i++)
{
temp_velocity = min_lab_velocity + i * difference;
lab_velocities[i] = temp_velocity;
lab_vel_squared[i] = temp_velocity * temp_velocity;
}
}
public void SetTOFInfo(float[] lab_array, float[] polarization_array, float[] depol, boolean[] is_polar){
int i;
float temp_angle, temp_depolar;
tof_lab_angles = lab_array;
tof_polarization_angles = polarization_array;
depolarization = depol;
tof_is_polarized = is_polar;
// Find cosines and sines of the angles and find polarization information
cos_theta_lab = new float[num_tofs];
sin_theta_lab = new float[num_tofs];
cos_polar_angle = new float[num_tofs];
sin_polar_angle = new float[num_tofs];
depolar_major = new float[num_tofs];
depolar_minor = new float[num_tofs];
for(i = 0; i < num_tofs; i++)
{
temp_angle = (float) (Math.PI/180f*(tof_lab_angles[i]));
cos_theta_lab[i] = (float) Math.cos(temp_angle);
sin_theta_lab[i] = (float) Math.sin(temp_angle);
if(tof_is_polarized[i] == true)
{
temp_angle = (float) (Math.PI/180f*(tof_polarization_angles[i]));
cos_polar_angle[i] = (float) Math.cos(temp_angle);
sin_polar_angle[i] = (float) Math.sin(temp_angle);
temp_depolar = depolarization[i];
depolar_major[i] = 1/(1 + temp_depolar);
depolar_minor[i] = temp_depolar/(1 + temp_depolar);
}
else
{
cos_polar_angle[i] = 1.0f;
sin_polar_angle[i] = 0.0f;
depolar_major[i] = 0.5f;
depolar_minor[i] = 0.5f;
}
}
}
public void SetTOFTimeInfo(float start_time, float end_time, int num_points)
{
starting_time = start_time;
ending_time = end_time;
num_tof_points = num_points;
}
public void ResetNumContribPOEs(){
num_poes = 0;
for(int i = 0; i < num_total_poes; i++)
{
if(data_for_poes.get(i).is_included)
{
num_poes++;
}
}
}
public void ReplacePOECalcData(boolean t_or_f){
ResetNumContribPOEs();
}
public void SetPOECalcData(){
int i, j, number_channels;
float mass1, mass2, temp_mass_ratio;
float sum;
num_poes = 0;
sum = 0.0f;
// Determine mass_ratios and scale all relative_weights
//
// Here, mass ratio is (m1 * (m1 + m2))/ (2*m2)
// Extra factor of 1/(4.184e6) is so units will be (kcal sec^2 / m^2 mol) so energies
// will be in units of kcal/mol
for(i = 0; i < num_total_poes; i++)
{
POECalcData this_poecalcdata = data_for_poes.get(i);
if(this_poecalcdata.is_included)
{
number_channels = this_poecalcdata.num_channels;
this_poecalcdata.mass_ratio = new float[number_channels];
for(j = 0; j < number_channels; j++)
{
mass1 = this_poecalcdata.mass_1[j];
mass2 = this_poecalcdata.mass_2[j];
temp_mass_ratio = (float) ((mass1 * (mass1 + mass2)) / (2 * 4.184e6 * mass2));
this_poecalcdata.mass_ratio[j] = temp_mass_ratio;
sum += this_poecalcdata.rel_weight[j];
num_poes++;
}
}
}
// Normalize the relative weights of all the channels
if(sum != 0.0)
{
for(i = 0; i < num_total_poes; i++)
{
POECalcData this_poecalcdata = data_for_poes.get(i);
if(this_poecalcdata.is_included)
{
for(j = 0; j < this_poecalcdata.num_channels; j++)
{
this_poecalcdata.rel_weight[j] /= sum;
}
}
}
}
}
public void SetTOF2CosGamma(){
int tof_num, theta_bm_num, phi_bm_num, theta_det_num, phi_det_num;
int num_bm_phis, num_det_phis;
//float time;
float[][][][] this_tof_2cos_gamma;
float[][][] this_det_theta_2cos_gamma;
float[][] this_det_phi_2cos_gamma;
float[] this_bm_theta_2cos_gamma;
float[] dereferenced_cos_phi_beam;
float[] dereferenced_sin_phi_beam;
float[] dereferenced_cos_phi_det;
float[] dereferenced_sin_phi_det;
float cos_lab_thistof;
float sin_lab_thistof;
float cos_this_beam_theta;
float sin_this_beam_theta;
float cos_this_beam_phi;
float sin_this_beam_phi;
float cos_this_det_theta;
float sin_this_det_theta;
float cos_this_det_phi;
float sin_this_det_phi;
//clock_t start, end;
//start = clock();
old_num_tofs = num_tofs;
old_num_theta_bm = num_beam_ang_segs;
old_num_theta_det = num_det_ang_segs;
if(num_tofs == 0)
{
TOF_2cos_gamma = null;
return;
}
// Allocate memory for this 5 dimensional array
TOF_2cos_gamma = new float[num_tofs][][][][];
for(tof_num = 0; tof_num < num_tofs; tof_num++)
{
TOF_2cos_gamma[tof_num] = new float[num_det_ang_segs][][][];
this_tof_2cos_gamma = TOF_2cos_gamma[tof_num];
cos_lab_thistof = cos_theta_lab[tof_num];
sin_lab_thistof = sin_theta_lab[tof_num];
for(theta_det_num = 0; theta_det_num < num_det_ang_segs; theta_det_num++)
{
num_det_phis = 3 * theta_det_num + 1;
//TOF_2cos_gamma[tof_num][theta_det_num] = new float**[num_det_phis];
this_tof_2cos_gamma[theta_det_num] = new float[num_det_phis][][];
this_det_theta_2cos_gamma = this_tof_2cos_gamma[theta_det_num];
cos_this_det_theta = (float) cos_theta_detector[theta_det_num];
sin_this_det_theta = (float) sin_theta_detector[theta_det_num];
dereferenced_cos_phi_det = cos_phi_detector[theta_det_num];
dereferenced_sin_phi_det = sin_phi_detector[theta_det_num];
for(phi_det_num = 0; phi_det_num < num_det_phis; phi_det_num++)
{
//TOF_2cos_gamma[tof_num][theta_det_num][phi_det_num] = new float*[num_bm_ang_segs];
this_det_theta_2cos_gamma[phi_det_num] = new float[num_beam_ang_segs][];
this_det_phi_2cos_gamma = this_det_theta_2cos_gamma[phi_det_num];
cos_this_det_phi = dereferenced_cos_phi_det[phi_det_num];
sin_this_det_phi = dereferenced_sin_phi_det[phi_det_num];
for(theta_bm_num = 0; theta_bm_num < num_beam_ang_segs; theta_bm_num++)
{
num_bm_phis = 3 * theta_bm_num + 1;
//TOF_2cos_gamma[tof_num][theta_det_num][phi_det_num][theta_bm_num] = new float[num_bm_phis];
this_det_phi_2cos_gamma[theta_bm_num] = new float[num_bm_phis];
this_bm_theta_2cos_gamma = this_det_phi_2cos_gamma[theta_bm_num];
cos_this_beam_theta = (float) cos_theta_beam[theta_bm_num];
sin_this_beam_theta = (float) sin_theta_beam[theta_bm_num];
dereferenced_cos_phi_beam = cos_phi_beam[theta_bm_num];
dereferenced_sin_phi_beam = sin_phi_beam[theta_bm_num];
for(phi_bm_num = 0; phi_bm_num < num_bm_phis; phi_bm_num++)
{
cos_this_beam_phi = dereferenced_cos_phi_beam[phi_bm_num];
sin_this_beam_phi = dereferenced_sin_phi_beam[phi_bm_num];
// Determine 2*cos(gamma) for each pair of detector & beam angles
// for later use in the Law of Cosines: c^2 = a^2 + b^2 - 2abcos(gamma)
// (For each TOF!)
this_bm_theta_2cos_gamma[phi_bm_num] = 2 *
( (sin_this_beam_theta*cos_this_beam_phi*sin_this_det_theta*cos_this_det_phi)
+ (sin_this_beam_theta*sin_this_beam_phi*sin_this_det_theta*sin_this_det_phi*cos_lab_thistof)
+ (sin_this_beam_theta*sin_this_beam_phi*cos_this_det_theta*sin_lab_thistof)
- (cos_this_beam_theta*sin_this_det_theta*sin_this_det_phi*sin_lab_thistof)
+ (cos_this_beam_theta*cos_this_det_theta*cos_lab_thistof) );
}
}
}
}
}
//end = clock();
//time = (end - start)/CLK_TCK;
//time *= 1.0;
//end = clock();
}
public TOFData[] RunMainFlightTimeCalculation(POEData[] poes, int num_new_tofs,
float beam_half_width, float det_half_width){
// For initial run-through, need to step through each new TOF which is being created
// and determine the TOF from all the input data. Then, the TOF must me created in the
// session document so it can be displayed with other TOF's.
/*float time;
clock_t start, end;
start = clock(); */
int[] number_channels;
Color[] tof_colors;
// Need to get the P(E)'s from the document when needed.
int i, tof_num, poe_num, chan_num, vel_num, bm_theta_num, bm_phi_num;
int bm_vel_num, det_theta_num, det_phi_num;
int this_num_channels, this_poe_num_points;
int this_num_det_phi_segs, this_num_bm_phi_segs;
int int_energy_pt, num_included_poes;
int min_lab_vel_num, max_lab_vel_num;
float half_width_sum_deg = beam_angular_width + detector_angular_width;
float half_width_sum = (float) (Math.PI/180*(half_width_sum_deg));
float cos_half_width_sum = (float) Math.cos(half_width_sum);
float sin_half_width_sum = (float) Math.sin(half_width_sum);
float cos_this_theta_lab, sin_this_theta_lab;
float cos_this_theta_bm, sin_this_theta_bm;
float sin_this_phi_bm, sin_this_phi_det, cos_theta_polar_major;
float poe_energy_inc_inverse, first_two_usqr_terms, lab_vel_times_bm_vel;
float u_squared, u_inverse;
float energy_point, lower_energy_amp, energy_amp;
float this_poe_beta;
float this_chan_mass_ratio, this_chan_inverse_mass_ratio, this_chan_rel_weight;
float this_poe_energy_min, this_poe_energy_max, this_poe_energy_increment;
float this_lab_velocity, this_lab_velocity_squared;
float this_bm_velocity, this_bm_vel_squared;
float[] this_poe_mass_ratios, this_poe_rel_weights;
float[] this_poe_energy_amp;
float cos_cos_term, sin_sin_term;
float cos_smallest_gamma, cos_largest_gamma;
float cos_theta_recoil, sin_theta_recoil;
float[] deref_sin_phi_det, deref_sin_phi_bm;
float this_depolar_minor, depolar_difference;
float this_cos_polar, this_sin_polar;
float cos_this_theta_det, sin_this_theta_det;
float[][][][] this_tof_2cos_gamma;
float[][][] this_det_theta_2cos_gamma;
float[][] this_det_phi_2cos_gamma;
float[] this_bm_theta_2cos_gamma;
float[][][][] prob_lab_vel;
float[][][] prob_lab_vel_this_tof;
float[][] pr_lv_this_poe;
float[] prob_lab_vel_this_chan;
float[][] tof_arrays_this_poe;
float[] tof_array_this_channel;
float[] tof_array_poe;
int tof_point_num, ion_point_num, time_seg_num;
float first_lab_vel;
float inverse_lab_vel_spacings;
float velocity_point, lower_vel_prob, this_tof_time, this_ionizer_count, this_distance;
float this_time_count, this_time_inverse, real_lab_vel;
int vel_point_int, count;
int count_vel = 0;
POECalcData current_poe_data;
POEData this_poe;
float u_smallest_squared, u_min_squared_poe;
float u_largest_squared, u_max_squared_poe;
float u_squared_v_first, u_squared_v_last;
float v_beam_smallest_u;
float v_beam_first, v_beam_last;
float v_beam_first_squared, v_beam_last_squared;
float amount_per_vel_seg, percent_done, amount_per_chan, amount_per_poe;
float lab_vel_times_cos_theta_det, bm_vel_times_cos_theta_bm_times_cos_theta_lab;
float bm_vel_times_cos_theta_bm_times_sin_theta_lab, lab_vel_times_sin_theta_det;
float lab_vel_times_sin_th_det_times_sin_phi_det;
float bm_vel_times_sin_theta_bm_times_cos_theta_lab, bm_vel_times_sin_theta_bm_times_sin_theta_lab;
float dwell_time_micro;
float det_phi_prob_sum, det_theta_prob_sum, bm_theta_prob_sum, bm_phi_prob_sum;
//float this_bm_vel_prob;
float min_u_squared_this_vel, max_u_squared_this_vel;
float[][][] this_tof_min_u_squared_array, this_tof_max_u_squared_array;
float[][] this_poe_min_u_squared_array, this_poe_max_u_squared_array;
float[] this_chan_min_u_squared_array, this_chan_max_u_squared_array;
float energy_min_over_energy_inc, mass_ratio_over_energy_inc;
float depolar_term_1, depolar_term_2;
float[] time_array_for_tofs = null;
float[][][] tof_arrays;
float[] total_tof_counts;
num_new_tofs = num_tofs;
if(num_tofs == 0)
{
calculated_tofs = null;
return null;
}
TOFData[] new_calc_tofs = new TOFData[num_tofs];
calculated_tofs = new_calc_tofs;
TOFData this_TOF;
//float*dummy1, *dummy2;
first_lab_vel = lab_velocities[0];
inverse_lab_vel_spacings = (float) (1.0 / (lab_velocities[1] - first_lab_vel));
v_beam_first = beam_velocities[0];
v_beam_first_squared = bm_vel_squared[0];
v_beam_last = beam_velocities[num_beam_vel_segs - 1];
v_beam_last_squared = bm_vel_squared[num_beam_vel_segs - 1];
dwell_time_micro = (ending_time - starting_time) / (num_tof_points - 1);
String tof_title;
String dummy;
prob_lab_vel = new float[num_tofs][][][];