# 1 file of E^-2 5-component 6e2-1e11 GeV (10:5:3:2:1) hard = 2.5e6 * MuonGun.corsika_genprob('Standard5Comp') # In order to compare to "unweighted" CORSIKA, turn the Hoerandel flux # into a probability (since we happen to know the integral) areanorm = 0.131475115 * area # 1 file of natural-spectrum ("unweighted") CORSIKA unweighted = (2.5e7 / areanorm) * MuonGun.corsika_genprob('Hoerandel5') model = MuonGun.load_model('GaisserH4a_atmod12_SIBYLL') model.flux.min_multiplicity = 1 model.flux.max_multiplicity = 1 # spectrum = MuonGun.OffsetPowerLaw(5.0, 5e2, 8e2, 10**4.5) spectrum = MuonGun.OffsetPowerLaw(5, 8e2, 2e3, 1e5) # spectrum = MuonGun.OffsetPowerLaw(1.1, 650, 800, 1e8) gun = 1e5 * MuonGun.EnergyDependentSurfaceInjector(surface, model.flux, spectrum, model.radius) # gun = 1e5*MuonGun.StaticSurfaceInjector(surface, model.flux, spectrum, model.radius) # gun.target_surface = lambda e: surface def get_weight(weighter, energy, zenith=numpy.pi / 8, scale=True): shape = energy.shape if scale: x = numpy.array([gun.target_surface(e).radius - 1 for e in energy]) else: # x = numpy.ones(shape[0])*surface.radius - 1 x = numpy.ones(shape[0]) * surface.radius - 1 # x = surface.radius*numpy.ones(shape) - 1 y = numpy.zeros(shape)
from icecube import icetray, dataclasses, dataio from icecube import phys_services, simclasses, MuonGun from I3Tray import I3Tray from os.path import expandvars tray = I3Tray() tray.context['I3RandomService'] = phys_services.I3GSLRandomService(1337) from icecube.MuonGun.segments import GenerateBundles outer = MuonGun.Cylinder(1600, 800) inner = MuonGun.Cylinder(300, 150, dataclasses.I3Position(0, 0, -350)) spectrum = MuonGun.OffsetPowerLaw(5, 1e3, 1e1, 1e4) model = MuonGun.load_model('GaisserH4a_atmod12_SIBYLL') generator = MuonGun.EnergyDependentSurfaceInjector( outer, model.flux, spectrum, model.radius, MuonGun.ConstantSurfaceScalingFunction(inner)) tray.AddSegment( GenerateBundles, 'BundleGen', NEvents=1000, Generator=generator, GCDFile=expandvars( '$I3_TESTDATA/GCD/GeoCalibDetectorStatus_IC86.55697_corrected_V2.i3.gz' )) class Harvest(icetray.I3ConditionalModule): def __init__(self, context): super(Harvest, self).__init__(context) self.AddOutBox("OutBox")
#Inner and outher target surfaces outSurface = Cylinder(1600 * I3Units.m, 800 * I3Units.m) inSurface = Cylinder(500 * I3Units.m, 150 * I3Units.m, I3Position(46.3, -34.9, -300)) #Sets energy and spectral index of muons #Jackob's spectrum #spectrum = MuonGun.OffsetPowerLaw(5.0, 5e2, 200, 1e6) spectrum = MuonGun.OffsetPowerLaw(5.0, 7e2, int(sys.argv[2]), int(sys.argv[3])) #spectrum = MuonGun.OffsetPowerLaw(5.2, 7e2, 150, 1e5) #spectrum = MuonGun.OffsetPowerLaw(2, 1e3, 1e3, 1e5) #This version only aims at inSurface, but muons originate at outSurface scaling = MuonGun.ConstantSurfaceScalingFunction(inSurface) #generator = MuonGun.EnergyDependentSurfaceInjector(outSurface, model.flux, spectrum, model.radius, scaling,0,1) generator = MuonGun.EnergyDependentSurfaceInjector(outSurface, model.flux, spectrum, model.radius, scaling) #This version aims at whatever surface you give it, but originates all the muons inside the surface, not at the top layer of ice #generator = MuonGun.StaticSurfaceInjector(surface, model.flux, spectrum, model.radius) #Not sure yet what this does? # generator = MuonGun.Floodlight() # set up a random number generator randomService = phys_services.I3SPRNGRandomService(seed=options.SEED * 2, nstreams=10000, streamnum=options.RUNNUMBER) tray.context['I3RandomService'] = randomService #Generate bundles of muons tray.AddSegment(GenerateBundles,
def main(cfg, run_number, scratch): with open(cfg, 'r') as stream: if int(yaml.__version__[0]) < 5: # backwards compatibility for yaml versions before version 5 cfg = yaml.load(stream) else: cfg = yaml.full_load(stream) cfg['run_number'] = run_number cfg['run_folder'] = get_run_folder(run_number) tray = I3Tray() random_services, _ = create_random_services( dataset_number=cfg['dataset_number'], run_number=cfg['run_number'], seed=cfg['seed'], n_services=2) random_service, random_service_prop = random_services tray.context['I3RandomService'] = random_service model = MuonGun.load_model(cfg['muongun_model']) model.flux.min_multiplicity = cfg['muongun_min_multiplicity'] model.flux.max_multiplicity = cfg['muongun_max_multiplicity'] spectrum = MuonGun.OffsetPowerLaw(cfg['gamma'], cfg['e_min'] * icetray.I3Units.GeV, cfg['e_min'] * icetray.I3Units.GeV, cfg['e_max'] * icetray.I3Units.GeV) surface = MuonGun.Cylinder(1600, 800, dataclasses.I3Position(31.25, 19.64, 0)) if cfg['muongun_generator'] == 'energy': scale = MuonGun.BasicSurfaceScalingFunction() scale.SetSideScaling(4., 17266, 3.41, 1.74) scale.SetCapScaling(4., 23710, 3.40, 1.88) generator = MuonGun.EnergyDependentSurfaceInjector( surface, model.flux, spectrum, model.radius, scale) elif cfg['muongun_generator'] == 'static': generator = MuonGun.StaticSurfaceInjector(surface, model.flux, spectrum, model.radius) elif cfg['muongun_generator'] == 'floodlight': generator = MuonGun.Floodlight( surface=surface, energyGenerator=spectrum, cosMin=cfg['muongun_floodlight_min_cos'], cosMax=cfg['muongun_floodlight_max_cos'], ) else: err_msg = 'MuonGun generator {} is not known.' err_msg += " Must be 'energy','static' or 'floodlight" raise ValueError(err_msg.format(cfg['muongun_generator'])) tray.Add(MuonGun.segments.GenerateBundles, 'MuonGenerator', Generator=generator, NEvents=cfg['n_events_per_run'], GCDFile=cfg['gcd']) tray.Add("Rename", keys=["I3MCTree", "I3MCTree_preMuonProp"]) tray.AddSegment(segments.PropagateMuons, "PropagateMuons", RandomService=random_service_prop, **cfg['muon_propagation_config']) if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace(' ', '0') if cfg['distance_splits'] is not None: click.echo('SplittingDistance: {}'.format(cfg['distance_splits'])) distance_splits = np.atleast_1d(cfg['distance_splits']) dom_limits = np.atleast_1d(cfg['threshold_doms']) if len(dom_limits) == 1: dom_limits = np.ones_like(distance_splits) * cfg['threshold_doms'] oversize_factors = np.atleast_1d(cfg['oversize_factors']) order = np.argsort(distance_splits) distance_splits = distance_splits[order] dom_limits = dom_limits[order] oversize_factors = oversize_factors[order] stream_objects = generate_stream_object(distance_splits, dom_limits, oversize_factors) tray.AddModule(OversizeSplitterNSplits, "OversizeSplitterNSplits", thresholds=distance_splits, thresholds_doms=dom_limits, oversize_factors=oversize_factors) for stream_i in stream_objects: outfile_i = stream_i.transform_filepath(outfile) tray.AddModule("I3Writer", "writer_{}".format(stream_i.stream_name), Filename=outfile_i, Streams=[ icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M') ], If=stream_i) click.echo('Output ({}): {}'.format(stream_i.stream_name, outfile_i)) else: click.echo('Output: {}'.format(outfile)) tray.AddModule("I3Writer", "writer", Filename=outfile, Streams=[ icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M') ]) click.echo('Scratch: {}'.format(scratch)) tray.AddModule("TrashCan", "the can") tray.Execute() tray.Finish()
def main(cfg, run_number, scratch): with open(cfg, 'r') as stream: cfg = yaml.load(stream) cfg['run_number'] = run_number cfg['run_folder'] = get_run_folder(run_number) tray = I3Tray() random_service, random_service_prop, _ = create_random_services( dataset_number=cfg['dataset_number'], run_number=cfg['run_number'], seed=cfg['seed']) tray.context['I3RandomService'] = random_service model = MuonGun.load_model(cfg['muongun_model']) model.flux.min_multiplicity = cfg['muongun_min_multiplicity'] model.flux.max_multiplicity = cfg['muongun_max_multiplicity'] spectrum = MuonGun.OffsetPowerLaw( cfg['gamma'], cfg['e_min']*icetray.I3Units.TeV, cfg['e_min']*icetray.I3Units.TeV, cfg['e_max']*icetray.I3Units.TeV) surface = MuonGun.Cylinder(1600, 800, dataclasses.I3Position(31.25, 19.64, 0)) if cfg['muongun_generator'] == 'energy': scale = MuonGun.BasicSurfaceScalingFunction() scale.SetSideScaling(4., 17266, 3.41, 1.74) scale.SetCapScaling(4., 23710, 3.40, 1.88) generator = MuonGun.EnergyDependentSurfaceInjector(surface, model.flux, spectrum, model.radius, scale) elif cfg['muongun_generator'] == 'static': generator = MuonGun.StaticSurfaceInjector(surface, model.flux, spectrum, model.radius) elif cfg['muongun_generator'] =='floodlight': generator = MuonGun.Floodlight(surface = surface, energyGenerator=spectrum, cosMin=cfg['muongun_floodlight_min_cos'], cosMax=cfg['muongun_floodlight_max_cos'], ) else: err_msg = 'MuonGun generator {} is not known.' err_msg += " Must be 'energy','static' or 'floodlight" raise ValueError(err_msg.format(cfg['muongun_generator'])) tray.Add(MuonGun.segments.GenerateBundles, 'MuonGenerator', Generator=generator, NEvents=cfg['n_events_per_run'], GCDFile=cfg['gcd']) tray.Add("Rename", keys=["I3MCTree", "I3MCTree_preMuonProp"]) tray.AddSegment( segments.PropagateMuons, "PropagateMuons", RandomService=random_service_prop) if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace(' ', '0') outfile = outfile.replace('.bz2', '') tray.AddModule("I3Writer", "writer", Filename=outfile, Streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M')]) tray.AddModule("TrashCan", "the can") tray.Execute() tray.Finish()
def main(cfg, run_number, scratch): with open(cfg, 'r') as stream: cfg = yaml.load(stream, Loader=yaml.Loader) cfg['run_number'] = run_number cfg['run_folder'] = get_run_folder(run_number) if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace(' ', '0') if cfg['distance_splits'] is not None: click.echo('SplittingDistances: {}'.format(cfg['distance_splits'])) click.echo('Oversizefactors: {}'.format(cfg['oversize_factors'])) click.echo('NEvents: {}'.format(cfg['n_events_per_run'])) click.echo('EMin: {}'.format(cfg['e_min'])) click.echo('EMax: {}'.format(cfg['e_max'])) click.echo('EBreak: {}'.format(cfg['muongun_e_break'])) click.echo('Gamma: {}'.format(cfg['gamma'])) click.echo('ZenithMin: {}'.format(cfg['zenith_min'])) click.echo('ZenithMax: {}'.format(cfg['zenith_max'])) # create convex hull if 'use_convex_hull' in cfg and cfg['use_convex_hull']: # hardcode icecube corner points # ToDo: read from geometry file points = [ [-570.90002441, -125.13999939, 501], # string 31 [-256.14001465, -521.08001709, 501], # string 1 [361., -422.82998657, 501], # string 6 [576.36999512, 170.91999817, 501], # string 50 [338.44000244, 463.72000122, 501], # string 74 [101.04000092, 412.79000854, 501], # string 72 [22.11000061, 509.5, 501], # string 78 [-347.88000488, 451.51998901, 501], # string 75 [-570.90002441, -125.13999939, -502], # string 31 [-256.14001465, -521.08001709, -502], # string 1 [361., -422.82998657, -502], # string 6 [576.36999512, 170.91999817, -502], # string 50 [338.44000244, 463.72000122, -502], # string 74 [101.04000092, 412.79000854, -502], # string 72 [22.11000061, 509.5, -502], # string 78 [-347.88000488, 451.51998901, -502], # string 75 ] convex_hull = ConvexHull(points) else: convex_hull = None if 'extend_past_hull' not in cfg: cfg['extend_past_hull'] = 0.0 random_services, _ = create_random_services( dataset_number=cfg['dataset_number'], run_number=cfg['run_number'], seed=cfg['seed'], n_services=2) random_service, random_service_prop = random_services # create muon muon = create_muon( azimuth_range=[cfg['azimuth_min'], cfg['azimuth_max']], zenith_range=[cfg['zenith_min'], cfg['zenith_max']], energy_range=[cfg['e_min'], cfg['e_max']], anchor_time_range=cfg['anchor_time_range'], anchor_x_range=cfg['anchor_x_range'], anchor_y_range=cfg['anchor_y_range'], anchor_z_range=cfg['anchor_z_range'], length_to_go_back=cfg['length_to_go_back'], convex_hull=convex_hull, extend_past_hull=cfg['extend_past_hull'], random_service=random_services[0], ) tray = I3Tray() tray.context['I3RandomService'] = random_service tray.AddModule("I3InfiniteSource", "TheSource", Prefix=cfg['gcd'], Stream=icetray.I3Frame.DAQ) if cfg['MuonGenerator'] == 'MuonGunSinglemuons': tray.AddSegment(segments.GenerateSingleMuons, "GenerateCosmicRayMuons", NumEvents=cfg['n_events_per_run'], FromEnergy=cfg['e_min'] * icetray.I3Units.GeV, ToEnergy=cfg['e_max'] * icetray.I3Units.GeV, BreakEnergy=cfg['muongun_e_break'] * icetray.I3Units.GeV, GammaIndex=cfg['gamma'], ZenithRange=[ cfg['zenith_min'] * icetray.I3Units.deg, cfg['zenith_max'] * icetray.I3Units.deg ]) elif cfg['MuonGenerator'] == 'MuonGunGeneral': model = MuonGun.load_model(cfg['muongun_model']) model.flux.min_multiplicity = cfg['muongun_min_multiplicity'] model.flux.max_multiplicity = cfg['muongun_max_multiplicity'] spectrum = MuonGun.OffsetPowerLaw(cfg['gamma'], cfg['e_min'] * icetray.I3Units.GeV, cfg['e_min'] * icetray.I3Units.GeV, cfg['e_max'] * icetray.I3Units.GeV) surface = MuonGun.Cylinder(1600, 800, dataclasses.I3Position(31.25, 19.64, 0)) if cfg['muongun_generator'] == 'energy': scale = MuonGun.BasicSurfaceScalingFunction() scale.SetSideScaling(4., 17266, 3.41, 1.74) scale.SetCapScaling(4., 23710, 3.40, 1.88) generator = MuonGun.EnergyDependentSurfaceInjector( surface, model.flux, spectrum, model.radius, scale) elif cfg['muongun_generator'] == 'static': generator = MuonGun.StaticSurfaceInjector(surface, model.flux, spectrum, model.radius) elif cfg['muongun_generator'] == 'floodlight': generator = MuonGun.Floodlight( surface=surface, energyGenerator=spectrum, cosMin=cfg['muongun_floodlight_min_cos'], cosMax=cfg['muongun_floodlight_max_cos'], ) else: err_msg = 'MuonGun generator {} is not known.' err_msg += " Must be 'energy','static' or 'floodlight" raise ValueError(err_msg.format(cfg['muongun_generator'])) tray.Add(MuonGun.segments.GenerateBundles, 'MuonGenerator', Generator=generator, NEvents=cfg['n_events_per_run'], GCDFile=cfg['gcd']) tray.Add("Rename", keys=["I3MCTree", "I3MCTree_preMuonProp"]) elif cfg['MuonGenerator'] == 'MuonResimulation': tray.AddModule(ParticleMultiplier, 'make_particles', num_events=cfg['n_events_per_run'], primary=muon) else: err_msg = 'MuonGenerator {} is not known.' err_msg += " Must be 'MuonGunSinglemuons','MuonGunGeneral' or 'MuonResimulation" raise ValueError(err_msg.format(cfg['MuonGenerator'])) # -------------------------------------- # Propagate Muons # -------------------------------------- tray.AddSegment(segments.PropagateMuons, "PropagateMuons", RandomService=random_service_prop, **cfg['muon_propagation_config']) # -------------------------------------- # Distance Splits # -------------------------------------- if cfg['distance_splits'] is not None: click.echo('SplittingDistance: {}'.format(cfg['distance_splits'])) distance_splits = np.atleast_1d(cfg['distance_splits']) dom_limits = np.atleast_1d(cfg['threshold_doms']) if len(dom_limits) == 1: dom_limits = np.ones_like(distance_splits) * cfg['threshold_doms'] oversize_factors = np.atleast_1d(cfg['oversize_factors']) order = np.argsort(distance_splits) distance_splits = distance_splits[order] dom_limits = dom_limits[order] oversize_factors = oversize_factors[order] stream_objects = generate_stream_object(distance_splits, dom_limits, oversize_factors) tray.AddModule(OversizeSplitterNSplits, "OversizeSplitterNSplits", thresholds=distance_splits, thresholds_doms=dom_limits, oversize_factors=oversize_factors) for stream_i in stream_objects: outfile_i = stream_i.transform_filepath(outfile) tray.AddModule("I3Writer", "writer_{}".format(stream_i.stream_name), Filename=outfile_i, Streams=[ icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M') ], If=stream_i) click.echo('Output ({}): {}'.format(stream_i.stream_name, outfile_i)) else: click.echo('Output: {}'.format(outfile)) tray.AddModule("I3Writer", "writer", Filename=outfile, Streams=[ icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M') ]) click.echo('Scratch: {}'.format(scratch)) tray.Execute() del tray