numass-framework/numass-main/src/main/groovy/inr/numass/scripts/SystTransmission.groovy

114 lines
3.8 KiB
Groovy
Raw Normal View History

2016-03-22 16:57:22 +03:00
/*
* Copyright 2015 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.scripts;
import hep.dataforge.context.GlobalContext;
import static hep.dataforge.context.GlobalContext.out;
import hep.dataforge.tables.ListTable;
2016-03-22 16:57:22 +03:00
import hep.dataforge.datafitter.FitManager;
import hep.dataforge.datafitter.FitState;
import hep.dataforge.datafitter.FitTask;
import hep.dataforge.datafitter.MINUITPlugin
import hep.dataforge.datafitter.ParamSet;
import hep.dataforge.datafitter.models.XYModel;
import hep.dataforge.exceptions.NamingException;
import hep.dataforge.exceptions.PackFormatException;
import inr.numass.data.SpectrumDataAdapter;
import inr.numass.data.SpectrumGenerator;
2016-05-25 12:18:43 +03:00
import inr.numass.models.BetaSpectrum
import inr.numass.models.ModularSpectrum
2016-03-22 16:57:22 +03:00
import inr.numass.models.NBkgSpectrum;
import inr.numass.models.ResolutionFunction
import inr.numass.utils.DataModelUtils;
import hep.dataforge.plotfit.PlotFitResultAction;
import hep.dataforge.plots.PlotFrame
2016-06-18 17:57:23 +03:00
import hep.dataforge.plots.data.PlottableXYFunction
2016-03-22 16:57:22 +03:00
import hep.dataforge.plots.jfreechart.JFreeChartFrame
import java.io.FileNotFoundException;
import java.util.Locale;
import org.apache.commons.math3.analysis.BivariateFunction
import static java.util.Locale.setDefault;
/**
*
* @author Darksnake
*/
setDefault(Locale.US);
new MINUITPlugin().startGlobal();
FitManager fm = new FitManager();
ResolutionFunction resolution = new ResolutionFunction(8.3e-5);
2016-03-27 20:40:50 +03:00
//resolution.setTailFunction(ResolutionFunction.getRealTail());
resolution.setTailFunction(ResolutionFunction.getAngledTail(0.00325));
2016-05-25 12:18:43 +03:00
ModularSpectrum beta = new ModularSpectrum(new BetaSpectrum(), resolution, 18395d, 18580d);
2016-03-22 16:57:22 +03:00
beta.setCaching(false);
NBkgSpectrum spectrum = new NBkgSpectrum(beta);
XYModel model = new XYModel("tritium", spectrum, new SpectrumDataAdapter());
ParamSet allPars = new ParamSet();
2016-03-27 20:40:50 +03:00
allPars.setPar("N", 6e9, 1e5, 0, Double.POSITIVE_INFINITY);
2016-03-22 16:57:22 +03:00
2016-03-27 20:40:50 +03:00
allPars.setPar("bkg", 0.002, 0.005 );
2016-03-22 16:57:22 +03:00
allPars.setPar("E0", 18575.0, 0.1 );
allPars.setPar("mnu2", 0, 2);
def mster = 3000;// Mass of sterile neutrino in eV
allPars.setPar("msterile2", mster**2, 1);
allPars.setPar("U2", 0, 1e-4);
allPars.setPar("X", 0, 0.05, 0d, Double.POSITIVE_INFINITY);
allPars.setPar("trap", 1, 0.01, 0d, Double.POSITIVE_INFINITY);
int seed = 12316
SpectrumGenerator generator = new SpectrumGenerator(model, allPars, seed);
2016-03-27 20:40:50 +03:00
def config = DataModelUtils.getUniformSpectrumConfiguration(18530d, 18580, 1e7, 60)
2016-03-22 16:57:22 +03:00
//def config = DataModelUtils.getSpectrumConfigurationFromResource("/data/run23.cfg")
ListTable data = generator.generateExactData(config);
2016-03-22 16:57:22 +03:00
FitState state = new FitState(data, model, allPars);
2016-03-27 20:40:50 +03:00
println("Simulating data with real tail")
2016-03-22 16:57:22 +03:00
println("Fitting data with real parameters")
2016-03-27 20:40:50 +03:00
FitState res = fm.runTask(state, "QOW", FitTask.TASK_RUN, "N", "bkg", "E0", "mnu2");
2016-03-22 16:57:22 +03:00
res.print(out());
def mnu2 = res.getParameters().getValue("mnu2");
println("Setting constant tail and fitting")
resolution.setTailFunction(ResolutionFunction.getConstantTail());
2016-03-27 20:40:50 +03:00
res = fm.runTask(state, "QOW", FitTask.TASK_RUN, "N", "bkg","E0","mnu2");
2016-03-22 16:57:22 +03:00
res.print(out());
def diff = res.getParameters().getValue("mnu2") - mnu2;
println("\n\nSquared mass difference: ${diff}")