9 #include <mdst/dataobjects/MCParticle.h>
10 #include <framework/logging/Logger.h>
11 #include <framework/datastore/DataStore.h>
12 #include <framework/datastore/StoreArray.h>
13 #include <framework/utilities/HTML.h>
14 #include <framework/utilities/Conversion.h>
16 #include <TDatabasePDG.h>
20 #include <boost/algorithm/string.hpp>
25 const double MCParticle::c_epsilon = 10e-7;
28 void MCParticle::setMassFromPDG()
30 if (TDatabasePDG::Instance()->GetParticle(m_pdg) ==
nullptr)
31 throw(ParticlePDGNotKnownError() << m_pdg);
32 m_mass = TDatabasePDG::Instance()->GetParticle(m_pdg)->Mass();
36 float MCParticle::getCharge()
const
43 if (TDatabasePDG::Instance()->GetParticle(m_pdg) ==
nullptr) {
44 B2ERROR(
"PDG=" << m_pdg <<
" ***code unknown to TDatabasePDG");
48 return TDatabasePDG::Instance()->GetParticle(m_pdg)->Charge() / 3.0;
52 vector<MCParticle*> MCParticle::getDaughters()
const
54 vector<MCParticle*> result;
55 if (m_firstDaughter > 0) {
57 if (m_lastDaughter > m_plist->GetEntriesFast())
throw LastChildIndexOutOfRangError();
58 TClonesArray& plist = *m_plist;
59 result.reserve(m_lastDaughter - m_firstDaughter + 1);
60 for (
int i = m_firstDaughter - 1; i < m_lastDaughter; i++) {
61 result.push_back(
static_cast<MCParticle*
>(plist[i]));
69 if (i >= getNDaughters()) {
72 return getDaughters().at(i);
75 int MCParticle::getNDaughters()
const
77 if (getFirstDaughter() == 0)
79 return getLastDaughter() - getFirstDaughter() + 1;
82 void MCParticle::fixParticleList()
const
84 if (m_plist != 0)
return;
86 TClonesArray* plist(0);
91 if (MCParticles && MCParticles.
getPtr()->IndexOf(
this) >= 0) {
92 plist = MCParticles.
getPtr();
97 TClonesArray* value =
dynamic_cast<TClonesArray*
>(iter->second.ptr);
98 if (value && value->GetClass() == Class() && value->IndexOf(
this) >= 0) {
106 B2ERROR(
"Could not determine StoreArray the MCParticle belongs to !");
107 throw NoParticleListSetError();
111 for (
int i = 0; i < plist->GetEntriesFast(); i++) {
117 std::string MCParticle::getName()
const
119 const TParticlePDG* p = TDatabasePDG::Instance()->GetParticle(m_pdg);
123 return std::to_string(m_pdg);
125 std::string MCParticle::getInfoHTML()
const
127 std::stringstream out;
128 out <<
"<b>Charge</b>=" << (int)getCharge();
129 out <<
", <b>PDG</b>=" << getPDG();
130 out <<
" (" << getName() <<
")";
132 out <<
"<b>isPrimaryParticle</b>=" << isPrimaryParticle();
133 out <<
",<b>isInitial</b>=" << isInitial();
134 out <<
",<b>isVirtual</b>=" << isVirtual();
137 out <<
"<b>pT</b>=" << getMomentum().Rho();
138 out <<
", <b>pZ</b>=" << m_momentum_z;
140 std::string unitType = HTML::chooseUnitOfLength(getProductionVertex());
142 out <<
"<b>V</b>=" << HTML::getStringConvertToUnit(getProductionVertex(), precision, unitType);
152 const MCParticle* MCParticle::getParticleFromGeneralizedIndexString(
const std::string& generalizedIndex)
const
155 std::vector<std::string> generalizedIndexes;
156 boost::split(generalizedIndexes, generalizedIndex, boost::is_any_of(
":"));
158 if (generalizedIndexes.empty()) {
159 B2WARNING(
"Generalized index of MC daughter particle is empty. Skipping.");
170 for (
auto& indexString : generalizedIndexes) {
174 dauIndex = Belle2::convertString<int>(indexString);
175 }
catch (std::invalid_argument&) {
176 B2WARNING(
"Found the string " << indexString <<
"instead of a daughter index.");
181 if (dauIndex >=
int(currentPart->
getNDaughters()) or dauIndex < 0) {
182 B2WARNING(
"Daughter index out of range" <<
LogVar(
"daughter index", dauIndex));
183 B2WARNING(
"Trying to access non-existing particle.");
187 currentPart = dauPart;
StoreEntryMap::const_iterator StoreEntryConstIter
const_iterator for a StoreEntry map.
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
A Class to store the Monte Carlo particle information.
virtual std::string getName() const override
Return name of this particle.
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
const MCParticle * getDaughter(int i) const
Return i-th daughter.
int getNDaughters() const
Return number of daughter MCParticles.
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
TClonesArray * getPtr() const
Raw access to the underlying TClonesArray.
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.