Rewrite a branch, by putting condition on branch

The program I am using is copied from the one given in ROOT tutorials and modified as per my use:
ROOT: tutorials/tree/copytree3.C File Reference by Rene Brun.

void copytree()
 {
  
    const auto filename = "./File.root" ;
  
    TFile oldfile(filename);
    TTree *oldtree;
    oldfile.GetObject("TREE", oldtree);
  
    // Deactivate all branches
    oldtree->SetBranchStatus("*", 0);
  
    // Activate only what you want 
    for (auto activeBranchName : {"MW1_TOF", "MW2_TOF"})
    oldtree->SetBranchStatus(activeBranchName, 1);
  
    // Create a new file + a clone of old tree in new file
    TFile newfile("New.root", "recreate");
    auto newtree = oldtree->CloneTree();
  
    newtree->Print();
    newfile.Write();
 }

Now, for the branch ‘MW1_TOF’, I have range from 0 to 4096, and I want to put a condition to read only MW1_TOF <= 1000 for example.
How do I incorporate the same in the program?

ROOT Version: Not Provided
Platform: Ubuntu
Compiler: Not Provided

I must be missing something, because copyTree.C shows exactly that:

      oldtree->GetEntry(i);
      if (event->GetNtrack() > 605)
         newtree->Fill();

If this doesn’t apply to your case, can you explain what “I want to put a condition to read only MW1_TOF <= 1000” means? Do you only want to write those?

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