FancyTTreeInterpolator.h
1 // -*- C++ -*-.
2 /**************************************************************************************************************
3  Author: Ben Strutt
4  Email: b.strutt.12@ucl.ac.uk
5 
6  Description:
7  Give this class a TTree plus a branch name to serve as an 'x-axis', normally this is a time.
8  FancyTTreeInterpolator generates TGraphs of any TTree branch variable as a function of your x-axis.
9  That allows us to do two slightly clever things.
10  The first slightly clever thing is that it sorts the data so it is x-axis (time) ordered.
11  The second slightly clever thing is that it can then interpolate the data to values between entries.
12  This interpolation is equivalent to TGraph::Eval.
13 **************************************************************************************************************/
14 
15 #ifndef FANCYTTREEINTERPOLATOR_H
16 #define FANCYTTREEINTERPOLATOR_H
17 
18 #include "TObject.h"
19 #include "TTree.h"
20 #include "TChain.h"
21 #include "TGraph.h"
22 #include "TROOT.h"
23 #include "TMath.h"
24 #include "TAxis.h"
25 #include "TCanvas.h"
26 
27 #include <iostream>
28 #include <exception>
29 #include <stdexcept>
30 
31 namespace Acclaim
32 {
33 
42 
43  public:
44  FancyTTreeInterpolator(TTree* t, TString xAxisText);
46 
47  void add(TString yAxisText);
48  void add(TString yAxisText, TString cut);
49  void add(TString yAxisText, Double_t wrapValue);
50  void add(TString yAxisText, TString cut, Double_t wrapValue);
51  Double_t interp(TString yAxisText, Double_t xAxisValue);
52  TGraph* get(TString yAxisText);
53  TGraph* makeSortedTGraph(TString yAxisText);
54  TGraph* makeSortedTGraph(TString yAxisText, TString cutString);
55  TGraph* makeSortedTGraph(TString yAxisText, Double_t wrapValue);
56  TGraph* makeSortedTGraph(TString yAxisText, TString cutString, Double_t wrapValue);
57 
58  TTree* fTree;
59  TString fXAxisText;
60  std::map<TString,TGraph*> fStringToGraph;
61  std::map<TString, Double_t> fStringToWrapValue;
62  Double_t fXmin;
63  Double_t fXmax;
64 
65  };
66 }
67 
68 #endif //FANCYTTREESORTERANDINTERPOLATOR_H
std::map< TString, TGraph * > fStringToGraph
Internally stored TGraphs, accessed by TTree branch name.
TString fXAxisText
Branch name with which the intepolater was initialized.
TGraph * makeSortedTGraph(TString yAxisText)
Makes a sorted TGraph from fTree->Draw() with no cuts.
Double_t fXmax
Stored x-axis lower limit.
TTree * fTree
TTree with which the intepolater was initialized.
Namespace which wraps everything in the library.
std::map< TString, Double_t > fStringToWrapValue
Internally stored wrapValues, accessed by TTree branch name.
void add(TString yAxisText)
Adds a TGraph to the interally stored TGraphs.
Double_t interp(TString yAxisText, Double_t xAxisValue)
Get interpolated yAxisText variable at xAxisValue (time).
A class to interpolate sparse, but continuous data in a TTree.
Double_t fXmin
Stored x-axis lower limit.
FancyTTreeInterpolator(TTree *t, TString xAxisText)
Constructor.