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()
   def Execute(self,stats):
        if not ipmodule.ParsingModule.Execute(self,stats): return 0

        import icecube.icetray
        from icecube import icetray,dataclasses, phys_services, dataio
        from icecube.MuonGun import load_model, StaticSurfaceInjector, Cylinder, OffsetPowerLaw
        from icecube.MuonGun.segments import GenerateBundles

        from I3Tray import I3Tray, I3Units
        
        modelstr = self.GetParameter('model')
        emax   = self.GetParameter("eprimarymax")
        emin   = self.GetParameter("eprimarymin")
        length = self.GetParameter("length")
        radius = self.GetParameter("radius")
        cthmin = self.GetParameter('cthmin')
        cthmax = self.GetParameter('cthmax')
        gamma  = self.GetParameter('gamma')

        seed   = self.GetParameter('seed')
        nproc  = self.GetParameter('nproc')
        procnum  = self.GetParameter('procnum')
        gcdfile = self.GetParameter('gcdfile')
    
        # Instantiate a tray 
        tray = I3Tray()

        # Configure IceTray services
        summary = dataclasses.I3MapStringDouble()
        tray.context["I3SummaryService"] = summary
         
        randomService = phys_services.I3SPRNGRandomService(seed, nproc, procnum)
        tray.context["I3RandomService"] = randomService


        # Use Hoerandel as a template for generating muons
        model = load_model(modelstr)
        # Generate only single muons, no bundles
        model.flux.max_multiplicity = 1
        # Center the sampling surface on the barycenter of IC79 strings
        #surface = Cylinder(1600*I3Units.m, 800*I3Units.m, dataclasses.I3Position(31.25, 19.64, 0))
        surface = Cylinder(length*I3Units.m, radius*I3Units.m)
        # Draw energies from an E^-2 power law broken at 1 TeV, from 10 TeV to 10 PeV
        spectrum = OffsetPowerLaw(gamma, 1*I3Units.TeV, 10*I3Units.TeV, 10*I3Units.PeV)
        # Set up the generator. This gets stored in a special frame for later reference
        generator = StaticSurfaceInjector(surface, model.flux, spectrum, model.radius)

        # Configure TraySegment that actually does stuff
        tray.AddSegment(GenerateBundles,"corsika-background", Generator=generator, 
              RunNumber=self.runid, NEvents=self.nshowers, 
              GCDFile=self.gcdfile,
              FromTime=dataclasses.I3Time(self.mjd),
              ToTime=dataclasses.I3Time(self.mjd))

        def renameMCTree(frame):
          mctree = frame["I3MCTree"]
          del frame["I3MCTree"]
          frame["I3MCTree_preMuonProp"] = mctree
        tray.AddModule(renameMCTree, "renameMCTree", Streams=[icetray.I3Frame.DAQ])
        tray.AddSegment(PropagateMuons,'propagator', RandomService=randomService, 
             CylinderLength=self.length,
             CylinderRadius=self.radius,
             bs=self.bs,
             ph=self.ph,
             bb=self.bb,
             sh=self.sh)

        tray.AddModule(BasicCounter,"count_g", Streams = [icetray.I3Frame.DAQ], 
              name = "Generated Events", Stats = stats)
       
        tray.AddModule("I3Writer","writer", filename = self.outputfile, streams =[icecube.icetray.I3Frame.DAQ] )

        

        # Execute the Tray
        tray.Execute()
        

        del tray
        return 0
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=100,
                        type=int,
                        help='Maximum muon bundle multiplcity')
    parser.add_argument('--emin',
                        default=1e3,
                        type=float,
                        help='Muon min energy (GeV)')
    parser.add_argument('--emax',
                        default=1e7,
                        type=float,
                        help='Muon max energy (GeV)')
    parser.add_argument('--nevents',
                        default=1000,
                        type=int,
                        help='Number of events')
    parser.add_argument('--nfiles',
                        default=1,
                        type=int,
                        help='Number of files to generate')
    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)
    flux = model.flux
    radii = model.radius
    energies = model.energy
    #surface = MuonGun.ExtrudedPolygon.from_file(gcdFile, padding=60*I3Units.m)
    surface = Cylinder(1200 * I3Units.m, 600 * I3Units.m,
                       dataclasses.I3Position(0, 0, 0))
    generator = NaturalRateInjector(surface, flux, energies)
    #spectrum = OffsetPowerLaw(1, 1*I3Units.TeV, args.emin, args.emax)
    #generator = StaticSurfaceInjector(surface, model.flux, spectrum, model.radius)

    #setup I3Tray
    tray = I3Tray()
    tray.context['I3RandomService'] = phys_services.I3GSLRandomService(
        seed=args.nseed)
    #generate events
    #tray.AddModule("I3MuonGun::GeneratorModule", 'MuonGenerator',
    #               Generator=generator)
    tray.AddSegment(GenerateBundles,
                    'MuonGenerator',
                    Generator=generator,
                    RunNumber=args.runnum,
                    NEvents=args.nevents,
                    GCDFile=gcdFile)

    #propagate particles
    tray.Add(segments.PropagateMuons,
             'PropagateMuons',
             RandomService='I3RandomService',
             InputMCTreeName="I3MCTree",
             OutputMCTreeName="I3MCTree")
    tray.Add(header, streams=[icetray.I3Frame.DAQ])
    tray.Add("I3NullSplitter")

    #more muongun stuff
    tray.AddModule('I3MuonGun::WeightCalculatorModule',
                   'Weight',
                   Model=BundleModel(flux, radii, energies),
                   Generator=args.nfiles * args.nevents * generator)
    tray.AddModule('I3MuonGun::WeightCalculatorModule',
                   'Biased_Weight',
                   Model=model,
                   Generator=args.nfiles * args.nevents * generator)
    tray.Add(find_primary)
    surface_det = MuonGun.ExtrudedPolygon.from_file(gcdFile)
    tray.Add(todet, surface=surface_det)

    #do an N > 0 cut
    def ncut(frame):
        if frame.Has('EnteringMuon_0'):
            return True
        else:
            return False

    tray.AddModule(ncut, 'ncut')

    #effective area
    def eff_area(frame, generator):
        mctree = frame['I3MCTree']
        primary = mctree.primaries[0]
        muon = mctree.get_daughters(primary)[0]
        bundle = BundleConfiguration([BundleEntry(0, muon.energy)])
        fluence = generator.generated_events(primary, bundle)
        if fluence > 0.:
            area = 1. / fluence
            frame["MCMuon"] = muon
            frame["MuonEffectiveArea"] = dataclasses.I3Double(area)
        else:
            icecube.icetray.logging.log_warn(
                "Fluence value of {0:f} encountered.".format(fluence),
                unit="GenerateSingleMuons")
        return True

    tray.AddModule(eff_area, 'effective area', generator=generator)

    #detector stuff
    pulses = 'InIcePulses'
    #tray.Add(segments.PropagatePhotons, 'PropagatePhotons',
    #         RandomService='I3RandomService',
    #         HybridMode=args.hybrid,
    #         MaxParallelEvents=100,
    #         UseAllCPUCores=True,
    #         UseGPUs=args.use_gpu)

    #tray.Add(segments.DetectorSim, "DetectorSim",
    #         RandomService='I3RandomService',
    #         RunID=args.runnum,
    #         KeepPropagatedMCTree=True,
    #         KeepMCHits=True,
    #         KeepMCPulses=True,
    #         SkipNoiseGenerator=True,
    #         GCDFile=gcdFile,
    #         InputPESeriesMapName="I3MCPESeriesMap")

    #write everything to file
    tray.AddModule(
        'I3Writer',
        'writer',
        Streams=[
            icetray.I3Frame.Physics,
            icetray.I3Frame.Simulation,
            #icetray.I3Frame.DAQ
        ],
        filename=args.out)
    tray.Execute()
    tray.Finish()
Esempio n. 4
0
def main():
    parser = argparse.ArgumentParser(
        description='Generates muons in IceCube with varying multiplicity')
    parser.add_argument('--nseed',
                        default=1,
                        type=int,
                        help='seed for randomization')
    parser.add_argument('--model',
                        default='Hoerandel5_atmod12_SIBYLL',
                        type=str)
    parser.add_argument('--gcd', default='auto', type=str)
    parser.add_argument('--ice',
                        default='SpiceLea',
                        help='Either Spice1, SpiceMie or SpiceLea')
    parser.add_argument('--include-gcd',
                        default=False,
                        action='store_true',
                        help='Include GCD in output')
    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('--emin',
                        default=1e3,
                        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=1e3,
                        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')
    parser.add_argument('--use-gpu',
                        action='store_true',
                        default=False,
                        help='simulate using GPUs instead of CPU cores')
    args = parser.parse_args()

    if args.gcd == 'auto':
        gcdFilesDefault = {
            'IC86':
            os.path.expandvars(
                '$I3_TESTDATA/sim/GeoCalibDetectorStatus_IC86.55697_corrected_V2.i3.gz'
            ),
            'IC79':
            os.path.expandvars(
                '$I3_TESTDATA/sim/GeoCalibDetectorStatus_IC79.55380_L2a.i3.gz'
            ),
        }
        gcdFile = gcdFilesDefault[args.detector]
    else:
        gcdFile = args.gcd

    tray = I3Tray()
    tray.context['I3RandomService'] = phys_services.I3GSLRandomService(
        seed=args.nseed)
    gcd = expandvars(
        '$I3_TESTDATA/sim/GeoCalibDetectorStatus_IC86.55697_corrected_V2.i3.gz'
    )

    model = load_model(args.model)
    surface = Cylinder(1600 * I3Units.m, 800 * I3Units.m,
                       dataclasses.I3Position(0, 0, 0))
    spectrum = OffsetPowerLaw(2, 0 * I3Units.TeV, args.emin * I3Units.GeV,
                              args.emax * I3Units.GeV)
    generator = StaticSurfaceInjector(surface, model.flux, spectrum,
                                      model.radius)

    tray.AddSegment(GenerateBundles,
                    'MuonGenerator',
                    Generator=generator,
                    NEvents=args.nevents,
                    GCDFile=gcd)
    tray.AddModule('I3MuonGun::WeightCalculatorModule',
                   'MuonWeight',
                   Model=model,
                   Generator=generator)

    icetray.logging.set_level_for_unit("I3PropagatorService", "TRACE")
    icetray.logging.set_level_for_unit("I3PropagatorMMC", "TRACE")
    icetray.logging.set_level_for_unit("I3PropagatorServiceMMC", "TRACE")

    tray.Add(segments.PropagateMuons,
             'PropagateMuons',
             RandomService='I3RandomService')
    tray.Add(segments.PropagatePhotons,
             "PropagatePhotons",
             InputMCTree='I3MCTree',
             MaxParallelEvents=1,
             KeepIndividualMaps=False,
             IceModel=args.ice,
             UnshadowedFraction=0.9,
             HybridMode=args.hybrid,
             IgnoreMuons=False,
             UseAllCPUCores=True,
             UseGPUs=args.use_gpu)
    tray.Add(segments.DetectorSim,
             "DetectorSim",
             RandomService='I3RandomService',
             RunID=args.runnum,
             GCDFile=gcdFile,
             InputPESeriesMapName="I3MCPESeriesMap",
             KeepMCHits=True,
             KeepPropagatedMCTree=True,
             SkipNoiseGenerator=False)
    #tray.AddModule('I3PropagatorModule', 'propagator', PropagatorServices=make_propagators(),
    #	       RandomService='I3RandomService', RNGStateName="RNGState")
    tray.AddModule('I3Writer',
                   'writer',
                   Streams=list(map(icetray.I3Frame.Stream, "SQP")),
                   filename=args.model + "_" + args.out)

    tray.Execute()
Esempio n. 5
0
    '$I3_TESTDATA/sim/GeoCalibDetectorStatus_IC80_DC6.54655.i3.gz')

import sys
outfile = sys.argv[1]

tray = I3Tray()

randomService = phys_services.I3SPRNGRandomService(1, 10000, 1)
tray.context['I3RandomService'] = randomService

from icecube.icetray import I3Units
from icecube.MuonGun import load_model, StaticSurfaceInjector, Cylinder, OffsetPowerLaw
from icecube.MuonGun.segments import GenerateBundles

# Use Hoerandel as a template for generating muons
model = load_model('Hoerandel5_atmod12_SIBYLL')
# Generate only single muons, no bundles
model.flux.max_multiplicity = 1
# Center the sampling surface on the barycenter of IC79 strings
surface = Cylinder(1600 * I3Units.m, 800 * I3Units.m,
                   dataclasses.I3Position(31.25, 19.64, 0))
surface = Cylinder(1600 * I3Units.m, 800 * I3Units.m)
# Draw energies from an E^-2 power law broken at 1 TeV, from 10 TeV to 10 PeV
spectrum = OffsetPowerLaw(2, 1 * I3Units.TeV, 10 * I3Units.TeV,
                          10 * I3Units.PeV)
# Set up the generator. This gets stored in a special frame for later reference
generator = StaticSurfaceInjector(surface, model.flux, spectrum, model.radius)

tray.AddSegment(GenerateBundles,
                'MuonGenerator',
                Generator=generator,