CleanupTree.C
Go to the documentation of this file.
1 #include <set>
2 
3 void CleanupTree(bool cleanP4=false){
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, par, corrupted;
13  double numslc;
14  oldtree->SetBranchAddress("run",&run);
15  oldtree->SetBranchAddress("subrun",&subrun);
16  oldtree->SetBranchAddress("par",&par);
17  oldtree->SetBranchAddress("corrupted",&corrupted);
18  oldtree->SetBranchAddress("numslc",&numslc);
19 
20  //Create a new file + a clone of old tree in new file
21  TFile *newfile = new TFile("MetricsClean.root","recreate");
22  TTree *newtree = oldtree->CloneTree(0);
23 
24  set<int> cleanruns;
25 
26  if(cleanP4){
27 
28 // ifstream fileListItr("checksubruns/ListMissingRuns.txt");
29  ifstream fileListItr("missingana.txt");
30 
31  int misrun;
32 
33  while(fileListItr >> misrun){
34  cleanruns.insert(misrun);
35  cout << "Change Run: " << misrun << endl;
36  }
37  /*
38  for (Long64_t i = 0; i < nentries; i++) {
39 
40  //if(i%(nentries/10)==0) cout << int(100.0*i/nentries+0.5) << "% done" << endl;
41 
42  oldtree->GetEntry(i);
43 
44  if (cleanruns.count(run) == 0){
45  if((run == 18344 || run == 18345)){
46  cleanruns.insert(run);
47  cout << "Change Run: " << run << endl;
48  }
49  }
50 
51  }
52  */
53  }
54 
55  for (Long64_t i = 0; i < nentries; i++) {
56 
57  if(i%(nentries/10)==0) cout << int(100.0*i/nentries+0.5) << "% done" << endl;
58 
59  oldtree->GetEntry(i);
60 
61  thisId = run*100 + subrun;
62 
63  // if we have not seen this subrun yet, add it to the set
64  // and to the entry list
65  if (eventIds.count(thisId) == 0){
66 
67  eventIds.insert(thisId);
68 
69  if (cleanruns.count(run) == 0 || !cleanP4) newtree->Fill();
70 
71  }
72 
73  }
74 
75 // newtree->Print();
76  newtree->AutoSave();
77 
78  delete oldfile;
79  delete newfile;
80 
81 }
82 
Double_t numslc
Definition: SimpleIterate.C:61
Int_t par
Definition: SimpleIterate.C:24
Long64_t nentries
OStream cout
Definition: OStream.cxx:6
void CleanupTree(bool cleanP4=false)
Definition: CleanupTree.C:3
ifstream fileListItr("ManBadSubruns.txt")
Int_t corrupted
Definition: SimpleIterate.C:59
set< int > cleanruns