Mess with adapters. Partially resolved. Need to rewrite.
This commit is contained in:
parent
19d2f95121
commit
5bcd1277f0
@ -16,7 +16,6 @@
|
||||
package inr.numass.data;
|
||||
|
||||
import hep.dataforge.exceptions.DataFormatException;
|
||||
import hep.dataforge.exceptions.NameNotFoundException;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
import hep.dataforge.tables.ValueMap;
|
||||
@ -25,6 +24,8 @@ import hep.dataforge.tables.XYAdapter;
|
||||
import hep.dataforge.values.Value;
|
||||
import hep.dataforge.values.Values;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Darksnake
|
||||
*/
|
||||
@ -59,7 +60,7 @@ public class SpectrumDataAdapter extends XYAdapter {
|
||||
}
|
||||
|
||||
public double getTime(Values point) {
|
||||
return this.getFrom(point, POINT_LENGTH_NAME, 1d).doubleValue();
|
||||
return this.getComponent(point, POINT_LENGTH_NAME, 1d).doubleValue();
|
||||
}
|
||||
|
||||
public Values buildSpectrumDataPoint(double x, long count, double t) {
|
||||
@ -79,30 +80,37 @@ public class SpectrumDataAdapter extends XYAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getYerr(Values point) throws NameNotFoundException {
|
||||
if (super.providesYError(point)) {
|
||||
return Value.of(super.getYerr(point).doubleValue() / getTime(point));
|
||||
} else {
|
||||
double y = super.getY(point).doubleValue();
|
||||
if (y < 0) {
|
||||
throw new DataFormatException();
|
||||
} else if (y == 0) {
|
||||
//avoid infinite weights
|
||||
return Value.of(1d / getTime(point));
|
||||
} else {
|
||||
return Value.of(Math.sqrt(y) / getTime(point));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(Values point) {
|
||||
return super.getY(point).numberValue().longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getY(Values point) {
|
||||
return Value.of(super.getY(point).doubleValue() / getTime(point));
|
||||
public Value getValue(Values point, String axis) {
|
||||
if (Objects.equals(axis, XYAdapter.Y_AXIS)) {
|
||||
return Value.of(getComponent(point, Y_VALUE_KEY).doubleValue() / getTime(point));
|
||||
} else {
|
||||
return super.getValue(point, axis);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getError(Values point, String axis) {
|
||||
if (Objects.equals(axis, XYAdapter.Y_AXIS)) {
|
||||
if (super.providesYError(point)) {
|
||||
return Value.of(getComponent(point, Y_ERROR_KEY).doubleValue() / getTime(point));
|
||||
} else {
|
||||
double y = getComponent(point, Y_VALUE_KEY).doubleValue();
|
||||
if (y < 0) {
|
||||
throw new DataFormatException();
|
||||
} else if (y == 0) {
|
||||
//avoid infinite weights
|
||||
return Value.of(1d / getTime(point));
|
||||
} else {
|
||||
return Value.of(Math.sqrt(y) / getTime(point));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return super.getError(point, axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import inr.numass.data.SpectrumDataAdapter
|
||||
import inr.numass.data.SpectrumGenerator
|
||||
import inr.numass.models.NBkgSpectrum
|
||||
import inr.numass.models.NumassModelsKt
|
||||
import inr.numass.models.misc.GaussFunction
|
||||
import inr.numass.models.misc.Gauss
|
||||
import inr.numass.models.sterile.NumassBeta
|
||||
import inr.numass.utils.DataModelUtils
|
||||
|
||||
@ -30,37 +30,45 @@ ctx.getPluginManager().load(NumassPlugin)
|
||||
|
||||
new GrindShell(ctx).eval {
|
||||
def beta = new NumassBeta().getSpectrum(0)
|
||||
def response = new GaussFunction(4.0)
|
||||
def response = new Gauss(5.0)
|
||||
ParametricFunction spectrum = NumassModelsKt.convolute(beta, response)
|
||||
|
||||
def model = new XYModel(Meta.empty(), new SpectrumDataAdapter(), new NBkgSpectrum(spectrum));
|
||||
|
||||
ParamSet params = morph(ParamSet, [:], "params") {
|
||||
N(value: 1e+12, err: 30, lower: 0)
|
||||
bkg(value: 1.0, err: 0.1)
|
||||
bkg(value: 5.0, err: 0.1)
|
||||
E0(value: 18575.0, err: 0.1)
|
||||
mnu2(value: 0, err: 0.01)
|
||||
msterile2(value: 1000**2, err: 1)
|
||||
U2(value: 0.0, err: 1e-3)
|
||||
X(value: 0.0, err: 0.01, lower: 0)
|
||||
trap(value: 1.0, err: 0.05)
|
||||
//X(value: 0.0, err: 0.01, lower: 0)
|
||||
//trap(value: 1.0, err: 0.05)
|
||||
w(value: 150, err: 5)
|
||||
//shift(value: 1, err: 1e-2)
|
||||
tail(value: 1e-4, err: 1e-5)
|
||||
}
|
||||
|
||||
SpectrumGenerator generator = new SpectrumGenerator(model, params, 12316);
|
||||
|
||||
PlotHelper ph = plots
|
||||
|
||||
ph.plot((2000..19500).step(100).collectEntries {
|
||||
[it, model.value(it, params)]
|
||||
}, "spectrum").configure(showLine: true, showSymbol: false, showErrors: false, thickness: 3, color: "red")
|
||||
ph.plot(data: (2000..19500).step(50).collectEntries { [it, model.value(it, params)] }, name: "spectrum")
|
||||
.configure(showLine: true, showSymbol: false, showErrors: false, thickness: 2, connectionType: "spline", color: "red")
|
||||
|
||||
|
||||
Table data = generator.generateData(DataModelUtils.getUniformSpectrumConfiguration(10000, 19500, 1, 950));
|
||||
|
||||
//params.setParValue("w", 151)
|
||||
//params.setParValue("X", 0.01)
|
||||
//params.setParValue("trap", 0.01)
|
||||
//params.setParValue("mnu2", 4)
|
||||
|
||||
ph.plot(data).configure(color: "blue")
|
||||
ph.plot(data: (2000..19500).step(50).collectEntries { [it, model.value(it, params)] }, name: "spectrum-mod")
|
||||
.configure(showLine: true, showSymbol: false, showErrors: false, thickness: 2, connectionType: "spline", color: "green")
|
||||
|
||||
ph.plot(data: data, adapter: new SpectrumDataAdapter())
|
||||
.configure(color: "blue")
|
||||
|
||||
FitState state = new FitState(data, model, params);
|
||||
|
||||
|
@ -24,7 +24,7 @@ import java.lang.Math.*
|
||||
/**
|
||||
* @author Darksnake
|
||||
*/
|
||||
class GaussFunction(private val cutoff: Double = 4.0) : AbstractParametricFunction(list), FunctionSupport {
|
||||
class Gauss(private val cutoff: Double = 4.0) : AbstractParametricFunction(*list), FunctionSupport {
|
||||
|
||||
private fun getShift(pars: ValueProvider): Double {
|
||||
return pars.getDouble("shift", 0.0)
|
@ -0,0 +1,41 @@
|
||||
package inr.numass.models.misc
|
||||
|
||||
import hep.dataforge.stat.parametric.AbstractParametricFunction
|
||||
import hep.dataforge.values.Values
|
||||
|
||||
class ConstantTail(private val defaultTail: Double = 0.0) : AbstractParametricFunction("tail") {
|
||||
override fun derivValue(parName: String, x: Double, set: Values): Double {
|
||||
if (parName == "tail" && x <= 0) {
|
||||
return 1.0
|
||||
} else {
|
||||
return 0.0
|
||||
}
|
||||
}
|
||||
|
||||
override fun value(x: Double, set: Values): Double {
|
||||
return if (x <= 0) {
|
||||
set.getDouble("tail", defaultTail)
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
|
||||
override fun providesDeriv(name: String): Boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class exponentialTail : AbstractParametricFunction("tail") {
|
||||
override fun derivValue(parName: String?, x: Double, set: Values?): Double {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun value(x: Double, set: Values?): Double {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun providesDeriv(name: String?): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
}
|
@ -204,7 +204,7 @@ class NumassBeta : AbstractParametricBiFunction(list) {
|
||||
return BetaSpectrum(fs);
|
||||
}
|
||||
|
||||
inner class BetaSpectrum(val fs: Double) : AbstractParametricFunction(list) {
|
||||
inner class BetaSpectrum(val fs: Double) : AbstractParametricFunction(*list) {
|
||||
|
||||
override fun providesDeriv(name: String): Boolean {
|
||||
return this@NumassBeta.providesDeriv(name)
|
||||
|
@ -47,7 +47,7 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor(
|
||||
configuration: Meta,
|
||||
val source: ParametricBiFunction = NumassBeta(),
|
||||
val transmission: NumassTransmission = NumassTransmission(context, configuration.getMetaOrEmpty("transmission")),
|
||||
val resolution: ParametricBiFunction = NumassResolution(context, configuration.getMeta("resolution", Meta.empty()))) : AbstractParametricFunction(list) {
|
||||
val resolution: ParametricBiFunction = NumassResolution(context, configuration.getMeta("resolution", Meta.empty()))) : AbstractParametricFunction(*list) {
|
||||
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user