#########################################################################
#
# Script: generate_fixedtheta_particles.py
#
# Author: Igor Volobouev, Feb 2005
#
# Purpose: invokes a simple cosmic ray MC generator which makes
#          cosmic rays with fixed energy and incidence angle, but
#          uniformly distributed in phi. Theta argument is the angle
#          which rays make with the z axis (should be -180 for normal
#          incidence). The output is written to stdout in the format
#          acceptable by Gleam.
#
#########################################################################

"""
Usage: generate_fixedtheta_particles nevents particleName energy
                    max_impact_par backoff_distance theta_deg t0
"""

import random_seed
import sys
import math

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 == 7):
        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
        theta = float(argv[i])/180.0*math.pi; i+=1
        t0 = int(argv[i]); i+=1
    else:
        print __doc__
        return 1
    # create the cosmic ray generator
    label = CosmicRayLabel("test", ())
    generator = ThetaRangeTubeSource(label, coords.LOCAL, particleName, \
                                     FixedEnergySpectrum(energy), \
                                     max_impact_par, backoff_distance, \
                                     theta, theta)
    # write "nevents" events to the standard output
    generate_simple_events(t0, generator, nevents, sys.stdout)
    return 0

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