Commit 9540d99a authored by vpalladi's avatar vpalladi

All new GUI

parent ed31bd1f
#!/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 classes.coo import *
# geometry from Paul
from Geometry.geom import *
######## main ########
def main():
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
#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 )
# trigger_cells_128 = {}
# trigger_cells_128[0] = tc_matrix_128[0].get_trigger_cells()
# trigger_cells_128[1] = tc_matrix_128[1].get_trigger_cells()
# trigger_cells_128[2] = tc_matrix_128[2].get_trigger_cells()
# trigger_cells_128[3] = tc_matrix_128[3].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_matrices = {}
tc_matrices[256] = tc_matrices_256
tc_matrices[128] = tc_matrices_128
tc_matrices[0] = tc_matrices_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, [0, 0] ] ]
for wafer in range(0, geom.numberOfWafers(layer)) :
# center_paul_coo = geom.waferPair(layer, wafer) # this are intergers
# 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]
### 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.'
### the list of all the wafers and tc
### save the list of all the wafers and tc
if PRINT_LIST :
### 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.'
### store results in a file
fileOut = open('layer_'+str(layer)+'.txt', 'w')
for wafer_type in wafers :
for wafer in wafers[wafer_type] :
wafer_must_print = 0
if wafer_type == 0 :
wafer_must_print = 1
if len(PICK_WAFER) != 0:
if wafer.get_id() in PICK_WAFER :
wafer_must_print = 1
else :
wafer_must_print = 1
if wafer_must_print == 1 :
wafer.print_list(fileOut, geom)
fileOut.close()
### 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)
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 :
wafer.draw_trigger_cells(TRIGGER_CELL_ID_ON, TRIGGER_CELL_NORM_ID_ON)
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()
# if python says run, then we should run
if __name__ == '__main__':
main()
#!/usr/bin/python
import sys
import os
sys.path.append('/opt/root/5.34.36/lib')
import math
import ROOT
from modules.cell import Cell
from modules.points import *
from Geometry.geom import *
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
import matplotlib.figure as pfig
inputNtuple = ROOT.TFile.Open("./test_triggergeom.root")
tree = inputNtuple.Get("hgcaltriggergeomtester/TreeCells")
# loop over the ttree ntries
cells = []
geom = Geometry()
WAFER_SIDE = geom.waferWidth()/math.sqrt(3.0)
WAFER_WIDTH = geom.waferWidth()
for ientry, entry in enumerate(tree):
if ientry%1000 == 0 :
print ientry
tc_id = entry.id
zside = entry.zside
subdet = entry.subdet
layer = entry.layer
wafer = entry.wafer
wafertype = entry.wafertype
waferrow = entry.waferrow
wafercolumn = entry.wafercolumn
cell = entry.cell
x = entry.x
y = entry.y
z = entry.z
x1 = entry.x1
y1 = entry.y1
x2 = entry.x2
y2 = entry.y2
x3 = entry.x3
y3 = entry.y3
x4 = entry.x4
y4 = entry.y4
# print ientry,'###',tc_id_,zside_,subdet_,layer_,wafer_,wafertype_ #etc, etc
if layer == 1 :
side = 0.
if wafertype==-1 :
#side = WAFER_WIDTH/20
side = math.sqrt( 2.*1.06 / (3.*math.sqrt(3.) ) )
else :
#side = WAFER_WIDTH/20
side = math.sqrt( 2.*0.56 / (3.*math.sqrt(3.) ) )
cells.append( Cell( side=side, centre=Point2D(x,y)) )
if layer > 1 :
print 'done.'
break
fig = plt.figure('Test', figsize=(17,17) )
for cell in cells :
cell.draw()
plt.ylim([-200, 200])
plt.xlim([-200, 200])
plt.show()
......@@ -2,20 +2,18 @@
import math, copy
#import numpy as np
import collections
import random
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
#import pygame
#from pygame.locals import *
# modules
from param.var import *
from shapes import *
from points import *
from data_types import *
from modules.seedButton import *
from mp7 import *
from matplotlib.widgets import Button
......@@ -24,7 +22,7 @@ s3 = math.sqrt(3.)
# basic cell class
class BaseCell:
def __init__( self, side=1, centre=Point2D(0,0), rotation_rad=0.0, mirror=0, cell_id=HGCid(), cmssw_id=-1, energy=-1 ):
def __init__( self, side=1, centre=Point2D(0,0), rotation_rad=0.0, mirror=0, cell_id=HGCid(), cmssw_id=-1, energy=-1, seedTh=5, minTh_mipT=2 ):
# geom attributes
self.centre = centre
......@@ -44,12 +42,24 @@ class BaseCell:
# status and energy
self.energy = energy
self.seedTh = seedTh
self.minTh_mipT = minTh_mipT
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'
# set methods
def set_energy( self, energy ) :
self.energy = energy
if energy >= self.seedTh :
self.status = 'seed'
elif energy < self.seedTh and energy >= self.minTh_mipT :
self.status = 'hit'
else :
self.status = 'none'
# get methods
def get_side( self ) :
return self.side
......@@ -96,10 +106,28 @@ class BaseCell:
# drawing
def draw(self, linestyle='dotted', linewidth=0.5) :
self.shape.draw(linestyle=linestyle, linewidth=linewidth, fill=0)
if self.status == 'seed' :
self.draw_seed()
if self.status == 'hit' :
self.draw_hit()
if self.status == 'none' :
self.draw_none()
def draw_id(self):
self.cell_id.draw( self.centre )
def draw_seed( self ) :
self.shape.poly.set_facecolor( yellow )
self.shape.poly.set_fill(1)
def draw_hit( self ) :
self.shape.poly.set_facecolor( blue )
self.shape.poly.set_fill(1)
def draw_none( self ) :
self.shape.poly.set_fill(0)
# def draw_cmssw_id(self) :
# plt.text( self.centre.x, self.centre.x, str(self.cmssw_cell_id),
# size=10,
......@@ -107,22 +135,26 @@ class BaseCell:
# verticalalignment='centre',)
# GUI
def set_seed(self) :
def set_seed(self, energy=-1) :
self.status = 'seed'
self.shape.poly.set_facecolor( yellow )
self.shape.poly.set_fill(1)
def set_hit(self) :
self.draw_seed()
self.energy = random.uniform(self.seedTh, 255)
def set_hit(self, energy=-1) :
self.status = 'hit'
self.shape.poly.set_facecolor( blue )
self.shape.poly.set_fill(1)
self.draw_hit()
self.energy = random.uniform( self.minTh_mipT, self.seedTh-1 )
def set_none(self) :
self.status = 'none'
self.shape.poly.set_fill(0)
self.energy = 0
# printing methods
def get_mp7_word( self ) :
w = HGCwordMP7( 0, int(self.energy), 0, self.cell_id.get_row(), self.cell_id.get_col() )
return w
class Cell(BaseCell):
......
......@@ -5,16 +5,25 @@ from points import *
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 __str__( self ) :
return '['+str(self.row)+','+str(self.col)+']'
def __eq__( self, other ) :
if self.row == other.row and self.col == other.col :
return True
return False
def get_row( self ) :
return row
return self.row
def get_col( self ) :
return col
return self.col
def draw( self, centre=Point2D(0, 0) ) :
id_string = str(self.row)+'-'+str(self.col)
......@@ -22,3 +31,74 @@ class HGCid :
size=7,
horizontalalignment='center',
verticalalignment='center')
class HGCwordMP7 :
# 28 24 20 16 12 8 4 0
# v 0000 0000 0000 000e eeee eeew wwrr rccc
# 0-2 col(c) 3-5 row(r) 6-8 wafer(w) 9-16 energy(e)
# v valid
def __init__( self, valid=0, energy=0, wafer=0, row=0, col=0, soe_word=False, eoe_word=False ) :
self.valid = valid # 1b
self.energy = energy # 8b
self.wafer = wafer # 3b
self.hgc_id = HGCid(row, col) # 3b + 3b
self.is_soe_word = soe_word
self.is_eoe_word = eoe_word
if self.is_soe_word or self.is_eoe_word :
self.valid = 0 # 1b
def __str__( self ) :
return self.get_32b_hex_string()
def set_hex_string( self, str_word ) :
if str_word == '0vbcbcbcbc' or str_word == '0vfbfbfbfb' :
self.valid = 0
self.energy = 0
self.wafer = 0
self.hgc_id.row = 0
self.hgc_id.col = 0
else :
l = str_word.split('v')
self.valid = int(l[0])
w = int(l[1], 16)
self.energy = (w>>9) & 0x1ff
self.wafer = (w>>6) & 0x7
self.hgc_id.row = (w>>3) & 0x7
self.hgc_id.col = w & 0x7
if str_word == '0vbcbcbcbc' :
self.is_soe_word = False
self.is_eoe_word = True
if str_word == '0vfbfbfbfb' :
self.is_soe_word = True
self.is_eoe_word = False
def get_32b_hex_string( self ) :
string_out = ''
if self.is_eoe_word :
string_out = '0vbcbcbcbc'
elif self.is_soe_word :
string_out = '0vfbfbfbfb'
else :
out = 0
out = out | ( (self.energy<<9) & 0x1fe00 )
out = out | ( (self.wafer<<6) & 0x1c0 )
out = out | ( (self.hgc_id.row<<3) & 0x38 )
out = out | ( (self.hgc_id.col) & 0x7 )
string_out = str(self.valid).zfill(1)+'v'+format(out, '08X')
return string_out
#import numpy as np
import collections
# matlibplot
import matplotlib.path as mplPath
import matplotlib.pyplot as plt
# data types
from data_types import HGCwordMP7
class MP7 :
nChannels = 72
def __init__( self ) :
self.data_32b = []
self.nEvents = 0
for i in range(0, self.nChannels) :
self.data_32b.append( [] )
self.add_zeros()
def load_file( self, file_name ) :
f = open(file_name, 'r')
f.readline() # board type
f.readline() # quadrants
f.readline() # links
lines = f.readlines()
for line in lines :
#line = line[14:]