9 #include <analysis/modules/PrintMCParticles/PrintMCParticlesModule.h> 
   10 #include <analysis/dataobjects/StringWrapper.h> 
   12 #include <mdst/dataobjects/MCParticle.h> 
   14 #include <framework/geometry/B2Vector3.h> 
   16 #include <framework/logging/LogConnectionConsole.h> 
   18 #include <boost/format.hpp> 
   19 #include <boost/algorithm/string.hpp> 
   21 #include <TDatabasePDG.h> 
   22 #include <Math/Vector3D.h> 
   37   std::string statusToString(
const MCParticle& mc)
 
   39     static std::map<int, std::string> names {
 
   50     std::vector<std::string> set;
 
   51     for (
auto&& [status, name] : names) {
 
   52       if (mc.hasStatus(status)) set.emplace_back(name);
 
   54     return boost::join(set, 
", ");
 
   58   std::string g4ProcessToName(
int process)
 
   62     static std::map<int, std::string> translation{
 
   63       {1, 
"CoulombScattering"},
 
   65       {3, 
"Bremsstrahlung"},
 
   66       {4, 
"PairProdByCharged"},
 
   68       {6, 
"AnnihilationToMuMu"},
 
   69       {7, 
"AnnihilationToHadrons"},
 
   70       {8, 
"NuclearStopping"},
 
   71       {9, 
"ElectronGeneralProcess"},
 
   72       {10, 
"MultipleScattering"},
 
   74       {12, 
"PhotoElectricEffect"},
 
   75       {13, 
"ComptonScattering"},
 
   76       {14, 
"GammaConversion"},
 
   77       {15, 
"GammaConversionToMuMu"},
 
   78       {16, 
"GammaGeneralProcess"},
 
   80       {22, 
"Scintillation"},
 
   81       {23, 
"SynchrotronRadiation"},
 
   82       {24, 
"TransitionRadiation"},
 
   83       {111, 
"HadronElastic"},
 
   84       {121, 
"HadronInelastic"},
 
   86       {132, 
"MuAtomicCapture"},
 
   88       {151, 
"HadronAtRest"},
 
   89       {152, 
"LeptonAtRest"},
 
   90       {161, 
"ChargeExchange"},
 
   91       {210, 
"RadioactiveDecay"},
 
   93       {202, 
"Decay_WithSpin"},
 
   94       {203, 
"Decay_PionMakeSpin"},
 
   95       {210, 
"Decay_Radioactive"},
 
   96       {211, 
"Decay_Unknown"},
 
   97       {221, 
"Decay_MuAtom "},
 
   98       {231, 
"Decay_External"},
 
  100     if (
auto it = translation.find(process); it != translation.end()) {
 
  103     return "[Unknown process]";
 
  115   addParam(
"maxLevel", 
m_maxLevel, 
"Show only up to specified depth level, -1 means no limit", -1);
 
  119   addParam(
"showStatus", 
m_showStatus, 
"Show extendend status information of the particle", 
false);
 
  137     m_output << 
"Content of MCParticle list" << std::endl;
 
  141   std::vector<MCParticle*> first_gen;
 
  143     if (mc.getMother() != 
nullptr) 
continue;
 
  144     first_gen.emplace_back(&mc);
 
  161   particles.erase(std::remove_if(particles.begin(), particles.end(), [](
MCParticle * mc) {
 
  162     return not mc->hasStatus(MCParticle::c_PrimaryParticle);
 
  163   }), particles.end());
 
  172   std::string colorStart[] = {
"", 
""};
 
  173   std::string colorEnd = 
"";
 
  176     colorStart[0] = anyExtraInfo ? 
"\x1b[31;1m" : 
"\x1b[31m";
 
  177     colorStart[1] = anyExtraInfo ? 
"\x1b[1m" : 
"";
 
  181   TDatabasePDG* pdb = TDatabasePDG::Instance();
 
  184   const auto num_particles = particles.size();
 
  185   size_t particle_index{0};
 
  186   for (
const auto* mc : particles) {
 
  188     const bool last = ++particle_index == num_particles;
 
  189     m_output << indent << (last ? 
"╰" : 
"├");
 
  192     TParticlePDG* pdef = pdb->GetParticle(mc->getPDG());
 
  194     m_output << 
" (" << mc->getPDG() << 
")" << colorEnd;
 
  197     auto daughters = mc->getDaughters();
 
  202     const std::string newIndent = indent + (last ? 
" " : 
"│") + 
"   ";
 
  204     const std::string propIndent = 
"\n" + newIndent + (showDaughters ? 
"│ " : 
"");
 
  206     if ((not showDaughters) and (not daughters.empty())) {
 
  212       m_output << boost::format(
"mass=%.3g energy=%.3g charge=%d") % mc->getMass() % mc->getEnergy() % mc->getCharge();
 
  218       m_output << boost::format(
"p=(%.3g, %.3g, %.3g) |p|=%.3g") % p.X() % p.Y() % p.Z() % p.Mag();
 
  221       const ROOT::Math::XYZVector& v = mc->getVertex();
 
  223       m_output << boost::format(
"production vertex=(%.3g, %.3g, %.3g), time=%.3g") % v.X() % v.Y() % v.Z() % mc->getProductionTime();
 
  227       m_output << 
"status flags=" << statusToString(*mc);
 
  230         m_output << 
"creation process=" << g4ProcessToName(mc->getSecondaryPhysicsProcess());
 
  233       m_output << 
"list index=" << mc->getIndex();
 
  236     if (showDaughters and anyExtraInfo) 
m_output << propIndent;
 
  241       printTree(daughters, level + 1, newIndent);
 
  244     if (anyExtraInfo and not last) 
m_output << newIndent << std::endl;
 
static bool terminalSupportsColors(int fileDescriptor)
Returns true if the given file descriptor is a tty and supports colors.
A Class to store the Monte Carlo particle information.
@ c_IsFSRPhoton
bit 7: Particle is from finial state radiation
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
@ c_IsPHOTOSPhoton
bit 8: Particle is an radiative photon from PHOTOS
@ c_PrimaryParticle
bit 0: Particle is primary particle.
@ c_LeftDetector
bit 2: Particle left the detector (the simulation volume).
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
@ c_StoppedInDetector
bit 3: Particle was stopped in the detector (the simulation volume).
@ c_IsISRPhoton
bit 6: Particle is from initial state radiation
void setDescription(const std::string &description)
Sets the description of the module.
std::stringstream m_output
Buffer to keep all the output while building the tree.
virtual void initialize() override
init.
bool m_showProperties
Show remaining properties.
virtual void event() override
Method is called for each event.
StoreArray< MCParticle > m_mcparticles
store array for the MCParticles
bool m_showStatus
Show extended status information.
int m_maxLevel
Show only up to specified depth level.
PrintMCParticlesModule()
Constructor.
bool m_showVertices
Show particle production vertices.
void filterPrimaryOnly(std::vector< MCParticle * > &particles) const
if m_onlyPrimary is set remove all non primary particles from the given vector inplace
StoreObjPtr< StringWrapper > m_stringWrapper
string wrapper to store the MCDecayString
void printTree(const std::vector< MCParticle * > &particles, int level=1, const std::string &indent="")
Loops recursively over the MCParticle list and prints information about each particle.
bool m_showMomenta
Show particle momenta.
std::string m_particleList
The name of the MCParticle collection.
bool m_suppressPrint
Suppress print the information.
bool m_onlyPrimaries
Print only primary particles.
REG_MODULE(B2BIIConvertBeamParams)
Register the module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Abstract base class for different kinds of events.