Exemple #1
0
def characterize(signal, start, stop):
    '''
    Characterize the peak in the signal bracketed by [start,stop).
    Return characterization as a PeakedPulse.
    '''
    base = stop-start
    peak = signal[start:stop]
    sumq = sum(peak)
    height = max(peak)
    loc = peak.index(height)

    h = histutil.sig2hist(peak)
    fit = histutil.fit_gaus(h)
    del(h)

    return PeakedPulse(start, loc, base, height, sumq, *fit)
Exemple #2
0
    def set_channel(self, chn, sig):
        minq = min(sig)
        iminq = int(minq+0.5)
        self.obj.qmin[chn] = iminq
        self.obj.tmin[chn] = minbin = sig.index(minq)

        maxq = max(sig)
        imaxq = int(maxq+0.5)
        self.obj.qmax[chn] = imaxq
        self.obj.tmax[chn] = maxinb = sig.index(maxq)


        low,high = 50,150
        start = max(0, minbin - low)
        stop = min(len(sig), minbin + high)
        windowed = sig[:start] + sig[stop:]
        iminq = int(min(windowed)+0.5)

        pwr = ROOT.TH1F('pwr','power', imaxq-iminq+2,iminq-1,imaxq+1)
        map(pwr.Fill, windowed)

        self.obj.avg[chn] = pwr.GetMean()
        self.obj.rms[chn] = pwr.GetRMS()

        # guess-fit the pedestal
        fit = histutil.fit_gaus(pwr)
        const, mean, sigma = fit
        self.obj.const[chn] = const
        self.obj.mean[chn] = mean
        self.obj.sigma[chn] = sigma

        # simple, fixed window around peak
        winlow, winhigh = 10,40
        winstart = max(0, minbin - winlow)
        winstop = min(len(sig), minbin + winhigh)
        winsig = sig[winstart:winstop]
        self.obj.qwin[chn] = mean * len(winsig) - sum(winsig)

        #if not chn:
        #    print 'Fit:',mean, sigma, const

        for c in sig[start:stop]:
            if c > mean - 3*sigma:
                continue
            self.obj.n3[chn] += 1
            self.obj.sum3[chn] += c
            if c > mean - 4*sigma:
                continue
            self.obj.n4[chn] += 1
            self.obj.sum4[chn] += c
            if c > mean - 5*sigma:
                continue
            self.obj.n5[chn] += 1
            self.obj.sum5[chn] += c
            continue

        # make a positive-going signal w.r.t. fit "pedestal"
        pulse = [mean - s for s in sig] 
        ps = peaks.downhills(pulse, 0.0, 3*sigma)
        
        npeaks = len(ps)
        self.obj.qnpeaks[chn] = npeaks

        if not npeaks:
            return

        # Characterize the dominant peak and transfer the returned
        # PulsedPeak values to the tree.  What a coincidence the two
        # are named so similarly....
        if npeaks == 1:
            pp = peaks.characterize(pulse, *ps[0])
            for field_name in pp._fields:
                val = self.obj.__dict__['dp%s'%field_name]
                val[chn] = pp.__dict__[field_name]

        saved_peaks = []
        for count, (l,r) in enumerate(ps):
            peak = pulse[l:r]
            totq = sum(peak)
            if not count:
                self.obj.qpeak[chn] = totq
                self.obj.qwid[chn] = len(peak)
                saved_peaks.append({'t':l, 'q':peak, 'c':chn})

            maxq = max(pulse[l:r])
            if maxq < 3*sigma:
                continue        # shouldn't happen
            self.obj.qpeaks3[chn] += totq
            if maxq < 4*sigma:
                continue
            self.obj.qpeaks4[chn] += totq
            if maxq < 5*sigma:
                continue
            self.obj.qpeaks5[chn] += totq
            continue
        if self.save_peaks:
            self.saved_peaks.append(saved_peaks)

        return