compareSelectedSets.C
Go to the documentation of this file.
1 #include <string>
2 #include <set>
3 #include <iostream>
4 #include <fstream>
5 #include <iomanip>
6 #include <math.h>
7 
8 #include "TH1.h"
9 #include "TCanvas.h"
10 #include "TFile.h"
11 
12 struct EventID{
13 
15  : run(0)
16  , subrun(0)
17  , event(0)
18  , slice(0)
19  , cycle(0)
20  , energy(0.)
21  {}
22 
23  EventID(long r,
24  long sr,
25  long ev,
26  long sl,
27  long c,
28  double en)
29  : run(r)
30  , subrun(sr)
31  , event(ev)
32  , slice(sl)
33  , cycle(c)
34  , energy(en)
35  {}
36 
37  long run ;
38  long subrun;
39  long event ;
40  long slice ;
41  long cycle ;
42  double energy;
43 
44  bool operator<(EventID const& other) const {
45  if(run < other.run ) return true;
46  else{
47  if(run == other.run &&
48  subrun < other.subrun) return true;
49  else{
50  if(run == other.run &&
51  subrun == other.subrun &&
52  event < other.event ) return true;
53  else {
54  if(run == other.run &&
55  subrun == other.subrun &&
56  event == other.event &&
57  slice < other.slice ) return true;
58  else{
59  if(run == other.run &&
60  subrun == other.subrun &&
61  event == other.event &&
62  slice == other.slice &&
63  cycle < other.cycle ) return true;
64  }
65  }
66  }
67  }
68  return false;
69  }
70 
71 };
72 
73 void fillEventSetFromFile(std::set<EventID> & sample,
74  std::string const& fileName,
75  std::string const& sel)
76 {
78  std::string selectToUse = "NuMu";
79  if(sel == "nue") selectToUse = "NuE";
80  else if(sel == "nus") selectToUse = "NC";
81 
82  std::cout << fileName
83  << std::endl;
84 
85  // read in the event lists list of events
86  std::ifstream eventLists(fileName);
87 
88  std::cout << fileName
89  << " is open "
90  << eventLists.is_open()
91  << std::endl;
92 
93  double energy;
94  double run, subrun, event, slice, cycle;
95 
96  long ev;
97 
98  while( !eventLists.eof() && eventLists.is_open() ){
99  eventLists >> select >> run >> subrun >> event >> slice >> cycle >> energy;
100 
101  if(select.find(selectToUse) == std::string::npos) continue;
102 
103  if(event > 1.e6){
104  ev = event / 10;
105  ev *= 10.;
106  }
107  else ev = event;
108 
109  EventID evId((long)run,
110  (long)subrun,
111  (long)ev,
112  (long)slice,
113  (long)cycle,
114  energy);
115 
116  if(sample.size() < 10)
117  std::cout << select
118  << " event: "
119  << evId.run
120  << " "
121  << evId.subrun
122  << " "
123  << evId.event
124  << " / "
125  << event
126  << " "
127  << evId.slice
128  << " "
129  << evId.cycle
130  << std::endl;
131 
132  sample.insert(evId);
133 
134  } // end loop to load event lists events
135 
136  std::cout << "There are "
137  << sample.size()
138  << " events "
139  << std::endl;
140 }
141 
143  std::string sel1="SELECT1",
144  std::string sel2="SELECT2",
145  std::string sample="FILETYPE",
146  std::string horncur="HORNCUR",
147  std::string tag="TAG")
148 {
149 
150  std::set<EventID> sample1Events;
151  std::set<EventID> sample2Events;
152 
153  std::string inputName("selectedEvents_" + det + "_" + sel1 + "_" + horncur + "_" + sample + "_" + tag + ".txt");
154 
155  std::cout << inputName
156  << std::endl;
157 
158  fillEventSetFromFile(sample1Events, inputName, sel1);
159 
160  inputName = "selectedEvents_" + det + "_" + sel2 + "_" + horncur + "_" + sample + "_" + tag + ".txt";
161 
162  fillEventSetFromFile(sample2Events, inputName, sel2);
163 
164  // loop over the event list and look for missing caf events
165  int dups = 0;
166 
167  std::ofstream dupList("duplicate_list_" + det + "_" + sel1 + "_" + sel2 + "_" + horncur + "_" + sample + "_" + tag + ".txt");
168 
169  for(auto const& itr : sample1Events){
170  if(sample2Events.find(itr) != sample2Events.end()){
171  ++dups;
172 
173  dupList << sel1
174  << " "
175  << itr.run
176  << " "
177  << itr.subrun
178  << " "
179  << itr.event
180  << " "
181  << itr.slice
182  << " "
183  << itr.cycle
184  << std::endl;
185  }
186  } // end loop to look for duplicated evnets
187 
188  std::cout << "There are "
189  << dups
190  << " events from "
191  << sel1
192  << " duplicated in "
193  << sel2
194  << std::endl;
195 
196  dups = 0;
197 
198  for(auto const& itr : sample2Events){
199  if(sample1Events.find(itr) != sample1Events.end()){
200  ++dups;
201 
202  dupList << sel2
203  << " "
204  << itr.run
205  << " "
206  << itr.subrun
207  << " "
208  << itr.event
209  << " "
210  << itr.slice
211  << " "
212  << itr.cycle
213  << std::endl;
214  }
215  } // end loop to look for duplicated evnets
216 
217  dupList.close();
218 
219  std::cout << "There are "
220  << dups
221  << " events from "
222  << sel2
223  << " duplicated in "
224  << sel1
225  << std::endl;
226 }
EventID(long r, long sr, long ev, long sl, long c, double en)
fileName
Definition: plotROC.py:78
void fillEventSetFromFile(std::set< EventID > &sample, std::string const &fileName, std::string const &sel)
double energy
Definition: compareEvents.C:54
bool operator<(EventID const &other) const
caf::StandardRecord * sr
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
void compareSelectedSets(std::string det="DETECTOR", std::string sel1="SELECT1", std::string sel2="SELECT2", std::string sample="FILETYPE", std::string horncur="HORNCUR", std::string tag="TAG")
TRandom3 r(0)
std::string select
Definition: compareEvents.C:57
enum BeamMode string