コード例 #1
0
def plot_wave(filename, asic, channel):

    c = ROOT.TCanvas()
    graph = ROOT.TGraph()

    Vped = 900
    Vped = (0.021 + 0.0006 * Vped) * 1000

    NSamples = 14 * 32
    sample0 = 0
    chann = channel + asic * 16
    print(chann)
    reader = target_io.EventFileReader(filename)
    NEvents = reader.GetNEvents()
    useEvents = NEvents
    print("found %d events, using %d events" % (NEvents, useEvents))
    ampl = np.zeros([NEvents, NSamples])

    # Directory of transfer functions
    tf_filename = '/Users/az/CTA/work/PMT_SiPM_Ibaraki/data/transfer_fun/TF/tf_chan%d.mat' % chann
    mat_tf = scipy.io.loadmat(tf_filename)

    for ievt in range(0, useEvents):
        rawdata = reader.GetEventPacket(ievt, chann)
        packet = target_driver.DataPacket()
        packet.Assign(rawdata, reader.GetPacketSize())

        wf = packet.GetWaveform(0)

        for sample in range(0, NSamples):
            ampl[ievt, sample] = mat_tf.get('invertedTFs')[sample,
                                                           wf.GetADC(sample0 +
                                                                     sample)]
            V = ampl[ievt, sample]

            graph.SetPoint(sample, sample, V)

        graph.SetTitle("")
        graph.SetMarkerStyle(20)
        graph.SetMarkerSize(0.3)
        graph.GetXaxis().SetTitle("cell number")
        graph.GetYaxis().SetTitle("Voltage (mV)")

        graph.GetXaxis().SetLimits(0, NSamples)

        graph.Draw("apl")

        graph.GetHistogram().GetXaxis().SetNdivisions(400 + 14, 0)
        graph.GetYaxis().SetRangeUser(860, 930)

        c.SetGridx()
        c.SetGridy()

        c.Print("test2.pdf")

        input('input')
コード例 #2
0
 def _set_data_packet_parameters(self):
     """ assigns data packet characteristics """
     self.reader = target_io.EventFileReader(self.filename)
     self.n_events = self.reader.GetNEvents()
     rawdata = self.reader.GetEventPacket(0, 0)
     self.packet = target_driver.DataPacket()
     self.packet_size = self.reader.GetPacketSize()
     self.packet.Assign(rawdata, self.packet_size)
     wf = self.packet.GetWaveform(0)
     self.n_samples = wf.GetSamples()
     self.waveform = np.arange(self.n_samples, dtype=int)
     self._set_channels_per_packet()
コード例 #3
0
def maketf(channel, cell):
    tf = np.zeros(int(dac_counts / step))  # prepare an array for TF

    for i in tqdm(range(int(dac_counts / step)),
                  desc="DAC counts / step",
                  leave=False):
        counts = i * step  #current DAC value
        vped = 19.2 + 0.6 * counts  #pedestal voltage
        filename = '/Volumes/Untitled/kuroda/2020target/run/202003run_Delay352/TF_acq_%d.fits' % counts  #input file name

        reader = target_io.EventFileReader(filename)
        NEvents = reader.GetNEvents()

        ampl = np.zeros([NEvents,
                         Nsamples])  #array for ADC values in cells (waveform)

        for ievt in range(NEvents):
            rawdata = reader.GetEventPacket(ievt, channel)
            packet = target_driver.DataPacket()
            packet.Assign(rawdata, reader.GetPacketSize())

            wf = packet.GetWaveform(0)
            ampl[ievt] = wf.GetADC(
                sample0 + cell)  #fill the array with ADC and make a waveform
        ampl[ampl == 0] = np.nan  #convert zeros to NaN
        sigma = np.nanstd(
            ampl[:, cell])  #calculate noise std in every cell (capacitor)
        if sigma > 2.:
            tf[i] = np.nanmean(ampl[int(round(NEvents *
                                              0.2)):int(round(NEvents * 0.8)),
                                    cell])  #check for consistency
            sigma = np.nanstd(ampl[int(round(NEvents *
                                             0.2)):int(round(NEvents * 0.8)),
                                   cell])
            if sigma > 10.:
                print(
                    "std dev is still large: %f for counts: %d and voltage %f"
                    % (sigma, counts, 19.2 + 0.6 * counts))
        else:
            tf[i] = np.nanmean(ampl[:, cell])

    return tf
コード例 #4
0
ファイル: cern_extract.py プロジェクト: zdhughes5/cern
def extractADCS(filename_raw, filename_cal, nBlocks):

    nChannels = 16
    channels = list(range(16))
    nSamples = nBlocks * 32
    SCALE = 13.6
    OFFSET = 700

    reader_raw = target_io.EventFileReader(filename_raw)
    reader_cal = target_io.EventFileReader(filename_cal)
    nEvents = reader_cal.GetNEvents()

    print(nEvents, "events read")
    timestamp = 0

    ampl_raw = np.zeros([nEvents, nChannels, nSamples])
    ampl_cal = np.zeros([nEvents, nChannels, nSamples])
    ampl_cmc = np.zeros([nEvents, nChannels, nSamples])

    for this_event in range(1, nEvents):

        for this_channel in channels:

            if (this_event % 1000 == 0):
                print("Event {} of {} of channel {}".format(
                    this_event, nEvents, this_channel))

            event_header = target_driver.EventHeader()
            rv = reader_cal.GetEventHeader(this_event, event_header)

            #get timestamp in ns from event header
            timestamp = event_header.GetTACK()

            #print("Event ",ievt, " Timestamp in ns",timestamp, " Time since last Event in us ",(timestamp-timestamp_prev)/1000.)
            #first get the right packet from event, if only one channel/packet, then packetnumber = channel

            rawdata_raw = reader_raw.GetEventPacket(this_event, this_channel)
            rawdata_cal = reader_cal.GetEventPacket(this_event, this_channel)
            packet_raw = target_driver.DataPacket()
            packet_cal = target_driver.DataPacket()
            packet_raw.Assign(rawdata_raw, reader_raw.GetPacketSize())
            packet_cal.Assign(rawdata_cal, reader_cal.GetPacketSize())

            #get the waveform, if only one channel/packet, only one waveform!
            wf_raw = packet_raw.GetWaveform(this_channel)
            wf_cal = packet_cal.GetWaveform(this_channel)

            raw_adc = np.zeros(nSamples, dtype=np.float)
            cal_adc = np.zeros(nSamples, dtype=np.float)
            raw_adc = wf_raw.GetADC16bitArray(nSamples)
            cal_adc = wf_cal.GetADC16bitArray(nSamples)

            ampl_raw[this_event, this_channel, :] = raw_adc[:]
            ampl_cal[this_event,
                     this_channel, :] = (cal_adc[:] / SCALE) - OFFSET

            #common mode correction
            for this_notChannel in [x for x in channels if x != this_channel]:

                wf_cmc = packet_cal.GetWaveform(this_notChannel)
                #dircetly access the full array (faster)
                adc = np.zeros(nSamples, dtype=np.float)
                adc = wf_cmc.GetADC16bitArray(nSamples)
                ampl_cmc[this_event, this_channel, :] = ampl_cmc[
                    this_event, this_channel, :] + ((
                        (adc / SCALE) - OFFSET) * 1 / 10)

    return (ampl_raw, ampl_cal, ampl_cmc)
コード例 #5
0
import target_io as ti
import target_driver
import numpy as np
import pandas as pd

path = "/Volumes/gct-jason/astri_onsky_archive/d2019-05-01_mrk501/Run12817_r0.tio"

reader = ti.EventFileReader(path)
packet_size = reader.GetPacketSize()
n_packets_per_event = reader.GetNPacketsPerEvent()
packet = target_driver.DataPacket()
wf = target_driver.Waveform()

d_list = []
iev = 10892
for ipack in range(n_packets_per_event):
    event_packet = reader.GetEventPacket(iev, ipack)
    packet.Assign(event_packet, packet_size)
    module = packet.GetSlotID()
    first_cell_id = packet.GetFirstCellId()
    stale = packet.GetStaleBit()
    tack = packet.GetTACKTime()
    n_waveforms = packet.GetNumberOfWaveforms()

    print(ipack, n_waveforms, packet.IsEmpty(), packet.IsFilled(), packet.IsValid())

    for iwav in range(n_waveforms):
        packet.AssociateWaveform(iwav, wf)
        asic = wf.GetASIC()
        channel = wf.GetChannel()
コード例 #6
0
    def makehist(self):
        # dv and dt
        dV = 1.454170273973432 * 1e-6
        dT = 1 * ns
        bin_width = dV * dT / mV / ns * 750

        self.hNoise = ROOT.TH1D("noise","noise;Charge (mV #times ns);", 1000, -299.5 * bin_width, 700.5 * bin_width)
        self.hSignal = ROOT.TH1D("signal","signal;Charge (mV #times ns);", 1000, -299.5 * bin_width, 700.5 * bin_width)
        print('\nanalyzing a%d ch%d'%(self.asic,self.channel))

        # Time window for integration. integral +/- 6 ns around the peak
        tw = 12 # change
        NSamples = 14 * 32
        sample0 = 0
        chann = self.channel + self.asic*16

        reader = target_io.EventFileReader(self.filename)
        NEvents  = reader.GetNEvents()
        useEvents = NEvents
        print("found %d events, using %d events"%(NEvents, useEvents))
        ampl = np.zeros([NEvents,NSamples])

        # Directory of transfer functions
        #tf_filename = '/Users/az/CTA/work/PMT_SiPM_Nagoya/target/TF/new_run/mat/tf_chan%d.mat' % chann
        tf_filename = '/Volumes/Untitled/kuroda/2020target/transfer_fun/TF/mat/tf_chan%d.mat' % chann
        mat_tf = scipy.io.loadmat(tf_filename)

        for i_event in tqdm(range(useEvents)):
            rawdata = reader.GetEventPacket(i_event,chann)
            packet = target_driver.DataPacket()
            packet.Assign(rawdata, reader.GetPacketSize())
            wf = packet.GetWaveform(0)

            for sample in range(NSamples):
                ampl[i_event, sample] = mat_tf.get('TFs')[sample, wf.GetADC(sample0+sample)]

        # Fill noise
        for i_event in tqdm(range(0, useEvents)):
            t_peak = 190 # change
            charge = 0.
            mean = np.mean(ampl[i_event, t_peak - 50 : t_peak])
            stdev = np.std(ampl[i_event, t_peak - 50 : t_peak])
            if (np.amax(ampl[i_event, t_peak - 50 : t_peak]) - np.amin(ampl[i_event, t_peak - 50 : t_peak]) > 10):
                continue
      
            for cell in range(t_peak, t_peak + 2 * tw):
                if ampl[i_event, cell] >= mean - 2 * stdev:
                    charge += ampl[i_event, cell]
                else:
                    charge += mean
            charge -= mean * tw * 2
            self.hNoise.Fill(charge)

            # Fill signal
        for i_event in tqdm(range(0, useEvents)):
            t_peak = 297 # change
            charge = 0.
            mean = np.mean(ampl[i_event, t_peak - 50 : t_peak])
            stdev = np.std(ampl[i_event, t_peak - 50 : t_peak])
            if (np.amax(ampl[i_event, t_peak - 50 : t_peak]) - np.amin(ampl[i_event, t_peak - 50 : t_peak]) > 10):
                continue

            for cell in range(t_peak, t_peak + 2 * tw):
                if ampl[i_event, cell] >= mean - 2 * stdev:
                    charge += ampl[i_event, cell]
                else:
                    charge += mean
            charge -= mean * tw * 2
            self.hSignal.Fill(charge)



        # Output
        dirname = 'hists'
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        dirname = '%s/%s' % (dirname, self.filename[:-5])
        if not os.path.exists(dirname):
            try:
                os.mkdir(dirname)
            except:
                print('Failed to mkdir. Already exists?')
        hfile = ROOT.TFile("%s/hist_as%d_ch%d.root" %(dirname, self.asic, self.channel), "recreate")
        self.hNoise.Write()
        self.hSignal.Write()
        hfile.Close()
        return
コード例 #7
0
    def makehist(self):
        # dv and dt
        dV = 1.454170273973432 * 1e-6
        dT = 1 * ns
        bin_width = dV * dT / mV / ns * 750

        # Time window for integration. integral +/- 6 ns around the peak
        tw = 12
        NSamples = 14*32
        sample0=0
        chann = self.channel + self.asic*16
    ##    print(chann)
        reader = target_io.EventFileReader(self.filename)
        NEvents  = reader.GetNEvents()
        useEvents = NEvents
        #print("found %d events, using %d events"%(NEvents, useEvents))
        ampl = np.zeros([NEvents,NSamples])

        self.g_waveform = []
        self.hpeaktime = ROOT.TH1D("peaktime%s %d %d" % (self.filename, self.asic, self.channel),"peaktime;time (ns);", NSamples + 1 , -0.5, NSamples + 0.5)
        self.hNoise = ROOT.TH1D("noise%s %d %d" % (self.filename, self.asic, self.channel),"noise;Charge (mV #times ns);", 1000, -299.5 * bin_width, 700.5 * bin_width)
        self.hSignal = ROOT.TH1D("signal%s %d %d" % (self.filename, self.asic, self.channel),"signal;Charge (mV #times ns);", 1000, -299.5 * bin_width, 700.5 * bin_width)

        # Directory of transfer functions #############################################################################
        tf_filename = '/Volumes/Untitled/kuroda/2020target/transfer_fun/TF/mat/tf_chan%d.mat' % chann  ########### tf file のディレクトリを指定する
        mat_tf = scipy.io.loadmat(tf_filename)

        for ievt in tqdm(range(0, useEvents), leave = False, desc = "Events"):
            rawdata = reader.GetEventPacket(ievt,chann)
            packet = target_driver.DataPacket()
            packet.Assign(rawdata, reader.GetPacketSize())
            wf = packet.GetWaveform(0)

            for sample in range(0, NSamples):
                ampl[ievt,sample] = mat_tf.get('TFs')[sample, wf.GetADC(sample0+sample)]

            # Fill noise

        count_wave = 0
        for ievt in tqdm(range(0, useEvents), leave = False, desc = "Events"):
            max_bin = np.argmax(ampl[ievt])
            self.hpeaktime.Fill(max_bin)
            ################################# 生波形の抽出 #################################################################
            #if 360 > max_bin > 280 and count_wave < 50 :  ###################### ここで、描画する生波形を取得するための条件を指定する
            self.g_waveform.append( ROOT.TGraph(NSamples,np.arange(NSamples)*1.0, ampl[ievt]) )
            count_wave += 1


        for ievt in tqdm(range(0, useEvents), leave = False, desc = "Events"):
            t_peak = 190
            charge = 0.
            mean = np.mean(ampl[ievt, t_peak - 50 : t_peak])
            stdev = np.std(ampl[ievt, t_peak - 50 : t_peak])
            if (np.amax(ampl[ievt, t_peak - 50 : t_peak]) - np.amin(ampl[ievt, t_peak - 50 : t_peak]) > 10):
                continue
            # charge = np.sum(ampl[ievt, t_peak : t_peak + 2 * tw]) - mean * tw * 2
            for cell in range(t_peak, t_peak + 2 * tw):
                if ampl[ievt, cell] >= mean - 2 * stdev:
                    charge += ampl[ievt, cell]
                else:
                    charge += mean
            charge -= mean * tw * 2
            self.hNoise.Fill(charge)

            # Fill signal
        for ievt in tqdm(range(0, useEvents), leave = False, desc = "Events"):
            t_peak = 297
            charge = 0.
            mean = np.mean(ampl[ievt, t_peak - 50 : t_peak])
            stdev = np.std(ampl[ievt, t_peak - 50 : t_peak])
            if (np.amax(ampl[ievt, t_peak - 50 : t_peak]) - np.amin(ampl[ievt, t_peak - 50 : t_peak]) > 10):
                continue
            # charge = np.sum(ampl[ievt, t_peak : t_peak + 2 * tw]) - mean * tw * 2
            for cell in range(t_peak, t_peak + 2 * tw):
                if ampl[ievt, cell] >= mean - 2 * stdev:
                    charge += ampl[ievt, cell]
                else:
                    charge += mean
            charge -= mean * tw * 2
            self.hSignal.Fill(charge)



        # Output
        dirname = 'hists'
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        dirname = '%s/%s' % (dirname, self.filename[:-5])
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        hfile = ROOT.TFile("%s/hist_as%d_ch%d.root" %(dirname, self.asic, self.channel), "recreate")
        self.hNoise.Write()
        self.hSignal.Write()
        hfile.Close()
        return