Skip to content

Commit

Permalink
v0.1-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
cwsalgado committed Mar 4, 2015
1 parent 1edd87c commit d93c0bd
Show file tree
Hide file tree
Showing 97 changed files with 348 additions and 5,941 deletions.
9 changes: 9 additions & 0 deletions pythonPWA/batchFarmServices/GUI_alpha_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@
cf = numpy.load(os.path.join(indir,"GUI","Control_List.npy"))
i = 1
M= cf[0]
"""
This is the submition program for the alpha calculation.
"""

def submit(jsub_file):
"""
This function calls the JLab jsub command for a specific jsub .txt file created by this program.
Args:
jsub_file (string): The file name for the jsub file.
"""
cmd = 'jsub '+jsub_file
proc = Popen(cmd,
shell = True,
Expand Down
9 changes: 9 additions & 0 deletions pythonPWA/batchFarmServices/GUI_gamp_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@
keyfiles=glob.glob(os.path.join(keyfileDir,'*.keyfile'))
cf = numpy.load(os.path.join(indir,"GUI","Control_List.npy"))
i=1
"""
This is the submition program for gamp.
"""

def submit(jsub_file):
"""
This function calls the JLab jsub command for a specific jsub .txt file created by this program.
Args:
jsub_file (string): The file name for the jsub file.
"""
cmd = 'jsub '+jsub_file
proc = Popen(cmd,
shell = True,
Expand Down
9 changes: 9 additions & 0 deletions pythonPWA/batchFarmServices/GUI_subPyNormInt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
"""
import os, glob, sys, numpy, time
from subprocess import Popen
"""
This is submition program for the normint calculation
"""

indir = os.getcwd().strip("GUI")
cf = numpy.load(os.path.join(indir,"GUI","Control_List.npy"))
scriptOutDir=os.path.join(indir,"scripts","submitions")
i = 1

def submit(jsub_file):
"""
This function calls the JLab jsub command for a specific jsub .txt file created by this program.
Args:
jsub_file (string): The file name for the jsub file.
"""
cmd = 'jsub '+jsub_file
proc = Popen(cmd,
shell = True,
Expand Down
34 changes: 22 additions & 12 deletions pythonPWA/batchFarmServices/PWA_GUI
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import numpy, os
import subprocess as sp

class PWA_GUI(object):

"""
This program is the PWA_GUI, or main GUI for doing fitting and simulation in PyPWA.
"""

def back1(self):
frame2.grid_forget()
root.update()
self.destrFr1()
root.update()


def back2(self):
frame3.grid_forget()
Expand All @@ -19,8 +23,9 @@ class PWA_GUI(object):
btnF1.pack(side="top")
btnF2.pack(side="top")
btnF3.pack(side="top")
btnF4.pack(side="top")
btnB0.pack(side="bottom")
btnF4.pack(side="top")
btnGF.pack(side="top")
#btnB0.pack(side="bottom")
root.update()

def mvBAMP1(self):
Expand All @@ -31,7 +36,7 @@ class PWA_GUI(object):
btnOut.pack(side="top")
btnIn=tk.Button(frame2, text="IN", height=2 , width = 10,command= lambda: self.mvBAMP2("i"))
btnIn.pack(side="top")
btnB0.pack(side="bottom")
#btnB0.pack(side="bottom")
root.update()

def mvBAMP2(self,direct):
Expand Down Expand Up @@ -97,8 +102,9 @@ class PWA_GUI(object):
btnS2.pack(side="top")
btnS3.pack(side="top")
btnS4.pack(side="top")
btnS5.pack(side="top")
btnB0.pack(side="bottom")
btnS5.pack(side="top")
btnGS.pack(side="top")
#btnB0.pack(side="bottom")

def runD(self,prog,FoS):
if prog == 0:
Expand Down Expand Up @@ -136,7 +142,7 @@ class PWA_GUI(object):
btnR0=tk.Button(frame3, text="data", height=2 , width = 10,command= lambda: self.runD(prog,"y"))
btnR1=tk.Button(frame3, text="accMC", height=2 , width = 10,command= lambda: self.runaM(prog,"y"))
btnR2=tk.Button(frame3, text="rawMC", height=2 , width = 10,command= lambda: self.runrM(prog,"y"))
btnB1.grid(row=3,column=0,sticky="N"+"S"+"E"+"W")
#btnB1.grid(row=3,column=0,sticky="N"+"S"+"E"+"W")
if prog != 2:
btnR0.grid(row=0,column=0,sticky="N"+"S"+"E"+"W")
btnR1.grid(row=1,column=0,sticky="N"+"S"+"E"+"W")
Expand All @@ -145,7 +151,9 @@ class PWA_GUI(object):

def sim2(self,prog):
self.runF(prog,"n")


def destrFr1(self):
frame2.destroy()


PG = PWA_GUI()
Expand All @@ -166,17 +174,19 @@ btnS2=tk.Button(frame2, text="normint", height=2 , width = 10,command= lambda: P
btnS3=tk.Button(frame2, text="iList", height=2 , width = 10,command= lambda:sp.call([os.getcwd().strip("GUI")+"/scripts/subSimulator","i"]))
btnS4=tk.Button(frame2, text="iMax", height=2 , width = 10,command= lambda: sp.call(os.getcwd().strip("GUI")+"/scripts/getImax.py"))
btnS5=tk.Button(frame2, text="Simulator", height=2 , width = 10,command= lambda: sp.call([os.getcwd().strip("GUI")+"/scripts/subSimulator","s"]))
btnGS=tk.Button(frame2, text="GRAPHIC\nPLOT", height=2 , width = 10, command= lambda: sp.call(os.getcwd()+"/graphicPlotSim"))


btnF0=tk.Button(frame2, text="Run Gamp", height=2 , width = 10,command= lambda: PG.fitt2(0))
btnF1=tk.Button(frame2, text="Gen Alpha", height=2 , width = 10,command= lambda: PG.fitt2(1))
btnF2=tk.Button(frame2, text="normint", height=2 , width = 10,command= lambda: PG.fitt2(2))
btnF3=tk.Button(frame2, text="Fitter", height=2 , width = 10,command= lambda: sp.call(os.getcwd().strip("GUI")+"/scripts/subLikelihood"))
btnF4=tk.Button(frame2, text="nTrue", height=2 , width = 10,command= lambda: sp.call(os.getcwd().strip("GUI")+"/scripts/subWalkNTrue"))
btnGF=tk.Button(frame2, text="GRAPHIC\nPLOT", height=2 , width = 10, command= lambda: sp.call(os.getcwd()+"/graphicPlot"))

btnC=tk.Button(frame, text="PWA\nCONTROLS", height=2 , width = 10, command= lambda: sp.call(os.getcwd()+"/pwa_controls"))
btnC.pack(side="top")
btnG=tk.Button(frame, text="GRAPHIC\nPLOT", height=2 , width = 10, command= lambda: sp.call(os.getcwd()+"/graphicPlot"))
btnG.pack(side="top")

btnF=tk.Button(frame, text="FITTING", height=2 , width = 10, command= lambda: PG.fitt())
btnF.pack(side="top")
btnS=tk.Button(frame, text="SIMULATION", height=2 , width = 10,command= lambda: PG.sim())
Expand Down
42 changes: 36 additions & 6 deletions pythonPWA/batchFarmServices/dataSimulatorNPY.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,67 @@
from batchFarmServices.fast_like import FASTLikelihood

class dataSimulator(object):
"""description of class"""
"""
This is the program that does the work of simulation for PyPWA simulaton.
"""
def __init__(self,
mass=1010.,
waves=[],
normint=None,
productionAmplitudes=[],
alphaList=[],
beamPolarization=.4,
alphaList=[],
dataDir = None,
rhoAA=None,
iList=None,
iMax=0):

"""
Default FASTLikelihood constructor
Kwargs:
mass (float): Test mass at the center of the bin.
waves (array): Array of all waves in this pwa fit/simulation.
normint (array): PyPWA normalization integral object
productionAmplitudes (list): List of all production amplitudes/ V values.
alphaList (list): List of all alpha values for that bin.
dataDir (string): File path to the mass bin directory that is being simulated.
rhoAA (numpy ndarray): The PyPWA rhoAA object.
iList (numpy array): List of all intensities.
iMax (float): The maximum intensity for the whole mass range.
"""
self.mass=mass
self.waves=waves
self.normint=normint
self.productionAmplitudes=productionAmplitudes
self.alphaList=alphaList
self.beamPolarization=beamPolarization
self.alphaList=alphaList
self.dataDir=dataDir
self.rhoAA=rhoAA
self.iList=iList
self.iMax=iMax

def calcIList(self):
"""
Calculates the list of intensities.
Returns:
iList; Note, does NOT save it. Must be saved after returning.
"""

minuitLn=FASTLikelihood(waves=self.waves,productionAmplitudes=self.productionAmplitudes,rhoAA=self.rhoAA,accNormInt=self.normint)
iList = minuitLn.calcInt()

return iList

def execute(self,inputGampFile,outputRawGampFile,outputAccGampFile,inputPfFile,outputPFGampFile):
"""
This function does the bulk of the simulation work for PyPWA simulation.
Args:
inputGampFile (file): Open file with the flat .gamp events.
outputRawGampFile (file): Open file for the events that only pass the weight filter.
outputAccGampFile (file): Open file for the events that pass both the weight and p/f filter.
inputPfFile (file): Open file with the acceptance of the events (p/f).
outputPFGampFile (file): Open file for the events that only pass the p/f filter.
"""

#igreader=gampReader(gampFile=inputGampFile)
#inputGampEvents=igreader.readGamp()
Expand Down
File renamed without changes.
54 changes: 48 additions & 6 deletions pythonPWA/batchFarmServices/fast_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

import numpy as np
import os
"""
This is the mathmatical class of the likelihood calculation and the calculation of the intensity.
"""

class FASTLikelihood(object):

"""
This is the mathmatical class of the likelihood calculation and the calculation of the intensity.
"""
def __init__(self,
waves=[],
productionAmplitudes=[],
Expand All @@ -25,6 +24,18 @@ def __init__(self,
rhoAA = None,
accNormInt=None,
):
"""
Default FASTLikelihood constructor
Kwargs:
waves (array): Array of all waves in this pwa fit/simulation.
productionAmplitudes (list): List of all production amplitudes/ V values.
alphaList (list): List of all alpha values for that bin.
acceptedPath (string): Full file path to the accepted MC alpha file
generatedPath (string): Full file path to the generated MC alpha file
rhoAA (numpy ndarray array): PyPWA rhoAA array.
accNormInt (numpy array): The normalization integral from the accepted MC.
"""

self.waves=waves
self.productionAmplitudes=productionAmplitudes
Expand All @@ -44,15 +55,34 @@ def __init__(self,
# return float(num[0]) use it.

def countAlphas(self,path):
"""
Returns the length of an alpha file.
Args:
path (string): Path to the alpha file to be measured.
Returns:
Length of file. (float)
"""

Alpha = open(path,'r')
AlphaList = Alpha.readlines()
return float(len(AlphaList))

def calcetaX(self):
"""
Sets the self.etaX variable.
"""
self.etaX=(self.countAlphas(self.acceptedPath)/self.countAlphas(self.generatedPath))


def calclnL(self):
def calclnL(self):
"""
Calculates the value of the negative of the log likelihood function.
Returns:
Value of the negative of the log likelihood function. (float)
"""
a0 = 0.
a1 = 0.
for i in range(self.nwaves):
Expand All @@ -63,13 +93,25 @@ def calclnL(self):
return -((np.log(a0)).sum(0)) + (self.etaX * a1)

def calcneglnL(self,paramsList):
"""
Sets the production Amplitudes from Minuit and calculates the value of the negative of the log likelihood function.
Returns:
Value of the negative of the log likelihood function. (float)
"""
self.productionAmplitudes=paramsList
self.calcetaX()
LLog = self.calclnL()
print"LLog:",LLog
return LLog

def calcInt(self):
def calcInt(self):
"""
Calculates the list of intensities for a mass bin.
Returns:
iList (numpy array)
"""
a0 = 0.
for i in range(self.nwaves):
for j in range(self.nwaves):
Expand Down
5 changes: 4 additions & 1 deletion pythonPWA/batchFarmServices/fitting_Install
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import os
import numpy,sys
import subprocess as sp
from subprocess import Popen

"""
This program is the first step for the PyPWA fitting process. It sets up all directories and files needed for fitting
as well as all binning in mass as prescribed by the pwa_controls GUI.
"""
indir = os.path.split(os.path.split(os.getcwd())[0])[0]
print "Top Directory: ",indir
sys.path.append(os.path.join(indir,"pythonPWA"))
Expand Down
Loading

0 comments on commit d93c0bd

Please sign in to comment.