Belle II Software  release-06-00-14
EKLMADCModule.cc
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 /* Own header. */
10 #include <klm/eklm/modules/EKLMADC/EKLMADCModule.h>
11 
12 /* KLM headers. */
13 #include <klm/eklm/geometry/GeometryData.h>
14 #include <klm/simulation/ScintillatorSimulator.h>
15 
16 /* Belle 2 headers. */
17 #include <framework/gearbox/Unit.h>
18 
19 /* ROOT headers. */
20 #include <TH1F.h>
21 
22 using namespace Belle2;
23 
24 REG_MODULE(EKLMADC)
25 
26 static const char MemErr[] = "Memory allocation error.";
27 
29  Module(),
30  m_fout(nullptr),
31  m_SciSimPar(nullptr),
32  m_hDir(nullptr),
33  m_hRef(nullptr)
34 {
35  setDescription("Standalone generation and studies of ADC output.");
37  addParam("OutputFile", m_out, "Output file.", std::string("EKLMADC.root"));
38  addParam("Mode", m_mode, "Mode (\"Shape\" or \"Strips\").",
39  std::string("Strips"));
40 }
41 
43 {
44 }
45 
46 void EKLMADCModule::generateHistogram(const char* name, double l, double d,
47  int npe)
48 {
49  int j;
50  double t, s;
51  KLM::ScintillatorSimulator fe(m_SciSimPar, nullptr, 0, false);
52  KLMTime* klmTime = &(KLMTime::Instance());
53  klmTime->updateConstants();
54  TH1F* h = nullptr;
57  try {
58  h = new TH1F(name, "", m_SciSimPar->getNDigitizations(), 0, t);
59  } catch (std::bad_alloc& ba) {
60  B2FATAL(MemErr);
61  }
62  for (j = 0; j < m_SciSimPar->getNDigitizations(); j++) {
63  m_hDir[j] = 0;
64  m_hRef[j] = 0;
65  }
66  fe.generatePhotoelectrons(l, d, npe, 0, false);
67  fe.generatePhotoelectrons(l, d, npe, 0, true);
68  fe.fillSiPMOutput(m_hDir, true, false);
69  fe.fillSiPMOutput(m_hRef, false, true);
70  s = 0;
71  for (j = 0; j < m_SciSimPar->getNDigitizations(); j++)
72  s = s + m_hDir[j] + m_hRef[j];
73  for (j = 1; j <= m_SciSimPar->getNDigitizations(); j++)
74  h->SetBinContent(j, (m_hDir[j - 1] + m_hRef[j - 1]) / s);
75  h->Write();
76  delete h;
77 }
78 
80 {
81  /* cppcheck-suppress variableScope */
82  char str[32];
83  /* cppcheck-suppress variableScope */
84  int i;
85  /* cppcheck-suppress variableScope */
86  double l;
87  if (!m_SciSimParDatabase.isValid())
88  B2FATAL("EKLM digitization parameters are not available.");
91  try {
92  m_fout = new TFile(m_out.c_str(), "recreate");
93  } catch (std::bad_alloc& ba) {
94  B2FATAL(MemErr);
95  }
96  m_hDir = (float*)malloc(m_SciSimPar->getNDigitizations() * sizeof(float));
97  if (m_hDir == nullptr)
98  B2FATAL(MemErr);
99  m_hRef = (float*)malloc(m_SciSimPar->getNDigitizations() * sizeof(float));
100  if (m_hRef == nullptr)
101  B2FATAL(MemErr);
102  if (m_mode.compare("Strips") == 0) {
103  for (i = 1; i <= geoDat->getNStrips(); i++) {
104  l = geoDat->getStripLength(i) / CLHEP::mm * Unit::mm;
105  snprintf(str, 32, "h%d_near", i);
106  generateHistogram(str, l, 0, 10000);
107  snprintf(str, 32, "h%d_far", i);
108  generateHistogram(str, l, l, 10000);
109  }
110  } else if (m_mode.compare("Shape") == 0) {
112  generateHistogram("FitShape", 0, 0, 1000000);
113  } else
114  B2FATAL("Unknown operation mode.");
115  free(m_hDir);
116  free(m_hRef);
117  m_fout->Close();
118  delete m_fout;
119 }
120 
122 {
123 }
124 
126 {
127 }
128 
130 {
131 }
132 
134 {
135  delete m_SciSimPar;
136 }
137 
void generateHistogram(const char *name, double l, double d, int npe)
Generate output histogram.
~EKLMADCModule()
Destructor.
void initialize() override
Initializer.
float * m_hRef
Reflected histogram.
void event() override
This method is called for each event.
TFile * m_fout
Output file.
Definition: EKLMADCModule.h:90
void endRun() override
This method is called if the current run ends.
void terminate() override
This method is called at the end of the event processing.
EKLMADCModule()
Constructor.
KLMScintillatorDigitizationParameters * m_SciSimPar
Scintillator simulation parameters.
Definition: EKLMADCModule.h:96
float * m_hDir
Direct histogram.
void beginRun() override
Called when entering a new run.
std::string m_out
Name of output file.
Definition: EKLMADCModule.h:87
DBObjPtr< KLMScintillatorDigitizationParameters > m_SciSimParDatabase
Scintillator simulation parameters.
Definition: EKLMADCModule.h:93
std::string m_mode
Operation mode.
Definition: EKLMADCModule.h:84
int getNStrips() const
Get number of strips.
EKLM geometry data.
Definition: GeometryData.h:38
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
Definition: GeometryData.cc:33
double getStripLength(int strip) const
Get strip length.
Definition: GeometryData.h:71
Class to store KLM scintillator simulation parameters in the database.
void setMirrorReflectiveIndex(float reflectiveIndex)
Set mirror reflective index.
int getADCSamplingTDCPeriods() const
Get ADC sampling time in TDC periods.
int getNDigitizations() const
Get number of digitizations (points) in one sample.
KLM time conversion.
Definition: KLMTime.h:27
double getTDCPeriod() const
Get TDC period.
Definition: KLMTime.h:45
void updateConstants()
Update constants from database objects.
Definition: KLMTime.cc:20
static KLMTime & Instance()
Instantiation.
Definition: KLMTime.cc:14
Digitize EKLMSim2Hits to get EKLM StripHits.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
static const double mm
[millimeters]
Definition: Unit.h:70
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.