api.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef ROOT_API_HPP
  2. #define ROOT_API_HPP
  3. #include <string>
  4. #include <vector>
  5. #include <tuple>
  6. #include "filval/api.hpp"
  7. #include "filval/root/value.hpp"
  8. namespace fv::root{
  9. decltype(auto)
  10. lorentz_vectors(Value<std::vector<float>>* pt, Value<std::vector<float>>* eta,
  11. Value<std::vector<float>>* phi, Value<std::vector<float>>* mass,
  12. const std::string& alias=""){
  13. typedef std::vector<TLorentzVector> type;
  14. const std::string& name = root::LorentzVectors::fmt_name(pt, eta, phi, mass);
  15. if (check_exists<type>(name))
  16. return lookup<type>(name);
  17. else
  18. return (Value<type>*)new root::LorentzVectors(pt, eta, phi, mass, alias);
  19. }
  20. decltype(auto)
  21. lorentz_vectors(const std::string& pt_name, const std::string& eta_name,
  22. const std::string& phi_name, const std::string& mass_name,
  23. const std::string& alias=""){
  24. return lorentz_vectors(lookup<std::vector<float>>(pt_name), lookup<std::vector<float>>(eta_name),
  25. lookup<std::vector<float>>(phi_name), lookup<std::vector<float>>(mass_name),
  26. alias);
  27. }
  28. decltype(auto)
  29. energies(Value<std::vector<TLorentzVector>>* vectors, const std::string& alias="") {
  30. typedef std::vector<float> type;
  31. const std::string& name = root::Energies::fmt_name(vectors);
  32. if (check_exists<type>(name))
  33. return lookup<type>(name);
  34. else
  35. return (Value<type>*)new root::Energies(vectors, alias);
  36. }
  37. decltype(auto)
  38. energies(const std::string& vectors_name, const std::string& alias="") {
  39. return energies(lookup<std::vector<TLorentzVector>>(vectors_name), alias);
  40. }
  41. template<typename... DataTypes>
  42. decltype(auto)
  43. mva_data(Value<bool>* is_training, Value<bool>* is_signal, Value<double>* weight,
  44. const std::pair<std::string, Value<DataTypes>*>&&... data_vals) {
  45. typedef typename root::MVAData<DataTypes...> mva_type;
  46. typedef typename mva_type::type type;
  47. std::string alias="";
  48. const std::string& name = mva_type::fmt_name(is_training, is_signal, weight,
  49. std::forward<const std::pair<std::string,Value<DataTypes>*>>(data_vals)...);
  50. if (check_exists<type>(name))
  51. return lookup<type>(name);
  52. else
  53. return (Value<type>*)new mva_type(is_training, is_signal, weight,
  54. std::forward<const std::pair<std::string,Value<DataTypes>*>>(data_vals)...);
  55. }
  56. }
  57. #endif // ROOT_API_HPP