-
Notifications
You must be signed in to change notification settings - Fork 0
/
hessio.py
935 lines (782 loc) · 26.1 KB
/
hessio.py
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
import numpy as np
import os
import ctypes
__all__ = ['move_to_next_event','file_open','close_file',
'get_global_event_count','get_run_number',
'get_num_telescope','get_telescope_with_data_list',
'get_teldata_list',
'get_num_teldata','get_num_channel','get_num_pixels',
'get_num_samples','get_adc_sample','get_adc_sum',
'get_data_for_calibration','get_pixel_position',
'get_pixel_timing_timval','get_mirror_area',
'get_pixel_timing_num_times_types',
'get_pixel_timing_threshold','get_pixel_timing_peak_global',
'get_mc_event_xcore', 'get_mc_event_ycore' ,'get_mc_shower_energy',
'get_mc_shower_azimuth' ,'get_mc_shower_altitude','get_adc_known',
'get_ref_shape' ,'get_ref_step','get_time_slice',
'get_ref_shapes', 'get_nrefshape' ,'get_lrefshape',
'get_tel_event_gps_time' ,'get_tel_event_gps_time','get_central_event_teltrg_list',
'get_num_tel_trig' ,'get_central_event_gps_time',
'get_mirror_number', 'get_optical_foclen', 'get_telescope_ids',
'HessioTelescopeIndexError','HessioGeneralError']
_path = os.path.dirname(__file__)
lib = np.ctypeslib.load_library('pyhessio', _path)
lib.close_file.restype = None
lib.file_open.argtypes = [ctypes.c_char_p]
lib.file_open.restype=ctypes.c_int
lib.get_adc_sample.argtypes = [ctypes.c_int,ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_uint16, flags="C_CONTIGUOUS")]
lib.get_adc_sample.restype = ctypes.c_int
lib.get_adc_sum.argtypes = [ctypes.c_int,ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_int32, flags="C_CONTIGUOUS")]
lib.get_adc_sum.restype = ctypes.c_int
lib.get_data_for_calibration.argtypes=[ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS"),
np.ctypeslib.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS")]
lib.get_data_for_calibration.restype=ctypes.c_int
lib.get_global_event_count.restype = ctypes.c_int
lib.get_mirror_area.argtypes = [ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS")]
lib.get_mirror_area.restype = ctypes.c_int
lib.get_num_channel.argtypes = [ctypes.c_int]
lib.get_num_channel.restype = ctypes.c_int
lib.get_num_pixels.argtypes = [ctypes.c_int]
lib.get_num_pixels.restype = ctypes.c_int
lib.get_num_samples.argtypes = [ctypes.c_int]
lib.get_num_samples.restype = ctypes.c_int
lib.get_num_teldata.restype = ctypes.c_int
lib.get_num_telescope.restype = ctypes.c_int
lib.get_num_tel_trig.restype = ctypes.c_int
lib.get_pixel_timing_num_times_types.argtypes = [ctypes.c_int]
lib.get_pixel_timing_num_times_types.restype = ctypes.c_int
lib.get_pixel_position.argtypes=[ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS"),
np.ctypeslib.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS")]
lib.get_pixel_position.restype=ctypes.c_int
lib.get_pixel_timing_peak_global.argtypes = [ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_float, flags="C_CONTIGUOUS")]
lib.get_pixel_timing_peak_global.restype = ctypes.c_int
lib.get_pixel_timing_threshold.argtypes = [ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_int, flags="C_CONTIGUOUS")]
lib.get_pixel_timing_threshold.restype = ctypes.c_int
lib.get_pixel_timing_timval.argtypes = [ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_float, flags="C_CONTIGUOUS")]
lib.get_pixel_timing_timval.restype=ctypes.c_int
lib.get_run_number.restype = ctypes.c_int
lib.get_telescope_with_data_list.argtypes = [np.ctypeslib.ndpointer(ctypes.c_int, flags="C_CONTIGUOUS")]
lib.get_telescope_with_data_list.restype = ctypes.c_int
lib.move_to_next_event.argtypes = [np.ctypeslib.ndpointer(ctypes.c_int)]
lib.move_to_next_event.restype = ctypes.c_int
lib.get_mc_event_xcore.restype = ctypes.c_double
lib.get_mc_event_ycore.restype = ctypes.c_double
lib.get_mc_shower_energy.restype = ctypes.c_double
lib.get_mc_shower_azimuth.restype = ctypes.c_double
lib.get_mc_shower_altitude.restype = ctypes.c_double
lib.get_adc_known.restype = ctypes.c_int
lib.get_adc_known.argtypes = [ctypes.c_int,ctypes.c_int,ctypes.c_int]
lib.get_ref_shape.restype = ctypes.c_double
lib.get_ref_shape.argtypes = [ctypes.c_int,ctypes.c_int,ctypes.c_int]
lib.get_time_slice.restype = ctypes.c_double
lib.get_time_slice.argtypes = [ctypes.c_int]
lib.get_ref_step.restype = ctypes.c_double
lib.get_ref_step.argtypes = [ctypes.c_int]
lib.get_ref_shapes.restypes = ctypes.c_int
lib.get_ref_shapes.argtypes =[ctypes.c_int,ctypes.c_int, np.ctypeslib.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS")]
lib.get_nrefshape.restypes = ctypes.c_int
lib.get_nrefshape.argtypes = [ctypes.c_int]
lib.get_lrefshape.restypes = ctypes.c_int
lib.get_lrefshape.argtypes = [ctypes.c_int]
lib.get_tel_event_gps_time.restype = ctypes.c_int
lib.get_tel_event_gps_time.argtypes = [ctypes.c_int,np.ctypeslib.ndpointer(ctypes.c_long, flags="C_CONTIGUOUS"), np.ctypeslib.ndpointer(ctypes.c_long, flags="C_CONTIGUOUS")]
lib.get_central_event_gps_time.restype = ctypes.c_int
lib.get_central_event_gps_time.argtypes = [np.ctypeslib.ndpointer(ctypes.c_long, flags="C_CONTIGUOUS"), np.ctypeslib.ndpointer(ctypes.c_long, flags="C_CONTIGUOUS")]
lib.get_central_event_teltrg_list.restype = ctypes.c_int
lib.get_central_event_teltrg_list.argtypes = [np.ctypeslib.ndpointer(ctypes.c_int, flags="C_CONTIGUOUS")]
lib.get_mirror_number.argtypes = [ctypes.c_int]
lib.get_mirror_number.restype = ctypes.c_int
lib.get_optical_foclen.argtypes = [ctypes.c_int]
lib.get_optical_foclen.restype = ctypes.c_double
lib.get_telescope_ids.argtypes = [np.ctypeslib.ndpointer(ctypes.c_int, flags="C_CONTIGUOUS")]
lib.get_telescope_ids.restype = ctypes.c_int
TEL_INDEX_NOT_VALID =-2
class HessioGeneralError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
class HessioTelescopeIndexError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
class HessioChannelIndexError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
def move_to_next_event(limit=0):
"""
Read data form input file
and fill corresponding container
Data can be then access with
other available functions in
this module
By default all events are computed
Parameters
----------
limit: int,optional
limit allows to limit the number of event generated
"""
result = np.zeros(1,dtype=np.int32)
res = 0
evt_num = 0
while res >= 0 and ( limit == 0 or evt_num < limit):
res = lib.move_to_next_event(result)
if res != -1:
yield res,result[0]
evt_num = evt_num + 1
def file_open(filename):
"""
Open input data file
Parameters
----------
filename: str
Returns
--------
0 in case of success, otherwise -1
"""
b_filename = filename.encode('utf-8')
return lib.file_open(b_filename)
def close_file():
"""
Close opened iobuf
"""
lib.close_file()
def get_global_event_count():
"""
Returns
-------
counter for system trigger
"""
return lib.get_global_event_count()
def get_run_number():
"""
Returns
-------
run number read in data file
or -1 if not available
Raises
------
HessioGeneralError
If hsdata->run_header.run is not available
"""
run = lib.get_run_number()
if run > 0 : return run
else:
raise(HessioGeneralError("run number not available"))
def get_num_telescope():
"""
Returns
-------
number of telescopes in current run.
Raises
------
HessioGeneralError
If hsdata->event.num_tel is not available
"""
number = lib.get_num_telescope()
if number > 0 : return number
else:
raise(HessioGeneralError("number of telescopes in current run not available"))
def get_num_tel_trig():
"""
Returns
-------
number How many telescopes triggered in Central Event
Raises
------
HessioGeneralError
If hsdata is not available
"""
number = lib.get_num_tel_trig()
if number > 0 : return number
else:
raise(HessioGeneralError("number of triggered telescopes in central event not available"))
def get_mirror_area(telescope_id):
"""
Returns
-------
total area of individual mirrors corrected
for inclination [m^2].
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
if hsdata->camera_set[itel].mirror_area not available
HessioTelescopeIndexError
if no telescope exist with this id
"""
data = np.zeros(1,dtype=np.double)
result = lib.get_mirror_area(telescope_id,data)
if result == 0:
return data[0]
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
raise(HessioGeneralError("hsdata->camera_set[itel].mirror_area not available"))
def get_telescope_with_data_list():
"""
Returns
-------
list of telescope with data for current event
Raises
------
HessioGeneralError
if information is not available
"""
try:
return get_teldata_list()
except:
raise(HessioGeneralError("hsdata->event.teldata_list is not available"))
def get_teldata_list():
"""
Returns
-------
list of IDs of telescopes with data for current event
Raises
------
HessioGeneralError
if information is not available
"""
num_teldata= get_num_teldata()
if num_teldata >= 0:
array = np.zeros(num_teldata,dtype=np.int32)
lib.get_telescope_with_data_list(array)
return array
else:
raise(HessioGeneralError("hsdata->event.num_teldata is not available"))
def get_num_teldata():
"""
Returns
-------
number of telescopes for which we actually have data
Raises
------
HessioGeneralError
If hsdata->event.num_teldata is not available
"""
number = lib.get_num_teldata()
if number > 0:
return number
else:
raise(HessioGeneralError("hsdata->event.num_teldata is not available"))
def get_num_channel(telescope_id):
"""
Returns
-------
type of channel used
HI_GAIN 0 /**< Index to high-gain channels in adc_sum, adc_sample, pedestal, ... */
LO_GAIN 1 /**< Index to low-gain channels in adc_sum, adc_sample, pedestal, ... */
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
If hsdata->event.teldata[itel].raw
HessioTelescopeIndexError
if no telescope exist with this id
"""
result = lib.get_num_channel(telescope_id)
if result >= 0: return result
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError(" hsdata->event.teldata[itel].raw not available"))
def get_num_pixels(telescope_id):
"""
Returns
-------
the number of pixels in the camera (as in configuration)
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
If hsdata->camera_set[itel].num_pixels
HessioTelescopeIndexError
if no telescope exist with this id
"""
result = lib.get_num_pixels(telescope_id)
if result >= 0 : return result
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("hsdata->camera_set[itel].num_pixels not available"))
def get_pixel_timing_threshold(telescope_id):
"""
Returns
-------
PixelTiming threshold:
- Minimum base-to-peak raw amplitude difference applied in pixel selection
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
If hsdata->event.teldata[itel].pixtm
HessioTelescopeIndexError
if no telescope exist with this id
"""
threshold = np.zeros(1,dtype=np.int32)
result = lib.get_pixel_timing_threshold(telescope_id,threshold)
if result == 0: return threshold[0]
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("hsdata->event.teldata[itel].pixtm not available"))
def get_pixel_timing_peak_global(telescope_id):
"""
Returns
-------
PixelTiming peak_global:
- Camera-wide (mean) peak position [time slices]
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
If hsdata->event.teldata[itel].pixtm; not available
HessioTelescopeIndexError
if no telescope exist with this id
"""
peak = np.zeros(1,dtype=np.float32)
result = lib.get_pixel_timing_peak_global(telescope_id,peak)
if result == 0: return peak[0]
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("hsdata->event.teldata[itel].pixtm; not available"))
def get_pixel_timing_num_times_types(telescope_id):
"""
Returns
-------
how many different types of times can we store
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
If hsdata->event.teldata[itel].pixtm->num_types not available
HessioTelescopeIndexError
if no telescope exist with this id
"""
result = lib.get_pixel_timing_num_times_types(telescope_id)
if result >= 0: return result
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("hsdata->event.teldata[itel].pixtm->num_types not available"))
def get_num_samples(telescope_id):
"""
Returns
-------
the number of samples (time slices) recorded
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
data->event.teldata[itel].raw->num->samples not available
HessioTelescopeIndexError
if no telescope exist with this id
"""
result = lib.get_num_samples(telescope_id)
if result >= 0: return result
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("ata->event.teldata[itel].raw->num->samples not available"))
def get_adc_sample(telescope_id,channel):
"""
Returns
-------
pulses sampled
Parameters
----------
telescope_id: int
channel: int (0->HI_GAIN, 1->LOW_GAIN)
Raises
------
HessioGeneralError
If information is not available
HessioTelescopeIndexError
if no telescope exist with this id
HessioChannelIndexError
If channel does not exist for this telescope
"""
if channel > get_num_channel(telescope_id)-1:
raise(HessioChannelIndexError("telescope " + str(telescope_id) + " has not channel " + str(channel)))
try:
npix = get_num_pixels(telescope_id)
ntimeslices = get_num_samples(telescope_id)
if ( ntimeslices > 0):
data = np.zeros(npix*ntimeslices,dtype=np.uint16)
result = lib.get_adc_sample(telescope_id,channel ,data)
if result == 0:
d_data = data.reshape(npix,ntimeslices)
return d_data
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("adc sample not available for telescope "+
str(telescope_id) +
" and channel " + str(channel)))
else:
return np.zeros(0)
except HessioTelescopeIndexError: raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
except HessioGeneralError: raise (HessioGeneralError("adc sample not available for telescope "+
str(telescope_id) +
" and channel " + str(channel)))
def get_adc_sum(telescope_id,channel):
"""
Returns
-------
the sum of ADC values.
Parameters
----------
telescope_id: int
channel: int (0->HI_GAIN, 1->LOW_GAIN)
Raises
------
HessioGeneralError
If No adc_sum for telescope
HessioTelescopeIndexError
if no telescope exist with this id
HessioChannelIndexError
If channel does not exist for this telescope
"""
if channel > get_num_channel(telescope_id)-1:
raise(HessioChannelIndexError("telescope " + str(telescope_id) + " has not channel " + str(channel)))
npix = get_num_pixels(telescope_id)
data = np.zeros(npix,dtype=np.int32)
result = lib.get_adc_sum(telescope_id,channel ,data)
if result == 0:
return data
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("No adc_sum for telescope "+ str(telescope_id)))
def get_pixel_timing_timval(telescope_id):
"""
Returns
-------
PixelTiming.timval
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
if hsdata->event.teldata[itel]->timval[ipix][itimes] not available
HessioTelescopeIndexError
if no telescope exist with this id
"""
npix = get_num_pixels(telescope_id)
ntimes = get_pixel_timing_num_times_types(telescope_id)
data = np.zeros(npix*ntimes,dtype=np.float32)
result = lib.get_pixel_timing_timval(telescope_id,data)
if result == 0:
d_data = data.reshape(npix,ntimes)
return d_data
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("no pixel timing timval for telescope "
+ str(telescope_id)))
def get_data_for_calibration(telescope_id):
"""
Returns
-------
pedestal, calibration 2D array
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
if data not available for this telescope
HessioTelescopeIndexError
if no telescope exist with this id
"""
npix = get_num_pixels(telescope_id)
ngain = 2 # LOW and HI Gain
pedestal = np.zeros(ngain*npix,dtype=np.double)
calibration = np.zeros(ngain*npix,dtype=np.double)
result = lib.get_data_for_calibration(telescope_id,pedestal,calibration)
if result == 0:
d_ped = pedestal.reshape(ngain,npix)
d_cal = calibration.reshape(ngain,npix)
return d_ped, d_cal
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("no calibration data for telescope "
+ str(telescope_id)))
def get_pixel_position(telescope_id):
"""
Returns
-------
pixels position for a telecsope id
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
if pixel position not available for this telescope
HessioTelescopeIndexError
if no telescope exist with this id
"""
npix = get_num_pixels(telescope_id)
pos_x = np.zeros(npix,dtype=np.double)
pos_y = np.zeros(npix,dtype=np.double)
result = lib.get_pixel_position(telescope_id,pos_x,pos_y)
if result == 0:
return pos_x, pos_y
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("no pixel position for telescope "
+ str(telescope_id)))
def get_mc_event_xcore():
"""
Returns
-------
x core position w.r.t. array reference point [m],
x -> N
"""
return lib.get_mc_event_xcore()
def get_mc_event_ycore():
"""
Returns
-------
y core position w.r.t. array reference point [m],
y -> W
"""
return lib.get_mc_event_ycore()
def get_mc_shower_energy():
"""
Returns
-------
shower primary energy [TeV]
"""
return lib.get_mc_shower_energy()
def get_mc_shower_azimuth():
"""
Returns
-------
shower azimuth (N->E) [rad]
"""
return lib.get_mc_shower_azimuth()
def get_mc_shower_altitude():
"""
Returns
-------
shower altitude [rad]
"""
return lib.get_mc_shower_altitude()
def get_adc_known(telescope_id, channel, pixel_id):
"""
Returns:
--------
individual channel recorded information ?
Bit 0: sum, 1: samples, 2: ADC was in saturation.
Parameters
----------
telescope_id: int
channel: int, HI_GAIN, LOW_GAIN
pixel_id, int
"""
return lib.get_adc_known(telescope_id, channel, pixel_id)
def get_ref_shape(telescope_id, channel, fshape):
"""
Returns:
--------
Reference pulse shape(s)
If telescope_id, channel or fshape are not valid return 0.
Parameters
----------
telescope_id: int
channel: int, HI_GAIN, LOW_GAIN
fshape, int
"""
return lib.get_ref_shape(telescope_id, channel, fshape)
def get_ref_shapes(telescope_id,channel):
"""
Returns:
--------
Array of Reference pulse shape(s).
0 if channel is not valid
TEL_INDEX_NOT_VALID if telescope index is not valid
Parameters
----------
telescope_id: int
channel: int, HI_GAIN, LOW_GAIN
"""
num_shapes= get_lrefshape(telescope_id)
if num_shapes>= 0:
array = np.zeros(num_shapes,dtype=np.double)
lib.get_ref_shapes(telescope_id, channel, array)
return array
else:
raise(HessioGeneralError("PixelTimming pulse shape(s) not available"))
def get_nrefshape(telescope_id):
"""
Returns:
--------
Number of following reference pulse shapes (num_gains or 0)
TEL_INDEX_NOT_VALID if telescope index is not valid
Parameters
----------
telescope_id: int
"""
return lib.get_nrefshape(telescope_id)
def get_lrefshape(telescope_id):
"""
Returns:
Length of following reference pulse shape(s).
TEL_INDEX_NOT_VALID if telescope index is not valid
--------
Parameters
----------
telescope_id: int
"""
return lib.get_lrefshape(telescope_id)
def get_ref_step(telescope_id):
"""
Returns:
--------
If telescope_id, channel or fshape are not valid return 0.
Parameters
----------
telescope_id: int
"""
return lib.get_ref_step(telescope_id)
def get_time_slice(telescope_id):
"""
Returns:
--------
Width of readout time slice (i.e. one sample) [ns].
If telescope_id is not valid return 0.
Parameters
----------
telescope_id: int
"""
return lib.get_time_slice(telescope_id)
def get_tel_event_gps_time(telescope_id):
"""
Returns:
--------
telescope event gps tine in a 2D array:
-seconds
-nonosecond
Parameters
----------
telescope_id: int
"""
seconds = np.zeros(1,dtype=np.long)
nanoseconds = np.zeros(1,dtype=np.long)
result = lib.get_tel_event_gps_time(telescope_id,seconds,nanoseconds)
if result == 0:
return seconds[0], nanoseconds[0]
else:
raise(HessioGeneralError("no event gps time for telescope "))
def get_central_event_gps_time():
"""
Returns:
--------
telescope central envent gps tine in a 2D array:
-seconds
-nonosecond
"""
seconds = np.zeros(1,dtype=np.long)
nanoseconds = np.zeros(1,dtype=np.long)
result = lib.get_central_event_gps_time(seconds,nanoseconds)
if result == 0:
return seconds[0], nanoseconds[0]
else:
raise(HessioGeneralError("no central event gps time"))
def get_central_event_teltrg_list():
"""
Returns
-------
List of IDs of triggered telescopes
Raises
------
HessioGeneralError if information is not available
"""
num_teltrig= lib.get_num_tel_trig()
if num_teltrig >= 0:
array = np.zeros(num_teltrig,dtype=np.int32)
lib.get_central_event_teltrg_list(array)
return array
else:
raise(HessioGeneralError("hsdata is not available"))
def get_mirror_number(telescope_id):
"""
Returns
-------
total number of mirror tiles of a telescope
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
if hsdata->camera_set[itel].num_mirrors not available
HessioTelescopeIndexError
if no telescope exist with this id
"""
result = lib.get_mirror_number(telescope_id)
if result >= 0 : return result
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("hsdata->camera_set[itel].num_mirrors not available"))
def get_optical_foclen(telescope_id):
"""
Returns
-------
focal length ofoptics of a telescope [m]
Parameters
----------
telescope_id: int
Raises
------
HessioGeneralError
if hsdata->camera_set[itel].flen not available
HessioTelescopeIndexError
if no telescope exist with this id
"""
result = lib.get_optical_foclen(telescope_id)
if result >=0 : return result
elif result == TEL_INDEX_NOT_VALID:
raise(HessioTelescopeIndexError("no telescope wth id " + str(telescope_id)))
else:
raise(HessioGeneralError("hsdata->camera_set[itel].flen not available"))
def get_telescope_ids():
"""
Returns
-------
list of IDs of telescopes used in the run
Raises
------
HessioGeneralError
if information is not available
"""
num_tel = get_num_telescope()
if num_tel >=0:
array = np.zeros(num_tel,dtype=np.int32)
lib.get_telescope_ids(array)
return array
else:
raise(HessioGeneralError("hsdata->run_header.tel_id is not available"))