12 #include <generators/modules/EventT0GeneratorModule.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/datastore/StoreObjPtr.h>
19 #include <framework/gearbox/Unit.h>
20 #include <framework/logging/Logger.h>
47 setDescription(
"Module generates discrete event t0 in ~4ns steps (bunch spacing) "
48 "according to double gaussian distribution and adds it to the "
49 "production and decay times of MCParticles. This means that after "
50 "this module the time origin (t = 0) is set to what L1 trigger "
51 "would give as the collision time.");
53 setPropertyFlags(c_ParallelProcessingCertified);
56 addParam(
"coreGaussWidth", m_coreGaussWidth,
"sigma of core gaussian [ns]", 10.0);
57 addParam(
"tailGaussWidth", m_tailGaussWidth,
"sigma of tail gaussian [ns]", 20.0);
58 addParam(
"tailGaussFraction", m_tailGaussFraction,
59 "fraction (by area) of tail gaussian", 0.0);
60 addParam(
"fixedT0", m_fixedT0,
61 "If set, a fixed event t0 is used instead of simulating the bunch timing.", m_fixedT0);
62 addParam(
"maximumT0", m_maximumT0,
63 "If set, randomize between -maximum and maximum.",
69 void EventT0GeneratorModule::initialize()
71 m_mcParticles.isRequired();
72 m_initialParticles.registerInDataStore();
75 m_bunchTimeSep = 2 * 1.96516 * Unit::ns;
77 if (not std::isnan(m_maximumT0) and not std::isnan(m_fixedT0)) {
78 B2ERROR(
"You can not set both the maximum T0 and the fixed T0 option.");
83 void EventT0GeneratorModule::event()
85 double collisionTime = 0.0f;
87 if (not std::isnan(m_maximumT0)) {
88 collisionTime = -m_maximumT0 + (2 * m_maximumT0) * gRandom->Rndm();
89 }
else if (not std::isnan(m_fixedT0)) {
90 collisionTime = m_fixedT0;
93 double sigma = m_coreGaussWidth;
94 if (gRandom->Rndm() < m_tailGaussFraction) sigma = m_tailGaussWidth;
96 collisionTime = gRandom->Gaus(0., sigma);
98 const int relBunchNo = round(collisionTime / m_bunchTimeSep);
99 collisionTime = relBunchNo * m_bunchTimeSep;
102 for (
auto& particle : m_mcParticles) {
103 particle.setProductionTime(particle.getProductionTime() + collisionTime);
104 particle.setDecayTime(particle.getDecayTime() + collisionTime);
108 if (!m_initialParticles.isValid()) m_initialParticles.create();
109 m_initialParticles->setTime(collisionTime);