value.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. LorentzVectors(Value<std::vector<float>>* pt,
  28. Value<std::vector<float>>* eta,
  29. Value<std::vector<float>>* phi,
  30. Value<std::vector<float>>* mass,
  31. const std::string& alias)
  32. :DerivedValue<std::vector<TLorentzVector>>("lorentz_vectors("+pt->get_name()+","
  33. +eta->get_name()+","
  34. +phi->get_name()+","
  35. +mass->get_name()+")",
  36. alias),
  37. pt_val(pt), eta_val(eta), phi_val(phi), mass_val(mass) { }
  38. };
  39. class Energies : public DerivedValue<std::vector<float>>{
  40. protected:
  41. Value<std::vector<TLorentzVector>> *vectors;
  42. void update_value(){
  43. std::vector<TLorentzVector>& vecs = vectors->get_value();
  44. this->value.clear();
  45. for (auto v : vecs){
  46. this->value.push_back(v.Energy());
  47. }
  48. }
  49. public:
  50. Energies(Value<std::vector<TLorentzVector>> *vectors,
  51. const std::string& alias)
  52. :DerivedValue<std::vector<float>>("energies("+vectors->get_name()+")", alias),
  53. vectors(vectors) { }
  54. };
  55. }
  56. #endif // root_value_hpp