def fr2npz(gain, shaping, json_file, npz_file): ''' Convert field response file to numpy (.json or .json.bz2 to .npz) If gain and shaping are non zero then convolve each field response function with the corresponding electronics response function. Result holds a number of arrays and scalar values. Arrays: - resp[012] :: one 2D array for each plane. A wire region is 10 pixels wide. Each row of pixels represents the average field response between the two original drift paths bounding the row. The 2D array also makes explicit the flipped-symmetry that the original field response file leaves implicit. The columns mark time. Note, to make a per-wire sub-array of all impact rows #3 (counting from 0) you can use Numpy indexing like: dat['resp2'][3::10,:] - bincenters[012] :: the pitch location in mm of the row centers - pitches :: the nominal wire pitch for each plane as used in the Garfield simulation. - locations :: the locations along the drift direction of each of the planes. - eresp :: electronics response function, if gain/shaping given - espec :: the FFT of this, if gain/shaping given Scalar values: - origin :: in mm of where the drifts start in the same axis as the locations - tstart :: time when drift starts - period :: the sampling period in ns of the field response (ie, width of resp columns) - speed :: in mm/ns of the nominal electron drift speed used in the Garfield calculation. - gain : the passed in gain - shaping :: the passed in shaping time ''' import wirecell.sigproc.response.persist as per import wirecell.sigproc.response.arrays as arrs import numpy fr = per.load(json_file) gain *= units.mV/units.fC shaping *= units.us dat = arrs.fr2arrays(fr, gain, shaping) numpy.savez(npz_file, **dat)
def plot_spectra(ctx, responsefile, outfile): ''' Plot per plane response spectra. ''' import wirecell.sigproc.response.persist as per import wirecell.sigproc.response.plots as plots fr = per.load(responsefile) plots.plot_specs(fr, outfile)
def plot_response(ctx, responsefile, outfile, region, trange, title, reflect): ''' Plot per plane responses. ''' import wirecell.sigproc.response.persist as per import wirecell.sigproc.response.plots as plots trange = list(map(int, trange.split(','))) fr = per.load(responsefile) plots.plot_planes(fr, outfile, trange, region, reflect, title)
def plot_response(ctx, responsefile, pdffile, trange): ''' Make some plots from a response file. ''' import wirecell.sigproc.response.persist as per import wirecell.sigproc.response.plots as plots trange = list(map(int, trange.split(','))) fr = per.load(responsefile) plots.plot_planes(fr, pdffile, trange)
def response_info(ctx, json_file): ''' Show some info about a field response file (.json or .json.bz2). ''' import wirecell.sigproc.response.persist as per fr = per.load(json_file) print ("origin:%.2f cm, period:%.2f us, tstart:%.2f us, speed:%.2f mm/us, axis:(%.2f,%.2f,%.2f)" % \ (fr.origin/units.cm, fr.period/units.us, fr.tstart/units.us, fr.speed/(units.mm/units.us), fr.axis[0],fr.axis[1],fr.axis[2])) for pr in fr.planes: print ("\tplane:%d, location:%.4fmm, pitch:%.4fmm" % \ (pr.planeid, pr.location/units.mm, pr.pitch/units.mm))
def plot_response(ctx, trange, title, log10, regions, responsefile, outfile): ''' Plot per-conductor (wire/strip) respnonses. ''' import wirecell.sigproc.response.persist as per import wirecell.sigproc.response.plots as plots trange = list(map(int, trange.split(','))) if regions: regions = list(map(int, regions.split(','))) fr = per.load(responsefile) plots.plot_conductors(fr, outfile, trange, title, log10, regions)
def plot_paths(rfile, n): fr = per.load(rfile) pr = fr.planes[plane] print(f'{colors[n]} {rfile}: plane={plane} {len(pr.paths)} paths:') for ind in irange: path = pr.paths[ind] tot_q = numpy.sum(path.current) * fr.period dt_us = fr.period / units.us tot_es = tot_q / units.eplus print( f'\t{ind}: {path.pitchpos:f}: {len(path.current)} samples, dt={dt_us:.3f} us, tot={tot_es:.3f} electrons' ) plt.gca().set_xlim(*trange) times = plots.time_linspace(fr, plane) plt.plot(times / units.us, path.current, color=colors[n], linestyle=styles[n])
def frzero(ctx, number, output, infile): ''' Given a WCT FR file, make a new one with off-center wires zeroed. ''' import wirecell.sigproc.response.persist as per import wirecell.sigproc.response.arrays as arrs fr = per.load(infile) for pr in fr.planes: for path in pr.paths: wire = int(path.pitchpos / pr.pitch) if abs(wire) <= number: print( f'keep wire: {wire}, pitch = {path.pitchpos} / {pr.pitch}') continue nc = len(path.current) for ind in range(nc): path.current[ind] = 0 per.dump(output, fr)
def plot_response(ctx, responsefile, pdffile): import wirecell.sigproc.response.persist as per import wirecell.sigproc.response.plots as plots fr = per.load(responsefile) plots.plot_planes(fr, pdffile)