def test_write_geomap(self): estimator = SHEstimator() estimator.estimator = SHGeoType.geomap estimator.geometry = CarthesianMesh() estimator.geometry.axis[0].start = -1.0 estimator.geometry.axis[1].start = -25.0 estimator.geometry.axis[2].start = -15.0 estimator.geometry.axis[0].stop = 1.0 estimator.geometry.axis[1].stop = 25.0 estimator.geometry.axis[2].stop = 35.0 estimator.geometry.axis[0].nbins = 1 estimator.geometry.axis[1].nbins = 50 estimator.geometry.axis[2].nbins = 50 estimator.detector_type = SHDetType.zone estimator.particle_type = SHParticleType.unknown estimator.filename = "ex_yzzon" line1, line2 = EstimatorWriter.get_lines(estimator) ref_line1 = "GEOMAP -1.0 -25.0 -15.0 1.0 25.0 35.0" ref_line2 = " 1 50 50 0 ZONE ex_yzzon" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2) estimator.detector_type = SHDetType.medium line1, line2 = EstimatorWriter.get_lines(estimator) ref_line2 = " 1 50 50 0 MEDIUM ex_yzzon" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2) estimator.detector_type = SHDetType.rho line1, line2 = EstimatorWriter.get_lines(estimator) ref_line2 = " 1 50 50 0 RHO ex_yzzon" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2)
def test_write_zone(self): estimator = SHEstimator() estimator.estimator = SHGeoType.zone estimator.geometry = Zone() estimator.geometry.start = 1 estimator.detector_type = SHDetType.dose estimator.particle_type = SHParticleType.all estimator.filename = "DH_dose" line1, = EstimatorWriter.get_lines(estimator) ref_line1 = "ZONE 1 -1 DOSE DH_dose" self.assertEqual(str(line1), ref_line1) estimator.geometry.stop = 300 line1, = EstimatorWriter.get_lines(estimator) ref_line1 = "ZONE 1 300 -1 DOSE DH_dose" self.assertEqual(str(line1), ref_line1) estimator.particle_type = SHParticleType.heavy_ion estimator.heavy_ion_type.a = 12 estimator.heavy_ion_type.z = 6 line1, line2 = EstimatorWriter.get_lines(estimator) ref_line1 = "ZONE 1 300 25 DOSE DH_dose" ref_line2 = " 6 12 " self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2)
def generate_geomap(): result = "" # create empty estimator object estimator = SHEstimator() estimator.estimator = SHGeoType.geomap estimator.particle_type = SHParticleType.unknown # possible detector types and associated names det_types = OrderedDict({ "zon": SHDetType.zone, "rho": SHDetType.rho, "med": SHDetType.medium }) # possible geometries and associated names geometries_dict = msh_geometries() for geometry_name, det_name in product(geometries_dict, det_types): estimator.geometry = geometries_dict[geometry_name] estimator.detector_type = det_types[det_name] estimator.filename = det_name + "_" + geometry_name text = EstimatorWriter.get_text(estimator, add_comment=True) result += text return result
def generate_mesh(geometry_function, estimator_type): result = "" # create empty estimator object estimator = SHEstimator() estimator.estimator = estimator_type # possible particle types and associated names part_types = OrderedDict({ "al": SHParticleType.all, "p": SHParticleType.proton, "n": SHParticleType.neutron }) # possible detector types and associated names det_types = OrderedDict({ "en": SHDetType.energy, "fl": SHDetType.fluence, "aen": SHDetType.avg_energy, "bet": SHDetType.avg_beta }) # possible geometries and associated names geometries_dict = geometry_function() for geometry_name, part_name, det_name in product(geometries_dict, part_types, det_types): estimator.geometry = geometries_dict[geometry_name] estimator.detector_type = det_types[det_name] estimator.particle_type = part_types[part_name] estimator.filename = det_name + "_" + geometry_name + "_" + part_name text = EstimatorWriter.get_text(estimator, add_comment=True) result += text return result
def generate_plane(): result = "" # create empty estimator object estimator = SHEstimator() estimator.estimator = SHGeoType.plane # possible particle types and associated names part_types = OrderedDict({ "al": SHParticleType.all, "p": SHParticleType.proton, "n": SHParticleType.neutron }) # possible detector types and associated names det_types = OrderedDict({"cnt": SHDetType.counter}) # possible geometries and associated names geometries_dict = plane_geometries() for geometry_name, part_name, det_name in product(geometries_dict, part_types, det_types): estimator.geometry = geometries_dict[geometry_name] estimator.detector_type = det_types[det_name] estimator.particle_type = part_types[part_name] estimator.filename = det_name + "_" + geometry_name + "_" + part_name text = EstimatorWriter.get_text(estimator, add_comment=True) result += text return result
def test_write_cyl(self): estimator = SHEstimator() estimator.estimator = SHGeoType.cyl estimator.geometry = CylindricalMesh() estimator.geometry.axis[0].start = 0.0 estimator.geometry.axis[1].start = 0.0 estimator.geometry.axis[2].start = 0.0 estimator.geometry.axis[0].stop = 10.0 estimator.geometry.axis[1].stop = 7.0 estimator.geometry.axis[2].stop = 30.0 estimator.geometry.axis[0].nbins = 1 estimator.geometry.axis[1].nbins = 1 estimator.geometry.axis[2].nbins = 300 estimator.detector_type = SHDetType.energy estimator.particle_type = SHParticleType.all estimator.filename = "ex_cyl" line1, line2 = EstimatorWriter.get_lines(estimator) ref_line1 = "CYL 0.0 0.0 0.0 10.0 7.0 30.0" ref_line2 = " 1 1 300 -1 ENERGY ex_cyl" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2) estimator.detector_type = SHDetType.avg_beta estimator.particle_type = SHParticleType.proton ref_line2 = " 1 1 300 2 AVG-BETA ex_cyl" line1, line2 = EstimatorWriter.get_lines(estimator) self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2) estimator.particle_type = SHParticleType.heavy_ion estimator.heavy_ion_type.a = 12 estimator.heavy_ion_type.z = 6 ref_line2 = " 1 1 300 25 AVG-BETA ex_cyl" ref_line3 = " 6 12 " line1, line2, line3 = EstimatorWriter.get_lines(estimator) self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2) self.assertEqual(str(line3), ref_line3)
def test_write_plane_compact(self): estimator = SHEstimator() estimator.estimator = SHGeoType.plane estimator.geometry = Plane() estimator.geometry.set_point(x=0.0, y=0.0, z=0.0) estimator.geometry.set_normal(x=0.0, y=0.0, z=1.0) estimator.detector_type = SHDetType.counter estimator.particle_type = SHParticleType.proton estimator.filename = "NB_count2" line1, line2 = EstimatorWriter.get_lines(estimator) ref_line1 = "PLANE 0.0 0.0 0.0 0.0 0.0 1.0" ref_line2 = " 2 COUNTER NB_count2" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2)
def test_write_cyl_compact(self): estimator = SHEstimator() estimator.estimator = SHGeoType.cyl estimator.geometry = CylindricalMesh() estimator.geometry.set_axis(axis_no=0, start=0.0, stop=10.0, nbins=1) estimator.geometry.set_axis(axis_no=1, start=0.0, stop=7.0, nbins=1) estimator.geometry.set_axis(axis_no=2, start=0.0, stop=30.0, nbins=300) estimator.detector_type = SHDetType.energy estimator.particle_type = SHParticleType.all estimator.filename = "ex_cyl" line1, line2 = EstimatorWriter.get_lines(estimator) ref_line1 = "CYL 0.0 0.0 0.0 10.0 7.0 30.0" ref_line2 = " 1 1 300 -1 ENERGY ex_cyl" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2)
def test_write_plane(self): estimator = SHEstimator() estimator.estimator = SHGeoType.plane estimator.geometry = Plane() estimator.geometry.point_x = 0.0 estimator.geometry.point_y = 0.0 estimator.geometry.point_z = 0.0 estimator.geometry.normal_x = 0.0 estimator.geometry.normal_y = 0.0 estimator.geometry.normal_z = 1.0 estimator.detector_type = SHDetType.counter estimator.particle_type = SHParticleType.all estimator.filename = "NB_count1" line1, line2 = EstimatorWriter.get_lines(estimator) ref_line1 = "PLANE 0.0 0.0 0.0 0.0 0.0 1.0" ref_line2 = " -1 COUNTER NB_count1" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2)
def main(args=sys.argv[1:]): """ Compose programatically detect.dat SHIELDHIT-12A input file with fixed mesh and many combinations of detector and particle type. :param args: part of sys.argv, used here to simplify automated testing :return: None """ # create empty estimator object estimator = SHEstimator() # create carthesian mesh # it is done once and in single place # editing in manually in detect.dat file would require changes in many lines, # for every combination of particle and detector type, making it error prone estimator.estimator = SHGeoType.msh estimator.geometry = CarthesianMesh() estimator.geometry.set_axis(axis_no=0, start=-5.0, stop=5.0, nbins=1) estimator.geometry.set_axis(axis_no=1, start=-5.0, stop=5.0, nbins=1) estimator.geometry.set_axis(axis_no=2, start=0.0, stop=30.0, nbins=300) # possible detector types and associated names det_types = {SHDetType.energy: "en", SHDetType.fluence: "fl"} # possible particle types and associated names particle_types = { SHParticleType.all: "all", SHParticleType.proton: "p", SHParticleType.neutron: "n" } # open detector.dat file for writing with open("detect.dat", "w") as f: f.write(CardLine.credits + "\n") # loop over all combinations of detector and particle types # output filename will be composed from associated detector and particle names for dt, pt in product(det_types.keys(), particle_types.keys()): estimator.detector_type = dt estimator.particle_type = pt estimator.filename = det_types[dt] + "_" + particle_types[pt] text = EstimatorWriter.get_text(estimator, add_comment=True) f.write(text) f.write(CardLine.comment + "\n")
def test_write_geomap_compact(self): estimator = SHEstimator() estimator.estimator = SHGeoType.geomap estimator.geometry = CarthesianMesh() estimator.geometry.set_axis(axis_no=0, start=-1.0, stop=1.0, nbins=1) estimator.geometry.set_axis(axis_no=1, start=-25.0, stop=25.0, nbins=50) estimator.geometry.set_axis(axis_no=2, start=-15.0, stop=35.0, nbins=50) estimator.detector_type = SHDetType.zone estimator.particle_type = SHParticleType.unknown estimator.filename = "ex_yzzon" line1, line2 = EstimatorWriter.get_lines(estimator) ref_line1 = "GEOMAP -1.0 -25.0 -15.0 1.0 25.0 35.0" ref_line2 = " 1 50 50 0 ZONE ex_yzzon" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2)
def test_write_msh(self): estimator = SHEstimator() estimator.estimator = SHGeoType.msh estimator.geometry = CarthesianMesh() estimator.geometry.axis[0].start = -5.0 estimator.geometry.axis[1].start = -5.0 estimator.geometry.axis[2].start = 0.0 estimator.geometry.axis[0].stop = 5.0 estimator.geometry.axis[1].stop = 5.0 estimator.geometry.axis[2].stop = 30.0 estimator.geometry.axis[0].nbins = 1 estimator.geometry.axis[1].nbins = 1 estimator.geometry.axis[2].nbins = 300 estimator.detector_type = SHDetType.energy estimator.particle_type = SHParticleType.all estimator.filename = "ex_zmsh" line1, line2 = EstimatorWriter.get_lines(estimator) ref_line1 = "MSH -5.0 -5.0 0.0 5.0 5.0 30.0" ref_line2 = " 1 1 300 -1 ENERGY ex_zmsh" self.assertEqual(str(line1), ref_line1) self.assertEqual(str(line2), ref_line2)
def main(args=sys.argv[1:]): """ Compose programatically detect.dat SHIELDHIT-12A input file with fixed mesh and many combinations of detector and particle type. :param args: part of sys.argv, used here to simplify automated testing :return: None """ # create empty estimator object estimator = SHEstimator() # create carthesian mesh # it is done once and in single place # editing in manually in detect.dat file would require changes in many lines, # for every combination of particle and detector type, making it error prone estimator.estimator = SHGeoType.msh estimator.geometry = CarthesianMesh() estimator.geometry.set_axis(axis_no=0, start=-5.0, stop=5.0, nbins=1) estimator.geometry.set_axis(axis_no=1, start=-5.0, stop=5.0, nbins=1) estimator.geometry.set_axis(axis_no=2, start=0.0, stop=30.0, nbins=300) # possible detector types and associated names det_types = {SHDetType.energy: "en", SHDetType.fluence: "fl"} # possible particle types and associated names particle_types = {SHParticleType.all: "all", SHParticleType.proton: "p", SHParticleType.neutron: "n"} # open detector.dat file for writing with open("detect.dat", "w") as f: f.write(CardLine.credits + "\n") # loop over all combinations of detector and particle types # output filename will be composed from associated detector and particle names for dt, pt in product(det_types.keys(), particle_types.keys()): estimator.detector_type = dt estimator.particle_type = pt estimator.filename = det_types[dt] + "_" + particle_types[pt] text = EstimatorWriter.get_text(estimator, add_comment=True) f.write(text) f.write(CardLine.comment + "\n")