ATLAS Offline Software
AuxElementBranch.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef MUONTESTER_AUXELEMENTBRANCH_IXX
5 #define MUONTESTER_AUXELEMENTBRANCH_IXX
6 
7 #include <MuonTesterTree/AuxElementBranch.h>
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::AuxElement::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 std::runtime_error("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 // ParticleVariableBranch
38 //########################################################################################
39 template <class T>
40 ParticleVariableBranch<T>::ParticleVariableBranch(TTree* t, const std::string& var_name, const std::string& acc) :
41  AuxElementBranch<T>(t, var_name, acc) {}
42 template <class T>
43 ParticleVariableBranch<T>::ParticleVariableBranch(MuonTesterTree& t, const std::string& var_name, const std::string& acc) :
44  AuxElementBranch<T>(t, var_name, acc) {}
45 template <class T> void ParticleVariableBranch<T>::push_back(const xAOD::IParticle* p) { AuxElementBranch<T>::push_back(p); }
46 template <class T> void ParticleVariableBranch<T>::push_back(const xAOD::IParticle& p) { AuxElementBranch<T>::push_back(p); }
47 template <class T> void ParticleVariableBranch<T>::operator+=(const xAOD::IParticle* p) { AuxElementBranch<T>::push_back(p); }
48 template <class T> void ParticleVariableBranch<T>::operator+=(const xAOD::IParticle& p) { AuxElementBranch<T>::push_back(p); }
49 
50 //########################################################################################
51 // ParticleVariableBranchGeV
52 //########################################################################################
53 template <class T>
54 ParticleVariableBranchGeV<T>::ParticleVariableBranchGeV(TTree* t, const std::string& var_name, const std::string& acc) :
55  ParticleVariableBranch<T>(t, var_name, acc) {}
56 
57 template <class T>
58 ParticleVariableBranchGeV<T>::ParticleVariableBranchGeV(MuonTesterTree& t, const std::string& var_name, const std::string& acc) :
59  ParticleVariableBranch<T>(t, var_name, acc) {}
60 
61 template <class T> void ParticleVariableBranchGeV<T>::push_back(const xAOD::IParticle* p) {
62  if (p) push_back(*p);
63 }
64 template <class T> void ParticleVariableBranchGeV<T>::push_back(const xAOD::IParticle& p) {
65  size_t s = size();
66  ParticleVariableBranch<T>::push_back(p);
67  constexpr double MeVtoGeV = 1.e-3;
68  get(s) *= MeVtoGeV;
69 }
70 }
71 #endif