Exemplo n.º 1
0
 def setup(self):
     self.hev_enabled = ((self.config['hev_gain_model'][0] != 'disabled')
                         and self.config['tail_veto_threshold'])
     if self.hev_enabled:
         self.to_pe = straxen.get_to_pe(self.run_id,
                                        self.config['hev_gain_model'],
                                        self.config['n_tpc_pmts'])
Exemplo n.º 2
0
    def setup(self):
        self.to_pe = straxen.get_to_pe(self.run_id, self.config['gain_model'],
                                       self.config['n_tpc_pmts'])

        buffer_pmts = np.zeros(self.config['he_channel_offset'])
        self.to_pe = np.concatenate((buffer_pmts, self.to_pe))
        self.to_pe *= self.config['le_to_he_amplification']
Exemplo n.º 3
0
    def setup(self):
        c = self.config
        c.update(get_resource(c['fax_config'], fmt='json'))
        # Update gains to the nT defaults
        self.to_pe = get_to_pe(self.run_id, c['gain_model'],
                               c['channel_map']['tpc'][1] + 1)
        c['gains'] = 1 / self.to_pe * (1e-8 * 2.25 / 2**14) / (1.6e-19 * 10 *
                                                               50)
        c['gains'][self.to_pe == 0] = 0
        if c['seed'] != False:
            np.random.seed(c['seed'])

        overrides = self.config['fax_config_override']
        if overrides is not None:
            c.update(overrides)

        #We hash the config to load resources. Channel map is immutable and cannot be hashed
        self.config['channel_map'] = dict(self.config['channel_map'])
        self.config['channel_map']['sum_signal'] = 800
        self.config['channels_bottom'] = np.arange(self.config['n_top_pmts'],
                                                   self.config['n_tpc_pmts'])

        self.get_instructions()
        self.check_instructions()
        self._setup()
Exemplo n.º 4
0
 def setup(self):
     if self.config['peak_min_pmts'] > 2:
         # Can fix by resplitting, NotImplemented
         raise warn(f"Raising the peak_min_pmts to "
                    f"{self.config['peak_min_pmts']} interferes with "
                    f"lone_hit definition. See "
                    f"github.com/XENONnT/straxen/issues/295")
     self.to_pe = straxen.get_to_pe(self.run_id, self.config['gain_model'],
                                    self.config['n_tpc_pmts'])
Exemplo n.º 5
0
 def setup(self):
     to_pe = straxen.get_to_pe(self.run_id,
                               self.config['gain_model_nv'],
                               self.config['n_nveto_pmts'])
     self.channel_range = self.config['channel_map']['nveto']
     
     # Create to_pe array of size max channel:
     self.to_pe = np.zeros(self.channel_range[1] + 1, dtype=np.float32)
     self.to_pe[self.channel_range[0]:] = to_pe[:]
Exemplo n.º 6
0
    def setup(self):
        self.channel_range = self.config['channel_map']['mv']
        self.n_channel = (self.channel_range[1] - self.channel_range[0]) + 1

        to_pe = straxen.get_to_pe(self.run_id,
                                  self.config['gain_model_mv'],
                                  self.n_channel)

        # Create to_pe array of size max channel:
        self.to_pe = np.zeros(self.channel_range[1] + 1, dtype=np.float32)
        self.to_pe[self.channel_range[0]:] = to_pe[:]
Exemplo n.º 7
0
    def setup(self):
        c = self.config
        c.update(get_resource(c['fax_config'], fmt='json'))
        # Update gains to the nT defaults
        self.to_pe = get_to_pe(self.run_id, c['gain_model'],
                               len(c['channels_in_detector']['tpc']))
        c['gains'] = 1 / self.to_pe * (1e-8 * 2.25 / 2**14) / (1.6e-19 * 10 *
                                                               50)
        c['gains'][self.to_pe == 0] = 0
        if c['seed'] != False:
            np.random.seed(c['seed'])

        overrides = self.config['fax_config_override']
        if overrides is not None:
            c.update(overrides)

        if c['optical']:
            self.instructions, self.channels, self.timings = read_optical(
                c['fax_file'])
            c['nevents'] = len(self.instructions['event_number'])

        elif c['fax_file']:
            assert c['fax_file'][
                -5:] != '.root', 'None optical g4 input is deprecated use EPIX instead'
            self.instructions = instruction_from_csv(c['fax_file'])
            c['nevents'] = np.max(self.instructions['event_number'])

        else:
            self.instructions = rand_instructions(c)

        # Let below cathode S1 instructions pass but remove S2 instructions
        m = (self.instructions['z'] <
             -c['tpc_length']) & (self.instructions['type'] == 2)
        self.instructions = self.instructions[~m]

        assert np.all(self.instructions['x']**2 + self.instructions['y']**2 < c['tpc_radius']**2), \
                "Interation is outside the TPC"
        assert np.all(self.instructions['z'] < 0.25), \
                "Interation is outside the TPC"
        assert np.all(self.instructions['amp'] > 0), \
                "Interaction has zero size"
Exemplo n.º 8
0
        def wrapped_f(context: strax.Context, run_id: str, **kwargs):
            # Validate arguments
            known_kwargs = (
                'time_range seconds_range time_within time_selection '
                'ignore_time_warning '
                'selection_str t_reference to_pe config').split()
            for k in kwargs:
                if k not in known_kwargs and k not in parameters:
                    # Python itself also raises TypeError for invalid kwargs
                    raise TypeError(f"Unknown argument {k} for {f.__name__}")

            if 'config' in kwargs:
                context = context.new_context(config=kwargs['config'])
            if 'config' in parameters:
                kwargs['config'] = context.config

            # Say magic words to enable holoviews
            if hv_bokeh:
                global _hv_bokeh_initialized
                if not _hv_bokeh_initialized:
                    import holoviews
                    holoviews.extension('bokeh')
                    _hv_bokeh_initialized = True

            # TODO: This is a placeholder until the corrections system
            # is more fully developed
            if 'to_pe' in parameters and 'to_pe' not in kwargs:
                kwargs['to_pe'] = straxen.get_to_pe(
                    run_id, context.config['gain_model'],
                    context.config['n_tpc_pmts'])

            # Prepare selection arguments
            kwargs['time_range'] = context.to_absolute_time_range(
                run_id,
                targets=requires,
                **{
                    k: kwargs.get(k)
                    for k in ('time_range seconds_range time_within'.split())
                })
            kwargs.setdefault('time_selection', default_time_selection)
            kwargs.setdefault('selection_str', None)

            kwargs['t_reference'] = context.estimate_run_start(
                run_id, requires)

            if warn_beyond_sec is not None and not kwargs.get(
                    'ignore_time_warning'):
                tr = kwargs['time_range']
                if tr is None:
                    sec_requested = float('inf')
                else:
                    sec_requested = (tr[1] - tr[0]) / int(1e9)
                if sec_requested > warn_beyond_sec:
                    tr_str = "the entire run" if tr is None else f"{sec_requested} seconds"
                    raise ValueError(
                        f"The author of this mini analysis recommends "
                        f"not requesting more than {warn_beyond_sec} seconds. "
                        f"You are requesting {tr_str}. If you wish to proceed, "
                        "pass ignore_time_warning = True.")

            # Load required data, if any
            if len(requires):
                deps_by_kind = strax.group_by_kind(requires, context=context)
                for dkind, dtypes in deps_by_kind.items():
                    if dkind in kwargs:
                        # Already have data, just apply cuts
                        kwargs[dkind] = context.apply_selection(
                            kwargs[dkind],
                            selection_str=kwargs['selection_str'],
                            time_range=kwargs['time_range'],
                            time_selection=kwargs['time_selection'])
                    else:
                        kwargs[dkind] = context.get_array(
                            run_id,
                            dtypes,
                            selection_str=kwargs['selection_str'],
                            time_range=kwargs['time_range'],
                            time_selection=kwargs['time_selection'],
                            # Arguments for new context, if needed
                            config=kwargs.get('config'),
                            register=kwargs.get('register'),
                            storage=kwargs.get('storage', tuple()))

                # If user did not give time kwargs, but the function expects
                # a time_range, try to add one based on the time range of the data
                base_dkind = list(deps_by_kind.keys())[0]
                x = kwargs[base_dkind]
                if len(x) and kwargs.get('time_range') is None:
                    x0 = x.iloc[0] if isinstance(x, pd.DataFrame) else x[0]
                    try:
                        kwargs.setdefault('time_range',
                                          (x0['time'], strax.endtime(x).max()))

                    except AttributeError:
                        # If x is a holoviews dataset, this will fail.
                        pass

            if 'seconds_range' in parameters:
                if kwargs.get('time_range') is None:
                    scr = None
                else:
                    scr = tuple([(t - kwargs['t_reference']) / int(1e9)
                                 for t in kwargs['time_range']])
                kwargs.setdefault('seconds_range', scr)

            kwargs.setdefault('run_id', run_id)
            kwargs.setdefault('context', context)

            if 'kwargs' in parameters:
                # Likely this will be passed to another mini-analysis
                to_pass = kwargs
                # Do not pass time_range and seconds_range both (unless explicitly requested)
                # strax does not like that
                if 'seconds_range' in to_pass and not 'seconds_range' in parameters:
                    del to_pass['seconds_range']
                if 'time_within' in to_pass and not 'time_within' in parameters:
                    del to_pass['time_within']
            else:
                # Pass only arguments the function wants
                to_pass = {k: v for k, v in kwargs.items() if k in parameters}
            return f(**to_pass)
Exemplo n.º 9
0
 def setup(self):
     self.to_pe = straxen.get_to_pe(self.run_id,
                                    self.config['gain_model_nv'],
                                    self.n_channel)
Exemplo n.º 10
0
 def setup(self):
     self.to_pe = straxen.get_to_pe(self.run_id,
                                    self.config['gain_model'],
                                    n_tpc_pmts=self.config['n_tpc_pmts'])
Exemplo n.º 11
0
 def setup(self):
     self.to_pe = get_to_pe(self.run_id, self.config['to_pe_file'])