Belle II Software  release-05-02-19
FilterValueDataSet.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler (jakob.lettenbichler@oeaw.ac.at) *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/logging/Logger.h>
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include <limits> // std::numeric_limits
18 
19 
20 namespace Belle2 {
27  class SecIDPair {
28  public:
29  unsigned outer;
30  unsigned inner;
33  SecIDPair() { reset(); }
34 
36  void reset()
37  {
38  outer = std::numeric_limits<unsigned>::max();
39  inner = std::numeric_limits<unsigned>::max();
40  }
41 
44  bool isValid()
45  {
46  return ((outer == std::numeric_limits<unsigned>::max())
47  or (inner == std::numeric_limits<unsigned>::max()))
48  ? false : true;
49  }
50  };
51 
52 
53 
55  class SecIDTriplet {
56  public:
57  unsigned outer;
58  unsigned center;
59  unsigned inner;
62  SecIDTriplet() { reset(); }
63 
65  void reset()
66  {
67  outer = std::numeric_limits<unsigned>::max();
68  center = std::numeric_limits<unsigned>::max();
69  inner = std::numeric_limits<unsigned>::max();
70  }
71 
74  bool isValid()
75  {
76  return ((outer == std::numeric_limits<unsigned>::max())
77  or (center == std::numeric_limits<unsigned>::max())
78  or (inner == std::numeric_limits<unsigned>::max()))
79  ? false : true;
80  }
81  };
82 
83 
84 
86  class SecIDQuadruplet {
87  public:
88  unsigned outer;
89  unsigned outerCenter;
90  unsigned innerCenter;
91  unsigned inner;
95 
97  void reset()
98  {
99  outer = std::numeric_limits<unsigned>::max();
100  outerCenter = std::numeric_limits<unsigned>::max();
101  innerCenter = std::numeric_limits<unsigned>::max();
102  inner = std::numeric_limits<unsigned>::max();
103  }
104 
107  bool isValid()
108  {
109  return ((outer == std::numeric_limits<unsigned>::max())
110  or (outerCenter == std::numeric_limits<unsigned>::max())
111  or (innerCenter == std::numeric_limits<unsigned>::max())
112  or (inner == std::numeric_limits<unsigned>::max()))
113  ? false : true;
114  }
115  };
116 
117 
118 
120  template <class SecIDSetType>
121  class FilterValueDataSet {
122  protected:
124  std::map<std::string, double> m_values;
125 
126  public:
127 
129  unsigned expNo;
130 
132  unsigned runNo;
133 
135  unsigned evtNo;
136 
138  unsigned trackNo;
139 
141  int pdg;
142 
144  SecIDSetType secIDs;
145 
146 
148 
150  explicit FilterValueDataSet(std::vector<std::string> filterNames) :
151  expNo(std::numeric_limits<unsigned>::max()),
152  runNo(std::numeric_limits<unsigned>::max()),
153  evtNo(std::numeric_limits<unsigned>::max()),
154  trackNo(std::numeric_limits<unsigned>::max()),
155  pdg(std::numeric_limits<int>::max())
156  {
157  for (auto name : filterNames) {
158  m_values.insert({name, std::numeric_limits<double>::max()});
159  B2DEBUG(60, "FilterValueDataSet::constructor: filterName " << name << " has been added.");
160  }
161  B2DEBUG(50, "FilterValueDataSet::constructor: " << m_values.size() << " filters have been added.");
162  }
163 
165  void setValueOfFilter(std::string filterName, double value)
166  {
167  auto it = m_values.find(filterName);
168  if (it == m_values.end()) {
169  B2ERROR("FilterValueDataSet::setValueOfFilter: filterName " << filterName
170  << "is not known, value " << value
171  << " will NOT be added!");
172  return;
173  }
174  it->second = value;
175  }
176 
178  double* getValuePtr(std::string filterName)
179  {
180  double* valuePtr = nullptr;
181  auto it = m_values.find(filterName);
182  if (it != m_values.end()) {
183  valuePtr = &it->second;
184  } else { B2WARNING("filter could not be found, returning nullptr instead!"); }
185  return valuePtr;
186  }
187 
189  void reset()
190  {
191  expNo = std::numeric_limits<unsigned>::max();
192  runNo = std::numeric_limits<unsigned>::max();
193  evtNo = std::numeric_limits<unsigned>::max();
194  trackNo = std::numeric_limits<unsigned>::max();
195  pdg = std::numeric_limits<int>::max();
196  secIDs.reset();
197  for (auto& entry : m_values) {
198  entry.second = std::numeric_limits<double>::max();
199  }
200  }
201 
204  bool isValid()
205  {
206  if (expNo == std::numeric_limits<unsigned>::max()) return false;
207  if (runNo == std::numeric_limits<unsigned>::max()) return false;
208  if (evtNo == std::numeric_limits<unsigned>::max()) return false;
209  if (trackNo == std::numeric_limits<unsigned>::max()) return false;
210  if (pdg == std::numeric_limits<int>::max()) return false;
211  for (auto& entry : m_values) {
212  if (entry.second == std::numeric_limits<double>::max()) return false;
213  }
214  return secIDs.isValid();
215  }
216  };
217 
219 }
220 
Belle2::SecIDTriplet::center
unsigned center
id of center sector.
Definition: FilterValueDataSet.h:66
Belle2::SecIDQuadruplet
allows to set outer, outerCenter, innerCenter and inner secID.
Definition: FilterValueDataSet.h:94
Belle2::SecIDTriplet
allows to set outer, center and inner secID.
Definition: FilterValueDataSet.h:63
Belle2::SecIDPair::inner
unsigned inner
id of inner sector.
Definition: FilterValueDataSet.h:38
Belle2::SecIDPair::isValid
bool isValid()
checks if any value is still not set and returns false if that is the case.
Definition: FilterValueDataSet.h:52
Belle2::SecIDPair::outer
unsigned outer
id of outer sector.
Definition: FilterValueDataSet.h:37
Belle2::SecIDTriplet::SecIDTriplet
SecIDTriplet()
constructor - resets all values to outer = std::numeric_limits< unsigned>::max();
Definition: FilterValueDataSet.h:70
Belle2::FilterValueDataSet::reset
void reset()
resets all values stored to std::numeric_limits< double>::max().
Definition: FilterValueDataSet.h:197
Belle2::SecIDTriplet::inner
unsigned inner
id of inner sector.
Definition: FilterValueDataSet.h:67
Belle2::FilterValueDataSet
contains the relevant information needed for filling a TTree containing train-data for the secMap.
Definition: FilterValueDataSet.h:129
Belle2::FilterValueDataSet::secIDs
SecIDSetType secIDs
contains the secIDs.
Definition: FilterValueDataSet.h:152
Belle2::FilterValueDataSet::evtNo
unsigned evtNo
number of the event this dataset is taken from.
Definition: FilterValueDataSet.h:143
Belle2::SecIDQuadruplet::innerCenter
unsigned innerCenter
id of inner-center sector.
Definition: FilterValueDataSet.h:98
Belle2::FilterValueDataSet::isValid
bool isValid()
checks if any value is still not set and returns false if that is the case.
Definition: FilterValueDataSet.h:212
Belle2::SecIDQuadruplet::outerCenter
unsigned outerCenter
id of outer-center sector.
Definition: FilterValueDataSet.h:97
Belle2::SecIDQuadruplet::reset
void reset()
sets all values to outer = std::numeric_limits< unsigned>::max();
Definition: FilterValueDataSet.h:105
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SecIDQuadruplet::inner
unsigned inner
id of inner sector.
Definition: FilterValueDataSet.h:99
Belle2::FilterValueDataSet::runNo
unsigned runNo
number of the run this dataset is taken from.
Definition: FilterValueDataSet.h:140
Belle2::FilterValueDataSet::expNo
unsigned expNo
number of the experiment this dataset is taken from.
Definition: FilterValueDataSet.h:137
Belle2::SecIDQuadruplet::isValid
bool isValid()
checks if any value is still not set and returns false if that is the case.
Definition: FilterValueDataSet.h:115
Belle2::SecIDPair::SecIDPair
SecIDPair()
constructor - resets all values to outer = std::numeric_limits< unsigned>::max();
Definition: FilterValueDataSet.h:41
Belle2::FilterValueDataSet::trackNo
unsigned trackNo
number of the reference track this dataset is taken from (its ID in the datastore).
Definition: FilterValueDataSet.h:146
Belle2::FilterValueDataSet::pdg
int pdg
Pdg given by reference track.
Definition: FilterValueDataSet.h:149
Belle2::FilterValueDataSet::FilterValueDataSet
FilterValueDataSet(std::vector< std::string > filterNames)
constructor, expects to get a vector of names for filters.
Definition: FilterValueDataSet.h:158
Belle2::SecIDQuadruplet::outer
unsigned outer
id of outer sector.
Definition: FilterValueDataSet.h:96
Belle2::SecIDQuadruplet::SecIDQuadruplet
SecIDQuadruplet()
constructor - resets all values to outer = std::numeric_limits< unsigned>::max();
Definition: FilterValueDataSet.h:102
Belle2::SecIDTriplet::isValid
bool isValid()
checks if any value is still not set and returns false if that is the case.
Definition: FilterValueDataSet.h:82
Belle2::FilterValueDataSet::setValueOfFilter
void setValueOfFilter(std::string filterName, double value)
for given filterName a value is set.
Definition: FilterValueDataSet.h:173
Belle2::SecIDTriplet::reset
void reset()
sets all values to outer = std::numeric_limits< unsigned>::max();
Definition: FilterValueDataSet.h:73
Belle2::FilterValueDataSet::m_values
std::map< std::string, double > m_values
map containing a value for each key==name of filter.
Definition: FilterValueDataSet.h:132
Belle2::FilterValueDataSet::getValuePtr
double * getValuePtr(std::string filterName)
returns pointer to value of given filterName, nullptr if filterName has not been found.
Definition: FilterValueDataSet.h:186
Belle2::SecIDPair::reset
void reset()
sets all values to outer = std::numeric_limits< unsigned>::max();
Definition: FilterValueDataSet.h:44
Belle2::SecIDTriplet::outer
unsigned outer
id of outer sector.
Definition: FilterValueDataSet.h:65