PandaRoot
PndSimpleNtuple.h
Go to the documentation of this file.
1 // -------------------------------------------------------------------------------
2 // --------- PndSimpleNtuple --------
3 // -------------------------------------------------------------------------------
4 //
5 // Represents a simplified N-Tuple based on a ROOT TTree.
6 //
7 // Branches of type double, float or int are created on the fly with the command
8 //
9 // 'Column(TString name, double/float/int value);'
10 //
11 // At the end of each event (i.e. when the N-Tuple should be filled) either
12 //
13 // 'DumpData()' or
14 // 'AcceptData()'
15 //
16 // has to be called. The method 'AcceptData()' is a conditional fill in case a
17 // certain precut is fulfilled, which can be set either in the constructor with
18 //
19 // PndSimpleNtuple(TString name, TString title, TString <precut>)
20 //
21 // or with the method
22 //
23 // SetPrecut(TString precut)
24 //
25 // which can even be changed inbetween. The precut is a TFormula directly based
26 // on the branches of the TTree.
27 //
28 // -------------------------------------------------------------------------------
29 
30 #ifndef PndSimpleNtuple_H
31 #define PndSimpleNtuple_H 1
32 
33 #include "TString.h"
34 #include "TTree.h"
35 #include "TTreeFormula.h"
36 #include <iostream>
37 #include <map>
38 #include <vector>
39 
41  public:
42  PndSimpleNtuple(TString name, TString title, TString precut = "");
43 
45  {
46  if (fFml != 0)
47  delete fFml;
48  }
49 
50  void Column(const TString &name, double value); // sets double value of a variable 'name'
51  void Column(const TString &name, float value); // sets float value of a variable 'name'
52  void Column(const TString &name, int value); // sets integer value of a variable 'name'
53  void Column(const TString &name, bool value); // sets bool value of a variable 'name'
54 
55  void ColumnD(const TString &name, double value) { Column(name, value); } // sets double value of a variable 'name'
56  void ColumnF(const TString &name, float value) { Column(name, value); } // sets float value of a variable 'name'
57  void ColumnI(const TString &name, int value) { Column(name, value); } // sets integer value of a variable 'name'
58  void ColumnB(const TString &name, bool value) { Column(name, value); } // sets bool value of a variable 'name'
59 
60  // void Column(TString name, Double_t *vpointer, TString idxvar); // sets double value array of a variable 'name', index variable 'idxvar'
61  // void Column(TString name, Float_t *vpointer, TString idxvar); // sets float value array of a variable 'name', index variable 'idxvar'
62  // void Column(TString name, Int_t *vpointer, TString idxvar); // sets integer value array of a variable 'name', index variable 'idxvar'
63  // void Column(TString name, Bool_t *vpointer, TString idxvar); // sets bool value of array a variable 'name', index variable 'idxvar'
64 
65  bool DumpData()
66  {
67  fTree->Fill();
68  fTmpTree->Reset();
69  return true;
70  } // writes the current event
71  bool Accept(); // check whether entry fulfills cut
72  bool AcceptData()
73  {
74  if (Accept()) {
75  DumpData();
76  return true;
77  }
78  return false;
79  } // writes current event if accepted
80 
81  TTree *GetTree() { return fTree; }
82  double GetCurrentValue(TString name);
83  void SetPrecut(TString precut);
84  bool BranchExists(TString name) { return (fBrTypes.find(name) != fBrTypes.end()); }
85  int ShowBranches();
86 
87  private:
88  TTree *fTree;
89  TTree *fTmpTree;
90 
91  std::map<TString, double> fDValues;
92  std::map<TString, float> fFValues;
93  std::map<TString, int> fIValues;
94  std::map<TString, char> fBValues;
95 
96  std::map<TString, int> fBrTypes;
97 
98  TString fPrecut; // precut in TTreeFormula notation
99  TTreeFormula *fFml; // the actual formula
100 };
101 
102 #endif
void SetPrecut(TString precut)
void ColumnD(const TString &name, double value)
void ColumnB(const TString &name, bool value)
PndSimpleNtuple(TString name, TString title, TString precut="")
bool BranchExists(TString name)
void ColumnI(const TString &name, int value)
void ColumnF(const TString &name, float value)
void Column(const TString &name, double value)
double GetCurrentValue(TString name)