Commit eca71dfa authored by David Blyth's avatar David Blyth

Improved trackeff and generalized PreciseTicks suggested number of ticks

parent feb3eff8
...@@ -7,10 +7,14 @@ import ( ...@@ -7,10 +7,14 @@ import (
"gonum.org/v1/plot" "gonum.org/v1/plot"
) )
type PreciseTicks struct{} type PreciseTicks struct {
NSuggestedTicks int
}
func (PreciseTicks) Ticks(min, max float64) []plot.Tick { func (t PreciseTicks) Ticks(min, max float64) []plot.Tick {
const suggestedTicks = 4 if t.NSuggestedTicks == 0 {
t.NSuggestedTicks = 4
}
if max <= min { if max <= min {
panic("illegal range") panic("illegal range")
...@@ -18,12 +22,12 @@ func (PreciseTicks) Ticks(min, max float64) []plot.Tick { ...@@ -18,12 +22,12 @@ func (PreciseTicks) Ticks(min, max float64) []plot.Tick {
tens := math.Pow10(int(math.Floor(math.Log10(max - min)))) tens := math.Pow10(int(math.Floor(math.Log10(max - min))))
n := (max - min) / tens n := (max - min) / tens
for n < suggestedTicks-1 { for n < float64(t.NSuggestedTicks)-1 {
tens /= 10 tens /= 10
n = (max - min) / tens n = (max - min) / tens
} }
majorMult := int(n / (suggestedTicks - 1)) majorMult := int(n / float64(t.NSuggestedTicks-1))
switch majorMult { switch majorMult {
case 7: case 7:
majorMult = 6 majorMult = 6
......
...@@ -3,10 +3,10 @@ package main ...@@ -3,10 +3,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"image/color"
"log" "log"
"math" "math"
"os" "os"
//"strconv"
"github.com/decibelcooper/proio/go-proio" "github.com/decibelcooper/proio/go-proio"
"github.com/decibelcooper/proio/go-proio/model/eic" "github.com/decibelcooper/proio/go-proio/model/eic"
...@@ -25,10 +25,12 @@ var ( ...@@ -25,10 +25,12 @@ var (
fracCut = flag.Float64("frac", 0.01, "maximum fractional magnitude of the difference in momentum between track and true") fracCut = flag.Float64("frac", 0.01, "maximum fractional magnitude of the difference in momentum between track and true")
etaLimit = flag.Float64("etalimit", 4, "maximum absolute value of eta") etaLimit = flag.Float64("etalimit", 4, "maximum absolute value of eta")
nBins = flag.Int("nbins", 80, "number of bins") nBins = flag.Int("nbins", 80, "number of bins")
title = flag.String("title", "", "plot title")
prefix = flag.String("prefix", "out", "output file prefix")
) )
func printUsage() { func printUsage() {
fmt.Fprintf(os.Stderr, `Usage: `+os.Args[0]+` [options] <proio-input-file> <output-prefix> fmt.Fprintf(os.Stderr, `Usage: `+os.Args[0]+` [options] <proio-input-files>...
options: options:
`, `,
...@@ -39,19 +41,25 @@ options: ...@@ -39,19 +41,25 @@ options:
func main() { func main() {
flag.Usage = printUsage flag.Usage = printUsage
flag.Parse() flag.Parse()
if flag.NArg() != 2 { if flag.NArg() < 1 {
printUsage() printUsage()
log.Fatal("Invalid arguments") log.Fatal("Invalid arguments")
} }
p, _ := plot.New()
p.Title.Text = *title
p.X.Label.Text = "eta"
p.X.Tick.Marker = eicplot.PreciseTicks{NSuggestedTicks: 5}
p.Y.Tick.Marker = eicplot.PreciseTicks{NSuggestedTicks: 5}
for i, filename := range flag.Args() {
etaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit) etaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit)
trueEtaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit) trueEtaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit)
reader, err := proio.Open(flag.Arg(0)) reader, err := proio.Open(filename)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer reader.Close()
eventNum := 0 eventNum := 0
for event := range reader.ScanEvents() { for event := range reader.ScanEvents() {
...@@ -160,18 +168,25 @@ func main() { ...@@ -160,18 +168,25 @@ func main() {
} }
} }
errPoints := plotutil.ErrorPoints{points, xErrors, yErrors} errPoints := plotutil.ErrorPoints{points, xErrors, yErrors}
scatter, _ := plotter.NewScatter(errPoints) xerr, _ := plotter.NewXErrorBars(errPoints)
yerr, _ := plotter.NewYErrorBars(errPoints) yerr, _ := plotter.NewYErrorBars(errPoints)
p, _ := plot.New() pointColor := color.RGBA{A: 255}
p.Title.Text = "Tracking efficiency" switch i {
p.X.Label.Text = "eta" case 1:
p.X.Tick.Marker = eicplot.PreciseTicks{} pointColor = color.RGBA{G: 255, A: 255}
p.Y.Tick.Marker = eicplot.PreciseTicks{} case 2:
p.Add(scatter) pointColor = color.RGBA{B: 255, A: 255}
}
xerr.LineStyle.Color = pointColor
yerr.LineStyle.Color = pointColor
p.Add(xerr)
p.Add(yerr) p.Add(yerr)
prefix := flag.Arg(1) reader.Close()
p.Save(6*vg.Inch, 4*vg.Inch, prefix+".pdf") }
p.Save(6*vg.Inch, 4*vg.Inch, prefix+".png")
p.Save(6*vg.Inch, 4*vg.Inch, *prefix+".pdf")
p.Save(6*vg.Inch, 4*vg.Inch, *prefix+".png")
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment