Reading HepMC weights with python

Dear ROOT experts,

Using a C++ macro, I usually read the weights of events using:

ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
Long64_t numberOfEntries = treeReader->GetEntries();
TClonesArray *branchEvent = treeReader->UseBranch("Event");
for(Int_t entry = 0; entry < numberOfEntries; ++entry)
     {
        treeReader->ReadEntry(entry);
        HepMCEvent *event = (HepMCEvent*) branchEvent->At(0);
       cout << event->Weight << endl;
     }

What is the pythonic way of doing this?

Thank you,
Amin

Dear Ameen,

There is a more Pythonic way to iterate over the entries of a TTree in Python and accessing its branches, as illustrated in this example.

However, in your C++ macro you are using a wrapper class for TTreeReader (ExRootTreeReader), so you can’t use the pythonization directly. You can still write a range loop in Python to iterate over the entries, but the rest of the code should look very similar to the C++ version.

Best,
Enric

Dear Enric,

Thank you for the reply. I will implement the method used in the example.

Best,
Amin

Dear Ameen,

Sure, let us know if you need any other help.

Best,
Enric

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