Belle II Software  release-06-02-00
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 include. */
10 #include <generators/modules/BoostMCParticlesModule.h>
11 
12 /* Belle2 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 <TLorentzVector.h>
19 
20 using namespace Belle2;
21 
22 REG_MODULE(BoostMCParticles)
23 
24 BoostMCParticlesModule::BoostMCParticlesModule() : Module(), m_firstEvent{true}, m_initial(0)
25 {
26  setDescription(
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  TLorentzVector 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  TLorentzVector productionVertex{mcParticle.getProductionVertex(), Const::speedOfLight * mcParticle.getProductionTime()};
56  productionVertex = m_boost * productionVertex;
57  mcParticle.setProductionVertex(productionVertex.X(), productionVertex.Y(), productionVertex.Z());
58  mcParticle.setProductionTime(productionVertex.T() / Const::speedOfLight);
59  }
60  if (mcParticle.getDecayTime() != 0.) { // Boost only if the decay vertex is not the default one.
61  TLorentzVector decayVertex{mcParticle.getDecayVertex(), Const::speedOfLight * mcParticle.getDecayTime()};
62  decayVertex = m_boost * decayVertex;
63  mcParticle.setDecayVertex(decayVertex.X(), decayVertex.Y(), decayVertex.Z());
64  mcParticle.setDecayTime(decayVertex.T() / Const::speedOfLight);
65  }
66  }
67 }
Module for boosting the MCParticles from CM to LAB frame.
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.
TLorentzRotation m_boost
Boost rotation.
InitialParticleGeneration m_initial
Initial particle generation.
StoreArray< MCParticle > m_mcParticles
MC particles.
static const double speedOfLight
[cm/ns]
Definition: Const.h:575
This class contains the initial state for the given event.
const TLorentzRotation & 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
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
void initialize()
function to be executed on initialize()
MCInitialParticles & generate()
Generate a new event.
Abstract base class for different kinds of events.