CbmRoot
CbmUtils.h
Go to the documentation of this file.
1 #ifndef CBMUTILS_H_
2 #define CBMUTILS_H_
3 
4 #include <sstream> // for string, stringstream
5 #include <vector> // for vector
6 
7 class TCanvas;
8 class TH1;
9 class TH1D;
10 class TH2;
11 class TH2D;
12 
13 namespace Cbm {
14 
15  template<class T>
16  std::string ToString(const T& value) {
17  std::stringstream ss;
18  ss << (T) value;
19  return ss.str();
20  }
21 
22  template<class T>
23  std::string NumberToString(const T& value, int precision = 1) {
24  // First determine number of digits in float
25  std::string digis = ToString<int>(value);
26  int ndigis = digis.size();
27 
28  std::stringstream ss;
29  ss.precision(ndigis + precision);
30  ss << value;
31  return ss.str();
32  }
33 
34  /* Returns -1 if x<0, +1 if x>0, 0 if x==0 */
35  template<class T>
36  int Sign(const T& x) {
37  static const T ZERO = 0;
38  return (x > ZERO) ? 1 : ((x < ZERO) ? -1 : 0);
39  }
40 
41  void SaveCanvasAsImage(TCanvas* c,
42  const std::string& dir,
43  const std::string& option = "eps;png;gif");
44 
45  std::string FindAndReplace(const std::string& name,
46  const std::string& oldSubstr,
47  const std::string& newSubstr);
48 
49  std::vector<std::string> Split(const std::string& name, char delimiter);
50 
51  /*
52  * \brief Divide 1D histograms and return result histogram h = h1 / h2.
53  * \param[in] h1 Pointer to the first histogram.
54  * \param[in] h2 Pointer to the second histogram.
55  * \param[in] histName Name of the result histogram. if histName = "" then histName = h1->GetName() + "_divide"
56  * \param[in] scale Scale factor of result histogram.
57  * \param[in] titleYaxis Y axis title of result histogram.
58  */
59  TH1D* DivideH1(TH1* h1,
60  TH1* h2,
61  const std::string& histName = "",
62  double scale = 100.,
63  const std::string& titleYaxis = "Efficiency [%]");
64 
65 
66  /*
67  * \brief Divide 2D histograms and return result histogram h = h1 / h2.
68  * \param[in] h1 Pointer to the first histogram.
69  * \param[in] h2 Pointer to the second histogram.
70  * \param[in] histName Name of the result histogram. if histName = "" then histName = h1->GetName() + "_divide"
71  * \param[in] scale Scale factor of result histogram.
72  * \param[in] titleZaxis Z axis title of result histogram.
73  */
74  TH2D* DivideH2(TH2* h1,
75  TH2* h2,
76  const std::string& histName = "",
77  double scale = 100.,
78  const std::string& titleZaxis = "Efficiency [%]");
79 
80 } // namespace Cbm
81 
82 #endif /* CBMUTILS_H_ */
Cbm::FindAndReplace
string FindAndReplace(const string &name, const string &oldSubstr, const string &newSubstr)
Definition: CbmUtils.cxx:45
Cbm::DivideH2
TH2D * DivideH2(TH2 *h1, TH2 *h2, const string &histName, double scale, const string &titleZaxis)
Definition: CbmUtils.cxx:92
Cbm::Sign
int Sign(const T &x)
Definition: CbmUtils.h:36
Cbm::DivideH1
TH1D * DivideH1(TH1 *h1, TH1 *h2, const string &histName, double scale, const string &titleYaxis)
Definition: CbmUtils.cxx:70
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
Cbm::SaveCanvasAsImage
void SaveCanvasAsImage(TCanvas *c, const std::string &dir, const std::string &option)
Definition: CbmUtils.cxx:20
Cbm::NumberToString
std::string NumberToString(const T &value, int precision=1)
Definition: CbmUtils.h:23
NS_L1TrackFitter::ZERO
const fvec ZERO
Definition: L1TrackFitter.cxx:32
Cbm::ToString
std::string ToString(const T &value)
Definition: CbmUtils.h:16
Cbm::Split
vector< string > Split(const string &name, char delimiter)
Definition: CbmUtils.cxx:54
Cbm
Definition: CbmGeometryUtils.cxx:31