TTreeReader Plotting Different Variable

Hi Everyone,

I’ve been running into an interesting issue with TTreeReader. I am currently using v6.12/06.
I’m using TTreeReaderArray<Float_t> to read through a leaf consisting of 2-element arrays holding Mass. I then input the first element of each array into a histogram. When I plot this histogram, I instead see the plot corresponding to the first element of the 2-element array corresponding to the X position.
When I use the interpreter to plot the Mass, everything is working fine.

Does anybody know what could be the issue? If you need more information, please let me know.

Thanks!

Hi,
given what you said my guess would be that there is something fishy in your code (if TTreeReaderArray routinely picked up the wrong values people would have noticed).

Could you try to come up with a minimal self-contained piece of code that reproduces the issue and share it here? (then if you could also share the data, even just a couple of entries, it would make it much easier to debug).

Cheers,
Enrico

Hi, sorry for the late response. Below is the code I have to read and display the root file. I’ve attached the root file, shortened down to just 10 events, each holding a 2D array for Mass (TTwoTrackChunk.data_.M) and the X variable. Below I’m attempting to plot both elements of the mass array, to compare it easily with the TBrowser plots. For me, the plot that the code displays is the same as the plot for the X variable in the TBrowser, as opposed to mass.

Thank you for the help!

void Mass_broken() {

    TH1F* mass = new TH1F("h", "Mass Distribution Old;Mass (GeV/c);Count", 100, -660, 660);

    TFile *data_file = TFile::Open("data.root");

    TTreeReader Reader("Experiment", data_file);

    TTreeReaderArray<Float_t> mass_array(Reader, "TTwoTrackChunk.data_.M");

    while(Reader.Next()) {
        mass->Fill(mass_array[0]);
        mass->Fill(mass_array[1]);
    }

    mass->Draw();
}

data.root (10.9 KB)

Hi,
do you also get the following warnings?

Warning in <TClass::Init>: no dictionary for class Data is available
Warning in <TClass::Init>: no dictionary for class FortranData<TTwoTrackChunk> is available
Warning in <TClass::Init>: no dictionary for class TTwoTrackChunk is available

EDIT:
I am not 100% sure they have anything to do with the wrongly read data, but I see that TBrowser reads one thing (M has range 0 -> 350) and TTreeReaderArray reads another (entries with values from -116 to 426, with same distribution as X). This is weird but it might be caused by the missing dictionaries.

@Axel or @Danilo might know better

1 Like

Yes, I do get those warnings. Is that something I could fix, or would it rely on who made the root file?
What you wrote in your edit is exactly the problem I’m having (but with a lower entry of ~ -300).
Thanks

Hi,

the issue is indeed the absence of a dictionary. So, you need a dictionary for the classes which were persistified in your dataset. In other words, you can:

  1. Take the code which was used to create the file and load the appropriate libraries (whoever wrote out the classes, had the dictionaries available :slight_smile: )
  2. Emulate those classes via the MakeProject utility. ROOT can rebuild the classes which were used to write data in ROOT files (they are self-descriptive). Unfortunately, you’ll be able to access the methods of the classes, not persistifiable, but only the data members: here the instructions.

Cheers,
D

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.