예제 #1
0
    def start(self):

        output_parameters = {'MuonEff': [],
                             'ImpactP': [],
                             'RingWidth': []}

        numev = 0
        num_muons_found = 0

        for event in hessio_event_source(self.infile):
            self.log.info("Event Number: %d, found %d muons", numev, num_muons_found)

            self.calib.calibrate(event)
            muon_evt = analyze_muon_event(event)

            numev += 1

            if not muon_evt['MuonIntensityParams']:  # No telescopes contained a good muon
                continue
            else:
                if self.display:
                    plot_muon_event(event, muon_evt)

                for tid in muon_evt['TelIds']:
                    idx = muon_evt['TelIds'].index(tid)
                    if not muon_evt['MuonIntensityParams'][idx]:
                        continue

                    self.log.info("** Muon params: %s", muon_evt[idx])

                    output_parameters['MuonEff'].append(
                        muon_evt['MuonIntensityParams'][idx].optical_efficiency_muon
                    )
                    output_parameters['ImpactP'].append(
                        muon_evt['MuonIntensityParams'][idx].impact_parameter.value
                    )
                    output_parameters['RingWidth'].append(
                        muon_evt['MuonIntensityParams'][idx].ring_width.value
                    )

                    print_muon(muon_evt, printer=self.log.info)
                    num_muons_found += 1



        t = Table(output_parameters)
        t['ImpactP'].unit = 'm'
        t['RingWidth'].unit = 'deg'
        if self.outfile:
            t.write(self.outfile)
예제 #2
0
def test_basic_muon_reco(example_event):
    """
    Really simplistic test: just run the analyze_muon_event code, to make
    sure it doesn't crash. The input event is so far not a muon, so no output
    is generated.

    Parameters
    ----------
    test_event - a sample event (fixture)

    """

    calib = CameraCalibrator(subarray=example_event.inst.subarray)
    calib(example_event)

    muon_params = muon.analyze_muon_event(example_event)
    assert muon_params is not None
예제 #3
0
def test_basic_muon_reco(example_event):
    """
    Really simplistic test: just run the analyze_muon_event code, to make
    sure it doesn't crash. The input event is so far not a muon, so no output
    is generated.

    Parameters
    ----------
    test_event - a sample event (fixture)

    """

    calib = CameraCalibrator()
    calib.calibrate(example_event)

    muon_params = muon.analyze_muon_event(example_event)
    assert muon_params is not None
예제 #4
0
    def start(self):

        numev = 0
        self.num_muons_found = defaultdict(int)

        for event in tqdm(self.source, desc='detecting muons'):

            self.calib.calibrate(event)
            muon_evt = analyze_muon_event(event)

            if numev == 0:
                _exclude_some_columns(event.inst.subarray, self.writer)

            numev += 1

            if not muon_evt['MuonIntensityParams']:
                # No telescopes  contained a good muon
                continue
            else:
                if self.display:
                    plot_muon_event(event, muon_evt)

                for tel_id in muon_evt['TelIds']:
                    idx = muon_evt['TelIds'].index(tel_id)
                    intens_params = muon_evt['MuonIntensityParams'][idx]

                    if intens_params is not None:
                        ring_params = muon_evt['MuonRingParams'][idx]
                        cam_id = str(event.inst.subarray.tel[tel_id].camera)
                        self.num_muons_found[cam_id] += 1
                        self.log.debug("INTENSITY: %s", intens_params)
                        self.log.debug("RING: %s", ring_params)
                        self.writer.write(table_name=cam_id,
                                          containers=[intens_params,
                                                      ring_params])

                self.log.info(
                    "Event Number: %d, found %s muons",
                    numev, dict(self.num_muons_found)
                )
예제 #5
0
    def start(self):

        numev = 0
        self.num_muons_found = defaultdict(int)

        for event in tqdm(self.source, desc='detecting muons'):

            self.calib.calibrate(event)
            muon_evt = analyze_muon_event(event)

            if numev == 0:
                _exclude_some_columns(event.inst.subarray, self.writer)

            numev += 1

            if not muon_evt['MuonIntensityParams']:
                # No telescopes  contained a good muon
                continue
            else:
                if self.display:
                    plot_muon_event(event, muon_evt)

                for tel_id in muon_evt['TelIds']:
                    idx = muon_evt['TelIds'].index(tel_id)
                    intens_params = muon_evt['MuonIntensityParams'][idx]

                    if intens_params is not None:
                        ring_params = muon_evt['MuonRingParams'][idx]
                        cam_id = str(event.inst.subarray.tel[tel_id].camera)
                        self.num_muons_found[cam_id] += 1
                        self.log.debug("INTENSITY: %s", intens_params)
                        self.log.debug("RING: %s", ring_params)
                        self.writer.write(table_name=cam_id,
                                          containers=[intens_params,
                                                      ring_params])

                self.log.info(
                    "Event Number: %d, found %s muons",
                    numev, dict(self.num_muons_found)
                )
예제 #6
0
def main():
    script = os.path.splitext(os.path.basename(__file__))[0]
    log.info("[SCRIPT] {}".format(script))

    parser = argparse.ArgumentParser(
        description='Display each event in the file',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-f', '--file', dest='input_path', action='store',
                        default=get_dataset('gamma_test.simtel.gz'),
                        help='path to the input file')

    parser.add_argument('-O', '--origin', dest='origin', action='store',
                         #was .origin_list()
                        default='hessio', help='origin of the file')
    parser.add_argument('-D', dest='display', action='store_true',
                        default=False, help='display the camera events')
    parser.add_argument('-t', '--telescope', dest='tel', action='store',
                        type=int, default=None,
                        help='telecope to view. Default = All')
    parser.add_argument('--pdf', dest='output_path', action='store',
                        default=None,
                        help='path to store a pdf output of the plots')
    parser.add_argument('--calib-help', dest='calib_help', action='store_true',
                        default=False,
                        help='display the arguments used for the camera '
                             'calibration')
    
    args, excess_args = parser.parse_known_args()

    #params, unknown_args = calibration_parameters(excess_args,
    #                                              args.origin,
    #                                              args.calib_help)
    r1 = HessioR1Calibrator(None, None)
    dl0 = CameraDL0Reducer(None, None)
    dl1 = CameraDL1Calibrator(None, None)

    log.debug("[file] Reading file")
    #input_file = InputFile(args.input_path, args.origin)
    #source = input_file.read()
    source = hessio_event_source(args.input_path)
    
    geom_dict = {}

    #
    plot_dict = {}
    muoneff = []
    impactp = []
    ringwidth = []
    plot_dict = {'MuonEff':muoneff,'ImpactP':impactp,'RingWidth':ringwidth}

    numev = 0

    for event in source:
        print("Event Number",numev)
        r1.calibrate(event)
        dl0.reduce(event)
        dl1.calibrate(event)
        muon_evt = analyze_muon_event(event)

        numev += 1
        #Test display #Flag 1 for true (wish to display)
        #plot_muon_event(event,muon_evt)
        # display_telescope(muon_evt, muon_evt[0].tel_id, 1, geom_dict, pp, fig)
        if muon_evt[0] is not None and muon_evt[1] is not None:

            plot_muon_event(event,muon_evt,None,args)
            
            plot_dict['MuonEff'].append(muon_evt[1].optical_efficiency_muon)
            plot_dict['ImpactP'].append(muon_evt[1].impact_parameter.value)
            plot_dict['RingWidth'].append(muon_evt[1].ring_width.value)
            
            display_muon_plot(muon_evt) 
            #Store and or Plot muon parameters here

        #if numev > 50: #for testing purposes - kill early
        #    break

    t = Table([muoneff, impactp, ringwidth], names=('MuonEff','ImpactP','RingWidth'), meta={'name': 'muon analysis results'})
    t['ImpactP'].unit = 'm'
    t['RingWidth'].unit = 'deg'
    #    print('plotdict',plot_dict)

    t.write(str(args.output_path)+'_muontable.fits',overwrite=True) #NEED this to overwrite

    plot_muon_efficiency(args.output_path)
    
    log.info("[COMPLETE]")
예제 #7
0
def main():
    script = os.path.splitext(os.path.basename(__file__))[0]
    log.info("[SCRIPT] {}".format(script))

    parser = argparse.ArgumentParser(
        description='Display each event in the file',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-f',
                        '--file',
                        dest='input_path',
                        action='store',
                        default=get_dataset('gamma_test.simtel.gz'),
                        help='path to the input file')

    parser.add_argument(
        '-O',
        '--origin',
        dest='origin',
        action='store',
        # was .origin_list()
        default='hessio',
        help='origin of the file')
    parser.add_argument('-D',
                        dest='display',
                        action='store_true',
                        default=False,
                        help='display the camera events')
    parser.add_argument('-t',
                        '--telescope',
                        dest='tel_FIXME',
                        action='store',
                        type=int,
                        default=None,
                        help='telecope to view. Default = All')
    parser.add_argument('--pdf',
                        dest='output_path',
                        action='store',
                        default=None,
                        help='path to store a pdf output of the plots')
    parser.add_argument('--calib-help',
                        dest='calib_help',
                        action='store_true',
                        default=False,
                        help='display the arguments used for the camera '
                        'calibration')

    args, excess_args = parser.parse_known_args()

    # params, unknown_args = calibration_parameters(excess_args,
    #                                              args.origin,
    #                                              args.calib_help)
    r1 = HessioR1Calibrator(None, None)
    dl0 = CameraDL0Reducer(None, None)
    dl1 = CameraDL1Calibrator(None, None)

    log.debug("[file] Reading file")
    # input_file = InputFile(args.input_path, args.origin)
    # source = input_file.read()
    source = hessio_event_source(args.input_path)

    muoneff = []
    impactp = []
    ringwidth = []
    plot_dict = {
        'MuonEff': muoneff,
        'ImpactP': impactp,
        'RingWidth': ringwidth
    }

    numev = 0

    for event in source:
        print("Event Number", numev)
        r1.calibrate(event)
        dl0.reduce(event)
        dl1.calibrate(event)

        muon_evt = analyze_muon_event(event)

        numev += 1
        # Test display #Flag 1 for true (wish to display)
        # plot_muon_event(event,muon_evt)
        # display_telescope(muon_evt, muon_evt[0].tel_id, 1, geom_dict, pp, fig)
        #if muon_evt[0] is not None and muon_evt[1] is not None:
        if not muon_evt[
                'MuonIntensityParams']:  #No telescopes contained a good muon
            continue
        else:
            plot_muon_event(event, muon_evt, None, args)

            for tid in muon_evt['TelIds']:
                idx = muon_evt['TelIds'].index(tid)
                if not muon_evt['MuonIntensityParams'][idx]:
                    continue

                plot_dict['MuonEff'].append(muon_evt['MuonIntensityParams']
                                            [idx].optical_efficiency_muon)
                plot_dict['ImpactP'].append(muon_evt['MuonIntensityParams']
                                            [idx].impact_parameter.value)
                plot_dict['RingWidth'].append(
                    muon_evt['MuonIntensityParams'][idx].ring_width.value)

            display_muon_plot(muon_evt)
            # Store and or Plot muon parameters here

            # if numev > 50: #for testing purposes - kill early
            #    break

    t = Table([muoneff, impactp, ringwidth],
              names=('MuonEff', 'ImpactP', 'RingWidth'),
              meta={'name': 'muon analysis results'})
    t['ImpactP'].unit = 'm'
    t['RingWidth'].unit = 'deg'
    #    print('plotdict',plot_dict)

    #t.write(str(args.output_path) + '_muontable.fits', overwrite=True)  # NEED
    # this to overwrite

    #plot_muon_efficiency(args.output_path)

    log.info("[COMPLETE]")
예제 #8
0
    def start(self):

        output_parameters = {
            'MuonEff': [],
            'ImpactP': [],
            'RingWidth': [],
            'RingCont': [],
            'RingComp': [],
            'RingPixComp': [],
            'Core_x': [],
            'Core_y': [],
            'Impact_x_arr': [],
            'Impact_y_arr': [],
            'MCImpactP': [],
            'ImpactDiff': [],
            'RingSize': [],
            'RingRadius': [],
            'NTels': []
        }

        numev = 0
        num_muons_found = 0

        for event in event_source(self.infile):
            self.log.info("Event Number: %d, found %d muons", numev,
                          num_muons_found)
            self.calib.calibrate(event)
            muon_evt = analyze_muon_event(event)

            numev += 1

            if not muon_evt[
                    'MuonIntensityParams']:  # No telescopes contained a good muon
                continue
            else:
                if self.display:
                    plot_muon_event(event, muon_evt)

                ntels = len(event.r0.tels_with_data)
                #if(len( event.r0.tels_with_data) <= 1):
                #continue
                #print("event.r0.tels_with_data", event.r0.tels_with_data)
                for tid in muon_evt['TelIds']:
                    idx = muon_evt['TelIds'].index(tid)
                    if muon_evt['MuonIntensityParams'][idx] is not None:
                        print("pos, tid", event.inst.subarray.positions[tid],
                              tid)
                        tel_x = event.inst.subarray.positions[tid][0]
                        tel_y = event.inst.subarray.positions[tid][1]
                        core_x = event.mc.core_x  # MC Core x
                        core_y = event.mc.core_y  # MC Core y
                        rec_impact_x = muon_evt['MuonIntensityParams'][
                            idx].impact_parameter_pos_x
                        rec_impact_y = muon_evt['MuonIntensityParams'][
                            idx].impact_parameter_pos_y
                        print("rec_impact_x, rec_impact_y", rec_impact_x,
                              rec_impact_y)
                        print("event.mc.core_x, event.mc.core_y",
                              event.mc.core_x, event.mc.core_y)
                        impact_mc = np.sqrt(
                            np.power(core_x - tel_x, 2) +
                            np.power(core_y - tel_y, 2))
                        print("simulated impact", impact_mc)
                        # Coordinate transformation to move the impact point to array coordinates
                        rec_impact_x_arr = tel_x + rec_impact_x
                        rec_impact_y_arr = tel_y + rec_impact_y
                        print("impact_x_arr, impact_y_arr", rec_impact_x_arr,
                              rec_impact_y_arr)
                        # Distance between core of the showe and impact parameter
                        impact_diff = np.sqrt(
                            np.power(core_x - rec_impact_x_arr, 2) +
                            np.power(core_y - rec_impact_y_arr, 2))
                        print("impact_diff ", impact_diff)
                        self.log.info("** Muon params: %s",
                                      muon_evt['MuonIntensityParams'][idx])

                        output_parameters['MuonEff'].append(
                            muon_evt['MuonIntensityParams']
                            [idx].optical_efficiency_muon)
                        output_parameters['ImpactP'].append(
                            muon_evt['MuonIntensityParams']
                            [idx].impact_parameter.value)
                        output_parameters['RingWidth'].append(
                            muon_evt['MuonIntensityParams']
                            [idx].ring_width.value)
                        output_parameters['RingCont'].append(
                            muon_evt['MuonRingParams'][idx].ring_containment)
                        output_parameters['RingComp'].append(
                            muon_evt['MuonIntensityParams']
                            [idx].ring_completeness)
                        output_parameters['RingPixComp'].append(
                            muon_evt['MuonIntensityParams']
                            [idx].ring_pix_completeness)
                        output_parameters['Core_x'].append(
                            event.mc.core_x.value)
                        output_parameters['Core_y'].append(
                            event.mc.core_y.value)
                        output_parameters['Impact_x_arr'].append(
                            rec_impact_x_arr.value)
                        output_parameters['Impact_y_arr'].append(
                            rec_impact_y_arr.value)
                        output_parameters['MCImpactP'].append(impact_mc.value)
                        output_parameters['ImpactDiff'].append(
                            impact_diff.value)
                        output_parameters['RingSize'].append(
                            muon_evt['MuonIntensityParams'][idx].ring_size)
                        output_parameters['RingRadius'].append(
                            muon_evt['MuonRingParams'][idx].ring_radius.value)
                        output_parameters['NTels'].append(ntels)

                        print_muon(muon_evt, printer=self.log.info)
                        num_muons_found += 1

        t = Table(output_parameters)
        t['ImpactP'].unit = 'm'
        t['RingWidth'].unit = 'deg'
        #t['MCImpactP'].unit = 'm'
        if self.outfile:
            t.write(self.outfile)