示例#1
0
    def AddBadDOMLists(frame, listHLC, listSLC):
        if "BadDomsList" in frame:
            dynamicList = set(frame["BadDomsList"])

            identicalHLC = isOldListSubsetOfNewList(dynamicList, set(listHLC))
            if not identicalHLC:
                print(
                    "*** REPLACING EXISTING BAD DOM LIST in D-frame (HLC)! ***"
                )
                del frame["BadDomsList"]
                newList = set(listHLC).union(dynamicList)
                print("  -> new DOM entries in updated list are:",
                      newList.difference(dynamicList))
                frame["BadDomsList"] = dataclasses.I3VectorOMKey(newList)
        else:
            frame["BadDomsList"] = dataclasses.I3VectorOMKey(listHLC)

        if "BadDomsListSLC" in frame:
            dynamicList = set(frame["BadDomsListSLC"])

            identicalSLC = isOldListSubsetOfNewList(dynamicList, set(listSLC))
            if not identicalSLC:
                print(
                    "*** REPLACING EXISTING BAD DOM LIST in D-frame (SLC)! ***"
                )
                del frame["BadDomsListSLC"]

                newList = set(listSLC).union(dynamicList)
                print("  -> new DOM entries in updated list are:",
                      newList.difference(dynamicList))
                frame["BadDomsListSLC"] = dataclasses.I3VectorOMKey(newList)
        else:
            frame["BadDomsListSLC"] = dataclasses.I3VectorOMKey(listSLC)
    def DetectorStatus(self, frame):
        """
        Adds a list of bad iceTop doms to the D frame.

        The source is usually the already created BadDomsList (see BadDomListModule).
        It just filters the IceTop doms out and stores them in this list.

        Args:
            frame (icecube.icetray.I3Frame): The detector status frame
        """

        if not frame.Has(self.input_list):
            icetray.logging.log_warn(
                '{0} not in frame. Not generating {1}.'.format(
                    self.input_list, self.output_list))
            self.PushFrame(frame)
            return

        bd_all = frame[self.input_list]
        bd_it = dataclasses.I3VectorOMKey()

        for key in bd_all:
            if is_ice_top(key):
                bd_it.append(key)

        frame.Put(self.output_list, bd_it)
        self.PushFrame(frame)
 def find_specials(frame, Output):
     if "SpecialHits" in frame:
         specials = frame["SpecialHits"]
         spec_oms = dataclasses.I3VectorOMKey()
         for omk in specials.keys():
             spec_oms.append(omk)
         frame[Output] = spec_oms
示例#4
0
    def convertToVectorOMKey(frame, inputName, outputName):
        if inputName not in frame: return

        keys = []
        origErrata = frame[inputName]
        for key, window in origErrata:
            keys.append(key)
        newObject = dataclasses.I3VectorOMKey(keys)
        frame[outputName] = newObject
    def DetectorStatus(self, frame):
        """
        Adds the bad dom list with name `self.listName` to the D frame.
        Which sources are used for the list is specified by the options (see method `Configure` or `__init__`).

        Args:
            frame (icecube.icetray.I3Frame): The detector status frame
        """

        # Make frame accessible for all methods
        self.frame = frame

        badDomList = []

        # Add requested sources
        if self.temporaryBadDomsOnly:
            badDomList = badDomList + self._GetTemporarilyBadDoms()
        elif self.disabledKeysOnly:
            badDomList = badDomList + self._GetUnconfiguredDoms()
        else:
            badDomList = badDomList + self._GetUnconfiguredDoms() \
                                    + self._GetNoHVDoms() \
                                    + self._GetDroppedDoms() \
                                    + self._GetTemporarilyBadDoms()

        # Add good good SLC keys ("dark noise")
        if self.addGoodSlcOnlyKeys:
            badDomList = badDomList + self._GetDarkNoiseModeDoms()

        # Custom keys are always added
        badDomList = badDomList + self.customKeys

        # Sort the list and remove duplicates
        badDomList = set(sorted(badDomList))

        # Convert list
        i3bdl = dataclasses.I3VectorOMKey()
        for om in badDomList:
            i3bdl.append(om)

        # Write list to frame
        frame[self.listName] = i3bdl

        self.PushFrame(frame)
示例#6
0
def flag_borked_slc(frame):
    # Find SLC launches affected by DOMsimulator off-by-one bug,
    # and tell Millipede to ignore them
    bad_keys = set()
    import numpy
    for om, dls in frame['InIceRawData'].iteritems():
        for dl in dls:
            if dl.lc_bit == False and dl.charge_stamp_highest_sample == 0:
                print '%s, she is the bad!' % om
                bad_keys.add(om)
    if len(bad_keys) > 0:
        frame['BorkedSLC'] = dataclasses.I3VectorOMKey(bad_keys)
        frame[
            'OfflinePulses_NoBorkedSLC'] = dataclasses.I3RecoPulseSeriesMapMask(
                frame, 'OfflinePulses',
                lambda om, idx, pulse: om not in bad_keys)
    else:
        frame[
            'OfflinePulses_NoBorkedSLC'] = dataclasses.I3RecoPulseSeriesMapMask(
                frame, 'OfflinePulses')
 def Detector(self, frame):
     frame['IceTopBadDOMs'] = dataclasses.I3VectorOMKey()
     frame['IceTopBadTanks'] = dataclasses.TankKey.I3VectorTankKey()
     self.PushFrame(frame)
示例#8
0
 def createEmptyDOMLists(frame, ListNames=[]):
     for name in ListNames:
         if name in frame: continue
         frame[name] = dataclasses.I3VectorOMKey()
示例#9
0
newI3Calibration = dataclasses.I3Calibration()
newI3DetectorStatus = dataclasses.I3DetectorStatus()
newSPEScalingFactors = dataclasses.I3MapKeyDouble()
newSPEAbove = dataclasses.I3MapKeyDouble()
newI3Calibration.dom_cal = dataclasses.Map_OMKey_I3DOMCalibration()
newI3DetectorStatus.dom_status = dataclasses.Map_OMKey_I3DOMStatus()

newI3Calibration.dom_cal[dummyOMKey] = newDOMCalib
newI3Calibration.start_time = start_time
newI3Calibration.end_time = end_time
newI3Calibration.vem_cal = dataclasses.I3VEMCalibrationMap()

newI3DetectorStatus.daq_configuration_name = "P-ONE_Estimate"
newI3DetectorStatus.dom_status[dummyOMKey] = newDOMStatus
newI3DetectorStatus.start_time = start_time
newI3DetectorStatus.end_time = end_time
newI3DetectorStatus.trigger_status = trigger_status

newSPEAbove[dummyOMKey] = newAbove
newSPEScalingFactors[dummyOMKey] = newScalingFactor

frame = icetray.I3Frame(icetray.I3Frame.DetectorStatus)
frame["I3Calibration"] = newI3Calibration
frame["I3DetectorStatus"] = newI3DetectorStatus
frame["SPEAbove"] = newSPEAbove
frame["SPEScalingFactors"] = newSPEScalingFactors
frame["BadDomsList"] = dataclasses.I3VectorOMKey()
frame["BadDomsListSLC"] = dataclasses.I3VectorOMKey()

outfile.push(frame)
outfile.close()
示例#10
0
    def WaveformDerivatives(frame):
        frame["DoublePulseWaveforms"] = dataclasses.I3WaveformSeriesMap()
        frame["BinsToT1"] = dataclasses.I3VectorDouble(
        )  # bins with time over threshold (ToT) for the first pulse of a derivative waveform
        frame["BinsToT2"] = dataclasses.I3VectorDouble(
        )  # bins with time over threshold (ToT) for the second pulse of a derivative waveform
        frame["BinsTbT"] = dataclasses.I3VectorDouble(
        )  # bins with time below threshold (TbT) for the first trailing edge of a derivative waveform
        frame["Amp1"] = dataclasses.I3VectorDouble(
        )  # cumulative derivative amplitude of time over threshold (ToT) for the first pulse
        frame["Amp2"] = dataclasses.I3VectorDouble(
        )  # cumulative derivative amplitude of time over threshold (ToT) for the second pulse
        frame["AmpTrailing"] = dataclasses.I3VectorDouble(
        )  # cumulative derivative amplitude of time below threshold (ToT) for the trailing edge
        frame["DPWaveformQTot"] = dataclasses.I3VectorDouble()
        frame["DP_T1"] = dataclasses.I3VectorDouble()
        frame["DP_T2"] = dataclasses.I3VectorDouble()
        frame["DPWaveformPulse1Amp"] = dataclasses.I3VectorDouble()
        frame["DPWaveformPulse2Amp"] = dataclasses.I3VectorDouble()
        frame["DP_OMs"] = dataclasses.I3VectorOMKey()

        SDtag = False
        LCtag = False

        if frame.Has("CalibratedWaveformsHLCATWD"):

            wf_map = frame["CalibratedWaveformsHLCATWD"]
            dp_count = 0  #count number of dp waveforms from this event
            dp_om_keys = []
            for om, wf_series in wf_map:
                for wf in wf_series:
                    wf_vect = wf.waveform

                    wf_status = wf.status
                    wf_binwidth = wf.bin_width
                    start_time = wf.time
                    if wf_status == 0:
                        wf_qtot = 0.0
                        for i in range(128):
                            wf_vect[i] = wf_vect[
                                i] / I3Units.mV  #transform wf unit to mV
                            wf_qtot += wf_vect[
                                i]  #individual wf integrated charge in mV
                        #Calculate Sliding Time Window (STW) derivatives for waveforms
                        stw_vect = []
                        stepsize = 2
                        for i in range(1, 127):
                            stw_vect += [(wf_vect[i + 1] - wf_vect[i - 1]) /
                                         (wf_binwidth * stepsize)]
                        der_wf_bins = len(stw_vect)

                        der_flag = 0
                        for i in range(1, der_wf_bins - 6):
                            # 3, 4, 5, 6 bins tried. With 6 bins required, all the manually-selected nice double pulse waveforms picked up by the algorithm.
                            if (stw_vect[i - 1] > 0 and stw_vect[i] > 0
                                    and stw_vect[i + 1] > 0
                                    and stw_vect[i + 2] > 0
                                    and stw_vect[i + 3] > 0
                                    and stw_vect[i + 4] > 0):
                                der_flag = i - 1
                                #Finding point where waveform first sees light.
                                break
                        #sum up the amplitude of the rising edge
                        amp_rising = 0.
                        for i1 in range(der_flag, der_flag + 6):
                            amp_rising += stw_vect[i1]

                        wf_diff = []
                        for i in range(der_flag, 128 - der_step, der_step):
                            wf_diff += [(wf_vect[i + der_step] - wf_vect[i]) /
                                        (wf_binwidth * der_step)]
                        diff_wf_bins = len(wf_diff)

                        #search for the first and second pulses!
                        pulse1 = False
                        pulse2 = False
                        trailing = False
                        i_flag = 0
                        j_flag = 0
                        k_flag = 0
                        amp_p1 = 0  #amplitude of first rising edge in the derivative waveform
                        amp_p2 = 0  #amplitude of second rising edge in the derivative waveform
                        amp_trailing = 0  #amplitude of first trailing edge in the derivative waveform

                        binsToT1 = 0
                        binsToT2 = 0
                        binsTbT = 0
                        j1_flag = 0
                        j2_flag = 0
                        j3_flag = 0
                        bins_p21 = 0
                        bins_p22 = 0
                        dp_t1 = 0
                        dp_t2 = 0
                        dp_amp1 = 0  # amplitude of first pulse
                        dp_amp2 = 0  # amplitude of second pulse
                        #first pulse search
                        for i in range(diff_wf_bins - bins_p2 - bins_trailing):
                            #if wf_diff[i]>0: #and wf_diff[i+1]>0:
                            if np.prod([
                                    True if wf_diff[n] > 0.0 else False
                                    for n in range(i, i + bins_p1)
                            ]):
                                pulse1 = True
                                i_flag = i
                                break

                        #trailing edge search
                        if pulse1:
                            # firstly move the index out of the positive region
                            for k in range(i_flag + bins_p1,
                                           diff_wf_bins - bins_trailing):  #
                                if np.prod([
                                        True if wf_diff[n] < 0.0 else False
                                        for n in range(k, k + bins_trailing)
                                ]):
                                    k_flag = k
                                    trailing = True
                                    l_flag = k_flag + bins_trailing
                                    break
                                    dp_t1 = start_time + der_flag * 422.4 / 128  #beginning time of the first pulse

                        #second pulse search
                        if pulse1 and trailing:
                            for j in range(l_flag, (diff_wf_bins - bins_p2)):
                                if np.prod([
                                        True if wf_diff[n] > 0.0 else False
                                        for n in range(j, j + bins_p2)
                                ]):
                                    pulse2 = True
                                    j_flag = j
                                    break

                            for q in range(
                                    der_flag, der_flag + j_flag * der_step
                            ):  # transform the derivative waveform index back to the waveform vector basis
                                dp_amp1 += wf_vect[
                                    q]  #calculate amplitude of first pulse

                            #move the index out of the positive region, and do another round of big pulse search.
                            #If the later pulse is bigger than the earlier one, point the index to the bigger one.
                            #Having more than (including) two pulses with ToT of 3 derivetive waveform bins, which is
                            #duration of 3*4*3.3 ns, is quite rare. Therefore, another round of searching should be sufficient enough.
                            if j_flag and j_flag < (diff_wf_bins - bins_p2):
                                for j1 in range(j_flag,
                                                (diff_wf_bins - bins_p2)):
                                    if wf_diff[j1] < 0:
                                        j1_flag = j1
                                        break
                            if j1_flag and j1_flag < (diff_wf_bins - bins_p2):
                                for j2 in range(j1_flag,
                                                (diff_wf_bins - bins_p2)):
                                    if np.prod([
                                            True if wf_diff[n] > 0.0 else False
                                            for n in range(j2, j2 + bins_p2)
                                    ]):
                                        j2_flag = j2
                                        break
                                #move the index out of the positive region
                            if j2_flag and j2_flag < (diff_wf_bins - bins_p2):
                                j3_flag = 0
                                for g in range(j2_flag + bins_p2,
                                               diff_wf_bins):
                                    if wf_diff[g] < 0:
                                        j3_flag = g
                                        break
                                if j3_flag == 0:
                                    j3_flag = diff_wf_bins
                                bins_p21 = j1_flag - j_flag
                                bins_p22 = j3_flag - j2_flag
                                pulse3 = True
                                if bins_p22 > bins_p21:
                                    j_flag = j2_flag

                            dp_t2 = start_time + (
                                der_flag + j_flag * der_step
                            ) * 422.4 / 128  #starting time of second pulse
                            for q in range(
                                    der_flag + j_flag * der_step, 128
                            ):  # transform the derivative waveform index back to the waveform vector basis
                                dp_amp2 += wf_vect[
                                    q]  #calculate amplitude of second pulse

                        if pulse1 and trailing and pulse2:
                            # calculate the cumulative derivative amplitude for potential first pulse
                            for s in range(i_flag, k_flag):
                                amp_p1 += wf_diff[s]
                            binsToT1 = k_flag - i_flag

                            #move the index out of the first trailing edge region
                            r_flag = 0
                            for r in range(l_flag, (diff_wf_bins - bins_p2)):
                                if wf_diff[r] > 0:
                                    r_flag = r
                                    break
                            for q in range(k_flag, r_flag):
                                amp_trailing += wf_diff[q]
                            binsTbT = r_flag - k_flag

                            # move the index out of the second positive region
                            h_flag = 0
                            for h in range(j_flag + bins_p2, diff_wf_bins):
                                if wf_diff[h] < 0:
                                    h_flag = h
                                    break
                            if h_flag == 0:
                                h_flag = diff_wf_bins
                            # calculate the cumulative derivative amplitude for second pulse
                            for t in range(j_flag, h_flag):
                                amp_p2 += wf_diff[t]
                            binsToT2 = h_flag - j_flag

                        if wf_qtot > WfQtot and pulse1 and trailing and pulse2 and amp_p1 > Amp1LC and amp_p2 > Amp2LC and amp_trailing < AmpTrailingLC:  # if this waveform has double peak feature.
                            if amp_p1 > Amp1SD and amp_p2 > Amp2SD and amp_trailing < AmpTrailingSD and binsToT1 > 1:  #if this waveform passes single dom double peak:
                                SDtag = True

                            dp_count += 1
                            dp_om_keys.append(om)

                            frame["Amp1"].append(amp_p1)
                            frame["Amp2"].append(amp_p2)
                            frame["AmpTrailing"].append(amp_trailing)
                            frame["BinsToT1"].append(binsToT1)
                            frame["BinsTbT"].append(binsTbT)
                            frame["BinsToT2"].append(binsToT2)
                            frame["DPWaveformQTot"].append(wf_qtot)
                            frame["DP_OMs"].append(om)
                            frame["DoublePulseWaveforms"].update(
                                {om: wf_series})
                            frame["DPWaveformPulse1Amp"].append(dp_amp1)
                            frame["DPWaveformPulse2Amp"].append(dp_amp2)
                            frame["DP_T1"].append(dp_t1)
                            frame["DP_T2"].append(dp_t2)

                    #end if
                #end for
            #end for

        #Finding waveforms that have neighboring DOMs that also see double pulses. If they do, use a lower threshold.
            for i in dp_om_keys:
                for j in dp_om_keys:
                    if i[0] == j[0]:
                        if 0 < np.abs(np.int(j[1]) - np.int(i[1])) < 3:
                            LCtag = True
                            break
                if LCtag:
                    break

            frame["DPFlagSD"] = icetray.I3Int(SDtag)
            frame["DPFlagLC"] = icetray.I3Int(LCtag)

        else:
            return False

        #Keeping the double pulse events only
        if DiscardEvents:
            if LCtag or SDtag:
                return True
            return False
示例#11
0
 def createEmptyDOMLists(frame, ListNames=[]):
     print("Making list of DOMs")
     for name in ListNames:
         if name in frame: continue
         frame[name] = dataclasses.I3VectorOMKey()
示例#12
0
def createEmptyDOMLists(frame, ListNames=[]):
	# I like having frame objects in there even if they are empty for some frames
	for name in ListNames:
		if name in frame: continue
		frame[name] = dataclasses.I3VectorOMKey()