Beispiel #1
0
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'))
Beispiel #2
0
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'))
Beispiel #3
0
def getwaves(totalpath):
    """
    This function finds and reads in all bamp files in the provided directory an
d returns
    a list of all waves of type pwawave.wave after populating the needed data me
mbers 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")
            
            #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))))
    return wavelist
Beispiel #4
0
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
Beispiel #5
0
 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