-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaw_lukas.cxx
2222 lines (2078 loc) · 95.8 KB
/
aw_lukas.cxx
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
/**************************************
Initial code by [email protected] and [email protected]
Written by [email protected]
modified for single board / self triggered readout
**************************************/
// aw_lukas specific header
#include "aw_lukas.h"
using namespace RooFit;
using namespace std;
using namespace chrono;
using namespace RooFit;
int main(int argc, char *argv[])
{
// Timer for program execution time measurement
high_resolution_clock::time_point t_total_begin = high_resolution_clock::now();
///////////////////////////////////////////////////////////////
// Read all existing command line argunments and file names
///////////////////////////////////////////////////////////////
char inputfile[200];
char outputfile[200];
char outputfile_proto_trace[200];
char outputfile_energy_calib[200];
char configfile[200];
unsigned int no_of_events=0, do_no_of_events=0;
int realign_first_NOE=0;
// Parse the input file
if(argc<=1){
printf("No datafile set!!!\n");
print_usage();
return(-1);
}
strcpy(inputfile, argv[1]);
// Parse the output file
if(argc<=2){
printf("No outputfile declared.\n");
sprintf(outputfile,"%s.root",argv[1]);
printf("outputfile set to: %s\n",outputfile);
}
else strcpy(outputfile, argv[2]);
// Parse the config file
bool conf_exists = false;
if(argc<=3){
printf("No config file set, using standard or command line parameters.\n");
}
else {
conf_exists = true;
strcpy(configfile, argv[3]);
printf("Config file read in: %s\n",configfile);
}
// Now parse all command line options
for(int n=0; n<argc; n++){
if(strstr(argv[n],"-n")!=NULL){ // set stop after # of counts
n++;
printf("Max count enabled!\n");
if(n<argc){
do_no_of_events=1;
no_of_events=atoi(argv[n]);
}
else{
printf("Missing max. number of events!\n");
return(-1);
}
}
// Reading of Digital threshold
if(strstr(argv[n],"-t")!=NULL){
n++;
if(n<argc){
THRESHOLD_MULTIPLICY=atoi(argv[n]);
printf("Software threshold multiplicy set to: %3.2f !\n", THRESHOLD_MULTIPLICY);
}
else{
printf("Missing treshold multiplicy!\n");
return(-1);
}
}
// Reading of glitch filter settings
if(strstr(argv[n],"-g")!=NULL){ // set stop after # of counts
n++;
if(n<argc){
GLITCH_FILTER_RANGE=atoi(argv[n]);
GLITCH_FILTER = true;
printf("Glitch filter range set to: %i !\n", GLITCH_FILTER_RANGE);
}
else{
printf("Missing glitch filter parameter!\n");
return(-1);
}
}
if(strstr(argv[n],"-L")!=NULL){ // set stop after # of counts
n++;
if(n<argc){
L=atoi(argv[n]);
printf("Moving average range set to: %i !\n", L);
}
// Check if L is odd
if (L%2 == 0){
printf("SETTINGS ERROR: MA window must be odd!\n");
return(-1);
}
}
if(strstr(argv[n],"-d")!=NULL){ // set stop after # of counts
n++;
if(n<argc){
DELAY=atoi(argv[n]);
printf("DELAY for CFD set to: %i !\n", DELAY);
}
}
if(strstr(argv[n],"-f")!=NULL){ // set stop after # of counts
n++;
if(n<argc){
CFD_fraction=atof(argv[n]);
if ( CFD_fraction < 1. && CFD_fraction > 0. ){
printf("Fraction for CFD set to: %f !\n", CFD_fraction);
}
else{
printf("SETTINGS ERROR: CFD fraction must be set between 0 and 1!\n");
return(-1);
}
}
}
if(strstr(argv[n],"-M")!=NULL){ // set stop after # of counts
n++;
if(n<argc){
M=atoi(argv[n]);
printf("Window length for MWD set to: %i !\n", M);
}
// Check if M is odd
if (M%2 == 0){
printf("SETTINGS ERROR: MWD window must be odd!\n");
return(-1);
}
}
if(strstr(argv[n],"-v")!=NULL){ // turn verbose output on
n++;
if(n<argc){
strcpy(VERBOSE, argv[n]);
printf("Verbose options set to: %s !\n", VERBOSE);
}
}
if(strstr(argv[n],"-I")!=NULL){ // set the number of inter samples
// Check if MULTIS is 1, 2, or 4
n++;
if (atoi(argv[n]) == 1 || atoi(argv[n]) == 2 || atoi(argv[n]) == 4){
if(n<argc){
MULTIS=atoi(argv[n]);
printf("Window length for MWD set to: %i !\n", M);
}
}
else{
printf("SETTINGS ERROR: Intersampling number not 1,2, or 4!\n");
return(-1);
}
}
if(strstr(argv[n],"-r")!=NULL){ // realign_first_NOE
realign_first_NOE=1;
}
if(strstr(argv[n],"-m")!=NULL){ // multiple files with startfile
realign_first_NOE=42;
}
if(strstr(argv[n],"-e")!=NULL){ // turn verbose output on
MULTIS_CALIB_MODE = true;
printf("\n\n++++++++++++++++++++++++++++++++\n");
printf("+++ ENERGY CALIBRATION MODE +++\n");
printf("++++++++++++++++++++++++++++++++\n");
}
if(strstr(argv[n],"-h")!=NULL){ // print help page
print_usage();
return(-1);
}
}
// Check if MA interval length is larger than sample of baseline cut
if (L > BASELINE_CUT){
printf("SETTINGS ERROR: Moving average interval larger than baseline! Not allowed!\n");
return(-1);
}
// Check if MWD interval length is larger than sample of baseline cut
if (M > BASELINE_CUT){
printf("SETTINGS ERROR: MWD moving average interval larger than baseline! Not allowed!\n");
return(-1);
}
//////////////////////////////////////////////////////////
// Initialize detector readout
//////////////////////////////////////////////////////////
// Standard detector analysis mode is cosmics mode, is changed by config file
sprintf(MODE, "COSMICS"); // standard setting
// Read the config file if file is given
if(conf_exists){
bool conf_healthy = read_config(configfile);
if (conf_healthy == false){
printf("ERROR: Config file error!\n");
return(-1);
}
}
// Print mapping if verbose flag is set
if (is_in_string(VERBOSE, "c")) print_detector_config();
// Set up detector read out
DETECTOR.init_readout(inputfile, realign_first_NOE);
//TRACELEN=DETECTOR.get_maxevents(1);
randit(1);
//////////////////////////////////////////////////////////
// Construct TFile for storing all plot/histograms and define folder structure
//////////////////////////////////////////////////////////
//TFile hfile(outputfile,"RECREATE","NTEC analysis");
hfile = new TFile(outputfile,"RECREATE","NTEC analysis");
hfile->SetCompressionLevel(1);
// Create folder structure
build_structure();
// Proto signal is to be extracted
if (EXTRACT_PROTO == 1){
sprintf(outputfile_proto_trace, "%s_proto_trace.dat", outputfile);
proto_out = new ofstream(outputfile_proto_trace);
if (proto_out->is_open()){
printf("NOTICE(main): Opened proto trace output file %s.\n", outputfile_proto_trace);
}
else printf("WARNING(statistics): Unable to write proto trace file.\n");
}
// Open file for saving the energy calibration paramters from cosmics
if (strcmp(MODE, "COSMICS")==0){
sprintf(outputfile_energy_calib, "%s_energy_calib.txt", outputfile);
energy_out = new ofstream(outputfile_energy_calib);
if (energy_out->is_open()){
printf("NOTICE(main): Opened energy calibration output file %s.\n", outputfile_energy_calib);
}
else printf("WARNING(statistics): Unable to write energy calibration file.\n");
}
// array_simulate_proto();
// Recalculate the energy windows
E_WINDOW_LENGTH = (E_WINDOW_RIGHT - E_WINDOW_LEFT)/N_E_WINDOW;
////////////////////////////////////////////////////////
// BUILD HISTOGRAMS / LOAD PROTO TRACES FROM FILE
////////////////////////////////////////////////////////
// Reset/initialize signal container
// If in normal extraction mode, use CHANNELS_EFF
if (MULTIS_CALIB_MODE == false){
// Initialize the signal containers
init_signal(RAW, CHANNELS, "true"); // Has to be CHANNELS
init_signal(RAW_CALIB, CHANNELS_EFF);
init_signal(MA, CHANNELS_EFF);
init_signal(MWD, CHANNELS_EFF);
init_signal(TMAX, CHANNELS_EFF);
init_signal(NMO, CHANNELS_EFF);
// Init the Calorimeter sum (only one element per filter type in the vector)
init_signal(ECAL25, 5);
// Initialize histograms, done in extra functionS
init_hists(CHANNELS_EFF);
}
else{
init_signal(RAW, CHANNELS);
// Initialize histograms, done in extra function
// Initialize the MULTIS container
init_multis_norm(MULTIS_NORM, CHANNELS);
init_hists(CHANNELS);
}
// Save the Proto Trace
if (EXTRACT_PROTO == 0){
for (int i = 0; i<(int)RAW_CALIB.size(); i++){
RAW_CALIB[i].proto_trace_fit = PROTO[i].proto_trace_fit;
}
}
// Save costum threshold multiplicies
if (TH_MULTIPLICITY.size() != RAW_CALIB.size() && THRESHOLD_MULTIPLICY == -1){
printf("ERROR: Check your costum threshold multiplicies from the ini file! Must be exactly one row for every real channel!\n");
printf("TH_MULTIPLICITY.size()=%d, RAW_CALIB.size()=%d\n", (int)TH_MULTIPLICITY.size(), (int)RAW_CALIB.size());
return(-1);
}
if (THRESHOLD_MULTIPLICY == -1){
for (int i = 0; i<(int)RAW_CALIB.size(); i++){
RAW_CALIB[i].base.TH_multiplicity = TH_MULTIPLICITY[i];
}
}
else{
for (int i = 0; i<(int)RAW_CALIB.size(); i++){
RAW_CALIB[i].base.TH_multiplicity = THRESHOLD_MULTIPLICY;
}
}
printf("INITIALIZATION COMPLETED! BEGIN READOUT!\n");
/////////////////////////////////////////////////////
// BEGIN SIGNAL READOUT
/////////////////////////////////////////////////////
// Initialize the loop condition
int m=1;
// Reset NOE number of events counter
// loop timer
high_resolution_clock::time_point t_loop_begin = high_resolution_clock::now();
NOE=0;
do{
// Keep reading as long there are unread events
m=DETECTOR.read_one_event(NOE);
// Print some verbose information
if (is_in_string(VERBOSE, "p")){ // "p" for progress report
if (no_of_events != 0) {
if(NOE%((int)no_of_events/10)==0){
high_resolution_clock::time_point t_loop_end = high_resolution_clock::now();
// duration<double, milli> dur = ( t_loop_end - t_loop_begin );
auto duration = duration_cast<milliseconds>( t_loop_end - t_loop_begin ).count();
cout << "Analysing event: " << NOE << " (" << duration/1000 << "s per cycle)" << endl;
}
}
else {
if(NOE%1000 ==0) {
high_resolution_clock::time_point t_loop_end = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>( t_loop_end - t_loop_begin ).count();
cout << "Analysing event: " << NOE << " (" << duration/1000 << "s per cycle)" << endl;
}
}
// reset timer
t_loop_begin = high_resolution_clock::now();
}
// Increase Global number of events counter
NOE++;
// If there is an event, do the extraction
if(m==1){ // && t!=-13){ // not eof for either of these files
// MULTISAMPLING CALIBRATION MODE
// Depending on the program mode, do either calibration or final extraction
//
if(strcmp(MODE, "MULTIS") == 0 || MULTIS_CALIB_MODE == true) {
// Extract calibration information
multis_calib();
// Fill histograms with result, respecting the correct program mode
fill_hists();
}
// FEATURE EXTRACTION MODE
// Depending on the program mode, do either calibration or final extraction
//
else{
// Extract energy and timing information
extraction();
// Fill histograms with result, respecting the correct program mode
fill_hists();
}
// Every 1000 events plot a random event
if (NOE%1000==0){
// Plot every 100th raw signal
hfile->cd("WAVE_FORMS/RAW");
plot_waves(RAW, "Signal_RAW", "TRACE");
}
}
if(do_no_of_events==1){
if(NOE>=no_of_events) m=0;
}
}while(m==1);
/////////////////////////////////////////////////////
// END SIGNAL READOUT
/////////////////////////////////////////////////////
// Print final statistics
if(strcmp(MODE, "MULTIS") == 0 || MULTIS_CALIB_MODE == true) {
print_stat_multis_calib();
plot_multis_hist();
}
else{
print_final_statistics();
}
/////////////////////////////////////////////////////
// END PHYSICS PROGRAM
/////////////////////////////////////////////////////
// End programm timer
high_resolution_clock::time_point t_total_end = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>( t_total_end - t_total_begin ).count();
if (NB_ACT_CHANNELS == 0) NB_ACT_CHANNELS++; // Avoid deviding by zero
cout << endl << "Program exectuion time: " << (duration/1000)
<< "s (" << duration/NB_ACT_CHANNELS/1000 << "s per active channel)" << endl << endl;
// Write and save and delete the root file element in program
printf("Writing root file...\n");
hfile->Write();
// If put stuff after deleting hfile, software might crash. Beware!
delete hfile;
printf("\nRoot file written! Program ends here.\n");
// If put stuff after deleting hfile, software might crash. Beware!
/////////////////////////////////////////////////////
// END OF PROGRAM
/////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////
// ENERGY AND TIMING EXTRACITON
/////////////////////////////////////////////////////
void extraction(){
/////////////////////////////////////////////////////
// INITIALIZE SIGNAL CONTAINERS
/////////////////////////////////////////////////////
reset_signal(RAW); // raw has to be of lentgh CHANNELS
reset_signal(RAW_CALIB);
reset_signal(MA);
reset_signal(MWD);
reset_signal(TMAX);
reset_signal(NMO);
reset_signal(ECAL25);
/////////////////////////////////////////////////////
// FETCH RAW CONTENT FROM DATA
/////////////////////////////////////////////////////
// Create dummy container for fetching the signal
int entry = 0;
unsigned int dumm_cont[CHANNELS][TRACELEN];
// Initialization of the boards (has to start with 1, since 0 is usually the IOL board)
// and fetching the ADC content
for(int board=1; board<=BOARDS; board++){
for(int channel=0; channel<8; channel++){
// Convert the board channel to overall channel
entry = (board-1)*8 + channel;
// Fetch the channels
DETECTOR.get_trace(board, channel, dumm_cont[entry]);
// Save the entries in the RAW container
for(int n=0; n<TRACELEN; n++){
double dumm = (double) dumm_cont[entry][n]; // Has no function but is needed to work (dunno why)
RAW[entry].trace.push_back((double) dumm_cont[entry][n]);
dumm++; // Has no function but is needed to work (dunno why)
}
// Calculate the baseline information for the RAW and RAW_Calib
RAW[entry].base.mean = array_mean(RAW[entry].trace, 0,BASELINE_CUT);
// Already subtract the baseline from the signals
for (int n = 0; n<TRACELEN; n++){
RAW[entry].trace[n] -= RAW[entry].base.mean;
}
// Recalculate the baseline information for the RAW and RAW_Calib
RAW[entry].base.mean = array_mean(RAW[entry].trace, 0,BASELINE_CUT);
// Now calculate the std and TH for the baselines
RAW[entry].base.std = array_std(RAW[entry].trace,0, BASELINE_CUT,RAW[entry].base.mean);
RAW[entry].base.TH = THRESHOLD_MULTIPLICY * RAW[entry].base.std;
}
}
// According to polarity and baseline, transform negative signals into positive signals
for (int a = 0; a<(int)MAPPING.size(); a++){
for (int b = 0; b<(int)MAPPING[a].size(); b++){
// Mapped hardware channel in RAW container
int h = MAPPING[a][b].board_nb * 8 + MAPPING[a][b].h_channel_start;
// If it's a solo channel
if (MAPPING[a][b].multis == 1 && MAPPING[a][b].polarity == -1){
for (int n = 0; n < (int)RAW[h].trace.size(); n++){
RAW[h].trace[n] = 2 * RAW[h].base.mean + (RAW[h].trace[n]*(-1));
}
}
// If not:
if (MAPPING[a][b].multis == 2 && MAPPING[a][b].polarity == -1){
for (int n = 0; n < (int)RAW[h].trace.size(); n++){
RAW[h].trace[n] = 2 * RAW[h].base.mean + (RAW[h].trace[n]*(-1));
RAW[h+1].trace[n] = 2 * RAW[h+1].base.mean + (RAW[h+1].trace[n]*(-1));
}
}
if (MAPPING[a][b].multis == 4 && MAPPING[a][b].polarity == -1){
for (int n = 0; n < (int)RAW[h].trace.size(); n++){
RAW[h].trace[n] = 2 * RAW[h].base.mean + (RAW[h].trace[n]*(-1));
RAW[h+1].trace[n] = 2 * RAW[h+1].base.mean + (RAW[h+1].trace[n]*(-1));
RAW[h+2].trace[n] = 2 * RAW[h+2].base.mean + (RAW[h+2].trace[n]*(-1));
RAW[h+3].trace[n] = 2 * RAW[h+3].base.mean + (RAW[h+3].trace[n]*(-1));
}
}
}
}
// i is the software channel, including all multisampling channels. mapping from hardware channels has to be done
for (int a = 0; a<(int)MAPPING.size(); a++){
for (int b = 0; b<(int)MAPPING[a].size(); b++){
// Chrystal channel (Channel of matrix)
int ch = b*(int)MAPPING.size()+a;
// Mapped hardware channel in RAW container
int h = MAPPING[a][b].board_nb * 8 + MAPPING[a][b].h_channel_start;
// Check if hardware channel is valid channel, otherwise leave that channel out and set the flag
if (MAPPING[a][b].board_nb != 99) {
RAW_CALIB[ch].is_valid = true;
MA[ch].is_valid = true;
MWD[ch].is_valid = true;
TMAX[ch].is_valid = true;
NMO[ch].is_valid = true;
// Aditionally for the RAW channels
RAW[h].is_valid = true;
if (MAPPING[a][b].multis == 2){
RAW[h+1].is_valid = true;
}
if (MAPPING[a][b].multis == 4){
RAW[h+1].is_valid = true;
RAW[h+2].is_valid = true;
RAW[h+3].is_valid = true;
}
}
else continue;
// Now fill the software channels according to the mapping and multisampling
for(int n=0; n<TRACELEN; n++){
if (MAPPING[a][b].multis == 1){
RAW_CALIB[ch].trace.push_back( ((double) RAW[h].trace[n] )* CALIB.multis[h] * CALIB.RAW_energy[ch] * GENERAL_SCALING);
// Update the channel info
RAW_CALIB[ch].hardware_addr = h;
RAW_CALIB[ch].polarity = MAPPING[a][b].polarity;
}
else if (MAPPING[a][b].multis == 2){
// Save the samples correctly
RAW_CALIB[ch].trace.push_back((double) RAW[h+1].trace[n] * CALIB.multis[h+1] * CALIB.RAW_energy[ch] * GENERAL_SCALING);
RAW_CALIB[ch].trace.push_back((double) RAW[h].trace[n] * CALIB.multis[h] * CALIB.RAW_energy[ch] * GENERAL_SCALING);
// Update the channel information
RAW_CALIB[ch].multis = 2;
RAW_CALIB[ch].clock_speed = 200; // in MHz
RAW_CALIB[ch].sample_t = 5.; // in MHz
RAW_CALIB[ch].tracelen = TRACELEN * 2;
RAW_CALIB[ch].hardware_addr = h;
RAW_CALIB[ch].polarity = MAPPING[a][b].polarity;
}
else if (MAPPING[a][b].multis == 4){
// Save the samples correctly
RAW_CALIB[ch].trace.push_back((double) RAW[h+3].trace[n] * CALIB.multis[h+3] * CALIB.RAW_energy[ch] * GENERAL_SCALING);
RAW_CALIB[ch].trace.push_back((double) RAW[h+2].trace[n] * CALIB.multis[h+2] * CALIB.RAW_energy[ch] * GENERAL_SCALING);
RAW_CALIB[ch].trace.push_back((double) RAW[h+1].trace[n] * CALIB.multis[h+1] * CALIB.RAW_energy[ch] * GENERAL_SCALING);
RAW_CALIB[ch].trace.push_back((double) RAW[h].trace[n] * CALIB.multis[h] * CALIB.RAW_energy[ch] * GENERAL_SCALING);
// Update the channel information
RAW_CALIB[ch].multis = 4;
RAW_CALIB[ch].clock_speed = 400; // in MHz
RAW_CALIB[ch].sample_t = 2.5; // in MHz
RAW_CALIB[ch].tracelen = TRACELEN * 4;
RAW_CALIB[ch].hardware_addr = h;
RAW_CALIB[ch].polarity = MAPPING[a][b].polarity;
}
}
}
}
for(int board=1; board<=BOARDS; board++){
for(int channel=0; channel<8; channel++){
// Convert the board channel to overall channel
entry = (board-1)*8 + channel;
RAW[entry].CFD.trace.clear();
RAW[entry].CFD.trace = CFD(RAW[entry].trace, 1);
}
}
for (int i = 0; i < (int)RAW_CALIB.size(); i++){
/////////////////////////////////////////////////////
// APPLICATION OF THE FILTER TO RAW_CALIB
/////////////////////////////////////////////////////
MA[i].trace.clear(); MA[i].sample_t = RAW_CALIB[i].sample_t; MA[i].multis = RAW_CALIB[i].multis;
MWD[i].trace.clear(); MWD[i].sample_t = RAW_CALIB[i].sample_t; MWD[i].multis = RAW_CALIB[i].multis;
TMAX[i].trace.clear(); TMAX[i].sample_t = RAW_CALIB[i].sample_t; TMAX[i].multis = RAW_CALIB[i].multis;
MA[i].trace = MA_filter(RAW_CALIB[i].trace, CALIB.MA_energy[i], L*MA[i].multis);
MWD[i].trace = MWD_filter(RAW_CALIB[i].trace, CALIB.MWD_energy[i]);
// if (i == 7) printf("%3.3f\n", CALIB.TMAX_energy[i]);
TMAX[i].trace = FIR_filter(RAW_CALIB[i].trace, CALIB.TMAX_energy[i]);
for (int n = 0; n < (int)MA[i].trace.size(); n++){
// printf("%3.1f\n",RAW_CALIB[i].trace[n] );
// printf("%3.1f %3.1f %3.1f\n", RAW_CALIB[i].trace[n], MA[i].trace[n], (double)FIR_COEF.size() );
}
// printf("++++++++++++++++++++++\n");
/////////////////////////////////////////////////////
// APPLICATION OF THE CONSTANT FRACTION DISCRIMINATOR
/////////////////////////////////////////////////////
RAW_CALIB[i].CFD.trace.clear();
MA[i].CFD.trace.clear();
MWD[i].CFD.trace.clear();
TMAX[i].CFD.trace.clear();
RAW_CALIB[i].CFD.trace = CFD(RAW_CALIB[i].trace, RAW_CALIB[i].multis);
MA[i].CFD.trace = CFD(MA[i].trace, RAW_CALIB[i].multis);
MWD[i].CFD.trace = CFD(MWD[i].trace, RAW_CALIB[i].multis);
TMAX[i].CFD.trace = CFD(TMAX[i].trace, RAW_CALIB[i].multis);
}
/////////////////////////////////////////////////////
// CALCULATE BASELINE STATISTICS
/////////////////////////////////////////////////////
// Calculate the baseline statistics
for (int i = 0; i < (int)RAW_CALIB.size(); i++){
// Check if channel is valid
if (RAW_CALIB[i].is_valid == false) continue;
// otherwise do the calculation
RAW_CALIB[i].base.mean = array_mean(RAW_CALIB[i].trace, 0,BASELINE_CUT*RAW_CALIB[i].multis);
RAW_CALIB[i].base.std = array_std(RAW_CALIB[i].trace, 0, BASELINE_CUT*RAW_CALIB[i].multis,RAW_CALIB[i].base.mean);
RAW_CALIB[i].base.TH = RAW_CALIB[i].base.TH_multiplicity * RAW_CALIB[i].base.std;
//
MA[i].base.mean = array_mean(MA[i].trace, 0,BASELINE_CUT*MA[i].multis);
MA[i].base.std = array_std(MA[i].trace, 0, BASELINE_CUT*MA[i].multis,MA[i].base.mean);
MA[i].base.TH = RAW_CALIB[i].base.TH_multiplicity * MA[i].base.std;
//
MWD[i].base.mean = array_mean(MWD[i].trace, 0,BASELINE_CUT*MWD[i].multis);
MWD[i].base.std = array_std(MWD[i].trace, 0, BASELINE_CUT*MWD[i].multis,MWD[i].base.mean);
MWD[i].base.TH = RAW_CALIB[i].base.TH_multiplicity * MWD[i].base.std;
//
TMAX[i].base.mean = array_mean(TMAX[i].trace, 0,BASELINE_CUT*TMAX[i].multis);
TMAX[i].base.std = array_std(TMAX[i].trace, 0, BASELINE_CUT*TMAX[i].multis,TMAX[i].base.mean);
TMAX[i].base.TH = RAW_CALIB[i].base.TH_multiplicity * TMAX[i].base.std;
// printf("%3.3f %3.3f %3.3f %d\n", MA[i].base.mean, MA[i].base.std, MA[i].base.TH, MA[i].multis);
}
/////////////////////////////////////////////////////
// EXTRACT FEATURES FROM TRACES
/////////////////////////////////////////////////////
// First the RAW traces
for(int i=0; i<(int)RAW.size(); i++){
// Extract the maximum
RAW[i].energy = RAW[i].trace[array_largest(RAW[i].trace, BASELINE_CUT, ENERGY_WINDOW_MAX)];
RAW[i].energy_n = array_largest(RAW[i].trace, BASELINE_CUT, ENERGY_WINDOW_MAX);
// Look for CFD Zero Crossing
/// Search for minimum before zero xrossing
RAW[i].CFD.Xzero = array_zero_xing(RAW[i].CFD.trace, ZERO_XING_CUT, RAW[i].energy_n, -1);
// Already fill the samples into a histogram for baseline noise estimation
for(int n=0; n < BASELINE_CUT; n++){
RAW[i].base.h_samples.hist->Fill(RAW[i].trace[n]);
}
}
int plot = 0;
//
// Then the Filtered traces
//
// In beam mode first check if the central crystal is healthy
int central_healty = 0;
int valid_max = 0;
// Left and Right borders for maximum detection
int left = BASELINE_CUT * RAW_CALIB[0].multis;
int right = ENERGY_WINDOW_MAX * RAW_CALIB[0].multis;
// Already extract features of RAW_CALIB
if (strcmp(MODE, "BEAM")==0){
RAW_CALIB[CENTRAL].energy_n = array_largest(RAW_CALIB[CENTRAL].trace, left, right); // sample number of largest sample
RAW_CALIB[CENTRAL].energy = RAW_CALIB[CENTRAL].trace[RAW_CALIB[CENTRAL].energy_n];
RAW_CALIB[CENTRAL].integral = signal_integral(RAW_CALIB[CENTRAL], 0);
RAW_CALIB[CENTRAL].ratio = RAW_CALIB[CENTRAL].integral / RAW_CALIB[CENTRAL].energy;
//
TMAX[CENTRAL].energy_n = array_largest(TMAX[CENTRAL].trace, left, right);
TMAX[CENTRAL].energy = TMAX[CENTRAL].trace[TMAX[CENTRAL].energy_n];
TMAX[CENTRAL].integral = signal_integral(TMAX[CENTRAL], 0);
TMAX[CENTRAL].ratio = TMAX[CENTRAL].integral / TMAX[CENTRAL].energy;
TMAX[CENTRAL].is_signal = 1;
TMAX[CENTRAL].CFD.Xzero = array_zero_xing(TMAX[CENTRAL].CFD.trace, ZERO_XING_CUT*TMAX[CENTRAL].multis, array_largest(TMAX[CENTRAL].CFD.trace, 0, 1E5), -1);
if (strcmp("RAW_CALIB", VALIDITY) == 0) valid_max = is_valid_max( RAW_CALIB[CENTRAL], RAW_CALIB[CENTRAL].energy_n );
if (strcmp("TMAX", VALIDITY) == 0) valid_max = is_valid_max( TMAX[CENTRAL], TMAX[CENTRAL].energy_n );
//
if ( valid_max == 0 ){
// printf("%3.3f\n", TMAX[CENTRAL].ratio);
if ( RAW_CALIB[CENTRAL].ratio < UPPER_RATIO && RAW_CALIB[CENTRAL].ratio > LOWER_RATIO){
// if ( RAW_CALIB[CENTRAL].ratio < UPPER_RATIO && RAW_CALIB[CENTRAL].ratio > LOWER_RATIO){
RAW_CALIB[CENTRAL].is_signal = 1;
central_healty = 1;
FILTER_EFFICIENCY[0]++;
}
else {
central_healty = 0;
plot = 6;
FILTER_EFFICIENCY[6]++;
}
}
else {
central_healty = 0;
plot = valid_max;
FILTER_EFFICIENCY[valid_max]++;
}
}
else central_healty = 1;
// Now loop through all the channels
for(int i=0; i<(int)RAW_CALIB.size(); i++){
// plot = 1;
// Only extract features from valid channels
if (RAW_CALIB[i].is_valid == false) continue;
// Left and Right borders for maximum detection
int left = BASELINE_CUT * RAW_CALIB[i].multis;
int right = ENERGY_WINDOW_MAX * RAW_CALIB[i].multis;
// Already extract features of RAW_CALIB
RAW_CALIB[i].energy_n = array_largest(RAW_CALIB[i].trace, RAW_CALIB[i].multis*BASELINE_CUT, RAW_CALIB[i].multis*ENERGY_WINDOW_MAX); // sample number of largest sample
RAW_CALIB[i].energy = RAW_CALIB[i].trace[RAW_CALIB[i].energy_n];
RAW_CALIB[i].integral = signal_integral(RAW_CALIB[i], 0);
RAW_CALIB[i].ratio = RAW_CALIB[i].integral / RAW_CALIB[i].energy;
RAW_CALIB[i].CFD.Xzero = array_zero_xing(RAW_CALIB[i].CFD.trace, ZERO_XING_CUT*RAW_CALIB[i].multis, array_largest(RAW_CALIB[i].CFD.trace, 0, 1E5), -1);
// printf("%3.1f %3.1f %d\n", RAW_CALIB[i].energy, RAW_CALIB[i].base.TH, RAW_CALIB[i].energy_n);
// printf("%d %3.3f %3.3f %3.3f %d\n", RAW_CALIB[i].energy_n, RAW_CALIB[i].energy, RAW_CALIB[i].integral, RAW_CALIB[i].ratio, is_valid_max( RAW_CALIB[i], RAW_CALIB[i].energy_n ));
TMAX[i].energy_n = array_largest(TMAX[i].trace, TMAX[i].multis*BASELINE_CUT, TMAX[i].multis*ENERGY_WINDOW_MAX); // sample number of largest sample
TMAX[i].energy = TMAX[i].trace[TMAX[i].energy_n];
TMAX[i].integral = signal_integral(TMAX[i], 0);
TMAX[i].ratio = TMAX[i].integral / TMAX[i].energy;
TMAX[i].CFD.Xzero = array_zero_xing(TMAX[i].CFD.trace, ZERO_XING_CUT*TMAX[i].multis, array_largest(TMAX[i].CFD.trace, 0, 1E5), -1);
// Search for maximum and check if valid
// Decide which filter type to chose for making the validity decicion
if ( is_valid_max( RAW_CALIB[i], RAW_CALIB[i].energy_n ) == 0 && central_healty == 1 ){ // The maximum is valid
// Signal is good
RAW_CALIB[i].is_signal = 1;
// Save the sum of all signals per channel
RAW_CALIB[i].proto_trace = array_sum(RAW_CALIB[i].proto_trace, RAW_CALIB[i].trace, 1);
// Fill the proto trace hist
for (int n = 0; n < (int)RAW_CALIB[i].proto_trace.size(); n++){
RAW_CALIB[i].TH2D_proto_trace.hist->Fill(n, RAW_CALIB[i].trace[n]);
}
//
// Only look for the filter traces if raw trace is not a glitch
MA[i].energy_n = array_largest(MA[i].trace, left, right);
// printf("%3.3f %d %d\n", MA[i].base.TH, MA[i].energy_n, is_valid_max( MA[i], MA[i].energy_n ));
// printf("%d %3.3f %d\n", MA[i].energy_n, MA[i].energy, is_valid_max( MA[i], MA[i].energy_n ));
if ( is_valid_max( MA[i], MA[i].energy_n ) == 0 ){
MA[i].energy = MA[i].trace[MA[i].energy_n];
MA[i].integral = signal_integral(MA[i], 0);
MA[i].ratio = MA[i].integral / MA[i].energy;
MA[i].is_signal = 1;
MA[i].CFD.Xzero = array_zero_xing(MA[i].CFD.trace, ZERO_XING_CUT*MA[i].multis, array_largest(MA[i].CFD.trace, 0, 1E5), -1);
}
else{ MA[i].energy = 0; MA[i].integral = 0; MA[i].ratio = 0; MA[i].is_signal = 0;}
//
MWD[i].energy_n = array_largest(MWD[i].trace, left, right);
if ( is_valid_max( MWD[i], MWD[i].energy_n ) == 0 ){
MWD[i].energy = MWD[i].trace[MWD[i].energy_n];
MWD[i].integral = signal_integral(MWD[i], 0);
MWD[i].ratio = MWD[i].integral / MWD[i].energy;
MWD[i].is_signal = 1;
MWD[i].CFD.Xzero = array_zero_xing(MWD[i].CFD.trace, ZERO_XING_CUT*MWD[i].multis, array_largest(MWD[i].CFD.trace, 0, 1E5), -1);
}
else{ MWD[i].energy = 0; MWD[i].integral = 0; MWD[i].ratio = 0; MWD[i].is_signal = 0;}
//
TMAX[i].energy_n = array_largest(TMAX[i].trace, left, right);
// printf("%d %d\n", TMAX[i].energy_n, (int)TMAX[i].trace.size());
// if ( is_valid_max( TMAX[i], TMAX[i].energy_n ) == 0 ){
TMAX[i].energy = TMAX[i].trace[TMAX[i].energy_n];
TMAX[i].integral = signal_integral(TMAX[i], 0);
TMAX[i].ratio = TMAX[i].integral / TMAX[i].energy;
TMAX[i].is_signal = 1;
TMAX[i].CFD.Xzero = array_zero_xing(TMAX[i].CFD.trace, ZERO_XING_CUT*TMAX[i].multis, array_largest(TMAX[i].CFD.trace, 0, 1E5), -1);
// }
// else{ TMAX[i].energy = 0; TMAX[i].integral = 0; TMAX[i].ratio = 0; TMAX[i].is_signal = 0;}
// printf("%d %d %d %d \n", RAW_CALIB[i].CFD.Xzero, MA[i].CFD.Xzero, MWD[i].CFD.Xzero, TMAX[i].CFD.Xzero );
// For the sake of computational efficiency, only do the Nelder-Mead optimization for signal events
// If the proto traces are already extracted, do the optimization
if (EXTRACT_PROTO==0){
// Now do optimization for prototraces and RAW_CALIB
// For initial parameters, take:
// For amplitude, calculate the ratio between trace maximum and proto trace maximum
// For shift, look for sample number of trace maximum
// double init_A = RAW_CALIB[i].trace[RAW_CALIB[i].energy_n] / RAW_CALIB[i].proto_trace[array_largest(RAW_CALIB[i].proto_trace, 0, (int)RAW_CALIB[i].proto_trace.size())];
vector<double> init; init.push_back(1); init.push_back(0.0);
double a0[]={0.0, -100.0}, a1[]={1.5, 0.0}, a2[]={ 0.0, 100.0};
vector<vector<double> > simplex;
simplex.push_back( vector<double>(a0,a0+2) );
simplex.push_back( vector<double>(a1,a1+2) );
simplex.push_back( vector<double>(a2,a2+2) );
vector<double> weights;
for (int n = 0; n < 90; n++){
weights.push_back(1);
}
for (int n = 100; n < 120; n++){
weights.push_back(10);
}
for (int n = 110; n < (int)RAW_CALIB[i].trace.size(); n++){
weights.push_back(1);
}
vector<double> snadbox;
snadbox.push_back(1.0);
snadbox.push_back(0.0);
if (i==0) {
RAW_CALIB[i].trace = array_adjust(RAW_CALIB[i].trace, snadbox, 0);
TMAX[i].trace = FIR_filter(RAW_CALIB[i].trace, CALIB.TMAX_energy[i]);
}
// if (i==0) plot = 1;
// The whole optimization process is stored, where the last element is the optimium
vector<vector<double> > opt;
// printf("\n%d %d\n", (int)RAW_CALIB[i].trace.size(), (int)RAW_CALIB[i].proto_trace_fit.size());
int debug = 0;
// if (i == 1) debug = 2;
opt = BT::Simplex(array_compare,
RAW_CALIB[i].trace,
RAW_CALIB[i].proto_trace_fit,
weights,
50, 250,
init,
(double) 1e-7,
simplex,
1E2,
debug
);
// printf("++++++++++\n %3.3f %3.3f\n++++++++++", opt[0], opt[1]);
// Save optimized wave form in NMO trace
NMO[i].trace = array_adjust(RAW_CALIB[i].proto_trace_fit, opt.back(), 0);
NMO[i].is_signal = 1;
NMO[i].is_valid = true;
int len1 = (int)NMO[i].trace.size();
int len2 = (int)RAW_CALIB[i].trace.size();
double frac = (double)len1/(double)len2;
NMO[i].energy_n = array_largest(NMO[i].trace, (int)left*frac, (int)right*frac); // sample number of largest sample
NMO[i].energy = NMO[i].trace[NMO[i].energy_n];
NMO[i].integral = signal_integral(NMO[i], 0);
NMO[i].ratio = NMO[i].integral / NMO[i].energy;
NMO[i].CFD.Xzero = array_zero_xing(NMO[i].CFD.trace, BASELINE_CUT*NMO[i].multis, array_largest(NMO[i].CFD.trace, 0, 1E5), -1);
// if (i == CENTRAL ) plot = 1;
// plot = 1;
}
else{
// For the NMO, fill the non-optimized traces with 0
for (int n = 0; n < (int)RAW_CALIB[0].trace.size(); n++){
NMO[i].trace.push_back(0.0);
}
}
}
else {
// If not valid, set all energies and integrals to 0
RAW_CALIB[i].energy = 0; RAW_CALIB[i].integral = 0;RAW_CALIB[i].ratio = 0; RAW_CALIB[i].is_signal = 0;
MA[i].energy = 0; MA[i].integral = 0; MA[i].ratio = 0; MA[i].is_signal = 0;
MWD[i].energy = 0; MWD[i].integral = 0; MWD[i].ratio = 0; MWD[i].is_signal = 0;
TMAX[i].energy = 0; TMAX[i].integral = 0; TMAX[i].ratio = 0; TMAX[i].is_signal = 0;
NMO[i].energy = 0; NMO[i].integral = 0; NMO[i].ratio = 0; NMO[i].is_signal = 0;
// For the NMO, fill the non-optimized traces with 0
for (int n = 0; n < (int)RAW_CALIB[0].trace.size(); n++){
NMO[i].trace.push_back(0.0);
}
}
// Calculate sample_t of NMO which can be different than
double nmo_tracelen = (double)NMO[i].trace.size();
NMO[i].sample_t = (double)( SAMPLE_t * (TRACELEN/nmo_tracelen) ); // NMO can have a higher sampling rate, calculate it based on the ADC sampling
// printf("%3.2f\n", NMO[i].sample_t);
// Calculate the CFD traces
RAW_CALIB[i].CFD.trace.clear();
RAW_CALIB[i].CFD.trace = CFD(RAW_CALIB[i].trace, RAW_CALIB[i].multis);
MA[i].CFD.trace.clear();
MA[i].CFD.trace = CFD(MA[i].trace, MA[i].multis);
MWD[i].CFD.trace.clear();
MWD[i].CFD.trace = CFD(MWD[i].trace, MWD[i].multis);
TMAX[i].CFD.trace.clear();
TMAX[i].CFD.trace = CFD(TMAX[i].trace, TMAX[i].multis);
// Calculate the multiplication adjustment to the higher res NMO trace
double multiplier = (double)(NMO[i].trace.size() / RAW_CALIB[i].trace.size());
//
NMO[i].CFD.trace.clear();
NMO[i].CFD.trace = CFD(NMO[i].trace, NMO[i].multis*multiplier);
// if ( RAW_CALIB[i].ratio == 0 ){
// if ( i == 4 ) plot = 1;
// }
// if ( is_valid_max( RAW_CALIB[i], array_largest(RAW_CALIB[i].trace, left, right) ) == 4 ){
// if ( i == 4 ) plot = 2;
// }
}
/////////////////////////////////////////////////////
// TEST FOR COINCIDENCE
/////////////////////////////////////////////////////
// Check for coincidences according to the analysis mode
// + Column cut: only look for coincident events in stacked crystals
// for (int i = 0; i < (int)RAW_CALIB.size(); i++){
// printf("%d ", RAW_CALIB[i].is_signal);
// }
// printf("\n");
// Column cut / cosmics mode:
bool is_coinc = false;
//
if(strcmp(MODE, "COSMICS") == 0) {
// Array for saving column information
int column = 0;
// Check for each column if there was any event
for (int b = 0; b < (int)MAPPING[0].size(); b++){
column = 0;
for (int a = 0; a < (int)MAPPING.size(); a++){
// Chrystal channel (Channel of matrix)
int ch = b*(int)MAPPING.size()+a;
if (RAW_CALIB[7].is_signal == 1) {
plot = 1;
// printf("%3.3f %3.3f %3.3f\n", RAW_CALIB[7].energy, RAW_CALIB[7].base.TH, RAW_CALIB[7].base.std);
}
// Check if there was a signal in channel ch
if (RAW_CALIB[ch].is_signal == 1 && RAW_CALIB[ch].is_valid == 1){
column++;
}
}
// printf("%d %d\n", column, (int)MAPPING.size() - 1);
// Now check how many signals per column
if (column < COINC_LEVEL ){//(int)MAPPING[0].size()-1){
// Throw away events in this column
for (int a = 0; a < (int)MAPPING.size(); a++){
// Chrystal channel (Channel of matrix)
int ch = b*(int)MAPPING.size()+a;
RAW_CALIB[ch].energy = 0;
MA[ch].energy = 0;
MWD[ch].energy = 0;
TMAX[ch].energy = 0;
NMO[ch].energy = 0;
//
RAW_CALIB[ch].integral = 0;
MA[ch].integral = 0;
MWD[ch].integral = 0;
TMAX[ch].integral = 0;
NMO[ch].integral = 0;
}
}
else is_coinc = true;
// If it's only one crystal per column, set the coincidencec setting still to true
if ( (int)MAPPING.size() == 1){
is_coinc = true;
}
// If there are coincident events, do timing extraction
else{
// start the interpolation by looping over all channels
// interpolate is searching for the zero crossing point of the CFD signals
// interpolate(RAW_CALIB);
// interpolate(MA);
// interpolate(MWD);
// interpolate(TMAX);
// And now compare the timing
// time_compare(RAW_CALIB);
// time_compare(MA);
// time_compare(MWD);
// time_compare(TMAX);
}
}
}
//
//
if(strcmp(MODE, "BEAM") == 0) {
is_coinc = false;
// If xtal in beam is not valid
// Read out the tagger statistics
int tags_per_event = 0;
for(int n=0; n<TAG_CHANNELS; n++){
TAGGER.time[n]=DETECTOR.get_value(BOARDS+1, n, 1);
// Check for multiple taggs or non tags
if (TAGGER.time[n] != 0.0 ){
tags_per_event++;
TAGGER.counts[n]++;
}
}
// Enter number of tags per event into the counter
TAGGER.multiples_per_count[tags_per_event]++;
// Check in witch channel the multi counts appeared
if (tags_per_event > 1){
for(int n=0; n<TAG_CHANNELS; n++){
if (TAGGER.time[n] != 0.0 ){
TAGGER.multiples_per_channel[n]++;
}
}
}
// Enter the tagged energy in the right histogram and do the timing
for (int k = 0; k < N_E_WINDOW; k ++){
// If the right tagger channel is found
for (int i = 0; i < (int)RAW_CALIB.size(); i++){
// Check for the central crystal
if ( i==CENTRAL && RAW_CALIB[i].is_signal == 1 ) is_coinc = true;
// Fill all events for the right tagger
if ( RAW_CALIB[i].is_signal == true && // If signal is valid
TAGGER.time[k] != 0 // and if tagger is set for energy k
){
RAW_CALIB[i].tagged[k].energy = RAW_CALIB[i].energy;