Beispiel #1
0
def runclient(args):
    hd=hitdata()
    hf=tofhitfind() 
    
    ds = DataSource(args.exprun+':smd')
    det1 = Detector('pnccdFront',ds.env())
    det2 = Detector('ACQ4',ds.env())
    epics = ds.env().epicsStore()
    thresh = 0.40
    
#    print "rank, size = ", rank, size
    
    for nevent,evt in enumerate(ds.events()):
        if nevent%(size-1)==rank-1:  # different ranks look at different events
#           print rank," processing event", nevent
            eid = evt.get(EventId)
            sec = eid.time()[0]
            nsec = eid.time()[1]
            fid = eid.fiducials()
            et = EventTime(int((sec<<32)|nsec),fid)

            tof, tofAxis = det2.raw(evt)
	
	    if (hf.hitfind(tof[0],tofAxis[0],thresh)):
                epdict=dict()
                for name in epics.names():
                    epdict[name]=epics.value(name)

                img = det1.image(evt)
                obj = dofitting(img)  #call fitting routine
                comp = {'et':et , 'tof':tof[0], 'tofAxis':tofAxis[0], 'epics':epdict, 'drop':obj['drop'],'tofsum':hf.sum}
                hd.send(comp, obj['orig'], obj['fit'])	 
        if nevent == args.noe : break

    hd.endrun()	
Beispiel #2
0
def runmaster(args,nClients, mask):

    hd = hitdata()

    inith5(args)
    initHist('DropSize',100,0,1000)

    while nClients > 0:
        # Remove client if the run ended
        if hd.recv():
#            print "end run called"
            nClients -= 1
        else:
#            print "Calling plot?"
            plot(hd)
            writeh5(hd)
            

    closeh5(mask)
Beispiel #3
0
def runmaster(args,nClients, mask):
    hd = hitdata()

    inith5(args)
    initHist('DropSize',50,500,2000)
    initHist('TOFhits',1000,-500,1000)
    initHist('IMGhits',1000,0,5000)

    bkgTOF = np.empty(10000)
    nTOF = 0

    startTime = time.time()

    while nClients > 0:
        # Remove client if the run ended
        if hd.recv():
#            print "end run called"
            nClients -= 1
            bkgTOF += hd.myobj['tof']
            nTOF = nTOF+hd.myobj['ntof']
        else:
#            print "Calling plot?"
            if hd.myobj['diodeDrop']:
                print 'master detected drop'
                plotDDrop = Image(0,"Diode Drop Image",hd.myobj['img'])
                publish.send('DDROP',plotDDrop)
                continue


            comp = hd.myobj['comp']
            size=(comp['drop']['a']+comp['drop']['b'])/2.0
            plot(hd, args)
            pushToHist('DropSize',size)
            pushToHist('TOFhits',comp['tofsum'])
            pushToHist('IMGhits',comp['imgsum'])
            writeh5(hd)
            
    endTime = time.time()
    hitRate = nHits / (endTime - startTime)
    print('Hitrate = ', hitRate)
    closeh5(mask, bkgTOF/nTOF, hitRate)
Beispiel #4
0
def runmaster(args,nClients):

    hd = hitdata()

    inith5(args)
    initHist('DropSize',100,0,2000)
    initHist('TOFhits',1000,-2,2)

    while nClients > 0:
        # Remove client if the run ended
        if hd.recv():
#            print "end run called"
            nClients -= 1
        else:
#            print "Calling plot?"
            plot(hd)
            comp = hd.myobj['comp']
            size=(comp['drop']['a']+comp['drop']['b'])/2.0
            pushToHist('DropSize',size)
            pushToHist('TOFhits',comp['tofsum'])
            writeh5(hd)
            

    closeh5()
Beispiel #5
0
def runclient(args, mask, thresholds):
    hd=hitdata()
    hf=tofhitfind() 
    ihf=imghitfind()
    
    ds = DataSource('exp=amoj5415:run=' + args.exprun+':smd')
   # ds = DataSource('exp=amoj5415:' + args.exprun+':smd'+':dir=/reg/d/ffb/amo/amoj5415/xtc:live')
#    ds = DataSource(args.exprun+':smd'+':dir=/reg/d/ffb/amo/amoj5415/xtc:live')
  
    det1 = Detector('pnccdFront',ds.env())
    det2 = Detector('ACQ4',ds.env())
    epics = ds.env().epicsStore()
    diodeThresh = thresholds['diode'] #0.15 #diode drop threshold. 0.15=diode drop active, -100=disble drop detection
    thresh = thresholds['tof'] #2 #tof threshold. 0=none, 1=loose, 2=typical, 20=AQUIRIS scale = 1
    upperThresh = thresholds['tofUpper'] #2000E10 #tof threshold to dump IR only shots
    ithr   = thresholds['image'] #850 #image threshold. -1e6 = none, (80) 500=typical

    bkgTOF = np.zeros(10000)
    bkgN = 0
    
#    print "rank, size = ", rank, size
    try:
        for nevent,evt in enumerate(ds.events()):
            howFarBehind = time.time() - evt.get(EventId).time()[0]
            if howFarBehind < 30.0:
                time.sleep(30.0-howFarBehind)
            if nevent == args.noe : break #kill if we reach event noe
 #           if (rank == 1) : print("nevent", nevent)
            if nevent%(size-1)==rank-1:  # different ranks look at different events
                try:

                #                print rank," processing event", nevent
                    eid = evt.get(EventId)
                    sec = eid.time()[0]
                    nsec = eid.time()[1]
                    fid = eid.fiducials()
                    et = EventTime(int((sec<<32)|nsec),fid)

                    tof = det2.raw(evt)
                    if tof is not None: 
                        tof, tofAxis = det2.raw(evt)
                    else:
                        print nevent, " tof read failure"
                        continue
                    diode = np.max(tof[2])
                    #print ("event " + str(nevent) + " diode is " + str(diode))

                    if (diode < diodeThresh):
                    #if (np.random.random() > 0.99):
                        print('diode below thresh @ ' + str(diode))
                        img = det1.image(evt) 
                        hd.sendDiode(img)
                        continue
                        
                                        
                    if (hf.hitfind(tof[0],tofAxis[0],thresh, upperThresh)):
                 
                        #if (np.random.random() > 0):
                        epdict=dict()
                        for name in epics.names():
                            epdict[name]=epics.value(name)

#                       if(np.random.random() > 0):   #
                        img = det1.image(evt) 
                        if (ihf.pixelCountThreshold(img[200:475,150:940],ithr)):     
                            print ("hit at ", time.ctime(), eid)
                            obj = dummyFit(img, mask)  #call fitting routine
                            comp = { 'et':et , 'tof':tof[0], 'tofAxis':tofAxis[0], 'epics':epdict, 'drop':obj['drop'], 'tofsum':hf.sum , 'imgsum':ihf.sum, 'diode':diode }
                            hd.send(comp, obj['orig'], obj['fit'])
                    else:
                  #      if (bkgN < 60):
                  #          img = det1.calib(evt)
                  #          ihf.formBackground(img[:,:])
                        bkgTOF += tof[0]
                        bkgN += 1

                except Exception as e:
                    print "Exception on rank: ", rank, " event ", nevent
                    print e
                    continue
    except Exception as e:
        print "Exception wiht for loop on rank: ", rank 
        print e

    hd.endrun(bkgTOF, bkgN)