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 (
"gonum.org/v1/plot"
)
type PreciseTicks struct{}
type PreciseTicks struct {
NSuggestedTicks int
}
func (PreciseTicks) Ticks(min, max float64) []plot.Tick {
const suggestedTicks = 4
func (t PreciseTicks) Ticks(min, max float64) []plot.Tick {
if t.NSuggestedTicks == 0 {
t.NSuggestedTicks = 4
}
if max <= min {
panic("illegal range")
......@@ -18,12 +22,12 @@ func (PreciseTicks) Ticks(min, max float64) []plot.Tick {
tens := math.Pow10(int(math.Floor(math.Log10(max - min))))
n := (max - min) / tens
for n < suggestedTicks-1 {
for n < float64(t.NSuggestedTicks)-1 {
tens /= 10
n = (max - min) / tens
}
majorMult := int(n / (suggestedTicks - 1))
majorMult := int(n / float64(t.NSuggestedTicks-1))
switch majorMult {
case 7:
majorMult = 6
......
......@@ -3,10 +3,10 @@ package main
import (
"flag"
"fmt"
"image/color"
"log"
"math"
"os"
//"strconv"
"github.com/decibelcooper/proio/go-proio"
"github.com/decibelcooper/proio/go-proio/model/eic"
......@@ -25,10 +25,12 @@ var (
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")
nBins = flag.Int("nbins", 80, "number of bins")
title = flag.String("title", "", "plot title")
prefix = flag.String("prefix", "out", "output file prefix")
)
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:
`,
......@@ -39,19 +41,25 @@ options:
func main() {
flag.Usage = printUsage
flag.Parse()
if flag.NArg() != 2 {
if flag.NArg() < 1 {
printUsage()
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)
trueEtaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit)
reader, err := proio.Open(flag.Arg(0))
reader, err := proio.Open(filename)
if err != nil {
log.Fatal(err)
}
defer reader.Close()
eventNum := 0
for event := range reader.ScanEvents() {
......@@ -160,18 +168,25 @@ func main() {
}
}
errPoints := plotutil.ErrorPoints{points, xErrors, yErrors}
scatter, _ := plotter.NewScatter(errPoints)
xerr, _ := plotter.NewXErrorBars(errPoints)
yerr, _ := plotter.NewYErrorBars(errPoints)
p, _ := plot.New()
p.Title.Text = "Tracking efficiency"
p.X.Label.Text = "eta"
p.X.Tick.Marker = eicplot.PreciseTicks{}
p.Y.Tick.Marker = eicplot.PreciseTicks{}
p.Add(scatter)
pointColor := color.RGBA{A: 255}
switch i {
case 1:
pointColor = color.RGBA{G: 255, A: 255}
case 2:
pointColor = color.RGBA{B: 255, A: 255}
}
xerr.LineStyle.Color = pointColor
yerr.LineStyle.Color = pointColor
p.Add(xerr)
p.Add(yerr)
prefix := flag.Arg(1)
p.Save(6*vg.Inch, 4*vg.Inch, prefix+".pdf")
p.Save(6*vg.Inch, 4*vg.Inch, prefix+".png")
reader.Close()
}
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