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