def testCheckVolume(): print "*************** Testing neutrinos *******************" tray = I3Tray() tray.AddModule('I3Reader', 'reader', FilenameList=["/afs/ifh.de/user/c/clozano/lustre/Datasets/Phase1/GCDs/GeoCalibDetectorStatus_ICUpgrade.v53.mixed.V0.i3.bz2","/afs/ifh.de/user/c/clozano/lustre/Datasets/Phase1/results/dataset_with_cuts_15_02_19/nu_simulation/mixed/1251/genie_ICU_v53_mixed.1251.000042_output.i3.bz2"]) tray.Add(check_volume, "testcoincify", Streams = [icetray.I3Frame.DAQ,icetray.I3Frame.Physics]) tray.Add('I3Writer', Filename = "test_nu.i3", Streams = [icetray.I3Frame.DAQ, icetray.I3Frame.Physics] ) tray.Execute(100) tray.Finish() del tray print "*************** Testing muons *******************" tray = I3Tray() tray.AddModule('I3Reader', 'reader', FilenameList=["/afs/ifh.de/user/c/clozano/lustre/Datasets/Phase1/GCDs/GeoCalibDetectorStatus_ICUpgrade.v53.mixed.V0.i3.bz2", "/afs/ifh.de/user/c/clozano/lustre/Datasets/Phase1/results/dataset_with_cuts_15_02_19/muongun/mixed/MuonGun_ICUpgrade.v53.mixed.001351.000985_output.i3.bz2"]) tray.Add(check_volume, "testcoincify", Streams = [icetray.I3Frame.DAQ,icetray.I3Frame.Physics]) tray.Add('I3Writer', Filename = "test_muons.i3", Streams = [icetray.I3Frame.DAQ, icetray.I3Frame.Physics] ) tray.Execute(100) tray.Finish() del tray
def extract_i3_file_gcd_diff(url, baseline_gcd, stop_after_first_p_frame=True): frame_packet = [] if stop_after_first_p_frame: SuspendAfterStop = icetray.I3Frame.Physics else: SuspendAfterStop = None icetray.set_log_level_for_unit('I3Tray', icetray.I3LogLevel.LOG_WARN) tray = I3Tray() tray.Add("I3Reader", "reader", FilenameList=[url]) if baseline_gcd is not None: tray.Add(compress, "GCD_diff", base_filename=baseline_gcd, base_path=config.base_GCD_path) tray.Add(FrameArraySink, "FrameArraySink", FrameStore=frame_packet, SuspendAfterStop=SuspendAfterStop) tray.Execute() del tray icetray.set_log_level_for_unit('I3Tray', icetray.I3LogLevel.LOG_NOTICE) return frame_packet
def main(): """Script to run Retro recos in icetray""" parser = ArgumentParser() parser.add_argument( "--input-i3-file", type=str, required=True, nargs="+", help="""Input I3 file""", ) parser.add_argument( "--output-i3-file", type=str, required=True, help="""Output I3 file""", ) split_kwargs = init_obj.parse_args(dom_tables=True, tdi_tables=True, parser=parser) other_kw = split_kwargs.pop("other_kw") # instantiate Retro reco object my_reco = Reco(**split_kwargs) tray = I3Tray() tray.AddModule( _type="I3Reader", _name="reader", FilenameList=other_kw["input_i3_file"], ) tray.Add( _type=my_reco, _name="retro", methods="crs_prefit", reco_pulse_series_name="SRTTWOfflinePulsesDC", hit_charge_quant=0.05, min_hit_charge=0.25, seeding_recos=["L5_SPEFit11", "LineFit_DC"], triggers=["I3TriggerHierarchy"], additional_keys=["L5_oscNext_bool"], filter='event["header"]["L5_oscNext_bool"] and len(event["hits"]) >= 8', point_estimator="median", ) tray.AddModule( _type="I3Writer", _name="writer", DropOrphanStreams=[icetray.I3Frame.DAQ], filename=other_kw["output_i3_file"], ) tray.AddModule(_type="TrashCan", _name="GoHomeYouReDrunk") tray.Execute() tray.Finish()
def harvest_detector_parameters(GCDFile): from icecube import dataio, dataclasses from I3Tray import I3Tray tray = I3Tray() tray.Add(dataio.I3Reader, Filenamelist=[GCDFile]) # make sure the geometry is updated to the new granular format tray.AddModule("I3GeometryDecomposer", If=lambda frame: ("I3OMGeoMap" not in frame) and ("I3ModuleGeoMap" not in frame)) def pluck_geo(frame): pluck_geo.frame = frame pluck_geo.frame = None tray.Add(pluck_geo, Streams=[icetray.I3Frame.Geometry]) def pluck_calib(frame): pluck_calib.frame = frame pluck_calib.frame = None tray.Add(pluck_calib, Streams=[icetray.I3Frame.Calibration]) tray.Execute() if CableOrientation: icetray.logging.log_warn( "Explicitly simulating cable shadow. This will reduce overall DOM efficiency by ~10%.", unit="clsim") pluck_geo.frame['CableShadow'] = GetIceCubeCableShadow( CableOrientation) if isinstance(CableOrientation, str) else CableOrientation geometry = clsim.I3CLSimSimpleGeometryFromI3Geometry( DOMRadius, DOMOversizeFactor, pluck_geo.frame, ignoreSubdetectors=dataclasses.ListString(IgnoreSubdetectors), # NB: we trust advanced users to properly label subdetectors, and disable any # min/max string/om numbers and strings/oms to ignore ignoreStrings=dataclasses.ListInt(), ignoreDomIDs=dataclasses.ListUInt(), ignoreStringIDsSmallerThan=1, ignoreStringIDsLargerThan=numpy.iinfo(numpy.int32).max, ignoreDomIDsSmallerThan=1, ignoreDomIDsLargerThan=numpy.iinfo(numpy.uint32).max, splitIntoPartsAccordingToPosition=False, useHardcodedDeepCoreSubdetector=False) rde = dict() spe_compensation_factor = dict() for k, domcal in pluck_calib.frame['I3Calibration'].dom_cal.iteritems( ): rde[k] = domcal.relative_dom_eff comp = domcal.combined_spe_charge_distribution.compensation_factor spe_compensation_factor[k] = comp if not math.isnan(comp) else 1. return geometry, rde, spe_compensation_factor
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() 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 the Tray tray.Execute() summary = tray.context['I3SummaryService'] save_stats(tray, summary, stats) WriteI3Summary(summary, self.summaryfile) del tray return 0
def book_weights(infiles, outfile, model='Hoerandel5_atmod12_SIBYLL'): tray = I3Tray() tray.AddModule('I3Reader', 'reader', filenamelist=infiles) tray.AddModule( lambda frame: frame.Put('MCPrimary', frame['I3MCTree'].primaries[0]), Streams=[icetray.I3Frame.DAQ]) tray.AddModule(lambda frame: frame.Put('Muon', frame['I3MCTree'][1]), Streams=[icetray.I3Frame.DAQ]) model = MuonGun.load_model(model) generator = harvest_generators(infiles) tray.AddModule('I3MuonGun::WeightCalculatorModule', 'MuonWeight', Model=model, Generator=generator) from icecube.hdfwriter import I3SimHDFWriter tray.AddSegment(I3SimHDFWriter, 'scribe', Output=outfile, Keys=[ 'MCPrimary', 'Muon', 'MuonWeight', dict(key='I3MCTree', name='BundleParameters', converter=MuonGun.converters.MuonBundleConverter( 1, generator.surface)) ], Types=[]) tray.Execute()
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) infile = cfg['infile_pattern'].format(**cfg) infile = infile.replace(' ', '0') tray = I3Tray() tray.context['I3FileStager'] = dataio.get_stagers() random_service, _, run_id = create_random_services( dataset_number=cfg['dataset_number'], run_number=cfg['run_number'], seed=cfg['seed']) tray.context['I3RandomService'] = random_service tray.Add('I3Reader', FilenameList=[cfg['gcd_pass2'], infile]) if run_number < cfg['det_pass2_keep_all_upto']: cfg['det_keep_mc_hits'] = True cfg['det_keep_propagated_mc_tree'] = True cfg['det_keep_mc_pulses'] = True tray.AddSegment(segments.DetectorSim, "Detector5Sim", RandomService='I3RandomService', RunID=run_id, GCDFile=cfg['gcd_pass2'], KeepMCHits=cfg['det_keep_mc_hits'], KeepPropagatedMCTree=cfg['det_keep_propagated_mc_tree'], KeepMCPulses=cfg['det_keep_mc_pulses'], SkipNoiseGenerator=cfg['det_skip_noise_generation'], LowMem=cfg['det_low_mem'], InputPESeriesMapName=MCPE_SERIES_MAP, BeaconLaunches=cfg['det_add_beacon_launches'], FilterTrigger=cfg['det_filter_trigger']) if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace(' ', '0') print(outfile) print(cfg['outfile_pattern']) tray.AddModule("I3Writer", "EventWriter", filename=outfile, Streams=[ icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.TrayInfo, icetray.I3Frame.Simulation ]) tray.AddModule("TrashCan", "the can") tray.Execute() tray.Finish()
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) if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace(' ', '0') click.echo('Run: {}'.format(run_number)) click.echo('ParticleType: {}'.format(cfg['particle_type'])) click.echo('Outfile: {}'.format(outfile)) click.echo('n_events_per_run: {}'.format(cfg['n_events_per_run'])) click.echo('smearing_angle: {}'.format(cfg['smearing_angle'])) click.echo('skymap_path: {}'.format(cfg['skymap_path'])) tray = I3Tray() random_services, _ = create_random_services( dataset_number=cfg['dataset_number'], run_number=cfg['run_number'], seed=cfg['seed'], n_services=2) tray.AddModule( 'I3InfiniteSource', 'source', # Prefix=gcdfile, Stream=icetray.I3Frame.DAQ) tray.AddModule(ParticleFactory, 'make_particles', particle_type=cfg['particle_type'], map_filename=cfg['skymap_path'], num_events=cfg['n_events_per_run'], smearing_angle=cfg['smearing_angle'] * I3Units.deg, random_state=cfg['seed'], random_service=random_services[0]) tray.AddSegment(segments.PropagateMuons, 'propagate_muons', RandomService=random_services[1], InputMCTreeName='I3MCTree', **cfg['muon_propagation_config']) tray.AddModule('I3Writer', 'write', Filename=outfile, Streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Stream('M')]) tray.AddModule('TrashCan', 'trash') tray.Execute() tray.Finish() del tray
def run(hook=lambda tray: None): tray = I3Tray() tray.Add("I3InfiniteSource", Stream=icetray.I3Frame.Physics) tray.Add(thing3, "thing3") tray.Add(thing2, "thing2") tray.Add(thing1, "thing1") hook(tray) tray.Execute(1)
def main(): """ plot steamshovel-like eventdisplay with matplotlib """ parser = argparse.ArgumentParser( description='Input i3 file and output matplotlib evdisplay') parser.add_argument('-i', '--infile', nargs='+') parser.add_argument('-g', '--grid', default=False, action='store_true') parser.add_argument('-d', '--det', default=False, action='store_true') parser.add_argument('-c', '--coord', default=False, action='store_true') parser.add_argument('-N', '--nframes', type=int, default=None, help='number of frames to process') parser.add_argument('-p', '--pulse', type=str, default='OfflinePulsesHLC', help='specify the pulse type (default SplitInIcePulses)') parser.add_argument('--xlim', nargs=2, default=(None,None), type=float, help='(xlow, xup)') parser.add_argument('--ylim', nargs=2, default=(None,None), type=float, help='(ylow, yup)') parser.add_argument('--zlim', nargs=2, default=(-600, 500), type=float, help='(zlow, zup)') parser.add_argument('--tlim', nargs=2, default=(-np.inf, np.inf), type=float, help='(tlow, tup)') parser.add_argument('--particle', nargs=7, default=(None, None, None, None, None, None, None), type=float, help='(x,y,z,t,zen,azi,topo) topo=0 cascade, 1 track, 2 hybrid') parser.add_argument('--step', default=10, type=float, help='nodes for particle, cherenkov bubbles placed here') parser.add_argument('-s', '--scaling', default=0.1, type=float, help='factor to scale down qtot by for bubble size') parser.add_argument('--linearsfn', default=False, action='store_true', help='plot bubble size linearly with DOM qtot') parser.add_argument('--cmap', default='jet_r') parser.add_argument('--depthshade', default=False, action='store_true') parser.add_argument('--cherenkov', default=False, action='store_true', help='draw cherenkov sphere') parser.add_argument('--view', nargs=2, default=(None,None), type=float, help='Passed to ax.view_init for initial elev and azimuth angle') parser.add_argument('--llhout', default=None, help='Path to DF llh 10 output file to show vertex convergence') args = parser.parse_args() tray = I3Tray() tray.Add('I3Reader', Filenamelist=args.infile) tray.Add(draw_event, draw_grid=args.grid, draw_detector=args.det, draw_coord=args.coord, pulse=args.pulse, xlim=args.xlim, ylim=args.ylim, zlim=args.zlim, tlim=args.tlim, particle=Particle(*args.particle), scaling=args.scaling, linearsfn=args.linearsfn, cmap=args.cmap, depthshade=args.depthshade, cherenkov=args.cherenkov, step=args.step, view=args.view, llhout=args.llhout) if args.nframes is None: tray.Execute() else: tray.Execute(args.nframes) tray.Finish()
def setUp(self): self.tray = I3Tray() def add_frame_object(frame): # any frame object will do frame["FrameObject"] = icetray.OMKey(21, 30) self.tray.AddModule("BottomlessSource") self.tray.AddModule(add_frame_object)
def _run_on(self, files): try: tray = I3Tray() tray.AddModule("I3Reader", "reader", filenamelist=files) tray.AddModule(AllframesModule, "All", filenamelist=files) tray.Execute() tray.Finish() except NotEqualError as e: self.fail(e.message)
def generate(nevents=1, fname='foo.i3'): tray = I3Tray() generator = MuonGun.Floodlight() # set up a random number generator randomService = phys_services.I3SPRNGRandomService(seed=1, nstreams=10000, streamnum=1) tray.context['I3RandomService'] = randomService def make_particle(): p = dataclasses.I3Particle() p.pos = dataclasses.I3Position(0, 0, 2e3) p.dir = dataclasses.I3Direction(0, 0) p.time = 0 p.energy = 10**randomService.Uniform(3, 6) p.type = p.DeltaE p.location_type = p.InIce return p make_particle.i = 0 def make_mctree(frame): mctree = dataclasses.I3MCTree() primary = make_particle() primary.location_type = primary.Anywhere primary.type = primary.unknown muon = make_particle() mctree.add_root(primary) mctree.append_child(primary, muon) frame['I3MCTree'] = mctree tray.AddSegment(GenerateBundles, 'BundleGen', Generator=generator, NEvents=nevents, GCDFile=gcd) def stash(frame): frame['RemadeMCTree'] = dataclasses.I3MCTree(frame['I3MCTree']) tray.AddModule(stash, 'copy', Streams=[icetray.I3Frame.DAQ]) tray.AddModule('I3PropagatorModule', 'propagator', PropagatorServices=make_propagators(), RandomService=randomService, RNGStateName="RNGState") tray.AddModule('I3Writer', 'writer', Streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Physics], filename=fname) tray.Execute(nevents + 3)
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) infile = cfg['infile_pattern'].format(**cfg) infile = infile.replace(' ', '0') if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace(' ', '0') tray = I3Tray() """The main script""" tray.AddModule('I3Reader', 'i3 reader', FilenameList=[cfg['gcd'], infile]) #-------------------------------------------------- # Mask Pulses #-------------------------------------------------- tray.AddModule(get_valid_pulse_map, 'get_valid_pulse_map', pulse_key=cfg['DNN_pulse_key'], excluded_doms=cfg['DNN_excluded_doms'], partial_exclusion=cfg['DNN_partial_exclusion'], verbose=True, If=lambda f: cfg['DNN_pulse_key'] in f) #-------------------------------------------------- # Apply DNN_reco #-------------------------------------------------- tray.AddModule( DeepLearningReco, 'DeepLearningReco', PulseMapString=cfg['DNN_pulse_key'] + '_masked', OutputBaseName=cfg['DNN_output_base_name'], DNNModel=cfg['DNN_model'], DNNModelDirectory=cfg['DNN_model_directory'], MeasureTime=cfg['DNN_measure_time'], ParallelismThreads=cfg['resources']['cpus'][cfg['step']], ) tray.AddModule("I3Writer", "EventWriter", filename=outfile, Streams=[ icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.TrayInfo, icetray.I3Frame.Simulation ], DropOrphanStreams=[icetray.I3Frame.DAQ]) tray.Execute() del tray
def main(): parser = argparse.ArgumentParser( description='This program extracts hits from a pulse series into a text file') parser.add_argument('inp', nargs='+', help='input files') parser.add_argument('-g', '--gcd', type=str, default=None, help='GCD file') parser.add_argument('-o', '--outdir', type=str, default='dats', help='output directory') parser.add_argument('-P', '--preserve', default=False, action='store_true', help='use the input filename as part of the outdir instead of eventid.runid') parser.add_argument('-p', '--pulses', type=str, default=None, help='specify the pulse series to process, defaults to output of TopologicalSplitter') parser.add_argument('-r', '--residual', type=float, default=None, help='specify the residual time after the median of pulse-series after which pulses are not saved. Default is to save all hits.') parser.add_argument('-w', '--window', type=float, default=np.inf, help='specify the time window length before the med+residual stop time over which pulses are saved. Default is infinite.') parser.add_argument('--raw', type=str, default='InIcePulses', help='specify the Q-frame pulse to process with TopologicalSplitter') parser.add_argument('--ini', type=str, default=None, help='specify key in frame to use as seed for extraction to ini') args = parser.parse_args() flist = sorted(args.inp) for fname in flist: tray = I3Tray() if args.gcd is None: tray.Add('I3Reader', Filename=fname) else: tray.Add('I3Reader', Filenamelist=[args.gcd, fname]) pulses = args.pulses if pulses is None: pulses = 'SplitTopoPulses' tray.Add('I3TopologicalSplitter', InputName=args.raw, OutputName=pulses, Multiplicity=5, TimeWindow=2000*I3Units.ns, TimeCone=500*I3Units.ns, XYDist=300*I3Units.m, ZDomDist=15) if args.preserve: subdir = os.path.splitext(os.path.basename(fname))[0] else: subdir = None tray.Add(extract, pulses=pulses, residual=args.residual, window=args.window, outdir=args.outdir, subdir=subdir, ini=args.ini, If=lambda frame:frame.Has(pulses)) tray.Execute()
def Execute(self,stats): if not ipmodule.ParsingModule.Execute(self,stats): return 0 import random from math import pi from .. import segments random.seed(self.seed) def Generator(frame, FromEnergy = 1*I3Units.TeV, ToEnergy = 1*I3Units.TeV): p = dataclasses.I3Particle() p.energy = random.uniform(FromEnergy, ToEnergy) p.pos = dataclasses.I3Position(0,0,0) zenith = random.uniform(0., pi) azimuth = random.uniform(0., 2*pi) p.dir = dataclasses.I3Direction(zenith, azimuth) p.length = 500 * I3Units.m p.type = dataclasses.I3Particle.ParticleType.MuMinus p.location_type = dataclasses.I3Particle.LocationType.InIce p.time = 0. * I3Units.ns tree = dataclasses.I3MCTree() tree.add_primary(p) frame["I3MCTree_preMuonProp"] = tree # Instantiate a tray tray = I3Tray() tray.AddModule("I3InfiniteSource", Stream=icetray.I3Frame.DAQ) tray.Add(Generator, FromEnergy = self.fromenergy, ToEnergy = self.toenergy, Streams = [icetray.I3Frame.DAQ] ) tray.Add("I3Writer", filename=self.outputfile, Streams=[icetray.I3Frame.TrayInfo, icetray.I3Frame.DAQ, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M')]) # Execute the Tray print(tray) tray.Execute(self.nevents) # Free memory del tray return 0
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) icetray.logging.set_level("WARN") 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']), 'Level2') 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']), 'Level3') outfile = outfile.replace(' ', '0') outfile = outfile.replace('2012_pass2', '2012') print('Outfile != $FINAL_OUT clean up for crashed scripts not possible!') outfile = outfile.replace(' ', '0') outfile = outfile.replace('2012_pass2', '2012') tray = I3Tray() photonics_dir = os.path.join(PHOTON_TABLES, 'SPICEMie') photonics_driver_dir = os.path.join(photonics_dir, 'driverfiles') tray.AddSegment( MuonL3, gcdfile=cfg['gcd'], infiles=infile, output_i3=outfile, output_hd5=None, output_root=None, photonicsdir=photonics_dir, photonicsdriverdir=photonics_driver_dir, photonicsdriverfile=DRIVER_FILE, infmuonampsplinepath=os.path.join(SPLINE_TABLES, 'InfBareMu_mie_abs_z20a10.fits'), infmuonprobsplinepath=os.path.join(SPLINE_TABLES, 'InfBareMu_mie_prob_z20a10.fits'), cascadeampsplinepath=os.path.join(SPLINE_TABLES, 'ems_mie_z20_a10.abs.fits'), cascadeprobsplinepath=os.path.join(SPLINE_TABLES, 'ems_mie_z20_a10.prob.fits')) tray.AddModule("TrashCan", "Bye") tray.Execute() tray.Finish()
def Execute(self, stats): if not ipmodule.IPBaseClass.Execute(self, stats): return 0 import icecube.icetray from I3Tray import I3Tray from icecube import dataio, dataclasses, phys_services inputfile = self.GetParameter('inputfile') outputfile = self.GetParameter('outputfile') # Instantiate a tray tray = I3Tray() # Configure IceTray services summary = dataclasses.I3MapStringDouble() summaryfile = self.GetParameter('summaryfile') if os.path.exists(summaryfile): summary = ReadI3Summary(summaryfile) tray.context['I3SummaryService'] = summary # Configure IceTray modules tray.AddModule("I3Reader", "reader", filenamelist=[inputfile]) tray.AddModule(ModifyEventTime, "mod_mjd", MJD=self.GetParameter('mjd'), MJDSeconds=self.GetParameter('mjdseconds'), MJDNanoSeconds=self.GetParameter('mjdnanoseconds')) tray.AddModule("I3Writer", "writer", filename=outputfile) # Execute the Tray tray.Execute() tray.PrintUsage() summary = tray.context['I3SummaryService'] # Save stats for k in tray.Usage(): stats[str(k.key()) + ":usr"] = k.data().usertime summary[str(k.key()) + ":usr"] = k.data().usertime stats[str(k.key()) + ":sys"] = k.data().systime summary[str(k.key()) + ":sys"] = k.data().systime stats[str(k.key()) + ":ncall"] = k.data().ncall summary[str(k.key()) + ":ncall"] = k.data().ncall WriteI3Summary(summary, summaryfile) # Free memory del tray return 0
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) 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', 'pass2') if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace('Level0.{}'.format(cfg['step']), 'Level2') outfile = outfile.replace(' ', '0') outfile = outfile.replace('2012_pass2', 'pass2') print('Outfile != $FINAL_OUT clean up for crashed scripts not possible!') tray = I3Tray() """The main L1 script""" tray.AddModule('I3Reader', 'i3 reader', FilenameList=[cfg['gcd_pass2'], infile]) tray.AddSegment(OfflineFilter, "OfflineFilter", dstfile=None, mc=True, doNotQify=True, photonicsdir=PHOTONICS_DIR) tray.AddModule("I3Writer", "EventWriter", filename=outfile, Streams=[ icetray.I3Frame.DAQ, icetray.I3Frame.Physics, icetray.I3Frame.TrayInfo, icetray.I3Frame.Simulation, icetray.I3Frame.Stream('m'), icetray.I3Frame.Stream('M') ], DropOrphanStreams=[icetray.I3Frame.DAQ]) tray.AddModule("TrashCan", "the can") tray.Execute() tray.Finish() del tray
def good(fname): try: tray = I3Tray() tray.Add('I3GSLRandomServiceFactory', Seed=1337) tray.Add('I3CORSIKAReader', 'reader', filenamelist=[fname], CheckIntegrity=not opts.detailed) tray.Execute() tray.Finish() except RuntimeError: return False return True
def setUp(self): tray = I3Tray() tray.Add(Generator) tray.Add("I3NullSplitter", "nullsplit", SubEventStreamName='null') tray.Add( hdfwriter.I3HDFWriter, Output='foo.hdf5', Keys=['I3CorsikaInfo', 'I3EventHeader', 'I3MCTree', 'I3MCPrimary'], Types=[], SubEventStreams=["null"], ) tray.Execute()
def write_empty_file(fname): """ Run an I3Tray that emits no frames """ tray = I3Tray() tray.Add("I3InfiniteSource") tray.Add("I3Writer", Streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Physics], DropOrphanStreams=[icetray.I3Frame.DAQ], filename=fname) tray.Execute(1)
def create_dataset(outfile, infiles): """ Creates a dataset in hdf5 format. Parameters: ----------- outfile : str Path to the hdf5 file. paths : dict A list of intput i3 files. """ global event_offset global distances_offset event_offset, distances_offset = 0, 0 infiles = infiles tray = I3Tray() tray.AddModule('I3Reader', FilenameList = infiles) tray.AddModule(process_frame, 'process_frame') tray.AddModule(get_weight_by_flux, 'get_weight_by_flux') tray.AddModule(I3TableWriter, 'I3TableWriter', keys = vertex_features + [ # Meta data 'PDGEncoding', 'InteractionType', 'NumberChannels', 'NeutrinoEnergy', 'CascadeEnergy', 'MuonEnergy', 'TrackLength', 'DeltaLLH', 'DCFiducialPE', 'RunID', 'EventID', # Lookups 'NumberVertices', # Coordinates and pairwise distances 'VertexX', 'VertexY', 'VertexZ', 'COGCenteredVertexX', 'COGCenteredVertexY', 'COGCenteredVertexZ', # Auxilliary targets 'PrimaryX', 'PrimaryY', 'PrimaryZ', 'COGCenteredPrimaryX', 'COGCenteredPrimaryY', 'COGCenteredPrimaryZ', 'PrimaryAzimuth', 'PrimaryZenith', 'PrimaryEnergy', # Reconstruction 'RecoX', 'RecoY', 'RecoZ', 'COGCenteredRecoX', 'COGCenteredRecoY', 'COGCenteredRecoZ', 'RecoAzimuth', 'RecoZenith', # Flux weights 'NuMuFlux', 'NueFlux', 'NoFlux', # Debug stuff 'PrimaryXOriginal', 'PrimaryYOriginal', 'PrimaryZOriginal', 'CMeans', 'COGCenteredCMeans', ], TableService=I3HDFTableService(outfile), SubEventStreams=['TTrigger'], BookEverything=False ) tray.Execute() tray.Finish()
def setUp(self): from icecube import icetray,tableio,dataclasses,hdfwriter from icecube.tableio import I3TableWriter import tempfile from I3Tray import I3Tray, load from icecube import phys_services tray = I3Tray() tray.AddModule("I3InfiniteSource","streams", Stream=icetray.I3Frame.Physics) self.tray = tray self.tempfile = tempfile.NamedTemporaryFile() self.hdf_service = hdfwriter.I3HDFTableService(self.tempfile.name,0) self.target = I3TableWriter self.bookie = DOMLaunchBookie()
def main(output_file="./floodlight.i3.gz", num_events=100, gamma_index=2, energy_offset=1e3, energy_min=1e4, energy_max=1e7, coszen_min=-1., coszen_max=1.): tray = I3Tray() tray.context["I3RandomService"] =\ icecube.phys_services.I3SPRNGRandomService(1, 10000, 1) surface = icecube.MuonGun.Cylinder(length=1600. * icecube.icetray.I3Units.m, radius=800. * icecube.icetray.I3Units.m) spectrum = icecube.MuonGun.OffsetPowerLaw( gamma_index, energy_offset * icecube.icetray.I3Units.GeV, energy_min * icecube.icetray.I3Units.GeV, energy_max * icecube.icetray.I3Units.GeV) # Illuminate IceCube isotropically with muons. generator = icecube.MuonGun.Floodlight(surface, spectrum, coszen_min, coszen_max) tray.AddSegment(icecube.MuonGun.segments.GenerateBundles, "muongun", Generator=generator, NEvents=num_events, GCDFile="") # Calculate effective area. tray.AddModule(effective_area, "effective_area", generator=generator, Streams=[icecube.icetray.I3Frame.DAQ]) tray.AddModule("I3Writer", "writer", filename=output_file, Streams=[icecube.icetray.I3Frame.DAQ]) tray.AddModule("TrashCan", "trash") tray.Execute() tray.Finish() return
def harvest_detector_parameters(GCDFile): from icecube import dataio, dataclasses from I3Tray import I3Tray tray = I3Tray() tray.Add(dataio.I3Reader, Filenamelist=[GCDFile]) # make sure the geometry is updated to the new granular format tray.AddModule("I3GeometryDecomposer", If=lambda frame: ("I3OMGeoMap" not in frame) and ("I3ModuleGeoMap" not in frame)) def pluck_geo(frame): pluck_geo.frame = frame pluck_geo.frame = None tray.Add(pluck_geo, Streams=[icetray.I3Frame.Geometry]) def pluck_calib(frame): pluck_calib.frame = frame pluck_calib.frame = None tray.Add(pluck_calib, Streams=[icetray.I3Frame.Calibration]) tray.Execute() geometry = clsim.I3CLSimSimpleGeometryFromI3Geometry( DOMRadius, DOMOversizeFactor, pluck_geo.frame, ignoreSubdetectors=dataclasses.ListString(IgnoreSubdetectors), # NB: we trust advanced users to properly label subdetectors, and disable any # min/max string/om numbers and strings/oms to ignore ignoreStrings=dataclasses.ListInt(), ignoreDomIDs=dataclasses.ListUInt(), ignoreStringIDsSmallerThan=1, ignoreStringIDsLargerThan=numpy.iinfo(numpy.int32).max, ignoreDomIDsSmallerThan=1, ignoreDomIDsLargerThan=numpy.iinfo(numpy.uint32).max, splitIntoPartsAccordingToPosition=False, useHardcodedDeepCoreSubdetector=False) rde = dict() for k, domcal in pluck_calib.frame['I3Calibration'].dom_cal.iteritems( ): rde[k] = domcal.relative_dom_eff return geometry, rde
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) infile = cfg['infile_pattern'].format(**cfg) infile = infile.replace(' ', '0') if scratch: outfile = cfg['scratchfile_pattern'].format(**cfg) else: outfile = cfg['outfile_pattern'].format(**cfg) outfile = outfile.replace(' ', '0') tray = I3Tray() tray.Add('I3Reader', FilenameList=[cfg['gcd'], infile]) # 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 # -------------------------------------- # Propagate Muons # -------------------------------------- tray.AddSegment( segments.PropagateMuons, "PropagateMuons", RandomService=random_service_prop, **cfg['muon_propagation_config']) 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()
def good(fname): try: tray = I3Tray() tray.Add('I3GSLRandomServiceFactory', Seed=1337) tray.Add('I3CORSIKAReader', 'reader', filenamelist=[fname], CheckIntegrity=not opts.detailed) tray.Add('CORSIKAResampler', 'resample', OverSampling=10, CylinderHeight=1200, CylinderRadius=600) tray.Execute() except RuntimeError: return False return True
def testVeto(): recopulses = "I3RecoPulseSeriesMapGen2" tray = I3Tray() tray.AddModule( 'I3Reader', 'reader', FilenameList=[ "/afs/ifh.de/user/c/clozano/lustre/Datasets/Phase1/GCDs/GeoCalibDetectorStatus_ICUpgrade.v53.mixed.V0.i3.bz2", "/afs/ifh.de/user/c/clozano/lustre/Datasets/Phase1/results/dataset_with_cuts_15_02_19/nu_simulation/mixed/1251/genie_ICU_v53_mixed.1251.000042_output.i3.bz2" ]) tray.Add(MyVeto, "testingveto", Pulses=recopulses, nRows=2) tray.Add('I3Writer', Filename="test.i3", Streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Physics]) tray.Execute(200) tray.Finish() del tray
def main(): test_data_base_dir = os.path.expandvars('$I3_TESTDATA') if not os.path.exists(test_data_base_dir): raise RuntimeError('No test data has been downloaded, yet! '\ 'Type "cd $I3_BUILD; make rsync" to get it!') filename = os.path.join(test_data_base_dir, 'event-viewer', 'Level3aGCD_IC79_EEData_Run00115990.i3') hdf_filename = os.path.join( os.getenv('I3_SRC'), 'CommonVariables', 'resources', 'examples', 'track_characteristics', 'I3TrackCharacteristicsCalculatorSegment_data.hdf') pulses_map_name = 'MaskedOfflinePulses' reco_particle_name = 'MPEFit_SLC' track_cylinder_radius = 150. * I3Units.m print('Calculating track characteristics for "%s" '\ 'pulses and "%s" reco particle within the "%fm" track cylinder '\ 'radius.'%\ (pulses_map_name, reco_particle_name, track_cylinder_radius)) print('Writing HDF output file to "%s".' % (hdf_filename)) tray = I3Tray() tray.AddModule("I3Reader", "reader", Filename=filename) tableio_keys_to_book = [] tableio_keys_to_book +=\ tray.AddSegment(track_characteristics.I3TrackCharacteristicsCalculatorSegment, 'tc', PulseSeriesMapName = pulses_map_name, ParticleName = reco_particle_name, OutputI3TrackCharacteristicsValuesName = reco_particle_name+'Characteristics', TrackCylinderRadius = track_cylinder_radius, BookIt = True ) tray.AddSegment(hdfwriter.I3HDFWriter, 'hdfwriter', Keys=tableio_keys_to_book, SubEventStreams=['nullsplit'], Output=hdf_filename) tray.Execute()