ATLAS Offline Software
AuxElementBranch.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef MUONTESTER_AUXELEMENTBRANCH_IXX
5 #define MUONTESTER_AUXELEMENTBRANCH_IXX
6 
7 
8 //########################################################################################
9 // AuxElementBranch
10 //########################################################################################
11 namespace MuonVal {
12 template <class T> void AuxElementBranch<T>::setAccessor(const std::string& name) {
13  if (!initialized()) m_acc = SG::ConstAccessor<T>(name);
14 }
15 template <class T> void AuxElementBranch<T>::push_back(const SG::AuxElement* p) {
16  if (p != nullptr) push_back(*p);
17 }
18 template <class T> void AuxElementBranch<T>::operator+=(const SG::AuxElement& p) { push_back(p); }
19 template <class T> void AuxElementBranch<T>::operator+=(const SG::AuxElement* p) { push_back(p); }
20 template <class T> void AuxElementBranch<T>::push_back(const SG::AuxElement& p) {
21  if (m_acc.isAvailable(p))
22  VectorBranch<T>::push_back(m_acc(p));
23  else if (hasDefault()) {
24  VectorBranch<T>::push_back(getDefault());
25  } else {
26  THROW_EXCEPTION("Decoration is not available to fill " + name());
27  }
28 }
29 template <class T>
30 AuxElementBranch<T>::AuxElementBranch(TTree* t, const std::string& var_name, const std::string& acc) :
31  VectorBranch<T>(t, var_name), m_acc(acc.empty() ? var_name : acc) {}
32 template <class T>
33 AuxElementBranch<T>::AuxElementBranch(MuonTesterTree& t, const std::string& var_name, const std::string& acc) :
34  VectorBranch<T>(t, var_name), m_acc(acc.empty() ? var_name : acc) {}
35 
36 //########################################################################################
37 // GenericAuxDecorationBranch
38 //########################################################################################
39 template <class T>
40  GenericAuxDecorationBranch<T>::GenericAuxDecorationBranch(TTree* t, const std::string& var_name, const FuncType_t& func):
41  VectorBranch<T>(t, var_name),
42  m_func{func}{}
43 template <class T>
44  GenericAuxDecorationBranch<T>::GenericAuxDecorationBranch(MuonTesterTree& t, const std::string& var_name, const FuncType_t& func):
45  VectorBranch<T>(t, var_name),
46  m_func{func}{}
47 
48 template <class T> void GenericAuxDecorationBranch<T>::push_back(const SG::AuxElement* p) { push_back(m_func(p)); }
49 template <class T> void GenericAuxDecorationBranch<T>::push_back(const SG::AuxElement& p) { push_back(&p); }
50 template <class T> void GenericAuxDecorationBranch<T>::operator+=(const SG::AuxElement* p) { push_back(p); }
51 template <class T> void GenericAuxDecorationBranch<T>::operator+=(const SG::AuxElement& p) { push_back(p); }
52 //########################################################################################
53 // ParticleVariableBranch
54 //########################################################################################
55 template <class T>
56 ParticleVariableBranch<T>::ParticleVariableBranch(TTree* t, const std::string& var_name, const std::string& acc) :
57  AuxElementBranch<T>(t, var_name, acc) {}
58 template <class T>
59 ParticleVariableBranch<T>::ParticleVariableBranch(MuonTesterTree& t, const std::string& var_name, const std::string& acc) :
60  AuxElementBranch<T>(t, var_name, acc) {}
61 template <class T> void ParticleVariableBranch<T>::push_back(const xAOD::IParticle* p) { AuxElementBranch<T>::push_back(p); }
62 template <class T> void ParticleVariableBranch<T>::push_back(const xAOD::IParticle& p) { AuxElementBranch<T>::push_back(p); }
63 template <class T> void ParticleVariableBranch<T>::operator+=(const xAOD::IParticle* p) { AuxElementBranch<T>::push_back(p); }
64 template <class T> void ParticleVariableBranch<T>::operator+=(const xAOD::IParticle& p) { AuxElementBranch<T>::push_back(p); }
65 
66 //########################################################################################
67 // ParticleVariableBranchGeV
68 //########################################################################################
69 template <class T>
70 ParticleVariableBranchGeV<T>::ParticleVariableBranchGeV(TTree* t, const std::string& var_name, const std::string& acc) :
71  ParticleVariableBranch<T>(t, var_name, acc) {}
72 
73 template <class T>
74 ParticleVariableBranchGeV<T>::ParticleVariableBranchGeV(MuonTesterTree& t, const std::string& var_name, const std::string& acc) :
75  ParticleVariableBranch<T>(t, var_name, acc) {}
76 
77 template <class T> void ParticleVariableBranchGeV<T>::push_back(const xAOD::IParticle* p) {
78  if (p) push_back(*p);
79 }
80 template <class T> void ParticleVariableBranchGeV<T>::push_back(const xAOD::IParticle& p) {
81  size_t s = size();
82  ParticleVariableBranch<T>::push_back(p);
83  constexpr double MeVtoGeV = 1.e-3;
84  get(s) *= MeVtoGeV;
85 }
86 }
87 #endif