Commit ed31bd1f authored by vpalladi's avatar vpalladi

tc and cell numenclature done

parent d4e774de
......@@ -24,24 +24,33 @@ s3 = math.sqrt(3.)
# basic cell class
class BaseCell:
def __init__( self, side, centre=Point2D(0,0), rotation=0.0 ):
def __init__( self, side=1, centre=Point2D(0,0), rotation_rad=0.0, mirror=0, cell_id=HGCid(), cmssw_id=-1, energy=-1 ):
# geom attributes
self.centre = centre
self.rotation = rotation
self.side = side
self.width = s3*side
# transformation
self.rotation = rotation_rad
self.mirror = mirror
# ids
self.cell_id = HGCcellId(0, 0)
self.cmssw_cell_id = -1
self.cell_id = cell_id
self.cmssw_id = -1
# build the cell
self.build_cell()
self.status = 'none' # not hit seed
# status and energy
self.energy = energy
self.status = 'none' # none, hit, seed
# build cell and cell's elements
def build_cell(self) :
print 'this is the base_cell.build_cell() method'
# get cell geometry
# get methods
def get_side( self ) :
return self.side
......@@ -51,10 +60,6 @@ class BaseCell:
def get_corners( self ) :
return self.shape.get_coo()
def translate( self, point=Point2D(0,0) ) :
self.shape.translate( point )
self.centre = self.centre + point
def contains_point(self, point) :
if self.shape.contains_point( point ) :
return True
......@@ -66,23 +71,12 @@ class BaseCell:
if not self.contains_point(point) :
return False
def remove_points_not_in_shape(self, shape) :
self.shape.remove_points_not_in_shape(shape)
# id
def set_id(self, cell_id):
self.cell_id = cell_id
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_wafer_type(self):
# return self.wafer_type
# CMS coordinates
def set_cmssw_id(self, cmssw_id):
......@@ -91,59 +85,50 @@ class BaseCell:
def get_cmssw_id(self):
return self.cmssw_id
# transformations
def translate( self, point=Point2D(0,0) ) :
self.shape.translate( point )
self.centre = self.centre + point
def remove_points_not_in_shape(self, shape) :
self.shape.remove_points_not_in_shape(shape)
# drawing
def draw(self, linestyle='dotted', linewidth=0.5) :
self.shape.draw(linestyle=linestyle, linewidth=linewidth, fill=0)
# 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_id(self):
self.cell_id.draw( self.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()
# GUI
def set_seed(self) :
self.status = 'seed'
self.shape.poly.set_facecolor( yellow )
self.shape.poly.set_fill(1)
def set_hit(self) :
self.status = 'hit'
self.shape.poly.set_facecolor( blue )
self.shape.poly.set_fill(1)
def set_none(self) :
self.status = 'none'
self.shape.poly.set_fill(0)
# 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):
......@@ -151,50 +136,24 @@ 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)
# penthagon
self.shape = penthagon_corner( side=self.side, centre=self.centre, rotation_rad=self.rotation, mirror=self.mirror)
#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 LongSideZoltanCell(BaseCell):
def build_cell(self):
# penthagon
self.shape = hexagon_flatside_long( side=self.side, centre=self.centre, rotation_rad=self.rotation)
class ShortSideZoltanCell(BaseCell):
def build_cell(self):
# penthagon
self.shape = hexagon_flatside_short( side=self.side, centre=self.centre, rotation_rad=self.rotation)
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
from points import *
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
class HGCid :
def __init__( self, row=999, col=999 ) :
self.row = row
self.col = col
def get_row( self ) :
return row
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
def get_col( self ) :
return col
def draw( self, centre=Point2D(0, 0) ) :
id_string = str(self.row)+'-'+str(self.col)
plt.text( centre.x, centre.y, id_string,
size=7,
horizontalalignment='center',
verticalalignment='center')
#!/usr/bin/python
import math
class hexagon:
def __init__(self, center, side) :
s3 = math.sqrt(3.)
A = [ 0., 1. ]
B = [ s3/2., 0.5 ]
C = [ s3/2., -0.5 ]
D = [ 0., -1. ]
E = [ -s3/2., -0.5 ]
F = [ -s3/2., 0.5 ]
self.coo = [A, B, C, D, E, F]
self.coo = [ [ coo*side for coo in point] for point in self.coo ]
self.coo = [ [ p_coo+c_coo for p_coo,c_coo in zip(point,center)] for point in self.coo]
def translate(self, new_center) :
self.coo = [ [ p_coo+c_coo for p_coo,c_coo in zip(point,new_center)] for point in self.coo]
def get_coo(self) :
return self.coo
import math, copy
import numpy as np
import collections
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
from param.var import *
from cell import *
from tc import *
# cells matrix
class Cell_matrix :
def __init__(self, first_row, last_row, first_column, last_column, cell_side, wafer_type) :
self.cells = {}
# building up the matrix
for row in range(first_row, last_row) :
self.cells[row] = {} # nest dictionaries rows (row_US for cell is always row)
for column in range (first_column, last_column) :
cell = Cell(row, column, cell_side, wafer_type)
self.cells[ cell.get_user_id()[0] ][ cell.get_user_id()[1] ] = cell
# draw cell
def draw(self, user_id=1) :
for row in self.cells :
row_cells = self.cells[row]
for col in row_cells :
self.cells[row][col].draw()
if user_id :
self.cells[row][col].draw_user_id()
# return cells
def get_cells(self) : # return a nested dict
return self.cells
# trigger cells matrix
class Trigger_cell_matrix :
def __init__(self, cells, pivot=TC_CELL_PIVOT ) :
self.trigger_cells = {}
# building up the matrix
for row in cells :
row_cells = cells[row]
for col in row_cells :
cell = cells[row][col]
if cell.get_type() == pivot :
trigger_cell = Trigger_cell( cell.get_center(),
cell.get_side(),
None,
cell.get_user_id()[0],
cell.get_user_id()[1] )
if cell.get_user_id_row() not in self.trigger_cells :
self.trigger_cells[cell.get_user_id_row()] = {}
self.trigger_cells[cell.get_user_id_row()][cell.get_user_id_col()] = trigger_cell
# draw TC matrices
def draw(self) :
for row in self.trigger_cells :
row_trigger_cells = self.trigger_cells[row]
for col in row_trigger_cells :
self.trigger_cells[row][col].draw()
# return cells and TC
def get_trigger_cells(self) : # return a nested dict
return self.trigger_cells
......@@ -24,8 +24,8 @@ class Panel :
self.nRow = 2
self.nCol = 3
##vito self.wafers[0] = {}
##vito self.wafers[0][0] = ZoltanWafer(self.wafer_side, wafer_type='LG')
self.wafers[0] = {}
#self.wafers[0][0] = ZoltanWafer(self.wafer_side, wafer_type='HG')
for row in range( 0, self.nRow ) :
self.wafers[row] = {}
......@@ -39,18 +39,18 @@ class Panel :
if (row%2) == 0 :
centre.x = centre.x + self.wafer_width/2
# self.wafers[row][col] = Wafer(self.wafer_side, wafer_type='LG', centre=centre)
self.wafers[row][col] = ZoltanWafer(self.wafer_side, wafer_type='LG', centre=centre)
#self.wafers[row][col] = Wafer(self.wafer_side, wafer_type='LG', centre=centre)
self.wafers[row][col] = ZoltanWafer(self.wafer_side, wafer_type='HG', centre=centre)
def draw( self ) :
for row in range( 0, self.nRow ) :
for col in range( 0, self.nCol ) :
self.wafers[row][col].draw()
self.wafers[row][col].draw_cells()
#self.wafers[row][col].draw_cells()
#self.wafers[row][col].draw_cells_id()
#self.wafers[row][col].draw_trigger_cells()
self.wafers[row][col].draw_trigger_cells()
self.wafers[row][col].draw_trigger_cells_id()
# GUI
def on_click( self, event ) :
p = Point2D( event.xdata, event.ydata )
......
......@@ -50,7 +50,14 @@ class Point2D :
cos = math.cos(math.pi/6)
return -self.x*sin+self.y*cos
def get_mag(self) :
return math.sqrt( self.x*self.x + self.y*self.y )
def get_dist_uv(self) :
rho = self.get_mag()
sin_theta = self.y / rho
cos_theta = self.x / rho
return Point2D( rho * (cos_theta/2.-math.sqrt(3)*sin_theta/2.), rho * (cos_theta/2.+math.sqrt(3)*sin_theta/2.) )
class Point3D :
def __init__(self, x, y, z) :
......
......@@ -215,6 +215,11 @@ class WaferBase:
for col in self.tcs[row] :
self.tcs[row][col].draw(linestyle='solid', linewidth=2)
def draw_trigger_cells_id(self, cms_id_on=1, user_id_on=1, type_on=0):
for row in self.tcs :
for col in self.tcs[row] :
self.tcs[row][col].draw_id()
def draw_id(self) :
plt.text( self.centre.x, self.centre.y, str(self.wafer_id),
size=13,
......@@ -524,10 +529,10 @@ class ZoltanWafer(WaferBase):
def map_cells( self ) :
if self.wafer_type == 'LG' :
self.cell_width = (2*self.side)/14
elif self.wafer_type == 'HG' :
if self.wafer_type == 'HG' :
self.cell_width = (2*self.side)/16
elif self.wafer_type == 'LG' :
self.cell_width = (2*self.side)/12
self.cell_side = self.cell_width/math.sqrt(3.)
......@@ -545,7 +550,6 @@ class ZoltanWafer(WaferBase):
cells_Xoffset = self.cell_side/2.
cells_Yoffset = 0.
A_corner = hexagon( side=2*self.cell_side, centre=Point2D(0, self.side) )
B_corner = hexagon( side=2*self.cell_side, centre=Point2D(self.width/2, self.side/2) )
C_corner = hexagon( side=2*self.cell_side, centre=Point2D(self.width/2, -self.side/2) )
......@@ -553,7 +557,7 @@ class ZoltanWafer(WaferBase):
E_corner = hexagon( side=2*self.cell_side, centre=Point2D(-self.width/2, -self.side/2) )
F_corner = hexagon( side=2*self.cell_side, centre=Point2D(-self.width/2, self.side/2) )
coner_shapes = [ A_corner, B_corner, C_corner, D_corner, E_corner, F_corner ]
corner_shapes = [ A_corner, B_corner, C_corner, D_corner, E_corner, F_corner ]
AB_shape = side_square(self.side, self.cell_side, 'AB')
BC_shape = side_square(self.side, self.cell_side, 'BC')
......@@ -595,7 +599,7 @@ class ZoltanWafer(WaferBase):
cell_centre,
rotation_rad=rotation )
for iCorner, corner in enumerate(coner_shapes) :
for iCorner, corner in enumerate(corner_shapes) :
if corner.contains_point( cell_centre.get_list() ) :
rotation = -math.pi*(5./6.)+iCorner*math.pi/3
mirror = 0
......@@ -610,54 +614,65 @@ class ZoltanWafer(WaferBase):
rotation_rad=rotation,
mirror=mirror )
if add :
self.cells[row][col] = cell
for row in self.cells :
for col in self.cells[row] :
origin = Point2D( self.centre.x+self.cells[row][col].side/2, -self.side+self.cells[row][col].width/2 )
c_side = self.cells[row][col].side
x = self.cells[row][col].centre.x
y = self.cells[row][col].centre.y
m = math.sqrt(3.)/3.
k = self.shape.get_coo()[3].y
point = self.cells[row][col].centre - origin
k_30 = y+x/m
x_30 = m*(k_30-k)/(m*m+1)
y_30 = m*x_30 + k
d_30 = math.sqrt( (x-x_30)*(x-x_30) + (y-y_30)*(y-y_30) )
print '""""""'
print row, col
print self.cells[row][col].centre.get_list()
print point.get_list()
print point.get_u(),point.get_v()
r = int( round( (d_30-c_side/2)/(c_side*1.5) ) )
m = -math.sqrt(3.)/3.
k = self.shape.get_coo()[3].y
k_150 = y+x/m
x_150 = m*(k_150-k)/(m*m+1)
y_150 = m*x_150 + k
d_150 = math.sqrt( (x-x_150)*(x-x_150) + (y-y_150)*(y-y_150) )
c = int( round( (d_150-c_side)/(c_side*1.5) ) )
r = int( point.get_u() / ( (3./2.)*self.cells[row][col].side ) )
c = int( point.get_v() / self.cells[row][col].side )
self.cells[row][col].set_id( HGCid( r, c ) )
def map_trigger_cells_LG(self) :
self.tcs = {}
xOffset = self.cell_side/2.
yOffset = self.cell_width
xStep = 3*self.cell_side
yStep = 2*self.cell_width
for row in range(-4, 4) :
self.tcs[row] = {}
for row in range(-4, 5) :
self.tcs[row] = {}
for col in range(-4, 4) :
tc_centre = Point2D(xOffset+col*xStep, yOffset+row*yStep)
xOffset = self.cell_side/2.
yOffset = self.cell_width
xStep = 3*self.cell_side
yStep = 2*self.cell_width
tc_centre = Point2D( xOffset + col*xStep, yOffset + row*yStep )
if col%2 == 1 :
tc_centre.y = tc_centre.y+self.cell_width
tc = TriggerCell( centre=tc_centre, side=self.cell_side, rotation_rad=math.pi*(5./6.) )
if self.shape_extended.contains_point( tc_centre.get_list() ) :
if self.shape.contains_point( tc_centre.get_list() ) :
if (tc_centre.y-tc_centre.x * math.sqrt(3.)/3 ) > 0 and (tc_centre.y+tc_centre.x * math.sqrt(3.)/3 ) > 0 :
tc.remove_points_not_in_shape(self.shape_extended)
tc = TriggerCell( centre=tc_centre, side=self.cell_side, rotation_rad=math.pi*(5./6.), cell_id=HGCid(row,col) )
elif tc_centre.x > 0 and (tc_centre.y-tc_centre.x * math.sqrt(3.)/3 ) < 0 :
......@@ -669,7 +684,7 @@ class ZoltanWafer(WaferBase):
if col%2 == 1 :
tc_centre.y = tc_centre.y+self.cell_width
tc = TriggerCell( centre=tc_centre, side=self.cell_side, rotation_rad=math.pi*(5./6.)-(2./3.)*math.pi )
tc = TriggerCell( centre=tc_centre, side=self.cell_side, rotation_rad=math.pi*(5./6.)-(2./3.)*math.pi, cell_id=HGCid(row,col) )
tc.remove_points_not_in_shape(self.shape_extended)