Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to specify which branches to drop instead of keep #14

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions rapido/src/arbusto.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
class Arbusto : public Arbol
{
protected:
/** Invert how the branches are kept */
bool remove_branches;
/** Names of branches in original ROOT TTree to keep */
std::vector<TString> keep_branch_names;
std::vector<TString> branch_names;
/** Pointer to current TTree to skim */
TTree* orig_ttree;
public:
Expand All @@ -27,9 +29,10 @@ class Arbusto : public Arbol
* @param new_tfile pointer to output TFile
* @param tchain pointer to TChain of input TFiles
* @param branch_names std::vector of branch names to keep
* @param remove_branches bool selections so branches are dropped not kept
* @return none
*/
Arbusto(TFile* new_tfile, TChain* tchain, std::vector<TString> branch_names);
Arbusto(TFile* new_tfile, TChain* tchain, std::vector<TString> branch_names, bool remove_branches);
/**
* Arbusto object overload constructor
* @param cli HEPCLI object
Expand Down
23 changes: 12 additions & 11 deletions rapido/src/arbusto.icc
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
Arbusto::Arbusto() {}

Arbusto::Arbusto(TFile* new_tfile, TChain* tchain, std::vector<TString> keep_branch_names)
: keep_branch_names(keep_branch_names)
Arbusto::Arbusto(TFile* new_tfile, TChain* tchain, std::vector<TString> branch_names, bool remove_branches)
: remove_branches(remove_branches), branch_names(branch_names)
{
// If remove_branches is true, this inverts the selection to drop the listed branches
tfile = new_tfile;
// Disable all branches
tchain->SetBranchStatus("*", 0);
tchain->SetBranchStatus("*", remove_branches);
// Enable selected branches
for (auto branch_name : keep_branch_names)
for (auto branch_name : branch_names)
{
tchain->SetBranchStatus(branch_name, 1);
tchain->SetBranchStatus(branch_name, !remove_branches);
}
ttree = (TTree*)tchain->CloneTree(0);
}

Arbusto::Arbusto(HEPCLI& cli, std::vector<TString> keep_branch_names)
: keep_branch_names(keep_branch_names)
Arbusto::Arbusto(HEPCLI& cli, std::vector<TString> branch_names)
: branch_names(branch_names)
{
tfile = new TFile(TString(cli.output_dir+"/"+cli.output_name+".root"), "RECREATE");
// Disable all branches
cli.input_tchain->SetBranchStatus("*", 0);
// Enable selected branches
for (auto branch_name : keep_branch_names)
for (auto branch_name : branch_names)
{
cli.input_tchain->SetBranchStatus(branch_name, 1);
}
Expand All @@ -42,11 +43,11 @@ Arbusto::~Arbusto()
void Arbusto::init(TTree* next_ttree)
{
// Disable all branches
next_ttree->SetBranchStatus("*", 0);
next_ttree->SetBranchStatus("*", remove_branches);
// Enable selected branches
for (auto branch_name : keep_branch_names)
for (auto branch_name : branch_names)
{
next_ttree->SetBranchStatus(branch_name, 1);
next_ttree->SetBranchStatus(branch_name, !remove_branches);
}
next_ttree->CopyAddresses(ttree);
orig_ttree = next_ttree;
Expand Down
6 changes: 5 additions & 1 deletion skimmer/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ int main(int argc, char** argv)
"RECREATE"
);

// Set to true to specify branches to DROP instead of keep
bool remove_branches = false;

// Output setting (setting which TBranches to save from original Nano)
Arbusto arbusto = Arbusto(
output_tfile,
Expand All @@ -40,7 +43,8 @@ int main(int argc, char** argv)
"SubJet*",
"HLT_*",
"Pileup*"
}
},
remove_branches
);

// Initialize TLists for metadata TTrees
Expand Down
Loading