Belle II Software  release-06-00-14
ScintillatorSimulator.h
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 #pragma once
10 
11 /* KLM headers. */
12 #include <klm/dataobjects/bklm/BKLMSimHit.h>
13 #include <klm/dataobjects/eklm/EKLMSimHit.h>
14 #include <klm/dbobjects/KLMScintillatorDigitizationParameters.h>
15 #include <klm/dbobjects/KLMScintillatorFEEData.h>
16 #include <klm/simulation/ScintillatorFirmware.h>
17 #include <klm/time/KLMTime.h>
18 
19 /* Belle 2 headers. */
20 #include <framework/database/DBObjPtr.h>
21 
22 namespace Belle2 {
28  namespace KLM {
29 
34 
35  public:
36 
38  struct Photoelectron {
39  int bin;
40  double expTime;
41  bool isReflected;
42  };
43 
52  ScintillatorFirmware* fitter,
53  double digitizationInitialTime,
54  bool debug);
55 
60 
65 
70 
76  void simulate(
77  const std::multimap<KLMChannelNumber, const BKLMSimHit*>::iterator& firstHit,
78  const std::multimap<KLMChannelNumber, const BKLMSimHit*>::iterator& end);
79 
85  void simulate(
86  const std::multimap<KLMChannelNumber, const EKLMSimHit*>::iterator& firstHit,
87  const std::multimap<KLMChannelNumber, const EKLMSimHit*>::iterator& end);
88 
93 
98  enum ScintillatorFirmwareFitStatus getFitStatus() const;
99 
103  double getNPhotoelectrons();
104 
109 
113  double getEnergy();
114 
118  void setFEEData(const KLMScintillatorFEEData* FEEData);
119 
128  void generatePhotoelectrons(double stripLen, double distSiPM,
129  int nPhotons, double timeShift,
130  bool isReflected);
131 
138  void fillSiPMOutput(float* hist, bool useDirect, bool useReflected);
139 
144  float getMCTime() const
145  {
146  return m_MCTime;
147  }
148 
153  float getSiPMMCTime() const
154  {
155  return m_SiPMMCTime;
156  }
157 
158  private:
159 
164  void reallocPhotoElectronBuffers(int size);
165 
169  void prepareSimulation();
170 
174  void performSimulation();
175 
181  int* sortPhotoelectrons(int nPhotoelectrons);
182 
186  void addRandomSiPMNoise();
187 
191  void simulateADC();
192 
196  void debugOutput();
197 
199  const KLMTime* m_Time;
200 
203 
206 
209 
211  bool m_Debug;
212 
214  double m_histRange;
215 
218 
221 
223  float* m_amplitude;
224 
227 
230 
233 
236 
239 
242 
245 
247  enum ScintillatorFirmwareFitStatus m_FPGAStat;
248 
251 
253  int m_npe;
254 
256  double m_Energy;
257 
259  std::string m_stripName;
260 
262  double m_Pedestal;
263 
266 
269 
271  float m_MCTime;
272 
275 
276  };
277 
278  }
279 
281 }
Class to store KLM scintillator simulation parameters in the database.
KLM time conversion.
Definition: KLMTime.h:27
Digitize EKLMSim2Hits to get EKLM StripHits.
float getSiPMMCTime() const
Get SiPM MC time.
void setFEEData(const KLMScintillatorFEEData *FEEData)
Set FEE data.
int * m_PhotoelectronIndex2
Buffer for photoelectron indices.
float * m_amplitudeReflected
Analog amplitude (reflected).
void debugOutput()
Debug output (signal and fit result histograms).
enum ScintillatorFirmwareFitStatus getFitStatus() const
Get fit status.
double * m_SignalTimeDependence
Buffer for signal time dependence calculation.
void generatePhotoelectrons(double stripLen, double distSiPM, int nPhotons, double timeShift, bool isReflected)
Generate photoelectrons.
double * m_SignalTimeDependenceDiff
Buffer for signal time dependence calculation.
double m_Energy
Total energy deposited in the strip.
float * m_amplitudeDirect
Analog amplitude (direct).
ScintillatorSimulator(const ScintillatorSimulator &)=delete
Copy constructor (disabled).
void addRandomSiPMNoise()
Add random noise to the signal (amplitude-dependend).
void simulateADC()
Simulate ADC (create digital signal from analog),.
void prepareSimulation()
Prepare simulation.
void simulate(const std::multimap< KLMChannelNumber, const BKLMSimHit * >::iterator &firstHit, const std::multimap< KLMChannelNumber, const BKLMSimHit * >::iterator &end)
Simulate BKLM strip.
double getEnergy()
Get total energy deposited in the strip (sum over ssimulation hits).
double m_histRange
Time range, (number of digitizations) * (ADC sampling time).
void reallocPhotoElectronBuffers(int size)
Reallocate photoelectron buffers.
bool m_Debug
Debug mode (generates additional output files with histograms).
double m_DigitizationInitialTime
Initial digitization time.
double getNPhotoelectrons()
Get number of photoelectrons (fit result).
ScintillatorSimulator & operator=(const ScintillatorSimulator &)=delete
Operator = (disabled).
struct Photoelectron * m_Photoelectrons
Buffer for photoelectron data.
ScintillatorFirmware * m_fitter
Fitter.
std::string m_stripName
Name of the strip.
enum ScintillatorFirmwareFitStatus m_FPGAStat
FPGA fit status.
KLMScintillatorFirmwareFitResult * getFPGAFit()
Get fit data.
KLMScintillatorFirmwareFitResult m_FPGAFit
FPGA fit data.
void performSimulation()
Perform common simulation stage.
double m_PhotoelectronAmplitude
Photoelectron amplitude.
int getNGeneratedPhotoelectrons()
Get generated number of photoelectrons.
int * m_PhotoelectronIndex
Buffer for photoelectron indices.
void fillSiPMOutput(float *hist, bool useDirect, bool useReflected)
Fill SiPM output.
int * sortPhotoelectrons(int nPhotoelectrons)
Sort photoelectrons.
int m_npe
Number of photoelectrons (generated).
int m_PhotoelectronBufferSize
Size of photoelectron data buffer.
ScintillatorSimulator(const KLMScintillatorDigitizationParameters *digPar, ScintillatorFirmware *fitter, double digitizationInitialTime, bool debug)
Constructor.
const KLMScintillatorDigitizationParameters * m_DigPar
Parameters.
Abstract base class for different kinds of events.
int bin
Hit time bin in ADC output histogram.
bool isReflected
Direct (false) or reflected (true).
double expTime
exp(-m_DigPar->PEAttenuationFreq * (-time))