Commit d0074cb7 authored by vpalladi's avatar vpalladi
Browse files

- pythong code cleaned up

- updated README.txt
- minor changes of Makefiles (compiles and python version from 2.7 to 2.6 (lxXX cmpatibility) )
parent a8f9dd45
Pipeline #6862 skipped
......@@ -11,8 +11,8 @@ CXX = g++
TOP = $(shell pwd)
# python
PYTHON_LOCAL_DIR = $(TOP)/python
NAMING_DIR = $(PYTHON_LOCAL_DIR)/naming
PYTHON_CODE = $(TOP)/python
NAMING_DIR = $(PYTHON_CODE)/naming
PYTHON_2_7 = /usr/include/python2.7
......@@ -30,9 +30,9 @@ HEPMC_DIR = $(TOP)/HepMC/2.06.09
PYTHON_2_7 = /usr/include/python2.7
##################################################
### create $TOP/bin directory if it does not exist
### create $(TOP)/bin directory if it does not exist
##################################################
#MKD_BIN = mkdir -p ./bin
MKD_BIN = mkdir -p ./bin
##########################
### flags and libs and INC
......@@ -43,18 +43,19 @@ ROOT_CFLAGS = $(shell root-config --cflags)
ROOT_GLIBS = $(shell root-config --glibs)
# HepMC flags
HEPMCFLAGS = -I$(HEPMC_DIR)/include -L$(HEPMC_DIR)/lib -lHepMC -lHepMCfio
HEPMC_FLAGS = -I$(HEPMC_DIR)/include
HEPMC_LIBS = -L$(HEPMC_DIR)/lib -lHepMC #-lHepMCfio
# CXX flags
CXXFLAGS = -Wall -std=c++0x
CXXFLAGS += $(ROOT_CFLAGS)
CXXFLAGS += $(HEPMC_FLAGS)
CXXFLAGS += -I$(INTERFACE_DIR) -I$(NAVIGATION_INC)
CXXFLAGS += -I$(TOP)/src -I$(PYTHON_2_7)
CXXFLAGS += $(HEPMCFLAGS)
# CXX LIBS
CXXLIBS = $(ROOT_GLIBS)
CXXLIBS = $(ROOT_GLIBS)
CXXLIBS += $(HEPMC_LIBS)
# all my files .ccp .cc and .hh
MAINS_CPP := $(wildcard $(TOP)/src/*.cpp)
......@@ -66,6 +67,7 @@ EXES := $(MAINS_CPP:.cpp=.exe)
all: $(EXES)
%.exe: %.cpp
$(MKD_BIN)
$(CXX) -o bin/$(notdir $@) $< $(CXXFLAGS) $(CXXLIBS)
py_lib:
......
#############
#############
##################
## installation ##
##################
1. HepMC:
......@@ -18,6 +27,9 @@
c.6. make test
c.7. make install
2. matplotlib:
2. python: tested with versions 2.6 2.7; numpy and matplotlib needed
3. Data:
data are expected to be stored or linked in a folder called 'RawData' located in your top directory
PYTHON_2_7 = /usr/include/python2.7
PYTHON = /usr/include/python2.6
LIB_DIR = $(TOP)/python/naming/Geometry
......@@ -7,6 +7,6 @@ all:
mkdir -p $(LIB_DIR)
touch $(LIB_DIR)/__init__.py
cp Geometry.hh Geometry.cpp
x86_64-linux-gnu-gcc -DPYTHON_WRAPPER -std=c++11 -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I$(PYTHON_2_7) -c Geometry.cpp -o Geometry.o
gcc -DPYTHON_WRAPPER -std=c++0x -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I$(PYTHON) -c Geometry.cpp -o Geometry.o
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security Geometry.o -lboost_python -o $(LIB_DIR)/geom.so
rm Geometry.o Geometry.cpp
#!/usr/bin/python
## known bug: tc.fill_trigger_cells() must be called once
import math, copy
import numpy as np
import collections
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as ptl
# 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 *
######## main ########
def main():
geom = Geometry()
geom.initialise()
# which layer?
layer = LAYER
# initialize and prepare screen
#pygame.init()
#screen = pygame.display.set_mode(WINSIZE)
#pygame.display.set_caption('wafer')
#screen.fill(white)
# 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_matrix_256 = Trigger_cell_matrix( cells_256 )
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_matrix_128 = Trigger_cell_matrix( cells_128 )
trigger_cells_128 = tc_matrix_128.get_trigger_cells()
print ' done.'
cell_matrix = {}
cell_matrix[256] = cell_matrix_256
cell_matrix[128] = cell_matrix_128
cell_matrix[0] = cell_matrix_256
cells = {}
cells[256] = cells_256
cells[128] = cells_128
cells[0] = cells_256
tc_matrix = {}
tc_matrix[256] = tc_matrix_256
tc_matrix[128] = tc_matrix_128
tc_matrix[0] = tc_matrix_256
trigger_cells = {}
trigger_cells[256] = trigger_cells_256
trigger_cells[128] = trigger_cells_128
trigger_cells[0] = trigger_cells_256
######################
### wafer's centers
######################
# 256 cells wafer
centers_256 = []
# 128 cells wafer centers
centers_128 = []
# test
test_center = [ [ [0, 0], 1] ]
### for wafer in range(0, geom.numberOfWafers(0)) :
### center_paul_coo = geom.waferPair(layer, wafer)
### norm_X = (math.sqrt(3)/2.)*WAFER_SIDE
### norm_Y = 1.5*WAFER_SIDE
### center = [center_paul_coo[0]*norm_X, center_paul_coo[1]*norm_Y]
###
### wafer_type = geom.waferType(layer, wafer)
### if wafer_type == 1 :
### centers_256.append( [center, wafer] )
### else :
### centers_128.append( [center, wafer] )
###
### 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 :
### wafers[wafer_type] = []
### for center,wafer_id in centers[wafer_type] :
### wafers[wafer_type].append ( Wafer( WAFER_SIDE, cell_matrix[wafer_type], tc_matrix[wafer_type], cell_side[wafer_type] ) )
### wafers[wafer_type][-1].place_wafer(center, wafer_id)
### print ' done.'
###
### ### looping to find wafer and tc neighbours
### print ' >>> Searching for neighbour wafers...'
### for wafer_type in wafers :
### for wafer_to_probe_type in wafers :
### for wafer in wafers[wafer_type] :
### for wafer_to_probe in wafers[wafer_to_probe_type] :
### wafer.add_neighbour_wafer(wafer_to_probe)
### print ' done.'
###
### ### the list of all the wafers and tc
### if PRINT_LIST :
### for wafer_type in wafers :
### for wafer in wafers[wafer_type] :
### wafer.print_list()
###
### ### drawing wafer
### w_types = []
### if DRAW_WAFER_256 :
### w_types.append(256)
### if DRAW_WAFER_128 :
### w_types.append(128)
### if DRAW_WAFER_TEST :
### w_types.append(0)
###
### for w_type in w_types :
### for wafer in wafers[w_type] :
### wafer.draw_cells(CMS_ID_ON, USER_ID_ON, TYPE_ON)
### wafer.draw_trigger_cells(TRIGGER_CELL_ID_ON)
### wafer.draw(WAFER_ID_ON)
###
### 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')
### 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.show()
# if python says run, then we should run
if __name__ == '__main__':
main()
import math, copy
import numpy as np
import collections
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
#import pygame
#from pygame.locals import *
from var import *
from hexagon import *
s3 = math.sqrt(3.)
# basic cell class
class Cell:
def __init__(self, row, column, side, wafer_type, shape=None, wafer_center=[0,0]):
self.row = row
self.col = column
self.center = [0, 0]
self.side = side
self.user_id = [0, 0]
self.wafer_type = wafer_type
self.cell_type = ''
# 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]
# 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 = 'A'
self.color = red
else :
self.cell_type = 'D'
self.color = green
else :
if ((self.user_id[1]-1)/2)%2 == 0 :
self.cell_type = 'C'
self.color = blue
else :
self.cell_type = '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])
# cell geometry
def get_type(self) :
return self.cell_type
def get_side(self) :
return self.side
def get_center(self):
return self.center
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]
# user id
def get_raw_coordinate(self) :
return [self.row, self.col]
def get_user_id(self):
return self.user_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_cms_id(self, id):
self.cms_id = id
def get_cms_id(self):
return self.cms_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_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, surface, color, font="arial", size=15):
# myfont = pygame.font.SysFont(font, size)
# label = myfont.render( str(self.cms_id) , 1, color)
# pos = [ self.corners_SC[4][0]+self.side/4, self.corners_SC[4][1]-self.side/2 ]
# surface.blit(label, pos)
# printing methods
def print_corners(self):
for i in range (0, 5):
print str(i)+' = '+str( self.corners[i] )
def title(txt) :
print ' ### ',str(txt),' ### '
def sub_title(txt) :
print '\t >>> ',str(txt)
def sub_sub_title(txt) :
print '\t\t -> ',str(txt)
def body(txt) :
print ' ',str(txt)
import math, copy
import numpy as np
import collections
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
from 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 ) :
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() == TC_CELL_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
......@@ -2,8 +2,6 @@
import math, copy
import numpy as np
import collections
import pygame
from pygame.locals import *
# matplotlib
import matplotlib.path as mplPath
......
import math, copy
import numpy as np
import collections
import pygame
from pygame.locals import *
# matplotlib
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
# my classes
from param.var import *
from com import *
from hexagon import *
# basic trigger cell class
class Trigger_cell :
def __init__(self, center_cell_1, cell_side, shape=None, shape_reduced=None, row_id=-1, col_id=-1, cms_id=-1, wafer_id=-1):
self.id = [row_id, col_id]
self.cms_id = cms_id
self.wafer_id = wafer_id
self.is_peripheral = 0
self.cell_side = cell_side
self.neighbour_tc_id = []
s3 = math.sqrt(3.)
s32 = s3/2.
s334 = (3./4.)*s3
# TC type 2
#
# /\/\
# 2||||3
# /\/\/
# 1||||4
# \/\/
#
A = [ 0. , 1. ]
B = [ 0. , 2. ]
C = [ s32 , 2.5 ]
D = [ s3 , 2. ]
E = [ 3*s32 , 2.5 ]
F = [ 2*s3 , 2. ]
G = [ 2*s3 , 1. ]
H = [ 3*s32 , 0.5 ]
I = [ 3*s32 , -0.5 ]
L = [ s3 , -1. ]
M = [ s32 , -0.5 ]
N = [ 0. , -1. ]
O = [ -s32 , -0.5 ]
P = [ -s32 , 0.5 ]
tmp = []
tmp.append(A)
tmp.append(B)
tmp.append(C)
tmp.append(D)
tmp.append(E)
tmp.append(F)
tmp.append(G)
tmp.append(H)
tmp.append(I)
tmp.append(L)
tmp.append(M)
tmp.append(N)
tmp.append(O)
tmp.append(P)
tmp = [ [ coo*self.cell_side for coo in point] for point in tmp ]
tmp = [ [ p_coo+c_coo for p_coo,c_coo in zip(point,center_cell_1)] for point in tmp ]
int_points = [ [ s32, 0.5 ], [ s3, 1. ]]
int_points = [ [ coo*self.cell_side for coo in point] for point in int_points ]
int_points = [ [ p_coo+c_coo for p_coo,c_coo in zip(point,center_cell_1)] for point in int_points ]
# consider only the corners contained in a ginven shape (wafer)
self.corners = []
if shape == None :
self.corners = tmp
else :
for point in tmp :
if shape.contains_point(point) :
self.corners.append(point)
if len(self.corners) < 14 :
for point in int_points :
if shape.contains_point(point) and not(shape_reduced.contains_point(point) ) :
self.corners.append(point)
for point in self.corners :
# define if the TC is a pheripheral cell
if shape.contains_point(point) and not(shape_reduced.contains_point(point) ) :