Exemple #1
0
def _model_flux_weighting(model='H3a', energy=None, num_groups=4):

    comp_list = get_comp_list(num_groups=num_groups)

    if energy is None:
        energy = get_energybins().energy_midpoints

    model_names = ['H3a', 'H4a', 'Polygonato']
    assert model in model_names
    flux_models = [GaisserH3a(), GaisserH4a(), Hoerandel5()]
    model_dict = dict(zip(model_names, flux_models))
    flux = model_dict[model]

    p = PDGCode().values
    pdg_codes = np.array([2212, 1000020040, 1000080160, 1000260560])
    particle_names = [p[pdg_code].name for pdg_code in pdg_codes]

    group_names = np.array(
        composition_group_labels(particle_names, num_groups=num_groups))

    comp_to_pdg_list = {
        composition: pdg_codes[group_names == composition]
        for composition in comp_list
    }

    # Replace O16Nucleus with N14Nucleus + Al27Nucleus
    for composition, pdg_list in comp_to_pdg_list.items():
        if 1000080160 in pdg_list:
            pdg_list = pdg_list[pdg_list != 1000080160]
            comp_to_pdg_list[composition] = np.append(pdg_list,
                                                      [1000070140, 1000130270])
        else:
            continue

    flux_df = pd.DataFrame()
    for composition in comp_list:
        comp_flux = []
        for energy_mid in energy:
            flux_energy_mid = flux(energy_mid,
                                   comp_to_pdg_list[composition]).sum()
            comp_flux.append(flux_energy_mid)
        flux_df['flux_{}'.format(composition)] = comp_flux

    flux_df['flux_total'] = flux_df.sum(axis=1)

    return flux_df
Exemple #2
0
    s = str(ptype)[:6]
    if s == '100002':
        ptype = 1000020040
    elif s == '100007':
        ptype = 1000070140
    elif s == '100008':
        ptype = 1000080160
    elif s == '100013':
        ptype = 1000130270
    elif s == '100026':
        ptype = 1000260560
    return ptype


print(generator([100000], [1000020040]))
flux = GaisserH4a()
events = []
count = 0
nan_count = 0
zero_count = 0
for file_name in files:
    try:
        x = np.load(file_name, mmap_mode="r")['arr_0']
    except Exception:
        print(file_name)
        pass

    spl = file_name.split('_')
    for e in x:
        event = np.zeros(1, dtype=event_dtype)
        qtot = e['qtot']
Exemple #3
0
def main():

    #arguement parser
    parser = argparse.ArgumentParser(
        description='Generates muons in IceCube with varying multiplicity')
    parser.add_argument('inp', nargs='+')
    parser.add_argument('--nseed',
                        default=1,
                        type=int,
                        help='seed for randomization')
    parser.add_argument('--out', default='corsika', help='Output file')
    parser.add_argument('--runnum',
                        default=1,
                        type=int,
                        help='Run number for this sim')
    parser.add_argument('--did',
                        default=20694,
                        type=int,
                        help='Simpord Number for this sim')
    parser.add_argument('--nfiles',
                        default=1,
                        type=int,
                        help='Number of files to generate')
    #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')
    args = parser.parse_args()

    #geometry parameters
    gcdFile = args.gcd
    surface = Cylinder(1600 * I3Units.m, 800 * I3Units.m,
                       dataclasses.I3Position(0, 0, 0))
    surface_det = MuonGun.ExtrudedPolygon.from_file(gcdFile)

    #setup reconstruction parameters
    pulses = 'InIcePulses'
    HLCpulses = 'HLCInIcePulses'

    #setup I3Tray
    tray = I3Tray()
    tray.context['I3RandomService'] = phys_services.I3GSLRandomService(
        seed=args.nseed)
    #tray.context['I3RandomService'] =  phys_services.I3SPRNGRandomService(seed = args.nseed)
    infiles = args.inp

    tray.Add('I3Reader', Filenamelist=[args.gcd] + infiles)

    #weighting
    tray.Add(header, streams=[icetray.I3Frame.DAQ])
    tray.Add("I3NullSplitter")
    generator = weighting.FiveComponent(947487,
                                        1000,
                                        1e+07,
                                        normalization=[5, 2.5, 1.1, 1.2, 1],
                                        gamma=[-2.65, -2.6, -2.6, -2.6, -2.6],
                                        height=1000,
                                        radius=500,
                                        LowerCutoffType='EnergyPerNucleon',
                                        UpperCutoffType='EnergyPerNucleon')
    nfiles = args.nfiles
    generator *= nfiles
    flux = GaisserH4a()
    tray.Add(getweights, generator=generator, flux=flux)

    #find intersecting muons
    tray.Add(muonstodet, surface=surface_det)
    tray.Add(primarytodet, surface=surface_det)

    #do an N > 0 cut
    global total_events
    total_events = 0
    global passed_events
    passed_events = 0

    def ncut(frame):
        global total_events
        global passed_events
        total_events += 1
        if frame.Has('EnteringMuon_0'):
            passed_events += 1
            return True
        else:
            return False

    tray.AddModule(ncut, 'ncut')

    #write everything to file
    tray.AddModule(
        'I3Writer',
        'writer',
        Streams=[
            icetray.I3Frame.Physics,
            #icetray.I3Frame.DAQ
        ],
        filename=args.out + "_" + str(args.nseed) + ".i3.gz")
    tray.Execute()
    tray.Finish()
    print "totol events processed: " + str(total_events)
    print "total events with one muon: " + str(passed_events)
    print "efficiency: %0.2f" % (1. * passed_events / total_events)
    end_time = time.asctime()
    print 'Ended:', end_time