Last active
March 8, 2018 14:43
-
-
Save themperek/31720b7a186618b17f489a3ad504638c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
PIXEL_NO = 8*400 | |
PIXEL_AREA = 50*50 | |
HIT_RATE_CM = 0.5*(10**9) # this is hit rate should be region rate for this | |
TRIGGER_RATE = 4.0/40 | |
pixel_hit_rate_bx = ((float(PIXEL_AREA)/(10000*10000)) * HIT_RATE_CM )/ (40*(10**6)) | |
trig_mem = np.full((100000) ,-1, dtype=np.int) | |
stat_trig = np.full((10000) ,0, dtype=np.int) | |
wait_time = np.full((10000) ,0, dtype=np.int) | |
hits_list = {} | |
reg_wait_time = 0 | |
hits_count = 0 | |
trig_id = 0 | |
trig_req_id = 0 | |
for bx in range(1000000): #(1000000): | |
trig = np.random.rand(1) < TRIGGER_RATE #if trigger | |
if trig: | |
hits = np.count_nonzero(np.random.rand(PIXEL_NO) < pixel_hit_rate_bx) #lottery | |
empty = np.where(trig_mem==-1)[0] #check in queue empty position | |
trig_mem[empty[:hits]] = trig_id #insert | |
hits_list[trig_id] = [bx,hits] | |
trig_id += 1 | |
#every 2nd bx remove one hit or move with trigger | |
if bx % 2 == 0: | |
reg_hits = np.where(trig_mem==trig_req_id)[0] | |
if len(reg_hits): #if hits with this trigger id | |
waited = bx - hits_list[trig_req_id][0] | |
ht = hits_list[trig_req_id][1] | |
hits_count += ht | |
reg_wait_time += (waited*ht) | |
wait_time[waited] += ht | |
trig_mem[reg_hits[0]] = -1 | |
reg_hits = np.where(trig_mem==trig_req_id)[0] | |
if len(reg_hits) == 0: | |
if trig_id > trig_req_id: | |
trig_req_id += 1 | |
trig_in_fifo = np.count_nonzero(np.unique(trig_mem))-1 | |
stat_trig[trig_in_fifo] += 1 | |
if bx % 1000 == 999: | |
print 'bx:', bx , 'trig_queue:', trig_in_fifo | |
print 'trigger size hist', stat_trig[:200] | |
print 'wait_time hist', wait_time[:200] | |
np.save('trg_fifo.npy', stat_trig) | |
np.save('wait.npy', wait_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment