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,139 +41,152 @@ options: ...@@ -39,139 +41,152 @@ 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")
} }
etaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit) p, _ := plot.New()
trueEtaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit) 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}
reader, err := proio.Open(flag.Arg(0)) for i, filename := range flag.Args() {
if err != nil { etaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit)
log.Fatal(err) trueEtaHist := hbook.NewH1D(*nBins, -*etaLimit, *etaLimit)
}
defer reader.Close() reader, err := proio.Open(filename)
if err != nil {
eventNum := 0 log.Fatal(err)
for event := range reader.ScanEvents() { }
ids := event.TaggedEntries("Reconstructed")
for _, id := range ids {
track, ok := event.GetEntry(id).(*eic.Track)
if !ok {
continue
}
partCandID := make(map[uint64]uint64) eventNum := 0
for _, obsID := range track.Observation { for event := range reader.ScanEvents() {
eDep, ok := event.GetEntry(obsID).(*eic.EnergyDep) ids := event.TaggedEntries("Reconstructed")
for _, id := range ids {
track, ok := event.GetEntry(id).(*eic.Track)
if !ok { if !ok {
continue continue
} }
for _, sourceID := range eDep.Source { partCandID := make(map[uint64]uint64)
simHit, ok := event.GetEntry(sourceID).(*eic.SimHit) for _, obsID := range track.Observation {
eDep, ok := event.GetEntry(obsID).(*eic.EnergyDep)
if !ok { if !ok {
continue continue
} }
partCandID[simHit.Particle]++ for _, sourceID := range eDep.Source {
simHit, ok := event.GetEntry(sourceID).(*eic.SimHit)
if !ok {
continue
}
partCandID[simHit.Particle]++
}
} }
}
partID := uint64(0) partID := uint64(0)
hitCount := uint64(0) hitCount := uint64(0)
for id, count := range partCandID { for id, count := range partCandID {
if count > hitCount { if count > hitCount {
partID = id partID = id
hitCount = count hitCount = count
}
} }
}
part, ok := event.GetEntry(partID).(*eic.Particle) part, ok := event.GetEntry(partID).(*eic.Particle)
if !ok { if !ok {
continue continue
} }
if len(track.Segment) == 0 { if len(track.Segment) == 0 {
continue continue
} }
pMag := math.Sqrt(math.Pow(part.P.X, 2) + math.Pow(part.P.Y, 2) + math.Pow(part.P.Z, 2)) pMag := math.Sqrt(math.Pow(part.P.X, 2) + math.Pow(part.P.Y, 2) + math.Pow(part.P.Z, 2))
eta := math.Atanh(part.P.Z / pMag) eta := math.Atanh(part.P.Z / pMag)
pT := math.Sqrt(math.Pow(part.P.X, 2) + math.Pow(part.P.Y, 2)) pT := math.Sqrt(math.Pow(part.P.X, 2) + math.Pow(part.P.Y, 2))
chargeMag := math.Abs(float64(part.Charge)) chargeMag := math.Abs(float64(part.Charge))
poqMag := pMag / chargeMag poqMag := pMag / chargeMag
diffMag := math.Sqrt(math.Pow(track.Segment[0].Poq.X-part.P.X/chargeMag, 2) + diffMag := math.Sqrt(math.Pow(track.Segment[0].Poq.X-part.P.X/chargeMag, 2) +
math.Pow(track.Segment[0].Poq.Y-part.P.Y/chargeMag, 2) + math.Pow(track.Segment[0].Poq.Y-part.P.Y/chargeMag, 2) +
math.Pow(track.Segment[0].Poq.Z-part.P.Z/chargeMag, 2)) math.Pow(track.Segment[0].Poq.Z-part.P.Z/chargeMag, 2))
fracDiff := diffMag / poqMag fracDiff := diffMag / poqMag
// cuts // cuts
if pT < *pTMin { if pT < *pTMin {
continue continue
} }
if fracDiff > *fracCut { if fracDiff > *fracCut {
continue continue
}
etaHist.Fill(eta, 1)
} }
etaHist.Fill(eta, 1) ids = event.TaggedEntries("GenStable")
} for _, id := range ids {
part, ok := event.GetEntry(id).(*eic.Particle)
if !ok {
continue
}
ids = event.TaggedEntries("GenStable") pMag := math.Sqrt(math.Pow(part.P.X, 2) + math.Pow(part.P.Y, 2) + math.Pow(part.P.Z, 2))
for _, id := range ids { eta := math.Atanh(part.P.Z / pMag)
part, ok := event.GetEntry(id).(*eic.Particle) pT := math.Sqrt(math.Pow(part.P.X, 2) + math.Pow(part.P.Y, 2))
if !ok {
continue
}
pMag := math.Sqrt(math.Pow(part.P.X, 2) + math.Pow(part.P.Y, 2) + math.Pow(part.P.Z, 2)) // cuts
eta := math.Atanh(part.P.Z / pMag) if pT < *pTMin {
pT := math.Sqrt(math.Pow(part.P.X, 2) + math.Pow(part.P.Y, 2)) continue
}
// cuts trueEtaHist.Fill(eta, 1)
if pT < *pTMin {
continue
} }
trueEtaHist.Fill(eta, 1) eventNum++
} }
eventNum++ points := make(plotter.XYs, *nBins)
} xErrors := make(plotter.XErrors, *nBins)
yErrors := make(plotter.YErrors, *nBins)
points := make(plotter.XYs, *nBins) binHalfWidth := *etaLimit / float64(*nBins)
xErrors := make(plotter.XErrors, *nBins) binSigma := binHalfWidth / math.Sqrt(3.)
yErrors := make(plotter.YErrors, *nBins) for i := range points {
binHalfWidth := *etaLimit / float64(*nBins) trueX, trueY := trueEtaHist.XY(i)
binSigma := binHalfWidth / math.Sqrt(3.)
for i := range points { points[i].X = trueX + binHalfWidth
trueX, trueY := trueEtaHist.XY(i) xErrors[i].Low = binSigma
xErrors[i].High = binSigma
points[i].X = trueX + binHalfWidth
xErrors[i].Low = binSigma _, trackY := etaHist.XY(i)
xErrors[i].High = binSigma if trueY > 0 {
points[i].Y = trackY / trueY
_, trackY := etaHist.XY(i) yErrors[i].Low = math.Sqrt((1 - trackY/trueY) * trackY / math.Pow(trueY, 2))
if trueY > 0 { yErrors[i].High = yErrors[i].Low
points[i].Y = trackY / trueY }
yErrors[i].Low = math.Sqrt((1 - trackY/trueY) * trackY / math.Pow(trueY, 2)) }
yErrors[i].High = yErrors[i].Low errPoints := plotutil.ErrorPoints{points, xErrors, yErrors}
xerr, _ := plotter.NewXErrorBars(errPoints)
yerr, _ := plotter.NewYErrorBars(errPoints)
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)
reader.Close()
} }
errPoints := plotutil.ErrorPoints{points, xErrors, yErrors}
scatter, _ := plotter.NewScatter(errPoints)
yerr, _ := plotter.NewYErrorBars(errPoints)
p, _ := plot.New() p.Save(6*vg.Inch, 4*vg.Inch, *prefix+".pdf")
p.Title.Text = "Tracking efficiency" p.Save(6*vg.Inch, 4*vg.Inch, *prefix+".png")
p.X.Label.Text = "eta"
p.X.Tick.Marker = eicplot.PreciseTicks{}
p.Y.Tick.Marker = eicplot.PreciseTicks{}
p.Add(scatter)
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")
} }
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