main.go 1.25 KB
Newer Older
David Blyth's avatar
David Blyth committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
package main

import (
	"flag"
	"fmt"
	"log"
	"math"
	"os"

	"github.com/decibelcooper/eicplot"
	"github.com/decibelcooper/proio/go-proio"
	"github.com/decibelcooper/proio/go-proio/model/eic"
	"go-hep.org/x/hep/hbook"
	"go-hep.org/x/hep/hplot"
	"gonum.org/v1/plot"
	"gonum.org/v1/plot/vg"
)

func printUsage() {
	fmt.Fprintf(os.Stderr, `Usage: `+os.Args[0]+` [options] <proio-input-file>

options:
`,
	)
	flag.PrintDefaults()
}

var (
	output = flag.String("output", "out.png", "output file")
)

func main() {
	flag.Usage = printUsage
	flag.Parse()
	if flag.NArg() != 1 {
		printUsage()
		log.Fatal("Invalid arguments")
	}

	reader, err := proio.Open(flag.Arg(0))
	if err != nil {
		log.Fatal(err)
	}
	defer reader.Close()

	p, _ := plot.New()
	p.X.Label.Text = "log_10{E dep. (MeV)}"
	p.X.Tick.Marker = eicplot.PreciseTicks{5}
	p.Y.Tick.Marker = eicplot.LogTicks{}
	p.Y.Scale = eicplot.LogScale{}

	hist := hbook.NewH1D(100, -9, 2)

	for event := range reader.ScanEvents() {
		trackerIDs := event.TaggedEntries("Tracker")
		for _, id := range trackerIDs {
			eDep, ok := event.GetEntry(id).(*eic.EnergyDep)
			if !ok {
				continue
			}

			hist.Fill(math.Log10(float64(eDep.Mean*1000)), 1)
		}
	}

	hPlot := hplot.NewH1D(hist)
	p.Add(hPlot)

	p.Save(6*vg.Inch, 4*vg.Inch, *output)
}