Ejemplo n.º 1
0
 def get_nstations(frame):
     nstation = 0
     if IT_pulses in frame:
         nstation = count_stations(
             dataclasses.I3RecoPulseSeriesMap.from_frame(frame, IT_pulses))
     frame.Put('NStations', icetray.I3Int(nstation))
def main(args, outputLevel=2):
    from I3Tray import I3Tray
    from icecube import dataio, icetop_Level3_scripts, dataclasses, phys_services, frame_object_diff
    from icecube.icetop_Level3_scripts import icetop_globals

    icetray.I3Logger.global_logger.set_level(icetray.I3LogLevel.LOG_ERROR)
    icetray.I3Logger.global_logger.set_level_for_unit(
        "MakeQualityCuts", icetray.I3LogLevel.LOG_INFO)

    if not args.L3_gcdfile:
        if args.isMC:
            gcdfile = [
                "/data/ana/CosmicRay/IceTop_level3/sim/%s/GCD/Level3_%i_GCD.i3.gz"
                % (args.detector, args.dataset)
            ]
        else:
            gcdfile = glob.glob(
                "/data/ana/CosmicRay/IceTop_level3/data/%s/GCD/Level3_%s_data_Run00%i_????_GCD.i3.gz"
                % (args.detector, args.detector, args.run))
    else:
        gcdfile = [args.L3_gcdfile]

    # Instantiate a tray
    tray = I3Tray()
    tray.context['I3FileStager'] = dataio.get_stagers(
        staging_directory=os.environ['_CONDOR_SCRATCH_DIR'])
    tray.AddModule('I3Reader',
                   'Reader',
                   FilenameList=gcdfile + args.inputFiles)

    #---------------------------------------------------------------------------------------------------------------

    from icecube.frame_object_diff.segments import uncompress

    # If the L2 gcd file is not specified, use the base_filename which is used for compressing. Check First whether it exists.
    # If the L2 gcd file is provided (probably in the case when running on your own cluster and when you copied the diff and L2 GCDs there),
    # then you use this, but you check first whether the filename makes sense (is the same as the base_filename used for compression).
    def CheckL2GCD(frame):
        geodiff = frame["I3GeometryDiff"]
        if args.L2_gcdfile:
            L2_GCD = args.L2_gcdfile
            if os.path.basename(L2_GCD) != os.path.basename(
                    geodiff.base_filename):
                icetray.logging.log_fatal(
                    '''The provided L2 GCD seems not suited to use for uncompressing the L3 GCD.
                                           It needs to have the same filename as the L2 GCD used to create the diff.'''
                )
        else:
            L2_GCD = geodiff.base_filename
        if not os.path.exists(L2_GCD):
            icetray.logging.log_fatal("L2 GCD file %s not found" % L2_GCD)

    tray.AddModule(CheckL2GCD, 'CheckL2CD', Streams=[icetray.I3Frame.Geometry])

    tray.Add(
        uncompress,
        base_filename=args.L2_gcdfile)  # works correctly if L2_gcdfile is None

    #---------------------------------------------------------------------------------------------------------------

    tray.AddSegment(icetop_Level3_scripts.segments.level3_IceTop,
                    "level3_IceTop",
                    detector=args.detector,
                    do_select=args.select,
                    isMC=args.isMC,
                    add_jitter=args.add_jitter)

    #---------------------------------------------------------------------------------------------------------------

    if args.do_inice:
        itpulses = 'IceTopHLCSeedRTPulses'

        tray.AddSegment(
            icetop_Level3_scripts.segments.level3_Coinc,
            "level3_Coinc",
            Detector=args.detector,
            isMC=args.isMC,
            do_select=args.select,
            IceTopTrack='Laputop',
            IceTopPulses=itpulses,
        )

    if args.waveforms:
        from icecube.icetop_Level3_scripts.functions import count_stations

        tray.AddModule(
            icetop_Level3_scripts.modules.FilterWaveforms,
            'FilterWaveforms',  #Puts IceTopWaveformWeight in the frame.
            pulses=icetop_globals.icetop_hlc_pulses,
            If=lambda frame: icetop_globals.icetop_hlc_pulses in frame and
            count_stations(
                dataclasses.I3RecoPulseSeriesMap.from_frame(
                    frame, icetop_globals.icetop_hlc_pulses)) >= 5)

        tray.AddSegment(icetop_Level3_scripts.segments.ExtractWaveforms,
                        'IceTop',
                        If=lambda frame: "IceTopWaveformWeight" in frame and
                        frame["IceTopWaveformWeight"].value != 0)

    #---------------------------------------------------------------------------------------------------------------

    ## Which keys to keep:
    wanted_general = [
        'I3EventHeader', icetop_globals.filtermask, 'I3TriggerHierarchy'
    ]

    if args.isMC:
        wanted_general += [
            'MCPrimary',
            'MCPrimaryInfo',
            'AirShowerComponents',
            'IceTopComponentPulses_Electron',
            'IceTopComponentPulses_ElectronFromChargedMesons',
            'IceTopComponentPulses_Gamma',
            'IceTopComponentPulses_GammaFromChargedMesons',
            'IceTopComponentPulses_Muon',
            'IceTopComponentPulses_Hadron',
        ]

    wanted_icetop_filter = ['IceTop_EventPrescale', 'IceTop_StandardFilter']

    wanted_icetop_pulses = [
        icetop_globals.icetop_hlc_pulses,
        icetop_globals.icetop_slc_pulses,
        icetop_globals.icetop_clean_hlc_pulses,
        icetop_globals.icetop_tank_pulse_merger_excluded_tanks,
        icetop_globals.icetop_cluster_cleaning_excluded_tanks,
        icetop_globals.icetop_HLCseed_clean_hlc_pulses,
        icetop_globals.icetop_HLCseed_excluded_tanks,
        icetop_globals.icetop_HLCseed_clean_hlc_pulses + '_SnowCorrected',
        'TankPulseMergerExcludedSLCTanks',
        'IceTopLaputopSeededSelectedHLC',
        'IceTopLaputopSeededSelectedSLC',
        'IceTopLaputopSmallSeededSelectedHLC',
        'IceTopLaputopSmallSeededSelectedSLC',
    ]

    wanted_icetop_waveforms = [
        'IceTopVEMCalibratedWaveforms', 'IceTopWaveformWeight'
    ]

    wanted_icetop_reco = [
        'ShowerCOG', 'ShowerPlane', 'ShowerPlaneParams', 'Laputop',
        'LaputopParams', 'LaputopSnowDiagnostics', 'LaputopSmall',
        'LaputopSmallParams', 'IsSmallShower'
    ]

    wanted_icetop_cuts = [
        'Laputop_FractionContainment',
        'Laputop_OnionContainment',
        'Laputop_NearestStationIsInfill',
        'StationDensity',
        'IceTopMaxSignal',
        'IceTopMaxSignalInEdge',
        'IceTopMaxSignalTank',
        'IceTopMaxSignalString',
        'IceTopNeighbourMaxSignal',
        'IT73AnalysisIceTopQualityCuts',
    ]

    wanted = wanted_general + wanted_icetop_filter + wanted_icetop_pulses + wanted_icetop_waveforms + wanted_icetop_reco + wanted_icetop_cuts

    if args.do_inice:
        wanted_inice_filter = [
            'IceTopInIce_EventPrescale', 'IceTopInIce_StandardFilter'
        ]

        wanted_inice_pulses = [
            icetop_globals.inice_pulses, icetop_globals.inice_coinc_pulses,
            icetop_globals.inice_clean_coinc_pulses,
            icetop_globals.inice_clean_coinc_pulses + "TimeRange",
            icetop_globals.inice_clean_coinc_pulses + "_Balloon",
            "SaturationWindows", "CalibrationErrata",
            'SRT' + icetop_globals.inice_coinc_pulses
        ]

        wanted_inice_reco = [
            "Millipede", "MillipedeFitParams", "Millipede_dEdX", "Stoch_Reco",
            "Stoch_Reco2", "I3MuonEnergyLaputopCascadeParams",
            "I3MuonEnergyLaputopParams"
        ]

        wanted_inice_cuts = [
            'NCh_' + icetop_globals.inice_clean_coinc_pulses,
            'IT73AnalysisInIceQualityCuts'
        ]

        wanted_inice_muon = [
            'CoincMuonReco_LineFit', 'CoincMuonReco_SPEFit2',
            'CoincMuonReco_LineFitParams', 'CoincMuonReco_SPEFit2FitParams',
            'CoincMuonReco_MPEFit', 'CoincMuonReco_MPEFitFitParams',
            'CoincMuonReco_MPEFitMuEX', 'CoincMuonReco_CVMultiplicity',
            'CoincMuonReco_CVStatistics',
            'CoincMuonReco_MPEFitCharacteristics',
            'CoincMuonReco_SPEFit2Characteristics',
            'CoincMuonReco_MPEFitTruncated_BINS_Muon',
            'CoincMuonReco_MPEFitTruncated_AllBINS_Muon',
            'CoincMuonReco_MPEFitTruncated_ORIG_Muon',
            'CoincMuonReco_SPEFit2_D4R_CascadeParams',
            'CoincMuonReco_SPEFit2_D4R_Params',
            'CoincMuonReco_MPEFitDirectHitsC'
        ]

        wanted = wanted + wanted_inice_filter + wanted_inice_pulses + wanted_inice_reco + wanted_inice_cuts + wanted_inice_muon

    tray.AddModule("Keep", 'DropObjects', Keys=wanted)

    if args.output.replace('.bz2', '').replace('.gz', '')[-3:] == '.i3':
        tray.AddModule(
            "I3Writer",
            "i3-writer",
            Filename=args.output,
            DropOrphanStreams=[icetray.I3Frame.DAQ],
            streams=[icetray.I3Frame.DAQ, icetray.I3Frame.Physics],
        )
    else:
        raise Exception('I do not know how to handle files with extension %s' %
                        outfile.replace('.bz2', '').replace('.gz', '')[-3:])

    # Execute the Tray
    if args.n is None:
        tray.Execute()
    else:
        tray.Execute(args.n)

    if args.print_usage:
        tray.PrintUsage(fraction=1.0)
    tray.Finish()
Ejemplo n.º 3
0
def add_nstations(frame, pulses='SRTCoincPulses'):
    nstation = count_stations(
        dataclasses.I3RecoPulseSeriesMap.from_frame(frame, pulses))
    frame['NStations'] = icetray.I3Int(nstation)