Esempio n. 1
0
    def __init__(self, polar_root_file, reference_time=0., rsp_file=None):
        """
        container class that converts raw POLAR root data into useful python
        variables


        :param polar_root_file: path to polar event file
        :param reference_time: reference time of the events (tunix?)
        :param rsp_file: path to rsp file
        """

        # open the event file
        with open_ROOT_file(polar_root_file) as f:
            tmp = tree_to_ndarray(f.Get('polar_out'))

            # extract the pedestal corrected ADC channels
            # which are non-integer and possibly
            # less than zero
            pha = tmp['Energy']

            # non-zero ADC channels are invalid
            idx = pha >= 0
            pha = pha[idx]

            # get the dead time fraction
            self._dead_time_fraction = tmp['dead_ratio'][idx]

            # get the arrival time, in tunix of the events
            self._time = tmp['tunix'][idx] - reference_time

            # digitize the ADC channels into bins
            # these bins are preliminary

        with open_ROOT_file(rsp_file) as f:
            matrix = th2_to_arrays(f.Get('rsp'))[-1]
            ebounds = th2_to_arrays(f.Get('EM_bounds'))[-1]
            mc_low = th2_to_arrays(f.Get('ER_low'))[-1]
            mc_high = th2_to_arrays(f.Get('ER_high'))[-1]

        mc_energies = np.append(mc_low, mc_high[-1])

        # build the POLAR response

        self._rsp = InstrumentResponse(matrix=matrix,
                                       ebounds=ebounds,
                                       monte_carlo_energies=mc_energies)

        # bin the ADC channels

        self._binned_pha = np.digitize(pha, ebounds)
Esempio n. 2
0
    def __init__(self, polar_root_file, reference_time=0., rsp_file=None):
        """
        container class that converts raw POLAR root data into useful python
        variables


        :param polar_root_file: path to polar event file
        :param reference_time: reference time of the events (tunix?)
        :param rsp_file: path to rsp file
        """

        # open the event file
        with open_ROOT_file(polar_root_file) as f:
            tmp = tree_to_ndarray(f.Get('polar_out'))

            # extract the pedestal corrected ADC channels
            # which are non-integer and possibly
            # less than zero
            pha = tmp['Energy']

            # non-zero ADC channels are invalid
            idx = pha >= 0
            pha = pha[idx]

            # get the dead time fraction
            self._dead_time_fraction = tmp['dead_ratio'][idx]

            # get the arrival time, in tunix of the events
            self._time = tmp['tunix'][idx] - reference_time

            # digitize the ADC channels into bins
            # these bins are preliminary

        with open_ROOT_file(rsp_file) as f:
            matrix = th2_to_arrays(f.Get('rsp'))[-1]
            ebounds = th2_to_arrays(f.Get('EM_bounds'))[-1]
            mc_low = th2_to_arrays(f.Get('ER_low'))[-1]
            mc_high = th2_to_arrays(f.Get('ER_high'))[-1]

        mc_energies = np.append(mc_low, mc_high[-1])

        # build the POLAR response

        self._rsp = InstrumentResponse(matrix=matrix,
                                       ebounds=ebounds,
                                       monte_carlo_energies=mc_energies)

        # bin the ADC channels

        self._binned_pha = np.digitize(pha, ebounds)
Esempio n. 3
0
    def __init__(self, root_file, run_name):

        self._run_name = run_name

        # Read the data from the ROOT file

        with open_ROOT_file(root_file) as f:

            # Read first the TTrees as pandas DataFrame

            self._data_on = tree_to_ndarray(
                f.Get(run_name + '/data_on'))  # type: np.ndarray
            self._data_off = tree_to_ndarray(
                f.Get(run_name + '/data_off'))  # type: np.ndarray
            self._tRunSummary = np.squeeze(
                tree_to_ndarray(f.Get(run_name +
                                      '/tRunSummary')))  # type: np.ndarray

            # Now read the histogram
            self._log_recon_energies, \
            self._log_mc_energies, \
            self._hMigration = th2_to_arrays(f.Get(run_name + "/hMigration"))

            # Transform energies to keV (they are in TeV)
            self._log_recon_energies += 9
            self._log_mc_energies += 9

            # Compute bin centers and bin width of the Monte Carlo energy bins

            self._dE = (10**self._log_mc_energies[1:] -
                        10**self._log_mc_energies[:-1])
            self._mc_energies_c = (10**self._log_mc_energies[1:] +
                                   10**self._log_mc_energies[:-1]) / 2.0
            self._recon_energies_c = (10**self._log_recon_energies[1:] +
                                      10**self._log_recon_energies[:-1]) / 2.0

            self._n_chan = self._log_recon_energies.shape[0] - 1

            # Remove all nans by substituting them with 0.0
            idx = np.isfinite(self._hMigration)
            self._hMigration[~idx] = 0.0

            # Read the TGraph
            tgraph = f.Get(run_name + "/gMeanEffectiveArea")
            self._log_eff_area_energies, self._eff_area = tgraph_to_arrays(
                tgraph)

            # Transform the effective area to cm2 (it is in m2 in the file)
            self._eff_area *= 1e8  #This value is for VEGAS, because VEGAS effective area is in cm2

            # Transform energies to keV
            self._log_eff_area_energies += 9

        # Now use the effective area provided in the file to renormalize the migration matrix appropriately
        self._renorm_hMigration()

        # Exposure is tOn*(1-tDeadtimeFrac)
        self._exposure = float(1 -
                               self._tRunSummary['DeadTimeFracOn']) * float(
                                   self._tRunSummary['tOn'])

        # Members for generating OGIP equivalents

        self._mission = "VERITAS"
        self._instrument = "VERITAS"

        # Now bin the counts

        self._counts, _ = self._bin_counts_log(self._data_on['Erec'] * 1e9,
                                               self._log_recon_energies)

        # Now bin the background counts

        self._bkg_counts, _ = self._bin_counts_log(
            self._data_off['Erec'] * 1e9, self._log_recon_energies)

        print(
            "Read a %s x %s matrix, spectrum has %s bins, eff. area has %s elements"
            % (self._hMigration.shape[0], self._hMigration.shape[1],
               self._counts.shape[0], self._eff_area.shape[0]))

        # Read in the background renormalization (ratio between source and background region)

        self._bkg_renorm = float(self._tRunSummary['OffNorm'])

        self._start_energy = np.log10(175E6)  #175 GeV in keV
        self._end_energy = np.log10(18E9)  #18 TeV in keV
        self._first_chan = (
            np.abs(self._log_recon_energies -
                   self._start_energy)).argmin()  #Values used by Giacomo 61
        self._last_chan = (
            np.abs(self._log_recon_energies -
                   self._end_energy)).argmin()  #Values used by Giacomo 110
Esempio n. 4
0
    def __init__(self, root_file, run_name):

        self._run_name = run_name

        # Read the data from the ROOT file

        with open_ROOT_file(root_file) as f:

            # Read first the TTrees as pandas DataFrame

            self._data_on = tree_to_ndarray(f.Get(run_name+'/data_on'))  # type: np.ndarray
            self._data_off = tree_to_ndarray(f.Get(run_name+'/data_off'))  # type: np.ndarray
            self._tRunSummary = np.squeeze(tree_to_ndarray(f.Get(run_name+'/tRunSummary')))  # type: np.ndarray

            # Now read the histogram
            self._log_recon_energies, \
            self._log_mc_energies, \
            self._hMigration = th2_to_arrays(f.Get(run_name + "/hMigration"))

            # Transform energies to keV (they are in TeV)
            self._log_recon_energies += 9
            self._log_mc_energies += 9

            # Compute bin centers and bin width of the Monte Carlo energy bins

            self._dE = (10 ** self._log_mc_energies[1:] - 10 ** self._log_mc_energies[:-1])
            self._mc_energies_c = (10 ** self._log_mc_energies[1:] + 10 ** self._log_mc_energies[:-1]) / 2.0
            self._recon_energies_c = (10 ** self._log_recon_energies[1:] + 10 ** self._log_recon_energies[:-1]) / 2.0
	
            self._n_chan = self._log_recon_energies.shape[0] - 1

            # Remove all nans by substituting them with 0.0
            idx = np.isfinite(self._hMigration)
            self._hMigration[~idx] = 0.0

            # Read the TGraph
            tgraph = f.Get(run_name + "/gMeanEffectiveArea")
            self._log_eff_area_energies, self._eff_area = tgraph_to_arrays(tgraph)

            # Transform the effective area to cm2 (it is in m2 in the file)
            self._eff_area *= 1e8 #This value is for VEGAS, because VEGAS effective area is in cm2

            # Transform energies to keV
            self._log_eff_area_energies += 9

        # Now use the effective area provided in the file to renormalize the migration matrix appropriately
        self._renorm_hMigration()

        # Exposure is tOn*(1-tDeadtimeFrac)
        self._exposure = float(1 - self._tRunSummary['DeadTimeFracOn']) * float(self._tRunSummary['tOn'])

        # Members for generating OGIP equivalents

        self._mission = "VERITAS"
        self._instrument = "VERITAS"

        # Now bin the counts

        self._counts, _ = self._bin_counts_log(self._data_on['Erec'] * 1e9, self._log_recon_energies)

        # Now bin the background counts

        self._bkg_counts, _ = self._bin_counts_log(self._data_off['Erec'] * 1e9, self._log_recon_energies)

        print("Read a %s x %s matrix, spectrum has %s bins, eff. area has %s elements" %
              (self._hMigration.shape[0], self._hMigration.shape[1], self._counts.shape[0], self._eff_area.shape[0]))

        # Read in the background renormalization (ratio between source and background region)

        self._bkg_renorm = float(self._tRunSummary['OffNorm'])

        self._start_energy = np.log10(175E6)#175 GeV in keV
        self._end_energy = np.log10(18E9)#18 TeV in keV
        self._first_chan = (np.abs(self._log_recon_energies-self._start_energy)).argmin()
        self._last_chan = (np.abs(self._log_recon_energies-self._end_energy)).argmin()