TTTT Analysis 0.1

value.hpp
1 #ifndef root_value_hpp
2 #define root_value_hpp
3 #include "filval/value.hpp"
4 #include "TLorentzVector.h"
5
6 namespace fv::root{
7
8 class LorentzVectors : public DerivedValue<std::vector<TLorentzVector>>{
9 protected:
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;
14
15 void update_value(){
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());
22 this->value.clear();
23 TLorentzVector lv;
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);
27 }
28 }
29
30 public:
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()+")";
35 }
36
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) { }
44 };
45
46 class Energies : public DerivedValue<std::vector<float>>{
47 protected:
48 Value<std::vector<TLorentzVector>> *vectors;
49 void update_value(){
50 std::vector<TLorentzVector>& vecs = vectors->get_value();
51 this->value.clear();
52 for (auto v : vecs){
53 this->value.push_back(v.Energy());
54 }
55 }
56
57 public:
58 static std::string fmt_name(Value<std::vector<TLorentzVector>> *vectors){
59 return "energies("+vectors->get_name()+")";
60 }
61
62 Energies(Value<std::vector<TLorentzVector>> *vectors,
63 const std::string& alias)
64 :DerivedValue<std::vector<float>>(fmt_name(vectors), alias),
65 vectors(vectors) { }
66 };
67
68 }
69 #endif // root_value_hpp
std
fv::root
Definition: api.hpp:8
value.hpp