Sfoglia il codice sorgente

Adds dijet invarient mass distribution

Caleb Fangmeier 7 anni fa
parent
commit
f19b577f8b
2 ha cambiato i file con 79 aggiunte e 19 eliminazioni
  1. 47 19
      api.hpp
  2. 32 0
      value.hpp

+ 47 - 19
api.hpp

@@ -10,7 +10,7 @@ namespace fv{
         GenValue* gv = GenValue::get_value(name);
         Value<T>* tv = dynamic_cast<Value<T>*>(gv);
         if(tv == nullptr){
-            CRITICAL("Value: "+gv->get_name() + "has improper type.",-1);
+            CRITICAL("Value: \""+gv->get_name() + "\" has improper type.",-1);
         }
         return tv;
     }
@@ -24,89 +24,117 @@ namespace fv{
     }
 
     template <typename... ArgTypes>
-    Zip<ArgTypes...>* zip(Value<std::vector<ArgTypes>>*... args, const std::string& alias=""){
+    Value<std::vector<std::tuple<ArgTypes...>>>*
+    zip(Value<std::vector<ArgTypes>>*... args, const std::string& alias=""){
         return new Zip<ArgTypes...>(args..., alias);
     }
 
     template <typename Ret, typename... ArgTypes>
-    Map<Ret(ArgTypes...)>* map(Function<Ret(ArgTypes...)>& fn,
-                                        Zip<ArgTypes...>* arg, const std::string& alias=""){
+    Map<Ret(ArgTypes...)>*
+    map(Function<Ret(ArgTypes...)>& fn,
+        Value<std::vector<std::tuple<ArgTypes...>>>* arg, const std::string& alias=""){
         return new Map<Ret(ArgTypes...)>(fn, arg, alias);
     }
 
 
     template <typename... ArgTypes>
-    Tuple<ArgTypes...>* tuple(Value<ArgTypes>*... args, const std::string& alias=""){
+    Tuple<ArgTypes...>*
+    tuple(Value<ArgTypes>*... args, const std::string& alias=""){
         return new Tuple<ArgTypes...>(args..., alias);
     }
 
     template <typename Ret, typename... ArgTypes>
-    Apply<Ret(ArgTypes...)>* apply(Function<Ret(ArgTypes...)>& fn,
-                                   Tuple<ArgTypes...>* arg, const std::string& alias=""){
+    Apply<Ret(ArgTypes...)>*
+    apply(Function<Ret(ArgTypes...)>& fn,
+          Tuple<ArgTypes...>* arg, const std::string& alias=""){
         return new Apply<Ret(ArgTypes...)>(fn, arg, alias);
     }
 
     template <typename T1, typename T2>
-    Pair<T1, T2>* pair(Value<T1>* val1, Value<T2>* val2, const std::string& alias=""){
+    Pair<T1, T2>*
+    pair(Value<T1>* val1, Value<T2>* val2, const std::string& alias=""){
         return new Pair<T1,T2>(val1, val2, alias);
     }
 
     template <typename T1, typename T2>
-    Pair<T1, T2>* pair(const std::string& name1, const std::string& name2, const std::string& alias=""){
+    Pair<T1, T2>*
+    pair(const std::string& name1, const std::string& name2, const std::string& alias=""){
         return pair<T1,T2>(lookup<T1>(name1), lookup<T2>(name2), alias);
     }
 
 
     template <typename T>
-    Max<T>* max(Value<std::vector<T>>* v, const std::string alias){
+    Max<T>*
+    max(Value<std::vector<T>>* v, const std::string alias){
         return new Max<T>(v, alias);
     }
 
     template <typename T>
-    Max<T>* max(const std::string& v_name, const std::string alias){
+    Max<T>*
+    max(const std::string& v_name, const std::string alias){
         return max(lookup<std::vector<T>>(v_name), alias);
     }
 
     template <typename T>
-    Min<T>* min(Value<std::vector<T>>* v, const std::string alias){
+    Min<T>*
+    min(Value<std::vector<T>>* v, const std::string alias){
         return new Min<T>(v, alias);
     }
 
     template <typename T>
-    Min<T>* min(const std::string& v_name, const std::string alias){
+    Min<T>*
+    min(const std::string& v_name, const std::string alias){
         return min(lookup<std::vector<T>>(v_name), alias);
     }
 
     template <typename T>
-    Range<T>* range(Value<std::vector<T>>* v, const std::string alias){
+    Range<T>*
+    range(Value<std::vector<T>>* v, const std::string alias){
         return new Range<T>(v, alias);
     }
 
     template <typename T>
-    Range<T>* range(const std::string& v_name, const std::string alias){
+    Range<T>*
+    range(const std::string& v_name, const std::string alias){
         return range(lookup<std::vector<T>>(v_name), alias);
     }
 
     template <typename T>
-    Mean<T>* mean(Value<std::vector<T>>* v, const std::string alias){
+    Mean<T>*
+    mean(Value<std::vector<T>>* v, const std::string alias){
         return new Mean<T>(v, alias);
     }
 
     template <typename T>
-    Mean<T>* mean(const std::string& v_name, const std::string alias){
+    Mean<T>*
+    mean(const std::string& v_name, const std::string alias){
         return mean(lookup<std::vector<T>>(v_name), alias);
     }
 
     template <typename T>
-    Count<T>* count(Function<bool(T)>& selector, Value<std::vector<T>>* v, const std::string alias){
+    Count<T>*
+    count(Function<bool(T)>& selector, Value<std::vector<T>>* v, const std::string alias){
         return new Count<T>(selector, v, alias);
     }
 
     template <typename T>
-    Count<T>* count(Function<bool(T)>& selector, const std::string& v_name, const std::string alias){
+    Count<T>*
+    count(Function<bool(T)>& selector, const std::string& v_name, const std::string alias){
         return count<T>(selector, lookup<std::vector<T>>(v_name), alias);
     }
 
+    template <typename FST, typename SND>
+    Value<std::vector<std::tuple<FST,SND>>>*
+    cart_product(Value<std::vector<FST>>* val1, Value<std::vector<SND>>* val2, const std::string alias){
+        return new CartProduct<FST, SND>(val1, val2, alias);
+    }
+
+    template <typename FST, typename SND>
+    Value<std::vector<std::tuple<FST,SND>>>*
+    cart_product(const std::string& val1_name, const std::string& val2_name, const std::string alias = ""){
+        return cart_product<FST,SND>(lookup<std::vector<FST>>(val1_name), lookup<std::vector<SND>>(val2_name), alias);
+    }
+
     ObsFilter* obs_filter(const std::string& name, std::function<bool()> filter_function, const std::string& impl=""){
         return new ObsFilter(name, filter_function, impl);
     }

+ 32 - 0
value.hpp

@@ -897,6 +897,38 @@ class MinIndex : public ReduceIndex<T>{
                           v, alias) { }
 };
 
+/**
+ * Find and return the minimum value of a vector and its index.
+ */
+template <typename FST, typename SND>
+class CartProduct : public DerivedValue<std::vector<std::tuple<FST,SND>>>{
+    private:
+        Value<std::vector<FST>>* val1;
+        Value<std::vector<SND>>* val2;
+        bool self_product;
+
+        void update_value(){
+            this->value.clear();
+            auto& v1 = val1->get_value();
+            auto& v2 = val2->get_value();
+            for(int i=0; i<v1.size(); i++){
+                int lower_lim = self_product ? i+1 : 0;
+                for(int j=lower_lim; j<v2.size(); j++){
+                    this->value.push_back(std::tuple<FST,SND>(v1[i],v2[j]));
+                }
+            }
+        }
+
+    public:
+        CartProduct(Value<std::vector<FST>>* val1, Value<std::vector<SND>>* val2, const std::string alias="")
+          :DerivedValue<std::vector<std::tuple<FST,SND>>>("cartProduct("+
+                                                          val1->get_name()+","+
+                                                          val2->get_name()+")", alias),
+           val1(val1),
+           val2(val2),
+           self_product(val1 == val2) { }
+};
+
 /**
  * A generic value owning only a function object.
  * All necessary values upon which this value depends must be bound to the