-
Notifications
You must be signed in to change notification settings - Fork 1
/
removeDuplicates.C
55 lines (45 loc) · 1.65 KB
/
removeDuplicates.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <set>
#include <TString.h>
#include <TFile.h>
#include <TTree.h>
void removeDuplicates(TString filename) {
std::cout<<filename<<std::endl;
TFile *oldfile = new TFile(filename);
//TTree *oldtree = (TTree*)oldfile->Get("Ana/passedEvents");
TTree *oldtree = (TTree*)oldfile->Get("passedEvents");
Long64_t nentries = oldtree->GetEntries();
std::cout<<nentries<<" total entries."<<std::endl;
ULong64_t Run, LumiSect, Event;
bool passedZ4lSelection;
oldtree->SetBranchAddress("Run",&Run);
oldtree->SetBranchAddress("LumiSect",&LumiSect);
oldtree->SetBranchAddress("Event",&Event);
//Create a new file + a clone of old tree in new file
TFile *newfile = new TFile(
filename.ReplaceAll(".root","_noDuplicates.root")
,"recreate");
TTree *newtree = oldtree->CloneTree(0);
std::set<TString> runlumieventSet;
int nremoved = 0;
for (Long64_t i=0;i<nentries; i++) {
if (i%10000==0) std::cout<<i<<"/"<<nentries<<std::endl;
oldtree->GetEntry(i);
TString s_Run = std::to_string(Run);
TString s_Lumi = std::to_string(LumiSect);
TString s_Event = std::to_string(Event);
TString runlumievent = s_Run+":"+s_Lumi+":"+s_Event;
if (runlumieventSet.find(runlumievent)==runlumieventSet.end()) {
runlumieventSet.insert(runlumievent);
newtree->Fill();
} else {
nremoved++;
}
//if (passedZ4lSelection) newtree->Fill();
}
std::cout<<nremoved<<" duplicates."<<std::endl;
newtree->Print();
newtree->AutoSave();
//delete oldfile;
delete newfile;
}