Belle II Software  release-08-01-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  m_SourceOfTC(3)
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  addParam("SourceOfTC", m_SourceOfTC,
78  "Select source of TC data(1:=ECLHit or 2:=ECLSimHit or 3:=ECLHit+TRGECLBGTCHit)",
79  m_SourceOfTC);
80 
81  if (_ConditionDB == 1) { //Use global tag
82  m_FAMPara.addCallback(this, &TRGECLFAMModule::beginRun);
83  }
84  B2DEBUG(100, "TRGECLFAMModule ... created");
85  Threshold.clear();
86 
87  }
88 //
89 //
90 //
92  {
93 
94  B2DEBUG(100, "TRGECLFAMModule ... destructed ");
95 
96  }
97 //
98 //
99 //
100  void
102  {
103 
104  B2DEBUG(100, "TRGECLFAMModule::initialize ... options");
105  B2DEBUG(100, "TRGECLFAMModule::initialize> FAM Fit Method = " << _famMethod
106  << " ; Bin of Time Interval = " << _binTimeInterval
107  << " ;output TC waveforml = " << _waveform);
108  if (m_SourceOfTC <= 0 ||
109  m_SourceOfTC >= 4) {
110  B2FATAL("TRGECLFAMModule::initialize> SourceOfTC must be 1 or 2 or 3");
111  }
112 
113  m_nRun = 0;
114  m_nEvent = 1;
115 
116  m_TRGECLDigi0.registerInDataStore();
117  m_TRGECLWaveform.registerInDataStore();
118  m_TRGECLHit.registerInDataStore();
119  m_TRGECLFAMAna.registerInDataStore();
120  m_eventLevelClusteringInfo.registerInDataStore();
121 
122  // m_FAMPara = new DBObjPtr<TRGECLFAMPara>;
123  }
124 //
125 //
126 //
127  void
129  {
130  if (_ConditionDB == 0) {
131  Threshold.resize(576, _threshold);
132  } else if (_ConditionDB == 1) { //Use global tag
133  Threshold.resize(576, 0);
134  for (const auto& para : m_FAMPara) {
135  Threshold[para.getTCId() - 1] = (int)((para.getThreshold()) * (para.getConversionFactor()));
136  }
137  }
138 
139  B2DEBUG(200, "TRGECLFAMModule ... beginRun called ");
140 
141  }
142 //
143 //
144 //
145  void
147  {
148 
149  B2DEBUG(200, "TRGECLFAMMoudle ... event called");
150  //
151  //
152  if (m_nEvent < 1e2) {if (m_nEvent % 10 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
153  else if (m_nEvent < 1e3) {if (m_nEvent % 100 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
154  else if (m_nEvent < 1e4) {if (m_nEvent % 1000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
155  else if (m_nEvent < 1e5) {if (m_nEvent % 10000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
156  else if (m_nEvent < 1e6) {if (m_nEvent % 100000 == 0) {B2DEBUG(200, "TRGECLFAMModule::event> evtno= " << m_nEvent);}}
157 
158 
159  //
160  //
161  //
162  // FAM Digitizer
163  TrgEclDigitizer* obj_trgeclDigi = new TrgEclDigitizer();
164  obj_trgeclDigi->setWaveform(_waveform);
165  obj_trgeclDigi->setFADC(_FADC);
166  obj_trgeclDigi->setup(m_SourceOfTC);
167  if (_famMethod == 1 || _famMethod == 2) {
168  // no-fit method = backup method 1
169  obj_trgeclDigi->digitization01(TCDigiE, TCDigiT);
170  } else if (_famMethod == 3) {
171  // orignal method = backup method 2
172  obj_trgeclDigi->digitization02(TCDigiE, TCDigiT);
173  }
174  obj_trgeclDigi-> save(m_nEvent);
175 
176 
177  // FAM Fitter
178  TrgEclFAMFit* obj_trgeclfit = new TrgEclFAMFit();
179  obj_trgeclfit-> SetBeamBkgTagFlag(_beambkgtag);
180  obj_trgeclfit-> SetAnaTagFlag(_famana);
181  obj_trgeclfit-> setup(m_nEvent);
182  obj_trgeclfit-> SetThreshold(Threshold);
183 
184  if (_famMethod == 1) {obj_trgeclfit-> FAMFit01(TCDigiE, TCDigiT); } // fitting method
185  else if (_famMethod == 2) {obj_trgeclfit-> FAMFit02(TCDigiE, TCDigiT); } // no-fit method = backup method 1
186  else if (_famMethod == 3) { obj_trgeclfit-> FAMFit03(TCDigiE, TCDigiT); } // orignal method = backup method 2
187  obj_trgeclfit-> save(m_nEvent);
188 
189 
190  // Count number of trigger cells in each ECL region for EventLevelClusteringInfo
191  uint16_t nTCsPerRegion[3] = {};
192  const double absTimeRequirement = 9999.; // Selection on time to reproduce data
193  const int firstBarrelId = 81; // First TCId in the barrel
194  const int lastBarrelId = 512; // Last TCId in the barrel
195  for (auto& trgeclhit : m_TRGECLHit) {
196  const int tcId = trgeclhit.getTCId();
197  const double tcTime = trgeclhit.getTimeAve();
198  if (std::abs(tcTime) < absTimeRequirement) {
199  if (tcId < firstBarrelId) {
200  nTCsPerRegion[0]++;
201  } else if (tcId > lastBarrelId) {
202  nTCsPerRegion[2]++;
203  } else {
204  nTCsPerRegion[1]++;
205  }
206  }
207  }
208 
209  // Store
211  m_eventLevelClusteringInfo->setNECLTriggerCellsFWD(nTCsPerRegion[0]);
212  m_eventLevelClusteringInfo->setNECLTriggerCellsBarrel(nTCsPerRegion[1]);
213  m_eventLevelClusteringInfo->setNECLTriggerCellsBWD(nTCsPerRegion[2]);
214 
215 
216  //
217  //
218  //
219  m_nEvent++;
220  delete obj_trgeclDigi;
221  delete obj_trgeclfit;
222  //
223  //
224  //
225  }
226 //
227 //
228 //
229  void
231  {
232  B2DEBUG(200, "TRGECLFAMModule ... endRun called ");
233  }
234 //
235 //
236 //
237  void
239  {
240  B2DEBUG(100, "TRGECLFAMModule ... terminate called ");
241  }
242 //
243 //
244 //
246 } // 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 m_SourceOfTC
Set source of TC data (1:=ECLHit or 2:=ECLSimHit or 3:=ECLHit+TRGECLBGTCHit)
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 setup(int)
setup fam module
void setFADC(int fadc)
Set flag of waveform table.
void setWaveform(int wave)
Set flag of waveform table.
void digitization01(std::vector< std::vector< double >> &, std::vector< std::vector< double >> &)
fit method, digi with 125ns interval
void digitization02(std::vector< std::vector< double >> &, std::vector< std::vector< double >> &)
original no fit method, digi with 12ns interval
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.