Belle II Software  release-06-00-14
TRGECLFAMModule.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 #define TRGECLFAM_SHORT_NAMES
10 
11 //framework headers
12 #include <framework/logging/Logger.h>
13 
14 //trg package headers
15 #include "trg/ecl/modules/trgecl/TRGECLFAMModule.h"
16 #include "trg/ecl/TrgEclDigitizer.h"
17 #include "trg/ecl/TrgEclFAMFit.h"
18 
19 #include "trg/ecl/dbobjects/TRGECLFAMPara.h"
20 
21 #include <iostream>
22 
23 using namespace std;
24 
25 namespace Belle2 {
30 //
31 //
33  REG_MODULE(TRGECLFAM);
34 //
35 //
36 //
37  string
38  TRGECLFAMModule::version() const
39  {
40  return string("TRGECLFAMModule 1.00");
41  }
42 //
43 //
44 //
45  TRGECLFAMModule::TRGECLFAMModule()
46  : Module::Module(),
47  _debugLevel(0),
48  _famMethod(1),
49  _binTimeInterval(125),
50  _waveform(0),
51  _beambkgtag(0),
52  _famana(0),
53  _threshold(100.0),
54  _FADC(1),
55  _ConditionDB(0)
56 
57  {
58 
59  string desc = "TRGECLFAMModule(" + version() + ")";
60  setDescription(desc);
62 
63  addParam("DebugLevel", _debugLevel, "TRGECL debug level", _debugLevel);
64  addParam("FAMFitMethod", _famMethod, "TRGECLFAM fit method", _famMethod);
65  addParam("FAMBinTimeInterval", _binTimeInterval, "TRGECLFAM binTimeInterval",
67  addParam("TCWaveform", _waveform, "Output the TC waveform ",
68  _waveform);
69  addParam("FAMAnaTable", _famana, "Save FAM ana table ",
70  _famana);
71  addParam("BeamBkgTag", _beambkgtag, "Save beambackground tag in TRGECLHit table ",
72  _beambkgtag);
73  addParam("TCThreshold", _threshold, "Set FAM TC threshold ",
74  _threshold);
75  addParam("ShapingFunction", _FADC, "Set function of shaper ", _FADC);
76  addParam("ConditionDB", _ConditionDB, "Use conditionDB ", _ConditionDB);
77 
78  if (_ConditionDB == 1) { //Use global tag
79  m_FAMPara.addCallback(this, &TRGECLFAMModule::beginRun);
80  }
81  B2DEBUG(100, "TRGECLFAMModule ... created");
82  Threshold.clear();
83  }
84 //
85 //
86 //
88  {
89 
90  B2DEBUG(100, "TRGECLFAMModule ... destructed ");
91 
92 
93  }
94 //
95 //
96 //
97  void
99  {
100 
101  B2DEBUG(100, "TRGECLFAMModule::initialize ... options");
102  B2DEBUG(100, "TRGECLFAMModule::initialize> FAM Fit Method = "
103  << _famMethod << " ; Bin of Time Interval = " << _binTimeInterval << " ;output TC waveforml = " << _waveform);
104 
105  m_nRun = 0;
106  m_nEvent = 1;
107 
108  m_TRGECLDigi0.registerInDataStore();
109  m_TRGECLWaveform.registerInDataStore();
110  m_TRGECLHit.registerInDataStore();
111  m_TRGECLFAMAna.registerInDataStore();
112  // m_FAMPara = new DBObjPtr<TRGECLFAMPara>;
113  }
114 //
115 //
116 //
117  void
119  {
120  if (_ConditionDB == 0) {
121  Threshold.resize(576, _threshold);
122  } else if (_ConditionDB == 1) { //Use global tag
123  Threshold.resize(576, 0);
124  for (const auto& para : m_FAMPara) {
125  Threshold[para.getTCId() - 1] = (int)((para.getThreshold()) * (para.getConversionFactor()));
126  }
127  }
128 
129  B2DEBUG(200, "TRGECLFAMModule ... beginRun called ");
130 
131  }
132 //
133 //
134 //
135  void
137  {
138 
139  B2DEBUG(200, "TRGECLFAMMoudle ... event called");
140  //
141  //
142  if (m_nEvent < 1e2) {if (m_nEvent % 10 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
143  else if (m_nEvent < 1e3) {if (m_nEvent % 100 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
144  else if (m_nEvent < 1e4) {if (m_nEvent % 1000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
145  else if (m_nEvent < 1e5) {if (m_nEvent % 10000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
146  else if (m_nEvent < 1e6) {if (m_nEvent % 100000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
147 
148 
149  //
150  //
151  //
152  // FAM Digitizer
153  TrgEclDigitizer* obj_trgeclDigi = new TrgEclDigitizer();
154  obj_trgeclDigi-> setWaveform(_waveform);
155  obj_trgeclDigi-> setFADC(_FADC);
156  obj_trgeclDigi-> setup();
157  if (_famMethod == 2 || _famMethod == 1) {obj_trgeclDigi-> digitization01(TCDigiE, TCDigiT); } // no-fit method = backup method 1
158  else if (_famMethod == 3) { obj_trgeclDigi-> digitization02(TCDigiE, TCDigiT); } // orignal method = backup method 2
159  obj_trgeclDigi-> save(m_nEvent);
160 
161 
162  // FAM Fitter
163  TrgEclFAMFit* obj_trgeclfit = new TrgEclFAMFit();
164  obj_trgeclfit-> SetBeamBkgTagFlag(_beambkgtag);
165  obj_trgeclfit-> SetAnaTagFlag(_famana);
166  obj_trgeclfit-> setup(m_nEvent);
167  obj_trgeclfit-> SetThreshold(Threshold);
168 
169  if (_famMethod == 1) {obj_trgeclfit-> FAMFit01(TCDigiE, TCDigiT); } // fitting method
170  else if (_famMethod == 2) {obj_trgeclfit-> FAMFit02(TCDigiE, TCDigiT); } // no-fit method = backup method 1
171  else if (_famMethod == 3) { obj_trgeclfit-> FAMFit03(TCDigiE, TCDigiT); } // orignal method = backup method 2
172  obj_trgeclfit-> save(m_nEvent);
173 
174 
175  //
176  //
177  //
178  m_nEvent++;
179  delete obj_trgeclDigi;
180  delete obj_trgeclfit;
181  //
182  //
183  //
184  }
185 //
186 //
187 //
188  void
190  {
191  B2DEBUG(200, "TRGECLFAMModule ... endRun called ");
192  }
193 //
194 //
195 //
196  void
198  {
199  B2DEBUG(100, "TRGECLFAMModule ... terminate called ");
200  }
201 //
202 //
203 //
205 } // namespace Belle2
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
int _FADC
Set Shaping Function.
int _famana
save FAM ana table
std::vector< std::vector< double > > TCDigiT
Digitized TC T [ns].
int _ConditionDB
Use Condition DB.
StoreArray< TRGECLFAMAna > m_TRGECLFAMAna
output for TRGECLFAMAna
int _debugLevel
Parameters.
int _beambkgtag
save Beam background tag in TRGECLHit table
int _binTimeInterval
Time interval.
std::vector< std::vector< double > > TCDigiE
Digitized TC E [GeV].
StoreArray< TRGECLDigi0 > m_TRGECLDigi0
output for TRGECLDigi0
int m_nEvent
Event number.
int _threshold
Threshold input.
StoreArray< TRGECLWaveform > m_TRGECLWaveform
output for TRGECLWaveform
StoreArray< TRGECLHit > m_TRGECLHit
output for TRGECLHit
std::vector< int > Threshold
Threshold.
DBArray< TRGECLFAMPara > m_FAMPara
FAM Parameters.
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
virtual void initialize() override
Initilizes TRGECLFAMModule.
virtual void event() override
Called event by event.
virtual void endRun() override
Called when run ended.
virtual void terminate() override
Called when processing ended.
virtual void beginRun() override
Called when new run started.
std::string version(void) const
returns version of TRGECLFAMModule.
virtual ~TRGECLFAMModule()
Destructor.
Abstract base class for different kinds of events.