Ver código fonte

Simplifies interface to TH* Objects

Caleb Fangmeier 7 anos atrás
pai
commit
40f53a4a6b
2 arquivos alterados com 41 adições e 879 exclusões
  1. 0 837
      python/EGamma_TrackingValidation.ipynb
  2. 41 42
      root/container.hpp

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 837
python/EGamma_TrackingValidation.ipynb


+ 41 - 42
root/container.hpp

@@ -84,6 +84,14 @@ namespace fv::root::util{
 
 namespace fv::root {
 
+struct TH1Params{
+    std::string label_x;
+    int nbins;
+    double low;
+    double high;
+    std::string label_y;
+};
+
 template <typename V>
 class _ContainerTH1 : public Container<TH1,V>{
     private:
@@ -94,31 +102,26 @@ class _ContainerTH1 : public Container<TH1,V>{
                              << "Probably built with imcompatible type",-1);
                 }
                 this->container = new TH1D(this->get_name().c_str(), this->title.c_str(),
-                                           this->nbins, this->low, this->high);
-                this->container->SetXTitle(label_x.c_str());
-                this->container->SetYTitle(label_y.c_str());
+                                           params.nbins, params.low, params.high);
+                this->container->SetXTitle(params.label_x.c_str());
+                this->container->SetYTitle(params.label_y.c_str());
             }
             _do_fill();
         }
 
     protected:
         std::string title;
-        std::string label_x;
-        std::string label_y;
-        int nbins;
-        double low;
-        double high;
+        TH1Params params;
 
         virtual void _do_fill() = 0;
 
     public:
-        explicit _ContainerTH1(const std::string &name, const std::string& title, Value<V>* value,
-                               int nbins, double low, double high,
-                               const std::string& label_x = "",
-                               const std::string& label_y = "")
+        explicit _ContainerTH1(const std::string& name, Value<V>* value,
+                               const std::string& title,
+                               TH1Params params)
           :Container<TH1,V>(name, value),
-           title(title), nbins(nbins), low(low), high(high),
-           label_x(label_x), label_y(label_y) { }
+           title(title),
+           params(params) { }
 
         void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
             util::save_as(this->get_container(), fname, option);
@@ -133,7 +136,7 @@ class ContainerTH1 : public _ContainerTH1<V>{
     }
     public:
         GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTH1<V>(new_name, this->title, this->value, this->nbins, this->low, this->high, this->label_x, this->label_y);
+            return new ContainerTH1<V>(new_name, this->value, this->title, this->params);
         }
 };
 
@@ -146,11 +149,20 @@ class ContainerTH1Many : public _ContainerTH1<std::vector<V>>{
     }
     public:
         GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTH1Many<V>(new_name, this->title, this->value, this->nbins, this->low, this->high, this->label_x, this->label_y);
+            return new ContainerTH1Many<V>(new_name, this->value, this->title, this->params);
         }
 };
 
-
+struct TH2Params{
+    std::string label_x;
+    int nbins_x;
+    double low_x;
+    double high_x;
+    std::string label_y;
+    int nbins_y;
+    double low_y;
+    double high_y;
+};
 
 template <typename V>
 class _ContainerTH2 : public Container<TH2,std::pair<V,V>>{
@@ -162,43 +174,32 @@ class _ContainerTH2 : public Container<TH2,std::pair<V,V>>{
                              << "Probably built with imcompatible type",-1);
                 }
                 this->container = new TH2D(this->get_name().c_str(), this->title.c_str(),
-                                           this->nbins_x, this->low_x, this->high_x,
-                                           this->nbins_y, this->low_y, this->high_y);
-                this->container->SetXTitle(label_x.c_str());
-                this->container->SetYTitle(label_y.c_str());
+                                           params.nbins_x, params.low_x, params.high_x,
+                                           params.nbins_y, params.low_y, params.high_y);
+                this->container->SetXTitle(params.label_x.c_str());
+                this->container->SetYTitle(params.label_y.c_str());
             }
             _do_fill(this->value->get_value());
         }
 
     protected:
         std::string title;
-        std::string label_x;
-        std::string label_y;
-        int nbins_x;
-        int nbins_y;
-        double low_x;
-        double low_y;
-        double high_x;
-        double high_y;
+        TH2Params params;
 
         virtual void _do_fill(const std::pair<V,V>& val) = 0;
 
     public:
-        explicit _ContainerTH2(const std::string& name, const std::string& title,
-                               Value<std::pair<V, V>>* value,
-                               int nbins_x, double low_x, double high_x,
-                               int nbins_y, double low_y, double high_y,
-                               const std::string& label_x = "",
-                               const std::string& label_y = "")
+        explicit _ContainerTH2(const std::string& name, Value<std::pair<V, V>>* value,
+                               const std::string& title,
+                               TH2Params params)
           :Container<TH2,std::pair<V,V>>(name, value),
            title(title),
-           nbins_x(nbins_x), low_x(low_x), high_x(high_x),
-           nbins_y(nbins_y), low_y(low_y), high_y(high_y),
-           label_x(label_x), label_y(label_y) { }
+           params(params) { }
 
         void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
             util::save_as(this->get_container(), fname, option);
         }
+
 };
 
 template <typename V>
@@ -209,8 +210,7 @@ class ContainerTH2 : public _ContainerTH2<V>{
     }
     public:
         GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTH2<V>(new_name, this->title, this->value, this->nbins_x, this->low_x, this->high_x,
-                                       this->nbins_y, this->low_y, this->high_y, this->label_x, this->label_y);
+            return new ContainerTH2<V>(new_name, this->title, this->value, this->params);
         }
 };
 
@@ -224,8 +224,7 @@ class ContainerTH2Many : public _ContainerTH2<std::vector<V>>{
     }
     public:
         GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTH2Many<V>(new_name, this->title, this->value, this->nbins_x, this->low_x, this->high_x,
-                                           this->nbins_y, this->low_y, this->high_y, this->label_x, this->label_y);
+            return new ContainerTH2Many<V>(new_name, this->value, this->title, this->params);
         }
 };