AlbertoPdRF / root-file-viewer

View ROOT files directly in VS Code!
https://marketplace.visualstudio.com/items?itemName=albertopdrf.root-file-viewer
MIT License
47 stars 5 forks source link

Displaying merged (hadd) files bug #5

Closed iokarkan closed 3 years ago

iokarkan commented 3 years ago

Hi!

First off, thanks for this project, it is VERY useful.

I have come across a bug after performing a merging operation in some root files. I was able to re-create the problem with reduced versions of the original files, so you can check them.

The process is the following: I want to merge 3 files: file1.root, file2.root and file3.root, using ROOT's hadd. The files only each have a Tree with a "Var" variable inside, which takes a single value in each file, but that value is different between the 3 files.

After using hadd total.root ./* in a folder that only has these 3 files, I see that in the produced total.root file the "Var" value is that of file1.root and hasn't accommodated the other file2 and file3 values, but the "Entries" have changed and correspond to the sum of the 3 files' "Entries".

ROOT's TBrowser shows the 3 "Var" values separately in the viewer, as intended.

image rootVSCode_bug.zip

AlbertoPdRF commented 3 years ago

Hey @iokarkan, thanks for the issue and the kind words!

I can indeed reproduce the bug, and I can also observe the same behaviour when opening the file on https://root.cern/js/latest/, so I think this could be a bug coming directly from JavaScript ROOT -- @linev could you confirm if that's the case?

linev commented 3 years ago

You can see "Overflow:33329" - these are "lost" values. Seems to be, values of "Var" branch differs in three different files. By default JSROOT uses 1000 first values to define histogram range. If following values do not match - one sees "overflow" or "undeflow" counts.

To get better result, you can try to start "Player" for the TTree object (via context menu Draw/player) and provide following expression "Var;accum:50000". It says that 50000 values should be accumulated before histogram is created. You should get result like this:

https://jsroot.gsi.de/latest/?file=../files/tmp/total.root&item=Tree&opt=Var;accum:50000;player

canvas

AlbertoPdRF commented 3 years ago

Ah, got it! I can get the same result within VS Code:

Fixed `total.root` preview through `Draw/player`

Thanks for yet another very quick reply!

@iokarkan I hope this solves your problem! I'm going to go ahead and close the issue, as it doesn't seem like a bug after all :slightly_smiling_face:

linev commented 3 years ago

Short update One can directly create histogram using TTree::Draw expression syntax:

https://root.cern/js/latest/?file=../files/hsimple.root&item=ntuple&opt=px>>hist(100,-10,10);player

Supported features can be seen here:

https://github.com/root-project/jsroot/blob/master/docs/JSROOT.md#ttree-draw