Belle II Software  release-08-01-10
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 
58  template <class AType>
59  void Parameter<AType>::Set(const AType& value)
60  {
61  m_value = value;
62  m_isSet = true;
63  }
64 
66  template <class AType>
67  void Parameter<AType>::Set(const Parameter<AType>& parameter)
68  {
69  if (parameter.m_isSet)
70  Set(parameter.m_value);
71  }
72 
74  template <class AType>
75  void Parameter<AType>::SetTemporarily(const AType& value)
76  {
77  m_temporaryValue = value;
78  m_isSetTemporarily = true;
79  }
80 
82  template <class AType>
84  {
85  if (parameter.m_isSet)
86  SetTemporarily(parameter.m_value);
87  }
88 
91  template <class AType>
93  {
94  if (m_isSetTemporarily) {
95  m_isSetTemporarily = false;
96  return m_temporaryValue;
97  } else {
98  return m_value;
99  }
100  }
101 
104  class Axis {
105  public:
107  Axis() {}
108 
114  Axis(int nbins, double low, double up, std::string title)
115  {
116  m_nbins.Set(nbins);
117  m_low.Set(low);
118  m_up.Set(up);
119  m_title.Set(title);
120  }
121 
123  Axis& nbins(int nbins) { m_nbins.Set(nbins); return *this; }
125  Axis& low(double low) { m_low.Set(low); return *this; }
127  Axis& up(double up) { m_up.Set(up); return *this; }
129  Axis& title(std::string title) { m_title.Set(title); return *this; }
130 
131  private:
140 
141  friend class Factory;
142  };
143 
151  class Factory {
152  public:
155  explicit Factory(DQMHistoModuleBase* histoModule)
156  {
157  m_histoModule = histoModule;
158  }
159 
161  Factory& xAxis(const Axis& axis)
162  {
163  m_nbinsx.SetTemporarily(axis.m_nbins);
164  m_xlow.SetTemporarily(axis.m_low);
165  m_xup.SetTemporarily(axis.m_up);
166  m_xTitle.SetTemporarily(axis.m_title);
167 
168  return *this;
169  }
170 
172  Factory& yAxis(const Axis& axis)
173  {
174  m_nbinsy.SetTemporarily(axis.m_nbins);
175  m_ylow.SetTemporarily(axis.m_low);
176  m_yup.SetTemporarily(axis.m_up);
177  m_yTitle.SetTemporarily(axis.m_title);
178 
179  return *this;
180  }
181 
183  Factory& xAxisDefault(const Axis& axis)
184  {
185  m_nbinsx.Set(axis.m_nbins);
186  m_xlow.Set(axis.m_low);
187  m_xup.Set(axis.m_up);
188  m_xTitle.Set(axis.m_title);
189 
190  return *this;
191  }
192 
194  Factory& yAxisDefault(const Axis& axis)
195  {
196  m_nbinsy.Set(axis.m_nbins);
197  m_ylow.Set(axis.m_low);
198  m_yup.Set(axis.m_up);
199  m_yTitle.Set(axis.m_title);
200 
201  return *this;
202  }
203 
206  TH1F* CreateTH1F(std::string name, std::string title);
208  TH2F* CreateTH2F(std::string name, std::string title);
209 
211  TH1F** CreateLayersTH1F(boost::format nameTemplate, boost::format titleTemplate);
213  TH2F** CreateLayersTH2F(boost::format nameTemplate, boost::format titleTemplate);
215  TH1F** CreateSensorsTH1F(boost::format nameTemplate, boost::format titleTemplate);
217  TH2F** CreateSensorsTH2F(boost::format nameTemplate, boost::format titleTemplate);
218 
223  Factory& nbinsxDefault(int nbinsx) { m_nbinsx.Set(nbinsx); return *this; }
224  Factory& xlowDefault(double xlow) { m_xlow.Set(xlow); return *this; }
225  Factory& xupDefault(double xup) { m_xup.Set(xup); return *this; }
226  Factory& nbinsyDefault(int nbinsy) { m_nbinsy.Set(nbinsy); return *this; }
227  Factory& ylowDefault(double ylow) { m_ylow.Set(ylow); return *this; }
228  Factory& yupDefault(double yup) { m_yup.Set(yup); return *this; }
229  Factory& xTitleDefault(std::string xTitle) { m_xTitle.Set(xTitle); return *this; }
230  Factory& yTitleDefault(std::string yTitle) { m_yTitle.Set(yTitle); return *this; }
231  Factory& zTitleDefault(std::string zTitle) { m_zTitle.Set(zTitle); return *this; }
238  Factory& nbinsx(int nbinsx) { m_nbinsx.SetTemporarily(nbinsx); return *this; }
239  Factory& xlow(double xlow) { m_xlow.SetTemporarily(xlow); return *this; }
240  Factory& xup(double xup) { m_xup.SetTemporarily(xup); return *this; }
241  Factory& nbinsy(int nbinsy) { m_nbinsy.SetTemporarily(nbinsy); return *this; }
242  Factory& ylow(double ylow) { m_ylow.SetTemporarily(ylow); return *this; }
243  Factory& yup(double yup) { m_yup.SetTemporarily(yup); return *this; }
244  Factory& xTitle(std::string xTitle) { m_xTitle.SetTemporarily(xTitle); return *this; }
245  Factory& yTitle(std::string yTitle) { m_yTitle.SetTemporarily(yTitle); return *this; }
246  Factory& zTitle(std::string zTitle) { m_zTitle.SetTemporarily(zTitle); return *this; }
249  private:
252 
262  };
263 }
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.