susy_cfa  b611ccad937ea179f86a1f5663960264616c0a20
find_duplicates.cxx
Go to the documentation of this file.
1 // find_duplicates: Finds all unique events in a list of cfA files
2 
3 #include <ctime>
4 
5 #include <vector>
6 #include <fstream>
7 #include <iostream>
8 #include <set>
9 #include <map>
10 
11 #include "TString.h"
12 #include "TChain.h"
13 
14 #include "utilities.hpp"
15 
16 using namespace std;
17 
18 int main(int argc, char *argv[]){
19  time_t startTime, curTime;
20  time(&startTime);
21 
23 
24  // TString sample1("archive/15-07-23_test_single/small_quick_MET");
25  // TString sample2("archive/15-07-23_test_single/small_quick_Run2015B__HTMHT_MET_files10_batch");
26 
27  TString sample1("archive/15-07-23_test_single/small_quick_Run2015B__SingleMuon_DoubleMuon_HTMHT_MET_files5");
28  TString sample2("archive/15-07-23_test_single/small_quick_HTMHT");
29  int desired_trigger(0);
30 
31  int c(0);
32  while((c=getopt(argc, argv, "f:"))!=-1){
33  switch(c){
34  case 'f':
35  sample1=optarg;
36  break;
37  default:
38  break;
39  }
40  }
41 
42  vector<bool> *trig(0);
43  map<UInt_t, set<UInt_t> > events;
44  UInt_t event, run, levent;
45  TChain chain("tree"), chain2("tree");
46  int files = chain.Add(sample1+"*.root"), nmiss(0), ndup(0);
47  chain2.Add(sample2+"*.root");
48  if(files<1) return 1;
49 
50  cout<<endl<<"Doing "<<sample1<<endl;
51  chain.SetBranchAddress("event", &event);
52  chain.SetBranchAddress("run", &run);
53  chain.SetBranchAddress("trig", &trig);
54  long entries(chain.GetEntries());
55  //entries = 100;
56  for(int entry(0); entry<entries; entry++){
57  levent = event;
58  chain.GetEntry(entry);
59  if(entry%250000==0) {
60  cout<<"Doing entry "<<entry<<" of "<<entries<<endl;
61  //event = levent;
62  }
63  if(!trig->at(desired_trigger)) continue;
64  if(events.find(run) == events.end()) events[run] = set<UInt_t>(); // New run
65  if(events[run].find(event) == events[run].end()){ // New event
66  events[run].insert(event);
67  } else {// If event did not exist
68  cout<<entry<<": Event "<<event<<" in run "<<run<<" is duplicated"<<endl;
69  ndup++;
70  }
71  //cout<<entry<<": event "<<event<<", run "<<run<<". Total of "<<events[run].size()<<" events in this run"<<endl;
72  } // Loop over entries
73 
74 
75  cout<<endl<<"Doing "<<sample2<<endl;
76  chain2.SetBranchAddress("event", &event);
77  chain2.SetBranchAddress("run", &run);
78  chain2.SetBranchAddress("trig", &trig);
79  entries = chain2.GetEntries();
80  for(int entry(0); entry<entries; entry++){
81  levent = event;
82  chain2.GetEntry(entry);
83  if(entry%250000==0) {
84  cout<<"Doing entry "<<entry<<" of "<<entries<<endl;
85  }
86  if(!trig->at(desired_trigger)) continue; // MET170 trigger
87  if(events.find(run) == events.end()) events[run] = set<UInt_t>(); // New run
88  if(events[run].find(event) == events[run].end()){ // New event
89  events[run].insert(event);
90  cout<<entry<<": Event "<<event<<" in run "<<run<<" is not in "<<sample1<<endl;
91  nmiss++;
92  } else {// If event did not exist
93  }
94  //cout<<entry<<": event "<<event<<", run "<<run<<". Total of "<<events[run].size()<<" events in this run"<<endl;
95  } // Loop over entries
96 
97 
98  time(&curTime);
99  cout<<"Running over "<<entries<<" events took "<<difftime(curTime,startTime)<<" seconds. There were "
100  <<nmiss<<" events missing and "<<ndup<<" duplicate"<<endl<<endl;
101 
102  return 0;
103 }
string files
Definition: data_combine.py:33
int main(int argc, char *argv[])
int const & run() const
STL namespace.
int const & event() const
std::vector< bool > const & trig() const