9 #include <generators/modules/GeneratedVertexDisplacerModule.h>
10 #include <framework/core/ModuleParam.templateDetails.h>
30 R
"DOC(""Takes a list of PDG values and lifetime paramters to displaces the vertex of MCParticles with matching PDG value corresponding to the given lifetime parameter. Can be used betwenerator and the detector simulation.)DOC");
33 addParam(
"lifetimeOption", m_lifetimeOption,
34 "Set the lifetime option, either 'fixed', 'flat' or 'exponential'. Option is set globally.",
string(
"fixed"));
35 addParam(
"lifetime", m_lifetime,
36 "Set the numerical value of the lifetime c*tau in units of [cm]. Example: (lifetime_1, lifetime_2, ... ,lifetime_N). Lifetime_X is set for PDG_X.",
37 std::vector<float> {0});
38 addParam(
"pdgVal", m_pdgVals,
39 "PDG values of MCParticles that should be displaced. Subsequent daughters of these will be displaced accordingly. Example: (PDG_1, PDG_2, ... , PDG_N). PDG_X corresponds to lifetime_X.",
40 std::vector<int> { -999});
41 addParam(
"maxDecayTime", m_maxDecayTime,
42 "Set the maximal allowed decay time in c*tau [cm] for the option 'flat'. The 'exponential' option is not bound. Default 300cm.",
43 static_cast<float>(300));
44 addParam(
"ctau", m_ctau,
45 "Input unit option. True (default): module expects lifetime as ctau [cm]. False: lifetime as tau [ns].",
54 B2DEBUG(0,
"Initialize GeneratedVertexDisplacerModule");
55 m_mcparticles.isRequired(m_particleList);
57 if (m_pdgVals.size() != m_lifetime.size()) {
58 B2FATAL(
"List of PDG values and lifetime parameters have different sizes. Specify a lifetime for each PDG value.");
61 if ((m_lifetimeOption.compare(
"fixed") != 0) && (m_lifetimeOption.compare(
"flat") != 0)
62 && (m_lifetimeOption.compare(
"exponential") != 0)) {
63 B2FATAL(
"Lifetime option must be 0 (fixed), 1 (flat) or 2 (exponential).");
71 if (m_mcparticles.getEntries() < 1) {
72 B2WARNING(
"MC particle container empty. Calling next event.");
76 for (
int mcp_index = 0; mcp_index < m_mcparticles.getEntries(); mcp_index++) {
82 int mcp_pdg = mcp.
getPDG();
84 for (
unsigned int param_index = 0; param_index < m_pdgVals.size(); param_index++) {
85 if (m_pdgVals.at(param_index) == mcp_pdg) {
86 B2DEBUG(0,
"Displacing Vertex of particle with pdg_id: " << mcp_pdg <<
" with lifetime: " << m_lifetime.at(
87 param_index) <<
" and option: " << m_lifetimeOption);
88 displace(mcp, m_lifetime.at(param_index));
100 TLorentzVector* displacementVector =
new TLorentzVector();
101 getDisplacement(particle, lifetime, *displacementVector);
103 TVector3 newDecayVertex = particle.getProductionVertex();
104 newDecayVertex.SetX(newDecayVertex.X() + displacementVector->X());
105 newDecayVertex.SetY(newDecayVertex.Y() + displacementVector->Y());
106 newDecayVertex.SetZ(newDecayVertex.Z() + displacementVector->Z());
108 particle.setDecayVertex(newDecayVertex);
109 particle.setDecayTime(particle.getProductionTime() + displacementVector->T());
110 particle.setValidVertex(
true);
113 if (particle.getNDaughters()) {
114 displaceDaughter(*displacementVector, particle.getDaughters());
117 delete displacementVector;
123 for (
unsigned int daughter_index = 0; daughter_index < daughters.size(); daughter_index++) {
125 MCParticle* daughter_mcp = daughters.at(daughter_index);
129 MCParticle& mcp = *m_mcparticles[daughter_mcpArrayIndex];
136 displaceDaughter(motherDisplacementVector, daughter_mcp->
getDaughters());
143 const MCParticle& particle,
float lifetime, TLorentzVector& displacement)
145 TLorentzVector fourVector_mcp = particle.get4Vector();
146 float decayLength_mcp = 0;
149 if (m_lifetimeOption.compare(
"fixed") == 0) decayLength_mcp = lifetime;
150 else if (m_lifetimeOption.compare(
"flat") == 0) decayLength_mcp = gRandom->Uniform(0, m_maxDecayTime);
152 decayLength_mcp = -1 * std::log(gRandom->Uniform(0, 1.)) * lifetime * fourVector_mcp.Gamma() * fourVector_mcp.Beta();
154 if (!particle.getMass()) {
155 B2WARNING(
"Displacing a particle with zero mass. Forcing Gamma=1 for the decay time.");
156 decayLength_mcp = -1 * std::log(gRandom->Uniform(0, 1.)) * lifetime;
160 float pMag = fourVector_mcp.P();
161 displacement.SetX(decayLength_mcp * fourVector_mcp.X() / pMag);
162 displacement.SetY(decayLength_mcp * fourVector_mcp.Y() / pMag);
163 displacement.SetZ(decayLength_mcp * fourVector_mcp.Z() / pMag);
static const double speedOfLight
[cm/ns]
"Takes a list of PDG values and lifetime paramters to displaces the vertex of MCParticles with matchi...
void getDisplacement(const MCParticle &particle, float lifetime, TLorentzVector &displacement)
Helper function to calculate the numerical value of the vertex displacement (x,y,z,...
void displaceDaughter(TLorentzVector &motherDisplacementVector, std::vector< MCParticle * > daughters)
Helper function to loop over subsequent daughters and displaces their vertices corresponding to their...
virtual void initialize() override
Register input and output data, initialises the module.
virtual void event() override
Method is called for each event.
virtual void terminate() override
Terminates the module.
void displace(MCParticle &particle, float lifetime)
Helper function to displace the mother particles (corresponding to given pdf values).
A Class to store the Monte Carlo particle information.
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
@ c_PrimaryParticle
bit 0: Particle is primary particle.
void setProductionVertex(const TVector3 &vertex)
Set production vertex position.
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
void setValidVertex(bool valid)
Set indication wether vertex and time information is valid or just default.
int getNDaughters() const
Return number of daughter MCParticles.
TVector3 getDecayVertex() const
Return decay vertex.
int getPDG() const
Return PDG code of particle.
float getProductionTime() const
Return production time in ns.
TVector3 getProductionVertex() const
Return production vertex position.
void setProductionTime(float time)
Set production time.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.