Belle II Software  release-08-00-10
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_eventLevelClusteringInfo.registerInDataStore();
113 
114  // m_FAMPara = new DBObjPtr<TRGECLFAMPara>;
115  }
116 //
117 //
118 //
119  void
121  {
122  if (_ConditionDB == 0) {
123  Threshold.resize(576, _threshold);
124  } else if (_ConditionDB == 1) { //Use global tag
125  Threshold.resize(576, 0);
126  for (const auto& para : m_FAMPara) {
127  Threshold[para.getTCId() - 1] = (int)((para.getThreshold()) * (para.getConversionFactor()));
128  }
129  }
130 
131  B2DEBUG(200, "TRGECLFAMModule ... beginRun called ");
132 
133  }
134 //
135 //
136 //
137  void
139  {
140 
141  B2DEBUG(200, "TRGECLFAMMoudle ... event called");
142  //
143  //
144  if (m_nEvent < 1e2) {if (m_nEvent % 10 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
145  else if (m_nEvent < 1e3) {if (m_nEvent % 100 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
146  else if (m_nEvent < 1e4) {if (m_nEvent % 1000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
147  else if (m_nEvent < 1e5) {if (m_nEvent % 10000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
148  else if (m_nEvent < 1e6) {if (m_nEvent % 100000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
149 
150 
151  //
152  //
153  //
154  // FAM Digitizer
155  TrgEclDigitizer* obj_trgeclDigi = new TrgEclDigitizer();
156  obj_trgeclDigi-> setWaveform(_waveform);
157  obj_trgeclDigi-> setFADC(_FADC);
158  obj_trgeclDigi-> setup();
159  if (_famMethod == 2 || _famMethod == 1) {obj_trgeclDigi-> digitization01(TCDigiE, TCDigiT); } // no-fit method = backup method 1
160  else if (_famMethod == 3) { obj_trgeclDigi-> digitization02(TCDigiE, TCDigiT); } // orignal method = backup method 2
161  obj_trgeclDigi-> save(m_nEvent);
162 
163 
164  // FAM Fitter
165  TrgEclFAMFit* obj_trgeclfit = new TrgEclFAMFit();
166  obj_trgeclfit-> SetBeamBkgTagFlag(_beambkgtag);
167  obj_trgeclfit-> SetAnaTagFlag(_famana);
168  obj_trgeclfit-> setup(m_nEvent);
169  obj_trgeclfit-> SetThreshold(Threshold);
170 
171  if (_famMethod == 1) {obj_trgeclfit-> FAMFit01(TCDigiE, TCDigiT); } // fitting method
172  else if (_famMethod == 2) {obj_trgeclfit-> FAMFit02(TCDigiE, TCDigiT); } // no-fit method = backup method 1
173  else if (_famMethod == 3) { obj_trgeclfit-> FAMFit03(TCDigiE, TCDigiT); } // orignal method = backup method 2
174  obj_trgeclfit-> save(m_nEvent);
175 
176 
177  // Count number of trigger cells in each ECL region for EventLevelClusteringInfo
178  uint16_t nTCsPerRegion[3] = {};
179  const double absTimeRequirement = 9999.; // Selection on time to reproduce data
180  const int firstBarrelId = 81; // First TCId in the barrel
181  const int lastBarrelId = 512; // Last TCId in the barrel
182  for (auto& trgeclhit : m_TRGECLHit) {
183  const int tcId = trgeclhit.getTCId();
184  const double tcTime = trgeclhit.getTimeAve();
185  if (std::abs(tcTime) < absTimeRequirement) {
186  if (tcId < firstBarrelId) {
187  nTCsPerRegion[0]++;
188  } else if (tcId > lastBarrelId) {
189  nTCsPerRegion[2]++;
190  } else {
191  nTCsPerRegion[1]++;
192  }
193  }
194  }
195 
196  // Store
198  m_eventLevelClusteringInfo->setNECLTriggerCellsFWD(nTCsPerRegion[0]);
199  m_eventLevelClusteringInfo->setNECLTriggerCellsBarrel(nTCsPerRegion[1]);
200  m_eventLevelClusteringInfo->setNECLTriggerCellsBWD(nTCsPerRegion[2]);
201 
202 
203  //
204  //
205  //
206  m_nEvent++;
207  delete obj_trgeclDigi;
208  delete obj_trgeclfit;
209  //
210  //
211  //
212  }
213 //
214 //
215 //
216  void
218  {
219  B2DEBUG(200, "TRGECLFAMModule ... endRun called ");
220  }
221 //
222 //
223 //
224  void
226  {
227  B2DEBUG(100, "TRGECLFAMModule ... terminate called ");
228  }
229 //
230 //
231 //
233 } // 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.
StoreObjPtr< EventLevelClusteringInfo > m_eventLevelClusteringInfo
EventLevelClusteringInfo.
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.