Ejemplo n.º 1
0
    parser.add_argument("-c",
                        "--cosmic-ray-model",
                        type=str,
                        required=False,
                        default="GlobalSplineFitBeta",
                        help="Primary cosmic ray spectrum model")
    parser.add_argument("-o",
                        "--output-dir",
                        type=str,
                        required=False,
                        default="",
                        help="Output directory")
    args = parser.parse_args()

    # Get interaction model
    interaction_model = normalize_hadronic_model_name(args.interaction_model)

    # Get primary cosmic ray spectrum model
    assert hasattr(
        crf,
        args.cosmic_ray_model), "Unknown primary cosmic ray spectrum model"
    CRModel = getattr(
        crf, args.cosmic_ray_model)  # Gettting class (NOT instantiating)
    assert issubclass(
        CRModel, crf.PrimaryFlux), "Unknown primary cosmic ray spectrum model"

    # define CR model parameters
    if args.cosmic_ray_model == "HillasGaisser2012":
        CR_vers = "H3a"
    elif args.cosmic_ray_model == "GaisserStanevTilav":
        CR_vers = "4-gen"
Ejemplo n.º 2
0
    def __init__(self, interaction_model, primary_model, theta_deg, **kwargs):

        self._mceq_db = MCEq.data.HDF5Backend()

        interaction_model = normalize_hadronic_model_name(interaction_model)

        # Save atmospheric parameters
        self.density_config = kwargs.pop('density_model', config.density_model)
        self.theta_deg = theta_deg

        #: Interface to interaction tables of the HDF5 database
        self._interactions = MCEq.data.Interactions(mceq_hdf_db=self._mceq_db)

        #: handler for cross-section data of type :class:`MCEq.data.HadAirCrossSections`
        self._int_cs = MCEq.data.InteractionCrossSections(
            mceq_hdf_db=self._mceq_db)

        #: handler for cross-section data of type :class:`MCEq.data.HadAirCrossSections`
        self._cont_losses = MCEq.data.ContinuousLosses(
            mceq_hdf_db=self._mceq_db, material='air')

        #: Interface to decay tables of the HDF5 database
        self._decays = MCEq.data.Decays(mceq_hdf_db=self._mceq_db)

        #: Particle manager (initialized/updated in set_interaction_model)
        self.pman = None

        # Particle list to keep track of previously initialized particles
        self._particle_list = None

        # General Matrix dimensions and shortcuts, controlled by
        # grid of yield matrices
        self._energy_grid = self._mceq_db.energy_grid

        # Initialize solution vector
        self._solution = np.zeros(1)
        # Initialize empty state (particle density) vector
        self._phi0 = np.zeros(1)
        # Initialize matrix builder (initialized in set_interaction_model)
        self.matrix_builder = None
        # Save initial condition (primary flux) to restore after dimensional resizing
        self._restore_initial_condition = None

        # Set interaction model and compute grids and matrices
        self.set_interaction_model(interaction_model,
                                   particle_list=kwargs.pop(
                                       'particle_list', None))

        # Default GPU device id for CUDA
        self._cuda_device = kwargs.pop('cuda_gpu_id', config.cuda_gpu_id)

        # Print particle list after tracking particles have been initialized
        self.pman.print_particle_tables(2)

        # Set atmosphere and geometry TODO do not allow empty density model
        # if density_model is not None:
        self.set_density_model(self.density_config)

        # Set initial flux condition
        if primary_model is not None:
            self.set_primary_model(*primary_model)
Ejemplo n.º 3
0
        nue_down[iz] = gs('total_nue', 0)[tr]
        anue_down[iz] = gs('total_antinue', 0)[tr]

    fd_derivative = lambda up, down: (up - down) / (2. * delta)

    dnumu = fd_derivative(numu_up, numu_down)
    danumu = fd_derivative(anumu_up, anumu_down)
    dnue = fd_derivative(nue_up, nue_down)
    danue = fd_derivative(anue_up, anue_down)
    return [
        RectBivariateSpline(cos_theta, np.log(etr), dist)
        for dist in [numu, dnumu, anumu, danumu, nue, dnue, anue, danue]
    ]

if __name__ == '__main__':
    iamod = normalize_hadronic_model_name(sys.argv[1])  #the interaction model
    iatag = sys.argv[2]  # Tag name for the interaction model

    CRModel = pm.GaisserHonda

    print 'Running with', iamod
    idjob = 0  # int(os.path.expandvars('$SGE_TASK_ID')) - 1

    mceq_run = MCEqRun(
        #provide the string of the interaction model
        interaction_model=iamod,
        #primary cosmic ray flux model
        #support a tuple (primary model class (not instance!), arguments)
        primary_model=(CRModel, None),
        # Zenith angle in degrees. 0=vertical, 90=horizontal
        theta_deg=0.,
Ejemplo n.º 4
0
    def set_interaction_model(self,
                              interaction_model,
                              particle_list=None,
                              update_particle_list=True,
                              force=False):
        """Sets interaction model and/or an external charm model for calculation.

        Decay and interaction matrix will be regenerated automatically
        after performing this call.

        Args:
          interaction_model (str): name of interaction model
          charm_model (str, optional): name of charm model
          force (bool): force loading interaction model
        """
        interaction_model = normalize_hadronic_model_name(interaction_model)

        info(1, interaction_model)

        if not force and (self._interactions.iam == interaction_model
                          ) and particle_list != self._particle_list:
            info(2, 'Skip, since current model identical to',
                 interaction_model + '.')
            return

        self._int_cs.load(interaction_model)

        # TODO: simplify this, stuff not needed anymore
        if not update_particle_list and self._particle_list is not None:
            info(10, 'Re-using particle list.')
            self._interactions.load(interaction_model,
                                    parent_list=self._particle_list)
            self.pman.set_interaction_model(self._int_cs, self._interactions)
            self.pman.set_decay_channels(self._decays)
            self.pman.set_continuous_losses(self._cont_losses)

        elif self._particle_list is None:
            info(10, 'New initialization of particle list.')
            # First initialization
            if particle_list is None:
                self._interactions.load(interaction_model)
            else:
                self._interactions.load(interaction_model,
                                        parent_list=particle_list)

            self._decays.load(parent_list=self._interactions.particles)
            self._particle_list = self._interactions.particles + self._decays.particles
            # Create particle database
            self.pman = ParticleManager(self._particle_list, self._energy_grid,
                                        self._int_cs)
            self.pman.set_interaction_model(self._int_cs, self._interactions)
            self.pman.set_decay_channels(self._decays)
            self.pman.set_continuous_losses(self._cont_losses)
            self.matrix_builder = MatrixBuilder(self.pman)

        elif (update_particle_list and particle_list != self._particle_list):
            info(10, 'Updating particle list.')
            # Updated particle list received
            if particle_list is None:
                self._interactions.load(interaction_model)
            else:
                self._interactions.load(interaction_model,
                                        parent_list=particle_list)

            self._decays.load(parent_list=self._interactions.particles)
            self._particle_list = self._interactions.particles + self._decays.particles
            self.pman.set_interaction_model(
                self._int_cs,
                self._interactions,
                updated_parent_list=self._particle_list)
            self.pman.set_decay_channels(self._decays)
            self.pman.set_continuous_losses(self._cont_losses)

        else:
            raise Exception('Should not happen in practice.')

        # Update dimensions if particle dimensions changed
        self._phi0.resize(self.dim_states)
        self._solution.resize(self.dim_states)

        # Restore insital condition if present
        if self._restore_initial_condition is not None:
            self._restore_initial_condition[0](
                *self._restore_initial_condition[1:])

        # initialize matrices
        self.int_m, self.dec_m = self.matrix_builder.construct_matrices(
            skip_decay_matrix=False)