Просмотр исходного кода

Adds histogram containers to be filled with arrays, rather than singular
values. Also adds the ability to provide an alias in a value's
constructor. Continues to implement old analysis in new framework.

Caleb Fangmeier лет назад: 7
Родитель
Сommit
38070229c3
6 измененных файлов с 239 добавлено и 151 удалено
  1. 10 2
      analysis/MiniTreeDataSet.hpp
  2. 32 15
      analysis/TTTT_Analysis.cpp
  3. 3 1
      filval/container.hpp
  4. 65 53
      filval/value.hpp
  5. 127 78
      filval_root/container.hpp
  6. 2 2
      legacy/MiniTree.cpp

+ 10 - 2
analysis/MiniTreeDataSet.hpp

@@ -39,7 +39,11 @@ class MiniTreeDataSet : public DataSet,
 
         template <typename T>
         Value<T>* track_branch(const std::string& bname){
-            T* bref = (T*) fChain->GetBranch(bname.c_str())->GetAddress();
+            TBranch* branch = fChain->GetBranch(bname.c_str());
+            if (branch == nullptr){
+                CRITICAL("Branch: " << bname << " does not exist in input tree.", -1);
+            }
+            T* bref = (T*) branch->GetAddress();
             fChain->SetBranchStatus(bname.c_str(), true);
             INFO("Registering branch \"" << bname
                  << "\" with address " << bref
@@ -49,7 +53,11 @@ class MiniTreeDataSet : public DataSet,
 
         template <typename T>
         Value<T*>* track_branch_ptr(const std::string& bname){
-            T* bref = (T*) fChain->GetBranch(bname.c_str())->GetAddress();
+            TBranch* branch = fChain->GetBranch(bname.c_str());
+            if (branch == nullptr){
+                CRITICAL("Branch: " << bname << " does not exist in input tree.", -1);
+            }
+            T* bref = (T*) branch->GetAddress();
             fChain->SetBranchStatus(bname.c_str(), true);
             INFO("Registering pointer branch \"" << bname
                  << "\" with address " << bref

+ 32 - 15
analysis/TTTT_Analysis.cpp

@@ -26,12 +26,27 @@ Filter* lookup_filter(const string& name){
 
 void enable_branches(MiniTreeDataSet& mt){
     mt.fChain->SetBranchStatus("*", false);
-    mt.track_branch<int>("nJet");
+
     mt.track_branch<int>("nLepGood");
     mt.track_branch_ptr<float>("LepGood_pt");
     mt.track_branch_ptr<float>("LepGood_eta");
     mt.track_branch_ptr<float>("LepGood_phi");
     mt.track_branch_ptr<float>("LepGood_mass");
+    mt.track_branch_ptr<float>("LepGood_mcPt");
+    mt.track_branch_ptr<int>("LepGood_charge");
+
+    mt.track_branch<int>("nJet");
+    mt.track_branch_ptr<float>("Jet_pt");
+    mt.track_branch_ptr<float>("Jet_eta");
+    mt.track_branch_ptr<float>("Jet_phi");
+    mt.track_branch_ptr<float>("Jet_mass");
+    mt.track_branch_ptr<float>("Jet_btagCMVA");
+
+    mt.track_branch<int>("nGenTop");
+
+    mt.track_branch<int>("ngenLep");
+    mt.track_branch_ptr<int>("genLep_sourceId");
+    mt.track_branch_ptr<float>("genLep_pt");
 }
 
 void declare_values(MiniTreeDataSet& mt){
@@ -45,19 +60,19 @@ void declare_values(MiniTreeDataSet& mt){
             return n>0 ? sum / n : 0;
             })));
 
-    auto pt_wrapper  = new WrapperVector<float>("nLepGood", "LepGood_pt");
-    auto eta_wrapper = new WrapperVector<float>("nLepGood", "LepGood_eta");
-    auto phi_wrapper = new WrapperVector<float>("nLepGood", "LepGood_phi");
-    auto m_wrapper   = new WrapperVector<float>("nLepGood", "LepGood_mass");
-    /* auto dxy_wrapper   = new WrapperVector<float>("nLepGood", "LepGood_dxy"); */
+    new WrapperVector<float>("nLepGood", "LepGood_pt", "LepGood_pt");
+    new WrapperVector<float>("nLepGood", "LepGood_eta", "LepGood_eta");
+    new WrapperVector<float>("nLepGood", "LepGood_phi", "LepGood_phi");
+    new WrapperVector<float>("nLepGood", "LepGood_mass", "LepGood_mass");
 
-    auto& get_energy = GenFunction::register_function<float(float,float,float,float)>("get_energy", FUNC(([](float pt, float eta, float phi, float m){
-        TLorentzVector t;
-        t.SetPtEtaPhiM(pt, eta, phi, m);
-        return t.E();
-    })));
+    auto& get_energy = GenFunction::register_function<float(float,float,float,float)>("get_energy",
+            FUNC(([](float pt, float eta, float phi, float m){
+                TLorentzVector t;
+                t.SetPtEtaPhiM(pt, eta, phi, m);
+                return t.E();
+            })));
 
-    auto lepton_energy = new ZipMapFour<float, float>(get_energy, pt_wrapper, eta_wrapper, phi_wrapper, m_wrapper);
+    auto lepton_energy = new ZipMapFour<float, float>(get_energy, "LepGood_pt", "LepGood_eta", "LepGood_phi", "LepGood_mass");
     GenValue::alias("lepton_energy", lepton_energy);
 
     GenValue::alias("avg_lepton_energy", new Reduce<float>(mean , "lepton_energy"));
@@ -73,7 +88,10 @@ void declare_values(MiniTreeDataSet& mt){
 }
 
 void declare_containers(MiniTreeDataSet& mt){
-    mt.register_container(new ContainerTH1I("nLepGood", "Lepton Multiplicity", lookup("nLepGood"), 10, 0, 10));
+    mt.register_container(new ContainerTH1I("lepton_count", "Lepton Multiplicity", lookup("nLepGood"), 8, 0, 8));
+    mt.register_container(new ContainerTH1I("top_quark_count", "Top Quark Multiplicity", lookup("nGenTop"), 8, 0, 8));
+
+    mt.register_container(new ContainerTH1FMany("lepton_pt_all", "Lepton Pt - All", lookup("LepGood_pt"), 50, 0, 500));
 
     mt.register_container(new ContainerTH1I("nLepGood2", "Lepton Multiplicity", lookup("nLepGood"), 10, 0, 10));
     mt.get_container("nLepGood2")->add_filter(lookup_filter("3<=nLepGood<5"));
@@ -81,7 +99,7 @@ void declare_containers(MiniTreeDataSet& mt){
     mt.register_container(new ContainerTH1I("nLepGood3", "Lepton Multiplicity", lookup("nLepGood"), 10, 0, 10));
     mt.get_container("nLepGood3")->add_filter(!(*lookup_filter("3<=nLepGood<5")));
 
-    /* mt.register_container(new ContainerTGraph("nLepvsnJet", new Pair<int, int>("nLepGood", "nJet") )); */
+    mt.register_container(new ContainerTGraph("nLepvsnJet", new Pair<int, int>("nLepGood", "nJet") ));
 
     mt.register_container(new ContainerTH1F("avg_lepton_energy", "Average Lepton Energy", lookup("avg_lepton_energy"), 50, 0, 500));
     mt.register_container(new ContainerTH1F("max_lepton_energy", "Maximum Lepton Energy", lookup("max_lepton_energy"), 50, 0, 500));
@@ -97,7 +115,6 @@ void run_analysis(const std::string& filename){
     declare_containers(mt);
     mt.process();
     mt.save_all();
-    /* save_containers(mt); */
 }
 
 int main(int argc, char * argv[])

+ 3 - 1
filval/container.hpp

@@ -44,7 +44,9 @@ class GenContainer{
             return name;
         }
         virtual void save_as(const std::string& fname, const SaveOption& option) = 0;
-        virtual void save(const SaveOption& option=SaveOption::PNG) = 0;
+        virtual void save(const SaveOption& option=SaveOption::PNG) {
+            save_as(get_name(), option);
+        }
 };
 typedef std::map<std::string, GenContainer*> ContainerSet;
 

+ 65 - 53
filval/value.hpp

@@ -203,11 +203,20 @@ class GenValue{
          * pointers.
          */
         inline static std::map<const std::string, GenValue*> values;
+        /**
+         * Composite value names are typically nested. This makes complex
+         * values have rather unwieldy names. Therefore, one can declare
+         * aliases which allow for more human-usable names to be used. When a
+         * value is requested by name, an alias with that value takes precidence
+         * over a name with that value.
+         */
         inline static std::map<const std::string, GenValue*> aliases;
     public:
-        GenValue(const std::string& name)
+        GenValue(const std::string& name, const std::string& alias)
           :name(name){
             values[name] = this;
+            if (alias != "")
+                GenValue::alias(alias, this);
         }
 
         const std::string& get_name(){
@@ -287,8 +296,8 @@ std::ostream& operator<<(std::ostream& os, GenValue& gv){
 template <typename T>
 class Value : public GenValue{
     public:
-        Value(const std::string& name)
-          :GenValue(name){ }
+        Value(const std::string& name, const std::string& alias="")
+          :GenValue(name, alias){ }
         /** Calculate, if necessary, and return the value held by this object.
          */
         virtual T& get_value() = 0;
@@ -310,8 +319,8 @@ class ObservedValue : public Value<T>{
         T *val_ref;
         void _reset(){ }
     public:
-        ObservedValue(const std::string& name, T* val_ref)
-          :Value<T>(name),
+        ObservedValue(const std::string& name, T* val_ref, const std::string& alias="")
+          :Value<T>(name, alias),
            val_ref(val_ref){ }
         T& get_value(){
             return *val_ref;
@@ -354,8 +363,8 @@ class DerivedValue : public Value<T>{
          */
         virtual void update_value() = 0;
     public:
-        DerivedValue(const std::string& name)
-          :Value<T>(name),
+        DerivedValue(const std::string& name, const std::string& alias="")
+          :Value<T>(name, alias),
            value_valid(false) { }
 
         T& get_value(){
@@ -394,13 +403,13 @@ class WrapperVector : public DerivedValue<std::vector<T> >{
         }
 
     public:
-        WrapperVector(Value<int>* size, Value<T*>* data)
-          :DerivedValue<std::vector<T> >("vectorOf("+size->get_name()+","+data->get_name()+")"),
+        WrapperVector(Value<int>* size, Value<T*>* data, const std::string& alias="")
+          :DerivedValue<std::vector<T> >("vectorOf("+size->get_name()+","+data->get_name()+")", alias),
            size(size), data(data){ }
 
-        WrapperVector(const std::string &label_size, const std::string &label_data)
+        WrapperVector(const std::string &label_size, const std::string &label_data, const std::string& alias="")
           :WrapperVector(dynamic_cast<Value<int>*>(GenValue::get_value(label_size)),
-                         dynamic_cast<Value<T*>*>(GenValue::get_value(label_data))) { }
+                         dynamic_cast<Value<T*>*>(GenValue::get_value(label_data)), alias) { }
 };
 
 /**
@@ -415,12 +424,13 @@ class Pair : public DerivedValue<std::pair<T1, T2> >{
             this->value.second = value_pair.second->get_value();
         }
     public:
-        Pair(Value<T1> *value1, Value<T2> *value2)
-          :DerivedValue<std::pair<T1, T2> >("pair("+value1->get_name()+","+value2->get_name()+")"),
+        Pair(Value<T1> *value1, Value<T2> *value2, const std::string alias="")
+          :DerivedValue<std::pair<T1, T2> >("pair("+value1->get_name()+","+value2->get_name()+")", alias),
            value_pair(value1, value2){ }
-        Pair(const std::string& label1, const std::string& label2)
-          :Pair(dynamic_cast<Value<T1>*>(GenValue::values.at(label1)),
-                dynamic_cast<Value<T1>*>(GenValue::values.at(label2))){ }
+        Pair(const std::string& label1, const std::string& label2, const std::string alias="")
+          :Pair(dynamic_cast<Value<T1>*>(GenValue::get_value(label1)),
+                dynamic_cast<Value<T1>*>(GenValue::get_value(label2)),
+                alias){ }
 };
 
 /**
@@ -462,18 +472,20 @@ class ZipMapFour : public DerivedValue<std::vector<R> >{
     public:
         ZipMapFour(Function<R(T, T, T, T)>& f,
                    Value<std::vector<T> >* v1, Value<std::vector<T> >* v2,
-                   Value<std::vector<T> >* v3, Value<std::vector<T> >* v4)
-          :DerivedValue<std::vector<R> >("zipmap("+f.get_name()+":"+v1->get_name()+","+v2->get_name()+","+v3->get_name()+","+v4->get_name()+")"),
+                   Value<std::vector<T> >* v3, Value<std::vector<T> >* v4, const std::string alias="")
+          :DerivedValue<std::vector<R> >("zipmap("+f.get_name()+":"+v1->get_name()+","+v2->get_name()+","+
+                                                                    v3->get_name()+","+v4->get_name()+")", alias),
            f(f), v1(v1), v2(v2), v3(v3), v4(v4) { }
 
-        ZipMapFour(Function<R(T, T, T, T)>* f,
-                   const std::string &label1, const std::string &label2,
-                   const std::string &label3, const std::string &label4)
+        ZipMapFour(Function<R(T, T, T, T)>& f,
+                   const std::string& label1, const std::string& label2,
+                   const std::string& label3, const std::string& label4, const std::string alias="")
           :ZipMapFour(f,
-                      dynamic_cast<Value<std::vector<T> >*>(GenValue::values.at(label1)),
-                      dynamic_cast<Value<std::vector<T> >*>(GenValue::values.at(label2)),
-                      dynamic_cast<Value<std::vector<T> >*>(GenValue::values.at(label3)),
-                      dynamic_cast<Value<std::vector<T> >*>(GenValue::values.at(label4))){ }
+                      dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(label1)),
+                      dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(label2)),
+                      dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(label3)),
+                      dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(label4)),
+                      alias){ }
 };
 
 
@@ -492,12 +504,12 @@ class Reduce : public DerivedValue<T>{
             this->value = reduce(v->get_value());
         }
     public:
-        Reduce(Function<T(std::vector<T>)>& reduce, Value<std::vector<T> >* v)
-          :DerivedValue<T>("reduceWith("+reduce.get_name()+":"+v->get_name()+")"),
+        Reduce(Function<T(std::vector<T>)>& reduce, Value<std::vector<T> >* v, const std::string alias="")
+          :DerivedValue<T>("reduceWith("+reduce.get_name()+":"+v->get_name()+")", alias),
            reduce(reduce), v(v) { }
 
-        Reduce(Function<T(std::vector<T>)>& reduce, const std::string& v_name)
-          :Reduce(reduce, dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(v_name))) { }
+        Reduce(Function<T(std::vector<T>)>& reduce, const std::string& v_name, const std::string alias="")
+          :Reduce(reduce, dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(v_name)), alias) { }
 };
 
 /**
@@ -506,11 +518,11 @@ class Reduce : public DerivedValue<T>{
 template <typename T>
 class Max : public Reduce<T>{
     public:
-        Max(const std::string& v_name)
+        Max(const std::string& v_name, const std::string alias="")
           :Reduce<T>(GenFunction::register_function<T(std::vector<T>)>("max",
                       FUNC(([](std::vector<T> vec){
                           return *std::max_element(vec.begin(), vec.end());}))),
-                      v_name) { }
+                      v_name, alias) { }
 };
 
 /**
@@ -519,10 +531,10 @@ class Max : public Reduce<T>{
 template <typename T>
 class Min : public Reduce<T>{
     public:
-        Min(const std::string& v_name)
+        Min(const std::string& v_name, const std::string alias="")
           :Reduce<T>(new Function<T(std::vector<T>)>("min", [](std::vector<T> vec){
                          return *std::min_element(vec.begin(), vec.end());}),
-                     v_name) { }
+                     v_name, alias) { }
 };
 
 /**
@@ -531,12 +543,12 @@ class Min : public Reduce<T>{
 template <typename T>
 class Mean : public Reduce<T>{
     public:
-        Mean(const std::string& v_name)
+        Mean(const std::string& v_name, const std::string alias="")
           :Reduce<T>(new Function<T(std::vector<T>)>("mean", [](std::vector<T> vec){
                         int n = 0; T sum = 0;
                         for (T e : vec){ n++; sum += e; }
                         return n>0 ? sum / n : 0; }),
-                     v_name) { }
+                     v_name, alias) { }
 };
 
 /**
@@ -545,11 +557,11 @@ class Mean : public Reduce<T>{
 template <typename T>
 class ElementOf : public Reduce<T>{
     public:
-        ElementOf(Value<int>* index, const std::string& v_name)
+        ElementOf(Value<int>* index, const std::string& v_name, const std::string alias="")
           :Reduce<T>(new Function<T(std::vector<T>)>("elementOf", [index](std::vector<T> vec){return vec[index->get_value()];}),
-                     v_name) { }
-        ElementOf(const std::string& name, int index, const std::string& v_name)
-          :Reduce<T>(name, [index](std::vector<T> vec){return vec[index];}, v_name) { }
+                     v_name, alias) { }
+        ElementOf(const std::string& name, int index, const std::string& v_name, const std::string alias="")
+          :Reduce<T>(name, [index](std::vector<T> vec){return vec[index];}, v_name, alias) { }
 };
 
 /**
@@ -566,12 +578,12 @@ class ReduceIndex : public DerivedValue<std::pair<T, int> >{
             this->value = reduce(v->get_value());
         }
     public:
-        ReduceIndex(Function<std::pair<T,int>(std::vector<T>)>& reduce, Value<std::vector<T> >* v)
-          :DerivedValue<T>("reduceIndexWith("+reduce.get_name()+":"+v->get_name()+")"),
+        ReduceIndex(Function<std::pair<T,int>(std::vector<T>)>& reduce, Value<std::vector<T> >* v, const std::string alias="")
+          :DerivedValue<T>("reduceIndexWith("+reduce.get_name()+":"+v->get_name()+")", alias),
            reduce(reduce), v(v) { }
 
-        ReduceIndex(Function<std::pair<T,int>(std::vector<T>)>& reduce, const std::string& v_name)
-          :ReduceIndex(reduce, dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(v_name))) { }
+        ReduceIndex(Function<std::pair<T,int>(std::vector<T>)>& reduce, const std::string& v_name, const std::string alias="")
+          :ReduceIndex(reduce, dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(v_name)), alias) { }
 };
 
 /**
@@ -580,12 +592,12 @@ class ReduceIndex : public DerivedValue<std::pair<T, int> >{
 template <typename T>
 class MaxIndex : public ReduceIndex<T>{
     public:
-        MaxIndex(const std::string& v_name)
+        MaxIndex(const std::string& v_name, const std::string alias="")
           :ReduceIndex<T>(GenFunction::register_function<T(std::vector<T>)>("maxIndex",
                       FUNC(([](std::vector<T> vec){
                                auto elptr = std::max_element(vec.begin(), vec.end());
                                return std::pair<T,int>(*elptr, int(elptr-vec.begin())); }
-                          ))), v_name) { }
+                          ))), v_name, alias) { }
 };
 
 /**
@@ -594,12 +606,12 @@ class MaxIndex : public ReduceIndex<T>{
 template <typename T>
 class MinIndex : public ReduceIndex<T>{
     public:
-        MinIndex(const std::string& v_name)
+        MinIndex(const std::string& v_name, const std::string alias="")
           :ReduceIndex<T>(GenFunction::register_function<T(std::vector<T>)>("minIndex",
                       FUNC(([](std::vector<T> vec){
                                auto elptr = std::min_element(vec.begin(), vec.end());
                                return std::pair<T,int>(*elptr, int(elptr-vec.begin())); }
-                          ))), v_name) { }
+                          ))), v_name, alias) { }
 };
 
 /**
@@ -615,8 +627,8 @@ class BoundValue : public DerivedValue<T>{
             this->value = f();
         }
     public:
-        BoundValue(Function<T()>& f)
-          :DerivedValue<T>(f.get_name()+"(<bound>)"),
+        BoundValue(Function<T()>& f, const std::string alias="")
+          :DerivedValue<T>(f.get_name()+"(<bound>)", alias),
            f(f) { }
 };
 
@@ -629,8 +641,8 @@ class PointerValue : public DerivedValue<T*>{
     protected:
         void update_value(){ }
     public:
-        PointerValue(const std::string& name, T* ptr)
-          :DerivedValue<T*>(name){
+        PointerValue(const std::string& name, T* ptr, const std::string alias="")
+          :DerivedValue<T*>(name, alias){
             this->value = ptr;
         }
 };
@@ -646,8 +658,8 @@ class ConstantValue : public DerivedValue<T>{
             this->value = const_value;
         }
     public:
-        ConstantValue(const std::string& name, T const_value)
-            :DerivedValue<T>("const::"+name),
+        ConstantValue(const std::string& name, T const_value, const std::string alias="")
+            :DerivedValue<T>("const::"+name, alias),
              const_value(const_value) { }
 };
 }

+ 127 - 78
filval_root/container.hpp

@@ -22,7 +22,7 @@ void _save_img(TObject* container, const std::string& fname){
 void _save_bin(TObject* container, const std::string& fname){
     INFO("Saving object: " << container->GetName() << " into file " << fname);
     TFile* f = TFile::Open(fname.c_str(), "UPDATE");
-    container->Write(container->GetName());
+    container->Write(container->GetName(), TObject::kOverwrite);
     f->Close();
 }
 
@@ -42,124 +42,175 @@ void _save_as(TObject* container, const std::string& fname, const SaveOption& op
 
 namespace fv::root {
 
-template <typename T>
+template <typename V, typename D>
 class ContainerTH1 : public Container<TH1>{
     private:
         void _fill(){
             if (container == nullptr){
                 init_TH1();
             }
-            container->Fill(value->get_value());
+            _do_fill(value->get_value());
         }
 
     protected:
         std::string title;
         int nbins;
-        T low;
-        T high;
-        Value<T> *value;
+        D low;
+        D high;
+        Value<V> *value;
         virtual void init_TH1() = 0;
+        virtual void _do_fill(V& val) = 0;
+
     public:
         explicit ContainerTH1(const std::string &name, const std::string& title, GenValue *value,
-                     int nbins, T low, T high)
+                     int nbins, D low, D high)
           :Container<TH1>(name, nullptr),
            title(title), nbins(nbins), low(low), high(high),
-           value(dynamic_cast<Value<T>*>(value)) { }
+           value(dynamic_cast<Value<V>*>(value)) { }
 
         void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            util::_save_as(container, fname, option);
-        }
-
-        void save(const SaveOption& option = SaveOption::PNG) {
-            save_as(this->get_name(), option);
+            util::_save_as(get_container(), fname, option);
         }
 };
 
-class ContainerTH1D : public ContainerTH1<double>{
-    using ContainerTH1::ContainerTH1;
+template <typename V>
+class _ContainerTH1D : public ContainerTH1<V, double>{
+    using ContainerTH1<V, double>::ContainerTH1;
     void init_TH1(){
-        this->container = new TH1D(this->get_name().c_str(), title.c_str(), nbins, low, high);
+        this->container = new TH1D(this->get_name().c_str(), this->title.c_str(),
+                                   this->nbins, this->low, this->high);
     }
 };
 
-class ContainerTH1F : public ContainerTH1<float>{
-    using ContainerTH1::ContainerTH1;
-    void init_TH1(){
-        this->container = new TH1F(this->get_name().c_str(), title.c_str(), nbins, low, high);
+class ContainerTH1D : public _ContainerTH1D<double>{
+    using _ContainerTH1D<double>::_ContainerTH1D;
+    void _do_fill(double& val){
+        this->container->Fill(val);
     }
 };
 
-class ContainerTH1I : public ContainerTH1<int>{
-    using ContainerTH1::ContainerTH1;
-    void init_TH1(){
-        this->container = new TH1I(this->get_name().c_str(), title.c_str(), nbins, low, high);
+class ContainerTH1DMany : public _ContainerTH1D<std::vector<double>>{
+    using _ContainerTH1D<std::vector<double>>::_ContainerTH1D;
+    void _do_fill(std::vector<double>& val){
+        for(double x : val)
+            this->container->Fill(x);
     }
 };
 
 
-template <typename T>
-class ContainerTH2 : public Container<TH2>{
-    private:
-        void _fill(){
-            if (container == nullptr){
-                init_TH2();
-            }
-            std::pair<T, T> val = value->get_value();
-            container->Fill(val.first, val.second);
-        }
-
-    protected:
-        std::string title;
-        int nbins_x;
-        int nbins_y;
-        T low_x;
-        T low_y;
-        T high_x;
-        T high_y;
-        Value<std::pair<T, T> > *value;
-        virtual void init_TH2() = 0;
-
-    public:
-        explicit ContainerTH2(const std::string& name, const std::string& title,
-                      int nbins_x, double low_x, double high_x,
-                      int nbins_y, double low_y, double high_y,
-                      GenValue* value)
-          :Container<TH2>(name, nullptr),
-           nbins_x(nbins_x), low_x(low_x), high_x(high_x),
-           nbins_y(nbins_y), low_y(low_y), high_y(high_y),
-           value(dynamic_cast<Value<T>*>(value)) { }
+template <typename V>
+class _ContainerTH1F : public ContainerTH1<V, float>{
+    using ContainerTH1<V,float>::ContainerTH1;
+    void init_TH1(){
+        this->container = new TH1F(this->get_name().c_str(), this->title.c_str(),
+                                   this->nbins, this->low, this->high);
+    }
+};
 
-        void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            util::_save_as(container, fname, option);
-        }
+class ContainerTH1F : public _ContainerTH1F<float>{
+    using _ContainerTH1F<float>::_ContainerTH1F;
+    void _do_fill(float& val){
+        this->container->Fill(val);
+    }
+};
 
-        void save(const SaveOption& option = SaveOption::PNG) {
-            save_as(this->get_name(), option);
-        }
+class ContainerTH1FMany : public _ContainerTH1F<std::vector<float>>{
+    using _ContainerTH1F<std::vector<float>>::_ContainerTH1F;
+    void _do_fill(std::vector<float>& val){
+        for(float x : val)
+            this->container->Fill(x);
+    }
 };
 
-class ContainerTH2D : public ContainerTH2<double>{
-    using ContainerTH2::ContainerTH2;
-    void init_TH2(){
-        this->container = new TH2D(this->get_name().c_str(), title.c_str(), nbins_x, low_x, high_x, nbins_y, low_y, high_y);
+
+template <typename V>
+class _ContainerTH1I : public ContainerTH1<V, int>{
+    using ContainerTH1<V,int>::ContainerTH1;
+    void init_TH1(){
+        this->container = new TH1I(this->get_name().c_str(), this->title.c_str(),
+                                   this->nbins, this->low, this->high);
     }
 };
 
-class ContainerTH2F : public ContainerTH2<float>{
-    using ContainerTH2::ContainerTH2;
-    void init_TH2(){
-        this->container = new TH2F(this->get_name().c_str(), title.c_str(), nbins_x, low_x, high_x, nbins_y, low_y, high_y);
+class ContainerTH1I : public _ContainerTH1I<int>{
+    using _ContainerTH1I<int>::_ContainerTH1I;
+    void _do_fill(int& val){
+        this->container->Fill(val);
     }
 };
 
-class ContainerTH2I : public ContainerTH2<int>{
-    using ContainerTH2::ContainerTH2;
-    void init_TH2(){
-        this->container = new TH2I(this->get_name().c_str(), title.c_str(), nbins_x, low_x, high_x, nbins_y, low_y, high_y);
+class ContainerTH1IMany : public _ContainerTH1I<std::vector<int>>{
+    using _ContainerTH1I<std::vector<int>>::_ContainerTH1I;
+    void _do_fill(std::vector<int>& val){
+        for(int x : val)
+            this->container->Fill(x);
     }
 };
 
 
+/* template <typename T> */
+/* class ContainerTH2 : public Container<TH2>{ */
+/*     private: */
+/*         void _fill(){ */
+/*             if (container == nullptr){ */
+/*                 init_TH2(); */
+/*             } */
+/*             std::pair<T, T> val = value->get_value(); */
+/*             container->Fill(val.first, val.second); */
+/*         } */
+
+/*     protected: */
+/*         std::string title; */
+/*         int nbins_x; */
+/*         int nbins_y; */
+/*         T low_x; */
+/*         T low_y; */
+/*         T high_x; */
+/*         T high_y; */
+/*         Value<std::pair<T, T> > *value; */
+/*         virtual void init_TH2() = 0; */
+
+/*     public: */
+/*         explicit ContainerTH2(const std::string& name, const std::string& title, */
+/*                       int nbins_x, double low_x, double high_x, */
+/*                       int nbins_y, double low_y, double high_y, */
+/*                       GenValue* value) */
+/*           :Container<TH2>(name, nullptr), */
+/*            nbins_x(nbins_x), low_x(low_x), high_x(high_x), */
+/*            nbins_y(nbins_y), low_y(low_y), high_y(high_y), */
+/*            value(dynamic_cast<Value<T>*>(value)) { } */
+
+/*         void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) { */
+/*             util::_save_as(get_container(), fname, option); */
+/*         } */
+
+/*         void save(const SaveOption& option = SaveOption::PNG) { */
+/*             save_as(this->get_name(), option); */
+/*         } */
+/* }; */
+
+/* class ContainerTH2D : public ContainerTH2<double>{ */
+/*     using ContainerTH2::ContainerTH2; */
+/*     void init_TH2(){ */
+/*         this->container = new TH2D(this->get_name().c_str(), title.c_str(), nbins_x, low_x, high_x, nbins_y, low_y, high_y); */
+/*     } */
+/* }; */
+
+/* class ContainerTH2F : public ContainerTH2<float>{ */
+/*     using ContainerTH2::ContainerTH2; */
+/*     void init_TH2(){ */
+/*         this->container = new TH2F(this->get_name().c_str(), title.c_str(), nbins_x, low_x, high_x, nbins_y, low_y, high_y); */
+/*     } */
+/* }; */
+
+/* class ContainerTH2I : public ContainerTH2<int>{ */
+/*     using ContainerTH2::ContainerTH2; */
+/*     void init_TH2(){ */
+/*         this->container = new TH2I(this->get_name().c_str(), title.c_str(), nbins_x, low_x, high_x, nbins_y, low_y, high_y); */
+/*     } */
+/* }; */
+
+
 class ContainerTGraph : public Container<TGraph>{
     private:
         Value<std::pair<int, int> > *value;
@@ -182,16 +233,14 @@ class ContainerTGraph : public Container<TGraph>{
             if (data_modified){
                 delete container;
                 container = new TGraph(x_data.size(), x_data.data(), y_data.data());
+                container->SetName(get_name().c_str());
+                std::cout << "name: " << container->GetName() << std::endl;
                 data_modified = false;
             }
             return container;
         }
         void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            util::_save_as(container, fname, option);
-        }
-
-        void save(const SaveOption& option = SaveOption::PNG) {
-            save_as(this->get_name(), option);
+            util::_save_as(get_container(), fname, option);
         }
 };
 

+ 2 - 2
legacy/MiniTree.cpp

@@ -220,8 +220,8 @@ void MiniTree::Loop(HistCollection* hc){
          *
          */
         ++(*hc); // Increments event count
-        hc->lepton_count->Fill(nLepGood);
-        hc->top_quark_count->Fill(nGenTop);
+        hc->lepton_count->Fill(nLepGood); //DONE
+        hc->top_quark_count->Fill(nGenTop); //DONE
         for(int i=0; i<nLepGood; i++){
             double delta_pt_val = LepGood_pt[i] - LepGood_mcPt[i];
             hc->delta_pt->Fill(delta_pt_val);