compareTextLists.C
Go to the documentation of this file.
1 /* this macro takes the cmf and caf lists of events
2  * and does a few things
3  * -- it first checks that all events in caf are present in cmf and vice versa
4  * -- it then produces a tree with any differences between
5  * ereco, etrue, cvweights, pdgcodes and CCNC values
6  */
7 
8 
9 #include <string>
10 #include <set>
11 #include <iostream>
12 #include <fstream>
13 #include <iomanip>
14 #include <math.h>
15 
16 #include "TH1.h"
17 #include "TCanvas.h"
18 #include "TFile.h"
19 
20 struct EventInfo{
21 
23  : lepe(0.0)
24  , hade(0.0)
25  , ecalo(0.0)
26  , ereco(0.)
27  , etrue(0.)
28  , pdg(0.)
29  , ccnc(0.)
30  , cvwgt(0.)
31  {}
32 
33  EventInfo(double le,
34  double he,
35  double ec,
36  double er,
37  double et,
38  double p,
39  double cc,
40  double ew)
41  : lepe(le)
42  , hade(he)
43  , ecalo(ec)
44  , ereco(er)
45  , etrue(et)
46  , pdg(p)
47  , ccnc(cc)
48  , cvwgt(ew)
49  {}
50 
51  double lepe;
52  double hade;
53  double ecalo;
54  double ereco;
55  double etrue;
56  double pdg;
57  double ccnc;
58  double cvwgt;
59 
60  // assume that ereco and cvwgt are the most likely
61  // offenders so put them first
62  bool operator<(EventInfo const& other) const {
63  if(ereco < other.ereco ) return true;
64  else{
65  if(ereco == other.ereco &&
66  cvwgt < other.cvwgt) return true;
67  else{
68  if(ereco == other.ereco &&
69  cvwgt == other.cvwgt &&
70  etrue < other.etrue) return true;
71  else{
72  if(ereco == other.ereco &&
73  cvwgt == other.cvwgt &&
74  etrue == other.etrue &&
75  pdg < other.pdg) return true;
76  else{
77  if(ereco == other.ereco &&
78  cvwgt == other.cvwgt &&
79  etrue == other.etrue &&
80  pdg == other.pdg &&
81  ccnc < other.ccnc) return true;
82  }
83  }
84  }
85  }
86  return false;
87  }
88 
89  bool operator==(EventInfo const& other) const{
90  if (ereco == other.ereco &&
91  cvwgt == other.cvwgt &&
92  etrue == other.etrue) return true;
93  else return false;
94  }
95 };
96 
97 struct EventID{
98 
100  : run(0)
101  , subrun(0)
102  , event(0)
103  , slice(0)
104  , cycle(0)
105 
106  {}
107 
108  EventID(long r,
109  long sr,
110  long ev,
111  long sl,
112  long c)
113  : run(r)
114  , subrun(sr)
115  , event(ev)
116  , slice(sl)
117  , cycle(c)
118  {}
119 
120  long run ;
121  long subrun;
122  long event ;
123  long slice ;
124  long cycle ;
125 
126  bool operator<(EventID const& other) const {
127  if(run < other.run ) return true;
128  else{
129  if(run == other.run &&
130  subrun < other.subrun) return true;
131  else{
132  if(run == other.run &&
133  subrun == other.subrun &&
134  event < other.event ) return true;
135  else {
136  if(run == other.run &&
137  subrun == other.subrun &&
138  event == other.event &&
139  slice < other.slice ) return true;
140  else{
141  if(run == other.run &&
142  subrun == other.subrun &&
143  event == other.event &&
144  slice == other.slice &&
145  cycle < other.cycle ) return true;
146  }
147  }
148  }
149  }
150  return false;
151  }
152 };
153 
154 // just a simple struct for holding the name and eventMap together
156  std::map<EventID, EventInfo> eventMap;
158 };
159 
160 void fillEventMapFromFile(EventContainer & eventContainer,
161  std::string const& fileName)
162 {
163 
164  // read in the event lists list of events
165  std::ifstream eventLists(fileName);
166 
167  std::cout << fileName
168  << " is open "
169  << eventLists.is_open()
170  << std::endl;
171 
172  double run, subrun, event, slice, cycle;
173  double lepe, hade, ecalo, ereco, etrue, pdg, ccnc, cvwgt;
174 
175  long ev;
176 
177  while( !eventLists.eof() && eventLists.is_open() ){
178  eventLists >> run >> subrun >> event >> slice >> cycle
179  >> lepe >> hade >> ecalo >> ereco >> etrue >> pdg >> ccnc >> cvwgt;
180 
181  if(event > 1.e6){
182  ev = event / 10;
183  ev *= 10.;
184  }
185  else ev = event;
186 
187  EventID evId((long)run,
188  (long)subrun,
189  (long)ev,
190  (long)slice,
191  (long)cycle);
192 
193  EventInfo evIn(lepe, hade, ecalo, ereco, etrue, pdg, ccnc, cvwgt);
194 
195  if(eventContainer.eventMap.size() < 10)
196  std::cout << " event: "
197  << evId.run
198  << " "
199  << evId.subrun
200  << " "
201  << evId.event
202  << " / "
203  << event
204  << " "
205  << evId.slice
206  << " "
207  << evId.cycle
208  << std::endl;
209 
210  eventContainer.eventMap[evId] = evIn;
211 
212  } // end loop to load event lists events
213 
214  std::cout << "There are "
215  << eventContainer.eventMap.size()
216  << " events "
217  << std::endl;
218 }
219 
221  EventContainer &searchSample)
222 {
223 
224  EventContainer differentEventSample;
225  differentEventSample.name = baseSample.name + "NotIn" + searchSample.name;
226 
227  std::map<EventID, EventInfo> baseMap = baseSample.eventMap;
228  std::map<EventID, EventInfo> searchMap = searchSample.eventMap;
229 
230  int nEvents=0;
231 
232  for (auto& itr : baseMap){
233 
234  // first, check if the event exists in the searchMap
235  if (searchMap.find(itr.first) != searchMap.end()){
236  // if it exists, check that the information is correct
237  if (itr.second == searchMap[itr.first]){
238  }
239  else{
240  // event exists, but information is wrong
241  differentEventSample.eventMap[itr.first] = itr.second;
242  }
243 
244  }
245  else{
246  // event doesn't exist
247  std::cout
248  << "Event "
249  << itr.first.run << " "
250  << itr.first.subrun << " "
251  << itr.first.event << " "
252  << itr.first.slice << " "
253  << itr.first.cycle
254  << " exists in "
255  << baseSample.name
256  << " but not in "
257  << searchSample.name
258  << ". Printing information."
259  << "\n ereco " << itr.second.ereco
260  << "\n etrue " << itr.second.etrue
261  << "\n pdg " << itr.second.pdg
262  << "\n ccnc " << itr.second.ccnc
263  << "\n cvwgt " << itr.second.cvwgt
264  << std::endl;
265  ++nEvents;
266  }
267  }
268 
269  std::cout
270  << "there are "
271  << nEvents
272  << " events in base sample not in search sample"
273  << std::endl;
274 
275  return differentEventSample;
276 }
277 
279 
280  // setup output histograms, canvas
281  TFile* eventDifferences = new TFile("eventDifferences.root", "recreate");
282  TTree* t = new TTree("ed", "Event Differences");
283  int run;
284  int subrun;
285  int event;
286  int slice;
287  int cycle;
288  double cmf_lepe;
289  double cmf_hade;
290  double cmf_ecalo;
291  double cmf_ereco;
292  double cmf_etrue;
293  double cmf_pdg;
294  double cmf_ccnc;
295  double cmf_cvwgt;
296  double caf_lepe;
297  double caf_hade;
298  double caf_ecalo;
299  double caf_ereco;
300  double caf_etrue;
301  double caf_pdg;
302  double caf_ccnc;
303  double caf_cvwgt;
304  t->Branch("run" , &run);
305  t->Branch("subrun" , &subrun);
306  t->Branch("event" , &event);
307  t->Branch("slice" , &slice);
308  t->Branch("cycle" , &cycle);
309  t->Branch("cmf_lepe" , &cmf_lepe);
310  t->Branch("cmf_hade" , &cmf_hade);
311  t->Branch("cmf_ecalo" , &cmf_ecalo);
312  t->Branch("cmf_ereco" , &cmf_ereco);
313  t->Branch("cmf_etrue" , &cmf_etrue);
314  t->Branch("cmf_pdg" , &cmf_pdg);
315  t->Branch("cmf_ccnc" , &cmf_ccnc);
316  t->Branch("cmf_cvwgt" , &cmf_cvwgt);
317  t->Branch("caf_lepe" , &caf_lepe);
318  t->Branch("caf_hade" , &caf_hade);
319  t->Branch("caf_ecalo" , &caf_ecalo);
320  t->Branch("caf_ereco" , &caf_ereco);
321  t->Branch("caf_etrue" , &caf_etrue);
322  t->Branch("caf_pdg" , &caf_pdg);
323  t->Branch("caf_ccnc" , &caf_ccnc);
324  t->Branch("caf_cvwgt" , &caf_cvwgt);
325 
326  for (auto& itr : cmf.eventMap){
327  run = itr.first.run;
328  subrun = itr.first.subrun;
329  event = itr.first.event;
330  cycle = itr.first.cycle;
331  slice = itr.first.slice;
332 
333  cmf_lepe = itr.second.lepe;
334  cmf_hade = itr.second.hade;
335  cmf_ecalo = itr.second.ecalo;
336  cmf_ereco = itr.second.ereco;
337  cmf_etrue = itr.second.etrue;
338  cmf_pdg = itr.second.pdg;
339  cmf_ccnc = itr.second.ccnc;
340  cmf_cvwgt = itr.second.cvwgt;
341 
342  caf_lepe = caf.eventMap[itr.first].lepe;
343  caf_hade = caf.eventMap[itr.first].hade;
344  caf_ecalo = caf.eventMap[itr.first].ecalo;
345  caf_ereco = caf.eventMap[itr.first].ereco;
346  caf_etrue = caf.eventMap[itr.first].etrue;
347  caf_pdg = caf.eventMap[itr.first].pdg;
348  caf_ccnc = caf.eventMap[itr.first].ccnc;
349  caf_cvwgt = caf.eventMap[itr.first].cvwgt;
350 
351  t->Fill();
352  }
353  t->Write();
354 }
355 
357 {
358 
359  EventContainer cmfEvents;
360  EventContainer cafEvents;
361 
362  cmfEvents.name = "cmf";
363  cafEvents.name = "caf";
364 
365  std::cout
366  << "Configured with "
367  << "\n -- cmf file: " << cmfFile
368  << "\n -- caf file: " << cafFile
369  << std::endl;
370 
371  fillEventMapFromFile(cmfEvents, cmfFile);
372  fillEventMapFromFile(cafEvents, cafFile);
373 
374  EventContainer CMFEventDiff = findMissingFiles(cmfEvents, cafEvents);
375  EventContainer CAFEventDiff = findMissingFiles(cafEvents, cmfEvents);
376 
377  saveToFile(CMFEventDiff, CAFEventDiff);
378 
379 }
std::map< EventID, EventInfo > eventMap
fileName
Definition: plotROC.py:78
void saveToFile(EventContainer cmf, EventContainer caf)
const char * p
Definition: xmltok.h:285
void compareTextLists(std::string cmfFile, std::string cafFile)
EventID(long r, long sr, long ev, long sl, long c)
bool operator<(EventInfo const &other) const
bool operator==(EventInfo const &other) const
EventContainer findMissingFiles(EventContainer &baseSample, EventContainer &searchSample)
bool operator<(EventID const &other) const
caf::StandardRecord * sr
double he
Definition: runWimpSim.h:113
EventInfo(double le, double he, double ec, double er, double et, double p, double cc, double ew)
std::string name
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
TChain * le
Definition: leana.C:12
void cc()
Definition: test_ana.C:28
TRandom3 r(0)
void fillEventMapFromFile(EventContainer &eventContainer, std::string const &fileName)
This module creates Common Analysis Files.
Definition: FileReducer.h:10
enum BeamMode string