CleanupPrelim.C
Go to the documentation of this file.
1 #include <set>
2 
3 void CleanupPrelim(){
4 
5  set<int> eventIds; // keep track of already seen event numbers
6  int thisId = 0;
7 
8  //Get old file, old tree and set top branch address
9  TFile *oldfile = new TFile("MetricsTree_All.root","read");
10  TTree *oldtree = (TTree*)oldfile->Get("mytree");
11  Long64_t nentries = oldtree->GetEntries();
12  int run, subrun, preliminary;
13  oldtree->SetBranchAddress("run",&run);
14  oldtree->SetBranchAddress("subrun",&subrun);
15  oldtree->SetBranchAddress("preliminary",&preliminary);
16 
17  //Create a new file + a clone of old tree in new file
18  TFile *newfile = new TFile("MetricsClean.root","recreate");
19  TTree *newtree = oldtree->CloneTree(0);
20 
21  set<int> cleanruns;
22 
23  for (Long64_t i = 0; i < nentries; i++) {
24 
25  if(i%(nentries/10)==0) cout << int(100.0*i/nentries+0.5) << "% done" << endl;
26 
27  oldtree->GetEntry(i);
28 
29  thisId = run*100 + subrun;
30 
31  // if we have not seen this subrun yet, add it to the set
32  // and to the entry list
33  if (eventIds.count(thisId) == 0 && !preliminary){
34 
35  eventIds.insert(thisId);
36 
37  newtree->Fill();
38 
39  }
40 
41  }
42 
43 // newtree->Print();
44  newtree->AutoSave();
45 
46  delete oldfile;
47  delete newfile;
48 
49 }
50 
void CleanupPrelim()
Definition: CleanupPrelim.C:3
Long64_t nentries
Int_t preliminary
Definition: SimpleIterate.C:63
OStream cout
Definition: OStream.cxx:6
set< int > cleanruns