[807] | 1 | # $Id: slabGeometry.py,v 1.3 2003/06/20 12:41:07 dressel Exp $ |
---|
| 2 | # ------------------------------------------------------------------- |
---|
| 3 | # GEANT4 tag $Name: $ |
---|
| 4 | # ------------------------------------------------------------------- |
---|
| 5 | # |
---|
| 6 | import math |
---|
| 7 | import G4Kernel |
---|
| 8 | import parallelHall |
---|
| 9 | import posLog |
---|
| 10 | |
---|
| 11 | class SlabedGeometry(object): |
---|
| 12 | def __init__(self, tiaraSpecs, cellWidth, parallelGeo): |
---|
| 13 | self.arrPosLogVol = [] |
---|
| 14 | self.normalCellSolid = None |
---|
| 15 | self.logNormCell = None |
---|
| 16 | self.lastCellSolid = None |
---|
| 17 | self.logLastCell = None |
---|
| 18 | self.createCells(tiaraSpecs, cellWidth, parallelGeo) |
---|
| 19 | |
---|
| 20 | def createCells(self, tiaraSpecs, cellWidth, parallelGeo): |
---|
| 21 | print "SlabedGeometry::createCells:" |
---|
| 22 | print "halfLength", parallelGeo.halfLength,\ |
---|
| 23 | "halfWidth", parallelGeo.halfWidth |
---|
| 24 | nCells = int(tiaraSpecs.experiment.shieldWidth / cellWidth) |
---|
| 25 | print "cellWidth", cellWidth |
---|
| 26 | print "nCells", nCells |
---|
| 27 | zCellStart = tiaraSpecs.dimensions.targetPosZ + \ |
---|
| 28 | tiaraSpecs.dimensions.distTargetExperiment + \ |
---|
| 29 | tiaraSpecs.experiment.colWidth |
---|
| 30 | print "zCellStart", zCellStart |
---|
| 31 | zCellRegion = parallelGeo.halfLength - zCellStart |
---|
| 32 | print "zCellRegion", zCellRegion |
---|
| 33 | lengthLastCell = zCellRegion - nCells * cellWidth |
---|
| 34 | print "lengthLastCell", lengthLastCell |
---|
| 35 | print "sum cell length:", lengthLastCell + nCells * cellWidth |
---|
| 36 | vacuum = tiaraSpecs.materials.GetMaterial("vacuum") |
---|
| 37 | self.normalCellSolid = G4Kernel.G4Box("cellBox", |
---|
| 38 | parallelGeo.halfWidth, |
---|
| 39 | parallelGeo.halfWidth, |
---|
| 40 | cellWidth/2) |
---|
| 41 | print "normal box:",parallelGeo.halfWidth,cellWidth/2 |
---|
| 42 | self.logNormCell = G4Kernel.G4LogicalVolume(self.normalCellSolid, |
---|
| 43 | vacuum, |
---|
| 44 | "cellLog") |
---|
| 45 | |
---|
| 46 | zPos = zCellStart - 0.5 * cellWidth |
---|
| 47 | for i in range(nCells): |
---|
| 48 | zPos += cellWidth |
---|
| 49 | self.arrPosLogVol.append(posLog.PosLog(zPos, self.logNormCell)) |
---|
| 50 | print "zPos", zPos |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | self.lastCellSolid = G4Kernel.G4Box("lastCellBox", |
---|
| 54 | parallelGeo.halfWidth, |
---|
| 55 | parallelGeo.halfWidth, |
---|
| 56 | lengthLastCell/2) |
---|
| 57 | self.logLastCell = G4Kernel.G4LogicalVolume(self.lastCellSolid, |
---|
| 58 | vacuum, |
---|
| 59 | "lastCellLog") |
---|
| 60 | |
---|
| 61 | print "last cell:", parallelGeo.halfWidth, lengthLastCell/2 |
---|
| 62 | |
---|
| 63 | zPos += cellWidth/2+lengthLastCell/2 |
---|
| 64 | self.arrPosLogVol.append(posLog.PosLog(zPos, self.logLastCell)) |
---|
| 65 | print "last cell zPos", zPos |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | def getArrPosLogVol(self): |
---|
| 71 | return self.arrPosLogVol |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | class SlabedImportanceGeometry(object): |
---|
| 76 | def __init__(self, tiaraSpecs, cellWidth, impBase, parallelGeo = None): |
---|
| 77 | self.parallelGeo = parallelGeo |
---|
| 78 | self.tiaraSpecs = tiaraSpecs |
---|
| 79 | self.cellWidth = cellWidth |
---|
| 80 | self.iStore = None |
---|
| 81 | self.geometryCells = [] |
---|
| 82 | self.base = impBase |
---|
| 83 | cellwidth_cm = cellWidth / CLHEP.cm |
---|
| 84 | self.nameExt = "-cellWidth_%(cellwidth_cm)d" %vars() |
---|
| 85 | self.buildParallelGeometry() |
---|
| 86 | self.setImportances() |
---|
| 87 | |
---|
| 88 | def buildParallelGeometry(self): |
---|
| 89 | self.parallelGeo = parallelHall.ParallelHall(self.tiaraSpecs) |
---|
| 90 | |
---|
| 91 | self.slabedGeo = SlabedGeometry(self.tiaraSpecs, |
---|
| 92 | self.cellWidth, |
---|
| 93 | self.parallelGeo) |
---|
| 94 | self.parallelGeo.placeCells(self.slabedGeo.getArrPosLogVol()) |
---|
| 95 | self.iStore = G4Kernel.G4IStore(self.parallelGeo.getWorldVolume()) |
---|
| 96 | self.geometryCells = self.parallelGeo.getGeometryCells() |
---|
| 97 | |
---|
| 98 | def setImportances(self): |
---|
| 99 | worldCell = G4Kernel.G4GeometryCell(self.parallelGeo.\ |
---|
| 100 | getWorldVolume(), 0) |
---|
| 101 | self.iStore.AddImportanceGeometryCell(1, worldCell) |
---|
| 102 | nCells = len(self.geometryCells) |
---|
| 103 | for i in range(nCells-1): |
---|
| 104 | cell = self.geometryCells[i] |
---|
| 105 | importance = math.pow(self.base, i) |
---|
| 106 | print "i=", importance |
---|
| 107 | self.iStore.AddImportanceGeometryCell(importance, cell) |
---|
| 108 | lastCell = self.geometryCells[nCells-1] |
---|
| 109 | importance = math.pow(self.base, nCells-2) |
---|
| 110 | print "last cells i=", importance |
---|
| 111 | self.iStore.AddImportanceGeometryCell(importance, lastCell) |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | def getWorldVolume(self): |
---|
| 116 | return self.parallelGeo.getWorldVolume() |
---|
| 117 | |
---|
| 118 | def getImportanceStore(self): |
---|
| 119 | return self.iStore |
---|