Exemplo n.º 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()	
Exemplo n.º 2
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)