#########################################################################
#
# Script: generate_isotropic_particles.py
#
# Author: Igor Volobouev, Feb 2005
#
# Purpose: invokes a simple cosmic ray MC generator which makes
#          isotropically distributed cosmic rays with fixed energy.
#          The output is written to stdout in the format acceptable
#          by Gleam.
#
#########################################################################

"""
Usage: generate_isotropic_particles nevents particleName energy_in_MeV
                          max_impact_par_mm backoff_distance_mm t0_sec
"""

import random_seed
import sys

from cr_sources import *
from source_utils import *
from simple_generator import *
import coords

def main(argv=None):
    # parse the command line
    if argv is None:
        argv = sys.argv
    argc = len(argv)-1
    if (argc == 0):
        print __doc__
        return 0
    elif (argc == 6):
        i = 1
        nevents = int(argv[i]); i+=1
        particleName = argv[i]; i+=1
        energy = float(argv[i]); i+=1
        max_impact_par = float(argv[i]); i+=1
        backoff_distance = float(argv[i]); i+=1
        t0 = int(argv[i]); i+=1
    else:
        print __doc__
        return 1
    # create the cosmic ray generator
    label = CosmicRayLabel("test", ())
    generator = IsotropicTubeSource(label, coords.LOCAL, particleName,
                                    FixedEnergySpectrum(energy),
                                    max_impact_par, backoff_distance)
    # write "nevents" events to the standard output
    generate_simple_events(t0, generator, nevents, sys.stdout)
    return 0

if __name__=='__main__':
    sys.exit(main())
