def _add_i3_random_service(tray, usegslrng, seed, nstreams, streamnum): if (nstreams is None) or (streamnum is None): #either may be 0 rand = phys_services.I3GSLRandomService(seed=seed) elif usegslrng: rand = phys_services.I3GSLRandomService(seed=seed * nstreams + streamnum) else: rand = phys_services.I3SPRNGRandomService(seed=seed, nstreams=nstreams, streamnum=streamnum) tray.context['I3RandomService'] = rand
def Configure(self,tray): from icecube import icetray, dataclasses, dataio, phys_services, interfaces from .ppc import PPCTraySegment from I3Tray import I3Tray,I3Units from .. import segments if self.propagatemuons: randomServiceForPropagators = phys_services.I3SPRNGRandomService( seed = self.seed, nstreams = self.nproc*2, streamnum = self.nproc + self.procnum)\ if not self.usegslrng else phys_services.I3GSLRandomService(seed = self.seed*self.nproc+self.procnum) tray.context['I3PropagatorRandomService'] = randomServiceForPropagators tray.AddModule("Rename","rename_corsika_mctree",Keys=['I3MCTree','I3MCTree_preMuonProp']) tray.AddSegment(segments.PropagateMuons, 'propagator', RandomService= randomServiceForPropagators, **self.proposalparams ) tray.AddSegment(PPCTraySegment,"ppc_photons", gpu = self.gpu, usegpus = self.usegpus, UnshadowedFraction = self.efficiency, DOMOversizeFactor = self.oversize, IceModelLocation = self.icemodellocation, HoleIceParameterization = self.holeiceparametrization, IceModel = self.icemodel, volumecyl = self.volumecyl, gpulib = self.gpulib, InputMCTree = self.mctreename, keep_empty_events = self.keepemptyevents, MCPESeriesName = self.photonseriesname, tempdir = self.tempdir) if self.runmphitfilter: tray.AddModule("MPHitFilter","hitfilter", HitOMThreshold=1, RemoveBackgroundOnly=False, I3MCPESeriesMapName=self.photonseriesname) if self.enablehistogram and self.histogramfilename: from icecube.production_histograms import ProductionHistogramModule from icecube.production_histograms.histogram_modules.simulation.mcpe_module import I3MCPEModule tray.AddModule(ProductionHistogramModule, Histograms = [I3MCPEModule], OutputFilename = self.histogramfilename) tray.AddModule("I3Writer","writer", filename=self.outputfile, Streams=[icetray.I3Frame.TrayInfo, icetray.I3Frame.DAQ, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M')])
def create_random_services(dataset_number, run_number, seed, n_services=1, use_gslrng=False): from icecube import phys_services, icetray, dataclasses if run_number < 0: raise RuntimeError("negative run numbers are not supported") elif run_number >= MAX_RUN_NUMBER: raise RuntimeError( "run numbers > %u are not supported".format(MAX_RUN_NUMBER)) if dataset_number < 0: raise RuntimeError("negative dataset numbers are not supported") max_run_num = MAX_RUN_NUMBER // 10 int_run_number = dataset_number * max_run_num + run_number random_services = [] for i in range(n_services): streamnum = run_number + (MAX_RUN_NUMBER * i) if use_gslrng: random_services.append( phys_services.I3GSLRandomService( seed=seed * MAX_RUN_NUMBER * n_services + streamnum)) else: random_services.append( phys_services.I3SPRNGRandomService(seed=seed, nstreams=MAX_RUN_NUMBER * n_services, streamnum=streamnum)) return random_services, int_run_number
def Execute(self, stats): 'Runs the tray, but the important stuff happens in segment_X(...)' if not ipmodule.ParsingModule.Execute(self, stats): return 0 # Load libraries from icecube import (earthmodel_service, PROPOSAL, cmc, phys_services) from icecube import (polyplopia, dataclasses, dataio) # support json ParamsMap, so we can get our dict from the iceprod config file try: import json except ImportError: json = None # Instantiate a tray tray = I3Tray() randomService = phys_services.I3SPRNGRandomService( seed = self.seed, nstreams = self.nproc, streamnum = self.procnum)\ if not self.usegslrng else phys_services.I3GSLRandomService(seed) tray.context['I3RandomService'] = randomService # Configure IceTray modules tray.AddModule("I3Reader", "reader", FilenameList=[self.gcdfile, self.inputfile]) from .. import segments from I3Tray import I3Units tray.Add(segments.PolyplopiaMergePEs, "merge", mctype=self.mctype, RandomService=randomService, mctree_name="I3MCTree", bgfile=self.backgroundfile, separate_coincident_mctree_name="BackgroundI3MCTree", timewindow=self.timewindow, rate=5.0 * I3Units.kilohertz) tray.AddModule("I3Writer", "writer", Filename=self.outputfile, Streams=[ icetray.I3Frame.TrayInfo, icetray.I3Frame.DAQ, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M') ]) # Execute the Tray tray.Execute() # Free memory del tray return 0
def Configure(self): self.maskname = self.GetParameter("OutputMaskName") self.filtconfigs = self.GetParameter("FilterConfigs") if self.filtconfigs == None: icetray.logging.log_fatal("No filter configurations provided", "FilterMaskMaker") self.randserv = self.GetParameter("RandomService") if self.randserv == None: icetray.logging.log_info("No random service given, taking a basic one internally", "FilterMaskMaker") from icecube import phys_services self.randserv = phys_services.I3GSLRandomService(13337)
def configure_tray(tray, params, stats, logger): """ Configures the I3Tray instance: adds modules, segments, services, etc. Args: tray (I3Tray): the IceProd tray instance params (dict): command-line arguments (and default values) referenced as dict entries; see add_args() stats (dict): dictionary that collects run-time stats logger (logging.Logger): the logger for this script """ # first check some variables that might need to be set dataset = 0 if params['runid'] is None: runid = int(10**math.ceil(math.log10(params['nproc'])) * dataset + params['procnum']) else: runid = params['runid'] # THE THING tray.AddSegment(segments.GenerateIceTopShowers, "GenerateIceTopShowers", NSamples=params['samples'], Files=params['inputfilelist'], GCDFile=params['gcdfile'], x=params['x'], y=params['y'], r=params['r'] * I3Units.meter, TankResponse=params['tank_response'], TankSamplingRadius=params['tank_sampling_radius'], UnthinRadius=params['unthin_r'], RunID=runid, RaiseObservationLevel=params['raise_observation_level'] * I3Units.m) if params['propagatemuons']: # segments.PropagateMuons requires a random service, I would prefer to use the same one used above. # I could also set the state of randomService to the state of tray.context['I3RandomService'] before running this segment. if params['usegslrng']: randomService = phys_services.I3GSLRandomService( seed=params['seed'] * params['nproc'] + params['procnum']) else: randomService = phys_services.I3SPRNGRandomService( seed=params['seed'], nstreams=params['nproc'], streamnum=params['procnum']) tray.Add('Rename', Keys=['I3MCTree', 'I3MCTree_preMuonProp']) tray.AddSegment(segments.PropagateMuons, "PropagateMuons", RandomService=randomService) tray.AddModule(PrintContext, "ctx") if params['dump']: tray.AddModule("Dump", "dump")
def run_tray(self, cors): from icecube import icetray,phys_services, dataio, dataclasses from .. import segments # Instantiate a tray tray = I3Tray() # Configure IceTray services summary = dataclasses.I3MapStringDouble() tray.context['I3SummaryService'] = summary if self.usegslrng: randomService = phys_services.I3GSLRandomService(self.seed) else: randomService = phys_services.I3SPRNGRandomService(self.seed, self.nproc, self.procnum) tray.context["I3RandomService"] = randomService tray.AddSegment(CorsikaReaderTraySegment, gcdfile=self.gcdfile, randomService=randomService, SimulateIceTop=self.simulateicetop, select_neutrino=self.selectneutrino, legacyoversampling=self.legacyoversampling, oversampling=self.oversampling, cors=cors, stats=self.stats) if self.enablehistogram and self.histogramfilename: from icecube.production_histograms import ProductionHistogramModule from icecube.production_histograms.histogram_modules.simulation.mctree_primary import I3MCTreePrimaryModule tray.AddModule(ProductionHistogramModule, Histograms = [I3MCTreePrimaryModule], OutputFilename = self.histogramfilename) tray.AddModule("I3Writer", filename = self.outputfile, Streams=[icetray.I3Frame.TrayInfo, icetray.I3Frame.DAQ, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M')]) # Execute the Tray tray.Execute() # Save stats summary = tray.context['I3SummaryService'] for k in tray.Usage(): self.stats[str(k.key())+":usr"] = k.data().usertime summary[str(k.key())+":usr"] = k.data().usertime self.stats[str(k.key())+":sys"] = k.data().systime summary[str(k.key())+":sys"] = k.data().systime self.stats[str(k.key())+":ncall"] = k.data().systime summary[str(k.key())+":ncall"] = k.data().systime WriteI3Summary(summary, self.summaryfile)
def dom_simulation(frame, time_shift=10, nhits=n_hits): global hit_times random_service = phys_services.I3GSLRandomService(2) geo = frame["I3Geometry"].omgeo cal = frame["I3Calibration"].dom_cal stat = frame["I3DetectorStatus"].dom_status #DOMLauncher.I3DOM.merge_pulses = True #DOMLauncher.I3DOM.use_tabulation(True) omKey1 = icetray.OMKey(47, 2) dom1 = DOMLauncher.I3InIceDOM(random_service, omKey1) dom1.configure(cal[omKey1], stat[omKey1]) omKey2 = icetray.OMKey(47, 3) dom2 = DOMLauncher.I3InIceDOM(random_service, omKey2) dom2.configure(cal[omKey2], stat[omKey2]) dom1.rapcal_time_shift = 0 dom2.rapcal_time_shift = time_shift #making the doms neigbors dom2.get_neighbors().append(dom1) dom1.get_neighbors().append(dom2) pulses = simclasses.I3MCPulseSeries() pulse = simclasses.I3MCPulse() pulse.charge = 1 pulse.time = 0 for i in range(nhits): pulses.append(pulse) hit_times += [pulse.time] pulse.time += 29e3 triggers = DOMLauncher.DCStream() print("simulating discriminator") dom1.discriminator(pulses, triggers) dom2.discriminator(pulses, triggers) triggers = sorted(triggers, key=lambda t: t.time) i = 0 for trigg in triggers: if (i % 100 == 0): print(trigg.DOM, trigg.time) i += 1 if (trigg.DOM == omKey1): dom1.add_trigger(trigg) elif (trigg.DOM == omKey2): dom2.add_trigger(trigg) print("ending simulation") dom1.trigger_launch(False) dom2.trigger_launch(False) launch_map = dataclasses.I3DOMLaunchSeriesMap() launch_map[dom1.get_omkey()] = dom1.get_domlaunches() launch_map[dom2.get_omkey()] = dom2.get_domlaunches() frame["InIceRawData"] = launch_map
def PropagateMuons( tray, name, RandomService=None, CylinderRadius=1200. * I3Units.m, CylinderLength=1700. * I3Units.m, ): from I3Tray import I3Units from icecube import icetray, dataclasses, phys_services, sim_services, simclasses from icecube import cmc muPropagator = MakePropagator( radius=CylinderRadius, length=CylinderLength, particleType=dataclasses.I3Particle.ParticleType.MuMinus) tauPropagator = MakePropagator( radius=CylinderRadius, length=CylinderLength, particleType=dataclasses.I3Particle.ParticleType.TauMinus) cascadePropagator = cmc.I3CascadeMCService( phys_services.I3GSLRandomService(1)) # dummy RNG # set up propagators propagators = sim_services.I3ParticleTypePropagatorServiceMap() for pt in 'MuMinus', 'MuPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = muPropagator for pt in 'TauMinus', 'TauPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = tauPropagator for pt in 'DeltaE', 'Brems', 'PairProd', 'NuclInt', 'Hadrons', 'EMinus', 'EPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = cascadePropagator tray.AddModule('I3PropagatorModule', name + '_propagator', PropagatorServices=propagators, RandomService=RandomService, RNGStateName="RNGState", InputMCTreeName="I3MCTree_preMuonProp", OutputMCTreeName="I3MCTree") # add empty MMCTrackList objects for events that have none def addEmptyMMCTrackList(frame): if "MMCTrackList" not in frame: frame["MMCTrackList"] = simclasses.I3MMCTrackList() tray.AddModule(addEmptyMMCTrackList, name + '_addEmptyMMCTrackList', Streams=[icetray.I3Frame.DAQ])
def make_propagators(): """ Set up a stable of propagators for all the kinds of particles we're going to see. """ from icecube.PROPOSAL import I3PropagatorServicePROPOSAL from icecube.cmc import I3CascadeMCService propagators = sim_services.I3ParticleTypePropagatorServiceMap() muprop = I3PropagatorServicePROPOSAL(type=dataclasses.I3Particle.MuMinus) cprop = I3CascadeMCService(phys_services.I3GSLRandomService(1)) # dummy RNG for pt in 'MuMinus', 'MuPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = muprop for pt in 'DeltaE', 'Brems', 'PairProd', 'NuclInt', 'Hadrons', 'EMinus', 'EPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = cprop return propagators
def make_propagators(): from icecube.sim_services import I3ParticleTypePropagatorServiceMap from icecube.PROPOSAL import I3PropagatorServicePROPOSAL from icecube.cmc import I3CascadeMCService propagators = I3ParticleTypePropagatorServiceMap() muprop = I3PropagatorServicePROPOSAL(type=dataclasses.I3Particle.MuMinus, cylinderHeight=1200, cylinderRadius=700) cprop = I3CascadeMCService( phys_services.I3GSLRandomService(1)) # dummy RNG for pt in 'MuMinus', 'MuPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = muprop for pt in 'DeltaE', 'Brems', 'PairProd', 'NuclInt', 'Hadrons', 'EMinus', 'EPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = cprop return propagators
def configure_tray(tray, params, stats, logger): """ Configures the I3Tray instance: adds modules, segments, services, etc. Args: tray (I3Tray): the IceProd tray instance params (dict): command-line arguments (and default values) referenced as dict entries; see add_args() stats (dict): dictionary that collects run-time stats logger (logging.Logger): the logger for this script """ if params['propagatemuons']: if params['usegslrng']: randomServiceForPropagators = phys_services.I3GSLRandomService(seed=params['seed'] * params['nproc'] + params['procnum']) else: randomServiceForPropagators = phys_services.I3SPRNGRandomService(seed=params['seed'], nstreams=params['nproc'] * 2, streamnum=params['nproc'] + params['procnum']) tray.context['I3PropagatorRandomService'] = randomServiceForPropagators tray.AddModule("Rename", "rename_corsika_mctree", Keys=['I3MCTree', 'I3MCTree_preMuonProp']) tray.AddSegment(segments.PropagateMuons, 'propagator', RandomService=randomServiceForPropagators, **params['proposalparams']) tray.AddSegment(segments.PPCTraySegment, "ppc_photons", GPU=params['gpu'], UseGPUs=params['usegpus'], UnshadowedFraction=params['efficiency'], DOMOversizeFactor=params['oversize'], IceModelLocation=params['icemodellocation'], HoleIceParameterization=params['holeiceparametrization'], IceModel=params['icemodel'], volumecyl=params['volumecyl'], gpulib=params['gpulib'], InputMCTree=params['mctreename'], keep_empty_events=params['keepemptyevents'], MCPESeriesName=params['photonseriesname'], tempdir=params['tempdir']) if params['runmphitfilter']: tray.AddModule("MPHitFilter", "hitfilter", HitOMThreshold=1, RemoveBackgroundOnly=False, I3MCPESeriesMapName=params['photonseriesname']) if params['enablehistogram'] and params['histogramfilename']: tray.AddModule(ProductionHistogramModule, Histograms=[I3MCPEModule], OutputFilename=params['histogramfilename'])
def ExtractDST13(tray, name, dst_output_filename = "I3DST13.hdf5", dstname = "I3DST13", extract_to_frame = True, If = lambda f: True): """ Record in compact form limited information from reconstructions, triggers and cut parameters for every triggered event. """ from icecube import dst from icecube import phys_services from icecube.tableio import I3TableWriter from . import TDSTConverter # Open output file if dst_output_filename.endswith('.root'): # Open output file from icecube.rootwriter import I3ROOTTableService table_service = I3ROOTTableService(filename= dst_output_filename, master= "dst", #Default name: "MasterTree". #mode=RECREATE, ) elif dst_output_filename.endswith('.hdf5') or dst_output_filename.endswith('.hd5'): from icecube.hdfwriter import I3HDFTableService table_service = I3HDFTableService(dst_output_filename, 6) if "I3RandomService" not in tray.context: dstRng = phys_services.I3GSLRandomService(int(time.time())) tray.context["I3RandomService"]=dstRng tray.AddModule('I3DSTExtractor13', 'UnpackDST', SubEventStreamName = 'TDST13', FileName = dst_output_filename, DSTName = dstname, DSTHeaderName = dstname+"Header", EventHeaderName = 'I3EventHeader', ExtractToFrame = extract_to_frame, TriggerName = 'I3TriggerHierarchy', ) tray.AddModule(I3TableWriter, "writer", TableService = table_service, SubEventStreams= ['TDST13'], Keys = [ "CutDST", "TDSTTriggers"], )
def test_down_sample_MCPE(self): rng = phys_services.I3GSLRandomService(42) self.tray.AddModule("I3DownsampleMCPE", SampleFrac = 0.50, RandomService = rng) def TestModule(frame): self.assertTrue("DownsampledMCPEs" in frame) mcpemap = frame["DownsampledMCPEs"] npes = sum([1 for pe in mcpemap[icetray.OMKey(21,30)]]) self.assertTrue(npes > 400) self.assertTrue(npes < 600) self.tray.AddModule(TestModule, streams = [icetray.I3Frame.DAQ]) self.tray.Execute(1)
def testSLC(self): random_service = phys_services.I3GSLRandomService(1337) key = OMKey(40, 40) cal = self.frame["I3Calibration"].dom_cal stat = self.frame["I3DetectorStatus"].dom_status for charge in range(1, 160): charge = charge / 2. for i in range(0, 30): dom = DOMLauncher.I3InIceDOM(random_service, key) dom.configure(cal[key], stat[key]) pulses = simclasses.I3MCPulseSeries() pulse = simclasses.I3MCPulse() pulse.charge = charge pulse.time = 0 pulses.append(pulse) dcstream = DOMLauncher.DCStream() dom.discriminator(pulses, dcstream) dcstream = sorted(dcstream, key=lambda t: t.time) for trigger in dcstream: dom.add_trigger(trigger) dom.trigger_launch(True) launches = dom.get_domlaunches() for launch in launches: self.assert_(launch.lc_bit == False, "All launches should be SLC") global nLaunches nLaunches += 1 stamp = launch.raw_charge_stamp any_big = False all_even = True for sample in stamp: if sample >= 512: any_big = True if sample % 2 == 1: all_even = False if (any_big): global nBig nBig += 1 if any_big and not all_even: print("Bad SLC readout:", stamp) self.assert_( not any_big or (any_big and all_even), "All samples must be small, or all must be even")
def get_propagators(): """ Set up a stable of propagators for muons, taus, and cascades. """ from icecube import sim_services, phys_services from icecube.PROPOSAL import I3PropagatorServicePROPOSAL from icecube.cmc import I3CascadeMCService propagators = sim_services.I3ParticleTypePropagatorServiceMap() mu_tau_prop = I3PropagatorServicePROPOSAL() cprop = I3CascadeMCService( phys_services.I3GSLRandomService(1)) # dummy RNG for pt in 'MuMinus', 'MuPlus', 'TauMinus', 'TauPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = mu_tau_prop for pt in 'DeltaE', 'Brems', 'PairProd', 'NuclInt', 'Hadrons', 'EMinus', 'EPlus': propagators[getattr(dataclasses.I3Particle.ParticleType, pt)] = cprop return propagators
def Execute(self,stats={}): from .. import segments if not ipmodule.ParsingModule.Execute(self,stats): return 0 from icecube import icetray, dataclasses, dataio, phys_services, interfaces from icecube import corsika_reader from I3Tray import I3Tray,I3Units # Instantiate a tray tray = I3Tray() summary_in = self.summaryfile summary_out = self.summaryfile if not os.path.exists(self.summaryfile): summary_in = '' randomService = phys_services.I3SPRNGRandomService( seed = self.seed, nstreams = self.nproc, streamnum = self.procnum)\ if not self.usegslrng else phys_services.I3GSLRandomService(seed = self.seed*self.nproc+self.procnum) tray.context['I3RandomService'] = randomService inputfiles = self.GetParameter('inputfilelist') # Configure IceTray modules tray.AddModule("I3Reader", "reader",filenamelist=[self.gcdfile]+inputfiles) tray.AddModule("CORSIKAResampler","resample", OverSampling=self.oversampling, CylinderHeight=self.cylinderheight, CylinderRadius=self.cylinderradius) self.Configure(tray) # Execute print(tray) tray.Execute() del tray return 0
def main(config_file, run_number, scratch): with open(config_file, '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) if 'dictitems' in cfg.keys(): cfg = cfg['dictitems'] cfg['run_number'] = run_number cfg['run_folder'] = get_run_folder(run_number) infile = cfg['infile_pattern'].format(**cfg) infile = infile.replace(' ', '0') infile = infile.replace('Level0.{}'.format(cfg['previous_step']), 'Level0.{}'.format(cfg['previous_step'] % 10)) infile = infile.replace('2012_pass2', '2012') if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace('Level0.{}'.format(cfg['step']), 'Level0.{}'.format(cfg['step'] % 10)) outfile = outfile.replace(' ', '0') outfile = outfile.replace('2012_pass2', '2012') print('Outfile != $FINAL_OUT clean up for crashed scripts not possible!') _, seed = create_random_services(dataset_number=cfg['dataset_number'], run_number=cfg['run_number'], seed=cfg['seed'], n_services=0) tray = I3Tray() tray.AddModule('I3Reader', 'reader', FilenameList=[cfg['gcd_2012'], infile], SkipKeys=[ 'I3DST11', 'I3SuperDST', 'I3VEMCalData', 'PoleMuonLlhFit', 'PoleMuonLlhFitCutsFirstPulseCuts', 'PoleMuonLlhFitFitParams', 'CramerRaoPoleL2IpdfGConvolute_2itParams', 'CramerRaoPoleL2MPEFitParams', 'PoleL2IpdfGConvolute_2it', 'PoleL2IpdfGConvolute_2itFitParams', 'PoleL2MPEFit', 'PoleL2MPEFitCuts', 'PoleL2MPEFitFitParams', 'PoleL2MPEFitMuE', ]) class SkipSFrames(icetray.I3ConditionalModule): S_stream = icetray.I3Frame.Stream('S') def __init__(self, context): icetray.I3ConditionalModule.__init__(self, context) def Configure(self): self.Register(self.S_stream, self.SFrame) def SFrame(self, frame): pass # tray.AddModule(SkipSFrames, # "Skip I Frames") def check_driving_time(frame): if 'DrivingTime' not in frame: frame['DrivingTime'] = dataclasses.I3Time( frame['I3EventHeader'].start_time) return True tray.AddModule(check_driving_time, 'DrivingTimeCheck', Streams=[icetray.I3Frame.DAQ]) # move that old filterMask out of the way tray.AddModule("Rename", "filtermaskmover", Keys=["FilterMask", "OrigFilterMask"]) if cfg['L1_2012_qify']: tray.AddModule("QConverter", "qify", WritePFrame=False) def MissingITCheck(frame): #print "Fixing IceTop RO" if "IceTopRawData" not in frame: itrd = dataclasses.I3DOMLaunchSeriesMap() frame["IceTopRawData"] = itrd tray.AddModule(MissingITCheck, 'L1_AddIceTopPulses', Streams=[icetray.I3Frame.DAQ]) if cfg['L1_2012_retrigger']: # some cleanup first tray.AddModule("Delete", "delete_triggerHierarchy", Keys=["I3TriggerHierarchy", "TimeShift"]) gcd_file = dataio.I3File(cfg['gcd_2012']) tray.AddSegment(trigger_sim.TriggerSim, "trig", gcd_file=gcd_file) tray.AddSegment(jeb_filter_2012.BaseProcessing, "BaseProc", pulses=filter_globals.CleanedMuonPulses, decode=False, simulation=True, DomLauncher=(not cfg['L1_2012_dom_simulator'])) tray.AddSegment(jeb_filter_2012.MuonFilter, "MuonFilter", pulses=filter_globals.CleanedMuonPulses, If=which_split(split_name=filter_globals.InIceSplitter)) tray.AddSegment(jeb_filter_2012.CascadeFilter, "CascadeFilter", pulses=filter_globals.CleanedMuonPulses, muon_llhfit_name=filter_globals.muon_llhfit, If=which_split(split_name=filter_globals.InIceSplitter)) tray.AddSegment(jeb_filter_2012.FSSFilter, "FSSFilter", pulses=filter_globals.SplitUncleanedInIcePulses, If=which_split(split_name=filter_globals.InIceSplitter)) tray.AddSegment(jeb_filter_2012.LowUpFilter, "LowUpFilter", If=which_split(split_name=filter_globals.InIceSplitter)) tray.AddSegment(jeb_filter_2012.ShadowFilter, "ShawdowFilters", If=which_split(split_name=filter_globals.InIceSplitter)) # use the PID as a seed. Good enough? tray.AddSegment(jeb_filter_2012.GCFilter, "GCFilter", mcseed=seed, If=which_split(split_name=filter_globals.InIceSplitter)) tray.AddSegment(jeb_filter_2012.VEFFilter, "VEFFilter", pulses=filter_globals.CleanedMuonPulses, If=which_split(split_name=filter_globals.InIceSplitter)) if PHOTONICS_DIR is not None: photonicstabledirmu = os.path.join(PHOTONICS_DIR, 'SPICE1') photonicsdriverfilemu = os.path.join('driverfiles', 'mu_photorec.list') else: photonicstabledirmu = None photonicsdriverfilemu = None tray.AddSegment(jeb_filter_2012.OnlineL2Filter, "OnlineL2", pulses=filter_globals.CleanedMuonPulses, llhfit_name=filter_globals.muon_llhfit, improved_linefit=True, paraboloid=False, PhotonicsTabledirMu=photonicstabledirmu, PhotonicsDriverfileMu_Spice1=photonicsdriverfilemu, If=which_split(split_name=filter_globals.InIceSplitter)) tray.AddSegment(jeb_filter_2012.DeepCoreFilter, "DeepCoreFilter", pulses=filter_globals.SplitUncleanedInIcePulses, If=which_split(split_name=filter_globals.InIceSplitter)) tray.AddSegment(jeb_filter_2012.EHEFilter, "EHEFilter", If=which_split(split_name=filter_globals.NullSplitter)) tray.AddSegment(jeb_filter_2012.MinBiasFilters, "MinBias", If=which_split(split_name=filter_globals.NullSplitter)) tray.AddSegment(jeb_filter_2012.SlopFilters, "SLOP", If=which_split(split_name=filter_globals.NullSplitter)) tray.AddSegment(jeb_filter_2012.FixedRateTrigFilter, "FixedRate", If=which_split(split_name=filter_globals.NullSplitter)) tray.AddSegment(jeb_filter_2012.CosmicRayFilter, "CosmicRayFilter", pulseMask=filter_globals.SplitUncleanedITPulses, If=which_split(split_name=filter_globals.IceTopSplitter)) tray.AddSegment(jeb_filter_2012.DST, "DSTFilter", dstname="I3DST12", pulses=filter_globals.CleanedMuonPulses, If=which_split(split_name=filter_globals.InIceSplitter)) # make random service filter_mask_randoms = phys_services.I3GSLRandomService(seed) # override MinBias Prescale filterconfigs = filter_globals.filter_pairs + filter_globals.sdst_pairs if cfg['L1_min_bias_prescale'] is not None: for i, filtertuple in enumerate(filterconfigs): if filtertuple[0] == filter_globals.FilterMinBias: del filterconfigs[i] filterconfigs.append( (filtertuple[0], cfg['L1_min_bias_prescale'])) break click.echo(filterconfigs) # Generate filter Masks for all P frames tray.AddModule(filter_tools.FilterMaskMaker, "MakeFilterMasks", OutputMaskName=filter_globals.filter_mask, FilterConfigs=filterconfigs, RandomService=filter_mask_randoms) # Merge the FilterMasks tray.AddModule("OrPframeFilterMasks", "make_q_filtermask", InputName=filter_globals.filter_mask, OutputName=filter_globals.qfilter_mask) #Q+P frame specific keep module needs to go first, as KeepFromSubstram #will rename things, let's rename post keep. def is_Q(frame): return frame.Stop == frame.DAQ tray.AddModule( "Keep", "keep_before_merge", keys=filter_globals.q_frame_keeps + [ 'InIceDSTPulses', # keep DST pulse masks 'IceTopDSTPulses', 'CalibratedWaveformRange', # keep calibration info 'UncleanedInIcePulsesTimeRange', 'SplitUncleanedInIcePulsesTimeRange', 'SplitUncleanedInIceDSTPulsesTimeRange', 'CalibrationErrata', 'SaturationWindows', 'InIceRawData', # keep raw data for now 'IceTopRawData', 'CorsikaWeightMap', # sim keys 'I3MCWeightDict', 'MCHitSeriesMap', 'MMCTrackList', 'I3MCTree', 'I3LinearizedMCTree', 'MCPrimary', 'MCPrimaryInfo', 'TimeShift', # the time shift amount 'WIMP_params', # Wimp-sim 'SimTrimmer', # for SimTrimmer flag 'I3MCPESeriesMap', 'I3MCPulseSeriesMap', 'I3MCPulseSeriesMapParticleIDMap', ] + muongun_keys, If=is_Q) tray.AddModule("I3IcePickModule<FilterMaskFilter>", "filterMaskCheckAll", FilterNameList=filter_globals.filter_streams, FilterResultName=filter_globals.qfilter_mask, DecisionName="PassedAnyFilter", DiscardEvents=False, Streams=[icetray.I3Frame.DAQ]) def do_save_just_superdst(frame): if frame.Has("PassedAnyFilter"): if not frame["PassedAnyFilter"].value: return True # <- Event failed to pass any filter. else: return False # <- Event passed some filter else: print "Failed to find key frame Bool!!" return False tray.AddModule( "Keep", "KeepOnlySuperDSTs", keys=filter_globals.keep_nofilterpass + [ 'PassedAnyFilter', 'InIceDSTPulses', 'IceTopDSTPulses', 'SplitUncleanedInIcePulses', 'SplitUncleanedInIcePulsesTimeRange', 'SplitUncleanedInIceDSTPulsesTimeRange', 'CorsikaWeightMap', # sim keys 'I3MCWeightDict', 'MCHitSeriesMap', 'MMCTrackList', 'I3MCTree', 'I3LinearizedMCTree', 'MCPrimary', 'MCPrimaryInfo', 'TimeShift', # the time shift amount 'WIMP_params', # Wimp-sim 'I3MCPESeriesMap', 'I3MCPulseSeriesMap', 'I3MCPulseSeriesMapParticleIDMap', ] + muongun_keys, If=do_save_just_superdst) ## Now clean up the events that not even the SuperDST filters passed on. tray.AddModule("I3IcePickModule<FilterMaskFilter>", "filterMaskCheckSDST", FilterNameList=filter_globals.sdst_streams, FilterResultName=filter_globals.qfilter_mask, DecisionName="PassedKeepSuperDSTOnly", DiscardEvents=False, Streams=[icetray.I3Frame.DAQ]) def dont_save_superdst(frame): if frame.Has("PassedKeepSuperDSTOnly") and frame.Has( "PassedAnyFilter"): if frame["PassedAnyFilter"].value: return False # <- these passed a regular filter, keeper elif not frame["PassedKeepSuperDSTOnly"].value: return True # <- Event failed to pass SDST filter. else: return False # <- Event passed some SDST filter else: print "Failed to find key frame Bool!!" return False # backward compatibility if 'L1_keep_untriggered' in cfg and cfg['L1_keep_untriggered']: discard_substream_and_keys = False else: discard_substream_and_keys = True if discard_substream_and_keys: tray.AddModule("Keep", "KeepOnlyDSTs", keys=filter_globals.keep_dst_only + [ "PassedAnyFilter", "PassedKeepSuperDSTOnly", filter_globals.eventheader ] + muongun_keys, If=dont_save_superdst) ## Frames should now contain only what is needed. now flatten, write/send to server ## Squish P frames back to single Q frame, one for each split: tray.AddModule( "KeepFromSubstream", "null_stream", StreamName=filter_globals.NullSplitter, KeepKeys=filter_globals.null_split_keeps, ) # Keep the P frames for InIce intact #tray.AddModule("KeepFromSubstream","inice_split_stream", # StreamName = filter_globals.InIceSplitter, # KeepKeys = filter_globals.inice_split_keeps + filter_globals.onlinel2filter_keeps, # ) # in_ice_keeps = filter_globals.inice_split_keeps + \ filter_globals.onlinel2filter_keeps in_ice_keeps = in_ice_keeps + [ 'I3EventHeader', 'SplitUncleanedInIcePulses', 'SplitUncleanedInIcePulsesTimeRange', 'SplitUncleanedInIceDSTPulsesTimeRange', 'I3TriggerHierarchy', 'GCFilter_GCFilterMJD' ] tray.AddModule( "Keep", "inice_keeps", keys=in_ice_keeps + muongun_keys, If=which_split(split_name=filter_globals.InIceSplitter), ) tray.AddModule( "KeepFromSubstream", "icetop_split_stream", StreamName=filter_globals.IceTopSplitter, KeepKeys=filter_globals.icetop_split_keeps, ) tray.AddModule("I3IcePickModule<FilterMaskFilter>", "filterMaskCheck", FilterNameList=filter_globals.filters_keeping_allraw, FilterResultName=filter_globals.qfilter_mask, DecisionName="PassedConventional", DiscardEvents=False, Streams=[icetray.I3Frame.DAQ]) ## Clean out the Raw Data when not passing conventional filter def I3RawDataCleaner(frame): if not (('PassedConventional' in frame and frame['PassedConventional'].value == True) or ('SimTrimmer' in frame and frame['SimTrimmer'].value == True)): frame.Delete('InIceRawData') frame.Delete('IceTopRawData') tray.AddModule(I3RawDataCleaner, "CleanErrataForConventional", Streams=[icetray.I3Frame.DAQ]) tray.AddModule("I3Writer", "EventWriter", filename=outfile, Streams=[ icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.TrayInfo, icetray.I3Frame.Stream('S') ]) tray.AddModule("TrashCan", "the can") tray.Execute() tray.Finish()
# It then writes two files: a data file and a configuration file # the configuration file (a LIC file) can be read by LeptonWeighter from I3Tray import * from icecube import icetray, dataio, dataclasses from icecube import phys_services from icecube import LeptonInjector from icecube.icetray import I3Units seed = 15 # create an icetray tray = I3Tray() # Add a random service, an Earth model, and a source of DAQ frames randomService = phys_services.I3GSLRandomService(seed=seed) tray.context["I3RandomService"] = randomService tray.AddService("I3EarthModelServiceFactory", "Earth") tray.AddModule("I3InfiniteSource", "TheSource", Stream=icetray.I3Frame.DAQ) # specify where the cross sections are # alternatively, you can use the test cross sections included in the resources directory xs_folder = "/cvmfs/icecube.opensciencegrid.org/data/neutrino-generator/cross_section_data/csms_differential_v1.0/" # we create a list of injector objects # each of these injectors can have a unique cross sections used injector_list = [] injector_list.append( LeptonInjector.injector( NEvents = 100, FinalType1 = dataclasses.I3Particle.ParticleType.MuMinus,
"DEBUG") icetray.logging.set_level_for_unit("I3CLSimStepToPhotonConverterCUDA", "DEBUG") for i in range(0, args.repeat): DetectorParams = clsim.traysegments.common.setupDetector( GCDFile=args.gcd_file, DOMOversizeFactor=args.oversize, HoleIceParameterization=expandvars( "$I3_SRC/ice-models/resources/models/angsens/as.nominal"), IceModelLocation=expandvars( "$I3_SRC/ice-models/resources/models/spice_3.2.2-for_clsim")) icetray.logging.set_level_for_unit('ppc', 'WARN') rng = phys_services.I3GSLRandomService(0) from icecube.ppc import MakeCLSimPropagator clsimer = clsim.traysegments.common.setupPropagators( rng, DetectorParams, UseCPUs=not args.use_gpus, UseCUDA=args.cuda)[0] #pprint('---> clsim granularity %d, bunch size %d' % (clsimer.workgroupSize, clsimer.maxNumWorkitems)) try: from math import gcd except ImportError: from fractions import gcd lcm = lambda a, b: a * b / gcd(a, b) granularity = int(clsimer.workgroupSize) maxBunchSize = clsimer.maxNumWorkitems
mctree.add_primary(primary) mctree.append_child(primary, daughter) frame["I3MCTree"] = mctree self.PushFrame(frame) self.eventCounter += 1 if self.eventCounter == self.nEvents: self.RequestSuspension() tray = I3Tray() # a random number generator randomService = phys_services.I3GSLRandomService(options.SEED) tray.AddModule("I3InfiniteSource", "streams", Prefix=options.GCDFILE, Stream=icetray.I3Frame.DAQ) tray.AddModule("I3MCEventHeaderGenerator", "gen_header", Year=2009, DAQTime=158100000000000000, RunNumber=1, EventID=1, IncrementEventID=True) tray.AddModule(
def main(): #arguement parser parser = argparse.ArgumentParser( description='Generates muons in IceCube with varying multiplicity') parser.add_argument('--nseed', default=1, type=int, help='seed for randomization') #muongun args parser.add_argument('--model', default='GaisserH4a_atmod12_SIBYLL', type=str) parser.add_argument('--multiplicity', default=1000, type=int, help='Maximum muon bundle multiplcity') parser.add_argument('--emin', default=1e1, type=float, help='Muon min energy (GeV)') parser.add_argument('--emax', default=1e6, type=float, help='Muon max energy (GeV)') parser.add_argument('--nevents', default=100, type=int, help='Number of events') parser.add_argument('--out', default='muongun.i3.gz', help='Output file') parser.add_argument('--runnum', default=1, type=int, help='Run number for this sim') #detector args parser.add_argument( '--gcd', default=os.path.expandvars( '$I3_TESTDATA/sim/GeoCalibDetectorStatus_IC86.55697_corrected_V2.i3.gz' ), type=str, help='gcd file') parser.add_argument( '--no-hybrid', action="store_false", default=False, dest='hybrid', help='do not perform a hybrid simulation (i.e. use clsim only)') parser.add_argument('--use-gpu', action='store_true', default=False, help='simulate using GPUs instead of CPU cores') args = parser.parse_args() #setup muongun parameters gcdFile = args.gcd model = load_model(args.model) model.flux.max_multiplicity = args.multiplicity surface = Cylinder(1600 * I3Units.m, 800 * I3Units.m, dataclasses.I3Position(0, 0, 0)) surface_det = MuonGun.ExtrudedPolygon.from_file(gcdFile) spectrum = OffsetPowerLaw(2, 0 * I3Units.TeV, args.emin, args.emax) #spectrum = OffsetPowerLaw(2.65, 0*I3Units.TeV, args.emin, args.emax) generator = StaticSurfaceInjector(surface, model.flux, spectrum, model.radius) #setup reconstruction parameters icetray.load('VHESelfVeto') pulses = 'InIcePulses' HLCpulses = 'HLCInIcePulses' #setup I3Tray tray = I3Tray() tray.context['I3RandomService'] = phys_services.I3GSLRandomService( seed=args.nseed) #generate events tray.AddSegment(GenerateBundles, 'MuonGenerator', Generator=generator, NEvents=args.nevents, GCDFile=gcdFile) #propagate particles tray.Add(segments.PropagateMuons, 'PropagateMuons', RandomService='I3RandomService', InputMCTreeName="I3MCTree", OutputMCTreeName="I3MCTree") tray.Add(segments.PropagatePhotons, 'PropagatePhotons', RandomService='I3RandomService', HybridMode=args.hybrid, MaxParallelEvents=100, UseAllCPUCores=True, UseGPUs=args.use_gpu) #detector stuff tray.Add(DetectorSim, "DetectorSim", RandomService='I3RandomService', RunID=args.runnum, KeepPropagatedMCTree=True, KeepMCHits=True, KeepMCPulses=True, SkipNoiseGenerator=True, GCDFile=gcdFile, InputPESeriesMapName="I3MCPESeriesMap") #tray.Add(header, streams=[icetray.I3Frame.DAQ]) #tray.Add("I3NullSplitter") #clean the pulses tray.AddModule('I3MuonGun::WeightCalculatorModule', 'Weight', Model=model, Generator=generator) tray.AddModule('I3LCPulseCleaning', 'cleaning', OutputHLC=HLCpulses, OutputSLC='', Input=pulses) #now do the veto from icecube.filterscripts import filter_globals icetray.load("filterscripts", False) icetray.load("cscd-llh", False) tray.Add(find_primary) tray.Add(todet, surface=surface_det) tray.AddModule('HomogenizedQTot', 'qtot_totalDirty', Pulses=pulses, Output='HomogenizedQTotDirty', If=lambda frame: frame.Has('EnteringMuon_0')) tray.AddModule("VHESelfVeto", 'selfveto_3Dirty', VetoThreshold=3, VertexThreshold=3, pulses=pulses, OutputBool="VHESelfVeto_3Dirty", OutputVertexPos="VHESelfVetoVertexPos_3Dirty", OutputVertexTime="VHESelfVetoVertexTime_3Dirty", If=lambda frame: frame.Has('EnteringMuon_0')) tray.AddModule('HomogenizedQTot', 'qtot_totalClean', Pulses=HLCpulses, Output='HomogenizedQTotClean', If=lambda frame: frame.Has('EnteringMuon_0')) tray.AddModule("VHESelfVeto", 'selfveto_3Clean', VetoThreshold=3, VertexThreshold=3, pulses=HLCpulses, OutputBool="VHESelfVeto_3Clean", OutputVertexPos="VHESelfVetoVertexPos_3Clean", OutputVertexTime="VHESelfVetoVertexTime_3Clean", If=lambda frame: frame.Has('EnteringMuon_0')) #tray.Add(printer, If = lambda frame:frame.Has('EnteringMuon_0')) #tray.Add(print_gen, generator=generator) #write everything to file tray.AddModule( 'I3Writer', 'writer', Streams=[ icetray.I3Frame.Physics, #icetray.I3Frame.DAQ ], filename=args.out) tray.Execute() tray.Finish()
print("storing I3Photons") from I3Tray import * from os.path import expandvars import os import sys from icecube import icetray, dataclasses, dataio, phys_services from icecube import clsim # a random number generator try: randomService = phys_services.I3SPRNGRandomService( seed=options.SEED, nstreams=10000, streamnum=options.RUNNUMBER) except AttributeError: randomService = phys_services.I3GSLRandomService( seed=options.SEED * 10000 + options.RUNNUMBER, ) tray = I3Tray() tray.AddModule("I3Reader", "reader", Filename=infile) if options.REMOVEPHOTONDATA: photonSeriesName = None else: photonSeriesName = "PropagatedPhotons" tray.AddSegment( clsim.I3CLSimMakeHits, "makeCLSimHits", GCDFile=options.GCDFILE, PhotonSeriesName=photonSeriesName,
print("Working out CutValues") ## This is just a dumb container. cv = phys_services.I3CutValues() cog_pos = dataclasses.I3Position(0.0, 0.0, 0.0) cv.cog = cog_pos cv.ldir = 500.5 * icetray.I3Units.m cv.ndir = 5 cv.nchan = 55 print("your I3CutValues: %s %.2f %d %d" % (cv.cog, cv.ldir, cv.ndir, cv.nchan)) print("Working out GCDFileService") mytime = dataclasses.I3Time(2010, 158082172000000000) infile = os.path.expandvars( "$I3_TESTDATA/GCD/GeoCalibDetectorStatus_IC86.55697_corrected_V2.i3.gz") my_fs = phys_services.I3GCDFileCalibrationService(infile) my_cal = my_fs.get_calibration(mytime) print("I found calibrations for %d DOMs" % len(my_cal.dom_cal)) print("Working out randoms") rng = phys_services.I3GSLRandomService(31334) print("Please take these 100 rands") print([rng.gaus(0, 1) for x in range(100)])
def test_time_increment(self): print self.frame event_header = self.frame["I3EventHeader"] if self.event_header : time_difference = event_header.start_time - self.event_header.start_time print("%f" % time_difference) print(" %s" % str(event_header.start_time)) print(" %s" % str(self.event_header.start_time)) self.assertNotEqual(time_difference, 0, "TimeRange is not working correctly.") self.event_header = event_header tray = I3Tray() tray.context["I3RandomService"] = phys_services.I3GSLRandomService(1618); gcd_file = expandvars("$I3_TESTDATA/sim/GeoCalibDetectorStatus_2013.56429_V1.i3.gz") tray.AddModule("I3InfiniteSource", prefix=gcd_file, stream=icetray.I3Frame.DAQ) tray.AddModule(frame_setup, Streams = [icetray.I3Frame.DAQ]) tray.AddModule("I3GlobalTriggerSim", I3DOMLaunchSeriesMapNames = ["InIceRawData"], FromTime = dataclasses.I3Time(53005), ToTime = dataclasses.I3Time(53006), FilterMode = False, RunID = 0)
def configure_tray(tray, params, stats, logger): """ Configures the I3Tray instance: adds modules, segments, services, etc. Args: tray (I3Tray): the IceProd tray instance params (dict): command-line arguments (and default values) referenced as dict entries; see add_args() stats (dict): dictionary that collects run-time stats logger (logging.Logger): the logger for this script """ if params['usegslrng']: randomServiceForPropagators = phys_services.I3GSLRandomService( seed=2 * (params['seed'] * params['nproc'] + params['procnum'])) else: randomServiceForPropagators = phys_services.I3SPRNGRandomService( seed=params['seed'], nstreams=params['nproc'] * 2, streamnum=params['nproc'] + params['procnum']) tray.AddModule("I3InfiniteSource", "TheSource", Prefix=params['gcdfile'], Stream=icetray.I3Frame.DAQ) tray.AddModule(DAQCounter, "counter3", nevents=int(params['nevents'])) vnutypes = [] vtyperatio = [] for key in params['nutypes']: vnutypes.append(key) vtyperatio.append(params['nutypes[key]']) tray.AddSegment(segments.GenerateNeutrinos, 'generator', RandomService=tray.context['I3RandomService'], RunID=params['runid'], NumEvents=params['nevents'], SimMode=params['simmode'], VTXGenMode=params['vtxgenmode'], InjectionMode=params['injectionmode'], CylinderParams=params['cylinderparams'], AutoExtendMuonVolume=params['autoextendmuonvolume'], Flavor=params['nuflavor'], NuTypes=vnutypes, PrimaryTypeRatio=vtyperatio, GammaIndex=params['gamma'], FromEnergy=params['fromenergy'], ToEnergy=params['toenergy'], ZenithRange=[params['zenithmin'], params['zenithmax']], AzimuthRange=[params['azimuthmin'], params['azimuthmax']], UseDifferentialXsection=params['usedifferentialxsection'], CrossSections=params['crosssections'], CrossSectionsPath=params['crosssectionspath'], ZenithSamplingMode=params['zenithsamplingmode'], ParamsMap=params['paramsmap']) if params['polyplopia']: tray.AddSegment(segments.PolyplopiaSegment, "coincify", RandomService=tray.context['I3RandomService'], mctype='NuGen', bgfile=params['backgroundfile'], timewindow=40. * I3Units.microsecond, rate=5.0 * I3Units.kilohertz) if params['propagatemuons']: tray.context['I3PropagatorRandomService'] = randomServiceForPropagators tray.AddSegment(segments.PropagateMuons, 'propagator', RandomService=randomServiceForPropagators, **params['proposalparams']) tray.AddModule(BasicCounter, "count_g", Streams=[icetray.I3Frame.DAQ], name="Generated Events", Stats=stats) if params['enablehistogram'] and params['histogramfilename']: tray.AddModule(ProductionHistogramModule, Histograms=[I3MCTreePrimaryModule, I3MCTreeModule], OutputFilename=params['histogramfilename'])
"-g", "--gcd", default=expandvars( '$I3_TESTDATA/GCD/GeoCalibDetectorStatus_IC86.55697_corrected_V2.i3.gz' )) parser.add_argument("outfile", help="save plot to file") args = parser.parse_args() 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(
from I3Tray import I3Tray from icecube import icetray from icecube import dataclasses from icecube import dataio from icecube import phys_services from icecube import simclasses from icecube import DOMLauncher import numpy as np tray = I3Tray() PATH = os.getenv('I3_TESTDATA') + '/GCD/' GCD_FN = PATH + 'GeoCalibDetectorStatus_IC86.55697_corrected_V2.i3.gz' tray.AddModule("I3InfiniteSource", "FrameMaker", Prefix=GCD_FN) random_service = phys_services.I3GSLRandomService(2) def testTiming(frame): global random_service #Choosing an arbitrary DOM that we know exists in the detector configuration. omKey = icetray.OMKey(42, 2) #geo = self.frame["I3Geometry"].omgeo cal = frame["I3Calibration"].dom_cal stat = frame["I3DetectorStatus"].dom_status dom = DOMLauncher.I3InIceDOM(random_service, omKey) dom.configure(cal[omKey], stat[omKey]) import time
def TabulatePhotonsFromSource(tray, name, PhotonSource="cascade", Zenith=0. * I3Units.degree, Azimuth=0. * I3Units.degree, ZCoordinate=0. * I3Units.m, Energy=1. * I3Units.GeV, FlasherWidth=127, FlasherBrightness=127, Seed=12345, NEvents=100, IceModel='spice_mie', DisableTilt=False, Filename="", TabulateImpactAngle=False, PhotonPrescale=1, Axes=None, Directions=None, Sensor='DOM', RecordErrors=False): """ Tabulate the distribution of photoelectron yields on IceCube DOMs from various light sources. The light profiles of the sources are computed from the same parameterizations used in PPC, but like in the direct propagation mode can be computed using GEANT4 instead. The mode of tabulation is controlled primarily by the **PhotonSource** parameter. - *'cascade'* will simulate an electromagnetic cascade of **Energy** GeV at (0, 0, **ZCoordinate**), oriented according to **Zenith** and **Azimuth**. The default coordinate system is spherical and centered the given vertex, with 200 quadratically spaced bins in radius, 36 linear bins in azimuthal angle (only from 0 to 180 degrees by default), 100 linear bins in the cosine of the polar angle, and 105 quadratic bins in time residual w.r.t the direct path from (0, 0, **ZCoordinate**). - *'flasher'* will simulate a 405 nm LED flasher pulse with the given **FlasherWidth** and **FlasherBrightness** settings. The source position and coordinate system are the same as for the 'cascade' case. - *'infinite-muon'* will simulate a "bare" muon of infinite length. The coordinate system is cylindrical and centered on the axis of the muon. Since the muon's position is degenerate with time, the usual parallel distance is replaced by the z coordinate of the closest approach to the detection position, and the starting positions of the simulated muons are sampled randomly (**ZCoordinate** is ignored). There are 100 quadratic bins in perpendicular distance to the source axis, 36 linear bins in azimuthal angle (0 to :math:`\pi` radians), 100 linear bins in z coordinate of closest approach, and 105 quadratic bins in time residual w.r.t. the earliest possible Cherenkov photon. :param PhotonSource: the type of photon source ('cascade', 'flasher', or 'infinite-muon'). :param Zenith: the orientation of the source :param ZCoordinate: the depth of the source :param Energy: the energy of the source (only for cascade tables) :param FlasherWidth: the width of the flasher pulse (only for flasher tables) :param FlasherBrightness: the brightness of the flasher pulse (only for flasher tables) :param Seed: the seed for the random number service :param NEvents: the number of events to simulate :param RecordErrors: record the squares of weights as well (useful for error bars) :param IceModel: the path to an ice model in $I3_SRC/clsim/resources/ice. Likely values include: 'spice_mie' ppc-style SPICE-Mie parametrization 'photonics_spice_1/Ice_table.spice.i3coords.cos080.10feb2010.txt' Photonics-style SPICE1 table 'photonics_wham/Ice_table.wham.i3coords.cos094.11jul2011.txt' Photonics-style WHAM! table :param DisableTilt: if true, disable tilt in ice model :param Filename: the name of the FITS file to write :param TabulateImpactAngle: if True, tabulate the impact position of the photon on the DOM instead of weighting by the DOM's angular acceptance :param Axes: a subclass of :cpp:class:`clsim::tabulator::Axes` that defines the coordinate system. If None, an appropriate default will be chosen based on **PhotonSource**. :param Directions: a set of directions to allow table generation for multiple sources. If None, only one direction given by **Zenith** and **Azimuth** is used. """ # check sanity of args PhotonSource = PhotonSource.lower() if PhotonSource not in ['cascade', 'flasher', 'infinite-muon']: raise ValueError( "photon source %s is unknown. Please specify either 'cascade', 'flasher', or 'infinite-muon'" % PhotonSource) from icecube import icetray, dataclasses, dataio, phys_services, sim_services, clsim from os.path import expandvars # a random number generator randomService = phys_services.I3GSLRandomService(Seed) tray.AddModule("I3InfiniteSource", name + "streams", Stream=icetray.I3Frame.DAQ) tray.AddModule("I3MCEventHeaderGenerator", name + "gen_header", Year=2009, DAQTime=158100000000000000, RunNumber=1, EventID=1, IncrementEventID=True) if Directions is None: Directions = numpy.asarray([(Zenith, Azimuth)]) if PhotonSource in ('cascade', 'flasher', 'muon-segment'): if PhotonSource == 'muon-segment': ptype = I3Particle.ParticleType.MuMinus else: ptype = I3Particle.ParticleType.EMinus def reference_source(zenith, azimuth, scale): source = I3Particle() source.type = ptype source.energy = Energy * scale source.pos = I3Position(0., 0., ZCoordinate) source.dir = I3Direction(zenith, azimuth) source.time = 0. if PhotonSource == 'muon-segment': source.length = 3. else: source.length = 0. source.location_type = I3Particle.LocationType.InIce return source elif PhotonSource == 'infinite-muon': from icecube import MuonGun # pad depth to ensure that the track appears effectively infinite surface = MuonGun.Cylinder(1800, 800) # account for zenith-dependent distribution of track lengths length_scale = surface.area(dataclasses.I3Direction( 0, 0)) / surface.area(dataclasses.I3Direction(Zenith, 0)) ptype = I3Particle.ParticleType.MuMinus def reference_source(zenith, azimuth, scale): source = I3Particle() source.type = ptype source.energy = Energy * scale source.dir = I3Direction(zenith, azimuth) source.pos = surface.sample_impact_position( source.dir, randomService) crossings = surface.intersection(source.pos, source.dir) source.length = crossings.second - crossings.first source.time = 0. source.location_type = I3Particle.LocationType.InIce return source import copy class MakeParticle(icetray.I3Module): def __init__(self, ctx): super(MakeParticle, self).__init__(ctx) self.AddOutBox("OutBox") self.AddParameter("SourceFunction", "", lambda: None) self.AddParameter("NEvents", "", 100) def Configure(self): self.reference_source = self.GetParameter("SourceFunction") self.nevents = self.GetParameter("NEvents") self.emittedEvents = 0 def DAQ(self, frame): if PhotonSource != "flasher": primary = I3Particle() mctree = I3MCTree() mctree.add_primary(primary) for zenith, azimuth in Directions: source = self.reference_source(zenith, azimuth, 1. / len(Directions)) mctree.append_child(primary, source) frame["I3MCTree"] = mctree # use the emitting particle as a geometrical reference frame["ReferenceParticle"] = source else: pulseseries = I3CLSimFlasherPulseSeries() for zenith, azimuth in Directions: pulse = makeFlasherPulse(0, 0, ZCoordinate, zenith, azimuth, FlasherWidth, FlasherBrightness, 1. / len(Directions)) pulseseries.append(pulse) frame["I3FlasherPulseSeriesMap"] = pulseseries frame["ReferenceParticle"] = self.reference_source( Zenith, Azimuth, 1.) self.PushFrame(frame) self.emittedEvents += 1 if self.emittedEvents >= self.nevents: self.RequestSuspension() tray.AddModule(MakeParticle, SourceFunction=reference_source, NEvents=NEvents) if PhotonSource == "flasher": flasherpulse = "I3FlasherPulseSeriesMap" mctree = None else: flasherpulse = None mctree = "I3MCTree" header = dict(FITSTable.empty_header) header['zenith'] = Zenith / I3Units.degree header['azimuth'] = Azimuth / I3Units.degree header['z'] = ZCoordinate header['energy'] = Energy header['type'] = int(ptype) header['efficiency'] = Efficiency.RECEIVER | Efficiency.WAVELENGTH if PhotonSource == 'infinite-muon': header['n_events'] = length_scale * NEvents / float(PhotonPrescale) if Axes is None: if PhotonSource != "infinite-muon": dims = [ clsim.tabulator.PowerAxis(0, 580, 200, 2), clsim.tabulator.LinearAxis(0, 180, 36), clsim.tabulator.LinearAxis(-1, 1, 100), clsim.tabulator.PowerAxis(0, 7e3, 105, 2), ] geo = clsim.tabulator.SphericalAxes else: dims = [ clsim.tabulator.PowerAxis(0, 580, 100, 2), clsim.tabulator.LinearAxis(0, numpy.pi, 36), clsim.tabulator.LinearAxis(-8e2, 8e2, 80), clsim.tabulator.PowerAxis(0, 7e3, 105, 2), ] geo = clsim.tabulator.CylindricalAxes # Add a dimension for the impact angle if TabulateImpactAngle: dims.append(clsim.tabulator.LinearAxis(-1, 1, 20)) Axes = geo(dims) if PhotonSource == "flasher": header['flasherwidth'] = FlasherWidth header['flasherbrightness'] = FlasherBrightness # some constants DOMRadius = 0.16510 * icetray.I3Units.m # 13" diameter referenceArea = dataclasses.I3Constants.pi * DOMRadius**2 # NB: GetIceCubeDOMAcceptance() calculates the quantum efficiency by # dividing the geometric area (a circle of radius domRadius) by the # tabulated effective area. Scaling that radius by *sqrt(prescale)* # _reduces_ the effective quantum efficiency by a factor *prescale*. # Since we draw photons directly from the QE-weighted Cherenkov # spectrum, this causes *prescale* fewer photons to be progagated per # light source. We compensate by dividing the number of events by # *prescale* in the header above. # to be propagated per light source. domAcceptance = clsim.GetIceCubeDOMAcceptance( domRadius=math.sqrt(PhotonPrescale) * DOMRadius) if Sensor.lower() == 'dom': angularAcceptance = clsim.GetIceCubeDOMAngularSensitivity(holeIce=True) elif Sensor.lower() == 'degg': referenceArea = dataclasses.I3Constants.pi * (300. * I3Units.mm / 2)**2 angularAcceptance = Gen2Sensors.GetDEggAngularSensitivity(pmt='both') domAcceptance = Gen2Sensors.GetDEggAcceptance(active_fraction=1. / PhotonPrescale) elif Sensor.lower() == 'wom': # outer diameter of the pressure vessel is 11.4 cm, walls are 9 mm thick referenceArea = (11 - 2 * 0.9) * 90 * icetray.I3Units.cm2 angularAcceptance = Gen2Sensors.GetWOMAngularSensitivity() domAcceptance = Gen2Sensors.GetWOMAcceptance(active_fraction=1. / PhotonPrescale) else: raise ValueError("Don't know how to simulate %ds yet" % (sensor)) tray.AddSegment( I3CLSimTabulatePhotons, name + "makeCLSimPhotons", MCTreeName= mctree, # if source is a cascade this will point to the I3MCTree FlasherPulseSeriesName= flasherpulse, # if source is a flasher this will point to the I3CLSimFlasherPulseSeries MMCTrackListName=None, # do NOT use MMC ParallelEvents= 1, # only work at one event at a time (it'll take long enough) RandomService=randomService, # UnWeightedPhotons=True, UseGPUs= False, # table-making is not a workload particularly suited to GPUs UseCPUs=True, # it should work fine on CPUs, though Area=referenceArea, WavelengthAcceptance=domAcceptance, AngularAcceptance=angularAcceptance, DoNotParallelize=True, # no multithreading UseGeant4=False, OverrideApproximateNumberOfWorkItems= 1, # if you *would* use multi-threading, this would be the maximum number of jobs to run in parallel (OpenCL is free to split them) ExtraArgumentsToI3CLSimModule=dict(Filename=Filename, TableHeader=header, Axes=Axes, PhotonsPerBunch=200, EntriesPerPhoton=5000, RecordErrors=RecordErrors), MediumProperties=parseIceModel( expandvars("$I3_SRC/clsim/resources/ice/" + IceModel), disableTilt=DisableTilt), )
from I3Tray import I3Tray from icecube.clsim.traysegments.common import setupPropagators, setupDetector, configureOpenCLDevices from icecube.clsim.traysegments.I3CLSimMakePhotons import I3CLSimMakePhotonsWithServer from icecube.ice_models import icewave from icecube.ice_models import angsens_unified from icecube.snowstorm import Perturber, MultivariateNormal, DeltaDistribution, UniformDistribution from icecube.snowstorm import all_parametrizations # Snowstorm parametrizations from icecube import phys_services print("done") # set argparse arguments GCDFile = args.gcdfile InputFiles = args.infile OutputFile = args.outfile RandomService = phys_services.I3GSLRandomService(args.seed) NumEventsPerModel = args.events_per_model SummaryFile = args.summaryfile UseCPUs = args.cpu UseGPUs = not args.cpu DOMOversizeFactor = args.domoversizefactor UseI3PropagatorService = args.UseI3PropagatorService log_level = args.log_level # set icetray logging level log_levels = { "error": icetray.I3LogLevel.LOG_ERROR, "warn": icetray.I3LogLevel.LOG_WARN, "info": icetray.I3LogLevel.LOG_INFO, "debug": icetray.I3LogLevel.LOG_DEBUG, "trace": icetray.I3LogLevel.LOG_TRACE