FairRoot/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 
44  ~PndSimpleNtuple(){if (fFml!=0) delete fFml;}
45 
46  void Column(const TString &name, double value); // sets double value of a variable 'name'
47  void Column(const TString &name, float value); // sets float value of a variable 'name'
48  void Column(const TString &name, int value); // sets integer value of a variable 'name'
49  void Column(const TString &name, bool value); // sets bool value of a variable 'name'
50 
51  void ColumnD(const TString &name, double value) {Column(name, value);} // sets double value of a variable 'name'
52  void ColumnF(const TString &name, float value) {Column(name, value);} // sets float value of a variable 'name'
53  void ColumnI(const TString &name, int value) {Column(name, value);} // sets integer value of a variable 'name'
54  void ColumnB(const TString &name, bool value) {Column(name, value);} // sets bool value of a variable 'name'
55 
56  //void Column(TString name, Double_t *vpointer, TString idxvar); // sets double value array of a variable 'name', index variable 'idxvar'
57  //void Column(TString name, Float_t *vpointer, TString idxvar); // sets float value array of a variable 'name', index variable 'idxvar'
58  //void Column(TString name, Int_t *vpointer, TString idxvar); // sets integer value array of a variable 'name', index variable 'idxvar'
59  //void Column(TString name, Bool_t *vpointer, TString idxvar); // sets bool value of array a variable 'name', index variable 'idxvar'
60 
61  bool DumpData() { fTree->Fill(); fTmpTree->Reset(); return true; } // writes the current event
62  bool Accept(); // check whether entry fulfills cut
63  bool AcceptData() {if (Accept()) {DumpData(); return true;} return false; } // writes current event if accepted
64 
65  TTree* GetTree() {return fTree;}
66  double GetCurrentValue(TString name);
67  void SetPrecut(TString precut);
68  bool BranchExists(TString name) { return (fBrTypes.find(name)!=fBrTypes.end()); }
69  int ShowBranches();
70 
71 private:
72  TTree *fTree;
73  TTree *fTmpTree;
74 
75  std::map<TString, double> fDValues;
76  std::map<TString, float> fFValues;
77  std::map<TString, int> fIValues;
78  std::map<TString, char> fBValues;
79 
80  std::map<TString, int> fBrTypes;
81 
82  TString fPrecut; // precut in TTreeFormula notation
83  TTreeFormula *fFml; // the actual formula
84 };
85 
86 #endif
void SetPrecut(TString precut)
std::map< TString, double > fDValues
std::map< TString, float > fFValues
void ColumnD(const TString &name, double value)
TTreeFormula * fFml
std::map< TString, int > fIValues
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)
TString name
std::map< TString, char > fBValues
void Column(const TString &name, double value)
double GetCurrentValue(TString name)
std::map< TString, int > fBrTypes