Ejemplo n.º 1
0
 def test_ParticleCollector(self):
     c = crp.Candidate()
     p = crp.ParticleCollector()
     p.process(c)
     c_out = p[0]
     for c_i in p:
         c_out = c_i
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
    def testParticleCollectorIterator(self):
        collector = crp.ParticleCollector()
        lengths = [1 * crp.pc, 10 * crp.pc, 100 * crp.pc]
        for l in lengths:
            c = crp.Candidate()
            c.setTrajectoryLength(l)
            collector.process(c)

        self.assertEqual(len(collector), len(lengths))

        for c, l in zip(collector, lengths):
            self.assertEqual(c.getTrajectoryLength(), l)
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
obs_trash = crpropa.Observer()
obs_trash.add(
    crpropa.ObserverSurface(
        crpropa.Sphere(crpropa.Vector3d(0), 21 * crpropa.kpc)))
sim.add(obs_trash)

# ## Lambert's distribution
# For the source setup we have to consider that from an isotropic propagation
# in the Extragalactic universe, the directions on any surface element follows
# the Lambert's distribution (https://en.wikipedia.org/wiki/Lambert%27s_cosine_law).
# You could also phrase: vertical incident angles are more frequent due to the