#ifndef root_value_hpp #define root_value_hpp #include "filval/value.hpp" #include "TLorentzVector.h" namespace fv::root{ class LorentzVectors : public DerivedValue>{ protected: Value> *pt_val; Value> *eta_val; Value> *phi_val; Value> *mass_val; void update_value(){ auto pt = pt_val->get_value(); auto eta = eta_val->get_value(); auto phi = phi_val->get_value(); auto mass = mass_val->get_value(); std::vector sizes = {pt.size(), eta.size(), phi.size(), mass.size()}; int size = *std::min_element(sizes.begin(), sizes.end()); this->value.clear(); TLorentzVector lv; for (int i =0; ivalue.push_back(lv); } } public: static std::string fmt_name(Value>* pt, Value>* eta, Value>* phi, Value>* mass){ return "lorentz_vectors("+pt->get_name()+"," +eta->get_name()+","+ phi->get_name()+"," +mass->get_name()+")"; } LorentzVectors(Value>* pt, Value>* eta, Value>* phi, Value>* mass, const std::string& alias) :DerivedValue>(fmt_name(pt,eta,phi,mass), alias), pt_val(pt), eta_val(eta), phi_val(phi), mass_val(mass) { } }; class Energies : public DerivedValue>{ private: Value> *vectors; void update_value(){ std::vector& vecs = vectors->get_value(); this->value.clear(); for (auto v : vecs){ this->value.push_back(v.Energy()); } } public: static std::string fmt_name(Value> *vectors){ return "energies("+vectors->get_name()+")"; } Energies(Value> *vectors, const std::string& alias) :DerivedValue>(fmt_name(vectors), alias), vectors(vectors) { } }; namespace detail { template decltype(auto) tuple_get_values_impl(const Tuple& t, std::index_sequence){ return std::make_tuple(std::get<1>(std::get(t))->get_value()...); } template decltype(auto) tuple_get_labels_impl(const Tuple& t, std::index_sequence){ return std::make_tuple(std::get<0>(std::get(t))...); } } /** * Converts a tuple of pairs of label/Value objects to a tuple of the contained values */ template std::tuple tuple_get_values(const std::tuple*>...>& t){ return detail::tuple_get_values_impl*>...>>(t, std::index_sequence_for{}); } /** * Converts a tuple of pairs of label/Value objects to a tuple of just the * labels */ template decltype(auto) tuple_get_labels(const std::tuple*>...>& t){ return detail::tuple_get_labels_impl*>...>>(t, std::index_sequence_for{}); } //----------------------- template char type_lookup(){ return 0; } template <> char type_lookup(){ return 'I'; } template <> char type_lookup(){ return 'F'; } template <> char type_lookup(){ return 'F'; } template class MVAData : public DerivedValue>>{ private: std::tuple*>...> data; Value* is_training; Value* is_signal; Value* weight; void update_value(){ this->value = std::make_tuple(is_training->get_value(), is_signal->get_value(), weight->get_value(), tuple_get_values(data)); } template static std::vector> get_label_types_impl(std::pair*>... pairs){ return std::vector>({ std::make_pair(pairs.first,type_lookup())...}); } public: typedef std::tuple> type; std::vector> get_label_types(){ return call(get_label_types_impl, data); } static std::string fmt_name(Value* is_training, Value* is_signal, Value* weight, const std::pair*>&&... data_vals){ //TODO: add data names return "mva_data("+is_training->get_name()+"," +is_signal->get_name()+"," +weight->get_name()+")"; } MVAData(Value* is_training, Value* is_signal, Value* weight, const std::pair*>&&... data_vals) :DerivedValue(fmt_name(is_training, is_signal, weight, std::forward*>>(data_vals)...),""), data(std::make_tuple(data_vals...)), is_training(is_training), is_signal(is_signal), weight(weight) { } }; } #endif // root_value_hpp