Exemplo n.º 1
0
def detsim(files_in, file_out, compression, event_range, detector_db,
           run_number, krmap_filename, psfsipm_filename):

    npmt, nsipm = dsim.npmts, dsim.nsipms
    pmt_wid, sipm_wid = dsim.wf_pmt_bin_time, dsim.wf_sipm_bin_time
    nsamp_pmt = int(dsim.wf_buffer_time // pmt_wid)
    nsamp_sipm = int(dsim.wf_buffer_time // sipm_wid)

    generate_wfs_ = fl.map(get_function_generate_wfs(
        krmap_filename=krmap_filename, psfsipm_filename=psfsipm_filename),
                           args=("hits"),
                           out=("wfs"))

    with tb.open_file(file_out, "w",
                      filters=tbl.filters(compression)) as h5out:

        write_mc = fl.sink(mc_info_writer(h5out), args=("mc", "evt"))
        wf_writer_ = fl.sink(wf_writer(h5out,
                                       n_sens_eng=npmt,
                                       n_sens_trk=nsipm,
                                       length_eng=nsamp_pmt,
                                       length_trk=nsamp_sipm),
                             args=("evt", "wfs"))

        save_run_info(h5out, run_number)
        return push(source=load_hits(files_in),
                    pipe=pipe(generate_wfs_, fork(wf_writer_, write_mc)))
Exemplo n.º 2
0
def position_signal(conf):

    files_in      = glob(os.path.expandvars(conf.files_in))
    file_out      =      os.path.expandvars(conf.file_out)
    detector_db   =                         conf.detector_db
    run_number    =                     int(conf.run_number)
    max_time      =                     int(conf.max_time)
    buffer_length =                   float(conf.buffer_length)
    pre_trigger   =                   float(conf.pre_trigger)
    trg_threshold =                   float(conf.trg_threshold)
    compression   =                         conf.compression

    npmt, nsipm        = get_no_sensors(detector_db, run_number)
    pmt_wid, sipm_wid  = get_sensor_binning(files_in[0])
    nsamp_pmt          = int(buffer_length * units.mus /  pmt_wid)
    nsamp_sipm         = int(buffer_length * units.mus / sipm_wid)

    bin_calculation    = calculate_binning(max_time)
    pmt_binning        = fl.map(bin_calculation,
                                args = ("pmt_wfs" ,  "pmt_binwid"),
                                out  = ("pmt_bins", "pmt_bin_wfs"))

    extract_minmax     = fl.map(bin_minmax,
                                args = "pmt_bins",
                                out  = ("min_bin", "max_bin"))

    sipm_binning       = fl.map(bin_calculation,
                                args = ("sipm_wfs", "sipm_binwid",
                                        "min_bin" ,     "max_bin") ,
                                out  = ("sipm_bins", "sipm_bin_wfs"))

    sensor_order_      = fl.map(partial(sensor_order,
                                        detector_db = detector_db,
                                        run_number  =  run_number),
                                args = ("pmt_bin_wfs", "sipm_bin_wfs"),
                                out  = ("pmt_ord", "sipm_ord"))

    trigger_finder_    = fl.map(trigger_finder(buffer_length,
                                               pmt_wid, trg_threshold),
                                args = "pmt_wfs",
                                out  = "triggers")

    event_times        = fl.map(trigger_times,
                                args = ("triggers", "timestamp", "pmt_bins"),
                                out  = "evt_times")

    calculate_buffers_ = fl.map(calculate_buffers(buffer_length, pre_trigger,
                                                  pmt_wid      ,    sipm_wid),
                                args = ("triggers",
                                        "pmt_bins" ,  "pmt_bin_wfs",
                                        "sipm_bins", "sipm_bin_wfs"),
                                out  = "buffers")

    with tb.open_file(file_out, "w", filters = tbl.filters(compression)) as h5out:

        write_mc         = fl.sink(mc_info_writer(h5out),
                                   args = ("mc", "evt"))
        buffer_writer_   = fl.sink(buffer_writer(h5out                  ,
                                                 n_sens_eng = npmt      ,
                                                 n_sens_trk = nsipm     ,
                                                 length_eng = nsamp_pmt ,
                                                 length_trk = nsamp_sipm),
                                   args = ("evt", "pmt_ord", "sipm_ord",
                                           "evt_times", "buffers"))

        save_run_info(h5out, run_number)
        return push(source = load_sensors(files_in, detector_db, run_number),
                    pipe   = pipe(pmt_binning         ,
                                  extract_minmax      ,
                                  sipm_binning        ,
                                  sensor_order_       ,
                                  trigger_finder_     ,
                                  event_times         ,
                                  calculate_buffers_  ,
                                  fork(buffer_writer_,
                                       write_mc      )))
Exemplo n.º 3
0
        yield dict(number=number)


def number_adder(y):
    def adder(x):
        return x + y

    return adder


from math import sqrt

add_42 = fl.map(number_adder(42), args="number", out="number+42")
take_sqrt = fl.map(sqrt, args="number+42", out="final result")

do_everything = fl.pipe(add_42, take_sqrt)


def file_writer(file):
    def write(data):
        file.write(f"{data}\n")

    return write


@fl.RESULT
def counter(future):
    count = 0
    try:
        while True:
            yield
Exemplo n.º 4
0
        yield dict(number=number)


def number_adder(y):
    def adder(x):
        return x + y

    return adder


from math import sqrt

add_42 = fl.map(number_adder(42), args="number", out="number+42")
take_sqrt = fl.map(sqrt, args="number+42", out="final result")

do_everything = fl.pipe(add_42, take_sqrt)


def file_writer(file):
    def write(data):
        file.write(f"{data}\n")

    return write


@fl.RESULT
def counter(future):
    count = 0
    try:
        while True:
            yield
Exemplo n.º 5
0
        yield dict(number=number)


def number_adder(y):
    def adder(x):
        return x + y

    return adder


from math import sqrt

add_42 = fl.map(number_adder(42), args="number", out="number+42")
take_sqrt = fl.map(sqrt, args="number+42", out="final result")

do_everything = fl.pipe(add_42, take_sqrt)


def file_writer(file):
    def write(data):
        file.write(f"{data}\n")

    return write


with open("demonstration_0.txt", "w") as file:
    print_ = fl.sink(print, args="final result")
    write = fl.sink(file_writer(file), args="final result")

    fl.push(source=lost_numbers(),
            pipe=fl.pipe(fl.spy(print), add_42, fl.spy(print), take_sqrt,