RDFAnalysis  0.1.1
Physics analysis with ROOT::RDataFrame
Node.h
Go to the documentation of this file.
1 #ifndef RDFAnalysis_Node_H
2 #define RDFAnalysis_Node_H
3 
4 // Package includes
6 #include "RDFAnalysis/NodeBase.h"
7 #include "RDFAnalysis/NodeFwd.h"
8 
14 namespace RDFAnalysis {
15 
31  template <typename Detail>
32  class Node : public NodeBase
33  {
34  public:
35  // Typedefs
37  using detail_t = Detail;
38 
49  template <typename F>
51  const std::string& name,
52  F f,
53  const ColumnNames_t& columns = {})
54  {
55  NodeBase::Define(name, f, columns);
56  return this;
57  }
58 
69  const std::string& name,
70  const std::string& expression)
71  {
72  NodeBase::Define(name, expression);
73  return this;
74  }
75 
89  const std::string& name,
90  const std::string& expression,
91  const ColumnNames_t& columns)
92  {
93  NodeBase::Define(name, expression, columns);
94  return this;
95  }
96 
114  template <
115  std::size_t N,
116  typename F,
117  typename Ret_t = typename ROOT::TTraits::CallableTraits<F>::ret_type>
118  std::enable_if_t<N==std::tuple_size<Ret_t>::value, Node>* Define(
119  const std::array<std::string, N>& names,
120  F f,
121  const ColumnNames_t& columns)
122  {
123  NodeBase::Define(names, f, columns);
124  return this;
125  }
126 
139  template <typename F>
140  std::enable_if_t<std::is_convertible<typename ROOT::TTraits::CallableTraits<F>::ret_type, std::tuple<bool, float>>::value, Node*> Filter(
141  F f,
142  const ColumnNames_t& columns = {},
143  const std::string& name = "",
144  const std::string& cutflowName = "",
146 
161  template <typename F>
162  std::enable_if_t<std::is_convertible<typename ROOT::TTraits::CallableTraits<F>::ret_type, bool>::value, Node*> Filter(
163  F f,
164  const ColumnNames_t& columns = {},
165  const std::string& name = "",
166  const std::string& cutflowName = "",
167  const std::string& weight = "",
169 
178  Node* Filter(
179  const std::string& expression,
180  const std::string& name = "",
181  const std::string& cutflowName = "",
182  const std::string& weight = "",
184 
197  template <typename F, typename W>
198  std::enable_if_t<!std::is_convertible<F, std::string>::value && !std::is_convertible<W, std::string>::value, Node*> Filter(
199  F f,
200  const ColumnNames_t& columns,
201  const std::string& name,
202  const std::string& cutflowName,
203  W w,
204  const ColumnNames_t& weightColumns = {},
206 
217  template <typename W>
219  const std::string& expression,
220  const std::string& name,
221  const std::string& cutflowName,
222  W w,
223  const ColumnNames_t& weightColumns = {},
225 
227  auto children() { return as_range(m_children); }
229  auto children() const { return as_range(m_children); }
230 
232  Detail& detail() { return m_detail; }
234  const Detail& detail() const { return m_detail; }
235 
237  Node* parent() { return m_parent; }
239  const Node* parent() const { return m_parent; }
240 
242  bool isRoot() const { return m_parent == nullptr; }
243 
254  static std::unique_ptr<Node> createROOT(
255  const RNode& rnode,
256  std::unique_ptr<IBranchNamer>&& namer,
257  bool isMC,
258  const std::string& name = "ROOT",
259  const std::string& cutflowName = "Number of events",
260  const std::string& weight = "",
262  {
263  return std::unique_ptr<Node>(
264  new Node(rnode, std::move(namer), isMC,
265  name, cutflowName, weight, strategy) );
266  }
267 
272  void run(ULong64_t printEvery);
273 
282  void run(ULong64_t printEvery, ULong64_t total);
283 
294  template <typename Monitor>
295  void run(Monitor monitor);
296 
297  private:
307  Node(
308  const RNode& rnode,
309  std::unique_ptr<IBranchNamer>&& namer,
310  bool isMC,
311  const std::string& name = "ROOT",
312  const std::string& cutflowName = "Number of events",
313  const std::string& weight = "",
315 
327  template <typename W>
328  Node(
329  const RNode& rnode,
330  std::unique_ptr<IBranchNamer>&& namer,
331  bool isMC,
332  const std::string& name,
333  const std::string& cutflowName,
334  W w,
335  const ColumnNames_t& columns,
336  WeightStrategy strategy);
337 
347  Node(
348  Node& parent,
349  std::map<std::string, RNode>&& rnodes,
350  const std::string& name,
351  const std::string& cutflowName,
352  const std::string& weight,
353  WeightStrategy strategy);
354 
355 
367  template <typename W>
368  Node(
369  Node& parent,
370  std::map<std::string, RNode>&& rnodes,
371  const std::string& name,
372  const std::string& cutflowName,
373  W w,
374  const ColumnNames_t& columns,
375  WeightStrategy strategy);
376 
378  Node* m_parent = nullptr;
379 
381  std::vector<std::unique_ptr<Node>> m_children;
382 
384  Detail m_detail;
385  }; //> end class Node
386 
387 } //> end namespace RDFAnalysis
388 #include "RDFAnalysis/Node.icc"
389 #endif //> !RDFAnalysis_Node_H
The base class for the Node classes.
Node * parent()
Get the parent of this node.
Definition: Node.h:237
const std::string & cutflowName() const
Get the name in a cutflow.
Definition: NodeBase.h:395
Base class for the Node classes.
Definition: NodeBase.h:41
Node * Define(const std::string &name, const std::string &expression, const ColumnNames_t &columns)
Define a new variable on this node.
Definition: Node.h:88
const std::map< std::string, RNode > & rnodes() const
Get the RNode objects.
Definition: NodeBase.h:404
bool isMC() const
Was &#39;MC&#39; mode activated?
Definition: NodeBase.h:401
ROOT::RDataFrame::ColumnNames_t ColumnNames_t
Helper typedef.
Definition: NodeBase.h:30
Detail detail_t
The type of the Detail on this node.
Definition: Node.h:37
std::enable_if_t< std::is_convertible< typename ROOT::TTraits::CallableTraits< F >::ret_type, std::tuple< bool, float > >::value, Node * > Filter(F f, const ColumnNames_t &columns={}, const std::string &name="", const std::string &cutflowName="", WeightStrategy strategy=WeightStrategy::Default)
Create a filter on this node.
const std::string & name() const
Get the name.
Definition: NodeBase.h:392
std::enable_if_t<!std::is_convertible< F, std::string >{}, T > enable_ifn_string_t
Reduce size of enable_if statements.
Definition: Helpers.h:114
bool isRoot() const
Is the node the root?
Definition: Node.h:242
Node * Define(const std::string &name, const std::string &expression)
Define a new variable on this node.
Definition: Node.h:68
const Detail & detail() const
(Const) get the node details
Definition: Node.h:234
Definition: CutflowDetail.h:11
Class to represent a single step in the analysis process.
Definition: Node.h:32
auto as_range(Container &container)
Make a range_t from a container.
Definition: Helpers.h:44
WeightStrategy
enum class to describe how weights are applied.
Definition: WeightStrategy.h:33
const IBranchNamer & namer() const
The namer.
Definition: NodeBase.h:409
Forward declaration for the node class.
auto children()
Allow access to iterate over the child nodes.
Definition: Node.h:227
std::enable_if_t< N==std::tuple_size< Ret_t >::value, Node > * Define(const std::array< std::string, N > &names, F f, const ColumnNames_t &columns)
Define several new variables on this node in a single statement.
Definition: Node.h:118
static std::unique_ptr< Node > createROOT(const RNode &rnode, std::unique_ptr< IBranchNamer > &&namer, bool isMC, const std::string &name="ROOT", const std::string &cutflowName="Number of events", const std::string &weight="", WeightStrategy strategy=WeightStrategy::Default)
Create the root node of the tree.
Definition: Node.h:254
enable_ifn_string_t< F, NodeBase * > Define(const std::string &name, F f, const ColumnNames_t &columns={})
Define a new variable on this node.
Detail & detail()
Get the node details.
Definition: Node.h:232
ROOT::RDF::RNode RNode
Helper typedef.
Definition: NodeBase.h:28
auto children() const
Allow (const) access to iterate over the child nodes.
Definition: Node.h:229
Empty detail class.
enable_ifn_string_t< F, Node * > Define(const std::string &name, F f, const ColumnNames_t &columns={})
Define a new variable on this node.
Definition: Node.h:50
void run(ULong64_t printEvery)
Trigger the run.
const Node * parent() const
(const) get the parent of this node
Definition: Node.h:239