[no commit message]

This commit is contained in:
Alexander Nozik 2016-06-04 20:12:40 +03:00
parent 695c0ee75b
commit bf86bd0041
7 changed files with 32 additions and 17 deletions

View File

@ -29,11 +29,11 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.plots.PlotsPlugin;
import hep.dataforge.plots.XYPlotFrame;
import hep.dataforge.plots.data.PlottableData;
import hep.dataforge.plots.data.PlottableFunction;
import hep.dataforge.plots.data.PlottableXYFunction;
import hep.dataforge.tables.PointSource;
import hep.dataforge.tables.XYAdapter;
import java.util.function.Function;
import org.apache.commons.math3.analysis.UnivariateFunction;
import java.util.stream.StreamSupport;
/**
*
@ -68,7 +68,15 @@ public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin
.buildFrom(context).buildPlotFrame(getName(), name,
metaData.getNode("plot", Meta.empty()));
frame.add(new PlottableFunction("fit", function, data, adapter));//FIXME replace by helper
PlottableXYFunction fit = new PlottableXYFunction("fit");
fit.setDensity(100, false);
fit.setSmoothing(true);
// ensuring all data points are calculated explicitly
StreamSupport.stream(data.spliterator(), false)
.map(dp -> adapter.getX(dp).doubleValue()).sorted().forEach(d -> fit.calculateIn(d));
frame.add(fit);
frame.add(PlottableData.plot("data", adapter, data));

View File

@ -55,6 +55,7 @@ import inr.numass.models.TransmissionInterpolator;
import inr.numass.models.VariableLossSpectrum;
import org.apache.commons.math3.analysis.BivariateFunction;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.util.FastMath;
/**
*
@ -218,8 +219,12 @@ public class NumassPlugin extends BasicPlugin {
}
//Adding trapping energy dependence
//Intercept = 4.95745, B1 = -0.36879, B2 = 0.00827
sp.setTrappingFunction((Ei,Ef)->LossCalculator.getTrapFunction().value(Ei, Ef)*(4.95745-0.36879*Ei+0.00827*Ei*Ei));
context.getReport().report("Using folowing trapping energy dependecy^ {}", "4.95745-0.36879*Ei+0.00827*Ei*Ei");
//sp.setTrappingFunction((Ei,Ef)->LossCalculator.getTrapFunction().value(Ei, Ef)*(4.95745-0.36879*Ei+0.00827*Ei*Ei));
sp.setTrappingFunction((Ei, Ef) -> {
return 4.1e-5 * FastMath.exp(-(Ei - Ef) / 600d) + 7.2e-3 * (0.05349 - 4.36375E-6 * (Ei) + 1.09875E-10 * Ei * Ei);
});
context.getReport().report("Using folowing trapping formula: {}",
"4e-5 * FastMath.exp(-(Ei - Ef) / 550d) + 7.2e-3 * (0.05349 - 4.36375E-6 * (Ei) + 1.09875E-10 * Ei**2)");
NBkgSpectrum spectrum = new NBkgSpectrum(sp);
return new XYModel(spectrum, getAdapter(an));

View File

@ -34,7 +34,7 @@ import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.plots.PlotsPlugin;
import hep.dataforge.plots.XYPlotFrame;
import hep.dataforge.plots.data.PlottableData;
import hep.dataforge.plots.data.PlottableFunction;
import hep.dataforge.plots.data.PlottableXYFunction;
import hep.dataforge.simulation.GaussianParameterGenerator;
import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.MapPoint;
@ -90,7 +90,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
case "scatter-empiric-experimental":
scatterFunction = new ExperimentalVariableLossSpectrum.Loss(0.3).total(pars);
frame.add(new PlottableFunction("Cross-section", (x) -> scatterFunction.value(x), 0, 100, 1000));
frame.add(PlottableXYFunction.plotFunction("Cross-section", (x) -> scatterFunction.value(x), 0, 100, 1000));
break;
default:
throw new RuntimeException("Can work only with variable loss spectra");

View File

@ -19,7 +19,7 @@ import hep.dataforge.functions.FunctionCaching;
import hep.dataforge.maths.integration.GaussRuleIntegrator;
import hep.dataforge.maths.integration.UnivariateIntegrator;
import hep.dataforge.plots.XYPlotFrame;
import hep.dataforge.plots.data.PlottableFunction;
import hep.dataforge.plots.data.PlottableXYFunction;
import hep.dataforge.values.NamedValueSet;
import static java.lang.Math.exp;
import java.util.ArrayList;
@ -168,12 +168,12 @@ public class LossCalculator {
final LossCalculator loss = LossCalculator.instance;
final List<Double> probs = loss.getGunLossProbabilities(set.getDouble("X"));
UnivariateFunction single = (double e) -> probs.get(1) * scatterFunction.value(e);
frame.add(new PlottableFunction("Single scattering", x->single.value(x), 0, 100, 1000));
frame.add(PlottableXYFunction.plotFunction("Single scattering", x->single.value(x), 0, 100, 1000));
for (int i = 2; i < probs.size(); i++) {
final int j = i;
UnivariateFunction scatter = (double e) -> probs.get(j) * loss.getLossValue(j, e, 0d);
frame.add(new PlottableFunction(j + " scattering", x->scatter.value(x), 0, 100, 1000));
frame.add(PlottableXYFunction.plotFunction(j + " scattering", x->scatter.value(x), 0, 100, 1000));
}
UnivariateFunction total = (eps) -> {
@ -187,11 +187,11 @@ public class LossCalculator {
return sum;
};
frame.add(new PlottableFunction("Total loss", x->total.value(x), 0, 100, 1000));
frame.add(PlottableXYFunction.plotFunction("Total loss", x->total.value(x), 0, 100, 1000));
} else {
frame.add(new PlottableFunction("Differential crosssection", x->scatterFunction.value(x), 0, 100, 2000));
frame.add(PlottableXYFunction.plotFunction("Differential crosssection", x->scatterFunction.value(x), 0, 100, 2000));
}
}

View File

@ -88,6 +88,8 @@ public class ModularSpectrum extends AbstractParametricFunction {
public void setTrappingFunction(BivariateFunction trappingFunction) {
this.trappingFunction = trappingFunction;
LoggerFactory.getLogger(getClass()).info("Recalculating modular spectrum cache");
setupCache();
}

View File

@ -17,7 +17,7 @@ package inr.numass.models;
import hep.dataforge.maths.integration.GaussRuleIntegrator;
import hep.dataforge.plots.PlotFrame;
import hep.dataforge.plots.data.PlottableFunction;
import hep.dataforge.plots.data.PlottableXYFunction;
import hep.dataforge.plots.fx.FXPlotUtils;
import org.apache.commons.math3.analysis.UnivariateFunction;
@ -40,8 +40,8 @@ public class TestNeLossParametrisation {
System.out.println(norm);
frame.add(new PlottableFunction("old", x->oldFunction.value(x), 0, 30, 300));
frame.add(new PlottableFunction("new", x->newFunction.value(x), 0, 30, 300));
frame.add(PlottableXYFunction.plotFunction("old", x->oldFunction.value(x), 0, 30, 300));
frame.add(PlottableXYFunction.plotFunction("new", x->newFunction.value(x), 0, 30, 300));
}
public static UnivariateFunction getSingleScatterFunction(

View File

@ -17,7 +17,7 @@ package inr.numass.models;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.plots.data.PlottableData;
import hep.dataforge.plots.data.PlottableFunction;
import hep.dataforge.plots.data.PlottableXYFunction;
import hep.dataforge.plots.fx.FXPlotUtils;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
@ -33,7 +33,7 @@ public class TransmissionInterpolatorTest {
TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(GlobalContext.instance(),
"d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.out", "Uset", "CR", 15, 0.8, 19002d);
frame.add(PlottableData.plot("data", interpolator.getX(), interpolator.getY()));
frame.add(new PlottableFunction("interpolated", x->interpolator.value(x), interpolator.getXmin(), interpolator.getXmax(), 2000));
frame.add(PlottableXYFunction.plotFunction("interpolated", x->interpolator.value(x), interpolator.getXmin(), interpolator.getXmax(), 2000));
// PrintFunction.printFuntionSimple(new PrintWriter(System.out), interpolator, interpolator.getXmin(), interpolator.getXmax(), 500);
}