BurstCube

simGenerator module

class simGenerator.configurator(*args)[source]
azbins

Creates increments of azimuth angle to be sampled by individual source files.

createSourceFiles(dir='')[source]

Creates a source file from a configurator object with a specific angle and energy

Parameters:
  • dir (string) –
  • desired directory of the output (the) –
Returns:

  • In your directory all of the source files with specific angles
  • and energies.

ebins

Creates increments of energy (keV) to be sampled by individual source files.

loadConfig(path)[source]
saveConfig(path)[source]
zebins

Creates increments of zenith angle to be sampled by individual source files.

simGenerator.createSourceString(config, energy, ze, az)[source]

Creates a source file from a configurator object with a specific angle and energy

Parameters:config (string) – The .yaml file the imposes the conditions for the source files desired.
Returns:srcstr – A sring which can be used to create a source file for cosima.
Return type:string

bcSim module

class bcSim.simFile(simFile, sourceFile, logFile='')[source]
ED_res
azimuth
calculateAeff(useEres=False, width=0.0)[source]

Calculates effective area of sim file.

Parameters:
  • useEres (Boolean) – Switch to either use the energy resolution in the calculation or not. If you don’t use this it assumes all of the events are good.
  • width (Float) – The energy width that is used to reject events in the selection.
Returns:

Aeff – The effective area.

Return type:

Float

energy
fileToDict(filename, commentString='#', termString=None)[source]
getEresFromFile(filename, commentString='//')[source]
getHits(detID=4)[source]

Get the hit details of all of the events in the sim file. Ignores the a,b,and c details.

Parameters:detID (int) – Detector ID (usually 4)
Returns:hits – Five column Structured array. Columns are all floats and are x_pos, y_pos, z_pos, E, and tobs.
Return type:numpy structured array
getTriggerProbability(num_det=4, test=False)[source]

Takes a single simFile (from bcSim.simFiles(config.yaml)) and returns the probability of hitting in each detector

Parameters:
  • num_det (integer) – Number of detectors to get triggers for.
  • test (boolean) – Run a quick test over a limited number of events (20)
Returns:

prob_det_info – Array is (energy, az, ze, error, prob1, prob2, …)

Return type:

numpy array

logToDict(filename)[source]

Reads a gzipped log file and populates a dictionary with information about the events. Returns this dictionary.

Parameters:filename (string or byte like object) – Name of log file to read.
Returns:
  • eventDict (dictionary)
  • Dictionary with the key being the trigger number (int). Each
  • value is a tuple of the event number (int) and the detector
  • (str) that was hit.
passEres(alpha=2.57, escape=30.0)[source]

Calculates the fraction of events that are good (fully absorbed) and those that escape. The default escape photon energy is for CsI (30.0 keV). An alpha of 2.57 is based on 10% energy resolution at 662 keV with 1/sqrt(E) scaling. Sigma is calculated as the FWHM or eres diveded by 2.35.

Returns:
  • frac (float)
  • mod_frac (float)
printDetails()[source]

Prints the general information about specific sim files.

zenith
class bcSim.simFiles(config_file)[source]
applyEres()[source]

Applies the energy resolution to the deposited energy in each sim file and returns a flattened array for plotting.

Returns:
  • null (numpy array)
  • numpy array that contains all of the events with eres applied.
calculateAeff(useEres=False, sigma=2.0)[source]

Calculates effective area from the information contained within the .sim files.

Parameters:
  • self (null) –
  • useEres (boolean) – Switch to use the energy resolution in the calculation.
  • sigma (float) – Width of energy cut in sigma. Default is 2.0.
Returns:

aeffs – Numpy array containing effective area of detector.

Return type:

array

getAllTriggerProbability(num_detectors=4, test=False)[source]

Returns the probabability of hitting each detector in each simulation.

Parameters:
  • num_detectors (int) – Number of detectors in the simulation
  • test (boolean) – run a quick test over a limited number of files (20)
Returns:

det_prob – Contains information from all the files about the energy, angles and probability of hitting a given detector

Return type:

numpy array

loadFiles()[source]
Parameters:self (null) –
Returns:sfs – numpy array containing information about each sim file.
Return type:array

plotSim module

plotSim.getGBMdata(gbmfile='')[source]

Reads the GBM NaI effective area file and returns a numpy array with two columns energy and aeff.

Parameters:gbmfile (string) – Name of file that contains the GBM data. If not given, will look in the installed location.
Returns:
  • gbmdata (array)
  • numpy array with two columns energy and aeff
plotSim.plotAeff(simFiles, useEres=False, plotGBM=False)[source]

Plots the GBM NaI effective area against the changing parts of the simulation

Parameters:simFiles (list) – Simulation files generated by MEGAlib.
Returns:
Return type:a bunch of plots!
plotSim.plotAeffComparison(sims, names, useEres=False, compareTo='GBM', axis='ze', elim=(1, 100000.0))[source]

Makes Aeff comparison plots of two or more simulations.

Parameters:
  • sims (list) – List of simulation objects that need to be compared.
  • names (list) – List of strings used to label the plots. Should be the same length as the sims list.
  • compareTo (string) – The curve to make the comparison to in the percent difference. Default is GBM. You can pick any of the other curves in the names list.
  • axis (string) – Either ze or az for the angle axis to plot against.
Returns:

Return type:

Nothing

plotSim.plotAeffvsEnergy(energy, aeff, aeff_eres, aeff_eres_modfrac, az=0, ze=0, plotGBM=False)[source]

Plots the GBM NaI effective area against the energy of that source.

Parameters:
  • energy (array) – numpy array of energy in units of keV of the sources.
  • aeff (array) – numpy array with GBM NaI effective area.
  • aeff_eres (array) – I’ll look up energy resulution later
  • aeff_eres_modfrac (array) – plus escape?
Returns:

Return type:

a plot of the effective area vs. energy.

plotSim.plotAeffvsPhi(azimuth, aeff, aeff_eres, aeff_eres_modfrac)[source]

Plots the GBM NaI effective area against the polar angle phi used to generate that source.

Parameters:
  • azimuth (array) – numpy array of the angle in deg of the source.
  • aeff (array) – numpy array with GBM NaI effective area.
  • aeff_eres (array) – I’ll look up energy resulution later
  • aeff_eres_modfrac (array) – plus escape?
Returns:

Return type:

a plot!

plotSim.plotAeffvsTheta(theta, aeff, aeff_eres, aeff_eres_modfrac, energy=100.0, paren='')[source]

Plots the GBM NaI effective area against the polar angle theta used to generate that source.

Parameters:
  • theta (array) – numpy array of the angle in deg of the source.
  • aeff (array) – numpy array with GBM NaI effective area.
  • aeff_eres (array) – I’ll look up energy resulution later
  • aeff_eres_modfrac (array) – plus escape?
Returns:

Return type:

a plot!

plotSim.plotAngleComparison(sims, names, axis='ze', compareTo='', useEres=False, energyRange=(99, 101), angleRange=(0, 360))[source]

Makes Theta comparison plots of two or more simulations.

Parameters:
  • sims (list) – List of simulation objects that need to be compared.
  • names (list) – List of strings used to label the plots. Should be the same length as the sims list.
  • axis (string ('ze' or 'az')) – Axis to plot (either ‘ze’ for zenith or ‘az’ for azimuth.
  • compareTo (string) – The curve to make the comparison to in the percent difference. Default is the first in the list. You can pick any of the other curves in the names list.
  • usEres (bool) – Use the energy resolution in the effective area calculation.
  • energyRang (list) – The energy range (in keV) to plot as (emin, emax).
  • angleRange (list) – The angular range (in keV) to plot as (degmin, degmax). This will only plot curves that fall into this range for the axis that you are not plotting against (i.e. it’ll be ‘az’ if you selected ‘ze’ for axis above.
Returns:

Return type:

Nothing

utils module

utils.getAllTriggerProbability(filelist, num_detectors=4, test=False)[source]

Takes a bunch of simFiles (from bcSim.simFiles(config.yaml)) and returns the probability of hitting in each detector

Parameters:
  • self (simFiles) –
  • test (run a quick test over a limited number of files (20)) –
Returns:

det_prob – Contains information from all the files about the energy, angles and probability of hitting a given detector

Return type:

numpy array

utils.getDetailsFromFilename(filename)[source]

Function to get the energy and angle from a filename. Really should be meta data.

This function will be deprecated at some point since the energy and angle are in the simFile object now.

utils.getFilenameFromDetails(details)[source]

Takes a dictionary of details and makes a machine readible filename out of it. Angle comes in radians.

utils.getTriggerProbability(htsimfile, num_det=4, test=False)[source]

Takes a single simFile (from bcSim.simFiles(config.yaml)) and returns the probability of hitting in each detector

Parameters:
  • self (simFile) –
  • test (run a quick test over a limited number of events (20)) –
Returns:

  • prob_det_info (1x6 numpy array containing information about the)
  • energy, angles and probability of hitting a given detector

utils.setPath(desiredPath='', desiredPathName='BURSTCUBE')[source]

Checks for desiredPathName path. Returns 0 if ok, 1 if bad.