예제 #1
0
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
예제 #2
0
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","nTrueListV.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])))        
    if sys.argv[3] == "s":
        nTrueList = [ntrue(resonances,waves,testMass,normint)]  
        for wave in waves:
            nTrueList.append(wave.filename.rstrip(".bamp"))
            nTrueList.append(ntrueforwave(resonances,waves,wave,testMass,normint))