@@ -529,3 +529,51 @@ TEST(RDFVarySnapshot, GH20320)
529529 EXPECT_EQ (take_val->front (), 2 );
530530 EXPECT_EQ (take_var_up->front (), 3 );
531531}
532+
533+ // https://github.com/root-project/root/issues/20506
534+ // When snapshot is invoked on JITted Defines with variations, the Snapshot
535+ // Action needs to JIT the computation graph before creating outputs.
536+ // When this wasn't happening, the varied Defines be identical to nominal and
537+ // not be snapshot.
538+ TEST (RDFVarySnapshot, IncludeDependentColumns_JIT)
539+ {
540+ const char *fileName{" dataframe_snapshot_include_dependent_columns.root" };
541+ RemoveFileRAII (fileName);
542+ constexpr unsigned int N = 10 ;
543+
544+ ROOT::RDataFrame rdf (N);
545+ auto df = rdf.Define (" Muon_pt" , " return static_cast<double>(rdfentry_)" )
546+ .Vary (" Muon_pt" , " ROOT::VecOps::RVec<double>({Muon_pt*0.5, Muon_pt*2})" , {" down" , " up" }, " muon_unc" )
547+ .Define (" Muon_2pt" , " return 2. * Muon_pt;" );
548+
549+ ROOT::RDF::RSnapshotOptions opts;
550+ opts.fOverwriteIfExists = true ;
551+ opts.fIncludeVariations = true ;
552+
553+ auto snapshot = df.Snapshot (" Events" , fileName, {" Muon_pt" , " Muon_2pt" }, opts);
554+
555+ TFile file (fileName);
556+ auto tree = file.Get <TTree>(" Events" );
557+ ASSERT_NE (tree, nullptr );
558+ tree->Scan ();
559+
560+ double Muon_pt, Muon_pt_up, Muon_pt_down;
561+ double Muon_2pt, Muon_2pt_up, Muon_2pt_down;
562+ ASSERT_EQ (TTree::kMatch , tree->SetBranchAddress (" Muon_pt" , &Muon_pt));
563+ ASSERT_EQ (TTree::kMatch , tree->SetBranchAddress (" Muon_pt__muon_unc_up" , &Muon_pt_up));
564+ ASSERT_EQ (TTree::kMatch , tree->SetBranchAddress (" Muon_pt__muon_unc_down" , &Muon_pt_down));
565+ ASSERT_EQ (TTree::kMatch , tree->SetBranchAddress (" Muon_2pt" , &Muon_2pt));
566+ ASSERT_EQ (TTree::kMatch , tree->SetBranchAddress (" Muon_2pt__muon_unc_up" , &Muon_2pt_up));
567+ ASSERT_EQ (TTree::kMatch , tree->SetBranchAddress (" Muon_2pt__muon_unc_down" , &Muon_2pt_down));
568+
569+ EXPECT_EQ (tree->GetEntries (), N);
570+ for (unsigned int i = 0 ; i < tree->GetEntries (); ++i) {
571+ ASSERT_GT (tree->GetEntry (i), 0 );
572+ EXPECT_EQ (2 . * Muon_pt, Muon_2pt);
573+
574+ EXPECT_EQ (0.5 * Muon_pt, Muon_pt_down);
575+ EXPECT_EQ (0.5 * Muon_2pt, Muon_2pt_down);
576+ EXPECT_EQ (2 . * Muon_pt, Muon_pt_up);
577+ EXPECT_EQ (2 . * Muon_2pt, Muon_2pt_up);
578+ }
579+ }
0 commit comments