CMS 3D CMS Logo

Functions | Variables
TkAlMapDesign_phase0_cfg Namespace Reference

Functions

def read_TPLfile (file_name)
 
def test_draw (w, h)
 

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 objects.autophobj.float, createfilelist.int, and split.

Referenced by test_draw().

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

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