# Root2yoda error

**URL:** <https://root-forum.cern.ch/t/root2yoda-error/47283>\
**Category:** Newbie\
**Created:** [October 18, 2021, 7:04am UTC](https://root-forum.cern.ch/t/root2yoda-error/47283 "2021-10-18T07:04:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumankkundu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@Sumankkundu](https://root-forum.cern.ch/u/Sumankkundu)\
**Post date:** [October 18, 2021, 7:04am UTC](https://root-forum.cern.ch/t/root2yoda-error/47283/1 "2021-10-18T07:04:02Z")

</div>

Dear expert,  
I am trying to convert few root histograms in a root file to yoda scatter 2D hist format using **root2yoda** script.  
But I get the following error :  
_**Traceback (most recent call last):**_  
\*\*\* File “./root2yoda”, line 46, in \*\*\*  
\*\*\* analysisobjects = [to\_yoda(path, ro) for (path, ro) in rootobjects]\*\*\*  
\*\*\* File “./root2yoda”, line 43, in to\_yoda\*\*\*  
\*\*\* ao.path = path\*\*\*  
_ **AttributeError: ‘yoda.core.Scatter2D’ object attribute ‘path’ is read-only** _

I have tried both root V6.16 and V6.22 and end up with same error

I am attaching the root file which I want to convert.  
[Data\_Unfolded\_Run2.root](https://root-forum.cern.ch/uploads/short-url/6SdggGfTWWl10kFyrGR56czHO4S.root) (68.2 KB)

Please suggest any solution. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![sbinet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sbinet/32/13166_2.png) [@sbinet](https://root-forum.cern.ch/u/sbinet)\
**Post date:** [October 18, 2021, 8:01am UTC](https://root-forum.cern.ch/t/root2yoda-error/47283/2 "2021-10-18T08:01:53Z")

</div>

it seems you are using the **python** version of the `root2yoda` script, shipped with the [yoda](https://yoda.hepforge.org/) project.

the `root2yoda` program shipped with the [go-hep.org](https://go-hep.org) project doesn’t seem to have issues with the file you’ve attached:

```auto
$> curl -O -L https://go-hep.org/dist/latest/root2yoda-linux_amd64.exe
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 18.4M 100 18.4M 0 0 20.8M 0 --:--:-- --:--:-- --:--:-- 20.8M

$> chmod +x ./root2yoda-linux_amd64.exe 
$> ./root2yoda-linux_amd64.exe -o o.yoda.gz ./Data_Unfolded_Run2.root 
root2yoda: processing ./Data_Unfolded_Run2.root

$> ll
total 19M
-rw-r--r-- 1 binet binet 69K Oct 18 09:54 Data_Unfolded_Run2.root
-rw-r--r-- 1 binet binet 21K Oct 18 09:59 o.yoda.gz
-rwxr-xr-x 1 binet binet 19M Oct 18 09:58 root2yoda-linux_amd64.exe

$> file o.yoda.gz 
o.yoda.gz: gzip compressed data, original size modulo 2^32 123104

$> ./root2yoda-linux_amd64.exe ./Data_Unfolded_Run2.root > o.yoda
root2yoda: processing ./Data_Unfolded_Run2.root

$> ll
total 19M
-rw-r--r-- 1 binet binet 69K Oct 18 09:54 Data_Unfolded_Run2.root
-rw-r--r-- 1 binet binet 121K Oct 18 09:59 o.yoda
-rw-r--r-- 1 binet binet 21K Oct 18 09:59 o.yoda.gz
-rwxr-xr-x 1 binet binet 19M Oct 18 09:58 root2yoda-linux_amd64.exe

$> head o.yoda
BEGIN YODA_HISTO1D_V2 /Edd_TUnfold_NoReg_typ_1_eta0_24_pt4
Path: /Edd_TUnfold_NoReg_typ_1_eta0_24_pt4
Title: 'HT2 Unfolded No Reg Charged Particles 2.4 #rho^{T}_{Tot} pt4'
Type: Histo1D
---
# Mean: -3.702428e+00
# Area: 1.581013e+08
# ID ID sumw sumw2 sumwx sumwx2 numEntries
Total Total 1.581013e+08	6.598662e+10	-5.853587e+08	2.401912e+09	3.788040e+05
Underflow	Underflow	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00

```

hth,  
-s

---

<div class="post-metadata">

**Author:** ![Sumankkundu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@Sumankkundu](https://root-forum.cern.ch/u/Sumankkundu)\
**Post date:** [October 18, 2021, 8:56am UTC](https://root-forum.cern.ch/t/root2yoda-error/47283/3 "2021-10-18T08:56:00Z")

</div>

Thank you, so much for prompt reply.  
But one issue still there, The type of the yoda file format is “Type: Histo1D”. But in Rivet, we need “Type=Scatter2D”.  
Can it possible to get “Type=Scatter2D” format with this script?

---

<div class="post-metadata">

**Author:** ![sbinet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sbinet/32/13166_2.png) [@sbinet](https://root-forum.cern.ch/u/sbinet)\
**Post date:** [October 18, 2021, 9:08am UTC](https://root-forum.cern.ch/t/root2yoda-error/47283/4 "2021-10-18T09:08:18Z")

</div>

it’s relatively easy with [Go-HEP](https://go-hep.org) to convert a `H1` histogram into a 2D scatter points:

- [hbook.NewS2DFromH1D](https://pkg.go.dev/go-hep.org/x/hep/hbook#NewS2DFromH1D)

but one would need to actually write the code that loops over your file (be it the YODA file or the ROOT one), convert each `H1` into its scatter point equivalent, and save it (into the YODA or ROOT format).  
I suppose one could do the same in ROOT (`TH1D` to `TGraph{,Errors}`) and run _a_ `root2yoda` script on it.

as this is a rather specific task, I don’t think there is an off-the-shelf script or binary that does that.

you’ll have to write code 🙂

---

<div class="post-metadata">

**Author:** ![sbinet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sbinet/32/13166_2.png) [@sbinet](https://root-forum.cern.ch/u/sbinet)\
**Post date:** [October 18, 2021, 9:25am UTC](https://root-forum.cern.ch/t/root2yoda-error/47283/5 "2021-10-18T09:25:18Z")

</div>

FYI, here is what it would look like with [Go-HEP](https://go-hep.org):

```auto
package main

import (
	"flag"
	"log"
	"os"

	"go-hep.org/x/hep/groot"
	"go-hep.org/x/hep/groot/rhist"
	"go-hep.org/x/hep/hbook"
	"go-hep.org/x/hep/hbook/rootcnv"
	"go-hep.org/x/hep/hbook/yodacnv"
)

func main() {
	flag.Parse()

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

	w, err := os.Create("o.yoda")
	if err != nil {
		log.Fatalf("could not create output YODA file: %+v", err)
	}
	defer w.Close()

	for _, k := range f.Keys() {
		o, err := f.Get(k.Name())
		if err != nil {
			log.Fatal(err)
		}
		th1, ok := o.(rhist.H1)
		if !ok {
			log.Printf("discarding %q...", k)
			continue
		}

		h1 := rootcnv.H1D(th1)
		s2 := hbook.NewS2DFromH1D(h1)
		err = yodacnv.Write(w, s2)
		if err != nil {
			log.Fatalf("could not write %q: %+v", k.Name(), err)
		}
	}

	err = w.Close()
	if err != nil {
		log.Fatalf("could not close output YODA file: %+v", err)
	}
}

```

ex:

```auto
#> go build -o cnv ./main.go
#> ./cnv ./Data_Unfolded_Run2.root
#> head o.yoda
BEGIN YODA_SCATTER2D_V2 /Edd_TUnfold_NoReg_typ_0_eta0_3_pt0
Path: /Edd_TUnfold_NoReg_typ_0_eta0_3_pt0
Title: 'HT2 Unfolded No Reg Jets 2.4 #tau_{_{#perp}} pt0'
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+	
-6.410000e+00	3.000000e-01	3.000000e-01	6.368566e+09	8.675885e+07	8.675885e+07
-5.835000e+00	2.750000e-01	2.750000e-01	8.022018e+09	9.263745e+07	9.263745e+07
-5.305000e+00	2.550000e-01	2.550000e-01	8.259488e+09	8.544773e+07	8.544773e+07
-4.805000e+00	2.450000e-01	2.450000e-01	8.548090e+09	7.729565e+07	7.729565e+07

```

---

<div class="post-metadata">

**Author:** ![Sumankkundu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@Sumankkundu](https://root-forum.cern.ch/u/Sumankkundu)\
**Post date:** [October 18, 2021, 1:15pm UTC](https://root-forum.cern.ch/t/root2yoda-error/47283/6 "2021-10-18T13:15:13Z")

</div>

Thanks, get It.
