Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:00

0001 
0002 M_X = 1.
0003 M_Y = 2.5
0004 M_T = .2
0005 
0006 PIX_D_W = 10.
0007 PIX_L_W = 20.
0008 PIX_L_H = 10.
0009 
0010 STR_D_W = 10.
0011 STR_TID_D_W = 5.5
0012 STR_L_W = 24.
0013 STR_L_H = 12.
0014 
0015 TkMap_GEO = {
0016     'pixel' : {
0017         'BPIX': {
0018             'L1': {
0019                 'file': 'Relative_TPolyLine_Pixel_phase1_BPIX_L1.txt',
0020                 'x_off': -2*PIX_L_W - 2*M_X,
0021                 'y_off': -PIX_L_H, 
0022                 'x_scale': PIX_L_W,
0023                 'y_scale': PIX_L_H,
0024             },
0025             'L2': {
0026                 'file': 'Relative_TPolyLine_Pixel_phase1_BPIX_L2.txt',
0027                 'x_off': -PIX_L_W - M_X,
0028                 'y_off': -PIX_L_H, 
0029                 'x_scale': PIX_L_W,
0030                 'y_scale': PIX_L_H,
0031             },
0032             'L3': {
0033                 'file': 'Relative_TPolyLine_Pixel_phase1_BPIX_L3.txt',
0034                 'x_off': -2*PIX_L_W - 2*M_X,
0035                 'y_off': M_Y,
0036                 'x_scale': PIX_L_W,
0037                 'y_scale': PIX_L_H,
0038             },
0039             'L4': {
0040                 'file': 'Relative_TPolyLine_Pixel_phase1_BPIX_L4.txt',
0041                 'x_off': -PIX_L_W - M_X,
0042                 'y_off': M_Y,
0043                 'x_scale': PIX_L_W,
0044                 'y_scale': PIX_L_H,
0045             },
0046         },
0047         'FPIX-': {
0048             '-1': {
0049                 'file': 'Relative_TPolyLine_Pixel_phase1_FPIX_-1.txt',
0050                 'x_off': -2*PIX_L_W - 2*M_X,
0051                 'y_off': -PIX_L_H - M_Y - PIX_D_W, 
0052                 'x_scale': PIX_D_W,
0053                 'y_scale': PIX_D_W,
0054             },
0055             '-2': {
0056                 'file': 'Relative_TPolyLine_Pixel_phase1_FPIX_-2.txt',
0057                 'x_off': -PIX_L_W - M_X - PIX_L_W/4. - M_X/2.,
0058                 'y_off': -PIX_L_H - M_Y - PIX_D_W, 
0059                 'x_scale': PIX_D_W,
0060                 'y_scale': PIX_D_W,
0061             },
0062             '-3': {
0063                 'file': 'Relative_TPolyLine_Pixel_phase1_FPIX_-3.txt',
0064                 'x_off': -PIX_D_W - M_X,
0065                 'y_off': -PIX_L_H - M_Y - PIX_D_W, 
0066                 'x_scale': PIX_D_W,
0067                 'y_scale': PIX_D_W,
0068             },
0069         },
0070         'FPIX+': {
0071             '+1': {
0072                 'file': 'Relative_TPolyLine_Pixel_phase1_FPIX_+1.txt',
0073                 'x_off': -2*PIX_L_W - 2*M_X,
0074                 'y_off': PIX_L_H + 2*M_Y, 
0075                 'x_scale': PIX_D_W,
0076                 'y_scale': PIX_D_W,
0077             },
0078             '+2': {
0079                 'file': 'Relative_TPolyLine_Pixel_phase1_FPIX_+2.txt',
0080                 'x_off': -PIX_L_W - M_X - PIX_L_W/4. - M_X/2.,
0081                 'y_off': PIX_L_H + 2*M_Y, 
0082                 'x_scale': PIX_D_W,
0083                 'y_scale': PIX_D_W,
0084             },
0085             '+3': {
0086                 'file': 'Relative_TPolyLine_Pixel_phase1_FPIX_+3.txt',
0087                 'x_off': -PIX_D_W- M_X,
0088                 'y_off': PIX_L_H + 2*M_Y, 
0089                 'x_scale': PIX_D_W,
0090                 'y_scale': PIX_D_W,
0091             },
0092         }, 
0093     },
0094     'strips': {
0095         'TIB': {
0096             'L1': {
0097                 'file': 'Relative_TPolyLine_Strips_TIB_L1.txt',
0098                 'x_off': M_X,
0099                 'y_off': -STR_L_H,
0100                 'x_scale': STR_L_W,
0101                 'y_scale': STR_L_H,
0102             },
0103             'L2': {
0104                 'file': 'Relative_TPolyLine_Strips_TIB_L2.txt',
0105                 'x_off': 2*M_X + STR_L_W,
0106                 'y_off': -STR_L_H,
0107                 'x_scale': STR_L_W,
0108                 'y_scale': STR_L_H,
0109             },
0110             'L3': {
0111                 'file': 'Relative_TPolyLine_Strips_TIB_L3.txt',
0112                 'x_off': M_X,
0113                 'y_off': M_Y,
0114                 'x_scale': STR_L_W,
0115                 'y_scale': STR_L_H,
0116             },
0117             'L4': {
0118                 'file': 'Relative_TPolyLine_Strips_TIB_L4.txt',
0119                 'x_off': 2*M_X + STR_L_W,
0120                 'y_off': M_Y,
0121                 'x_scale': STR_L_W,
0122                 'y_scale': STR_L_H,
0123             },
0124         },
0125         'TOB': {
0126             'L1': {
0127                 'file': 'Relative_TPolyLine_Strips_TOB_L1.txt',
0128                 'x_off': 3*M_X + 2*STR_L_W,
0129                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2.,
0130                 'x_scale': STR_L_W,
0131                 'y_scale': STR_L_H,
0132             },
0133             'L2': {
0134                 'file': 'Relative_TPolyLine_Strips_TOB_L2.txt',
0135                 'x_off': 4*M_X + 3*STR_L_W,
0136                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2.,
0137                 'x_scale': STR_L_W,
0138                 'y_scale': STR_L_H,
0139             },
0140             'L3': {
0141                 'file': 'Relative_TPolyLine_Strips_TOB_L3.txt',
0142                 'x_off': 3*M_X + 2*STR_L_W,
0143                 'y_off': - STR_L_H/2. + M_Y/2.,
0144                 'x_scale': STR_L_W,
0145                 'y_scale': STR_L_H,
0146             },
0147             'L4': {
0148                 'file': 'Relative_TPolyLine_Strips_TOB_L4.txt',
0149                 'x_off': 4*M_X + 3*STR_L_W,
0150                 'y_off': - STR_L_H/2. + M_Y/2.,
0151                 'x_scale': STR_L_W,
0152                 'y_scale': STR_L_H,
0153             },
0154             'L5': {
0155                 'file': 'Relative_TPolyLine_Strips_TOB_L5.txt',
0156                 'x_off': 3*M_X + 2*STR_L_W,
0157                 'y_off': STR_L_H/2. + M_Y + M_Y/2.,
0158                 'x_scale': STR_L_W,
0159                 'y_scale': STR_L_H,
0160             },
0161             'L6': {
0162                 'file': 'Relative_TPolyLine_Strips_TOB_L6.txt',
0163                 'x_off': 4*M_X + 3*STR_L_W,
0164                 'y_off': STR_L_H/2. + M_Y + M_Y/2.,
0165                 'x_scale': STR_L_W,
0166                 'y_scale': STR_L_H,
0167             },
0168         },
0169         'TID-': {
0170             '-1': {
0171                 'file': 'Relative_TPolyLine_Strips_TID_-1.txt',
0172                 'x_off': M_X + (STR_L_W + M_X)/2.,
0173                 'y_off': - STR_L_H - M_Y - STR_TID_D_W,
0174                 'x_scale': STR_TID_D_W,
0175                 'y_scale': STR_TID_D_W,
0176             },
0177             '-2': {
0178                 'file': 'Relative_TPolyLine_Strips_TID_-2.txt',
0179                 'x_off': M_X + STR_L_W/2. - STR_TID_D_W/2. + (STR_L_W + M_X)/2.,
0180                 'y_off': - STR_L_H - M_Y - STR_TID_D_W,
0181                 'x_scale': STR_TID_D_W,
0182                 'y_scale': STR_TID_D_W,
0183             },
0184             '-3': {
0185                 'file': 'Relative_TPolyLine_Strips_TID_-3.txt',
0186                 'x_off': M_X + STR_L_W - STR_TID_D_W + (STR_L_W + M_X)/2.,
0187                 'y_off': - STR_L_H - M_Y - STR_TID_D_W,
0188                 'x_scale': STR_TID_D_W,
0189                 'y_scale': STR_TID_D_W,
0190             },
0191         },
0192         'TID+': {
0193             '+1': {
0194                 'file': 'Relative_TPolyLine_Strips_TID_+1.txt',
0195                 'x_off': M_X + (STR_L_W + M_X)/2.,
0196                 'y_off': STR_L_H +2*M_Y,
0197                 'x_scale': STR_TID_D_W,
0198                 'y_scale': STR_TID_D_W,
0199             },
0200             '+2': {
0201                 'file': 'Relative_TPolyLine_Strips_TID_+2.txt',
0202                 'x_off': M_X + STR_L_W/2. - STR_TID_D_W/2. + (STR_L_W + M_X)/2.,
0203                 'y_off': STR_L_H +2*M_Y,
0204                 'x_scale': STR_TID_D_W,
0205                 'y_scale': STR_TID_D_W,
0206             },
0207             '+3': {
0208                 'file': 'Relative_TPolyLine_Strips_TID_+3.txt',
0209                 'x_off': M_X + STR_L_W - STR_TID_D_W + (STR_L_W + M_X)/2.,
0210                 'y_off': STR_L_H +2*M_Y,
0211                 'x_scale': STR_TID_D_W,
0212                 'y_scale': STR_TID_D_W,
0213             },
0214         },
0215         'TEC-': {
0216             '-1': {
0217                 'file': 'Relative_TPolyLine_Strips_TEC_-1.txt',
0218                 'x_off': M_X,
0219                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0220                 'x_scale': STR_D_W,
0221                 'y_scale': STR_D_W,
0222             },
0223             '-2': {
0224                 'file': 'Relative_TPolyLine_Strips_TEC_-2.txt',
0225                 'x_off': M_X +((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0226                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0227                 'x_scale': STR_D_W,
0228                 'y_scale': STR_D_W,
0229             },
0230             '-3': {
0231                 'file': 'Relative_TPolyLine_Strips_TEC_-3.txt',
0232                 'x_off': M_X + 2*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0233                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0234                 'x_scale': STR_D_W,
0235                 'y_scale': STR_D_W,
0236             },
0237             '-4': {
0238                 'file': 'Relative_TPolyLine_Strips_TEC_-4.txt',
0239                 'x_off': M_X + 3*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0240                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0241                 'x_scale': STR_D_W,
0242                 'y_scale': STR_D_W,
0243             },
0244             '-5': {
0245                 'file': 'Relative_TPolyLine_Strips_TEC_-5.txt',
0246                 'x_off': M_X + 4*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0247                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0248                 'x_scale': STR_D_W,
0249                 'y_scale': STR_D_W,
0250             },
0251             '-6': {
0252                 'file': 'Relative_TPolyLine_Strips_TEC_-6.txt',
0253                 'x_off': M_X + 5*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0254                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0255                 'x_scale': STR_D_W,
0256                 'y_scale': STR_D_W,
0257             },
0258             '-7': {
0259                 'file': 'Relative_TPolyLine_Strips_TEC_-7.txt',
0260                 'x_off': M_X + 6*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0261                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0262                 'x_scale': STR_D_W,
0263                 'y_scale': STR_D_W,
0264             },
0265             '-8': {
0266                 'file': 'Relative_TPolyLine_Strips_TEC_-8.txt',
0267                 'x_off': M_X + 7*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0268                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0269                 'x_scale': STR_D_W,
0270                 'y_scale': STR_D_W,
0271             },
0272             '-9': {
0273                 'file': 'Relative_TPolyLine_Strips_TEC_-9.txt',
0274                 'x_off': M_X + 8*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0275                 'y_off': -STR_L_H - M_Y - STR_L_H/2. + M_Y/2. - M_Y - STR_D_W,
0276                 'x_scale': STR_D_W,
0277                 'y_scale': STR_D_W,
0278             },
0279         },
0280         'TEC+': {
0281             '+1': {
0282                 'file': 'Relative_TPolyLine_Strips_TEC_+1.txt',
0283                 'x_off': M_X,
0284                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0285                 'x_scale': STR_D_W,
0286                 'y_scale': STR_D_W,
0287             },
0288             '+2': {
0289                 'file': 'Relative_TPolyLine_Strips_TEC_+2.txt',
0290                 'x_off': M_X + ((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0291                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0292                 'x_scale': STR_D_W,
0293                 'y_scale': STR_D_W,
0294             },
0295             '+3': {
0296                 'file': 'Relative_TPolyLine_Strips_TEC_+3.txt',
0297                 'x_off': M_X + 2*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0298                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0299                 'x_scale': STR_D_W,
0300                 'y_scale': STR_D_W,
0301             },
0302             '+4': {
0303                 'file': 'Relative_TPolyLine_Strips_TEC_+4.txt',
0304                 'x_off': M_X + 3*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0305                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0306                 'x_scale': STR_D_W,
0307                 'y_scale': STR_D_W,
0308             },
0309             '+5': {
0310                 'file': 'Relative_TPolyLine_Strips_TEC_+5.txt',
0311                 'x_off': M_X + 4*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0312                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0313                 'x_scale': STR_D_W,
0314                 'y_scale': STR_D_W,
0315             },
0316             '+6': {
0317                 'file': 'Relative_TPolyLine_Strips_TEC_+6.txt',
0318                 'x_off': M_X + 5*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0319                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0320                 'x_scale': STR_D_W,
0321                 'y_scale': STR_D_W,
0322             },
0323             '+7': {
0324                 'file': 'Relative_TPolyLine_Strips_TEC_+7.txt',
0325                 'x_off': M_X + 6*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0326                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0327                 'x_scale': STR_D_W,
0328                 'y_scale': STR_D_W,
0329             },
0330             '+8': {
0331                 'file': 'Relative_TPolyLine_Strips_TEC_+8.txt',
0332                 'x_off': M_X + 7*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0333                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0334                 'x_scale': STR_D_W,
0335                 'y_scale': STR_D_W,
0336             },
0337             '+9': {
0338                 'file': 'Relative_TPolyLine_Strips_TEC_+9.txt',
0339                 'x_off': M_X + 8*((4*STR_L_W + 3*M_X - 9*STR_D_W)/8. + STR_D_W),
0340                 'y_off': STR_L_H + STR_L_H/2. + M_Y/2. + 2*M_Y,
0341                 'x_scale': STR_D_W,
0342                 'y_scale': STR_D_W,
0343             },
0344         },
0345     },
0346 }
0347 
0348 # Add text
0349 for layer in TkMap_GEO['pixel']['BPIX']:
0350     TkMap_GEO['pixel']['BPIX'][layer]['latex'] = {
0351         'text': 'BPIX '+layer,
0352         'x': TkMap_GEO['pixel']['BPIX'][layer]['x_off'],
0353         'y': TkMap_GEO['pixel']['BPIX'][layer]['y_off'] + PIX_L_H + M_T,
0354         'alignment': 11,
0355     }
0356 
0357 for z in ['-', '+']:
0358     TkMap_GEO['pixel']['FPIX'+z]['latex'] = {
0359         'text': 'FPIX',
0360         'x': TkMap_GEO['pixel']['FPIX'+z][z+'1']['x_off'],
0361         'y': TkMap_GEO['pixel']['FPIX'+z][z+'1']['y_off'] + PIX_D_W + M_T,
0362         'alignment': 11,
0363     }
0364     for disc in TkMap_GEO['pixel']['FPIX'+z]:
0365         if disc == 'latex': continue
0366         TkMap_GEO['pixel']['FPIX'+z][disc]['latex'] = {
0367             'text': disc,
0368             'x': TkMap_GEO['pixel']['FPIX'+z][disc]['x_off'] + PIX_D_W,
0369             'y': TkMap_GEO['pixel']['FPIX'+z][disc]['y_off'] + PIX_D_W,
0370             #'alignment': 33,
0371             'alignment': 23,
0372         }
0373 for det in ['TIB', 'TOB']:
0374     for layer in TkMap_GEO['strips'][det]:
0375         TkMap_GEO['strips'][det][layer]['latex'] = {
0376             'text': det+' '+layer,
0377             'x': TkMap_GEO['strips'][det][layer]['x_off'],
0378             'y': TkMap_GEO['strips'][det][layer]['y_off'] + STR_L_H + M_T,
0379             'alignment': 11,
0380         }
0381 
0382 for z in ['-', '+']:
0383     TkMap_GEO['strips']['TEC'+z]['latex'] = {
0384         'text': 'TEC',
0385         'x': TkMap_GEO['strips']['TEC'+z][z+'1']['x_off'],
0386         'y': TkMap_GEO['strips']['TEC'+z][z+'1']['y_off'] + STR_D_W + M_T,
0387         'alignment': 11,
0388     }
0389     for disc in TkMap_GEO['strips']['TEC'+z]:
0390         if disc == 'latex': continue
0391         TkMap_GEO['strips']['TEC'+z][disc]['latex'] = {
0392             'text': disc,
0393             'x': TkMap_GEO['strips']['TEC'+z][disc]['x_off'] + STR_D_W,
0394             'y': TkMap_GEO['strips']['TEC'+z][disc]['y_off'] + STR_D_W,
0395             #'alignment': 33,
0396             'alignment': 23,
0397         }
0398 
0399 # TID
0400 for z in ['-', '+']:
0401     TkMap_GEO['strips']['TID'+z]['latex'] = {
0402         'text': 'TID',
0403         #'x': TkMap_GEO['strips']['TID'+z][z+'1']['x_off'],
0404         'x': TkMap_GEO['strips']['TID'+z][z+'1']['x_off'] - 2*M_T,
0405         #'y': TkMap_GEO['strips']['TID'+z][z+'1']['y_off'] + STR_TID_D_W + M_T,
0406         'y': TkMap_GEO['strips']['TID'+z][z+'1']['y_off'] + STR_TID_D_W/2.,
0407         #'alignment': 11,
0408         'alignment': 32,
0409     }
0410     for disc in TkMap_GEO['strips']['TID'+z]:
0411         if disc == 'latex': continue
0412         TkMap_GEO['strips']['TID'+z][disc]['latex'] = {
0413             'text': disc,
0414             'x': TkMap_GEO['strips']['TID'+z][disc]['x_off'] + STR_TID_D_W,
0415             'y': TkMap_GEO['strips']['TID'+z][disc]['y_off'] + STR_TID_D_W,
0416             'alignment': 13,
0417         }
0418 
0419 def read_TPLfile(file_name):
0420     o_file = open(file_name, 'r')
0421     lines = o_file.readlines()
0422     o_file.close()
0423 
0424     TPL_dict = {}
0425     for line in lines:
0426         if '#' in line: continue
0427         splt_line = line.replace('\n', '').split(' ')
0428         det_id = int(splt_line[0])
0429         x = []
0430         y = []
0431         for idx,coo in enumerate(splt_line[1:]):
0432             #print(coo)
0433             try:
0434                 val = float(coo)
0435                 if (idx%2) == 0: 
0436                     y.append(val)
0437                 else: 
0438                     x.append(val)
0439             except ValueError:
0440                 continue
0441         TPL_dict[det_id] = {}
0442         TPL_dict[det_id]['x'] = x
0443         TPL_dict[det_id]['y'] = y
0444     return TPL_dict
0445         
0446     
0447 
0448 if __name__ == '__main__':
0449     import ROOT
0450     from array import array
0451     #TPL_dict = read_TPLfile('Relative_TPolyLine_Pixel_phase1_BPIX_L1.txt')
0452     #print(TPL_dict)
0453 
0454     def test_draw(w, h):
0455         canvas = ROOT.TCanvas('canvas', 'detector canvas', w, h)
0456         
0457         # Load all modules in absolute positions
0458         # Find max x and y to rescale later for window
0459         all_modules = {}
0460         all_text = {}
0461         x_max = -9999.
0462         y_max = -9999.
0463         x_min = 9999.
0464         y_min = 9999.
0465         for det in TkMap_GEO:
0466             for sub in TkMap_GEO[det]:
0467                 for part in TkMap_GEO[det][sub]:
0468                     if part == 'latex':
0469                         all_text[det+'_'+sub] = TkMap_GEO[det][sub][part]
0470                         continue
0471                     if 'latex' in TkMap_GEO[det][sub][part]:
0472                         all_text[det+'_'+sub+'_'+part] = TkMap_GEO[det][sub][part]['latex']
0473                     TPL_dict = read_TPLfile(TkMap_GEO[det][sub][part]['file'])
0474                     for module in TPL_dict:
0475                         x_canv = []
0476                         y_canv = []
0477                         for idx in range(len(TPL_dict[module]['x'])):
0478                             x_canv.append(TPL_dict[module]['x'][idx]*TkMap_GEO[det][sub][part]['x_scale'] + TkMap_GEO[det][sub][part]['x_off'])
0479                             y_canv.append(TPL_dict[module]['y'][idx]*TkMap_GEO[det][sub][part]['y_scale'] + TkMap_GEO[det][sub][part]['y_off'])
0480                         if max(x_canv) > x_max: x_max = max(x_canv)
0481                         if max(y_canv) > y_max: y_max = max(y_canv)
0482                         if min(x_canv) < x_min: x_min = min(x_canv)
0483                         if min(y_canv) < y_min: y_min = min(y_canv)
0484                         TPL_dict[module]['x'] = x_canv
0485                         TPL_dict[module]['y'] = y_canv
0486                     all_modules.update(TPL_dict)
0487 
0488         r_margin = 1
0489         l_margin = 1
0490         t_margin = 1
0491         b_margin = 1
0492 
0493         x_max += r_margin
0494         x_min -= l_margin
0495         y_max += t_margin
0496         y_min -= b_margin
0497 
0498         x_range = x_max - x_min
0499         y_range = y_max - y_min
0500         if (x_range + 0.)/(w + 0.) > (y_range + 0.)/(h + 0.):
0501             x_scale = x_range
0502             y_scale = (h + 0.)/(w + 0.)*x_range
0503         else:
0504             y_scale = y_range
0505             x_scale = (w + 0.)/(h + 0.)*y_range
0506         TPL = {} 
0507         for module in all_modules:
0508             x = array('d', [])
0509             y = array('d', [])
0510             for idx in range(len(all_modules[module]['x'])):
0511                 x.append((all_modules[module]['x'][idx] - x_min + 0.)/(x_scale + 0.))
0512                 y.append((all_modules[module]['y'][idx] - y_min + 0.)/(y_scale + 0.))
0513             # Begin point is end point
0514             x.append((all_modules[module]['x'][0] - x_min + 0.)/(x_scale + 0.))
0515             y.append((all_modules[module]['y'][0] - y_min + 0.)/(y_scale + 0.))
0516             #print(x, y)
0517             TPL[module] = ROOT.TPolyLine(len(x), x, y) 
0518             #TPL[module].SetFillColor(1)
0519             TPL[module].SetLineColor(1)
0520             TPL[module].Draw('f')
0521             TPL[module].Draw()
0522         TL = ROOT.TLatex()
0523         TL.SetTextSize(0.025)
0524         for key in all_text:
0525             x = (all_text[key]['x'] - x_min + 0.)/(x_scale + 0.)
0526             y = (all_text[key]['y'] - y_min + 0.)/(y_scale + 0.)
0527             TL.SetTextAlign(all_text[key]['alignment'])
0528             TL.DrawLatex(x, y, all_text[key]['text'])
0529         #TL.SetTextSize(0.025)
0530         #TL.SetTextAlign(11)
0531         #TL.DrawLatex(0.1, 0.1, 'bottom')
0532         #TL.SetTextAlign(13)
0533         #TL.DrawLatex(0.1, 0.1, 'top')
0534         canvas.Update() 
0535         raw_input('exit')
0536    
0537     test_draw(1500, 750)
0538     #test_draw(125, 500)
0539     #test_draw(500, 500)
0540     #raw_input('exit')
0541  
0542