예제 #1
0
 def __init__(self,
              gamp1Path,
              gamp2Path):
     
     self.gampReader1=gampReader(gampFile=open(gamp1Path,'r'))
     self.gampReader2=gampReader(gampFile=open(gamp2Path,'r'))
     
     self.gamp1Events=self.gampReader1.readGamp()
     self.gamp2Events=self.gampReader2.readGamp()
예제 #2
0
    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()
예제 #3
0
    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()
예제 #4
0
    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()
예제 #5
0
    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()
예제 #6
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