CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
TkAlMapDesign_phase0_cfg Namespace Reference

Functions

def read_TPLfile
 
def test_draw
 

Variables

int M_T = .2
 
int M_X = 1
 
float M_Y = 2.5
 
int PIX_D_W = 10
 
int PIX_L_H = 12
 
int PIX_L_W = 24
 
int STR_D_W = 10
 
int STR_L_H = 12
 
int STR_L_W = 24
 
float STR_TID_D_W = 5.5
 
dictionary TkMap_GEO
 

Function Documentation

def TkAlMapDesign_phase0_cfg.read_TPLfile (   file_name)

Definition at line 408 of file TkAlMapDesign_phase0_cfg.py.

References submitPVValidationJobs.split().

Referenced by test_draw().

409 def read_TPLfile(file_name):
410  o_file = open(file_name, 'r')
411  lines = o_file.readlines()
412  o_file.close()
413 
414  TPL_dict = {}
415  for line in lines:
416  if '#' in line: continue
417  splt_line = line.replace('\n', '').split(' ')
418  det_id = int(splt_line[0])
419  x = []
420  y = []
421  for idx,coo in enumerate(splt_line[1:]):
422  #print(coo)
423  try:
424  val = float(coo)
425  if (idx%2) == 0:
426  y.append(val)
427  else:
428  x.append(val)
429  except ValueError:
430  continue
431  TPL_dict[det_id] = {}
432  TPL_dict[det_id]['x'] = x
433  TPL_dict[det_id]['y'] = y
434  return TPL_dict
435 
436 
def TkAlMapDesign_phase0_cfg.test_draw (   w,
  h 
)

Definition at line 443 of file TkAlMapDesign_phase0_cfg.py.

References mps_check.array, SiStripPI.max, min(), sistrip::SpyUtilities.range(), and read_TPLfile().

444  def test_draw(w, h):
445  canvas = ROOT.TCanvas('canvas', 'detector canvas', w, h)
446 
447  # Load all modules in absolute positions
448  # Find max x and y to rescale later for window
449  all_modules = {}
450  all_text = {}
451  x_max = -9999.
452  y_max = -9999.
453  x_min = 9999.
454  y_min = 9999.
455  for det in TkMap_GEO:
456  for sub in TkMap_GEO[det]:
457  for part in TkMap_GEO[det][sub]:
458  if part == 'latex':
459  all_text[det+'_'+sub] = TkMap_GEO[det][sub][part]
460  continue
461  if 'latex' in TkMap_GEO[det][sub][part]:
462  all_text[det+'_'+sub+'_'+part] = TkMap_GEO[det][sub][part]['latex']
463  TPL_dict = read_TPLfile(TkMap_GEO[det][sub][part]['file'])
464  for module in TPL_dict:
465  x_canv = []
466  y_canv = []
467  for idx in range(len(TPL_dict[module]['x'])):
468  x_canv.append(TPL_dict[module]['x'][idx]*TkMap_GEO[det][sub][part]['x_scale'] + TkMap_GEO[det][sub][part]['x_off'])
469  y_canv.append(TPL_dict[module]['y'][idx]*TkMap_GEO[det][sub][part]['y_scale'] + TkMap_GEO[det][sub][part]['y_off'])
470  if max(x_canv) > x_max: x_max = max(x_canv)
471  if max(y_canv) > y_max: y_max = max(y_canv)
472  if min(x_canv) < x_min: x_min = min(x_canv)
473  if min(y_canv) < y_min: y_min = min(y_canv)
474  TPL_dict[module]['x'] = x_canv
475  TPL_dict[module]['y'] = y_canv
476  all_modules.update(TPL_dict)
477 
478  r_margin = 1
479  l_margin = 1
480  t_margin = 1
481  b_margin = 1
482 
483  x_max += r_margin
484  x_min -= l_margin
485  y_max += t_margin
486  y_min -= b_margin
487 
488  x_range = x_max - x_min
489  y_range = y_max - y_min
490  if (x_range + 0.)/(w + 0.) > (y_range + 0.)/(h + 0.):
491  x_scale = x_range
492  y_scale = (h + 0.)/(w + 0.)*x_range
493  else:
494  y_scale = y_range
495  x_scale = (w + 0.)/(h + 0.)*y_range
496  TPL = {}
497  for module in all_modules:
498  x = array('d', [])
499  y = array('d', [])
500  for idx in range(len(all_modules[module]['x'])):
501  x.append((all_modules[module]['x'][idx] - x_min + 0.)/(x_scale + 0.))
502  y.append((all_modules[module]['y'][idx] - y_min + 0.)/(y_scale + 0.))
503  # Begin point is end point
504  x.append((all_modules[module]['x'][0] - x_min + 0.)/(x_scale + 0.))
505  y.append((all_modules[module]['y'][0] - y_min + 0.)/(y_scale + 0.))
506  #print(x, y)
507  TPL[module] = ROOT.TPolyLine(len(x), x, y)
508  #TPL[module].SetFillColor(1)
509  TPL[module].SetLineColor(1)
510  TPL[module].Draw('f')
511  TPL[module].Draw()
512  TL = ROOT.TLatex()
513  TL.SetTextSize(0.025)
514  for key in all_text:
515  x = (all_text[key]['x'] - x_min + 0.)/(x_scale + 0.)
516  y = (all_text[key]['y'] - y_min + 0.)/(y_scale + 0.)
517  TL.SetTextAlign(all_text[key]['alignment'])
518  TL.DrawLatex(x, y, all_text[key]['text'])
519  #TL.SetTextSize(0.025)
520  #TL.SetTextAlign(11)
521  #TL.DrawLatex(0.1, 0.1, 'bottom')
522  #TL.SetTextAlign(13)
523  #TL.DrawLatex(0.1, 0.1, 'top')
524  canvas.Update()
525  raw_input('exit')
tuple array
Definition: mps_check.py:216
const uint16_t range(const Frame &aFrame)
T min(T a, T b)
Definition: MathUtil.h:58

Variable Documentation

int TkAlMapDesign_phase0_cfg.M_T = .2

Definition at line 4 of file TkAlMapDesign_phase0_cfg.py.

int TkAlMapDesign_phase0_cfg.M_X = 1

Definition at line 2 of file TkAlMapDesign_phase0_cfg.py.

float TkAlMapDesign_phase0_cfg.M_Y = 2.5

Definition at line 3 of file TkAlMapDesign_phase0_cfg.py.

int TkAlMapDesign_phase0_cfg.PIX_D_W = 10

Definition at line 6 of file TkAlMapDesign_phase0_cfg.py.

int TkAlMapDesign_phase0_cfg.PIX_L_H = 12

Definition at line 10 of file TkAlMapDesign_phase0_cfg.py.

int TkAlMapDesign_phase0_cfg.PIX_L_W = 24

Definition at line 9 of file TkAlMapDesign_phase0_cfg.py.

int TkAlMapDesign_phase0_cfg.STR_D_W = 10

Definition at line 12 of file TkAlMapDesign_phase0_cfg.py.

int TkAlMapDesign_phase0_cfg.STR_L_H = 12

Definition at line 15 of file TkAlMapDesign_phase0_cfg.py.

int TkAlMapDesign_phase0_cfg.STR_L_W = 24

Definition at line 14 of file TkAlMapDesign_phase0_cfg.py.

float TkAlMapDesign_phase0_cfg.STR_TID_D_W = 5.5

Definition at line 13 of file TkAlMapDesign_phase0_cfg.py.

dictionary TkAlMapDesign_phase0_cfg.TkMap_GEO

Definition at line 17 of file TkAlMapDesign_phase0_cfg.py.