Looping a subset of events to a new file

Hi,

I am trying to select a subset of a big TTree and writing it to a new file, so I can have a smaller event sample to work with.

There’s a couple of example codes in ROOT tutorials for this, e.g. this https://root.cern.ch/root/html/tutorials/tree/copytree3.C.html and also files copytree.C and copytree2.C in root/tutorials/tree.

None of them work, the first and fatal issue being that ‘libEvent.so’ does not seem to exist in more recent installations, and I also cannot find it online.

Could you please point me to the right direction for achieving my goal?
I have tried both root5 and root6 with no luck.

Best,

Juska


_ROOT Version: 5.x and 6.12.06
_Platform: Ubuntu 16.04
Compiler: gcc


Hi Juska,

Suppose to have a file called myfile.root containing a dataset called mytree. In order to save a few events of it, there are at least 2 solutions. You could:

  1. Use the rooteventselector command line tool
  2. Use ROOT’s dataframe:
ROOT::Experimental::TDataFrame f("mytree", "myfile.root");
f.Range(0, 123).Snapshot("mytree", "mySmallerFile.root");

Best,
D

1 Like

Hi D,

I first tried method 2, but encountered problems with missing dictionary files, but the first method with ‘rooteventselector’ program worked perfectly and will be a very useful tool for me in the future.

Thanks a lot for the advice, I finally start to see the perks of ROOT6!

Cheers,

Juska

Hi Juska,

great! :slight_smile:
If a library with dictionaries is missing, it’s missing and it’s not a bug of data frame. Do you happen to have more context you want to share? Can we help?

Cheers,
Danilo

Hi Danilo,

my understanding is that in my case the dictionaries are not really necessary, and lack of them normally only produces a warning. Here is my simple Snapshot-macro and the output:

juska@dell:~/Dropbox/postdoc/terajet/misc$ tail SliceTree3.C 
{
ROOT::Experimental::TDataFrame f("ak4/ProcessedTree", "/media/juska/BigLinux/run2_smp/hannu/P8SP5_Flat_QCD_MC.root");
f.Range(0, 123).Snapshot("mytree", "mySmallerFile.root");
}
juska@dell:~/Dropbox/postdoc/terajet/misc$ root SliceTree3.C
root [0] 
Processing SliceTree3.C...
Warning in <TClass::Init>: no dictionary for class QCDEvent is available
Warning in <TClass::Init>: no dictionary for class QCDEventHdr is available
Warning in <TClass::Init>: no dictionary for class QCDMET is available
Warning in <TClass::Init>: no dictionary for class QCDPFJet is available
Warning in <TClass::Init>: no dictionary for class QCDPFJetBTag is available
Warning in <TClass::Init>: no dictionary for class QCDJet is available
input_line_45:2:118: error: use of undeclared identifier 'QCDEvent'
 (reinterpret_cast<ROOT::Experimental::TDF::TInterface<ROOT::Detail::TDF::TRangeBase> *>(140725208250336L)->Snapshot<QCDEvent>("mytree", "mySmallerFile.root", *reinterpret_cast<std::vector<std::string> *>...
                                                                                                                     ^
input_line_45:2:127: error: expected unqualified-id
 (reinterpret_cast<ROOT::Experimental::TDF::TInterface<ROOT::Detail::TDF::TRangeBase> *>(140725208250336L)->Snapshot<QCDEvent>("mytree", "mySmallerFile.root", *reinterpret_cast<std::vector<std::string> *>...
                                                                                                                              ^
terminate called after throwing an instance of 'cling::CompilationException'
  what():  Error evaluating expression (reinterpret_cast<ROOT::Experimental::TDF::TInterface<ROOT::Detail::TDF::TRangeBase> *>(140725208250336L)->Snapshot<QCDEvent>("mytree", "mySmallerFile.root", *reinterpret_cast<std::vector<std::string> *>(140725208251168L), *reinterpret_cast<ROOT::Experimental::TDF::TSnapshotOptions *>(140725208251328L)))
juska@dell:~/Dropbox/postdoc/terajet/misc$ 

As ‘rooteventselector’ is able to produce an exact copy of the original root tree file, I do not see how Snapshot could not do without the dictionaries.

Best,

Juska

Hi Juska,

there is a technical reason behind this behaviour but I think we can easily fix this usecase. We need to produce a rootmap together with the dictionaries of QCDEvent, QCDEventHdr and so on. Are you the author of those classes? Did you compile them?
One thing to try, if you cannot change the way the library is built, is to add this line on top of your script:

gSystem->Load("libTheNameOfTheLib.so");

Where the proper name is used :wink:

Best,
D

Hi Danilo,

I am not an author of the classes in case, but I do have their implementations. Compiling them, however, is not a straightforward task as it seems that there is dependencies to a myriad classes of the CMS computing environment. I have tried this in the past without success.

For now I’m very satisfied with the other solution, I will re-open this topic if a need for fixing the other approach arises in the future.

Thanks once again!

Cheers,

Juska

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