go-hep.org/x/hep@v0.38.1/hbook/count_example_test.go (about)

     1  // Copyright ©2020 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package hbook_test
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"go-hep.org/x/hep/hbook"
    11  )
    12  
    13  func ExampleCount() {
    14  	c := hbook.Count{}
    15  	c.XRange = hbook.Range{Min: 0, Max: 1}
    16  	c.Val = 10
    17  	c.Err.Low = 2
    18  	c.Err.High = 3
    19  
    20  	fmt.Printf("[%v, %v] -> %v +%v -%v",
    21  		c.XRange.Min, c.XRange.Max,
    22  		c.Val, c.Err.High, c.Err.Low)
    23  
    24  	// Output:
    25  	// [0, 1] -> 10 +3 -2
    26  }
    27  
    28  func ExampleCount_withH1D() {
    29  
    30  	h := hbook.NewH1D(6, 0, 6)
    31  	h.Fill(-0.5, 1)
    32  	h.Fill(0, 1.5)
    33  	h.Fill(0.5, 1)
    34  	h.Fill(1.2, 1)
    35  	h.Fill(2.1, 2)
    36  	h.Fill(4.2, 1)
    37  	h.Fill(5.9, 1)
    38  	h.Fill(6, 0.5)
    39  
    40  	for _, c := range h.Counts() {
    41  		fmt.Printf("[%v, %v] -> %v +%.1f -%.1f\n",
    42  			c.XRange.Min, c.XRange.Max,
    43  			c.Val, c.Err.High, c.Err.Low)
    44  	}
    45  
    46  	// Output:
    47  	// [0, 1] -> 2.5 +0.9 -0.9
    48  	// [1, 2] -> 1 +0.5 -0.5
    49  	// [2, 3] -> 2 +1.0 -1.0
    50  	// [3, 4] -> 0 +0.0 -0.0
    51  	// [4, 5] -> 1 +0.5 -0.5
    52  	// [5, 6] -> 1 +0.5 -0.5
    53  }