Exemplo n.º 1
0
def tweak_source(source, vec):
	if len(vec) == 5:
		dx, dy, dz, dtheta, dphi = vec
	elif len(vec) == 6:
		dx, dy, dz = vec[:3]
		dtheta, dphi = vec[4:]
	# NB: PhotonicsSource needs degrees
	dtheta /= units.degree
	dphi /= units.degree
	phi = numpy.arctan2(source.diry, source.dirx)/units.degree - 180
	return photonics_service.PhotonicsSource(source.x+dx, source.y+dy,
	    source.z+dz, source.zenith+dtheta, phi+dphi, source.speed,
	    source.length, source.E, source.type)
Exemplo n.º 2
0
def random_sources(size=1):
	events = numpy.column_stack(random_vertices(size) + random_directions(size))
	for ev in events:
		yield photonics_service.PhotonicsSource(ev[0], ev[1], ev[2], 
		    ev[3], ev[4], 1, 0, 1e5, 1)
Exemplo n.º 3
0
# all following calls go more or less directly to photonics. use photonics units instead.
# define the cascade
x,y,z = 0., 0., 0.          # meters
zenith, azimuth = 0., 180. # degree
energy = 1e5                # GeV
photonicsType = 1           # e.m. cascade
length = 0                  # m (set to 0 for cascades)


## Creating photonics source
src = photonics_service.PhotonicsSource(x=x,
                                        y=y,
                                        z=z,
                                        zenith=zenith,
                                        azimuth=azimuth,
                                        speed = 1,
                                        length = length,
                                        energy = energy,
                                        type = photonicsType)
## 
### Order of obtaining information :
# 1) Select the coordinates of OM
# 2) Select source to get expectations 
# 3) Get probability quantiles

distances = []; amplitudes = []; 
quantiles = []; time_edges = np.linspace(0.0,3000.0,201)
for i in xrange(0,21):
    dummy_service.SelectModuleCoordinates(0.0, 0.0,  5.0 * i) ### Selecting source coordinates 
    amp, dist, geotime = dummy_service.SelectSource(src)      ### Selecting source, returns amplitude (in PEs), 
Exemplo n.º 4
0
segment_energy = 3.40  ##  segment energy (l = 15 m)

# Creating particles for sources
segment1 = dataclasses.I3Particle()
segment1.pos = dataclasses.I3Position(0.0, 0.0, 0.0)
segment1.dir = dataclasses.I3Direction(1.0, 0.0, 0.0)
segment1.length = segment_length
segment1.energy = segment_energy
segment1.shape = segment1.shape.ContainedTrack
segment2 = deepcopy(segment1)
segment2.pos.x = segment1.pos.x + segment1.length * segment1.dir.x
segment2.pos.y = segment1.pos.y + segment1.length * segment1.dir.y
segment2.pos.z = segment1.pos.z + segment1.length * segment1.dir.z

# Creating sources from particles
tr_source1 = photonics_service.PhotonicsSource(segment1)
tr_source2 = photonics_service.PhotonicsSource(segment2)

# Creating particle for cascade sources
cascade = deepcopy(segment1)
cascade.shape = cascade.shape.Cascade
cascade.length = 0.0
cascade.energy = 10.
# Creating photonics sources for cascade
cscd_source = photonics_service.PhotonicsSource(cascade)

time_edges = np.linspace(-25.0, 2500.0, 102)

### Order of obtaining information :
# 1) Select the coordinates of OM
# 2) Select source to get expectations
Exemplo n.º 5
0
def sampler_demo(pxs):
    """Plot samples from an EM cascade light source."""
    import pylab as p

    rand = phys_services.I3GSLRandomService(
        1337)  # creating random number generator

    pxs.SelectModuleCoordinates(
        0, 50, 0)  # First step for photonics services - select position of OM

    ps = photonics_service.PhotonicsSource(
        x=0,
        y=0,
        z=0,
        zenith=90,
        azimuth=0,
        speed=1.,
        length=0,
        energy=1e5,
        type=1
    )  ### Creating photonics source, type = 1 for cascade and =0 fo tracks
    meanpe, distance, geotime = pxs.SelectSource(
        ps
    )  # Getting the expectation for the OM position selected before from source
    # returns expectation (in photo-electrons), distance to emmision point and time to travel this time

    num_pe = rand.poisson(
        meanpe)  ## Getting random number of photonos for expectation

    dt = numpy.array(
        pxs.GetTimeDelays(rand, num_pe)
    )  ## Generates delay num_pe delay times (for a given OM position and given source)

    fig = p.figure(figsize=(8, 6))  ## Figure for the distribution plots
    fig.subplots_adjust(bottom=0.12, left=0.25)

    edges = numpy.linspace(0, 1000, 1001)  # Time edges

    quantiles = pxs.GetProbabilityQuantiles(
        edges, 0, 0)  ## Reading charge distribution (normalized to 1)
    centers = 0.5 * (edges[1:] + edges[:-1])

    p.plot(centers, quantiles, color='k', ls='--', label='Mean')

    pandel = gen_pandel(distance)  ## Comparing to pandel function
    prop_quantiles = (pandel.cdf(edges[1:]) - pandel.cdf(edges[:-1])
                      )  ## Reading Pandel distribution (not part of photonics
    p.plot(centers, prop_quantiles, color='k', ls=':', label='Proposal')

    bins, edges, patches = p.hist(dt,
                                  bins=700,
                                  range=(0, 7000),
                                  histtype='step',
                                  color='k',
                                  normed=True,
                                  linestyle='solid',
                                  label='Samples')

    p.xlabel('Delay time [ns]')
    p.ylabel('dP/dt')
    p.xlim((0, 1000))

    p.legend(prop=dict(size='medium'))
Exemplo n.º 6
0
def azi_scan(pxs,
             omx=-50,
             omy=0,
             omz=0,
             t_edges=numpy.linspace(0, 500, 101),
             az_edges=numpy.linspace(-180, 180, 101),
             zcenter=0,
             gradient=True):

    with_numpy = hasattr(pxs, 'GetProbabilityQuantileGradients')

    if gradient and not with_numpy:
        raise ValueError(
            """You asked for gradients, but the PhotonicsService instance you passed
            (%s) doesn't appear to be able to return Numpy arrays.""" % (pxs))

    pxs.SelectModuleCoordinates(omx, omy, omz)  # selecting modules coordinates
    t0 = 0
    t_centers = 0.5 * (t_edges[1:] + t_edges[:-1])
    az_centers = 0.5 * (az_edges[1:] + az_edges[:-1])

    amp_shape = (az_centers.size, t_centers.size)

    zenith = 90.

    sources = [
        photonics_service.PhotonicsSource(0, 0, zcenter, zenith, azi, 1.0, 0,
                                          1e5, 1) for azi in az_centers
    ]  # creating photonics sources (rotating azimuth direction for cascades)

    amps = numpy.empty(amp_shape)
    if gradient:
        grads = numpy.empty(amp_shape + (7, ))
    else:
        grads = None

    if with_numpy:
        te = t_edges
    else:  # sometimes you have to bend over backwards.
        te = icetray.vector_double()
        te.extend(t_edges)

    for i, source in enumerate(sources):
        meanamp, distance, geotime = pxs.SelectSource(
            source
        )  # Selecting source from sources (cascades with different directions)
        # Numpy-less versions of GetProbabilityQuantiles return a
        # wrapped vector<double> rather than a useful Numpy array
        quantiles = numpy.asarray(pxs.GetProbabilityQuantiles(
            te, t0,
            0))  # Getting timing distribution, t0 should be added since
        amps[
            i, :] = meanamp * quantiles  ## Quantiles are normalized to 1, have to scale up
        if gradient:
            # amplitude gradients are given with respect to x, y, z, theta, phi, E
            # quantile gradients are given with respect to x, y, z, t, theta, phi
            amp_grad = numpy.zeros((1, 1, 7))
            temp = pxs.GetMeanAmplitudeGradient(
            )  # Amplitude gradients for given source and position
            amp_grad[:, :, :3] = temp[:3]
            amp_grad[:, :, 4:] = temp[3:]
            quant_grads = numpy.zeros(quantiles.shape + (7, ))
            temp = pxs.GetProbabilityQuantileGradients(
                t_edges, t0)  # Reading time gradients
            quant_grads[:, :-1] = temp
            # drizzle lightly with Chain Rule sauce
            grads[i] = amp_grad * quantiles[:, numpy.
                                            newaxis] + meanamp * quant_grads

    return (
        t_edges, az_edges, amps, grads
    )  # returning time and azimuth distribution of the charge + gradients
Exemplo n.º 7
0
        "LowEnergyCorrectedCascades_z20_a10_250m.prob.fits"),  ## Timing tables
    timingSigma=0.0,
    maxRadius=np.inf
)  ## If the light sensor is further from the source than this distance - zero will be returned, default value is infinite

# all following calls go more or less directly to photonics. use photonics units instead.
# define the cascade
x, y, z = 0., 0., 0.  # meters
zenith, azimuth = 45., 180.  # degree
energy = 1e5  # GeV
photonicsType = 1  # e.m. cascade
length = 0  # m (irrelevant for cascades)
speed = 1.  # in fractions of c
# create source object and define module coordinates
src = photonics_service.PhotonicsSource(
    x, y, z, zenith, azimuth, speed, length, energy,
    photonicsType)  # Creating photonics source, 1 in the middle - is speed
ps.SelectModuleCoordinates(-100, 0, 0)  # selecting cooridnates of module

# make some manual calls to the service
for delay in [100, 500, 1000, 2000]:
    totamp, prob = ps.GetPhotorecInfo(
        delay, src
    )  ## Getting expectation and probability dp/dt at delay time for given source
    print("delay: %5.0f meanamp: %10f dpdt: %10f" % (delay, totamp, prob))

# use numpy.vectorize to create a function that accepts arrays as arguments
dpdt = n.vectorize(lambda t: ps.GetPhotorecInfo(t, src)[1])

# plot the delay time pdf
delays = n.linspace(0, 3000, 1000)