Belle II Software development
ScintillatorSimulator Class Reference

Digitize EKLMSim2Hits to get EKLM StripHits. More...

#include <ScintillatorSimulator.h>

Classes

struct  Photoelectron
 Photoelectron data. More...
 

Public Member Functions

 ScintillatorSimulator (const KLMScintillatorDigitizationParameters *digPar, ScintillatorFirmware *fitter, double digitizationInitialTime, bool debug)
 Constructor.
 
 ScintillatorSimulator (const ScintillatorSimulator &)=delete
 Copy constructor (disabled).
 
ScintillatorSimulatoroperator= (const ScintillatorSimulator &)=delete
 Operator = (disabled).
 
 ~ScintillatorSimulator ()
 Destructor.
 
void simulate (const std::multimap< KLMChannelNumber, const KLMSimHit * >::iterator &firstHit, const std::multimap< KLMChannelNumber, const KLMSimHit * >::iterator &end)
 Simulate a strip.
 
KLMScintillatorFirmwareFitResultgetFPGAFit ()
 Get fit data.
 
enum ScintillatorFirmwareFitStatus getFitStatus () const
 Get fit status.
 
double getNPhotoelectrons ()
 Get number of photoelectrons (fit result).
 
int getNGeneratedPhotoelectrons ()
 Get generated number of photoelectrons.
 
double getEnergy ()
 Get total energy deposited in the strip (sum over ssimulation hits).
 
void setFEEData (const KLMScintillatorFEEData *FEEData)
 Set FEE data.
 
void generatePhotoelectrons (double stripLen, double distSiPM, int nPhotons, double timeShift, bool isReflected)
 Generate photoelectrons.
 
void fillSiPMOutput (float *hist, bool useDirect, bool useReflected)
 Fill SiPM output.
 
float getMCTime () const
 Get MC time.
 
float getSiPMMCTime () const
 Get SiPM MC time.
 

Private Member Functions

void reallocPhotoElectronBuffers (int size)
 Reallocate photoelectron buffers.
 
void prepareSimulation ()
 Prepare simulation.
 
void performSimulation ()
 Perform common simulation stage.
 
int * sortPhotoelectrons (int nPhotoelectrons)
 Sort photoelectrons.
 
void addRandomSiPMNoise ()
 Add random noise to the signal (amplitude-dependend).
 
void simulateADC ()
 Simulate ADC (create digital signal from analog),.
 
void debugOutput ()
 Debug output (signal and fit result histograms).
 

Private Attributes

const KLMTimem_Time
 Time.
 
const KLMScintillatorDigitizationParametersm_DigPar
 Parameters.
 
ScintillatorFirmwarem_fitter
 Fitter.
 
double m_DigitizationInitialTime
 Initial digitization time.
 
bool m_Debug
 Debug mode (generates additional output files with histograms).
 
double m_histRange
 Time range, (number of digitizations) * (ADC sampling time).
 
float * m_amplitudeDirect
 Analog amplitude (direct).
 
float * m_amplitudeReflected
 Analog amplitude (reflected).
 
float * m_amplitude
 Analog amplitude.
 
int * m_ADCAmplitude
 Digital amplitude.
 
double * m_SignalTimeDependence
 Buffer for signal time dependence calculation.
 
double * m_SignalTimeDependenceDiff
 Buffer for signal time dependence calculation.
 
struct Photoelectronm_Photoelectrons
 Buffer for photoelectron data.
 
int * m_PhotoelectronIndex
 Buffer for photoelectron indices.
 
int * m_PhotoelectronIndex2
 Buffer for photoelectron indices.
 
int m_PhotoelectronBufferSize
 Size of photoelectron data buffer.
 
enum ScintillatorFirmwareFitStatus m_FPGAStat
 FPGA fit status.
 
KLMScintillatorFirmwareFitResult m_FPGAFit
 FPGA fit data.
 
int m_npe
 Number of photoelectrons (generated).
 
double m_Energy
 Total energy deposited in the strip.
 
std::string m_stripName
 Name of the strip.
 
double m_Pedestal
 Pedestal.
 
double m_PhotoelectronAmplitude
 Photoelectron amplitude.
 
int m_Threshold
 Threshold.
 
float m_MCTime
 MC time.
 
float m_SiPMMCTime
 MC time at SiPM.
 

Detailed Description

Digitize EKLMSim2Hits to get EKLM StripHits.

Definition at line 30 of file ScintillatorSimulator.h.

Constructor & Destructor Documentation

◆ ScintillatorSimulator()

ScintillatorSimulator ( const KLMScintillatorDigitizationParameters * digPar,
ScintillatorFirmware * fitter,
double digitizationInitialTime,
bool debug )

Constructor.

Parameters
[in]digParDigitization parameters.
[in]digitizationInitialTimeInitial digitization time.
[in]fitterFitter.
[in]debugUse debug mode.

Definition at line 62 of file ScintillatorSimulator.cc.

65 :
66 m_Time(&(KLMTime::Instance())),
67 m_DigPar(digPar),
68 m_fitter(fitter),
69 m_DigitizationInitialTime(digitizationInitialTime),
70 m_Debug(debug),
71 m_FPGAStat(c_ScintillatorFirmwareNoSignal),
72 m_npe(0),
73 m_Energy(0),
74 m_MCTime(-1),
75 m_SiPMMCTime(-1)
76{
77 int i;
78 const double samplingTime = m_DigPar->getADCSamplingTDCPeriods() *
79 m_Time->getTDCPeriod();
80 /* cppcheck-suppress variableScope */
81 double time, attenuationTime;
82 m_histRange = m_DigPar->getNDigitizations() * samplingTime;
83 m_Pedestal = m_DigPar->getADCPedestal();
84 m_PhotoelectronAmplitude = m_DigPar->getADCPEAmplitude();
85 m_Threshold = m_DigPar->getADCThreshold();
86 /* Amplitude arrays. */
87 m_amplitudeDirect = (float*)malloc(m_DigPar->getNDigitizations() *
88 sizeof(float));
89 if (m_amplitudeDirect == nullptr)
90 B2FATAL(MemErr);
91 m_amplitudeReflected = (float*)malloc(m_DigPar->getNDigitizations() *
92 sizeof(float));
93 if (m_amplitudeReflected == nullptr)
94 B2FATAL(MemErr);
95 m_amplitude = (float*)malloc(m_DigPar->getNDigitizations() * sizeof(float));
96 if (m_amplitude == nullptr)
97 B2FATAL(MemErr);
98 m_ADCAmplitude = (int*)malloc(m_DigPar->getNDigitizations() * sizeof(int));
99 if (m_ADCAmplitude == nullptr)
100 B2FATAL(MemErr);
101 m_SignalTimeDependence = (double*)malloc((m_DigPar->getNDigitizations() + 1) *
102 sizeof(double));
103 if (m_SignalTimeDependence == nullptr)
104 B2FATAL(MemErr);
105 m_SignalTimeDependenceDiff = (double*)malloc(m_DigPar->getNDigitizations() *
106 sizeof(double));
107 if (m_SignalTimeDependenceDiff == nullptr)
108 B2FATAL(MemErr);
109 attenuationTime = 1.0 / m_DigPar->getPEAttenuationFrequency();
110 for (i = 0; i <= m_DigPar->getNDigitizations(); i++) {
111 time = samplingTime * i;
112 m_SignalTimeDependence[i] =
113 exp(-digPar->getPEAttenuationFrequency() * time) * attenuationTime /
114 samplingTime;
115 if (i > 0) {
116 m_SignalTimeDependenceDiff[i - 1] = m_SignalTimeDependence[i - 1] -
117 m_SignalTimeDependence[i];
118 }
119 }
120 m_Photoelectrons = nullptr;
121 m_PhotoelectronIndex = nullptr;
122 m_PhotoelectronIndex2 = nullptr;
123 reallocPhotoElectronBuffers(100);
124}
static KLMTime & Instance()
Instantiation.
Definition KLMTime.cc:14

◆ ~ScintillatorSimulator()

Destructor.

Definition at line 127 of file ScintillatorSimulator.cc.

128{
129 free(m_amplitudeDirect);
130 free(m_amplitudeReflected);
131 free(m_amplitude);
132 free(m_ADCAmplitude);
133 free(m_SignalTimeDependence);
134 free(m_SignalTimeDependenceDiff);
135 free(m_Photoelectrons);
136 free(m_PhotoelectronIndex);
137 free(m_PhotoelectronIndex2);
138}

Member Function Documentation

◆ addRandomSiPMNoise()

void addRandomSiPMNoise ( )
private

Add random noise to the signal (amplitude-dependend).

Definition at line 252 of file ScintillatorSimulator.cc.

253{
254 int i;
255 for (i = 0; i < m_DigPar->getNDigitizations(); i++)
256 m_amplitude[i] = m_amplitude[i] +
257 gRandom->PoissonD(m_DigPar->getMeanSiPMNoise());
258}

◆ debugOutput()

void debugOutput ( )
private

Debug output (signal and fit result histograms).

Definition at line 513 of file ScintillatorSimulator.cc.

514{
515 int i;
516 std::string str;
517 StoreObjPtr<EventMetaData> event;
518 TFile* hfile = nullptr;
519 TH1D* histAmplitudeDirect = nullptr;
520 TH1D* histAmplitudeReflected = nullptr;
521 TH1D* histAmplitude = nullptr;
522 TH1D* histADCAmplitude = nullptr;
523 try {
524 histAmplitudeDirect =
525 new TH1D("histAmplitudeDirect", m_stripName.c_str(),
526 m_DigPar->getNDigitizations(), 0, m_histRange);
527 histAmplitudeReflected =
528 new TH1D("histAmplitudeReflected", m_stripName.c_str(),
529 m_DigPar->getNDigitizations(), 0, m_histRange);
530 histAmplitude =
531 new TH1D("histAmplitude", m_stripName.c_str(),
532 m_DigPar->getNDigitizations(), 0, m_histRange);
533 histADCAmplitude =
534 new TH1D("histADCAmplitude", m_stripName.c_str(),
535 m_DigPar->getNDigitizations(), 0, m_histRange);
536 } catch (std::bad_alloc& ba) {
537 B2FATAL(MemErr);
538 }
539 for (i = 0; i < m_DigPar->getNDigitizations(); i++) {
540 histAmplitudeDirect->SetBinContent(i + 1, m_amplitudeDirect[i]);
541 histAmplitudeReflected->SetBinContent(i + 1, m_amplitudeReflected[i]);
542 histAmplitude->SetBinContent(i + 1, m_amplitude[i]);
543 histADCAmplitude->SetBinContent(i + 1, m_ADCAmplitude[i]);
544 }
545 str = std::string("experiment_") + std::to_string(event->getExperiment()) +
546 "_run_" + std::to_string(event->getRun()) + "_event_" +
547 std::to_string(event->getEvent()) + "_" + m_stripName + ".root";
548 try {
549 hfile = new TFile(str.c_str(), "NEW");
550 } catch (std::bad_alloc& ba) {
551 B2FATAL(MemErr);
552 }
553 hfile->Append(histAmplitudeDirect);
554 hfile->Append(histAmplitudeReflected);
555 hfile->Append(histAmplitude);
556 hfile->Append(histADCAmplitude);
557 hfile->Write();
558 hfile->Close();
559}

◆ fillSiPMOutput()

void fillSiPMOutput ( float * hist,
bool useDirect,
bool useReflected )

Fill SiPM output.

Parameters
[in,out]histOutput histogram (signal is added to it).
[in]useDirectUse direct photons.
[in]useReflectedUse reflected photons.

Definition at line 418 of file ScintillatorSimulator.cc.

420{
421 /* cppcheck-suppress variableScope */
422 int i, bin, maxBin;
423 double attenuationTime, sig, expSum;
424 /* cppcheck-suppress variableScope */
425 int ind1, ind2, ind3;
426 int* indexArray;
427 if (m_npe == 0)
428 return;
429 attenuationTime = 1.0 / m_DigPar->getPEAttenuationFrequency();
430 indexArray = sortPhotoelectrons(m_npe);
431 ind1 = 0;
432 expSum = 0;
433 while (1) {
434 ind2 = ind1;
435 bin = m_Photoelectrons[indexArray[ind1]].bin;
436 while (1) {
437 ind2++;
438 if (ind2 == m_npe)
439 break;
440 if (bin != m_Photoelectrons[indexArray[ind2]].bin)
441 break;
442 }
443 /* Now ind1 .. ind2 - photoelectrons in current bin. */
444 for (ind3 = ind1; ind3 != ind2; ind3++) {
445 if (m_Photoelectrons[indexArray[ind3]].isReflected && !useReflected)
446 continue;
447 if (!m_Photoelectrons[indexArray[ind3]].isReflected && !useDirect)
448 continue;
449 if (bin >= 0) {
450 sig = attenuationTime - m_Photoelectrons[indexArray[ind3]].expTime *
451 m_SignalTimeDependence[bin + 1];
452 hist[bin] = hist[bin] + sig;
453 }
454 expSum = expSum + m_Photoelectrons[indexArray[ind3]].expTime;
455 }
456 if (ind2 == m_npe)
457 maxBin = m_DigPar->getNDigitizations() - 1;
458 else
459 maxBin = m_Photoelectrons[indexArray[ind2]].bin;
460 for (i = bin + 1; i <= maxBin; i++) {
461 sig = m_SignalTimeDependenceDiff[i] * expSum;
462 hist[i] = hist[i] + sig;
463 }
464 if (ind2 == m_npe)
465 break;
466 ind1 = ind2;
467 }
468}

◆ generatePhotoelectrons()

void generatePhotoelectrons ( double stripLen,
double distSiPM,
int nPhotons,
double timeShift,
bool isReflected )

Generate photoelectrons.

Parameters
[in]stripLenStrip length.
[in]distSiPMDistance from hit to SiPM.
[in]nPhotonsNumber of photons to be simulated.
[in]timeShiftTime of hit.
[in]isReflectedWhether the hits are reflected or not.

Definition at line 308 of file ScintillatorSimulator.cc.

311{
312 const double samplingTime = m_DigPar->getADCSamplingTDCPeriods() *
313 m_Time->getTDCPeriod();
314 const double maxHitTime = m_DigPar->getNDigitizations() * samplingTime;
315 int i;
316 /* cppcheck-suppress variableScope */
317 double hitTime, deExcitationTime, cosTheta, hitDist, selection;
318 double inverseLightSpeed, inverseAttenuationLength;
319 inverseLightSpeed = 1.0 / m_DigPar->getFiberLightSpeed();
320 inverseAttenuationLength = 1.0 / m_DigPar->getAttenuationLength();
321 /* Generation of photoelectrons. */
322 for (i = 0; i < nPhotons; i++) {
323 if (m_npe >= m_PhotoelectronBufferSize)
324 reallocPhotoElectronBuffers(m_npe + 100);
325 cosTheta = gRandom->Uniform(m_DigPar->getMinCosTheta(), 1);
326 if (!isReflected)
327 hitDist = distSiPM / cosTheta;
328 else
329 hitDist = (2.0 * stripLen - distSiPM) / cosTheta;
330 /* Fiber absorption. */
331 selection = gRandom->Uniform();
332 if (selection > exp(-hitDist * inverseAttenuationLength))
333 continue;
334 /* Account for mirror reflective index. */
335 if (isReflected) {
336 selection = gRandom->Uniform();
337 if (selection > m_DigPar->getMirrorReflectiveIndex())
338 continue;
339 }
340 deExcitationTime =
341 gRandom->Exp(m_DigPar->getScintillatorDeExcitationTime()) +
342 gRandom->Exp(m_DigPar->getFiberDeExcitationTime());
343 hitTime = hitDist * inverseLightSpeed + deExcitationTime +
344 timeShift - m_DigitizationInitialTime;
345 if (hitTime >= maxHitTime)
346 continue;
347 if (hitTime >= 0)
348 m_Photoelectrons[m_npe].bin = floor(hitTime / samplingTime);
349 else
350 m_Photoelectrons[m_npe].bin = -1;
351 m_Photoelectrons[m_npe].expTime =
352 exp(m_DigPar->getPEAttenuationFrequency() * hitTime);
353 m_Photoelectrons[m_npe].isReflected = isReflected;
354 m_PhotoelectronIndex[m_npe] = m_npe;
355 m_npe++;
356 }
357}

◆ getEnergy()

double getEnergy ( )

Get total energy deposited in the strip (sum over ssimulation hits).

Definition at line 508 of file ScintillatorSimulator.cc.

509{
510 return m_Energy;
511}

◆ getFitStatus()

enum KLM::ScintillatorFirmwareFitStatus getFitStatus ( ) const

Get fit status.

Returns
Status of the fit.

Definition at line 490 of file ScintillatorSimulator.cc.

491{
492 return m_FPGAStat;
493}

◆ getFPGAFit()

Get fit data.

Definition at line 485 of file ScintillatorSimulator.cc.

486{
487 return &m_FPGAFit;
488}

◆ getMCTime()

float getMCTime ( ) const
inline

Get MC time.

Returns
MC time.

Definition at line 132 of file ScintillatorSimulator.h.

133 {
134 return m_MCTime;
135 }

◆ getNGeneratedPhotoelectrons()

int getNGeneratedPhotoelectrons ( )

Get generated number of photoelectrons.

Definition at line 503 of file ScintillatorSimulator.cc.

504{
505 return m_npe;
506}

◆ getNPhotoelectrons()

double getNPhotoelectrons ( )

Get number of photoelectrons (fit result).

Definition at line 495 of file ScintillatorSimulator.cc.

496{
497 double intg;
498 intg = m_FPGAFit.getAmplitude();
499 return intg * m_DigPar->getPEAttenuationFrequency() /
500 m_PhotoelectronAmplitude;
501}

◆ getSiPMMCTime()

float getSiPMMCTime ( ) const
inline

Get SiPM MC time.

Returns
SiPM MC yime.

Definition at line 141 of file ScintillatorSimulator.h.

142 {
143 return m_SiPMMCTime;
144 }

◆ performSimulation()

void performSimulation ( )
private

Perform common simulation stage.

Definition at line 230 of file ScintillatorSimulator.cc.

231{
232 if (m_Debug) {
233 fillSiPMOutput(m_amplitudeDirect, true, false);
234 fillSiPMOutput(m_amplitudeReflected, false, true);
235 for (int i = 0; i < m_DigPar->getNDigitizations(); i++)
236 m_amplitude[i] = m_amplitudeDirect[i] + m_amplitudeReflected[i];
237 } else
238 fillSiPMOutput(m_amplitude, true, true);
239 /* SiPM noise and ADC. */
240 if (m_DigPar->getMeanSiPMNoise() > 0)
241 addRandomSiPMNoise();
242 simulateADC();
243 m_FPGAStat = m_fitter->fit(m_ADCAmplitude, m_Threshold, &m_FPGAFit);
244 if (m_FPGAStat != c_ScintillatorFirmwareSuccessfulFit)
245 return;
246 if (m_Debug) {
247 if (m_npe >= 10)
248 debugOutput();
249 }
250}

◆ prepareSimulation()

void prepareSimulation ( )
private

Prepare simulation.

Definition at line 148 of file ScintillatorSimulator.cc.

149{
150 m_MCTime = -1;
151 m_SiPMMCTime = -1;
152 m_npe = 0;
153 m_Energy = 0;
154 for (int i = 0; i < m_DigPar->getNDigitizations(); i++) {
155 if (m_Debug) {
156 m_amplitudeDirect[i] = 0;
157 m_amplitudeReflected[i] = 0;
158 } else
159 m_amplitude[i] = 0;
160 }
161}

◆ reallocPhotoElectronBuffers()

void reallocPhotoElectronBuffers ( int size)
private

Reallocate photoelectron buffers.

Parameters
[in]sizeNew size of buffers.

Definition at line 41 of file ScintillatorSimulator.cc.

42{
43 m_PhotoelectronBufferSize = size;
44 /*
45 * Here there is a memory leak in case of realloc() failure, but it does not
46 * matter because a fatal error is issued in this case.
47 */
48 m_Photoelectrons =
49 (struct Photoelectron*)realloc(m_Photoelectrons,
50 size * sizeof(struct Photoelectron));
51 m_PhotoelectronIndex = (int*)realloc(m_PhotoelectronIndex,
52 size * sizeof(int));
53 m_PhotoelectronIndex2 = (int*)realloc(m_PhotoelectronIndex2,
54 size * sizeof(int));
55 if (size != 0) {
56 if (m_Photoelectrons == nullptr || m_PhotoelectronIndex == nullptr ||
57 m_PhotoelectronIndex2 == nullptr)
58 B2FATAL(MemErr);
59 }
60}

◆ setFEEData()

void setFEEData ( const KLMScintillatorFEEData * FEEData)

Set FEE data.

Definition at line 140 of file ScintillatorSimulator.cc.

142{
143 m_Pedestal = FEEData->getPedestal();
144 m_PhotoelectronAmplitude = FEEData->getPhotoelectronAmplitude();
145 m_Threshold = FEEData->getThreshold();
146}
int getThreshold() const
Get threshold.
float getPhotoelectronAmplitude() const
Get photoelectron amplitude.
float getPedestal() const
Get pedestal.

◆ simulate()

void simulate ( const std::multimap< KLMChannelNumber, const KLMSimHit * >::iterator & firstHit,
const std::multimap< KLMChannelNumber, const KLMSimHit * >::iterator & end )

Simulate a strip.

Parameters
[in]firstHitFirst hit in this strip.
[in]endEnd of hit range.

Definition at line 163 of file ScintillatorSimulator.cc.

166{
167 m_stripName = "strip_" + std::to_string(firstHit->first);
168 prepareSimulation();
169 bklm::GeometryPar* geoPar = bklm::GeometryPar::instance();
170 const KLMSimHit* hit = firstHit->second;
171 double stripLength;
172 bool isBKLM = (hit->getSubdetector() == KLMElementNumbers::c_BKLM);
173 if (isBKLM) {
174 const bklm::Module* module =
175 geoPar->findModule(hit->getSection(), hit->getSector(), hit->getLayer());
176 stripLength =
177 2.0 * (hit->isPhiReadout() ?
178 module->getPhiScintHalfLength(hit->getStrip()) :
179 module->getZScintHalfLength(hit->getStrip()));
180 } else {
182 hit->getStrip()) / CLHEP::mm * Unit::mm;
183 }
184 std::vector<const KLMSimHit*> hits;
185 for (std::multimap<KLMChannelNumber, const KLMSimHit*>::iterator it = firstHit;
186 it != end; ++it)
187 hits.push_back(it->second);
188 std::sort(hits.begin(), hits.end(), compareKLMSimHits);
189 for (std::vector<const KLMSimHit*>::iterator it = hits.begin();
190 it != hits.end(); ++it) {
191 hit = *it;
192 m_Energy = m_Energy + hit->getEnergyDeposit();
193 /* Poisson mean for number of photons. */
194 double nPhotons = hit->getEnergyDeposit() * m_DigPar->getNPEperMeV();
195 /* Fill histograms. */
196 double sipmDistance, time;
197 if (isBKLM) {
198 sipmDistance = hit->getPropagationTime() *
199 m_DigPar->getFiberLightSpeed();
200 time = hit->getTime() + hit->getPropagationTime();
201 if (m_MCTime < 0) {
202 m_MCTime = hit->getTime();
203 m_SiPMMCTime = time;
204 } else {
205 if (hit->getTime() < m_MCTime)
206 m_MCTime = hit->getTime();
207 if (time < m_SiPMMCTime)
208 m_SiPMMCTime = time;
209 }
210 } else {
211 sipmDistance = 0.5 * stripLength - hit->getLocalPosition().X();
212 time = hit->getTime() + sipmDistance / m_DigPar->getFiberLightSpeed();
213 if (m_MCTime < 0)
214 m_MCTime = time;
215 else
216 m_MCTime = time < m_MCTime ? time : m_MCTime;
217 }
218 int generatedPhotons = gRandom->Poisson(nPhotons);
219 generatePhotoelectrons(stripLength, sipmDistance, generatedPhotons,
220 hit->getTime(), false);
221 if (m_DigPar->getMirrorReflectiveIndex() > 0) {
222 generatedPhotons = gRandom->Poisson(nPhotons);
223 generatePhotoelectrons(stripLength, sipmDistance, generatedPhotons,
224 hit->getTime(), true);
225 }
226 }
227 performSimulation();
228}
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
double getStripLength(int strip) const
Get strip length.
static const double mm
[millimeters]
Definition Unit.h:70
const Module * findModule(int section, int sector, int layer) const
Get the pointer to the definition of a module.
static GeometryPar * instance(void)
Static method to get a reference to the singleton GeometryPar instance.

◆ simulateADC()

void simulateADC ( )
private

Simulate ADC (create digital signal from analog),.

Definition at line 470 of file ScintillatorSimulator.cc.

471{
472 int i;
473 /* cppcheck-suppress variableScope */
474 double amp;
475 if (m_Pedestal == 0 || m_PhotoelectronAmplitude == 0)
476 B2FATAL("Incorrect EKLM ADC simulation parameters.");
477 for (i = 0; i < m_DigPar->getNDigitizations(); i++) {
478 amp = m_Pedestal - m_PhotoelectronAmplitude * m_amplitude[i];
479 if (amp < m_DigPar->getADCSaturation())
480 amp = m_DigPar->getADCSaturation();
481 m_ADCAmplitude[i] = floor(amp);
482 }
483}

◆ sortPhotoelectrons()

int * sortPhotoelectrons ( int nPhotoelectrons)
private

Sort photoelectrons.

Parameters
[in]nPhotoelectronsNumber of photoelectrons.
Returns
Pointer to index array.

Definition at line 260 of file ScintillatorSimulator.cc.

261{
262 int* currentIndexArray, *newIndexArray, *tmpIndexArray;
263 int i, i1, i2, i1Max, i2Max, j, mergeSize;
264 currentIndexArray = m_PhotoelectronIndex;
265 newIndexArray = m_PhotoelectronIndex2;
266 mergeSize = 1;
267 while (mergeSize < nPhotoelectrons) {
268 for (i = 0; i < nPhotoelectrons; i = i + 2 * mergeSize) {
269 i1 = i;
270 j = i;
271 i2 = i + mergeSize;
272 if (i2 > nPhotoelectrons)
273 i2 = nPhotoelectrons;
274 i1Max = i2;
275 i2Max = i2 + mergeSize;
276 if (i2Max > nPhotoelectrons)
277 i2Max = nPhotoelectrons;
278 while (i1 < i1Max || i2 < i2Max) {
279 if (i1 < i1Max) {
280 if (i2 < i2Max) {
281 if (m_Photoelectrons[currentIndexArray[i1]].bin <
282 m_Photoelectrons[currentIndexArray[i2]].bin) {
283 newIndexArray[j] = currentIndexArray[i1];
284 i1++;
285 } else {
286 newIndexArray[j] = currentIndexArray[i2];
287 i2++;
288 }
289 } else {
290 newIndexArray[j] = currentIndexArray[i1];
291 i1++;
292 }
293 } else {
294 newIndexArray[j] = currentIndexArray[i2];
295 i2++;
296 }
297 j++;
298 }
299 }
300 tmpIndexArray = currentIndexArray;
301 currentIndexArray = newIndexArray;
302 newIndexArray = tmpIndexArray;
303 mergeSize = mergeSize * 2;
304 }
305 return currentIndexArray;
306}

Member Data Documentation

◆ m_ADCAmplitude

int* m_ADCAmplitude
private

Digital amplitude.

Definition at line 214 of file ScintillatorSimulator.h.

◆ m_amplitude

float* m_amplitude
private

Analog amplitude.

Definition at line 211 of file ScintillatorSimulator.h.

◆ m_amplitudeDirect

float* m_amplitudeDirect
private

Analog amplitude (direct).

Definition at line 205 of file ScintillatorSimulator.h.

◆ m_amplitudeReflected

float* m_amplitudeReflected
private

Analog amplitude (reflected).

Definition at line 208 of file ScintillatorSimulator.h.

◆ m_Debug

bool m_Debug
private

Debug mode (generates additional output files with histograms).

Definition at line 199 of file ScintillatorSimulator.h.

◆ m_DigitizationInitialTime

double m_DigitizationInitialTime
private

Initial digitization time.

Definition at line 196 of file ScintillatorSimulator.h.

◆ m_DigPar

const KLMScintillatorDigitizationParameters* m_DigPar
private

Parameters.

Definition at line 190 of file ScintillatorSimulator.h.

◆ m_Energy

double m_Energy
private

Total energy deposited in the strip.

Definition at line 244 of file ScintillatorSimulator.h.

◆ m_fitter

ScintillatorFirmware* m_fitter
private

Fitter.

Definition at line 193 of file ScintillatorSimulator.h.

◆ m_FPGAFit

FPGA fit data.

Definition at line 238 of file ScintillatorSimulator.h.

◆ m_FPGAStat

enum ScintillatorFirmwareFitStatus m_FPGAStat
private

FPGA fit status.

Definition at line 235 of file ScintillatorSimulator.h.

◆ m_histRange

double m_histRange
private

Time range, (number of digitizations) * (ADC sampling time).

Definition at line 202 of file ScintillatorSimulator.h.

◆ m_MCTime

float m_MCTime
private

MC time.

Definition at line 259 of file ScintillatorSimulator.h.

◆ m_npe

int m_npe
private

Number of photoelectrons (generated).

Definition at line 241 of file ScintillatorSimulator.h.

◆ m_Pedestal

double m_Pedestal
private

Pedestal.

Definition at line 250 of file ScintillatorSimulator.h.

◆ m_PhotoelectronAmplitude

double m_PhotoelectronAmplitude
private

Photoelectron amplitude.

Definition at line 253 of file ScintillatorSimulator.h.

◆ m_PhotoelectronBufferSize

int m_PhotoelectronBufferSize
private

Size of photoelectron data buffer.

Definition at line 232 of file ScintillatorSimulator.h.

◆ m_PhotoelectronIndex

int* m_PhotoelectronIndex
private

Buffer for photoelectron indices.

Definition at line 226 of file ScintillatorSimulator.h.

◆ m_PhotoelectronIndex2

int* m_PhotoelectronIndex2
private

Buffer for photoelectron indices.

Definition at line 229 of file ScintillatorSimulator.h.

◆ m_Photoelectrons

struct Photoelectron* m_Photoelectrons
private

Buffer for photoelectron data.

Definition at line 223 of file ScintillatorSimulator.h.

◆ m_SignalTimeDependence

double* m_SignalTimeDependence
private

Buffer for signal time dependence calculation.

Definition at line 217 of file ScintillatorSimulator.h.

◆ m_SignalTimeDependenceDiff

double* m_SignalTimeDependenceDiff
private

Buffer for signal time dependence calculation.

Definition at line 220 of file ScintillatorSimulator.h.

◆ m_SiPMMCTime

float m_SiPMMCTime
private

MC time at SiPM.

Definition at line 262 of file ScintillatorSimulator.h.

◆ m_stripName

std::string m_stripName
private

Name of the strip.

Definition at line 247 of file ScintillatorSimulator.h.

◆ m_Threshold

int m_Threshold
private

Threshold.

Definition at line 256 of file ScintillatorSimulator.h.

◆ m_Time

const KLMTime* m_Time
private

Time.

Definition at line 187 of file ScintillatorSimulator.h.


The documentation for this class was generated from the following files: