From d93c0bde5c477347e10a2fb4b4782cc7ef92a6f1 Mon Sep 17 00:00:00 2001 From: cwsalgado Date: Wed, 4 Mar 2015 13:58:26 -0500 Subject: [PATCH] v0.1-beta --- pythonPWA/batchFarmServices/GUI_alpha_main.py | 9 + pythonPWA/batchFarmServices/GUI_gamp_main.py | 9 + .../batchFarmServices/GUI_subPyNormInt.py | 9 + pythonPWA/batchFarmServices/PWA_GUI | 34 +- .../batchFarmServices/dataSimulatorNPY.py | 42 +- .../batchFarmServices/farmCheck.py | 0 pythonPWA/batchFarmServices/fast_like.py | 54 +- pythonPWA/batchFarmServices/fitting_Install | 5 +- .../batchFarmServices/generateAlphaNPY.py | 36 +- pythonPWA/batchFarmServices/getImax.py | 3 + pythonPWA/batchFarmServices/graphicPlot | 5 +- .../batchFarmServices/graphicPlotSim | 0 pythonPWA/batchFarmServices/massBinner.py | 36 +- pythonPWA/batchFarmServices/mvBAMP_GUI | 7 +- .../batchFarmServices/pwa_SIM.py | 0 pythonPWA/batchFarmServices/pwa_controls | 3 + pythonPWA/batchFarmServices/rhoAA.py | 23 +- .../batchFarmServices/run_normintFARM.py | 4 +- .../batchFarmServices/simulation_Install | 9 +- pythonPWA/batchFarmServices/simulatorMain.py | 12 +- pythonPWA/batchFarmServices/subLikelihood | 30 +- pythonPWA/batchFarmServices/subSimulator | 26 + pythonPWA/batchFarmServices/subWalkNTrue | 27 +- pythonPWA/batchFarmServices/walkingNTrue.py | 9 +- .../batchFarmServices/GUI_alpha_main.py | 95 --- .../batchFarmServices/GUI_gamp_main.py | 98 ---- .../batchFarmServices/GUI_subPyNormInt.py | 83 --- pythonPWA/pythonPWA/batchFarmServices/PWA_GUI | 200 ------- .../pythonPWA/batchFarmServices/__init__.py | 4 - .../batchFarmServices/dataSimulatorNPY.py | 112 ---- .../pythonPWA/batchFarmServices/fast_like.py | 121 ---- .../batchFarmServices/fitting_Install | 74 --- .../batchFarmServices/fnGenerator.py | 81 --- .../batchFarmServices/generateAlphaNPY.py | 279 --------- .../pythonPWA/batchFarmServices/getImax.py | 28 - .../batchFarmServices/graphicHelp.py | 107 ---- .../pythonPWA/batchFarmServices/graphicPlot | 543 ------------------ .../pythonPWA/batchFarmServices/gui_submit | 151 ----- .../batchFarmServices/likelihoodTest.py | 55 -- .../pythonPWA/batchFarmServices/massBinner.py | 202 ------- .../pythonPWA/batchFarmServices/mvBAMP_GUI | 54 -- .../pythonPWA/batchFarmServices/pwa_controls | 240 -------- .../batchFarmServices/resonances.txt | 6 - .../pythonPWA/batchFarmServices/rhoAA.py | 58 -- .../batchFarmServices/run_normintFARM.py | 24 - .../batchFarmServices/simulation_Install | 74 --- .../batchFarmServices/simulatorMain.py | 114 ---- .../pythonPWA/batchFarmServices/subLikelihood | 87 --- .../pythonPWA/batchFarmServices/subSimulator | 98 ---- .../pythonPWA/batchFarmServices/subWalkNTrue | 82 --- .../batchFarmServices/walkingNTrue.py | 126 ---- .../pythonPWA/fileHandlers/gampTranslator.py | 4 + pythonPWA/pythonPWA/pythonPWA/__init__.py | 3 - .../pythonPWA/pythonPWA/dataTypes/__init__.py | 3 - .../pythonPWA/dataTypes/gampEvent.py | 54 -- .../pythonPWA/dataTypes/gampParticle.py | 47 -- .../pythonPWA/dataTypes/resonance.py | 40 -- .../pythonPWA/pythonPWA/dataTypes/wave.py | 42 -- .../pythonPWA/fileHandlers/__init__.py | 4 - .../pythonPWA/fileHandlers/bampReader.py | 27 - .../pythonPWA/fileHandlers/gampReader.py | 73 --- .../pythonPWA/fileHandlers/gampTranslator.py | 121 ---- .../pythonPWA/fileHandlers/getWaves.py | 29 - .../pythonPWA/fileHandlers/getWavesGen.py | 48 -- .../pythonPWA/pythonPWA/model/__init__.py | 5 - .../pythonPWA/pythonPWA/model/complexV.py | 30 - pythonPWA/pythonPWA/pythonPWA/model/getPhi.py | 22 - .../pythonPWA/pythonPWA/model/intensity.py | 89 --- pythonPWA/pythonPWA/pythonPWA/model/magV.py | 18 - .../pythonPWA/pythonPWA/model/nExpected.py | 53 -- pythonPWA/pythonPWA/pythonPWA/model/nTrue.py | 122 ---- .../pythonPWA/pythonPWA/model/normInt.py | 87 --- .../pythonPWA/pythonPWA/model/prodAmp.py | 76 --- .../pythonPWA/pythonPWA/model/spinDensity.py | 30 - .../pythonPWA/pythonPWA/utilities/FourVec.py | 133 ----- .../pythonPWA/utilities/LorentzTransform.py | 83 --- .../pythonPWA/utilities/OHMintensity.py | 120 ---- .../pythonPWA/pythonPWA/utilities/ThreeVec.py | 116 ---- .../pythonPWA/pythonPWA/utilities/__init__.py | 3 - .../pythonPWA/utilities/breitWigner.py | 27 - .../pythonPWA/pythonPWA/utilities/chunks.py | 8 - .../pythonPWA/utilities/countGampSet.py | 26 - .../pythonPWA/utilities/dataSimulator.py | 100 ---- .../pythonPWA/utilities/dataSimulatorFarm.py | 74 --- .../pythonPWA/utilities/devTestFarm.py | 49 -- .../pythonPWA/utilities/fnGenerator.py | 86 --- .../pythonPWA/utilities/gampSlist.py | 86 --- .../pythonPWA/utilities/generatePureWave.py | 80 --- .../pythonPWA/utilities/likelihood.py | 82 --- .../pythonPWA/utilities/minuitLikelihood.py | 188 ------ .../pythonPWA/utilities/phaseMotion.py | 57 -- .../pythonPWA/utilities/plotGampEvents.py | 40 -- .../pythonPWA/utilities/plotNTrue.py | 32 -- .../pythonPWA/pythonPWA/utilities/plotter.py | 38 -- .../pythonPWA/utilities/pwa_controls | 175 ------ .../pythonPWA/pythonPWA/utilities/randM.py | 23 - .../pythonPWA/pythonPWA/utilities/rotation.py | 48 -- 97 files changed, 348 insertions(+), 5941 deletions(-) rename pythonPWA/{pythonPWA => }/batchFarmServices/farmCheck.py (100%) rename pythonPWA/{pythonPWA => }/batchFarmServices/graphicPlotSim (100%) rename pythonPWA/{pythonPWA => }/batchFarmServices/pwa_SIM.py (100%) delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/GUI_alpha_main.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/GUI_gamp_main.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/GUI_subPyNormInt.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/PWA_GUI delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/__init__.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/dataSimulatorNPY.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/fast_like.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/fitting_Install delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/fnGenerator.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/generateAlphaNPY.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/getImax.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/graphicHelp.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/graphicPlot delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/gui_submit delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/likelihoodTest.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/massBinner.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/mvBAMP_GUI delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/pwa_controls delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/resonances.txt delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/rhoAA.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/run_normintFARM.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/simulation_Install delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/simulatorMain.py delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/subLikelihood delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/subSimulator delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/subWalkNTrue delete mode 100755 pythonPWA/pythonPWA/batchFarmServices/walkingNTrue.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/__init__.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/dataTypes/__init__.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/dataTypes/gampEvent.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/dataTypes/gampParticle.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/dataTypes/resonance.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/dataTypes/wave.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/fileHandlers/__init__.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/fileHandlers/bampReader.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/fileHandlers/gampReader.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/fileHandlers/gampTranslator.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/fileHandlers/getWaves.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/fileHandlers/getWavesGen.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/__init__.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/complexV.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/getPhi.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/intensity.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/magV.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/nExpected.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/nTrue.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/normInt.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/prodAmp.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/model/spinDensity.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/FourVec.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/LorentzTransform.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/OHMintensity.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/ThreeVec.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/__init__.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/breitWigner.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/chunks.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/countGampSet.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/dataSimulator.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/dataSimulatorFarm.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/devTestFarm.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/fnGenerator.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/gampSlist.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/generatePureWave.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/likelihood.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/minuitLikelihood.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/phaseMotion.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/plotGampEvents.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/plotNTrue.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/plotter.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/pwa_controls delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/randM.py delete mode 100644 pythonPWA/pythonPWA/pythonPWA/utilities/rotation.py diff --git a/pythonPWA/batchFarmServices/GUI_alpha_main.py b/pythonPWA/batchFarmServices/GUI_alpha_main.py index 6abc7e7d..abec4f9b 100755 --- a/pythonPWA/batchFarmServices/GUI_alpha_main.py +++ b/pythonPWA/batchFarmServices/GUI_alpha_main.py @@ -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, diff --git a/pythonPWA/batchFarmServices/GUI_gamp_main.py b/pythonPWA/batchFarmServices/GUI_gamp_main.py index 5aebea33..68f16eec 100755 --- a/pythonPWA/batchFarmServices/GUI_gamp_main.py +++ b/pythonPWA/batchFarmServices/GUI_gamp_main.py @@ -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, diff --git a/pythonPWA/batchFarmServices/GUI_subPyNormInt.py b/pythonPWA/batchFarmServices/GUI_subPyNormInt.py index f7d583eb..1520fecb 100755 --- a/pythonPWA/batchFarmServices/GUI_subPyNormInt.py +++ b/pythonPWA/batchFarmServices/GUI_subPyNormInt.py @@ -10,6 +10,9 @@ """ 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")) @@ -17,6 +20,12 @@ 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, diff --git a/pythonPWA/batchFarmServices/PWA_GUI b/pythonPWA/batchFarmServices/PWA_GUI index 9b81c24a..49775e6a 100755 --- a/pythonPWA/batchFarmServices/PWA_GUI +++ b/pythonPWA/batchFarmServices/PWA_GUI @@ -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() @@ -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): @@ -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): @@ -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: @@ -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") @@ -145,7 +151,9 @@ class PWA_GUI(object): def sim2(self,prog): self.runF(prog,"n") - + + def destrFr1(self): + frame2.destroy() PG = PWA_GUI() @@ -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()) diff --git a/pythonPWA/batchFarmServices/dataSimulatorNPY.py b/pythonPWA/batchFarmServices/dataSimulatorNPY.py index b8291a80..0733bde7 100755 --- a/pythonPWA/batchFarmServices/dataSimulatorNPY.py +++ b/pythonPWA/batchFarmServices/dataSimulatorNPY.py @@ -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() diff --git a/pythonPWA/pythonPWA/batchFarmServices/farmCheck.py b/pythonPWA/batchFarmServices/farmCheck.py similarity index 100% rename from pythonPWA/pythonPWA/batchFarmServices/farmCheck.py rename to pythonPWA/batchFarmServices/farmCheck.py diff --git a/pythonPWA/batchFarmServices/fast_like.py b/pythonPWA/batchFarmServices/fast_like.py index 999b826a..2f63cee8 100755 --- a/pythonPWA/batchFarmServices/fast_like.py +++ b/pythonPWA/batchFarmServices/fast_like.py @@ -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=[], @@ -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 @@ -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): @@ -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): diff --git a/pythonPWA/batchFarmServices/fitting_Install b/pythonPWA/batchFarmServices/fitting_Install index 5d3c69d6..b6fca474 100755 --- a/pythonPWA/batchFarmServices/fitting_Install +++ b/pythonPWA/batchFarmServices/fitting_Install @@ -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")) diff --git a/pythonPWA/batchFarmServices/generateAlphaNPY.py b/pythonPWA/batchFarmServices/generateAlphaNPY.py index ef4182ac..9f962092 100755 --- a/pythonPWA/batchFarmServices/generateAlphaNPY.py +++ b/pythonPWA/batchFarmServices/generateAlphaNPY.py @@ -15,10 +15,23 @@ import math class generateAlphas(object): + """ + This program calculates the value of alpha for every event in a .gamp file and saves it to a .txt list, one event per line. + """ + alphaName = "alpha" labelOut = "" def __init__(self, mode, indir, gfile): + """ + Default generatAlphas constructor + + Kwargs: + mode (int): 8 = p pi+ pi- pi0, 22 = p p+ p-, 24 = p k+ k-, 42 = gamma p --> p Ks Ks (pi+ pi- pi+ pi-) + indir (string): Full file path to directory of file + gfile (string): File name without .gamp extension. + """ + self.mode = mode self.indir = indir self.gfile = gfile+".gamp" @@ -40,10 +53,11 @@ def __init__(self, mode, indir, gfile): self.analyze42() if self.mode == "EtaPiN": self.analyzeEtaPiN - ''' - p pi+ pi- pi0 - ''' + def analyze8(self): + ''' + p pi+ pi- pi0 + ''' for i in range(int(self.gampList.shape[0])): event = self.gampT.writeEvent(self.gampList[i,:,:]) for particles in event.particles: @@ -83,10 +97,11 @@ def analyze8(self): sys.stdout.write(str(i)+"\r") sys.stdout.flush() self.alphalist.append(alpha) - ''' - p p+ p- - ''' + def analyze22(self): + ''' + p p+ p- + ''' for i in range(int(self.gampList.shape[0])): event = self.gampT.writeEvent(self.gampList[i,:,:]) for particles in event.particles: @@ -123,6 +138,9 @@ def analyze22(self): def analyze24(self): + """ + p k+ k- + """ for i in range(int(self.gampList.shape[0])): event = self.gampT.writeEvent(self.gampList[i,:,:]) for particles in event.particles: @@ -164,6 +182,9 @@ def analyze24(self): self.alphalist.append(alpha) def analyze42(self): + """ + gamma p --> p Ks Ks (pi+ pi- pi+ pi-) + """ for i in range(int(self.gampList.shape[0])): event = self.gampT.writeEvent(self.gampList[i,:,:]) nks = 0 @@ -240,6 +261,9 @@ def analyzeEtaPiN(self): def toFile(self): + """ + Saves the list to a file. + """ f = open(os.path.join(self.indir, self.alphaName), 'w') for alpha in self.alphalist: f.write(str(alpha) + "\n") diff --git a/pythonPWA/batchFarmServices/getImax.py b/pythonPWA/batchFarmServices/getImax.py index 2b767172..1d8e4c17 100755 --- a/pythonPWA/batchFarmServices/getImax.py +++ b/pythonPWA/batchFarmServices/getImax.py @@ -10,6 +10,9 @@ """ import numpy import os +""" + This program runs in the interactive farm to retrieve the maximum intensity value among the whole mass range. +""" topDir = os.getcwd().rstrip("GUI") diff --git a/pythonPWA/batchFarmServices/graphicPlot b/pythonPWA/batchFarmServices/graphicPlot index 549309e5..13242aed 100755 --- a/pythonPWA/batchFarmServices/graphicPlot +++ b/pythonPWA/batchFarmServices/graphicPlot @@ -11,7 +11,10 @@ import argparse sys.path.append(os.path.join(os.getcwd().strip("GUI"),"pythonPWA")) from batchFarmServices.graphicHelp import Help class graphicPlot(object): - + """ + This is the graphicPlot GUI optimized for fitting. + """ + def __init__(self, topDir = os.getcwd().strip("GUI"), dataL = [], diff --git a/pythonPWA/pythonPWA/batchFarmServices/graphicPlotSim b/pythonPWA/batchFarmServices/graphicPlotSim similarity index 100% rename from pythonPWA/pythonPWA/batchFarmServices/graphicPlotSim rename to pythonPWA/batchFarmServices/graphicPlotSim diff --git a/pythonPWA/batchFarmServices/massBinner.py b/pythonPWA/batchFarmServices/massBinner.py index 36a5b12c..1688de52 100755 --- a/pythonPWA/batchFarmServices/massBinner.py +++ b/pythonPWA/batchFarmServices/massBinner.py @@ -15,13 +15,23 @@ from pythonPWA.utilities.FourVec import FourVector from pythonPWA.fileHandlers.gampTranslator import gampTranslator """ - This is the pyPWA mass binning utility + This is the PyPWA mass binning utility that simulation/fitting install uses to bin .gamp files in mass. """ class massBinner(object): def __init__(self,indir=None,bindir=None,gfile=None,verb="q"): + """ + This is the default massBinner constructor. + + Kwargs: + indir (string): The full file path to the top directory. + bindir (string): The full file path to the directory where the new mass bin directories will be written. + gfile (string): The name of the .gamp file to be binned. (/Without/ the .gamp extension.) + verb (string): either "q" for quiet or "v" for verbose. + """ + self.indir = indir self.bindir = bindir self.Control = np.load(os.path.join(sys.argv[1],"GUI","Control_List.npy")) @@ -34,12 +44,21 @@ def __init__(self,indir=None,bindir=None,gfile=None,verb="q"): if not os.path.isfile(os.path.join(self.indir,self.nfile)): if self.verb == "v": print "Starting translator, for",self.gfile - self.gampT.translate(os.path.join(self.indir,self.nfile)) - self.gampList=np.load(os.path.join(self.indir,self.nfile)) + self.gampList=self.gampT.translate(os.path.join(self.indir,self.nfile)) self.nBins = int(((int(self.Control[3])-int(self.Control[2]))/int(self.Control[4])))+1 self.bins = np.zeros(shape=(self.nBins,int(self.gampList.shape[0]))) def calcMass(self,event): + """ + This function calculates the mass of a single event. + + Args: + event (PyPWA gampEvent object) + + Returns: + mass of the event (float) + """ + mass = FourVector(E=[0,0,0,0]) for part in range(len(event.particles)): if part > 1 and event.particles[part].particleID != 0: @@ -51,6 +70,10 @@ def calcMass(self,event): return math.sqrt(mass.dot(mass)) def binner(self): + """ + Creates a pass/fail 2D array mask for all bins and events. + """ + for i in range(int(self.gampList.shape[0])): event = self.gampT.writeEvent(self.gampList[i,:,:]) mass = self.calcMass(event) @@ -63,6 +86,13 @@ def binner(self): np.save("bins",self.bins) def fill(self,direct): + """ + Uses the bins p/f array mask to create all bin directories and fill all binned .gamp files. + + Args: + direct (string): keyword the program uses to know what kind of .gamp file is being binned and the directories to make. + """ + if self.verb == "v": print "\nStarting binner" self.binner() diff --git a/pythonPWA/batchFarmServices/mvBAMP_GUI b/pythonPWA/batchFarmServices/mvBAMP_GUI index 1159b86b..d9f9076e 100755 --- a/pythonPWA/batchFarmServices/mvBAMP_GUI +++ b/pythonPWA/batchFarmServices/mvBAMP_GUI @@ -14,8 +14,11 @@ from subprocess import Popen nfile = sys.argv[2]+".bamp" oI = sys.argv[1] +""" + This is the program used by the PWA_GUI's wave function to move .bamp files between the fit/simulation and the /overflow directory. +""" -if os.path.isdir(os.path.join(os.getcwd().strip("GUI"),"fitting"): +if os.path.isdir(os.path.join(os.getcwd().strip("GUI"),"fitting")): for d in os.listdir(os.path.join(os.getcwd().strip("GUI"),"fitting")): if "_MeV" in d: for m in ("mc","data"): @@ -37,7 +40,7 @@ if os.path.isdir(os.path.join(os.getcwd().strip("GUI"),"fitting"): sys.stdout.write(d.rstrip("_MeV")+"\r") sys.stdout.flush() print "DONE " -elif os.path.isdir(os.path.join(os.getcwd().strip("GUI"),"simulation"): +elif os.path.isdir(os.path.join(os.getcwd().strip("GUI"),"simulation")): for d in os.listdir(os.path.join(os.getcwd().strip("GUI"),"simulation")): if "_MeV" in d: if oI == "o": diff --git a/pythonPWA/pythonPWA/batchFarmServices/pwa_SIM.py b/pythonPWA/batchFarmServices/pwa_SIM.py similarity index 100% rename from pythonPWA/pythonPWA/batchFarmServices/pwa_SIM.py rename to pythonPWA/batchFarmServices/pwa_SIM.py diff --git a/pythonPWA/batchFarmServices/pwa_controls b/pythonPWA/batchFarmServices/pwa_controls index 5c7d9aca..6d62af89 100755 --- a/pythonPWA/batchFarmServices/pwa_controls +++ b/pythonPWA/batchFarmServices/pwa_controls @@ -17,6 +17,9 @@ else: from graphicHelp import Help class Control(object): + """ + This program is the pwa_controls GUI, or the gui the user uses to specify environment variables for PyPWA. + """ def __init__(self, reactMode = 24, diff --git a/pythonPWA/batchFarmServices/rhoAA.py b/pythonPWA/batchFarmServices/rhoAA.py index fb47d694..512bd5f7 100755 --- a/pythonPWA/batchFarmServices/rhoAA.py +++ b/pythonPWA/batchFarmServices/rhoAA.py @@ -12,12 +12,25 @@ from pythonPWA.model.spinDensity import spinDensity class rhoAA(object): + """ + This class calculates the 3D numpy array, rhoAA. Each value is the spin density matrix times a wave times the complex conjugate of another wave and + possibly times Q. + """ def __init__(self, waves=[], alphaList=[], Q = [1], beamPolarization=0.4): - + """ + Default rhoAA constructor. + + Kwargs: + waves (array): Array of all waves in this pwa fit/simulation. + alphaList (list): List of all alpha values for this mass bin. + Q (list): List of all Q values for this mass bin. + beamPolarization (float): Value of beam polarization; 0.0 for no polarization. + + """ self.waves=waves self.alphaList=alphaList self.Q = Q @@ -26,7 +39,13 @@ def __init__(self, self.nwaves=len(self.waves) self.rhoAA = np.empty(shape=(self.nwaves,self.nwaves,self.eventNumber),dtype=np.complex) - def calc(self): + def calc(self): + """ + Function that does the work of calculating rhoAA + + Return: + rhoAA (numpy ndarray): Note, this class does NOT save the array and must be saved after returning. + """ for n in range(self.eventNumber): for i,iwave in enumerate(self.waves): for j,jwave in enumerate(self.waves): diff --git a/pythonPWA/batchFarmServices/run_normintFARM.py b/pythonPWA/batchFarmServices/run_normintFARM.py index da58ca6f..9a7e8611 100755 --- a/pythonPWA/batchFarmServices/run_normintFARM.py +++ b/pythonPWA/batchFarmServices/run_normintFARM.py @@ -13,7 +13,9 @@ 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) diff --git a/pythonPWA/batchFarmServices/simulation_Install b/pythonPWA/batchFarmServices/simulation_Install index bb5638d4..03074aa8 100755 --- a/pythonPWA/batchFarmServices/simulation_Install +++ b/pythonPWA/batchFarmServices/simulation_Install @@ -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 simulation process. It sets up all directories and files needed for simulation + 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")) @@ -32,7 +35,7 @@ for i in tdirs: os.makedirs(directoryBuffer) progs = ("generateAlphaNPY.py","GUI_alpha_main.py", "GUI_gamp_main.py","GUI_subPyNormInt.py","mvBAMP_GUI", -"run_normintFARM.py","massBinner.py","dataSimulatorNPY.py", +"run_normintFARM.py","massBinner.py", "getImax.py","resonances.txt","simulatorMain.py","subSimulator") for s in progs: cmd = 'cp '+os.path.join(os.getcwd(),str(s))+" "+os.path.join(indir,"scripts") @@ -44,7 +47,7 @@ for s in progs: elif s == progs[-1]: sys.stdout.write("Filling scripts"+"."*(progs.index(s)+1)+"\r\n") sys.stdout.flush() -guis = ("graphicPlot","pwa_controls","PWA_GUI","Control_List.npy") +guis = ("graphicPlotSim","pwa_controls","PWA_GUI","Control_List.npy") for g in guis: if g != guis[-1]: cmd = 'cp '+os.path.join(os.getcwd(),str(g))+" "+os.path.join(indir,"GUI") diff --git a/pythonPWA/batchFarmServices/simulatorMain.py b/pythonPWA/batchFarmServices/simulatorMain.py index 49aa9f4e..868ca568 100755 --- a/pythonPWA/batchFarmServices/simulatorMain.py +++ b/pythonPWA/batchFarmServices/simulatorMain.py @@ -18,8 +18,16 @@ from pythonPWA.model.nTrue import nTrueForFixedV1V2 as ntrue from pythonPWA.model.nTrue import nTrueForFixedV1V2AndWave as ntrueforwave import operator - from batchFarmServices.rhoAA import rhoAA +""" + This is the main simualtion program for PyPWA simulation. It creates the iList and the simulated gamp files. It can do this using the + fitted V values or from the pre chosen waves and resonences. + + Args: + bin (string) + topDir (string) + output (char) +""" Control = numpy.load(os.path.join(sys.argv[2],"GUI","Control_List.npy")) @@ -50,7 +58,7 @@ for wave in waves: nTrueList.append(wave.filename.rstrip(".bamp")) nTrueList.append(ntrueforwave(productionAmplitudes[waves.index(wave)],waves,wave,normint).real) - numpy.save(os.path.join(dataDir,"flat","nTrueListV.npy"),nTrueList) + numpy.save(os.path.join(dataDir,"flat","nTrueListR.npy"),nTrueList) elif os.path.isfile(os.path.join(topDir,"scripts","resonances.txt")): resonances=[] res = open(os.path.join(topDir,"scripts","resonances.txt")) diff --git a/pythonPWA/batchFarmServices/subLikelihood b/pythonPWA/batchFarmServices/subLikelihood index 290bcc13..42fb04b1 100755 --- a/pythonPWA/batchFarmServices/subLikelihood +++ b/pythonPWA/batchFarmServices/subLikelihood @@ -14,8 +14,17 @@ from subprocess import Popen indir = os.getcwd().strip("GUI") Control = numpy.load(os.path.join(indir,"GUI","Control_List.npy")) scriptOutDir=os.path.join(indir,"scripts","submitions") +""" + This is submition program for the likelihood program +""" 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, @@ -24,6 +33,16 @@ def submit(jsub_file): time.sleep(.5) def gen(directory,cmd): + """ + This function creates the jsub .txt file to be submitted to the JLab batch farm. + + Args: + directory (string): The file name for the jsub file. + cmd (string): The full command to be used in the jsub file. + + Returns: + jsub_filename (string): name of the jsub file created by this function. + """ auger_opts = dict( project = Control[9], track = 'analysis', @@ -46,7 +65,16 @@ COMMAND:{cmd} jsub_file.close() return jsub_filename -def parseDir(Bin): +def parseDir(Bin): + """ + This function creates the cmd string to be submitted to the JLab batch farm. + + Args: + bin (int): The int value for the mass in MeV for the mass bin. + + Returns: + cmd (string): The full command to be used in the jsub file. + """ cmd = os.path.join(indir,"scripts","likelihoodTest.py")+" "+str(Bin)+" "+indir return cmd diff --git a/pythonPWA/batchFarmServices/subSimulator b/pythonPWA/batchFarmServices/subSimulator index c133ab22..31e99617 100755 --- a/pythonPWA/batchFarmServices/subSimulator +++ b/pythonPWA/batchFarmServices/subSimulator @@ -16,8 +16,17 @@ import time, sys, numpy indir = os.getcwd().strip("GUI") Control = numpy.load(os.path.join(indir,"GUI","Control_List.npy")) scriptOutDir=os.path.join(indir,"scripts","submitions") +""" + This is submition program for the simulator. +""" 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, @@ -29,7 +38,16 @@ def submit(jsub_file): def gen(directory,cmd): + """ + This function creates the jsub .txt file to be submitted to the JLab batch farm. + Args: + directory (string): The file name for the jsub file. + cmd (string): The full command to be used in the jsub file. + + Returns: + jsub_filename (string): name of the jsub file created by this function. + """ auger_opts = dict( project = Control[9], track = 'analysis', @@ -56,7 +74,15 @@ COMMAND:{cmd} return jsub_filename def parseDir(Bin): + """ + This function creates the cmd string to be submitted to the JLab batch farm. + + Args: + bin (int): The int value for the mass in MeV for the mass bin. + Returns: + cmd (string): The full command to be used in the jsub file. + """ cmd = "/u/apps/anaconda/anaconda-2.0.1/bin/python2 "+os.path.join(indir,"scripts","simulatorMain.py")+" "+str(Bin)+" "+indir+" "+sys.argv[1] return cmd diff --git a/pythonPWA/batchFarmServices/subWalkNTrue b/pythonPWA/batchFarmServices/subWalkNTrue index b3f787b5..83211ecd 100755 --- a/pythonPWA/batchFarmServices/subWalkNTrue +++ b/pythonPWA/batchFarmServices/subWalkNTrue @@ -16,6 +16,12 @@ Control = numpy.load(os.path.join(indir,"GUI","Control_List.npy")) scriptOutDir=os.path.join(indir,"scripts","submitions") 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, @@ -24,6 +30,16 @@ def submit(jsub_file): time.sleep(.5) def gen(directory,cmd): + """ + This function creates the jsub .txt file to be submitted to the JLab batch farm. + + Args: + directory (string): The file name for the jsub file. + cmd (string): The full command to be used in the jsub file. + + Returns: + jsub_filename (string): name of the jsub file created by this function. + """ auger_opts = dict( project = Control[9], track = 'analysis', @@ -44,7 +60,16 @@ COMMAND:{cmd} jsub_file.close() return jsub_filename -def parseDir(Bin): +def parseDir(Bin): + """ + This function creates the cmd string to be submitted to the JLab batch farm. + + Args: + bin (int): The int value for the mass in MeV for the mass bin. + + Returns: + cmd (string): The full command to be used in the jsub file. + """ cmd = os.path.join(indir,"scripts","walkingNTrue.py")+" "+str(Bin)+" "+indir return cmd diff --git a/pythonPWA/batchFarmServices/walkingNTrue.py b/pythonPWA/batchFarmServices/walkingNTrue.py index 85e5c5da..68b08532 100755 --- a/pythonPWA/batchFarmServices/walkingNTrue.py +++ b/pythonPWA/batchFarmServices/walkingNTrue.py @@ -25,7 +25,14 @@ from pythonPWA.model.nTrue import calcStatSquaredError import operator -def calcNTrueForDir(dataDir): +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=[] diff --git a/pythonPWA/pythonPWA/batchFarmServices/GUI_alpha_main.py b/pythonPWA/pythonPWA/batchFarmServices/GUI_alpha_main.py deleted file mode 100755 index abec4f9b..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/GUI_alpha_main.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import os, glob, numpy, sys, time -from subprocess import Popen - -indir = os.getcwd().strip("GUI") -dataDir=os.path.join(indir,"fitting") -scriptOutDir=os.path.join(indir,"scripts","submitions") -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, - executable = os.environ.get('SHELL', '/bin/tcsh'), - env = os.environ) - time.sleep(.5) - -BoA = sys.argv[1] -if BoA == 'n': - DoM = sys.argv[2] - if DoM == 'weight': - dataDir=os.path.join(indir,"simulation") - AoR = sys.argv[3] - stri = '/'+DoM+'/'+AoR - filen = 'events' - elif DoM == 'flat': - dataDir=os.path.join(indir,"simulation") - stri = 'flat' - filen = 'events' -elif BoA == 'y': - DoM = sys.argv[2] - if DoM == 'mc': - dataDir=os.path.join(indir,"fitting") - AoR = sys.argv[3] - stri = '/'+DoM+'/'+AoR - filen = 'events' - elif DoM == 'data': - dataDir=os.path.join(indir,"fitting") - stri = DoM - filen = 'events' -for path, subdirs, files in os.walk(dataDir): - for filename in glob.glob(path): - if stri in filename: - cmd_opts = dict( - indir = indir, - cwd = os.path.join(indir,"scripts"), - filen = filen, - direct = filename+'/', - mode = M) - cmd = '''/u/apps/anaconda/anaconda-2.0.1/bin/python2 {cwd}/generateAlphaNPY.py {mode} {direct} {filen} {indir} - '''.format(**cmd_opts) - auger_opts = dict( - project = cf[9], - track = 'analysis', - jobname = 'AlphaGen', - os = 'centos65', - memory = '3000 MB', - time = 300, - cmd = cmd) - jsub_filename = os.path.join(scriptOutDir,"subAlpha"+str(i)) - jsub_file = open(jsub_filename,'w') - jsub_file.write('''\ -PROJECT: {project} -TRACK: {track} -JOBNAME: {jobname} -OS: {os} -MEMORY: {memory} -TIME: {time} -COMMAND: {cmd} - '''.format(**auger_opts)) - jsub_file.close() - print jsub_filename - submit(jsub_filename) - #os.remove(jsub_filename) - i += 1 diff --git a/pythonPWA/pythonPWA/batchFarmServices/GUI_gamp_main.py b/pythonPWA/pythonPWA/batchFarmServices/GUI_gamp_main.py deleted file mode 100755 index 68f16eec..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/GUI_gamp_main.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import os, glob, sys, time, numpy -from subprocess import Popen - -indir = os.getcwd().strip("GUI") -keyfileDir=os.path.join(indir,"keyfiles") -dataDir=os.path.join(indir,"fitting") -scriptOutDir=os.path.join(indir,"scripts","submitions") -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, - executable = os.environ.get('SHELL', '/bin/tcsh'), - env = os.environ) - time.sleep(.5) - -BoA = sys.argv[1] -if BoA == 'n': - DoM = sys.argv[2] - if DoM == 'weight': - dataDir=os.path.join(indir,"simulation") - AoR = sys.argv[3] - stri = '/'+DoM+'/'+AoR - filen = 'events' - elif DoM == 'flat': - dataDir=os.path.join(indir,"simulation") - stri = 'flat' - filen = 'events' -elif BoA == 'y': - DoM = sys.argv[2] - if DoM == 'mc': - dataDir=os.path.join(indir,"fitting") - AoR = sys.argv[3] - stri = '/'+DoM+'/'+AoR - filen = 'events' - elif DoM == 'data': - dataDir=os.path.join(indir,"fitting") - stri = 'data' - filen = 'events' -for keyfile in keyfiles: - for path, subdirs, files in os.walk(dataDir): - if stri in path: - for filename in glob.glob(os.path.join(path,'*.gamp')): - filename = os.path.basename(filename) - cmd_opts = dict( - outfile = os.path.join(path,os.path.basename(keyfile)).replace('.keyfile','.bamp'), - keyfile = os.path.join(keyfileDir,keyfile), - infile = os.path.join(path, filename)) - cmd = '''\ -/group/clas/builds/centos65/bin/gamp {keyfile} < {infile} > {outfile} - '''.format(**cmd_opts) - auger_opts = dict( - project = cf[9], - track = 'analysis', - jobname = 'runGamp', - os = 'centos65', - time = 360, - memory = '1000 MB', - cmd = cmd) - jsub_filename = os.path.join(scriptOutDir,"subGamp"+str(i)) - jsub_file = open(jsub_filename,'w') - jsub_file.write('''\ -PROJECT: {project} -TRACK: {track} -JOBNAME: {jobname} -OS: {os} -TIME: {time} -MEMORY: {memory} -COMMAND: {cmd} - '''.format(**auger_opts)) - jsub_file.close() - print jsub_filename - #if not os.path.isfile(os.path.join(path,os.path.basename(keyfile)).replace('.keyfile','.bamp')): - submit(jsub_filename) - #os.remove(jsub_filename) - i += 1 diff --git a/pythonPWA/pythonPWA/batchFarmServices/GUI_subPyNormInt.py b/pythonPWA/pythonPWA/batchFarmServices/GUI_subPyNormInt.py deleted file mode 100755 index 1520fecb..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/GUI_subPyNormInt.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -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, - executable = os.environ.get('SHELL', '/bin/tcsh'), - env = os.environ) - time.sleep(.5) - -BoA = sys.argv[1] -if BoA == 'n': - dataDir=os.path.join(indir,"simulation") - AoR = sys.argv[2] - stri = 'flat' - name = 'alphaevents.txt' -elif BoA == 'y': - dataDir=os.path.join(indir,"fitting") - AoR = sys.argv[2] - stri = '/mc/'+AoR - name = "alphaevents.txt" -for path, subdirs, files in os.walk(dataDir): - for filename in glob.glob(path): - if stri in filename: - cmd_opts = dict( - cwd = os.path.join(indir,"scripts"), - dirc = path, - name = name, - beamP = cf[1], - indir = indir - ) - cmd = '''/u/apps/anaconda/anaconda-2.0.1/bin/python2 {cwd}/run_normintFARM.py {dirc} {name} {beamP} {indir} - '''.format(**cmd_opts) - auger_opts = dict( - project = cf[9], - track = 'analysis', - jobname = 'normINT', - os = 'centos65', - memory = '3000 MB', - time = 360, - cmd = cmd) - jsub_filename = os.path.join(scriptOutDir,"subNormINT"+str(i)) - jsub_file = open(jsub_filename,'w') - jsub_file.write('''\ -PROJECT: {project} -TRACK: {track} -JOBNAME: {jobname} -OS: {os} -MEMORY: {memory} -TIME: {time} -COMMAND: {cmd} - '''.format(**auger_opts)) - - jsub_file.close() - print jsub_filename - submit(jsub_filename) - #os.remove(jsub_filename) - i += 1 diff --git a/pythonPWA/pythonPWA/batchFarmServices/PWA_GUI b/pythonPWA/pythonPWA/batchFarmServices/PWA_GUI deleted file mode 100755 index 49775e6a..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/PWA_GUI +++ /dev/null @@ -1,200 +0,0 @@ -#! /usr/bin/python -import Tkinter as tk -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): - self.destrFr1() - root.update() - - - def back2(self): - frame3.grid_forget() - root.update() - - def fitt(self): - frame2.grid(row=0,column=1,sticky="N"+"S"+"E"+"W") - btnF0.pack(side="top") - btnF1.pack(side="top") - btnF2.pack(side="top") - btnF3.pack(side="top") - btnF4.pack(side="top") - btnGF.pack(side="top") - #btnB0.pack(side="bottom") - root.update() - - def mvBAMP1(self): - frame2.grid(row=0,column=1,sticky="N"+"S"+"E"+"W") - label=tk.Label(frame2, text="Move waves in,\n or out of Fit?") - label.pack(side="top", fill="both", padx=10, pady=10) - btnOut=tk.Button(frame2, text="OUT", height=2 , width = 10,command= lambda: self.mvBAMP2("o")) - 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") - root.update() - - def mvBAMP2(self,direct): - if "fitting" in os.listdir(os.path.join(os.getcwd().strip("GUI"))): - for d in os.listdir(os.path.join(os.getcwd().strip("GUI"),"fitting")): - if "_MeV" in d: - bin1 = d - break - frame3.grid(row=0,column=2,sticky="N"+"S"+"E"+"W") - wvs = [] - if direct == "o": - for x in os.listdir(os.path.join(os.getcwd().strip("GUI"),"fitting",bin1,"data")): - if ".bamp" in x: - wvs.append(x) - elif direct == "i": - for x in os.listdir(os.path.join(os.getcwd().strip("GUI"),"fitting","overflow",bin1)): - if "data" in x: - wvs.append(x.strip("data")) - x = 0 - t = 0 - for y in range(len(wvs)): - btn = tk.Button(frame3, text = wvs[y].strip(".bamp"), height=2 , width = 15,command = lambda y=y: self.mvBAMP3(direct,wvs[y].strip(".bamp"))) - btn.grid(column=x,row=t) - t += 1 - if t > 9: - t = 0 - x += 1 - btnB1.grid(row=t+1,column=0,sticky="N"+"S"+"E"+"W") - - elif "simulation" in os.listdir(os.path.join(os.getcwd().strip("GUI"))): - for d in os.listdir(os.path.join(os.getcwd().strip("GUI"),"simulation")): - if "_MeV" in d: - bin1 = d - break - frame3.grid(row=0,column=2,sticky="N"+"S"+"E"+"W") - wvs = [] - if direct == "o": - for x in os.listdir(os.path.join(os.getcwd().strip("GUI"),"simulation",bin1,"flat")): - if ".bamp" in x: - wvs.append(x) - elif direct == "i": - for x in os.listdir(os.path.join(os.getcwd().strip("GUI"),"simulation","overflow",bin1)): - if "flat" in x: - wvs.append(x.strip("flat")) - x = 0 - t = 0 - for y in range(len(wvs)): - btn = tk.Button(frame3, text = wvs[y].strip(".bamp"), height=2 , width = 15,command = lambda y=y: self.mvBAMP3(direct,wvs[y].strip(".bamp"))) - btn.grid(column=x,row=t) - t += 1 - if t > 9: - t = 0 - x += 1 - btnB1.grid(row=t+1,column=0,sticky="N"+"S"+"E"+"W") - - def mvBAMP3(self,direct,bamp): - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","mvBAMP_GUI"),str(direct),str(bamp)]) - - def sim(self): - frame2.grid(row=0,column=1,sticky="N"+"S"+"E"+"W") - btnS0.pack(side="top") - btnS1.pack(side="top") - btnS2.pack(side="top") - btnS3.pack(side="top") - btnS4.pack(side="top") - btnS5.pack(side="top") - btnGS.pack(side="top") - #btnB0.pack(side="bottom") - - def runD(self,prog,FoS): - if prog == 0: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_gamp_main.py"),str(FoS),"data"]) - if prog == 1: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_alpha_main.py"),str(FoS),"data"]) - - def runF(self,prog,FoS): - if prog == 0: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_gamp_main.py"),str(FoS),"flat"]) - if prog == 1: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_alpha_main.py"),str(FoS),"flat"]) - if prog == 2: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_subPyNormInt.py"),str(FoS),"flat"]) - - def runaM(self,prog,FoS): - if prog == 0: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_gamp_main.py"),str(FoS),"mc","acc"]) - if prog == 1: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_alpha_main.py"),str(FoS),"mc","acc"]) - if prog == 2: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_subPyNormInt.py"),str(FoS),"acc"]) - - def runrM(self,prog,FoS): - if prog == 0: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_gamp_main.py"),str(FoS),"mc","raw"]) - if prog == 1: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_alpha_main.py"),str(FoS),"mc","raw"]) - if prog == 2: - sp.call([os.path.join(os.getcwd().strip("GUI"),"scripts","GUI_subPyNormInt.py"),str(FoS),"raw"]) - - def fitt2(self,prog): - frame3.grid(row=0,column=2,sticky="N"+"S"+"E"+"W") - if prog != 2: - 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") - 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") - btnR2.grid(row=2,column=0,sticky="N"+"S"+"E"+"W") - root.update() - - def sim2(self,prog): - self.runF(prog,"n") - - def destrFr1(self): - frame2.destroy() - - -PG = PWA_GUI() - -root = tk.Tk() -root.wm_title("GUI") - -frame=tk.Frame(root, height = 900, width = 900) -frame.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") -frame2=tk.Frame(root) -frame3=tk.Frame(root) -btnB0=tk.Button(frame2, text="back", height=2 , width = 10,command= lambda: PG.back1()) -btnB1=tk.Button(frame3, text="back", height=2 , width = 10,command= lambda: PG.back2()) - -btnS0=tk.Button(frame2, text="Run Gamp", height=2 , width = 10,command= lambda: PG.sim2(0)) -btnS1=tk.Button(frame2, text="Gen Alpha", height=2 , width = 10,command= lambda: PG.sim2(1)) -btnS2=tk.Button(frame2, text="normint", height=2 , width = 10,command= lambda: PG.sim2(2)) -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") - -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()) -btnS.pack(side="top") -btnMB=tk.Button(frame, text="WAVES", height=2 , width = 10,command= lambda: PG.mvBAMP1()) -btnMB.pack(side="top") -btnE=tk.Button(frame,text="exit", height=2 , width = 10,command= lambda: root.destroy()) -btnE.pack(side="bottom") - -root.mainloop() - diff --git a/pythonPWA/pythonPWA/batchFarmServices/__init__.py b/pythonPWA/pythonPWA/batchFarmServices/__init__.py deleted file mode 100755 index d1353728..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -""" - This module contains the programs associated with running pythonPWA in the JLab batch farm system -""" - diff --git a/pythonPWA/pythonPWA/batchFarmServices/dataSimulatorNPY.py b/pythonPWA/pythonPWA/batchFarmServices/dataSimulatorNPY.py deleted file mode 100755 index 0733bde7..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/dataSimulatorNPY.py +++ /dev/null @@ -1,112 +0,0 @@ -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -from random import random -import os, numpy -from batchFarmServices.rhoAA import rhoAA -from pythonPWA.fileHandlers.gampTranslator import gampTranslator -from batchFarmServices.fast_like import FASTLikelihood - -class dataSimulator(object): - """ - This is the program that does the work of simulation for PyPWA simulaton. - """ - def __init__(self, - mass=1010., - waves=[], - normint=None, - productionAmplitudes=[], - 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.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() - - gampT = gampTranslator(os.path.join(os.path.split(inputGampFile.name)[0],os.path.split(inputGampFile.name)[1])) - if not os.path.isfile(os.path.join(os.path.split(inputGampFile.name)[0],"events.npy")): - gampT.translate(os.path.join(os.path.split(inputGampFile.name)[0],"events.npy")) - gampList=numpy.load(os.path.join(os.path.split(inputGampFile.name)[0],"events.npy")) - - pf = inputPfFile - pflist = pf.readlines() - - wList=self.iList[:]/self.iMax - - wnList=numpy.zeros(shape=(wList.shape[0])) - - for wn in range(len(wList)): - if wList[wn]>random(): - wnList[wn] = 1 - - numpy.save(os.path.join(os.path.split(inputGampFile.name)[0],"wnList"),wnList) - - for wn in range(len(wnList)): - wnEvent = gampT.writeEvent(gampList[wn,:,:]) - if float(pflist[wn])==1.0: - wnEvent.writeGamp(outputPFGampFile) - if wnList[wn] == 1: - wnEvent.writeGamp(outputRawGampFile) - if wnList[wn] == 1 and float(pflist[wn])==1.0: - wnEvent.writeGamp(outputAccGampFile) - inputGampFile.close() - inputPfFile.close() - outputPFGampFile.close() - outputRawGampFile.close() - outputAccGampFile.close() diff --git a/pythonPWA/pythonPWA/batchFarmServices/fast_like.py b/pythonPWA/pythonPWA/batchFarmServices/fast_like.py deleted file mode 100755 index 2f63cee8..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/fast_like.py +++ /dev/null @@ -1,121 +0,0 @@ -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" - -import numpy as np -import os - -class FASTLikelihood(object): - """ - This is the mathmatical class of the likelihood calculation and the calculation of the intensity. - """ - def __init__(self, - waves=[], - productionAmplitudes=[], - alphaList=[], - acceptedPath=os.getcwd(), - generatedPath=os.getcwd(), - 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 - self.alphaList=alphaList - self.nwaves = len(self.waves) - self.acceptedPath=acceptedPath - self.generatedPath=generatedPath - self.iList=[] - self.accNormInt=accNormInt.sum(0).sum(0) - self.rhoAA = rhoAA - self.etaX = 0. - - -# def countAlphas(self,fname): This function will be able to read the .num file -# with open(fname) as f: instead of reading the entire file length. Uncomment -# num = f.readlines() it and comment '#' out the next function to -# 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): - """ - 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): - for j in range(self.nwaves): - VV = self.productionAmplitudes[i] * np.conjugate(self.productionAmplitudes[j]) - a0 = a0 + (VV * self.rhoAA[i,j,:]).real - a1 = a1 + (VV * self.accNormInt[i,j]).real - 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): - """ - 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): - VV = self.productionAmplitudes[i] * np.conjugate(self.productionAmplitudes[j]) - a0 = a0 + (VV * self.rhoAA[i,j,:]).real - return a0 - diff --git a/pythonPWA/pythonPWA/batchFarmServices/fitting_Install b/pythonPWA/pythonPWA/batchFarmServices/fitting_Install deleted file mode 100755 index b6fca474..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/fitting_Install +++ /dev/null @@ -1,74 +0,0 @@ -#! /u/apps/anaconda/anaconda-2.0.1/bin/python2 -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")) -if not os.path.isfile(os.path.join("Control_List.npy")): - sp.call("pwa_controls") -Control = numpy.load(os.path.join("Control_List.npy")) -print("Creating directory structure for PyPWA fitting") -tdirs = ("fitting","GUI","keyfiles","scripts") -for i in tdirs: - directoryBuffer=os.path.join(indir,str(i)) - os.makedirs(directoryBuffer) - if i != tdirs[-1]: - sys.stdout.write("Writing Directories"+"."*(tdirs.index(i)+1)+"\r") - sys.stdout.flush() - elif i == tdirs[-1]: - sys.stdout.write("Writing Directories"+"."*(tdirs.index(i)+1)+"\r\n") - sys.stdout.flush() - if i == "fitting": - for d in ("overflow","results"): - directoryBuffer=os.path.join(indir,"fitting",str(d)) - os.makedirs(directoryBuffer) - if i == "GUI": - directoryBuffer=os.path.join(indir,"GUI","plotLists") - os.makedirs(directoryBuffer) - if i == "scripts": - directoryBuffer=os.path.join(indir,"scripts","submitions") - os.makedirs(directoryBuffer) -progs = ("fnGenerator.py","generateAlphaNPY.py","GUI_alpha_main.py", -"GUI_gamp_main.py","GUI_subPyNormInt.py","likelihoodTest.py","mvBAMP_GUI", -"run_normintFARM.py","subLikelihood","subWalkNTrue","walkingNTrue.py","massBinner.py") -for s in progs: - cmd = 'cp '+os.path.join(os.getcwd(),str(s))+" "+os.path.join(indir,"scripts") - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - if s != progs[-1]: - sys.stdout.write("Filling scripts"+"."*(progs.index(s)+1)+"\r") - sys.stdout.flush() - elif s == progs[-1]: - sys.stdout.write("Filling scripts"+"."*(progs.index(s)+1)+"\r\n") - sys.stdout.flush() -guis = ("graphicPlot","pwa_controls","PWA_GUI","Control_List.npy") -for g in guis: - if g != guis[-1]: - cmd = 'cp '+os.path.join(os.getcwd(),str(g))+" "+os.path.join(indir,"GUI") - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - sys.stdout.write("Filling GUI"+"."*(guis.index(g)+1)+"\r") - sys.stdout.flush() - elif g == guis[-1]: - cmd = 'mv '+os.path.join(os.getcwd(),str(g))+" "+os.path.join(indir,"GUI") - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - sys.stdout.write("Filling GUI"+"."*(guis.index(g)+1)+"\r\n") - sys.stdout.flush() -cmd = "mv "+indir+"/*.keyfile "+os.path.join(indir,"keyfiles") -procx = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) -procx.wait() -print "Filling keyfiles" -for fil in os.listdir(indir): - if ".gamp" in fil: - cmd = "python "+indir+"/scripts/massBinner.py "+os.path.join(indir)+" "+os.path.join(indir,"fitting")+" "+str(fil).rstrip(".gamp")+" v" - procx = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - procx.wait() - -print "Welcome to PyPWA!\nYou are now ready to start Partial Wave Analysis!" diff --git a/pythonPWA/pythonPWA/batchFarmServices/fnGenerator.py b/pythonPWA/pythonPWA/batchFarmServices/fnGenerator.py deleted file mode 100755 index e1b1d610..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/fnGenerator.py +++ /dev/null @@ -1,81 +0,0 @@ -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -from pythonPWA.utilities.minuitLikelihood import minuitLikelihood -import os - -class generator(object): - def __init__(self): - self.fileName=None - - def createFile(self,numberOfTerms): - """ - Writes out a file containing a wrapper function for minuitLn.calcneglnL, - simply give this function the number of terms (which should be equivalent to - 2*number of waves) and it will write the needed wrapper function to the file - specified by self.filename. - """ - outputFile=open(self.fileName,'w') - outputString="def fn(" - bufferString="" - - reals=[] - imags=[] - - totalList=[] - - #make dual lists - for i in range(0,numberOfTerms,2): - reals.append("t"+str(i)) - - for i in range(1,numberOfTerms,2): - imags.append("t"+str(i)) - - for i in range(numberOfTerms): - totalList.append("t"+str(i)) - - for i in range(len(totalList)): - if i!=len(totalList)-1: - outputString+="t"+str(i)+"," - - if i==len(totalList)-1: - outputString+="t"+str(i) - - - outputString+="):\n\tretList=[" - - #construct numpy complexes - for i in range(len(reals)): - if i!=len(reals)-1: - outputString+="numpy.complex("+reals[i]+","+imags[i]+")," - if i==len(reals)-1: - outputString+="numpy.complex("+reals[i]+","+imags[i]+")" - - outputString+="]\n\treturn minuitLn.calcneglnL(retList)\n\n" - - outputFile.write(outputString) - - stringBuffer="m=Minuit(fn," - for i in range(len(totalList)): - if i!=len(totalList)-1: - stringBuffer+="t"+str(i)+"=.01," - - if i==len(totalList)-1: - stringBuffer+="t"+str(i)+"=.01" - - stringBuffer+=")\n" - - outputFile.write(stringBuffer) - """ - outputFile.write("Vvalues = m.values\n") - outputFile.write("numpy.save(os.path.join(dataDir,\"Vvalues.npy\"),Vvalues)\n") - outputFile.write("covariance=numpy.array(m.matrix())\n") - outputFile.write("numpy.save(os.path.join(dataDir,\"minuitCovar3.npy\"),covariance)\n") - """ - outputFile.close() diff --git a/pythonPWA/pythonPWA/batchFarmServices/generateAlphaNPY.py b/pythonPWA/pythonPWA/batchFarmServices/generateAlphaNPY.py deleted file mode 100755 index 9f962092..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/generateAlphaNPY.py +++ /dev/null @@ -1,279 +0,0 @@ -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Stephanie K. A. Bramlett , Joshua Pond - - -""" -import os, sys, numpy -sys.path.append(os.path.join(sys.argv[4],"pythonPWA")) -from pythonPWA.utilities.ThreeVec import ThreeVector -from pythonPWA.utilities.FourVec import FourVector -from pythonPWA.fileHandlers.gampTranslator import gampTranslator -import math - -class generateAlphas(object): - """ - This program calculates the value of alpha for every event in a .gamp file and saves it to a .txt list, one event per line. - """ - - alphaName = "alpha" - labelOut = "" - - def __init__(self, mode, indir, gfile): - """ - Default generatAlphas constructor - - Kwargs: - mode (int): 8 = p pi+ pi- pi0, 22 = p p+ p-, 24 = p k+ k-, 42 = gamma p --> p Ks Ks (pi+ pi- pi+ pi-) - indir (string): Full file path to directory of file - gfile (string): File name without .gamp extension. - """ - - self.mode = mode - self.indir = indir - self.gfile = gfile+".gamp" - self.nfile = gfile+".npy" - f = gfile.partition(".")[0] - self.gampT = gampTranslator(os.path.join(self.indir,self.gfile)) - if not os.path.isfile(os.path.join(self.indir,self.nfile)): - self.gampT.translate(os.path.join(self.indir,self.nfile)) - self.gampList=numpy.load(os.path.join(self.indir,self.nfile)) - self.alphaName = "alpha" + f + ".txt" - self.alphalist = [] - if self.mode == "8": - self.analyze8() - if self.mode == "22": - self.analyze22() - if self.mode == "24" or self.mode == 24 : - self.analyze24() - if self.mode == "42": - self.analyze42() - if self.mode == "EtaPiN": - self.analyzeEtaPiN - - def analyze8(self): - ''' - p pi+ pi- pi0 - ''' - for i in range(int(self.gampList.shape[0])): - event = self.gampT.writeEvent(self.gampList[i,:,:]) - for particles in event.particles: - if particles.particleID == 14.0: #proton - p = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 1.0: #photon gamma - bm = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 9.0: #p- - pim = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 8.0: #p+ - pip = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - - ptarget = FourVector(.938, 0.,0.,0.) - initp = bm + ptarget - finalp = pip + pim + p - pi0 = initp + finalp - pmeson = pip + pim + pi0 - pMeson = pmeson.p - beam3 = bm.p - polarization = ThreeVector(0.,1.,0.) - Normal = beam3 * pMeson - - cosAlpha = Normal.dot(polarization) / Normal.r() - alpha = math.acos(cosAlpha) - sys.stdout.write(str(i)+"\r") - sys.stdout.flush() - self.alphalist.append(alpha) - - def analyze22(self): - ''' - p p+ p- - ''' - for i in range(int(self.gampList.shape[0])): - event = self.gampT.writeEvent(self.gampList[i,:,:]) - for particles in event.particles: - if particles.particleID == 14.0: #proton - pp = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 1.0: #photon gamma - bm = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 9.0: #p- - pim = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 8.0: #p+ - pip = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - # - pmeson = pip + pim - pMeson = pmeson.p - beam3 = bm.p - polarization = ThreeVector(0.,1.,0.) - Normal = beam3 * pMeson - - cosAlpha = Normal.dot(polarization) / Normal.r() - alpha = math.acos(cosAlpha) - self.alphalist.append(alpha) - - - def analyze24(self): - """ - p k+ k- - """ - for i in range(int(self.gampList.shape[0])): - event = self.gampT.writeEvent(self.gampList[i,:,:]) - for particles in event.particles: - if particles.particleID == 14.0: #proton - pp = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 1.0: #photon gamma - bm = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 12.0: #K- - km = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 11.0: #K+ - kp = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) -# target = FourVector(.938, 0., 0., 0.) - pmeson = kp + km # K+ K- - -# if bm.z > 4.4: -# miss = bm + target - kp - km -# totalmiss = bm + target - kp - kp - pp - #determine alpha - pMeson = pmeson.p - beam3 = bm.p - polarization = ThreeVector(0.,1.,0.) - Normal = beam3 * pMeson - - cosAlpha = Normal.dot(polarization) / Normal.r() - alpha = math.acos(cosAlpha) - #print alpha - self.alphalist.append(alpha) - - def analyze42(self): - """ - gamma p --> p Ks Ks (pi+ pi- pi+ pi-) - """ - for i in range(int(self.gampList.shape[0])): - event = self.gampT.writeEvent(self.gampList[i,:,:]) - nks = 0 - for particles in event.particles: - if particles.particleID == 14.0: #proton - p = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 1.0: #photon gamma - bm = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 16.0: #Ks - if nks == 0: - ks1 = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - else: - ks2 = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - nks += 1 - - pmeson = ks1 + ks2 - pMeson = pmeson.p - beam3 = bm.p - polarization = ThreeVector(0.,1.,0.) - Normal = beam3 * pMeson - - cosAlpha = Normal.dot(polarization) / Normal.r() - alpha = math.acos(cosAlpha) - - self.alphalist.append(alpha) - - - def analyzeEtaPiN(self): - for i in range(int(self.gampList.shape[0])): - event = self.gampT.writeEvent(self.gampList[i,:,:]) - for particles in event.particles: - if particles.particleID == 13.0: #neutron - n = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 1.0: #photon gamma - bm = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 12.0: #eta - eta = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - if particles.particleID == 11.0: #p+ - pip = FourVector(float(particles.particleE), - float(particles.particleXMomentum), - float(particles.particleYMomentum), - float(particles.particleZMomentum)) - pmeson = eta + pip - pMeson = pmeson.p - beam3 = bm.p - polarization = ThreeVector(0.,1.,0.) - Normal = beam3 * pMeson - - cosAlpha = Normal.dot(polarization) / Normal.r() - alpha = math.acos(cosAlpha) - - self.alphalist.append(alpha) - - - def toFile(self): - """ - Saves the list to a file. - """ - f = open(os.path.join(self.indir, self.alphaName), 'w') - for alpha in self.alphalist: - f.write(str(alpha) + "\n") - f.close() - - - -indir = sys.argv[2] -gfile = sys.argv[3] -mode = sys.argv[1] -a = generateAlphas(mode, indir, gfile) -a.toFile() - diff --git a/pythonPWA/pythonPWA/batchFarmServices/getImax.py b/pythonPWA/pythonPWA/batchFarmServices/getImax.py deleted file mode 100755 index 1d8e4c17..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/getImax.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import numpy -import os -""" - This program runs in the interactive farm to retrieve the maximum intensity value among the whole mass range. -""" - -topDir = os.getcwd().rstrip("GUI") - -iMax = [0] - -for d in os.listdir(os.path.join(topDir,"simulation")): - if "_MeV" in d: - Max = numpy.amax(numpy.load(os.path.join(topDir,"simulation",d,"flat","iList.npy"))) - if Max > iMax[0]: - iMax[0] = Max - -numpy.save(os.path.join(topDir,"simulation","iMax.npy"),iMax) -print "DONE" diff --git a/pythonPWA/pythonPWA/batchFarmServices/graphicHelp.py b/pythonPWA/pythonPWA/batchFarmServices/graphicHelp.py deleted file mode 100755 index de8ce0e1..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/graphicHelp.py +++ /dev/null @@ -1,107 +0,0 @@ -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -class Help(object): - - def __init__(self): - - self.GPhelp =""" -GraphicPlot Help. - -When the dashboard opens for the first time, or -if the file name specified in pwa_controls does -not exist the display will read that there isn't -a saved list and that all the data will have to be -updated to plot. - -Hit pwa Controls and make sure that all the -information there is correct. The last two -are the only ones that will affect plotting. - -1st: Hit Update All and wait for the display - to read "PlotList updated." - -2nd: Hit save and wait for the dashboard to - update with the individual wave buttons. - -3rd: Hit any and all buttons for what you - would like to plot and then hit plot. - - You do not need to close the graph before - plotting again. Plot as many graphs as you - like. - -The data will be automatically loaded if the .npy -file specified in pwa_controls exists, which will be -indicated by the display. Start with step 3. - - """ - - self.CFhelp = """ -pwa_controls Help. - -Fill in all entry boxes. - -THERE ARE NO DEFAULT VALUES - -Reaction mode is the mode for generateAlphas: -8 = p pi+ pi- pi0 -22 = p p+ p- -24 = p k+ k- -42 = gamma p --> p Ks Ks -(pi+ pi- pi+ pi-)eta pi n - -Beam polarization is an important value for some -experiments. It must be a float value! -No polarization = 0.0 - -The Upper, lower, and range of the mass are inclusive -and will affect binning. - -Sets is almost never used. -Put 0 - -The number of Migrad calls should be at least 1000, -but any more will depend on other factors, like -number of events and waves. - -Name of tested reaction should just be a quick title, -possibly the same as the top directory of the project. -It will be used as the title of graphs made by -graphicPlot. - -Name of the saved data is the filename where graphicPlot -will save the CURRENT data loaded to it and where it will -look to load already saved data, they are all saved inside -/GUI/plotLists. Change this as often as you need to make -as many different sets of data and to view different sets -of data by using the pwa_controls button on the graphicPlot -button panel. But if you update anything and save over an -old file, then the old data will be lost. - -Press save when done. - -Saved values will be loaded -next time. - -""" - - self.PWAGhelp = """ - - - - - - - - - - - -""" diff --git a/pythonPWA/pythonPWA/batchFarmServices/graphicPlot b/pythonPWA/pythonPWA/batchFarmServices/graphicPlot deleted file mode 100755 index 13242aed..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/graphicPlot +++ /dev/null @@ -1,543 +0,0 @@ -#! /u/apps/anaconda/anaconda-2.0.1/bin/python2 -import matplotlib.pyplot as plt -from multiprocessing import Process -import subprocess as sp -import numpy -import os -import sys -import Tkinter as tk -import itertools -import argparse -sys.path.append(os.path.join(os.getcwd().strip("GUI"),"pythonPWA")) -from batchFarmServices.graphicHelp import Help -class graphicPlot(object): - """ - This is the graphicPlot GUI optimized for fitting. - """ - - def __init__(self, - topDir = os.getcwd().strip("GUI"), - dataL = [], - simL = [], - accMC = [], - rawMC = [], - normL = [], - normC = 0, - percL = [], - nT0 = [], - nTA = [], - nE0 = [], - nEA = [], - ran = [], - wvs = [], - delF = [], - allL = [[] for i in range(18)], - plts = [], - nms = [], - iL = 1, - nT0E = [], - nTAE = [], - nE0E = [], - nEAE = [], - er = 0, - errs = []): - self.topDir = topDir - self.dataL = dataL - self.simL = simL - self.accMC = accMC - self.rawMC = rawMC - self.normL = normL - self.normC = normC - self.percL = percL - self.nT0 = nT0 - self.nTA = nTA - self.nE0 = nE0 - self.nEA = nEA - self.ran = ran - self.wvs = wvs - self.delF = delF - self.allL = allL - self.plts = plts - self.nms = nms - self.iL = iL - self.nT0E = nT0E - self.nTAE = nTAE - self.nE0E = nE0E - self.nEAE = nEAE - self.er = er - self.errs = errs - self.Control = numpy.load("Control_List.npy") - - - def loadl(self): - self.Control = numpy.load("Control_List.npy") - if os.path.isfile(os.path.join(os.getcwd(),"plotLists",self.Control[8]+".npy")): - self.allL = numpy.load(os.path.join(os.getcwd(),"plotLists",self.Control[8]+".npy")) - self.dataL = self.allL[0] - self.simL = self.allL[1] - self.accMC = self.allL[2] - self.rawMC = self.allL[3] - self.normL = self.allL[4] - self.normC = self.allL[5] - self.percL = self.allL[6] - self.nT0 = self.allL[7] - self.nTA = self.allL[8] - self.nE0 = self.allL[9] - self.nEA = self.allL[10] - self.ran = self.allL[11] - self.wvs = self.allL[12] - self.delF = self.allL[13] - self.nT0E = self.allL[14] - self.nTAE = self.allL[15] - self.nE0E = self.allL[16] - self.nEAE = self.allL[17] - text.delete("0.0wordstart", "end") - text.insert("end",self.Control[8]+"\n"+"LOADED") - elif not os.path.isfile(os.path.join(os.getcwd(),"plotLists",self.Control[8]+".npy")): - text.delete("0.0wordstart", "end") - text.insert("end","NO LIST"+"\n"+"UPDATE AND PRESS SAVE "+"\n"+"FOR FITTED WAVES") - self.allL = [[] for i in range(14)] - - def mk_all(self): - self.allL = [self.dataL, - self.simL, - self.accMC, - self.rawMC, - self.normL, - self.normC, - self.percL, - self.nT0, - self.nTA, - self.nE0, - self.nEA, - self.ran, - self.wvs, - self.delF, - self.nT0E, - self.nTAE, - self.nE0E, - self.nEAE] - text.delete("0.0wordstart", "end") - text.insert("end","PLotList UPDATED") - return self.allL - - def file_len(self,fname): - with open(fname) as f: - num = f.readlines() - return int(num[0]) - - def up_range(self): - rang = [] - for r in sorted(os.listdir(os.path.join(self.topDir,"fitting"))): - if "_MeV" in r: - rang.append(r.strip("_MeV")) - self.ran = rang - text.delete("0.0wordstart", "end") - text.insert("end","RANGE UPDATED") - - def up_perc(self): - self.percL = [] - for i in range(len(self.ran)): - self.percL.append(float(float(self.dataL[i])/float(self.simL[i]))) - text.delete("0.0wordstart", "end") - text.insert("end","PERC UPDATED") - - def up_data(self): - self.dataL = [] - for d in self.ran: - if os.path.isfile(self.topDir+"/fitting/"+str(d)+"_MeV/data/events.num"): - self.dataL.append(self.file_len(self.topDir+"/fitting/"+str(d)+"_MeV/data/events.num")) - text.delete("0.0wordstart", "end") - text.insert("end","data UPDATED") - - def up_sim(self): - self.simL = [] - for d in self.ran: - if os.path.isfile(self.topDir+"/simulation/"+str(d)+"_MeV/data/raw/events.num"): - self.simL.append(self.file_len(self.topDir+"/simulation/"+str(d)+"_MeV/data/raw/rawDATA.num")) - text.delete("0.0wordstart", "end") - text.insert("end","sim UPDATED") - - def up_accMC(self): - self.accMC = [] - for d in self.ran: - if os.path.isfile(self.topDir+"/fitting/"+str(d)+"_MeV/mc/acc/events.num"): - self.accMC.append(self.file_len(self.topDir+"/fitting/"+str(d)+"_MeV/mc/acc/events.num")) - text.delete("0.0wordstart", "end") - text.insert("end","accMC UPDATED") - - def up_rawMC(self): - self.rawMC = [] - for d in self.ran: - if os.path.isfile(self.topDir+"/fitting/"+str(d)+"_MeV/mc/raw/events.num"): - self.rawMC.append(self.file_len(self.topDir+"/fitting/"+str(d)+"_MeV/mc/raw/events.num")) - text.delete("0.0wordstart", "end") - text.insert("end","rawMC UPDATED") - - def up_norms(self): - self.normL = [] - self.normC = (sum(self.simL))/(sum(self.dataL)) - for t in self.dataL: - self.normL.append(t*self.normC) - text.delete("0.0wordstart", "end") - text.insert("end","NORM UPDATED") - - def up_fits(self): - self.nT0 = [] - self.nE0 = [] - self.nT0E = [] - self.nE0E = [] - for d in self.ran: - if os.path.isfile(self.topDir+"/fitting/results/"+str(d)+"_MeV/nTrueList-0_"+str(d)+".npy"): - r0 = numpy.load(self.topDir+"/fitting/results/"+str(d)+"_MeV/nTrueList-0_"+str(d)+".npy") - self.nT0.append(float(r0[0][1])) - self.nE0.append(float(r0[0][3])) - self.nT0E.append(float(r0[0][2])) - self.nE0E.append(float(r0[0][4])) - elif not os.path.isfile(self.topDir+"/fitting/results/"+str(d)+"_MeV/nTrueList-0_"+str(d)+".npy"): - self.nT0.append(0) - self.nE0.append(0) - self.nT0E.append(0) - self.nE0E.append(0) - b = 0 - for dirs in sorted(os.listdir(os.path.join(self.topDir,"fitting","results"))): - if os.path.isfile(self.topDir+"/fitting/results/"+dirs+"/nTrueList-"+str(self.iL)+"_"+str(dirs.strip("_MeV"))+".npy"): - break - else: - b+=1 - while self.iL < 100: - if os.path.isfile(self.topDir+"/fitting/results/"+str(self.ran[b])+"_MeV/nTrueList-"+str(self.iL)+"_"+str(self.ran[b])+".npy"): - self.iL += 1 - elif not os.path.isfile(self.topDir+"/fitting/results/"+str(self.ran[b])+"_MeV/nTrueList-"+str(self.iL)+"_"+str(self.ran[b])+".npy"): - break - self.nTA = [[] for i in range(self.iL-1)] - self.nEA = [[] for i in range(self.iL-1)] - self.nTAE = [[] for i in range(self.iL-1)] - self.nEAE = [[] for i in range(self.iL-1)] - self.wvs = [] - for g in range(1,self.iL): - for d in self.ran: - if os.path.isfile(self.topDir+"/fitting/results/"+str(d)+"_MeV/nTrueList-"+str(g)+"_"+str(d)+".npy"): - rx = numpy.load(self.topDir+"/fitting/results/"+str(d)+"_MeV/nTrueList-"+str(g)+"_"+str(d)+".npy") - self.nTA[g-1].append(float(rx[0][1])) - self.nEA[g-1].append(float(rx[0][4])) - self.nTAE[g-1].append(float(rx[0][2])) - self.nEAE[g-1].append(float(rx[0][5])) - if d == self.ran[b]: - self.wvs.append(rx[0][3]) - elif not os.path.isfile(self.topDir+"/fittiing/results/"+str(d)+"_MeV/nTrueList-"+str(g)+"_"+str(d)+".npy"): - self.nTA[g-1].append(0) - self.nEA[g-1].append(0) - self.nTAE[g-1].append(0) - self.nEAE[g-1].append(0) - if len(self.nT0) == len(self.ran) and len(self.simL) == len(self.ran): - self.up_delF() - text.delete("0.0wordstart", "end") - text.insert("end","FITS UPDATED") - - def up_delF(self): - self.delF = [] - for i in range(len(self.ran)): - if float(float(self.nT0[i])-float(self.simL[i])) > 100.0 or float(float(self.nT0[i])-float(self.simL[i]))< -100.0: - self.delF.append(float(float(self.nT0[i])-float(self.simL[i]))) - else: - self.delF.append(0) - text.delete("0.0wordstart", "end") - text.insert("end","Delta UPDATED") - - def savel(self): - self.mk_all() - numpy.save(os.path.join(os.getcwd(),"plotLists",self.Control[8]+".npy"),self.allL) - text.delete("0.0wordstart", "end") - text.insert("end","SAVED") - self.destrFr() - self.wv_Buttons(len(GP.allL[8])) - root.update() - - def up_all(self): - text.delete("0.0wordstart", "end") - text.insert("end","UPDATE STARTED") - root.update() - self.up_range() - root.update() - self.up_data() - root.update() - self.up_sim() - root.update() - self.up_accMC() - root.update() - self.up_rawMC() - root.update() - self.up_norms() - root.update() - self.up_fits() - root.update() - self.up_perc() - root.update() - self.mk_all() - - def add_all(self): - self.add_data() - self.add_sim() - self.add_nTrue() - self.add_nExp() - text.delete("0.0wordstart", "end") - text.insert("end","DATA, SIM, nTRUE, nEXP"+"\n"+"\t"+"ADDED") - - def add_data(self): - self.plts.append(self.dataL) - self.nms.append("data") - self.errs.append(0) - text.delete("0.0wordstart", "end") - text.insert("end","data ADDED") - - def add_sim(self): - self.plts.append(self.simL) - self.nms.append("sim") - self.errs.append(0) - text.delete("0.0wordstart", "end") - text.insert("end","sim ADDED") - - def add_accMC(self): - self.plts.append(self.accMC) - self.nms.append("accMC") - self.errs.append(0) - text.delete("0.0wordstart", "end") - text.insert("end","accMC ADDED") - - def add_rawMC(self): - self.plts.append(self.rawMC) - self.nms.append("rawMC") - self.errs.append(0) - text.delete("0.0wordstart", "end") - text.insert("end","rawMC ADDED") - - def add_norms(self): - self.plts.append(self.normL) - self.nms.append("norm") - self.errs.append(0) - text.delete("0.0wordstart", "end") - text.insert("end","NORM ADDED") - - def add_perc(self): - self.plts.append(self.percL) - self.nms.append("% Accepted") - self.errs.append(0) - text.delete("0.0wordstart", "end") - text.insert("end","PERC ADDED") - - def add_nTrue(self): - self.plts.append(self.nT0) - self.nms.append("Total nTrue") - self.errs.append(self.nT0E) - text.delete("0.0wordstart", "end") - text.insert("end","nTrue ADDED") - - def add_nExp(self): - self.plts.append(self.nE0) - self.nms.append("Total nExp") - self.errs.append(self.nE0E) - text.delete("0.0wordstart", "end") - text.insert("end","nExp ADDED") - - def add_nTrue_wave(self,x): - self.plts.append(self.allL[8][x]) - self.nms.append(self.wvs[x].strip(".bamp")+"True") - self.errs.append(self.nTAE[x]) - text.delete("0.0wordstart", "end") - text.insert("end",self.wvs[x].strip(".bamp")+"True ADDED") - - def add_nExp_wave(self,x): - self.plts.append(self.allL[10][x]) - self.nms.append(self.wvs[x].strip(".bamp")+"Exp") - self.errs.append(self.nEAE[x]) - text.delete("0.0wordstart", "end") - text.insert("end",self.wvs[x].strip(".bamp")+"Exp ADDED") - - def add_delF(self): - self.plts.append(self.delF) - self.nms.append("Delta fit-sim") - self.errs.append(0) - text.delete("0.0wordstart", "end") - text.insert("end","Delta ADDED") - - def mk_plot(self,lis): - text.delete("0.0wordstart", "end") - text.insert("end","PLOTTING") - marker = itertools.cycle(('D','8','o','^','h','p','s','*','x','+')) - fig, ax1 = plt.subplots() - if self.percL in lis and len(lis)>1: - for i in range(len(lis)): - if lis[i] != self.percL: - if self.er == 1: - ax1.errorbar(self.ran,lis[i],yerr=self.errs[i],linestyle='',marker=marker.next(),label=self.nms[i]) - elif self.er ==0: - ax1.plot(self.ran,self.plts[i],linestyle='',marker=marker.next(),label=self.nms[i]) - ax1.legend(loc = 2) - ax1.set_ylabel("Events") - ax1.set_xlabel("Mass (MeV)") - else: - ax2 = ax1.twinx() - ax2.plot(self.ran,lis[i],linestyle='',marker=marker.next(),label=self.nms[i]) - ax2.legend() - ax2.set_ylabel("Percent") - elif not self.percL in lis: - for i in range(len(lis)): - if self.er == 1: - ax1.errorbar(self.ran,lis[i],yerr=self.errs[i],linestyle='',marker=marker.next(),label=self.nms[i]) - elif self.er ==0: - ax1.plot(self.ran,self.plts[i],linestyle='',marker=marker.next(),label=self.nms[i]) - ax1.legend() - ax1.set_ylabel("Events") - ax1.set_xlabel("Mass (MeV)") - elif self.percL in lis and len(lis)== 1: - for i in range(len(lis)): - ax1.plot(self.ran,self.plts[i],linestyle='',marker=marker.next(),label=self.nms[i]) - ax1.legend() - ax1.set_ylabel("Percent") - ax1.set_xlabel("Mass (MeV)") - plt.title(self.Control[7]+" "+self.Control[8]) - plt.show() - self.plts = [] - self.nms = [] - self.errs = [] - def plot(self, lis): - text.delete("0.0wordstart", "end") - text.insert("end","PLOTTING") - p = Process(target=self.mk_plot,args=(lis,)) - p.start() - self.plts = [] - self.nms = [] - self.errs = [] - - def wv_Buttons(self,lent): - frame4=tk.Frame(frame3) - frame5=tk.Frame(frame3) - frame4.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") - frame5.grid(row=1,column=0,sticky="N"+"S"+"E"+"W") - x = 0 - t = 0 - for y in range(lent): - btn = tk.Button(frame4, text = GP.wvs[y].strip(".bamp")+"\n"+"nTrue", command = lambda x=x,t=t: GP.add_nTrue_wave((x*9)+t+x)) - btn.grid(column=t,row=x) - btn = tk.Button(frame5, text = GP.wvs[y].strip(".bamp")+"\n"+"nExp", command = lambda x=x,t=t: GP.add_nExp_wave((x*9)+t+x)) - btn.grid(column=t,row=x) - t += 1 - if t > 9: - t = 0 - x += 1 - - def destrFr(self): - frame4.destroy() - frame5.destroy() - - def help_window(self): - window = tk.Toplevel(root) - window.wm_title("HELP") - tx = Help() - label = tk.Label(window, text=tx.GPhelp) - label.pack(side="top", fill="both", padx=10, pady=10) - - def error(self): - if self.er == 0: - self.er = 1 - text.delete("0.0wordstart", "end") - text.insert("end","ERROR ON") - elif self.er == 1: - self.er = 0 - text.delete("0.0wordstart", "end") - text.insert("end","ERROR OFF") - - -parser = argparse.ArgumentParser(description="""A graphing utility for the PyPWA partial wave analysis toolkit.""") -parser.add_argument("-t", "--topDir", help="Run graphicPlot with a different top directory than the current working directory.",default=os.getcwd().strip("GUI")) -args = parser.parse_args() - -GP = graphicPlot(topDir=args.topDir) - -root = tk.Tk() - -frame=tk.Frame(root) -frame1=tk.Frame(root) -frame2=tk.Frame(root) -frame3=tk.Frame(root) -frame4=tk.Frame(frame3) -frame5=tk.Frame(frame3) - -frame.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") -frame1.grid(row=0,column=1,sticky="N"+"S"+"E"+"W") -frame2.grid(row=1,column=0,sticky="N"+"S"+"E"+"W") -frame3.grid(row=1,column=1,sticky="N"+"S"+"E"+"W") -frame4.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") -frame5.grid(row=1,column=0,sticky="N"+"S"+"E"+"W") - -text=tk.Text(frame1, height = 3, width = 23, font = 13) -text.pack(side="top") -text.tag_config("0.0wordstart", justify = "center") - -root.wm_title("GRAPHIC PLOT"+args.topDir) - -GP.loadl() -lent = len(GP.allL[8]) - - -GP.wv_Buttons(lent) - -Pall = tk.Button(frame2, text="PLOT"+"\n"+"ALL", command=lambda: GP.add_all()) -Pdata = tk.Button(frame2, text="PLOT"+"\n"+"data", command=lambda: GP.add_data()) -Psim = tk.Button(frame2, text="PLOT"+"\n"+"sim", command=lambda: GP.add_sim()) -PaccMC = tk.Button(frame2, text="PLOT"+"\n"+"accMC", command=lambda: GP.add_accMC()) -PrawMC = tk.Button(frame2, text="PLOT"+"\n"+"rawMC", command=lambda: GP.add_rawMC()) -Pnorm = tk.Button(frame2, text="PLOT"+"\n"+"NORM", command=lambda: GP.add_norms()) -Pperc = tk.Button(frame2, text="PLOT"+"\n"+"PERC", command=lambda: GP.add_perc()) -PnT0 = tk.Button(frame2, text="PLOT"+"\n"+"nTrue", command=lambda: GP.add_nTrue()) -PnE0 = tk.Button(frame2, text="PLOT"+"\n"+"nExp", command=lambda: GP.add_nExp()) -PdelF = tk.Button(frame2, text="PLOT"+"\n"+"delta", command=lambda: GP.add_delF()) -help = tk.Button(frame2, text="HELP", command=lambda: GP.help_window()) -Plot = tk.Button(frame2, text="PLOT", fg = "red", command=lambda: GP.plot(GP.plts)) -err = tk.Button(frame2, text="ERROR", command=lambda: GP.error()) - - -Pall.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") -Pdata.grid(row=0,column=1,sticky="N"+"S"+"E"+"W") -Psim.grid(row=0,column=2,sticky="N"+"S"+"E"+"W") -PaccMC.grid(row=0,column=3,sticky="N"+"S"+"E"+"W") -PrawMC.grid(row=0,column=4,sticky="N"+"S"+"E"+"W") -Pnorm.grid(row=1,column=0,sticky="N"+"S"+"E"+"W") -Pperc.grid(row=1,column=1,sticky="N"+"S"+"E"+"W") -PnT0.grid(row=1,column=2,sticky="N"+"S"+"E"+"W") -PnE0.grid(row=1,column=3,sticky="N"+"S"+"E"+"W") -PdelF.grid(row=1,column=4,sticky="N"+"S"+"E"+"W") -help.grid(row=0,column=5,sticky="N"+"S"+"E"+"W") -Plot.grid(row=1,column=5,sticky="N"+"S"+"E"+"W") -err.grid(row=0,column=6,sticky="N"+"S"+"E"+"W") - -cob = tk.Button(frame, text="pwa"+"\n"+"Controls", command=lambda: sp.call(os.getcwd()+"/pwa_controls")) -load = tk.Button(frame, text="LOAD", command=lambda: GP.loadl()) -Uall = tk.Button(frame, text="UPDATE"+"\n"+"ALL", command=lambda: GP.up_all()) -Uran = tk.Button(frame, text="UPDATE"+"\n"+"RANGE", command=lambda: GP.up_range()) -Udata = tk.Button(frame, text="UPDATE"+"\n"+"data", command=lambda: GP.up_data()) -Usim = tk.Button(frame, text="UPDATE"+"\n"+"sim", command=lambda: GP.up_sim()) -UaccMC = tk.Button(frame, text="UPDATE"+"\n"+"accMC", command=lambda: GP.up_accMC()) -UrawMC = tk.Button(frame, text="UPDATE"+"\n"+"rawMC", command=lambda: GP.up_rawMC()) -Uperc = tk.Button(frame, text="UPDATE"+"\n"+"PERC", command=lambda: GP.up_perc()) -Unorm = tk.Button(frame, text="UPDATE"+"\n"+"NORM", command=lambda: GP.up_norms()) -Ufit = tk.Button(frame, text="UPDATE"+"\n"+"FITTED", command=lambda: GP.up_fits()) -save = tk.Button(frame, text="SAVE", command=lambda: GP.savel()) - -cob.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") -Uall.grid(row=0,column=1,sticky="N"+"S"+"E"+"W") -Uran.grid(row=0,column=2,sticky="N"+"S"+"E"+"W") -Udata.grid(row=0,column=3,sticky="N"+"S"+"E"+"W") -Usim.grid(row=0,column=4,sticky="N"+"S"+"E"+"W") -UaccMC.grid(row=0,column=5,sticky="N"+"S"+"E"+"W") -load.grid(row=1,column=0,sticky="N"+"S"+"E"+"W") -UrawMC.grid(row=1,column=1,sticky="N"+"S"+"E"+"W") -Uperc.grid(row=1,column=2,sticky="N"+"S"+"E"+"W") -Unorm.grid(row=1,column=3,sticky="N"+"S"+"E"+"W") -Ufit.grid(row=1,column=4,sticky="N"+"S"+"E"+"W") -save.grid(row=1,column=5,sticky="N"+"S"+"E"+"W") - - - -root.mainloop() diff --git a/pythonPWA/pythonPWA/batchFarmServices/gui_submit b/pythonPWA/pythonPWA/batchFarmServices/gui_submit deleted file mode 100755 index 4ef85f3a..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/gui_submit +++ /dev/null @@ -1,151 +0,0 @@ -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import Tkinter as tk -import os, glob, shutil -from subprocess import Popen - - -scriptOutDir=os.path.join(os.getcwd(),"subMCs") -binSize=int(raw_input("bin width?: ")) -maxEvents=int(raw_input("max number of events?: ")) -i=int(raw_input("Enter i value: ")) -submitted = [] - -def submit(jsub_file): - cmd = 'jsub '+str(jsub_file) - proc = Popen(cmd, - shell = True, - executable = os.environ.get('SHELL', '/bin/tcsh'), - env = os.environ) - proc.wait() - -def gen(directory,cmd): - - auger_opts = dict( - project = 'gluex', - track = 'simulation', - jobname = 'runMC', - os = 'centos62', - time = 2880, - memory = '3000 MB', - disk_space = '5000 MB', - cmd = cmd) - - jsub_filename = os.path.join(scriptOutDir,"subMC_"+directory) - jsub_file = open(jsub_filename,'w') - jsub_file.write('''\ -PROJECT:{project} -TRACK:{track} -JOBNAME:{jobname} -OS:{os} -TIME:{time} -MEMORY:{memory} -DISK_SPACE:{disk_space} -COMMAND:{cmd} -'''.format(**auger_opts)) - - jsub_file.close() - return jsub_filename - -def parseDir(directory): - Bin=directory.strip("_MeV") - L=float(Bin)/1000. - U=L+(binSize/1000.) - gampName=directory+".gamp" - gampPath=os.path.join(os.getcwd(),"MC",directory,".") - - cmd = "/home/salgado/TESTMC/gluex/MC.sh"+" "+str(L)+" "+str(U)+" "+gampName+" "+gampPath+" "+str(i)+" "+str(maxEvents) - - return cmd - -def All(list): - for d in sorted(os.listdir(os.path.join(os.getcwd(),"MC"))): - if not d.isalpha(): - list.extend([str(d)]) - -def Clear(list): - del list[0:len(list)] - -def Delete(list): - del list[len(list)-1] - - -class Application(tk.Frame): - def __init__(self, parent): - tk.Frame.__init__(self, parent) - self.parent = parent - self.pack() - self.createWidgets() - - - - def createWidgets(self): - frame = tk.Frame(self) - frame1 = tk.Frame(self) - frame2 = tk.Frame(self) - text = tk.Text(self, width = 72, font=12) - frame.pack(side = "left") - frame1.pack(side = "left") - frame2.pack(side = "left") - text.pack(side = "top") - root.wm_title("GUI SUBMIT") - for d in sorted(os.listdir(os.path.join(os.getcwd(),"MC"))): - if not d.isalpha(): - if int(d.strip("_MeV")) < 1520: - add = tk.Button(frame) - add["text"] = "add "+str(d) - add["command"] = lambda d=d: submitted.extend([str(d)]) - add.pack(side = "top", fill = "both") - for d in sorted(os.listdir(os.path.join(os.getcwd(),"MC"))): - if not d.isalpha(): - if int(d.strip("_MeV")) > 1500 and int(d.strip("_MeV")) < 2020: - add = tk.Button(frame1) - add["text"] = "add "+str(d) - add["command"] = lambda d=d: submitted.extend([str(d)]) - add.pack(side = "top", fill = "both") - for d in sorted(os.listdir(os.path.join(os.getcwd(),"MC"))): - if not d.isalpha(): - if int(d.strip("_MeV")) > 2000 and int(d.strip("_MeV")) < 2520: - add = tk.Button(frame2) - add["text"] = "add "+str(d) - add["command"] = lambda d=d: submitted.extend([str(d)]) - add.pack(side = "top", fill = "both") - - self.All = tk.Button(self, text="ALL", fg="purple", command=lambda: All(submitted)) - self.Clear = tk.Button(self, text="CLEAR"+"\n"+"LIST", fg="red", command=lambda: Clear(submitted)) - self.Delete = tk.Button(self, text="DELETE"+"\n"+"LAST", fg="brown", command=lambda: Delete(submitted)) - self.Print = tk.Button(self, text="PRINT", fg="blue", command=lambda: text.insert("end","\n"+"i= "+str(i)+"\n"+str(submitted))) - self.Reset_Text = tk.Button(self, text="CLEAR"+"\n"+"TEXT", fg="orange", command=lambda: text.delete("0.0wordstart", "end")) - self.QUIT = tk.Button(self, text="DONE", fg="green", command=root.destroy) - - self.All.pack(side = "left", fill = "both") - self.Delete.pack(side="left", fill = "both") - self.Clear.pack(side="left", fill = "both") - self.Reset_Text.pack(side="left", fill = "both") - self.Print.pack(side = "left", fill = "both") - self.QUIT.pack(side="left", fill = "both") - - - -root = tk.Tk() -app = Application(parent=root) -app.mainloop() - -if __name__ == '__main__': - - A = str(raw_input("Submit these? (y/n) ")) - if A.lower() == "y": - for d in submitted: - print "Processing bin",d - submit(gen(d,parseDir(d))) - else: - print("Terminated") - - diff --git a/pythonPWA/pythonPWA/batchFarmServices/likelihoodTest.py b/pythonPWA/pythonPWA/batchFarmServices/likelihoodTest.py deleted file mode 100755 index 5ddea261..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/likelihoodTest.py +++ /dev/null @@ -1,55 +0,0 @@ -#! /u/apps/anaconda/anaconda-2.0.1/bin/python2 -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -""" - This is the main program for running the calculation of the log likelihood fitter/minuit -""" - -import numpy -import os -import sys -sys.path.append(os.path.join(sys.argv[2],"pythonPWA")) -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,Q=QFactor,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,rhoAA=rhoAA) -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_strategy(2) -m.set_up(0.5) -m.migrad(ncall=int(Control[6])) - -Vvalues = m.values -numpy.save(os.path.join(dataDir,"Vvalues.npy"),Vvalues) -covariance=numpy.array(m.matrix()) -numpy.save(os.path.join(dataDir,"minuitCovar3.npy"),covariance) diff --git a/pythonPWA/pythonPWA/batchFarmServices/massBinner.py b/pythonPWA/pythonPWA/batchFarmServices/massBinner.py deleted file mode 100755 index 1688de52..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/massBinner.py +++ /dev/null @@ -1,202 +0,0 @@ -#! /usr/bin/python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import numpy as np -import math -import os, sys -sys.path.append(os.path.join(sys.argv[1],"pythonPWA")) -from pythonPWA.utilities.FourVec import FourVector -from pythonPWA.fileHandlers.gampTranslator import gampTranslator -""" - This is the PyPWA mass binning utility that simulation/fitting install uses to bin .gamp files in mass. -""" - - -class massBinner(object): - - def __init__(self,indir=None,bindir=None,gfile=None,verb="q"): - """ - This is the default massBinner constructor. - - Kwargs: - indir (string): The full file path to the top directory. - bindir (string): The full file path to the directory where the new mass bin directories will be written. - gfile (string): The name of the .gamp file to be binned. (/Without/ the .gamp extension.) - verb (string): either "q" for quiet or "v" for verbose. - """ - - self.indir = indir - self.bindir = bindir - self.Control = np.load(os.path.join(sys.argv[1],"GUI","Control_List.npy")) - self.Qfile = os.path.join(sys.argv[1],"QFactor.txt") - self.pFfile = os.path.join(sys.argv[1],"events.pf") - self.gfile = gfile+".gamp" - self.nfile = gfile+".npy" - self.verb = verb - self.gampT = gampTranslator(os.path.join(self.indir,self.gfile)) - if not os.path.isfile(os.path.join(self.indir,self.nfile)): - if self.verb == "v": - print "Starting translator, for",self.gfile - self.gampList=self.gampT.translate(os.path.join(self.indir,self.nfile)) - self.nBins = int(((int(self.Control[3])-int(self.Control[2]))/int(self.Control[4])))+1 - self.bins = np.zeros(shape=(self.nBins,int(self.gampList.shape[0]))) - - def calcMass(self,event): - """ - This function calculates the mass of a single event. - - Args: - event (PyPWA gampEvent object) - - Returns: - mass of the event (float) - """ - - mass = FourVector(E=[0,0,0,0]) - for part in range(len(event.particles)): - if part > 1 and event.particles[part].particleID != 0: - pp = FourVector(E = [float(event.particles[part].particleE), - float(event.particles[part].particleXMomentum), - float(event.particles[part].particleYMomentum), - float(event.particles[part].particleZMomentum)]) - mass = mass.__add__(pp) - return math.sqrt(mass.dot(mass)) - - def binner(self): - """ - Creates a pass/fail 2D array mask for all bins and events. - """ - - for i in range(int(self.gampList.shape[0])): - event = self.gampT.writeEvent(self.gampList[i,:,:]) - mass = self.calcMass(event) - for x in range(0, self.nBins): - if mass >= (float(float(self.Control[2]) + (x * float(self.Control[4]))) / 1000.0) and mass < ( float(float(self.Control[2]) + ((x + 1) * float(self.Control[4]))) / 1000.0): - self.bins[x,i] = 1 - if self.verb == "v": - sys.stdout.write("Binning event "+str(i+1)+"\r") - sys.stdout.flush() - np.save("bins",self.bins) - - def fill(self,direct): - """ - Uses the bins p/f array mask to create all bin directories and fill all binned .gamp files. - - Args: - direct (string): keyword the program uses to know what kind of .gamp file is being binned and the directories to make. - """ - - if self.verb == "v": - print "\nStarting binner" - self.binner() - if os.path.isfile(self.Qfile) and direct == "data": - Qlist = np.loadtxt(self.Qfile) - elif os.path.isfile(self.pFfile) and direct == "flat": - pFlist = np.loadtxt(self.pFfile) - for b in range(self.nBins): - if "fitting" in self.bindir: - if not os.path.isdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV")): - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV")) - os.mkdir(os.path.join(self.bindir,"results",str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV")) - os.mkdir(os.path.join(self.bindir,"overflow",str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV")) - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV","data")) - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV","mc")) - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV","mc","acc")) - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV","mc","raw")) - if self.verb == "v" and b ==0: - print "\nWriting "+str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV"+" directories." - if self.verb == "v" and b !=0: - print "Writing "+str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV"+" directories." - elif "simulation" in self.bindir: - if not os.path.isdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV")): - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV")) - os.mkdir(os.path.join(self.bindir,"overflow",str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV")) - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV","flat")) - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV","weight")) - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV","weight","acc")) - os.mkdir(os.path.join(self.bindir,str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV","weight","raw")) - if self.verb == "v" and b ==0: - print "\nWriting "+str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV"+" directories." - if self.verb == "v" and b !=0: - print "Writing "+str(int(self.Control[2]) + (b * int(self.Control[4])))+"_MeV"+" directories." - if os.path.isfile(self.Qfile) and direct == "data": - totNum = 0 - for r in range(self.nBins): - num = 0 - with open(os.path.join(self.bindir,str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV",direct,"events.gamp"),"w") as gF: - with open(os.path.join(self.bindir,str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV",direct,"QFactor.txt"),"w") as qfF: - for i in range(int(self.gampList.shape[0])): - if self.bins[r,i] == 1: - event = self.gampT.writeEvent(self.gampList[i,:,:]) - event.writeGamp(gF) - qfF.write(str(Qlist[i])+"\n") - num+=1 - totNum+=num - with open(os.path.join(self.bindir,str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV",direct,"events.num"),"w") as nF: - nF.write(str(num)) - if num == 0 or self.verb == "v": - print direct , str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV" , "has" , str(num) , "events." - excluded = self.gampList.shape[0]-totNum - if self.verb == "v" or excluded != 0: - print "Binning Complete, " + str(excluded) + " events not in range." - elif os.path.isfile(self.pFfile) and direct == "flat": - totNum = 0 - for r in range(self.nBins): - num = 0 - with open(os.path.join(self.bindir,str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV",direct,"events.gamp"),"w") as gF: - with open(os.path.join(self.bindir,str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV",direct,"events.pf"),"w") as pfF: - for i in range(int(self.gampList.shape[0])): - if self.bins[r,i] == 1: - event = self.gampT.writeEvent(self.gampList[i,:,:]) - event.writeGamp(gF) - pfF.write(str(pFlist[i])+"\n") - num+=1 - totNum+=num - with open(os.path.join(self.bindir,str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV",direct,"events.num"),"w") as nF: - nF.write(str(num)) - if num == 0 or self.verb == "v": - print direct , str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV" , "has" , str(num) , "events." - excluded = self.gampList.shape[0]-totNum - if self.verb == "v" or excluded != 0: - print "Binning Complete, " + str(excluded) + " events not in range." - else: - totNum = 0 - for r in range(self.nBins): - num = 0 - with open(os.path.join(self.bindir,str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV",direct,"events.gamp"),"w") as gF: - for i in range(int(self.gampList.shape[0])): - if self.bins[r,i] == 1: - event = self.gampT.writeEvent(self.gampList[i,:,:]) - event.writeGamp(gF) - num+=1 - totNum+=num - with open(os.path.join(self.bindir,str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV",direct,"events.num"),"w") as nF: - nF.write(str(num)) - if num == 0 or self.verb == "v": - print direct , str(int(self.Control[2]) + (r * int(self.Control[4])))+"_MeV" , "has" , str(num) , "events." - excluded = self.gampList.shape[0]-totNum - if self.verb == "v" or excluded != 0: - print "Binning Complete, " + str(excluded) + " events not in range." - -if len(sys.argv)==4: - mB = massBinner(indir=sys.argv[1],bindir=sys.argv[2],gfile=sys.argv[3]) -if len(sys.argv)==5: - mB = massBinner(indir=sys.argv[1],bindir=sys.argv[2],gfile=sys.argv[3],verb=sys.argv[4]) - -if "data" in sys.argv[3]: - direct = "data" -if "acc" in sys.argv[3]: - direct = "mc/acc" -if "raw" in sys.argv[3] and "fitting" in sys.argv[2]: - direct = "mc/raw" -elif "raw" in sys.argv[3] and "simulation" in sys.argv[2]: - direct = "flat" -mB.fill(direct) - diff --git a/pythonPWA/pythonPWA/batchFarmServices/mvBAMP_GUI b/pythonPWA/pythonPWA/batchFarmServices/mvBAMP_GUI deleted file mode 100755 index d9f9076e..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/mvBAMP_GUI +++ /dev/null @@ -1,54 +0,0 @@ -#! /usr/bin/python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" - -import os, glob, sys -from subprocess import Popen - -nfile = sys.argv[2]+".bamp" -oI = sys.argv[1] -""" - This is the program used by the PWA_GUI's wave function to move .bamp files between the fit/simulation and the /overflow directory. -""" - -if os.path.isdir(os.path.join(os.getcwd().strip("GUI"),"fitting")): - for d in os.listdir(os.path.join(os.getcwd().strip("GUI"),"fitting")): - if "_MeV" in d: - for m in ("mc","data"): - if m == "data": - if oI == "o": - cmd = 'mv '+os.path.join(os.getcwd().strip("GUI"),"fitting",str(d),str(m),nfile)+" "+os.path.join(os.getcwd().strip("GUI"),"fitting","overflow",str(d),str(m)+str(nfile)) - if oI == "i": - cmd = 'mv '+os.path.join(os.getcwd().strip("GUI"),"fitting","overflow",str(d),str(m)+str(nfile))+" "+os.path.join(os.getcwd().strip("GUI"),"fitting",str(d),str(m),nfile) - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - if m == "mc": - for a in ("acc","raw"): - if oI == "o": - cmd = 'mv '+os.path.join(os.getcwd().strip("GUI"),"fitting",str(d),str(m),str(a),nfile)+" "+os.path.join(os.getcwd().strip("GUI"),"fitting","overflow",str(d),str(a)+str(m)+str(nfile)) - if oI == "i": - cmd = 'mv '+os.path.join(os.getcwd().strip("GUI"),"fitting","overflow",str(d),str(a)+str(m)+str(nfile))+" "+os.path.join(os.getcwd().strip("GUI"),"fitting",str(d),str(m),str(a),nfile) - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - sys.stdout.write(d.rstrip("_MeV")+"\r") - sys.stdout.flush() - print "DONE " -elif os.path.isdir(os.path.join(os.getcwd().strip("GUI"),"simulation")): - for d in os.listdir(os.path.join(os.getcwd().strip("GUI"),"simulation")): - if "_MeV" in d: - if oI == "o": - cmd = 'mv '+os.path.join(os.getcwd().strip("GUI"),"simulation",str(d),"flat",nfile)+" "+os.path.join(os.getcwd().strip("GUI"),"simulation","overflow",str(d),"flat"+str(nfile)) - if oI == "i": - cmd = 'mv '+os.path.join(os.getcwd().strip("GUI"),"simulation","overflow",str(d),"flat"+str(nfile))+" "+os.path.join(os.getcwd().strip("GUI"),"simulation",str(d),"flat",nfile) - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - sys.stdout.write(d.rstrip("_MeV")+"\r") - sys.stdout.flush() - print "DONE " diff --git a/pythonPWA/pythonPWA/batchFarmServices/pwa_controls b/pythonPWA/pythonPWA/batchFarmServices/pwa_controls deleted file mode 100755 index 6d62af89..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/pwa_controls +++ /dev/null @@ -1,240 +0,0 @@ -#! /u/apps/anaconda/anaconda-2.0.1/bin/python2 -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import Tkinter as tk -import numpy, os, sys -if "GUI" in os.getcwd(): - sys.path.append(os.path.join(os.getcwd().rstrip("GUI"),"pythonPWA")) - from batchFarmServices.graphicHelp import Help -else: - from graphicHelp import Help - -class Control(object): - """ - This program is the pwa_controls GUI, or the gui the user uses to specify environment variables for PyPWA. - """ - - def __init__(self, - reactMode = 24, - BeamPole = 0.4, - LoMass = 1000, - UpMass = 2500, - RaMass = 20, - NumSet = 20, - MigNcal = 1000, - reactNm = None, - pltLstNm = None, - project = None): - - self.reactModeL = reactMode - self.BeamPoleL = BeamPole - self.UpMassL = UpMass - self.LoMassL = LoMass - self.RaMassL = RaMass - self.NumSetL = NumSet - self.MigNcalL = MigNcal - self.reactNmL = reactNm - self.pltLstNmL = pltLstNm - self.project = project - - def reactMode(self): - rM = ent0.get() - self.reactModeL = rM - - def BeamPole(self): - Bp = ent1.get() - self.BeamPoleL = Bp - - def LoMass(self): - Lm = ent2.get() - self.LoMassL = Lm - - def UpMass(self): - Um = ent3.get() - self.UpMassL = Um - - def RaMass(self): - Rm = ent4.get() - self.RaMassL = Rm - - def NumSet(self): - Ns = ent5.get() - self.NumSetL = Ns - - def MigNcal(self): - MnC = ent6.get() - self.MigNcalL = MnC - - def reactNm(self): - rNm = ent7.get() - self.reactNmL = rNm - - def pltLstNm(self): - plN = ent8.get() - self.pltLstNmL = plN - - def projNm(self): - prN = ent9.get() - self.project = prN - - def run(self): - self.reactMode() - self.BeamPole() - self.LoMass() - self.UpMass() - self.RaMass() - self.NumSet() - self.MigNcal() - self.reactNm() - self.pltLstNm() - self.projNm() - - def load(self,Con): - self.reactModeL = Con[0] - self.BeamPoleL = Con[1] - self.LoMassL = Con[2] - self.UpMassL = Con[3] - self.RaMassL = Con[4] - self.NumSetL = Con[5] - self.MigNcalL = Con[6] - self.reactNmL = Con[7] - self.pltLstNmL = Con[8] - self.project = Con[9] - - ent0.insert("end",Con[0]) - ent1.insert("end",Con[1]) - ent2.insert("end",Con[2]) - ent3.insert("end",Con[3]) - ent4.insert("end",Con[4]) - ent5.insert("end",Con[5]) - ent6.insert("end",Con[6]) - ent7.insert("end",Con[7]) - ent8.insert("end",Con[8]) - ent9.insert("end",Con[9]) - - def save(self): - self.run() - Con = [int(self.reactModeL), - float(self.BeamPoleL), - int(self.LoMassL), - int(self.UpMassL), - int(self.RaMassL), - int(self.NumSetL), - int(self.MigNcalL), - self.reactNmL, - self.pltLstNmL, - self.project] - numpy.save(os.getcwd()+"/Control_List.npy",Con) - root.destroy() - - def help_window(self): - window = tk.Toplevel(root) - window.wm_title("HELP") - tx = Help() - label = tk.Label(window, text=tx.CFhelp) - label.pack(side="top", fill="both", padx=10, pady=10) - - -Lst = ['Reaction Mode ', - 'Beam Polorization ', - 'Lower Mass ', - 'Upper Mass ', - 'Mass Range ', - 'Number of Sets ', - 'Max Number of Migrad Calls ', - 'Name of tested Reaction', - 'Name of saved plotting data', - 'Batch Farm project name'] - -Contr = Control() - -root = tk.Tk() -root.wm_title("PWA CONTROLS") - -frame=tk.Frame(root) -frame.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") - -L0=tk.Label(frame,text=Lst[0]) -L0.pack(side="top") - -ent0=tk.Entry(frame, width=30, font=55) -ent0.pack(side="top") - -L1=tk.Label(frame,text=Lst[1]) -L1.pack(side="top") - -ent1=tk.Entry(frame, width=30, font=55) -ent1.pack(side="top") - -L2=tk.Label(frame,text=Lst[2]) -L2.pack(side="top") - -ent2=tk.Entry(frame, width=30, font=55) -ent2.pack(side="top") - -L3=tk.Label(frame,text=Lst[3]) -L3.pack(side="top") - -ent3=tk.Entry(frame, width=30, font=55) -ent3.pack(side="top") - -L4=tk.Label(frame,text=Lst[4]) -L4.pack(side="top") - -ent4=tk.Entry(frame, width=30, font=55) -ent4.pack(side="top") - -L5=tk.Label(frame,text=Lst[5]) -L5.pack(side="top") - -ent5=tk.Entry(frame, width=30, font=55) -ent5.pack(side="top") - -L6=tk.Label(frame,text=Lst[6]) -L6.pack(side="top") - -ent6=tk.Entry(frame, width=30, font=55) -ent6.pack(side="top") - -L7=tk.Label(frame,text=Lst[7]) -L7.pack(side="top") - -ent7=tk.Entry(frame, width=30, font=55) -ent7.pack(side="top") - -L8=tk.Label(frame,text=Lst[8]) -L8.pack(side="top") - -ent8=tk.Entry(frame, width=30, font=55) -ent8.pack(side="top") - -L9=tk.Label(frame,text=Lst[9]) -L9.pack(side="top") - -ent9=tk.Entry(frame, width=30, font=55) -ent9.pack(side="top") - -frame1=tk.Frame(frame) -frame1.pack(side="top") - -btnS=tk.Button(frame1, text="SAVE", command= lambda: Contr.save()) -btnS.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") - -btnH=tk.Button(frame1,text="HELP",command=lambda: Contr.help_window()) -btnH.grid(row=0,column=1,sticky="N"+"S"+"E"+"W") - -if os.path.isfile(os.getcwd()+"/Control_List.npy"): - Con = numpy.load(os.getcwd()+"/Control_List.npy") - Contr.load(Con) - -root.mainloop() - - - diff --git a/pythonPWA/pythonPWA/batchFarmServices/resonances.txt b/pythonPWA/pythonPWA/batchFarmServices/resonances.txt deleted file mode 100755 index eb44e3cd..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/resonances.txt +++ /dev/null @@ -1,6 +0,0 @@ -# resonances.txt is the control file that devTest uses to get resonances to simulate from waves. -# Add resonaces starting on line 7 in the format cR (float) wR (list) w0 (float) r0 (float) phase (float) -# The sum of all cR for /all/ resonances needs to be 1.0 and the sum of the wR list for /each/ resonance needs to be 1.0 -# Ex: 1.0 1.0,0.0 1.0 0.5 0.0 -# One resonance to a line and use the # to comment. -# diff --git a/pythonPWA/pythonPWA/batchFarmServices/rhoAA.py b/pythonPWA/pythonPWA/batchFarmServices/rhoAA.py deleted file mode 100755 index 512bd5f7..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/rhoAA.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import numpy as np -import os -from pythonPWA.model.spinDensity import spinDensity - -class rhoAA(object): - """ - This class calculates the 3D numpy array, rhoAA. Each value is the spin density matrix times a wave times the complex conjugate of another wave and - possibly times Q. - """ - def __init__(self, - waves=[], - alphaList=[], - Q = [1], - beamPolarization=0.4): - """ - Default rhoAA constructor. - - Kwargs: - waves (array): Array of all waves in this pwa fit/simulation. - alphaList (list): List of all alpha values for this mass bin. - Q (list): List of all Q values for this mass bin. - beamPolarization (float): Value of beam polarization; 0.0 for no polarization. - - """ - self.waves=waves - self.alphaList=alphaList - self.Q = Q - self.beamPolarization=beamPolarization - self.eventNumber=len(self.alphaList) - self.nwaves=len(self.waves) - self.rhoAA = np.empty(shape=(self.nwaves,self.nwaves,self.eventNumber),dtype=np.complex) - - def calc(self): - """ - Function that does the work of calculating rhoAA - - Return: - rhoAA (numpy ndarray): Note, this class does NOT save the array and must be saved after returning. - """ - for n in range(self.eventNumber): - for i,iwave in enumerate(self.waves): - for j,jwave in enumerate(self.waves): - Ai = iwave.complexamplitudes[n] - Aj = jwave.complexamplitudes[n] - if len(self.Q) == 1: - self.rhoAA[i,j,n] = spinDensity(self.beamPolarization,self.alphaList[n])[iwave.epsilon,jwave.epsilon] * Ai * np.conjugate(Aj) - else: - self.rhoAA[i,j,n] = float(self.Q[n]) * spinDensity(self.beamPolarization,self.alphaList[n])[iwave.epsilon,jwave.epsilon] * Ai * np.conjugate(Aj) - return self.rhoAA diff --git a/pythonPWA/pythonPWA/batchFarmServices/run_normintFARM.py b/pythonPWA/pythonPWA/batchFarmServices/run_normintFARM.py deleted file mode 100755 index 9a7e8611..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/run_normintFARM.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -.. 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) diff --git a/pythonPWA/pythonPWA/batchFarmServices/simulation_Install b/pythonPWA/pythonPWA/batchFarmServices/simulation_Install deleted file mode 100755 index 03074aa8..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/simulation_Install +++ /dev/null @@ -1,74 +0,0 @@ -#! /u/apps/anaconda/anaconda-2.0.1/bin/python2 -import os -import numpy,sys -import subprocess as sp -from subprocess import Popen -""" - This program is the first step for the PyPWA simulation process. It sets up all directories and files needed for simulation - 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")) -if not os.path.isfile(os.path.join("Control_List.npy")): - sp.call("pwa_controls") -Control = numpy.load(os.path.join("Control_List.npy")) -print("Creating directory structure for PyPWA fitting") -tdirs = ("GUI","keyfiles","scripts","simulation") -for i in tdirs: - directoryBuffer=os.path.join(indir,str(i)) - os.makedirs(directoryBuffer) - if i != tdirs[-1]: - sys.stdout.write("Writing Directories"+"."*(tdirs.index(i)+1)+"\r") - sys.stdout.flush() - elif i == tdirs[-1]: - sys.stdout.write("Writing Directories"+"."*(tdirs.index(i)+1)+"\r\n") - sys.stdout.flush() - if i == "simulation": - directoryBuffer=os.path.join(indir,"simulation","overflow") - os.makedirs(directoryBuffer) - if i == "GUI": - directoryBuffer=os.path.join(indir,"GUI","plotLists") - os.makedirs(directoryBuffer) - if i == "scripts": - directoryBuffer=os.path.join(indir,"scripts","submitions") - os.makedirs(directoryBuffer) -progs = ("generateAlphaNPY.py","GUI_alpha_main.py", -"GUI_gamp_main.py","GUI_subPyNormInt.py","mvBAMP_GUI", -"run_normintFARM.py","massBinner.py", -"getImax.py","resonances.txt","simulatorMain.py","subSimulator") -for s in progs: - cmd = 'cp '+os.path.join(os.getcwd(),str(s))+" "+os.path.join(indir,"scripts") - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - if s != progs[-1]: - sys.stdout.write("Filling scripts"+"."*(progs.index(s)+1)+"\r") - sys.stdout.flush() - elif s == progs[-1]: - sys.stdout.write("Filling scripts"+"."*(progs.index(s)+1)+"\r\n") - sys.stdout.flush() -guis = ("graphicPlotSim","pwa_controls","PWA_GUI","Control_List.npy") -for g in guis: - if g != guis[-1]: - cmd = 'cp '+os.path.join(os.getcwd(),str(g))+" "+os.path.join(indir,"GUI") - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - sys.stdout.write("Filling GUI"+"."*(guis.index(g)+1)+"\r") - sys.stdout.flush() - elif g == guis[-1]: - cmd = 'mv '+os.path.join(os.getcwd(),str(g))+" "+os.path.join(indir,"GUI") - proc = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - proc.wait() - sys.stdout.write("Filling GUI"+"."*(guis.index(g)+1)+"\r\n") - sys.stdout.flush() -cmd = "mv "+indir+"/*.keyfile "+os.path.join(indir,"keyfiles") -procx = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) -procx.wait() -print "Filling keyfiles" -for fil in os.listdir(indir): - if ".gamp" in fil: - cmd = "python "+indir+"/scripts/massBinner.py "+os.path.join(indir)+" "+os.path.join(indir,"simulation")+" "+str(fil).rstrip(".gamp")+" v" - procx = Popen(cmd,shell = True,executable = os.environ.get('SHELL', '/bin/tcsh'),env = os.environ) - procx.wait() - -print "Welcome to PyPWA!\nYou are now ready to start Partial Wave Analysis!" diff --git a/pythonPWA/pythonPWA/batchFarmServices/simulatorMain.py b/pythonPWA/pythonPWA/batchFarmServices/simulatorMain.py deleted file mode 100755 index 868ca568..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/simulatorMain.py +++ /dev/null @@ -1,114 +0,0 @@ -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import numpy -import os -import sys -sys.path.append(os.path.join(sys.argv[2],"pythonPWA")) -from pythonPWA.fileHandlers.getWavesGen import getwaves -from batchFarmServices.dataSimulatorNPY import dataSimulator -from pythonPWA.model.complexV import complexV -from pythonPWA.dataTypes.resonance import resonance -from pythonPWA.model.nTrue import nTrueForFixedV1V2 as ntrue -from pythonPWA.model.nTrue import nTrueForFixedV1V2AndWave as ntrueforwave -import operator -from batchFarmServices.rhoAA import rhoAA -""" - This is the main simualtion program for PyPWA simulation. It creates the iList and the simulated gamp files. It can do this using the - fitted V values or from the pre chosen waves and resonences. - - Args: - bin (string) - topDir (string) - output (char) -""" - -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) - numpy.save(os.path.join(dataDir,"flat","nTrueListR.npy"),nTrueList) -elif os.path.isfile(os.path.join(topDir,"scripts","resonances.txt")): - resonances=[] - res = open(os.path.join(topDir,"scripts","resonances.txt")) - rez = res.readlines() - for re in rez: - if re[0] != "#" and re[0] != " " and re[0] != "\n": - rev = re.split(" ") - wRx = [(float(x)) for x in rev[1].split(",")] - resonances.append(resonance(cR=float(rev[0])*maxNumberOfEvents,wR=wRx,w0=float(rev[2]),r0=float(rev[3]),phase=float(rev[4]))) - for resonance in resonances: - for wave in waves: - productionAmplitudes.append(complexV(resonance,wave,waves,normint,testMass)) - if sys.argv[3] == "s": - numpy.save(os.path.join(dataDir,"flat","calcVvalues.npy"),productionAmplitudes) - 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) - numpy.save(os.path.join(dataDir,"flat","nTrueListR.npy"),nTrueList) - if len(productionAmplitudes) == 0: - print "There are no resonances in resonances.txt, modify it in /scripts and try again." - exit() -else: - print "There is neither a resonance.txt file, or a Vvalues.npy file consult the documentation and try again." - exit() - -if sys.argv[3] == "i": - rAA = rhoAA(waves=waves,alphaList=alphaList,beamPolarization=float(Control[1])) - rhoAA = rAA.calc() - numpy.save(os.path.join(dataDir,"flat","rhoAA.npy"),rhoAA) - - dSimulator=dataSimulator(mass=testMass,waves=waves,productionAmplitudes=productionAmplitudes,normint=normint,alphaList=alphaList,rhoAA=rhoAA) - iList = dSimulator.calcIList() - numpy.save(os.path.join(dataDir,"flat","iList"),iList) - -elif sys.argv[3] == "s": - inputGampFile=open(os.path.join(dataDir,"flat","events.gamp"),'r') - inputPfFile=open(os.path.join(dataDir,"flat","events.pf"),'r') - outputPFGampFile=open(os.path.join(dataDir,"weight","raw","events_pf.gamp"),'w') - outputRawGampFile=open(os.path.join(dataDir,"weight","raw","events.gamp"),'w') - outputAccGampFile=open(os.path.join(dataDir,"weight","acc","events.gamp"),'w') - - iList = numpy.load(os.path.join(dataDir,"flat","iList.npy")) - - iMax = numpy.load(os.path.join(topDir,"simulation","iMax.npy")) - - dSimulator=dataSimulator(mass=testMass,waves=waves,productionAmplitudes=productionAmplitudes,normint=normint,alphaList=alphaList,rhoAA=rhoAA,iList=iList,iMax=iMax[0]) - - dSimulator.execute(inputGampFile,outputRawGampFile,outputAccGampFile,inputPfFile,outputPFGampFile) - -else: - print "The last argument must be either i to calculate iList, or s to do the simulation." - exit() diff --git a/pythonPWA/pythonPWA/batchFarmServices/subLikelihood b/pythonPWA/pythonPWA/batchFarmServices/subLikelihood deleted file mode 100755 index 42fb04b1..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/subLikelihood +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import os, glob, shutil, time, numpy -from subprocess import Popen - -indir = os.getcwd().strip("GUI") -Control = numpy.load(os.path.join(indir,"GUI","Control_List.npy")) -scriptOutDir=os.path.join(indir,"scripts","submitions") -""" - This is submition program for the likelihood program -""" - -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, - executable = os.environ.get('SHELL', '/bin/tcsh'), - env = os.environ) - time.sleep(.5) - -def gen(directory,cmd): - """ - This function creates the jsub .txt file to be submitted to the JLab batch farm. - - Args: - directory (string): The file name for the jsub file. - cmd (string): The full command to be used in the jsub file. - - Returns: - jsub_filename (string): name of the jsub file created by this function. - """ - auger_opts = dict( - project = Control[9], - track = 'analysis', - jobname = 'fitLike', - os = 'centos65', - memory = "3000 MB", - time = 60, - cmd = cmd) - jsub_filename = os.path.join(scriptOutDir,directory) - jsub_file = open(jsub_filename,'w') - jsub_file.write('''\ -PROJECT:{project} -TRACK:{track} -JOBNAME:{jobname} -OS:{os} -MEMORY:{memory} -TIME:{time} -COMMAND:{cmd} -'''.format(**auger_opts)) - jsub_file.close() - return jsub_filename - -def parseDir(Bin): - """ - This function creates the cmd string to be submitted to the JLab batch farm. - - Args: - bin (int): The int value for the mass in MeV for the mass bin. - - Returns: - cmd (string): The full command to be used in the jsub file. - """ - cmd = os.path.join(indir,"scripts","likelihoodTest.py")+" "+str(Bin)+" "+indir - return cmd - -if __name__ == '__main__': - top = int(Control[2]) - bot = int(Control[3]) - ran = int(Control[4]) - for i in range(top,bot+ran,ran): - print "Processing bin",i - submit(gen(str(i)+"_MeV",parseDir(i))) diff --git a/pythonPWA/pythonPWA/batchFarmServices/subSimulator b/pythonPWA/pythonPWA/batchFarmServices/subSimulator deleted file mode 100755 index 31e99617..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/subSimulator +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import os, glob -from subprocess import Popen -import time, sys, numpy - -#add bin selection via -indir = os.getcwd().strip("GUI") -Control = numpy.load(os.path.join(indir,"GUI","Control_List.npy")) -scriptOutDir=os.path.join(indir,"scripts","submitions") -""" - This is submition program for the simulator. -""" - -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, - executable = os.environ.get('SHELL', '/bin/tcsh'), - env = os.environ) - time.sleep(1) - - - - -def gen(directory,cmd): - """ - This function creates the jsub .txt file to be submitted to the JLab batch farm. - - Args: - directory (string): The file name for the jsub file. - cmd (string): The full command to be used in the jsub file. - - Returns: - jsub_filename (string): name of the jsub file created by this function. - """ - auger_opts = dict( - project = Control[9], - track = 'analysis', - jobname = 'simulator', - os = 'centos65', - memory = '1000 MB', - time = 30, - cmd = cmd) - - jsub_filename = os.path.join(scriptOutDir,directory) - jsub_file = open(jsub_filename,'w') - jsub_file.write('''\ -PROJECT:{project} -TRACK:{track} -JOBNAME:{jobname} -OS:{os} -MEMORY:{memory} -TIME:{time} -COMMAND:{cmd} -'''.format(**auger_opts)) - - jsub_file.close() - - return jsub_filename - -def parseDir(Bin): - """ - This function creates the cmd string to be submitted to the JLab batch farm. - - Args: - bin (int): The int value for the mass in MeV for the mass bin. - - Returns: - cmd (string): The full command to be used in the jsub file. - """ - cmd = "/u/apps/anaconda/anaconda-2.0.1/bin/python2 "+os.path.join(indir,"scripts","simulatorMain.py")+" "+str(Bin)+" "+indir+" "+sys.argv[1] - - return cmd - - - -if __name__ == '__main__': - top = int(Control[2]) - bot = int(Control[3]) - ran = int(Control[4]) - for i in range(top,bot+ran,ran): - print "Processing bin",i - submit(gen(str(i)+"_MeV",parseDir(i))) diff --git a/pythonPWA/pythonPWA/batchFarmServices/subWalkNTrue b/pythonPWA/pythonPWA/batchFarmServices/subWalkNTrue deleted file mode 100755 index 83211ecd..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/subWalkNTrue +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/python -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import os, glob, time, numpy -from subprocess import Popen - -indir = os.getcwd().strip("GUI") -Control = numpy.load(os.path.join(indir,"GUI","Control_List.npy")) -scriptOutDir=os.path.join(indir,"scripts","submitions") - -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, - executable = os.environ.get('SHELL', '/bin/tcsh'), - env = os.environ) - time.sleep(.5) - -def gen(directory,cmd): - """ - This function creates the jsub .txt file to be submitted to the JLab batch farm. - - Args: - directory (string): The file name for the jsub file. - cmd (string): The full command to be used in the jsub file. - - Returns: - jsub_filename (string): name of the jsub file created by this function. - """ - auger_opts = dict( - project = Control[9], - track = 'analysis', - jobname = 'WalkNTrue', - os = 'centos65', - time = 30, - cmd = cmd) - jsub_filename = os.path.join(scriptOutDir,directory) - jsub_file = open(jsub_filename,'w') - jsub_file.write('''\ -PROJECT:{project} -TRACK:{track} -JOBNAME:{jobname} -OS:{os} -TIME:{time} -COMMAND:{cmd} -'''.format(**auger_opts)) - jsub_file.close() - return jsub_filename - -def parseDir(Bin): - """ - This function creates the cmd string to be submitted to the JLab batch farm. - - Args: - bin (int): The int value for the mass in MeV for the mass bin. - - Returns: - cmd (string): The full command to be used in the jsub file. - """ - cmd = os.path.join(indir,"scripts","walkingNTrue.py")+" "+str(Bin)+" "+indir - return cmd - -if __name__ == '__main__': - top = int(Control[2]) - bot = int(Control[3]) - ran = int(Control[4]) - for i in range(top,bot+ran,ran): - print "Processing bin",i - submit(gen(str(i)+"_MeV",parseDir(i))) diff --git a/pythonPWA/pythonPWA/batchFarmServices/walkingNTrue.py b/pythonPWA/pythonPWA/batchFarmServices/walkingNTrue.py deleted file mode 100755 index 68b08532..00000000 --- a/pythonPWA/pythonPWA/batchFarmServices/walkingNTrue.py +++ /dev/null @@ -1,126 +0,0 @@ -#! /u/apps/anaconda/anaconda-2.0.1/bin/python2 -""" -.. module:: batchFarmServices - :platform: Unix, Windows, OSX - :synopsis: Utilities for doing PWA with the Jlab batch system. - -.. moduleauthor:: Joshua Pond - - -""" -import numpy -import os -import sys -sys.path.append(os.path.join(sys.argv[2],"pythonPWA")) -from pythonPWA.dataTypes.resonance import resonance -from pythonPWA.fileHandlers.getWavesGen import getwaves -from pythonPWA.model.normInt import normInt -from pythonPWA.model.intensity import intensity -from pythonPWA.fileHandlers.gampReader import gampReader -from pythonPWA.utilities.dataSimulator import dataSimulator -from pythonPWA.model.nTrue import nTrueForFixedV1V2 as ntrue -from pythonPWA.model.nTrue import nTrueForFixedV1V2AndWave as ntrueforwave -from pythonPWA.model.nExpected import nExpForFixedV1V2 as nExp -from pythonPWA.model.nExpected import nExpForFixedV1V2AndWave as nExpforwave -from pythonPWA.model.nTrue import calcStatSquaredError -import operator - -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 - -retList=[] -topDir = os.path.join(sys.argv[2],"fitting") -print"processing", sys.argv[1] -ret=calcNTrueForDir(os.path.join(topDir,sys.argv[1]+"_MeV")) -retList.append(ret) - -plotLists=[[] for i in range(len(retList[0]))] -for bin in retList: - for item in bin: - plotLists[bin.index(item)].append(item) -for lists in plotLists: - numpy.save(os.path.join(topDir,"results",sys.argv[1]+"_MeV","nTrueList-"+str(plotLists.index(lists))+"_"+sys.argv[1]+".npy"),lists) - diff --git a/pythonPWA/pythonPWA/fileHandlers/gampTranslator.py b/pythonPWA/pythonPWA/fileHandlers/gampTranslator.py index 12a0da33..4f90d14a 100644 --- a/pythonPWA/pythonPWA/fileHandlers/gampTranslator.py +++ b/pythonPWA/pythonPWA/fileHandlers/gampTranslator.py @@ -74,9 +74,13 @@ def translate(self,saveFile): Args: saveFile (string): The file name the user wants the file named(will end in .npy). + + Returns: + The 3D numpy array of gamp events """ self.readFile() numpy.save(saveFile,self.events) + return self.events def writeEvent(self,dataSlice): """ diff --git a/pythonPWA/pythonPWA/pythonPWA/__init__.py b/pythonPWA/pythonPWA/pythonPWA/__init__.py deleted file mode 100644 index 3c33f643..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" - This is the pythonPWA core -""" diff --git a/pythonPWA/pythonPWA/pythonPWA/dataTypes/__init__.py b/pythonPWA/pythonPWA/pythonPWA/dataTypes/__init__.py deleted file mode 100644 index ea0ba1e9..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/dataTypes/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -This module contains the various data types used within the PWA project. -""" \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/dataTypes/gampEvent.py b/pythonPWA/pythonPWA/pythonPWA/dataTypes/gampEvent.py deleted file mode 100644 index 5a4fa84a..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/dataTypes/gampEvent.py +++ /dev/null @@ -1,54 +0,0 @@ -""" -.. module:: pythonPWA.dataTypes - :platform: Unix, Windows, OSX - :synopsis: Various data types used within the PWA project. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -class gampEvent(): - """ - This class represents a single gamp event. That is to say that - this class contains a set of particles and a flag to specify if - this event is accepted into the filtered data set. - """ - def __init__(self, - particles=[], - accepted=None, - raw=None): - """ - gampEvent class default constructor. - - Kwargs: - particles (list): A list of gampParticle items. - accepted (bool): Flag to denote if the gampEvent instance is accepted. - raw (bool): Flag to denote if the gampEvent instance is raw. - - """ - self.particles=particles - self.raw=raw - self.accepted=accepted - - def writeGamp(self,outputFile): - """ - This function writes a gamp event instance to an output file. - - Args: - outputFile (file): Output .gamp file to write the event instance to. - """ - outputFile.write(str(len(self.particles))+"\n") - for particle in self.particles: - outputFile.write(particle.toString()) - - def writeGampIfAccepted(self,outputFile): - """ - This function writes a gamp event instance to an output file, - but only if the accepted data member of said gamp event instance - is True. - - Args: - outputFile (file): Output .gamp file to write the event instance to. - """ - if self.accepted==True: - self.writeGamp(outputFile) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/dataTypes/gampParticle.py b/pythonPWA/pythonPWA/pythonPWA/dataTypes/gampParticle.py deleted file mode 100644 index c1ef0618..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/dataTypes/gampParticle.py +++ /dev/null @@ -1,47 +0,0 @@ -""" -.. module:: pythonPWA.dataTypes - :platform: Unix, Windows, OSX - :synopsis: Various data types used within the PWA project. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -class gampParticle(): - """ - This class represents a particle described in a single line of a - .gamp file. - """ - def __init__(self, - particleID=None, - particleCharge=None, - particleXMomentum=None, - particleYMomentum=None, - particleZMomentum=None, - particleE=None): - """ - gampParticle class default constructor. - - Kwargs: - particleID (int): Key used to lookup the type of this particle. - particleCharge (float): The electric charge value of this particle. - particleXMomentum (float): X-direction momentum of this particle. - particleYMomentum (float): Y-direction momentum of this particle. - particleZMomentum (float): Z-direction momentum of this particle. - particleE (float): Total energy of this particle. - """ - self.particleID=particleID - self.particleCharge=particleCharge - self.particleXMomentum=particleXMomentum - self.particleYMomentum=particleYMomentum - self.particleZMomentum=particleZMomentum - self.particleE=particleE - - def toString(self): - """ - Returns a string of the particle data members delimited by newlines. - """ - if "\n" in str(self.particleE): - return " ".join([str(self.particleID),str(self.particleCharge),str(self.particleXMomentum),str(self.particleYMomentum),str(self.particleZMomentum),str(self.particleE)]) - elif not "\n" in str(self.particleE): - return " ".join([str(int(self.particleID)),str(int(self.particleCharge)),str(self.particleXMomentum),str(self.particleYMomentum),str(self.particleZMomentum),str(self.particleE)+"\n"]) diff --git a/pythonPWA/pythonPWA/pythonPWA/dataTypes/resonance.py b/pythonPWA/pythonPWA/pythonPWA/dataTypes/resonance.py deleted file mode 100644 index 84344b4b..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/dataTypes/resonance.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -.. module:: pythonPWA.dataTypes - :platform: Unix, Windows, OSX - :synopsis: Various data types used within the PWA project. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -class resonance(): - """ - This class represents a resonance. - """ - def __init__(self, - cR=1.0, - wR=[], - w0=1., - r0=.5, - phase=0.): - """ - Default constructor for resonance class. - - Kwargs: - cR (float): - wR (list): - w0 (float): - r0 (float): - phase (float): - """ - self.wR=wR - self.cR=cR - self.w0=w0 - self.r0=r0 - self.phase=phase - - def toString(self): - """ - Returns a string of the resonance data memebers delimited by newlines. - """ - return "\n".join(["wR="+str(self.wR),"cR="+str(self.cR),"w0="+str(self.w0),"r0="+str(self.r0)]) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/dataTypes/wave.py b/pythonPWA/pythonPWA/pythonPWA/dataTypes/wave.py deleted file mode 100644 index be1d03c5..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/dataTypes/wave.py +++ /dev/null @@ -1,42 +0,0 @@ -""" -.. module:: pythonPWA.dataTypes - :platform: Unix, Windows, OSX - :synopsis: Various data types used within the PWA project. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -class wave(): - """ - This class represents a PWA wave. - """ - def __init__(self, - epsilon=0, - complexamplitudes=[], - w0=1000., - r0=100., - beta=0, - k=0, - filename=None): - - """ - Default constructor for the wave class - - Kwargs: - epsilon (int): Integer representing reflectivity of this wave. - beta (int): - k (int): - filename (string): Name of the file used to instantiate a wave instance, if getwaves was used to instantiate the wave instance. - """ - self.epsilon=epsilon - self.complexamplitudes=complexamplitudes - self.beta=beta - self.k=k - self.filename=filename - - def toString(self): - """ - returns a string of all the wave properties delimited by newlines. - """ - return "\n".join(["epsilon="+str(self.epsilon),"len(complexamplitudes)="+str(len(self.complexamplitudes)),"beta="+str(self.beta),"k="+str(self.k)]) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/__init__.py b/pythonPWA/pythonPWA/pythonPWA/fileHandlers/__init__.py deleted file mode 100644 index d0759805..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -""" -This module contains a few convience classes written to make working with the data types of the -PWA project easier whilst writing tools in python. -""" \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/bampReader.py b/pythonPWA/pythonPWA/pythonPWA/fileHandlers/bampReader.py deleted file mode 100644 index ce75aff6..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/bampReader.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -.. module:: pythonPWA.fileHandlers - :platform: Unix, Windows, OSX - :synopsis: Utilities for working with common PWA file formats. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy - -def readBamp(filename): - """ - This is a general bamp reading function. - - Args: - filename (string): Path to bamp file to be read. - - Returns: - List of numpy.complexes representing the complex amplitudes of the wave represented by the file. - """ - temp1=numpy.fromfile(file=filename,dtype=numpy.dtype('f8')) - temp2=temp1.reshape((2,-1),order='F') - temp3=[] - for lineNumber in range(temp2.shape[1]): - temp3.append(numpy.complex(temp2[0,lineNumber],temp2[1,lineNumber])) - return temp3 \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/gampReader.py b/pythonPWA/pythonPWA/pythonPWA/fileHandlers/gampReader.py deleted file mode 100644 index 8f6e586d..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/gampReader.py +++ /dev/null @@ -1,73 +0,0 @@ -""" -.. module:: pythonPWA.fileHandlers - :platform: Unix, Windows, OSX - :synopsis: Utilities for working with common PWA file formats. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import sys -import os - - -from pythonPWA.dataTypes.gampParticle import gampParticle -from pythonPWA.dataTypes.gampEvent import gampEvent - -class gampReader(): - """ - This class is a convience class used to ease the reading (and eventually writing) of gamp files. - """ - def __init__(self, - gampFile=None): - - """ - Default gampReader constructor. - - Kwargs: - gampFile (file): Must be an open file handle, gamp file to be read. - - """ - - self.gampFile=gampFile - self.events=[] - self.nParticles=0 - - def parseParticle(self,line): - """ - This function takes in a space delimited line representing a particle, and - instantiates a new instance of the gampParticle class from it then returns it. - - Args: - line (string): A single line representing a gamp particle. - - Returns: - A gampParticle, of type pythonPWA.dataTypes.gampParticle, instantiated from the argument. - """ - dataList=line.split(" ") - particle=gampParticle(particleID=dataList[0], - particleCharge=dataList[1], - particleXMomentum=dataList[2], - particleYMomentum=dataList[3], - particleZMomentum=dataList[4], - particleE=dataList[5]) - return particle - - def readGamp(self): - """ - This function parses a whole gamp file and returns a list of all gamp events. - - Returns: - List of all gampEvents contained within self.gampFile. - """ - contents=self.gampFile.readlines() - self.nParticles=int(contents[0]) - nLinesPerEvent=self.nParticles+1 - i=0 - while i - - -""" -import sys -import os -import numpy -import fileinput -from pythonPWA.dataTypes.gampParticle import gampParticle -from pythonPWA.dataTypes.gampEvent import gampEvent -class gampTranslator(): - """ - This class is a convience class used to convert a gamp .txt file into a 3 demensional numpy ndarray saved in numpy's .npy file format - """ - def __init__(self,gampFile=None): - """ - Default gampReader constructor. - - Kwargs: - gampFile (file): Must be an open file handle, gamp file to be read. - - """ - self.gampFile=gampFile - self.events= numpy.ones(shape=(1,1,6),dtype=float) - - def readFile(self): - """ - This function parses a whole gamp file and returns the 3 demensional array. The first demension is the event number. - The second is the line number in that event (0 is the number of particles, >0 is a particle). The third is the index within - an individual particle. - - """ - i = 0 - n = 0 - x = -1 - for line in fileinput.input([self.gampFile]): - if i == 0: - x = int(line) - self.events.resize(1+n,x+1,6) - self.events[n,0,0] = float(line) - i+=1 - elif i < x and i!= 0: - particle = line.split(" ") - self.events[n,i,0]= particle[0] - self.events[n,i,1]= particle[1] - self.events[n,i,2]= particle[2] - self.events[n,i,3]= particle[3] - self.events[n,i,4]= particle[4] - self.events[n,i,5]= particle[5].strip("\n") - i+=1 - elif i == x: - particle = line.split(" ") - self.events[n,i,0]= particle[0] - self.events[n,i,1]= particle[1] - self.events[n,i,2]= particle[2] - self.events[n,i,3]= particle[3] - self.events[n,i,4]= particle[4] - self.events[n,i,5]= particle[5].strip("\n") - i = 0 - n+=1 - x = -1 - sys.stdout.write(str(n)+"\r") - sys.stdout.flush() - - def translate(self,saveFile): - """ - This function will run the readFile function and then save the array to the specified file name. - - Args: - saveFile (string): The file name the user wants the file named(will end in .npy). - - Returns: - The 3D numpy array of gamp events - """ - self.readFile() - numpy.save(saveFile,self.events) - return self.events - - def writeEvent(self,dataSlice): - """ - This function takes a slice of the events array ([n,:,:]) and returns the pythonPWA gampEvent object of that slice. - - Args: - dataSlice (numpy ndarray): The 2 densional array of a single event fron the events 3D array. - - Returns: - gampEvent - """ - nPart = dataSlice[0,0] - event = [] - for i in range(int(nPart)): - dataList = dataSlice[i+1,:] - particle=gampParticle(particleID=dataList[0], - particleCharge=dataList[1], - particleXMomentum=dataList[2], - particleYMomentum=dataList[3], - particleZMomentum=dataList[4], - particleE=dataList[5]) - event.append(particle) - return gampEvent(particles=event) - - def writeFile(self,outFile,data): - """ - This function will convert the 3 demensional array of gamp data back into a text file of those events. - - Args: - outFile (string): The file name the user wants the file named(will end in .txt). - data (numpy ndarray): The 3D that will be converted. - """ - with open(outFile,"w") as gF: - for i in range(data.shape[0]): - event = self.writeEvent(data[i,:,:]) - event.writeGamp(gF) - sys.stdout.write(str(i)+"\r") - sys.stdout.flush() diff --git a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/getWaves.py b/pythonPWA/pythonPWA/pythonPWA/fileHandlers/getWaves.py deleted file mode 100644 index c9e72f49..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/getWaves.py +++ /dev/null @@ -1,29 +0,0 @@ -import re -import itertools as it -import os - -from pythonPWA.dataTypes.wave import wave -from pythonPWA.fileHandlers.bampReader import readBamp - -def getwaves(totalpath): - """ - This function finds and reads in all bamp files in the provided directory and returns - a list of all waves of type pwawave.wave after populating the needed data members of - each member. - """ - wavelist=[] - #filtering for bamp file types and populating bamplist - regexp=re.compile(".*(.bamp).*") - for files in os.listdir(totalpath): - if regexp.search(files): - #setting the beta value for the wave - idex=files.find(".bamp") - - #seting the waves epsilon value - bufferepsilon=files[idex-4] - if bufferepsilon=="-": - epsilon=0 - if bufferepsilon=="+": - epsilon=1 - wavelist.append(wave(epsilon=epsilon,complexamplitudes=readBamp(os.path.join(totalpath,files)))) - return wavelist diff --git a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/getWavesGen.py b/pythonPWA/pythonPWA/pythonPWA/fileHandlers/getWavesGen.py deleted file mode 100644 index e2976d79..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/fileHandlers/getWavesGen.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -.. module:: pythonPWA.fileHandlers - :platform: Unix, Windows, OSX - :synopsis: Utilities for working with common PWA file formats. - -.. moduleauthor:: Brandon Kaleiokalani DeMello , Josh Pond - - -""" -import re -import itertools as it -import os - -from pythonPWA.dataTypes.wave import wave -from pythonPWA.fileHandlers.bampReader import readBamp -import operator - -def getwaves(totalpath): - """ - This function finds and reads in all bamp files in the provided directory and returns - a list of all waves of type pwawave.wave after populating the needed data members of - each member. - - Args: - totalPath (string): Directory to scan for *.bamp files. - - Returns: - List of type pythonPWA.dataTypes.wave sorted by the 'filename' data member to ensure preserved ordering. - - """ - wavelist=[] - #filtering for bamp file types and populating bamplist - regexp=re.compile(".*(.bamp).*") - for files in os.listdir(totalpath): - if regexp.search(files): - #setting the beta value for the wave - idex=files.find(".bamp") - #setting the waves epsilon value - for b in range(len(files)): - if files[-int(b)] == '-': - epsilon=0 - break - if files[-int(b)] == '+': - epsilon=1 - break - wavelist.append(wave(epsilon=epsilon,complexamplitudes=readBamp(os.path.join(totalpath,files)),filename=files)) - return sorted(wavelist,key=operator.attrgetter('filename')) - diff --git a/pythonPWA/pythonPWA/pythonPWA/model/__init__.py b/pythonPWA/pythonPWA/pythonPWA/model/__init__.py deleted file mode 100644 index 8a01abda..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -This module contains the python representations of the functions and algorithms described in the -paper "On the partial-wave analysis of mesonic resonances decaying to multiparticle final states produced by polarized photons" -by Carlos Salgado and Dennis Weygand. -""" \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/model/complexV.py b/pythonPWA/pythonPWA/pythonPWA/model/complexV.py deleted file mode 100644 index 03c02940..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/complexV.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -.. module:: pythonPWA.model - :platform: Unix, Windows, OSX - :synopsis: Module describing the various mathematical constructs commonly used in partial wave analysis. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy -from pythonPWA.model.magV import magV -from pythonPWA.model.getPhi import getPhi - -def complexV(resonance,wave,waves,normint,mass): - """ - Production amplitude (V) function. - - Args: - resonance (pythonPWA.dataTypes.resonance): - wave (pythonPWA.dataTypes.wave): - waves (list) - normint (pythonPWA.model.normInt): - mass (float): - - Returns: - A numpy.complex value representing a production amplitude. - - """ - return numpy.complex(magV(mass,resonance,wave,waves,normint)*numpy.cos(getPhi(mass,resonance)+resonance.phase),magV(mass,resonance,wave,waves,normint)*numpy.sin(getPhi(mass,resonance)+resonance.phase)) - #return numpy.complex(magV(mass,resonance,wave,waves,normint)*(resonance.w0**2-mass**2)/(resonance.w0**2),magV(mass,resonance,wave,waves,normint)*(resonance.w0*resonance.r0)/(resonance.w0**2)) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/model/getPhi.py b/pythonPWA/pythonPWA/pythonPWA/model/getPhi.py deleted file mode 100644 index f891cbe3..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/getPhi.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -.. module:: pythonPWA.model - :platform: Unix, Windows, OSX - :synopsis: Module describing the various mathematical constructs commonly used in partial wave analysis. - -.. moduleauthor:: Brandon Kaleiokalani DeMello -""" -import numpy - -def getPhi(mass,resonance): - """ - Returns the value of Phi used in complex production amplitude calculation, and thus - number of events (nTrue.nTrue()), for a specified mass and resonance. - - Args: - mass (float): - resonance (pythonPWA.dataTypes.resonance): - - Returns: - Float representing the value of phi. - """ - return numpy.arctan((resonance.r0*resonance.w0)/(mass**2-resonance.w0**2)) #need to make this arccotan? invert args \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/model/intensity.py b/pythonPWA/pythonPWA/pythonPWA/model/intensity.py deleted file mode 100644 index cdf85146..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/intensity.py +++ /dev/null @@ -1,89 +0,0 @@ -""" -.. module:: pythonPWA.model - :platform: Unix, Windows, OSX - :synopsis: Module describing the various mathematical constructs commonly used in partial wave analysis. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy -from pythonPWA.model.complexV import complexV -from pythonPWA.model.spinDensity import spinDensity - -class intensity(object): - """ - This represents the intensity function used in the PWA model. - """ - def __init__(self, - resonances=[], - waves=[], - productionAmplitudes=[], - normint=None, - alphaList=[], - beamPolarization=.6 - ): - """ - Default constructor for the intensity class. - - Kwargs: - resonances (list): - waves (list): - productionAmplitudes (list): - normint (pythonPWA.model.normInt): - alphaList (list): - beamPolarization (float): - - """ - self.resonances=resonances - self.waves=waves - self.productionAmplitudes=productionAmplitudes - self.normint=normint - self.alphaList=alphaList - self.beamPolarization=beamPolarization - #DONT FORGET TO FIX AFTER DEBUGGING - self.testWriting=0 - self.testValues=[] - - def calculate(self,mass,eventNumber): - """ - Calculate function for the instensity class, returns the value for the instensity for specified mass and event number. - - Args: - mass (float): - eventNumber (int): - - Returns: - The value of the intensity function as a numpy.complex type. - - """ - ret=numpy.complex(0.,0.) - self.testValues=[] - for resonance1 in self.resonances: - #print"resonance1=",resonance1.r0 - for resonance2 in self.resonances: - #print"resonance2=",resonance2.r0 - for wave1 in self.waves: - for wave2 in self.waves: - if len(self.productionAmplitudes)==0: - ret+=complexV(resonance1,wave1,self.waves,self.normint,mass)*numpy.conjugate(complexV(resonance2,wave2,self.waves,self.normint,mass))*wave1.complexamplitudes[eventNumber]*numpy.conjugate(wave2.complexamplitudes[eventNumber])*spinDensity(self.beamPolarization,self.alphaList[eventNumber])[wave1.epsilon,wave2.epsilon] - if len(self.productionAmplitudes)!=0: - ret+=self.productionAmplitudes[self.waves.index(wave1)]*numpy.conjugate(self.productionAmplitudes[self.waves.index(wave2)])*wave1.complexamplitudes[eventNumber]*numpy.conjugate(wave2.complexamplitudes[eventNumber])*spinDensity(self.beamPolarization,self.alphaList[eventNumber])[wave1.epsilon,wave2.epsilon] - if self.testWriting==1: - if [self.waves.index(wave1),self.waves.index(wave2),self.resonances.index(resonance1),self.resonances.index(resonance2),complexV(resonance1,wave1,self.waves,self.normint,mass),complexV(resonance2,wave2,self.waves,self.normint,mass),complexV(resonance1,wave1,self.waves,self.normint,mass)*numpy.conjugate(complexV(resonance2,wave2,self.waves,self.normint,mass))*wave1.complexamplitudes[eventNumber]*numpy.conjugate(wave2.complexamplitudes[eventNumber])*spinDensity(self.beamPolarization,self.alphaList[eventNumber])[wave1.epsilon,wave2.epsilon],wave1.complexamplitudes[eventNumber],wave2.complexamplitudes[eventNumber]] not in self.testValues: - self.testValues.append([self.waves.index(wave1),self.waves.index(wave2),self.resonances.index(resonance1),self.resonances.index(resonance2),complexV(resonance1,wave1,self.waves,self.normint,mass),complexV(resonance2,wave2,self.waves,self.normint,mass),complexV(resonance1,wave1,self.waves,self.normint,mass)*numpy.conjugate(complexV(resonance2,wave2,self.waves,self.normint,mass))*wave1.complexamplitudes[eventNumber]*numpy.conjugate(wave2.complexamplitudes[eventNumber])*spinDensity(self.beamPolarization,self.alphaList[eventNumber])[wave1.epsilon,wave2.epsilon],wave1.complexamplitudes[eventNumber],wave2.complexamplitudes[eventNumber]]) - if self.testWriting==1: - for items in self.testValues: - print"="*10 - print"wave1",items[0] - - print"wave2",items[1] - print"resonance1:",items[2] - print"resonance2:",items[3] - print"v1:",items[4] - print"v2:",items[5] - - print"amplitude1:",items[7] - print"amplitude2:",items[8] - print"term:",items[6] - return ret diff --git a/pythonPWA/pythonPWA/pythonPWA/model/magV.py b/pythonPWA/pythonPWA/pythonPWA/model/magV.py deleted file mode 100644 index a60fb99b..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/magV.py +++ /dev/null @@ -1,18 +0,0 @@ -""" -.. module:: pythonPWA.model - :platform: Unix, Windows, OSX - :synopsis: Module describing the various mathematical constructs commonly used in partial wave analysis. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy -from pythonPWA.utilities.breitWigner import breitWigner - -def magV(mass,resonance,wave,waves,normint): - """ - Returns the magnitude of the production amplitued V, for a specified wave, - resonance, wave in the set of waves, and normalization integral. - """ - return numpy.sqrt((1./normint[wave.epsilon,wave.epsilon,waves.index(wave),waves.index(wave)])*resonance.wR[waves.index(wave)]*resonance.cR*breitWigner(mass,resonance.w0,resonance.r0)*numpy.conjugate(breitWigner(mass,resonance.w0,resonance.r0))) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/model/nExpected.py b/pythonPWA/pythonPWA/pythonPWA/model/nExpected.py deleted file mode 100644 index 5448d43e..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/nExpected.py +++ /dev/null @@ -1,53 +0,0 @@ -import numpy -from pythonPWA.model.complexV import complexV - -def gampLen(path): - ins = open(path) - for line in ins: - leng = line.strip("\n") - return float(leng) - -def countAlphas(path): - """ - Returns the length of an alpha angle file. - - Args: - path (string): - - Returns: - Int equivalent to the length of the alpha file. - """ - Alpha = open(path,'r') - AlphaList = Alpha.readlines() - - return float(len(AlphaList)) - -def etaX(apath,rpath): - """ - Calculates the acceptance. - - Returns: - Float value of the acceptance. - """ - #etax=(gampLen(apath)/gampLen(rpath)) - etaX=(countAlphas(apath)/countAlphas(rpath)) - return etaX - -def nExpForFixedV1V2(vList,waves,normint,apath,rpath): - """ - calculates the number of events for fitted v1 and v2 values. - """ - ret=0. - for wave1 in waves: - for wave2 in waves: - psi=normint[wave1.epsilon,wave2.epsilon,waves.index(wave1),waves.index(wave2)] - - ret+=vList[waves.index(wave1)]*numpy.conjugate(vList[waves.index(wave2)])*psi - return etaX(apath,rpath)*ret.real - -def nExpForFixedV1V2AndWave(v,waves,wave,normint,apath,rpath): - """ - calculates the number of events for fitted v1 and v2 values for a specific - wave. - """ - return etaX(apath,rpath)*v*numpy.conjugate(v)*normint[wave.epsilon,wave.epsilon,waves.index(wave),waves.index(wave)] diff --git a/pythonPWA/pythonPWA/pythonPWA/model/nTrue.py b/pythonPWA/pythonPWA/pythonPWA/model/nTrue.py deleted file mode 100644 index d2a0ddd7..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/nTrue.py +++ /dev/null @@ -1,122 +0,0 @@ -""" -.. module:: pythonPWA.model - :platform: Unix, Windows, OSX - :synopsis: Module describing the various mathematical constructs commonly used in partial wave analysis. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy -from pythonPWA.model.complexV import complexV - -def nTrue(resonances,waves,mass,normint): - """ - Returns the number of events for all resonances and waves for the specified mass and normalization integral. - """ - ret=0. - for resonance1 in resonances: - #print"resonance1=",resonance1.r0 - for resonance2 in resonances: - #print"resonance2=",resonance2.r0 - for wave1 in waves: - for wave2 in waves: - v1=complexV(resonance1,wave1,waves,normint,mass) - v2=numpy.conjugate(complexV(resonance2,wave2,waves,normint,mass)) - psi=normint[wave1.epsilon,wave2.epsilon,waves.index(wave1),waves.index(wave2)] - term=v1*v2*psi - ret+=term - return ret.real - -def nTrueForWave(resonances,waves,wave,mass,normint): - """ - Returns the number of events for all resonances, for a specified wave out of the set of all waves, for the specified mass, - and for the nomalization integral. - """ - ret=0. - for resonance1 in resonances: - for resonance2 in resonances: - v1=complexV(resonance1,wave,waves,normint,mass) - v2=numpy.conjugate(complexV(resonance2,wave,waves,normint,mass)) - psi=normint[wave.epsilon,wave.epsilon,waves.index(wave),waves.index(wave)] - term=v1*v2*psi - ret+=term - return ret.real - - -def nTrueForFixedV1V2(vList,waves,normint): - """ - calculates the number of events for fitted v1 and v2 values. - """ - ret=0. - for wave1 in waves: - for wave2 in waves: - psi=normint[wave1.epsilon,wave2.epsilon,waves.index(wave1),waves.index(wave2)] - print"psi:", psi - ret+=vList[waves.index(wave1)]*numpy.conjugate(vList[waves.index(wave2)])*psi - return ret.real - -def nTrueForFixedV1V2AndWave(v,waves,wave,normint): - """ - calculates the number of events for fitted v1 and v2 values for a specific - wave. - """ - return v*numpy.conjugate(v)*normint[wave.epsilon,wave.epsilon,waves.index(wave),waves.index(wave)] - -def partialDerivativeNTrue(rawNormalizationIntegral,vList,waves,wave,realFlag): - """ - Returns the value of the partial derivative of nTrue - """ - ret=0. - for wv in waves: - if realFlag==True: - ret+=rawNormalizationIntegral[wave.epsilon,wv.epsilon,waves.index(wave),waves.index(wv)]*numpy.real(vList[waves.index(wv)]) - if realFlag==False: - ret+=rawNormalizationIntegral[wave.epsilon,wv.epsilon,waves.index(wave),waves.index(wv)]*numpy.imag(vList[waves.index(wv)]) - return 2.*ret - -def constructJacobianVector(rawNormalizationIntegral,vList,waves): - """ - Returns a list representing the jacobian vector for specifed set of waves. - """ - jacobianVector=[] - for wave in waves: - realFlag=True - rPartial=partialDerivativeNTrue(rawNormalizationIntegral,vList,waves,wave,realFlag) - realFlag=False - iPartial=partialDerivativeNTrue(rawNormalizationIntegral,vList,waves,wave,realFlag) - jacobianVector.append(rPartial) - jacobianVector.append(iPartial) - return numpy.asmatrix(jacobianVector) - -def calcStatSquaredError(covarianceMatrix,rawNormalizationIntegral,vList,waves): - """ - Calculates the square of the statistical error for nTrue - """ - jacobian=constructJacobianVector(rawNormalizationIntegral,vList,waves) - return jacobian*covarianceMatrix*numpy.transpose(jacobian) - - -def calcSysSquaredError(iSets): - """ - Calculates the square of the systematic error for nTrue - """ - N=float(len(iSets)) - iHat=numpy.complex(0.,0.) - - for iSet in iSets: - iHat+=sum(iSet) - - iHat=iHat/N - - ret=numpy.complex(0.,0.) - for iSet in iSets: - for i in iSet: - ret+=(iHat-i)*(iHat-i) - return ret/N - -def calcNTrueError(iSets,covarianceMatrix,rawNormalizationIntegral,vList,waves): - """ - Calculates the total error in nTrue including the systematic and statistical error - """ - return calcSysSquaredError(iSets)+calcStatSquaredError(covarianceMatrix,rawNormalizationIntegral,vList,waves) diff --git a/pythonPWA/pythonPWA/pythonPWA/model/normInt.py b/pythonPWA/pythonPWA/pythonPWA/model/normInt.py deleted file mode 100644 index 31643baa..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/normInt.py +++ /dev/null @@ -1,87 +0,0 @@ -""" -.. module:: pythonPWA.model - :platform: Unix, Windows, OSX - :synopsis: Module describing the various mathematical constructs commonly used in partial wave analysis. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy -import os -from pythonPWA.model.spinDensity import spinDensity - -class normInt(): - """ - Represents a normalization integral. To compute the value of the normalization integral - call normInt.execute(). To save the normalization integral to a directory call normInt.save() - """ - def __init__(self, - waves=[], - alphaList=[], - beamPolarization=0.0): - - self.waves=waves - self.alphaList=alphaList - self.beamPolarization=float(beamPolarization) - - self.ret=numpy.ndarray((2,2,len(waves),len(waves)),dtype=numpy.complex) - self.ret[:,:,:,:]=numpy.complex(0.,0.) - - def execute(self): - """ - Returns the normalization integral for the waves, alphas, and beam polarization. - Note that the normalization integral is stored as a numpy ndarray with 4 dimensions. - The indexing of the normalization integral is [wave1.epsilon,wave2.epsilon,waves.index(wave1),waves.index(wave2)]. - This means that the first 2 dimensions (wave1.epsilon,wave2.epsilon) have length of 2. The last 2 dimensions - (waves.index(wave1),waves.index(waves2)) have length equal to the number of waves to be represented in this normalization - integral. - """ - evnumber=0 - for alpha in self.alphaList: - spindensity=spinDensity(self.beamPolarization,alpha) - for wave1 in self.waves: - for wave2 in self.waves: - temp=wave1.complexamplitudes[evnumber]*numpy.conj(wave2.complexamplitudes[evnumber])*spindensity[wave1.epsilon,wave2.epsilon] - self.ret[wave1.epsilon,wave2.epsilon,self.waves.index(wave1),self.waves.index(wave2)]+=temp - evnumber+=1 - - buffe=self.ret*(1./float(evnumber)) - self.ret=buffe - return self.ret - - def save(self,directory): - """ - Saves the current value of the normalization integral. Note that if this is called before - normInt.execute() it will save an ndarray of complex 0's to the specified file. - """ - numpy.save(os.path.join(directory,"normint.npy"),self.ret) - - def writeToAscii(self,directory): - """ - This function writes the values of the normalization integral to a text file. - Make sure to run execute method first. - """ - outfile=open(os.path.join(directory,"normint.txt"),'w') - outfile.write(str(len(self.waves))+"\n") - outfile.write(str(len(self.alphaList))+"\n") - for eps1 in range(2): - for eps2 in range(2): - outfile.write(str(len(self.waves))+" "+str(len(self.waves))+" "+str(eps1)+" "+str(eps2)+"\n") - for index1 in range(len(self.waves)): - for index2 in range(len(self.waves)-1): - tempcomplex=self.ret[eps1,eps2,index1,index2] - tempreal=numpy.real(tempcomplex) - tempim=numpy.imag(tempcomplex) - outfile.write(" ("+str(tempreal)+" + i "+str(tempim)+") , ") - tempcomplex=self.ret[eps1,eps2,index1,int(len(self.waves)-1)] - tempreal=numpy.real(tempcomplex) - tempim=numpy.imag(tempcomplex) - outfile.write(" ("+str(tempreal)+" + i "+str(tempim)+")") - outfile.write("\n") - outfile.write("\n") - outfile.write(str(len(self.waves))+"\n") - for wave in self.waves: - outfile.write(wave.filename+" "+str(self.waves.index(wave))+"\n") - outfile.close() - diff --git a/pythonPWA/pythonPWA/pythonPWA/model/prodAmp.py b/pythonPWA/pythonPWA/pythonPWA/model/prodAmp.py deleted file mode 100644 index bf190749..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/prodAmp.py +++ /dev/null @@ -1,76 +0,0 @@ -""" -.. module:: pythonPWA.model - :platform: Unix, Windows, OSX - :synopsis: Module describing the various mathematical constructs commonly used in partial wave analysis. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy -from pythonPWA.utilities.breitWigner import breitWigner - -class ProdAmp(): - """ - This is a recreation of the ProdAmp class written by Dennis Weygand. - The algorithmic structuring of this class is as similar to the ProdAmp - java version as possible. - """ - def __init__(self, - gList=[[0,0.], - [1,.4], - [2,1.], - [3,0.], - [4,0.], - [5,0.], - [6,0.], - [7,0.], - [8,0.]]): - self.gList=gList - - self.GAMMA1 = .340 - self.MASS1 = 1.400 - - self.GAMMA2 = .107 - self.MASS2 = 1.320 - - self.MASS3 = 2.040 - self.GAMMA3 = .313 - - self.MASS4 = 1.720 - self.GAMMA4 = .135 - - self.MASS5 = 2.20 - self.GAMMA5 = .313 - - self.MASS_A1 = 1.230 - self.WIDTH_A1 = .360 - - self.MASS_PI2 = 1.672 - self.WIDTH_PI2 = .259 - - self.MASS_PI1 = 1.600 - self.WIDTH_PI1 = .350 - - - def getStrength(self,beta): - for gPairs in self.gList: - if gPairs[0]==beta: - return gPairs[1] - - def V(self,mass,beta,k,eps): - BW=numpy.complex(0.,0.) - g=self.getStrength(beta) - - if(k<1): - if eps <=1: - return { - 1:breitWigner(mass,self.MASS1,self.GAMMA1)*g, - 2:breitWigner(mass,self.MASS2,self.GAMMA2)*g, - 3:breitWigner(mass,self.MASS3,self.GAMMA3)*g, - 4:breitWigner(mass,self.MASS4,self.GAMMA4)*g, - 5:breitWigner(mass,self.MASS5,self.GAMMA5)*g, - 6:breitWigner(mass,self.MASS_A1,self.WIDTH_A1)*g, - 7:breitWigner(mass,self.MASS_PI2,self.WIDTH_PI2)*g, - 8:breitWigner(mass,self.MASS_PI1,self.WIDTH_PI1)*g - }[beta] \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/model/spinDensity.py b/pythonPWA/pythonPWA/pythonPWA/model/spinDensity.py deleted file mode 100644 index 5227c893..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/model/spinDensity.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -.. module:: pythonPWA.model - :platform: Unix, Windows, OSX - :synopsis: Module describing the various mathematical constructs commonly used in partial wave analysis. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy - -def spinDensity(beampolarization,alpha): - """ - SpinDensity matrix for specified beam polarization and angle alpha. - - Args: - beampolarization (float): - alpha (float): - - Returns: - The entire spinDensity matrix for specified beam polarization and angle alpha. - Note that the spinDensity matrix is a 2x2 matrix indexed by the wave reflectivity (wave.epsilon). - """ - #TODO: need to make this check the type of alpha, if its type is none then return [[.5,0.],[0.,.5]] - complexrhomatrix=numpy.empty((2,2),dtype=numpy.complex) - complexrhomatrix[0,0]=numpy.complex(1.+beampolarization*numpy.cos(2.*alpha),0.) - complexrhomatrix[0,1]=numpy.complex(0.,beampolarization*numpy.sin(2.*alpha)) - complexrhomatrix[1,0]=numpy.complex(0.,-1.*beampolarization*numpy.sin(2.*alpha)) - complexrhomatrix[1,1]=numpy.complex(1.-beampolarization*numpy.cos(2.*alpha),0.) - return .5*complexrhomatrix \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/FourVec.py b/pythonPWA/pythonPWA/pythonPWA/utilities/FourVec.py deleted file mode 100644 index 9f88ec12..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/FourVec.py +++ /dev/null @@ -1,133 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Jun 25 13:50:19 2014 - -@author: sbramlett -""" - -import numpy as np -"""The class FourVector -examples of use -P0 = FourVector() -print P0 - -P1 = FourVector(ct = 9, x = 1, y = 2, z = 4) #or P1 = FourVector(9, 1, 2, 4) -print P1 -#with a threevec list -P2 = FourVector(99.9,[1, 2, 3]) -print P2 -#given a list -P3 = FourVector([9, 1, 2, 3]) -print P3 - -P4 = P1 + P2 -print P4 - -P5 = P2 * P1 -print P5 -""" -from ThreeVec import ThreeVector -#import LorentzTransform - -class FourVector(object): - vec=[] #the FourVec - p= ThreeVector() - def __init__(self, E=0, x=0, y=0, z=0): - if type(E) is list: - temp = E - self.E = temp[0] - self.x = temp[1] - self.y = temp[2] - self.z = temp[3] - self.p = ThreeVector([self.x, self.y, self.z]) - self.vec = [self.E, self.x, self.y, self.z] - if type(x) is list and type(E) is not list: - self.E = E - temp = x - self.x = temp[0] - self.y = temp[1] - self.z = temp[2] - self.p = ThreeVector([self.x, self.y, self.z]) - self.vec = [self.E, self.x, self.y, self.z] - if type(x) is ThreeVector and (type(E) is not list and type(E) is not ThreeVector): - self.E = E - temp = x - self.x = temp.x - self.y = temp.y - self.z = temp.z - p = temp - self.vec = [self.E, self.x, self.y, self.z] - elif type(E) is not list and type (x) is not list and type(y) is not list and type(z) is not list: - self.E = E - self.x = x - self.y = y - self.z = z - self.p = ThreeVector([self.x, self.y, self.z]) - self.vec = [self.E, self.x, self.y, self.z] - #end __init__ - def __repr__(self): - return str(self.vec) - def __add__(self, n): - pE = self.E + n.E - px = self.x + n.x - py = self.y + n.y - pz = self.z + n.z - pvec = FourVector(pE, px, py, pz) - return pvec - def __sub__(self, n): - pE = self.E - n.E - px = self.x - n.x - py = self.y - n.y - pz = self.z - n.z - pvec = FourVector(pE, px, py, pz) - return pvec - def toMatrix(self): - this = np.matrix([[self.E],[self.x], [self.y], [self.z]]) - return this - def times(self, L): #L is Lorentz transformation - this = self.toMatrix().transpose().dot(L.m).flatten().tolist() - t = this[0] - print t - return FourVector(t) - def r(self): - return (float(self.x**2) + float(self.y**2) + float(self.z**2))**(1./2.) - def lenSq(self): - return float(self.E)**2 - float(self.r())**2 - def phi(self): - return self.p.phi() - def theta(self): - return self.p.theta() - def cosTheta(self): - return self.p.CosTheta() - def dot(self, n): - return self.E*n.E - self.x*n.x - self.y*n.y - self.z*n.z - -#v = ThreeVector(1, 2, 3) -##print v -#P1 = FourVector(9, v) -#print P1 -#print P1.E - - -#print str(P1.lenSq()) -#P0 = FourVector() -#print P0 -# -#P1 = FourVector(E = 9, x = 1, y = 2, z = 4) -##print P1 -## -#P2 = FourVector(99.9,[1, 2, 3]) -###print P2 -#P1 + P2 -#print P1 -#P3 = FourVector([9, 1, 2, 3]) -##print P3 -#print type(P2.E) -# -#P4 = P1 + P2 -#print P4 -# -#P5 = P2 * P1 -#print P5 - - diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/LorentzTransform.py b/pythonPWA/pythonPWA/pythonPWA/utilities/LorentzTransform.py deleted file mode 100644 index c6a96107..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/LorentzTransform.py +++ /dev/null @@ -1,83 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Jun 25 15:13:23 2014 - -@author: sbramlett -""" -from FourVec import FourVector -from ThreeVec import ThreeVector -import numpy as np -import sys, os -#sys.path.append("/home/sbramlett/workspace/PythonPWA/bdemello/pythonPWA/pythonPWA/pythonPWA/utilities") -from rotation import rotation -''' -can be called 3 ways -1. with a FourVector -2. with alpha, beta, gamma -3. with a matrix -''' - -class lorentzTransform(object): - #vec should be a FourVector - def __init__(self, a = 1., b = 1., g = 1.): - #sets beta, the velocity = p/E - self.m = np.matrix(np.identity(4)) - if isinstance(a, FourVector): - x = -a.x / a.E - y = -a.y / a.E - z = -a.z / a.E - _beta = ThreeVector(x, y, z) - self.setBeta(_beta) - if type(a) == np.matrix: - self.m = a - elif type(a) == float: #alpha beta and gamma should all be floats - self.alpha = a - self.beta = b - self.gamma = g - rot = rotation(self.alpha, self.beta, self.gamma) - self.setrot(rot) - - def setBeta(self, _beta): - #beta = _beta.r() - gamma = 1./((1. - _beta.lenSq()))**(1./2.) - gFactor = gamma**2 / (gamma + 1.) - row0 = [gamma, gamma * _beta.x, gamma * _beta.y, gamma * _beta.z] - row1 = [gamma * _beta.x, (_beta.x**2 * gFactor)+1., _beta.x * _beta.y * gFactor, _beta.x * _beta.z * gFactor] - row2 = [gamma * _beta.y, _beta.x * _beta.y * gFactor, (_beta.y**2 * gFactor)+1., _beta.y * _beta.z * gFactor] - row3 = [gamma * _beta.z, _beta.x * _beta.z * gFactor, _beta.y * _beta.z * gFactor ,(_beta.z**2 * gFactor)+1.] - self.m = np.matrix([row0, row1, row2, row3]) - return self.m - def setrot(self, rot): - for i in range(1,4): - for j in range(1,4): - self.m[i,j] = rot.m[i-1, j-1] - self.m[0,0] = 1 - def toString(self): - this = self.m.tolist() - row0 = this[0] - row1 = this[1] - row2 = this[2] - row3 = this[3] - return str(row0) + "\n" + str(row1) + "\n" + str(row2) + "\n" + str(row3) + "\n" - - def __repr__(self): - return self.toString() - - -#v = FourVector(-0.165421, -0.188449, 0.546792, 1.11454) -##print v -##print "in main",type(v) -#l = lorentzTransform(v) -##print l.m -#print v.times(l) -#l = lorentzTransform(1., 2., 3.) -#print l -#f = FourVector(2.,4.,6.,8.) -#print f.times(l) -#test = FourVector(5., 1., 1., 1.) -#l = lorentzTransform(test) -#print l -#test.times(l) -#print test - - \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/OHMintensity.py b/pythonPWA/pythonPWA/pythonPWA/utilities/OHMintensity.py deleted file mode 100644 index 80a647df..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/OHMintensity.py +++ /dev/null @@ -1,120 +0,0 @@ -""" -.. module:: pythonPWA.utilities - :platform: Unix, Windows, OSX - :synopsis: Module containing various useful scripts. - -.. moduleauthor:: Josh Pond - - -""" -import numpy -from pythonPWA.model.complexV import complexV -from pythonPWA.model.spinDensity import spinDensity - - -class intensity(object): - """ - Class for calculating the intensity function from the PWA model by the omega vectorizing method - """ - def __init__(self, - resonances=[], - waves=[], - - normint=None, - alphaList=[], - beamPolarization=.6 - ): - """ - Default constructor for the intensity class. - - Kwargs: - resonances (list): - waves (list): - - normint (pythonPWA.model.normInt): - alphaList (list): - beamPolarization (float): - - """ - self.resonances=resonances - self.waves=waves - - self.normint=normint - self.alphaList=alphaList - self.beamPolarization=beamPolarization - - self.rex=numpy.ndarray((int(len(self.waves)),int(len(self.waves))),dtype=numpy.complex) - self.rex[:,:]=numpy.complex(0.,0.) - - - def calcRez(self,mass,wave1,wave2): - """ - Calculate the value of omega for each index in the matrix, returns the value of omega for specified mass and waves. - - Args: - mass (float): - wave1 (pythonPWA.dataTypes.wave): - wave2 (pythonPWA.dataTypes.wave): - - Returns: - The value of the omega[i,i] as a numpy.complex type. - - """ - rez = numpy.complex(0.,0.) - for resonance1 in self.resonances: - for resonance2 in self.resonances: - rez += complexV(resonance1,wave1,self.waves,self.normint,mass)*numpy.conjugate(complexV(resonance2,wave2,self.waves,self.normint,mass)) - return rez - - - - - - def calcOHM(self,mass): - """ - Calculate the value of the omega matrix, returns the omega matrix for specified mass. - - Args: - mass (float): - - Returns: - The omega matrix as a numpy.ndarray of numpy.complex type. - - """ - for wave1 in self.waves: - for wave2 in self.waves: - #print(str(self.waves.index(wave1))+"'"+str(self.waves.index(wave2))) - - - self.rex[self.waves.index(wave1),self.waves.index(wave2)] = self.calcRez(mass,wave1,wave2) - - - - - - - - - return self.rex - - - def calculate(self,mass,eventNumber,ohmlist): - """ - Calculate function for the instensity class, returns the value for the instensity for specified mass and event number. - - Args: - mass (float): - eventNumber (int): - ohmlist (numpy.ndarray) - - Returns: - The value of the intensity function as a numpy.complex type. - - """ - ret=numpy.complex(0.,0.) - self.testValues=[] - for wave1 in self.waves: - for wave2 in self.waves: - ret+=ohmlist[self.waves.index(wave1),self.waves.index(wave2)]*wave1.complexamplitudes[eventNumber]*numpy.conjugate(wave2.complexamplitudes[eventNumber])*spinDensity(self.beamPolarization,self.alphaList[eventNumber])[wave1.epsilon,wave2.epsilon] - - return ret diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/ThreeVec.py b/pythonPWA/pythonPWA/pythonPWA/utilities/ThreeVec.py deleted file mode 100644 index ab8ec8b5..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/ThreeVec.py +++ /dev/null @@ -1,116 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Thu Jun 26 13:48:01 2014 - -@author: sbramlett -""" -#import numbers -import numpy as np -import math -class ThreeVector(object): - vec = [] - def __init__(self, x = 0, y = 0, z = 0): - if type(x) is not list: - self.x = x - self.y = y - self.z = z - self.vec = [x,y,z] - if type(x) is list and len(x) == 3: - temp = x - self.x = temp[0] - self.y = temp[1] - self.z = temp[2] - self.vec = [self.x, self.y, self.z] - ''' - For printing the Three Vector - ''' - def __repr__(self): - return str(self.vec) - ''' - Add two Three Vectors together - ''' - def __add__(self, n): - px = self.x + n.x - py = self.y + n.y - pz = self.z + n.z - pvec = ThreeVector(px, py, pz) - return pvec - ''' - Subtract two Three Vectors together - ''' - def __sub__(self, n): - px = self.x - n.x - py = self.y - n.y - pz = self.z - n.z - pvec = ThreeVector(px, py, pz) - return pvec - ''' - def __mul__(self, n): - px = self.x * n.x - py = self.y * n.y - pz = self.z * n.z - pvec = ThreeVector(px, py, pz) - return pvec - ''' - ''' - Cross or scalar product - ''' - def __mul__(self, n): - if type(n) is ThreeVector: - px = self.y * n.z - self.z * n.y - py = self.z * n.x - self.x * n.z - pz = self.x * n.y - self.y * n.x - pvec = ThreeVector(px, py, pz) - return pvec - else: - print n - px = self.x * n - py = self.y * n - pz = self.z * n - pvec = ThreeVector(px, py, pz) - return pvec - ''' - #Dot Product of two Three Vectors together - ''' - def dot(self, A): - new = self.x * A.x + self.y * A.y + self.z * A.z - return new - ''' - #The Length of the vector - ''' - def r(self): - r = (self.x**2 + self.y**2 + self.z**2)**(1./2.) - return r - ''' - #The length of the vectore squared - ''' - def lenSq(self): - return self.r()**2 - ''' - ''' - def cosTheta(self, args): - if type(args) is ThreeVector: - n = self.dot(args) - ret = n / self.r() / args.r() - return ret - def CosTheta(self): - return self.z /self.r() - - def sinTheta(self): - return (self.x**2 + self.y**2)/r() - def phi(self): - return math.atan2(self.y, self.x) - def theta(self): - return math.acos(self.CosTheta()) - -#x = [1, 2, 3] -#y = [4, 5, 6] -#print np.cross(x, y) -# -#P1 = ThreeVector(x) -#print str(P1.lenSq()) -#print P1 -#P2 = ThreeVector(y) -#print P1 * P2 -#print np.cross(P1.vec, P2.vec) - \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/__init__.py b/pythonPWA/pythonPWA/pythonPWA/utilities/__init__.py deleted file mode 100644 index 5bb635c2..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -This module contains a few utility classes used when working within the pythonPWA environment. -""" \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/breitWigner.py b/pythonPWA/pythonPWA/pythonPWA/utilities/breitWigner.py deleted file mode 100644 index 387fca59..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/breitWigner.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -.. module:: pythonPWA.utilities - :platform: Unix, Windows, OSX - :synopsis: Module containing various useful scripts. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import numpy - -def breitWigner(mass,resMass,gamma): - """ - Briet Wigner function for a given mass, resonance mass, and resonance width. Note that here, it assumes a fixed - resonance width. - - Args: - mass (float): - resMass (float): - gamma (float): - - Returns: - Numpy.complex value representing the Briet Wigner function value. - """ - dr=mass-resMass - denom=dr*dr+gamma*gamma/4. - return numpy.complex(dr*gamma/(2.*denom),gamma*gamma/(denom*4.)) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/chunks.py b/pythonPWA/pythonPWA/pythonPWA/utilities/chunks.py deleted file mode 100644 index 841ff9cd..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/chunks.py +++ /dev/null @@ -1,8 +0,0 @@ -def chunks(l, n): - """ - Simple list splitting algorithm obtained from stackOverflow from: - http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python - """ - if n<1: - n=1 - return [l[i:i+n] for i in range(0, len(l), n)] \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/countGampSet.py b/pythonPWA/pythonPWA/pythonPWA/utilities/countGampSet.py deleted file mode 100644 index 7ae4d419..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/countGampSet.py +++ /dev/null @@ -1,26 +0,0 @@ -print"events in initial gamp:", len(numpyInitialGampList) - -initial=[] -for initalGamp in numpyInitialGampList: - initial.append(1) - -accepted=[] -acceptedEvents=[] -for accGamp in numpyAccGampList: - if accGamp !=None: - accepted.append(1) - acceptedEvents.append(accGamp) - if accGamp ==None: - accepted.append(0) - -raw=[] -rawEvents=[] -for rawGamp in numpyRawGampList: - if rawGamp != None: - raw.append(1) - rawEvents.append(rawGamp) - if rawGamp==None: - raw.append(0) - -print"events in raw gamp:",len(rawEvents) -print"events in accepted gamp:",len(acceptedEvents) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/dataSimulator.py b/pythonPWA/pythonPWA/pythonPWA/utilities/dataSimulator.py deleted file mode 100644 index 9c50bd10..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/dataSimulator.py +++ /dev/null @@ -1,100 +0,0 @@ -""" -.. module:: pythonPWA.utilities - :platform: Unix, Windows, OSX - :synopsis: Module containing various useful scripts. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -from random import random - -from pythonPWA.fileHandlers.gampReader import gampReader -from pythonPWA.model.intensity import intensity - - -class dataSimulator(object): - """ - This is the main simulator class. By instantiating the variables to the desired values - you can easily simulate data with any characteristics that you would like. - """ - def __init__(self, - mass=1010., - waves=[], - resonances=[], - normint=None, - productionAmplitudes=[], - alphaList=[], - dataDir=None, - beamPolarization=.4): - """ - Default constructor for the dataSimulator class. - - Kwargs: - mass (float): - waves (list): - resonances (list): - normint (pythonPWA.model.normInt): - productionAmplitudes (list): - alphaList (list): - beamPolarization (float): - - """ - - - self.mass=mass - self.waves=waves - self.resonances=resonances - self.normint=normint - self.productionAmplitudes=productionAmplitudes - self.alphaList=alphaList - self.beamPolarization=beamPolarization - self.intensity=intensity(resonances=self.resonances, - waves=self.waves, - productionAmplitudes=self.productionAmplitudes, - normint=self.normint, - alphaList=self.alphaList, - beamPolarization=self.beamPolarization) - - def calcIList(self): - """ - Calculates and returns a list of intensities for each event. - - Returns: - List - """ - iList=[] - for event in range(len(self.alphaList)): - i=self.intensity.calculate(self.mass,event) - iList.append(i) - return iList - - def calcWList(self,iList,iMax,inputGampFile,outputRawGampFile,outputAccGampFile,inputPfFile): - """ - Calculates the list of weights for each event, and writes the raw gamp file. - - Args: - iList (list): - iMax (float): - inputGampFile (file): - outputRawGampFile (file): - outputAccGampFile (file): - inputPfFile (file): - - """ - wList=[x/iMax for x in iList] - igreader=gampReader(gampFile=inputGampFile) - inputGampEvents=igreader.readGamp() - - rawGampEvents=[] - for wn in range(len(wList)): - if wList[wn]>random(): - inputGampEvents[wn].raw=True - rawGampEvents.append(inputGampEvents[wn]) - - for rawGamps in rawGampEvents: - rawGamps.writeGamp(outputRawGampFile) - - outputRawGampFile.close() - outputAccGampFile.close() - diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/dataSimulatorFarm.py b/pythonPWA/pythonPWA/pythonPWA/utilities/dataSimulatorFarm.py deleted file mode 100644 index 65a40139..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/dataSimulatorFarm.py +++ /dev/null @@ -1,74 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Mon Jun 23 10:15:05 2014 - -@author: salgado -""" - -from random import random -import os -from pythonPWA.fileHandlers.gampReader import gampReader -from pythonPWA.model.intensity import intensity - - -class dataSimulator(object): - """description of class""" - def __init__(self, - mass=1010., - waves=[], - resonances=[], - normint=None, - productionAmplitudes=[], - alphaList=[], - beamPolarization=.4, - dataDir = None): - - self.mass=mass - self.waves=waves - self.resonances=resonances - self.normint=normint - self.productionAmplitudes=productionAmplitudes - self.alphaList=alphaList - self.beamPolarization=beamPolarization - self.dataDir=dataDir - self.intensity=intensity(resonances=self.resonances, - waves=self.waves, - productionAmplitudes=self.productionAmplitudes, - normint=self.normint, - alphaList=self.alphaList, - beamPolarization=self.beamPolarization) - - def execute(self,inputGampFile,outputRawGampFile,outputAccGampFile,inputPfFile): - - igreader=gampReader(gampFile=inputGampFile) - inputGampEvents=igreader.readGamp() - - iList=[] - iMax=0. - - pf = inputPfFile - pflist = pf.readlines() - randomPFList=[] - - for event in range(len(self.alphaList)): - i=self.intensity.calculate(self.mass,event) - iList.append(i) - - iMax=max(iList) - wList=[x/iMax for x in iList] - - rawGampEvents=[] - - for wn in range(len(wList)): - if wList[wn]>random(): - inputGampEvents[wn].raw=True - rawGampEvents.append(inputGampEvents[wn]) - randomPFList.append(pflist[wn]) - - for rawGamps in rawGampEvents: - rawGamps.writeGamp(outputRawGampFile) - if int(randomPFList[rawGampEvents.index(rawGamps)])==1: - rawGamps.writeGamp(outputAccGampFile) - - outputRawGampFile.close() - outputAccGampFile.close() \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/devTestFarm.py b/pythonPWA/pythonPWA/pythonPWA/utilities/devTestFarm.py deleted file mode 100644 index f67c4fa2..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/devTestFarm.py +++ /dev/null @@ -1,49 +0,0 @@ -import numpy -import os -import sys -sys.path.append("/u/home/jpond/bdemello/bdemello/pythonPWA/pythonPWA") - -from pythonPWA.dataTypes.resonance import resonance -from pythonPWA.fileHandlers.getWavesGen import getwaves -from pythonPWA.model.normInt import normInt -from pythonPWA.model.intensity import intensity -from pythonPWA.fileHandlers.gampReader import gampReader -#from pythonPWA.utilities.dataSimulator import dataSimulator -from DataSimulatorFarm import dataSimulator - -dataDir=os.path.join("/volatile","halld","pippimpi0","data",sys.argv[1]+"_MeV","set_"+sys.argv[2]) - - -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') - -dSimulator.execute(inputGampFile,outputRawGampFile,outputAccGampFile,inputPfFile) - - diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/fnGenerator.py b/pythonPWA/pythonPWA/pythonPWA/utilities/fnGenerator.py deleted file mode 100644 index 84b0b350..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/fnGenerator.py +++ /dev/null @@ -1,86 +0,0 @@ -from pythonPWA.utilities.minuitLikelihood import minuitLikelihood -import os - -class generator(object): - def __init__(self): - self.fileName=None - - def createFile(self,numberOfTerms,inputSeedFile=None): - """ - Writes out a file containing a wrapper function for minuitLn.calcneglnL, - simply give this function the number of terms (which should be equivalent to - 2*number of waves) and it will write the needed wrapper function to the file - specified by self.filename. - """ - outputFile=open(self.fileName,'w') - if inputSeedFile==None: - outputString="def fn(" - - if inputSeedFile!=None: - outputString="import numpy\ndef fn(" - - - bufferString="" - - reals=[] - imags=[] - - totalList=[] - - #make dual lists - for i in range(0,numberOfTerms,2): - reals.append("t"+str(i)) - - for i in range(1,numberOfTerms,2): - imags.append("t"+str(i)) - - for i in range(numberOfTerms): - totalList.append("t"+str(i)) - - for i in range(len(totalList)): - if i!=len(totalList)-1: - outputString+="t"+str(i)+"," - - if i==len(totalList)-1: - outputString+="t"+str(i) - - if inputSeedFile==None: - outputString+="):\n\tretList=[" - if inputSeedFile!=None: - outputString+="):\n\tinputSeedList=numpy.load("+inputSeedFile+")\n\tretList=[" - - #construct numpy complexes - for i in range(len(reals)): - if i!=len(reals)-1: - outputString+="numpy.complex("+reals[i]+","+imags[i]+")," - if i==len(reals)-1: - outputString+="numpy.complex("+reals[i]+","+imags[i]+")" - - outputString+="]\n\treturn minuitLn.calcneglnL(retList)\n\n" - - outputFile.write(outputString) - - stringBuffer="m=Minuit(fn," - for i in range(len(totalList)): - if i!=len(totalList)-1: - if inputSeedFile==None: - stringBuffer+="t"+str(i)+"=.01," - if inputSeedFile!=None: - stringBuffer+="t"+str(i)+"=inputSeedList["+i+"]," - - if i==len(totalList)-1: - if inputSeedFile==None: - stringBuffer+="t"+str(i)+"=.01" - if inputSeedFile!=None: - stringBuffer+="t"+str(i)+"=inputSeedList["+i+"]" - - stringBuffer+=")\n" - - outputFile.write(stringBuffer) - """ - outputFile.write("Vvalues = m.values\n") - outputFile.write("numpy.save(os.path.join(dataDir,\"Vvalues.npy\"),Vvalues)\n") - outputFile.write("covariance=numpy.array(m.matrix())\n") - outputFile.write("numpy.save(os.path.join(dataDir,\"minuitCovar3.npy\"),covariance)\n") - """ - outputFile.close() diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/gampSlist.py b/pythonPWA/pythonPWA/pythonPWA/utilities/gampSlist.py deleted file mode 100644 index 2f2a3c61..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/gampSlist.py +++ /dev/null @@ -1,86 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Thu Jul 3 14:25:12 2014 - -@author: sbramlett -""" - -import os -import sys -import time -import io -import profile -import numexpr as ne -sys.path.append("/home/sbramlett/workspace/PythonPWA/bdemello/pythonPWA/pythonPWA/pythonPWA") -from fileHandlers.gampReader import gampReader - - -ne.set_num_threads(4) -class gampSlist(object): - def __init__(self, indir, gfile): - self.indir = indir - self.gfile = gfile - print time.time() - igreader=gampReader(gampFile = open(os.path.join(indir,gfile),'r')) - self.events = igreader.readGamp() - print time.time() - self.eventslist = [] - def generate(self): - for event in self.events: - for particles in event.particles: - if particles.particleID == "14": #proton - prE = float(particles.particleE) - prpx = float(particles.particleXMomentum) - prpy = float(particles.particleYMomentum) - prpz = float(particles.particleZMomentum) - mp = float((float(particles.particleE)**2 - float(particles.particleXMomentum)**2 - - float(particles.particleYMomentum)**2 - float(particles.particleZMomentum)**2)**(1./2.)) - if particles.particleID == "1": #photon - phE = float(particles.particleE) - phpx = float(particles.particleXMomentum) - phpy = float(particles.particleYMomentum) - phpz = float(particles.particleZMomentum) - if particles.particleID == "12": #K- - kmE = float(particles.particleE) - kmpx = float(particles.particleXMomentum) - kmpy = float(particles.particleYMomentum) - kmpz = float(particles.particleZMomentum) - if particles.particleID == "11": #K+ - kpE = float(particles.particleE) - kppx = float(particles.particleXMomentum) - kppy = float(particles.particleYMomentum) - kppz = float(particles.particleZMomentum) - mk = float((float(particles.particleE)**2 - float(particles.particleXMomentum)**2 - - float(particles.particleYMomentum)**2 - float(particles.particleZMomentum)**2)**(1./2.)) - sab = (.93827 + phE)**2 - (0 + phpx)**2 - (0 + phpy)**2 - (0 + phpz)**2 - sa1 = (phE - kpE)**2 - (phpx - kppx)**2 - (phpy - kppy)**2 - (phpz - kppz)**2 - s12 = (kpE + kmE)**2 - (kppx + kmpx)**2 - (kppy + kmpy)**2 - (kppz + kmpz)**2 - s23 = (kmE + prE)**2 - (kmpx + prpx)**2 - (kmpy + prpy)**2 - (kmpz + prpz)**2 - sb3 = (.93827 - prE)**2 - (0 - prpx)**2 - (0 - prpy)**2 - (0 - prpz)**2 - slist = [mk, mp, sab, sa1, s12, s23, sb3] - #print slist - #print - self.eventslist.append(slist) - print time.time() - return self.eventslist - - def toFile(self, outputdir, outputFile): - f = open(os.path.join(outputdir, outputFile), 'w') - f.write(str(len(self.events)) + "\n") - for slist in self.eventslist: - f.write(str(slist) + "\n") - f.close() - -###example -indir = "/home/sbramlett/Documents/" -gfile = "test.gamp" -##print indir -## -igreader=gampReader(gampFile = io.open(os.path.join(indir,gfile),'r')) -profile.run('igreader.readGamp();print') -#slist = gampSlist(indir, gfile) -#slist.generate() -#print slist.eventslist -#slist.toFile(indir, "eventsSlist.txt") - - \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/generatePureWave.py b/pythonPWA/pythonPWA/pythonPWA/utilities/generatePureWave.py deleted file mode 100644 index 621048b6..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/generatePureWave.py +++ /dev/null @@ -1,80 +0,0 @@ -import os -import numpy -from pythonPWA.utilities.randM import randm -from pythonPWA.fileHandlers.bampReader import readBamp -from pythonPWA.fileHandlers.gampReader import gampReader - -class generatePureWave(): - """ - This class generates weight files, gamp files, and acceptance - masks for a chosen wave. Simply call generatePureWave().execute(directory,mcGamp,ampFile) - to produce said files. - """ - def __init__(self): - pass - - def execute(self,directory,mcGamp,ampFile): - """ - Creates the weight file, gamp file, and acceptance mask for - specified wave. - """ - amps=readBamp(os.path.join(directory,ampFile+".bamp")) - nEvent=0 - wtMax=0. - wtFile=os.path.join(directory,mcGamp+"."+ampFile+".wt") - output=open(wtFile,'w') - print "weight file:\t",wtFile - - for amplitude in amps: - wt=numpy.real(amplitude*numpy.conjugate(amplitude)) - if nEvent < 10: - print"wt ",wt - if wt>wtMax: - wtMax=wt - output.write(str(wt)+"\n") - nEvent+=1 - - print"Number of Events = ",nEvent,"\tMaximum weight=",wtMax - output.close() - - print"select events" - fileBase=mcGamp - inputGampFile=os.path.join(directory,fileBase+".gamp") - inputPfFile=os.path.join(directory,fileBase+".pf") - - fin=open(inputGampFile,'r') - pfin=open(inputPfFile,'r') - print"input gamp file=",inputGampFile," ",inputPfFile - - outputGampFileRaw=os.path.join(directory,ampFile+".gamp") - outputPfFile=os.path.join(directory,ampFile+".pf") - - outWt=open(outputGampFileRaw,'w') - outPf=open(outputPfFile,'w') - - src=gampReader(fin) - pfSrc=pfin - - fwt=open(wtFile,'r') - wtSrc=fwt - - nout=0 - - n=0 - for event in src.readGamp(): - accFlag=int(pfSrc.readline()) - - n+=1 - - wt=float(wtSrc.readline()) - r=randm(0.0,wtMax) - - if wt>r: - event.writeGamp(outWt) - outPf.write(str(accFlag)+"\n") - nout+=1 - - outWt.close() - outPf.close() - - print"# written ",nout," to file",outputGampFileRaw \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/likelihood.py b/pythonPWA/pythonPWA/pythonPWA/utilities/likelihood.py deleted file mode 100644 index d0849706..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/likelihood.py +++ /dev/null @@ -1,82 +0,0 @@ -""" -.. module:: pythonPWA.utilities - :platform: Unix, Windows, OSX - :synopsis: Module containing various useful scripts. - -.. moduleauthor:: Josh Pond - - -""" -import numpy -from math import log -from pythonPWA.model.complexV import complexV -from pythonPWA.model.spinDensity import spinDensity -from pythonPWA.model.intensity import intensity -from random import random - -class likelihood(object): - """ - Description of class - """ - def __init__(self, - resonances=[], - waves=[], - productionAmplitudes=[], - normint=None, - alphaList=[], - beamPolarization=.6 - ): - - self.resonances=resonances - self.waves=waves - self.productionAmplitudes=productionAmplitudes - self.normint=normint - self.alphaList=alphaList - self.beamPolarization=beamPolarization - #This is the intensity including the extra sigma and the natural log - def calclogI(self,mass,eventNumber): - ret=numpy.complex(0.,0.) - for n in range(1,eventNumber,1): - for resonance1 in self.resonances: - for resonance2 in self.resonances: - for wave1 in self.waves: - for wave2 in self.waves: - if len(self.productionAmplitudes)!=0: - ret+=log(self.productionAmplitudes[self.waves.index(wave1)]*numpy.conjugate(self.productionAmplitudes[self.waves.index(wave2)])*wave1.complexamplitudes[eventNumber]*numpy.conjugate(wave2.complexamplitudes[eventNumber])*spinDensity(self.beamPolarization,self.alphaList[eventNumber])[wave1.epsilon,wave2.epsilon]) - return ret - - - def countAlphas(self,path): - Alpha = open(path,'r') - AlphaList = Alpha.readlines() - - return len(AlphaList) - #This calculates Eta x - def etaX(self,pathA,pathG): - etax=(self.countAlphas(pathA)/self.countAlphas(pathG)) - - return etax - - - - - #This calculates only the sums in the right term - def calcSigmaN(self,mass,eventNumber): - reN=numpy.complex(0,0) - for resonance1 in self.resonances: - for resonance2 in self.resonances: - for wave1 in self.waves: - for wave2 in self.waves: - if len(self.productionAmplitudes)!=0: - reN+=self.productionAmplitudes[self.waves.index(wave1)]*numpy.conjugate(self.productionAmplitudes[self.waves.index(wave2)])*self.normint - return reN - - #This multiplies Eta and the sums to make the entire N/right term - def calcN(self,pathA,pathG,mass,eventNumber): - return self.etaX(pathA,pathG) * self.calcSigmaN(mass,eventNumber) - - #This adds the left and right terms to make the log likelihood. - def calcneglnL(self, mass, eventNumber, pathA, pathG): - return -(self.calclogI(mass,eventNumber)) + self.calcN(pathA,pathG,mass,eventNumber) - - \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/minuitLikelihood.py b/pythonPWA/pythonPWA/pythonPWA/utilities/minuitLikelihood.py deleted file mode 100644 index 0b5e470e..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/minuitLikelihood.py +++ /dev/null @@ -1,188 +0,0 @@ -""" -.. module:: pythonPWA.utilities - :platform: Unix, Windows, OSX - :synopsis: Module containing various useful scripts. - -.. moduleauthor:: Josh Pond , Brandon Kaleiokalani DeMello - - -""" -from pythonPWA.utilities.chunks import chunks -import numpy -from math import log -from pythonPWA.model.complexV import complexV -from pythonPWA.model.spinDensity import spinDensity -from pythonPWA.model.intensity import intensity -from random import random - -import os - -class minuitLikelihood(object): - """ - This class represents the likelihood function, with arguments modified to work well with iminuit. - """ - def __init__(self, - waves=[], - productionAmplitudes=[], - normint=None, - alphaList=[], - beamPolarization=.4, - mass=1010., - eventNumber=10000, - acceptedPath=os.getcwd(), - generatedPath=os.getcwd(), - accAlphaList=[], - accNormInt=None, - rawAlphaList=[], - rawNormInt=None - ): - """ - Default constructor for the minuitLikelihood class. - - Kwargs: - waves (list): - productionAmplitudes (list): - normint (pythonPWA.model.normInt): - alphaList (list): - beamPolarization (float): - mass (float): - eventNumber (int): - acceptedPath (string): - generatedPath (string): - accAlphaList (list): - accNormInt (pythonPWA.model.normInt): - rawAlphaList (list): - rawNormInt (pythonPWA.model.normInt): - """ - - self.waves=waves - self.productionAmplitudes=productionAmplitudes - self.normint=normint - self.alphaList=alphaList - self.beamPolarization=beamPolarization - self.mass=mass - self.eventNumber=len(self.alphaList) - self.acceptedPath=acceptedPath - self.generatedPath=generatedPath - self.debugPrinting=0 - self.iList=[] - self.accAlphaList=accAlphaList - self.accNormInt=accNormInt - self.rawAlphaList=rawAlphaList - self.rawNormInt=rawNormInt - - - def calclogI(self): - """ - The logarithm intensity function. - - Returns: - Numpy.complex data type representing the value of the logarithm of the intensity function. - """ - ret=numpy.complex(0.,0.) - for n in range(0,len(self.alphaList)-1,1): - argret=numpy.complex(0.,0.) - for wave1 in self.waves: - for wave2 in self.waves: - if len(self.productionAmplitudes)!=0: - #logarithmic domain error - arg = self.productionAmplitudes[self.waves.index(wave1)]*numpy.conjugate(self.productionAmplitudes[self.waves.index(wave2)])*wave1.complexamplitudes[n]*numpy.conjugate(wave2.complexamplitudes[n])*spinDensity(self.beamPolarization,self.alphaList[n])[wave1.epsilon,wave2.epsilon] - argret+=arg - argret=argret.real - if self.debugPrinting==1: - print"loop#",n,"="*10 - print"argval:",arg - print"argtype:",type(arg) - print"productionAmps1:",self.productionAmplitudes[self.waves.index(wave1)] - print"productionAmps2*:",numpy.conjugate(self.productionAmplitudes[self.waves.index(wave2)]) - print"spinDensityValue:",spinDensity(self.beamPolarization,self.alphaList[n])[wave1.epsilon,wave2.epsilon] - print"A1:",wave1.complexamplitudes[n] - print"A2*:",numpy.conjugate(wave2.complexamplitudes[n]) - if argret > 0.: - ret+=log(argret) - - self.iList.append(argret) - return ret - - def countAlphas(self,path): - """ - Returns the length of an alpha angle file. - - Args: - path (string): - - Returns: - Int equivalent to the length of the alpha file. - """ - Alpha = open(path,'r') - AlphaList = Alpha.readlines() - - return float(len(AlphaList)) - - #This calculates Eta x - def etaX(self): - """ - Calculates the acceptance. - - Returns: - Float value of the acceptance. - """ - etax=(self.countAlphas(self.acceptedPath)/self.countAlphas(self.generatedPath)) - # print "etax:",etax - return etax - - - #This calculates only the sums in the right term - def calcSigmaN(self): - """ - Returns: - Numpy.complex - """ - reN=numpy.complex(0,0) - for wave1 in self.waves: - for wave2 in self.waves: - if len(self.productionAmplitudes)!=0: - #print"for wave index:",self.waves.index(wave1),"\nV=",self.productionAmplitudes[self.waves.index(wave1)] - reN+=self.productionAmplitudes[self.waves.index(wave1)]*numpy.conjugate(self.productionAmplitudes[self.waves.index(wave2)])*self.accNormInt[wave1.epsilon,wave2.epsilon,self.waves.index(wave1),self.waves.index(wave2)] - - return reN - - #This multiplies Eta and the sums to make the entire N/right term - def calcN(self): - """ - This multiplies Eta and the sums to make the entire N/right term. - - Returns: - Float - """ - return self.etaX() * self.calcSigmaN() - - #This adds the left and right terms to make the log likelihood. - #def calcneglnL(self,wave1Re,wave1Im,wave2Re,wave2Im): - def calcneglnL(self,paramsList): - - - - - """ - This adds the left and right terms to make the log likelihood. - - Args: - paramsList (list): - - Returns: - Numpy.complex - """ - self.productionAmplitudes=paramsList - #this needs to be generalizable to n number of waves, not just 2 - #imags=[x for x in paramsList if x%2==0] - #reals=[x for x in paramsList if x not in imags] - - - #for i in range(len(imags)): - # self.productionAmplitudes.append(numpy.complex(reals[i],imags[i])) - - #self.productionAmplitudes=[numpy.complex(wave1Re,wave1Im),numpy.complex(wave2Re,wave2Im)] - LLog = -(self.calclogI()) + self.calcN() - print"LLog:",LLog - return LLog diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/phaseMotion.py b/pythonPWA/pythonPWA/pythonPWA/utilities/phaseMotion.py deleted file mode 100644 index 7600e9c9..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/phaseMotion.py +++ /dev/null @@ -1,57 +0,0 @@ -""" -.. module:: pythonPWA - :platform: Unix, Windows, OSX - :synopsis: Module containing various functions associated with calculating the phase motion between 2 waves. - -.. moduleauthor:: Brandon Kaleiokalani DeMello -""" - -import numpy - -def createComplexList(vList): - """ - This function takes in a list of v's (for example the returned list from an iminuit fit) - and returns a list of numpy complexes representing the proper v's for each wave. Note - that this function should maintain the ordering established on wave list instantiation, - i.e. alphabetical ordering of waves based on filename. - """ - reals=[vList[x] for x in range(0,len(vList),2)] - imags=[vList[x] for x in range(1,len(vList),2)] - complexes=[] - for i in range(len(reals)): - complexes.append(numpy.complex(reals[i],imags[i])) - return complexes - -def deltaPhi(v1,v2): - """ - Returns the value of equation 372 in the paper by Salgado and Weygand. - """ - return numpy.atan(numpy.imag(v1*numpy.conj(v2))/numpy.real(v1*numpy.conj(v2))) - -def phaseDifference(waves,vList,waveName1,waveName2): - """ - A higher level wrapper around deltaPhi that allows you to simply supply the list - of waves, vs, and 2 strings of the filenames of the waves that you want to calculate - deltaPhi for and returns you the desired phase difference between the 2 specified waves. - """ - complexes=createComplexList(vList) - index1=None - index2=None - - #this loop can be cleaned up using the fact that - ##index1 and index2 are initially set to None. - ###will do this later. - for wave in waves: - if wave.filename==waveName1: - index1=waves.index(wave) - for wave in waves: - if wave.filename==waveName2: - index2=waves.index(wave) - - #checking to make sure that filenames are valid - if index1==None: - print"File name 1 not found" - if index2==None: - print"File name 2 not found" - - return deltaPhi(complexes[index1],complexes[index2]) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/plotGampEvents.py b/pythonPWA/pythonPWA/pythonPWA/utilities/plotGampEvents.py deleted file mode 100644 index cdf6aa12..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/plotGampEvents.py +++ /dev/null @@ -1,40 +0,0 @@ -inputGampFile=open(os.path.join(dataDir,"events.gamp"),'r') -initialGampList,rawGampList,accGampList=dSimulator.execute(inputGampFile,outputRawGampFile,outputAccGampFile,inputPfFile) -numpyInitialGampList=numpy.array(initialGampList) -numpyRawGampList=numpy.array(rawGampList) -numpyAccGampList=numpy.array(accGampList) - -numpy.save(os.path.join(dataDir,"numpyInitialGampList"),numpyInitialGampList) -numpy.save(os.path.join(dataDir,"numpyRawGampList"),numpyRawGampList) -numpy.save(os.path.join(dataDir,"numpyAccGampList"),numpyAccGampList) -numpyInitialGampList=numpy.load(os.path.join(dataDir,"numpyInitialGampList.npy")) -numpyRawGampList=numpy.load(os.path.join(dataDir,"numpyRawGampList.npy")) -numpyAccGampList=numpy.load(os.path.join(dataDir,"numpyAccGampList.npy")) - -from mpl_toolkits.mplot3d import Axes3D -import matplotlib.pyplot as plt -import numpy as np - -def plotGampEvents(initial,raw,accepted,nInitial,nFinal): - initial=initial[nInitial:nFinal] - raw=raw[nInitial:nFinal] - accepted=accepted[nInitial:nFinal] - - fig = plt.figure(figsize=(14, 10), dpi=100) - fig.suptitle("Gamp Events "+str(nInitial)+" to "+str(nFinal)) - ax = fig.add_subplot(111, projection='3d') - - xCoords=[x for x in range(nFinal) if x>=nInitial] - ax.bar(xCoords,initial,zs=[2 for z in range(nFinal) if z>=nInitial],zdir='y',color='g',alpha=0.6) - ax.bar(xCoords,raw,zs=[1 for z in range(nFinal) if z>=nInitial],zdir='y',color='b',alpha=0.75) - ax.bar(xCoords,accepted,zs=[0 for z in range(nFinal) if z>=nInitial],zdir='y',color='r',alpha=.8) - - ax.set_xlabel('Event Number') - ax.set_ylabel('Gamp File') - ax.set_zlabel('Event Present') - - ax.axes.yaxis.set_ticklabels(['accepted','','raw','','initial']) - ax.axes.zaxis.set_ticklabels(['not present','','','','','present']) - plt.show() - -plotGampEvents(initial,raw,accepted,0,200) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/plotNTrue.py b/pythonPWA/pythonPWA/pythonPWA/utilities/plotNTrue.py deleted file mode 100644 index b5d74c4f..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/plotNTrue.py +++ /dev/null @@ -1,32 +0,0 @@ -from mpl_toolkits.mplot3d import Axes3D -import matplotlib.pyplot as plt -import numpy as np - -def plotnTrue(nTrueList,nTrueDWaveList,nTruePWaveList,massList): - - fig = plt.figure(figsize=(14, 10), dpi=100) - fig.suptitle("Predicted Events") - ax = fig.add_subplot(111, projection='3d') - - xCoords=massList - ax.bar(xCoords,nTrueList,zs=[0 for z in range(len(massList))],zdir='y',color='g',alpha=0.6,width=1.,linewidth=0) - ax.bar(xCoords,nTruePWaveList,zs=[1 for z in range(len(massList))],zdir='y',color='b',alpha=0.75,width=1.,linewidth=0) - ax.bar(xCoords,nTrueDWaveList,zs=[2 for z in range(len(massList))],zdir='y',color='r',alpha=.8,width=1.,linewidth=0) - - ax.set_xlabel('Mass (MeV)') - ax.set_ylabel('Wave') - ax.set_zlabel('Number of Events') - - ax.axes.yaxis.set_ticklabels(['Total','','Wave 1','','Wave 2']) - #ax.axes.zaxis.set_ticklabels(['not present','','','','','present']) - plt.show() - -nTrueList=[] -nTrueDWaveList=[] -nTruePWaveList=[] -for mass in massList: - nTrueList.append(nTrue(resonances,waveList,mass,normint)) - nTrueDWaveList.append(nTrueForWave(resonances,waveList,waveList[1],mass,normint)) - nTruePWaveList.append(nTrueForWave(resonances,waveList,waveList[0],mass,normint)) - -plotnTrue(nTrueList,nTrueDWaveList,nTruePWaveList,massList) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/plotter.py b/pythonPWA/pythonPWA/pythonPWA/utilities/plotter.py deleted file mode 100644 index c68dd25b..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/plotter.py +++ /dev/null @@ -1,38 +0,0 @@ -import matplotlib.pyplot as plt - -class plotter(): - """ - A very simple plotting shortcut. Simply initialize the plotter by - providing the desired data sets and labels. - """ - def __init__(self, - xAxisData=[1,2,3,4,5], - yAxisData=[1,2,3,4,5], - title="", - xAxisTitle="", - yAxisTitle=""): - - self.xAxisData=xAxisData - self.yAxisData=yAxisData - plt.plot(self.xAxisData,self.yAxisData) - plt.suptitle(title) - plt.xlabel(xAxisTitle) - plt.ylabel(yAxisTitle) - self.numberOfPlots=0 - self.colors=['b','g','r','c','m','y'] - - def showPlot(self): - """ - Show the plotted figure with all yAxis data sets. - """ - plt.show() - - def addSubPlot(self,newYAxisData): - """ - Allows you to add a new plot of newYAxisData vs self.xAxisData. - Very handy if you want to check multiple functions values on the same - data set. - """ - if len(newYAxisData)==len(self.xAxisData): - self.numberOfPlots+=1 - plt.plot(self.xAxisData,newYAxisData,color=self.colors[self.numberOfPlots]) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/pwa_controls b/pythonPWA/pythonPWA/pythonPWA/utilities/pwa_controls deleted file mode 100644 index 7788902a..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/pwa_controls +++ /dev/null @@ -1,175 +0,0 @@ -#! /usr/bin/python -import Tkinter as tk -import numpy, os - -class Control(object): - - def __init__(self, - instDir = None, - reactMode = 24, - BeamPole = 0.4, - LoMass = 1000, - UpMass = 2500, - RaMass = 20, - NumSet = 20, - MigNcal = 1000): - - self.instDirL = instDir - self.reactModeL = reactMode - self.BeamPoleL = BeamPole - self.UpMassL = UpMass - self.LoMassL = LoMass - self.RaMassL = RaMass - self.NumSetL = NumSet - self.MigNcalL = MigNcal - - def instDir(self): - iD = ent0.get() - self.instDirL = iD - - def reactMode(self): - rM = ent1.get() - self.reactModeL = rM - - def BeamPole(self): - Bp = ent2.get() - self.BeamPoleL = Bp - - def UpMass(self): - Um = ent3.get() - self.UpMassL = Um - - def LoMass(self): - Lm = ent4.get() - self.LoMassL = Lm - - def RaMass(self): - Rm = ent5.get() - self.RaMassL = Rm - - def NumSet(self): - Ns = ent6.get() - self.NumSetL = Ns - - def MigNcal(self): - MnC = ent7.get() - self.MigNcalL = MnC - - def run(self): - self.instDir() - self.reactMode() - self.BeamPole() - self.LoMass() - self.UpMass() - self.RaMass() - self.NumSet() - self.MigNcal() - - def load(self,Con): - self.instDirL = Con[0] - self.reactModeL = Con[1] - self.BeamPoleL = Con[2] - self.LoMassL = Con[3] - self.UpMassL = Con[4] - self.RaMassL = Con[5] - self.NumSetL = Con[6] - self.MigNcalL = Con[7] - - ent0.insert("end",Con[0]) - ent1.insert("end",Con[1]) - ent2.insert("end",Con[2]) - ent3.insert("end",Con[3]) - ent4.insert("end",Con[4]) - ent5.insert("end",Con[5]) - ent6.insert("end",Con[6]) - ent7.insert("end",Con[7]) - - def save(self): - self.run() - Con = [self.instDirL, - int(self.reactModeL), - float(self.BeamPoleL), - int(self.LoMassL), - int(self.UpMassL), - int(self.RaMassL), - int(self.NumSetL), - int(self.MigNcalL)] - numpy.save(os.getcwd()+"/Control_List.npy",Con) - root.destroy() - -Lst = ['Full path to the directory '+'\n'+'the pythonPWA toolkit is installed', - 'Reaction Mode ', - 'Beam Polorization ', - 'Lower Mass ', - 'Upper Mass ', - 'Mass Range ', - 'Number of Sets ', - 'Max Number of Migrad Calls '] - -Contr = Control() - -root = tk.Tk() -root.wm_title("PWA CONTROLS") - -frame=tk.Frame(root) -frame.grid(row=0,column=0,sticky="N"+"S"+"E"+"W") - -L0=tk.Label(frame,text=Lst[0]) -L0.pack(side="top") - -ent0=tk.Entry(frame, width=30, font=55) -ent0.pack(side="top") - -L1=tk.Label(frame,text=Lst[1]) -L1.pack(side="top") - -ent1=tk.Entry(frame, width=30, font=55) -ent1.pack(side="top") - -L2=tk.Label(frame,text=Lst[2]) -L2.pack(side="top") - -ent2=tk.Entry(frame, width=30, font=55) -ent2.pack(side="top") - -L3=tk.Label(frame,text=Lst[3]) -L3.pack(side="top") - -ent3=tk.Entry(frame, width=30, font=55) -ent3.pack(side="top") - -L4=tk.Label(frame,text=Lst[4]) -L4.pack(side="top") - -ent4=tk.Entry(frame, width=30, font=55) -ent4.pack(side="top") - -L5=tk.Label(frame,text=Lst[5]) -L5.pack(side="top") - -ent5=tk.Entry(frame, width=30, font=55) -ent5.pack(side="top") - -L6=tk.Label(frame,text=Lst[6]) -L6.pack(side="top") - -ent6=tk.Entry(frame, width=30, font=55) -ent6.pack(side="top") - -L7=tk.Label(frame,text=Lst[7]) -L7.pack(side="top") - -ent7=tk.Entry(frame, width=30, font=55) -ent7.pack(side="top") - -btn=tk.Button(frame, text="SAVE", command= lambda: Contr.save()) -btn.pack(side="bottom") - -if os.path.isfile(os.getcwd()+"/Control_List.npy"): - Con = numpy.load(os.getcwd()+"/Control_List.npy") - Contr.load(Con) - -root.mainloop() - - - diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/randM.py b/pythonPWA/pythonPWA/pythonPWA/utilities/randM.py deleted file mode 100644 index 1b25dc93..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/randM.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -.. module:: pythonPWA.utilities - :platform: Unix, Windows, OSX - :synopsis: Module containing various useful scripts. - -.. moduleauthor:: Brandon Kaleiokalani DeMello - - -""" -import random - -def randm(low,high): - """ - Returns a random value, used in generatePureWave. - - Args: - low (float) - high (float) - - Returns: - Random value as a float. - """ - return ((high-low)*random.random()+low) \ No newline at end of file diff --git a/pythonPWA/pythonPWA/pythonPWA/utilities/rotation.py b/pythonPWA/pythonPWA/pythonPWA/utilities/rotation.py deleted file mode 100644 index d9d2a6a4..00000000 --- a/pythonPWA/pythonPWA/pythonPWA/utilities/rotation.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Jul 9 14:10:01 2014 - -@author: sbramlett -""" - -import numpy as np -import math - -class rotation(object): - def __init__(self, alpha = 1, beta = 1, gamma = 1): - if type(alpha) == np.matrix: - self.m = alpha - else: - #print type(alpha) - self.setabg(alpha, beta, gamma) - - def setabg(self, alpha, beta, gamma): - ca = math.cos(float(alpha)) - sa = math.sin(float(alpha)) - cb = math.cos(beta) - sb = math.sin(beta) - cg = math.cos(gamma) - sg = math.sin(gamma) - - row0 = [ca*cb*cg - sa*sg, cb*cg*sa + ca*sg, -cg*sb] - row1 = [-sg*cb*ca - cg*sa, -sg*cb*sa + cg*ca, sb*sg] - row2 = [ca*sb, sa*sb, cb] - - self.m = np.matrix([row0, row1, row2]) - return self.m - def toString(self): - row0 = self.m.tolist()[0] - row1 = self.m.tolist()[1] - row2 = self.m.tolist()[2] - return str(row0) + "\n" + str(row1) + "\n" + str(row2) + "\n" - def __repr__(self): - return self.toString() - - - -#i = rotation(1, 2, 3) -#print i.m -#z = rotation(i.m) -#print z - - \ No newline at end of file