CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
TkAlMapDesign_phase1_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 = 10
 
int PIX_L_W = 20
 
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_phase1_cfg.read_TPLfile (   file_name)

Definition at line 419 of file TkAlMapDesign_phase1_cfg.py.

References submitPVValidationJobs.split().

Referenced by test_draw().

420 def read_TPLfile(file_name):
421  o_file = open(file_name, 'r')
422  lines = o_file.readlines()
423  o_file.close()
424 
425  TPL_dict = {}
426  for line in lines:
427  if '#' in line: continue
428  splt_line = line.replace('\n', '').split(' ')
429  det_id = int(splt_line[0])
430  x = []
431  y = []
432  for idx,coo in enumerate(splt_line[1:]):
433  #print(coo)
434  try:
435  val = float(coo)
436  if (idx%2) == 0:
437  y.append(val)
438  else:
439  x.append(val)
440  except ValueError:
441  continue
442  TPL_dict[det_id] = {}
443  TPL_dict[det_id]['x'] = x
444  TPL_dict[det_id]['y'] = y
445  return TPL_dict
446 
447 
def TkAlMapDesign_phase1_cfg.test_draw (   w,
  h 
)

Definition at line 454 of file TkAlMapDesign_phase1_cfg.py.

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

455  def test_draw(w, h):
456  canvas = ROOT.TCanvas('canvas', 'detector canvas', w, h)
457 
458  # Load all modules in absolute positions
459  # Find max x and y to rescale later for window
460  all_modules = {}
461  all_text = {}
462  x_max = -9999.
463  y_max = -9999.
464  x_min = 9999.
465  y_min = 9999.
466  for det in TkMap_GEO:
467  for sub in TkMap_GEO[det]:
468  for part in TkMap_GEO[det][sub]:
469  if part == 'latex':
470  all_text[det+'_'+sub] = TkMap_GEO[det][sub][part]
471  continue
472  if 'latex' in TkMap_GEO[det][sub][part]:
473  all_text[det+'_'+sub+'_'+part] = TkMap_GEO[det][sub][part]['latex']
474  TPL_dict = read_TPLfile(TkMap_GEO[det][sub][part]['file'])
475  for module in TPL_dict:
476  x_canv = []
477  y_canv = []
478  for idx in range(len(TPL_dict[module]['x'])):
479  x_canv.append(TPL_dict[module]['x'][idx]*TkMap_GEO[det][sub][part]['x_scale'] + TkMap_GEO[det][sub][part]['x_off'])
480  y_canv.append(TPL_dict[module]['y'][idx]*TkMap_GEO[det][sub][part]['y_scale'] + TkMap_GEO[det][sub][part]['y_off'])
481  if max(x_canv) > x_max: x_max = max(x_canv)
482  if max(y_canv) > y_max: y_max = max(y_canv)
483  if min(x_canv) < x_min: x_min = min(x_canv)
484  if min(y_canv) < y_min: y_min = min(y_canv)
485  TPL_dict[module]['x'] = x_canv
486  TPL_dict[module]['y'] = y_canv
487  all_modules.update(TPL_dict)
488 
489  r_margin = 1
490  l_margin = 1
491  t_margin = 1
492  b_margin = 1
493 
494  x_max += r_margin
495  x_min -= l_margin
496  y_max += t_margin
497  y_min -= b_margin
498 
499  x_range = x_max - x_min
500  y_range = y_max - y_min
501  if (x_range + 0.)/(w + 0.) > (y_range + 0.)/(h + 0.):
502  x_scale = x_range
503  y_scale = (h + 0.)/(w + 0.)*x_range
504  else:
505  y_scale = y_range
506  x_scale = (w + 0.)/(h + 0.)*y_range
507  TPL = {}
508  for module in all_modules:
509  x = array('d', [])
510  y = array('d', [])
511  for idx in range(len(all_modules[module]['x'])):
512  x.append((all_modules[module]['x'][idx] - x_min + 0.)/(x_scale + 0.))
513  y.append((all_modules[module]['y'][idx] - y_min + 0.)/(y_scale + 0.))
514  # Begin point is end point
515  x.append((all_modules[module]['x'][0] - x_min + 0.)/(x_scale + 0.))
516  y.append((all_modules[module]['y'][0] - y_min + 0.)/(y_scale + 0.))
517  #print(x, y)
518  TPL[module] = ROOT.TPolyLine(len(x), x, y)
519  #TPL[module].SetFillColor(1)
520  TPL[module].SetLineColor(1)
521  TPL[module].Draw('f')
522  TPL[module].Draw()
523  TL = ROOT.TLatex()
524  TL.SetTextSize(0.025)
525  for key in all_text:
526  x = (all_text[key]['x'] - x_min + 0.)/(x_scale + 0.)
527  y = (all_text[key]['y'] - y_min + 0.)/(y_scale + 0.)
528  TL.SetTextAlign(all_text[key]['alignment'])
529  TL.DrawLatex(x, y, all_text[key]['text'])
530  #TL.SetTextSize(0.025)
531  #TL.SetTextAlign(11)
532  #TL.DrawLatex(0.1, 0.1, 'bottom')
533  #TL.SetTextAlign(13)
534  #TL.DrawLatex(0.1, 0.1, 'top')
535  canvas.Update()
536  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_phase1_cfg.M_T = .2

Definition at line 4 of file TkAlMapDesign_phase1_cfg.py.

int TkAlMapDesign_phase1_cfg.M_X = 1

Definition at line 2 of file TkAlMapDesign_phase1_cfg.py.

float TkAlMapDesign_phase1_cfg.M_Y = 2.5

Definition at line 3 of file TkAlMapDesign_phase1_cfg.py.

int TkAlMapDesign_phase1_cfg.PIX_D_W = 10

Definition at line 6 of file TkAlMapDesign_phase1_cfg.py.

int TkAlMapDesign_phase1_cfg.PIX_L_H = 10

Definition at line 8 of file TkAlMapDesign_phase1_cfg.py.

int TkAlMapDesign_phase1_cfg.PIX_L_W = 20

Definition at line 7 of file TkAlMapDesign_phase1_cfg.py.

int TkAlMapDesign_phase1_cfg.STR_D_W = 10

Definition at line 10 of file TkAlMapDesign_phase1_cfg.py.

int TkAlMapDesign_phase1_cfg.STR_L_H = 12

Definition at line 13 of file TkAlMapDesign_phase1_cfg.py.

int TkAlMapDesign_phase1_cfg.STR_L_W = 24

Definition at line 12 of file TkAlMapDesign_phase1_cfg.py.

float TkAlMapDesign_phase1_cfg.STR_TID_D_W = 5.5

Definition at line 11 of file TkAlMapDesign_phase1_cfg.py.

dictionary TkAlMapDesign_phase1_cfg.TkMap_GEO

Definition at line 15 of file TkAlMapDesign_phase1_cfg.py.