Skip to content

Commit

Permalink
Merge pull request #259 from WireCell/spdir-metric
Browse files Browse the repository at this point in the history
Add standardized SP metrics vs track direction.
  • Loading branch information
HaiwangYu authored Jan 26, 2024
2 parents a43dbcd + aae6ebc commit 805910f
Show file tree
Hide file tree
Showing 47 changed files with 3,161 additions and 125 deletions.
17 changes: 13 additions & 4 deletions cfg/layers/gen-mids.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@

# in-place generator for mids.jsonnet to save some typing.

cat <<EOF >mids.jsonnet
me="$(realpath "$BASH_SOURCE")"
mydir="$(dirname "$me")"

cd "$mydir"

out="mids.jsonnet"

cat <<EOF > "$out"
// This file is generated, do not edit.
// Generated on $(date) by $USER on $(hostname --fqdn)
// with $me
{
EOF

# this loop should keep path relative
for one in mids/*/mids.jsonnet
do
det=$(basename $(dirname $one))
echo " $det : import \"$one\"," >> mids.jsonnet
echo " $det : import \"$one\"," >> "$out"
done
echo "}" >> mids.jsonnet
echo "}" >> "$out"


5 changes: 5 additions & 0 deletions cfg/layers/midapi.jsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// This file defines the "mid" layer API.
//
// It provides a "base class" with dummy methods that will assert if not
// overridden.
//
// Caution: due to laziness it is likely woefully incomplete.
//
// Each detector variant mid API object will override what is here.
// Thus, this object simply gives a place to define an "abstract base
// class". Any method not provided by a concrete implementation and
Expand Down
4 changes: 2 additions & 2 deletions cfg/layers/mids.jsonnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is generated, do not edit.
// Generated on Tue 03 May 2022 01:14:07 PM EDT by bv on haiku.home

// Generated on Fri Dec 8 11:53:11 AM EST 2023 by bv on haiku.home
// with /home/bv/wrk/wct/spdir-metric/toolkit/cfg/layers/gen-mids.sh
{
pdsp : import "mids/pdsp/mids.jsonnet",
uboone : import "mids/uboone/mids.jsonnet",
Expand Down
39 changes: 39 additions & 0 deletions cfg/layers/mids/pdsp/api/resps.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function(params) {
sim: {
er: {
type: "ColdElecResponse",
name: "sim",
data: params.elec + params.ductor.binning,
},
fr: {
type: "FieldResponse",
name: "sim",
data: { filename: params.ductor.field_file }
},
rc: {
type: 'RCResponse',
data: params.ductor.binning { width: params.rc.width }
},
},
nf: {
fr: {
type: "FieldResponse",
name: "nf",
data: { filename: params.nf.field_file }
},
},
sp: {
er: {
type: "ColdElecResponse",
name: "sp",
data: params.elec + params.sp.binning,
},
fr: {
type: "FieldResponse",
name: "sp",
data: { filename: params.sp.field_file }
},
},

}

74 changes: 52 additions & 22 deletions cfg/layers/mids/pdsp/api/sim.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,27 @@ local wc = low.wc;
local pg = low.pg;
local idents = low.util.idents;

local frs = import "frs.jsonnet";
local resps = import "resps.jsonnet";

function(services, params, options={}) {

// Signal binning may be extended from nominal.
local sig_binning = params.ductor.binning,

local fr = frs(params).sim,

local cer = {
type: "ColdElecResponse",
data: params.elec + sig_binning,
},

local rc = {
type: 'RCResponse',
data: sig_binning { width: params.rc.width }
},
local res = resps(params).sim,

// some have more than one
local short_responses = [ cer, ],
local long_responses = [ rc, ],
local short_responses = [ res.er, ],
local long_responses = [ res.rc, ],

local pirs = [{
type: 'PlaneImpactResponse',
name: std.toString(plane),
uses: [fr, services.dft] + short_responses + long_responses,
uses: [res.fr, services.dft] + short_responses + long_responses,
data: sig_binning {
plane: plane,
dft: wc.tn(services.dft),
field_response: wc.tn(fr),
field_response: wc.tn(res.fr),
short_responses: [wc.tn(sr) for sr in short_responses],
long_responses: [wc.tn(lr) for lr in long_responses],
overall_short_padding: 100*wc.us,
Expand All @@ -64,15 +54,14 @@ function(services, params, options={}) {
params.ductor.start_time)
]),


// API method sim.reframer
reframer :: function(anode)
reframer :: function(anode, tags=[], name=null)
pg.pnode({
type: 'Reframer',
name: idents(anode),
name: if std.type(name) == "null" then idents(anode) else name,
data: {
anode: wc.tn(anode),
tags: [],
tags: tags,
fill: 0.0,
toffset: 0,
tbin: params.ductor.tbin,
Expand All @@ -82,7 +71,7 @@ function(services, params, options={}) {

// API method sim.signal: subgraph making pure signal voltage from
// depos.
signal :: function(anode)
signal :: function(anode, tags=[])
pg.pipeline([
pg.pnode({
type: 'DepoTransform',
Expand All @@ -101,7 +90,7 @@ function(services, params, options={}) {
nsigma: 3,
},
}, nin=1, nout=1, uses = pirs + [anode, services.random, services.dft]),
$.reframer(anode)]),
$.reframer(anode, tags=tags, name=idents(anode))]),

// API method sim.noise: subgraph adding noise to voltage
noise :: function(anode)
Expand Down Expand Up @@ -138,4 +127,45 @@ function(services, params, options={}) {
}
}, nin=1, nout=1, uses=[anode]),

// The approximated sim+sigproc
splat :: function(anode, name=null)
pg.pnode({
type: 'DepoFluxSplat',
name: if std.type(name) == "null" then idents(anode) else name,
data: params.splat {
anode: wc.tn(anode),
field_response: wc.tn(res.fr),
},
}, nin=1, nout=1, uses=[anode, res.fr]),


// Construct obsolete single-depo, not generic "splat"
singledeposplat :: function(anode)
pg.pnode({
type: 'DuctorFramer',
name: idents(anode),
data: {
ductor: 'DepoSplat:' + idents(anode),
fanin: 'FrameFanin:' + idents(anode),
},
}, nin=1, nout=1, uses=[ {
type: 'FrameFanin',
name: idents(anode),
data: {
multiplicity: 0, // "dynamic"
}
}, {
type: 'DepoSplat',
name: idents(anode),
data: {
anode: wc.tn(anode),
nsigma: 3.0,
start_time: params.ductor.start_time,
readout_time: params.ductor.readout_time,
tick: params.ductor.binning.tick,
continuous: true, // see DepoSplat comments
fixed: false,
drift_speed: params.lar.drift_speed,
} }]),

}
15 changes: 5 additions & 10 deletions cfg/layers/mids/pdsp/api/sp.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local spfilt = import "sp-filters.jsonnet";
local low = import "../../../low.jsonnet";
local wc = low.wc;

local frs = import "frs.jsonnet";
local resps = import "resps.jsonnet";

// Allow an optional argument "sparse" as this is really an end-user
// decision. Higher layers may expose this option to the TLA.
Expand All @@ -19,12 +19,7 @@ function(services, params, options={}) function(anode)
local fullscale = pars.digi.fullscale[1] - pars.digi.fullscale[0];
local ADC_mV_ratio = ((1 << resolution) - 1 ) / fullscale;

local fr = frs(pars).sp;

local cer = pars.ductor.binning {
type: "ColdElecResponse",
data: pars.elec,
};
local res = resps(params).sp;

low.pg.pnode({
type: 'OmnibusSigProc',
Expand All @@ -38,8 +33,8 @@ function(services, params, options={}) function(anode)
anode: wc.tn(anode),
dft: wc.tn(services.dft),
per_chan_resp: "",
field_response: wc.tn(fr),
elecresponse: wc.tn(cer),
field_response: wc.tn(res.fr),
elecresponse: wc.tn(res.er),
ftoffset: 0.0, // default 0.0
ctoffset: 1.0*wc.microsecond, // default -8.0
fft_flag: 0, // 1 is faster but higher memory, 0 is slightly slower but lower memory
Expand Down Expand Up @@ -82,4 +77,4 @@ function(services, params, options={}) function(anode)
isWrapped: false,
sparse : opts.sparse,
},
}, nin=1, nout=1, uses=[anode, services.dft, fr, cer] + spfilt)
}, nin=1, nout=1, uses=[anode, services.dft, res.fr, res.er] + spfilt)
3 changes: 2 additions & 1 deletion cfg/layers/mids/pdsp/mids.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// The "real" code is elsewhere
local api = import "api.jsonnet";


// Import all variant parameter packs to allow for dict like lookup.
local variants = {
nominal: import "variants/nominal.jsonnet",
};
} + import "variants/ssss.jsonnet";

function(services, variant="", options={})
api(services, variants[variant], options)
53 changes: 42 additions & 11 deletions cfg/layers/mids/pdsp/variants/nominal.jsonnet
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
// This is the base for *pdsp* variant parameter objects.

// Do NOT place any "if" in this file! If a new variant is needed,
// make an empty, new file in this directory and either import/inherit
// from this structure overiding only the new values. Do not
// copy-paste. Refactor this file if needed to achieve breif
// variants.
// This is the file cfg/layers/mids/pdsp/variant/nominal.jsonnet.
// If this file is found at any other path, I will delete it without notice.

// This is the BASE configuration for *pdsp* variant parameter objects. It
// yields an object of a schema expected throughout cfg/layers/mids/pdsp/.

// Do NOT change this file.

// If the nominal parameter do not suit your needs, follow these steps:
//
// 1. Pick a single, short name that describes your needs.
//
// 2. Start an EMPTY file in cfg/layers/mids/pdsp/variant/<name>.jsonnet
//
// 3. Import the nominal.jsonnet object
//
// 4. Yield the nominal object with any values overridden.
//
// 5. Add this new object to the variants object in mids.jsonnet.

local wc = import "wirecell.jsonnet";

local detectors = import "detectors.jsonnet";
local mydet = detectors.pdsp;

{
// Define the LAr properties. In principle, this is NOT subject
// to variance though in principle it could be (eg, top/bottom of
Expand Down Expand Up @@ -54,7 +69,8 @@ local wc = import "wirecell.jsonnet";

// The exhaustive list of the location of every single wire
// (or strip) segment.
wires_file: "protodune-wires-larsoft-v4.json.bz2",
// wires_file: "protodune-wires-larsoft-v4.json.bz2",
wires_file: mydet.wires,

// Comments on how to chose the "anode" plane location: The
// "anode" cut off plane, here measured from APA centerline,
Expand Down Expand Up @@ -162,7 +178,8 @@ local wc = import "wirecell.jsonnet";
// The ductor transforms drifted depos to currents
ductor: {

field_file: "dune-garfield-1d565.json.bz2",
# field_file: "dune-garfield-1d565.json.bz2",
field_file: mydet.fields,

// The distance from the anode centerline to where the field
// response calculation begins drifting. Take care that field
Expand Down Expand Up @@ -198,10 +215,23 @@ local wc = import "wirecell.jsonnet";
readout_time : self.binning.nticks * self.binning.tick,
},

// A "splat" (DepoFluxSplat) is an approximation to the combination of
// ductor+sigproc
splat : {
sparse: true,
tick: $.ductor.binning.tick,
window_start: $.ductor.start_time,
window_duration: $.ductor.readout_time,
reference_time: 0.0,

},

// Simulating noise
noise : {
model: {
spectra_file: "protodune-noise-spectra-v1.json.bz2",
#spectra_file: "protodune-noise-spectra-v1.json.bz2",
spectra_file: mydet.noise,

// These are frequency space binning which are not necessarily
// same as some time binning - but here they are.
period: $.binning.tick, // 1/frequency
Expand Down Expand Up @@ -274,7 +304,8 @@ local wc = import "wirecell.jsonnet";
// Imaging paramter pack
img : {
// For now we use MicroBooNE's
"charge_error_file": "microboone-charge-error.json.bz2",
#"charge_error_file": "microboone-charge-error.json.bz2",
"charge_error_file": mydet.qerr,

// Number of ticks to collect into one time slice span
span: 4,
Expand Down
Loading

0 comments on commit 805910f

Please sign in to comment.