EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DelphesSkim.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DelphesSkim.C
1 #include "TROOT.h"
2 #include "TChain.h"
3 #include "TTree.h"
4 #include "TFile.h"
5 #include "TCut.h"
6 #include "TString.h"
7 #include <iostream>
8 
9 void DelphesSkim(TString input_filename, TString output_filename, TString skimCuts = "")
10 {
11  auto input_file = TFile::Open(input_filename);
12 
13  if (input_file == nullptr || input_file->IsZombie() || input_file->TestBit(TFile::kRecovered)) {
14  std::cout << "The input ROOT file is corrupted. Exiting..." << std::endl;
15  return;
16  }
17 
18  auto input_tree = static_cast<TTree*>(input_file->Get("Delphes"));
19 
20  std::cout << "Input Delphes TTree contains " << input_tree->GetEntries() << " events..." << std::endl;
21 
22  auto output_file = TFile::Open(output_filename,"RECREATE");
23  output_file->cd();
24  auto output_tree = static_cast<TTree*>(input_tree->CopyTree(skimCuts));
25  output_tree->Write();
26 
27  std::cout << "... skimmed output Delphes TTree contains " << output_tree->GetEntries() << " events." << std::endl;
28 
29  output_file->Close();
30 }