-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphsController.java
More file actions
1565 lines (1186 loc) · 52.6 KB
/
Copy pathGraphsController.java
File metadata and controls
1565 lines (1186 loc) · 52.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 wf.view;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import org.jfree.chart.ChartPanel;
import org.jfree.data.xy.DefaultXYZDataset;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.SwingNode;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Separator;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import wf.util.Chart2D;
import wf.util.ComboBoxChLabels;
import wf.util.DataHistoHandler;
import wf.util.DataWaveformHandler;
import wf.util.ExportData;
import wf.util.NiceAxisScale;
import wf.util.RoundNumber;
public class GraphsController {
@FXML private AnchorPane graphs_ap;
@FXML private AnchorPane bottom_ap;
@FXML private AnchorPane top_ap;
@FXML private AnchorPane tabContainer1;
@FXML private AnchorPane tabContainer2;
@FXML private Button submit_bt;
@FXML private Button export_bt;
@FXML private Button reset_bt;
@FXML private Button smooth_bt;
@FXML private Button close_bt;
@FXML private ButtonBar bar_bb;
@FXML private LineChart<Number, Number> tab1_lineChart;
//@FXML private XYPlot<Number, Number> chartLineRight;
@FXML private NumberAxis lineChartXAxis;
@FXML private NumberAxis lineChartYAxis;
// @FXML private NumberAxis rightXAxis;
// @FXML private NumberAxis rightYAxis;
@FXML private ComboBoxChLabels tab1_chNumber_cb;
@FXML private ComboBox<String> tab1_parameter_cb;
@FXML private ComboBox<Integer> tab1_binning_cb;
@FXML private ComboBox<String> tab1_param1_cb;
@FXML private ComboBox<String> tab1_param2_cb;
@FXML private ComboBoxChLabels tab1_filter1ch_cb;
@FXML private ComboBoxChLabels tab1_filter2ch_cb;
@FXML private GridPane grid1_gr;
@FXML private GridPane tab1_grid1;
@FXML private GridPane tab1_grid2;
//@FXML private GridPane tab2_grid1;
//@FXML private GridPane tab2_grid2;
@FXML private HBox tab1_hb;
@FXML private HBox tab2_hb;
@FXML private Label title_lb;
@FXML private Label tab1_title_lb;
@FXML private Label tab1_chNumber_lb;
@FXML private Label tab1_parameter_lb;
@FXML private Label tab1_nBinning_lb;
@FXML private Label tab1_factor_lb;
@FXML private Label tab1_xAxisTitle_lb;
@FXML private Label tab1_xAxisMin_lb;
@FXML private Label tab1_xAxisMax_lb;
//@FXML private Label tab1_param1_lb;
//@FXML private Label tab1_param2_lb;
@FXML private Label tab1_totCounts_lb;
@FXML private Label tab1_totCountsValue_lb;
@FXML private Label tab1_integralRatio_lb;
@FXML private Label tab1_integralRatioValue_lb;
@FXML private Label tab1_filter1Ch_lb;
@FXML private Label tab1_filter2Ch_lb;
@FXML private Label tab1_filter1Par_lb;
@FXML private Label tab1_filter2Par_lb;
@FXML private Label tab1_filter1ParMin_lb;
@FXML private Label tab1_filter2ParMin_lb;
@FXML private Label tab1_filter1ParMax_lb;
@FXML private Label tab1_filter2ParMax_lb;
@FXML private Tab tab1_tp;
@FXML private Tab tab2_tp;
@FXML private TabPane graphs_tp;
@FXML private TextField tab1_xAxisMin_tf;
@FXML private TextField tab1_xAxisMax_tf;
@FXML private TextField tab1_scalingFactor_tf;
@FXML private TextField tab1_xAxisTitle_tf;
@FXML private TextField tab1_param1Min_tf;
@FXML private TextField tab1_param1Max_tf;
@FXML private TextField tab1_param2Min_tf;
@FXML private TextField tab1_param2Max_tf;
@FXML private VBox graphs_vb;
@FXML private VBox tab1_vb;
@FXML private VBox tab2_vb;
@FXML private VBox tab1_scrollP_vb;
@FXML private VBox tab2_scrollP_vb;
//settings Tab2, variable1
@FXML private ComboBoxChLabels tab21_chNumber_cb;
@FXML private ComboBox<String> tab21_parameter_cb;
@FXML private ComboBox<Integer> tab21_binning_cb;
@FXML private ComboBox<String> tab21_param1_cb;
@FXML private ComboBox<String> tab21_param2_cb;
@FXML private ComboBoxChLabels tab21_filter1ch_cb;
@FXML private ComboBoxChLabels tab21_filter2ch_cb;
//@FXML private GridPane grid1_gr;
@FXML private GridPane tab21_grid1;
@FXML private GridPane tab21_grid2;
//@FXML private HBox tab1_hb;
//@FXML private HBox tab2_hb;
//@FXML private Label title_lb;
@FXML private Label tab21_title_lb;
@FXML private Label tab21_chNumber_lb;
@FXML private Label tab21_parameter_lb;
@FXML private Label tab21_nBinning_lb;
@FXML private Label tab21_factor_lb;
@FXML private Label tab21_xAxisTitle_lb;
@FXML private Label tab21_xAxisMin_lb;
@FXML private Label tab21_xAxisMax_lb;
//@FXML private Label tab1_param1_lb;
//@FXML private Label tab1_param2_lb;
@FXML private Label tab21_totCounts_lb;
@FXML private Label tab21_totCountsValue_lb;
@FXML private Label tab21_integralRatio_lb;
@FXML private Label tab21_integralRatioValue_lb;
@FXML private Label tab21_filter1Ch_lb;
@FXML private Label tab21_filter2Ch_lb;
@FXML private Label tab21_filter1Par_lb;
@FXML private Label tab21_filter2Par_lb;
@FXML private Label tab21_filter1ParMin_lb;
@FXML private Label tab21_filter2ParMin_lb;
@FXML private Label tab21_filter1ParMax_lb;
@FXML private Label tab21_filter2ParMax_lb;
@FXML private TextField tab21_xAxisMin_tf;
@FXML private TextField tab21_xAxisMax_tf;
@FXML private TextField tab21_scalingFactor_tf;
@FXML private TextField tab21_xAxisTitle_tf;
@FXML private TextField tab21_param1Min_tf;
@FXML private TextField tab21_param1Max_tf;
@FXML private TextField tab21_param2Min_tf;
@FXML private TextField tab21_param2Max_tf;
//settings Tab2, variable2
@FXML private ComboBoxChLabels tab22_chNumber_cb;
@FXML private ComboBox<String> tab22_parameter_cb;
@FXML private ComboBox<Integer> tab22_binning_cb;
@FXML private ComboBox<String> tab22_param1_cb;
@FXML private ComboBox<String> tab22_param2_cb;
@FXML private ComboBoxChLabels tab22_filter1ch_cb;
@FXML private ComboBoxChLabels tab22_filter2ch_cb;
//@FXML private GridPane grid1_gr;
//@FXML private GridPane tab21_grid1;
//@FXML private GridPane tab21_grid2;
//@FXML private HBox tab1_hb;
//@FXML private HBox tab2_hb;
//@FXML private Label title_lb;
@FXML private Label tab22_title_lb;
@FXML private Label tab22_chNumber_lb;
@FXML private Label tab22_parameter_lb;
@FXML private Label tab22_nBinning_lb;
@FXML private Label tab22_factor_lb;
@FXML private Label tab22_xAxisTitle_lb;
@FXML private Label tab22_xAxisMin_lb;
@FXML private Label tab22_xAxisMax_lb;
//@FXML private Label tab1_param1_lb;
//@FXML private Label tab1_param2_lb;
@FXML private Label tab22_totCounts_lb;
@FXML private Label tab22_totCountsValue_lb;
@FXML private Label tab22_integralRatio_lb;
@FXML private Label tab22_integralRatioValue_lb;
@FXML private Label tab22_filter1Ch_lb;
@FXML private Label tab22_filter2Ch_lb;
@FXML private Label tab22_filter1Par_lb;
@FXML private Label tab22_filter2Par_lb;
@FXML private Label tab22_filter1ParMin_lb;
@FXML private Label tab22_filter2ParMin_lb;
@FXML private Label tab22_filter1ParMax_lb;
@FXML private Label tab22_filter2ParMax_lb;
@FXML private TextField tab22_xAxisMin_tf;
@FXML private TextField tab22_xAxisMax_tf;
@FXML private TextField tab22_scalingFactor_tf;
@FXML private TextField tab22_xAxisTitle_tf;
@FXML private TextField tab22_param1Min_tf;
@FXML private TextField tab22_param1Max_tf;
@FXML private TextField tab22_param2Min_tf;
@FXML private TextField tab22_param2Max_tf;
//@FXML private Label wfNumber_lb;
//@FXML private Label wfNumberDisplay_lb;
//@FXML private Label next_lb;
//@FXML private Label previous_lb;
@FXML private Separator north_sp;
@FXML private Separator south_sp;
@FXML private StackPane tab1_sp;
@FXML private StackPane tab2_sp;
//@FXML private VBox grid_container_vb;
@FXML private ScrollPane tab1_scrollP;
@FXML private ScrollPane tab2_scrollP;
private List<String> parameterNames = Arrays.asList(
"OFF", "Amp", "Amp-0.9", "Amp-0.5", "Amp-0.1", "BG", "CH", "FT",
"NPs", "RT", "SL", "TP", "TP-0.9L", "TP-0.5L", "TP-0.1L",
"TP-0.9T", "TP-0.5T", "TP-0.1T", "ToT");
private List<Integer> binningValues = Arrays.asList(
10, 20, 50, 100, 200, 500, 1000);
private double min1D;
private double max1D;
private double min2Dx;
private double min2Dy;
private double max2Dx;
private double max2Dy;
private double dataValue;
private double dataValue2Dx;
private double dataValue2Dy;
private double dataValueXpos;
private double tempDataValue;
private double stepValue;
private double stepValue2Dx;
private double stepValue2Dy;
private double totalCounts1D = 0.0;
private double ratio1D = 0.0;
private double totalCounts2Dx = 0.0;
private double ratio2Dx = 0.0;
private double totalCounts2Dy = 0.0;
private double ratio2Dy = 0.0;
private double niceMin1D; // values computed with NiceAxisScale class
private double niceMax1D;
private double niceMin2Dx; // values computed with NiceAxisScale class
private double niceMax2Dx;
private double niceMin2Dy; // values computed with NiceAxisScale class
private double niceMax2Dy;
private double tempParamValue;
private double tempFilterParamValue;
private double param1Min1D;
private double param1Max1D;
private double param2Min1D;
private double param2Max1D;
private double param1Min2Dx;
private double param1Max2Dx;
private double param2Min2Dx;
private double param2Max2Dx;
private double param1Min2Dy;
private double param1Max2Dy;
private double param2Min2Dy;
private double param2Max2Dy;
private double dataValue1DFilter1;
private double dataValue1DFilter2;
private double dataValue2DxFilter1;
private double dataValue2DxFilter2;
private double dataValue2DyFilter1;
private double dataValue2DyFilter2;
private int filter1DParam1channel;
private int filter1DParam2channel;
private int filter2DXParam1channel;
private int filter2DXParam2channel;
private int filter2DYParam1channel;
private int filter2DYParam2channel;
private int filter1DParam1SelectedIndex;
private int filter1DParam2SelectedIndex;
private int filter2DXParam1SelectedIndex;;
private int filter2DXParam2SelectedIndex;;
private int filter2DYParam1SelectedIndex;;
private int filter2DYParam2SelectedIndex;;
//private int selectedChannel;
private int size;
private int size2Dx;
private int size2Dy;
private int bin2Dx;
private int bin2Dy;
private int maxZvalue;
private int sumZvalue;
//private double maxZvalueX;
//private double maxZvalueY;
private double sumYValue;
private double sumYValueWeighted;
//private final int sm_div1 = 3; // divider constant for 3 points smoothing
private final int sm_div2 = 9; // divider constant for 5 points smoothing
//private final int sm_div3 = 27; // divider constant for 7 points smoothing
private final List<Integer> sm_k2 = new ArrayList<Integer>(Arrays.asList(1,2,3,2,1));
//private final List<Integer> sm_k3 = new ArrayList<Integer>(Arrays.asList(1,3,6,7,6,3,1));
private int sm_kIndex; //index used to loop through the coefficients
private int seriesSize;
private List<String> infoGraph = new ArrayList<>();
//private List<Integer> histoData2Dx = new ArrayList<>();
//private List<Integer> histoData2Dy = new ArrayList<>();
private List<Integer> histoData = new ArrayList<>();
private List<Double> Zval = new ArrayList<>();
private List<Double> Yval = new ArrayList<>();
private List<Double> Xval = new ArrayList<>();
private Double[] tempAxisValues = new Double[2]; // index 0 = Min; index 1 = Max;
private List<Integer[]> matrix2D = new ArrayList<>();
private XYChart.Series<Number, Number> series = new XYChart.Series<>();
private XYChart.Series<Number, Number> seriesSmoothed = new XYChart.Series<>();
//private static DataHistoHandler dataHistoHandler = DataHistoHandler.getInstance();
private static Chart2D chart2D = Chart2D.getInstance();
private static ExportData ed = ExportData.getInstance();
private NiceAxisScale nas = NiceAxisScale.getInstance();
private final Pattern factor_pt = Pattern.compile("\\d{0,5}(\\.\\d{0,5})?$");
private final BooleanProperty graphGenerated = new SimpleBooleanProperty(false);
private final BooleanProperty graph2DGenerated = new SimpleBooleanProperty(false);
private final SwingNode chartSwingNode = new SwingNode();
private final ChartPanel chartPanel = new ChartPanel(chart2D.getChart2D());
private final DataHistoHandler dataHistoHandler = DataHistoHandler.getInstance();
private final RoundNumber rn = RoundNumber.getInstance();
@FXML
public void initialize() {
initStyle();
initButtonBindings();
initComboBoxes();
initTextFields();
initGraph(tab1_grid1);
initGraph(tab21_grid1);
initGraph(tab21_grid2);
overwriteInitValues();
tab1_title_lb.setText("Settings");
tab21_title_lb.setText("Settings");
tab22_title_lb.setText("Settings");
tab1_integralRatioValue_lb.setText("0.0%");
tab21_integralRatioValue_lb.setText("0.0%");
tab22_integralRatioValue_lb.setText("0.0%");
tab1_sp.setMaxSize(500, 400);
tab2_sp.setMaxSize(500, 400);
tab1_lineChart.setLegendVisible(false);
tab1_lineChart.setAnimated(false);
lineChartXAxis.setAutoRanging(false);
//Stuff related to initialise Chart2D
//chartSwingNode.setContent(new ChartPanel(chart2D.getChart2D()));
chartSwingNode.setContent(chartPanel);
tab2_sp.getChildren().add(chartSwingNode);
chart2D.setXaxisTitle("A. U.");
chart2D.setYaxisTitle("A. U.");
}
@FXML
private void exitAction() {
tab1_chNumber_cb.removeCellFactoryButtonCell();
tab1_filter1ch_cb.removeCellFactoryButtonCell();
tab1_filter2ch_cb.removeCellFactoryButtonCell();
tab21_chNumber_cb.removeCellFactoryButtonCell();
tab21_filter1ch_cb.removeCellFactoryButtonCell();
tab21_filter2ch_cb.removeCellFactoryButtonCell();
tab22_chNumber_cb.removeCellFactoryButtonCell();
tab22_filter1ch_cb.removeCellFactoryButtonCell();
tab22_filter2ch_cb.removeCellFactoryButtonCell();
//chart2D.clearPlotData();
graphGenerated.set(false);
graph2DGenerated.set(false);
//tab1_scalingFactor_tf.setText("");
//chartLineLeft.getData().clear();
//chartLineRight.getData().clear();
//System.out.println(chartLineLeft.getData().size());
//wfSlider_sl.valueProperty().removeListener(slider_cl);
graphs_ap.getScene().getWindow().hide();
}
@FXML
private void resetAction() {
initGraph(tab1_grid1);
initGraph(tab21_grid1);
initGraph(tab21_grid2);
overwriteInitValues();
}
@FXML
private void exportAction() {
if(tab1_tp.isSelected()) {
infoGraph.clear();
Xval.clear();
Yval.clear();
infoGraph.add("Settings");
infoGraph.add("Channel : " + tab1_chNumber_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Variable : " + tab1_parameter_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Binning : " + tab1_binning_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Factor : " + tab1_scalingFactor_tf.getText());
infoGraph.add("Step : " + stepValue);
infoGraph.add("Filter P1, min, max : "
+ tab1_param1_cb.getSelectionModel().getSelectedItem()
+ ", " + String.valueOf(param1Min1D)
+ ", " + String.valueOf(param1Max1D));
infoGraph.add("Filter P2, min, max : "
+ tab1_param2_cb.getSelectionModel().getSelectedItem()
+ ", " + String.valueOf(param2Min1D)
+ ", " + String.valueOf(param2Max1D));
for(int d = 0; d < tab1_lineChart.getData().get(0).getData().size(); d++) {
Xval.add(rn.round(tab1_lineChart.getData().get(0).getData().get(d).getXValue().doubleValue(),5));
Yval.add(rn.round(tab1_lineChart.getData().get(0).getData().get(d).getYValue().doubleValue(),5));
}
ed.setDataSeries(Xval, Yval);
ed.writeGraphDataToDisk(tab1_chNumber_cb.getSelectionModel().getSelectedIndex(),
tab1_parameter_cb.getSelectionModel().getSelectedItem());
}
if(tab2_tp.isSelected()) {
infoGraph.clear();
Xval.clear();
Yval.clear();
Zval.clear();
//X axis
infoGraph.add("Settings [X]");
infoGraph.add("Channel : " + tab21_chNumber_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Variable : " + tab21_parameter_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Binning : " + tab21_binning_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Factor : " + tab21_scalingFactor_tf.getText());
infoGraph.add("Step : " + stepValue2Dx);
infoGraph.add("Filter P1, min, max : "
+ tab21_param1_cb.getSelectionModel().getSelectedItem()
+ ", " + String.valueOf(param1Min2Dx)
+ ", " + String.valueOf(param1Max2Dx));
infoGraph.add("Filter P2, min, max : "
+ tab21_param2_cb.getSelectionModel().getSelectedItem()
+ ", " + String.valueOf(param2Min2Dx)
+ ", " + String.valueOf(param2Max2Dx));
infoGraph.add("Settings [Y]");
infoGraph.add("Channel : " + tab22_chNumber_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Variable : " + tab22_parameter_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Binning : " + tab22_binning_cb.getSelectionModel().getSelectedItem());
infoGraph.add("Factor : " + tab22_scalingFactor_tf.getText());
infoGraph.add("Step : " + stepValue2Dy);
infoGraph.add("Filter P1, min, max : "
+ tab22_param1_cb.getSelectionModel().getSelectedItem()
+ ", " + String.valueOf(param1Min2Dy)
+ ", " + String.valueOf(param1Max2Dy));
infoGraph.add("Filter P2, min, max : "
+ tab22_param2_cb.getSelectionModel().getSelectedItem()
+ ", " + String.valueOf(param2Min2Dy)
+ ", " + String.valueOf(param2Max2Dy));
ed.setInfoGraph(infoGraph);
//Add a zero point. The real values are shifted 1/2 stepValue more
//Xval.add(0.0);
//Yval.add(0.0);
//Zval.add(0.0);
for (int i = 0; i < matrix2D.size(); i++) {
for (int j = 0; j < matrix2D.get(i).length; j++) {
if(matrix2D.get(i)[j] > 0) {
Xval.add(rn.round(stepValue2Dx*i*
Double.parseDouble(tab21_scalingFactor_tf.getText())
+(stepValue2Dx/2),5));
Yval.add(rn.round(stepValue2Dy*j*
Double.parseDouble(tab22_scalingFactor_tf.getText())
+(stepValue2Dy/2),5));
Zval.add((double) matrix2D.get(i)[j]);
}
}
}
ed.set2DDataSeries(Xval, Yval, Zval);
ed.write2DGraphDataToDisk(tab21_chNumber_cb.getSelectionModel().getSelectedIndex(),
tab21_parameter_cb.getSelectionModel().getSelectedItem(),
tab22_chNumber_cb.getSelectionModel().getSelectedIndex(),
tab22_parameter_cb.getSelectionModel().getSelectedItem());
}
}
@FXML
private void smoothAction() {
tab1_lineChart.getData().clear();
seriesSmoothed.getData().clear();
seriesSize = series.getData().size();
//the first and last two points are set to zero. Using 5 point smoothing filter
dataValueXpos = series.getData().get(0).getXValue().doubleValue();
seriesSmoothed.getData().add((new XYChart.Data<Number, Number>(dataValueXpos, 0)));
dataValueXpos = series.getData().get(1).getXValue().doubleValue();
seriesSmoothed.getData().add((new XYChart.Data<Number, Number>(dataValueXpos, 0)));
for(int s = 2; s < seriesSize-2; s++) {
sumYValue = 0;
sumYValueWeighted = 0;
sm_kIndex = 0;
//evaluate weighted point from raw data
for(int j = s-2; j < s+3; j++) {
sumYValue = sumYValue +
(double) series.getData().get(j).getYValue().doubleValue()
* (double) sm_k2.get(sm_kIndex);
sm_kIndex++;
}
sumYValueWeighted = sumYValue / (double) sm_div2;
//System.out.println(sumYValueWeighted);
dataValueXpos = series.getData().get(s).getXValue().doubleValue();
seriesSmoothed.getData().add(new XYChart.Data<Number, Number>(dataValueXpos, rn.round(sumYValueWeighted, 2)));
}
//last to points set to 0
seriesSmoothed.getData().add((new XYChart.Data<Number, Number>(seriesSize-2, 0.0)));
seriesSmoothed.getData().add((new XYChart.Data<Number, Number>(seriesSize-1, 0.0)));
//Fill chart
tab1_lineChart.getData().add(seriesSmoothed);
}
@FXML
private void submitAction() {
if(tab1_tp.isSelected()) {
preparePlot(tab1_chNumber_cb.getSelectionModel().getSelectedIndex(),
tab1_parameter_cb.getSelectionModel().getSelectedIndex(),
tab1_binning_cb.getSelectionModel().getSelectedItem());
}
if(tab2_tp.isSelected()) {
prepare2DPlot(tab21_chNumber_cb.getSelectionModel().getSelectedIndex(),
tab21_parameter_cb.getSelectionModel().getSelectedIndex(),
tab21_binning_cb.getSelectionModel().getSelectedItem(),
tab22_chNumber_cb.getSelectionModel().getSelectedIndex(),
tab22_parameter_cb.getSelectionModel().getSelectedIndex(),
tab22_binning_cb.getSelectionModel().getSelectedItem());
}
}
private void preparePlot(int channel, int parameter, int binning) {
histoData.clear();
series.getData().clear();
tab1_lineChart.getData().clear();
lineChartXAxis.setLabel(tab1_parameter_cb.getSelectionModel().getSelectedItem()
+ " " + tab1_xAxisTitle_tf.getText());
size = DataWaveformHandler.getWaveforms().get(channel).size();
//initialise data for histogram
for(int i = 0; i < binning; i++) {
histoData.add(0);
}
if(size > 0) {
//add channels related for filtering
dataProc(channel, size, Double.parseDouble(tab1_scalingFactor_tf.getText()),
binning, tab1_parameter_cb.getSelectionModel().getSelectedIndex()); }
}
private void prepare2DPlot(int channel1, int parameter1, int binning2DyDx,
int channel2, int parameter2, int binning2Dy) {
matrix2D.clear();
chart2D.setXaxisTitle(tab21_parameter_cb.getSelectionModel().getSelectedItem()
+ " " + tab21_xAxisTitle_tf.getText());
chart2D.setYaxisTitle(tab22_parameter_cb.getSelectionModel().getSelectedItem()
+ " " + tab22_xAxisTitle_tf.getText());
size2Dx = DataWaveformHandler.getWaveforms().get(channel1).size();
size2Dy = DataWaveformHandler.getWaveforms().get(channel2).size();
if((size2Dx > 0) && (size2Dy > 0)) {
dataProc2D(channel1, size2Dx, Double.parseDouble(tab21_scalingFactor_tf.getText()),
binning2DyDx, tab21_parameter_cb.getSelectionModel().getSelectedIndex(),
channel2, size2Dy, Double.parseDouble(tab22_scalingFactor_tf.getText()),
binning2Dy, tab22_parameter_cb.getSelectionModel().getSelectedIndex());
}
}
//Parameter functions
private void dataProc(int channel, int size, double factor, int binning, int method) {
filter1DParam1channel = tab1_filter1ch_cb.getSelectionModel().getSelectedIndex();
filter1DParam2channel = tab1_filter2ch_cb.getSelectionModel().getSelectedIndex();
filter1DParam1SelectedIndex = tab1_param1_cb.getSelectionModel().getSelectedIndex()-1;
filter1DParam2SelectedIndex = tab1_param2_cb.getSelectionModel().getSelectedIndex()-1;
//prepare textfields filter max and min values
param1Min1D = getFilterParamValueMin(tab1_param1Min_tf, filter1DParam1SelectedIndex);
param2Min1D = getFilterParamValueMin(tab1_param2Min_tf, filter1DParam2SelectedIndex);
param1Max1D = getFilterParamValueMax(tab1_param1Max_tf, filter1DParam1SelectedIndex);
param2Max1D = getFilterParamValueMax(tab1_param2Max_tf, filter1DParam2SelectedIndex);
//Retrieve Max and Min for nice axis values
computeAxisValues(channel, size, method);
min1D = getMinValueAxis(); // absolute Min and Max retrieved from all data
max1D = getMaxValueAxis();
setAxisValues(tab1_xAxisMin_tf, tab1_xAxisMax_tf, factor, min1D, max1D, "X");
niceMin1D = nas.getNiceMin();
niceMax1D = nas.getNiceMax();
//Calculate step equal to the bin dimension
stepValue = rn.round( (double) (niceMax1D - niceMin1D) / (double) binning, 5);
//System.out.println("NiceMin " + niceMin1D);
//System.out.println("NiceMax " + niceMax1D);
//System.out.println("Step " + stepValue);
//fill histo data
//Loop through waveforms
for(int w = 0; w < size; w++) {
dataValue = factor*getDataValue(channel, w, method);
//these values only have to be multiplied by factor scaling
dataValue1DFilter1 = factor*getFilterParamValue(filter1DParam1channel, w, filter1DParam1SelectedIndex);
dataValue1DFilter2 = factor*getFilterParamValue(filter1DParam2channel, w, filter1DParam2SelectedIndex);
//Loop through histodata
for(int h = 0; h < binning; h++) {
if(((param1Min1D) <= dataValue1DFilter1) && ((param1Max1D) >= dataValue1DFilter1)) {
if(((param2Min1D) <= dataValue1DFilter2) && ((param2Max1D) >= dataValue1DFilter2)) {
if(((niceMin1D + stepValue*h) <= dataValue) && ((niceMin1D + stepValue*(h+1)) >= dataValue)) {
histoData.set(h, histoData.get(h)+1);
break;
}
}
}
}
}
fillSeries(binning, stepValue, factor);
}
//Parameter functions
private void dataProc2D(int channel1, int size2Dx, double factor1, int binning2DyDx, int method1,
int channel2, int size2Dy, double factor2, int binning2Dy, int method2) {
filter2DXParam1channel = tab21_filter1ch_cb.getSelectionModel().getSelectedIndex();
filter2DXParam2channel = tab21_filter2ch_cb.getSelectionModel().getSelectedIndex();
filter2DYParam1channel = tab22_filter1ch_cb.getSelectionModel().getSelectedIndex();
filter2DYParam2channel = tab22_filter2ch_cb.getSelectionModel().getSelectedIndex();
filter2DXParam1SelectedIndex = tab21_param1_cb.getSelectionModel().getSelectedIndex()-1;
filter2DXParam2SelectedIndex = tab21_param2_cb.getSelectionModel().getSelectedIndex()-1;
filter2DYParam1SelectedIndex = tab22_param1_cb.getSelectionModel().getSelectedIndex()-1;
filter2DYParam2SelectedIndex = tab22_param2_cb.getSelectionModel().getSelectedIndex()-1;
//prepare textfields filter max and min values
//first parameter X
param1Min2Dx = getFilterParamValueMin(tab21_param1Min_tf, filter2DXParam1SelectedIndex);
param1Max2Dx = getFilterParamValueMax(tab21_param1Max_tf, filter2DXParam1SelectedIndex);
//second parameter X
param2Min2Dx = getFilterParamValueMin(tab21_param2Min_tf, filter2DXParam2SelectedIndex);
param2Max2Dx = getFilterParamValueMax(tab21_param2Max_tf, filter2DXParam2SelectedIndex);
//first parameter Y
param1Min2Dy = getFilterParamValueMin(tab22_param1Min_tf, filter2DYParam1SelectedIndex);
param1Max2Dy = getFilterParamValueMax(tab22_param1Max_tf, filter2DYParam1SelectedIndex);
//second parameter Y
param2Min2Dy = getFilterParamValueMin(tab22_param2Min_tf, filter2DYParam2SelectedIndex);
param2Max2Dy = getFilterParamValueMax(tab22_param2Max_tf, filter2DYParam2SelectedIndex);
//Retrieve Max and Min for nice axis values
//2D X axis
computeAxisValues(channel1, size2Dx, method1);
min2Dx = getMinValueAxis();
max2Dx = getMaxValueAxis();
setAxisValues(tab21_xAxisMin_tf, tab21_xAxisMax_tf, factor1, min2Dx, max2Dx, "X");
niceMin2Dx = nas.getNiceMin();
niceMax2Dx = nas.getNiceMax();
//Calculate step equal to the bin dimension
stepValue2Dx = (niceMax2Dx - niceMin2Dx) / (double) binning2DyDx;
//2D Y axis
computeAxisValues(channel2, size2Dy, method2);
min2Dy = getMinValueAxis();
max2Dy = getMaxValueAxis();
setAxisValues(tab22_xAxisMin_tf, tab22_xAxisMax_tf, factor2, min2Dy, max2Dy, "Y");
niceMin2Dy = nas.getNiceMin();
niceMax2Dy = nas.getNiceMax();
//Calculate step equal to the bin dimension
stepValue2Dy = (niceMax2Dy - niceMin2Dy) / (double) binning2Dy;
//Initialise 2 dimensional matrix
for(int i = 0; i < binning2DyDx; i++) {
Integer[] array = new Integer[binning2Dy];
for(int j = 0; j < binning2Dy; j++) {
array[j] = 0;
}
matrix2D.add(array);
}
totalCounts2Dx = 0;
totalCounts2Dy = 0;
ratio2Dx = 0;
ratio2Dy = 0;
//size arbitrary chosen as that for the X variable
for(int w = 0; w < size2Dx; w++) {
//get value related to the parameter 1,2 2Dx selected
dataValue2DxFilter1 = factor1*getFilterParamValue(filter2DXParam1channel, w, filter2DXParam1SelectedIndex);
dataValue2DxFilter2 = factor1*getFilterParamValue(filter2DXParam2channel, w, filter2DXParam2SelectedIndex);
//get value related to the parameter 1,2 2Dy selected
dataValue2DyFilter1 = factor2*getFilterParamValue(filter2DYParam1channel, w, filter2DYParam1SelectedIndex);
dataValue2DyFilter2 = factor2*getFilterParamValue(filter2DYParam2channel, w, filter2DYParam2SelectedIndex);
dataValue2Dx = factor1*getDataValue(channel1, w, method1);
dataValue2Dy = factor2*getDataValue(channel2, w, method2);
//Apply filters
//Now let's find to which index i and j the values correspond
//Use this loop to retrieve how many data > 0 are taken to calculate ratio integral
bin2Dx = 0;
bin2Dy = 0;
//Filter x
if(((param1Min2Dx) <= dataValue2DxFilter1) && ((param1Max2Dx) >= dataValue2DxFilter1)) {
if(((param2Min2Dx) <= dataValue2DxFilter2) && ((param2Max2Dx) >= dataValue2DxFilter2)) {
for (int i = 0; i < binning2DyDx; i++) {
if(((niceMin2Dx + stepValue2Dx*i) <= dataValue2Dx) && ((niceMin2Dx + stepValue2Dx*(i+1)) >= dataValue2Dx)) {
totalCounts2Dx++;
bin2Dx = i;
break;
}
}
}
}
//Filter y
if(((param1Min2Dy) <= dataValue2DyFilter1) && ((param1Max2Dy) >= dataValue2DyFilter1)) {
if(((param2Min2Dy) <= dataValue2DyFilter2) && ((param2Max2Dy) >= dataValue2DyFilter2)) {
for (int j = 0; j < binning2Dy; j++) {
if(((niceMin2Dy + stepValue2Dy*j) <= dataValue2Dy) && ((niceMin2Dy + stepValue2Dy*(j+1)) >= dataValue2Dy)) {
totalCounts2Dy++;
bin2Dy = j;
break;
}
}
}
}
//update matrix
matrix2D.get(bin2Dx)[bin2Dy]++;
}
//retrieve Z max
maxZvalue = 0;
sumZvalue = 0;
//maxZvalueX = 0;
//maxZvalueY = 0;
for (int i = 0; i < binning2DyDx; i++) {
for (int j = 0; j < binning2Dy; j++) {
if(matrix2D.get(i)[j] >= maxZvalue) {
maxZvalue = matrix2D.get(i)[j];
//maxZvalueX = i;
//maxZvalueY = j;
}
sumZvalue = sumZvalue + matrix2D.get(i)[j];
}
}
DefaultXYZDataset dataset = new DefaultXYZDataset();
for (int i = 0; i < binning2DyDx; i++) {
for (int j = 0; j < binning2Dy; j++) {
if(matrix2D.get(i)[j] > 0) {
dataset.addSeries("Series"+String.valueOf(i)+"_"+String.valueOf(j),
//new double[][]{{(i*stepValue2Dx)-stepValue2Dx/2},
new double[][]{{(niceMin2Dx + i*stepValue2Dx)},
{(niceMin2Dy + j*stepValue2Dy)},
{matrix2D.get(i)[j]}});
}
}
}
chart2D.updateLegend(maxZvalue, stepValue2Dx, stepValue2Dy);
chart2D.setXYZdataset(dataset);
ratio2Dx = totalCounts2Dx / size2Dx * 100;
ratio2Dy = totalCounts2Dy / size2Dy * 100;
tab21_totCountsValue_lb.setText(String.valueOf((int) totalCounts2Dx));
tab21_integralRatioValue_lb.setText(String.valueOf(rn.round(ratio2Dx,2) + "%"));
tab22_totCountsValue_lb.setText(String.valueOf((int) totalCounts2Dy));
tab22_integralRatioValue_lb.setText(String.valueOf(rn.round(ratio2Dy,2) + "%"));
graph2DGenerated.set(true);
//System.out.println("SumZValue " + sumZvalue);
/*
*
//print Matrix
for(int i = 0; i < binning2DyDx; i ++) {
for(int j = 0; j < binning2Dy; j ++) {
System.out.print(matrix2D.get(i)[j] + ", ");
}
System.out.println();
} */
}
private void fillSeries(int binning, double step, double factor) {
totalCounts1D = 0;
//Add an artificial zero otherwise graphs at zero are not connected when binning is small especially
series.getData().add(new XYChart.Data<Number, Number>(0, 0));
for(int s = 0; s < binning; s++) {
//step/2 to center the bin width
series.getData().add(new XYChart.Data<Number, Number>(niceMin1D + rn.round(step*s+(step/2),5), histoData.get(s)));
//System.out.println(s + " " + (niceMin1D + rn.round(step*s+(step/2),5) + " " + histoData.get(s)));
totalCounts1D = totalCounts1D + histoData.get(s);
//series.getData().add(new XYChart.Data<Number, Number>(step*s*factor, histoData.get(s)));
}
ratio1D = totalCounts1D / size * 100;
//Fill chart
tab1_lineChart.getData().add(series);
tab1_totCountsValue_lb.setText(String.valueOf((int) totalCounts1D));
tab1_integralRatioValue_lb.setText(String.valueOf(rn.round(ratio1D,2) + "%"));
graphGenerated.set(true);
}
private double getDataValue(int channel, int wf, int method) {
tempDataValue = 0.0;
//to avid exceptions due to having two channels with different sizes
if(DataWaveformHandler.getWaveforms().get(channel).size() > wf) {
switch(method) {
//case -1:
//tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_ID();
//break;
case 0:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_amp();
break;
case 1:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_amp_90p();
break;
case 2:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_amp_50p();
break;
case 3:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_amp_10p();
break;
case 4:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_bg();
break;
case 5:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_charge();
break;
case 6:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_ft();
break;
case 7:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_n_peaks();
break;
case 8:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_rt();
break;
case 9:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_slope();
break;
case 10:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_peak_time();
break;
case 11:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_peak_time_l90p();
break;
case 12:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_peak_time_l50p();
break;
case 13:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_peak_time_l10p();
break;
case 14:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_peak_time_t90p();
break;
case 15:
tempDataValue = DataWaveformHandler.getWaveforms().get(channel).get(wf).get_wf_peak_time_t50p();
break;