Migrating to new coroutines and kotlin 1.3
This commit is contained in:
parent
15e7974225
commit
61aef39670
30
build.gradle
30
build.gradle
@ -1,10 +1,7 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.2.70"
|
||||
ext.kotlin_version = "1.3.10"
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
url = "https://dl.bintray.com/kotlin/kotlin-eap"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -28,36 +25,37 @@ allprojects {
|
||||
//maven { url = "https://jitpack.io" }
|
||||
maven { url = "http://dl.bintray.com/kotlin/ktor" }
|
||||
maven { url = "https://dl.bintray.com/kotlin/kotlinx" }
|
||||
maven { url = "https://dl.bintray.com/kotlin/kotlin-eap"}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
testCompile group: 'junit', name: 'junit', version: '4.+'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
testImplementation group: 'junit', name: 'junit', version: '4.+'
|
||||
}
|
||||
|
||||
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = ['-Xjvm-default=enable']
|
||||
jvmTarget = "1.8"
|
||||
javaParameters = true
|
||||
freeCompilerArgs += [
|
||||
'-Xjvm-default=enable',
|
||||
"-progressive",
|
||||
"-Xuse-experimental=kotlin.Experimental"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = ['-Xjvm-default=enable']
|
||||
jvmTarget = "1.8"
|
||||
javaParameters = true
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
experimental {
|
||||
coroutines "enable"
|
||||
freeCompilerArgs += [
|
||||
'-Xjvm-default=enable',
|
||||
"-progressive",
|
||||
"-Xuse-experimental=kotlin.Experimental"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -16,12 +16,12 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "hep.dataforge:plots-jfc" // project(':dataforge-plots:plots-jfc')
|
||||
compile "hep.dataforge:dataforge-control" //project(':dataforge-control')
|
||||
compile "hep.dataforge:dataforge-gui"
|
||||
implementation "hep.dataforge:plots-jfc" // project(':dataforge-plots:plots-jfc')
|
||||
implementation "hep.dataforge:dataforge-control" //project(':dataforge-control')
|
||||
implementation "hep.dataforge:dataforge-gui"
|
||||
|
||||
// https://mvnrepository.com/artifact/commons-cli/commons-cli
|
||||
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
|
||||
implementation group: 'commons-cli', name: 'commons-cli', version: '1.4'
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
//DataForge dependencies
|
||||
compile project(':numass-control')
|
||||
//compile project(':numass-server')
|
||||
implementation project(':numass-control')
|
||||
//implementation project(':numass-server')
|
||||
|
||||
// optional device classpath
|
||||
devices project(':numass-control:cryotemp')
|
||||
|
@ -11,7 +11,7 @@ version = "0.2.0";
|
||||
//mainClassName = "inr.numass.readvac.Main"
|
||||
|
||||
dependencies {
|
||||
compile project(':numass-control')
|
||||
implementation project(':numass-control')
|
||||
}
|
||||
|
||||
task testDevice(dependsOn: classes, type: JavaExec) {
|
||||
|
@ -17,6 +17,6 @@
|
||||
version = "0.1.0"
|
||||
|
||||
dependencies {
|
||||
compile project(':numass-control')
|
||||
compile project(':numass-core')
|
||||
implementation project(':numass-control')
|
||||
implementation project(':numass-core')
|
||||
}
|
@ -18,15 +18,10 @@ package inr.numass.control.dante
|
||||
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.orElse
|
||||
import inr.numass.control.dante.DanteClient.Companion.CommandType.*
|
||||
import inr.numass.control.dante.DanteClient.Companion.Register.*
|
||||
import inr.numass.data.NumassProto
|
||||
import inr.numass.data.api.NumassPoint
|
||||
import inr.numass.data.storage.ProtoNumassPoint
|
||||
import kotlinx.coroutines.experimental.*
|
||||
import kotlinx.coroutines.experimental.channels.Channel
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.DataInputStream
|
||||
import java.io.OutputStream
|
||||
import java.lang.Math.pow
|
||||
@ -38,7 +33,6 @@ import java.time.Instant
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.coroutines.experimental.buildSequence
|
||||
import kotlin.math.ceil
|
||||
|
||||
internal val Byte.positive
|
||||
@ -254,7 +248,7 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable {
|
||||
message = comChannel.receive()
|
||||
}
|
||||
|
||||
return buildSequence {
|
||||
return sequence {
|
||||
val intBuffer = ByteBuffer.wrap(message.payload).asIntBuffer()
|
||||
while (intBuffer.hasRemaining()) {
|
||||
yield(intBuffer.get())
|
||||
@ -543,7 +537,7 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable {
|
||||
* Escape the sequence using DANTE convention
|
||||
*/
|
||||
private fun ByteArray.escape(): ByteArray {
|
||||
return buildSequence {
|
||||
return sequence {
|
||||
this@escape.forEach {
|
||||
yield(it)
|
||||
if (it == 0xdd.toByte()) {
|
||||
|
@ -30,7 +30,6 @@ import inr.numass.data.analyzers.SimpleAnalyzer
|
||||
import inr.numass.data.analyzers.withBinning
|
||||
import inr.numass.data.api.NumassBlock
|
||||
import inr.numass.data.channel
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val client = DanteClient("192.168.111.120", 8)
|
||||
|
@ -8,7 +8,7 @@ if (!hasProperty('mainClass')) {
|
||||
mainClassName = mainClass
|
||||
|
||||
dependencies {
|
||||
compile project(':numass-control')
|
||||
implementation project(':numass-control')
|
||||
}
|
||||
|
||||
task talkToServer(type: JavaExec) {
|
||||
|
@ -15,23 +15,13 @@
|
||||
*/
|
||||
package inr.numass.control.magnet
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.control.devices.AbstractDevice
|
||||
import hep.dataforge.control.ports.Port
|
||||
import hep.dataforge.control.ports.PortFactory
|
||||
import hep.dataforge.description.ValueDef
|
||||
import hep.dataforge.exceptions.ControlException
|
||||
import hep.dataforge.exceptions.PortException
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.states.StateDef
|
||||
import hep.dataforge.states.StateDefs
|
||||
import hep.dataforge.states.valueState
|
||||
import hep.dataforge.utils.DateTimeUtils
|
||||
import hep.dataforge.values.ValueType.*
|
||||
import inr.numass.control.DeviceView
|
||||
import inr.numass.control.magnet.fx.MagnetDisplay
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
@ -16,8 +16,6 @@
|
||||
package inr.numass.control.magnet.fx
|
||||
|
||||
import hep.dataforge.exceptions.PortException
|
||||
import hep.dataforge.fx.asDoubleProperty
|
||||
import hep.dataforge.states.ValueState
|
||||
import inr.numass.control.DeviceDisplayFX
|
||||
import inr.numass.control.magnet.LambdaMagnet
|
||||
import javafx.application.Platform
|
||||
@ -26,7 +24,6 @@ import javafx.beans.value.ObservableValue
|
||||
import javafx.scene.control.*
|
||||
import javafx.scene.layout.AnchorPane
|
||||
import javafx.scene.paint.Color
|
||||
import tornadofx.*
|
||||
|
||||
/**
|
||||
* FXML Controller class
|
||||
@ -61,13 +58,13 @@ class MagnetDisplay : DeviceDisplayFX<LambdaMagnet>() {
|
||||
|
||||
|
||||
init {
|
||||
targetIField.textProperty().addListener { observable: ObservableValue<out String>, oldValue: String, newValue: String ->
|
||||
targetIField.textProperty().addListener { _: ObservableValue<out String>, oldValue: String, newValue: String ->
|
||||
if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) {
|
||||
targetIField.text = oldValue
|
||||
}
|
||||
}
|
||||
|
||||
magnetSpeedField.textProperty().addListener { observable: ObservableValue<out String>, oldValue: String, newValue: String ->
|
||||
magnetSpeedField.textProperty().addListener { _: ObservableValue<out String>, oldValue: String, newValue: String ->
|
||||
if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) {
|
||||
magnetSpeedField.text = oldValue
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ mainClassName = mainClass
|
||||
|
||||
|
||||
dependencies {
|
||||
compile project(':numass-control')
|
||||
implementation project(':numass-control')
|
||||
}
|
@ -8,7 +8,7 @@ if (!hasProperty('mainClass')) {
|
||||
mainClassName = mainClass
|
||||
|
||||
dependencies {
|
||||
compile project(':numass-control')
|
||||
implementation project(':numass-control')
|
||||
}
|
||||
|
||||
task testDevice(dependsOn: classes, type: JavaExec) {
|
||||
|
@ -2,7 +2,6 @@ package inr.numass.control.readvac
|
||||
|
||||
import hep.dataforge.control.devices.Sensor
|
||||
import hep.dataforge.control.devices.Sensor.Companion.RESULT_VALUE
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import org.apache.commons.cli.DefaultParser
|
||||
import org.apache.commons.cli.HelpFormatter
|
||||
import org.apache.commons.cli.Options
|
||||
|
@ -5,9 +5,6 @@
|
||||
*/
|
||||
package inr.numass.control.readvac
|
||||
|
||||
import hep.dataforge.connections.Connection
|
||||
import hep.dataforge.connections.RoleDef
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.control.collectors.RegularPointCollector
|
||||
import hep.dataforge.control.connections.Roles
|
||||
import hep.dataforge.control.devices.Device
|
||||
@ -15,24 +12,9 @@ import hep.dataforge.control.devices.DeviceHub
|
||||
import hep.dataforge.control.devices.DeviceListener
|
||||
import hep.dataforge.control.devices.PortSensor.Companion.CONNECTED_STATE
|
||||
import hep.dataforge.control.devices.Sensor
|
||||
import hep.dataforge.description.ValueDef
|
||||
import hep.dataforge.exceptions.ControlException
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.states.StateDef
|
||||
import hep.dataforge.storage.api.TableLoader
|
||||
import hep.dataforge.storage.commons.LoaderFactory
|
||||
import hep.dataforge.storage.commons.StorageConnection
|
||||
import hep.dataforge.tables.TableFormatBuilder
|
||||
import hep.dataforge.utils.DateTimeUtils
|
||||
import hep.dataforge.values.Value
|
||||
import hep.dataforge.values.ValueMap
|
||||
import hep.dataforge.values.ValueType
|
||||
import hep.dataforge.values.Values
|
||||
import inr.numass.control.DeviceView
|
||||
import inr.numass.control.StorageHelper
|
||||
import kotlinx.coroutines.experimental.launch
|
||||
import kotlinx.coroutines.experimental.time.delay
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
@ -13,12 +13,12 @@ description = "A bse package with minimal dependencies for numass"
|
||||
|
||||
|
||||
dependencies {
|
||||
compile "hep.dataforge:dataforge-storage2"
|
||||
compile "hep.dataforge:dataforge-json"
|
||||
compile 'com.google.protobuf:protobuf-java:3.5.0'
|
||||
implementation "hep.dataforge:dataforge-storage2"
|
||||
implementation "hep.dataforge:dataforge-json"
|
||||
implementation 'com.google.protobuf:protobuf-java:3.5.0'
|
||||
|
||||
// https://mvnrepository.com/artifact/com.github.robtimus/sftp-fs
|
||||
compile group: 'com.github.robtimus', name: 'sftp-fs', version: '1.1.3'
|
||||
implementation group: 'com.github.robtimus', name: 'sftp-fs', version: '1.1.3'
|
||||
}
|
||||
|
||||
protobuf {
|
||||
|
@ -8,8 +8,6 @@ import hep.dataforge.names.Name
|
||||
import hep.dataforge.storage.Storage
|
||||
import hep.dataforge.storage.StorageElement
|
||||
import inr.numass.data.api.NumassSet
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import kotlin.coroutines.experimental.buildSequence
|
||||
|
||||
/**
|
||||
* Created by darksnake on 03-Feb-17.
|
||||
@ -22,7 +20,7 @@ class NumassDataFactory : DataFactory<NumassSet>(NumassSet::class.java) {
|
||||
* Build the sequence of name
|
||||
*/
|
||||
private fun Storage.sequence(prefix: Name = Name.empty()): Sequence<Pair<Name, StorageElement>> {
|
||||
return buildSequence {
|
||||
return sequence {
|
||||
runBlocking { getChildren() }.forEach {
|
||||
val newName = prefix + it.name
|
||||
yield(Pair(newName, it))
|
||||
|
@ -24,7 +24,6 @@ import hep.dataforge.storage.StorageElement
|
||||
import hep.dataforge.storage.files.FileStorage
|
||||
import hep.dataforge.storage.files.FileStorageElement
|
||||
import inr.numass.NumassEnvelopeType
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
|
||||
|
@ -27,16 +27,16 @@ compileGroovy.dependsOn(compileKotlin)
|
||||
compileGroovy.classpath += files(compileKotlin.destinationDir)
|
||||
|
||||
dependencies {
|
||||
compile group: 'commons-cli', name: 'commons-cli', version: '1.+'
|
||||
compile group: 'commons-io', name: 'commons-io', version: '2.+'
|
||||
compile project(':numass-core')
|
||||
compile "hep.dataforge:dataforge-minuit" //project(':dataforge-stat:dataforge-minuit')
|
||||
compile "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal')
|
||||
compile "hep.dataforge:dataforge-gui"
|
||||
//compile "hep.dataforge:dataforge-html"
|
||||
implementation group: 'commons-cli', name: 'commons-cli', version: '1.+'
|
||||
implementation group: 'commons-io', name: 'commons-io', version: '2.+'
|
||||
implementation project(':numass-core')
|
||||
implementation "hep.dataforge:dataforge-minuit" //project(':dataforge-stat:dataforge-minuit')
|
||||
implementation "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal')
|
||||
implementation "hep.dataforge:dataforge-gui"
|
||||
//implementation "hep.dataforge:dataforge-html"
|
||||
|
||||
// https://mvnrepository.com/artifact/org.ehcache/ehcache
|
||||
//compile group: 'org.ehcache', name: 'ehcache', version: '3.4.0'
|
||||
//implementation group: 'org.ehcache', name: 'ehcache', version: '3.4.0'
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,12 +37,9 @@ import inr.numass.data.api.NumassPoint
|
||||
import inr.numass.data.api.NumassSet
|
||||
import inr.numass.models.FSS
|
||||
import inr.numass.utils.ExpressionUtils
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction
|
||||
import org.jfree.chart.plot.IntervalMarker
|
||||
import org.jfree.chart.ui.RectangleInsets
|
||||
import org.slf4j.Logger
|
||||
import tornadofx.*
|
||||
import java.awt.Color
|
||||
import java.awt.Font
|
||||
import java.io.IOException
|
||||
|
@ -10,9 +10,6 @@ import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_RATE_KEY
|
||||
import inr.numass.data.api.NumassBlock
|
||||
import inr.numass.data.api.OrphanNumassEvent
|
||||
import inr.numass.data.api.SimpleBlock
|
||||
import kotlinx.coroutines.experimental.channels.asReceiveChannel
|
||||
import kotlinx.coroutines.experimental.channels.takeWhile
|
||||
import kotlinx.coroutines.experimental.channels.toList
|
||||
import org.apache.commons.math3.distribution.EnumeratedRealDistribution
|
||||
import org.apache.commons.math3.random.RandomGenerator
|
||||
import java.time.Duration
|
||||
@ -28,7 +25,7 @@ private fun RandomGenerator.nextDeltaTime(cr: Double): Long {
|
||||
|
||||
suspend fun Sequence<OrphanNumassEvent>.generateBlock(start: Instant, length: Long): NumassBlock {
|
||||
return SimpleBlock.produce(start, Duration.ofNanos(length)) {
|
||||
asReceiveChannel().takeWhile { it.timeOffset < length }.toList()
|
||||
takeWhile { it.timeOffset < length }.toList()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ import hep.dataforge.maths.chain.Chain
|
||||
import inr.numass.data.api.NumassBlock
|
||||
import inr.numass.data.api.OrphanNumassEvent
|
||||
import inr.numass.data.api.SimpleBlock
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import org.apache.commons.math3.random.RandomGenerator
|
||||
import java.lang.Math.max
|
||||
import java.time.Duration
|
||||
|
@ -21,14 +21,9 @@ import hep.dataforge.plots.PlotFrame
|
||||
import hep.dataforge.plots.data.XYFunctionPlot
|
||||
import hep.dataforge.utils.Misc
|
||||
import hep.dataforge.values.Values
|
||||
import kotlinx.coroutines.experimental.CompletableDeferred
|
||||
import kotlinx.coroutines.experimental.Deferred
|
||||
import kotlinx.coroutines.experimental.async
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import org.apache.commons.math3.analysis.BivariateFunction
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction
|
||||
import org.apache.commons.math3.exception.OutOfRangeException
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.lang.Math.exp
|
||||
import java.util.*
|
||||
|
||||
@ -41,6 +36,23 @@ import java.util.*
|
||||
object LossCalculator {
|
||||
private val cache = HashMap<Int, Deferred<UnivariateFunction>>()
|
||||
|
||||
private const val ION_POTENTIAL = 15.4//eV
|
||||
|
||||
val adjustX = true
|
||||
|
||||
|
||||
private fun getX(set: Values, eIn: Double): Double {
|
||||
return if (adjustX) {
|
||||
//From our article
|
||||
set.getDouble("X") * Math.log(eIn / ION_POTENTIAL) * eIn * ION_POTENTIAL / 1.9580741410115568e6
|
||||
} else {
|
||||
set.getDouble("X")
|
||||
}
|
||||
}
|
||||
|
||||
fun p0(set: Values, eIn: Double): Double {
|
||||
return LossCalculator.getLossProbability(0, getX(set, eIn))
|
||||
}
|
||||
|
||||
fun getGunLossProbabilities(X: Double): List<Double> {
|
||||
val res = ArrayList<Double>()
|
||||
@ -72,7 +84,7 @@ object LossCalculator {
|
||||
}
|
||||
|
||||
|
||||
private fun getCachedSpectrum(order: Int): Deferred<UnivariateFunction> {
|
||||
private fun CoroutineScope.getCachedSpectrum(order: Int): Deferred<UnivariateFunction> {
|
||||
return when {
|
||||
order <= 0 -> error("Non-positive loss cache order")
|
||||
order == 1 -> CompletableDeferred(singleScatterFunction)
|
||||
@ -235,23 +247,24 @@ object LossCalculator {
|
||||
* порядков
|
||||
*
|
||||
* @param X
|
||||
* @param Ei
|
||||
* @param Ef
|
||||
* @param eIn
|
||||
* @param eOut
|
||||
* @return
|
||||
*/
|
||||
fun getTotalLossDeriv(X: Double, Ei: Double, Ef: Double): Double {
|
||||
fun getTotalLossDeriv(X: Double, eIn: Double, eOut: Double): Double {
|
||||
val probs = getLossProbDerivs(X)
|
||||
|
||||
var sum = 0.0
|
||||
for (i in 1 until probs.size) {
|
||||
sum += probs[i] * getLossValue(i, Ei, Ef)
|
||||
sum += probs[i] * getLossValue(i, eIn, eOut)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
fun getTotalLossDerivBivariateFunction(X: Double): BivariateFunction {
|
||||
return BivariateFunction { Ei: Double, Ef: Double -> getTotalLossDeriv(X, Ei, Ef) }
|
||||
}
|
||||
fun getTotalLossDeriv(pars: Values, eIn: Double, eOut: Double) = getTotalLossDeriv(getX(pars, eIn), eIn, eOut)
|
||||
|
||||
fun getTotalLossDerivBivariateFunction(X: Double) = BivariateFunction { Ei: Double, Ef: Double -> getTotalLossDeriv(X, Ei, Ef) }
|
||||
|
||||
|
||||
/**
|
||||
* Значение полной функции потерь с учетом всех неисчезающих порядков
|
||||
@ -272,6 +285,8 @@ object LossCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
fun getTotalLossValue(pars: Values, Ei: Double, Ef: Double): Double = getTotalLossValue(getX(pars, Ei), Ei, Ef)
|
||||
|
||||
|
||||
/**
|
||||
* порог по вероятности, до которого вычисляются компоненты функции потерь
|
||||
|
@ -13,7 +13,6 @@ import hep.dataforge.values.Values
|
||||
import inr.numass.models.misc.LossCalculator
|
||||
import inr.numass.utils.ExpressionUtils
|
||||
import org.apache.commons.math3.analysis.BivariateFunction
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@ -44,23 +43,10 @@ class NumassTransmission(context: Context, meta: Meta) : AbstractParametricBiFun
|
||||
}
|
||||
}
|
||||
|
||||
private fun getX(eIn: Double, set: Values): Double {
|
||||
return if (adjustX) {
|
||||
//From our article
|
||||
set.getDouble("X") * Math.log(eIn / ION_POTENTIAL) * eIn * ION_POTENTIAL / 1.9580741410115568e6
|
||||
} else {
|
||||
set.getDouble("X")
|
||||
}
|
||||
}
|
||||
|
||||
fun p0(eIn: Double, set: Values): Double {
|
||||
return LossCalculator.getLossProbability(0, getX(eIn, set))
|
||||
}
|
||||
|
||||
override fun derivValue(parName: String, eIn: Double, eOut: Double, set: Values): Double {
|
||||
return when (parName) {
|
||||
"trap" -> trapFunc.value(eIn, eOut)
|
||||
"X" -> LossCalculator.getTotalLossDeriv(getX(eIn, set), eIn, eOut)
|
||||
"X" -> LossCalculator.getTotalLossDeriv(set, eIn, eOut)
|
||||
else -> super.derivValue(parName, eIn, eOut, set)
|
||||
}
|
||||
}
|
||||
@ -70,10 +56,8 @@ class NumassTransmission(context: Context, meta: Meta) : AbstractParametricBiFun
|
||||
}
|
||||
|
||||
override fun value(eIn: Double, eOut: Double, set: Values): Double {
|
||||
//calculate X taking into account its energy dependence
|
||||
val X = getX(eIn, set)
|
||||
// loss part
|
||||
val loss = LossCalculator.getTotalLossValue(X, eIn, eOut)
|
||||
val loss = LossCalculator.getTotalLossValue(set, eIn, eOut)
|
||||
// double loss;
|
||||
//
|
||||
// if(eIn-eOut >= 300){
|
||||
@ -94,7 +78,6 @@ class NumassTransmission(context: Context, meta: Meta) : AbstractParametricBiFun
|
||||
companion object {
|
||||
|
||||
private val list = arrayOf("trap", "X")
|
||||
private const val ION_POTENTIAL = 15.4//eV
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2018 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package inr.numass.models.sterile
|
||||
|
||||
import hep.dataforge.names.NameList
|
||||
import hep.dataforge.stat.parametric.ParametricBiFunction
|
||||
import hep.dataforge.values.Values
|
||||
|
||||
class ParametricBiFunctionCache(val function: ParametricBiFunction): ParametricBiFunction {
|
||||
override fun derivValue(parName: String?, x: Double, y: Double, set: Values?): Double {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun getNames(): NameList {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun value(x: Double, y: 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.
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import hep.dataforge.values.ValueType.BOOLEAN
|
||||
import hep.dataforge.values.Values
|
||||
import inr.numass.getFSS
|
||||
import inr.numass.models.FSS
|
||||
import inr.numass.models.misc.LossCalculator
|
||||
import inr.numass.utils.NumassIntegrator
|
||||
|
||||
/**
|
||||
@ -46,7 +47,7 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor(
|
||||
context: Context,
|
||||
configuration: Meta,
|
||||
val source: ParametricBiFunction = NumassBeta(),
|
||||
val transmission: NumassTransmission = NumassTransmission(context, configuration.getMetaOrEmpty("transmission")),
|
||||
val transmission: ParametricBiFunction = NumassTransmission(context, configuration.getMetaOrEmpty("transmission")),
|
||||
val resolution: ParametricBiFunction = NumassResolution(context, configuration.getMeta("resolution", Meta.empty()))
|
||||
) : AbstractParametricFunction(*list) {
|
||||
|
||||
@ -119,6 +120,8 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private inner class TransRes : AbstractParametricBiFunction(arrayOf("X", "trap")) {
|
||||
|
||||
override fun providesDeriv(name: String): Boolean {
|
||||
@ -135,7 +138,7 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor(
|
||||
|
||||
override fun value(eIn: Double, u: Double, set: Values): Double {
|
||||
|
||||
val p0 = transmission.p0(eIn, set)
|
||||
val p0 = LossCalculator.p0(set, eIn)
|
||||
return p0 * resolution.value(eIn, u, set) + lossRes(transmission, eIn, u, set)
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,6 @@ import inr.numass.actions.TimeAnalyzerAction
|
||||
import inr.numass.data.NumassGenerator
|
||||
import inr.numass.data.api.SimpleNumassPoint
|
||||
import inr.numass.data.generateBlock
|
||||
import kotlinx.coroutines.experimental.channels.produce
|
||||
import kotlinx.coroutines.experimental.channels.toList
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import java.time.Instant
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@ -17,7 +14,7 @@ fun main(args: Array<String>) {
|
||||
|
||||
val start = Instant.now()
|
||||
|
||||
val blockchannel = produce {
|
||||
val blockchannel = GlobalScope.produce {
|
||||
(1..num).forEach {
|
||||
val regularChain = NumassGenerator.generateEvents(cr)
|
||||
val bunchChain = NumassGenerator.generateBunches(40.0, 0.01, 5.0)
|
||||
|
@ -38,7 +38,6 @@ import inr.numass.data.SpectrumAdapter
|
||||
import inr.numass.data.SpectrumGenerator
|
||||
import inr.numass.models.NBkgSpectrum
|
||||
import inr.numass.models.sterile.SterileNeutrinoSpectrum
|
||||
import kotlinx.coroutines.experimental.launch
|
||||
import java.io.PrintWriter
|
||||
import kotlin.math.sqrt
|
||||
|
||||
@ -136,7 +135,7 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
plots.setType<DataPlot>()
|
||||
+plotResidual("trap", "trap" to 0.99)
|
||||
launch {
|
||||
context.launch(Dispatchers.Main) {
|
||||
try {
|
||||
+plotFitResidual("trap_fit", "trap" to 0.99)
|
||||
} catch (ex: Exception) {
|
||||
@ -144,15 +143,15 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
+plotResidual("X", "X" to 0.11)
|
||||
launch {
|
||||
context.launch(Dispatchers.Main) {
|
||||
+plotFitResidual("X_fit", "X" to 0.11)
|
||||
}
|
||||
+plotResidual("sterile_1", "U2" to 1e-3)
|
||||
launch {
|
||||
context.launch(Dispatchers.Main) {
|
||||
+plotFitResidual("sterile_1_fit", "U2" to 1e-3)
|
||||
}
|
||||
+plotResidual("sterile_3", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3)
|
||||
launch {
|
||||
context.launch(Dispatchers.Main) {
|
||||
+plotFitResidual("sterile_3_fit", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3)
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package inr.numass.scripts.timeanalysis
|
||||
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.coroutineContext
|
||||
import hep.dataforge.fx.output.FXOutputManager
|
||||
import hep.dataforge.goals.generate
|
||||
import hep.dataforge.goals.join
|
||||
@ -39,7 +38,7 @@ fun main(args: Array<String>) {
|
||||
.withDeadTime { (dt * 1000).toLong() }
|
||||
.generateBlock(start.plusNanos(it * length), length)
|
||||
}
|
||||
}.join(Global.coroutineContext) { blocks ->
|
||||
}.join(Global) { blocks ->
|
||||
SimpleNumassPoint(blocks, 12000.0)
|
||||
}.get()
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
package inr.numass.scripts.timeanalysis
|
||||
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.coroutineContext
|
||||
import hep.dataforge.fx.output.FXOutputManager
|
||||
import hep.dataforge.goals.generate
|
||||
import hep.dataforge.goals.join
|
||||
@ -37,7 +36,7 @@ fun main(args: Array<String>) {
|
||||
NumassPlugin().startGlobal()
|
||||
|
||||
val cr = 3.0
|
||||
val length = (30000 *1e9).toLong()
|
||||
val length = (30000 * 1e9).toLong()
|
||||
val num = 10
|
||||
val dt = 6.5
|
||||
|
||||
@ -52,14 +51,14 @@ fun main(args: Array<String>) {
|
||||
.generateBunches(6.0, 0.01, 5.0)
|
||||
|
||||
val discharges = NumassGenerator
|
||||
.generateBunches(50.0,0.001,0.1)
|
||||
.generateBunches(50.0, 0.001, 0.1)
|
||||
|
||||
NumassGenerator
|
||||
.mergeEventChains(events, bunches, discharges)
|
||||
.withDeadTime { (dt * 1000).toLong() }
|
||||
.generateBlock(start.plusNanos(it * length), length)
|
||||
}
|
||||
}.join(Global.coroutineContext) { blocks ->
|
||||
}.join(Global) { blocks ->
|
||||
SimpleNumassPoint(blocks, 18000.0)
|
||||
}.get()
|
||||
|
||||
|
@ -4,7 +4,6 @@ import inr.numass.data.channel
|
||||
import inr.numass.data.plotAmplitudeSpectrum
|
||||
import inr.numass.data.storage.ProtoNumassPoint
|
||||
import inr.numass.data.transformChain
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
@ -10,7 +10,6 @@ import hep.dataforge.storage.Storage
|
||||
import hep.dataforge.useValue
|
||||
import inr.numass.data.storage.NumassDataLoader
|
||||
import inr.numass.data.storage.NumassDirectory
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import java.io.File
|
||||
|
||||
private suspend fun createSummaryNode(storage: Storage): MetaBuilder {
|
||||
|
@ -22,13 +22,11 @@ import inr.numass.data.api.NumassSet
|
||||
import inr.numass.data.api.SimpleNumassPoint
|
||||
import inr.numass.data.storage.NumassDataLoader
|
||||
import inr.numass.data.storage.NumassDirectory
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import org.apache.commons.math3.analysis.ParametricUnivariateFunction
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException
|
||||
import org.apache.commons.math3.fitting.SimpleCurveFitter
|
||||
import org.apache.commons.math3.fitting.WeightedObservedPoint
|
||||
import java.util.stream.Collectors
|
||||
import kotlin.coroutines.experimental.buildSequence
|
||||
|
||||
|
||||
object Threshold {
|
||||
@ -39,7 +37,7 @@ object Threshold {
|
||||
val storage = NumassDirectory.read(context, meta.getString("data.dir")) as Storage
|
||||
|
||||
fun Storage.loaders(): Sequence<NumassDataLoader>{
|
||||
return buildSequence<NumassDataLoader> {
|
||||
return sequence<NumassDataLoader> {
|
||||
print("Reading ${this@loaders.fullName}")
|
||||
runBlocking { this@loaders.getChildren()}.forEach {
|
||||
if(it is NumassDataLoader){
|
||||
|
@ -17,10 +17,10 @@ apply plugin: 'com.github.johnrengelman.shadow'
|
||||
mainClassName = "inr.numass.server.ServerRunner"
|
||||
|
||||
dependencies {
|
||||
compile project(':numass-core')
|
||||
compile "hep.dataforge:storage-server" // project(':dataforge-storage:storage-servlet')
|
||||
compile "hep.dataforge:dataforge-messages"
|
||||
compile 'commons-daemon:commons-daemon:1.+'
|
||||
implementation project(':numass-core')
|
||||
implementation "hep.dataforge:storage-server" // project(':dataforge-storage:storage-servlet')
|
||||
implementation "hep.dataforge:dataforge-messages"
|
||||
implementation 'commons-daemon:commons-daemon:1.+'
|
||||
}
|
||||
|
||||
//processResources {
|
||||
|
@ -18,8 +18,8 @@ description = "The viewer for numass data"
|
||||
|
||||
|
||||
dependencies {
|
||||
compile project(':numass-core')
|
||||
compile "hep.dataforge:plots-jfc" //project(':dataforge-plots:plots-jfc')
|
||||
compile "hep.dataforge:dataforge-gui"
|
||||
implementation project(':numass-core')
|
||||
implementation "hep.dataforge:plots-jfc" //project(':dataforge-plots:plots-jfc')
|
||||
implementation "hep.dataforge:dataforge-gui"
|
||||
}
|
||||
|
||||
|
@ -22,9 +22,6 @@ import inr.numass.data.analyzers.SimpleAnalyzer
|
||||
import inr.numass.data.api.NumassBlock
|
||||
import inr.numass.data.api.NumassPoint
|
||||
import inr.numass.data.api.NumassSet
|
||||
import kotlinx.coroutines.experimental.CoroutineStart
|
||||
import kotlinx.coroutines.experimental.Deferred
|
||||
import kotlinx.coroutines.experimental.async
|
||||
|
||||
private val analyzer = SimpleAnalyzer()
|
||||
|
||||
@ -35,11 +32,11 @@ class CachedPoint(val point: NumassPoint) : NumassPoint by point {
|
||||
|
||||
override val meta: Meta = point.meta
|
||||
|
||||
val channelSpectra: Deferred<Map<Int, Table>> = async(start = CoroutineStart.LAZY) {
|
||||
val channelSpectra: Deferred<Map<Int, Table>> = GlobalScope.async(start = CoroutineStart.LAZY) {
|
||||
point.channels.mapValues { (_, value) -> analyzer.getAmplitudeSpectrum(value) }
|
||||
}
|
||||
|
||||
val spectrum: Deferred<Table> = async(start = CoroutineStart.LAZY) { analyzer.getAmplitudeSpectrum(point) }
|
||||
val spectrum: Deferred<Table> = GlobalScope.async(start = CoroutineStart.LAZY) { analyzer.getAmplitudeSpectrum(point) }
|
||||
}
|
||||
|
||||
class CachedSet(set: NumassSet) : NumassSet by set {
|
||||
|
@ -3,9 +3,6 @@ package inr.numass.viewer
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.fx.dfIconView
|
||||
import hep.dataforge.fx.except
|
||||
import hep.dataforge.fx.runGoal
|
||||
import hep.dataforge.fx.ui
|
||||
import hep.dataforge.storage.Storage
|
||||
import inr.numass.NumassProperties
|
||||
import inr.numass.data.api.NumassPoint
|
||||
@ -19,8 +16,6 @@ import javafx.scene.layout.Priority
|
||||
import javafx.scene.text.Font
|
||||
import javafx.stage.DirectoryChooser
|
||||
import javafx.stage.FileChooser
|
||||
import org.controlsfx.control.StatusBar
|
||||
import tornadofx.*
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
@ -65,7 +60,7 @@ class MainView(val context: Context = Global.getContext("viewer")) : View(title
|
||||
|
||||
if (rootDir != null) {
|
||||
NumassProperties.setNumassProperty("numass.viewer.lastPath", rootDir.absolutePath)
|
||||
kotlinx.coroutines.experimental.launch {
|
||||
GlobalScope.launch {
|
||||
runLater {
|
||||
path = rootDir.toPath()
|
||||
}
|
||||
@ -94,7 +89,7 @@ class MainView(val context: Context = Global.getContext("viewer")) : View(title
|
||||
val file = chooser.showOpenDialog(primaryStage.scene.window)
|
||||
if (file != null) {
|
||||
NumassProperties.setNumassProperty("numass.viewer.lastPath", file.parentFile.absolutePath)
|
||||
kotlinx.coroutines.experimental.launch {
|
||||
GlobalScope.launch {
|
||||
runLater {
|
||||
path = file.toPath()
|
||||
}
|
||||
|
@ -3,11 +3,6 @@ package inr.numass.viewer
|
||||
import hep.dataforge.fx.meta.MetaViewer
|
||||
import inr.numass.data.analyzers.NumassAnalyzer
|
||||
import javafx.beans.property.SimpleIntegerProperty
|
||||
import kotlinx.coroutines.experimental.async
|
||||
import org.controlsfx.glyphfont.FontAwesome
|
||||
import tornadofx.*
|
||||
import tornadofx.controlsfx.borders
|
||||
import tornadofx.controlsfx.toGlyph
|
||||
|
||||
class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) {
|
||||
|
||||
@ -24,7 +19,7 @@ class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) {
|
||||
row {
|
||||
button(graphic = FontAwesome.Glyph.REFRESH.toGlyph()) {
|
||||
action {
|
||||
async {
|
||||
GlobalScope.launch {
|
||||
val res = point.spectrum.await().sumBy { it.getValue(NumassAnalyzer.COUNT_KEY).int }
|
||||
runLater { count = res }
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ import inr.numass.data.storage.NumassDataLoader
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
import javafx.scene.control.ContextMenu
|
||||
import javafx.scene.control.TreeItem
|
||||
import kotlinx.coroutines.experimental.runBlocking
|
||||
import tornadofx.*
|
||||
|
||||
class StorageView(val storage: Storage) : View(title = "Numass storage", icon = dfIconView) {
|
||||
|
||||
|
@ -10,7 +10,6 @@ import inr.numass.data.storage.NumassDirectory
|
||||
import inr.numass.viewer.*
|
||||
import javafx.application.Application
|
||||
import javafx.scene.image.ImageView
|
||||
import tornadofx.*
|
||||
import java.io.File
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@ -33,7 +32,7 @@ class ViewerComponentsTest : View(title = "Numass viewer test", icon = ImageView
|
||||
top {
|
||||
button("Click me!") {
|
||||
action {
|
||||
kotlinx.coroutines.experimental.launch {
|
||||
GlobalScope.launch {
|
||||
val set: NumassSet = NumassDirectory.INSTANCE.read(Global, File("D:\\Work\\Numass\\data\\2017_05\\Fill_2").toPath())
|
||||
?.provide("loader::set_2", NumassSet::class.java).nullable
|
||||
?: kotlin.error("Error")
|
||||
|
@ -9,10 +9,10 @@ description = 'kodex/ktor based server'
|
||||
//mainClassName = "inr.numass.server.ServerRunner"
|
||||
|
||||
dependencies {
|
||||
compile "hep.dataforge:kodex-server"
|
||||
compile "hep.dataforge:dataforge-storage"
|
||||
compile "hep.dataforge:dataforge-control"
|
||||
compile project(":numass-core")
|
||||
implementation "hep.dataforge:kodex-server"
|
||||
implementation "hep.dataforge:dataforge-storage"
|
||||
implementation "hep.dataforge:dataforge-control"
|
||||
implementation project(":numass-core")
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
|
Loading…
Reference in New Issue
Block a user