10 #include <generators/modules/EventT0GeneratorModule.h>
13 #include <framework/gearbox/Unit.h>
14 #include <framework/logging/Logger.h>
41 setDescription(
"Module generates discrete event t0 in ~4ns steps (bunch spacing) "
42 "according to double gaussian distribution and adds it to the "
43 "production and decay times of MCParticles. This means that after "
44 "this module the time origin (t = 0) is set to what L1 trigger "
45 "would give as the collision time. In case of cosmics, the L1 trigger"
46 "jitter is generated according to a continuos double gaussian distribution");
48 setPropertyFlags(c_ParallelProcessingCertified);
51 addParam(
"coreGaussWidth", m_coreGaussWidth,
"sigma of core gaussian [ns]",
double(5.6));
52 addParam(
"tailGaussWidth", m_tailGaussWidth,
"sigma of tail gaussian [ns]",
double(14.5));
53 addParam(
"tailGaussFraction", m_tailGaussFraction,
54 "fraction (by area) of tail gaussian",
double(0.08));
55 addParam(
"fixedT0", m_fixedT0,
56 "If set, a fixed event t0 is used instead of simulating the bunch timing.", m_fixedT0);
57 addParam(
"maximumT0", m_maximumT0,
58 "If set, randomize between -maximum and maximum.",
60 addParam(
"isCosmics", m_isCosmics,
61 "if True simulate L1 jitter for cosmics",
bool(
false));
62 addParam(
"coreGaussWidthCosmics", m_coreGaussWidthCosmics,
"sigma of core gaussian for cosmics [ns]",
double(13));
63 addParam(
"tailGaussMeanCosmics", m_tailGaussMeanCosmics,
"mean of tail gaussian for cosmics [ns]",
double(28));
64 addParam(
"tailGaussWidthCosmics", m_tailGaussWidthCosmics,
"sigma of tail gaussian for cosmics [ns]",
double(15));
65 addParam(
"tailGaussFractionCosmics", m_tailGaussFractionCosmics,
66 "fraction (by area) of tail gaussian for cosmics",
double(0.09));
71 void EventT0GeneratorModule::initialize()
73 m_mcParticles.isRequired();
74 m_initialParticles.registerInDataStore();
75 m_simClockState.registerInDataStore();
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()
89 int beamRevo9Cycle = 0;
94 unsigned revo9range = (m_bunchStructure->getRFBucketsPerRevolution() / 4) * 9;
95 int revo9count = gRandom->Integer(revo9range);
100 bucket = m_bunchStructure->generateBucketNumber();
101 beamRevo9Cycle = gRandom->Integer(9);
102 int bucketRevo9 = bucket + beamRevo9Cycle * m_bunchStructure->getRFBucketsPerRevolution();
106 double timeJitter = 0;
107 if (not std::isnan(m_maximumT0)) {
108 timeJitter = -m_maximumT0 + (2 * m_maximumT0) * gRandom->Rndm();
109 }
else if (not std::isnan(m_fixedT0)) {
110 timeJitter = m_fixedT0;
112 double sigma = m_coreGaussWidth;
113 if (gRandom->Rndm() < m_tailGaussFraction) sigma = m_tailGaussWidth;
114 timeJitter = gRandom->Gaus(0., sigma);
119 double bucketTimeSep = 1 / m_clockSettings->getAcceleratorRF();
120 relBucketNo = round(timeJitter / bucketTimeSep);
121 revo9count = (bucketRevo9 + relBucketNo) / 4;
125 eventTime = (bucketRevo9 - revo9count * 4) * bucketTimeSep;
130 double sigma = m_coreGaussWidthCosmics;
131 if (gRandom->Rndm() < m_tailGaussFractionCosmics) sigma = m_tailGaussWidthCosmics;
132 eventTime = gRandom->Gaus(0., sigma);
137 for (
auto& particle : m_mcParticles) {
138 particle.setProductionTime(particle.getProductionTime() + eventTime);
139 particle.setDecayTime(particle.getDecayTime() + eventTime);
144 if (not m_initialParticles.isValid()) m_initialParticles.create();
145 m_initialParticles->setTime(eventTime);
148 revo9count %= revo9range;
149 if (revo9count < 0) revo9count += revo9range;
151 m_simClockState.create();
152 m_simClockState->setRevo9Count(revo9count);
153 m_simClockState->setBucketNumber(bucket);
154 m_simClockState->setBeamCycleNumber(beamRevo9Cycle);
155 m_simClockState->setRelativeBucketNo(relBucketNo);
Module generates discrete event t0 in ~4ns steps (bunch spacing) according to (double) gaussian distr...
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.