Belle II Software  release-05-02-19
ClosedLowerBoundedSet.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Eugenio Paoloni *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <tracking/trackFindingVXD/filterMap/filterFramework/TBranchLeafType.h>
14 #include <TBranch.h>
15 #include <TTree.h>
16 
17 #include <framework/logging/Logger.h>
18 
19 namespace Belle2 {
31  template< typename MinType >
32  class ClosedLowerBoundedSet {
33  public:
34 
36  explicit ClosedLowerBoundedSet(MinType min): m_min(min) {};
37 
40 
46  template< class VariableType >
47  inline bool contains(const VariableType& x) const { return m_min <= x ;};
48 
58  void persist(TTree* t, const std::string& branchName, const std::string& variableName)
59  {
60 
61  std::string leafList;
62  leafList += variableName;
63  leafList += "_min/";
64  leafList += TBranchLeafType(m_min);
65  TBranch* branch = new TBranch(t, branchName.c_str() , & m_min, leafList.c_str());
66  t->GetListOfBranches()->Add(branch);
67  }
68 
73  void setBranchAddress(TTree* t, const std::string& branchName,
74  const std::string& /*variableName*/)
75  {
76  if (t->SetBranchAddress(branchName.c_str(), & m_min) < 0) B2FATAL("ClosedLowerBoundedSet: branch address not valid");
77  }
78 
80  MinType getInf(void) const { return m_min; } ;
81 
82 
88  std::string getNameAndReference(std::vector< std::pair<char, void*> >* pointers = nullptr, const std::string& varname = "X")
89  {
90  std::string minVal = std::to_string(m_min);
91  // if pointer to vector is provided fill it
92  if (pointers != nullptr) {
93  // use the position in the vector as unique identifier
94  minVal = "#" + std::to_string(pointers->size());
95  (*pointers).push_back({TBranchLeafType(m_min), &m_min});
96  }
97  return ("(" + minVal + " <= " + varname + ")");
98  }
99 
100  private:
102  MinType m_min;
103  };
104 
105 
107 }
Belle2::TBranchLeafType
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.
Definition: TBranchLeafType.h:29
Belle2::ClosedLowerBoundedSet::getNameAndReference
std::string getNameAndReference(std::vector< std::pair< char, void * > > *pointers=nullptr, const std::string &varname="X")
generates a "name" and fills the vector with the variable references
Definition: ClosedLowerBoundedSet.h:96
Belle2::ClosedLowerBoundedSet::m_min
MinType m_min
the minimum value for this range
Definition: ClosedLowerBoundedSet.h:110
Belle2::ClosedLowerBoundedSet::ClosedLowerBoundedSet
ClosedLowerBoundedSet()
Constructor without argument.
Definition: ClosedLowerBoundedSet.h:47
Belle2::ClosedLowerBoundedSet::contains
bool contains(const VariableType &x) const
Method used by the filter tools to decide on the fate of the pair.
Definition: ClosedLowerBoundedSet.h:55
Belle2::ClosedLowerBoundedSet::persist
void persist(TTree *t, const std::string &branchName, const std::string &variableName)
Creates and sets the addresses of the leaves to store the min value.
Definition: ClosedLowerBoundedSet.h:66
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ClosedLowerBoundedSet::setBranchAddress
void setBranchAddress(TTree *t, const std::string &branchName, const std::string &)
sets the branch address for m_min
Definition: ClosedLowerBoundedSet.h:81
Belle2::ClosedLowerBoundedSet::getInf
MinType getInf(void) const
Accessor to the inf of the set (which coincides with the min)
Definition: ClosedLowerBoundedSet.h:88