Commit 874fe9bb authored by vpalladi's avatar vpalladi

new version of python code with mp7 data format

parent c25b469e
import math, copy
import numpy as np
#import numpy as np
import collections
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
......@@ -10,161 +11,190 @@ import matplotlib.pyplot as plt
#from pygame.locals import *
from param.var import *
from hexagon import *
from shapes import *
from points import *
from data_types import *
from modules.seedButton import *
from matplotlib.widgets import Button
s3 = math.sqrt(3.)
# basic cell class
class Cell:
class BaseCell:
def __init__(self, row, column, side, wafer_type, shape=None, wafer_center=[0,0]):
self.row = row
self.col = column
self.center = [0, 0]
def __init__( self, side, centre=Point2D(0,0), rotation=0.0 ):
self.centre = centre
self.rotation = rotation
self.side = side
self.user_id = [0, 0]
self.wafer_type = wafer_type
self.cell_type = 0
# column id
if row%2 == 1:
self.center[0] = self.center[0] + side*math.sqrt(3.)/2 + wafer_center[0] # takes the offset
self.center[0] = self.center[0] + column*side*math.sqrt(3.)
# row id
self.center[1] = self.center[1] + row*1.5*self.side
if self.wafer_type == 256 :
self.center[1] = self.center[1] + 1.*self.side
self.center[1] = self.center[1] + wafer_center[1]
self.width = s3*side
# ids
self.cell_id = HGCcellId(0, 0)
self.cmssw_cell_id = -1
# user coordinates
if row%2 == 0:
self.user_id = [ row, 2*column ]
else:
self.user_id = [ row, 2*column+1 ]
# cell type
if self.user_id[0]%2 == 0 :
if ((self.user_id[1]-1)/2)%2 == 0 :
self.cell_type = 0 # A
self.color = red
else :
self.cell_type = 3 # D
self.color = green
else :
if ((self.user_id[1]-1)/2)%2 == 0 :
self.cell_type = 2 # C
self.color = blue
else :
self.cell_type = 1 # B
self.color = yellow
# cms id
self.cms_id = -1
# hexagons corners
h = hexagon(self.center, self.side)
tmp = h.get_coo()
self.corners = []
if shape == None :
self.corners = tmp
else :
for point in tmp :
if shape.contains_point(point) :
self.corners.append(point)
self.user_id_str = str(self.user_id[0])+','+str(self.user_id[1])
self.center[0] = 0
self.center[1] = 0
for point in self.corners :
self.center[0] = self.center[0] + point[0]
self.center[1] = self.center[1] + point[1]
self.center[0] = self.center[0]/len(self.corners)
self.center[1] = self.center[1]/len(self.corners)
self.build_cell()
self.status = 'none' # not hit seed
# cell geometry
def get_type(self) :
return self.cell_type
# build cell and cell's elements
def build_cell(self) :
print 'this is the base_cell.build_cell() method'
def get_side(self) :
# get cell geometry
def get_side( self ) :
return self.side
def get_center(self):
return self.center
def get_centre( self ) :
return self.centre
def get_corners(self):
return self.corners
def translate(self, trans) :
self.corners = [ [ p_coo+c_coo for p_coo,c_coo in zip(point,trans)] for point in self.corners]
self.center[0] = self.center[0] + trans[0]
self.center[1] = self.center[1] + trans[1]
def get_corners( self ) :
return self.shape.get_coo()
# user id
def get_raw_coordinate(self) :
return [self.row, self.col]
def translate( self, point=Point2D(0,0) ) :
self.shape.translate( point )
self.centre = self.centre + point
def get_user_id(self):
return self.user_id
def get_user_id_row(self):
return self.user_id[0]
def contains_point(self, point) :
if self.shape.contains_point( point ) :
return True
else :
return False
def contains_shape(self, shape) :
for point in shape.get_coo_list() :
if not self.contains_point(point) :
return False
def get_user_id_col(self):
return self.user_id[1]
def remove_points_not_in_shape(self, shape) :
self.shape.remove_points_not_in_shape(shape)
def get_id(self):
return self.cell_id
# def get_user_id_row(self):
# return self.user_id[0]
#
# def get_user_id_col(self):
# return self.user_id[1]
def get_user_id_str(self):
return self.user_id_str
# def get_user_id_str(self):
# return self.user_id_str
def get_wafer_type(self):
return self.wafer_type
# def get_wafer_type(self):
# return self.wafer_type
# CMS coordinates
def set_cms_id(self, id):
self.cms_id = id
def set_cmssw_id(self, cmssw_id):
self.cmssw_id = cmssw_id
def get_cms_id(self):
return self.cms_id
def get_cmssw_id(self):
return self.cmssw_id
# drawing
def draw(self) :
if len( self.corners ) > 0 :
tc = plt.Polygon( self.corners )
tc.set_linewidth(0.5)
tc.set_linestyle('dotted')
tc.set_fill(0)
plt.gca().add_patch(tc)
def draw_user_id(self):
plt.text( self.center[0], self.center[1], self.user_id_str+'-'+str(self.cms_id),
size=7,
horizontalalignment='center',
verticalalignment='center')
# def draw_type(self, color) :
# tc = plt.Polygon( self.corners )
# tc.set_linewidth(0)
# tc.set_facecolor(color)
# plt.gca().add_patch(tc)
def draw(self, linestyle='dotted', linewidth=0.5) :
self.shape.draw(linestyle=linestyle, linewidth=linewidth, fill=0)
#def draw_user_id(self, surface, color, font="arial", size=10):
# myfont = pygame.font.SysFont(font, size)
# label = myfont.render( self.user_id_str , 1, color)
# surface.blit(label, self.corners_SC[5] )
#
def draw_cms_id(self) :
plt.text( self.center[0], self.center[1], str(self.cms_id),
size=10,
horizontalalignment='center',
verticalalignment='center',)
# def draw_id(self):
# plt.text( self.centre.x, self.centre.y, self.user_id_str+'-'+str(self.cms_id),
# size=7,
# horizontalalignment='centre',
# verticalalignment='centre')
#
# def draw_cmssw_id(self) :
# plt.text( self.centre.x, self.centre.x, str(self.cmssw_cell_id),
# size=10,
# horizontalalignment='centre',
# verticalalignment='centre',)
def change_color(self) :
if self.status == 'none' :
self.status = 'hit'
self.shape.poly.set_facecolor( blue )
self.shape.poly.set_fill(1)
elif self.status == 'hit' :
self.status = 'seed'
self.shape.poly.set_facecolor( yellow )
elif self.status == 'seed' :
self.status = 'none'
self.shape.poly.set_fill(0)
print self.status
plt.draw()
# printing methods
def print_corners(self):
for i in range (0, 5):
print str(i)+' = '+str( self.corners[i] )
class Cell(BaseCell):
def build_cell(self):
# hexagons corners
self.shape = hexagon( side=self.side, centre=self.centre, rotation_rad=self.rotation )
#self.user_id_str = str(self.user_id[0])+','+str(self.user_id[1])
#self.centre[0] = 0
#self.centre[1] = 0
#for point in self.corners :
# self.centre[0] = self.centre[0] + point[0]
# self.centre[1] = self.centre[1] + point[1]
#self.centre[0] = self.centre[0]/len(self.corners)
#self.centre[1] = self.centre[1]/len(self.corners)
class HalfCell(BaseCell):
def build_cell(self):
# hexagons corners
self.shape = half_hexagon(side=self.side, centre=self.centre, rotation_rad=self.rotation)
#tmp = self.shape.get_coo()
#
#self.corners = []
#if shape == None :
# self.corners = tmp
#else :
# for point in tmp :
# if shape.contains_point(point) :
# self.corners.append(point)
#
#self.user_id_str = str(self.user_id[0])+','+str(self.user_id[1])
#
#self.centre[0] = 0
#self.centre[1] = 0
#for point in self.corners :
# self.centre[0] = self.centre[0] + point[0]
# self.centre[1] = self.centre[1] + point[1]
#self.centre[0] = self.centre[0]/len(self.corners)
#self.centre[1] = self.centre[1]/len(self.corners)
class CornerZoltanCell(BaseCell):
def build_cell(self):
# hexagons corners
self.shape = hexagon_flatside_long(self.side, self.centre, rotation_rad=self.rotation)
#tmp = h.get_coo()
#
#self.corners = []
#if shape == None :
# self.corners = tmp
#else :
# for point in tmp :
# if shape.contains_point(point) :
# self.corners.append(point)
#
#self.user_id_str = str(self.user_id[0])+','+str(self.user_id[1])
#
#self.centre[0] = 0
#self.centre[1] = 0
#for point in self.corners :
# self.centre[0] = self.centre[0] + point[0]
# self.centre[1] = self.centre[1] + point[1]
#self.centre[0] = self.centre[0]/len(self.corners)
#self.centre[1] = self.centre[1]/len(self.corners)
class HGCwaferId :
def __init__(self, u=999, v=999) :
self.set(u, v)
def set(self, u, v) :
self.u = u
self.v = v
def u(self):
return self.u
def v(self):
return self.v
class HGCwaferId :
def __init__(self, u=999, v=999) :
self.set(u, v)
def set(self, u, v) :
self.u = u
self.v = v
def u(self):
return self.u
def v(self):
return self.v
class HGCcellId :
def __init__(self, x=999, y=999) :
self.set(x, y)
def set(self, x, y) :
self.x = x
self.y = y
def x(self):
return self.x
def y(self):
return self.y
#!/usr/bin/python
import math, copy
import numpy as np
import collections
import sys
from points import *
from shapes import *
#def genCentres(innerRadius, outerRadius, hexSide, rotation=0.) :
#
# hexWidth = hexSide * math.sqrt(3.)
#
# nCentresInOuterRadius = int ( outerRadius / hexSide )
#
# centres = [ ] # list of all centers
# yStep = (3./2.) * hexSide
# xStep = hexWidth
# # generate the row 0 positive col
# for iCentreY in range(-nCentresInOuterRadius, nCentresInOuterRadius+1) :
# Ycentre = iCentreY * yStep
# for iCentreX in range(-nCentresInOuterRadius, nCentresInOuterRadius+1) :
# if (iCentreY%2) == 0:
# Xcentre = iCentreX * xStep
# else :
# Xcentre = iCentreX * xStep + xStep/2.
# R = math.sqrt( Xcentre*Xcentre + Ycentre*Ycentre )
# if R > innerRadius and R < outerRadius:
# sin = math.sin(rotation)
# cos = math.cos(rotation)
# centres.append( [ Xcentre*cos-Ycentre*sin, Xcentre*sin+Ycentre*cos ] )
#
# return centres
def genCentres(innerRadius, outerRadius, hexSide, rotation=0., xTranslation=0., yTranslation=0.) :
hexWidth = hexSide * math.sqrt(3.)
nCentresInOuterRadius = int ( outerRadius / hexSide )
centres = {} # list of all centers
yStep = (3./2.) * hexSide
xStep = hexWidth
# generate the row 0 positive col
for row in range(-nCentresInOuterRadius, nCentresInOuterRadius+1) :
centres[row] = {}
for column in range(-nCentresInOuterRadius, nCentresInOuterRadius+1) :
if (column%2) == 0:
XcentreOrg = row * xStep
else :
XcentreOrg = row * xStep + xStep/2.
YcentreOrg = column * yStep
# transformations
sin = math.sin(rotation)
cos = math.cos(rotation)
Xcentre = XcentreOrg*cos-YcentreOrg*sin
Ycentre = XcentreOrg*sin+YcentreOrg*cos
Xcentre = Xcentre + xTranslation
Ycentre = Ycentre + yTranslation
R = math.sqrt( Xcentre*Xcentre + Ycentre*Ycentre )
if R > innerRadius and R < outerRadius:
# Xcentre = Xcentre - hexSide
centres[row][column] = Point2D( Xcentre, Ycentre )
return centres
def genPanelCentres(hexSide, rotation=0., xTranslation=0., yTranslation=0.) :
hexWidth = hexSide * math.sqrt(3.)
centres = {} # list of all centers
yStep = (3./2.) * hexSide
xStep = hexWidth
# generate the row 0 positive col
for row in range(0, 2) :
centres[row] = {}
for column in range(0, 3) :
if (column%2) == 0:
XcentreOrg = row * xStep
else :
XcentreOrg = row * xStep + xStep/2.
YcentreOrg = column * yStep
# transformations
sin = math.sin(rotation)
cos = math.cos(rotation)
Xcentre = XcentreOrg*cos-YcentreOrg*sin
Ycentre = XcentreOrg*sin+YcentreOrg*cos
Xcentre = Xcentre + xTranslation
Ycentre = Ycentre + yTranslation
centres[row][column] = Point2D( Xcentre, Ycentre )
return centres
#!/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
# my classes
from param.var import *
from modules.cell import *
from modules.tc import *
from modules.matrices import *
from modules.wafer import *
from modules.genCentres import *
# geometry for the c++ code
from Geometry.geom import *
class Layer :
#def __init__(self, LAYER_ID,
# WAFER_SIDE, CELL_HG_SIDE, CELL_LG_SIDE,
# PICK_WAFER, PICK_WAFER_FLAG,
# GENERATE_CENTRES=0, INNER_RADIUS=0, OUTER_RADIUS=50,
# BUILD_HG_WAFERS=1, BUILD_LG_WAFERS=1,
# WAFER_TYPE='zoltan') :
def __init__(self, LAYER_ID,
WAFER_SIDE, CELL_HG_SIDE, CELL_LG_SIDE,
PICK_WAFER, PICK_WAFER_FLAG,
GENERATE_CENTRES=0, INNER_RADIUS=0, OUTER_RADIUS=50,
BUILD_HG_WAFERS=1, BUILD_LG_WAFERS=1,
WAFER_TYPE='zoltan') :
geom = Geometry()
self.layer = LAYER_ID
self.w_side = WAFER_SIDE
self.w_width = self.w_side * math.sqrt(3.)
self.cell_hg_side = CELL_HG_SIDE
self.cell_lg_side = CELL_LG_SIDE
self.BUILD_LG_WAFERS = BUILD_LG_WAFERS
self.BUILD_HG_WAFERS = BUILD_HG_WAFERS
##################################################
#### generate all the wafer centres and types ####
##################################################
centers_wafers_hg = []
centers_wafers_lg = []
centres = []
wafer_types = []
if GENERATE_CENTRES :
centres_map = genCentres(INNER_RADIUS, OUTER_RADIUS, self.w_side)
for row in centres_map :
for c in centres_map[row] :
centres.append(centres_map[row][c])
wafer_types = [0 for i in range(0, len(centres))]
else :
for wafer in range(0, geom.numberOfWafers(self.layer)) :
centres.append( geom.waferPoint2D(self.layer, wafer) )
wafer_types.append( geom.waferType(self.layer, wafer) )
### temporary comment ### for wafer in range(0, geom.numberOfWafers(layer)) :
wafer = 0
for center,wafer_type in zip(centres, wafer_types) :
### define the wafer type
wafer_norm_id_row = int( round( center.y / ( 1.5*WAFER_SIDE) ) )
if wafer_norm_id_row % 2 == 0 :
wafer_norm_id_col = int( round( center.x / ( math.sqrt(3)*WAFER_SIDE ) ) ) # col
else :
wafer_norm_id_col = int( round( ( center.x - 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_wafers_hg.append( [center, wafer, wafer_norm_id] )
else :
centers_wafers_lg.append( [center, wafer, wafer_norm_id] )
#wafer = wafer+1
centers = {}
centers[256] = centers_wafers_hg
centers[128] = centers_wafers_lg
#centers[0] = test_center
cell_side = {}
cell_side[256] = self.cell_hg_side
cell_side[128] = self.cell_lg_side
#cell_side[0] = CELL256_SIDE
#### build wafers ####
w_id = []
wafers_to_build = []
if BUILD_HG_WAFERS :
wafers_to_build.append( 256 )
print 'processing '+str(len(centers[256]))+' wafers of HIGH granularity type'
if BUILD_LG_WAFERS :
wafers_to_build.append( 128 )
print 'processing '+str(len(centers[128]))+' wafers of LOW granularity type'
#########################
#### building wafers ####
#########################
print ' >>> Building wafers...'
self.wafers = {}
for wafer_type in wafers_to_build :
print 'processing '+str(wafer_type)+' type wafers'
self.wafers[wafer_type] = []
for center,wafer_id,wafer_norm_id in centers[wafer_type] :
#if not(geom.validWafer(self.layer, wafer_id)) :
# continue
wafer_must_build = 0
if wafer_type == 0 :