File indexing completed on 2024-04-06 12:18:48
0001 TTree *CopyTreeMulti(const char *selection, TTree *input, Long64_t ncandscut, Long64_t nentries = 1000000, Long64_t firstentry = 0)
0002 {
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 TTree *tree = input->CloneTree(0);
0038 if (tree == 0) return 0;
0039
0040
0041 TObjArray* branches = tree->GetListOfBranches();
0042 Int_t nb = branches->GetEntriesFast();
0043 for (Int_t i = 0; i < nb; ++i) {
0044 TBranch* br = (TBranch*) branches->UncheckedAt(i);
0045 if (br->InheritsFrom("TBranchElement")) {
0046 ((TBranchElement*) br)->ResetDeleteObject();
0047 }
0048 }
0049
0050 Long64_t entry,entryNumber;
0051 nentries = input->GetEntries();
0052
0053
0054 TTreeFormula *select = 0;
0055
0056
0057 if (strlen(selection)) {
0058 select = new TTreeFormula("Selection",selection,input);
0059 if (!select || !select->GetNdim()) { delete select; }
0060 }
0061
0062
0063 Int_t tnumber = -1;
0064 for (entry=firstentry;entry<firstentry+nentries;entry++) {
0065 Long64_t ncand = 0;
0066 entryNumber = input->GetEntryNumber(entry);
0067 if (entryNumber < 0) break;
0068 Long64_t localEntry = input->LoadTree(entryNumber);
0069 if (localEntry < 0) break;
0070 if (tnumber != input->GetTreeNumber()) {
0071 tnumber = input->GetTreeNumber();
0072 if (select) select->UpdateFormulaLeaves();
0073 }
0074 if (select) {
0075 Int_t ndata = select->GetNdata();
0076 for(Int_t current = 0; current<ndata; current++) {
0077 if (select->EvalInstance(current) != 0) ncand++;
0078 }
0079 if (ncand < ncandscut) continue;
0080 }
0081 input->GetEntry(entryNumber);
0082 tree->Fill();
0083 }
0084 return tree;
0085 }