fix: grid-fit mGrid handling + refactor
refactor: - noAdiabacity -> NO_ADIABACITY model - cli grouping
This commit is contained in:
@@ -10,7 +10,8 @@ enum class AdiabaticityModel(val description: String) {
|
||||
`2024_11`("Оригинальная таблица Влада, ноябрь 2024"),
|
||||
shifted("Со систематическим сдвигом"),
|
||||
vasya("Вариант от Васи"),
|
||||
faradey("Аналитическая модель для Цилиндра Фарадея");
|
||||
faradey("Аналитическая модель для Цилиндра Фарадея"),
|
||||
NO_ADIABACITY("Константная 1.0");
|
||||
|
||||
// ← Здесь обязательно реализуем функцию для каждой модели
|
||||
operator fun invoke(e: Double, u: Double): Double {
|
||||
@@ -58,6 +59,9 @@ enum class AdiabaticityModel(val description: String) {
|
||||
return 0.0
|
||||
}
|
||||
}
|
||||
NO_ADIABACITY -> {
|
||||
return 1.0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,6 @@ fun main (args: Array<String>) {
|
||||
fixRwall = config.fixRWall,
|
||||
fixE0 = config.fixE0,
|
||||
wallFunc = config.wallFunc,
|
||||
noAdiabacity = config.noAdiabacity,
|
||||
adiabacityFunc = config.adiabacityFunc
|
||||
)
|
||||
}
|
||||
|
||||
@@ -72,45 +72,40 @@ private class CustomArgs : CliktCommand() {
|
||||
|
||||
val spectrum: String by argument().help("path to spectrum TSV file")
|
||||
val full: String? by option().help("path to full spectrum (for test)")
|
||||
|
||||
val postfix: String? by option().help("save file postfix")
|
||||
|
||||
val norm: Double by option().double().default(8.311751921319484E8).help("NBkgSpectrum.norm")
|
||||
val bkg: Double by option().double().default(1612.626961212948).help("NBkgSpectrum.bkg")
|
||||
|
||||
val bkg: Double by option().double().default(1612.626961212948).help("NBkgSpectrum.bkg")
|
||||
val fixBkg: Boolean by option().flag().help("Don't fit bkg variable")
|
||||
|
||||
val mnu2: Double by option().double().default(0.0).help("NumassBeta.mnu2")
|
||||
val e0: Double by option().double().default(18572.0).help("NumassBeta.e0")
|
||||
val msterile2: Double by option().double().default(0.0.pow(2)).help("NumassBeta.msterile2")
|
||||
val u2: Double by option().double().default(1e-2).help("NumassBeta.u2")
|
||||
|
||||
val e0: Double by option().double().default(18572.0).help("NumassBeta.e0")
|
||||
val fixE0: Boolean by option().flag().help("Don't fit e0 variable")
|
||||
|
||||
val msterile2: Double by option().double().default(0.0.pow(2)).help("NumassBeta.msterile2")
|
||||
|
||||
val u2: Double by option().double().default(1e-2).help("NumassBeta.u2")
|
||||
val fixU2: Boolean by option().flag().help("Don't fit u2 variable")
|
||||
|
||||
val thickness: Double by option().double().default(0.3).help("NumassTransmission.thickness")
|
||||
|
||||
val trap: Double by option().double().default(1.0).help("NumassTransmission.trap")
|
||||
|
||||
val fixTrap: Boolean by option().flag().help("Don't fit trap variable")
|
||||
|
||||
val trapFunc: TrapModel by option().enum<TrapModel>().default(TrapModel.FINE_5DAY)
|
||||
.help(
|
||||
"trap model"
|
||||
)
|
||||
val fixTrap: Boolean by option().flag().help("Don't fit trap variable")
|
||||
|
||||
|
||||
val rwall: Double by option().double().default(0.17).help("rear wall")
|
||||
|
||||
val wallFunc: WallModel by option().enum<WallModel>().default(WallModel.TSV_2025_12_01)
|
||||
.help(
|
||||
"wall model"
|
||||
)
|
||||
|
||||
val fixRwall: Boolean by option().flag().help("Don't fit rwall variable")
|
||||
|
||||
val noAdiabacity: Boolean by option().flag().help("Use const 1 instead of adiabacity function")
|
||||
|
||||
val fixE0: Boolean by option().flag().help("Don't fit e0 variable")
|
||||
|
||||
// TODO: convert to enum
|
||||
val adiabacityFunc: AdiabaticityModel by option().enum<AdiabaticityModel>().default(AdiabaticityModel.`2024_11`)
|
||||
.help(
|
||||
@@ -144,7 +139,6 @@ private class CustomArgs : CliktCommand() {
|
||||
fixE0,
|
||||
trapFunc,
|
||||
fixRwall,
|
||||
noAdiabacity,
|
||||
wallFunc,
|
||||
cliArgs = this@CustomArgs,
|
||||
adiabacityFunc = adiabacityFunc
|
||||
@@ -180,13 +174,14 @@ suspend fun processCustom(
|
||||
fixE0: Boolean,
|
||||
trapFunc: ITrap,
|
||||
fixRwall: Boolean,
|
||||
noAdiabacity: Boolean,
|
||||
wallFunc: WallModel,
|
||||
cliArgs: Any? = null,
|
||||
adiabacityFunc: AdiabaticityModel
|
||||
) {
|
||||
println(cliArgs)
|
||||
|
||||
val postfix = if (postfix != null) "-$postfix" else ""
|
||||
|
||||
val data = parse(spectrumFile)
|
||||
val testData = if (full != null) parse(full) else data
|
||||
|
||||
@@ -201,11 +196,7 @@ suspend fun processCustom(
|
||||
},
|
||||
adjustX = false,
|
||||
), resolution = NumassResolution(1.7e-4, tailFunction = { e, u ->
|
||||
if (noAdiabacity) {
|
||||
1.0
|
||||
} else {
|
||||
adiabacityFunc(e, u)
|
||||
}
|
||||
adiabacityFunc(e, u)
|
||||
})
|
||||
).withNBkg()
|
||||
|
||||
@@ -262,7 +253,7 @@ suspend fun processCustom(
|
||||
@UnstableKMathAPI
|
||||
fun reportPage(
|
||||
spectrumFile: String,
|
||||
postfix: String?,
|
||||
postfix: String,
|
||||
data: XYErrorColumnarData<Double, Double, Double>,
|
||||
spectrum: NBkgSpectrum,
|
||||
fitParams: Map<Symbol, Double>,
|
||||
@@ -274,7 +265,7 @@ fun reportPage(
|
||||
): PlotlyPage {
|
||||
val report = Plotly.page {
|
||||
h3 {
|
||||
+"Fit for $spectrumFile ($postfix)"
|
||||
+"Fit for $spectrumFile${postfix.drop(1).takeIf { it.isNotEmpty() }?.let { " ($it)" } ?: ""}"
|
||||
}
|
||||
plot {
|
||||
scatter {
|
||||
|
||||
@@ -65,43 +65,33 @@ private class GridArgs : CliktCommand() {
|
||||
|
||||
val spectrum: String by argument().help("path to spectrum TSV file")
|
||||
val full: String? by option().help("path to full spectrum (for test)")
|
||||
|
||||
val postfix: String? by option().help("save file postfix")
|
||||
|
||||
val norm: Double by option().double().default(8.311751921319484E8).help("NBkgSpectrum.norm")
|
||||
val bkg: Double by option().double().default(1612.626961212948).help("NBkgSpectrum.bkg")
|
||||
|
||||
val bkg: Double by option().double().default(1612.626961212948).help("NBkgSpectrum.bkg")
|
||||
val fixBkg: Boolean by option().flag().help("Don't fit bkg variable")
|
||||
|
||||
val mnu2: Double by option().double().default(0.0).help("NumassBeta.mnu2")
|
||||
val e0: Double by option().double().default(18572.0).help("NumassBeta.e0")
|
||||
val msterile2: Double by option().double().default(0.0.pow(2)).help("NumassBeta.msterile2")
|
||||
val u2: Double by option().double().default(1e-2).help("NumassBeta.u2")
|
||||
|
||||
val fixU2: Boolean by option().flag().help("Don't fit u2 variable")
|
||||
val e0: Double by option().double().default(18572.0).help("NumassBeta.e0")
|
||||
val fixE0: Boolean by option().flag().help("Don't fit e0 variable")
|
||||
|
||||
val thickness: Double by option().double().default(0.3).help("NumassTransmission.thickness")
|
||||
|
||||
val trap: Double by option().double().default(1.0).help("NumassTransmission.trap")
|
||||
|
||||
val fixTrap: Boolean by option().flag().help("Don't fit trap variable")
|
||||
|
||||
val trapFunc: TrapModel by option().enum<TrapModel>().default(TrapModel.FINE_5DAY).help(
|
||||
"trap model"
|
||||
)
|
||||
val fixTrap: Boolean by option().flag().help("Don't fit trap variable")
|
||||
|
||||
|
||||
val rwall: Double by option().double().default(0.17).help("rear wall")
|
||||
|
||||
val wallFunc: WallModel by option().enum<WallModel>().default(WallModel.TSV_2025_12_01).help(
|
||||
"wall model"
|
||||
)
|
||||
|
||||
val fixRwall: Boolean by option().flag().help("Don't fit rwall variable")
|
||||
|
||||
val noAdiabacity: Boolean by option().flag().help("Use const 1 instead of adiabacity function")
|
||||
|
||||
val fixE0: Boolean by option().flag().help("Don't fit e0 variable")
|
||||
|
||||
val adiabacityFunc: AdiabaticityModel by option().enum<AdiabaticityModel>().default(AdiabaticityModel.`2024_11`)
|
||||
.help("adiabacity model")
|
||||
|
||||
@@ -121,13 +111,13 @@ private class GridArgs : CliktCommand() {
|
||||
@UnstableKMathAPI
|
||||
override fun run() {
|
||||
|
||||
val postfix = if (postfix != null) "-$postfix" else ""
|
||||
|
||||
val fitParamsBase: Map<Symbol, Double> = mapOf(
|
||||
NBkgSpectrum.norm to norm,
|
||||
NBkgSpectrum.bkg to bkg,
|
||||
NumassBeta.mnu2 to mnu2,
|
||||
NumassBeta.e0 to e0,
|
||||
NumassBeta.msterile2 to msterile2,
|
||||
NumassBeta.u2 to u2,
|
||||
NumassTransmission.thickness to thickness,
|
||||
NumassTransmission.trap to trap,
|
||||
rearWall to rwall
|
||||
@@ -141,14 +131,13 @@ private class GridArgs : CliktCommand() {
|
||||
},
|
||||
adjustX = false,
|
||||
), resolution = NumassResolution(1.7e-4, tailFunction = { e, u ->
|
||||
if (noAdiabacity) 1.0 else adiabacityFunc(e, u)
|
||||
adiabacityFunc(e, u)
|
||||
})
|
||||
).withNBkg()
|
||||
|
||||
val fitVars = mutableListOf(NBkgSpectrum.norm)
|
||||
if (!fixE0) fitVars += NumassBeta.e0
|
||||
if (!fixBkg) fitVars += NBkgSpectrum.bkg
|
||||
if (!fixU2) fitVars += NumassBeta.u2
|
||||
if (!fixTrap) fitVars += NumassTransmission.trap
|
||||
if (!fixRwall) fitVars += rearWall
|
||||
|
||||
@@ -166,7 +155,7 @@ private class GridArgs : CliktCommand() {
|
||||
extraM.forEach { mGrid.add(it) }
|
||||
mGrid = mGrid.sorted().distinct().toMutableList()
|
||||
|
||||
val reportsDir = dataPath.parent.resolve("${dataPath.nameWithoutExtension}.reports")
|
||||
val reportsDir = dataPath.parent.resolve("${dataPath.nameWithoutExtension}$postfix.reports")
|
||||
if (!noReports) reportsDir.createDirectories()
|
||||
|
||||
val chi2Matrix = mutableMapOf<Pair<Double, Double>, Double?>()
|
||||
@@ -179,7 +168,7 @@ private class GridArgs : CliktCommand() {
|
||||
val taskId = "${m.toInt()}_${String.format("%.0e", u2Val)}"
|
||||
|
||||
val fitParams = fitParamsBase.toMutableMap()
|
||||
fitParams[NumassBeta.msterile2] = m.pow(2)
|
||||
fitParams[NumassBeta.msterile2] = (m * 1000.0).pow(2)
|
||||
fitParams[NumassBeta.u2] = u2Val
|
||||
|
||||
val logMessages = mutableListOf<String>()
|
||||
@@ -219,7 +208,7 @@ private class GridArgs : CliktCommand() {
|
||||
}
|
||||
}
|
||||
}
|
||||
saveChi2GridToTsv(spectrum, mGrid, u2Grid, chi2Matrix)
|
||||
saveChi2GridToTsv(spectrum, postfix, mGrid, u2Grid, chi2Matrix)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,10 +226,17 @@ private fun generateLinearGrid(min: Double, max: Double, step: Double): List<Dou
|
||||
}
|
||||
|
||||
private fun saveChi2GridToTsv(
|
||||
spectrumFile: String, mGrid: List<Double>, u2Grid: List<Double>, chi2Matrix: Map<Pair<Double, Double>, Double?>
|
||||
spectrumFile: String,
|
||||
postfix: String,
|
||||
mGrid: List<Double>,
|
||||
u2Grid: List<Double>,
|
||||
chi2Matrix: Map<Pair<Double, Double>, Double?>
|
||||
) {
|
||||
val dataPath = Path(spectrumFile)
|
||||
val tsvPath = Path(dataPath.parent.toString(), dataPath.nameWithoutExtension + ".chi2_grid.tsv")
|
||||
val tsvPath = Path(
|
||||
dataPath.parent.toString(),
|
||||
dataPath.nameWithoutExtension + postfix + ".chi2_grid.tsv"
|
||||
)
|
||||
|
||||
File(tsvPath.toString()).printWriter().use { out ->
|
||||
out.print("m\\u2\t")
|
||||
|
||||
Reference in New Issue
Block a user