Touble save custom class using PyROOT RDataFrame (e.g. Delphes object)

Dear experts,
I have questions about writing the vector of objects in the TTree with RDataFrame. I wish to process the object (custom class from Delphes) saved in the tree and re-save some of the branches in the output. To be mre specific I make one example with 3 classes, Jet GenParticle and Weight:

ROOT.gInterpreter.ProcessLine('.L classes/DelphesClasses.cc')
df = ROOT.RDataFrame("Delphes","example.root")
# read
df=df.Define("LeadingJetPt","Jet.PT[0]") # read the Jet class -- pass
df=df.Define("LeadingParPt","Particle.PT[0]") # read the Particle class -- pass
df=df.Define("NominalW","Weight.Weight[0]") # read the Weight class -- pass
# saving
run=1 # 2, 3 different cases
if run==1:
    # case1: save Jet class -- pass
    branchList = ROOT.std.vector('std::string')()
    branchList.push_back("LeadingJetPt") # save the scalar -- pass
    branchList.push_back("Jet") # save the Jet class -- pass
    df.Snapshot("output","good.root",branchList) # pass
if run==2:
    # case2: save Particle class -- crash
    branchList = ROOT.std.vector('std::string')()
    branchList.push_back("LeadingParPt") # save the scalar -- pass
    branchList.push_back("Particle") # save the Particle class -- crash
    df.Snapshot("output","not_good2.root",branchList) # crash

if run==3:
    # case3: save Weight class -- crash
    branchList = ROOT.std.vector('std::string')()
    branchList.push_back("Weight") # save the Weight class -- crash
    df.Snapshot("output","not_good1.root",branchList) # crash

And observed:

Error in <TTreeReaderArrayBase::CreateContentProxy()>: The branch Particle contains data of type GenParticle. It cannot be accessed by a TTreeReaderArray<TRef>

Error in <TTreeReaderArrayBase::CreateContentProxy()>: The branch Weight contains data of type Weight. It cannot be accessed by a TTreeReaderArray<float>

It might be related to this thread and with latest root v6.30, after including the header(shipped with Delphes v3.5.0), most of the classes I/O work perfectly except the above two.

Any help or suggestion on how to save these classes would be helpful! Thank you and apologize for the lengthy description and correct me if I asked in a wrong place.

Best,
Qi

(not allowed to upload file so I put relavent snippet. I have one test root file and could email to experts if helpful)

// ... DelphesClasses.cc
#include "classes/DelphesClasses.h"
#include "classes/SortableObject.h"
CompBase *GenParticle::fgCompare = 0;
CompBase *Jet::fgCompare = CompPT<Jet>::Instance();
// ...
// ...DelphesClasses.h
class Jet: public SortableObject
{
public:
  Float_t PT; // jet transverse momentum
  TLorentzVector SoftDroppedJet;
  // more members...
  TRefArray Constituents; // references to constituents
  TRefArray Particles; // references to generated particles
  static CompBase *fgCompare; //!
  const CompBase *GetCompare() const { return fgCompare; }
  TLorentzVector P4() const;
  TLorentzVector Area;
  ClassDef(Jet, 4)
};

class GenParticle: public SortableObject
{
public:
  Int_t PID; // particle HEP ID number | hepevt.idhep[number]
  // more members...
  static CompBase *fgCompare; //!
  const CompBase *GetCompare() const { return fgCompare; }
  TLorentzVector P4() const;
  ClassDef(GenParticle, 2)
};

class Weight: public TObject
{
public:
  Float_t Weight; // weight for the event
  ClassDef(Weight, 1)
};
// ...SortableObject.h
class CompBase
{
public:
  virtual ~CompBase() {}
  virtual Bool_t IsSortable(const TObject *) const { return kTRUE; }
  virtual Int_t Compare(const TObject *obj1, const TObject *obj2) const = 0;
};

class SortableObject: public TObject
{
public:
  Bool_t IsSortable() const { return GetCompare() ? GetCompare()->IsSortable(this) : kFALSE; }
  Int_t Compare(const TObject *obj) const { return GetCompare()->Compare(this, obj); }
  virtual const CompBase *GetCompare() const = 0;
  ClassDef(SortableObject, 1)
};

template <typename T>
class CompPT: public CompBase
{
  CompPT() {}
public:
  static CompPT *Instance()
  {
    static CompPT single;
    return &single;
  }
  Int_t Compare(const TObject *obj1, const TObject *obj2) const
  {
    const T *t1 = static_cast<const T *>(obj1);
    const T *t2 = static_cast<const T *>(obj2);
    if(t1->PT > t2->PT)
      return -1;
    else if(t1->PT < t2->PT)
      return 1;
    else
      return 0;
  }
};

ROOT Version: 6.30/02
Platform: linuxx8664gcc
Compiler: g++ (GCC) 12.1.0


Welcome to the ROOT forum.

I guess @vpadulan can help you.