Belle II Software  release-08-01-10
BoostMCParticlesModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 /* Own header. */
10 #include <generators/modules/BoostMCParticlesModule.h>
11 
12 /* Basf2 headers. */
13 #include <framework/dataobjects/MCInitialParticles.h>
14 #include <framework/gearbox/Const.h>
15 #include <framework/logging/Logger.h>
16 
17 /* ROOT headers. */
18 #include <Math/Vector4D.h>
19 
20 using namespace Belle2;
21 
22 REG_MODULE(BoostMCParticles);
23 
24 BoostMCParticlesModule::BoostMCParticlesModule() : Module(), m_firstEvent{true}, m_initial(0)
25 {
27  R"DOC(Module for boosting the MCParticles from CM to LAB frame. The module must be appended to the path only when HepMC, Hepevt or LHE input files are used.)DOC");
28  addParam("MCParticlesStoreArrayName", m_mcParticlesName, "Name of the MC particles StoreArray.", std::string(""));
29 }
30 
32 {
35  const MCInitialParticles& initial = m_initial.generate();
36  m_boost = initial.getCMSToLab();
37 }
38 
40 {
41  if (m_beamParameters.hasChanged()) {
42  if (not m_firstEvent) {
43  // Be lenient with the first event: BeamParameters may be changed because of some basf2 black magic,
44  // so print the warning only if it changes during subsequent events.
45  B2WARNING("BeamParameters changed within the same process, check if this is fine according to the primary generator you are using.");
46  }
47  const MCInitialParticles& initial = m_initial.generate();
48  m_boost = initial.getCMSToLab();
49  }
50  m_firstEvent = false;
51  for (MCParticle& mcParticle : m_mcParticles) {
52  ROOT::Math::PxPyPzEVector momentum = mcParticle.get4Vector();
53  mcParticle.set4Vector(m_boost * momentum);
54  if (mcParticle.getProductionTime() != 0.) { // Boost only if the production vertex is not the default one.
55  ROOT::Math::XYZVector v = mcParticle.getProductionVertex();
56  ROOT::Math::PxPyPzEVector productionVertex(v.X(), v.Y(), v.Z(), Const::speedOfLight * mcParticle.getProductionTime());
57  productionVertex = m_boost * productionVertex;
58  mcParticle.setProductionVertex(productionVertex.X(), productionVertex.Y(), productionVertex.Z());
59  mcParticle.setProductionTime(productionVertex.T() / Const::speedOfLight);
60  }
61  if (mcParticle.getDecayTime() != 0.) { // Boost only if the decay vertex is not the default one.
62  ROOT::Math::XYZVector v = mcParticle.getDecayVertex();
63  ROOT::Math::PxPyPzEVector decayVertex(v.X(), v.Y(), v.Z(), Const::speedOfLight * mcParticle.getDecayTime());
64  decayVertex = m_boost * decayVertex;
65  mcParticle.setDecayVertex(decayVertex.X(), decayVertex.Y(), decayVertex.Z());
66  mcParticle.setDecayTime(decayVertex.T() / Const::speedOfLight);
67  }
68  }
69 }
bool m_firstEvent
Flag for keeping track of the first call of the event() method.
DBObjPtr< BeamParameters > m_beamParameters
Beam parameters.
void initialize() override
Initialize.
std::string m_mcParticlesName
Name of the MC particles StoreArray.
InitialParticleGeneration m_initial
Initial particle generation.
StoreArray< MCParticle > m_mcParticles
MC particles.
ROOT::Math::LorentzRotation m_boost
Boost rotation.
static const double speedOfLight
[cm/ns]
Definition: Const.h:686
This class contains the initial state for the given event.
const ROOT::Math::LorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
void initialize()
function to be executed on initialize()
MCInitialParticles & generate()
Generate a new event.
Abstract base class for different kinds of events.