I am trying to read a tree, which was written to file in C++ and some class objects were saved to the tree.
I would like to read the tree using pyroot, but am getting a strange error.
If I do the following:
self.fUniqueID = int() # UInt_t self.fBits = int() # UInt_t self.Number = int() # Long64_t self.ReadTime = float() # Float_t self.ProcTime = float() # Float_t self.ProcessID = int() # Int_t self.Weight = float() # Float_t self.ScalePDF = float() # Float_t self.AlphaQED = float() # Float_t self.AlphaQCD = float() # Float_t self.size = int() # Int_t self.chain.SetBranchAddress('Event.fUniqueID',self.fUniqueID) self.chain.SetBranchAddress('Event.fBits', self.fBits) self.chain.SetBranchAddress('Event.Number', self.Number) self.chain.SetBranchAddress('Event.ReadTime', self.ReadTime) self.chain.SetBranchAddress('Event.ProcTime', self.ProcTime) self.chain.SetBranchAddress('Event.ProcessID',self.ProcessID) self.chain.SetBranchAddress('Event.Weight', self.Weight) self.chain.SetBranchAddress('Event.ScalePDF', self.ScalePDF) self.chain.SetBranchAddress('Event.AlphaQED', self.AlphaQED) self.chain.SetBranchAddress('Event.AlphaQCD', self.AlphaQCD) self.chain.SetBranchAddress('Event_size', self.size)
where this code lives in a class and the chain is a TChain. In the initialization of the variables where I’d like the data to be stored upon calling “GetEntry()”, I have in the comment what type the variable is inside the TTree. However, I get the error below when calling the “SetBranchAddress” function with one of the variables which were initialized with “float()”. If I change the initialization to “int()” the program runs without complaint, but the data is incorrect (always 0).
File "/afs/cern.ch/work/c/childers/snowmass/analysisCode/treeAccess/DelphesBranchEvent.py", line 24, in __init__ self.chain.SetBranchAddress('Event.ReadTime', self.ReadTime) TypeError: none of the 3 overloaded methods succeeded. Full details: Int_t TChain::SetBranchAddress(const char* bname, void* add, TBranch** ptr = 0) => could not convert argument 2 Int_t TChain::SetBranchAddress(const char* bname, void* add, TBranch** ptr, TClass* realClass, EDataType datatype, Bool_t isptr) => takes at least 6 arguments (2 given) Int_t TChain::SetBranchAddress(const char* bname, void* add, TClass* realClass, EDataType datatype, Bool_t isptr) => takes at least 5 arguments (2 given)
I’ve also tried directly accessing the variables using the TTree:
but since the data was saved to the tree using a C++ class, which I have not (and cannot) load into python, it fails.
Is there a better way to do this (besides working in C++ of course)?