Commit 6a80a1fa authored by vpalladi's avatar vpalladi

minor bug fixing

parent 42d797f8
#!/usr/bin/python
import math, copy
import numpy as np
import collections
import sys
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as ptl
import matplotlib.figure as pfig
# mp7 data types
import mp7dataTypes as mp7dt
# my classes
from param.var import *
from modules.cell import *
from modules.tc import *
from modules.matrices import *
from modules.wafer import *
#from classes.coo import *
# geometry from Paul
from Geometry.geom import *
#
## usage
#
def usage(argv) :
if len(argv) == 1:
print 'This will visualize an mp7 data formatted file into frame of the HGC geometry'
print 'Usage: ',argv[0],' [layerId] [link_to_display] [fileName] [clu/mp7]'
exit()
#
##
#
def readMp7File(fileName) :
fileIn = open(fileName)
hgcData = [ [] for i in range(0,72) ]
for i in range(0, 3) :
fileIn.readline()
nLines=0
while 1 :
nLines=nLines+1
if nLines==56:
break
line = fileIn.readline()
if line == '' :
break
ilink = 0
for w in line.split(':')[-1].split(' ') :
data = w.split('v')
if len(data)==1 :
continue
if data[1]=='' :
continue
data[-1].strip()
mp7 = mp7dt.mp7Word()
mp7.data = int(data[-1], 16)
hgcData[ilink].append( mp7dt.mp72hgc(mp7) )
ilink = ilink+1
#mp7.p()
#mp7dt.mp72clu(mp7).p()
#print
#hgcData[-1].p()
return hgcData
#
## read cluster file
#
def readCluFile(fileName) :
fileIn = open(fileName)
cluData = []
while 1 :
line = fileIn.readline()
print line
if line == '' :
break
for pos, data in enumerate(line.split(' ')) :
if pos>0 :
print data
if data[1]=='' :
continue
data[-1].strip()
mp7 = mp7dt.mp7Word()
mp7.data = int(data, 16)
if (int(data, 16) & 0xff) != 0 :
cluData.append( mp7dt.mp72hgc(mp7) )
#mp7.p()
#mp7dt.mp72clu(mp7).p()
#print
#hgcData[-1].p()
print
return cluData
#
## visualize
#
def visualize(layer, hgcDataLink) :
geom = Geometry()
WAFER_SIDE = geom.waferWidth()/math.sqrt(3.0)
CELL256_SIDE = WAFER_SIDE / 15
CELL128_SIDE = WAFER_SIDE / 11
# which layer?
layer = 0
if len(sys.argv) == 1:
print "default layer number: ",layer
else :
layer = int(sys.argv[1])
print "selected layer: ",layer
# which lik to dispaly
base_cell = [-4, -52]
# define the pyplot figure
subpparm = pfig.SubplotParams(left=0, bottom=0.04, right=1, top=1, wspace=None, hspace=None)
plt.figure('Layer'+str(layer), figsize=(30,15), subplotpars=subpparm )
# map all the cells
print ' >>> generating 256 matrices '
cell_matrix_256 = Cell_matrix(FIRST_ROW, LAST_ROW, FIRST_COLUMN, LAST_COLUMN, CELL256_SIDE, 256)
cells_256 = cell_matrix_256.get_cells()
tc_matrices_256 = {}
tc_matrices_256[0] = Trigger_cell_matrix( cells_256, 0 )
tc_matrices_256[1] = Trigger_cell_matrix( cells_256, 1 )
tc_matrices_256[2] = Trigger_cell_matrix( cells_256, 2 )
tc_matrices_256[3] = Trigger_cell_matrix( cells_256, 3 )
#trigger_cells_256 = tc_matrix_256.get_trigger_cells()
print ' done.'
print ' >>> generating 128 matrices '
cell_matrix_128 = Cell_matrix(FIRST_ROW, LAST_ROW, FIRST_COLUMN, LAST_COLUMN, CELL128_SIDE, 128)
cells_128 = cell_matrix_128.get_cells()
tc_matrices_128 = {}
tc_matrices_128[0] = Trigger_cell_matrix( cells_128, 0 )
tc_matrices_128[1] = Trigger_cell_matrix( cells_128, 1 )
tc_matrices_128[2] = Trigger_cell_matrix( cells_128, 2 )
tc_matrices_128[3] = Trigger_cell_matrix( cells_128, 3 )
print ' done.'
cell_matrix = {}
cell_matrix[256] = cell_matrix_256
cell_matrix[128] = cell_matrix_128
cell_matrix[0] = cell_matrix_256
tc_matrices = {}
tc_matrices[256] = tc_matrices_256
tc_matrices[128] = tc_matrices_128
tc_matrices[0] = tc_matrices_256
######################
### wafer's centers
######################
# 256 cells wafer
centers_256 = []
# 128 cells wafer centers
centers_128 = []
# test
test_center = [ [ [0, 0], 1, [0, 0] ] ]
for wafer in range(0, geom.numberOfWafers(layer)) :
### from Geom
center = geom.waferPoint2D(layer, wafer)
wafer_type = geom.waferType(layer, wafer)
### define the wafer type
wafer_norm_id_row = int( round( center[1] / ( 1.5*WAFER_SIDE) ) )
if wafer_norm_id_row % 2 == 0 :
wafer_norm_id_col = int( round( center[0] / ( math.sqrt(3)*WAFER_SIDE ) ) ) # col
else :
wafer_norm_id_col = int( round( ( center[0] - math.sqrt(3)*WAFER_SIDE/2. ) / ( math.sqrt(3)*WAFER_SIDE) ) ) # col
wafer_norm_id = [wafer_norm_id_row, wafer_norm_id_col]
# append wafers center, type and norm id
if wafer_type == 1 :
centers_256.append( [center, wafer, wafer_norm_id] )
else :
centers_128.append( [center, wafer, wafer_norm_id] )
centers = {}
centers[256] = centers_256
centers[128] = centers_128
centers[0] = test_center
cell_side = {}
cell_side[256] = CELL256_SIDE
cell_side[128] = CELL128_SIDE
cell_side[0] = CELL256_SIDE
### draw what you need
w_id = []
wafers_to_build = []
if BUILD_WAFER_256 :
wafers_to_build.append( 256 )
print 'processing '+str(len(centers[256]))+' wafers type 256'
if BUILD_WAFER_128 :
wafers_to_build.append( 128 )
print 'processing '+str(len(centers[128]))+' wafers type 128'
if BUILD_WAFER_TEST :
wafers_to_build.append( 0 )
### building wafers
print ' >>> Building wafers...'
wafers = {}
for wafer_type in wafers_to_build :
print 'processing '+str(wafer_type)+' type wafers'
wafers[wafer_type] = []
for center,wafer_id,wafer_norm_id in centers[wafer_type] :
if not(geom.validWafer(layer, wafer_id)) :
continue
wafer_must_build = 0
if wafer_type == 0 :
wafer_must_build = 1
if len(PICK_WAFER) != 0:
if PICK_WAFER_FLAG == 'by_cms_id' :
if wafer_id in PICK_WAFER :
wafer_must_build = 1
if PICK_WAFER_FLAG == 'by_norm_id' :
if wafer_norm_id in PICK_WAFER :
wafer_must_build = 1
else :
wafer_must_build = 1
if wafer_must_build == 1 :
pivot = TC_CELL_PIVOT # 0=A 1=B 2=C 3=D
if TC_CELL_PIVOT_FIX == 0 :
if ( wafer_norm_id[0] % 2 ) == 0 :
if ( wafer_norm_id[1] % 2 ) == 0 :
pivot=0
else:
pivot=3
else:
if ( wafer_norm_id[1] % 2 ) == 0 :
pivot=1
else:
pivot=2
wafers[wafer_type].append ( Wafer( WAFER_SIDE, cell_matrix[wafer_type], tc_matrices[wafer_type][pivot], cell_side[wafer_type], layer, DRAW_CELLS, DRAW_TCS ) )
wafers[wafer_type][-1].place_wafer(center, wafer_id, layer)
wafer_must_build = 0
print ' done.'
### drawing wafer
w_types = []
if DRAW_WAFER_256 and BUILD_WAFER_256 :
w_types.append(256)
if DRAW_WAFER_128 and BUILD_WAFER_128 :
w_types.append(128)
if DRAW_WAFER_TEST :
w_types.append(0)
list_of_hits = []
for d in hgcDataLink :
print d.p()
list_of_hits.append([d.addr[0]+base_cell[0], d.addr[1]+base_cell[1]])
print d.addr[1]+base_cell[1],d.addr[1],base_cell[1]
for w_type in w_types :
for wafer in wafers[w_type] :
if w_type==128 :
wafer.draw(light_grey, WAFER_ID_ON, WAFER_NORM_ID_ON)
else :
wafer.draw(white, WAFER_ID_ON, WAFER_NORM_ID_ON)
if DRAW_TCS :
#list_of_hits = []
#for d in hgcDataLink :
# list_of_hits.append([d.addr[0]+base_cell[0], d.addr[1]+base_cell[1]])
wafer.draw_trigger_cells(TRIGGER_CELL_ID_ON, TRIGGER_CELL_NORM_ID_ON, list_of_hits)
#print list_of_hits
if DRAW_CELLS :
wafer.draw_cells(CMS_ID_ON, USER_ID_ON, TYPE_ON)
wafer.draw_edges()
if DRAW_CELL_MATRIX_256 :
cell_matrix[256].draw(USER_ID_ON)
if DRAW_CELL_MATRIX_128 :
cell_matrix[128].draw(USER_ID_ON)
if DRAW_TC_MATRIX_256 :
tc_matrix[256].draw()
if DRAW_TC_MATRIX_128 :
tc_matrix[128].draw()
plt.axis('scaled') # scale to the window size
if DRAW_CELL_MATRIX_256 or DRAW_CELL_MATRIX_128 or DRAW_TC_MATRIX_256 or DRAW_TC_MATRIX_128 or DRAW_TC_MATRIX or DRAW_WAFER_256 or DRAW_WAFER_128 or DRAW_WAFER_TEST :
plt.ylabel('Y[cm]')
plt.xlabel('X[cm]')
if SAVE_PDF :
plt.gcf().savefig('Layer_'+str(layer)+'.pdf', dpi=300)
plt.show()
#
## main
#
def main():
usage(sys.argv)
# hgcData = readMp7File(sys.argv[3])
linkToDisplay = int(sys.argv[2])
layerId = int(sys.argv[1])
if sys.argv[4] == 'mp7' :
hgcData = readMp7File(sys.argv[3])
visualize( layerId, hgcData[linkToDisplay] )
elif sys.argv[4] == 'clu' :
visualize( layerId, readCluFile(sys.argv[3]) )
#
## if python says run, then we should run
#
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment