def testParticleCollectorAsModuleListOutput(self): sim = crp.ModuleList() sim.add(crp.MaximumTrajectoryLength(3.14)) sim.add(crp.SimplePropagation(0.001, 0.001)) collector = crp.ParticleCollector() sim.add(collector) c = crp.Candidate() sim.run(c) self.assertAlmostEqual(collector[0].getTrajectoryLength(), 3.14, places=2)
def testParticleCollectorAsModuleListInput(self): sim = crp.ModuleList() sim.add(crp.MaximumTrajectoryLength(3.14)) sim.add(crp.SimplePropagation(0.001, 0.001)) collector = crp.ParticleCollector() c1 = crp.Candidate() c2 = crp.Candidate() collector.process(c1) collector.process(c2) sim.run(collector.getContainer()) for c in collector: self.assertAlmostEqual(c.getTrajectoryLength(), 3.14, places=2)
def runTest(self): outputFile = tempfile.NamedTemporaryFile() sim = crp.ModuleList() # photon fields CMB = crp.CMB() IRB = crp.IRB_Kneiske04() sim.add(crp.SimplePropagation(1 * crp.kpc, 1 * crp.Mpc)) sim.add(crp.Redshift()) sim.add(crp.PhotoPionProduction(CMB)) sim.add(crp.PhotoPionProduction(IRB)) sim.add(crp.PhotoDisintegration(CMB)) sim.add(crp.PhotoDisintegration(IRB)) sim.add(crp.NuclearDecay()) sim.add(crp.ElectronPairProduction(CMB)) sim.add(crp.ElectronPairProduction(IRB)) sim.add(crp.MinimumEnergy(1 * crp.EeV)) sim.add(crp.EMCascade()) # observer obs = crp.Observer() obs.add(crp.ObserverPoint()) sim.add(obs) # output output = crp.TextOutput(outputFile.name) output.set1D(True) obs.onDetection(output) # source source = crp.Source() source.add(crp.SourceUniform1D(1 * crp.Mpc, 1000 * crp.Mpc)) source.add(crp.SourceRedshift1D()) # power law spectrum with charge dependent maximum energy Z*100 EeV # elements: H, He, N, Fe with equal abundances at constant energy per # nucleon composition = crp.SourceComposition(1 * crp.EeV, 100 * crp.EeV, -1) composition.add(1, 1, 1) # H composition.add(4, 2, 1) # He-4 composition.add(14, 7, 1) # N-14 composition.add(56, 26, 1) # Fe-56 source.add(composition) # run simulation sim.run(source, 1) outputFile.close()
import crpropa import CRPropaROOTOutput print("My Simulation\n") ml = crpropa.ModuleList() ml.add(crpropa.SimplePropagation(1 * crpropa.parsec, 100 * crpropa.parsec)) ml.add(crpropa.MaximumTrajectoryLength(1000 * crpropa.parsec)) print("+++ List of modules") print(ml.getDescription()) print("+++ Preparing source") source = crpropa.Source() print(source.getDescription()) print("+++ Starting Simulation") ml.run(source, 1) print("+++ Done")
# Galactic lensing can be applied with the requirement that Liouville's theorem # holds, thus in this context: from an isotropic distribution outside the area # of influence of the Galactic magnetic field follows an isotropic arrival # distribution at any point within our Galaxy. # First, we are setting up the oberver which we will place further outside of # the Galactic center than Earth to exaggerate the observed effects: # In[1]: import crpropa import numpy as np n = 10000000 # simulation setup sim = crpropa.ModuleList() # we just need propagation in straight lines here to demonstrate the effect sim.add(crpropa.SimplePropagation()) # collect arriving cosmic rays at observer 19 kpc outside of the Galactic center # to exaggerate effects obs = crpropa.Observer() pos_earth = crpropa.Vector3d(-19, 0, 0) * crpropa.kpc # observer with radius 500 pc to collect fast reasonable statistics obs.add(crpropa.ObserverSurface(crpropa.Sphere(pos_earth, 0.5 * crpropa.kpc))) # Use crpropa's particle collector to only collect the cosmic rays at Earth output = crpropa.ParticleCollector() obs.onDetection(output) sim.add(obs) # discard outwards going cosmic rays, that missed Earth and leave the Galaxy
lat = float(sys.argv[3]) s1 = int(sys.argv[4]) s2 = int(sys.argv[5]) s3 = int(sys.argv[6]) pid = -crp.nucleusId(1, 1) sun = crp.Vector3d(-8.5, 0, 0) * crp.kpc E = E * crp.EeV nhat = hp.dir2vec(lon, lat, lonlat=True) direc = crp.Vector3d() direc.setXYZ(nhat[0], nhat[1], nhat[2]) ps = crp.ParticleState(pid, E, sun, direc) cr = crp.Candidate(ps) sim = crp.ModuleList() sim.add(crp.Redshift()) sim.add(crp.PhotoPionProduction(crp.CMB)) sim.add(crp.PhotoPionProduction(crp.IRB)) sim.add(crp.PhotoDisintegration(crp.CMB)) sim.add(crp.PhotoDisintegration(crp.IRB)) sim.add(crp.NuclearDecay()) sim.add(crp.ElectronPairProduction(crp.CMB)) sim.add(crp.ElectronPairProduction(crp.IRB)) np.random.seed(s1) p1 = ss.truncnorm.rvs(a1, b1, 18.25, 2.75, size=1)[0] p2 = ss.truncnorm.rvs(a2, b2, 0.2, 0.12, size=1)[0] p3 = ss.truncnorm.rvs(a3, b3, 10.97, 3.80, size=1)[0] p4 = ss.truncnorm.rvs(a4, b4, 2.84, 1.30, size=1)[0] Bfield = crp.JF12Field(s1, p1, p2, p3, p4) Bfield.randomStriated(s2)