Belle II Software  release-06-00-14
HistogramFactory.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <tracking/dqmUtils/DQMHistoModuleBase.h>
12 
13 namespace Belle2::HistogramFactory {
20  template <typename AType>
21  class Parameter {
22  public:
25  explicit Parameter(const AType& defaultValue) :
26  m_value(defaultValue), m_temporaryValue(defaultValue), m_isSet(false), m_isSetTemporarily(false)
27  {}
28 
31  void Set(const AType& value);
34  void Set(const Parameter<AType>& parameter);
37  void SetTemporarily(const AType& value);
40  void SetTemporarily(const Parameter<AType>& parameter);
41 
44  AType Get();
45 
46  private:
48  AType m_value;
52  bool m_isSet;
55  };
56 
59  template <class AType>
60  void Parameter<AType>::Set(const AType& value)
61  {
62  m_value = value;
63  m_isSet = true;
64  }
65 
68  template <class AType>
69  void Parameter<AType>::Set(const Parameter<AType>& parameter)
70  {
71  if (parameter.m_isSet)
72  Set(parameter.m_value);
73  }
74 
78  template <class AType>
79  void Parameter<AType>::SetTemporarily(const AType& value)
80  {
81  m_temporaryValue = value;
82  m_isSetTemporarily = true;
83  }
84 
87  template <class AType>
89  {
90  if (parameter.m_isSet)
91  SetTemporarily(parameter.m_value);
92  }
93 
96  template <class AType>
98  {
99  if (m_isSetTemporarily) {
100  m_isSetTemporarily = false;
101  return m_temporaryValue;
102  } else {
103  return m_value;
104  }
105  }
106 
109  class Axis {
110  public:
112  Axis() {}
113 
119  Axis(int nbins, double low, double up, std::string title)
120  {
121  m_nbins.Set(nbins);
122  m_low.Set(low);
123  m_up.Set(up);
124  m_title.Set(title);
125  }
126 
128  Axis& nbins(int nbins) { m_nbins.Set(nbins); return *this; }
130  Axis& low(double low) { m_low.Set(low); return *this; }
132  Axis& up(double up) { m_up.Set(up); return *this; }
134  Axis& title(std::string title) { m_title.Set(title); return *this; }
135 
136  private:
145 
146  friend class Factory;
147  };
148 
156  class Factory {
157  public:
160  explicit Factory(DQMHistoModuleBase* histoModule)
161  {
162  m_histoModule = histoModule;
163  }
164 
166  Factory& xAxis(const Axis& axis)
167  {
168  m_nbinsx.SetTemporarily(axis.m_nbins);
169  m_xlow.SetTemporarily(axis.m_low);
170  m_xup.SetTemporarily(axis.m_up);
171  m_xTitle.SetTemporarily(axis.m_title);
172 
173  return *this;
174  }
175 
177  Factory& yAxis(const Axis& axis)
178  {
179  m_nbinsy.SetTemporarily(axis.m_nbins);
180  m_ylow.SetTemporarily(axis.m_low);
181  m_yup.SetTemporarily(axis.m_up);
182  m_yTitle.SetTemporarily(axis.m_title);
183 
184  return *this;
185  }
186 
188  Factory& xAxisDefault(const Axis& axis)
189  {
190  m_nbinsx.Set(axis.m_nbins);
191  m_xlow.Set(axis.m_low);
192  m_xup.Set(axis.m_up);
193  m_xTitle.Set(axis.m_title);
194 
195  return *this;
196  }
197 
199  Factory& yAxisDefault(const Axis& axis)
200  {
201  m_nbinsy.Set(axis.m_nbins);
202  m_ylow.Set(axis.m_low);
203  m_yup.Set(axis.m_up);
204  m_yTitle.Set(axis.m_title);
205 
206  return *this;
207  }
208 
211  TH1F* CreateTH1F(std::string name, std::string title);
213  TH2F* CreateTH2F(std::string name, std::string title);
214 
216  TH1F** CreateLayersTH1F(boost::format nameTemplate, boost::format titleTemplate);
218  TH2F** CreateLayersTH2F(boost::format nameTemplate, boost::format titleTemplate);
220  TH1F** CreateSensorsTH1F(boost::format nameTemplate, boost::format titleTemplate);
222  TH2F** CreateSensorsTH2F(boost::format nameTemplate, boost::format titleTemplate);
223 
228  Factory& nbinsxDefault(int nbinsx) { m_nbinsx.Set(nbinsx); return *this; }
229  Factory& xlowDefault(double xlow) { m_xlow.Set(xlow); return *this; }
230  Factory& xupDefault(double xup) { m_xup.Set(xup); return *this; }
231  Factory& nbinsyDefault(int nbinsy) { m_nbinsy.Set(nbinsy); return *this; }
232  Factory& ylowDefault(double ylow) { m_ylow.Set(ylow); return *this; }
233  Factory& yupDefault(double yup) { m_yup.Set(yup); return *this; }
234  Factory& xTitleDefault(std::string xTitle) { m_xTitle.Set(xTitle); return *this; }
235  Factory& yTitleDefault(std::string yTitle) { m_yTitle.Set(yTitle); return *this; }
236  Factory& zTitleDefault(std::string zTitle) { m_zTitle.Set(zTitle); return *this; }
243  Factory& nbinsx(int nbinsx) { m_nbinsx.SetTemporarily(nbinsx); return *this; }
244  Factory& xlow(double xlow) { m_xlow.SetTemporarily(xlow); return *this; }
245  Factory& xup(double xup) { m_xup.SetTemporarily(xup); return *this; }
246  Factory& nbinsy(int nbinsy) { m_nbinsy.SetTemporarily(nbinsy); return *this; }
247  Factory& ylow(double ylow) { m_ylow.SetTemporarily(ylow); return *this; }
248  Factory& yup(double yup) { m_yup.SetTemporarily(yup); return *this; }
249  Factory& xTitle(std::string xTitle) { m_xTitle.SetTemporarily(xTitle); return *this; }
250  Factory& yTitle(std::string yTitle) { m_yTitle.SetTemporarily(yTitle); return *this; }
251  Factory& zTitle(std::string zTitle) { m_zTitle.SetTemporarily(zTitle); return *this; }
254  private:
257 
267  };
268 }
This class serves as a base for the TrackDQMModule and AlignDQMModule (and possibly other DQM histogr...
This class unites some parameters for Factory which describe one axis of histogram.
Parameter< double > m_low
lower boundary of axis range
Parameter< std::string > m_title
title of axis
Axis & nbins(int nbins)
Set value of nbins.
Axis & title(std::string title)
Set value of title.
Axis(int nbins, double low, double up, std::string title)
Constructor.
Parameter< double > m_up
upper boundary of axis range
Axis & up(double up)
Set value of up.
Parameter< int > m_nbins
number of bins in the axis
Axis & low(double low)
Set value of low.
This class is used for creating TH1F and TH2F objects.
TH2F * CreateTH2F(std::string name, std::string title)
Create TH2F with given name and title.
Factory & yAxisDefault(const Axis &axis)
Permanently copies parameters for y axis from given Axis.
Factory & xup(double xup)
Sets xup temporarily.
Factory & zTitle(std::string zTitle)
Sets zTitle temporarily.
Factory & xTitleDefault(std::string xTitle)
Sets xTitle permanently.
TH1F ** CreateLayersTH1F(boost::format nameTemplate, boost::format titleTemplate)
Create TH1F array for layers from given name template and title template.
Factory & ylowDefault(double ylow)
Sets ylow permanently.
Parameter< std::string > m_zTitle
title of the z axis
TH2F ** CreateLayersTH2F(boost::format nameTemplate, boost::format titleTemplate)
Create TH2F array for layers from given name template and title template.
Factory & xlowDefault(double xlow)
Sets xlow permanently.
Parameter< double > m_xup
upper boundary of x axis range
Factory & xupDefault(double xup)
Sets xup permanently.
Parameter< std::string > m_yTitle
title of the y axis
Factory & nbinsx(int nbinsx)
Sets nbinsx temporarily.
Parameter< int > m_nbinsy
number of bins along the y axis
Factory & xAxis(const Axis &axis)
Temporarily copies parameters for x axis from given Axis.
TH1F * CreateTH1F(std::string name, std::string title)
Create TH1F with given name and title.
Factory & nbinsy(int nbinsy)
Sets nbinsy temporarily.
TH2F ** CreateSensorsTH2F(boost::format nameTemplate, boost::format titleTemplate)
Create TH2F array for sensors from given name template and title template.
Parameter< double > m_ylow
lower boundary of y axis range
Factory & nbinsyDefault(int nbinsy)
Sets nbinsy permanently.
Factory & ylow(double ylow)
Sets ylow temporarily.
Factory & yTitleDefault(std::string yTitle)
Sets yTitle permanently.
Factory & yTitle(std::string yTitle)
Sets yTitle temporarily.
Factory & yAxis(const Axis &axis)
Temporarily copies parameters for y axis from given Axis.
Factory(DQMHistoModuleBase *histoModule)
Constructor.
Factory & zTitleDefault(std::string zTitle)
Sets zTitle permanently.
Parameter< int > m_nbinsx
number of bins along the x axis
Factory & xAxisDefault(const Axis &axis)
Permanently copies parameters for x axis from given Axis.
Parameter< std::string > m_xTitle
title of the x axis
Factory & yup(double yup)
Sets yup temporarily.
Parameter< double > m_yup
upper boundary of y axis range
Factory & yupDefault(double yup)
Sets yup permanently.
Factory & xTitle(std::string xTitle)
Sets xTitle temporarily.
Parameter< double > m_xlow
lower boundary of x axis range
TH1F ** CreateSensorsTH1F(boost::format nameTemplate, boost::format titleTemplate)
Create TH1F array for sensors from given name template and title template.
DQMHistoModuleBase * m_histoModule
DQM histogram module on which the Create- functions are called to create histograms.
Factory & nbinsxDefault(int nbinsx)
Sets nbinsx permanently.
Factory & xlow(double xlow)
Sets xlow temporarily.
This class represents a quantity which value can be set both permanently and temporarily.
void Set(const Parameter< AType > &parameter)
Copy permanent value from another parameter but only if its permanent value is set.
AType Get()
Returns value of the inner quantity.
void SetTemporarily(const Parameter< AType > &parameter)
Copy temporary value from another parameter but only if its temporary value is set.
Parameter(const AType &defaultValue)
Constructor.
bool m_isSet
determines if the permanent value is set
bool m_isSetTemporarily
determines if the temporary value is set
void Set(const AType &value)
Permanently sets inner quantity to given value.
void SetTemporarily(const AType &value)
Temporarily sets inner quantity to given value.