Exemple #1
0
def LoadLifetimesNorm(FitType, PathToFile):
    if FitType == 'P**n':
        #if was calculated using pax_v6.2.0 or younger
        PaxCorrectionTime, PaxCorrection, PaxCorrectionUncertainty = FormPars.GetLifetimeCorrectionPAX(
        )
        # if was calculated using Rn + Po instead of separating
        PoRnCorrectionTime, PoRnCorrection, PoRnCorrectionUncertainty = FormPars.GetPoRnCorrection(
        )

    fin = open(PathToFile)
    lines = fin.readlines()
    fin.close()

    Unixtimes = []
    UnixtimeErrors = []
    ELifeValues = []
    ELifeValueErrors = []

    for i, line in enumerate(lines):
        if line[0] == '#':
            continue

        contents = line[:-1].split("\t\t")
        unixtime = float(contents[0])
        unixtime_err = float(contents[1])
        value = float(contents[2])
        value_err = float(contents[3])

        # account for LCE
        if FitType == 'SingleScatter':
            S1ExponentialConstant = FormPars.GetS1ExponentialConstant()
            value = value * S1ExponentialConstant / (S1ExponentialConstant -
                                                     value)
            value_err = value * np.sqrt(
                np.power(value_err / value, 2.0) +
                np.power(value_err / (S1ExponentialConstant - value), 2.))
            if value_err < 0.:
                continue

        elif FitType == 'P**n':
            if unixtime < PaxCorrectionTime:
                value, value_err = ApplyLifetimeCorrection(
                    value, value_err, PaxCorrection, PaxCorrectionUncertainty)

            if unixtime < PoRnCorrectionTime:
                value, value_err = ApplyLifetimeCorrection(
                    value, value_err, PoRnCorrection,
                    PoRnCorrectionUncertainty)


#                print(unixtime)
#            value, value_err = ApplyLifetimeCorrection(value, value_err, RnCorrection, RnCorrectionUncertainty)

        Unixtimes.append(unixtime)
        UnixtimeErrors.append(unixtime_err)
        ELifeValues.append(value)
        ELifeValueErrors.append(value_err)

    return (Unixtimes, UnixtimeErrors, ELifeValues, ELifeValueErrors)
    def __init__(self, SCPickleFile):
        self.ReferenceUnixTime = 0
        self.SpecialPeriod = FormPars.GetSpecialPeriods()
        #        self.SpecialPeriod = [
        #                                         [1465913920, 1466517600]
        #                                        ] # in this period don't do the valve status treatment
        # during the gas only period, the circulation route is very different
        # see: https://xecluster.lngs.infn.it/dokuwiki/lib/exe/fetch.php?media=xenon:xenon1t:org:commissioning:meetings:160817:xenon1t-operating_modes-circulation-mode_3_x-circulation_gxe_high_flow-v0.pdf
        # so now the total flow is not basically the sum of FCV201&FCV202
        # but only FCV201
        self.GasOnlyPeriod = FormPars.GetGasOnlyPeriods()
        #        self.GasOnlyPeriod = [
        #                                              [1471900000, 1472840000],# the end day is 09/10 temporarily
        #                                             ]
        # configuration for getter deficiency periods and fraction
        self.GetterDeficiencyConfigs = []
        #        self.ProbableCathodeRange1 = [10, 20.]
        #        self.ProbableCathodeRange2 = [7., 10.]
        if not self.LoadFile(SCPickleFile):
            raise ValueError("SC pickle file error!")
#        self.MaximumHeatingPower = 260. # W
        self.MaximumHeatingPower = FormPars.GetMaximumHeatingPower()  # W
        return
Exemple #3
0
def LnLike(x):
    start_time = time.time()
    pars, IfOutOfBoundary = FormPars.FormPars(x, MinUnixTime, MaxUnixTime)
    if IfOutOfBoundary:
        #        print("Out of boundary!")
        return -np.inf
    global pElectronLifetimeTrend
    pElectronLifetimeTrend.SetParameters(pars)
    #    print("==== The parameters: =====")
    #    print(pElectronLifetimeTrend.GetParameters())
    LnL = LnLikeData()
    #    print(" LnL = "+str(LnL))
    #    print("=====================")
    #    print("Takes: "+str(time.time()-start_time) + " sec")
    return LnL
Exemple #4
0
    print("======== Syntax: =======")
    print("python ConvertEvolution.py .....")
    print("<Rn222 elife data txt file>")
    #    print("<Kr83 elife data txt file>")
    print("<prediction txt file> ")
    exit()

PathToLifetimesRn222 = sys.argv[1]
#PathToLifetimesKr83       = sys.argv[2]
PathToLifetimePredictions = sys.argv[2]

PathContents = PathToLifetimePredictions.split('/')
PathToKrLifetimeFile = '/'.join(
    PathContents[:-1]) + '/Kr83m/Kr_' + PathContents[-1]

ChangeVal, ChangeValErr = FormPars.GetKrCorrection()

(Rn222Unixtimes, Rn222UnixtimeErrors, Rn222ELifeValues,
 Rn222ELifeValueErrors) = np.asarray(
     MCMC_Tools.LoadFitData('Rn222', PathToFile=PathToLifetimesRn222))

#(
#    KrUnixtimes,
#    KrUnixtimeErrors,
#    KrELifeValues,
#    KrELifeValueErrors) = np.asarray(MCMC_Tools.LoadFitData('Kr83', PathToFile=PathToLifetimesKr83))

ScienceRunStartUnixtime = 1486054320
ScienceRunEndUnixtime = max(Rn222Unixtimes)
ScienceRunStartDatetime = datetime.datetime.fromtimestamp(
    ScienceRunStartUnixtime)
Exemple #5
0
    print("python PredictElectronLifetime.py")
    print("<Historian file>")
    print("<Fit result pickle>")
    print("<Prediction txt output>")
    print("<burn-in iteraction cut>")
    print("NOTICE: do remember to add \"-r\" at the end")
    exit()

SSELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeData_SingleScatter_ForV2Fitting.txt'
PoRnELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/old/pre_time_dependent_3d_fdc/ElectronLifetimeDataWithPoRn.txt'
Po218ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithPo218_1day_new_wobad.txt'
Rn220ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithRn220_1day_new_wobad.txt'
Rn222ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithRn222_1day_new_wobad.txt'
FileParams = '/dali/lgrandi/kobayashi1/xenon/analysis/ElectronLifetime/ElectronLifetime/PythonCodeELMCMCndna_semi_final24_2/TEMP_Param.txt'

MinUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMinTimeStamp())
MaxUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMaxTimeStamp())
#parser = argparse.ArgumentParser()
#parser.add_argument('--min_unixtime', type=int, help='Minimum unixtime', default=MinUnixTime)
#parser.add_argument('--max_unixtime', type=int, help='Maximum unixtime', default=MaxUnixTime)
#parser.add_argument('--include_firstss',type=int, choices=[0, 1], help='Include first ss combined fits', default=1)
#
#args = parser.parse_args()
#
#IncludeFirstSS               = args.include_firstss
#MinUnixTime                  = args.min_unixtime
#MaxUnixTime                  = args.max_unixtime
#verbose                      = args.verbose

HistorianFile = sys.argv[1]
FitResultInput = sys.argv[2]
if len(sys.argv) > 2:
    BurnInCutOff = int(sys.argv[2])



MCMC_Results = pickle.load(open(sPathToPickleMCMC, 'rb'))
sampler = MCMC_Results['sampler']
ndim = sampler.__dict__['dim']
niterations = sampler.__dict__['iterations']
nwalkers = sampler.__dict__['k']
chain = sampler.__dict__['_chain']

TotalEvents = chain.shape[1]

ParInfo = FormPars.GetParInfo()
ParNames = [ParInfo[i][0] for i in range(ndim)] # parameter names
ParDescs = [ParInfo[i][1] for i in range(ndim)] # parameter description
ParUnits = [ParInfo[i][2] for i in range(ndim)] # parameter units

#print(chain.shape)

assert TotalEvents == niterations
assert len(ParNames) == chain.shape[2]



#####################################
########  make corner plot  #########
#####################################
    print("<Fit result pickle>")
    print("<Prediction txt output>")
    print("<burn-in iteraction cut>")
    print("NOTICE: do remember to add \"-r\" at the end")
    exit()

HistorianFile = sys.argv[1]
FitResultInput = sys.argv[2]
PredictionOutputFile = sys.argv[3]
BurnInCutOff = int(sys.argv[4])

NumOfInterpolation = 2000
NumOfTrials = 400

# setting the parameters
MinUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMinTimeStamp())
#MaxUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMaxTimeStamp())
MaxUnixTime = 1533081600
default_pars = FormPars.GetDefaultPars()

#############################
## Get the MCMC result
#############################
import pickle
MCMCResults = pickle.load(open(FitResultInput, 'rb'))
sampler = MCMCResults['sampler']
ndim = sampler.__dict__['dim']
niterations = sampler.__dict__['iterations']
nwalkers = sampler.__dict__['k']
print(sampler)
print(ndim, nwalkers, niterations)
    print("< elife data txt file> ")
    print("<P**n elife data txt file>")
    print("<Kr83 elife data txt file>")
    print("< prediction txt file> ")
    print("< days to show after last data point >")
    print("<save fig name (rel.)>")
    exit()

ELifeDataFile = sys.argv[1]
PoRnELifeDataFile = sys.argv[2]
Kr83ELifeDataFile = sys.argv[3]
PredictionFile = sys.argv[4]
DaysAfterLastPoint = float(sys.argv[5])
FigureSaveName = sys.argv[6]

ScienceRunUnixtimes = FormPars.GetScienceRunUnixtimes()

Xe40kevELifeDataFile = '/home/zgreene/xenon1t/ElectronLifetime/FitData/ElectronLifetimeDataWithXe40keV.txt'
Xe129mELifeDataFile = '/home/zgreene/xenon1t/ElectronLifetime/FitData/ElectronLifetimeDataWithXe129m.txt'
Xe131mELifeDataFile = '/home/zgreene/xenon1t/ElectronLifetime/FitData/ElectronLifetimeDataWithXe131m.txt'
Rn222ELifeDataFile = '/home/zgreene/xenon1t/ElectronLifetime/FitData/ElectronLifetimeWithRn222.txt'
Po218ELifeDataFile = '/home/zgreene/xenon1t/ElectronLifetime/FitData/ElectronLifetimeWithPo218.txt'
Rn220ELifeDataFile = '/home/zgreene/xenon1t/ElectronLifetime/FitData/ElectronLifetimeWithRn220.txt'

ShowResiduals = False
ShowResiduals = True

#######################################
### Get elife data
#######################################
(UnixTimes, UnixTimeErrors, ELifeValues,
Exemple #9
0
import Fit_func2

from iminuit import Minuit

StartingTimeFit = time.time()
NumOfInterpolation = 1000

SSELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeData_SingleScatter_ForV2Fitting.txt'
PoRnELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/old/pre_time_dependent_3d_fdc/ElectronLifetimeDataWithPoRn_mod.txt'
Po218ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithPo218_1day_new_wobad.txt'
Rn220ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithRn220_1day_new_wobad.txt'
Rn222ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithRn222_1day_new_UB.txt'
FileParams = 'TEMP_Param.txt'

FormPars = MyFormPars()
MinUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMinTimeStamp())
MaxUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMaxTimeStamp())

parser = argparse.ArgumentParser()
parser.add_argument('historian_file',
                    type=str,
                    help='Path to historian pickle file')
parser.add_argument('prediction_output_file',
                    type=str,
                    help='Path to prediction output file')
parser.add_argument('--output_file',
                    type=str,
                    help='Output file name',
                    default='')
parser.add_argument('--nwalkers',
                    type=int,
Exemple #10
0
Rn222ELifeDataFile = '/home/zgreene/xenon1t/ElectronLifetime/FitData/ElectronLifetimeDataWithRn222.txt'

HistorianFile = sys.argv[1]
FitOutput = sys.argv[2]
ElectronLifetimeDataFile = sys.argv[3]
PoRnElectronLifetimeDataFile = sys.argv[4]

# pre-walking
nwalkers = int(sys.argv[5])
niterations = int(sys.argv[6])
threads = int(sys.argv[7])
PreWalkingPickleFilename = "NoneExist"
if len(sys.argv) > 8:
    PreWalkingPickleFilename = sys.argv[8]

print('\nFitting Electron Lifetime between ' + FormPars.GetMinTimeStamp() +
      ' and ' + FormPars.GetMaxTimeStamp() + '\n')

print('\nRunning with %i threads\n' % threads)
# setting the parameters
MinUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMinTimeStamp())
MaxUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMaxTimeStamp())
default_pars = FormPars.GetDefaultPars()

# initial parameters
x0, x0_steps = FormPars.GetInitialParametersMCMC()

# The main Light yield Trend
pElectronLifetimeTrend = MyElectronLifetimeTrend(HistorianFile, MinUnixTime,
                                                 MaxUnixTime, default_pars)
import MCMC_Tools
from MCMC_Tools import *

import Fit_func2

StartingTimeFit = time.time()

SSELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeData_SingleScatter_ForV2Fitting.txt'
PoRnELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/old/pre_time_dependent_3d_fdc/ElectronLifetimeDataWithPoRn_mod.txt'
Po218ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithPo218_1day_new_wobad.txt'
Rn220ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithRn220_1day_new_wobad.txt'
Rn222ELifeDataFile = '/home/kobayashi1/work/xenon/analysis/ElectronLifetime/ElectronLifetime/FitData/Lifetimes/ElectronLifetimeDataWithRn222_1day_new_UB.txt'
FileParams = 'TEMP_Param.txt'

FormPars = MyFormPars()
MinUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMinTimeStamp())
MaxUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMaxTimeStamp())

parser = argparse.ArgumentParser()
parser.add_argument('historian_file',
                    type=str,
                    help='Path to historian pickle file')
parser.add_argument('output_file', type=str, help='Output file name')
parser.add_argument('nwalkers', type=int, help='Number of walkers')
parser.add_argument('niterations', type=int, help='Number of iterations')
parser.add_argument('--nthreads',
                    type=int,
                    help='Number of threads',
                    default=1)
parser.add_argument('--pre_fit_file',
                    type=str,
Exemple #12
0
    print("<burn-in iteraction cut>")
    print("NOTICE: do remember to add \"-r\" at the end")
    exit()

HistorianFile = sys.argv[1]
FitResultInput = sys.argv[2]
PredictionOutputFile = sys.argv[3]
BurnInCutOff = int(sys.argv[4])


NumOfInterpolation = 1000
NumOfTrials = 1000


# setting the parameters
MinUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMinTimeStamp())
MaxUnixTime = GetUnixTimeFromTimeStamp(FormPars.GetMaxTimeStamp()) + 100*24*3600
default_pars = FormPars.GetDefaultPars()


#############################
## Get the MCMC result
#############################
import pickle
MCMCResults = pickle.load(open(FitResultInput, 'rb'))
sampler = MCMCResults['sampler']
ndim = sampler.__dict__['dim']
niterations = sampler.__dict__['iterations']
nwalkers = sampler.__dict__['k']
print(ndim, nwalkers, niterations)
    def GetInterpolationCathode(self, Dict):
        UnixTimes = Dict['unixtimes']
        Values = Dict['values']
        MinUnixTime = min(UnixTimes)
        MaxUnixTime = max(UnixTimes)
        ReturnValues = []
        previousValue = 15.  #default
        CathodeVoltages = FormPars.GetCathodeVoltages()
        for unixtime, value in zip(UnixTimes, Values):
            for Array in CathodeVoltages:
                if unixtime >= Array[0][0] and unixtime < Array[0][1]:
                    # force voltage to take on value
                    if Array[1][0] == Array[1][1]:
                        value = Array[1][0]
                        ReturnValues.append(value)
                        previousValue = value
                    else:
                        if value >= Array[1][0] and value < Array[1][1]:
                            ReturnValues.append(value)
                            previousValue = value
                        else:
                            ReturnValues.append(previousValue)
                    continue
#        for unixtime, value in zip(UnixTimes, Values):
#            if unixtime < 1484768100:
#                if unixtime >  1473956519 and unixtime < 1473997763:
#                    value = 15.
#                    ReturnValues.append(value)
#                    previousValue = value
#                    continue
#                if unixtime >  1475301507 and unixtime < 1475391507:
#                    value = 12.
#                    ReturnValues.append(value)
#                    previousValue = value
#                    continue
#                elif value<self.ProbableCathodeRange1[0] or value>self.ProbableCathodeRange1[1]:
#                    ReturnValues.append(previousValue)
#                    continue
#                ReturnValues.append( value )
#                previousValue = value
#            elif unixtime >= 1484768100 and unixtime < 1484949120:
#                value = 0.
#                ReturnValues.append( value )
#                previousValue = value
#            elif unixtime >= 1484949120 and unixtime < 1485445200:
#                value = 9.
#                ReturnValues.append( value )
#                previousValue = value
#            elif unixtime >= 1485445200 and unixtime < 1485802500:
#                value = 0.
#                ReturnValues.append( value )
#                previousValue = value
#            elif unixtime >= 1485802500 and unixtime < 1486054320:
#                value = 7.
#                ReturnValues.append( value )
#                previousValue = value
#            elif unixtime >= 1486054320 and unixtime < 1487265420:
#                value = 8.
#                ReturnValues.append( value )
#                previousValue = value
#            else:
#                if value<self.ProbableCathodeRange2[0] or value>self.ProbableCathodeRange2[1]:
#                    ReturnValues.append(previousValue)
#                    continue
#                ReturnValues.append( value )
#                previousValue = value

        return (MinUnixTime, MaxUnixTime, interp1d(UnixTimes, ReturnValues))