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>
15 #include <TDatabasePDG.h>
23 const double MCParticle::c_epsilon = 10e-7;
26 void MCParticle::setMassFromPDG()
28 if (TDatabasePDG::Instance()->GetParticle(m_pdg) ==
nullptr)
29 throw(ParticlePDGNotKnownError() << m_pdg);
30 m_mass = TDatabasePDG::Instance()->GetParticle(m_pdg)->Mass();
34 float MCParticle::getCharge()
const
41 if (TDatabasePDG::Instance()->GetParticle(m_pdg) ==
nullptr) {
42 B2ERROR(
"PDG=" << m_pdg <<
" ***code unknown to TDatabasePDG");
46 return TDatabasePDG::Instance()->GetParticle(m_pdg)->Charge() / 3.0;
50 vector<MCParticle*> MCParticle::getDaughters()
const
52 vector<MCParticle*> result;
53 if (m_firstDaughter > 0) {
55 if (m_lastDaughter > m_plist->GetEntriesFast())
throw LastChildIndexOutOfRangError();
56 TClonesArray& plist = *m_plist;
57 result.reserve(m_lastDaughter - m_firstDaughter + 1);
58 for (
int i = m_firstDaughter - 1; i < m_lastDaughter; i++) {
59 result.push_back(
static_cast<MCParticle*
>(plist[i]));
65 int MCParticle::getNDaughters()
const
67 if (getFirstDaughter() == 0)
69 return getLastDaughter() - getFirstDaughter() + 1;
72 void MCParticle::fixParticleList()
const
74 if (m_plist != 0)
return;
76 TClonesArray* plist(0);
81 if (MCParticles && MCParticles.
getPtr()->IndexOf(
this) >= 0) {
82 plist = MCParticles.
getPtr();
87 TClonesArray* value =
dynamic_cast<TClonesArray*
>(iter->second.ptr);
88 if (value && value->GetClass() == Class() && value->IndexOf(
this) >= 0) {
96 B2ERROR(
"Could not determine StoreArray the MCParticle belongs to !");
97 throw NoParticleListSetError();
101 for (
int i = 0; i < plist->GetEntriesFast(); i++) {
107 std::string MCParticle::getName()
const
109 const TParticlePDG* p = TDatabasePDG::Instance()->GetParticle(m_pdg);
113 return std::to_string(m_pdg);
115 std::string MCParticle::getInfoHTML()
const
117 std::stringstream out;
118 out <<
"<b>Charge</b>=" << (int)getCharge();
119 out <<
", <b>PDG</b>=" << getPDG();
120 out <<
" (" << getName() <<
")";
122 out <<
"<b>isPrimaryParticle</b>=" << isPrimaryParticle();
123 out <<
",<b>isInitial</b>=" << isInitial();
124 out <<
",<b>isVirtual</b>=" << isVirtual();
127 out <<
"<b>pT</b>=" << getMomentum().Pt();
128 out <<
", <b>pZ</b>=" << m_momentum_z;
130 std::string unitType = HTML::chooseUnitOfLength(getProductionVertex());
132 out <<
"<b>V</b>=" << HTML::getStringConvertToUnit(getProductionVertex(), precision, unitType);
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.
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.
Abstract base class for different kinds of events.