1+ import os
2+ import numpy as np
3+ import pytest
4+
5+ from orbit .core .bunch import Bunch
6+ from orbit .lattice import AccLattice
7+ from orbit .lattice import AccNode
8+ from orbit .teapot import DriftTEAPOT
9+ from orbit .teapot import QuadTEAPOT
10+ from orbit .teapot import TEAPOT_Lattice
11+
12+ from orbit_tools .bunch import set_bunch_coords
13+ from orbit_tools .diag import BunchHistogram
14+
15+
16+ def test_hist ():
17+ nbins = 100
18+ seed = 123
19+
20+ rng = np .random .default_rng (seed )
21+ x = rng .normal (size = (10_000 , 6 ))
22+
23+ bunch = Bunch ()
24+ bunch .mass (0.938 )
25+ bunch .getSyncParticle ().kinEnergy (1.000 )
26+ bunch .macroSize (1.0 )
27+ bunch = set_bunch_coords (bunch , x )
28+
29+ axis_list = []
30+ for i in range (6 ):
31+ axis_list .append ((i ,))
32+
33+ for i in range (6 ):
34+ for j in range (i ):
35+ axis_list .append ((i , j ))
36+
37+ for axis in axis_list :
38+ ndim = len (axis )
39+ shape = tuple (ndim * [nbins ])
40+ limits = ndim * [(- 5.0 , 5.0 )]
41+
42+ # Compute histogram using BunchHistogram
43+ hist = BunchHistogram (axis = axis , shape = shape , limits = limits )
44+ values = hist .compute_histogram (bunch )
45+ values = values / np .max (values )
46+
47+ # Compute histogram using NumPy
48+ values_np , _ = np .histogramdd (x [:, axis ], bins = hist .edges )
49+ values_np = values_np / np .max (values_np )
50+
51+ # Compare the histograms. There will be differences because Grid
52+ # classes use weighting.
53+ print (np .max (np .abs (values - values_np )))
54+
55+
56+
0 commit comments