Belle II Software development
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
13namespace 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>
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 {
117 m_low.Set(low);
118 m_up.Set(up);
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
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
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; }
239 Factory& xlow(double xlow) { m_xlow.SetTemporarily(xlow); return *this; }
240 Factory& xup(double xup) { m_xup.SetTemporarily(xup); 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 & up(double up)
Set value of up.
Axis(int nbins, double low, double up, std::string title)
Constructor.
Parameter< double > m_up
upper boundary of axis range
Axis & low(double low)
Set value of low.
Axis & title(std::string title)
Set value of title.
Parameter< int > m_nbins
number of bins in the axis
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.
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.
Factory & xTitleDefault(std::string xTitle)
Sets xTitle permanently.
Parameter< std::string > m_zTitle
title of the z axis
Factory & xupDefault(double xup)
Sets xup permanently.
TH2F ** CreateLayersTH2F(boost::format nameTemplate, boost::format titleTemplate)
Create TH2F array for layers from given name template and title template.
Factory & ylow(double ylow)
Sets ylow temporarily.
Factory & zTitle(std::string zTitle)
Sets zTitle temporarily.
Factory & yupDefault(double yup)
Sets yup permanently.
Factory & xlowDefault(double xlow)
Sets xlow permanently.
Factory & yAxisDefault(const Axis &axis)
Permanently copies parameters for y axis from given Axis.
Factory & xlow(double xlow)
Sets xlow temporarily.
Factory & nbinsyDefault(int nbinsy)
Sets nbinsy permanently.
Parameter< double > m_xup
upper boundary of x axis range
Factory & nbinsy(int nbinsy)
Sets nbinsy temporarily.
Factory & nbinsx(int nbinsx)
Sets nbinsx temporarily.
Parameter< std::string > m_yTitle
title of the y axis
Factory & yTitleDefault(std::string yTitle)
Sets yTitle permanently.
Factory & yAxis(const Axis &axis)
Temporarily copies parameters for y axis from given Axis.
Parameter< int > m_nbinsy
number of bins along the y axis
Factory & yTitle(std::string yTitle)
Sets yTitle temporarily.
TH1F * CreateTH1F(std::string name, std::string title)
Create TH1F with given name and title.
Factory & nbinsxDefault(int nbinsx)
Sets nbinsx permanently.
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 & xAxisDefault(const Axis &axis)
Permanently copies parameters for x axis from given Axis.
Factory & zTitleDefault(std::string zTitle)
Sets zTitle permanently.
Factory(DQMHistoModuleBase *histoModule)
Constructor.
Parameter< int > m_nbinsx
number of bins along the x axis
Parameter< std::string > m_xTitle
title of the x axis
Parameter< double > m_yup
upper boundary of y axis range
Factory & xAxis(const Axis &axis)
Temporarily copies parameters for x axis from given Axis.
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.
Factory & yup(double yup)
Sets yup temporarily.
Factory & xup(double xup)
Sets xup temporarily.
DQMHistoModuleBase * m_histoModule
DQM histogram module on which the Create- functions are called to create histograms.
Factory & xTitle(std::string xTitle)
Sets xTitle 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.