""" Control = numpy.load(os.path.join(sys.argv[2],"GUI","Control_List.npy")) dataDir=os.path.join(sys.argv[2],"simulation",sys.argv[1]+"_MeV") topDir=os.path.join(sys.argv[2]) alphaList=numpy.loadtxt(os.path.join(dataDir,"flat","alphaevents.txt")) maxNumberOfEvents=float(len(alphaList)) testMass= int(sys.argv[1])+(int(Control[4])/2.) productionAmplitudes=[] waves=getwaves(os.path.join(dataDir,"flat")) normint=numpy.load(os.path.join(dataDir,"flat","normint.npy")) if os.path.isfile(os.path.join(dataDir,"Vvalues.npy")): contents=numpy.load(os.path.join(dataDir,"Vvalues.npy")) orderedContents=sorted(contents.tolist().iteritems(),key=operator.itemgetter(0)) for i in range(0,len(orderedContents),2): realPart=orderedContents[i][1] imaginaryPart=orderedContents[i+1][1] productionAmplitudes.append(numpy.complex(realPart,imaginaryPart)) if sys.argv[3] == "s": nTrueList = [ntrue(productionAmplitudes,waves,normint)] for wave in waves: nTrueList.append(wave.filename.rstrip(".bamp")) nTrueList.append(ntrueforwave(productionAmplitudes[waves.index(wave)],waves,wave,normint).real)
""" .. module:: batchFarmServices :platform: Unix, Windows, OSX :synopsis: Utilities for doing PWA with the Jlab batch system. .. moduleauthor:: Joshua Pond <*****@*****.**> """ import os import sys sys.path.append(os.path.join(sys.argv[4], "pythonPWA")) import numpy from pythonPWA.fileHandlers.getWavesGen import getwaves from pythonPWA.model.normInt import normInt """ This is the program that does the work of calculating the normilization integral and returning it as a .npy file. """ dataDir = sys.argv[1] alphaList = numpy.loadtxt(os.path.join(dataDir, sys.argv[2])) waves = getwaves(dataDir) rInt = normInt(waves=waves, alphaList=alphaList, beamPolarization=sys.argv[3]) rInt.execute() rInt.save(dataDir)
from pythonPWA.fileHandlers.getWavesGen import getwaves from batchFarmServices.fast_like import FASTLikelihood from batchFarmServices.rhoAA import rhoAA import fnGenerator from iminuit import Minuit indir = sys.argv[2] Control = numpy.load(os.path.join(indir, "GUI", "Control_List.npy")) dataDir = os.path.join(indir, "fitting", sys.argv[1] + "_MeV") alphaList = numpy.loadtxt(os.path.join(dataDir, "data", "alphaevents.txt")) if os.path.isfile(os.path.join(dataDir, "data", "QFactor.txt")): QFactor = numpy.loadtxt(os.path.join(dataDir, "data", "QFactor.txt")) else: QFactor = [1] maxNumberOfEvents = float(len(alphaList)) waves = getwaves(os.path.join(dataDir, "data")) normint = numpy.load(os.path.join(dataDir, "mc", "raw", "normint.npy")) accNormInt = numpy.load(os.path.join(dataDir, "mc", "acc", "normint.npy")) acceptedPath = os.path.join(dataDir, "mc", "acc", "alphaevents.txt") generatedPath = os.path.join(dataDir, "mc", "raw", "alphaevents.txt") rAA = rhoAA(waves=waves, alphaList=alphaList, beamPolarization=float(Control[1])) rhoAA = rAA.calc() numpy.save(os.path.join(dataDir, "data", "rhoAA.npy"), rhoAA) minuitLn = FASTLikelihood(waves=waves, alphaList=alphaList, acceptedPath=acceptedPath, generatedPath=generatedPath, accNormInt=accNormInt, Q=QFactor,
from pythonPWA.fileHandlers.getWavesGen import getwaves from batchFarmServices.fast_like import FASTLikelihood from batchFarmServices.rhoAA import rhoAA import fnGenerator from iminuit import Minuit indir = sys.argv[2] Control = numpy.load(os.path.join(indir,"GUI","Control_List.npy")) dataDir=os.path.join(indir,"fitting",sys.argv[1]+"_MeV") alphaList=numpy.loadtxt(os.path.join(dataDir,"data","alphaevents.txt")) if os.path.isfile(os.path.join(dataDir,"data","QFactor.txt")): QFactor = numpy.loadtxt(os.path.join(dataDir,"data","QFactor.txt")) else: QFactor = [1] maxNumberOfEvents=float(len(alphaList)) waves=getwaves(os.path.join(dataDir,"data")) normint=numpy.load(os.path.join(dataDir,"mc","raw","normint.npy")) accNormInt=numpy.load(os.path.join(dataDir,"mc","acc","normint.npy")) acceptedPath=os.path.join(dataDir,"mc","acc","alphaevents.txt") generatedPath=os.path.join(dataDir,"mc","raw","alphaevents.txt") rAA = rhoAA(waves=waves,alphaList=alphaList,beamPolarization=float(Control[1])) rhoAA = rAA.calc() numpy.save(os.path.join(dataDir,"data","rhoAA.npy"),rhoAA) minuitLn=FASTLikelihood(waves=waves,alphaList=alphaList,acceptedPath=acceptedPath,generatedPath=generatedPath,accNormInt=accNormInt,Q=QFactor,rhoAA=rhoAA) if not os.path.isfile(os.path.join(sys.argv[2],"scripts","minInit.txt")): generator=fnGenerator.generator() generator.fileName=os.path.join(os.getcwd(),"generatedFn.py") generator.createFile(len(waves)*2) execfile(os.path.join(os.getcwd(),"generatedFn.py")) m.set_up(0.5)
alphaList=numpy.loadtxt(os.path.join(dataDir,"alphaevents.txt")) maxNumberOfEvents=float(len(alphaList)) testMass=1025. #resonances=[resonance(cR=maxNumberOfEvents,wR=[1.],w0=1320.,r0=100000.)] resonances=[resonance(cR=2.*maxNumberOfEvents/3.,wR=[0.,1.],w0=1320.,r0=107.),resonance(cR=maxNumberOfEvents/3.,wR=[1.,0.],w0=1895.,r0=235.)] waves=getwaves(dataDir) rInt=normInt(waves=waves,alphaList=alphaList) rInt.execute() rInt.save(dataDir) normint=numpy.load(os.path.join(dataDir,"normint.npy")) dSimulator=dataSimulator(mass=testMass,waves=waves,resonances=resonances,normint=normint,alphaList=alphaList) inputGampFile=open(os.path.join(dataDir,"events.gamp"),'r') inputPfFile=open(os.path.join(dataDir,"events.pf"),'r') outputRawGampFile=open(os.path.join(dataDir,"seq_raw_events.gamp"),'w') outputAccGampFile=open(os.path.join(dataDir,"selected_events.acc.gamp"),'w')
def calcNTrueForDir(dataDir): """ This function calculates the value of the total nTrue and the nTrue values for each wave for a single mass bin directory. Args: dataDir (string): The complete file path to the "mass_MeV" directory. """ #list to hold nTrue errors errorList=[] errorListEx=[] wvNameList=[] #getting our waves waves=getwaves(os.path.join(dataDir,"data")) #loading our accepted normalization integral (NOTE: its from the mc directory) accNormInt=numpy.load(os.path.join(dataDir,"mc","acc","normint.npy")) rawNormInt=numpy.load(os.path.join(dataDir,"mc","raw","normint.npy")) apath = os.path.join(dataDir,"mc","acc","alphaevents.txt") rpath = os.path.join(dataDir,"mc","raw","alphaevents.txt") #apath = os.path.join(dataDir,"mc","acc","events.num") #rpath = os.path.join(dataDir,"mc","raw","events.num") #instantiating our list of complex production amplitudes, should be ##a list of 2 numpy complexes contents=numpy.load(os.path.join(dataDir,"Vvalues.npy")) orderedContents=sorted(contents.tolist().iteritems(),key=operator.itemgetter(0)) vList=[] for i in range(0,len(orderedContents),2): realPart=orderedContents[i][1] imaginaryPart=orderedContents[i+1][1] vList.append(numpy.complex(realPart,imaginaryPart)) #calculating nTrue for both waves combined ntrueVal=ntrue(vList,waves,rawNormInt) nExpVal=nExp(vList,waves,accNormInt,apath,rpath) nTrueList=[] nExpList=[] #then storing it nTrueList.append(ntrueVal) nExpList.append(nExpVal) #next calculating nTrue for each wave for wave in waves: nTrueList.append(ntrueforwave(vList[waves.index(wave)],waves,wave,rawNormInt).real) nExpList.append(nExpforwave(vList[waves.index(wave)],waves,wave,accNormInt,apath,rpath).real) wvNameList.append(wave.filename) #next up lets load our raw normalization integral #loading our minuit covariance matrix obtained from fitting if os.path.isfile(os.path.join(dataDir,"minuitCovar3.npy")): covarianceMatrix=numpy.load(os.path.join(dataDir,"minuitCovar3.npy")) statSquared=calcStatSquaredError(covarianceMatrix,rawNormInt,vList,waves) statSquaredEx=calcStatSquaredError(covarianceMatrix,accNormInt,vList,waves) print statSquared print statSquaredEx errorList.append(numpy.sqrt(statSquared[0,0].real)) errorListEx.append(numpy.sqrt(statSquaredEx[0,0].real)) if not os.path.isfile(os.path.join(dataDir,"minuitCovar3.npy")): statSquared=0 errorList.append(0) statSquaredEx=0 errorListEx.append(0) for wave in waves: if statSquared != 0: buffer=numpy.zeros(shape=rawNormInt.shape) i=waves.index(wave) buffer[wave.epsilon,wave.epsilon,i,:]=rawNormInt[wave.epsilon,wave.epsilon,i,:] statSquared=calcStatSquaredError(covarianceMatrix,buffer,vList,waves) errorList.append(numpy.sqrt(statSquared[0,0].real)) buffer=numpy.zeros(shape=accNormInt.shape) i=waves.index(wave) buffer[wave.epsilon,wave.epsilon,i,:]=accNormInt[wave.epsilon,wave.epsilon,i,:] statSquared=calcStatSquaredError(covarianceMatrix,buffer,vList,waves) errorListEx.append(numpy.sqrt(statSquared[0,0].real)) else: errorList.append(0) errorListEx.append(0) #saving our results to be used in plotting later. format is numpy array [[nTrueTotal,nTrueWave1,nTrueWave2],[errorNTrueTotal,errorNTrueWave1,errorNTrueWave2]] #numpy.save(os.path.join(dataDir,"nTrueError.npy"),numpy.array([nTrueList,errorList])) retList=[] for i in range(len(nTrueList)): if i == 0: retList.append([dataDir.strip("_MeV"),nTrueList[i],errorList[i],nExpList[i],errorListEx[i]]) elif i > 0: retList.append([dataDir.strip("_MeV"),nTrueList[i],errorList[i],wvNameList[i-1],nExpList[i],errorListEx[i]]) return retList