def get_track_length_in_detector_safe(frame, trackname): if trackname not in frame: return None surf = phys_services.Cylinder(1000., 500.) intersect = surf.intersection(frame[trackname].pos, frame[trackname].dir) if np.isfinite(intersect.first) and np.isfinite(intersect.second): return max(intersect.second, 0.) - max(intersect.first, 0.) else: return 0.
def SelectNeutrino( tray, name, Propagators=None, AutoExtendMuonVolume=False, EnergyBiasPower=1, FlavorBias=[30, 1, 1], CylinderRadius=600 * I3Units.m, CylinderHeight=1200 * I3Units.m, CrossSections='csms', ): r""" Select a neutrino to interact, and add neutrino propagators to the context. :param AutoExtendMuonVolume: allow :math:`\nu_{\mu}` to interact far before they reach the detector :param EnergyBiasPower: select a neutrino from the bundle with probability proportional to E^power :param FlavorBias: scale selection probability for :math:`\nu_{e}/\nu_{\mu}/\nu_{\tau}` by these factors. The default value is appropriate for equal sampling of conventional atmospheric :math:`\nu_{e}/\nu_{\mu}`. :param CylinderRadius: radius of upright-cylinder target volume :param CylinderHeight: full height of simulation volume :param CrossSections: cross-section tables to use ('cteq5', 'css', or 'csms') """ from operator import add from icecube import neutrino_generator, sim_services, MuonGun # Set up NeutrinoGenerator internals random = tray.context['I3RandomService'] #surface = MuonGun.Cylinder(CylinderHeight, CylinderRadius) surface = phys_services.Cylinder(CylinderHeight, CylinderRadius) config = neutrino_generator.Steering() config.detection_surface = surface config.do_muon_range_extension = AutoExtendMuonVolume interactions = neutrino_generator.I3NuGInteractionInfo( random, config, CrossSections) interactions.initialize() # I3NuGSourceSelector needs this in its context tray.context['NuGSteer'] = config # Remove all but one neutrino tray.Add('I3NuGSourceSelector', EnergyBiasPowerIndex=EnergyBiasPower, ParticleBiases=reduce(add, [[b] * 2 for b in FlavorBias]), KeepDarkNeutrinos=False) # Store propagators in the context if not 'I3ParticleTypePropagatorServiceMap' in tray.context: tray.context[ 'I3ParticleTypePropagatorServiceMap'] = sim_services.I3ParticleTypePropagatorServiceMap( ) Propagators = tray.context['I3ParticleTypePropagatorServiceMap'] # Use NeutrinoPropagator for neutrinos prop = neutrino_generator.I3NeutrinoPropagator(random, config, interactions) # ensure that all nu_e and nu_mu reach the detector prop.prop_mode = neutrino_generator.PropagationMode.ncgrweighted tau_prop = neutrino_generator.I3NeutrinoPropagator(random, config, interactions) # un-weighted propagation for nu_tau to allow for tau regeneration tau_prop.prop_mode = neutrino_generator.PropagationMode.nopropweight for flavor in 'E', 'Mu', 'Tau': for ptype in '', 'Bar': Propagators[getattr(dataclasses.I3Particle.ParticleType, 'Nu' + flavor + ptype)] = tau_prop if flavor == 'Tau' else prop
def GenerateNeutrinos( tray, name, RandomService=None, RunID=None, NumEvents=100, SimMode='Full', VTXGenMode='NuGen', # currently only NuGen is supported InjectionMode='Surface', CylinderParams=[ 0, 0, 0, 0, 0 ], # CIRCLE[radius, active_height_before, active_height_after] SURFACE[radius, length, center_x, center_y, center_z] AutoExtendMuonVolume=True, Flavor="", # if it is set, I3NuGInjector is used. NuTypes=["NuMu", "NuMuBar" ], # if it is set, I3NuGDiffuseSource is used. PrimaryTypeRatio=[1, 1], GammaIndex=2.0, FromEnergy=1. * I3Units.TeV, ToEnergy=10. * I3Units.PeV, ZenithRange=[0, 180 * I3Units.degree], AzimuthRange=[0, 360 * I3Units.degree], UseDifferentialXsection=True, # set true if you use differential cross section CrossSections='csms_differential_v1.0', # CrossSectionsPath=None, ZenithSamplingMode='ANGEMU', ParamsMap=dict()): #----------------------------- # parameter check #----------------------------- if Flavor == "" and len(NuTypes) == 0: raise Exception('Need to set Flavor or NuTypes.') #----------------------------- # icetray start #----------------------------- from I3Tray import I3Units from icecube import icetray, dataclasses, dataio, phys_services, sim_services from icecube import neutrino_generator, MuonGun earthModelService = name + "_earthmodel" steering = name + "_steering" injector = name + "_injector" interactions = name + "_interactions" #----------------------------- # make ParamMap's key lowercase and # check multiple definitions. #----------------------------- params = dict() for key in ParamsMap: keylower = key.lower() if keylower in params: raise Exception('param %s is set twice!' % (keylower)) params[keylower] = ParamsMap[key] #----------------------------- # configure earthmodel service #----------------------------- earthModelServiceArgs = dict() if "earthmodels" in params: if not isinstance(params["earthmodels"], (list, tuple)): raise Exception('EarthModels must be a list of strings') earthModelServiceArgs['EarthModels'] = params["earthmodels"] if "materialmodels" in params: if not isinstance(params["materialmodels"], (list, tuple)): raise Exception('MaterialModels must be a list of strings') earthModelServiceArgs['MaterialModels'] = params["materialmodels"] if "earthparamspath" in params: params["earthparamspath"] = str(params["earthparamspath"]) earthModelServiceArgs['PathToDataFileDir'] = params["earthparamspath"] if "icecaptype" in params: params["icecaptype"] = str(params["icecaptype"]) earthModelServiceArgs['IceCapType'] = params["icecaptype"] if "icecapsimpleangle" in params: if not isinstance(params["icecapsimpleangle"], float): raise Exception('IceCapType must be a float') earthModelServiceArgs['IceCapSimpleAngle'] = params[ "icecapsimpleangle"] if "detectordepth" in params: if not isinstance(params["detectordepth"], float): raise Exception('DetectorDepth must be a float') earthModelServiceArgs['DetectorDepth'] = params["detectordepth"] tray.AddService("I3EarthModelServiceFactory", earthModelService, **earthModelServiceArgs) #----------------------------- # configure steering factory #----------------------------- # this is default cylinder. If you want to change cylinder size # and cylinder center, set positive value to CylinderParams. surface = phys_services.Cylinder(1900 * I3Units.m, 950 * I3Units.m) #surface = MuonGun.Cylinder(1900*I3Units.m, 950*I3Units.m) steeringServiceArgs = dict() steeringServiceArgs['MCTreeName'] = 'I3MCTree_preMuonProp' steeringServiceArgs['NEvents'] = NumEvents steeringServiceArgs['SimMode'] = SimMode steeringServiceArgs['VTXGenMode'] = VTXGenMode steeringServiceArgs['InjectionMode'] = InjectionMode steeringServiceArgs['DetectionSurface'] = surface steeringServiceArgs['CylinderParams'] = CylinderParams steeringServiceArgs['DoMuonRangeExtension'] = AutoExtendMuonVolume if "globalxsecscalefactor" in params: if not isinstance(params["globalxsecscalefactor"], (list, tuple)): raise Exception('GlobalXsecScaleFactor must be a list of float') steeringServiceArgs['GlobalXsecScaleFactor'] = params[ "globalxsecscalefactor"] if "usesimplescatterform" in params: if not isinstance(params['usesimplescatterform'], int): raise Exception('UseSimpleScatterForm must be an int ') if params['usesimplescatterform'] > 0: steeringServiceArgs['UseSimpleScatterForm'] = True else: steeringServiceArgs['UseSimpleScatterForm'] = False tray.AddService("I3NuGSteeringFactory", steering, EarthModelName=earthModelService, **steeringServiceArgs) #----------------------------- # configure injector #----------------------------- EnergyLogRange = [ math.log10(FromEnergy / I3Units.GeV), math.log10(ToEnergy / I3Units.GeV) ] injectorServiceArgs = dict() injectorServiceArgs['GammaIndex'] = GammaIndex injectorServiceArgs['ZenithMin'] = ZenithRange[0] injectorServiceArgs['ZenithMax'] = ZenithRange[1] injectorServiceArgs['AzimuthMin'] = AzimuthRange[0] injectorServiceArgs['AzimuthMax'] = AzimuthRange[1] injectorServiceArgs['EnergyMinLog'] = EnergyLogRange[0] injectorServiceArgs['EnergyMaxLog'] = EnergyLogRange[1] injectorServiceArgs['AngleSamplingMode'] = ZenithSamplingMode injectorServiceArgs['RandomService'] = RandomService if "zenithweightparam" in params: if not isinstance(params["zenithweightparam"], float): raise Exception('ZenithWeightParam must be a float') injectorServiceArgs['ZenithWeightParam'] = params["zenithweightparam"] if Flavor != "": injectorServiceArgs['NuFlavor'] = Flavor tray.AddService("I3NuGInjectorFactory", injector, SteeringName=steering, **injectorServiceArgs) else: injectorServiceArgs['NuTypes'] = NuTypes injectorServiceArgs['PrimaryTypeRatio'] = PrimaryTypeRatio tray.AddModule("I3NuGDiffuseSource", injector, SteeringName=steering, **injectorServiceArgs) #----------------------------- # configure interaction service #----------------------------- interactionServiceArgs = dict() if CrossSectionsPath is not None: interactionServiceArgs['TablesDir'] = CrossSectionsPath interactionServiceArgs['CrossSectionModel'] = CrossSections if UseDifferentialXsection == True: tray.AddService("I3NuGInteractionInfoDifferentialFactory", interactions, SteeringName=steering, **interactionServiceArgs) else: tray.AddService("I3NuGInteractionInfoFactory", interactions, SteeringName=steering, **interactionServiceArgs) #----------------------------- # configure neutrino generator #----------------------------- nugenArgs = dict() if "primarynuname" in params: params["primarynuname"] = str(params["primarynuname"]) nugenArgs['PrimaryNuName'] = params["primarynuname"] if "interactionweight" in params: if not isinstance(params["interactionweight"], (list, tuple)): raise Exception('InteractionWeight must be a list of float') nugenArgs['InteractionCCFactor'] = params["interactionweight"][0] nugenArgs['InteractionNCFactor'] = params["interactionweight"][1] nugenArgs['InteractionGRFactor'] = params["interactionweight"][2] nugenArgs['RandomService'] = RandomService if "propagationweightmode" in params: params["propagationweightmode"] = str(params["propagationweightmode"]) propmode = neutrino_generator.to_propagation_mode( params["propagationweightmode"]) nugenArgs['PropagationWeightMode'] = propmode if RunID is not None: nugenArgs['RunID'] = RunID tray.AddModule("I3NeutrinoGenerator", name + "_neutrino", SteeringName=steering, InjectorName=injector, InteractionInfoName=interactions, **nugenArgs)
#app.files.openLocalFile("./GCD_BigBird.i3") app.files.advanceFrame(5) #app.files.openLocalFile(options.input) #app.files.advanceFrame(2) _dumpScenario() #window.gl.setCameraPivot(7.17023658752, 36.1024436951, -63.2644119263) #window.gl.setCameraLoc(172.551498413, -1770.15148926, 500.825744629) #window.gl.setCameraOrientation(0.995834589005, 0.0911788865924, -4.71844785466e-16) from icecube import phys_services from icecube import dataclasses from icecube.icetray import I3Units import numpy as np cylinder = phys_services.Cylinder(1000, 625) bestfit = frame["OnlineL2_SplineMPE"].dir zenith = bestfit.zenith * 180. / 3.14 azimuth = bestfit.azimuth * 180. / 3.14 x = frame["OnlineL2_SplineMPE"].pos.x y = frame["OnlineL2_SplineMPE"].pos.y z = frame["OnlineL2_SplineMPE"].pos.z adir = dataclasses.I3Direction(zenith * I3Units.deg, azimuth * I3Units.deg) vtx = dataclasses.I3Position(x * I3Units.m, y * I3Units.m, z * I3Units.m) intercept = cylinder.intersection(vtx, adir) centre = dataclasses.I3Position(((intercept.second * adir + vtx).x + (intercept.first * adir + vtx).x) / 2., ((intercept.second * adir + vtx).y + (intercept.first * adir + vtx).y) / 2., ((intercept.second * adir + vtx).z +
def setUp(self): self.length = 100 self.radius = 200 self.surface = phys_services.Cylinder(self.length, self.radius)