value.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef root_value_hpp
  2. #define root_value_hpp
  3. #include "filval/value.hpp"
  4. #include "TLorentzVector.h"
  5. namespace fv::root{
  6. class LorentzVectors : public DerivedValue<std::vector<TLorentzVector>>{
  7. protected:
  8. Value<std::vector<float>> *pt_val;
  9. Value<std::vector<float>> *eta_val;
  10. Value<std::vector<float>> *phi_val;
  11. Value<std::vector<float>> *mass_val;
  12. void update_value(){
  13. auto pt = pt_val->get_value();
  14. auto eta = eta_val->get_value();
  15. auto phi = phi_val->get_value();
  16. auto mass = mass_val->get_value();
  17. std::vector<int> sizes = {pt.size(), eta.size(), phi.size(), mass.size()};
  18. int size = *std::min_element(sizes.begin(), sizes.end());
  19. this->value.clear();
  20. TLorentzVector lv;
  21. for (int i =0; i<size; i++){
  22. lv.SetPtEtaPhiM(pt[i], eta[i], phi[i], mass[i]);
  23. this->value.push_back(lv);
  24. }
  25. }
  26. public:
  27. static std::string fmt_name(Value<std::vector<float>>* pt, Value<std::vector<float>>* eta,
  28. Value<std::vector<float>>* phi, Value<std::vector<float>>* mass){
  29. return "lorentz_vectors("+pt->get_name()+"," +eta->get_name()+","+
  30. phi->get_name()+"," +mass->get_name()+")";
  31. }
  32. LorentzVectors(Value<std::vector<float>>* pt,
  33. Value<std::vector<float>>* eta,
  34. Value<std::vector<float>>* phi,
  35. Value<std::vector<float>>* mass,
  36. const std::string& alias)
  37. :DerivedValue<std::vector<TLorentzVector>>(fmt_name(pt,eta,phi,mass), alias),
  38. pt_val(pt), eta_val(eta), phi_val(phi), mass_val(mass) { }
  39. };
  40. class Energies : public DerivedValue<std::vector<float>>{
  41. protected:
  42. Value<std::vector<TLorentzVector>> *vectors;
  43. void update_value(){
  44. std::vector<TLorentzVector>& vecs = vectors->get_value();
  45. this->value.clear();
  46. for (auto v : vecs){
  47. this->value.push_back(v.Energy());
  48. }
  49. }
  50. public:
  51. static std::string fmt_name(Value<std::vector<TLorentzVector>> *vectors){
  52. return "energies("+vectors->get_name()+")";
  53. }
  54. Energies(Value<std::vector<TLorentzVector>> *vectors,
  55. const std::string& alias)
  56. :DerivedValue<std::vector<float>>(fmt_name(vectors), alias),
  57. vectors(vectors) { }
  58. };
  59. }
  60. #endif // root_value_hpp