diff --git a/build.gradle.kts b/build.gradle.kts index 639b645..f6d6bfe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,13 +13,13 @@ allprojects { } group = "ru.inr.mass" - version = "0.1.4-dev-2" + version = "0.1.4-dev-3" } val dataforgeVersion by extra("0.6.2") -val tablesVersion: String by extra("0.2.0-dev-3") +val tablesVersion: String by extra("0.2.1") val kmathVersion by extra("0.3.1") -val visionForgeVersion: String by rootProject.extra("0.3.0-dev-6") +val visionForgeVersion: String by rootProject.extra("0.3.0-dev-14") ksciencePublish { @@ -28,6 +28,7 @@ ksciencePublish { useSPCTeam() } space("https://maven.pkg.jetbrains.space/spc/p/numass/maven") + //repository("spc","https://maven.sciprog.center/spc") } apiValidation { diff --git a/gradle.properties b/gradle.properties index 87fa69b..e2dccaf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,4 +12,4 @@ org.gradle.parallel=true org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G toolsVersion=0.14.10-kotlin-1.9.0 -compose.version=1.5.1 +compose.version=1.5.3 diff --git a/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/NumassJsPlugin.kt b/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/NumassJsPlugin.kt index 586e356..cd87b95 100644 --- a/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/NumassJsPlugin.kt +++ b/numass-data-server/src/jsMain/kotlin/ru/inr/mass/data/server/NumassJsPlugin.kt @@ -12,15 +12,16 @@ import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName import space.kscience.plotly.models.LineShape import space.kscience.plotly.models.ScatterMode -import space.kscience.plotly.plotElement +import space.kscience.plotly.plotDiv import space.kscience.plotly.scatter import space.kscience.visionforge.ElementVisionRenderer +import space.kscience.visionforge.JsVisionClient import space.kscience.visionforge.Vision import space.kscience.visionforge.VisionClient import space.kscience.visionforge.plotly.PlotlyPlugin public class NumassJsPlugin : AbstractPlugin(), ElementVisionRenderer { - public val client: VisionClient by require(VisionClient) + public val client: VisionClient by require(JsVisionClient) public val numassCommon: NumassCommonPlugin by require(NumassCommonPlugin) public val plotly: PlotlyPlugin by require(PlotlyPlugin) @@ -59,7 +60,7 @@ public class NumassJsPlugin : AbstractPlugin(), ElementVisionRenderer { is VisionOfNumassPoint -> element.append { h1 { +"Point" } - plotElement { + plotDiv { vision.spectra.forEach { (channel, spectrum) -> val pairs = spectrum.entries.sortedBy { it.key } scatter { diff --git a/numass-workspace/build.gradle.kts b/numass-workspace/build.gradle.kts index 18e9212..d9b13b8 100644 --- a/numass-workspace/build.gradle.kts +++ b/numass-workspace/build.gradle.kts @@ -20,7 +20,8 @@ dependencies { implementation("space.kscience:dataforge-workspace:$dataforgeVersion") implementation("space.kscience:kmath-jupyter:$kmathVersion") - implementation("space.kscience:tables-kt:$tablesVersion") + implementation("space.kscience:tables-kt-csv:$tablesVersion") + implementation("org.apache.commons:commons-csv:1.10.0") implementation("space.kscience:visionforge-plotly:$visionForgeVersion") } diff --git a/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2023.kt b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2023.kt new file mode 100644 index 0000000..035e7e3 --- /dev/null +++ b/numass-workspace/src/main/kotlin/ru/inr/mass/scripts/run_2023.kt @@ -0,0 +1,97 @@ +package ru.inr.mass.scripts + +import org.apache.commons.csv.CSVFormat +import ru.inr.mass.models.* +import ru.inr.mass.workspace.Numass +import ru.inr.mass.workspace.buffer +import ru.inr.mass.workspace.fitWith +import space.kscience.dataforge.meta.Value +import space.kscience.dataforge.meta.double +import space.kscience.kmath.UnstableKMathAPI +import space.kscience.kmath.data.XYErrorColumnarData +import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.optimization.* +import space.kscience.kmath.real.map +import space.kscience.kmath.real.step +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.indices +import space.kscience.plotly.* +import space.kscience.plotly.models.ScatterMode +import space.kscience.tables.Column +import space.kscience.tables.Table +import space.kscience.tables.csv.readAsCsv +import space.kscience.tables.get +import kotlin.math.pow + +fun Column.toDoubleBuffer() = DoubleBuffer(size) { get(it).double } + +@OptIn(UnstableKMathAPI::class) +suspend fun main() { + val input = Table.readAsCsv( + Numass::class.java.getResource("/data/2023_events.tsv")!!, + csvFormat = CSVFormat.TDF + ) + + val timePerPoint = 30.0 * 129 + + val data: XYErrorColumnarData = XYErrorColumnarData.of( + input.columns["U"].toDoubleBuffer(), + input.columns["events"].toDoubleBuffer().map { it / timePerPoint }, + input.columns["error"].toDoubleBuffer().map { it / timePerPoint } + ) + + val spectrum: NBkgSpectrum = SterileNeutrinoSpectrum(fss = FSS.default).withNBkg() + + val args: Map = mapOf( + NBkgSpectrum.norm to 215443.0, + NBkgSpectrum.bkg to 2.0, + NumassBeta.mnu2 to 0.0, + NumassBeta.e0 to 18575.0, + NumassBeta.msterile2 to 2000.0.pow(2), + NumassBeta.u2 to 0.0, + NumassTransmission.thickness to 0.3, + NumassTransmission.trap to 1.0 + ) + + + val fit: XYFit = data.fitWith( + optimizer = QowOptimizer, + modelExpression = spectrum, + startingPoint = args, + OptimizationParameters(NBkgSpectrum.norm, NBkgSpectrum.bkg, NumassBeta.e0), + OptimizationIterations(20) + ) + + println("Chi squared/dof: ${fit.chiSquaredOrNull}/${fit.dof}") + + + Plotly.page { + plot { + scatter { + name = "Data" + mode = ScatterMode.markers + x.buffer = data.x + y.buffer = data.y + } + + scatter { + name = "Fit" + mode = ScatterMode.lines + x.buffer = 12000.0..18600.0 step 10.0 + y.numbers = x.doubles.map { spectrum(it, args + fit.resultPoint) } + } + } + + plot { + layout.title = "residuals" + scatter { + mode = ScatterMode.markers + x.buffer = data.x + y.numbers = data.x.indices.map { + (data.y[it] - spectrum(data.x[it], args + fit.resultPoint))/data.yErr[it] + } + } + } + }.makeFile() + +} \ No newline at end of file diff --git a/numass-workspace/src/main/resources/data/2023_events.tsv b/numass-workspace/src/main/resources/data/2023_events.tsv new file mode 100644 index 0000000..b5a4180 --- /dev/null +++ b/numass-workspace/src/main/resources/data/2023_events.tsv @@ -0,0 +1,108 @@ +U events error +12000 6.452460E+07 8032.720335 +12050 6.308058E+07 7942.32812 +12100 6.166233E+07 7852.536369 +12150 6.026178E+07 7762.846435 +12200 5.888044E+07 7673.359382 +12250 5.752020E+07 7584.207129 +12300 5.618589E+07 7495.725049 +12350 5.486976E+07 7407.412404 +12400 5.357057E+07 7319.192132 +12450 5.229649E+07 7231.631507 +12500 5.104097E+07 7144.295993 +12550 4.980586E+07 7057.326711 +12600 4.858747E+07 6970.471306 +12650 4.739252E+07 6884.222328 +12700 4.621748E+07 6798.344134 +12750 4.505844E+07 6712.55872 +12800 4.392086E+07 6627.281125 +12850 4.280192E+07 6542.317643 +12900 4.170236E+07 6457.736238 +12950 4.062241E+07 6373.571204 +13000 3.955862E+07 6289.564579 +13050 3.851518E+07 6206.059556 +13100 3.748997E+07 6122.905734 +13150 3.648207E+07 6040.03875 +13200 3.549434E+07 5957.712236 +13250 3.452146E+07 5875.496153 +13300 3.356598E+07 5793.615159 +13350 3.263059E+07 5712.318869 +13400 3.171169E+07 5631.313607 +13450 3.080984E+07 5550.661274 +13500 2.992572E+07 5470.440919 +13550 2.905686E+07 5390.441869 +13600 2.820575E+07 5310.908839 +13650 2.737116E+07 5231.745008 +13700 2.655560E+07 5153.212589 +13750 2.575232E+07 5074.674515 +13800 2.496715E+07 4996.713422 +13850 2.419569E+07 4918.911404 +13900 2.344232E+07 4841.727268 +13950 2.270363E+07 4764.832291 +14000 2.198215E+07 4688.512852 +14050 2.127411E+07 4612.386446 +14100 2.058196E+07 4536.734227 +14150 1.990347E+07 4461.330615 +14200 1.924117E+07 4386.475463 +14250 1.859371E+07 4312.041926 +14300 1.796066E+07 4238.001528 +14350 1.734144E+07 4164.305627 +14400 1.673491E+07 4090.832005 +14450 1.614486E+07 4018.066921 +14500 1.556582E+07 3945.354348 +14550 1.500395E+07 3873.492826 +14600 1.445357E+07 3801.785423 +14650 1.391677E+07 3730.51812 +14700 1.339411E+07 3659.796472 +14750 1.288430E+07 3589.470303 +14800 1.238646E+07 3519.440284 +14850 1.190164E+07 3449.875909 +14900 1.143011E+07 3380.844281 +14950 1.097078E+07 3312.217027 +15000 1.052425E+07 3244.109423 +15050 1.008924E+07 3176.356172 +15100 9.665787E+06 3108.984892 +15150 9.254249E+06 3042.079724 +15200 8.854339E+06 2975.624154 +15250 8.467155E+06 2909.837666 +15300 8.090963E+06 2844.46187 +15350 7.725603E+06 2779.496931 +15400 7.370687E+06 2714.900844 +15450 7.028022E+06 2651.041609 +15500 6.694518E+06 2587.376647 +15550 6.372090E+06 2524.299879 +15600 6.058846E+06 2461.472259 +15650 5.758606E+06 2399.709617 +15700 5.466336E+06 2338.019685 +15750 5.183979E+06 2276.835393 +15800 4.912587E+06 2216.435542 +15850 4.648231E+06 2155.975548 +15900 4.396058E+06 2096.677784 +15950 4.151727E+06 2037.578662 +16000 3.916397E+06 1978.98901 +16100 3.473288E+06 1863.676016 +16200 3.065010E+06 1750.717128 +16300 2.688767E+06 1639.746111 +16400 2.344119E+06 1531.051707 +16500 2.029421E+06 1424.577365 +16600 1.743956E+06 1320.589413 +16700 1.487062E+06 1219.45145 +16800 1.255541E+06 1120.509421 +16900 1.049216E+06 1024.312329 +17000 8.724297E+05 934.0394267 +17100 7.157295E+05 846.0079518 +17200 5.750288E+05 758.3065238 +17300 4.560588E+05 675.3212528 +17400 3.553991E+05 596.1536111 +17500 2.697442E+05 519.3690855 +17600 2.005270E+05 447.8024159 +17700 1.434300E+05 378.7215839 +17800 9.860455E+04 314.0136092 +17900 6.354514E+04 252.0816166 +18000 3.898907E+04 197.456499 +18100 2.149273E+04 146.6039915 +18200 1.010559E+04 100.5265405 +18300 4.910901E+03 70.07781835 +18400 2.252190E+03 47.4572434 +18500 1.860929E+03 43.13848425 +18600 1.760000E+03 41.95235393