go-hep.org/x/hep@v0.38.1/groot/rpad/pad.go (about) 1 // Copyright ©2023 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 rpad 6 7 import ( 8 "fmt" 9 "reflect" 10 11 "go-hep.org/x/hep/groot/rbase" 12 "go-hep.org/x/hep/groot/rbytes" 13 "go-hep.org/x/hep/groot/rcont" 14 "go-hep.org/x/hep/groot/root" 15 "go-hep.org/x/hep/groot/rtypes" 16 "go-hep.org/x/hep/groot/rvers" 17 ) 18 19 type Pad struct { 20 vpad rbase.VirtualPad 21 // bbox2d rbase.Object 22 23 fX1 float64 // X of lower X coordinate 24 fY1 float64 // Y of lower Y coordinate 25 fX2 float64 // X of upper X coordinate 26 fY2 float64 // Y of upper Y coordinate 27 fXtoAbsPixelk float64 // Conversion coefficient for X World to absolute pixel 28 fXtoPixelk float64 // Conversion coefficient for X World to pixel 29 fXtoPixel float64 // xpixel = fXtoPixelk + fXtoPixel*xworld 30 fYtoAbsPixelk float64 // Conversion coefficient for Y World to absolute pixel 31 fYtoPixelk float64 // Conversion coefficient for Y World to pixel 32 fYtoPixel float64 // ypixel = fYtoPixelk + fYtoPixel*yworld 33 fUtoAbsPixelk float64 // Conversion coefficient for U NDC to absolute pixel 34 fUtoPixelk float64 // Conversion coefficient for U NDC to pixel 35 fUtoPixel float64 // xpixel = fUtoPixelk + fUtoPixel*undc 36 fVtoAbsPixelk float64 // Conversion coefficient for V NDC to absolute pixel 37 fVtoPixelk float64 // Conversion coefficient for V NDC to pixel 38 fVtoPixel float64 // ypixel = fVtoPixelk + fVtoPixel*vndc 39 fAbsPixeltoXk float64 // Conversion coefficient for absolute pixel to X World 40 fPixeltoXk float64 // Conversion coefficient for pixel to X World 41 fPixeltoX float64 // xworld = fPixeltoXk + fPixeltoX*xpixel 42 fAbsPixeltoYk float64 // Conversion coefficient for absolute pixel to Y World 43 fPixeltoYk float64 // Conversion coefficient for pixel to Y World 44 fPixeltoY float64 // yworld = fPixeltoYk + fPixeltoY*ypixel 45 fXlowNDC float64 // X bottom left corner of pad in NDC [0,1] 46 fYlowNDC float64 // Y bottom left corner of pad in NDC [0,1] 47 fXUpNDC float64 48 fYUpNDC float64 49 fWNDC float64 // Width of pad along X in Normalized Coordinates (NDC) 50 fHNDC float64 // Height of pad along Y in Normalized Coordinates (NDC) 51 fAbsXlowNDC float64 // Absolute X top left corner of pad in NDC [0,1] 52 fAbsYlowNDC float64 // Absolute Y top left corner of pad in NDC [0,1] 53 fAbsWNDC float64 // Absolute Width of pad along X in NDC 54 fAbsHNDC float64 // Absolute Height of pad along Y in NDC 55 fUxmin float64 // Minimum value on the X axis 56 fUymin float64 // Minimum value on the Y axis 57 fUxmax float64 // Maximum value on the X axis 58 fUymax float64 // Maximum value on the Y axis 59 fTheta float64 // theta angle to view as lego/surface 60 fPhi float64 // phi angle to view as lego/surface 61 fAspectRatio float64 // ratio of w/h in case of fixed ratio 62 fNumber int32 // pad number identifier 63 fTickx int32 // Set to 1 if tick marks along X 64 fTicky int32 // Set to 1 if tick marks along Y 65 fLogx int32 // (=0 if X linear scale, =1 if log scale) 66 fLogy int32 // (=0 if Y linear scale, =1 if log scale) 67 fLogz int32 // (=0 if Z linear scale, =1 if log scale) 68 fPadPaint int32 // Set to 1 while painting the pad 69 fCrosshair int32 // Crosshair type (0 if no crosshair requested) 70 fCrosshairPos int32 // Position of crosshair 71 fBorderSize int16 // pad bordersize in pixels 72 fBorderMode int16 // Bordermode (-1=down, 0 = no border, 1=up) 73 fModified bool // Set to true when pad is modified 74 fGridx bool // Set to true if grid along X 75 fGridy bool // Set to true if grid along Y 76 fAbsCoord bool // Use absolute coordinates 77 fEditable bool // True if canvas is editable 78 fFixedAspectRatio bool // True if fixed aspect ratio 79 fPrimitives *rcont.List // ->List of primitives (subpads) 80 fExecs *rcont.List // List of commands to be executed when a pad event occurs 81 fName string // Pad name 82 fTitle string // Pad title 83 fNumPaletteColor int32 // Number of objects with an automatic color 84 fNextPaletteColor int32 // Next automatic color 85 } 86 87 func (*Pad) RVersion() int16 { 88 return rvers.Pad 89 } 90 91 func (*Pad) Class() string { 92 return "TPad" 93 } 94 95 func (p *Pad) Name() string { 96 return p.fName 97 } 98 99 func (p *Pad) Title() string { 100 return p.fTitle 101 } 102 103 // ROOTUnmarshaler is the interface implemented by an object that can 104 // unmarshal itself from a ROOT buffer 105 func (p *Pad) UnmarshalROOT(r *rbytes.RBuffer) error { 106 if r.Err() != nil { 107 return r.Err() 108 } 109 110 hdr := r.ReadHeader(p.Class(), p.RVersion()) 111 112 if hdr.Vers != 13 { 113 panic(fmt.Errorf( 114 "rpad: invalid %s version=%d > %d", 115 p.Class(), hdr.Vers, p.RVersion(), 116 )) 117 } 118 119 r.ReadObject(&p.vpad) 120 121 _ = r.ReadHeader("TAttBBox2D", rvers.AttBBox2D) 122 123 p.fX1 = r.ReadF64() 124 p.fY1 = r.ReadF64() 125 p.fX2 = r.ReadF64() 126 p.fY2 = r.ReadF64() 127 p.fXtoAbsPixelk = r.ReadF64() 128 p.fXtoPixelk = r.ReadF64() 129 p.fXtoPixel = r.ReadF64() 130 p.fYtoAbsPixelk = r.ReadF64() 131 p.fYtoPixelk = r.ReadF64() 132 p.fYtoPixel = r.ReadF64() 133 p.fUtoAbsPixelk = r.ReadF64() 134 p.fUtoPixelk = r.ReadF64() 135 p.fUtoPixel = r.ReadF64() 136 p.fVtoAbsPixelk = r.ReadF64() 137 p.fVtoPixelk = r.ReadF64() 138 p.fVtoPixel = r.ReadF64() 139 p.fAbsPixeltoXk = r.ReadF64() 140 p.fPixeltoXk = r.ReadF64() 141 p.fPixeltoX = r.ReadF64() 142 p.fAbsPixeltoYk = r.ReadF64() 143 p.fPixeltoYk = r.ReadF64() 144 p.fPixeltoY = r.ReadF64() 145 p.fXlowNDC = r.ReadF64() 146 p.fYlowNDC = r.ReadF64() 147 p.fXUpNDC = r.ReadF64() 148 p.fYUpNDC = r.ReadF64() 149 p.fWNDC = r.ReadF64() 150 p.fHNDC = r.ReadF64() 151 p.fAbsXlowNDC = r.ReadF64() 152 p.fAbsYlowNDC = r.ReadF64() 153 p.fAbsWNDC = r.ReadF64() 154 p.fAbsHNDC = r.ReadF64() 155 p.fUxmin = r.ReadF64() 156 p.fUymin = r.ReadF64() 157 p.fUxmax = r.ReadF64() 158 p.fUymax = r.ReadF64() 159 p.fTheta = r.ReadF64() 160 p.fPhi = r.ReadF64() 161 p.fAspectRatio = r.ReadF64() 162 p.fNumber = r.ReadI32() 163 p.fTickx = r.ReadI32() 164 p.fTicky = r.ReadI32() 165 p.fLogx = r.ReadI32() 166 p.fLogy = r.ReadI32() 167 p.fLogz = r.ReadI32() 168 p.fPadPaint = r.ReadI32() 169 p.fCrosshair = r.ReadI32() 170 p.fCrosshairPos = r.ReadI32() 171 p.fBorderSize = r.ReadI16() 172 p.fBorderMode = r.ReadI16() 173 p.fModified = r.ReadBool() 174 p.fGridx = r.ReadBool() 175 p.fGridy = r.ReadBool() 176 p.fAbsCoord = r.ReadBool() 177 p.fEditable = r.ReadBool() 178 p.fFixedAspectRatio = r.ReadBool() 179 180 { 181 var prims rcont.List 182 r.ReadObject(&prims) 183 if prims.Len() > 0 { 184 p.fPrimitives = &prims 185 } 186 } 187 188 { 189 execs := r.ReadObjectAny() 190 if execs != nil { 191 p.fExecs = execs.(*rcont.List) 192 } 193 } 194 195 p.fName = r.ReadString() 196 p.fTitle = r.ReadString() 197 198 p.fNumPaletteColor = r.ReadI32() 199 p.fNextPaletteColor = r.ReadI32() 200 201 r.CheckHeader(hdr) 202 return r.Err() 203 } 204 205 // Keys implements the ObjectFinder interface. 206 func (pad *Pad) Keys() []string { 207 var keys []string 208 if pad.fPrimitives != nil && pad.fPrimitives.Len() > 0 { 209 for i := range pad.fPrimitives.Len() { 210 o, ok := pad.fPrimitives.At(i).(root.Named) 211 if !ok { 212 continue 213 } 214 keys = append(keys, o.Name()) 215 } 216 } 217 return keys 218 } 219 220 // Get implements the ObjectFinder interface. 221 func (pad *Pad) Get(name string) (root.Object, error) { 222 for i := range pad.fPrimitives.Len() { 223 v := pad.fPrimitives.At(i) 224 o, ok := v.(root.Named) 225 if !ok { 226 continue 227 } 228 if o.Name() == name { 229 return v, nil 230 } 231 } 232 233 return nil, fmt.Errorf("no object named %q", name) 234 } 235 236 func init() { 237 f := func() reflect.Value { 238 var p Pad 239 return reflect.ValueOf(&p) 240 } 241 rtypes.Factory.Add("TPad", f) 242 } 243 244 var ( 245 _ root.Object = (*Pad)(nil) 246 _ root.Named = (*Pad)(nil) 247 _ root.ObjectFinder = (*Pad)(nil) 248 _ rbytes.Unmarshaler = (*Pad)(nil) 249 )