test_derived_flat_tree.cxx
Go to the documentation of this file.
1 /*
2  * test_derived_flat_tree.cxx
3  *
4  * Created on: Feb 15, 2021
5  * Author: chilgenb
6  */
7 
9 
10 #include <string>
11 #include <iostream>
12 using std::cerr;
13 using std::cout;
14 using std::endl;
15 
16 using namespace garana;
17 
18 namespace{
19  bool CheckHeader(HeaderTree* h1, HeaderTree* h2);
20  bool CheckGen(GenTree* g1, GenTree* g2);
21 }
22 
23 int main(int argc, char *argv[]) {
24 
25  //// check we got what we need from the command line ////
26  if(argc<3) {
27  cerr << "use error(test_derived_flat_tree): you must specify a root file to analyze ->" << '\n'
28  << " usage (input file order does not matter): test_derived_flat_tree "
29  << "<my_structured_tree.root> <my_flat_tree.root>" << endl;
30  return 1;
31  }
32 
33  if(argc>3) {
34  cerr << "use error(test_derived_flat_tree): too many arguments!" << endl;
35  return 2;
36  }
37 
38  // setup files
39  std::cout << "open TreeManager for file, " << argv[1] << endl;
40  TreeManager* tm1 = new TreeManager(argv[1]); //input file 1
41  std::cout << "open TreeManager for file, " << argv[2] << endl;
42  TreeManager* tm2 = new TreeManager(argv[2]); //input file 2
43  std::cout << "done constructing TreeManagers." << std::endl;
44 
45  bool pass = true;
46 
47  //Check header trees. only difference should be branch, TreeType
48  std::cout << "open headerTree 1" << std::endl;
49  HeaderTree* header1 = tm1->GetHeaderTree();
50  std::cout << "open headerTree 2" << std::endl;
51  HeaderTree* header2 = tm2->GetHeaderTree();
52  std::cout << "done constructing HeaderTrees." << std::endl;
53 
54  if(!CheckHeader(header1,header2)) {
55  cerr << "WARNING: header trees are incompatible" << endl;
56  pass = false;
57  }
58  else
59  std::cout << "Headers are compatible." << endl;
60 
61  GenTree* gen1 = tm1->GetGenTree();
62  GenTree* gen2 = tm2->GetGenTree();
63 
64  if(!CheckGen(gen1,gen2)) {
65  cerr << "WARNING: gen trees are incompatible" << endl;
66  pass = false;
67  }
68 
69  if(!pass){
70  cerr << "WARNING: test failed. something is amiss with your trees." << endl;
71  return 1;
72  }
73  else {
74  std::cout << "SUCESS!!!!!! =D" << std::endl;
75  }
76 
77  return 0;
78 }
79 
80 namespace{
81  bool CheckHeader(HeaderTree* h1, HeaderTree* h2) {
82 
83  h1->GetEntry(0);
84  h2->GetEntry(0);
85 
86  //determine which tree is structured and which one is flat
87  // TO DO: add check to make sure flat tree came from specific provided structured tree
88  // assume for now that user is careful (not a great assumption)"
89  try {
90  if(h1->TreeType() == h2->TreeType())
91  throw h1;
92  }
93  catch(HeaderTree* h){
94  cerr << "ERROR (test_derived_flat_tree): provided trees are either both structured or both flat!"
95  << endl;
96  return false;
97  }
98 
99  if(h1->NEntries() != h2->NEntries())
100  return false;
101 
102  if(h1->Run() != h2->Run())
103  return false;
104 
105  if(h1->SubRun() != h2->SubRun())
106  return false;
107 
108  return true;
109  }// CheckHeader()
110 
111  bool CheckGen(GenTree* g1, GenTree* g2) {
112 
113  if(g1->NEntries()!=g2->NEntries()){
114  cerr << "Gen: trees different length" << endl;
115  return false;
116  }
117 
118  for(UInt_t ientry=0; ientry<g1->NEntries(); ientry++){
119 
120  g1->GetEntry(ientry);
121  g2->GetEntry(ientry);
122 
123  if(g1->NGen()!=g2->NGen()){
124  cerr << "Gen: different NGen per entry ("
125  << g1->NGen() << " vs. " << g2->NGen()
126  << ")" << std::endl;
127  return false;
128  }
129 
130  for(UInt_t igen=0; igen<g1->NGen(); igen++){
131 
132  if(g1->IsGenie(igen)!=g2->IsGenie(igen)){
133  cerr << "Gen: disagreement on IsGenie" << endl;
134  return false;
135  }
136 
137  if(g1->NuPDG(igen)!=g2->NuPDG(igen))
138  return false;
139 
140  if(*(g1->NuP(igen))!= *(g2->NuP(igen)))
141  return false;
142 
143  if(g1->IsCC(igen)!=g2->IsCC(igen))
144  return false;
145 
146  if(g1->NFSParticles(igen)!=g2->NFSParticles(igen))
147  return false;
148 
149  if(g1->IsCC(igen)!=g2->IsCC(igen))
150  return false;
151 
152  if(*(g1->NuVertex(igen)) != *(g2->NuVertex(igen)))
153  return false;
154 
155  if(g1->FSTotEnergy(igen) != g2->FSTotEnergy(igen))
156  return false;
157 
158  }//for gen subentries
159 
160  }//for gen entries
161 
162  return true;
163 
164  }//CheckGen()
165 }
Int_t const & SubRun() const
Definition: HeaderTree.cxx:55
virtual const UInt_t NGen() const =0
virtual const UInt_t NFSParticles(const UInt_t &igen) const =0
const std::string *const TreeType() const
Definition: HeaderTree.cxx:32
virtual const TLorentzVector * NuVertex(const UInt_t &igen)=0
4-position of neutrino vertex
HLTPathStatus const pass
virtual const TLorentzVector * NuP(const UInt_t &igen)=0
initial neutrino 4-momentum
virtual const Bool_t IsCC(const UInt_t &igen) const =0
whether interaction is CC or not
virtual const Int_t NuPDG(const UInt_t &igen) const =0
neutrino PDG code
HeaderTree * GetHeaderTree() const
int main(int argc, char *argv[])
Int_t const & Run() const
Definition: HeaderTree.cxx:50
virtual const Float_t FSTotEnergy(const UInt_t &igen) const =0
virtual void GetEntry(const UInt_t &ientry)
Definition: TreeReader.cxx:39
GenTree * GetGenTree() const
size_t NEntries() const
Definition: TreeReader.cxx:35
QTextStream & endl(QTextStream &s)
virtual const Bool_t IsGenie(const UInt_t &igen) const =0