9#include <analysis/modules/NeutralHadron4MomentumCalculator/NeutralHadron4MomentumCalculatorModule.h> 
   11#include <framework/logging/Logger.h> 
   12#include <analysis/dataobjects/Particle.h> 
   13#include <analysis/DecayDescriptor/DecayDescriptorParticle.h> 
   14#include <analysis/utility/ParticleCopy.h> 
   26    R
"DOC(Calculates 4-momentum of a neutral hadron in a given decay chain e.g. B0 -> J/Psi K_L0, or anti-B0 -> p+ K- anti-n0.)DOC"); 
   30  addParam(
"decayString", 
m_decayString, 
"Decay string for which one wants to perform the calculation", std::string(
""));
 
 
   39  B2DEBUG(17, 
"Neutralhadron4MomentumCalculator: Use particle list: " << 
m_decayString);
 
   42    B2ERROR(
"NeutralHadron4MomentumCalculatorModule::initialize Invalid Decay Descriptor " << 
m_decayString);
 
   45  if (hierarchy.size() != 1)
 
   46    B2ERROR(
"NeutralHadron4MomentumCalculatorModule::initialize Only one particle can be selected in " << 
m_decayString);
 
   47  if (hierarchy[0].size() != 2)
 
   48    B2ERROR(
"NeutralHadron4MomentumCalculatorModule::initialize The selected particle must be a direct daughter " << 
m_decayString);
 
   50  std::string neutralHadronName = hierarchy[0][1].second;
 
   51  if (neutralHadronName != 
"n0" and neutralHadronName != 
"K_L0") {
 
   53      B2WARNING(
"NeutralHadron4MomentumCalculatorModule::initialize The selected particle is gamma but you allowed so; be aware.");
 
   55      B2WARNING(
"NeutralHadron4momentumCalculatorModule::initialize The selected particle can be from anything; the magnitude of " 
   56                "the momentum will be overridden by that calculated from the mother mass constraint; be aware.");
 
   58      B2ERROR(
"NeutralHadron4MomentumCalculatorModule::initialize The selected particle must be a long-lived neutral hadron " 
   59              "i.e. (anti-)n0 or K_L0, unless you set allowGamma to true and selected a photon (gamma), or you set " 
   60              "allowAnyParticleSource to true." 
   67  m_plist.isRequired(motherFullName);
 
 
   72  const unsigned int n = 
m_plist->getListSize();
 
   73  std::vector<unsigned int> toRemove;
 
   74  for (
unsigned i = 0; i < n; i++) {
 
   76    std::vector<Particle*> daughters = particle->
getDaughters();
 
   77    ROOT::Math::PxPyPzEVector others4Momentum;
 
   80        others4Momentum += daughters[j]->get4Vector();
 
   86    ROOT::Math::XYZVector neutralDirection = neutral->
getMomentum().Unit();
 
   87    double a = others4Momentum.Vect().Dot(neutralDirection);
 
   88    double b = (std::pow(particle->
getPDGMass(), 2) - std::pow(neutral->
getMass(), 2) - others4Momentum.mag2()) / 2.;
 
   89    double c = others4Momentum.E();
 
   90    double d = std::pow(neutral->
getMass(), 2);
 
   91    double D = (a * a - c * c) * d + b * b;
 
   93      double neutralP = (-1. * a * b - c * std::sqrt(D)) / (a * a - c * c);
 
   94      double neutralPx = neutralP * neutralDirection.X();
 
   95      double neutralPy = neutralP * neutralDirection.Y();
 
   96      double neutralPz = neutralP * neutralDirection.Z();
 
   97      double neutralE = std::sqrt(neutralP * neutralP + d);
 
   98      const ROOT::Math::PxPyPzEVector newNeutral4Momentum(neutralPx, neutralPy, neutralPz, neutralE);
 
  100      double motherPx = newNeutral4Momentum.Px() + others4Momentum.Px();
 
  101      double motherPy = newNeutral4Momentum.Py() + others4Momentum.Py();
 
  102      double motherPz = newNeutral4Momentum.Pz() + others4Momentum.Pz();
 
  103      double motherE = newNeutral4Momentum.E() + others4Momentum.E();
 
  104      const ROOT::Math::PxPyPzEVector newMother4Momentum(motherPx, motherPy, motherPz, motherE);
 
  112  m_plist->removeParticles(toRemove);
 
 
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
bool m_allowAnyParticleSource
Whether allow the selected particle to be from any ParticleSource.
void initialize() override
Initialization.
void event() override
Action to perform for each event.
std::string m_decayString
Decay string for which one wants to perform the calculation.
int m_iNeutral
Index of the neutral hadron in the decay string.
NeutralHadron4MomentumCalculatorModule()
Constructor: Sets the description, the properties and the parameters of the module.
DecayDescriptor m_decayDescriptor
Decay Descriptor to be initialized with m_decayString.
bool m_allowGamma
Whether allow the selected particle to be gamma.
StoreObjPtr< ParticleList > m_plist
ParticleList that one wants to perform the calculation.
Class to store reconstructed particles.
bool replaceDaughter(const Particle *oldDaughter, Particle *newDaughter)
Replace index of given daughter with new daughter, return true if a replacement is made.
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
double getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets Lorentz vector.
ROOT::Math::XYZVector getMomentum() const
Returns momentum vector.
double getMass() const
Returns invariant mass (= nominal for FS particles)
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Particle * copyParticle(const Particle *original)
Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
Abstract base class for different kinds of events.