From f2987e9173fe0bfa3a9120fb984986a10fbc3e69 Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Tue, 24 Jan 2023 10:52:50 +0100 Subject: [PATCH 1/3] cmd/lhef2hepmc: add -keep-all flag to keep intermediaries Signed-off-by: Sebastien Binet --- cmd/lhef2hepmc/main.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/lhef2hepmc/main.go b/cmd/lhef2hepmc/main.go index 0a1f0e78c..8f38422d4 100644 --- a/cmd/lhef2hepmc/main.go +++ b/cmd/lhef2hepmc/main.go @@ -26,6 +26,16 @@ var ( ifname = flag.String("i", "", "path to LHEF input file (default: STDIN)") ofname = flag.String("o", "", "path to HEPMC output file (default: STDOUT)") + // see https://arxiv.org/pdf/hep-ph/0109068.pdf, page 7: + // integer ISTUP(I) : status code + // –1 Incoming particle + // +1 Outgoing final state particle + // –2 Intermediate space-like propagator defining an x and Q2 which should be preserved + // +2 Intermediate resonance, Mass should be preserved + // +3 Intermediate resonance, for documentation only + // –9 Incoming beam particles at time t = −∞ + keep = flag.Bool("keep-all", false, "keep internediaries (with |ISTUP| != 1)") + // in case IDWTUP == +/-4, one has to keep track of the accumulated // weights and event numbers to evaluate the cross section on-the-fly. // The last evaluation is the one used. @@ -168,7 +178,7 @@ func main() { nmax := 2 imax := int(lhevt.NUP) for i := 0; i < imax; i++ { - if lhevt.ISTUP[i] != 1 { + if !*keep && lhevt.ISTUP[i] != 1 { continue } nmax += 1 @@ -181,7 +191,7 @@ func main() { ), GeneratedMass: lhevt.PUP[i][4], PdgID: lhevt.IDUP[i], - Status: 1, + Status: int(lhevt.ISTUP[i]), Barcode: 3 + i, }) if err != nil { From 5e5fc63688cf470d15327ac5097210be7e99e616 Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Tue, 24 Jan 2023 10:57:32 +0100 Subject: [PATCH 2/3] hepmc: use %w to report errors Signed-off-by: Sebastien Binet --- hepmc/decoder.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hepmc/decoder.go b/hepmc/decoder.go index 679e30540..2d049c5dc 100644 --- a/hepmc/decoder.go +++ b/hepmc/decoder.go @@ -128,13 +128,14 @@ loop: _ = tokens.next() // header 'N' nWeights, err := tokens.int() if err != nil { - return err + return fmt.Errorf("hepmc: could not decode N token: %w", err) } names := make(map[string]int, nWeights) for i := 0; i < nWeights; i++ { - nn, err := strconv.Unquote(tokens.next()) + tok := tokens.next() + nn, err := strconv.Unquote(tok) if err != nil { - return err + return fmt.Errorf("hepmc: could not unquote weight %q: %w", tok, err) } names[nn] = i } From 5b6e04888cca1ed53cd88e0ec700f0261ffb5604 Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Tue, 24 Jan 2023 11:00:49 +0100 Subject: [PATCH 3/3] hepmc/go-hepmc-dump: use errors.Is to properly detect io.EOF Signed-off-by: Sebastien Binet --- hepmc/go-hepmc-dump/main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hepmc/go-hepmc-dump/main.go b/hepmc/go-hepmc-dump/main.go index d0471665a..72df34089 100644 --- a/hepmc/go-hepmc-dump/main.go +++ b/hepmc/go-hepmc-dump/main.go @@ -35,6 +35,7 @@ package main import ( + "errors" "fmt" "io" "log" @@ -72,12 +73,13 @@ func main() { } func dump(w io.Writer, r io.Reader) error { - var err error dec := hepmc.NewDecoder(r) for { - var evt hepmc.Event - err = dec.Decode(&evt) - if err == io.EOF { + var ( + evt hepmc.Event + err = dec.Decode(&evt) + ) + if errors.Is(err, io.EOF) { return nil } if err != nil {