@@ -496,6 +496,32 @@ def _correct_tel_id(self, tel_id, run):
496496 cor_tel_id = tel_id
497497 return cor_tel_id
498498
499+ def _estimate_if_trig_pat_missing (self , pre_v6_data , evb_version ):
500+ # Runs before EVB v6.12 does not have the trigger part
501+ # of the pixel status bit pattern filled.
502+ # The information is in the debug field trigger_pattern
503+ # which comes from the feb.
504+ # This function tries to estimate if there is the need to fill
505+ # the relevant bit of the pixel_status
506+
507+ # Assume that tpat is in the pixel_status per default
508+ tpat_missing = False
509+
510+ if pre_v6_data :
511+ tpat_missing = True
512+ else :
513+ # idaq_version examples : 'v6.9.2-rc2' or 'v6.12.1'
514+ # starting from v6.12, we have the trigger pattern info in pixel_status
515+ if evb_version .startswith ("v6" ):
516+ split_version = re .split (r"\.|-" , evb_version )
517+ try :
518+ minor_version = int (split_version [1 ])
519+ if minor_version < 12 :
520+ tpat_missing = True
521+ except (IndexError , ValueError ):
522+ pass
523+ return tpat_missing
524+
499525 def __init__ (self , ** kwargs ):
500526 """
501527 Constructor of the NectarCAMEventSource class.
@@ -569,6 +595,10 @@ def __init__(self, **kwargs):
569595 self .tel_id , self .multi_file .camera_datastream , self ._pre_v6_data
570596 )
571597
598+ self ._missing_trig_pat = self ._estimate_if_trig_pat_missing (
599+ self ._pre_v6_data , self .nectarcam_service .idaq_version
600+ )
601+
572602 target_info = {}
573603
574604 # VIM : Put some pointing info to be filled as a reminder that it should be done
@@ -965,7 +995,9 @@ def fill_nectarcam_event_container_from_zfile(self, array_event, event):
965995
966996 if not self .pre_v6_data :
967997 event_container .first_cell_id = np .full (
968- (N_PIXELS ,), np .nan , dtype = event .first_cell_id .dtype
998+ (N_PIXELS ,),
999+ np .iinfo (event .first_cell_id .dtype ).max ,
1000+ dtype = event .first_cell_id .dtype ,
9691001 )
9701002 event_container .first_cell_id [
9711003 self .nectarcam_service .pixel_ids
@@ -975,6 +1007,18 @@ def fill_nectarcam_event_container_from_zfile(self, array_event, event):
9751007 if self .load_feb_info :
9761008 self .unpack_feb_data (event_container , event , nectarcam_data )
9771009
1010+ # Fill information of the trigger mask in the pixel_status if needed
1011+ # Note that FEB data must have been loaded
1012+ if self ._missing_trig_pat :
1013+ tpat = np .any (event_container .trigger_pattern , axis = 0 )
1014+
1015+ event_container .pixel_status = (
1016+ event_container .pixel_status & 0x1F
1017+ ) # Reset the trigger part
1018+ event_container .pixel_status [tpat ] = (
1019+ event_container .pixel_status [tpat ] | PixelStatus .PIXEL_TRIGGER_1
1020+ )
1021+
9781022 def fill_trigger_info (self , array_event ):
9791023 tel_id = self .tel_id
9801024
@@ -1095,9 +1139,7 @@ def unpack_feb_data(self, event_container, event, nectarcam_data):
10951139 3 ::n_fields
10961140 ]
10971141 # Unpack TS2 counters
1098- ts2_decimal = (
1099- lambda bits : bits - (1 << 8 ) if bits & 0x80 != 0 else bits
1100- ) # noqa: E731
1142+ ts2_decimal = lambda bits : (bits - (1 << 8 ) if bits & 0x80 != 0 else bits )
11011143 ts2_decimal_vec = np .vectorize (ts2_decimal )
11021144 event_container .feb_ts2_trig [
11031145 self .nectarcam_service .module_ids
@@ -1224,12 +1266,20 @@ def fill_r0r1_camera_container(self, zfits_event):
12241266 if not self .pre_v6_data :
12251267 if r0 .waveform is not None :
12261268 r0 .waveform = (
1227- r0 .waveform - self .nectarcam_datastream .waveform_offset
1228- ) / self .nectarcam_datastream .waveform_scale
1269+ r0 .waveform / self .nectarcam_datastream .waveform_scale
1270+ - self .nectarcam_datastream .waveform_offset
1271+ )
1272+ # r0.waveform = (
1273+ # r0.waveform - self.nectarcam_datastream.waveform_offset
1274+ # ) / self.nectarcam_datastream.waveform_scale
12291275 if r1 .waveform is not None :
12301276 r1 .waveform = (
1231- r1 .waveform - self .nectarcam_datastream .waveform_offset
1232- ) / self .nectarcam_datastream .waveform_scale
1277+ r1 .waveform / self .nectarcam_datastream .waveform_scale
1278+ - self .nectarcam_datastream .waveform_offset
1279+ )
1280+ # r1.waveform = (
1281+ # r1.waveform - self.nectarcam_datastream.waveform_offset
1282+ # ) / self.nectarcam_datastream.waveform_scale
12331283
12341284 return r0 , r1
12351285
0 commit comments