Skip to content

Instantly share code, notes, and snippets.

View natl's full-sized avatar

Nathanael Lampe natl

View GitHub Profile
@natl
natl / nbtester.py
Created August 5, 2020 01:54
Python Notebook Executor
import os
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
if os.path.exists('./foo.csv'):
os.remove('./foo.csv')
with open('test-notebook.ipynb') as ff:
# This notebook creates foo.csv
Sub ExtractHL()
'
' Macro1 Macro
' Extract hyperlink from cell in first column in Excel
'
Dim HL As Hyperlink
Dim xCell As Range
Dim char As Integer
G4VPhysicalVolume* DetectorConstruction::Construct()
{
// ......
// some code here
// ......
cellPhysical = new G4Ellipsoid("cell", cell_x, cell_y, cell_z);
@natl
natl / root_converter.py
Created December 7, 2016 17:01
A method to convert root tuples to structured numpy arrays. Can probably (definitely) be improved.
import numpy as np
import ROOT
typeDict = {"Char_t": 'S16', 'Double_t': 'f8', 'Int_t': 'i8'}
def load_tuple_to_array(filename, tuplename, directory=None):
"""
load_tuple_to_array(filename, tuplename, directory=None)
Return root tuple as numpy structured array
@natl
natl / chem_macros.txt
Created November 7, 2016 11:47
Macro commands for Geant4 chemistry module
Command directory path : /chem/
Guidance :
Sub-directories :
/chem/gun/
/chem/reaction/ ...Title not available...
Commands :
activate * ...Title not available...
@natl
natl / G4BioChemicalMaterials.cc
Last active October 10, 2016 17:03
Updated G4BioChemicalMaterials() Method for G4NistMaterialBuilder class
/*
A note on sources: Prior to October 2016, the biomolecules in G4 had
inconsistently set density and ionisation values. While NIST provides
density and mean excitation energy values for Adenine and Guanine,
these are not well-cited and of dubious reliability. In Oct. 2016,
the materials were updated. Mean excitation energy is based of
Sauer et al. (2011) Mean Excitation Energies for Biomolecules:
Glycine to DNA, (Advances in Quantum Chemistry, vol 62)
DOI: 10.1016/B978-0-12-386477-2.00011-5
#include <sstream>
Event::Event():
G4UserEventAction(),
fOutfile(0) // initialise as empty
{
// constructor
}
Event::BeginOfEventAction(){
@natl
natl / multiprocess.py
Created March 17, 2016 11:20
Small multiprocessing example
from multiprocessing import Queue, Pool
def run_job(val):
x = 0
for ii in range(val):
x += ii**2
return x
@natl
natl / log10-replace.sh
Last active March 7, 2016 21:48
Regex/sed command to replace instances of std::log10 with the new G4log method
echo "std::log10((a+(b/3))/4);" | sed 's|std::log10|1./G4Pow::logZ(10)*G4Log|'