Skip to content

Commit

Permalink
Adds coefficient plot.
Browse files Browse the repository at this point in the history
  • Loading branch information
luketpickering committed Apr 4, 2019
1 parent feaa8b2 commit ee74547
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 9 deletions.
95 changes: 89 additions & 6 deletions flux_hist.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,27 @@ class OffAxis_flux_hist {
targetvec = lalolib.entrywisemul(targetvec, 1E15);
let result = lalolib.solve(this.mat, targetvec);
this.mat = lalolib.entrywisemul(this.mat, 1E-15);
return (lalolib.mul(this.mat, result));
return { bf: lalolib.mul(this.mat, result), coeffs: result };
}
};

class flux_plot {

constructor() { this.Hists = []; }

DrawAxes(el, axes_ranges, yScaleFactor = 1) {
DrawAxes(el, axes_ranges, yScaleFactor = 1, xScaleFactor = 1) {
this.width = 450;
this.height = 350;
this.margin = {top : 20, right : 20, bottom : 75, left : 95};
this.tot_width = this.width + this.margin.left + this.margin.right;
this.tot_height = this.height + this.margin.top + this.margin.bottom;

let xScale = d3.scaleLinear()
.domain([ axes_ranges.xmin, axes_ranges.xmax ]) // input
.range([ 0, this.width ]); // output
let xScale =
d3.scaleLinear()
.domain([
axes_ranges.xmin * xScaleFactor, axes_ranges.xmax * xScaleFactor
]) // input
.range([ 0, this.width ]); // output
this.xScale = xScale;

let yScale =
Expand All @@ -135,7 +138,7 @@ class flux_plot {
this.yScale = yScale;

this.lineGen = d3.line()
.x(function(d) { return xScale(d[0]); })
.x(function(d) { return xScale(d[0] * xScaleFactor); })
.y(function(d) { return yScale(d[1] * yScaleFactor); });

this.svg = d3.select(el)
Expand Down Expand Up @@ -187,3 +190,83 @@ class flux_plot {
}
}
};

class off_axis_lincomb_plot {

constructor() { this.Hists = []; }

DrawAxes(el, axes_ranges, yScaleFactor = 1, xScaleFactor = 1) {
this.width = 300;
this.height = 250;
this.margin = {top : 20, right : 20, bottom : 75, left : 95};
this.tot_width = this.width + this.margin.left + this.margin.right;
this.tot_height = this.height + this.margin.top + this.margin.bottom;

let xScale =
d3.scaleLinear()
.domain([
axes_ranges.xmin * xScaleFactor, axes_ranges.xmax * xScaleFactor
]) // input
.range([ 0, this.width ]); // output
this.xScale = xScale;

let yScale =
d3.scaleLinear()
.domain([
-axes_ranges.ymax * yScaleFactor, axes_ranges.ymax * yScaleFactor
]) // input
.range([ this.height, 0 ]); // output
this.yScale = yScale;

this.lineGen = d3.line()
.x(function(d) { return xScale(d[0] * xScaleFactor); })
.y(function(d) { return yScale(d[1] * yScaleFactor); });

this.svg = d3.select(el)
.append("svg")
.attr("width", this.tot_width)
.attr("height", this.tot_height)
.append("g")
.attr("transform", "translate(" + this.margin.left + "," +
this.margin.top + ")");

this.svg.append("g")
.attr("class", "x_axis biglabel")
.attr("transform", "translate(0," + this.height + ")")
.call(d3.axisBottom(xScale).tickArguments([ 5 ]));

RenderLatexLabel(
this.svg.append("text").text("\\(\\textrm{Off axis position (m)}\\)"),
this.svg, "25ex", "10ex", this.width * 0.3, this.height * 1.15, 1, 1);

this.svg.append("g")
.attr("class", "y_axis biglabel")
.call(d3.axisLeft(yScale).tickArguments([ 3 ]));

RenderLatexLabel(
this.svg.append("text").text("\\(\\textrm{Sample weight}\\)"), this.svg,
"25ex", "10ex", -160, -80, 1, 1, -90);
}

Draw(flux_h) {
let lineclass = flux_h.line_class;
if (lineclass == undefined) {
lineclass = "line";
}

this.Hists.push(this.svg.append("path")
.attr("d", this.lineGen(flux_h.GetPointList()))
.attr("class", lineclass));
}
Clear(n = 1) {
if (n <= 0) {
return;
}
if (n > this.Hists.length) {
n = this.Hists.length;
}
for (let i = this.Hists.length - n; i < this.Hists.length; ++i) {
this.Hists[i].remove();
}
}
};
20 changes: 17 additions & 3 deletions osc.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,18 @@
FD_numode_numu_flux_osc.Oscillate(pdg_from, pdg_to, baseline_km, op);
fp.Draw(FD_numode_numu_flux_osc);
let bfbinc = ND_numuode_numu_flux.flux_match(FD_numode_numu_flux_osc);
let bfflux = new flux_hist(DUNE_flux.FD.numode.numu.bins_e, bfbinc);
let bfflux = new flux_hist(DUNE_flux.FD.numode.numu.bins_e, bfbinc.bf);
bfflux.line_class = "orange_line";
fp.Draw(bfflux);

let lincombplot_el = document.getElementById("LinCombPlot");

let lcp = new off_axis_lincomb_plot();
let lincomb = new flux_hist(DUNE_flux.ND.numode.numu.bins_OA, bfbinc.coeffs);
lincomb.line_class = "orange_line";
lcp.DrawAxes(lincombplot_el, lincomb, 1E5, 1);
lcp.Draw(lincomb);

document.getElementById("oscflux_btn").onclick =
function(){
FD_numode_numu_flux_osc = FD_numode_numu_flux.Copy();
Expand All @@ -195,10 +203,13 @@
fp.Clear(2);
fp.Draw(FD_numode_numu_flux_osc);
let bfbinc = ND_numuode_numu_flux.flux_match(FD_numode_numu_flux_osc);
let bfflux = new flux_hist(DUNE_flux.FD.numode.numu.bins_e, bfbinc);
let bfflux = new flux_hist(DUNE_flux.FD.numode.numu.bins_e, bfbinc.bf);
bfflux.line_class = "orange_line";
fp.Draw(bfflux);

lincomb = new flux_hist(DUNE_flux.ND.numode.numu.bins_OA, bfbinc.coeffs);
lincomb.line_class = "orange_line";
lcp.Draw(lincomb);
};

let cc = document.getElementById("ConstraintControls");
Expand Down Expand Up @@ -336,9 +347,12 @@ <h5>Click/Drag to choose parameters</h5>
</div>
</div>
<div class="row">
<div class="col-8">
<div class="col-6">
<div id="FluxHistPlot" ></div>
</div>
<div class="col-6">
<div id="LinCombPlot" ></div>
</div>
</div>
<div class="row">
<div class="col-8">
Expand Down

0 comments on commit ee74547

Please sign in to comment.