Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Salgado committed Jun 4, 2015
1 parent f5b62be commit f9eb2c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
11 changes: 6 additions & 5 deletions generalShell/fitting/FnTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ def nTrueFn():
print nTrue

from generalFitting import generalFit # Do not change this line
dataDir="./kvArgs.txt"
accDir="./kvArgsAcc.txt"
QDir="./QFactor.txt"
initial={'A1':.01,'A2':.01,'errordef':0.5}#do not change errordef
gF = generalFit(dataDir=dataDir,accDir=accDir,QDir=QDir,initial=initial)
dataDir="./kvArgs.txt" #filepath for data text file
accDir="./kvArgsAcc.txt" #filepath for accepted Monte Carlo text file
QDir="./QFactor.txt" #filepath for Q probability factor file. Leave empty if you do not have one.
genLen=3000000 #Integer value for number of generated Monte Carlo events
initial={'A1':.01,'A2':.01,'errordef':0.5}#initial values of fitted parameters as well as other iminuit arguments (do not change errordef)
gF = generalFit(dataDir=dataDir,accDir=accDir,QDir=QDir,genLen=genLen,initial=initial)
"""
In the above line do not change the names of any of the arguments but set the values to the directories
Of your data file, accepted MC file, list of Q Factors(If you do not account
Expand Down
5 changes: 3 additions & 2 deletions generalShell/fitting/generalFitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

class generalFit (object):

def __init__(self,dataDir=None,accDir=None,QDir=None,initial={}):
def __init__(self,dataDir=None,accDir=None,QDir=None,genLen=None,initial={}):
self.dataDir = dataDir
self.accDir = accDir
self.QDir = QDir
self.genLen = genLen
self.initial = initial
if ".txt" in self.dataDir:
if not os.path.isfile(self.dataDir.rstrip(".txt")+".npy"):
Expand Down Expand Up @@ -49,7 +50,7 @@ def calcLnLike(self,params):
sys.stdout.write("accepted "+str(i)+"\r")
sys.stdout.flush()
aList[i] = intFn(self.getaKVars(i),params)
val = -((self.QList*numpy.log(iList)).sum(0)) + ((1.0/float(self.accLen)) * aList.sum(0))
val = -((self.QList*numpy.log(iList)).sum(0)) + ((1.0/float(self.genLen)) * aList.sum(0))
print val
return val

Expand Down
5 changes: 3 additions & 2 deletions generalShell/simulation/FnSimTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def simFn():


from generalSim import generalSim
gS = generalSim()
if sys.argv[1] == "i":#example The first argument of numpy.save() is the filepath of the iList to be saved.
inputGampDir=""#Loaction of the Generated MC Gamp File(Same as above)
gS = generalSim(gampDir = inputGampDir)
if sys.argv[1] == "i":
numpy.save("",gS.calcIList({'A1':7.,'A2':-3.0,'A3':0.37,'A4':0.037,'A5':0.121}))#example The first argument of numpy.save() is the filepath of the iList to be saved.
elif sys.argv[1] == "s":
simFn()
24 changes: 14 additions & 10 deletions generalShell/simulation/generalSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@
import numpy
import os, sys
from pythonPWA.fileHandlers.gampTranslator import gampTranslator
from FnSim import ampFn
from FnSim import intFn
from FnSim import kvFn
from random import random

class generalSim (object):

def __init__(self):
pass
def __init__(self,gampDir):
self.gampDir = gampDir
self.gampT = gampTranslator(self.gampDir)
if not os.path.isfile(self.gampDir.rstrip(".gamp")+".npy"):
numpy.save(inputGampDir.rstrip(".gamp")+".npy",gampT.translate(inputGampDir.rstrip(".gamp")+".npy"))
self.gampT.events=numpy.load(self.gampDir.rstrip(".gamp")+".npy")
self.dataLen = self.gampT.events.shape[0]

def getdKVars(self,i):
if ".gamp" in self.dataDir:
return kvFn(self.dataT.writeEvent(self.dataT.events[i,:,:]))
if ".gamp" in self.gampDir:
return kvFn(self.gampT.writeEvent(self.gampT.events[i,:,:]))

def calcIList(self,params):
iList = numpy.zeros(shape = (self.dataLen))
iList = numpy.zeros(shape = (self.dataLen))
for i in range(self.dataLen):
iList[i] = ampFn(self.getdKVars(i),params)
iList[i] = intFn(self.getdKVars(i),params)
sys.stdout.write("int "+str(i)+"\r")
sys.stdout.flush()
return iList
Expand All @@ -27,14 +33,12 @@ def simulate(self,nTrueDir,inputGampDir,outputRawGampDir,outputAccGampDir,inputP
outputPFGampFile=open(outputPFGampDir,'w')
outputRawGampFile=open(outputRawGampDir,'w')
outputAccGampFile=open(outputAccGampDir,'w')
#igreader=gampReader(gampFile=inputGampFile)
#inputGampEvents=igreader.readGamp()
nTrueList = [((1.0/(iList.shape[0]))*(iList.sum(0)))]
numpy.save(nTrueDir,nTrueList)

gampT = gampTranslator(inputGampDir)
if not os.path.isfile(inputGampDir.rstrip(".gamp")+".npy"):
gampT.translate(inputGampDir.rstrip(".gamp")+".npy")
numpy.save(inputGampDir.rstrip(".gamp")+".npy",gampT.translate(inputGampDir.rstrip(".gamp")+".npy"))
gampList=numpy.load(inputGampDir.rstrip(".gamp")+".npy")


Expand Down

0 comments on commit f9eb2c9

Please sign in to comment.