4 #include "TLorentzVector.h" 8 class LorentzVectors :
public DerivedValue<std::vector<TLorentzVector>>{
10 Value<std::vector<float>> *pt_val;
11 Value<std::vector<float>> *eta_val;
12 Value<std::vector<float>> *phi_val;
13 Value<std::vector<float>> *mass_val;
16 auto pt = pt_val->get_value();
17 auto eta = eta_val->get_value();
18 auto phi = phi_val->get_value();
19 auto mass = mass_val->get_value();
20 std::vector<int> sizes = {pt.size(), eta.size(), phi.size(), mass.size()};
21 int size = *std::min_element(sizes.begin(), sizes.end());
24 for (
int i =0; i<size; i++){
25 lv.SetPtEtaPhiM(pt[i], eta[i], phi[i], mass[i]);
26 this->value.push_back(lv);
31 static std::string fmt_name(Value<std::vector<float>>* pt, Value<std::vector<float>>* eta,
32 Value<std::vector<float>>* phi, Value<std::vector<float>>* mass){
33 return "lorentz_vectors("+pt->get_name()+
"," +eta->get_name()+
","+
34 phi->get_name()+
"," +mass->get_name()+
")";
37 LorentzVectors(Value<std::vector<float>>* pt,
38 Value<std::vector<float>>* eta,
39 Value<std::vector<float>>* phi,
40 Value<std::vector<float>>* mass,
41 const std::string& alias)
42 :DerivedValue<
std::vector<TLorentzVector>>(fmt_name(pt,eta,phi,mass), alias),
43 pt_val(pt), eta_val(eta), phi_val(phi), mass_val(mass) { }
46 class Energies :
public DerivedValue<std::vector<float>>{
48 Value<std::vector<TLorentzVector>> *vectors;
50 std::vector<TLorentzVector>& vecs = vectors->get_value();
53 this->value.push_back(v.Energy());
58 static std::string fmt_name(Value<std::vector<TLorentzVector>> *vectors){
59 return "energies("+vectors->get_name()+
")";
62 Energies(Value<std::vector<TLorentzVector>> *vectors,
63 const std::string& alias)
64 :DerivedValue<
std::vector<float>>(fmt_name(vectors), alias),
70 template<
typename Tuple, std::size_t... Is>
71 decltype(
auto) tuple_get_values_impl(const Tuple& t,
std::index_sequence<Is...>){
72 return std::make_tuple(std::get<1>(std::get<Is>(t))->get_value()...);
75 template<
typename Tuple, std::size_t... Is>
76 decltype(
auto) tuple_get_labels_impl(const Tuple& t,
std::index_sequence<Is...>){
77 return std::make_tuple(std::get<0>(std::get<Is>(t))...);
83 template<
typename... ArgTypes>
84 std::tuple<ArgTypes...> tuple_get_values(
const std::tuple<std::pair<std::string,Value<ArgTypes>*>...>& t){
85 return detail::tuple_get_values_impl<std::tuple<std::pair<std::string,Value<ArgTypes>*>...>>(t, std::index_sequence_for<ArgTypes...>{});
92 template<
typename... ArgTypes>
93 decltype(
auto) tuple_get_labels(const
std::tuple<
std::pair<
std::
string,Value<ArgTypes>*>...>& t){
94 return detail::tuple_get_labels_impl<std::tuple<std::pair<std::string,Value<ArgTypes>*>...>>(t, std::index_sequence_for<ArgTypes...>{});
100 template <
typename T>
105 char type_lookup<int>(){
109 char type_lookup<float>(){
113 char type_lookup<double>(){
118 template<
typename... DataTypes>
119 class MVAData :
public DerivedValue<std::tuple<bool,bool,double,std::tuple<DataTypes...>>>{
121 std::tuple<std::pair<std::string,Value<DataTypes>*>...> data;
122 Value<bool>* is_training;
123 Value<bool>* is_signal;
124 Value<double>* weight;
127 this->value = std::make_tuple(is_training->get_value(), is_signal->get_value(), weight->get_value(),
128 tuple_get_values(data));
131 template <
typename... Types>
132 static std::vector<std::pair<std::string, char>> get_label_types_impl(std::pair<std::string,Value<Types>*>... pairs){
133 return std::vector<std::pair<std::string, char>>({ std::make_pair(pairs.first,type_lookup<Types>())...});
138 typedef std::tuple<bool, bool, double, std::tuple<DataTypes...>> type;
141 std::vector<std::pair<std::string, char>> get_label_types(){
142 return call(get_label_types_impl<DataTypes...>, data);
145 static std::string fmt_name(Value<bool>* is_training, Value<bool>* is_signal, Value<double>* weight,
146 const std::pair<std::string, Value<DataTypes>*>&&... data_vals){
148 return "mva_data("+is_training->get_name()+
"," 149 +is_signal->get_name()+
"," 150 +weight->get_name()+
")";
153 MVAData(Value<bool>* is_training, Value<bool>* is_signal,
154 Value<double>* weight,
const std::pair<std::string, Value<DataTypes>*>&&... data_vals)
155 :DerivedValue<type>(fmt_name(is_training, is_signal, weight,
156 std::forward<const
std::pair<
std::string,Value<DataTypes>*>>(data_vals)...),
""),
157 data(
std::make_tuple(data_vals...)),
158 is_training(is_training),
159 is_signal(is_signal),
163 #endif // root_value_hpp
decltype(auto) constexpr call(F &&f, Tuple &&t)
Call a function f with the elements of the tuple t as arguments.