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 SimIceTop(tray, name, input, output=None, gcd=None, log_level=2, samples=1, tanks=[], x=0.0, y=0.0, r=0.0, seed=0, rng="gsl", injector="normal", response="g4", new=True, pecompress=2, weighted=False, calibrate=False, trigger=False): """ Simulate IceTop response. Input can be a list of CORSIKA files or a tuple of ``(str, kwargs)``, which are passed to ``tray.AddService(str, "particle-injector", **kwargs)`` to create a custom particle injector. RandomServiceName should not be specified, it is overridden internally. The option "weighted" only takes effect if the input are CORSIKA files. """ import os import re from icecube import icetray, dataclasses, dataio from icecube.sim_services.sim_utils.gcd_utils import get_time from icecube.icetray import I3Units custom_injector = False if len(input) == 2 and isinstance(input[0], str) and isinstance(input[1], dict): custom_injector = True if gcd is None: raise ValueError("Need to specify a GCD file") if not os.path.exists(gcd): raise IOError("Specified GCD file does not exist") icetray.set_log_level_for_unit('I3TopSimulator', icetray.I3LogLevel(log_level)) icetray.set_log_level_for_unit('I3CorsikaReader', icetray.I3LogLevel(log_level)) icetray.set_log_level_for_unit('I3CorsikaInjector', icetray.I3LogLevel(log_level)) icetray.set_log_level_for_unit('I3G4TankResponse', icetray.I3LogLevel(log_level)) icetray.set_log_level_for_unit('I3ParamTankResponse', icetray.I3LogLevel(log_level)) # to be used by injector for tag in ("inj", "resp", "other"): if rng == "gsl": tray.AddService("I3GSLRandomServiceFactory", "gslrandom_" + tag, Seed=seed, InstallServiceAs='random_' + tag) elif rng == "root": tray.AddService("I3TRandomServiceFactory", "rootrandom_" + tag, Seed=seed, InstallServiceAs='random_' + tag) elif rng == "sprng": tray.AddService("I3SPRNGRandomServiceFactory", "sprngrandom_" + tag, Seed=seed, NStreams=1, StreamNum=0, InstallServiceAs='random_' + tag) else: raise ValueError("Unknown randon number generator: " + rng) if custom_injector: tray.AddService(input[0], "particle-injector", RandomServiceName = 'random_inj', **input[1]) else: # CORSIKA injector if weighted: if injector == "normal": tray.AddService("I3InjectorFactory<I3CorsikaInjector>", "particle-injector", FileNameList = input, RandomServiceName = 'random_inj', NumSamples = samples, # <-- Number of re-samples of the same shower ImportanceSampling = True, #PartDistr = os.path.join(os.path.dirname(options.output), # 'on_regions_' + os.path.basename(options.output).replace(extension, 'root')), Tanks = tanks, IgnoreParticleTypes = [75, 76, 85, 86, 95, 96] ) else: raise ValueError("option weighted requires normal injector") else: if injector == "normal": tray.AddService("I3InjectorFactory<I3CorsikaInjector>", "particle-injector", FileNameList = input, RandomServiceName = 'random_inj', NumSamples = samples, # <-- Number of re-samples of the same shower RelocationX = x, # <-- x-coordinate of core or resampling center (if Relocation R > 0) RelocationY = y, # <-- y-coordinate or core or resampling center (if Relocation R > 0) RelocationR = r, # <-- Re-sampling radius (if zero --> fixed core location) Tanks = tanks, IgnoreParticleTypes = [75, 76, 85, 86, 95, 96] ) elif injector == "unthin": tray.AddService("I3InjectorFactory<I3CorsikaThinnedInjector>", "particle-injector", FileNameList = input, RandomServiceName = 'random_inj', NumSamples = samples, # <-- Number of re-samples of the same shower RelocationX = x, # <-- x-coordinate of core or resampling center (if Relocation R > 0) RelocationY = y, # <-- y-coordinate or core or resampling center (if Relocation R > 0) RelocationR = r, # <-- Re-sampling radius (if zero --> fixed core location) ) else: raise ValueError("unknown injector option") if response == 'g4': from icecube import g4_tankresponse tray.AddService("I3IceTopResponseFactory<I3G4TankResponse>", "topresponse", RandomServiceName = "random_resp", ChargeScale = 1.02 ) elif response == 'param': tray.AddService("I3IceTopResponseFactory<I3ParamTankResponse>", "topresponse", RandomServiceName = "random_resp", UseSnowParam = True ) else: raise ValueError("Unknown IceTop tank response: " + response) tray.AddModule("I3InfiniteSource", "source", prefix = gcd, stream = icetray.I3Frame.DAQ ) time = get_time(dataio.I3File(gcd)) tray.AddModule("I3MCEventHeaderGenerator","time-gen", Year = time.utc_year, DAQTime = time.utc_daq_time) if new: tray.AddSegment(SimulateNew, 'new_simulation', InjectorServiceName = "particle-injector", ResponseServiceName = "topresponse", RandomServiceName = "random_other", InIceMCTreeName = '', Tanks = tanks, CompressPEs=pecompress ) else: tray.AddSegment(SimulateOld, 'old_simulation', InjectorServiceName = "particle-injector", ResponseServiceName = "topresponse", InIceMCTreeName = '', Tanks = tanks ) if calibrate: from icecube import topsimulator tray.AddSegment(CalibrateAndExtract, 'CalibrateExtract', Launches = 'IceTopRawData', ) tray.AddModule('I3TopAddComponentWaveforms', 'AddComponentWaveforms') if output is not None: # writing of output is requested if output.endswith(".h5") or output.endswith(".root"): # write tables keep_keys = ['I3EventHeader', 'MCTopCherenkovPulses', 'MCTopHitSeriesMap', 'IceTopPulses_HLC', 'IceTopPulses_SLC', 'IceTopHLCVEMPulses', 'IceTopSLCVEMPulses'] if custom_injector: keep_keys += ['I3MCTreeIT', 'MCTopPulses'] else: keep_keys += ['MCPrimary', 'MCPrimaryInfo', 'SamplingWeight', 'Samples'] tray.AddModule(DummySubEventSplit, 'split') from icecube.tableio import I3TableWriter if output.endswith('.h5'): from icecube.hdfwriter import I3HDFTableService hdf_service = I3HDFTableService(output) tray.AddModule(I3TableWriter, "writer", Keys = keep_keys, TableService = [ hdf_service ], SubEventStreams = ['IceTop'], ) elif output.endswith('.root'): from icecube.rootwriter import I3ROOTTableService root_service = I3ROOTTableService(output) tray.AddModule(I3TableWriter, "writer", Keys = keep_keys, TableService = [ root_service ], SubEventStreams = ['IceTop'], ) else: # write standard output format i3 tray.AddModule("I3Writer", "i3-writer", Filename = output, streams = [icetray.I3Frame.DAQ] )
def Execute(self, stats): if not ipmodule.ParsingModule.Execute(self, stats): return 0 from icecube import icetray from icecube import dataclasses from icecube import dataio from icecube import phys_services from icecube import sim_services from icecube import genie_icetray from icecube import simclasses from ..segments import PropagatePhotons from ..util import BasicHitFilter from I3Tray import I3Tray, I3Units icetray.set_log_level_for_unit('I3CLSimStepToPhotonConverterOpenCL', icetray.I3LogLevel.LOG_FATAL) # Instantiate a tray tray = I3Tray() randomService = phys_services.I3SPRNGRandomService(self.rngseed, self.rngnumberofstreams, self.rngstream)\ if not self.usegslrng else phys_services.I3GSLRandomService(seed = self.rngseed*self.rngnumberofstreams+self.rngstream) randomServiceForPropagators = phys_services.I3SPRNGRandomService( seed = self.rngseed, nstreams = self.rngnumberofstreams*2, streamnum = self.rngnumberofstreams + self.rngstream)\ if not self.usegslrng else phys_services.I3GSLRandomService(seed = 2*(self.rngseed*self.rngnumberofstreams+self.rngstream)) tray.context['I3RandomService'] = randomService tray.context['I3PropagatorRandomService'] = randomServiceForPropagators # Configure IceTray services summary = dataclasses.I3MapStringDouble() tray.context['I3SummaryService'] = summary tray.AddModule("I3InfiniteSource", "TheSource", Prefix=self.gcdfile, Stream=icetray.I3Frame.DAQ) tray.AddModule( "I3GENIEGenerator", "genie_generator", RandomService= randomService, # alternatively, this can be None and the I3RandomService can be installed using tray.AddService() SplineFilename=os.path.expandvars( "$I3_BUILD/genie-icetray/resources/splines/splines_water_2.8.6.xml" ), LHAPDFPath=os.path.expandvars( "$I3_BUILD/genie-icetray/resources/PDFsets" ), # use $I3_PORTS/bin/lhapdf-getdata to download the PDFsets NuEnergyMin=self.emin, NuEnergyMax=self.emax, PowerLawIndex=self.gamma, GenVolRadius=self.radius * I3Units.m, GenVolLength=self.length * I3Units.m, GenVolDepth=1950. * I3Units.m, NeutrinoFlavor=self. nuflavor, # generates neutrinos and anti-neutrinos (1:1) MaterialDensity=0.93 * I3Units.g / I3Units.cm3, # ice density TargetMixIngredients=[1000080160, 1000010010], # O16, H1 TargetMixQuantities=[1, 2], # H2O (O16->1x, H1->2x) ForceSingleProbScale=False, NEvents=self.nevents, GENIEPATH=self.geniepath) tray.AddModule(shifter, "cylinder_shifter", x=self.x * I3Units.m, y=self.y * I3Units.m, z=self.z * I3Units.m, Streams=[icetray.I3Frame.DAQ]) tray.AddSegment( PropagatePhotons, "photons", UseGPUs=self.gpuopt, UnshadowedFraction=self.efficiency, DOMOversizeFactor=self.oversize, IceModelLocation=self.icemodellocation, HybridMode=False, IceModel=self.icemodel, OutputPESeriesMapName=self.photonseriesname, OutputPhotonSeriesName=self.rawphotonseriesname, UseGeant4=True, ) tray.AddModule(BasicHitFilter, "hitfilter", Streams=[icetray.I3Frame.DAQ], HitSeriesMapNames=self.photonseriesname) # Add empty weightdict tray.AddModule(AddEmptyWeights) tray.AddModule("I3RemoveLargeDT", "removeLDT") tray.AddModule(ResetMCPE, 'reset', Streams=[icetray.I3Frame.DAQ]) if self.polyplopia: from .. import segments tray.AddSegment( segments.PolyplopiaSegment, "coincify", RandomService=randomService, mctype='Genie', mctree_name="I3MCTree", separate_coincident_mctree_name= "CoincidentI3MCTree_preMuonProp", bgfile=self.backgroundfile, timewindow=40. * I3Units.microsecond, rate=5.0 * I3Units.kilohertz, ) tray.AddSegment( segments.PropagateMuons, 'propagator', RandomService=randomServiceForPropagators, InputMCTreeName="CoincidentI3MCTree_preMuonProp", OutputMCTreeName="CoincidentI3MCTree", ) tray.AddModule("I3Writer", "writer", filename=self.outputfile, Streams=[ icetray.I3Frame.TrayInfo, icetray.I3Frame.DAQ, icetray.I3Frame.Stream('S'), icetray.I3Frame.Stream('M') ]) tray.Execute() return 0
def Execute(self, stats): if not ipmodule.ParsingModule.Execute(self, stats): return 0 from icecube import icetray from icecube import dataclasses from icecube import dataio from icecube import phys_services from icecube import sim_services from icecube import genie_icetray from icecube import simclasses # Instantiate a tray icetray.set_log_level_for_unit('I3CLSimStepToPhotonConverterOpenCL', icetray.I3LogLevel.LOG_FATAL) tray = I3Tray() if not self.summaryfile: raise Exception('must define summary file') tray.AddService("I3XMLSummaryServiceFactory", "summary")(("outputfilename", self.summaryfile), ) randomService = phys_services.I3SPRNGRandomService( seed=self.rngseed, nstreams=self.rngnumberofstreams, streamnum=self.rngstream) randomServiceForPropagators = phys_services.I3SPRNGRandomService( seed=self.rngseed, nstreams=self.rngnumberofstreams * 2, streamnum=self.rngnumberofstreams + self.rngstream) tray.context['I3RandomService'] = randomService tray.context['I3PropagatorRandomService'] = randomServiceForPropagators tray.AddModule("I3InfiniteSource", "TheSource", Prefix=self.gcdfile, Stream=icetray.I3Frame.DAQ) tray.AddModule( "I3GENIEGenerator", "genie_generator", RandomService= randomService, # alternatively, this can be None and the I3RandomService can be installed using tray.AddService() SplineFilename=os.path.expandvars( "$I3_BUILD/genie-icetray/resources/splines/splines_water_2.6.4.xml" ), LHAPDFPath=os.path.expandvars( "$I3_BUILD/genie-icetray/resources/PDFsets" ), # use $I3_PORTS/bin/lhapdf-getdata to download the PDFsets NuEnergyMin=self.emin, NuEnergyMax=self.emax, PowerLawIndex=self.gamma, GenVolRadius=800. * I3Units.m, GenVolLength=1200. * I3Units.m, GenVolDepth=1950. * I3Units.m, NeutrinoFlavor=self. nuflavor, # generates neutrinos and anti-neutrinos (1:1) MaterialDensity=0.93 * I3Units.g / I3Units.cm3, # ice density TargetMixIngredients=[1000080160, 1000010010], # O16, H1 TargetMixQuantities=[1, 2], # H2O (O16->1x, H1->2x) ForceSingleProbScale=False, NEvents=self.nevents, GENIEPATH=self.geniepath) # Add empty weightdict tray.AddModule(AddEmptyWeights) if self.polyplopia: from .. import segments tray.AddSegment( segments.PolyplopiaSegment, "coincify", RandomService=randomService, mctype='Genie', mctree_name="I3MCTree", separate_coincident_mctree_name= "CoincidentI3MCTree_preMuonProp", bgfile=self.backgroundfile, timewindow=40. * I3Units.microsecond, rate=5.0 * I3Units.kilohertz, ) tray.AddSegment( segments.PropagateMuons, 'propagator', RandomService=randomServiceForPropagators, InputMCTreeName="CoincidentI3MCTree_preMuonProp", OutputMCTreeName="CoincidentI3MCTree", ) tray.AddModule("I3Writer", "writer")( ("filename", self.outputfile), ("streams", [icetray.I3Frame.DAQ])) tray.AddModule("TrashCan", "the can") tray.Execute() tray.Finish() return 0
y.insert(0, smallnum) x.append(x[-1]) y.append(smallnum) return np.array(x), np.array(y) # # for logging # icetray.I3Logger.global_logger = icetray.I3PrintfLogger() icetray.set_log_level(icetray.I3LogLevel.LOG_WARN) #icetray.set_log_level_for_unit("EarthModelService",icetray.I3LogLevel.LOG_TRACE) #icetray.set_log_level_for_unit("I3NuG",icetray.I3LogLevel.LOG_TRACE) #icetray.set_log_level_for_unit("I3NuG",icetray.I3LogLevel.LOG_INFO) icetray.set_log_level_for_unit("I3NuG", icetray.I3LogLevel.LOG_ERROR) # generate random service random = phys_services.I3SPRNGRandomService(1, 10000, 1) # generate earthmodel service earthmodel = ["PREM_mmc"] materialmodel = ["Standard"] earth = earthmodel_service.EarthModelService("EarthModelService", "", earthmodel, materialmodel, "IceSheet", 30. * I3Units.degree, 1948 * I3Units.m) steer = neutrino_generator.Steering(earth) icetray.logging.log_info(
from icecube.icetray import I3Module from icecube.dataclasses import I3EventHeader, I3Particle from icecube.recclasses import I3LaputopParams from icecube.stochastics import * import multiprocessing as mp ## Are you using tableio? from icecube.tableio import I3TableWriter from icecube.rootwriter import I3ROOTTableService import numpy as np ## Set the log level ## Uncomment this in if you're doing code development! icetray.set_log_level(icetray.I3LogLevel.LOG_INFO) icetray.set_log_level_for_unit('Laputop', icetray.I3LogLevel.LOG_DEBUG) icetray.set_log_level_for_unit('Curvature', icetray.I3LogLevel.LOG_DEBUG) parser = argparse.ArgumentParser() parser.add_argument("-d", "--directory",type=str,default='12360', dest="directory_number",help="directory number") args = parser.parse_args() workspace = expandvars("$I3_BUILD") #HOME = expandvars("$HOME") HOME = '/data/user/amedina/CosmicRay/Curvature' data_set_number = args.directory_number directory = '/data/ana/CosmicRay/IceTop_level3/sim/IC86.2012/' file_list = os.listdir(directory+data_set_number)
def SimIceTop(tray, name, input, output=None, gcd=None, log_level=2, samples=1, x=0.0, y=0.0, r=0.0, seed=0, injector="normal", response="g4", weighted=False): import os import re from icecube import icetray, dataclasses, dataio from icecube import simclasses, sim_services, phys_services from icecube import topsimulator from icecube.icetray import I3Units if gcd is None: raise ValueError("Need to specify a GCD file") if not os.path.exists(gcd): raise IOError("Specified GCD file does not exist") for unit in ('I3TopSimulator', 'I3CorsikaReader', 'I3CorsikaInjector', 'I3CorsikaThinnedInjector', 'I3CorsikaGridInjector', 'I3G4TankResponse', 'I3ParamTankResponse'): icetray.set_log_level_for_unit(unit, icetray.I3LogLevel(log_level)) # to be used by injector for tag in ("inj", "resp", "other"): tray.AddService("I3GSLRandomServiceFactory", "gslrandom_" + tag, Seed=seed, InstallServiceAs='random_' + tag) if weighted: if injector == "normal": tray.AddService("I3InjectorFactory<I3CorsikaInjector>", "particle-injector", FileNameList = input, RandomServiceName = 'random_inj', NumSamples = samples, # <-- Number of re-samples of the same shower ImportanceSampling = True, #PartDistr = os.path.join(os.path.dirname(options.output), # 'on_regions_' + os.path.basename(options.output).replace(extension, 'root')), IgnoreParticleTypes = [75, 76, 85, 86, 95, 96] ) else: raise ValueError("option weighted requires normal injector") else: if injector == "normal": tray.AddService("I3InjectorFactory<I3CorsikaInjector>", "particle-injector", FileNameList = input, RandomServiceName = 'random_inj', NumSamples = samples, # <-- Number of re-samples of the same shower RelocationX = x, # <-- x-coordinate of core or resampling center (if Relocation R > 0) RelocationY = y, # <-- y-coordinate or core or resampling center (if Relocation R > 0) RelocationR = r, # <-- Re-sampling radius (if zero --> fixed core location) IgnoreParticleTypes = [75, 76, 85, 86, 95, 96] ) elif injector == "unthin": tray.AddService("I3InjectorFactory<I3CorsikaThinnedInjector>", "particle-injector", FileNameList = input, RandomServiceName = 'random_inj', NumSamples = samples, # <-- Number of re-samples of the same shower RelocationX = x, # <-- x-coordinate of core or resampling center (if Relocation R > 0) RelocationY = y, # <-- y-coordinate or core or resampling center (if Relocation R > 0) RelocationR = r, # <-- Re-sampling radius (if zero --> fixed core location) SmartUnthinning = False, IgnoreParticleTypes = [75, 76, 85, 86, 95, 96] ) else: raise ValueError("unknown injector option") if response == 'g4': from icecube import g4_tankresponse tray.AddService("I3IceTopResponseFactory<I3G4TankResponse>", "topresponse", RandomServiceName = "random_resp", ChargeScale = 1.02 ) elif response == 'param': tray.AddService("I3IceTopResponseFactory<I3ParamTankResponse>", "topresponse", RandomServiceName = "random_resp", UseSnowParam = True ) else: raise ValueError("Unknown IceTop tank response: " + response) def Inspect(frame): print frame.keys() tray.AddModule("I3InfiniteSource", "source", prefix = gcd, stream = icetray.I3Frame.DAQ ) tray.AddModule(Inspect, "inspect1") tray.AddModule("I3TopSimulator","I3TopSimulator", InjectorServiceName = "particle-injector", ResponseServiceName = "topresponse", PrimaryName = "MCPrimary", InIceMCTreeName = "", IceTopMCTreeName = "I3MCTreeIT", MuonCountName = "MuonCountMap", MuonEnergyCutOff = 0.0, CompressPEs = 0 ) tray.AddModule(Inspect, "inspect2") if output is not None: # writing of output is requested # write standard output format i3 tray.AddModule("I3Writer", "i3-writer", Filename = output, streams = [icetray.I3Frame.DAQ] )
from os.path import expandvars from I3Tray import I3Units from I3Tray import I3Tray from icecube import icetray from icecube import dataclasses as dc from icecube import phys_services from icecube import dataio from icecube import I3Db from icecube import BadDomList from icecube import vuvuzela from icecube import WaveCalibrator icetray.logging.rotating_files(options.LOGFILE) icetray.set_log_level_for_unit('Inject', icetray.I3LogLevel.LOG_TRACE) tray = I3Tray() tray.AddService("I3DbOMKey2MBIDFactory","dbomkey2mbid", host = options.DBHOST) tray.AddService("I3DbGeometryServiceFactory","dbgeometry", host = "dbs2.icecube.wisc.edu", CompleteGeometry = False, DeepCore = True, MJD = options.MJD) tray.AddService("I3DbDetectorStatusServiceFactory","dbstatus", host = options.DBHOST,
tray = I3Tray() seed=1 #ev_n=100000 #ev_n=10000 #ev_n=1000 #ev_n=100 ev_n=10 # # logging setting # icetray.I3Logger.global_logger = icetray.I3PrintfLogger() icetray.set_log_level(icetray.I3LogLevel.LOG_INFO) icetray.set_log_level_for_unit("I3NuG",icetray.I3LogLevel.LOG_TRACE) tray.AddService("I3SPRNGRandomServiceFactory","random")( ("Seed",seed), ("NStreams",seed+1), ("StreamNum",1)) from os.path import expandvars tray.AddModule("I3InfiniteSource", "source", prefix = expandvars("$I3_TESTDATA/sim/GeoCalibDetectorStatus_IC86.55380_corrected.i3.gz") ) tray.AddModule("I3MCEventHeaderGenerator","ev") #------------------ # injection neutrino
print("zenmin %f, zenmax %f" % (zenmin, zenmax)) print("zenalpha %f" % zenalpha) print("xsec %s" % xsecmodel) print("xsec scale " , global_xsec_scale) print("earthmodel " , earth) print("seed %d" % seed) print("nfiles %d" % nfiles) print("fileno %d" % fileno) #-------------- # for logging #-------------- icetray.I3Logger.global_logger = icetray.I3PrintfLogger() icetray.set_log_level(icetray.I3LogLevel.LOG_WARN) icetray.set_log_level_for_unit("EarthModelService",icetray.I3LogLevel.LOG_INFO) #icetray.set_log_level_for_unit("I3NuG",icetray.I3LogLevel.LOG_TRACE) #icetray.set_log_level_for_unit("I3NuG",icetray.I3LogLevel.LOG_INFO) icetray.set_log_level_for_unit("I3NuG",icetray.I3LogLevel.LOG_WARN) #-------------- # icetray start #-------------- tray = I3Tray() #from icecube.examples_simulation.configure_simulation import configure_service_modules #configure_service_modules( tray, season ) #random = tray.context['random'] # generate random service
def main(inputFiles, outfile, n=None, outputLevel=2): import math import numpy from I3Tray import I3Tray from icecube import icetray, dataclasses, dataio, phys_services, rock_bottom, gulliver, lilliput from icecube.rock_bottom import processing as rb_processing icetray.set_log_level_for_unit('RockBottom', icetray.I3LogLevel(outputLevel)) icetray.set_log_level_for_unit('I3TopNKG', icetray.I3LogLevel(outputLevel)) icetray.set_log_level_for_unit('I3LaputopSignalModel', icetray.I3LogLevel(outputLevel)) gcdfile = [ "/Users/javierg/IceCubeData/GeoCalibDetectorStatus_IC79.55380_L2a.i3" ] #gcdfile = ["/data/icet0/gonzalez/IceCubeData/GeoCalibDetectorStatus_IC79.55380_L2a.i3"] # Instantiate a tray tray = I3Tray() nkg = rock_bottom.ldf.NKG() #laputop_ltp = rock_bottom.functions.ERF(x_0=math.log10(0.1657), sigma=0.35) #rock_bottom_ltp = rock_bottom.functions.ERF(x_0=math.log10(0.22), sigma=0.14) laputop_ltp = 0 rock_bottom_ltp = 0 laputop_saturation = rock_bottom.functions.LaputopSaturationProbability() tray.AddService( 'SingleLDFSignalModel', "Single_NKGLDF", LDF=nkg, LTP=laputop_ltp, Saturation=laputop_saturation, ) tray.AddService( 'LaputopSignalModel', "Laputop_NKGLDF", LDF=nkg, LTP=laputop_ltp, Saturation=laputop_saturation, ) tray.AddService( "I3GulliverMinuitFactory", "Minuit", MinuitPrintLevel=-2, FlatnessCheck=True, Algorithm="SIMPLEX", MaxIterations=2500, MinuitStrategy=2, Tolerance=0.01, ) tray.AddModule('I3Reader', 'Reader', FilenameList=gcdfile + inputFiles) tray.AddSegment(rb_processing.SelectInIce, 'InIceSelection') tray.AddSegment(rb_processing.CalibrateSLCs, 'CalibrateSLCs', SLCVEMPulses='IceTopSLCVEMPulses') #tray.AddSegment(rb_processing.SelectPulses, 'SelectPulses', # Seed="MPEFitMuE") tray.AddModule( lambda frame: 'IceTopSelectedHLC' in frame and len(frame[ 'IceTopSelectedHLC']) >= 8, 'select_icetop') tray.AddSegment( rb_processing.MaxLikelihood, "NKG", #Parameters={'S_ref':(numpy.nan, numpy.nan, 2), # "beta":(numpy.nan, numpy.nan, 2), # "Moliere":(numpy.nan, numpy.nan, 100.)}, Parameters={ 'S_ref': (numpy.nan, numpy.nan, 2), 'x': [1000], 'y': [1000] }, #Parameters={'S_ref':(numpy.nan, numpy.nan, 2),"beta":(numpy.nan, numpy.nan, 2), 'x':[1000]}, Seed="MPEFitMuE", Model="Laputop_NKGLDF", HLCPulses="IceTopSelectedHLC", LDF="NKG_LDF") #tray.AddSegment(rb_processing.RedoOfflineIceTopReco, "OfflineIceTopReco", Pulses='IceTopSelectedHLC') tray.AddModule("I3Writer", "i3-writer", Filename="%s.i3" % outfile, DropOrphanStreams=[icetray.I3Frame.DAQ], streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Physics]) tray.AddModule('TrashCan', 'Done') # Execute the Tray if n is None: tray.Execute() else: tray.Execute(n) tray.Finish()
def recreate_alert_short_followup_msg(frame_packet, pulsesName="SplitInIcePulses"): from icecube import dataclasses, recclasses, simclasses from icecube import filterscripts from icecube.filterscripts.muonfilter import MuonFilter from icecube.filterscripts.onlinel2filter import OnlineL2Filter from icecube.filterscripts.hesefilter import HeseFilter from icecube.filterscripts.highqfilter import HighQFilter from icecube.filterscripts.gfufilter import GammaFollowUp from icecube.filterscripts.alerteventfollowup import AlertEventFollowup icetray.load("DomTools", False) SplineDir = '/opt/i3-data/photon-tables/splines/' SplineRecoAmplitudeTable = os.path.join( SplineDir, 'InfBareMu_mie_abs_z20a10_V2.fits') SplineRecoTimingTable = os.path.join(SplineDir, 'InfBareMu_mie_prob_z20a10_V2.fits') nominalPulsesName = "SplitInIcePulses" # make a copy so we don't change any other references frame_packet = [copy.copy(frame) for frame in frame_packet] # sanity check the packet if frame_packet[-1].Stop != icetray.I3Frame.Physics and frame_packet[ -1].Stop != icetray.I3Frame.Stream('p'): raise RuntimeError("frame packet does not end with Physics frame") # move the last packet frame from Physics to the Physics stream temporarily frame_packet[-1] = rewrite_frame_stop(frame_packet[-1], icetray.I3Frame.Stream('P')) output_frames = [] icetray.set_log_level_for_unit('I3Tray', icetray.I3LogLevel.LOG_WARN) tray = I3Tray() tray.AddModule(FrameArraySource, Frames=frame_packet) tray.Add(uncompress, "GCD_uncompress", keep_compressed=True, base_path=config.base_GCD_path) if pulsesName != nominalPulsesName: def copyPulseName(frame, old_name, new_name): mask = dataclasses.I3RecoPulseSeriesMapMask(frame, old_name) if new_name in frame: print( "** WARNING: {0} was already in frame. overwritten".format( new_name)) del frame[new_name] frame[new_name] = mask frame[new_name + "TimeRange"] = copy.deepcopy(frame[old_name + "TimeRange"]) tray.AddModule(copyPulseName, "copyPulseName", old_name=pulsesName, new_name=nominalPulsesName) # many of the filters check if the SMT8 trigger fired. Assume it did def AddInIceSMTTriggeredBool(frame): frame['InIceSMTTriggered'] = icetray.I3Bool(True) tray.Add(AddInIceSMTTriggeredBool, "AddInIceSMTTriggeredBool", Streams=[icetray.I3Frame.DAQ]) ##################### below is cut from BaseProcessing ################### from icecube import STTools from icecube import linefit, lilliput import icecube.lilliput.segments # first, perform the pulse cleaning that yields "CleanedMuonPulses" from icecube.STTools.seededRT.configuration_services import I3DOMLinkSeededRTConfigurationService seededRTConfig = I3DOMLinkSeededRTConfigurationService( ic_ic_RTRadius=150.0 * I3Units.m, ic_ic_RTTime=1000.0 * I3Units.ns, treat_string_36_as_deepcore=False, useDustlayerCorrection=False, allowSelfCoincidence=True) tray.AddModule( 'I3SeededRTCleaning_RecoPulseMask_Module', 'seededrt', InputHitSeriesMapName=nominalPulsesName, OutputHitSeriesMapName=nominalPulsesName + "_RTC", STConfigService=seededRTConfig, SeedProcedure='HLCCoreHits', NHitsThreshold=2, MaxNIterations=3, Streams=[icetray.I3Frame.Physics], ) tray.AddModule( "I3TimeWindowCleaning<I3RecoPulse>", "TimeWindowCleaning", InputResponse=nominalPulsesName + "_RTC", OutputResponse=nominalPulsesName + "_TWRTC", TimeWindow=6000 * I3Units.ns, ) tray.AddModule( "I3FirstPulsifier", "first-pulsify", InputPulseSeriesMapName=nominalPulsesName + "_TWRTC", OutputPulseSeriesMapName='FirstPulseMuonPulses', KeepOnlyFirstCharge=False, # default UseMask=False, # default ) tray.AddSegment( linefit.simple, "imprv_LF", inputResponse=nominalPulsesName + "_TWRTC", fitName='PoleMuonLinefit', ) tray.AddSegment( lilliput.segments.I3SinglePandelFitter, 'PoleMuonLlhFit', seeds=['PoleMuonLinefit'], pulses=nominalPulsesName + "_TWRTC", fitname='PoleMuonLlhFit', ) ##################### above is cut from BaseProcessing ################### # re-run all necessary filters tray.AddSegment( MuonFilter, "MuonFilter", pulses=nominalPulsesName + "_TWRTC", If=lambda frame: frame.Stop == icetray.I3Frame. Physics # work around stupidity in the filter's If=<...> statements ) # High Q filter tray.AddSegment( HighQFilter, "HighQFilter", pulses=nominalPulsesName, If=lambda frame: frame.Stop == icetray.I3Frame. Physics # work around stupidity in the filter's If=<...> statements ) # HESE veto (VHESelfVeto) tray.AddSegment( HeseFilter, "HeseFilter", pulses=nominalPulsesName, If=lambda frame: frame.Stop == icetray.I3Frame. Physics # work around stupidity in the filter's If=<...> statements ) # OnlineL2, used by HESE and GFU tray.AddSegment( OnlineL2Filter, "OnlineL2", pulses=nominalPulsesName + "_TWRTC", linefit_name='PoleMuonLinefit', llhfit_name='PoleMuonLlhFit', SplineRecoAmplitudeTable=SplineRecoAmplitudeTable, SplineRecoTimingTable=SplineRecoTimingTable, PathToCramerRaoTable=None, forceOnlineL2BadDOMList=None, If=lambda frame: frame.Stop == icetray.I3Frame. Physics # work around stupidity in the filter's If=<...> statements ) tray.AddSegment( GammaFollowUp, "GammaFollowUp", OnlineL2SegmentName="OnlineL2", pulses=nominalPulsesName + "_TWRTC", BDTUpFile=None, BDTDownFile=None, angular_error=True, If=lambda frame: frame.Stop == icetray.I3Frame. Physics # work around stupidity in the filter's If=<...> statements ) # we do not necessarily have launches, so EHE is practically impossible. Skip EHE alerts. # from icecube.filterscripts.ehefilter import EHEFilter # from icecube.filterscripts.ehealertfilter import EHEAlertFilter # tray.AddSegment(EHEFilter, "EHEFilter") # tray.AddSegment(EHEAlertFilter, "EHEAlertFilter", # pulses = nominalPulsesName + "_TWRTC", # # If = lambda frame: frame.Stop == icetray.I3Frame.Physics # work around stupidity in the filter's If=<...> statements # ) # finally, create "AlertShortFollowupMsg" tray.AddSegment( AlertEventFollowup, "AlertFollowup", omit_GCD_diff=True, If=lambda frame: frame.Stop == icetray.I3Frame. Physics # work around stupidity in the filter's If=<...> statements ) # the previous module also creates "AlertFullFollowupMsg" but we do not need it def cleanupFullFollowupMessage(frame): if "AlertFullFollowupMsg" in frame: del frame["AlertFullFollowupMsg"] tray.Add(cleanupFullFollowupMessage, "cleanupFullFollowupMessage") def delFrameObjectsWithDiffsAvailable(frame): all_keys = frame.keys() for key in frame.keys(): if not key.endswith('Diff'): continue non_diff_key = key[:-4] if non_diff_key in all_keys: del frame[non_diff_key] # print("deleted", non_diff_key, "from frame because a Diff exists") tray.AddModule(delFrameObjectsWithDiffsAvailable, "delFrameObjectsWithDiffsAvailable", Streams=[ icetray.I3Frame.Geometry, icetray.I3Frame.Calibration, icetray.I3Frame.DetectorStatus ]) tray.AddModule(FrameArraySink, FrameStore=output_frames) tray.AddModule("TrashCan") tray.Execute() tray.Finish() del tray icetray.set_log_level_for_unit('I3Tray', icetray.I3LogLevel.LOG_NOTICE) if "AlertShortFollowupMsg" not in output_frames[-1]: return dataclasses.I3String(json.dumps({'value': {'data': {}}})) else: return output_frames[-1]["AlertShortFollowupMsg"]
from os.path import expandvars from I3Tray import I3Units from I3Tray import I3Tray from icecube import icetray from icecube import dataclasses as dc from icecube import phys_services from icecube import dataio from icecube import I3Db from icecube import BadDomList from icecube import vuvuzela from icecube import WaveCalibrator icetray.logging.rotating_files(options.LOGFILE) icetray.set_log_level_for_unit('Inject', icetray.I3LogLevel.LOG_TRACE) tray = I3Tray() tray.AddService("I3DbOMKey2MBIDFactory", "dbomkey2mbid", host=options.DBHOST) tray.AddService("I3DbGeometryServiceFactory", "dbgeometry", host="dbs2.icecube.wisc.edu", CompleteGeometry=False, DeepCore=True, MJD=options.MJD) tray.AddService("I3DbDetectorStatusServiceFactory", "dbstatus", host=options.DBHOST,
import sys import os.path # Use a virtualenv if we have one if 'VIRTUAL_ENV' in os.environ: pass activate_script = os.path.join(os.environ['VIRTUAL_ENV'], 'bin', 'activate_this.py') if os.path.exists(activate_script): execfile(activate_script, {'__file__': activate_script}) # IPython will check if VIRTUAL_ENV is set, and complain unless # sys.executable (i.e. steamshovel) is inside the virtualenv. We've just # handled all the necessary setup, so squash the warning. del os.environ['VIRTUAL_ENV'] from icecube import icetray icetray.set_log_level_for_unit('icetray', icetray.I3LogLevel.LOG_FATAL) # If a dir named 'ipython' is inside this package, load it first # This allows a user to stash a newer version of ipython in this directory, # to take advantage of the 1.0.dev features required for the GUI python widget #sys.path.insert(0, os.path.join(__path__[0], 'ipython'))
import sys from icecube import icetray, dataio from icecube.icetray import I3Units from icecube import STTools from icecube.STTools.seededRT.configuration_services import I3DOMLinkSeededRTConfigurationService icetray.set_log_level(icetray.I3LogLevel.LOG_TRACE) icetray.set_log_level_for_unit('STToolsSeededRT', icetray.I3LogLevel.LOG_TRACE) icetray.set_log_level_for_unit('OMKeyPairMap', icetray.I3LogLevel.LOG_DEBUG) icetray.set_log_level_for_unit('OMKeyHasher', icetray.I3LogLevel.LOG_DEBUG) icetray.set_log_level_for_unit('I3SeededRTConfigurationService', icetray.I3LogLevel.LOG_DEBUG) try: gcdfilename = sys.argv[1] infilename = sys.argv[2] outfilename = sys.argv[3] except: raise RuntimeError("Usage: %s gcdfile infile outfile" % (sys.argv[0])) # Create a seededRT configuration service, based on DOM link ST settings. seededRTConfigService = I3DOMLinkSeededRTConfigurationService( allowSelfCoincidence=False, # Default: False useDustlayerCorrection=True, # Default: True treat_string_36_as_deepcore=True, # Default: True dustlayerUpperZBoundary=0 * I3Units.m, dustlayerLowerZBoundary=-150 * I3Units.m, ic_ic_RTTime=1000 * I3Units.ns, ic_ic_RTRadius=150 * I3Units.m)
def prepare_frames(frame_packet, pulsesName="SplitInIcePulses"): from icecube import dataclasses, recclasses, simclasses from icecube import DomTools, VHESelfVeto from icecube import photonics_service, gulliver, millipede from i3deepice.i3module import DeepLearningModule nominalPulsesName = "SplitInIcePulses" # sanity check the packet if frame_packet[-1].Stop != icetray.I3Frame.Physics and frame_packet[ -1].Stop != icetray.I3Frame.Stream('p'): raise RuntimeError("frame packet does not end with Physics frame") # move the last packet frame from Physics to the Physics stream temporarily frame_packet[-1] = rewrite_frame_stop(frame_packet[-1], icetray.I3Frame.Stream('P')) intermediate_frames = [] icetray.set_log_level_for_unit('I3Tray', icetray.I3LogLevel.LOG_WARN) tray = I3Tray() tray.AddModule(FrameArraySource, Frames=frame_packet) tray.Add(uncompress, "GCD_uncompress", keep_compressed=True, base_path=config.base_GCD_path) if pulsesName != nominalPulsesName: def copyPulseName(frame, old_name, new_name): mask = dataclasses.I3RecoPulseSeriesMapMask(frame, old_name) if new_name in frame: print( "** WARNING: {0} was already in frame. overwritten".format( new_name)) del frame[new_name] frame[new_name] = mask frame[new_name + "TimeRange"] = copy.deepcopy(frame[old_name + "TimeRange"]) tray.AddModule(copyPulseName, "copyPulseName", old_name=pulsesName, new_name=nominalPulsesName) tray.AddModule('I3LCPulseCleaning', 'lcclean1', Input=nominalPulsesName, OutputHLC=nominalPulsesName + 'HLC', OutputSLC=nominalPulsesName + 'SLC', If=lambda frame: nominalPulsesName + 'HLC' not in frame) tray.AddModule( 'VHESelfVeto', 'selfveto', VertexThreshold=250., # 250pe is the default setting Pulses=nominalPulsesName + 'HLC', OutputBool='HESE_VHESelfVeto', OutputVertexTime='HESE_VHESelfVetoVertexTime', OutputVertexPos='HESE_VHESelfVetoVertexPos', If=lambda frame: "HESE_VHESelfVeto" not in frame) def MarkFrameForSubThresholdVeto(frame): any_in_frame = ("HESE_VHESelfVeto" in frame) or ("HESE_VHESelfVetoVertexTime" in frame) or ("HESE_VHESelfVetoVertexPos" in frame) all_in_frame = ("HESE_VHESelfVeto" in frame) and ( "HESE_VHESelfVetoVertexTime" in frame) and ("HESE_VHESelfVetoVertexPos" in frame) if all_in_frame: # all good frame["HESE_VertexThreshold"] = dataclasses.I3Double(250.) elif any_in_frame: print(frame) raise RuntimeError( "Some of the HESE veto objects exist but not all of them. This is an error." ) else: print( " ******* VERY LOW CHARGE EVENT - re-doing HESE veto with much lower pe vertex threshold to at least get a seed position ******* " ) # Re-do this with 10pe, but let people looking at the resulting # frame know! (the resulting veto condition is basically meaningless) frame["HESE_VertexThreshold"] = dataclasses.I3Double(5.) frame["HESE_VHESelfVeto"] = icetray.I3Bool(False) tray.AddModule(MarkFrameForSubThresholdVeto, 'MarkFrameForSubThresholdVeto') # Make sure this actually calculated something - especially if we are far below the # veto threshold, this will silently do nothing (which is kind of expected). tray.AddModule( 'VHESelfVeto', 'selfveto-emergency-lowen-settings', VertexThreshold= 5., # usually this is at 250pe - use a much lower setting here Pulses=nominalPulsesName + 'HLC', OutputBool='HESE_VHESelfVeto_meaningless_lowen', OutputVertexTime='HESE_VHESelfVetoVertexTime', OutputVertexPos='HESE_VHESelfVetoVertexPos', If=lambda frame: (frame.Stop == icetray.I3Frame.Physics) and (frame["HESE_VertexThreshold"].value < 250. )) # this only runs if the previous module did not return anything def CheckHESEVertexExists(frame): pulses = dataclasses.I3RecoPulseSeriesMap.from_frame( frame, nominalPulsesName + 'HLC') if "HESE_VHESelfVeto" not in frame: print(pulses) print(frame) raise RuntimeError( "Cannot continue, HESE_VHESelfVeto not in frame (too low total charge?)." ) if "HESE_VHESelfVetoVertexTime" not in frame: print(pulses) print(frame) raise RuntimeError( "Cannot continue, HESE_VHESelfVetoVertexTime not in frame (too low total charge?)." ) if "HESE_VHESelfVetoVertexPos" not in frame: print(pulses) print(frame) raise RuntimeError( "Cannot continue, HESE_VHESelfVetoVertexPos not in frame (too low total charge?)." ) tray.AddModule(CheckHESEVertexExists, 'CheckHESEVertexExists') # make sure the script doesn't fail because some objects alreadye exist def cleanupFrame(frame): if "SaturatedDOMs" in frame: del frame["SaturatedDOMs"] # Added BrightDOMs Nov 28 2015 since it was already in frame - Will if "BrightDOMs" in frame: del frame["BrightDOMs"] tray.AddModule(cleanupFrame, "cleanupFrame", Streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Physics]) ################## def _weighted_quantile_arg(values, weights, q=0.5): indices = numpy.argsort(values) sorted_indices = numpy.arange(len(values))[indices] medianidx = (weights[indices].cumsum() / weights[indices].sum()).searchsorted(q) if (0 <= medianidx) and (medianidx < len(values)): return sorted_indices[medianidx] else: return numpy.nan def weighted_quantile(values, weights, q=0.5): if len(values) != len(weights): raise ValueError("shape of `values` and `weights` don't match!") index = _weighted_quantile_arg(values, weights, q=q) if not numpy.isnan(index): return values[index] else: return numpy.nan def weighted_median(values, weights): return weighted_quantile(values, weights, q=0.5) def LatePulseCleaning(frame, Pulses, Residual=3e3 * I3Units.ns): pulses = dataclasses.I3RecoPulseSeriesMap.from_frame(frame, Pulses) mask = dataclasses.I3RecoPulseSeriesMapMask(frame, Pulses) counter, charge = 0, 0 qtot = 0 times = dataclasses.I3TimeWindowSeriesMap() for omkey, ps in pulses.iteritems(): if len(ps) < 2: if len(ps) == 1: qtot += ps[0].charge continue ts = numpy.asarray([p.time for p in ps]) cs = numpy.asarray([p.charge for p in ps]) median = weighted_median(ts, cs) qtot += cs.sum() for p in ps: if p.time >= (median + Residual): if not times.has_key(omkey): ts = dataclasses.I3TimeWindowSeries() ts.append( dataclasses.I3TimeWindow(median + Residual, numpy.inf) ) # this defines the **excluded** time window times[omkey] = ts mask.set(omkey, p, False) counter += 1 charge += p.charge frame[nominalPulsesName + "LatePulseCleaned"] = mask frame[nominalPulsesName + "LatePulseCleanedTimeWindows"] = times frame[nominalPulsesName + "LatePulseCleanedTimeRange"] = copy.deepcopy( frame[Pulses + "TimeRange"]) tray.AddModule( LatePulseCleaning, "LatePulseCleaning", Pulses=nominalPulsesName, ) ExcludedDOMs = \ tray.AddSegment(millipede.HighEnergyExclusions, 'millipede_DOM_exclusions', Pulses = pulsesName, ExcludeDeepCore='DeepCoreDOMs', ExcludeSaturatedDOMs='SaturatedDOMs', ExcludeBrightDOMs='BrightDOMs', BadDomsList='BadDomsList', CalibrationErrata='CalibrationErrata', SaturationWindows='SaturationWindows' ) # I like having frame objects in there even if they are empty for some frames def createEmptyDOMLists(frame, ListNames=[]): for name in ListNames: if name in frame: continue frame[name] = dataclasses.I3VectorOMKey() tray.AddModule(createEmptyDOMLists, 'createEmptyDOMListsD', ListNames=["BadDomsList"], Streams=[icetray.I3Frame.DetectorStatus]) tray.AddModule(createEmptyDOMLists, 'createEmptyDOMListsQ', ListNames=["SaturatedDOMs", "CalibrationErrata"], Streams=[icetray.I3Frame.DAQ]) tray.AddModule(createEmptyDOMLists, 'createEmptyDOMListsP', ListNames=["BrightDOMs"], Streams=[icetray.I3Frame.Physics]) # add the late pulse exclusion windows ExcludedDOMs = ExcludedDOMs + [ nominalPulsesName + 'LatePulseCleaned' + 'TimeWindows' ] def EnsureExlusionObjectsExist(frame, ListNames=[]): for name in ListNames: if name in frame: continue print(frame) raise RuntimeError( "No frame object named \"{}\" found in frame (expected for DOM exclusions.)" .format(name)) tray.AddModule(EnsureExlusionObjectsExist, 'EnsureExlusionObjectsExist', ListNames=ExcludedDOMs, Streams=[icetray.I3Frame.Physics]) tray.AddModule(FrameArraySink, FrameStore=intermediate_frames) tray.AddModule("TrashCan") tray.Execute() tray.Finish() del tray print("") print("Starting CNN classification....") os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' ##### DeepIceLearning has a bug that does not allow multiple instances to be used. ##### work around this by just re-starting a full tray intermediate_frames2 = [] tray = I3Tray() tray.AddModule(FrameArraySource, Frames=intermediate_frames) tray.AddModule(DeepLearningModule, 'cnn_classification', batch_size=1, cpu_cores=1, gpu_cores=0, model='classification', pulsemap=nominalPulsesName, calib_errata='CalibrationErrata', bad_dom_list='BadDomsList', saturation_windows='SaturationWindows', bright_doms='BrightDOMs', save_as='CNN_classification') def print_classifier(frame): print("") print("CNN classification done:\n", frame["CNN_classification"]) print("") tray.AddModule(print_classifier, "print_classifier") ################## tray.AddModule(FrameArraySink, FrameStore=intermediate_frames2) tray.AddModule("TrashCan") tray.Execute() tray.Finish() del tray print("") print("Starting CNN energy reconstruction....") ##### DeepIceLearning has a bug that does not allow multiple instances to be used. ##### work around this by just re-starting a full tray output_frames_fullGCD = [] tray = I3Tray() tray.AddModule(FrameArraySource, Frames=intermediate_frames2) tray.AddModule(DeepLearningModule, 'cnn_energy', batch_size=1, cpu_cores=1, gpu_cores=0, model='mu_energy_reco_full_range', pulsemap=nominalPulsesName, calib_errata='CalibrationErrata', bad_dom_list='BadDomsList', saturation_windows='SaturationWindows', bright_doms='BrightDOMs', save_as='CNN_mu_energy_reco_full_range') def print_energy(frame): print("") print("CNN energy reco done: {:.2f}TeV".format( (10**frame["CNN_mu_energy_reco_full_range"]['mu_E_on_entry']) / 1e3)) print("") tray.AddModule(print_energy, "print_energy") ################## tray.AddModule(FrameArraySink, FrameStore=output_frames_fullGCD) tray.AddModule("TrashCan") tray.Execute() tray.Finish() del tray print("Final cleanup of GCD objects (where a Diff is avaiable)....") ##### Now remove GCD objects again where a Diff is available output_frames = [] tray = I3Tray() tray.AddModule(FrameArraySource, Frames=output_frames_fullGCD) def delFrameObjectsWithDiffsAvailable(frame): all_keys = frame.keys() for key in frame.keys(): if not key.endswith('Diff'): continue non_diff_key = key[:-4] if non_diff_key in all_keys: del frame[non_diff_key] # print("deleted", non_diff_key, "from frame because a Diff exists") tray.AddModule(delFrameObjectsWithDiffsAvailable, "delFrameObjectsWithDiffsAvailable", Streams=[ icetray.I3Frame.Geometry, icetray.I3Frame.Calibration, icetray.I3Frame.DetectorStatus ]) tray.AddModule(FrameArraySink, FrameStore=output_frames) tray.AddModule("TrashCan") tray.Execute() tray.Finish() del tray icetray.set_log_level_for_unit('I3Tray', icetray.I3LogLevel.LOG_NOTICE) ## we are done with preparing the frames. # move the last packet frame from Physics to the 'p' stream output_frames[-1] = rewrite_frame_stop(output_frames[-1], icetray.I3Frame.Stream('p')) return output_frames
""" This script demonstrates running HiveSplitter to split a RecoPulseSeries (located in the Q frame) into separate pulse series for each subevent, each in its own P frame. USAGE: python [this_script.py] [infile] [outfile] """ import sys from I3Tray import * from icecube import icetray, dataio, dataclasses from icecube import IceHive from icecube.icetray import I3Units icetray.set_log_level(icetray.I3LogLevel.LOG_INFO) icetray.set_log_level_for_unit("I3IceHive", icetray.I3LogLevel.LOG_DEBUG) tray = I3Tray() tray.AddModule("I3Reader", "Reader", FilenameList=sys.argv[1:-1]) tray.AddModule("Delete", "delete_keys_in_use", Keys=[ "MaskedOfflinePulses" + "_Physics", "MaskedOfflinePulses" + "_Noise", "MaskedOfflinePulses" + "_Noised", ]) #tray.AddModule("Dump", "dump")
#!/usr/bin/env python """ Try to tag afterpulse events by running the AfterpulseDiscard Module in CoincSuite: Read events with an already applied eventsplitter, run the module """ import os, sys from optparse import OptionParser from I3Tray import * from icecube import icetray, dataio, dataclasses #uncomment; plug in your most favourite, but very noise module for debugging icetray.set_log_level(icetray.I3LogLevel.LOG_INFO) icetray.set_log_level_for_unit('AfterpulseDiscard', icetray.I3LogLevel.LOG_TRACE) class RunParameters: def __init__(self): self.Infile = '' self.Outfile = '' self.NEvents = 0 #___________________PARSER__________________________ def parseOptions(parser, params): i3_testdata = os.path.expandvars("$I3_TESTDATA") parser.add_option("-i", "--input",
""" This script demonstrates running HiveSplitter to split a RecoPulseSeries (located in the Q frame) into separate pulse series for each subevent, each in its own P frame. USAGE: python [this_script.py] [infile] [outfile] """ import sys from I3Tray import * from icecube import icetray, dataio, dataclasses from icecube import IceHive from icecube.icetray import I3Units icetray.set_log_level(icetray.I3LogLevel.LOG_INFO) icetray.set_log_level_for_unit("I3HiveCleaning", icetray.I3LogLevel.LOG_DEBUG) tray = I3Tray() tray.AddModule("I3Reader", "Reader", FilenameList=sys.argv[1:-1]) tray.AddModule("Delete", "delete_keys_in_use", Keys=[ "HCMaskedOfflinePulses", ]) #tray.AddModule("Dump", "dump") from icecube import IceHiveZ tray.AddModule("I3HiveCleaning",
def main(inputFiles, outfile, n=None, outputLevel=2): import math import numpy from I3Tray import I3Tray from icecube import icetray, dataclasses, dataio, phys_services, rock_bottom, gulliver, lilliput icetray.set_log_level_for_unit('RockBottom', icetray.I3LogLevel(outputLevel)) icetray.set_log_level_for_unit('I3TwoLDFSignalModel', icetray.I3LogLevel(outputLevel)) icetray.set_log_level_for_unit('I3TopLeanFitter', icetray.I3LogLevel(outputLevel)) icetray.set_log_level_for_unit('I3TopSeedService', icetray.I3LogLevel(outputLevel)) gcdfile = [options.gcd] # Instantiate a tray tray = I3Tray() HLCPulses = 'OfflineIceTopSelectedHLC' SLCPulses = 'OfflineIceTopSelectedSLC' tray.AddService( 'I3GulliverMinuitFactory', 'Minuit', MinuitPrintLevel=-2, FlatnessCheck=True, Algorithm='SIMPLEX', MaxIterations=2500, MinuitStrategy=2, Tolerance=0.01, ) tray.AddService( 'TwoLDFSignalModel', 'TwoLDFSignalModel', TankResponseTablesDir= '/data/icet0/gonzalez/IceCubeSoftware/Sandbox/rock_bottom/resources/data/tank_response' ) tray.AddService('I3TopLDFLikelihoodFactory', 'TwoLDFLikelihood', Model='TwoLDFSignalModel', HLCPulses=HLCPulses, SLCPulses=SLCPulses, SaturatedPulses='', IgnoreTanks='') tray.AddService('I3TopTrivialGulliverParametrizationFactory', 'TwoLDFParam', Parameters=dataclasses.I3MapStringVectorDouble({ 'S_ref': (numpy.nan, numpy.nan, 2), 'rho_mu_ref': [1.], 'age': [0.8] })) tray.AddService( 'I3TopSeedServiceFactory', 'TwoLDFSeed', Seed='Laputop', HLCPulses=HLCPulses, SLCPulses=SLCPulses, SignalModel='TwoLDFSignalModel', ) tray.AddModule('I3Reader', 'Reader', FilenameList=gcdfile + inputFiles) #def select(frame): return True #tray.AddSegment(select, 'selection') tray.AddModule('I3TopLeanFitter', 'TwoLDFLeanFitter', Minimizer='Minuit', Parametrization='TwoLDFParam', LogLikelihood='TwoLDFLikelihood', Seed='TwoLDFSeed') tray.AddModule('I3Writer', 'i3-writer', Filename=outfile, DropOrphanStreams=[icetray.I3Frame.DAQ], streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Physics]) tray.AddModule('TrashCan', 'Done') # Execute the Tray if n is None: tray.Execute() else: tray.Execute(n) tray.Finish()