go-hep.org/x/hep@v0.38.1/lcio/trackerhitzcylinder.go (about)

     1  // Copyright ©2017 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package lcio
     6  
     7  import (
     8  	"fmt"
     9  	"strings"
    10  
    11  	"go-hep.org/x/hep/sio"
    12  )
    13  
    14  // TrackerHitZCylinderContainer is a collection of tracker hit z-cylinders.
    15  type TrackerHitZCylinderContainer struct {
    16  	Flags  Flags
    17  	Params Params
    18  	Hits   []TrackerHitZCylinder
    19  }
    20  
    21  type TrackerHitZCylinder struct {
    22  	CellID0 int32
    23  	CellID1 int32
    24  	Type    int32 // type of Track; encoded in parameters TrackerHitTypeName+TrackerHit TypeValue
    25  	Pos     [3]float64
    26  	Center  [2]float32
    27  	DRPhi   float32 // measurement error along RPhi
    28  	DZ      float32 // measurement error along z
    29  	EDep    float32 // energy deposit on the hit
    30  	EDepErr float32 // error measured on EDep
    31  	Time    float32
    32  	Quality int32 // quality flag word
    33  	RawHits []Hit
    34  }
    35  
    36  func (hit *TrackerHitZCylinder) GetCellID0() int32 { return hit.CellID0 }
    37  func (hit *TrackerHitZCylinder) GetCellID1() int32 { return hit.CellID1 }
    38  
    39  func (hits TrackerHitZCylinderContainer) String() string {
    40  	o := new(strings.Builder)
    41  	fmt.Fprintf(o, "%[1]s print out of TrackerHitZCylinder collection %[1]s\n\n", strings.Repeat("-", 15))
    42  	fmt.Fprintf(o, "  flag:  0x%x\n%v", hits.Flags, hits.Params)
    43  	fmt.Fprintf(o, "     LCIO::THBIT_BARREL   : %v\n", hits.Flags.Test(BitsThBarrel))
    44  
    45  	// FIXME(sbinet): quality-bits
    46  
    47  	fmt.Fprintf(o, "\n")
    48  
    49  	dec := NewCellIDDecoderFrom(hits.Params)
    50  	const (
    51  		head = " [   id   ] |cellId0 |cellId1 | position (x,y,z)            | time    |[type]|[qual]| EDep    |EDepError|  dRPhi  |    dZ   |    center (x,y)   |\n"
    52  		tail = "------------|--------|--------|-----------------------------|---------|------|------|---------|---------|---------|---------|-------------------|\n"
    53  	)
    54  	o.WriteString(head)
    55  	o.WriteString(tail)
    56  	for i := range hits.Hits {
    57  		hit := &hits.Hits[i]
    58  		fmt.Fprintf(o,
    59  			"[%09d] |%08d|%08d|%+.2e,%+.2e,%+.2e|%+.2e|[%04d]|[%04d]|%+.2e|%+.2e|%+.2e|%+.2e|%+.2e,%+.2e|\n",
    60  			ID(hit),
    61  			hit.CellID0, hit.CellID1,
    62  			hit.Pos[0], hit.Pos[1], hit.Pos[2],
    63  			hit.Time, hit.Type, hit.Quality,
    64  			hit.EDep, hit.EDepErr,
    65  			hit.DRPhi, hit.DZ,
    66  			hit.Center[0], hit.Center[1],
    67  		)
    68  		if dec != nil {
    69  			fmt.Fprintf(o, "        id-fields: (%s)\n", dec.ValueString(hit))
    70  		}
    71  	}
    72  	o.WriteString(tail)
    73  	return o.String()
    74  }
    75  
    76  func (*TrackerHitZCylinderContainer) VersionSio() uint32 {
    77  	return Version
    78  }
    79  
    80  func (hits *TrackerHitZCylinderContainer) MarshalSio(w sio.Writer) error {
    81  	enc := sio.NewEncoder(w)
    82  	enc.Encode(&hits.Flags)
    83  	enc.Encode(&hits.Params)
    84  	enc.Encode(int32(len(hits.Hits)))
    85  	for i := range hits.Hits {
    86  		hit := &hits.Hits[i]
    87  		enc.Encode(&hit.CellID0)
    88  		if hits.Flags.Test(BitsThID1) {
    89  			enc.Encode(&hit.CellID1)
    90  		}
    91  		enc.Encode(&hit.Type)
    92  		enc.Encode(&hit.Pos)
    93  		enc.Encode(&hit.Center)
    94  		enc.Encode(&hit.DRPhi)
    95  		enc.Encode(&hit.DZ)
    96  		enc.Encode(&hit.EDep)
    97  		enc.Encode(&hit.EDepErr)
    98  		enc.Encode(&hit.Time)
    99  		enc.Encode(&hit.Quality)
   100  
   101  		enc.Encode(int32(len(hit.RawHits)))
   102  		for ii := range hit.RawHits {
   103  			enc.Pointer(&hit.RawHits[ii])
   104  		}
   105  		enc.Tag(hit)
   106  	}
   107  	return enc.Err()
   108  }
   109  
   110  func (hits *TrackerHitZCylinderContainer) UnmarshalSio(r sio.Reader) error {
   111  	dec := sio.NewDecoder(r)
   112  	dec.Decode(&hits.Flags)
   113  	dec.Decode(&hits.Params)
   114  	var n int32
   115  	dec.Decode(&n)
   116  	hits.Hits = make([]TrackerHitZCylinder, int(n))
   117  	for i := range hits.Hits {
   118  		hit := &hits.Hits[i]
   119  		if r.VersionSio() > 1051 {
   120  			dec.Decode(&hit.CellID0)
   121  			if hits.Flags.Test(BitsThID1) {
   122  				dec.Decode(&hit.CellID1)
   123  			}
   124  		}
   125  		if r.VersionSio() > 1002 {
   126  			dec.Decode(&hit.Type)
   127  		}
   128  		dec.Decode(&hit.Pos)
   129  		dec.Decode(&hit.Center)
   130  		dec.Decode(&hit.DRPhi)
   131  		dec.Decode(&hit.DZ)
   132  		dec.Decode(&hit.EDep)
   133  		dec.Decode(&hit.EDepErr)
   134  		dec.Decode(&hit.Time)
   135  		if r.VersionSio() > 1011 {
   136  			dec.Decode(&hit.Quality)
   137  		}
   138  
   139  		var n int32 = 1
   140  		if r.VersionSio() > 1002 {
   141  			dec.Decode(&n)
   142  		}
   143  		hit.RawHits = make([]Hit, int(n))
   144  		for ii := range hit.RawHits {
   145  			dec.Pointer(&hit.RawHits[ii])
   146  		}
   147  		dec.Tag(hit)
   148  	}
   149  
   150  	return dec.Err()
   151  }
   152  
   153  var (
   154  	_ sio.Versioner = (*TrackerHitZCylinderContainer)(nil)
   155  	_ sio.Codec     = (*TrackerHitZCylinderContainer)(nil)
   156  	_ Hit           = (*TrackerHitZCylinder)(nil)
   157  )