def genRegTriplet(ofile, position, spacing, debug, nLayers=3): ''' Adds the triplet information based on the requested barrel layer Position Args: ofile: the file to be written to position: requested position of the barrel layer spacing: requested spacing between the triplet layers [mm] debug: print debug messages nLayers (optional): if !=3 will add more than 3 layers to the triplet ''' if nLayers == 3: multi = 'triplet' elif nLayers: multi = 'quartet' if position == 1: barrelName = "BRL_0_" + multi else: barrelName = "BRL_1_" + multi if debug: print '\nGenerating triplet "{2}" in layer {0} with spacing {1} mm'.format( position, spacing, barrelName) # Calculate inner and outer radius based on requested position and layer spacing # Allow for triplet to be at the top and bottom of barrel region tripletCentroid = radiiMap[position] if position == 1: tripletCentroid += (TRIPLET_TOLERANCE + spacing) if position == 6: tripletCentroid -= (TRIPLET_TOLERANCE + spacing) if nLayers == 3: innerRadius = tripletCentroid - (TRIPLET_TOLERANCE + spacing) outerRadius = tripletCentroid + (TRIPLET_TOLERANCE + spacing) if nLayers == 4: innerRadius = tripletCentroid - (TRIPLET_TOLERANCE + 1.5 * spacing) outerRadius = tripletCentroid + (TRIPLET_TOLERANCE + 1.5 * spacing) # add triplet sub-region header addSpecialBarrelHeader(ofile, barrelName, innerRadius, outerRadius, BIG_DELTA, SMALL_DELTA, nLayers) # Calculate radii of triplet layers (maybe put this into a function?) if nLayers == 3: radius1 = tripletCentroid - spacing radius2 = tripletCentroid radius3 = tripletCentroid + spacing elif nLayers == 4: radius1 = tripletCentroid - 1.5 * spacing radius2 = tripletCentroid - 0.5 * spacing radius3 = tripletCentroid + 0.5 * spacing radius4 = tripletCentroid + 1.5 * spacing # Add the layers tripletModuleType = "tripletPixel" l1 = Layer(radius=radius1, color=6, moduleType=tripletModuleType, layerNumber=1) l2 = Layer(radius=radius2, color=6, moduleType=tripletModuleType, layerNumber=2) l3 = Layer(radius=radius3, color=6, moduleType=tripletModuleType, layerNumber=3) if nLayers == 4: l4 = Layer(radius=radius4, color=6, moduleType=tripletModuleType, layerNumber=4) l1.addLayer(ofile) l2.addLayer(ofile) l3.addLayer(ofile) if nLayers == 4: l4.addLayer(ofile) ofile.write(' }\n') # close brace after barrel area if debug: print '\tinnerRadius', innerRadius print '\ttripletCentroid', tripletCentroid print '\touterRadius', outerRadius print '\t(r1, r2, r3) : ({0}, {1}, {2})'.format( radius1, radius2, radius3)
def genRegNormal(ofile, layerRange, barrelAreaID, debug): ''' Adds normal barrel regions withing the given layer range. Automatically detects if "multilayer" functionailty can be used Args: ofile: the file to be written to layerRange: the range of barrel layers to be included barrelAreaID: the ID of the barrel sub-region ''' barrelName = "BRL_" + str(barrelAreaID) + "_outer" # Calcualte length of barrel if len(layerRange) == 1 and layerRange[0] != 6: innerRadius = radiiMap[layerRange[0]] outerRadius = radiiMap[layerRange[0]] + 10 elif len(layerRange) == 1 and layerRange[0] == 6: innerRadius = radiiMap[layerRange[0]] - 10 outerRadius = radiiMap[layerRange[0]] else: innerRadius = radiiMap[layerRange[0]] outerRadius = radiiMap[layerRange[-1]] if debug: print '\nGenerating normal region for', barrelName print '\tinnerRadius', innerRadius print '\touterRadius', outerRadius addNormalBarrelHeader(ofile, barrelName, innerRadius, outerRadius, numLayers=len(layerRange)) usedLayerCounter = 0 # Add layers to barrel, first add macroPixel layers if layerRange[0] == 1: if len(layerRange) == 1: # one layer of macroPixel l1 = Layer(radius=-1, color=7, moduleType="macroPixel", layerNumber=1) usedLayerCounter = 1 elif len(layerRange) >= 2: # double layer of macroPixel l1 = Layer(radius=-1, color=7, moduleType="macroPixel", layerNumber="1-2") usedLayerCounter = 2 l1.addLayer(ofile) elif layerRange[0] == 2: # one layer of macroPixel l1 = Layer(radius=-1, color=7, moduleType="macroPixel", layerNumber=1) l1.addLayer(ofile) usedLayerCounter = 1 # remove layers 1 and 2 if in list if 1 in layerRange: layerRange.remove(1) if 2 in layerRange: layerRange.remove(2) if len(layerRange) == 0: ofile.write(' }\n') return # No remaining layers to draw # N layers of strips, in with N repeated layers, excluding layers 1 and 2 if 6 in layerRange: if len(layerRange) > 1: layerNumbering = "{0}-{1}".format( 1 + usedLayerCounter, len(layerRange) + usedLayerCounter) elif len(layerRange) == 1: layerNumbering = 1 + usedLayerCounter else: if len(layerRange) > 1: layerNumbering = "{0}-{1}".format(layerRange[0], layerRange[-1]) elif len(layerRange) == 1: layerNumbering = layerRange[0] l2 = Layer(radius=-1, color=1, moduleType="strip", layerNumber=layerNumbering) l2.addLayer(ofile) # Add end of barrel region ofile.write(' }\n')