GCTAEventList.cpp
51.8 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
/***************************************************************************
* GCTAEventList.cpp - CTA event list class *
* ----------------------------------------------------------------------- *
* copyright (C) 2010-2017 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file GCTAEventList.cpp
* @brief CTA event list class implementation
* @author Juergen Knoedlseder
*/
/* __ Includes ___________________________________________________________ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <typeinfo>
#include <cstdio> // sprintf
#include "GTools.hpp"
#include "GMath.hpp"
#include "GFilename.hpp"
#include "GFits.hpp"
#include "GFitsTable.hpp"
#include "GFitsBinTable.hpp"
#include "GFitsTableCol.hpp"
#include "GFitsTableFloatCol.hpp"
#include "GFitsTableDoubleCol.hpp"
#include "GFitsTableLongCol.hpp"
#include "GFitsTableULongCol.hpp"
#include "GTime.hpp"
#include "GTimeReference.hpp"
#include "GCTAEventList.hpp"
#include "GCTASupport.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_OPERATOR "GCTAEventList::operator[](int&)"
#define G_ROI "GCTAEventList::roi(GRoi&)"
#define G_APPEND_COLUMN "GCTAEventList::append_column(GFitsTableCol&)"
#define G_SET_MC_ID_NAMES "GCTAEventList::set_mc_id_names(std::vector<int>&,"\
" std::vector<std::string>&)"
#define G_FETCH "GCTAEventList::fetch()"
#define G_WRITE_DS_KEYS "GCTAEventList::write_ds_keys(GFitsHDU&, "\
"const std::string&) const"
/* __ Macros _____________________________________________________________ */
/* __ Coding definitions _________________________________________________ */
/* __ Debug definitions __________________________________________________ */
/*==========================================================================
= =
= Constructors/destructors =
= =
==========================================================================*/
/***********************************************************************//**
* @brief Void constructor
*
* Constructs empty event list.
***************************************************************************/
GCTAEventList::GCTAEventList(void) : GEventList()
{
// Initialise members
init_members();
// Return
return;
}
/***********************************************************************//**
* @brief File name constructor
*
* @param[in] filename Counts cube filename.
*
* Constructs event list by loading the events from a FITS file.
***************************************************************************/
GCTAEventList::GCTAEventList(const GFilename& filename) : GEventList()
{
// Initialise members
init_members();
// Load event list
load(filename);
// Return
return;
}
/***********************************************************************//**
* @brief Copy constructor
*
* @param[in] list Event list.
*
* Constructs event list by coping from another event list.
***************************************************************************/
GCTAEventList::GCTAEventList(const GCTAEventList& list) : GEventList(list)
{
// Initialise members
init_members();
// Copy members
copy_members(list);
// Return
return;
}
/***********************************************************************//**
* @brief Destructor
*
* Destructs event list.
***************************************************************************/
GCTAEventList::~GCTAEventList(void)
{
// Free members
free_members();
// Return
return;
}
/*==========================================================================
= =
= Operators =
= =
==========================================================================*/
/***********************************************************************//**
* @brief Assignment operator
*
* @param[in] list Event list.
* @return Event list.
*
* Assigns events from another event list.
***************************************************************************/
GCTAEventList& GCTAEventList::operator=(const GCTAEventList& list)
{
// Execute only if object is not identical
if (this != &list) {
// Copy base class members
this->GEventList::operator=(list);
// Free members
free_members();
// Initialise members
init_members();
// Copy members
copy_members(list);
} // endif: object was not identical
// Return this object
return *this;
}
/***********************************************************************//**
* @brief Event atom access operator
*
* @param[in] index Event index [0,...,size()-1].
* @return Pointer to event atom.
*
* @exception GException::out_of_range
* Event index outside valid range.
*
* Returns pointer to an event atom.
***************************************************************************/
GCTAEventAtom* GCTAEventList::operator[](const int& index)
{
// Make sure that the events are online
fetch();
// Optionally check if the index is valid
#if defined(G_RANGE_CHECK)
if (index < 0 || index >= size()) {
throw GException::out_of_range(G_OPERATOR, "Event index",
index, size());
}
#endif
// Return pointer
return (&(m_events[index]));
}
/***********************************************************************//**
* @brief Event atom access operator
*
* @param[in] index Event index [0,...,size()-1].
* @return Pointer to event atom.
*
* @exception GException::out_of_range
* Event index outside valid range.
*
* Returns pointer to an event atom.
***************************************************************************/
const GCTAEventAtom* GCTAEventList::operator[](const int& index) const
{
// Make sure that the events are online
fetch();
// Optionally check if the index is valid
#if defined(G_RANGE_CHECK)
if (index < 0 || index >= size()) {
throw GException::out_of_range(G_OPERATOR, "Event index",
index, size());
}
#endif
// Return pointer
return (&(m_events[index]));
}
/*==========================================================================
= =
= Public methods =
= =
==========================================================================*/
/***********************************************************************//**
* @brief Clear event list
*
* Clear event list.
***************************************************************************/
void GCTAEventList::clear(void)
{
// Free class members (base and derived classes, derived class first)
free_members();
this->GEventList::free_members();
this->GEvents::free_members();
// Initialise members
this->GEvents::init_members();
this->GEventList::init_members();
init_members();
// Return
return;
}
/***********************************************************************//**
* @brief Clone event list
*
* @return Pointer to deep copy of event list.
*
* Returns a pointer to a deep copy of the event list.
***************************************************************************/
GCTAEventList* GCTAEventList::clone(void) const
{
// Clone event list
return new GCTAEventList(*this);
}
/***********************************************************************//**
* @brief Load events from FITS file.
*
* @param[in] filename FITS file name.
*
* Loads the event list from a FITS file. See the read() method for details.
***************************************************************************/
void GCTAEventList::load(const GFilename& filename)
{
// Open FITS file
GFits fits(filename);
// Read event list
read(fits);
// Close FITS file
fits.close();
// Return
return;
}
/***********************************************************************//**
* @brief Save events into FITS file.
*
* @param[in] filename FITS file name.
* @param[in] clobber Overwrite existing FITS file (default: false).
*
* Saves the event list into a FITS file. See the write() method for details.
***************************************************************************/
void GCTAEventList::save(const GFilename& filename,
const bool& clobber) const
{
// Open or create FITS file (without extension name since the requested
// extension may not yet exist in the file)
GFits fits(filename.url(), true);
// Write event list
write(fits);
// Save FITS file
fits.save(clobber);
// Return
return;
}
/***********************************************************************//**
* @brief Read events from FITS file.
*
* @param[in] fits FITS file.
*
* Reads the event list from a FITS file.
*
* The events will be read by default from the extension `EVENTS` unless
* an extension name is explicitly specified in the FITS file name. The
* FITS header of the extension will be scanned for data sub-space keywords
* to extract the energy boundaries, the region of interest, as well as the
* extension name for the Good Time Intervals. If no extension name for
* Good Time Intervals is found it is expected that the Good Time Intervals
* reside in the `GTI` extension.
*
* If a Good Time Intervals is found in the same FITS file, the Good Time
* Intervals will be loaded. Otherwise, a single Good Time Interval will
* be assumed based on the `TSTART` and `TSTOP` keywords found in the header
* of the event list.
*
* The method clears the event list before reading, thus any events that
* existed before in the event list will be lost. Note that the method will
* actually not read the events but only the event metadata. The events are
* only read from the FITS file when they are actually need. This reduces
* the memory requirements. Events can be manually loaded into memory using
* the fetch() method. Events can be unloaded using the dispose() method, but
* the user has to take care of saving the events to disk in case he wants
* to keep them for further use.
***************************************************************************/
void GCTAEventList::read(const GFits& fits)
{
// Clear object
clear();
// Store the FITS file name
m_filename = fits.filename();
// Initialise events extension name
std::string extname = fits.filename().extname(gammalib::extname_cta_events);
// Get event list HDU
const GFitsTable& events = *fits.table(extname);
// Determine number of events from event list HDU
m_num_events = events.nrows();
// Signal presence of "DETX" and "DETY" columns
if (events.contains("DETX") && events.contains("DETY")) {
m_has_detxy = true;
}
else {
m_has_detxy = false;
}
// Signal presence of "PHASE" column
if (events.contains("PHASE")) {
m_has_phase = true;
}
else {
m_has_phase = false;
}
// Signal presence of "MC_ID" column
if (events.contains("MC_ID")) {
m_has_mc_id = true;
}
else {
m_has_mc_id = false;
}
// Read GTI extension name from data sub-space keyword
std::string gti_extname = gammalib::read_ds_gti_extname(events);
// If no GTI extension name was found then
if (gti_extname.empty()) {
gti_extname = gammalib::extname_gti;
}
// If GTI extension is present in FITS file then read Good Time Intervals
// from that extension
if (fits.contains(gti_extname)) {
const GFitsTable& gti = *fits.table(gti_extname);
m_gti_extname = gti_extname;
m_gti.read(gti);
}
// ... otherwise build GTI from TSTART and TSTOP
else {
// Read start and stop time
double tstart = events.real("TSTART");
double tstop = events.real("TSTOP");
// Create time reference from header information
GTimeReference timeref(events);
// Set GTI time reference
m_gti.reference(timeref);
// Set start and stop time
GTime start(tstart, m_gti.reference());
GTime stop(tstop, m_gti.reference());
// Append start and stop time as single time interval to GTI
m_gti.append(start, stop);
} // endelse: GTI built from TSTART and TSTOP
// Read region of interest from data sub-space keyword
m_roi = gammalib::read_ds_roi(events);
// Read energy boundaries from data sub-space keyword
m_ebounds = gammalib::read_ds_ebounds(events);
// Read phase intervals from data sub-space keyword
m_phases = gammalib::read_ds_phase(events);
// If the file name contains an expression then load the events now.
// We do this at the end to make sure that the GTI has been set before.
if (m_filename.has_expression()) {
read_events(events);
}
// Read Monte Carlo identifier keywords
read_mc_ids(events);
// Return
return;
}
/***********************************************************************//**
* @brief Write CTA events and Good Time Intervals into FITS file
*
* @param[in] fits FITS file.
*
* Writes the CTA event list and the Good Time intervals into a FITS file.
*
* The events will be written by default into the extension `EVENTS` unless
* an extension name is explicitly specified in the FITS file name. The
* method also writes the data sub-space keywords in the FITS header of the
* events table.
*
* In addition, the method will also append a table containing the Good Time
* Intervals of the events to the FITS file. The extension name for the Good
* Time Intervals is either taken from the m_gti_extname member, or if empty,
* is set to `GTI`.
***************************************************************************/
void GCTAEventList::write(GFits& fits) const
{
// Set event extension name
std::string evtname = fits.filename().extname(gammalib::extname_cta_events);
// Set GTI extension name
std::string gtiname = (m_gti_extname.empty())
? gammalib::extname_gti : m_gti_extname;
// Write events and GTIs
write(fits, evtname, gtiname);
// Return
return;
}
/***********************************************************************//**
* @brief Write CTA events and Good Time Intervals into FITS file
*
* @param[in] fits FITS file.
* @param[in] evtname Event FITS extension name.
* @param[in] gtiname Good Time Intervals FITS extension name.
*
* Writes the CTA event list and the Good Time intervals into a FITS file.
*
* The events will be written into the extension @p evtname while the Good
* Time Intervals will be written into the extension @p gtiname.
***************************************************************************/
void GCTAEventList::write(GFits& fits, const std::string& evtname,
const std::string& gtiname) const
{
// Allocate empty FITS binary table
GFitsBinTable table;
// Write events into binary table
write_events(table);
// Set FITS extension name
table.extname(evtname);
// Write data selection keywords
write_ds_keys(table, gtiname);
// Write Monte Carlo identifier keywords
write_mc_ids(table);
// Append event table to FITS file
fits.append(table);
// Write GTI extension
gti().write(fits, gtiname);
// Store FITS file name
m_filename = fits.filename();
// Return
return;
}
/***********************************************************************//**
* @brief Set ROI
*
* @param[in] roi ROI.
*
* @exception GException::invalid_argument
* Invalid region of interest class specified.
*
* Sets the region of interest of the event list.
***************************************************************************/
void GCTAEventList::roi(const GRoi& roi)
{
// Cast ROI dynamically
const GCTARoi* ptr = dynamic_cast<const GCTARoi*>(&roi);
// Throw exception if ROI is not of correct type
if (ptr == NULL) {
std::string cls = std::string(typeid(&roi).name());
std::string msg = "Invalid region of interest type \""+cls+"\" "
"provided on input. Please specify a \"GCTARoi\" "
"object as argument.";
throw GException::invalid_argument(G_ROI, msg);
}
// Set ROI
m_roi = *ptr;
// Return
return;
}
/***********************************************************************//**
* @brief Append event to event list
*
* @param[in] event Event.
*
* Appends an event to the end of the event list.
***************************************************************************/
void GCTAEventList::append(const GCTAEventAtom& event)
{
// Make sure that the events are online
fetch();
// Append event
m_events.push_back(event);
// Append an element to all additional columns
for (int i = 0; i < m_columns.size(); ++i) {
m_columns[i]->insert(m_columns[i]->nrows(),1);
}
// Set number of events
m_num_events = m_events.size();
// Set event index
int index = m_num_events - 1;
m_events[index].m_index = index;
// Return
return;
}
/***********************************************************************//**
* @brief Append FITS table column to event list
*
* @param[in] column FITS table column to be appended.
*
* @exception GException::invalid_argument
* FITS column has incompatible number of rows.
*
* Appends a FITS table column to the event list. The length of the FITS
* column must be identical to the number of events in the event list.
***************************************************************************/
void GCTAEventList::append_column(const GFitsTableCol& column)
{
// Throw an exception if the column has an incompatible number of rows
if (size() != column.nrows()) {
std::string msg = "Incompatible column length. Attempt to append a "
"column of length "+gammalib::str(column.nrows())+
" to an event list with "+gammalib::str(size())+
" events. Please specify a column of length "+
gammalib::str(size())+".";
throw GException::invalid_argument(G_APPEND_COLUMN, msg);
}
// Make sure that the events are online
fetch();
// Clone the FITS column. De-allocation is done when the object is free'd
GFitsTableCol* ptr = column.clone();
// Append the column
m_columns.push_back(ptr);
// Return
return;
}
/***********************************************************************//**
* @brief Remove events from event list
*
* @param[in] index Index from which on events should be removed.
* @param[in] number Number of event to remove (default: 1).
*
* Removes events from the event list. This method does nothing if @p index
* points beyond the event list. The method does also gently accept
* @p number arguments where @p index + @p number reach beyond the event
* list. In that case, all events from event @p index on will be removed.
***************************************************************************/
void GCTAEventList::remove(const int& index, const int& number)
{
// Make sure that the events are online
fetch();
// Continue only if index is valid
if (index < size()) {
// Determine number of elements to remove
int n_remove = (index + number > size()) ? size() - index : number;
// Remove events
m_events.erase(m_events.begin() + index,
m_events.begin() + index + n_remove);
// Remove elements from additional columns
for (int i = 0; i < m_columns.size(); ++i) {
m_columns[i]->remove(index, n_remove);
}
// Set number of events
m_num_events = m_events.size();
} // endif: index was valid
// Return
return;
}
/***********************************************************************//**
* @brief Fetch events
*
* @exception GException::file_error
* File not found.
* Unable to load events.
* @exception GException::invalid_value
* No file name has been specified.
* Fetched number of events mismatches the expectation.
*
* Fetches the events by reading them from a FITS file. This method does
* nothing if the events are already loaded, if there is nothing to fetch,
* or if the m_filename member is empty.
*
* The method is thread save. The method furthermore checks whether the
* loaded number of events corresponds to the expectation. If also checks
* whether the file from which events should be loaded actually exists.
***************************************************************************/
void GCTAEventList::fetch(void) const
{
// Continue only if events are not loaded but there are events to fetch
if (m_events.empty() && size() > 0) {
// Continue only if the file name is not empty
if (!m_filename.is_empty()) {
// Throw an exception if the file does not exist
if (!m_filename.exists()) {
std::string msg = "File \""+m_filename+"\" not found. "
"Cannot fetch events. Maybe the file has "
"been deleted in the meantime.";
GException::file_error(G_FETCH, msg);
}
// Initialise exception flag
bool has_exception = false;
// Load events. Catch any exception. Put the code into a critical
// zone as it might be called from within a parallelized thread.
#pragma omp critical(GCTAEventList_fetch)
{
try {
// Open FITS file
GFits fits(m_filename);
// Initialise events extension name
std::string extname = fits.filename().extname(gammalib::extname_cta_events);
// Get event list HDU
const GFitsTable& events = *fits.table(extname);
// Load event data
read_events(events);
// Close FITS file
fits.close();
}
catch (...) {
has_exception = true;
}
}
// Throw an exception if an exception has occured
if (has_exception) {
std::string msg = "Unable to load events from file \""+
m_filename+"\".";
throw GException::file_error(G_FETCH, msg);
}
// Throw an exception if the number of events does not correspond
// to the expectation
if (m_events.size() != size()) {
std::string msg = "Loaded "+gammalib::str(m_events.size())+
" events from FITS file while "+
gammalib::str(size())+" events were "
"expected. This should never happen!";
throw GException::invalid_value(G_FETCH, msg);
}
} // endif: filename was not empty
// Throw an exception if the FITS file name is not known
else {
std::string msg = "Unable to fetch "+gammalib::str(size())+
" events since the name of the FITS file from "
"which to fetch the events is not known.";
throw GException::invalid_value(G_FETCH, msg);
}
} // endif: there were no events
// Return
return;
}
/***********************************************************************//**
* @brief Dispose events
*
* Disposes the events to save memory. The method free's all memory
* associated to the events. The method should be used with care as it does
* not check whether the events can actually be recovered using the fetch()
* method. Eventually, the events should be saved before so that fetch()
* can recover them.
***************************************************************************/
void GCTAEventList::dispose(void) const
{
// Free additional columns
for (int i = 0; i < m_columns.size(); ++i) {
delete m_columns[i];
m_columns[i] = NULL;
}
// Clear events and additional columns
m_events.clear();
m_columns.clear();
// Now actually remove the memory reserved for these objects. See
// https://prateekvjoshi.com/2013/10/20/c-vector-memory-release/
// for an explanation of this code.
std::vector<GCTAEventAtom>(m_events).swap(m_events);
std::vector<GFitsTableCol*>(m_columns).swap(m_columns);
// Return
return;
}
/***********************************************************************//**
* @brief Set Monte Carlo identifiers and model names
*
* @param[in] ids Monte Carlo identifiers.
* @param[in] names Model name for each Monte Carlo identifier.
*
* Sets the Monte Carlo identifiers and their corresponding model names.
* The information will then be written into the header file.
***************************************************************************/
void GCTAEventList::set_mc_id_names(const std::vector<int>& ids,
const std::vector<std::string>& names)
{
// Throw an exception if the vectors have an incompatible size
if (ids.size() != names.size()) {
std::string msg = "The number of Monte Carlo identifiers ("+
gammalib::str(ids.size())+") does not correspond to "
"the number of model names ("+
gammalib::str(names.size())+"). Please provide the "
"same number of model names and Monte Carlo "
"identifiers.";
throw GException::invalid_argument(G_SET_MC_ID_NAMES, msg);
}
// Set vectors
m_mc_ids = ids;
m_mc_id_names = names;
// Return
return;
}
/***********************************************************************//**
* @brief Print event list information
*
* @param[in] chatter Chattiness.
* @return String containing event list information.
***************************************************************************/
std::string GCTAEventList::print(const GChatter& chatter) const
{
// Initialise result string
std::string result;
// Continue only if chatter is not silent
if (chatter != SILENT) {
// Append header
result.append("=== GCTAEventList ===");
// Append number of events and disposal information
result.append("\n"+gammalib::parformat("Number of events") +
gammalib::str(size()));
if (m_events.empty()) {
if (!m_filename.is_empty()) {
result.append(" (disposed in \""+m_filename+"\")");
}
else {
result.append(" (disposed without possibility to recover)");
}
}
else {
result.append(" (loaded)");
}
// Append GTI interval
result.append("\n"+gammalib::parformat("Time interval"));
if (gti().size() > 0) {
result.append(gammalib::str(tstart().mjd()));
result.append(" - ");
result.append(gammalib::str(tstop().mjd())+" days");
}
else {
result.append("not defined");
}
// Append energy intervals
if (gammalib::reduce(chatter) > SILENT) {
if (ebounds().size() > 0) {
result.append("\n"+ebounds().print(gammalib::reduce(chatter)));
}
else {
result.append("\n"+gammalib::parformat("Energy intervals") +
"not defined");
}
}
else {
result.append("\n"+gammalib::parformat("Energy interval"));
if (ebounds().size() > 0) {
result.append(gammalib::str(emin().TeV()));
result.append(" - ");
result.append(gammalib::str(emax().TeV())+" TeV");
}
else {
result.append("not defined");
}
}
// Append ROI
if (gammalib::reduce(chatter) > SILENT) {
if (roi().radius() > 0) {
result.append("\n"+roi().print(gammalib::reduce(chatter)));
}
else {
result.append("\n"+gammalib::parformat("Region of interest") +
"not defined");
}
}
else {
result.append("\n"+gammalib::parformat("Region of interest"));
if (roi().radius() > 0) {
result.append(roi().centre().print());
result.append(" Radius=");
result.append(gammalib::str(roi().radius())+" deg");
}
else {
result.append("not defined");
}
}
// EXPLICIT: Append IRF cache
if (chatter >= EXPLICIT) {
for (int i = 0; i < m_irf_names.size(); ++i) {
result.append("\n"+gammalib::parformat("IRF cache " +
gammalib::str(i)));
result.append(m_irf_names[i]+" = ");
int num = 0;
for (int k = 0; k < size(); ++k) {
if ((m_irf_values[i])[k] != -1.0) {
num++;
}
}
result.append(gammalib::str(num)+" values");
}
} // endif: chatter was explicit
} // endif: chatter was not silent
// Return result
return result;
}
/*==========================================================================
= =
= Private methods =
= =
==========================================================================*/
/***********************************************************************//**
* @brief Initialise class members
***************************************************************************/
void GCTAEventList::init_members(void)
{
// Initialise members
m_roi.clear();
m_phases.clear();
m_events.clear();
m_columns.clear();
m_filename.clear();
m_num_events = 0;
m_gti_extname = gammalib::extname_gti; //!< Default GTI extension name
m_has_phase = false;
m_has_detxy = true;
m_has_mc_id = false;
m_mc_ids.clear();
m_mc_id_names.clear();
// Initialise cache
m_irf_names.clear();
m_irf_values.clear();
// Return
return;
}
/***********************************************************************//**
* @brief Copy class members
*
* @param[in] list Event list.
***************************************************************************/
void GCTAEventList::copy_members(const GCTAEventList& list)
{
// Copy members
m_roi = list.m_roi;
m_phases = list.m_phases;
m_events = list.m_events;
m_filename = list.m_filename;
m_num_events = list.m_num_events;
m_gti_extname = list.m_gti_extname;
m_has_phase = list.m_has_phase;
m_has_detxy = list.m_has_detxy;
m_has_mc_id = list.m_has_mc_id;
m_mc_ids = list.m_mc_ids;
m_mc_id_names = list.m_mc_id_names;
// Copy cache
m_irf_names = list.m_irf_names;
m_irf_values = list.m_irf_values;
// Copy column pointers
m_columns.clear();
for (int i = 0; i < list.m_columns.size(); ++i) {
m_columns.push_back((list.m_columns[i]->clone()));
}
// Return
return;
}
/***********************************************************************//**
* @brief Delete class members
***************************************************************************/
void GCTAEventList::free_members(void)
{
// Free columns
for (int i = 0; i < m_columns.size(); ++i) {
delete m_columns[i];
m_columns[i] = NULL;
}
// Return
return;
}
/***********************************************************************//**
* @brief Read CTA events from FITS table
*
* @param[in] table FITS table.
*
* This method reads the CTA event list from a FITS table into memory.
* The following columns are mandatory in the FITS table:
*
* - EVENT_ID
* - TIME
* - RA
* - DEC
* - ENERGY
*
* Optionally, the
*
* - DETX
* - DETY
* - PHASE
*
* columns are read. Any other columns present in the FITS table will also be
* read, and written into the FITS table when the write_events() method is
* called.
***************************************************************************/
void GCTAEventList::read_events(const GFitsTable& table) const
{
// Dispose any existing events
dispose();
// Extract number of events in FITS file
int num = table.nrows();
// If there are events then load them
if (num > 0) {
// Reserve data
m_events.reserve(num);
// Get column pointers
const GFitsTableCol* ptr_eid = table["EVENT_ID"];
const GFitsTableCol* ptr_time = table["TIME"];
const GFitsTableCol* ptr_ra = table["RA"];
const GFitsTableCol* ptr_dec = table["DEC"];
const GFitsTableCol* ptr_energy = table["ENERGY"];
// Optionally get pointers to DETX and DETY columns
const GFitsTableCol* ptr_detx = (m_has_detxy) ? table["DETX"] : NULL;
const GFitsTableCol* ptr_dety = (m_has_detxy) ? table["DETY"] : NULL;
// Optionally get pointer to PHASE column
const GFitsTableCol* ptr_phase = (m_has_phase) ? table["PHASE"] : NULL;
// Optionally get pointer to MC_ID column
const GFitsTableCol* ptr_mc_id = (m_has_mc_id) ? table["MC_ID"] : NULL;
// Copy data from columns into GCTAEventAtom objects
for (int i = 0; i < num; ++i) {
// Allocate event
GCTAEventAtom event;
// Set mandatory information
event.m_time.set(ptr_time->real(i), m_gti.reference());
event.m_dir.dir().radec_deg(ptr_ra->real(i), ptr_dec->real(i));
event.m_energy.TeV(ptr_energy->real(i));
event.m_event_id = ptr_eid->integer(i);
event.m_index = i;
// If available, set detector coordinates in radians
if (m_has_detxy) {
event.m_dir.detx(ptr_detx->real(i)*gammalib::deg2rad);
event.m_dir.dety(ptr_dety->real(i)*gammalib::deg2rad);
}
// If available, set pulse phase
if (m_has_phase) {
event.m_phase = ptr_phase->real(i);
}
// If available, set Monte Carlo identifier
if (m_has_mc_id) {
event.m_mc_id = ptr_mc_id->integer(i);
}
// Append event
m_events.push_back(event);
} // endfor: looped over all events
// Loop over table and find optional columns
for (int i = 0; i < table.ncols(); ++i) {
// Get column pointer
const GFitsTableCol* col = table[i];
// Get column name
const std::string name = col->name();
// If column was mandatory or optional then skip it ...
if (name == "EVENT_ID" ||
name == "TIME" ||
name == "RA" ||
name == "DEC" ||
name == "ENERGY" ||
name == "DETX" ||
name == "DETY" ||
name == "PHASE" ||
name == "MC_ID") {
continue;
}
// ... otherwise keep a copy
else {
m_columns.push_back(col->clone());
}
} // endfor: loop over optional columns
} // endif: there were events
// Return
return;
}
/***********************************************************************//**
* @brief Read Monte Carlo identifier keywords from FITS HDU
*
* @param[in] table FITS table HDU.
*
* Reads the Monte Carlo identifier keywords for an event list from the FITS
* table HDU.
***************************************************************************/
void GCTAEventList::read_mc_ids(const GFitsTable& table)
{
// Clear Monte Carlo identifiers and names
m_mc_ids.clear();
m_mc_id_names.clear();
// Continue only if the header contains a "MCIDS" keyword
if (table.has_card("NMCIDS")) {
// Get number of Monte Carlo identifiers
int nids = table.integer("NMCIDS");
// Continue only if there are identifiers
if (nids > 0) {
// Reserve space for elements
m_mc_ids.reserve(nids);
m_mc_id_names.reserve(nids);
// Loop over Monte Carlo identifiers
for (int i = 0; i < nids; ++i) {
// Set keyword names
char keyword_id[10];
char keyword_name[10];
sprintf(keyword_id, "MID%5.5d", i+1);
sprintf(keyword_name, "MMN%5.5d", i+1);
// Get header keywords
int id = table.integer(std::string(keyword_id));
std::string name = table.string(std::string(keyword_name));
// Put identifier and name in list
m_mc_ids.push_back(id);
m_mc_id_names.push_back(name);
} // endfor: looped over Monte Carlo identifiers
} // endif: there were identifiers
} // endif: there were Monte Carlo identifiers
// Return
return;
}
/***********************************************************************//**
* @brief Write CTA events into FITS table
*
* @param[in] hdu FITS binary table.
*
* Write the CTA event list into a FITS binary table.
*
* The following mandatory columns will be written into the FITS table:
*
* - EVENT_ID
* - TIME
* - RA
* - DEC
* - ENERGY
*
* If available, also the
*
* - DETX
* - DETY
* - PHASE
*
* columns are written. Any other columns that were read by the read_events()
* method will be also written into the table.
***************************************************************************/
void GCTAEventList::write_events(GFitsBinTable& hdu) const
{
// Make sure that the events are online
fetch();
// Set extension name
hdu.extname(gammalib::extname_cta_events);
// If there are events then write them now
if (size() > 0) {
// Allocate mandatory columns
GFitsTableULongCol col_eid("EVENT_ID", size());
GFitsTableDoubleCol col_time("TIME", size());
GFitsTableFloatCol col_ra("RA", size());
GFitsTableFloatCol col_dec("DEC", size());
GFitsTableFloatCol col_energy("ENERGY", size());
// Set units of columns
// (see http://fits.gsfc.nasa.gov/standard30/fits_standard30aa.pdf)
col_time.unit("s");
col_ra.unit("deg");
col_dec.unit("deg");
col_energy.unit("TeV");
// Fill mandatory columns
for (int i = 0; i < size(); ++i) {
col_eid(i) = m_events[i].m_event_id;
col_time(i) = m_events[i].time().convert(m_gti.reference());
col_ra(i) = m_events[i].dir().dir().ra_deg();
col_dec(i) = m_events[i].dir().dir().dec_deg();
col_energy(i) = m_events[i].energy().TeV();
}
// Append mandatory columns to table
hdu.append(col_eid);
hdu.append(col_time);
hdu.append(col_ra);
hdu.append(col_dec);
hdu.append(col_energy);
// If available, add detector coordinates in degrees
if (m_has_detxy) {
// Allocate columns
GFitsTableFloatCol col_detx("DETX", size());
GFitsTableFloatCol col_dety("DETY", size());
// Set units of columns
// (see http://fits.gsfc.nasa.gov/standard30/fits_standard30aa.pdf)
col_detx.unit("deg");
col_dety.unit("deg");
// Fill columns
for (int i = 0; i < size(); ++i) {
col_detx(i) = m_events[i].dir().detx() * gammalib::rad2deg;
col_dety(i) = m_events[i].dir().dety() * gammalib::rad2deg;
}
// Append columns to table
hdu.append(col_detx);
hdu.append(col_dety);
}
// If available, add event phase
if (m_has_phase) {
// Allocate columns
GFitsTableFloatCol col_phase("PHASE", size());
// Fill columns
for (int i = 0; i < size(); ++i) {
col_phase(i) = m_events[i].m_phase;
}
// Append column to table
hdu.append(col_phase);
}
// If available, add Monte Carlo identifier
if (m_has_mc_id) {
// Allocate columns
GFitsTableLongCol col_mc_id("MC_ID", size());
// Fill columns
for (int i = 0; i < size(); ++i) {
col_mc_id(i) = m_events[i].m_mc_id;
}
// Append column to table
hdu.append(col_mc_id);
}
// Append other columns to table
for (int i = 0; i < m_columns.size(); ++i) {
hdu.append(*m_columns[i]);
}
} // endif: there were events to write
// Return
return;
}
/***********************************************************************//**
* @brief Write data sub-space keywords into FITS HDU
*
* @param[in] hdu FITS HDU.
* @param[in] gtiname Good Time Interval FITS extension.
*
* @exception GException::vector_mismatch
* Lower and upper phase boundaries have different size.
*
* Writes the data sub-space keywords for an event list into the FITS HDU.
* The following keywords will be written:
*
* DSTYP1 = "TIME" / Data sub-space type
* DSUNI1 = "s" / Data sub-space unit
* DSVAL1 = "TABLE" / Data sub-space value
* DSREF1 = ":[extname]" / Data sub-space reference
* DSTYP2 = "ENERGY" / Data sub-space type
* DSUNI2 = "TeV" / Data sub-space unit
* DSVAL2 = "[emin]:[emax]" / Data sub-space value
* DSTYP3 = "POS(RA,DEC)" / Data sub-space type
* DSUNI3 = "deg" / Data sub-space unit
* DSVAL3 = "CIRCLE([ra],[dec],[rad])" / Data sub-space value
* NDSKEYS = 3 / Number of data sub-space keys
*
* where
*
* [extname] is the GTI extension name @p gtiname
* [emin] is the minimum event energy in TeV
* [emax] is the maximum event energy in TeV
* [ra] is the Right Ascension of the Region of Interest centre in degrees
* [dec] is the Declination of the Region of Interest centre in degrees
* [rad] is the radius of the Region of Interest in degrees
***************************************************************************/
void GCTAEventList::write_ds_keys(GFitsHDU& hdu, const std::string& gtiname) const
{
// Set ROI parameters
double ra = roi().centre().dir().ra_deg();
double dec = roi().centre().dir().dec_deg();
double rad = roi().radius();
// Set energy range parameters
double e_min = emin().TeV();
double e_max = emax().TeV();
// Set energy selection string
std::string dsval2 = gammalib::str(e_min) + ":" +
gammalib::str(e_max);
// Set Good Time Intervals extension name
std::string dsref1 = ":"+gtiname;
// Add time selection keywords
hdu.card("DSTYP1", "TIME", "Data sub-space type");
hdu.card("DSUNI1", "s", "Data sub-space unit");
hdu.card("DSVAL1", "TABLE", "Data sub-space value");
hdu.card("DSREF1", dsref1, "Data sub-space reference");
// Add energy range selection
hdu.card("DSTYP2", "ENERGY", "Data sub-space type");
hdu.card("DSUNI2", "TeV", "Data sub-space unit");
hdu.card("DSVAL2", dsval2, "Data sub-space value");
// Initialise number of NDSKEYS
int ndskeys = 2;
// Add acceptance cone only if RoI information is valid
if (m_roi.is_valid()) {
// Set cone selection string
std::string dsval3 = "CIRCLE(" +
gammalib::str(ra) + "," +
gammalib::str(dec) + "," +
gammalib::str(rad) + ")";
// Write DS keywords
hdu.card("DSTYP3", "POS(RA,DEC)", "Data sub-space type");
hdu.card("DSUNI3", "deg", "Data sub-space unit");
hdu.card("DSVAL3", dsval3, "Data sub-space value");
ndskeys++;
} // endif: RoI was valid
// Check if there are phase interval cuts
if (m_phases.size() > 0) {
// Set phase interval string
std::string dsval4 = "";
for (int i = 0; i < m_phases.size(); ++i) {
if (i != 0) {
dsval4 += ",";
}
dsval4 += gammalib::str(m_phases.pmin(i)) + ":" +
gammalib::str(m_phases.pmax(i));
}
// Write DS keywords
ndskeys++;
hdu.card("DSTYP"+gammalib::str(ndskeys), "PHASE",
"Data sub-space type");
hdu.card("DSUNI"+gammalib::str(ndskeys), "DIMENSIONLESS",
"Data sub-space unit");
hdu.card("DSVAL"+gammalib::str(ndskeys), dsval4,
"Data sub-space value");
} // endif: there were phase interval cuts
// Set number of data selection keys
hdu.card("NDSKEYS", ndskeys, "Number of data sub-space keys");
// Return
return;
}
/***********************************************************************//**
* @brief Write Monte Carlo identifier keywords into FITS HDU
*
* @param[in] hdu FITS HDU.
*
* Writes the Monte Carlo identifier keywords for an event list into the FITS
* HDU. The following keywords will be written:
*
* NMCIDS Number of Monte Carlo identifiers
* MID00001 First Monte Carlo identifier
* MMN00001 Model name for first Monte Carlo identifier
* MID00002 Second Monte Carlo identifier
* MMN00002 Model name for second Monte Carlo identifier
* ...
***************************************************************************/
void GCTAEventList::write_mc_ids(GFitsHDU& hdu) const
{
// Set number of Monte Carlo identifiers
int nids = m_mc_ids.size();
// Continue only if there are Monte Carlo identifiers
if (nids > 0) {
// Set number of Monte Carlo identifiers
hdu.card("NMCIDS", nids, "Number of Monte Carlo identifiers");
// Loop over Monte Carlo identifiers
for (int i = 0; i < nids; ++i) {
// Set keyword names
char keyword_id[10];
char keyword_name[10];
sprintf(keyword_id, "MID%5.5d", i+1);
sprintf(keyword_name, "MMN%5.5d", i+1);
// Set comments
std::string comment_id = "Monte Carlo identifier for model " +
gammalib::str(i+1);
std::string comment_name = "Name of model " + gammalib::str(i+1);
// Write header keywords
hdu.card(std::string(keyword_id), m_mc_ids[i], comment_id);
hdu.card(std::string(keyword_name), m_mc_id_names[i], comment_name);
} // endfor: looped over Monte Carlo identifiers
} // endif: there were Monte Carlo identifiers
// Return
return;
}
/***********************************************************************//**
* @brief Initialize IRF cache for a given model
*
* @param[in] name Model name.
* @return Cache index (-1 if invalid).
***************************************************************************/
int GCTAEventList::irf_cache_init(const std::string& name) const
{
// Initialise cache index
int index = irf_cache_index(name);
// Continue only if model does not yet exist
if (index == -1) {
// Add model name and vector to cache. The vector is initialized
// to -1, which signals that no cache values exist
m_irf_names.push_back(name);
m_irf_values.push_back(std::vector<double>(size(), -1.0));
// Set index
index = m_irf_names.size()-1;
} // endif: model cache did not yet exist
// Return index
return index;
}
/***********************************************************************//**
* @brief Determines the cache index for a given model name
*
* @param[in] name Model name.
* @return Cache index (-1 if model has not been found).
***************************************************************************/
int GCTAEventList::irf_cache_index(const std::string& name) const
{
// Initialise index
int index = -1;
// Continue only if there are models in cache
if (!m_irf_names.empty()) {
// Search for model name
for (int i = 0; i < m_irf_names.size(); ++i) {
if (m_irf_names[i] == name) {
index = i;
break;
}
}
} // endif: there were models in cache
// Return index
return index;
}
/***********************************************************************//**
* @brief Get cache IRF value
*
* @param[in] name Model name.
* @param[in] index Event index [0,...,size()-1].
* @return IRF value (-1 if no cache value found).
***************************************************************************/
double GCTAEventList::irf_cache(const std::string& name, const int& index) const
{
// Initialise IRF value to invalid value
double irf = -1.0;
// Get cache index. Continue only if index is valid
int icache = irf_cache_index(name);
if (icache != -1) {
irf = (m_irf_values[icache])[index];
}
// Return IRF value
return irf;
}
/***********************************************************************//**
* @brief Set cache IRF value
*
* @param[in] name Model name.
* @param[in] index Event index [0,...,size()-1].
* @param[in] irf IRF value.
***************************************************************************/
void GCTAEventList::irf_cache(const std::string& name, const int& index,
const double& irf) const
{
// Initialize cache index. Continue only if index is valid
int icache = irf_cache_init(name);
if (icache != -1) {
(m_irf_values[icache])[index] = irf;
}
// Return
return;
}