Ejemplo n.º 1
0
 def _get_detector(self, gcd_file, output_file='detector.pickle'):
     ''' Generate detector contour using DeepCoreLabels
         Args:
             gcd_file: dataio.I3File
             I3File with at least a geometry frame.
         Returns: dict
             DOM positions of detector contours
     '''
     create_new = True
     if os.path.isfile(output_file):
         create_new = inp('{} already exists. '\
                          'Create new? [y/n] '.format(output_file))
         create_new = strtobool(create_new)
     if create_new:
         tray = I3Tray()
         tray.AddModule('I3Reader', 'reader', Filename=gcd_file)
         # create output_file in current folder
         tray.AddModule(dl.DeepCoreLabels,
                        'labelmaker',
                        DETECTOR_BUILD_ONLY=True,
                        EXTENDED=False)
         tray.AddModule('TrashCan', 'can')
         tray.Execute()
         tray.Finish()
         # load detector file to return it
     if sys.version_info[0] >= 3:
         import pickle
     else:
         import cPickle as pickle
     self._detector = pickle.load(open(output_file, 'rb'))
Ejemplo n.º 2
0
def test_my_little_function():
    my_features = ['muon_x', 'muon_y', 'muon_z', 'is_stopped']

    parser = argparse.ArgumentParser()
    parser.add_argument('-i', '--infiles', required=True)
    args = parser.parse_args()
    filelist = args.infiles.split(',')
    for nums in range(len(filelist)):
        if nums == (len(filelist) - 1):
            filelist[nums] = filelist[nums][:-1]
        featurestemp = [[] for i in range(len(my_features))]
        global event_run
        event_run = filelist[nums].split('/')[-1].split('.')[-3]

        tray = I3Tray()
        tray.AddModule('I3Reader', 'read_stuff', Filename=filelist[nums])
        tray.AddModule(test, 'test')
        tray.AddModule(savefeatures,
                       'asd',
                       fin=featurestemp,
                       names=my_features)
        tray.Execute()
        if nums == 0:
            featuresarray = np.column_stack(np.array(featurestemp))
        else:
            featuresarray = np.concatenate(
                (featuresarray, np.column_stack(featurestemp)), axis=0)
    return featuresarray
Ejemplo n.º 3
0
    def Execute(self, stats):
        'Runs the tray, but the important stuff happens in segment_X(...)'
        if not ipmodule.ParsingModule.Execute(self,stats):
            return 0

        # Load libraries
        from icecube import clsim
        from icecube import phys_services
        from icecube import sim_services
        from icecube import vuvuzela
        from icecube import DOMLauncher
        from icecube import trigger_sim

        # Instantiate a tray
        tray = I3Tray()

        self.segment_input(tray, stats)
        self.segment_main(tray, stats)
        self.segment_output(tray, stats)

        # Execute the Tray
        tray.Execute()
        tray.Finish()

        tray.PrintUsage()
        for k in tray.Usage():
            stats[str(k.key())+":usr"] = k.data().usertime
            stats[str(k.key())+":sys"] = k.data().systime
            stats[str(k.key())+":ncall"] = k.data().systime

        # Free memory
        del tray
        return 0
Ejemplo n.º 4
0
	def runtray(cls, fname):
		tray = I3Tray.I3Tray()
		
		tray.AddModule("I3InfiniteSource", "source", stream=icetray.I3Frame.DAQ)
		
		tray.AddModule(headerfaker, 'headers', Streams=[icetray.I3Frame.DAQ])
		
		tray.AddModule("I3NullSplitter", "s1")
		tray.AddModule("I3NullSplitter", "s2")
		
		for i in range(10):
			tray.AddModule(emitter, 's1e%d' % i, label='s1e%d' % i, prob=0.1, If=streampick("s1"))
			
		for i in range(10):
			tray.AddModule(emitter, 's2e%d' % i, label='s2e%d' % i, prob=0.1, If=streampick("s2"))

		tabler = hdfwriter.I3HDFTableService(fname)
		tray.AddModule(tableio.I3TableWriter, 'scribe',
			tableservice=tabler,
			types=[dataclasses.I3Particle],
			SubEventStreams=['s1','s2'],
			)
		
		tray.AddModule('TrashCan', 'YesWeCan')
		tray.Execute(100)
		tray.Finish()
Ejemplo n.º 5
0
def validate_i3_files(files):
    """ Checks that input i3 files aren't corrupted

    Parameters
    ----------
    files : array-like
        Iterable of i3 file paths to check.

    Returns
    -------
    good_file_list : list
        List of i3 files (from input files) that were able to be
        succeessfully loaded.
    """
    if isinstance(files, str):
        files = [files]

    good_file_list = []
    for i3file in files:
        try:
            test_tray = I3Tray()
            test_tray.Add('I3Reader', FileName=i3file)
            test_tray.Add(uncompress, 'uncompress')
            test_tray.Execute()
            test_tray.Finish()
            good_file_list.append(i3file)
        except RuntimeError:
            icetray.logging.log_warn('File {} is truncated'.format(i3file))
        finally:
            del test_tray

    return good_file_list
Ejemplo n.º 6
0
def TestCuts(file_list):
    tray = I3Tray()
    tray.AddModule("I3Reader","reader", FilenameList = file_list)
    tray.AddModule(Check_Data, "check-raw-data", Streams=[icetray.I3Frame.Physics])
    tray.AddSegment(QTot.CalQTot, "selfveto-qtot", pulses= PULSES_KEY)
    tray.AddModule(Get_Charges, "cuts-and-secelt", Streams=[icetray.I3Frame.Physics])
    tray.AddSegment(Reconstruction.OfflineCascadeReco, "CscdReco", suffix="_DP", Pulses='HLCPulses')
    tray.AddSegment(Reconstruction.MuonReco, "MuonReco", Pulses='HLCPulses')
    tray.AddModule(LLH_cut, "llhcut", Streams=[icetray.I3Frame.Physics])
    tray.AddSegment(Reconstruction.OfflineCascadeReco_noDC, "CscdReco_noDC", suffix="_noDC_DP", Pulses='HLCPulses')
    tray.AddSegment(Reconstruction.MuonReco_noDC, "MuonReco_noDC", Pulses='HLCPulses')
    tray.AddSegment(PolygonContainment.PolygonContainment, 'polyfit', geometry = GEO,RecoVertex='HESE3_VHESelfVetoVertexPos',outputname='_Veto')
   # tray.AddModule("I3TensorOfInertia",InputReadout = pulse_series)
    tray.AddModule("I3WaveCalibrator", "calibrator")(        
	("Launches", "InIceRawData"),  # EHE burn sample IC86
        ("Waveforms", "CalibratedWaveforms"),
        ("WaveformRange", "CalibratedWaveformRange_DP"),
        ("ATWDSaturationMargin",123), # 1023-900 == 123
        ("FADCSaturationMargin",  0), # i.e. FADCSaturationMargin
        ("Errata", "BorkedOMs"), # SAVE THIS IN L2 OUTPUT?
        )
    tray.AddModule("I3WaveformSplitter", "waveformsplit")(
        ("Input","CalibratedWaveforms"),
        ("HLC_ATWD","CalibratedWaveformsHLCATWD"),
        ("HLC_FADC","CalibratedWaveformsHLCFADC"),
        ("SLC","CalibratedWaveformsSLC"),
        ("PickUnsaturatedATWD",True),
        ("Force",True),
        )
    tray.Add(Make_Image, "getwave", Streams=[icetray.I3Frame.Physics])
#    tray.AddModule('I3Writer', 'writer', Filename= outfile+'.i3.bz2', Streams=[icetray.I3Frame.DAQ,icetray.I3Frame.Physics], DropOrphanStreams=[icetray.I3Frame.DAQ])
    tray.AddModule('TrashCan','thecan')
    tray.Execute()
    tray.Finish()
    return
Ejemplo n.º 7
0
    def Execute(self, stats):
        'Runs the tray, but the important stuff happens in segment_X(...)'

        if not ipmodule.ParsingModule.Execute(self, stats):
            return 0

        # Load libraries
        from icecube import (earthmodel_service, PROPOSAL, cmc, phys_services)
        from icecube import (polyplopia, dataclasses, dataio)

        # support json ParamsMap, so we can get our dict from the iceprod config file
        try:
            import json
        except ImportError:
            json = None

        # Instantiate a tray
        tray = I3Tray()

        randomService = phys_services.I3SPRNGRandomService(
             seed = self.seed,
             nstreams = self.nproc,
             streamnum = self.procnum)\
            if not self.usegslrng else phys_services.I3GSLRandomService(seed)

        tray.context['I3RandomService'] = randomService

        # Configure IceTray modules
        tray.AddModule("I3Reader",
                       "reader",
                       FilenameList=[self.gcdfile, self.inputfile])

        from .. import segments
        from I3Tray import I3Units

        tray.Add(segments.PolyplopiaMergePEs,
                 "merge",
                 mctype=self.mctype,
                 RandomService=randomService,
                 mctree_name="I3MCTree",
                 bgfile=self.backgroundfile,
                 separate_coincident_mctree_name="BackgroundI3MCTree",
                 timewindow=self.timewindow,
                 rate=5.0 * I3Units.kilohertz)

        tray.AddModule("I3Writer",
                       "writer",
                       Filename=self.outputfile,
                       Streams=[
                           icetray.I3Frame.TrayInfo, icetray.I3Frame.DAQ,
                           icetray.I3Frame.Stream('S'),
                           icetray.I3Frame.Stream('M')
                       ])

        # Execute the Tray
        tray.Execute()

        # Free memory
        del tray
        return 0
Ejemplo n.º 8
0
    def runTest(self):
        output_file = 'test/output.i3.gz'
        tray = I3Tray()
        tray.AddModule('I3Reader',
                       'reader',
                       Filenamelist=[self.gcd_file, self.i3_file])
        tray.AddModule(dl.DeepCoreLabels, 'labelmaker')
        tray.AddModule('I3Writer',
                       'writer',
                       Filename=os.path.join(self.path, output_file),
                       Streams=[icetray.I3Frame.Physics, icetray.I3Frame.DAQ])
        tray.AddModule('TrashCan', 'can')
        tray.Execute()
        i3_file = dataio.I3File(os.path.join(self.path, output_file))
        p_frame = i3_file.pop_physics()

        self.assertTrue('cc_in_deepcore' in p_frame, 'cc_in_deepcore was not'\
        ' found in i3_file after module execution')

        # cleaning up
        del tray
        del i3_file
        del p_frame

        # create plots
        self.i3_file = output_file
        self._get_detector(self.gcd_file)
        self._get_data(self.i3_file)
        self._plot_view(view='top')
        self._plot_view(view='side')
Ejemplo n.º 9
0
   def Execute(self,stats):

        from icecube import dataclasses

        if not ipmodule.ParsingModule.Execute(self,stats):
                return 0

        # Instantiate a tray 
        tray = I3Tray()

        # Configure IceTray services
        if os.path.exists(self.summaryfile):
           summary = ReadI3Summary(self.summaryfile)
        else: 
           summary = dataclasses.I3MapStringDouble()
        tray.context['I3SummaryService'] = summary

        # Configure IceTray modules 
        tray.AddModule("I3Reader", "reader",filenamelist=[self.gcdfile]+self.inputfilelist)

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

    from icecube import phys_services
    from icecube import sim_services
    from .. import segments

    tray = I3Tray()

    if self.summaryfile:
      tray.AddService('I3XMLSummaryServiceFactory','summaryfile',
                      outputfilename=self.summaryfile, inputfilename=self.summaryfile)

    # set the random number generator
    rngstate    = "rng.state"
    if not os.path.exists(rngstate):
      rngstate = ''
      print("Warning: no RNG state found. Using seed instead.")

    tray.AddService("I3SPRNGRandomServiceFactory","random",
                    Seed = self.seed,
                    StreamNum = self.procnum,
                    NStreams = self.nproc,
                    instatefile = rngstate,
                    outstatefile = 'rng.state',
                    )

    tray.AddModule("I3Reader","reader",
                   filenamelist = [self.gcdfile, self.inputfile],
                   )

    # The main segment
    tray.AddSegment(segments.IceTopSim, 'IceTopSim',
                    sim_trigger = self.sim_trigger,
                    sim_new = self.domlauncher,
                    calibrate = self.calibrate,
                    gcd = self.gcdfile,
                    )

    tray.AddModule("I3Writer","writer",
                   filename = self.outputfile,
                   streams = [I3Frame.DAQ],
                   )

    tray.AddModule("TrashCan","adios")

    tray.Execute()
    tray.Finish()

    tray.PrintUsage()
    for k in tray.Usage():
            stats[str(k.key())+":usr"] = k.data().usertime
            stats[str(k.key())+":sys"] = k.data().systime
            stats[str(k.key())+":ncall"] = k.data().systime

    # Free memory
    del tray
    return 0
Ejemplo n.º 11
0
def test_my_little_function():
    my_features = [
        'x', 'y', 'z', 'charge', 'domrad', 'domstr', 'status', 'eventid'
    ]
    my_truth = [
        'start_x', 'start_y', 'start_z', 'end_x', 'end_y', 'end_z', 'theta',
        'eventid'
    ]
    parser = argparse.ArgumentParser()
    parser.add_argument('-i', '--infiles', required=True)
    args = parser.parse_args()
    filelist = args.infiles.split(',')
    first_file_bad = 1
    for nums in range(len(filelist)):
        #		if nums == (len(filelist)-1):
        #			filelist[nums] = filelist[nums][:-1]
        featurestemp = [[] for i in range(len(my_features))]
        truthtemp = [[] for i in range(len(my_truth))]
        global event_run
        event_run = filelist[nums].split('/')[-1].split('.')[-3].split('_')[-1]
        #		event_run = filelist[nums].split('/')[-1].split('.')[-3]
        tray = I3Tray()
        tray.AddModule('I3Reader', 'read_stuff', Filename=filelist[nums])
        tray.AddModule('Delete', keys=["MMCTrackList"])
        tray.AddSegment(propagation.RecreateMCTree,
                        "recreate",
                        RawMCTree="I3MCTree_preMuonProp",
                        RNGState="I3MCTree_preMuonProp_RNGState",
                        Paranoia=False)
        tray.AddModule(test, 'test')
        tray.AddModule(savefeatures,
                       'asd',
                       fin=featurestemp,
                       names=my_features)
        tray.AddModule(savetruth, 'asd2', fin=truthtemp, names=my_truth)
        tray.Execute()
        for i in range(len(featurestemp)):
            featurestemp[i] = [
                item for sublist in featurestemp[i] for item in sublist
            ]
        featuresarray = np.column_stack(featurestemp)
        trutharray = np.column_stack(truthtemp)
        trutharray = trutharray[np.unique(trutharray[:, -1],
                                          return_index=True)[1]]
        if len(trutharray) > 10:
            if (nums == 0) or (first_file_bad == 1):
                print('Grouping')
                group, truth = get_groups(featuresarray[:, :-1], trutharray,
                                          featuresarray[:, -1])
                first_file_bad = 0
            else:
                print('Grouping and concatenating')
                tmp = get_groups(featuresarray[:, :-1], trutharray,
                                 featuresarray[:, -1])
                group = np.concatenate((group, np.copy(tmp[0])), axis=0)
                truth = np.concatenate((truth, np.copy(tmp[1])), axis=0)
        else:
            print('BAD FILE: ' + str(filelist[nums]))
    return group, truth
Ejemplo n.º 12
0
def main(input_files, output_file, count_frames=10):
    print("Creating I3Tray for", input_files)
    tray = I3Tray()
    tray.AddModule("I3Reader", "reader", Filenamelist=input_files)
    tray.AddSegment(wavecal.CalibrationAndCleaning, "CalibAndCleaning")
    tray.AddModule(ExtractWaveforms, "my_module", output_file=output_file)
    tray.Add("Dump")
    tray.Execute(count_frames)
Ejemplo n.º 13
0
    def run_booker(self, horizons_filename, body):

        ephem = test_horizons.read_horizons(horizons_filename)

        csv_dir_name = "tableout"
        csv_filename = os.path.join(csv_dir_name, "I3EventHeader.csv")

        tray = I3Tray()
        tray.Add(generator, times=ephem['date'])
        tray.Add(tableio.I3TableWriter,
                 tableservice=[tableio.I3CSVTableService(csv_dir_name)],
                 keys={
                     'I3EventHeader': [
                         astro.converters.I3SunAndMoonConverter(),
                         dataclasses.converters.I3EventHeaderConverter()
                     ],
                 })

        tray.Execute()
        tray.Finish()
        del tray

        with open(csv_filename, 'r') as csvfile:
            reader = csv.reader(csvfile)
            header = reader.next()

            keys = [
                'time_start_mjd_day [days]', 'time_start_mjd_sec [seconds]',
                'time_start_mjd_ns [ns]', body + '_zenith [radian]',
                body + '_azimuth [radian]'
            ]
            indices = {}
            for k in keys:
                indices[k] = header.index(k)

            #skip info row
            reader.next()

            for line_number, row in enumerate(reader):

                #row_values = [row[indices[k]] for k in keys]

                t = dataclasses.I3Time()
                t.set_mod_julian_time(
                    int(row[indices['time_start_mjd_day [days]']]),
                    int(row[indices['time_start_mjd_sec [seconds]']]),
                    float(row[indices['time_start_mjd_ns [ns]']]))
                self.assertEqual(
                    t, dataclasses.make_I3Time(ephem['date'][line_number]))

                assert (
                    abs(90 - float(row[indices[body + '_zenith [radian]']]) /
                        I3Units.degree - ephem['el'][line_number]) < 0.003)

                assert (test_horizons.azimuth_distance(
                    90 - (float(row[indices[body + '_azimuth [radian]']]) +
                          astro.ICECUBE_LONGITUDE) / I3Units.degree,
                    ephem['az'][line_number]) < 1.)
Ejemplo n.º 14
0
def runtray():
	featurecol = ['events','x','y','z','charge','time','domstring','group','HQE','domrad']
	features = [[] for i in featurecol]
	tray = I3Tray()
	tray.AddModule('I3Reader', 'I3Reader', filename=file)
	tray.AddModule(RIDE,'RIDE')
	tray.AddModule(featuresave,'save_features',col=featurecol,features=features)
	tray.Execute()
	array = np.array([np.concatenate(i) for i in features]).T
Ejemplo n.º 15
0
def run(hook=lambda tray: None):
    tray = I3Tray()
    tray.AddModule("I3InfiniteSource", "maw", Stream=icetray.I3Frame.Physics)
    tray.AddModule(thing3, 'thing3')
    tray.AddModule(thing2, 'thing2')
    tray.AddModule(thing1, 'thing1')
    hook(tray)
    tray.AddModule('TrashCan', 'YesWeCan')
    tray.Execute(1)
    tray.Finish()
Ejemplo n.º 16
0
   def run_tray(self, cors):
        from icecube import icetray,phys_services, dataio, dataclasses
        from .. import segments
        # Instantiate a tray 
        tray = I3Tray()

        # Configure IceTray services
        summary = dataclasses.I3MapStringDouble()
        tray.context['I3SummaryService'] = summary
        
        if self.usegslrng:
            randomService = phys_services.I3GSLRandomService(self.seed)
        else:
            randomService = phys_services.I3SPRNGRandomService(self.seed, self.nproc, self.procnum)
        tray.context["I3RandomService"] = randomService

        tray.AddSegment(CorsikaReaderTraySegment,
                  gcdfile=self.gcdfile, randomService=randomService,
                  SimulateIceTop=self.simulateicetop,
                  select_neutrino=self.selectneutrino, 
                  legacyoversampling=self.legacyoversampling,
                  oversampling=self.oversampling, cors=cors, stats=self.stats)


        if self.enablehistogram and self.histogramfilename:         
            from icecube.production_histograms import ProductionHistogramModule
            from icecube.production_histograms.histogram_modules.simulation.mctree_primary import I3MCTreePrimaryModule
        
            tray.AddModule(ProductionHistogramModule, 
                           Histograms = [I3MCTreePrimaryModule],
                           OutputFilename = self.histogramfilename)
       
        tray.AddModule("I3Writer", 
                       filename = self.outputfile, 
                       Streams=[icetray.I3Frame.TrayInfo,
                                icetray.I3Frame.DAQ,
                                icetray.I3Frame.Stream('S'),
                                icetray.I3Frame.Stream('M')])
         
        # Execute the Tray
        tray.Execute()

        # Save stats
        summary = tray.context['I3SummaryService']

        for k in tray.Usage():
            self.stats[str(k.key())+":usr"] = k.data().usertime
            summary[str(k.key())+":usr"] = k.data().usertime
            self.stats[str(k.key())+":sys"] = k.data().systime
            summary[str(k.key())+":sys"] = k.data().systime
            self.stats[str(k.key())+":ncall"] = k.data().systime
            summary[str(k.key())+":ncall"] = k.data().systime

        WriteI3Summary(summary, self.summaryfile)
def main(in_files, out_file, gcd_file):
    files = []
    files.append(gcd_file)
    if not isinstance(in_files, list):
        in_files = [in_files]
    files.extend(in_files)

    tray = I3Tray()

    # Read files
    tray.AddModule("I3Reader", "reader", Filenamelist=files)

    # Create correct MCPrimary
    tray.AddModule(weighting.get_weighted_primary,
                   "weighted_primary",
                   If=lambda frame: not frame.Has("MCPrimary"))

    def rename(frame):
        """ Rename for older files not having 'InIcePulses' key """
        if not frame.Has('InIcePulses'):
            frame['InIcePulses'] = frame['OfflinePulses']
        return True

    # Rename frames if InIcePulses
    tray.AddModule(rename, 'rename')

    ##########################################################################
    # Following code from hesefilter.py
    # Prepare Pulses
    tray.AddModule("I3LCPulseCleaning",
                   "cleaning_HLC",
                   OutputHLC="InIcePulsesHLC",
                   OutputSLC="",
                   Input="InIcePulses",
                   If=lambda frame: not frame.Has("InIcePulsesHLC"))

    # Apply HESE filter
    tray.AddModule("VHESelfVeto", "selfveto", Pulses="InIcePulsesHLC")

    # Add CausalQTot frame
    tray.AddModule('HomogenizedQTot',
                   'qtot_causal',
                   Pulses="InIcePulses",
                   Output='HESE_CausalQTot',
                   VertexTime='VHESelfVetoVertexTime')
    ##########################################################################

    # Save IDs if event is HESE-like
    tray.AddModule(collector, "collector", outfilename=out_file)

    tray.AddModule("TrashCan", "NacHsart")
    tray.Execute()
    tray.Finish()
Ejemplo n.º 18
0
    def test_tableio(self):
        csv_dir_name = "tableout"
        csv_filename = os.path.join(csv_dir_name, "Particle.csv")
        if os.path.exists(csv_filename):
            print("deleting", repr(csv_filename))
            os.unlink(csv_filename)

        coords = []
        for line in open(TEST_DATA +
                         "simbad_tevcat_galactic.txt").readlines()[7:-2]:
            line = line.split('|')
            coords.append([
                float(i) for l in (line[3], line[6], line[5])
                for i in l.split()
            ])

        tray = I3Tray()
        tray.Add(generator, Coords=coords)
        tray.Add(tableio.I3TableWriter,
                 tableservice=[tableio.I3CSVTableService(csv_dir_name)],
                 keys={
                     'Particle': [
                         dataclasses.converters.I3ParticleConverter(),
                         astro.converters.I3AstroConverter(),
                         astro.converters.I3GalacticConverter(),
                         astro.converters.I3SuperGalacticConverter(),
                     ]
                 })

        tray.Execute()

        del tray

        with open(csv_filename, 'r') as csvfile:
            reader = csv.reader(csvfile)
            header = next(reader)

            keys = ['ra', 'dec', 'gal_l', 'gal_b', 'sg_l', 'sg_b']
            indices = {}
            for k in keys:
                indices[k] = header.index(k + ' [radian]')

            #skip info row
            next(reader)

            for line_number, row in enumerate(reader):
                row_values = [
                    float(row[indices[k]]) / I3Units.degree for k in keys
                ]
                for i in range(len(row_values)):
                    self.assertAlmostEqual(row_values[i],
                                           coords[line_number][i], 2)
Ejemplo n.º 19
0
    def run_tray(self, cors):
        from icecube import icetray, phys_services, dataio, dataclasses
        # Instantiate a tray
        tray = I3Tray()

        # Configure IceTray services
        tray.AddService("I3XMLSummaryServiceFactory",
                        "summary",
                        outputfilename=self.summaryfile)

        randomService = phys_services.I3SPRNGRandomService(
            self.seed, self.nproc, self.procnum)
        tray.context["I3RandomService"] = randomService

        if self.oversampling > 1 and self.usepipe:
            self.logger.fatal(
                "Oversampling is not compatible with UsePIPE at this time")
            sys.exit(1)

        tray.AddSegment(CorsikaReaderTraySegment,
                        gcdfile="",
                        randomService=randomService,
                        SimulateIceTop=self.simulateicetop,
                        oversampling=self.oversampling,
                        cors=cors,
                        stats=self.stats)

        if self.histogramfilename:
            from icecube.production_histograms import ProductionHistogramModule
            from icecube.production_histograms.histogram_modules.simulation.mctree_primary import I3MCTreePrimaryModule

            tray.AddModule(ProductionHistogramModule,
                           Histograms=[I3MCTreePrimaryModule],
                           OutputFilename=self.histogramfilename)

        tray.AddModule("I3Writer",
                       filename=self.outputfile,
                       streams=[icetray.I3Frame.DAQ])

        # Execute the Tray
        tray.Execute()
        tray.Finish()

        # Save stats
        tray.PrintUsage()
        for k in tray.Usage():
            self.stats[str(k.key()) + ":usr"] = k.data().usertime
            self.stats[str(k.key()) + ":sys"] = k.data().systime
            self.stats[str(k.key()) + ":ncall"] = k.data().systime
   def Execute(self,stats):
        if not ipmodule.ParsingModule.Execute(self,stats): return 0

        # Instantiate a tray 
        tray = I3Tray()

        randomService = phys_services.I3SPRNGRandomService(self.rngseed, self.rngnumberofstreams, self.rngstream)
        tray.context['I3RandomService'] = randomService

        if not self.summaryfile:
            raise Exception('must define summary file')
        tray.AddService("I3XMLSummaryServiceFactory","summary")(
            ("outputfilename",self.summaryfile),
        )
         
        tray.AddSegment(NuGenTraySegment,"nugen",
             gcdfile=self.gcdfile,
             nuflavor=self.nuflavor,
             mjd=self.mjd, 
             nevents=self.nevents,
             cssflag=self.usecss, 
             runId=self.runid,
             randomService=randomService,
             elogmax=self.elogmax,
             elogmin=self.elogmin,
             gamma=self.gamma,
             stats=stats,
             bs=self.bs,
             ph=self.ph,
             bb=self.bb,
             sh=self.sh)

        tray.AddModule("I3Writer","writer")(
            ("filename",self.outputfile),
            ("streams",[icetray.I3Frame.DAQ])
        )

        tray.AddModule("TrashCan","trashcan")

        # Execute the Tray
        tray.Execute()
        tray.Finish()

        # Free memory
        del tray
        return 0
Ejemplo n.º 21
0
def main(inputfile, outputfolder, name, string, dom):
    tray = I3Tray()
    # Read files
    tray.AddModule('I3Reader', 'reader', Filenamelist=[inputfile])

    key = 'CalibratedWaveforms_ATWD'

    tray.AddModule(plot_waveforms,
                   'plot_wfs',
                   key=key,
                   outputfolder=outputfolder,
                   name=name,
                   string=string,
                   dom=dom)

    tray.AddModule('TrashCan', 'YesWeCan')
    tray.Execute()
    tray.Finish()
Ejemplo n.º 22
0
def produce_data_dict(i3_file, num_events):
    """IceTray script that wraps around an i3file and fills the events dict
       that is initialized outside the function

    Args:
        i3_file, and IceCube I3File
    Returns:
        True (IceTray standard)
    """

    #time_shift_args = { "I3MCTreeNames": ["I3MCTree"],
    #			"I3DOMLaunchSeriesMapNames": ["InIceRawData"]}

    tray = I3Tray()
    tray.AddModule(
        "I3Reader",
        "source",
        Filenamelist=[geometry_file, i3_file],
    )
    if not args['data']:
        tray.AddModule(cuts, 'cuts', Streams=[icetray.I3Frame.Physics])
        tray.AddModule(event_picker,
                       "event_picker",
                       Streams=[icetray.I3Frame.Physics])
    tray.AddModule("Delete",
                   "old_keys_cleanup",
                   keys=['CalibratedWaveformRange'])
    #tray.AddModule(I3TimeShifter, "T_Shifter", **time_shift_args )
    tray.AddModule(
        "I3WaveCalibrator",
        "sedan",
        Launches=waveform_key,
        Waveforms="CalibratedWaveforms",
        Errata="BorkedOMs",
        ATWDSaturationMargin=123,
        FADCSaturationMargin=0,
    )
    tray.AddModule(save_to_array, 'save', Streams=[icetray.I3Frame.Physics])
    if num_events == -1:
        tray.Execute()
    else:
        tray.Execute(num_events)
    tray.Finish()
    return
   def Execute(self,stats):
        if not ipmodule.ParsingModule.Execute(self,stats): return 0

        # Instantiate a tray 
        tray = I3Tray()

        randomService = phys_services.I3SPRNGRandomService(self.rngseed, self.rngnumberofstreams, self.rngstream)
        tray.context['I3RandomService'] = randomService

        summary = dataclasses.I3MapStringDouble()
        tray.context["I3SummaryService"] = summary
         
        tray.AddSegment(NuGenTraySegment,"nugen",
             gcdfile=self.gcdfile,
             nuflavor=self.nuflavor,
             mjd=self.mjd, 
             nevents=self.nevents,
             cssflag=self.usecss, 
             runId=self.runid,
             randomService=randomService,
             elogmax=self.elogmax,
             elogmin=self.elogmin,
             gamma=self.gamma,
             stats=stats,
             bs=self.bs,
             ph=self.ph,
             bb=self.bb,
             sh=self.sh)

        tray.AddModule("I3Writer","writer")(
            ("filename",self.outputfile),
            ("streams",[icetray.I3Frame.DAQ])
        )

        

        # Execute the Tray
        tray.Execute()
        

        # Free memory
        del tray
        return 0
Ejemplo n.º 24
0
def produce_data_dict(i3_file, num_events):
    """IceTray script that wraps around an i3file and fills the events dict
       that is initialized outside the function

    Args:
        i3_file, and IceCube I3File
    Returns:
        True (IceTray standard)
    """

    tray = I3Tray()
    tray.AddModule("I3Reader", "source",
                   FilenameList=[geometry_file,
                                 i3_file])

    if False:  # only needed if waveforms are used
        tray.AddModule(get_stream, "get_stream",
                       Streams=[icetray.I3Frame.Physics])


        tray.AddModule(event_picker, "event_picker",
                       Streams=[icetray.I3Frame.Physics])
        tray.AddModule("Delete",
                       "old_keys_cleanup",
                       keys=['CalibratedWaveformRange'])
        tray.AddModule("I3WaveCalibrator", "sedan",
                       Launches=waveform_key,
                       Waveforms="CalibratedWaveforms",
                       Errata="BorkedOMs",
                       ATWDSaturationMargin=123,
                       FADCSaturationMargin=0,)
    tray.AddModule(cuts, 'cuts',
                   Streams=[icetray.I3Frame.Physics])
    tray.AddModule(get_most_E_muon_info, 'get_most_E_muon_info',
                   Streams=[icetray.I3Frame.Physics])
    tray.AddModule(save_to_array, 'save',
                   Streams=[icetray.I3Frame.Physics])
    if num_events == -1:
        tray.Execute()
    else:
        tray.Execute(num_events)
    tray.Finish()
    return
Ejemplo n.º 25
0
def test_my_little_function():
    my_features = [
        'x', 'y', 'z', 'charge', 'domstr', 'group', 'HQE', 'icegroup'
    ]

    parser = argparse.ArgumentParser()
    parser.add_argument('-i', '--infiles', required=True)
    args = parser.parse_args()
    filelist = args.infiles.split(',')
    first_file_bad = 1
    for nums in range(len(filelist)):
        #		if nums == (len(filelist)-1):
        #			filelist[nums] = filelist[nums][:-1]
        featurestemp = [[] for i in range(len(my_features))]
        global event_run
        event_run = filelist[nums].split('/')[-1].split('.')[-3]

        tray = I3Tray()
        tray.AddModule('I3Reader', 'read_stuff', Filename=filelist[nums])
        #		tray.AddModule('Delete',keys=["MMCTrackList"])
        #		tray.AddSegment(propagation.RecreateMCTree,"recreate",RawMCTree="I3MCTree_preMuonProp",RNGState="I3MCTree_preMuonProp_RNGState",Paranoia=False)
        tray.AddModule(test, 'test')
        tray.AddModule(savefeatures,
                       'asd',
                       fin=featurestemp,
                       names=my_features)
        tray.Execute()
        for i in range(len(featurestemp)):
            featurestemp[i] = [
                item for sublist in featurestemp[i] for item in sublist
            ]
        if (nums == 0) or (first_file_bad == 1):
            print('Grouping')
            featuresarray = np.column_stack(featurestemp)
            first_file_bad = 0
        else:
            print('Grouping and concatenating')
            featuresarray = np.concatenate(
                (featuresarray, np.column_stack(featurestemp)), axis=0)
        print(featuresarray.shape)
    return featuresarray
Ejemplo n.º 26
0
   def Execute(self,stats={}):
        from .. import segments
        if not ipmodule.ParsingModule.Execute(self,stats): return 0

        from icecube import icetray, dataclasses, dataio, phys_services, interfaces
        from icecube import corsika_reader
        from I3Tray import I3Tray,I3Units

        # Instantiate a tray 
        tray = I3Tray()

        summary_in  = self.summaryfile
        summary_out = self.summaryfile
        if not os.path.exists(self.summaryfile):
           summary_in  = ''

        randomService = phys_services.I3SPRNGRandomService(
             		seed = self.seed,
             		nstreams = self.nproc,
             		streamnum = self.procnum)\
            if not self.usegslrng else phys_services.I3GSLRandomService(seed = self.seed*self.nproc+self.procnum)

        tray.context['I3RandomService'] = randomService



        inputfiles  = self.GetParameter('inputfilelist')
        # Configure IceTray modules 
        tray.AddModule("I3Reader", "reader",filenamelist=[self.gcdfile]+inputfiles)
        tray.AddModule("CORSIKAResampler","resample",
	        OverSampling=self.oversampling,
	        CylinderHeight=self.cylinderheight, 
	        CylinderRadius=self.cylinderradius)
        self.Configure(tray)

       # Execute 
        print(tray) 
        tray.Execute()

        del tray
        return 0
Ejemplo n.º 27
0
def ApplyMask(frame):
    tray = I3Tray()

    if frame.Has('SRTInIcePulses'):
        #print "yes SRTInIcePulses"
        #pulsemap0 = icecube.dataclasses.I3RecoPulseSeriesMap.from_frame(frame, 'SRTInIcePulses')
        #for i,j in pulsemap0:
        #print(i,j)

        my_mask = icecube.dataclasses.I3RecoPulseSeriesMapMask(
            frame, 'SRTInIcePulses', DCPulses)
        frame.Put('DCMask', my_mask)

        my_mask2 = icecube.dataclasses.I3RecoPulseSeriesMapMask(
            frame, 'SRTInIcePulses', NoDCPulses)
        frame.Put('NoDCMask', my_mask2)

        #off_pulses = frame['DCMask']
        # print(frame.keys())
    else:
        print("No SRTInIcePulses")
Ejemplo n.º 28
0
def main(argv):
    inputfile = ''
    outputfile = ''
    #move_file = ''
    folder_group = ''
    try:
        opts, args = getopt.getopt(argv,"hi:o:s:",["ifile=","ofile=","cut_score="])
    except getopt.GetoptError:
        print('test.py -i <inputfile> -o <outputfile> -s <cutscore>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print('test.py -i <input file name> -o <output file directory> <True/False> -s <cut score>')
            sys.exit()
        elif opt in  ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        elif opt in ("-s", "--cut_score"):
            cut_score = arg


    print('Input file is "', inputfile)
    print('Output file is "', outputfile)

#    files = [gcdfile,inputfile]
    
    tray = I3Tray()

    output_name = inputfile.split('/')[-1]
    #data
    #output_name = output_name.replace('Level3pass2','postBDTI')
    #mc                                                      
    output_name = output_name.replace('Level3','postBDTI')
    #output_name = output_name.replace('zst','bz2')
    outfile = (outputfile + '/' + output_name)

#    tray.AddModule('I3Reader', 'reader', FilenameList=files)
    tray.AddModule('I3Reader', 'reader', filename=inputfile)
    tray.AddModule(zenith_cut,     # function name
                   "MPEFitZenithFilter",     # module specifier
                   minDec=GC_dec-np.radians(10), maxDec = GC_dec+np.radians(10))
    tray.AddModule(splineMPE_cut,   
                    "MPEFitFilter")
    tray.AddModule(rlogl_cut,   
                "MPEFitrloglFilter")
    tray.AddModule(ldirE_cut,   
                    "MPEFitldirEFilter")
    tray.AddModule(sigma_cut,   
                    "SigmaFilter")
    
#    NIts = 2    
#    try:  
#        tray.AddSegment(DoReconstructions,'level3_recos',Pulses='SRTHVInIcePulses', If = lambda frame: frame.Stop==icetray.I3Frame.Physics)
    
    tray.AddModule(BDT_score,"BDT_cut", cut_score = cut_score)
    #clf.__del__()
    tray.Add('I3Writer','EventWriter',
        Streams=[icetray.I3Frame.DAQ,icetray.I3Frame.Physics],
        DropOrphanStreams=[icetray.I3Frame.DAQ],
        Filename=outfile)
    tray.AddModule('TrashCan','can')
    tray.Execute()
    tray.Finish()
Ejemplo n.º 29
0
    global total_events, saved_events

    if flag == 'first':
        total_events += 1
    elif flag == 'last':
        saved_events += 1


#Pulse Series
uncleaned_pulses = 'WavedeformPulses'

print ""
print "Starting I3Tray..."
#starttime = datetime.datetime.now()

tray = I3Tray()

tray.AddModule('I3Reader', 'reader', FilenameList=[GCD, inputfiles])

tray.AddModule("I3NullSplitter",
               "mysplit",
               InputPulseSeries='WavedeformPulses')


def selEvent(frame):
    evt_id = frame["I3EventHeader"].event_id
    print 'Event: ', evt_id
    if (evt_id != 6802):
        return False

Ejemplo n.º 30
0
from icecube import icetray, dataio, dataclasses
import I3Tray
from icecube.icetray import I3Units
from icecube.icetray import OMKey
from icecube import portia
from icecube import WaveCalibrator
from LumiProp import *

from ROOT import *

# Create my user defined lumi object
p_lumi = lumiProp("SC2")
allowedLumis = p_lumi.getLumis()

# Get Icetray pointer
tray = I3Tray.I3Tray()

#
## Specify the input file
#

fileList = ['../i3files/SC2_100per_EHEClean_DOMcalib_WaveCalib.i3.gz']

#
## Specify the output file and histograms
#

# File
#outfile = TFile("../plots/RootPlots/cutWaveTimeVars_refined.root","recreate")
#outfile = TFile("../plots/RootPlots/cutWaveTimeVars_wNDOMCheck.root","recreate")
#outfile = TFile("../plots/RootPlots/cutWaveTimeVars_AddedCounter.root","recreate")
Ejemplo n.º 31
0
from icecube import portia
from icecube import WaveCalibrator
import numpy as n
from icecube.BadDomList import bad_dom_list_static

#
## User classes to make things more compact
#

#from LumiProp import *
from ConfigOptions import *

#-----------------------------#
# Load libraries for modules
#-----------------------------#
I3Tray.load("libDomTools")
I3Tray.load("libophelia")
I3Tray.load("libportia")
I3Tray.load("libtree-maker")

#-----------------------------#
# Load the arguments and set
# configure options
#-----------------------------#

#
## Get arguments
#

m_config = ConfigOptions(sys.argv)
if not m_config.isValid():