RDataFrame: Snapshot does not work properly after Define and Range call

Dear @eneb,

I have tried your example but I re-wrote it a bit so that it can be compiled and reproduced easily and standalone:

#include <ROOT/RDataFrame.hxx>
#include <ROOT/RVec.hxx>
#include <Math/Vector4D.h>
#include <TInterpreter.h>

int main(){

    gInterpreter->GenerateDictionary("ROOT::RVec<ROOT::Math::PtEtaPhiEVector>", "Math/Vector4D.h;ROOT/RVec.hxx");

    // create dataframe
    ROOT::RDataFrame df("mini","mc_410000.ttbar_lep.root");
    // define variables needed for cuts and/or in the output
    auto df1 = df.Define("leptmp", "ROOT::VecOps::Construct<ROOT::Math::PtEtaPhiEVector>(0.001*lep_pt, lep_eta, lep_phi, 0.001*lep_E);"); // new RDataFrame to save the variable
    auto df2 = df1.Define("lep_theta", "return ROOT::VecOps::Map(leptmp,[](ROOT::Math::PtEtaPhiEVector x){return x.Theta();})");
    auto df_norange = df2.Filter("All(lep_pt > 27000. && lep_z0*sin(lep_theta) < 0.5)");

    auto df_range = df_norange.Range(0,50.);
    // save both dataframes
    auto snapshot_df_ranges = df_range.Snapshot("outputTree", "output_ranges.root");
    auto snapshot_df_no_ranges = df_norange.Snapshot("outputTree", "output_no_ranges.root");

    return 0;
}

The problem has nothing to do with the call to Ranges(). The main issue in your example is the missing the dictionary, with my debug version of ROOT what I see as an error is:

Error in <TTree::Branch>: The class requested (ROOT::VecOps::RVec<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiE4D<double> > >) for the branch "leptmp" is an instance of an stl collection and does not have a compiled CollectionProxy. Please generate the dictionary for this collection (ROOT::VecOps::RVec<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiE4D<double> > >) to avoid to write corrupted data.

hence I added the line above:

gInterpreter->GenerateDictionary("ROOT::RVec<ROOT::Math::PtEtaPhiEVector>", "Math/Vector4D.h;ROOT/RVec.hxx");

You can also follow a similar example here: Not being able to write RVec<PtEtaPhiMVector> object into root file with RDF snapshot

Cheers,
Marta