container.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef root_container_hpp
  2. #define root_container_hpp
  3. #include <utility>
  4. #include "../filval/filval.hpp"
  5. #include "TH1.h"
  6. #include "TH2.h"
  7. #include "TGraph.h"
  8. #include <iostream>
  9. namespace filval::root {
  10. template <typename T>
  11. class ContainerTH1 : public Container<TH1>{
  12. private:
  13. void _fill(){
  14. container->Fill(value->get_value());
  15. }
  16. protected:
  17. Value<T> *value;
  18. ContainerTH1(TH1* container, const std::string &name, Value<T> *value)
  19. :Container<TH1>(container, name),
  20. value(value){ }
  21. };
  22. class ContainerTH1D : public ContainerTH1<double>{
  23. public:
  24. ContainerTH1D(const std::string& name, const std::string& title,
  25. int nbins, double low, double high, GenValue* value)
  26. :ContainerTH1<double>(NULL, name, dynamic_cast<Value<double>*>(value)){
  27. this->container = new TH1D(name.c_str(), title.c_str(), nbins, low, high);
  28. }
  29. };
  30. class ContainerTH1F : public ContainerTH1<float>{
  31. public:
  32. ContainerTH1F(const std::string& name, const std::string& title,
  33. int nbins, float low, float high, GenValue* value)
  34. :ContainerTH1<float>(NULL, name, dynamic_cast<Value<float>*>(value)){
  35. this->container = new TH1D(name.c_str(), title.c_str(), nbins, low, high);
  36. }
  37. };
  38. class ContainerTH1I : public ContainerTH1<int>{
  39. public:
  40. ContainerTH1I(const std::string& name, const std::string& title,
  41. int nbins, int low, int high, GenValue* value)
  42. :ContainerTH1<int>(NULL, name, dynamic_cast<Value<int>*>(value)){
  43. this->container = new TH1I(name.c_str(), title.c_str(), nbins, low, high);
  44. }
  45. };
  46. template <typename T>
  47. class ContainerTH2 : public Container<TH2>{
  48. private:
  49. void _fill(){
  50. std::pair<T, T> val = value->get_value();
  51. container->Fill(val.first, val.second);
  52. }
  53. protected:
  54. Value<std::pair<T, T> > *value;
  55. ContainerTH2(TH2* container, const std::string &name, Value<std::pair<T, T> > *value)
  56. :Container<TH2>(container, name),
  57. value(value){ }
  58. };
  59. class ContainerTH2D : public ContainerTH2<double>{
  60. public:
  61. ContainerTH2D(const std::string& name, const std::string& title,
  62. int nbins_x, double low_x, double high_x,
  63. int nbins_y, double low_y, double high_y,
  64. GenValue* value)
  65. :ContainerTH2<double>(NULL, name, dynamic_cast<Value<std::pair<double, double> >*>(value)){
  66. this->container = new TH2D(name.c_str(), title.c_str(), nbins_x, low_x, high_x, nbins_y, low_y, high_y);
  67. }
  68. };
  69. class ContainerTH2I : public ContainerTH2<int>{
  70. public:
  71. ContainerTH2I(const std::string& name, const std::string& title,
  72. int nbins_x, int low_x, int high_x,
  73. int nbins_y, int low_y, int high_y,
  74. GenValue* value)
  75. :ContainerTH2<int>(NULL, name, dynamic_cast<Value<std::pair<int, int> >*>(value)){
  76. this->container = new TH2I(name.c_str(), title.c_str(), nbins_x, low_x, high_x, nbins_y, low_y, high_y);
  77. }
  78. };
  79. class ContainerTGraph : public Container<TGraph>{
  80. private:
  81. Value<std::pair<int, int> > *value;
  82. std::vector<int> x_data;
  83. std::vector<int> y_data;
  84. bool data_modified;
  85. void _fill(){
  86. auto val = value->get_value();
  87. x_data.push_back(val.first);
  88. y_data.push_back(val.second);
  89. /* std::cout << x_data.size() << std::endl; */
  90. data_modified = true;
  91. }
  92. public:
  93. ContainerTGraph(const std::string &name, GenValue* value)
  94. :Container<TGraph>(new TGraph(), name),
  95. value(dynamic_cast<Value<std::pair<int, int> >*>(value)),
  96. data_modified(false){ }
  97. TGraph* get_container(){
  98. if (data_modified){
  99. delete container;
  100. container = new TGraph(x_data.size(), x_data.data(), y_data.data());
  101. data_modified = false;
  102. }
  103. return container;
  104. }
  105. };
  106. }
  107. #endif // root_container_hpp