ATLAS Offline Software
IParticleFourMomBranch.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MUONTESTERTREE_IPARTICLEFOURMOMBRANCH_ICC
6 #define MUONTESTERTREE_IPARTICLEFOURMOMBRANCH_ICC
7 
8 namespace MuonVal {
9  template <typename T>
10  bool IParticleFourMomBranch::addVariable(const std::string& var,
11  const std::string& acc) {
12  if (getBranch<T>(var)) {
13  ATH_MSG_WARNING("The variable "<<var<<" has already been added.");
14  return true;
15  }
16  return addVariable(std::make_shared<ParticleVariableBranch<T>>(this->tree(),
17  name() + "_" + var,
18  acc.empty() ? var : acc));
19  }
20  template <typename T>
21  bool IParticleFourMomBranch::addVariable(T def_value,
22  const std::string& var,
23  const std::string& acc) {
24  if (!addVariable<T>(var, acc)) {
25  return false;
26  }
27  std::shared_ptr<ParticleVariableBranch<T>> br = getBranch<T>(var);
28  if (!br) {
29  ATH_MSG_ERROR( "Failed to retrieve "<<var<<".");
30  return false;
31  }
32  br->setDefault(def_value);
33  return true;
34  }
35  template <typename T>
36  bool IParticleFourMomBranch::addVariableGeV(const std::string& var,
37  const std::string& acc) {
38  if (getBranch<T>(var)) {
39  ATH_MSG_WARNING("The variable "<<var<<" has already been added.");
40  return true;
41  }
42  return addVariable(std::make_shared<ParticleVariableBranchGeV<T>>(this->tree(),
43  name() + "_" + var,
44  acc.empty() ? var : acc));
45  }
46  template <typename T>
47  bool IParticleFourMomBranch::addVariableGeV(T def_value,
48  const std::string& var,
49  const std::string& acc) {
50  if (!addVariableGeV<T>(var, acc)) {
51  return false;
52  }
53  std::shared_ptr<ParticleVariableBranch<T>> br = getBranch<T>(var);
54  if (!br) {
55  ATH_MSG_ERROR( "Failed to retrieve "<<var<<".");
56  return false;
57  }
58  br->setDefault(def_value);
59  return true;
60  }
61 
62  template <typename T>
63  std::shared_ptr<ParticleVariableBranch<T>> IParticleFourMomBranch::getBranch(const std::string& var) const {
64  const std::string searchMe{name() + "_" + var};
65  for (const auto& b : m_variables) {
66  if (b->name() == searchMe) {
67  return std::dynamic_pointer_cast<ParticleVariableBranch<T>>(b);
68  }
69  }
70  return std::shared_ptr<ParticleVariableBranch<T>>();
71  }
72 }
73 #endif