Filling TTree but setting Event ID manually?


I am working on creating root files from binary data files and there was a change of our readout mode. Before our data files were ordered by event number making it easy to fill the TTree after each event. Now the ordering is different (I am reading out several TDCs and first TDC0 sends all of its events, then TDC1 sends all of its events and so on).
Is there a way to set the event number manually when filling a tree such that the event ids from the different TDCs are the same even though I did TTree->Fill(); at different times?

Thank you very much!

Also, I am working with an old version of root that was already installed in the lab:

ROOT Version: 5.34/36
Built for linuxx8664gcc on Apr 05 2016
CINT/ROOT C/C++ Interpreter version 5.18.00

Why not defining an additional branch with the ‘event id’ ?

Later, you can re-order the tree by event id using TTree::GetTreeIndex

Thank you for help @ferhue !

While trying to implement this I stumbled upon a new issue.
In my .cc file I want to do

  TTreeIndex* new_ind = new TTreeIndex(tr, "EventNr", "0");

but when compiling I get “undefined reference to `TTreeIndex::TTreeIndex(TTree const*, char const*, char const*)'” event though I included TTreeIndex.h in my .hh file. Am I missing any other include files or what could be the issue here?

Since I have not yet managed to compile without errors I also have another question:
I have the same EventNr four times (once for each TDC) - will these events then be combined in one index or will there be four events with the same index?
And: Will I be able to later normally loop over the entries or do I need to use some other Index functions to loop over all of my data?

Thank you!

Concerning the compilation error: it seems you are missing the correct flags for the linker, see Trying to compile C++ and link to ROOT libraries?

There will be four consecutive entries in the tree with the same event id, I believe.

What you probably want is double-entry index:

This way, you can do this kind of loop:
for(i=0;i<maxEvents;++i) for (j=0;j<nTDCS;++j) tree.GetEntryWithIndex(i,j);

See ROOT: TTreeIndex Class Reference

An alternative would be to have each TDC in a different TTree.

Thank you so much!
Right now I have these commands in my Makefile (I inherited this programme from previous students)

        CXXFLAGS += $(shell $(ROOTSYS)/bin/root-config --cflags) -D__HAVEROOT
        LDFLAGS  += $(shell $(ROOTSYS)/bin/root-config --ldflags --glibs) -lMinuit2       

Do you know how I can find out which flags I need such that the compiler finds the TTreeIndex?

maybe -lTree after -lMinuit2 ?

unfortunately no.
the output I get while compiling already includes it:

g++ -o onlineAnalyzer onlineAnalyzer.o src/eventDispatcher.o src/onlineProcess.o src/ROOTFileHandler.o src/histograms.o src/eventDataTypes.o src/add_plots.o src/MidasFile.o src/MidasOnline.o ./waveformlibrary/lib/libwaveformanalyzer.a -m64 -L/phys/root-5.34.36/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lMinuit2 -lz /phys//rootana/lib/librootana.a /phys/midas//linux/lib/libmidas.a -lrt -lutil

Try with -lTreePlayer

For the future: you can get this information if you scroll down in the HTML documentation until the dependency graph:

1 Like

Thank you so much!
It looks like it’s working now! :smiley:

Great. Feel free to click on “Mark as solution”.