diff --git a/_episodes/02-uproot.md b/_episodes/02-uproot.md index e5674ab..096e5ba 100644 --- a/_episodes/02-uproot.md +++ b/_episodes/02-uproot.md @@ -75,12 +75,12 @@ Uproot doesn't do any plotting or histogram manipulation, so the most useful met h.to_hist().plot() ``` -Uproot histograms also satisfy the [UHI plotting protocol](https://uhi.readthedocs.io/en/latest/plotting.html), so they have methods like `values` (bin contents), `variances` (errors squared), and `edges`. +Uproot histograms also satisfy the [UHI plotting protocol](https://uhi.readthedocs.io/en/latest/plotting.html), so they have methods like `values` (bin contents), `variances` (errors squared), and `axes`. ```python h.values() h.variances() -h.axis("x").edges() # "x", "y", "z" or 0, 1, 2 +list(h.axes[0]) # "x", "y", "z" or 0, 1, 2 ``` ## Reading a TTree diff --git a/_episodes/03-ttree-details.md b/_episodes/03-ttree-details.md index 4fca3be..cfdfd65 100644 --- a/_episodes/03-ttree-details.md +++ b/_episodes/03-ttree-details.md @@ -72,7 +72,7 @@ However, it takes a long time because a lot of data have to be sent over the net To limit the amount of data read, set `entry_start` and `entry_stop` to the range you want. The `entry_start` is inclusive, `entry_stop` exclusive, and the first entry would be indexed by `0`, just like slices in an array interface (first lesson). Uproot only reads as many TBaskets as are needed to provide these entries. ```python -tree["nMuon"].array(entry_start=1000, entry_stop=2000) +tree["nMuon"].array(entry_start=1_000, entry_stop=2_000) ``` These are the building blocks of a parallel data reader: each is responsible for a different slice. (See also [uproot.TTree.num_entries_for](https://uproot.readthedocs.io/en/latest/uproot.behaviors.TTree.TTree.html#num-entries-for) and [uproot.TTree.common_entry_offsets](https://uproot.readthedocs.io/en/latest/uproot.behaviors.TTree.TTree.html#common-entry-offsets), which can be used to pick `entry_start`/`entry_stop` in optimal ways.) @@ -83,7 +83,7 @@ Suppose you know that you will need all of the muon TBranches. Asking for them i ```python muons = tree.arrays( - ["Muon_pt", "Muon_eta", "Muon_phi", "Muon_mass", "Muon_charge"], entry_stop=1000 + ["Muon_pt", "Muon_eta", "Muon_phi", "Muon_mass", "Muon_charge"], entry_stop=1_000 ) muons ``` @@ -114,7 +114,7 @@ Suppose you have many muon TBranches and you don't want to list them all. The [u ```python tree.keys(filter_name="Muon_*") -tree.arrays(filter_name="Muon_*", entry_stop=1000) +tree.arrays(filter_name="Muon_*", entry_stop=1_000) ``` (There are also `filter_typename` and `filter_branch` for more options.) @@ -124,7 +124,7 @@ tree.arrays(filter_name="Muon_*", entry_stop=1000) The best way to figure out what you're doing is to tinker with small datasets, and then scale them up. Here, we take 1000 events and compute dimuon masses. ```python -muons = tree.arrays(entry_stop=1000) +muons = tree.arrays(entry_stop=1_000) cut = muons["nMuon"] == 2 pt0 = muons["Muon_pt", cut, 0] @@ -178,11 +178,11 @@ In all of the above examples, the `array`, `arrays`, and `iterate` methods retur Use `library="np"` or `library="pd"` to get NumPy or Pandas, respectively. ```python -tree["nMuon"].array(library="np", entry_stop=10000) +tree["nMuon"].array(library="np", entry_stop=10_000) -tree.arrays(library="np", entry_stop=10000) +tree.arrays(library="np", entry_stop=10_000) -tree.arrays(library="pd", entry_stop=10000) +tree.arrays(library="pd", entry_stop=10_000) ``` NumPy is great for non-jagged data like the `"nMuon"` branch, but it has to represent an unknown number of muons per event as an array of NumPy arrays (i.e. Python objects). diff --git a/_episodes/05-histograms.md b/_episodes/05-histograms.md index ddb47e7..e15c9f5 100644 --- a/_episodes/05-histograms.md +++ b/_episodes/05-histograms.md @@ -82,19 +82,31 @@ h[10:110].plot() but often you want to select bins by coordinate value ```python +# Explicit version h[hist.loc(90) :].plot() + +# Short version +h[90j:].plot() ``` or rebin by a factor, ```python +# Explicit version h[:: hist.rebin(2)].plot() + +# Short version +h[::2j].plot() ``` or sum over a range. ```python +# Explicit version h[hist.loc(80) : hist.loc(100) : sum] + +# Short version +h[90j:100j:sum] ``` Things get more interesting when a histogram has multiple dimensions. @@ -123,13 +135,9 @@ vertexhist.fill( ) vertexhist[:, :, sum].plot2d_full() -vertexhist[ - hist.loc(-0.25) : hist.loc(0.25), hist.loc(-0.25) : hist.loc(0.25), sum -].plot2d_full() +vertexhist[-0.25j:0.25j, -0.25j:0.25j, sum].plot2d_full() vertexhist[sum, sum, :].plot() -vertexhist[ - hist.loc(-0.25) : hist.loc(0.25) : sum, hist.loc(-0.25) : hist.loc(0.25) : sum, : -].plot() +vertexhist[-0.25j:0.25j:sum, -0.25j:0.25j:sum, :].plot() ``` A histogram object can have more dimensions than you can reasonably visualize—you can slice, rebin, and project it into something visual later. diff --git a/_episodes/06-lorentz-vectors.md b/_episodes/06-lorentz-vectors.md index 9da116e..71b2f83 100644 --- a/_episodes/06-lorentz-vectors.md +++ b/_episodes/06-lorentz-vectors.md @@ -92,7 +92,7 @@ from hepunits import GeV particle.Particle.findall("pi") -z_boson = particle.Particle.from_name("Z0") +z_boson = particle.Particle.from_string("Z0") z_boson.mass / GeV, z_boson.width / GeV print(z_boson.describe()) diff --git a/_episodes/07-scaling-up.md b/_episodes/07-scaling-up.md index 7da87e9..cd7cf83 100644 --- a/_episodes/07-scaling-up.md +++ b/_episodes/07-scaling-up.md @@ -46,6 +46,6 @@ However, the [Coffea project](https://github.com/CoffeaTeam) ([documentation](ht and finally -- cookie [GitHub](https://github.com/scikit-hep/cookie), [documentation](https://scikit-hep.org/developer), a template for making your own... +- cookie [GitHub](https://github.com/scientific-python/cookie), [documentation](https://learn.scientific-python.org/development), a template for making your own... {% include links.md %}