def PolyplopiaSegment( tray, name, mctype='CORSIKA', RandomService=None, mctree_name="I3MCTree_preMuonProp", separate_coincident_mctree_name="", # leave empty to combine bgfile=None, timewindow=40. * I3Units.microsecond, rate=float('nan'), If=lambda f: True): """ There are three scenarios for polyplopia: 1. bgfile: We are reading background MC from a separate file and injecting events to signal (or weighted background) based on a Poisson distribution within the given time window. 2. we are generating MuonGun bundles and injecting events to signal (or weighted background) based on a Poisson distribution within the given time window. """ from icecube import polyplopia, MuonGun #tray.AddModule("ParticleMapper","mapprimary") if bgfile: # merge bg into signal background = polyplopia.CoincidentI3ReaderService(bgfile) else: # Use MuonGun # Default: use Hoerandel as a template for generating muons. model = MuonGun.load_model("Hoerandel5_atmod12_SIBYLL") #model = MuonGun.load_model('GaisserH4a_atmod12_SIBYLL') # Generate bundles (even if not 100 percent accurate). model.flux.max_multiplicity = 100 gamma_index = 2.6 energy_offset = 700. energy_min = 1e4 energy_max = 1e7 cylinder_length = 1600. cylinder_radius = 800. cylinder_x = 0. cylinder_y = 0. cylinder_z = 0. # Default: cylinder aligned with z-axis at detector center as injection # surface. outsurface_center = dataclasses.I3Position(cylinder_x * I3Units.m, cylinder_y * I3Units.m, cylinder_z * I3Units.m) outsurface = MuonGun.Cylinder(length=cylinder_length * I3Units.m, radius=cylinder_radius * I3Units.m, center=outsurface_center) generator = MuonGun.NaturalRateInjector(outsurface, model.flux, model.energy) background = polyplopia.MuonGunBackgroundService() background.set_generator(generator) background.set_rng(RandomService) background.set_rate(rate) background.set_mctree_name(mctree_name) tray.AddModule("PoissonMerger", "merge", CoincidentEventService=background, PrimaryType=mctype, MCTreeName=mctree_name, Rate=rate, SeparateMCTree=separate_coincident_mctree_name, TimeWindow=timewindow) return tray
from icecube import phys_services, sim_services, simclasses, MuonGun from I3Tray import I3Tray tray = I3Tray() tray.AddModule('I3InfiniteSource', 'driver') tray.AddService('I3GSLRandomServiceFactory', 'rng', Seed=1337) surface = MuonGun.Cylinder(1600, 800) model = MuonGun.load_model('GaisserH4a_atmod12_SIBYLL') flux = model.flux radii = model.radius energies = model.energy nevents = 10 generator = nevents * MuonGun.NaturalRateInjector(surface, flux, energies) tray.AddModule('I3MuonGun::GeneratorModule', 'generator', Generator=generator) tray.AddModule('I3MuonGun::WeightCalculatorModule', 'weight', Model=MuonGun.BundleModel(flux, radii, energies), Generator=generator) weights = [] def check_weight(frame): frame['MCMuon'] = frame['I3MCTree'].primaries[0] m = len(frame['I3MCTree'].children(frame['MCMuon'])) weight = frame['weight'].value