testFancyTTreeInterpolator.cxx
1 #include "FancyTTreeInterpolator.h"
2 
3 #include <iostream>
4 
5 #include "TFile.h"
6 #include "TTree.h"
7 #include "TChain.h"
8 //#include "UsefulAdu5Pat.h"
9 #include "TGraph.h"
10 
11 
12 int main(){
13 
14  // gSystem->Load("libAnitaEvent.so");
15 
16  TFile f("testFancyTTreeInterpolatorOutput.root", "recreate");
17 
18  TChain* gpsChain = new TChain("adu5PatTree");
19  const Int_t startRun = 331;
20  const Int_t endRun = 355;
21 
22  for(Int_t run=startRun; run<endRun; run++){
23  char gpsFileName[1024];
24  sprintf(gpsFileName, "root/run%d/gpsFile%d.root", run, run);
25  gpsChain->Add(gpsFileName);
26  }
27 
28 
29  FancyTTreeInterpolator treeInterp(gpsChain, "pat->realTime");
30  treeInterp.add("pat->latitude", "");
31  std::cout << treeInterp.fStringToGraph.find("pat->latitude")->first << std::endl;
32  int n = treeInterp.fStringToGraph.find("pat->latitude")->second->GetN();
33  std::cout << n << std::endl;
34 
35  // for(int i=0; i<n; i++){
36  // std::cout << treeInterp.fStringToGraph.find("pat->latitude")->second->GetY()[i] << std::endl;
37  // }
38 
39  try{// deliberate typo
40  treeInterp.interp("pat->latitudea", 10000);
41  }
42  catch(...){
43  std::cout << "Caught something!" << std::endl;
44  }
45 
46 
47  try{ // out of range time request
48  Double_t someNum = treeInterp.interp("pat->latitude", 10000);
49 
50  // these lines never get executed...
51  std::cout << someNum << std::endl;
52  std::cout << treeInterp.fStringToGraph.find("pat->latitude")->second->GetX()[0] << std::endl;
53  std::cout << treeInterp.fStringToGraph.find("pat->latitude")->second->GetX()[n-1] << std::endl;
54  }
55  catch(...){
56  std::cout << "Caught something!" << std::endl;
57  }
58 
59 
60  TGraph* gr = treeInterp.get("pat->latitude");
61  gr->SetName("grLat");
62  gr->Write();
63 
64 
65  /* Test unwrapping functionality in heading, should be smooth */
66  treeInterp.add("pat->heading", "pat->heading > -500", 360.0);
67  TGraph* gr2 = treeInterp.get("pat->heading");
68  gr2->SetName("grHeadUnwrapped");
69  gr2->Write();
70 
71 
72  TGraph* gr3 = new TGraph();
73  for(int i=0; i<gr2->GetN(); i++){
74  Double_t xVal = gr2->GetX()[i];
75  Double_t yVal = treeInterp.interp("pat->heading", xVal);
76  gr3->SetPoint(i, xVal, yVal);
77  }
78  gr3->SetName("grHeadUnwrappedAndInterped");
79  gr3->Write();
80 
81 
82  /* Test unwrapping functionality in heading, check we get back to the intial graph */
83  treeInterp.add("pat->heading", "pat->heading > -500");
84  TGraph* gr4 = treeInterp.get("pat->heading");
85  gr4->SetName("grHeadNoWrap");
86  gr4->Write();
87 
88 
89 
90  f.Close();
91 
92 }
93 
94 
A class to interpolate sparse, but continuous data in a TTree.